Skip to content

Commit 97864f4

Browse files
committed
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.
1 parent bd402fc commit 97864f4

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

mlir/include/mlir/IR/UseDefLists.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ template <typename OperandType> class IRObjectWithUseList {
4747
/// the IR that uses 'this' to use the other value instead. When this returns
4848
/// there are zero uses of 'this'.
4949
void replaceAllUsesWith(typename OperandType::ValueType newValue) {
50-
assert(this != OperandType::getUseList(newValue) &&
51-
"cannot RAUW a value with itself");
50+
assert(!newValue || this != OperandType::getUseList(newValue) &&
51+
"cannot RAUW a value with itself");
5252
while (!use_empty())
5353
use_begin()->set(newValue);
5454
}
@@ -126,8 +126,8 @@ class IRMultiObjectWithUseList : public IRObjectWithUseList<OperandType> {
126126
void replaceAllUsesWith(ValueType oldValue, ValueType newValue) {
127127
assert(this == OperandType::getUseList(oldValue) &&
128128
"value not attached to this use list");
129-
assert(this != OperandType::getUseList(newValue) &&
130-
"cannot RAUW a value with itself");
129+
assert(!newValue || this != OperandType::getUseList(newValue) &&
130+
"cannot RAUW a value with itself");
131131
for (OperandType &use : llvm::make_early_inc_range(getUses(oldValue)))
132132
use.set(newValue);
133133
}
@@ -337,6 +337,9 @@ class OpOperand : public IROperand<OpOperand, detail::OpaqueValue> {
337337
/// Return the current value being used by this operand.
338338
Value get() const;
339339

340+
/// Set the operand to the given value.
341+
void set(Value value);
342+
340343
/// Return which operand this is in the operand list of the User.
341344
unsigned getOperandNumber();
342345
};

mlir/lib/IR/Value.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ Value OpOperand::get() const {
111111
return IROperand<OpOperand, detail::OpaqueValue>::get();
112112
}
113113

114+
/// Set the operand to the given value.
115+
void OpOperand::set(Value value) {
116+
IROperand<OpOperand, detail::OpaqueValue>::set(value);
117+
}
118+
114119
/// Return which operand this is in the operand list.
115120
unsigned OpOperand::getOperandNumber() {
116121
return this - &getOwner()->getOpOperands()[0];

0 commit comments

Comments
 (0)