[Mlir-commits] [mlir] [MLIR][Python] Expose the insertion point of pattern rewriter (PR #161001)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Oct 3 20:56:25 PDT 2025
================
@@ -26,6 +26,31 @@ using namespace mlir::python;
namespace {
+class PyPatternRewriter {
+public:
+ PyPatternRewriter(MlirPatternRewriter rewriter)
+ : rewriter(rewriter), base(mlirPatternRewriterAsBase(rewriter)),
+ ctx(PyMlirContext::forContext(mlirRewriterBaseGetContext(base))) {}
+
+ PyInsertionPoint getInsertionPoint() const {
+ MlirBlock block = mlirRewriterBaseGetInsertionBlock(base);
+ MlirOperation op = mlirRewriterBaseGetOperationAfterInsertion(base);
+
+ if (mlirOperationIsNull(op)) {
+ MlirOperation owner = mlirBlockGetParentOperation(block);
+ auto parent = PyOperation::forOperation(ctx, owner);
+ return PyInsertionPoint(PyBlock(parent, block));
+ }
+
+ return PyInsertionPoint(PyOperation::forOperation(ctx, op));
+ }
+
+private:
+ MlirPatternRewriter rewriter [[maybe_unused]];
----------------
PragmaTwice wrote:
Done in https://github.com/llvm/llvm-project/pull/161001/commits/8694c3405acfbcb5cd2ffa3fd9c3eecb98cfb572
https://github.com/llvm/llvm-project/pull/161001
More information about the Mlir-commits
mailing list