10 #include "llvm/Support/Debug.h"
12 #define DEBUG_TYPE "dataflow"
13 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
14 #define DATAFLOW_DEBUG(X) LLVM_DEBUG(X)
16 #define DATAFLOW_DEBUG(X)
42 if (
auto *programPoint = dyn_cast<GenericProgramPoint *>())
43 return programPoint->print(os);
44 if (
auto *op = dyn_cast<Operation *>())
46 if (
auto value = dyn_cast<Value>())
47 return value.print(os);
48 return get<Block *>()->print(os);
52 if (
auto *programPoint = dyn_cast<GenericProgramPoint *>())
53 return programPoint->getLoc();
54 if (
auto *op = dyn_cast<Operation *>())
56 if (
auto value = dyn_cast<Value>())
57 return value.getLoc();
58 return get<Block *>()->getParent()->getLoc();
69 <<
"Priming analysis: " << analysis.debugName <<
"\n");
70 if (
failed(analysis.initialize(top)))
77 while (!worklist.empty()) {
78 auto [point, analysis] = worklist.front();
82 <<
"' on: " << point <<
"\n");
83 if (
failed(analysis->visit(point)))
89 }
while (!worklist.empty());
97 DATAFLOW_DEBUG(llvm::dbgs() <<
"Propagating update to " << state->debugName
98 <<
" of " << state->
point <<
"\n"
99 <<
"Value: " << *state <<
"\n");
109 auto inserted = state->
dependents.insert({point, analysis});
113 llvm::dbgs() <<
"Creating dependency between " << state->debugName
114 <<
" of " << state->
point <<
"\nand " << analysis->debugName
115 <<
" on " << point <<
"\n";
#define DATAFLOW_DEBUG(X)
Base class for generic analysis states.
virtual void onUpdate(DataFlowSolver *solver) const
This function is called by the solver when the analysis state is updated to optionally enqueue more w...
SetVector< DataFlowSolver::WorkItem > dependents
The dependency relations originating from this analysis state.
ProgramPoint point
The program point to which the state belongs.
Base class for all data-flow analyses.
void propagateIfChanged(AnalysisState *state, ChangeResult changed)
Propagate an update to a state if it changed.
virtual ~DataFlowAnalysis()
DataFlowAnalysis(DataFlowSolver &solver)
Create an analysis with a reference to the parent solver.
void addDependency(AnalysisState *state, ProgramPoint point)
Create a dependency between the given analysis state and program point on this analysis.
The general data-flow analysis solver.
void addDependency(AnalysisState *state, DataFlowAnalysis *analysis, ProgramPoint point)
Add a dependency to an analysis state on a child analysis and program point.
void enqueue(WorkItem item)
Push a work item onto the worklist.
void propagateIfChanged(AnalysisState *state, ChangeResult changed)
Propagate an update to an analysis state if it changed by pushing dependent work items to the back of...
LogicalResult initializeAndRun(Operation *top)
Initialize the children analyses starting from the provided top-level operation and run the analysis ...
std::pair< ProgramPoint, DataFlowAnalysis * > WorkItem
A work item on the solver queue is a program point, child analysis pair.
virtual ~GenericProgramPoint()
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Operation is the basic unit of execution within MLIR.
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
ChangeResult
A result type used to indicate if a change happened.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
This class represents an efficient way to signal success or failure.
Fundamental IR components are supported as first-class program points.
Location getLoc() const
Get the source location of the program point.
void print(raw_ostream &os) const
Print the program point.