namespace mlir {
-class BufferAssignmentTypeConverter;
+class BufferizeTypeConverter;
namespace linalg {
/// Populates the given list with patterns to bufferize linalg ops.
void populateLinalgBufferizePatterns(MLIRContext *context,
- BufferAssignmentTypeConverter &converter,
+ BufferizeTypeConverter &converter,
OwningRewritePatternList &patterns);
/// Performs standalone tiling of a single LinalgOp by `tileSizes`.
// Buffer allocation patterns.
//===----------------------------------------------------------------------===//
-/// Generic BufferAssignmentConversionPattern that matches any Operation* and
+/// Generic BufferizeConversionPattern that matches any Operation* and
/// dispatches internally. This avoids template instantiating one pattern for
/// each LinalgOp op.
-class LinalgOpConverter : public BufferAssignmentConversionPattern {
+class LinalgOpConverter : public BufferizeConversionPattern {
public:
- LinalgOpConverter(MLIRContext *context,
- BufferAssignmentTypeConverter &converter)
- : BufferAssignmentConversionPattern(context, converter) {}
+ LinalgOpConverter(MLIRContext *context, BufferizeTypeConverter &converter)
+ : BufferizeConversionPattern(context, converter) {}
LogicalResult
matchAndRewrite(Operation *op, ArrayRef<Value> operands,
/// stored in memory. A linalg.reshape is introduced to convert to the desired
/// n-D buffer form.
class TensorConstantOpConverter
- : public BufferAssignmentOpConversionPattern<ConstantOp> {
+ : public BufferizeOpConversionPattern<ConstantOp> {
public:
- using BufferAssignmentOpConversionPattern<
- ConstantOp>::BufferAssignmentOpConversionPattern;
+ using BufferizeOpConversionPattern<ConstantOp>::BufferizeOpConversionPattern;
LogicalResult
matchAndRewrite(ConstantOp op, ArrayRef<Value> operands,
/// TensorCastOp converts 1-1 to MemRefCastOp.
class TensorCastOpConverter
- : public BufferAssignmentOpConversionPattern<TensorCastOp> {
+ : public BufferizeOpConversionPattern<TensorCastOp> {
public:
- using BufferAssignmentOpConversionPattern<
- TensorCastOp>::BufferAssignmentOpConversionPattern;
+ using BufferizeOpConversionPattern<
+ TensorCastOp>::BufferizeOpConversionPattern;
LogicalResult
matchAndRewrite(TensorCastOp op, ArrayRef<Value> operands,
#include "mlir/Pass/Pass.h"
namespace mlir {
-class BufferAssignmentTypeConverter;
+class BufferizeTypeConverter;
} // namespace mlir
namespace mlir {
MLIRContext *ctx);
std::unique_ptr<FunctionPass> createRemoveShapeConstraintsPass();
-void populateShapeTypeConversionPatterns(
- MLIRContext *ctx, BufferAssignmentTypeConverter &converter,
- OwningRewritePatternList &patterns);
+void populateShapeTypeConversionPatterns(MLIRContext *ctx,
+ BufferizeTypeConverter &converter,
+ OwningRewritePatternList &patterns);
// Bufferizes shape dialect ops.
//
// Note that most shape dialect ops must be converted to std before
/// A helper type converter class for using inside Buffer Assignment operation
/// conversion patterns. The default constructor keeps all the types intact
/// except for the ranked-tensor types which is converted to memref types.
-class BufferAssignmentTypeConverter : public TypeConverter {
+class BufferizeTypeConverter : public TypeConverter {
public:
/// This enum is for showing how buffer placement operation converters should
/// conduct with certain result type after type conversion. This value can be
/// getResultConversionKind.
enum ResultConversionKind { AppendToArgumentsList, KeepAsFunctionResult };
- BufferAssignmentTypeConverter();
+ BufferizeTypeConverter();
/// This method tries to decompose a value of a certain type using provided
/// decompose callback functions. If it is unable to do so, the original value
SmallVector<DecomposeTypeConversionCallFn, 2> decomposeTypeConversions;
};
-/// Helper conversion pattern that encapsulates a BufferAssignmentTypeConverter
+/// Helper conversion pattern that encapsulates a BufferizeTypeConverter
/// instance.
template <typename SourceOp>
-class BufferAssignmentOpConversionPattern
- : public OpConversionPattern<SourceOp> {
+class BufferizeOpConversionPattern : public OpConversionPattern<SourceOp> {
public:
- explicit BufferAssignmentOpConversionPattern(
- MLIRContext *context, BufferAssignmentTypeConverter &converter,
- PatternBenefit benefit = 1)
+ explicit BufferizeOpConversionPattern(MLIRContext *context,
+ BufferizeTypeConverter &converter,
+ PatternBenefit benefit = 1)
: OpConversionPattern<SourceOp>(context, benefit), converter(converter) {}
protected:
- BufferAssignmentTypeConverter &converter;
+ BufferizeTypeConverter &converter;
};
-/// Helper conversion pattern that encapsulates a BufferAssignmentTypeConverter
+/// Helper conversion pattern that encapsulates a BufferizeTypeConverter
/// instance and that operates on Operation* to be compatible with OpInterfaces.
/// This allows avoiding to instantiate N patterns for ops that can be subsumed
/// by a single op interface (e.g. Linalg named ops).
-class BufferAssignmentConversionPattern : public ConversionPattern {
+class BufferizeConversionPattern : public ConversionPattern {
public:
- explicit BufferAssignmentConversionPattern(
- MLIRContext *context, BufferAssignmentTypeConverter &converter,
- PatternBenefit benefit = 1)
+ explicit BufferizeConversionPattern(MLIRContext *context,
+ BufferizeTypeConverter &converter,
+ PatternBenefit benefit = 1)
: ConversionPattern(benefit, converter, MatchAnyOpTypeTag()),
converter(converter) {}
protected:
- BufferAssignmentTypeConverter &converter;
+ BufferizeTypeConverter &converter;
};
-/// Converts the signature of the function using BufferAssignmentTypeConverter.
+/// Converts the signature of the function using BufferizeTypeConverter.
/// Each result type of the function is kept as a function result or appended to
/// the function arguments list based on ResultConversionKind for the converted
/// result type.
-class BufferAssignmentFuncOpConverter
- : public BufferAssignmentOpConversionPattern<FuncOp> {
+class BufferizeFuncOpConverter : public BufferizeOpConversionPattern<FuncOp> {
public:
- using BufferAssignmentOpConversionPattern<
- FuncOp>::BufferAssignmentOpConversionPattern;
+ using BufferizeOpConversionPattern<FuncOp>::BufferizeOpConversionPattern;
/// Performs the actual signature rewriting step.
LogicalResult matchAndRewrite(mlir::FuncOp, ArrayRef<Value>,
/// operation from the operand to the target function argument is inserted.
template <typename ReturnOpSourceTy, typename ReturnOpTargetTy,
typename CopyOpTy>
-class BufferAssignmentReturnOpConverter
- : public BufferAssignmentOpConversionPattern<ReturnOpSourceTy> {
+class BufferizeReturnOpConverter
+ : public BufferizeOpConversionPattern<ReturnOpSourceTy> {
public:
- using BufferAssignmentOpConversionPattern<
- ReturnOpSourceTy>::BufferAssignmentOpConversionPattern;
+ using BufferizeOpConversionPattern<
+ ReturnOpSourceTy>::BufferizeOpConversionPattern;
/// Performs the actual return-op conversion step.
LogicalResult
Type origin = originTypes[value.index()];
Type converted = value.value().getType();
auto kind = this->converter.getResultConversionKind(origin, converted);
- if (kind == BufferAssignmentTypeConverter::KeepAsFunctionResult)
+ if (kind == BufferizeTypeConverter::KeepAsFunctionResult)
newOperands.push_back(value.value());
else
- // kind = BufferAssignmentTypeConverter::AppendToArgumentsList
+ // kind = BufferizeTypeConverter::AppendToArgumentsList
needCopyOperands.push_back(value.value());
}
}
/// Rewrites the `CallOp` to match its operands and results with the signature
/// of the callee after rewriting the callee with
-/// BufferAssignmentFuncOpConverter.
-class BufferAssignmentCallOpConverter
- : public BufferAssignmentOpConversionPattern<CallOp> {
+/// BufferizeFuncOpConverter.
+class BufferizeCallOpConverter : public BufferizeOpConversionPattern<CallOp> {
public:
- using BufferAssignmentOpConversionPattern<
- CallOp>::BufferAssignmentOpConversionPattern;
+ using BufferizeOpConversionPattern<CallOp>::BufferizeOpConversionPattern;
/// Performs the actual rewriting step.
LogicalResult matchAndRewrite(CallOp, ArrayRef<Value>,
/// assignment.
template <typename ReturnOpSourceTy, typename ReturnOpTargetTy,
typename CopyOpTy>
-static void populateWithBufferAssignmentOpConversionPatterns(
- MLIRContext *context, BufferAssignmentTypeConverter &converter,
- OwningRewritePatternList &patterns) {
+static void
+populateWithBufferizeOpConversionPatterns(MLIRContext *context,
+ BufferizeTypeConverter &converter,
+ OwningRewritePatternList &patterns) {
// clang-format off
patterns.insert<
- BufferAssignmentCallOpConverter,
- BufferAssignmentFuncOpConverter,
- BufferAssignmentReturnOpConverter
+ BufferizeCallOpConverter,
+ BufferizeFuncOpConverter,
+ BufferizeReturnOpConverter
<ReturnOpSourceTy, ReturnOpTargetTy, CopyOpTy>
>(context, converter);
// clang-format on
// Specialization for `linalg::GenericOp`.
/// A pattern to convert Generic Linalg operations which work on tensors to
-/// use buffers. A buffer is allocated using BufferAssignmentPlacer for
-/// each operation result. BufferPlacement pass should be later used to move
+/// use buffers. BufferPlacement pass should be later used to move
/// Alloc operations to the correct positions and insert the missing Dealloc
/// operations in the correct places.
static void finalizeBufferAllocation(ConversionPatternRewriter &rewriter,
void runOnOperation() override {
MLIRContext &context = getContext();
ConversionTarget target(context);
- BufferAssignmentTypeConverter converter;
+ BufferizeTypeConverter converter;
// Mark all Standard operations legal.
target.addLegalDialect<StandardOpsDialect, vector::VectorDialect>();
});
converter.setResultConversionKind<RankedTensorType, MemRefType>(
- BufferAssignmentTypeConverter::AppendToArgumentsList);
+ BufferizeTypeConverter::AppendToArgumentsList);
OwningRewritePatternList patterns;
populateLinalgBufferizePatterns(&context, converter, patterns);
- populateWithBufferAssignmentOpConversionPatterns<
- mlir::ReturnOp, mlir::ReturnOp, linalg::CopyOp>(&context, converter,
- patterns);
+ populateWithBufferizeOpConversionPatterns<mlir::ReturnOp, mlir::ReturnOp,
+ linalg::CopyOp>(
+ &context, converter, patterns);
if (failed(applyFullConversion(this->getOperation(), target, patterns)))
this->signalPassFailure();
}
return std::make_unique<LinalgBufferizePass>();
}
void mlir::linalg::populateLinalgBufferizePatterns(
- MLIRContext *context, BufferAssignmentTypeConverter &converter,
+ MLIRContext *context, BufferizeTypeConverter &converter,
OwningRewritePatternList &patterns) {
patterns.insert<
// clang-format off
namespace {
// Propagate tensor to memref conversions through shape.assuming ops.
class TypeConversionAssumingOpConverter
- : public BufferAssignmentOpConversionPattern<shape::AssumingOp> {
+ : public BufferizeOpConversionPattern<shape::AssumingOp> {
public:
- using BufferAssignmentOpConversionPattern<
- shape::AssumingOp>::BufferAssignmentOpConversionPattern;
+ using BufferizeOpConversionPattern<
+ shape::AssumingOp>::BufferizeOpConversionPattern;
LogicalResult
matchAndRewrite(shape::AssumingOp assumingOp, ArrayRef<Value> operands,
MLIRContext &ctx = getContext();
OwningRewritePatternList patterns;
- BufferAssignmentTypeConverter converter;
+ BufferizeTypeConverter converter;
populateShapeTypeConversionPatterns(&ctx, converter, patterns);
ConversionTarget target(getContext());
//
// TODO: Change this to work generally with any type conversions.
void mlir::populateShapeTypeConversionPatterns(
- MLIRContext *context, BufferAssignmentTypeConverter &converter,
+ MLIRContext *context, BufferizeTypeConverter &converter,
OwningRewritePatternList &patterns) {
patterns.insert<TypeConversionAssumingOpConverter>(context, converter);
}
using namespace mlir;
//===----------------------------------------------------------------------===//
-// BufferAssignmentTypeConverter
+// BufferizeTypeConverter
//===----------------------------------------------------------------------===//
-/// Registers conversions into BufferAssignmentTypeConverter
-BufferAssignmentTypeConverter::BufferAssignmentTypeConverter() {
+/// Registers conversions into BufferizeTypeConverter
+BufferizeTypeConverter::BufferizeTypeConverter() {
// Keep all types unchanged.
addConversion([](Type type) { return type; });
// Convert RankedTensorType to MemRefType.
/// This method tries to decompose a value of a certain type using provided
/// decompose callback functions. If it is unable to do so, the original value
/// is returned.
-void BufferAssignmentTypeConverter::tryDecomposeValue(
+void BufferizeTypeConverter::tryDecomposeValue(
OpBuilder &builder, Location loc, Type type, Value value,
SmallVectorImpl<Value> &results) {
for (auto conversion : decomposeValueConversions)
/// This method tries to decompose a type using provided decompose callback
/// functions. If it is unable to do so, the original type is returned.
-void BufferAssignmentTypeConverter::tryDecomposeType(
- Type type, SmallVectorImpl<Type> &types) {
+void BufferizeTypeConverter::tryDecomposeType(Type type,
+ SmallVectorImpl<Type> &types) {
for (auto conversion : decomposeTypeConversions)
if (conversion(type, types) != llvm::None)
return;
}
/// This method returns ResultConversionKind for the input type.
-BufferAssignmentTypeConverter::ResultConversionKind
-BufferAssignmentTypeConverter::getResultConversionKind(Type origin,
- Type converted) {
+BufferizeTypeConverter::ResultConversionKind
+BufferizeTypeConverter::getResultConversionKind(Type origin, Type converted) {
for (auto conversion : resultTypeConversions) {
auto res = conversion(origin, converted);
if (res != llvm::None)
}
//===----------------------------------------------------------------------===//
-// BufferAssignmentFuncOpConverter
+// BufferizeFuncOpConverter
//===----------------------------------------------------------------------===//
/// Performs the actual function signature rewriting step.
-LogicalResult BufferAssignmentFuncOpConverter::matchAndRewrite(
+LogicalResult BufferizeFuncOpConverter::matchAndRewrite(
mlir::FuncOp funcOp, ArrayRef<Value> operands,
ConversionPatternRewriter &rewriter) const {
auto funcType = funcOp.getType();
for (auto origin : originTypes) {
Type converted = converter.convertType(origin);
auto kind = converter.getResultConversionKind(origin, converted);
- if (kind == BufferAssignmentTypeConverter::AppendToArgumentsList)
+ if (kind == BufferizeTypeConverter::AppendToArgumentsList)
conversion.addInputs(converted);
else
- // kind = BufferAssignmentTypeConverter::KeepAsFunctionResult
+ // kind = BufferizeTypeConverter::KeepAsFunctionResult
newResultTypes.push_back(converted);
}
}
}
//===----------------------------------------------------------------------===//
-// BufferAssignmentCallOpConverter
+// BufferizeCallOpConverter
//===----------------------------------------------------------------------===//
namespace {
} // namespace
/// Performs the actual rewriting step.
-LogicalResult BufferAssignmentCallOpConverter::matchAndRewrite(
+LogicalResult BufferizeCallOpConverter::matchAndRewrite(
CallOp callOp, ArrayRef<Value> operands,
ConversionPatternRewriter &rewriter) const {
for (Type origin : originTypes) {
Type converted = converter.convertType(origin);
auto kind = converter.getResultConversionKind(origin, converted);
- if (kind == BufferAssignmentTypeConverter::KeepAsFunctionResult) {
+ if (kind == BufferizeTypeConverter::KeepAsFunctionResult) {
newResultTypes.push_back(converted);
// The result value is not yet available. Its index is kept and it is
// replaced with the actual value of the new `CallOp` later.
resultMapping.addMapping(newResultTypes.size() - 1);
} else {
- // kind = BufferAssignmentTypeConverter::AppendToArgumentsList
+ // kind = BufferizeTypeConverter::AppendToArgumentsList
MemRefType memref = converted.dyn_cast<MemRefType>();
if (!memref)
return callOp.emitError("Cannot allocate for a non-Memref type");
// -----
-// Test Case: Simple case for checking if BufferAssignmentPlacer creates AllocOps right before GenericOps.
+// Test Case: Simple case for checking if BufferizePlacer creates AllocOps right before GenericOps.
#map0 = affine_map<(d0) -> (d0)>
// -----
-// Test Case: if-else case for checking if BufferAssignmentPlacer creates AllocOps right before GenericOps.
+// Test Case: if-else case for checking if BufferizePlacer creates AllocOps right before GenericOps.
#map0 = affine_map<(d0) -> (d0)>
// -----
-// Test case: Checking BufferAssignmentCallOpConverter and
-// BufferAssignmentFuncOpConverter and BufferAssignmentReturnOpConverter all
+// Test case: Checking BufferizeCallOpConverter and
+// BufferizeFuncOpConverter and BufferizeReturnOpConverter all
// together. The signature of `callee` after signature conversion would be:
// func @callee(%arg0: memref<5xf32>,%arg1: memref<5xf32>) -> ()
// -----
-// Test case: Checking BufferAssignmentCallOpConverter and
-// BufferAssignmentFuncOpConverter and BufferAssignmentReturnOpConverter all
+// Test case: Checking BufferizeCallOpConverter and
+// BufferizeFuncOpConverter and BufferizeReturnOpConverter all
// together on functions that also have memref typed results. The signature of
// `callee` after signature conversion would be:
using namespace mlir;
namespace {
-/// This pass tests the computeAllocPosition helper method and buffer assignment
+/// This pass tests the computeAllocPosition helper method and bufferize
/// operation converters. Furthermore, this pass converts linalg operations on
/// tensors to linalg operations on buffers to prepare them for the
/// BufferPlacement pass that can be applied afterwards.
OperationPass<ModuleOp>> {
/// Converts tensor-type generic linalg operations to memref ones using
- /// buffer assignment.
+ /// bufferize.
/// TODO: Avoid the copy-pasta by exposing the pattern from BufferPlacement.h
/// This is limited by not wanting BufferPlacement to depend on Linalg. Fixing
/// this probably requires an OpConversionPattern over generic Operation*. For
/// now only RewritePattern but not ConversionPattern allow this.
class GenericOpConverter
- : public BufferAssignmentOpConversionPattern<linalg::GenericOp> {
+ : public BufferizeOpConversionPattern<linalg::GenericOp> {
public:
- using BufferAssignmentOpConversionPattern<
- linalg::GenericOp>::BufferAssignmentOpConversionPattern;
+ using BufferizeOpConversionPattern<
+ linalg::GenericOp>::BufferizeOpConversionPattern;
LogicalResult
matchAndRewrite(linalg::GenericOp op, ArrayRef<Value> operands,
};
void populateTensorLinalgToBufferLinalgConversionPattern(
- MLIRContext *context, BufferAssignmentTypeConverter &converter,
+ MLIRContext *context, BufferizeTypeConverter &converter,
OwningRewritePatternList &patterns) {
- populateWithBufferAssignmentOpConversionPatterns<
- mlir::ReturnOp, mlir::ReturnOp, linalg::CopyOp>(context, converter,
- patterns);
+ populateWithBufferizeOpConversionPatterns<mlir::ReturnOp, mlir::ReturnOp,
+ linalg::CopyOp>(
+ context, converter, patterns);
patterns.insert<GenericOpConverter>(context, converter);
}
void runOnOperation() override {
MLIRContext &context = this->getContext();
ConversionTarget target(context);
- BufferAssignmentTypeConverter converter;
+ BufferizeTypeConverter converter;
// Mark all Standard operations legal.
target.addLegalDialect<StandardOpsDialect>();
});
auto kind = allowMemrefFunctionResults
- ? BufferAssignmentTypeConverter::KeepAsFunctionResult
- : BufferAssignmentTypeConverter::AppendToArgumentsList;
+ ? BufferizeTypeConverter::KeepAsFunctionResult
+ : BufferizeTypeConverter::AppendToArgumentsList;
converter.setResultConversionKind<RankedTensorType, MemRefType>(kind);
converter.setResultConversionKind<UnrankedTensorType, UnrankedMemRefType>(
kind);