1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00
llvm-mirror/lib/IR/Use.cpp
Jay Foad a5a47b7afe [IR] Simplify Use::swap. NFCI.
The new implementation makes it clear that there are exactly two
conditional stores (after the initial no-op optimization). By contrast
the old implementation had seven conditionals, some hidden inside other
functions.

This commit can change the order of operands in operand lists, hence the
tweak to one test case.

Differential Revision: https://reviews.llvm.org/D80116
2020-07-21 12:15:12 +01:00

45 lines
998 B
C++

//===-- Use.cpp - Implement the Use class ---------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "llvm/IR/Use.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include <new>
namespace llvm {
void Use::swap(Use &RHS) {
if (Val == RHS.Val)
return;
std::swap(Val, RHS.Val);
std::swap(Next, RHS.Next);
std::swap(Prev, RHS.Prev);
*Prev = this;
if (Next)
Next->Prev = &Next;
*RHS.Prev = &RHS;
if (RHS.Next)
RHS.Next->Prev = &RHS.Next;
}
unsigned Use::getOperandNo() const {
return this - getUser()->op_begin();
}
void Use::zap(Use *Start, const Use *Stop, bool del) {
while (Start != Stop)
(--Stop)->~Use();
if (del)
::operator delete(Start);
}
} // namespace llvm