[Mlir-commits] [mlir] [mlir][PDL] Use free-function cast for derived PDL values (PR #212212)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Jul 27 02:39:31 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Jonas Rickert (jorickert)

<details>
<summary>Changes</summary>

Following "[mlir] Remove deprecated cast member functions (#<!-- -->135556) (0078cf79adc2f24a168bc774cba1f39dda5e3752)",`Type::cast` and `Attribute::cast` are no longer available.

Update ProcessDerivedPDLValue to use `mlir::cast<T>(baseValue)` when adapting PDL values for native rewrite functions with derived argument types. Add a regression test for a rewrite function taking `ShapedType` and `IntegerAttr`.



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


2 Files Affected:

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


``````````diff
diff --git a/mlir/include/mlir/IR/PDLPatternMatch.h.inc b/mlir/include/mlir/IR/PDLPatternMatch.h.inc
index aa74202178a9b..10b397bdb3598 100644
--- a/mlir/include/mlir/IR/PDLPatternMatch.h.inc
+++ b/mlir/include/mlir/IR/PDLPatternMatch.h.inc
@@ -462,7 +462,7 @@ struct ProcessDerivedPDLValue : public ProcessPDLValueBasedOn<T, BaseT> {
   using ProcessPDLValueBasedOn<T, BaseT>::verifyAsArg;
 
   static T processAsArg(BaseT baseValue) {
-    return baseValue.template cast<T>();
+    return mlir::cast<T>(baseValue);
   }
   using ProcessPDLValueBasedOn<T, BaseT>::processAsArg;
 
diff --git a/mlir/unittests/IR/PatternMatchTest.cpp b/mlir/unittests/IR/PatternMatchTest.cpp
index 1c67bfc284d32..453e4eb8af699 100644
--- a/mlir/unittests/IR/PatternMatchTest.cpp
+++ b/mlir/unittests/IR/PatternMatchTest.cpp
@@ -33,9 +33,6 @@ TEST(OpRewritePatternTest, GetGeneratedNames) {
   ASSERT_EQ(ops.size(), 1u);
   ASSERT_EQ(ops.front().getStringRef(), test::OpB::getOperationName());
 }
-} // end anonymous namespace
-
-namespace {
 LogicalResult anOpRewritePatternFunc(test::OpA op, PatternRewriter &rewriter) {
   return failure();
 }
@@ -52,4 +49,14 @@ TEST(AnOpRewritePatternTest, PatternFuncAttributes) {
   ASSERT_EQ(pattern->getGeneratedOps().front().getStringRef(),
             test::OpB::getOperationName());
 }
+
+ShapedType rewriteShapedType(PatternRewriter & /*rewriter*/, ShapedType type,
+                            IntegerAttr /*rank*/) {
+  return type;
+}
+
+TEST(PDLPatternModuleTest, RegisterDerivedRewriteFunction) {
+  PDLPatternModule patterns;
+  patterns.registerRewriteFunction("rewrite_shaped_type", rewriteShapedType);
+}
 } // end anonymous namespace

``````````

</details>


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


More information about the Mlir-commits mailing list