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

Jonas Rickert llvmlistbot at llvm.org
Mon Jul 27 02:38:54 PDT 2026


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

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



>From 3e7af957fc7557530439ca495bd9a89325b5648d Mon Sep 17 00:00:00 2001
From: Jonas Rickert <jonas.rickert at amd.com>
Date: Mon, 27 Jul 2026 03:26:24 -0600
Subject: [PATCH] [mlir][PDL] Use free-function cast for derived PDL values

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

Signed-off-by: Jonas Rickert <jonas.rickert at amd.com>
---
 mlir/include/mlir/IR/PDLPatternMatch.h.inc |  2 +-
 mlir/unittests/IR/PatternMatchTest.cpp     | 13 ++++++++++---
 2 files changed, 11 insertions(+), 4 deletions(-)

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



More information about the Mlir-commits mailing list