Skip to content

Commit caa2a4a

Browse files
[mlir][bufferization] Remove deallocationFn from BufferizationOptions (#67128)
One-Shot Bufferize no longer deallocates buffers, so `deallocationFn` can be removed. Note: There is a `bufferization.dealloc_tensor` op that now always bufferizes to `memref.dealloc`. This op will be phased out soon.
1 parent 1a3abc2 commit caa2a4a

File tree

3 files changed

+3
-29
lines changed

3 files changed

+3
-29
lines changed

mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,6 @@ struct BufferizationOptions {
243243
/// dynamic extents and alignment.
244244
using AllocationFn = std::function<FailureOr<Value>(
245245
OpBuilder &, Location, MemRefType, ValueRange, unsigned int)>;
246-
/// Deallocator function: Deallocate a buffer that was allocated with
247-
/// AllocatorFn.
248-
using DeallocationFn =
249-
std::function<LogicalResult(OpBuilder &, Location, Value)>;
250246
/// Memcpy function: Generate a memcpy between two buffers.
251247
using MemCpyFn =
252248
std::function<LogicalResult(OpBuilder &, Location, Value, Value)>;
@@ -279,20 +275,14 @@ struct BufferizationOptions {
279275
/// Return `true` if the given op should be bufferized.
280276
bool isOpAllowed(Operation *op) const;
281277

282-
/// Helper functions for allocation, deallocation, memory copying.
278+
/// Helper functions for allocation and memory copying.
283279
std::optional<AllocationFn> allocationFn;
284-
std::optional<DeallocationFn> deallocationFn;
285280
std::optional<MemCpyFn> memCpyFn;
286281

287282
/// Create a memref allocation with the given type and dynamic extents.
288283
FailureOr<Value> createAlloc(OpBuilder &b, Location loc, MemRefType type,
289284
ValueRange dynShape) const;
290285

291-
/// Creates a memref deallocation. The given memref buffer must have been
292-
/// allocated using `createAlloc`.
293-
LogicalResult createDealloc(OpBuilder &b, Location loc,
294-
Value allocatedBuffer) const;
295-
296286
/// Creates a memcpy between two given buffers.
297287
LogicalResult createMemCpy(OpBuilder &b, Location loc, Value from,
298288
Value to) const;

mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,6 @@ LogicalResult BufferizableOpInterface::resolveTensorOpOperandConflicts(
220220
return op->emitError("copying of unranked tensors is not implemented");
221221

222222
AliasingValueList aliasingValues = state.getAliasingValues(opOperand);
223-
// Is the result yielded from a block? Or are deallocations turned off
224-
// entirely? In either case, mark the allocation as "escaping", so that it
225-
// will not be deallocated.
226223
if (aliasingValues.getNumAliases() == 1 &&
227224
isa<OpResult>(aliasingValues.getAliases()[0].value) &&
228225
!state.bufferizesToMemoryWrite(opOperand) &&
@@ -723,7 +720,7 @@ void bufferization::replaceOpWithBufferizedValues(RewriterBase &rewriter,
723720
}
724721

725722
//===----------------------------------------------------------------------===//
726-
// Bufferization-specific scoped alloc/dealloc insertion support.
723+
// Bufferization-specific scoped alloc insertion support.
727724
//===----------------------------------------------------------------------===//
728725

729726
/// Create a memref allocation with the given type and dynamic extents.
@@ -742,18 +739,6 @@ FailureOr<Value> BufferizationOptions::createAlloc(OpBuilder &b, Location loc,
742739
return b.create<memref::AllocOp>(loc, type, dynShape).getResult();
743740
}
744741

745-
/// Creates a memref deallocation. The given memref buffer must have been
746-
/// allocated using `createAlloc`.
747-
LogicalResult BufferizationOptions::createDealloc(OpBuilder &b, Location loc,
748-
Value allocatedBuffer) const {
749-
if (deallocationFn)
750-
return (*deallocationFn)(b, loc, allocatedBuffer);
751-
752-
// Default buffer deallocation via DeallocOp.
753-
b.create<memref::DeallocOp>(loc, allocatedBuffer);
754-
return success();
755-
}
756-
757742
/// Create a memory copy between two memref buffers.
758743
LogicalResult BufferizationOptions::createMemCpy(OpBuilder &b, Location loc,
759744
Value from, Value to) const {

mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,7 @@ LogicalResult DeallocTensorOp::bufferize(RewriterBase &rewriter,
526526
FailureOr<Value> buffer = getBuffer(rewriter, getTensor(), options);
527527
if (failed(buffer))
528528
return failure();
529-
if (failed(options.createDealloc(rewriter, getLoc(), *buffer)))
530-
return failure();
529+
rewriter.create<memref::DeallocOp>(getLoc(), *buffer);
531530
rewriter.eraseOp(getOperation());
532531
return success();
533532
}

0 commit comments

Comments
 (0)