[Mlir-commits] [mlir] [mlir][bufferization] Move AllocationOpInterface implementations (PR #65578)
Mehdi Amini
llvmlistbot at llvm.org
Thu Sep 7 14:26:29 PDT 2023
================
@@ -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(
----------------
joker-eph wrote:
The name of the API really does not reflect that this is about the Memref dialect.
It's also not clear to me why lib/Dialect/Bufferization/Bufferize.cpp is the place to register an implementation of an interface for the Memref dialect?
https://github.com/llvm/llvm-project/pull/65578
More information about the Mlir-commits
mailing list