[Mlir-commits] [mlir] [MLIR][Python] Call `notifyOperationInserted` while constructing new op in rewrite patterns (PR #163694)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Oct 16 20:09:32 PDT 2025


================
@@ -202,7 +207,15 @@ class PyRewritePatternSet {
           PyMlirContext::forContext(mlirOperationGetContext(op));
       nb::object opView = PyOperation::forOperation(ctx, op)->createOpView();
 
-      nb::object res = f(opView, PyPatternRewriter(rewriter));
+      PyPatternRewriter pyRewriter(rewriter);
+      nb::object listener = nb::cast(pyRewriter.getListener());
+
+      listener.attr("__enter__")();
+      auto exit = llvm::make_scope_exit([listener] {
+        listener.attr("__exit__")(nb::none(), nb::none(), nb::none());
+      });
----------------
PragmaTwice wrote:

Thank you for your patch! I understand the code, but since we can already get the listener via
`nb::object listener = nb::cast(pyRewriter.getListener())`
without passing additional user data, is there any difference?

https://github.com/llvm/llvm-project/pull/163694


More information about the Mlir-commits mailing list