[PatternRewriter] Rename OwningRewritePatternList -> RewritePatternSet and insert -> add

This maintains the old name to have minimal source impact on downstream codes, and
does not do the huge mechanical patch.  I expect the huge mechanical patch to land
sometime this week, but we can keep around the old names for a couple weeks to reduce
impact on downstream projects.

Differential Revision: https://reviews.llvm.org/D99119
This commit is contained in:
Chris Lattner 2021-03-22 15:02:04 -07:00
parent fc069f0165
commit 549e190236
27 changed files with 155 additions and 60 deletions

View File

@ -24,8 +24,8 @@ class RewritePattern;
class Value;
class ValueRange;
// Owning list of rewriting patterns.
class OwningRewritePatternList;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
/// Emit code that computes the given affine expression using standard
/// arithmetic operations applied to the provided dimension and symbol values.

View File

@ -12,7 +12,8 @@
namespace mlir {
class LLVMTypeConverter;
class OwningRewritePatternList;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
/// Collect a set of patterns to convert from the ArmSVE dialect to LLVM.
void populateArmSVEToLLVMConversionPatterns(LLVMTypeConverter &converter,

View File

@ -18,8 +18,9 @@ class ModuleOp;
template <typename T>
class OperationPass;
class MLIRContext;
class OwningRewritePatternList;
class TypeConverter;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
/// Create a pass to convert Async operations to the LLVM dialect.
std::unique_ptr<OperationPass<ModuleOp>> createConvertAsyncToLLVMPass();

View File

@ -24,7 +24,8 @@ class Location;
struct LogicalResult;
class ModuleOp;
class Operation;
class OwningRewritePatternList;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
template <typename T>
class OperationPass;

View File

@ -13,10 +13,12 @@
namespace mlir {
class LLVMTypeConverter;
class OwningRewritePatternList;
class ConversionTarget;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
template <typename OpT> class OperationPass;
template <typename OpT>
class OperationPass;
namespace gpu {
class GPUModuleOp;

View File

@ -13,8 +13,9 @@
namespace mlir {
class LLVMTypeConverter;
class OwningRewritePatternList;
class ConversionTarget;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
template <typename OpT>
class OperationPass;

View File

@ -15,8 +15,9 @@
namespace mlir {
class MLIRContext;
class OwningRewritePatternList;
class SPIRVTypeConverter;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
/// Appends to a pattern list additional patterns for translating Linalg ops to
/// SPIR-V ops.

View File

@ -16,7 +16,8 @@ class MLIRContext;
class ModuleOp;
template <typename T>
class OperationPass;
class OwningRewritePatternList;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
/// Populate the given list with patterns that convert from OpenMP to LLVM.
void populateOpenMPToLLVMConversionPatterns(LLVMTypeConverter &converter,

View File

@ -15,8 +15,9 @@ class AffineForOp;
class ConversionTarget;
struct LogicalResult;
class MLIRContext;
class OwningRewritePatternList;
class Value;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
namespace scf {
class ForOp;

View File

@ -18,9 +18,10 @@ namespace mlir {
class Pass;
// Owning list of rewriting patterns.
class OwningRewritePatternList;
class SPIRVTypeConverter;
struct ScfToSPIRVContextImpl;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
struct ScfToSPIRVContext {
ScfToSPIRVContext();

View File

@ -15,10 +15,9 @@
namespace mlir {
struct LogicalResult;
class Pass;
class RewritePattern;
// Owning list of rewriting patterns.
class OwningRewritePatternList;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
/// Collect a set of patterns to lower from scf.for, scf.if, and
/// loop.terminator to CFG operations within the Standard dialect, in particular

View File

@ -17,7 +17,8 @@ class FuncOp;
class ModuleOp;
template <typename T>
class OperationPass;
class OwningRewritePatternList;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
void populateShapeToStandardConversionPatterns(
OwningRewritePatternList &patterns);

View File

@ -18,7 +18,8 @@ class LLVMTypeConverter;
class ModuleOp;
template <typename T>
class OperationPass;
class OwningRewritePatternList;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
/// Value to pass as bitwidth for the index type when the converter is expected
/// to derive the bitwidth from the LLVM data layout.

View File

@ -12,10 +12,11 @@
namespace mlir {
class LLVMTypeConverter;
class OwningRewritePatternList;
class ModuleOp;
template <typename OpT>
class OperationPass;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
/// Collect a set of patterns to convert from the GPU dialect to ROCDL.
void populateVectorToROCDLConversionPatterns(

View File

@ -13,8 +13,9 @@
namespace mlir {
class MLIRContext;
class OwningRewritePatternList;
class Pass;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
/// Control whether unrolling is used when lowering vector transfer ops to SCF.
///

View File

@ -13,7 +13,8 @@ namespace mlir {
class LLVMConversionTarget;
class LLVMTypeConverter;
class OwningRewritePatternList;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
/// Collect a set of patterns to lower AMX ops to ops that map to LLVM
/// intrinsics.

View File

@ -13,7 +13,8 @@ namespace mlir {
class LLVMConversionTarget;
class LLVMTypeConverter;
class OwningRewritePatternList;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
/// Collect a set of patterns to lower AVX512 ops to ops that map to LLVM
/// intrinsics.

View File

@ -11,12 +11,11 @@
namespace mlir {
class OwningRewritePatternList;
class RewritePatternSet;
void populateExpandTanhPattern(OwningRewritePatternList &patterns);
void populateExpandTanhPattern(RewritePatternSet &patterns);
void populateMathPolynomialApproximationPatterns(
OwningRewritePatternList &patterns);
void populateMathPolynomialApproximationPatterns(RewritePatternSet &patterns);
} // namespace mlir

View File

@ -19,9 +19,10 @@ namespace mlir {
class ConversionTarget;
class MLIRContext;
class OwningRewritePatternList;
class Region;
class TypeConverter;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
namespace scf {

View File

@ -19,8 +19,9 @@ namespace mlir {
class ConversionTarget;
class MLIRContext;
class Operation;
class OwningRewritePatternList;
class TypeConverter;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
/// Add a pattern to the given pattern list to convert the operand and result
/// types of a CallOp with the given type converter.

View File

@ -19,7 +19,8 @@
namespace mlir {
class OwningRewritePatternList;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
void populateStdBufferizePatterns(BufferizeTypeConverter &typeConverter,
OwningRewritePatternList &patterns);

View File

@ -14,7 +14,8 @@
namespace mlir {
class OwningRewritePatternList;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
void populateTensorBufferizePatterns(BufferizeTypeConverter &typeConverter,
OwningRewritePatternList &patterns);

View File

@ -28,7 +28,8 @@
namespace mlir {
class MLIRContext;
class OwningRewritePatternList;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
namespace vector {
class VectorDialect;

View File

@ -16,8 +16,9 @@
namespace mlir {
class MLIRContext;
class OwningRewritePatternList;
class VectorTransferOpInterface;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
namespace scf {
class IfOp;

View File

@ -51,9 +51,11 @@ class RewritePattern;
class Type;
class Value;
class ValueRange;
template <typename ValueRangeT> class ValueTypeRange;
template <typename ValueRangeT>
class ValueTypeRange;
class OwningRewritePatternList;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
//===----------------------------------------------------------------------===//
// AbstractOperation
@ -132,12 +134,14 @@ public:
/// Returns an instance of the concept object for the given interface if it
/// was registered to this operation, null otherwise. This should not be used
/// directly.
template <typename T> typename T::Concept *getInterface() const {
template <typename T>
typename T::Concept *getInterface() const {
return interfaceMap.lookup<T>();
}
/// Returns true if the operation has a particular trait.
template <template <typename T> class Trait> bool hasTrait() const {
template <template <typename T> class Trait>
bool hasTrait() const {
return hasTraitFn(TypeID::get<Trait>());
}
@ -148,7 +152,8 @@ public:
/// This constructor is used by Dialect objects when they register the list of
/// operations they contain.
template <typename T> static void insert(Dialect &dialect) {
template <typename T>
static void insert(Dialect &dialect) {
insert(T::getOperationName(), dialect, TypeID::get<T>(),
T::getParseAssemblyFn(), T::getPrintAssemblyFn(),
T::getVerifyInvariantsFn(), T::getFoldHookFn(),
@ -220,7 +225,8 @@ public:
void append(NamedAttribute attr) { push_back(attr); }
/// Add an array of named attributes.
template <typename RangeT> void append(RangeT &&newAttributes) {
template <typename RangeT>
void append(RangeT &&newAttributes) {
append(std::begin(newAttributes), std::end(newAttributes));
}
@ -851,7 +857,8 @@ LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
namespace llvm {
// Identifiers hash just like pointers, there is no need to hash the bytes.
template <> struct DenseMapInfo<mlir::OperationName> {
template <>
struct DenseMapInfo<mlir::OperationName> {
static mlir::OperationName getEmptyKey() {
auto pointer = llvm::DenseMapInfo<void *>::getEmptyKey();
return mlir::OperationName::getFromOpaquePointer(pointer);
@ -871,7 +878,8 @@ template <> struct DenseMapInfo<mlir::OperationName> {
/// The pointer inside of an identifier comes from a StringMap, so its alignment
/// is always at least 4 and probably 8 (on 64-bit machines). Allow LLVM to
/// steal the low bits.
template <> struct PointerLikeTypeTraits<mlir::OperationName> {
template <>
struct PointerLikeTypeTraits<mlir::OperationName> {
public:
static inline void *getAsVoidPointer(mlir::OperationName I) {
return const_cast<void *>(I.getAsOpaquePointer());

View File

@ -715,22 +715,22 @@ public:
};
//===----------------------------------------------------------------------===//
// OwningRewritePatternList
// RewritePatternSet
//===----------------------------------------------------------------------===//
class OwningRewritePatternList {
class RewritePatternSet {
using NativePatternListT = std::vector<std::unique_ptr<RewritePattern>>;
public:
OwningRewritePatternList(MLIRContext *context) : context(context) {}
RewritePatternSet(MLIRContext *context) : context(context) {}
/// Construct a OwningRewritePatternList populated with the given pattern.
OwningRewritePatternList(MLIRContext *context,
/// Construct a RewritePatternSet populated with the given pattern.
RewritePatternSet(MLIRContext *context,
std::unique_ptr<RewritePattern> pattern)
: context(context) {
nativePatterns.emplace_back(std::move(pattern));
}
OwningRewritePatternList(PDLPatternModule &&pattern)
RewritePatternSet(PDLPatternModule &&pattern)
: context(pattern.getModule()->getContext()),
pdlPatterns(std::move(pattern)) {}
@ -749,7 +749,7 @@ public:
}
//===--------------------------------------------------------------------===//
// Pattern Insertion
// 'add' methods for adding patterns to the set.
//===--------------------------------------------------------------------===//
/// Add an instance of each of the pattern types 'Ts' to the pattern list with
@ -758,41 +758,104 @@ public:
template <typename... Ts, typename ConstructorArg,
typename... ConstructorArgs,
typename = std::enable_if_t<sizeof...(Ts) != 0>>
OwningRewritePatternList &insert(ConstructorArg &&arg,
ConstructorArgs &&... args) {
RewritePatternSet &add(ConstructorArg &&arg, ConstructorArgs &&... args) {
// The following expands a call to emplace_back for each of the pattern
// types 'Ts'. This magic is necessary due to a limitation in the places
// that a parameter pack can be expanded in c++11.
// FIXME: In c++17 this can be simplified by using 'fold expressions'.
(void)std::initializer_list<int>{0, (insertImpl<Ts>(arg, args...), 0)...};
(void)std::initializer_list<int>{0, (addImpl<Ts>(arg, args...), 0)...};
return *this;
}
/// Add an instance of each of the pattern types 'Ts'. Return a reference to
/// `this` for chaining insertions.
template <typename... Ts>
OwningRewritePatternList &insert() {
(void)std::initializer_list<int>{0, (insertImpl<Ts>(), 0)...};
RewritePatternSet &add() {
(void)std::initializer_list<int>{0, (addImpl<Ts>(), 0)...};
return *this;
}
/// Add the given native pattern to the pattern list. Return a reference to
/// `this` for chaining insertions.
OwningRewritePatternList &insert(std::unique_ptr<RewritePattern> pattern) {
RewritePatternSet &add(std::unique_ptr<RewritePattern> pattern) {
nativePatterns.emplace_back(std::move(pattern));
return *this;
}
/// Add the given PDL pattern to the pattern list. Return a reference to
/// `this` for chaining insertions.
OwningRewritePatternList &insert(PDLPatternModule &&pattern) {
RewritePatternSet &add(PDLPatternModule &&pattern) {
pdlPatterns.mergeIn(std::move(pattern));
return *this;
}
// Add a matchAndRewrite style pattern represented as a C function pointer.
template <typename OpType>
OwningRewritePatternList &
RewritePatternSet &add(LogicalResult (*implFn)(OpType,
PatternRewriter &rewriter)) {
struct FnPattern final : public OpRewritePattern<OpType> {
FnPattern(LogicalResult (*implFn)(OpType, PatternRewriter &rewriter),
MLIRContext *context)
: OpRewritePattern<OpType>(context), implFn(implFn) {}
LogicalResult matchAndRewrite(OpType op,
PatternRewriter &rewriter) const override {
return implFn(op, rewriter);
}
private:
LogicalResult (*implFn)(OpType, PatternRewriter &rewriter);
};
add(std::make_unique<FnPattern>(std::move(implFn), getContext()));
return *this;
}
//===--------------------------------------------------------------------===//
// Pattern Insertion
//===--------------------------------------------------------------------===//
// TODO: These are soft deprecated in favor of the 'add' methods above.
/// Add an instance of each of the pattern types 'Ts' to the pattern list with
/// the given arguments. Return a reference to `this` for chaining insertions.
/// Note: ConstructorArg is necessary here to separate the two variadic lists.
template <typename... Ts, typename ConstructorArg,
typename... ConstructorArgs,
typename = std::enable_if_t<sizeof...(Ts) != 0>>
RewritePatternSet &insert(ConstructorArg &&arg, ConstructorArgs &&... args) {
// The following expands a call to emplace_back for each of the pattern
// types 'Ts'. This magic is necessary due to a limitation in the places
// that a parameter pack can be expanded in c++11.
// FIXME: In c++17 this can be simplified by using 'fold expressions'.
(void)std::initializer_list<int>{0, (addImpl<Ts>(arg, args...), 0)...};
return *this;
}
/// Add an instance of each of the pattern types 'Ts'. Return a reference to
/// `this` for chaining insertions.
template <typename... Ts>
RewritePatternSet &insert() {
(void)std::initializer_list<int>{0, (addImpl<Ts>(), 0)...};
return *this;
}
/// Add the given native pattern to the pattern list. Return a reference to
/// `this` for chaining insertions.
RewritePatternSet &insert(std::unique_ptr<RewritePattern> pattern) {
nativePatterns.emplace_back(std::move(pattern));
return *this;
}
/// Add the given PDL pattern to the pattern list. Return a reference to
/// `this` for chaining insertions.
RewritePatternSet &insert(PDLPatternModule &&pattern) {
pdlPatterns.mergeIn(std::move(pattern));
return *this;
}
// Add a matchAndRewrite style pattern represented as a C function pointer.
template <typename OpType>
RewritePatternSet &
insert(LogicalResult (*implFn)(OpType, PatternRewriter &rewriter)) {
struct FnPattern final : public OpRewritePattern<OpType> {
FnPattern(LogicalResult (*implFn)(OpType, PatternRewriter &rewriter),
@ -816,13 +879,13 @@ private:
/// chaining insertions.
template <typename T, typename... Args>
std::enable_if_t<std::is_base_of<RewritePattern, T>::value>
insertImpl(Args &&... args) {
addImpl(Args &&... args) {
nativePatterns.emplace_back(
std::make_unique<T>(std::forward<Args>(args)...));
}
template <typename T, typename... Args>
std::enable_if_t<std::is_base_of<PDLPatternModule, T>::value>
insertImpl(Args &&... args) {
addImpl(Args &&... args) {
pdlPatterns.mergeIn(T(std::forward<Args>(args)...));
}
@ -831,6 +894,10 @@ private:
PDLPatternModule pdlPatterns;
};
// TODO: OwningRewritePatternList is soft-deprecated and will be removed in the
// future.
using OwningRewritePatternList = RewritePatternSet;
} // end namespace mlir
#endif // MLIR_PATTERN_MATCH_H

View File

@ -51,6 +51,6 @@ static LogicalResult convertTanhOp(math::TanhOp op, PatternRewriter &rewriter) {
return success();
}
void mlir::populateExpandTanhPattern(OwningRewritePatternList &patterns) {
patterns.insert(convertTanhOp);
void mlir::populateExpandTanhPattern(RewritePatternSet &patterns) {
patterns.add(convertTanhOp);
}