[Mlir-commits] [mlir] [mlir][IR] Delete `match` and `rewrite` functions (PR #130259)
Matthias Springer
llvmlistbot at llvm.org
Thu Mar 6 23:58:31 PST 2025
https://github.com/matthias-springer updated https://github.com/llvm/llvm-project/pull/130259
>From 127556b4de041479daf3eee47c081ffb621ddf1b Mon Sep 17 00:00:00 2001
From: Matthias Springer <mspringer at nvidia.com>
Date: Fri, 7 Mar 2025 08:53:44 +0100
Subject: [PATCH] [mlir][IR] Delete `match` and `rewrite` functions
---
.../mlir/Conversion/LLVMCommon/Pattern.h | 11 ---
mlir/include/mlir/IR/PatternMatch.h | 50 -------------
.../mlir/Transforms/DialectConversion.h | 74 -------------------
3 files changed, 135 deletions(-)
diff --git a/mlir/include/mlir/Conversion/LLVMCommon/Pattern.h b/mlir/include/mlir/Conversion/LLVMCommon/Pattern.h
index e78f174ff8586..c65f7d7217be5 100644
--- a/mlir/include/mlir/Conversion/LLVMCommon/Pattern.h
+++ b/mlir/include/mlir/Conversion/LLVMCommon/Pattern.h
@@ -40,11 +40,6 @@ LogicalResult oneToOneRewrite(
/// during the entire pattern lifetime.
class ConvertToLLVMPattern : public ConversionPattern {
public:
- /// `SplitMatchAndRewrite` is deprecated. Use `matchAndRewrite` instead of
- /// separate `match` and `rewrite`.
- using SplitMatchAndRewrite =
- detail::ConversionSplitMatchAndRewriteImpl<ConvertToLLVMPattern>;
-
ConvertToLLVMPattern(StringRef rootOpName, MLIRContext *context,
const LLVMTypeConverter &typeConverter,
PatternBenefit benefit = 1);
@@ -147,16 +142,10 @@ class ConvertToLLVMPattern : public ConversionPattern {
template <typename SourceOp>
class ConvertOpToLLVMPattern : public ConvertToLLVMPattern {
public:
- using OperationT = SourceOp;
using OpAdaptor = typename SourceOp::Adaptor;
using OneToNOpAdaptor =
typename SourceOp::template GenericAdaptor<ArrayRef<ValueRange>>;
- /// `SplitMatchAndRewrite` is deprecated. Use `matchAndRewrite` instead of
- /// separate `match` and `rewrite`.
- using SplitMatchAndRewrite = detail::ConversionSplitMatchAndRewriteImpl<
- ConvertOpToLLVMPattern<SourceOp>>;
-
explicit ConvertOpToLLVMPattern(const LLVMTypeConverter &typeConverter,
PatternBenefit benefit = 1)
: ConvertToLLVMPattern(SourceOp::getOperationName(),
diff --git a/mlir/include/mlir/IR/PatternMatch.h b/mlir/include/mlir/IR/PatternMatch.h
index d1f00c34f87b4..fc6ae8fb55fec 100644
--- a/mlir/include/mlir/IR/PatternMatch.h
+++ b/mlir/include/mlir/IR/PatternMatch.h
@@ -234,48 +234,9 @@ class Pattern {
// RewritePattern
//===----------------------------------------------------------------------===//
-namespace detail {
-/// Helper class that derives from a RewritePattern class and provides separate
-/// `match` and `rewrite` entry points instead of a combined `matchAndRewrite`.
-///
-/// This class is deprecated. Use `matchAndRewrite` instead of separate `match`
-/// and `rewrite`.
-template <typename PatternT>
-class SplitMatchAndRewriteImpl : public PatternT {
- using PatternT::PatternT;
-
- /// Attempt to match against IR rooted at the specified operation, which is
- /// the same operation kind as getRootKind().
- ///
- /// Note: This function must not modify the IR.
- virtual LogicalResult match(typename PatternT::OperationT op) const = 0;
-
- /// Rewrite the IR rooted at the specified operation with the result of
- /// this pattern, generating any new operations with the specified
- /// rewriter.
- virtual void rewrite(typename PatternT::OperationT op,
- PatternRewriter &rewriter) const = 0;
-
- LogicalResult matchAndRewrite(typename PatternT::OperationT op,
- PatternRewriter &rewriter) const final {
- if (succeeded(match(op))) {
- rewrite(op, rewriter);
- return success();
- }
- return failure();
- }
-};
-} // namespace detail
-
/// RewritePattern is the common base class for all DAG to DAG replacements.
class RewritePattern : public Pattern {
public:
- using OperationT = Operation *;
-
- /// `SplitMatchAndRewrite` is deprecated. Use `matchAndRewrite` instead of
- /// separate `match` and `rewrite`.
- using SplitMatchAndRewrite = detail::SplitMatchAndRewriteImpl<RewritePattern>;
-
virtual ~RewritePattern() = default;
/// Attempt to match against code rooted at the specified operation,
@@ -334,7 +295,6 @@ namespace detail {
/// class or Interface.
template <typename SourceOp>
struct OpOrInterfaceRewritePatternBase : public RewritePattern {
- using OperationT = SourceOp;
using RewritePattern::RewritePattern;
/// Wrapper around the RewritePattern method that passes the derived op type.
@@ -357,11 +317,6 @@ template <typename SourceOp>
struct OpRewritePattern
: public detail::OpOrInterfaceRewritePatternBase<SourceOp> {
- /// `SplitMatchAndRewrite` is deprecated. Use `matchAndRewrite` instead of
- /// separate `match` and `rewrite`.
- using SplitMatchAndRewrite =
- detail::SplitMatchAndRewriteImpl<OpRewritePattern<SourceOp>>;
-
/// Patterns must specify the root operation name they match against, and can
/// also specify the benefit of the pattern matching and a list of generated
/// ops.
@@ -378,11 +333,6 @@ template <typename SourceOp>
struct OpInterfaceRewritePattern
: public detail::OpOrInterfaceRewritePatternBase<SourceOp> {
- /// `SplitMatchAndRewrite` is deprecated. Use `matchAndRewrite` instead of
- /// separate `match` and `rewrite`.
- using SplitMatchAndRewrite =
- detail::SplitMatchAndRewriteImpl<OpInterfaceRewritePattern<SourceOp>>;
-
OpInterfaceRewritePattern(MLIRContext *context, PatternBenefit benefit = 1)
: detail::OpOrInterfaceRewritePatternBase<SourceOp>(
Pattern::MatchInterfaceOpTypeTag(), SourceOp::getInterfaceID(),
diff --git a/mlir/include/mlir/Transforms/DialectConversion.h b/mlir/include/mlir/Transforms/DialectConversion.h
index f54397e942ae0..879c9a486e694 100644
--- a/mlir/include/mlir/Transforms/DialectConversion.h
+++ b/mlir/include/mlir/Transforms/DialectConversion.h
@@ -528,82 +528,14 @@ class TypeConverter {
// Conversion Patterns
//===----------------------------------------------------------------------===//
-namespace detail {
-/// Helper class that derives from a ConversionRewritePattern class and
-/// provides separate `match` and `rewrite` entry points instead of a combined
-/// `matchAndRewrite`.
-template <typename PatternT>
-class ConversionSplitMatchAndRewriteImpl : public PatternT {
- using PatternT::PatternT;
-
- /// Attempt to match against IR rooted at the specified operation, which is
- /// the same operation kind as getRootKind().
- ///
- /// Note: This function must not modify the IR.
- virtual LogicalResult match(typename PatternT::OperationT op) const = 0;
-
- /// Rewrite the IR rooted at the specified operation with the result of
- /// this pattern, generating any new operations with the specified
- /// rewriter.
- virtual void rewrite(typename PatternT::OperationT op,
- typename PatternT::OpAdaptor adaptor,
- ConversionPatternRewriter &rewriter) const {
- // One of the two `rewrite` functions must be implemented.
- llvm_unreachable("rewrite is not implemented");
- }
-
- virtual void rewrite(typename PatternT::OperationT op,
- typename PatternT::OneToNOpAdaptor adaptor,
- ConversionPatternRewriter &rewriter) const {
- if constexpr (std::is_same<typename PatternT::OpAdaptor,
- ArrayRef<Value>>::value) {
- rewrite(op, PatternT::getOneToOneAdaptorOperands(adaptor), rewriter);
- } else {
- SmallVector<Value> oneToOneOperands =
- PatternT::getOneToOneAdaptorOperands(adaptor.getOperands());
- rewrite(op, typename PatternT::OpAdaptor(oneToOneOperands, adaptor),
- rewriter);
- }
- }
-
- LogicalResult
- matchAndRewrite(typename PatternT::OperationT op,
- typename PatternT::OneToNOpAdaptor adaptor,
- ConversionPatternRewriter &rewriter) const final {
- if (succeeded(match(op))) {
- rewrite(op, adaptor, rewriter);
- return success();
- }
- return failure();
- }
-
- LogicalResult
- matchAndRewrite(typename PatternT::OperationT op,
- typename PatternT::OpAdaptor adaptor,
- ConversionPatternRewriter &rewriter) const final {
- // Users would normally override this function in conversion patterns to
- // implement a 1:1 pattern. Patterns that are derived from this class have
- // separate `match` and `rewrite` functions, so this `matchAndRewrite`
- // overload is obsolete.
- llvm_unreachable("this function is unreachable");
- }
-};
-} // namespace detail
-
/// Base class for the conversion patterns. This pattern class enables type
/// conversions, and other uses specific to the conversion framework. As such,
/// patterns of this type can only be used with the 'apply*' methods below.
class ConversionPattern : public RewritePattern {
public:
- using OperationT = Operation *;
using OpAdaptor = ArrayRef<Value>;
using OneToNOpAdaptor = ArrayRef<ValueRange>;
- /// `SplitMatchAndRewrite` is deprecated. Use `matchAndRewrite` instead of
- /// separate `match` and `rewrite`.
- using SplitMatchAndRewrite =
- detail::ConversionSplitMatchAndRewriteImpl<ConversionPattern>;
-
/// Hook for derived classes to implement combined matching and rewriting.
/// This overload supports only 1:1 replacements. The 1:N overload is called
/// by the driver. By default, it calls this 1:1 overload or reports a fatal
@@ -668,16 +600,10 @@ class ConversionPattern : public RewritePattern {
template <typename SourceOp>
class OpConversionPattern : public ConversionPattern {
public:
- using OperationT = SourceOp;
using OpAdaptor = typename SourceOp::Adaptor;
using OneToNOpAdaptor =
typename SourceOp::template GenericAdaptor<ArrayRef<ValueRange>>;
- /// `SplitMatchAndRewrite` is deprecated. Use `matchAndRewrite` instead of
- /// separate `match` and `rewrite`.
- using SplitMatchAndRewrite =
- detail::ConversionSplitMatchAndRewriteImpl<OpConversionPattern<SourceOp>>;
-
OpConversionPattern(MLIRContext *context, PatternBenefit benefit = 1)
: ConversionPattern(SourceOp::getOperationName(), benefit, context) {}
OpConversionPattern(const TypeConverter &typeConverter, MLIRContext *context,
More information about the Mlir-commits
mailing list