Skip to content

Commit

Permalink
[mlir][IR] Delete match and rewrite functions
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-springer committed Mar 7, 2025
1 parent a21cfca commit 127556b
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 135 deletions.
11 changes: 0 additions & 11 deletions mlir/include/mlir/Conversion/LLVMCommon/Pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(),
Expand Down
50 changes: 0 additions & 50 deletions mlir/include/mlir/IR/PatternMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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(),
Expand Down
74 changes: 0 additions & 74 deletions mlir/include/mlir/Transforms/DialectConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 127556b

Please sign in to comment.