diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/BufferViewFlowAnalysis.h b/mlir/include/mlir/Dialect/Bufferization/Transforms/BufferViewFlowAnalysis.h --- a/mlir/include/mlir/Dialect/Bufferization/Transforms/BufferViewFlowAnalysis.h +++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/BufferViewFlowAnalysis.h @@ -57,6 +57,12 @@ /// Removes the given values from all alias sets. void remove(const SetVector &aliasValues); + /// Replaces all occurrences of 'from' in the internal datastructures with + /// 'to'. This is useful when the defining operation of a value has to be + /// re-built because additional results have to be added or the types of + /// results have to be changed. + void rename(Value from, Value to); + private: /// This function constructs a mapping from values to its immediate /// dependencies. diff --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferViewFlowAnalysis.cpp b/mlir/lib/Dialect/Bufferization/Transforms/BufferViewFlowAnalysis.cpp --- a/mlir/lib/Dialect/Bufferization/Transforms/BufferViewFlowAnalysis.cpp +++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferViewFlowAnalysis.cpp @@ -45,6 +45,18 @@ llvm::set_subtract(entry.second, aliasValues); } +void BufferViewFlowAnalysis::rename(Value from, Value to) { + dependencies[to] = dependencies[from]; + dependencies.erase(from); + + for (auto &[key, value] : dependencies) { + if (value.contains(from)) { + value.insert(to); + value.erase(from); + } + } +} + /// This function constructs a mapping from values to its immediate /// dependencies. It iterates over all blocks, gets their predecessors, /// determines the values that will be passed to the corresponding block