Fix some corner cases missed by D71955

* replaceAllUsesWith may be supplied with a null value.
* some compilers fail to implicitly convert single result operations to
OpaqueValue, so add an explicit OpOperand::set(Value) method.
This commit is contained in:
River Riddle 2020-01-02 09:58:16 -08:00
parent bd402fc3f3
commit 97864f4f3a
2 changed files with 12 additions and 4 deletions

View File

@ -47,8 +47,8 @@ public:
/// the IR that uses 'this' to use the other value instead. When this returns
/// there are zero uses of 'this'.
void replaceAllUsesWith(typename OperandType::ValueType newValue) {
assert(this != OperandType::getUseList(newValue) &&
"cannot RAUW a value with itself");
assert(!newValue || this != OperandType::getUseList(newValue) &&
"cannot RAUW a value with itself");
while (!use_empty())
use_begin()->set(newValue);
}
@ -126,8 +126,8 @@ public:
void replaceAllUsesWith(ValueType oldValue, ValueType newValue) {
assert(this == OperandType::getUseList(oldValue) &&
"value not attached to this use list");
assert(this != OperandType::getUseList(newValue) &&
"cannot RAUW a value with itself");
assert(!newValue || this != OperandType::getUseList(newValue) &&
"cannot RAUW a value with itself");
for (OperandType &use : llvm::make_early_inc_range(getUses(oldValue)))
use.set(newValue);
}
@ -337,6 +337,9 @@ public:
/// Return the current value being used by this operand.
Value get() const;
/// Set the operand to the given value.
void set(Value value);
/// Return which operand this is in the operand list of the User.
unsigned getOperandNumber();
};

View File

@ -111,6 +111,11 @@ Value OpOperand::get() const {
return IROperand<OpOperand, detail::OpaqueValue>::get();
}
/// Set the operand to the given value.
void OpOperand::set(Value value) {
IROperand<OpOperand, detail::OpaqueValue>::set(value);
}
/// Return which operand this is in the operand list.
unsigned OpOperand::getOperandNumber() {
return this - &getOwner()->getOpOperands()[0];