diff --git a/mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h b/mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h index 1c715f8b9a53e..ea61ac86b9e08 100644 --- a/mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h +++ b/mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h @@ -243,10 +243,6 @@ struct BufferizationOptions { /// dynamic extents and alignment. using AllocationFn = std::function( OpBuilder &, Location, MemRefType, ValueRange, unsigned int)>; - /// Deallocator function: Deallocate a buffer that was allocated with - /// AllocatorFn. - using DeallocationFn = - std::function; /// Memcpy function: Generate a memcpy between two buffers. using MemCpyFn = std::function; @@ -279,20 +275,14 @@ struct BufferizationOptions { /// Return `true` if the given op should be bufferized. bool isOpAllowed(Operation *op) const; - /// Helper functions for allocation, deallocation, memory copying. + /// Helper functions for allocation and memory copying. std::optional allocationFn; - std::optional deallocationFn; std::optional memCpyFn; /// Create a memref allocation with the given type and dynamic extents. FailureOr createAlloc(OpBuilder &b, Location loc, MemRefType type, ValueRange dynShape) const; - /// Creates a memref deallocation. The given memref buffer must have been - /// allocated using `createAlloc`. - LogicalResult createDealloc(OpBuilder &b, Location loc, - Value allocatedBuffer) const; - /// Creates a memcpy between two given buffers. LogicalResult createMemCpy(OpBuilder &b, Location loc, Value from, Value to) const; diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp index 57cd303d2076e..c73f7067e5d6e 100644 --- a/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp +++ b/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp @@ -220,9 +220,6 @@ LogicalResult BufferizableOpInterface::resolveTensorOpOperandConflicts( return op->emitError("copying of unranked tensors is not implemented"); AliasingValueList aliasingValues = state.getAliasingValues(opOperand); - // Is the result yielded from a block? Or are deallocations turned off - // entirely? In either case, mark the allocation as "escaping", so that it - // will not be deallocated. if (aliasingValues.getNumAliases() == 1 && isa(aliasingValues.getAliases()[0].value) && !state.bufferizesToMemoryWrite(opOperand) && @@ -770,7 +767,7 @@ void bufferization::replaceOpWithBufferizedValues(RewriterBase &rewriter, } //===----------------------------------------------------------------------===// -// Bufferization-specific scoped alloc/dealloc insertion support. +// Bufferization-specific scoped alloc insertion support. //===----------------------------------------------------------------------===// /// Create a memref allocation with the given type and dynamic extents. @@ -789,18 +786,6 @@ FailureOr BufferizationOptions::createAlloc(OpBuilder &b, Location loc, return b.create(loc, type, dynShape).getResult(); } -/// Creates a memref deallocation. The given memref buffer must have been -/// allocated using `createAlloc`. -LogicalResult BufferizationOptions::createDealloc(OpBuilder &b, Location loc, - Value allocatedBuffer) const { - if (deallocationFn) - return (*deallocationFn)(b, loc, allocatedBuffer); - - // Default buffer deallocation via DeallocOp. - b.create(loc, allocatedBuffer); - return success(); -} - /// Create a memory copy between two memref buffers. LogicalResult BufferizationOptions::createMemCpy(OpBuilder &b, Location loc, Value from, Value to) const { diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp index 745333de65815..7c6c1be351cce 100644 --- a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp +++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp @@ -526,8 +526,7 @@ LogicalResult DeallocTensorOp::bufferize(RewriterBase &rewriter, FailureOr buffer = getBuffer(rewriter, getTensor(), options); if (failed(buffer)) return failure(); - if (failed(options.createDealloc(rewriter, getLoc(), *buffer))) - return failure(); + rewriter.create(getLoc(), *buffer); rewriter.eraseOp(getOperation()); return success(); }