[Mlir-commits] [mlir] 012d973 - [mlir][PDL] PDLToPDLInterp: Use the pdl pattern name in the generated rewriter. (#149481)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Jan 31 03:24:16 PST 2026
Author: jumerckx
Date: 2026-01-31T03:24:11-08:00
New Revision: 012d97311667b1d1aad370a4574c591c0488ab28
URL: https://github.com/llvm/llvm-project/commit/012d97311667b1d1aad370a4574c591c0488ab28
DIFF: https://github.com/llvm/llvm-project/commit/012d97311667b1d1aad370a4574c591c0488ab28.diff
LOG: [mlir][PDL] PDLToPDLInterp: Use the pdl pattern name in the generated rewriter. (#149481)
Before, the rewriters generated by `convert-pdl-to-pdl-interp` had a
generic `"pdl_generated_rewriter"` name. With this change, the name from
the original pdl pattern is kept for the rewriter. This makes it easier
to relate the two.
---------
Co-authored-by: Mehdi Amini <joker-eph at gmail.com>
Added:
Modified:
mlir/lib/Conversion/PDLToPDLInterp/PDLToPDLInterp.cpp
mlir/test/Conversion/PDLToPDLInterp/pdl-to-pdl-interp-rewriter.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/PDLToPDLInterp/PDLToPDLInterp.cpp b/mlir/lib/Conversion/PDLToPDLInterp/PDLToPDLInterp.cpp
index a4c66e125f6bf..5efe604bf47f4 100644
--- a/mlir/lib/Conversion/PDLToPDLInterp/PDLToPDLInterp.cpp
+++ b/mlir/lib/Conversion/PDLToPDLInterp/PDLToPDLInterp.cpp
@@ -639,9 +639,12 @@ void PatternLowering::generate(SuccessNode *successNode, Block *¤tBlock) {
SymbolRefAttr PatternLowering::generateRewriter(
pdl::PatternOp pattern, SmallVectorImpl<Position *> &usedMatchValues) {
builder.setInsertionPointToEnd(rewriterModule.getBody());
+ // Get the pattern name if available, otherwise use default
+ StringRef rewriterName = "pdl_generated_rewriter";
+ if (auto symName = pattern.getSymName())
+ rewriterName = symName.value();
auto rewriterFunc = pdl_interp::FuncOp::create(
- builder, pattern.getLoc(), "pdl_generated_rewriter",
- builder.getFunctionType({}, {}));
+ builder, pattern.getLoc(), rewriterName, builder.getFunctionType({}, {}));
rewriterSymbolTable.insert(rewriterFunc);
// Generate the rewriter function body.
diff --git a/mlir/test/Conversion/PDLToPDLInterp/pdl-to-pdl-interp-rewriter.mlir b/mlir/test/Conversion/PDLToPDLInterp/pdl-to-pdl-interp-rewriter.mlir
index e5a84d69dcad9..cf0cefd3280a8 100644
--- a/mlir/test/Conversion/PDLToPDLInterp/pdl-to-pdl-interp-rewriter.mlir
+++ b/mlir/test/Conversion/PDLToPDLInterp/pdl-to-pdl-interp-rewriter.mlir
@@ -260,3 +260,30 @@ module @range_op {
}
}
}
+
+// -----
+
+// CHECK-LABEL: module @named_pattern
+module @named_pattern {
+ // CHECK: pdl_interp.func @matcher(%[[ARG0:.*]]: !pdl.operation) {
+ // CHECK: pdl_interp.check_operation_name of %[[ARG0]] is "foo.op" -> ^bb2, ^bb1
+ // CHECK: ^bb1:
+ // CHECK: pdl_interp.finalize
+ // CHECK: ^bb2:
+ // CHECK: pdl_interp.check_operand_count of %[[ARG0]] is 0 -> ^bb3, ^bb1
+ // CHECK: ^bb3:
+ // CHECK: pdl_interp.check_result_count of %[[ARG0]] is 0 -> ^bb4, ^bb1
+ // CHECK: ^bb4:
+ // CHECK: pdl_interp.record_match @rewriters::@my_pattern(%[[ARG0]] : !pdl.operation) : benefit(1), loc([%[[ARG0]]]), root("foo.op") -> ^bb1
+ // CHECK: }
+ // CHECK: module @rewriters {
+ // CHECK: pdl_interp.func @my_pattern(%[[ARG0:.*]]: !pdl.operation) {
+ // CHECK: pdl_interp.apply_rewrite "rewriter"(%[[ARG0]] : !pdl.operation)
+ // CHECK: pdl_interp.finalize
+ // CHECK: }
+ // CHECK: }
+ pdl.pattern @my_pattern : benefit(1) {
+ %root = operation "foo.op"
+ rewrite %root with "rewriter"
+ }
+}
More information about the Mlir-commits
mailing list