[Mlir-commits] [mlir] [MLIR][Python] Call `notifyOperationInserted` while constructing new op in rewrite patterns (PR #163694)
Maksim Levental
llvmlistbot at llvm.org
Thu Oct 16 19:17:24 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());
+ });
----------------
makslevental wrote:
I guess the "core" way to do this is [ForwardingListener](https://github.com/llvm/llvm-project/blob/c88f3c582dc2ef5f2fdfd0c5887f5f7562f49095/mlir/include/mlir/IR/PatternMatch.h#L431) ie the listener "chains" have to actually be constructed at instantiation of the leaf listener (which then forwards up the chain or something like that).
> this can be a little hard since listener is like a field of PatternRewriter
can't you play the same trick we play everywhere already: just put it into `*userData`?
https://github.com/llvm/llvm-project/pull/163694
More information about the Mlir-commits
mailing list