From 1faa5e28f6b5dfce9aa64e3cf42645a05f4bfbf8 Mon Sep 17 00:00:00 2001 From: Maksim Levental Date: Fri, 24 Oct 2025 15:57:53 -0700 Subject: [PATCH 1/2] [MLIR][Python] fix getOwner --- mlir/lib/Bindings/Python/IRCore.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 getOwner() { MlirOperation owner = mlirOpOperandGetOwner(opOperand); PyMlirContextRef context = PyMlirContext::forContext(mlirOperationGetContext(owner)); From cac248c89e3ed88892c9c4ebc24e4f98eb89ca5d Mon Sep 17 00:00:00 2001 From: makslevental Date: Sat, 25 Oct 2025 10:49:06 -0700 Subject: [PATCH 2/2] add test --- mlir/test/python/ir/operation.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 +@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)