[Mlir-commits] [mlir] [mlir][PDL] Use free-function cast in ProcessDerivedPDLValue::process… (PR #220006)

Om Gupta llvmlistbot at llvm.org
Mon Aug 31 08:27:44 PDT 2026


https://github.com/omgupta-iitk created https://github.com/llvm/llvm-project/pull/220006

`ProcessDerivedPDLValue::processAsArg` still used the `cast` member
function that was removed from Attribute and Type in #135556. Because it
is a member of a class template it is only instantiated when a native PDL
constraint or rewrite function takes a derived attribute or type
parameter, which nothing in-tree does, so the removal did not surface it.
Downstream users hit a hard compile error.

Switch to the free-function form, matching the `Operation *`
specialization below which already does this. The `Operation *` path was
never affected because it overrides `processAsArg`; only derived
attributes and types were broken.

Add a unit test registering rewrite and constraint functions with
`StringAttr`, `IntegerType` and `TypeAttr` parameters

>From d8b68d13b9573073a462fb286a009b0f63bfc65c Mon Sep 17 00:00:00 2001
From: Om Gupta <omgupta23 at iitk.ac.in>
Date: Mon, 31 Aug 2026 20:49:37 +0530
Subject: [PATCH] [mlir][PDL] Use free-function cast in
 ProcessDerivedPDLValue::processAsArg

---
 mlir/include/mlir/IR/PDLPatternMatch.h.inc |  4 +---
 mlir/unittests/IR/PatternMatchTest.cpp     | 28 ++++++++++++++++++++++
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/mlir/include/mlir/IR/PDLPatternMatch.h.inc b/mlir/include/mlir/IR/PDLPatternMatch.h.inc
index a39a46382affd..b49ec3e4d2a1b 100644
--- a/mlir/include/mlir/IR/PDLPatternMatch.h.inc
+++ b/mlir/include/mlir/IR/PDLPatternMatch.h.inc
@@ -461,9 +461,7 @@ struct ProcessDerivedPDLValue : public ProcessPDLValueBasedOn<T, BaseT> {
   }
   using ProcessPDLValueBasedOn<T, BaseT>::verifyAsArg;
 
-  static T processAsArg(BaseT baseValue) {
-    return baseValue.template cast<T>();
-  }
+  static T processAsArg(BaseT baseValue) { return cast<T>(baseValue); }
   using ProcessPDLValueBasedOn<T, BaseT>::processAsArg;
 
   static void processAsResult(PatternRewriter &, PDLResultList &results,
diff --git a/mlir/unittests/IR/PatternMatchTest.cpp b/mlir/unittests/IR/PatternMatchTest.cpp
index 1c67bfc284d32..6d516d06cb421 100644
--- a/mlir/unittests/IR/PatternMatchTest.cpp
+++ b/mlir/unittests/IR/PatternMatchTest.cpp
@@ -53,3 +53,31 @@ TEST(AnOpRewritePatternTest, PatternFuncAttributes) {
             test::OpB::getOperationName());
 }
 } // end anonymous namespace
+
+#if MLIR_ENABLE_PDL_IN_PATTERNMATCH
+namespace {
+FailureOr<StringAttr> derivedValueRewriteFunc(PatternRewriter &rewriter,
+                                              Operation *op, StringAttr attr,
+                                              IntegerType type) {
+  return attr;
+}
+
+LogicalResult derivedValueConstraintFunc(PatternRewriter &rewriter,
+                                         Operation *op, TypeAttr attr) {
+  return success();
+}
+
+TEST(PDLPatternModuleTest, RegisterFunctionsWithDerivedValues) {
+  PDLPatternModule pdlPattern;
+
+  pdlPattern.registerRewriteFunction("rewriter", derivedValueRewriteFunc);
+  pdlPattern.registerConstraintFunction("constraint",
+                                        derivedValueConstraintFunc);
+
+  ASSERT_EQ(pdlPattern.getRewriteFunctions().size(), 1U);
+  ASSERT_TRUE(pdlPattern.getRewriteFunctions().contains("rewriter"));
+  ASSERT_EQ(pdlPattern.getConstraintFunctions().size(), 1U);
+  ASSERT_TRUE(pdlPattern.getConstraintFunctions().contains("constraint"));
+}
+} // end anonymous namespace
+#endif // MLIR_ENABLE_PDL_IN_PATTERNMATCH



More information about the Mlir-commits mailing list