NFC: Rename DialectConversionPattern to ConversionPattern.

--

PiperOrigin-RevId: 249857277
This commit is contained in:
River Riddle 2019-05-24 10:36:16 -07:00 committed by Mehdi Amini
parent fe2716aee3
commit ae1651368f
11 changed files with 52 additions and 62 deletions

View File

@ -24,8 +24,8 @@
#include <memory> #include <memory>
namespace mlir { namespace mlir {
class ConversionPattern;
class DialectConversion; class DialectConversion;
class DialectConversionPattern;
class MLIRContext; class MLIRContext;
class Module; class Module;
class RewritePattern; class RewritePattern;

View File

@ -131,11 +131,10 @@ static ArrayAttr makePositionAttr(FuncBuilder &builder,
} }
// RangeOp creates a new range descriptor. // RangeOp creates a new range descriptor.
class RangeOpConversion : public DialectConversionPattern { class RangeOpConversion : public ConversionPattern {
public: public:
explicit RangeOpConversion(MLIRContext *context) explicit RangeOpConversion(MLIRContext *context)
: DialectConversionPattern(linalg::RangeOp::getOperationName(), 1, : ConversionPattern(linalg::RangeOp::getOperationName(), 1, context) {}
context) {}
void rewrite(Operation *op, ArrayRef<Value *> operands, void rewrite(Operation *op, ArrayRef<Value *> operands,
PatternRewriter &rewriter) const override { PatternRewriter &rewriter) const override {
@ -158,11 +157,10 @@ public:
} }
}; };
class ViewOpConversion : public DialectConversionPattern { class ViewOpConversion : public ConversionPattern {
public: public:
explicit ViewOpConversion(MLIRContext *context) explicit ViewOpConversion(MLIRContext *context)
: DialectConversionPattern(linalg::ViewOp::getOperationName(), 1, : ConversionPattern(linalg::ViewOp::getOperationName(), 1, context) {}
context) {}
void rewrite(Operation *op, ArrayRef<Value *> operands, void rewrite(Operation *op, ArrayRef<Value *> operands,
PatternRewriter &rewriter) const override { PatternRewriter &rewriter) const override {
@ -283,11 +281,10 @@ public:
} }
}; };
class SliceOpConversion : public DialectConversionPattern { class SliceOpConversion : public ConversionPattern {
public: public:
explicit SliceOpConversion(MLIRContext *context) explicit SliceOpConversion(MLIRContext *context)
: DialectConversionPattern(linalg::SliceOp::getOperationName(), 1, : ConversionPattern(linalg::SliceOp::getOperationName(), 1, context) {}
context) {}
void rewrite(Operation *op, ArrayRef<Value *> operands, void rewrite(Operation *op, ArrayRef<Value *> operands,
PatternRewriter &rewriter) const override { PatternRewriter &rewriter) const override {
@ -375,10 +372,10 @@ public:
// When converting the "some_consumer" operation, don't emit anything and // When converting the "some_consumer" operation, don't emit anything and
// effectively drop it. // effectively drop it.
class DropConsumer : public DialectConversionPattern { class DropConsumer : public ConversionPattern {
public: public:
explicit DropConsumer(MLIRContext *context) explicit DropConsumer(MLIRContext *context)
: DialectConversionPattern("some_consumer", 1, context) {} : ConversionPattern("some_consumer", 1, context) {}
void rewrite(Operation *op, ArrayRef<Value *> operands, void rewrite(Operation *op, ArrayRef<Value *> operands,
PatternRewriter &rewriter) const override { PatternRewriter &rewriter) const override {

View File

@ -51,11 +51,10 @@ static ArrayAttr makePositionAttr(FuncBuilder &builder,
namespace { namespace {
// Common functionality for Linalg LoadOp and StoreOp conversion to the // Common functionality for Linalg LoadOp and StoreOp conversion to the
// LLVM IR Dialect. // LLVM IR Dialect.
template <typename Op> template <typename Op> class LoadStoreOpConversion : public ConversionPattern {
class LoadStoreOpConversion : public DialectConversionPattern {
public: public:
explicit LoadStoreOpConversion(MLIRContext *context) explicit LoadStoreOpConversion(MLIRContext *context)
: DialectConversionPattern(Op::getOperationName(), 1, context) {} : ConversionPattern(Op::getOperationName(), 1, context) {}
using Base = LoadStoreOpConversion<Op>; using Base = LoadStoreOpConversion<Op>;
// Compute the pointer to an element of the buffer underlying the view given // Compute the pointer to an element of the buffer underlying the view given

View File

@ -77,14 +77,14 @@ Value *memRefTypeCast(FuncBuilder &builder, Value *val) {
/// Lower toy.mul to Linalg `matmul`. /// Lower toy.mul to Linalg `matmul`.
/// ///
/// This class inherit from `DialectConversionPattern` and override `rewrite`, /// This class inherit from `ConversionPattern` and override `rewrite`,
/// similarly to the PatternRewriter introduced in the previous chapter. /// similarly to the PatternRewriter introduced in the previous chapter.
/// It will be called by the DialectConversion framework (see `LateLowering` /// It will be called by the DialectConversion framework (see `LateLowering`
/// class below). /// class below).
class MulOpConversion : public DialectConversionPattern { class MulOpConversion : public ConversionPattern {
public: public:
explicit MulOpConversion(MLIRContext *context) explicit MulOpConversion(MLIRContext *context)
: DialectConversionPattern(toy::MulOp::getOperationName(), 1, context) {} : ConversionPattern(toy::MulOp::getOperationName(), 1, context) {}
void rewrite(Operation *op, ArrayRef<Value *> operands, void rewrite(Operation *op, ArrayRef<Value *> operands,
PatternRewriter &rewriter) const override { PatternRewriter &rewriter) const override {

View File

@ -77,14 +77,14 @@ Value *memRefTypeCast(FuncBuilder &builder, Value *val) {
/// Lower a toy.add to an affine loop nest. /// Lower a toy.add to an affine loop nest.
/// ///
/// This class inherit from `DialectConversionPattern` and override `rewrite`, /// This class inherit from `ConversionPattern` and override `rewrite`,
/// similarly to the PatternRewriter introduced in the previous chapter. /// similarly to the PatternRewriter introduced in the previous chapter.
/// It will be called by the DialectConversion framework (see `LateLowering` /// It will be called by the DialectConversion framework (see `LateLowering`
/// class below). /// class below).
class AddOpConversion : public DialectConversionPattern { class AddOpConversion : public ConversionPattern {
public: public:
explicit AddOpConversion(MLIRContext *context) explicit AddOpConversion(MLIRContext *context)
: DialectConversionPattern(toy::AddOp::getOperationName(), 1, context) {} : ConversionPattern(toy::AddOp::getOperationName(), 1, context) {}
/// Lower the `op` by generating IR using the `rewriter` builder. The builder /// Lower the `op` by generating IR using the `rewriter` builder. The builder
/// is setup with a new function, the `operands` array has been populated with /// is setup with a new function, the `operands` array has been populated with
@ -126,11 +126,10 @@ public:
/// Lowers `toy.print` to a loop nest calling `printf` on every individual /// Lowers `toy.print` to a loop nest calling `printf` on every individual
/// elements of the array. /// elements of the array.
class PrintOpConversion : public DialectConversionPattern { class PrintOpConversion : public ConversionPattern {
public: public:
explicit PrintOpConversion(MLIRContext *context) explicit PrintOpConversion(MLIRContext *context)
: DialectConversionPattern(toy::PrintOp::getOperationName(), 1, context) { : ConversionPattern(toy::PrintOp::getOperationName(), 1, context) {}
}
void rewrite(Operation *op, ArrayRef<Value *> operands, void rewrite(Operation *op, ArrayRef<Value *> operands,
PatternRewriter &rewriter) const override { PatternRewriter &rewriter) const override {
@ -225,11 +224,10 @@ private:
}; };
/// Lowers constant to a sequence of store in a buffer. /// Lowers constant to a sequence of store in a buffer.
class ConstantOpConversion : public DialectConversionPattern { class ConstantOpConversion : public ConversionPattern {
public: public:
explicit ConstantOpConversion(MLIRContext *context) explicit ConstantOpConversion(MLIRContext *context)
: DialectConversionPattern(toy::ConstantOp::getOperationName(), 1, : ConversionPattern(toy::ConstantOp::getOperationName(), 1, context) {}
context) {}
void rewrite(Operation *op, ArrayRef<Value *> operands, void rewrite(Operation *op, ArrayRef<Value *> operands,
PatternRewriter &rewriter) const override { PatternRewriter &rewriter) const override {
@ -269,11 +267,10 @@ public:
}; };
/// Lower transpose operation to an affine loop nest. /// Lower transpose operation to an affine loop nest.
class TransposeOpConversion : public DialectConversionPattern { class TransposeOpConversion : public ConversionPattern {
public: public:
explicit TransposeOpConversion(MLIRContext *context) explicit TransposeOpConversion(MLIRContext *context)
: DialectConversionPattern(toy::TransposeOp::getOperationName(), 1, : ConversionPattern(toy::TransposeOp::getOperationName(), 1, context) {}
context) {}
void rewrite(Operation *op, ArrayRef<Value *> operands, void rewrite(Operation *op, ArrayRef<Value *> operands,
PatternRewriter &rewriter) const override { PatternRewriter &rewriter) const override {
@ -302,11 +299,10 @@ public:
}; };
// Lower toy.return to standard return operation. // Lower toy.return to standard return operation.
class ReturnOpConversion : public DialectConversionPattern { class ReturnOpConversion : public ConversionPattern {
public: public:
explicit ReturnOpConversion(MLIRContext *context) explicit ReturnOpConversion(MLIRContext *context)
: DialectConversionPattern(toy::ReturnOp::getOperationName(), 1, : ConversionPattern(toy::ReturnOp::getOperationName(), 1, context) {}
context) {}
void rewrite(Operation *op, ArrayRef<Value *> operands, void rewrite(Operation *op, ArrayRef<Value *> operands,
PatternRewriter &rewriter) const override { PatternRewriter &rewriter) const override {

View File

@ -212,11 +212,11 @@ offset, the min/max values or the strides. Their static (constant) dimensions
are available directly in the type signature. are available directly in the type signature.
An operation conversion is defined as special pattern by inheriting from An operation conversion is defined as special pattern by inheriting from
`mlir::DialectConversionPattern` and by reimplementing the matching and the `mlir::ConversionPattern` and by reimplementing the matching and the rewriting
rewriting functions: functions:
```c++ ```c++
class ViewOpConversion : public DialectConversionPattern { class ViewOpConversion : public ConversionPattern {
public: public:
// A conversion constructor, may take arbtirary operands but must be able // A conversion constructor, may take arbtirary operands but must be able
// to obtain an MLIRContext from them to call the parent constructor. // to obtain an MLIRContext from them to call the parent constructor.
@ -237,15 +237,14 @@ public:
} }
``` ```
The `DialectConversionPattern` constructor takes, in addition to the context, The `ConversionPattern` constructor takes, in addition to the context, the name
the name of the main operation to be matched and the "benefit" of a match. These of the main operation to be matched and the "benefit" of a match. These operands
operands are intended to be useful for defining an optimization problem across are intended to be useful for defining an optimization problem across multiple
multiple possible conversions but are currently ignored by the conversion possible conversions but are currently ignored by the conversion framework.
framework.
```c++ ```c++
ViewOpConversion::ViewOpConversion(MLIRContext *context) ViewOpConversion::ViewOpConversion(MLIRContext *context)
: DialectConversionPattern(linalg::ViewOp::getOperationName(), 1, context) {} : ConversionPattern(linalg::ViewOp::getOperationName(), 1, context) {}
``` ```
The matching function can be used, for example, to apply different conversions The matching function can be used, for example, to apply different conversions
@ -621,7 +620,7 @@ class Lowering : public DialectConversion {
protected: protected:
// Produce a set of operation conversion patterns. This is called once per // Produce a set of operation conversion patterns. This is called once per
// conversion. // conversion.
llvm::DenseSet<DialectConversionPattern *> llvm::DenseSet<ConversionPattern *>
initConverter(MLIRContext *context) override { initConverter(MLIRContext *context) override {
allocator.Reset(); allocator.Reset();
// Call a helper function provided by MLIR to build a set of operation // Call a helper function provided by MLIR to build a set of operation

View File

@ -49,7 +49,7 @@ public:
SmallVectorImpl<NamedAttributeList> &convertedArgAttrs) { /*...*/ } SmallVectorImpl<NamedAttributeList> &convertedArgAttrs) { /*...*/ }
// This gets called once to set up operation converters. // This gets called once to set up operation converters.
llvm::DenseSet<DialectConversionPattern *> llvm::DenseSet<ConversionPattern *>
initConverters(MLIRContext *context) override { initConverters(MLIRContext *context) override {
RewriteListBuilder<MulOpConversion, PrintOpConversion, RewriteListBuilder<MulOpConversion, PrintOpConversion,
TransposeOpConversion>::build(allocator, context); TransposeOpConversion>::build(allocator, context);
@ -65,14 +65,14 @@ Individual operation converters are following this pattern:
```c++ ```c++
/// Lower a toy.add to an affine loop nest. /// Lower a toy.add to an affine loop nest.
/// ///
/// This class inherit from `DialectConversionPattern` and override `rewrite`, /// This class inherit from `ConversionPattern` and override `rewrite`,
/// similarly to the PatternRewriter introduced in the previous chapter. /// similarly to the PatternRewriter introduced in the previous chapter.
/// It will be called by the DialectConversion framework (see `LateLowering` /// It will be called by the DialectConversion framework (see `LateLowering`
/// class below). /// class below).
class AddOpConversion : public DialectConversionPattern { class AddOpConversion : public ConversionPattern {
public: public:
explicit AddOpConversion(MLIRContext *context) explicit AddOpConversion(MLIRContext *context)
: DialectConversionPattern(toy::AddOp::getOperationName(), 1, context) {} : ConversionPattern(toy::AddOp::getOperationName(), 1, context) {}
/// Lower the `op` by generating IR using the `rewriter` builder. The builder /// Lower the `op` by generating IR using the `rewriter` builder. The builder
/// is setup with a new function, the `operands` array has been populated with /// is setup with a new function, the `operands` array has been populated with

View File

@ -135,7 +135,7 @@ private:
/// Base class for operation conversions targeting the LLVM IR dialect. Provides /// Base class for operation conversions targeting the LLVM IR dialect. Provides
/// conversion patterns with an access to the containing LLVMLowering for the /// conversion patterns with an access to the containing LLVMLowering for the
/// purpose of type conversions. /// purpose of type conversions.
class LLVMOpLowering : public DialectConversionPattern { class LLVMOpLowering : public ConversionPattern {
public: public:
LLVMOpLowering(StringRef rootOpName, MLIRContext *context, LLVMOpLowering(StringRef rootOpName, MLIRContext *context,
LLVMLowering &lowering); LLVMLowering &lowering);

View File

@ -36,17 +36,16 @@ class Operation;
class Type; class Type;
class Value; class Value;
/// Base class for the dialect conversion patterns that require type changes. /// Base class for the conversion patterns that require type changes. Specific
/// Specific conversions must derive this class and implement least one /// conversions must derive this class and implement least one `rewrite` method.
/// `rewrite` method.
/// NOTE: These conversion patterns can only be used with the 'apply*' methods /// NOTE: These conversion patterns can only be used with the 'apply*' methods
/// below. /// below.
class DialectConversionPattern : public RewritePattern { class ConversionPattern : public RewritePattern {
public: public:
/// Construct an DialectConversionPattern. `rootName` must correspond to the /// Construct an ConversionPattern. `rootName` must correspond to the
/// canonical name of the first operation matched by the pattern. /// canonical name of the first operation matched by the pattern.
DialectConversionPattern(StringRef rootName, PatternBenefit benefit, ConversionPattern(StringRef rootName, PatternBenefit benefit,
MLIRContext *ctx) MLIRContext *ctx)
: RewritePattern(rootName, benefit, ctx) {} : RewritePattern(rootName, benefit, ctx) {}
/// Hook for derived classes to implement matching. Dialect conversion /// Hook for derived classes to implement matching. Dialect conversion
@ -60,7 +59,7 @@ public:
/// operation matched by the pattern, `operands` is a list of rewritten values /// operation matched by the pattern, `operands` is a list of rewritten values
/// that are passed to this operation, `rewriter` can be used to emit the new /// that are passed to this operation, `rewriter` can be used to emit the new
/// operations. This function must be reimplemented if the /// operations. This function must be reimplemented if the
/// DialectConversionPattern ever needs to replace an operation that does not /// ConversionPattern ever needs to replace an operation that does not
/// have successors. This function should not fail. If some specific cases of /// have successors. This function should not fail. If some specific cases of
/// the operation are not supported, these cases should not be matched. /// the operation are not supported, these cases should not be matched.
virtual void rewrite(Operation *op, ArrayRef<Value *> operands, virtual void rewrite(Operation *op, ArrayRef<Value *> operands,
@ -74,7 +73,7 @@ public:
/// of (potentially rewritten) successor blocks, `operands` is a list of lists /// of (potentially rewritten) successor blocks, `operands` is a list of lists
/// of rewritten values passed to each of the successors, co-indexed with /// of rewritten values passed to each of the successors, co-indexed with
/// `destinations`, `rewriter` can be used to emit the new operations. It must /// `destinations`, `rewriter` can be used to emit the new operations. It must
/// be reimplemented if the DialectConversionPattern ever needs to replace a /// be reimplemented if the ConversionPattern ever needs to replace a
/// terminator operation that has successors. This function should not fail /// terminator operation that has successors. This function should not fail
/// the pass. If some specific cases of the operation are not supported, /// the pass. If some specific cases of the operation are not supported,
/// these cases should not be matched. /// these cases should not be matched.

View File

@ -185,7 +185,7 @@ static Type getMemRefElementPtrType(MemRefType t, LLVMLowering &lowering) {
LLVMOpLowering::LLVMOpLowering(StringRef rootOpName, MLIRContext *context, LLVMOpLowering::LLVMOpLowering(StringRef rootOpName, MLIRContext *context,
LLVMLowering &lowering_) LLVMLowering &lowering_)
: DialectConversionPattern(rootOpName, /*benefit=*/1, context), : ConversionPattern(rootOpName, /*benefit=*/1, context),
lowering(lowering_) {} lowering(lowering_) {}
namespace { namespace {

View File

@ -90,7 +90,7 @@ constexpr StringLiteral ArgConverter::kCastName;
// DialectConversionRewriter // DialectConversionRewriter
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// This class implements a pattern rewriter for DialectConversionPattern /// This class implements a pattern rewriter for ConversionPattern
/// patterns. It automatically performs remapping of replaced operation values. /// patterns. It automatically performs remapping of replaced operation values.
struct DialectConversionRewriter final : public PatternRewriter { struct DialectConversionRewriter final : public PatternRewriter {
/// This class represents one requested operation replacement via 'replaceOp'. /// This class represents one requested operation replacement via 'replaceOp'.
@ -182,15 +182,15 @@ struct DialectConversionRewriter final : public PatternRewriter {
} // end anonymous namespace } // end anonymous namespace
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// DialectConversionPattern // ConversionPattern
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// Rewrite the IR rooted at the specified operation with the result of this /// Rewrite the IR rooted at the specified operation with the result of this
/// pattern. If an unexpected error is encountered (an internal compiler /// pattern. If an unexpected error is encountered (an internal compiler
/// error), it is emitted through the normal MLIR diagnostic hooks and the IR is /// error), it is emitted through the normal MLIR diagnostic hooks and the IR is
/// left in a valid state. /// left in a valid state.
void DialectConversionPattern::rewrite(Operation *op, void ConversionPattern::rewrite(Operation *op,
PatternRewriter &rewriter) const { PatternRewriter &rewriter) const {
SmallVector<Value *, 4> operands; SmallVector<Value *, 4> operands;
auto &dialectRewriter = static_cast<DialectConversionRewriter &>(rewriter); auto &dialectRewriter = static_cast<DialectConversionRewriter &>(rewriter);
dialectRewriter.remapValues(op->getOperands(), operands); dialectRewriter.remapValues(op->getOperands(), operands);