[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:42:37 PDT 2026
https://github.com/jorickert updated https://github.com/llvm/llvm-project/pull/212212
>From 5287e5b6b42a9ec42880bd18389b26c896e2474f 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 | 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
More information about the Mlir-commits
mailing list