Skip to content

[mlir][dataflow] disallow outside use of propagateIfChanged for DataFlowSolver #120885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mlir/include/mlir/Analysis/DataFlowFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ class DataFlowSolver {

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

/// Get the configuration of the solver.
Expand All @@ -410,6 +412,9 @@ class DataFlowSolver {
/// Configuration of the dataflow solver.
DataFlowConfig config;

/// The solver is working on the worklist.
bool isRunning = false;

/// The solver's work queue. Work items can be inserted to the front of the
/// queue to be processed greedily, speeding up computations that otherwise
/// quickly degenerate to quadratic due to propagation of state updates.
Expand Down
7 changes: 7 additions & 0 deletions mlir/lib/Analysis/DataFlowFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "mlir/IR/Location.h"
#include "mlir/IR/Operation.h"
#include "mlir/IR/Value.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/iterator.h"
#include "llvm/Config/abi-breaking.h"
#include "llvm/Support/Casting.h"
Expand Down Expand Up @@ -104,6 +105,10 @@ Location LatticeAnchor::getLoc() const {
//===----------------------------------------------------------------------===//

LogicalResult DataFlowSolver::initializeAndRun(Operation *top) {
// Enable enqueue to the worklist.
isRunning = true;
auto guard = llvm::make_scope_exit([&]() { isRunning = false; });

// Initialize the analyses.
for (DataFlowAnalysis &analysis : llvm::make_pointee_range(childAnalyses)) {
DATAFLOW_DEBUG(llvm::dbgs()
Expand Down Expand Up @@ -134,6 +139,8 @@ LogicalResult DataFlowSolver::initializeAndRun(Operation *top) {

void DataFlowSolver::propagateIfChanged(AnalysisState *state,
ChangeResult changed) {
assert(isRunning &&
"DataFlowSolver is not running, should not use propagateIfChanged");
if (changed == ChangeResult::Change) {
DATAFLOW_DEBUG(llvm::dbgs() << "Propagating update to " << state->debugName
<< " of " << state->anchor << "\n"
Expand Down
Loading