[Mlir-commits] [mlir] c05ce9b - [MLIR][Python] fix getOwner to return (typed) nb::object instead of abstract PyOpView (#165053)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Oct 25 18:48:50 PDT 2025


Author: Maksim Levental
Date: 2025-10-26T01:48:46Z
New Revision: c05ce9b0057c9b1413bee964bb2d400ffbddede5

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

LOG: [MLIR][Python] fix getOwner to return (typed) nb::object instead of abstract PyOpView (#165053)

https://github.com/llvm/llvm-project/pull/157930 changed `nb::object
getOwner()` to `PyOpView getOwner()` which implicitly constructs the
generic OpView against from a (possibly) concrete OpView. This PR fixes
that.

Added: 
    

Modified: 
    mlir/lib/Bindings/Python/IRCore.cpp
    mlir/test/python/ir/operation.py

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp
index 06d0256e6287b..cda4fe19c16f8 100644
--- a/mlir/lib/Bindings/Python/IRCore.cpp
+++ b/mlir/lib/Bindings/Python/IRCore.cpp
@@ -598,7 +598,7 @@ class PyOpOperand {
 public:
   PyOpOperand(MlirOpOperand opOperand) : opOperand(opOperand) {}
 
-  PyOpView getOwner() {
+  nb::typed<nb::object, PyOpView> getOwner() {
     MlirOperation owner = mlirOpOperandGetOwner(opOperand);
     PyMlirContextRef context =
         PyMlirContext::forContext(mlirOperationGetContext(owner));

diff  --git a/mlir/test/python/ir/operation.py b/mlir/test/python/ir/operation.py
index 1d4ede1ee336a..f5fa4dad856f8 100644
--- a/mlir/test/python/ir/operation.py
+++ b/mlir/test/python/ir/operation.py
@@ -1187,3 +1187,15 @@ def callback(op):
         module.operation.walk(callback)
     except RuntimeError:
         print("Exception raised")
+
+
+# CHECK-LABEL: TEST: testGetOwnerConcreteOpview
+ at run
+def testGetOwnerConcreteOpview():
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = arith.ConstantOp(value=42, result=IntegerType.get_signless(32))
+            r = arith.AddIOp(a, a, overflowFlags=arith.IntegerOverflowFlags.nsw)
+            for u in a.result.uses:
+                assert isinstance(u.owner, arith.AddIOp)


        


More information about the Mlir-commits mailing list