[Mlir-commits] [mlir] 7c6419b - [NFC][mlir][bufferization] Move AllocationOpInterface implementations (#65578)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Sep 7 00:59:55 PDT 2023
Author: Martin Erhart
Date: 2023-09-07T09:59:51+02:00
New Revision: 7c6419bc3c836538fc68b84a3a7621ecf21cc70c
URL: https://github.com/llvm/llvm-project/commit/7c6419bc3c836538fc68b84a3a7621ecf21cc70c
DIFF: https://github.com/llvm/llvm-project/commit/7c6419bc3c836538fc68b84a3a7621ecf21cc70c.diff
LOG: [NFC][mlir][bufferization] Move AllocationOpInterface implementations (#65578)
The new Buffer Deallocation pass introduced in D158421 will not need the
AllocationOpInterface anymore, thus it is better to move those default
implementations to a place where they will still be used.
Added:
Modified:
mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp b/mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
index 9a831e4c322ea0e..f74c6255c196ba5 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
@@ -625,46 +625,6 @@ class BufferDeallocation : public BufferPlacementTransformationBase {
// BufferDeallocationPass
//===----------------------------------------------------------------------===//
-struct DefaultAllocationInterface
- : public bufferization::AllocationOpInterface::ExternalModel<
- DefaultAllocationInterface, memref::AllocOp> {
- static std::optional<Operation *> buildDealloc(OpBuilder &builder,
- Value alloc) {
- return builder.create<memref::DeallocOp>(alloc.getLoc(), alloc)
- .getOperation();
- }
- static std::optional<Value> buildClone(OpBuilder &builder, Value alloc) {
- return builder.create<bufferization::CloneOp>(alloc.getLoc(), alloc)
- .getResult();
- }
- static ::mlir::HoistingKind getHoistingKind() {
- return HoistingKind::Loop | HoistingKind::Block;
- }
- static ::std::optional<::mlir::Operation *>
- buildPromotedAlloc(OpBuilder &builder, Value alloc) {
- Operation *definingOp = alloc.getDefiningOp();
- return builder.create<memref::AllocaOp>(
- definingOp->getLoc(), cast<MemRefType>(definingOp->getResultTypes()[0]),
- definingOp->getOperands(), definingOp->getAttrs());
- }
-};
-
-struct DefaultAutomaticAllocationHoistingInterface
- : public bufferization::AllocationOpInterface::ExternalModel<
- DefaultAutomaticAllocationHoistingInterface, memref::AllocaOp> {
- static ::mlir::HoistingKind getHoistingKind() { return HoistingKind::Loop; }
-};
-
-struct DefaultReallocationInterface
- : public bufferization::AllocationOpInterface::ExternalModel<
- DefaultAllocationInterface, memref::ReallocOp> {
- static std::optional<Operation *> buildDealloc(OpBuilder &builder,
- Value realloc) {
- return builder.create<memref::DeallocOp>(realloc.getLoc(), realloc)
- .getOperation();
- }
-};
-
/// The actual buffer deallocation pass that inserts and moves dealloc nodes
/// into the right positions. Furthermore, it inserts additional clones if
/// necessary. It uses the algorithm described at the top of the file.
@@ -725,16 +685,6 @@ LogicalResult bufferization::deallocateBuffers(Operation *op) {
return success();
}
-void bufferization::registerAllocationOpInterfaceExternalModels(
- DialectRegistry ®istry) {
- registry.addExtension(+[](MLIRContext *ctx, memref::MemRefDialect *dialect) {
- memref::AllocOp::attachInterface<DefaultAllocationInterface>(*ctx);
- memref::AllocaOp::attachInterface<
- DefaultAutomaticAllocationHoistingInterface>(*ctx);
- memref::ReallocOp::attachInterface<DefaultReallocationInterface>(*ctx);
- });
-}
-
//===----------------------------------------------------------------------===//
// BufferDeallocationPass construction
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
index 8fca041fe6aaa69..7358d0d465d3e3d 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
@@ -682,3 +682,59 @@ BufferizationOptions bufferization::getPartialBufferizationOptions() {
options.opFilter.allowDialect<BufferizationDialect>();
return options;
}
+
+//===----------------------------------------------------------------------===//
+// Default AllocationOpInterface implementation and registration
+//===----------------------------------------------------------------------===//
+
+namespace {
+struct DefaultAllocationInterface
+ : public bufferization::AllocationOpInterface::ExternalModel<
+ DefaultAllocationInterface, memref::AllocOp> {
+ static std::optional<Operation *> buildDealloc(OpBuilder &builder,
+ Value alloc) {
+ return builder.create<memref::DeallocOp>(alloc.getLoc(), alloc)
+ .getOperation();
+ }
+ static std::optional<Value> buildClone(OpBuilder &builder, Value alloc) {
+ return builder.create<bufferization::CloneOp>(alloc.getLoc(), alloc)
+ .getResult();
+ }
+ static ::mlir::HoistingKind getHoistingKind() {
+ return HoistingKind::Loop | HoistingKind::Block;
+ }
+ static ::std::optional<::mlir::Operation *>
+ buildPromotedAlloc(OpBuilder &builder, Value alloc) {
+ Operation *definingOp = alloc.getDefiningOp();
+ return builder.create<memref::AllocaOp>(
+ definingOp->getLoc(), cast<MemRefType>(definingOp->getResultTypes()[0]),
+ definingOp->getOperands(), definingOp->getAttrs());
+ }
+};
+
+struct DefaultAutomaticAllocationHoistingInterface
+ : public bufferization::AllocationOpInterface::ExternalModel<
+ DefaultAutomaticAllocationHoistingInterface, memref::AllocaOp> {
+ static ::mlir::HoistingKind getHoistingKind() { return HoistingKind::Loop; }
+};
+
+struct DefaultReallocationInterface
+ : public bufferization::AllocationOpInterface::ExternalModel<
+ DefaultAllocationInterface, memref::ReallocOp> {
+ static std::optional<Operation *> buildDealloc(OpBuilder &builder,
+ Value realloc) {
+ return builder.create<memref::DeallocOp>(realloc.getLoc(), realloc)
+ .getOperation();
+ }
+};
+} // namespace
+
+void bufferization::registerAllocationOpInterfaceExternalModels(
+ DialectRegistry ®istry) {
+ registry.addExtension(+[](MLIRContext *ctx, memref::MemRefDialect *dialect) {
+ memref::AllocOp::attachInterface<DefaultAllocationInterface>(*ctx);
+ memref::AllocaOp::attachInterface<
+ DefaultAutomaticAllocationHoistingInterface>(*ctx);
+ memref::ReallocOp::attachInterface<DefaultReallocationInterface>(*ctx);
+ });
+}
More information about the Mlir-commits
mailing list