Skip to content

Commit f767c20

Browse files
mscuttariDhruvSrivastavaX
authored andcommitted
[MLIR] Keep cached symbol tables across buffer deallocation insertions (llvm#141956)
The `DeallocationState` class has been modified to keep a reference to an externally owned `SymbolTableCollection` class, to preserve the cached symbol tables across multiple insertions of deallocation instructions.
1 parent 3c988db commit f767c20

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct DeallocationOptions {
104104
/// BufferDeallocation pass.
105105
class DeallocationState {
106106
public:
107-
DeallocationState(Operation *op);
107+
DeallocationState(Operation *op, SymbolTableCollection &symbolTables);
108108

109109
// The state should always be passed by reference.
110110
DeallocationState(const DeallocationState &) = delete;
@@ -189,7 +189,7 @@ class DeallocationState {
189189
private:
190190
// Symbol cache to lookup functions from call operations to check attributes
191191
// on the function operation.
192-
SymbolTableCollection symbolTable;
192+
SymbolTableCollection &symbolTable;
193193

194194
// Mapping from each SSA value with MemRef type to the associated ownership in
195195
// each block.

mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@ func::FuncOp buildDeallocationLibraryFunction(OpBuilder &builder, Location loc,
120120
SymbolTable &symbolTable);
121121

122122
/// Run the ownership-based buffer deallocation.
123-
LogicalResult deallocateBuffersOwnershipBased(FunctionOpInterface op,
124-
DeallocationOptions options);
123+
LogicalResult
124+
deallocateBuffersOwnershipBased(FunctionOpInterface op,
125+
DeallocationOptions options,
126+
SymbolTableCollection &symbolTables);
125127

126128
// Options struct for BufferResultsToOutParams pass.
127129
// Note: defined only here, not in tablegen.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ void Ownership::combine(Ownership other) { *this = getCombined(other); }
9494
// DeallocationState
9595
//===----------------------------------------------------------------------===//
9696

97-
DeallocationState::DeallocationState(Operation *op) : liveness(op) {}
97+
DeallocationState::DeallocationState(Operation *op,
98+
SymbolTableCollection &symbolTables)
99+
: symbolTable(symbolTables), liveness(op) {}
98100

99101
void DeallocationState::updateOwnership(Value memref, Ownership ownership,
100102
Block *block) {

mlir/lib/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ namespace {
166166
/// program have a corresponding de-allocation.
167167
class BufferDeallocation {
168168
public:
169-
BufferDeallocation(Operation *op, DeallocationOptions options)
170-
: state(op), options(options) {}
169+
BufferDeallocation(Operation *op, DeallocationOptions options,
170+
SymbolTableCollection &symbolTables)
171+
: state(op, symbolTables), options(options) {}
171172

172173
/// Performs the actual placement/creation of all dealloc operations.
173174
LogicalResult deallocate(FunctionOpInterface op);
@@ -1027,11 +1028,13 @@ struct OwnershipBasedBufferDeallocationPass
10271028
DeallocationOptions options;
10281029
options.privateFuncDynamicOwnership = privateFuncDynamicOwnership;
10291030

1031+
mlir::SymbolTableCollection symbolTables;
1032+
10301033
auto status = getOperation()->walk([&](func::FuncOp func) {
10311034
if (func.isExternal())
10321035
return WalkResult::skip();
10331036

1034-
if (failed(deallocateBuffersOwnershipBased(func, options)))
1037+
if (failed(deallocateBuffersOwnershipBased(func, options, symbolTables)))
10351038
return WalkResult::interrupt();
10361039

10371040
return WalkResult::advance();
@@ -1047,11 +1050,11 @@ struct OwnershipBasedBufferDeallocationPass
10471050
// Implement bufferization API
10481051
//===----------------------------------------------------------------------===//
10491052

1050-
LogicalResult
1051-
bufferization::deallocateBuffersOwnershipBased(FunctionOpInterface op,
1052-
DeallocationOptions options) {
1053+
LogicalResult bufferization::deallocateBuffersOwnershipBased(
1054+
FunctionOpInterface op, DeallocationOptions options,
1055+
SymbolTableCollection &symbolTables) {
10531056
// Gather all required allocation nodes and prepare the deallocation phase.
1054-
BufferDeallocation deallocation(op, options);
1057+
BufferDeallocation deallocation(op, options, symbolTables);
10551058

10561059
// Place all required temporary clone and dealloc nodes.
10571060
return deallocation.deallocate(op);

0 commit comments

Comments
 (0)