-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[mlir][bufferization] Remove remaining dialect conversion-based infra parts #114155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir][bufferization] Remove remaining dialect conversion-based infra parts #114155
Conversation
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-func Author: Matthias Springer (matthias-springer) ChangesThis 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. Depends on #114154. Full diff: https://github.com/llvm/llvm-project/pull/114155.diff 4 Files Affected:
diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h b/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
index ebed2c354bfca5..2f495d304b4a56 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
@@ -38,24 +38,6 @@ struct BufferizationStatistics {
int64_t numTensorOutOfPlace = 0;
};
-/// A helper type converter class that automatically populates the relevant
-/// materializations and type conversions for bufferization.
-class BufferizeTypeConverter : public TypeConverter {
-public:
- BufferizeTypeConverter();
-};
-
-/// Marks ops used by bufferization for type conversion materializations as
-/// "legal" in the given ConversionTarget.
-///
-/// This function should be called by all bufferization passes using
-/// BufferizeTypeConverter so that materializations work properly. One exception
-/// is bufferization passes doing "full" conversions, where it can be desirable
-/// for even the materializations to remain illegal so that they are eliminated,
-/// such as via the patterns in
-/// populateEliminateBufferizeMaterializationsPatterns.
-void populateBufferizeMaterializationLegality(ConversionTarget &target);
-
/// Bufferize `op` and its nested ops that implement `BufferizableOpInterface`.
///
/// Note: This function does not resolve read-after-write conflicts. Use this
@@ -81,11 +63,6 @@ LogicalResult bufferizeOp(Operation *op, const BufferizationOptions &options,
LogicalResult bufferizeBlockSignature(Block *block, RewriterBase &rewriter,
const BufferizationOptions &options);
-/// Return `BufferizationOptions` such that the `bufferizeOp` behaves like the
-/// old (deprecated) partial, dialect conversion-based bufferization passes. A
-/// copy will be inserted before every buffer write.
-BufferizationOptions getPartialBufferizationOptions();
-
} // namespace bufferization
} // namespace mlir
diff --git a/mlir/include/mlir/Dialect/Func/Transforms/Passes.h b/mlir/include/mlir/Dialect/Func/Transforms/Passes.h
index 02fc9e1d934390..0248f068320c54 100644
--- a/mlir/include/mlir/Dialect/Func/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/Func/Transforms/Passes.h
@@ -18,10 +18,6 @@
#include "mlir/Pass/Pass.h"
namespace mlir {
-namespace bufferization {
-class BufferizeTypeConverter;
-} // namespace bufferization
-
class RewritePatternSet;
namespace func {
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
index 8fffdbf664c3f4..da77a735cd59d7 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
@@ -11,6 +11,8 @@
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/Bufferization/Transforms/BufferUtils.h"
+
+#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
#include "mlir/Dialect/Bufferization/Transforms/Bufferize.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/MemRef/Utils/MemRefUtils.h"
@@ -138,8 +140,7 @@ bufferization::getGlobalFor(arith::ConstantOp constantOp, uint64_t alignment,
alignment > 0 ? IntegerAttr::get(globalBuilder.getI64Type(), alignment)
: IntegerAttr();
- BufferizeTypeConverter typeConverter;
- auto memrefType = cast<MemRefType>(typeConverter.convertType(type));
+ auto memrefType = cast<MemRefType>(getMemRefTypeWithStaticIdentityLayout(type));
if (memorySpace)
memrefType = MemRefType::Builder(memrefType).setMemorySpace(memorySpace);
auto global = globalBuilder.create<memref::GlobalOp>(
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
index 62ce2583f4fa1d..6f0cdfa20f7be5 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
@@ -37,65 +37,6 @@ namespace bufferization {
using namespace mlir;
using namespace mlir::bufferization;
-//===----------------------------------------------------------------------===//
-// BufferizeTypeConverter
-//===----------------------------------------------------------------------===//
-
-static Value materializeToTensor(OpBuilder &builder, TensorType type,
- ValueRange inputs, Location loc) {
- assert(inputs.size() == 1);
- assert(isa<BaseMemRefType>(inputs[0].getType()));
- return builder.create<bufferization::ToTensorOp>(loc, type, inputs[0]);
-}
-
-/// Registers conversions into BufferizeTypeConverter
-BufferizeTypeConverter::BufferizeTypeConverter() {
- // Keep all types unchanged.
- addConversion([](Type type) { return type; });
- // Convert RankedTensorType to MemRefType.
- addConversion([](RankedTensorType type) -> Type {
- return MemRefType::get(type.getShape(), type.getElementType());
- });
- // Convert UnrankedTensorType to UnrankedMemRefType.
- addConversion([](UnrankedTensorType type) -> Type {
- return UnrankedMemRefType::get(type.getElementType(), 0);
- });
- addArgumentMaterialization(materializeToTensor);
- addSourceMaterialization(materializeToTensor);
- addTargetMaterialization([](OpBuilder &builder, BaseMemRefType type,
- ValueRange inputs, Location loc) -> Value {
- assert(inputs.size() == 1 && "expected exactly one input");
-
- if (auto inputType = dyn_cast<MemRefType>(inputs[0].getType())) {
- // MemRef to MemRef cast.
- assert(inputType != type && "expected different types");
- // Unranked to ranked and ranked to unranked casts must be explicit.
- auto rankedDestType = dyn_cast<MemRefType>(type);
- if (!rankedDestType)
- return nullptr;
- BufferizationOptions options;
- options.bufferAlignment = 0;
- FailureOr<Value> replacement =
- castOrReallocMemRefValue(builder, inputs[0], rankedDestType, options);
- if (failed(replacement))
- return nullptr;
- return *replacement;
- }
-
- if (isa<TensorType>(inputs[0].getType())) {
- // Tensor to MemRef cast.
- return builder.create<bufferization::ToMemrefOp>(loc, type, inputs[0]);
- }
-
- llvm_unreachable("only tensor/memref input types supported");
- });
-}
-
-void mlir::bufferization::populateBufferizeMaterializationLegality(
- ConversionTarget &target) {
- target.addLegalOp<bufferization::ToTensorOp, bufferization::ToMemrefOp>();
-}
-
namespace {
static LayoutMapOption parseLayoutMapOption(const std::string &s) {
@@ -545,17 +486,3 @@ bufferization::bufferizeBlockSignature(Block *block, RewriterBase &rewriter,
return success();
}
-
-BufferizationOptions bufferization::getPartialBufferizationOptions() {
- BufferizationOptions options;
- options.allowUnknownOps = true;
- options.copyBeforeWrite = true;
- options.enforceAliasingInvariants = false;
- options.unknownTypeConverterFn = [](Value value, Attribute memorySpace,
- const BufferizationOptions &options) {
- return getMemRefTypeWithStaticIdentityLayout(
- cast<TensorType>(value.getType()), memorySpace);
- };
- options.opFilter.allowDialect<BufferizationDialect>();
- return options;
-}
|
@llvm/pr-subscribers-mlir-bufferization Author: Matthias Springer (matthias-springer) ChangesThis 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. Depends on #114154. Full diff: https://github.com/llvm/llvm-project/pull/114155.diff 4 Files Affected:
diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h b/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
index ebed2c354bfca5..2f495d304b4a56 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
@@ -38,24 +38,6 @@ struct BufferizationStatistics {
int64_t numTensorOutOfPlace = 0;
};
-/// A helper type converter class that automatically populates the relevant
-/// materializations and type conversions for bufferization.
-class BufferizeTypeConverter : public TypeConverter {
-public:
- BufferizeTypeConverter();
-};
-
-/// Marks ops used by bufferization for type conversion materializations as
-/// "legal" in the given ConversionTarget.
-///
-/// This function should be called by all bufferization passes using
-/// BufferizeTypeConverter so that materializations work properly. One exception
-/// is bufferization passes doing "full" conversions, where it can be desirable
-/// for even the materializations to remain illegal so that they are eliminated,
-/// such as via the patterns in
-/// populateEliminateBufferizeMaterializationsPatterns.
-void populateBufferizeMaterializationLegality(ConversionTarget &target);
-
/// Bufferize `op` and its nested ops that implement `BufferizableOpInterface`.
///
/// Note: This function does not resolve read-after-write conflicts. Use this
@@ -81,11 +63,6 @@ LogicalResult bufferizeOp(Operation *op, const BufferizationOptions &options,
LogicalResult bufferizeBlockSignature(Block *block, RewriterBase &rewriter,
const BufferizationOptions &options);
-/// Return `BufferizationOptions` such that the `bufferizeOp` behaves like the
-/// old (deprecated) partial, dialect conversion-based bufferization passes. A
-/// copy will be inserted before every buffer write.
-BufferizationOptions getPartialBufferizationOptions();
-
} // namespace bufferization
} // namespace mlir
diff --git a/mlir/include/mlir/Dialect/Func/Transforms/Passes.h b/mlir/include/mlir/Dialect/Func/Transforms/Passes.h
index 02fc9e1d934390..0248f068320c54 100644
--- a/mlir/include/mlir/Dialect/Func/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/Func/Transforms/Passes.h
@@ -18,10 +18,6 @@
#include "mlir/Pass/Pass.h"
namespace mlir {
-namespace bufferization {
-class BufferizeTypeConverter;
-} // namespace bufferization
-
class RewritePatternSet;
namespace func {
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
index 8fffdbf664c3f4..da77a735cd59d7 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
@@ -11,6 +11,8 @@
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/Bufferization/Transforms/BufferUtils.h"
+
+#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
#include "mlir/Dialect/Bufferization/Transforms/Bufferize.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/MemRef/Utils/MemRefUtils.h"
@@ -138,8 +140,7 @@ bufferization::getGlobalFor(arith::ConstantOp constantOp, uint64_t alignment,
alignment > 0 ? IntegerAttr::get(globalBuilder.getI64Type(), alignment)
: IntegerAttr();
- BufferizeTypeConverter typeConverter;
- auto memrefType = cast<MemRefType>(typeConverter.convertType(type));
+ auto memrefType = cast<MemRefType>(getMemRefTypeWithStaticIdentityLayout(type));
if (memorySpace)
memrefType = MemRefType::Builder(memrefType).setMemorySpace(memorySpace);
auto global = globalBuilder.create<memref::GlobalOp>(
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
index 62ce2583f4fa1d..6f0cdfa20f7be5 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
@@ -37,65 +37,6 @@ namespace bufferization {
using namespace mlir;
using namespace mlir::bufferization;
-//===----------------------------------------------------------------------===//
-// BufferizeTypeConverter
-//===----------------------------------------------------------------------===//
-
-static Value materializeToTensor(OpBuilder &builder, TensorType type,
- ValueRange inputs, Location loc) {
- assert(inputs.size() == 1);
- assert(isa<BaseMemRefType>(inputs[0].getType()));
- return builder.create<bufferization::ToTensorOp>(loc, type, inputs[0]);
-}
-
-/// Registers conversions into BufferizeTypeConverter
-BufferizeTypeConverter::BufferizeTypeConverter() {
- // Keep all types unchanged.
- addConversion([](Type type) { return type; });
- // Convert RankedTensorType to MemRefType.
- addConversion([](RankedTensorType type) -> Type {
- return MemRefType::get(type.getShape(), type.getElementType());
- });
- // Convert UnrankedTensorType to UnrankedMemRefType.
- addConversion([](UnrankedTensorType type) -> Type {
- return UnrankedMemRefType::get(type.getElementType(), 0);
- });
- addArgumentMaterialization(materializeToTensor);
- addSourceMaterialization(materializeToTensor);
- addTargetMaterialization([](OpBuilder &builder, BaseMemRefType type,
- ValueRange inputs, Location loc) -> Value {
- assert(inputs.size() == 1 && "expected exactly one input");
-
- if (auto inputType = dyn_cast<MemRefType>(inputs[0].getType())) {
- // MemRef to MemRef cast.
- assert(inputType != type && "expected different types");
- // Unranked to ranked and ranked to unranked casts must be explicit.
- auto rankedDestType = dyn_cast<MemRefType>(type);
- if (!rankedDestType)
- return nullptr;
- BufferizationOptions options;
- options.bufferAlignment = 0;
- FailureOr<Value> replacement =
- castOrReallocMemRefValue(builder, inputs[0], rankedDestType, options);
- if (failed(replacement))
- return nullptr;
- return *replacement;
- }
-
- if (isa<TensorType>(inputs[0].getType())) {
- // Tensor to MemRef cast.
- return builder.create<bufferization::ToMemrefOp>(loc, type, inputs[0]);
- }
-
- llvm_unreachable("only tensor/memref input types supported");
- });
-}
-
-void mlir::bufferization::populateBufferizeMaterializationLegality(
- ConversionTarget &target) {
- target.addLegalOp<bufferization::ToTensorOp, bufferization::ToMemrefOp>();
-}
-
namespace {
static LayoutMapOption parseLayoutMapOption(const std::string &s) {
@@ -545,17 +486,3 @@ bufferization::bufferizeBlockSignature(Block *block, RewriterBase &rewriter,
return success();
}
-
-BufferizationOptions bufferization::getPartialBufferizationOptions() {
- BufferizationOptions options;
- options.allowUnknownOps = true;
- options.copyBeforeWrite = true;
- options.enforceAliasingInvariants = false;
- options.unknownTypeConverterFn = [](Value value, Attribute memorySpace,
- const BufferizationOptions &options) {
- return getMemRefTypeWithStaticIdentityLayout(
- cast<TensorType>(value.getType()), memorySpace);
- };
- options.opFilter.allowDialect<BufferizationDialect>();
- return options;
-}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
9192d2d
to
d1d51e3
Compare
7c2f6b6
to
e0b61b5
Compare
mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp
Outdated
Show resolved
Hide resolved
e0b61b5
to
1e194b3
Compare
d1d51e3
to
5c02edc
Compare
1beeac3
to
5353a10
Compare
71721ff
to
af499b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
I am thinking whether it would be helpful if you mention somewhere (Bufferize.h) about the old-bufferizer; also, why type-converter was there and no longer needed etc.
When people run into errors (or discover that their merge fails) the comment might give them some guidance.
They are going to find this commit during the integrate. The commit message should be enough. That's why I put |
… parts 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. Depends on #114154.
af499b3
to
4cce2a8
Compare
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.
Depends on #114154.