Skip to content

Commit a60050c

Browse files
[mlir][dataflow] Allow re-run all analyses in DataFlowSolver (llvm#120881)
In downstream (check google/heir#1228, especially [this commit](ZenithalHourlyRate/heir@fbf0b27); also check google/heir#1154) we often need to re-run the analysis during the transformation pass as IR get changed based on the analysis result and analysis continuously get invalidated. There are solutions to it like `getOrCreateState` for newly created `Value` (`AnchorT`), but warning is that the new state does not propagate! This is quite unexpected as user of analysis would expect it to propagate. We downstream used to use `solver->propagateIfChanged` but that turned out to be not working, see detailed writeup in google/heir#1153. Just call `initializeAndRun` repeatedly also does not solve the problem as `analysisStates` is not cleared and the monotonicity of `AnalysisState` will make the analysis invalid as `join` will not work as expected (the first join is no longer `join(uninitialized, init value)`, instead it becomes `join(higher value, init value)`. To correctly re-run the analysis, either a new `DataFlowSolver` is created, or we can just clear the `analysisState`.
1 parent 5b74fb7 commit a60050c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

mlir/include/mlir/Analysis/DataFlowFramework.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ class DataFlowConfig {
308308
/// according to their dependency relations until a fixed point is reached.
309309
/// 3. Query analysis state results from the solver.
310310
///
311+
/// Steps to re-run a data-flow analysis when IR changes:
312+
/// 1. Erase all analysis states as they are no longer valid.
313+
/// 2. Re-run the analysis using `initializeAndRun`.
314+
///
311315
/// TODO: Optimize the internal implementation of the solver.
312316
class DataFlowSolver {
313317
public:
@@ -346,6 +350,9 @@ class DataFlowSolver {
346350
}
347351
}
348352

353+
// Erase all analysis states
354+
void eraseAllStates() { analysisStates.clear(); }
355+
349356
/// Get a uniqued lattice anchor instance. If one is not present, it is
350357
/// created with the provided arguments.
351358
template <typename AnchorT, typename... Args>

0 commit comments

Comments
 (0)