forked from OSchip/llvm-project
Simplify handleOperandChangeImpl() removing last argument (NFC)
The Use argument was used to compute the operand number for a fast path when replacing only one operand. However we always have to go through all the operands. So the argument number can be recomputed locally anyway. From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 260454
This commit is contained in:
parent
4fc6044a5e
commit
8914d29008
|
@ -131,7 +131,7 @@ public:
|
|||
/// use Value::replaceAllUsesWith, which automatically dispatches to this
|
||||
/// method as needed.
|
||||
///
|
||||
void handleOperandChange(Value *, Value *, Use *);
|
||||
void handleOperandChange(Value *, Value *);
|
||||
|
||||
static Constant *getNullValue(Type* Ty);
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ class ConstantInt : public Constant {
|
|||
|
||||
friend class Constant;
|
||||
void destroyConstantImpl();
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To);
|
||||
|
||||
protected:
|
||||
// allocate space for exactly zero operands
|
||||
|
@ -239,7 +239,7 @@ class ConstantFP : public Constant {
|
|||
|
||||
friend class Constant;
|
||||
void destroyConstantImpl();
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To);
|
||||
|
||||
protected:
|
||||
ConstantFP(Type *Ty, const APFloat& V);
|
||||
|
@ -310,7 +310,7 @@ class ConstantAggregateZero : public Constant {
|
|||
|
||||
friend class Constant;
|
||||
void destroyConstantImpl();
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To);
|
||||
|
||||
protected:
|
||||
explicit ConstantAggregateZero(Type *ty)
|
||||
|
@ -357,7 +357,7 @@ class ConstantArray : public Constant {
|
|||
|
||||
friend class Constant;
|
||||
void destroyConstantImpl();
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To);
|
||||
|
||||
protected:
|
||||
ConstantArray(ArrayType *T, ArrayRef<Constant *> Val);
|
||||
|
@ -400,7 +400,7 @@ class ConstantStruct : public Constant {
|
|||
|
||||
friend class Constant;
|
||||
void destroyConstantImpl();
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To);
|
||||
|
||||
protected:
|
||||
ConstantStruct(StructType *T, ArrayRef<Constant *> Val);
|
||||
|
@ -459,7 +459,7 @@ class ConstantVector : public Constant {
|
|||
|
||||
friend class Constant;
|
||||
void destroyConstantImpl();
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To);
|
||||
|
||||
protected:
|
||||
ConstantVector(VectorType *T, ArrayRef<Constant *> Val);
|
||||
|
@ -509,7 +509,7 @@ class ConstantPointerNull : public Constant {
|
|||
|
||||
friend class Constant;
|
||||
void destroyConstantImpl();
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To);
|
||||
|
||||
protected:
|
||||
explicit ConstantPointerNull(PointerType *T)
|
||||
|
@ -562,7 +562,7 @@ class ConstantDataSequential : public Constant {
|
|||
|
||||
friend class Constant;
|
||||
void destroyConstantImpl();
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To);
|
||||
|
||||
protected:
|
||||
explicit ConstantDataSequential(Type *ty, ValueTy VT, const char *Data)
|
||||
|
@ -786,7 +786,7 @@ class ConstantTokenNone : public Constant {
|
|||
|
||||
friend class Constant;
|
||||
void destroyConstantImpl();
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To);
|
||||
|
||||
protected:
|
||||
explicit ConstantTokenNone(LLVMContext &Context)
|
||||
|
@ -813,7 +813,7 @@ class BlockAddress : public Constant {
|
|||
|
||||
friend class Constant;
|
||||
void destroyConstantImpl();
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To);
|
||||
|
||||
public:
|
||||
/// Return a BlockAddress for the specified function and basic block.
|
||||
|
@ -860,7 +860,7 @@ class ConstantExpr : public Constant {
|
|||
|
||||
friend class Constant;
|
||||
void destroyConstantImpl();
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To);
|
||||
|
||||
protected:
|
||||
ConstantExpr(Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
|
||||
|
@ -1229,7 +1229,7 @@ class UndefValue : public Constant {
|
|||
|
||||
friend class Constant;
|
||||
void destroyConstantImpl();
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To);
|
||||
|
||||
protected:
|
||||
explicit UndefValue(Type *T) : Constant(T, UndefValueVal, nullptr, 0) {}
|
||||
|
|
|
@ -93,7 +93,7 @@ private:
|
|||
|
||||
friend class Constant;
|
||||
void destroyConstantImpl();
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
|
||||
Value *handleOperandChangeImpl(Value *From, Value *To);
|
||||
|
||||
protected:
|
||||
/// \brief The intrinsic ID for this subclass (which must be a Function).
|
||||
|
|
|
@ -1466,16 +1466,18 @@ void BlockAddress::destroyConstantImpl() {
|
|||
getBasicBlock()->AdjustBlockAddressRefCount(-1);
|
||||
}
|
||||
|
||||
Value *BlockAddress::handleOperandChangeImpl(Value *From, Value *To, Use *U) {
|
||||
Value *BlockAddress::handleOperandChangeImpl(Value *From, Value *To) {
|
||||
// This could be replacing either the Basic Block or the Function. In either
|
||||
// case, we have to remove the map entry.
|
||||
Function *NewF = getFunction();
|
||||
BasicBlock *NewBB = getBasicBlock();
|
||||
|
||||
if (U == &Op<0>())
|
||||
if (From == NewF)
|
||||
NewF = cast<Function>(To->stripPointerCasts());
|
||||
else
|
||||
else {
|
||||
assert(From == NewBB && "From does not match any operand");
|
||||
NewBB = cast<BasicBlock>(To);
|
||||
}
|
||||
|
||||
// See if the 'new' entry already exists, if not, just update this in place
|
||||
// and return early.
|
||||
|
@ -2787,14 +2789,14 @@ Constant *ConstantDataVector::getSplatValue() const {
|
|||
/// work, but would be really slow because it would have to unique each updated
|
||||
/// array instance.
|
||||
///
|
||||
void Constant::handleOperandChange(Value *From, Value *To, Use *U) {
|
||||
void Constant::handleOperandChange(Value *From, Value *To) {
|
||||
Value *Replacement = nullptr;
|
||||
switch (getValueID()) {
|
||||
default:
|
||||
llvm_unreachable("Not a constant!");
|
||||
#define HANDLE_CONSTANT(Name) \
|
||||
case Value::Name##Val: \
|
||||
Replacement = cast<Name>(this)->handleOperandChangeImpl(From, To, U); \
|
||||
Replacement = cast<Name>(this)->handleOperandChangeImpl(From, To); \
|
||||
break;
|
||||
#include "llvm/IR/Value.def"
|
||||
}
|
||||
|
@ -2814,39 +2816,35 @@ void Constant::handleOperandChange(Value *From, Value *To, Use *U) {
|
|||
destroyConstant();
|
||||
}
|
||||
|
||||
Value *ConstantInt::handleOperandChangeImpl(Value *From, Value *To, Use *U) {
|
||||
Value *ConstantInt::handleOperandChangeImpl(Value *From, Value *To) {
|
||||
llvm_unreachable("Unsupported class for handleOperandChange()!");
|
||||
}
|
||||
|
||||
Value *ConstantFP::handleOperandChangeImpl(Value *From, Value *To, Use *U) {
|
||||
Value *ConstantFP::handleOperandChangeImpl(Value *From, Value *To) {
|
||||
llvm_unreachable("Unsupported class for handleOperandChange()!");
|
||||
}
|
||||
|
||||
Value *ConstantTokenNone::handleOperandChangeImpl(Value *From, Value *To,
|
||||
Use *U) {
|
||||
Value *ConstantTokenNone::handleOperandChangeImpl(Value *From, Value *To) {
|
||||
llvm_unreachable("Unsupported class for handleOperandChange()!");
|
||||
}
|
||||
|
||||
Value *UndefValue::handleOperandChangeImpl(Value *From, Value *To, Use *U) {
|
||||
Value *UndefValue::handleOperandChangeImpl(Value *From, Value *To) {
|
||||
llvm_unreachable("Unsupported class for handleOperandChange()!");
|
||||
}
|
||||
|
||||
Value *ConstantPointerNull::handleOperandChangeImpl(Value *From, Value *To,
|
||||
Use *U) {
|
||||
Value *ConstantPointerNull::handleOperandChangeImpl(Value *From, Value *To) {
|
||||
llvm_unreachable("Unsupported class for handleOperandChange()!");
|
||||
}
|
||||
|
||||
Value *ConstantAggregateZero::handleOperandChangeImpl(Value *From, Value *To,
|
||||
Use *U) {
|
||||
Value *ConstantAggregateZero::handleOperandChangeImpl(Value *From, Value *To) {
|
||||
llvm_unreachable("Unsupported class for handleOperandChange()!");
|
||||
}
|
||||
|
||||
Value *ConstantDataSequential::handleOperandChangeImpl(Value *From, Value *To,
|
||||
Use *U) {
|
||||
Value *ConstantDataSequential::handleOperandChangeImpl(Value *From, Value *To) {
|
||||
llvm_unreachable("Unsupported class for handleOperandChange()!");
|
||||
}
|
||||
|
||||
Value *ConstantArray::handleOperandChangeImpl(Value *From, Value *To, Use *U) {
|
||||
Value *ConstantArray::handleOperandChangeImpl(Value *From, Value *To) {
|
||||
assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
|
||||
Constant *ToC = cast<Constant>(To);
|
||||
|
||||
|
@ -2860,9 +2858,11 @@ Value *ConstantArray::handleOperandChangeImpl(Value *From, Value *To, Use *U) {
|
|||
// Keep track of whether all the values in the array are "ToC".
|
||||
bool AllSame = true;
|
||||
Use *OperandList = getOperandList();
|
||||
unsigned OperandNo = 0;
|
||||
for (Use *O = OperandList, *E = OperandList+getNumOperands(); O != E; ++O) {
|
||||
Constant *Val = cast<Constant>(O->get());
|
||||
if (Val == From) {
|
||||
OperandNo = (O - OperandList);
|
||||
Val = ToC;
|
||||
++NumUpdated;
|
||||
}
|
||||
|
@ -2882,65 +2882,57 @@ Value *ConstantArray::handleOperandChangeImpl(Value *From, Value *To, Use *U) {
|
|||
|
||||
// Update to the new value.
|
||||
return getContext().pImpl->ArrayConstants.replaceOperandsInPlace(
|
||||
Values, this, From, ToC, NumUpdated, U - OperandList);
|
||||
Values, this, From, ToC, NumUpdated, OperandNo);
|
||||
}
|
||||
|
||||
Value *ConstantStruct::handleOperandChangeImpl(Value *From, Value *To, Use *U) {
|
||||
Value *ConstantStruct::handleOperandChangeImpl(Value *From, Value *To) {
|
||||
assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
|
||||
Constant *ToC = cast<Constant>(To);
|
||||
|
||||
Use *OperandList = getOperandList();
|
||||
unsigned OperandToUpdate = U-OperandList;
|
||||
assert(getOperand(OperandToUpdate) == From && "ReplaceAllUsesWith broken!");
|
||||
|
||||
SmallVector<Constant*, 8> Values;
|
||||
Values.reserve(getNumOperands()); // Build replacement struct.
|
||||
|
||||
// Fill values with the modified operands of the constant struct. Also,
|
||||
// compute whether this turns into an all-zeros struct.
|
||||
bool isAllZeros = false;
|
||||
bool isAllUndef = false;
|
||||
if (ToC->isNullValue()) {
|
||||
isAllZeros = true;
|
||||
for (Use *O = OperandList, *E = OperandList+getNumOperands(); O != E; ++O) {
|
||||
Constant *Val = cast<Constant>(O->get());
|
||||
Values.push_back(Val);
|
||||
if (isAllZeros) isAllZeros = Val->isNullValue();
|
||||
unsigned NumUpdated = 0;
|
||||
bool AllSame = true;
|
||||
unsigned OperandNo = 0;
|
||||
for (Use *O = OperandList, *E = OperandList + getNumOperands(); O != E; ++O) {
|
||||
Constant *Val = cast<Constant>(O->get());
|
||||
if (Val == From) {
|
||||
OperandNo = (O - OperandList);
|
||||
Val = ToC;
|
||||
++NumUpdated;
|
||||
}
|
||||
} else if (isa<UndefValue>(ToC)) {
|
||||
isAllUndef = true;
|
||||
for (Use *O = OperandList, *E = OperandList+getNumOperands(); O != E; ++O) {
|
||||
Constant *Val = cast<Constant>(O->get());
|
||||
Values.push_back(Val);
|
||||
if (isAllUndef) isAllUndef = isa<UndefValue>(Val);
|
||||
}
|
||||
} else {
|
||||
for (Use *O = OperandList, *E = OperandList + getNumOperands(); O != E; ++O)
|
||||
Values.push_back(cast<Constant>(O->get()));
|
||||
Values.push_back(Val);
|
||||
AllSame &= Val == ToC;
|
||||
}
|
||||
Values[OperandToUpdate] = ToC;
|
||||
|
||||
if (isAllZeros)
|
||||
if (AllSame && ToC->isNullValue())
|
||||
return ConstantAggregateZero::get(getType());
|
||||
|
||||
if (isAllUndef)
|
||||
if (AllSame && isa<UndefValue>(ToC))
|
||||
return UndefValue::get(getType());
|
||||
|
||||
// Update to the new value.
|
||||
return getContext().pImpl->StructConstants.replaceOperandsInPlace(
|
||||
Values, this, From, ToC);
|
||||
Values, this, From, ToC, NumUpdated, OperandNo);
|
||||
}
|
||||
|
||||
Value *ConstantVector::handleOperandChangeImpl(Value *From, Value *To, Use *U) {
|
||||
Value *ConstantVector::handleOperandChangeImpl(Value *From, Value *To) {
|
||||
assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
|
||||
Constant *ToC = cast<Constant>(To);
|
||||
|
||||
SmallVector<Constant*, 8> Values;
|
||||
Values.reserve(getNumOperands()); // Build replacement array...
|
||||
unsigned NumUpdated = 0;
|
||||
unsigned OperandNo = 0;
|
||||
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
|
||||
Constant *Val = getOperand(i);
|
||||
if (Val == From) {
|
||||
OperandNo = i;
|
||||
++NumUpdated;
|
||||
Val = ToC;
|
||||
}
|
||||
|
@ -2951,20 +2943,21 @@ Value *ConstantVector::handleOperandChangeImpl(Value *From, Value *To, Use *U) {
|
|||
return C;
|
||||
|
||||
// Update to the new value.
|
||||
Use *OperandList = getOperandList();
|
||||
return getContext().pImpl->VectorConstants.replaceOperandsInPlace(
|
||||
Values, this, From, ToC, NumUpdated, U - OperandList);
|
||||
Values, this, From, ToC, NumUpdated, OperandNo);
|
||||
}
|
||||
|
||||
Value *ConstantExpr::handleOperandChangeImpl(Value *From, Value *ToV, Use *U) {
|
||||
Value *ConstantExpr::handleOperandChangeImpl(Value *From, Value *ToV) {
|
||||
assert(isa<Constant>(ToV) && "Cannot make Constant refer to non-constant!");
|
||||
Constant *To = cast<Constant>(ToV);
|
||||
|
||||
SmallVector<Constant*, 8> NewOps;
|
||||
unsigned NumUpdated = 0;
|
||||
unsigned OperandNo = 0;
|
||||
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
|
||||
Constant *Op = getOperand(i);
|
||||
if (Op == From) {
|
||||
OperandNo = i;
|
||||
++NumUpdated;
|
||||
Op = To;
|
||||
}
|
||||
|
@ -2976,9 +2969,8 @@ Value *ConstantExpr::handleOperandChangeImpl(Value *From, Value *ToV, Use *U) {
|
|||
return C;
|
||||
|
||||
// Update to the new value.
|
||||
Use *OperandList = getOperandList();
|
||||
return getContext().pImpl->ExprConstants.replaceOperandsInPlace(
|
||||
NewOps, this, From, To, NumUpdated, U - OperandList);
|
||||
NewOps, this, From, To, NumUpdated, OperandNo);
|
||||
}
|
||||
|
||||
Instruction *ConstantExpr::getAsInstruction() {
|
||||
|
|
|
@ -43,7 +43,7 @@ void GlobalValue::destroyConstantImpl() {
|
|||
llvm_unreachable("You can't GV->destroyConstantImpl()!");
|
||||
}
|
||||
|
||||
Value *GlobalValue::handleOperandChangeImpl(Value *From, Value *To, Use *U) {
|
||||
Value *GlobalValue::handleOperandChangeImpl(Value *From, Value *To) {
|
||||
llvm_unreachable("Unsupported class for handleOperandChange()!");
|
||||
}
|
||||
|
||||
|
|
|
@ -380,7 +380,7 @@ void Value::replaceAllUsesWith(Value *New) {
|
|||
// constant because they are uniqued.
|
||||
if (auto *C = dyn_cast<Constant>(U.getUser())) {
|
||||
if (!isa<GlobalValue>(C)) {
|
||||
C->handleOperandChange(this, New, &U);
|
||||
C->handleOperandChange(this, New);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue