Skip to content

Commit b9982b2

Browse files
committed
[mlir][bufferization] Add rename function to BufferViewFlowAnalysis
This new function to replace a Value with another Value saves us from re-running the entire alias analysis when an operation has to be re-build because additional result values have to be added (e.g., when adding more iter_args to an scf.for). Reviewed By: springerm Differential Revision: https://reviews.llvm.org/D156665
1 parent 4397433 commit b9982b2

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ class BufferViewFlowAnalysis {
5757
/// Removes the given values from all alias sets.
5858
void remove(const SetVector<Value> &aliasValues);
5959

60+
/// Replaces all occurrences of 'from' in the internal datastructures with
61+
/// 'to'. This is useful when the defining operation of a value has to be
62+
/// re-built because additional results have to be added or the types of
63+
/// results have to be changed.
64+
void rename(Value from, Value to);
65+
6066
private:
6167
/// This function constructs a mapping from values to its immediate
6268
/// dependencies.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ void BufferViewFlowAnalysis::remove(const SetVector<Value> &aliasValues) {
4545
llvm::set_subtract(entry.second, aliasValues);
4646
}
4747

48+
void BufferViewFlowAnalysis::rename(Value from, Value to) {
49+
dependencies[to] = dependencies[from];
50+
dependencies.erase(from);
51+
52+
for (auto &[key, value] : dependencies) {
53+
if (value.contains(from)) {
54+
value.insert(to);
55+
value.erase(from);
56+
}
57+
}
58+
}
59+
4860
/// This function constructs a mapping from values to its immediate
4961
/// dependencies. It iterates over all blocks, gets their predecessors,
5062
/// determines the values that will be passed to the corresponding block

0 commit comments

Comments
 (0)