Skip to content

Commit 2dc277b

Browse files
[mlir][dataflow] Only allow propagateIfChanged when DataFlowSolver is running
1 parent f51db95 commit 2dc277b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

mlir/include/mlir/Analysis/DataFlowFramework.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ class DataFlowSolver {
403403

404404
/// Propagate an update to an analysis state if it changed by pushing
405405
/// dependent work items to the back of the queue.
406+
/// This should only be used when DataFlowSolver is running.
407+
/// Otherwise, the solver won't process the work items.
406408
void propagateIfChanged(AnalysisState *state, ChangeResult changed);
407409

408410
/// Get the configuration of the solver.
@@ -412,6 +414,9 @@ class DataFlowSolver {
412414
/// Configuration of the dataflow solver.
413415
DataFlowConfig config;
414416

417+
// The solver is working on the worklist.
418+
bool isRunning = false;
419+
415420
/// The solver's work queue. Work items can be inserted to the front of the
416421
/// queue to be processed greedily, speeding up computations that otherwise
417422
/// quickly degenerate to quadratic due to propagation of state updates.

mlir/lib/Analysis/DataFlowFramework.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,16 @@ Location LatticeAnchor::getLoc() const {
104104
//===----------------------------------------------------------------------===//
105105

106106
LogicalResult DataFlowSolver::initializeAndRun(Operation *top) {
107+
// Enable enqueue to the worklist.
108+
isRunning = true;
107109
// Initialize the analyses.
108110
for (DataFlowAnalysis &analysis : llvm::make_pointee_range(childAnalyses)) {
109111
DATAFLOW_DEBUG(llvm::dbgs()
110112
<< "Priming analysis: " << analysis.debugName << "\n");
111-
if (failed(analysis.initialize(top)))
113+
if (failed(analysis.initialize(top))) {
114+
isRunning = false;
112115
return failure();
116+
}
113117
}
114118

115119
// Run the analysis until fixpoint.
@@ -121,19 +125,25 @@ LogicalResult DataFlowSolver::initializeAndRun(Operation *top) {
121125

122126
DATAFLOW_DEBUG(llvm::dbgs() << "Invoking '" << analysis->debugName
123127
<< "' on: " << point << "\n");
124-
if (failed(analysis->visit(point)))
128+
if (failed(analysis->visit(point))) {
129+
isRunning = false;
125130
return failure();
131+
}
126132
}
127133

128134
// Iterate until all states are in some initialized state and the worklist
129135
// is exhausted.
130136
} while (!worklist.empty());
131137

138+
// Prevent further updates to the worklist
139+
isRunning = false;
132140
return success();
133141
}
134142

135143
void DataFlowSolver::propagateIfChanged(AnalysisState *state,
136144
ChangeResult changed) {
145+
assert(isRunning &&
146+
"DataFlowSolver is not running, should not use propagateIfChanged");
137147
if (changed == ChangeResult::Change) {
138148
DATAFLOW_DEBUG(llvm::dbgs() << "Propagating update to " << state->debugName
139149
<< " of " << state->anchor << "\n"

0 commit comments

Comments
 (0)