Skip to content

Commit 2ff2e87

Browse files
[mlir][bufferization] Remove remaining dialect conversion-based infra parts (#114155)
This commit removes the last remaining components of the dialect conversion-based bufferization passes. Note for LLVM integration: If you depend on these components, migrate to One-Shot Bufferize or copy them to your codebase.
1 parent f87cabe commit 2ff2e87

File tree

4 files changed

+5
-102
lines changed

4 files changed

+5
-102
lines changed

mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,6 @@ struct BufferizationStatistics {
3838
int64_t numTensorOutOfPlace = 0;
3939
};
4040

41-
/// A helper type converter class that automatically populates the relevant
42-
/// materializations and type conversions for bufferization.
43-
class BufferizeTypeConverter : public TypeConverter {
44-
public:
45-
BufferizeTypeConverter();
46-
};
47-
48-
/// Marks ops used by bufferization for type conversion materializations as
49-
/// "legal" in the given ConversionTarget.
50-
///
51-
/// This function should be called by all bufferization passes using
52-
/// BufferizeTypeConverter so that materializations work properly. One exception
53-
/// is bufferization passes doing "full" conversions, where it can be desirable
54-
/// for even the materializations to remain illegal so that they are eliminated,
55-
/// such as via the patterns in
56-
/// populateEliminateBufferizeMaterializationsPatterns.
57-
void populateBufferizeMaterializationLegality(ConversionTarget &target);
58-
5941
/// Bufferize `op` and its nested ops that implement `BufferizableOpInterface`.
6042
///
6143
/// Note: This function does not resolve read-after-write conflicts. Use this
@@ -81,11 +63,6 @@ LogicalResult bufferizeOp(Operation *op, const BufferizationOptions &options,
8163
LogicalResult bufferizeBlockSignature(Block *block, RewriterBase &rewriter,
8264
const BufferizationOptions &options);
8365

84-
/// Return `BufferizationOptions` such that the `bufferizeOp` behaves like the
85-
/// old (deprecated) partial, dialect conversion-based bufferization passes. A
86-
/// copy will be inserted before every buffer write.
87-
BufferizationOptions getPartialBufferizationOptions();
88-
8966
} // namespace bufferization
9067
} // namespace mlir
9168

mlir/include/mlir/Dialect/Func/Transforms/Passes.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
#include "mlir/Pass/Pass.h"
1919

2020
namespace mlir {
21-
namespace bufferization {
22-
class BufferizeTypeConverter;
23-
} // namespace bufferization
24-
2521
class RewritePatternSet;
2622

2723
namespace func {

mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "mlir/Dialect/Bufferization/Transforms/BufferUtils.h"
14+
15+
#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
1416
#include "mlir/Dialect/Bufferization/Transforms/Bufferize.h"
1517
#include "mlir/Dialect/MemRef/IR/MemRef.h"
1618
#include "mlir/Dialect/MemRef/Utils/MemRefUtils.h"
@@ -138,8 +140,9 @@ bufferization::getGlobalFor(arith::ConstantOp constantOp, uint64_t alignment,
138140
alignment > 0 ? IntegerAttr::get(globalBuilder.getI64Type(), alignment)
139141
: IntegerAttr();
140142

141-
BufferizeTypeConverter typeConverter;
142-
auto memrefType = cast<MemRefType>(typeConverter.convertType(type));
143+
// Memref globals always have an identity layout.
144+
auto memrefType =
145+
cast<MemRefType>(getMemRefTypeWithStaticIdentityLayout(type));
143146
if (memorySpace)
144147
memrefType = MemRefType::Builder(memrefType).setMemorySpace(memorySpace);
145148
auto global = globalBuilder.create<memref::GlobalOp>(

mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -37,65 +37,6 @@ namespace bufferization {
3737
using namespace mlir;
3838
using namespace mlir::bufferization;
3939

40-
//===----------------------------------------------------------------------===//
41-
// BufferizeTypeConverter
42-
//===----------------------------------------------------------------------===//
43-
44-
static Value materializeToTensor(OpBuilder &builder, TensorType type,
45-
ValueRange inputs, Location loc) {
46-
assert(inputs.size() == 1);
47-
assert(isa<BaseMemRefType>(inputs[0].getType()));
48-
return builder.create<bufferization::ToTensorOp>(loc, type, inputs[0]);
49-
}
50-
51-
/// Registers conversions into BufferizeTypeConverter
52-
BufferizeTypeConverter::BufferizeTypeConverter() {
53-
// Keep all types unchanged.
54-
addConversion([](Type type) { return type; });
55-
// Convert RankedTensorType to MemRefType.
56-
addConversion([](RankedTensorType type) -> Type {
57-
return MemRefType::get(type.getShape(), type.getElementType());
58-
});
59-
// Convert UnrankedTensorType to UnrankedMemRefType.
60-
addConversion([](UnrankedTensorType type) -> Type {
61-
return UnrankedMemRefType::get(type.getElementType(), 0);
62-
});
63-
addArgumentMaterialization(materializeToTensor);
64-
addSourceMaterialization(materializeToTensor);
65-
addTargetMaterialization([](OpBuilder &builder, BaseMemRefType type,
66-
ValueRange inputs, Location loc) -> Value {
67-
assert(inputs.size() == 1 && "expected exactly one input");
68-
69-
if (auto inputType = dyn_cast<MemRefType>(inputs[0].getType())) {
70-
// MemRef to MemRef cast.
71-
assert(inputType != type && "expected different types");
72-
// Ranked to unranked casts must be explicit.
73-
auto rankedDestType = dyn_cast<MemRefType>(type);
74-
if (!rankedDestType)
75-
return nullptr;
76-
BufferizationOptions options;
77-
options.bufferAlignment = 0;
78-
FailureOr<Value> replacement =
79-
castOrReallocMemRefValue(builder, inputs[0], rankedDestType, options);
80-
if (failed(replacement))
81-
return nullptr;
82-
return *replacement;
83-
}
84-
85-
if (isa<TensorType>(inputs[0].getType())) {
86-
// Tensor to MemRef cast.
87-
return builder.create<bufferization::ToMemrefOp>(loc, type, inputs[0]);
88-
}
89-
90-
llvm_unreachable("only tensor/memref input types supported");
91-
});
92-
}
93-
94-
void mlir::bufferization::populateBufferizeMaterializationLegality(
95-
ConversionTarget &target) {
96-
target.addLegalOp<bufferization::ToTensorOp, bufferization::ToMemrefOp>();
97-
}
98-
9940
namespace {
10041

10142
static LayoutMapOption parseLayoutMapOption(const std::string &s) {
@@ -564,17 +505,3 @@ bufferization::bufferizeBlockSignature(Block *block, RewriterBase &rewriter,
564505

565506
return success();
566507
}
567-
568-
BufferizationOptions bufferization::getPartialBufferizationOptions() {
569-
BufferizationOptions options;
570-
options.allowUnknownOps = true;
571-
options.copyBeforeWrite = true;
572-
options.enforceAliasingInvariants = false;
573-
options.unknownTypeConverterFn = [](Value value, Attribute memorySpace,
574-
const BufferizationOptions &options) {
575-
return getMemRefTypeWithStaticIdentityLayout(
576-
cast<TensorType>(value.getType()), memorySpace);
577-
};
578-
options.opFilter.allowDialect<BufferizationDialect>();
579-
return options;
580-
}

0 commit comments

Comments
 (0)