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

Jonas Rickert llvmlistbot at llvm.org
Mon Jul 27 05:22:21 PDT 2026


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

>From adbbcde736fac3468962dcbbe36c3ee099d084bf 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 1/2] [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)`.
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 |  4 +---
 mlir/unittests/IR/PatternMatchTest.cpp     | 13 ++++++++++---
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/mlir/include/mlir/IR/PDLPatternMatch.h.inc b/mlir/include/mlir/IR/PDLPatternMatch.h.inc
index aa74202178a9b..33cb1e4f75425 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 mlir::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..a7d26b2f47d2c 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

>From f225255dd1343ddfe48cbdd23f28421d773542d2 Mon Sep 17 00:00:00 2001
From: Jonas Rickert <jonas.rickert at amd.com>
Date: Mon, 27 Jul 2026 06:20:16 -0600
Subject: [PATCH 2/2] Make depdency on type switch explicit

Signed-off-by: Jonas Rickert <jonas.rickert at amd.com>
---
 mlir/include/mlir/IR/PatternMatch.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mlir/include/mlir/IR/PatternMatch.h b/mlir/include/mlir/IR/PatternMatch.h
index 83477c79ff582..0189ad4881056 100644
--- a/mlir/include/mlir/IR/PatternMatch.h
+++ b/mlir/include/mlir/IR/PatternMatch.h
@@ -12,6 +12,7 @@
 #include "mlir/IR/Builders.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "llvm/ADT/FunctionExtras.h"
+#include "llvm/ADT/TypeSwitch.h"
 #include "llvm/Support/TypeName.h"
 #include <optional>
 



More information about the Mlir-commits mailing list