api: supporting replaceUsesWithIf
Closed this issue · 0 comments
jianyicheng commented
Now we only have replace_by
in the core, and in some cases we only want to replace part of the uses with a new value. This is implemented as replaceUsesWithIf
in MLIR: https://mlir.llvm.org/doxygen/classmlir_1_1Operation.html#a6f5567fd62feeaf0cbba4877732c512a
Given the current implementation of replace_by
:
Lines 157 to 164 in cd2d585
I wonder if it would be useful to add the following function:
def replace_by_except(self, value: SSAValue, exception: [SSAValue]) -> None:
"""Replace the value by another value in its uses except the given exception."""
for use in self.uses.copy():
if use not in exception:
use.operation.operands[use.index] = value
assert len(self.uses) <= len(exception), "unexpected error in xdsl"