-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir][IR] Delete match
and rewrite
functions
#130259
base: main
Are you sure you want to change the base?
[mlir][IR] Delete match
and rewrite
functions
#130259
Conversation
@llvm/pr-subscribers-mlir-core @llvm/pr-subscribers-mlir Author: Matthias Springer (matthias-springer) ChangesThe Note for LLVM integration: Update your patterns to use I plan to merge this PR in April. Full diff: https://github.com/llvm/llvm-project/pull/130259.diff 3 Files Affected:
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..ec522f0cba33e 100644
--- a/mlir/include/mlir/Transforms/DialectConversion.h
+++ b/mlir/include/mlir/Transforms/DialectConversion.h
@@ -529,81 +529,15 @@ class TypeConverter {
//===----------------------------------------------------------------------===//
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 +602,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,
|
efddc66
to
127556b
Compare
Would be good to announce this in the forum as well, and add to the change log. |
+1, there are quite a few of these I see hanging around that would need to be addressed. |
I posted a PSA on Discourse: https://discourse.llvm.org/t/psa-deprecating-match-and-rewrite/85048 |
The
match
andrewrite
functions have been deprecated in #130031. This commit deletes them entirely.Note for LLVM integration: Update your patterns to use
matchAndRewrite
instead of separatematch
/rewrite
.I plan to merge this PR in April.