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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Aug 31 08:28:44 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Om Gupta (omgupta-iitk)

<details>
<summary>Changes</summary>

`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

---
Full diff: https://github.com/llvm/llvm-project/pull/220006.diff


2 Files Affected:

- (modified) mlir/include/mlir/IR/PDLPatternMatch.h.inc (+1-3) 
- (modified) mlir/unittests/IR/PatternMatchTest.cpp (+28) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/220006


More information about the Mlir-commits mailing list