[Mlir-commits] [mlir] [mlir][PDL] Set debug name on PDL patterns (PR #182661)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Apr 22 02:36:25 PDT 2026
https://github.com/SamNour updated https://github.com/llvm/llvm-project/pull/182661
>From 8cbb39b9bfb7bc4882e88ee362a48aea00ed74da Mon Sep 17 00:00:00 2001
From: Samnour2 <samnour2 at amd.com>
Date: Sat, 21 Feb 2026 02:24:07 -0700
Subject: [PATCH 1/2] [mlir][PDL] Set debug name on PDL patterns
PDLByteCodePattern did not have its debug name set, making PDL
patterns anonymous in debug logs.
---
mlir/lib/Rewrite/ByteCode.cpp | 18 +++++++++-----
mlir/test/Rewrite/pdl-bytecode-debug.mlir | 30 +++++++++++++++++++++++
2 files changed, 42 insertions(+), 6 deletions(-)
create mode 100644 mlir/test/Rewrite/pdl-bytecode-debug.mlir
diff --git a/mlir/lib/Rewrite/ByteCode.cpp b/mlir/lib/Rewrite/ByteCode.cpp
index cf00216288115..1f5795a74d298 100644
--- a/mlir/lib/Rewrite/ByteCode.cpp
+++ b/mlir/lib/Rewrite/ByteCode.cpp
@@ -42,18 +42,24 @@ PDLByteCodePattern PDLByteCodePattern::create(pdl_interp::RecordMatchOp matchOp,
PatternBenefit benefit = matchOp.getBenefit();
MLIRContext *ctx = matchOp.getContext();
+ StringRef debugName = matchOp.getRewriter().getLeafReference().getValue();
// Collect the set of generated operations.
SmallVector<StringRef, 8> generatedOps;
if (ArrayAttr generatedOpsAttr = matchOp.getGeneratedOpsAttr())
generatedOps =
llvm::to_vector<8>(generatedOpsAttr.getAsValueRange<StringAttr>());
- // Check to see if this is pattern matches a specific operation type.
- if (std::optional<StringRef> rootKind = matchOp.getRootKind())
- return PDLByteCodePattern(rewriterAddr, configSet, *rootKind, benefit, ctx,
- generatedOps);
- return PDLByteCodePattern(rewriterAddr, configSet, MatchAnyOpTypeTag(),
- benefit, ctx, generatedOps);
+ // Check to see if this pattern matches a specific operation type.
+ std::optional<StringRef> rootKind = matchOp.getRootKind();
+ PDLByteCodePattern pattern =
+ rootKind
+ ? PDLByteCodePattern(rewriterAddr, configSet, *rootKind, benefit, ctx,
+ generatedOps)
+ : PDLByteCodePattern(rewriterAddr, configSet, MatchAnyOpTypeTag(),
+ benefit, ctx, generatedOps);
+
+ pattern.setDebugName(debugName);
+ return pattern;
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Rewrite/pdl-bytecode-debug.mlir b/mlir/test/Rewrite/pdl-bytecode-debug.mlir
new file mode 100644
index 0000000000000..6b49773bcd060
--- /dev/null
+++ b/mlir/test/Rewrite/pdl-bytecode-debug.mlir
@@ -0,0 +1,30 @@
+// RUN: mlir-opt %s -test-pdl-bytecode-pass -split-input-file --debug 2>&1 | FileCheck %s
+
+//===----------------------------------------------------------------------===//
+// Test that named PDL patterns have their debug name set.
+//===----------------------------------------------------------------------===//
+
+module @patterns {
+ pdl_interp.func @matcher(%root : !pdl.operation) {
+ pdl_interp.check_operation_name of %root is "test.op" -> ^pat, ^end
+
+ ^pat:
+ pdl_interp.record_match @rewriters::@named_pattern(%root : !pdl.operation) : benefit(1), loc([%root]), root("test.op") -> ^end
+
+ ^end:
+ pdl_interp.finalize
+ }
+
+ module @rewriters {
+ pdl_interp.func @named_pattern(%root : !pdl.operation) {
+ %op = pdl_interp.create_operation "test.replaced_by_pattern"
+ pdl_interp.erase %root
+ pdl_interp.finalize
+ }
+ }
+}
+
+// CHECK: Pattern named_pattern
+module @ir {
+ "test.op"() : () -> ()
+}
\ No newline at end of file
>From e3df274ceebf051e354e6d3419d5fe9eadac78c3 Mon Sep 17 00:00:00 2001
From: "Sam.Nour" <sam.nour at amd.com>
Date: Tue, 21 Apr 2026 09:23:47 +0200
Subject: [PATCH 2/2] Delete mlir/test/Rewrite/pdl-bytecode-debug.mlir
---
mlir/test/Rewrite/pdl-bytecode-debug.mlir | 30 -----------------------
1 file changed, 30 deletions(-)
delete mode 100644 mlir/test/Rewrite/pdl-bytecode-debug.mlir
diff --git a/mlir/test/Rewrite/pdl-bytecode-debug.mlir b/mlir/test/Rewrite/pdl-bytecode-debug.mlir
deleted file mode 100644
index 6b49773bcd060..0000000000000
--- a/mlir/test/Rewrite/pdl-bytecode-debug.mlir
+++ /dev/null
@@ -1,30 +0,0 @@
-// RUN: mlir-opt %s -test-pdl-bytecode-pass -split-input-file --debug 2>&1 | FileCheck %s
-
-//===----------------------------------------------------------------------===//
-// Test that named PDL patterns have their debug name set.
-//===----------------------------------------------------------------------===//
-
-module @patterns {
- pdl_interp.func @matcher(%root : !pdl.operation) {
- pdl_interp.check_operation_name of %root is "test.op" -> ^pat, ^end
-
- ^pat:
- pdl_interp.record_match @rewriters::@named_pattern(%root : !pdl.operation) : benefit(1), loc([%root]), root("test.op") -> ^end
-
- ^end:
- pdl_interp.finalize
- }
-
- module @rewriters {
- pdl_interp.func @named_pattern(%root : !pdl.operation) {
- %op = pdl_interp.create_operation "test.replaced_by_pattern"
- pdl_interp.erase %root
- pdl_interp.finalize
- }
- }
-}
-
-// CHECK: Pattern named_pattern
-module @ir {
- "test.op"() : () -> ()
-}
\ No newline at end of file
More information about the Mlir-commits
mailing list