[Mlir-commits] [mlir] 6ff74f9 - [mlir][python] Update `PyOpResult.owner` to get the parent object.

Mike Urbach llvmlistbot at llvm.org
Wed Apr 28 13:40:06 PDT 2021


Author: Mike Urbach
Date: 2021-04-28T14:39:59-06:00
New Revision: 6ff74f96fd9ecdd903f66613c2e1422cb686b58e

URL: https://github.com/llvm/llvm-project/commit/6ff74f96fd9ecdd903f66613c2e1422cb686b58e
DIFF: https://github.com/llvm/llvm-project/commit/6ff74f96fd9ecdd903f66613c2e1422cb686b58e.diff

LOG: [mlir][python] Update `PyOpResult.owner` to get the parent object.

Previously, this API would return the PyObjectRef, rather than the
underlying PyOperation.

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D101416

Added: 
    

Modified: 
    mlir/lib/Bindings/Python/IRCore.cpp
    mlir/test/Bindings/Python/ir_value.py

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp
index 0945753f9fc9..781e9aed66e9 100644
--- a/mlir/lib/Bindings/Python/IRCore.cpp
+++ b/mlir/lib/Bindings/Python/IRCore.cpp
@@ -1566,7 +1566,7 @@ class PyOpResult : public PyConcreteValue<PyOpResult> {
           mlirOperationEqual(self.getParentOperation()->get(),
                              mlirOpResultGetOwner(self.get())) &&
           "expected the owner of the value in Python to match that in the IR");
-      return self.getParentOperation();
+      return self.getParentOperation().getObject();
     });
     c.def_property_readonly("result_number", [](PyOpResult &self) {
       return mlirOpResultGetResultNumber(self.get());

diff  --git a/mlir/test/Bindings/Python/ir_value.py b/mlir/test/Bindings/Python/ir_value.py
index 3b88fee375a0..1db9f33a65cd 100644
--- a/mlir/test/Bindings/Python/ir_value.py
+++ b/mlir/test/Bindings/Python/ir_value.py
@@ -25,3 +25,16 @@ def testCapsuleConversions():
 
 
 run(testCapsuleConversions)
+
+
+# CHECK-LABEL: TEST: testOpResultOwner
+def testOpResultOwner():
+  ctx = Context()
+  ctx.allow_unregistered_dialects = True
+  with Location.unknown(ctx):
+    i32 = IntegerType.get_signless(32)
+    op = Operation.create("custom.op1", results=[i32])
+    assert op.result.owner == op
+
+
+run(testOpResultOwner)


        


More information about the Mlir-commits mailing list