Skip to content

Commit e97696f

Browse files
committed
Leverage PybindAdaptors and fix test
1 parent 825d9f6 commit e97696f

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

mlir/lib/Bindings/Python/IRCore.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3726,30 +3726,22 @@ void mlir::python::populateIRCore(py::module &m) {
37263726
kValueReplaceAllUsesWithDocstring)
37273727
.def(
37283728
"replace_all_uses_except",
3729-
[](PyValue &self, PyValue &with, PyOperation &exception) {
3730-
MlirValue selfValue = self.get();
3731-
MlirValue withValue = with.get();
3732-
MlirOperation exceptedUser = exception.get();
3733-
3734-
mlirValueReplaceAllUsesExceptWithSingle(selfValue, withValue,
3735-
exceptedUser);
3729+
[](MlirValue self, MlirValue with, MlirOperation exception) {
3730+
mlirValueReplaceAllUsesExceptWithSingle(self, with, exception);
37363731
},
37373732
py::arg("with"), py::arg("exceptions"),
37383733
kValueReplaceAllUsesExceptDocstring)
37393734
.def(
37403735
"replace_all_uses_except",
3741-
[](PyValue &self, PyValue &with, py::list exceptions) {
3742-
MlirValue selfValue = self.get();
3743-
MlirValue withValue = with.get();
3744-
3736+
[](MlirValue self, MlirValue with, py::list exceptions) {
37453737
// Convert Python list to a SmallVector of MlirOperations
37463738
llvm::SmallVector<MlirOperation, 4> exceptionOps;
37473739
for (py::handle exception : exceptions) {
37483740
exceptionOps.push_back(exception.cast<PyOperation &>().get());
37493741
}
37503742

37513743
mlirValueReplaceAllUsesExceptWithSet(
3752-
selfValue, withValue, exceptionOps.data(),
3744+
self, with, exceptionOps.data(),
37533745
static_cast<intptr_t>(exceptionOps.size()));
37543746
},
37553747
py::arg("with"), py::arg("exceptions"),

mlir/test/python/ir/value.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def testValueReplaceAllUsesWithExcept():
161161
op1 = Operation.create("custom.op1", operands=[value])
162162
op2 = Operation.create("custom.op2", operands=[value])
163163
value2 = Operation.create("custom.op3", results=[i32]).results[0]
164-
value.replace_all_uses_except(value2, [op1])
164+
value.replace_all_uses_except(value2, op1)
165165

166166
assert len(list(value.uses)) == 1
167167

0 commit comments

Comments
 (0)