Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@ struct BufferizationOptions {
/// dynamic extents and alignment.
using AllocationFn = std::function<FailureOr<Value>(
OpBuilder &, Location, MemRefType, ValueRange, unsigned int)>;
/// Deallocator function: Deallocate a buffer that was allocated with
/// AllocatorFn.
using DeallocationFn =
std::function<LogicalResult(OpBuilder &, Location, Value)>;
/// Memcpy function: Generate a memcpy between two buffers.
using MemCpyFn =
std::function<LogicalResult(OpBuilder &, Location, Value, Value)>;
Expand Down Expand Up @@ -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> allocationFn;
std::optional<DeallocationFn> deallocationFn;
std::optional<MemCpyFn> memCpyFn;

/// Create a memref allocation with the given type and dynamic extents.
FailureOr<Value> 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;
Expand Down
17 changes: 1 addition & 16 deletions mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<OpResult>(aliasingValues.getAliases()[0].value) &&
!state.bufferizesToMemoryWrite(opOperand) &&
Expand Down Expand Up @@ -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.
Expand All @@ -789,18 +786,6 @@ FailureOr<Value> BufferizationOptions::createAlloc(OpBuilder &b, Location loc,
return b.create<memref::AllocOp>(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<memref::DeallocOp>(loc, allocatedBuffer);
return success();
}

/// Create a memory copy between two memref buffers.
LogicalResult BufferizationOptions::createMemCpy(OpBuilder &b, Location loc,
Value from, Value to) const {
Expand Down
3 changes: 1 addition & 2 deletions mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,7 @@ LogicalResult DeallocTensorOp::bufferize(RewriterBase &rewriter,
FailureOr<Value> buffer = getBuffer(rewriter, getTensor(), options);
if (failed(buffer))
return failure();
if (failed(options.createDealloc(rewriter, getLoc(), *buffer)))
return failure();
rewriter.create<memref::DeallocOp>(getLoc(), *buffer);
rewriter.eraseOp(getOperation());
return success();
}
Expand Down