MLIR
18.0.0git
|
Base class for all data-flow analyses. More...
#include "mlir/Analysis/DataFlowFramework.h"
Public Member Functions | |
virtual | ~DataFlowAnalysis () |
DataFlowAnalysis (DataFlowSolver &solver) | |
Create an analysis with a reference to the parent solver. More... | |
virtual LogicalResult | initialize (Operation *top)=0 |
Initialize the analysis from the provided top-level operation by building an initial dependency graph between all program points of interest. More... | |
virtual LogicalResult | visit (ProgramPoint point)=0 |
Visit the given program point. More... | |
Protected Member Functions | |
void | addDependency (AnalysisState *state, ProgramPoint point) |
Create a dependency between the given analysis state and program point on this analysis. More... | |
void | propagateIfChanged (AnalysisState *state, ChangeResult changed) |
Propagate an update to a state if it changed. More... | |
template<typename PointT > | |
void | registerPointKind () |
Register a custom program point class. More... | |
template<typename PointT , typename... Args> | |
PointT * | getProgramPoint (Args &&...args) |
Get or create a custom program point. More... | |
template<typename StateT , typename PointT > | |
StateT * | getOrCreate (PointT point) |
Get the analysis state associated with the program point. More... | |
template<typename StateT , typename PointT > | |
const StateT * | getOrCreateFor (ProgramPoint dependent, PointT point) |
Get a read-only analysis state for the given point and create a dependency on dependent . More... | |
Friends | |
class | DataFlowSolver |
Allow the data-flow solver to access the internals of this class. More... | |
Base class for all data-flow analyses.
A child analysis is expected to build an initial dependency graph (and optionally provide an initial state) when initialized and define transfer functions when visiting program points.
In classical data-flow analysis, the dependency graph is fixed and analyses define explicit transfer functions between input states and output states. In this framework, however, the dependency graph can change during the analysis, and transfer functions are opaque such that the solver doesn't know what states calling visit
on an analysis will be updated. This allows multiple analyses to plug in and provide values for the same state.
Generally, when an analysis queries an uninitialized state, it is expected to "bail out", i.e., not provide any updates. When the value is initialized, the solver will re-invoke the analysis. If the solver exhausts its worklist, however, and there are still uninitialized states, the solver "nudges" the analyses by default-initializing those states.
Definition at line 352 of file DataFlowFramework.h.
|
virtualdefault |
|
explicit |
Create an analysis with a reference to the parent solver.
Definition at line 125 of file DataFlowFramework.cpp.
|
protected |
Create a dependency between the given analysis state and program point on this analysis.
Definition at line 127 of file DataFlowFramework.cpp.
|
inlineprotected |
Get the analysis state associated with the program point.
The returned state is expected to be "write-only", and any updates need to be propagated by propagateIfChanged
.
Definition at line 412 of file DataFlowFramework.h.
References mlir::DataFlowSolver::getOrCreateState().
|
inlineprotected |
Get a read-only analysis state for the given point and create a dependency on dependent
.
If the return state is updated elsewhere, this analysis is re-invoked on the dependent.
Definition at line 420 of file DataFlowFramework.h.
|
inlineprotected |
Get or create a custom program point.
Definition at line 404 of file DataFlowFramework.h.
References mlir::DataFlowSolver::getProgramPoint().
|
pure virtual |
Initialize the analysis from the provided top-level operation by building an initial dependency graph between all program points of interest.
This can be implemented by calling visit
on all program points of interest below the top-level operation.
An analysis can optionally provide initial values to certain analysis states to influence the evolution of the analysis.
Implemented in mlir::dataflow::AbstractSparseBackwardDataFlowAnalysis, mlir::dataflow::AbstractSparseForwardDataFlowAnalysis, mlir::dataflow::AbstractDenseBackwardDataFlowAnalysis, mlir::dataflow::AbstractDenseForwardDataFlowAnalysis, and mlir::dataflow::DeadCodeAnalysis.
|
protected |
Propagate an update to a state if it changed.
Definition at line 131 of file DataFlowFramework.cpp.
Referenced by mlir::dataflow::AbstractDenseForwardDataFlowAnalysis::join(), mlir::dataflow::AbstractSparseForwardDataFlowAnalysis::join(), mlir::dataflow::AbstractDenseBackwardDataFlowAnalysis::meet(), mlir::dataflow::AbstractSparseBackwardDataFlowAnalysis::meet(), mlir::dataflow::IntegerRangeAnalysis::setToEntryState(), mlir::dataflow::SparseConstantPropagation::setToEntryState(), and mlir::dataflow::LivenessAnalysis::visitCallOperand().
|
inlineprotected |
Register a custom program point class.
Definition at line 398 of file DataFlowFramework.h.
References mlir::StorageUniquer::registerParametricStorageType().
|
pure virtual |
Visit the given program point.
This function is invoked by the solver on this analysis with a given program point when a dependent analysis state is updated. The function is similar to a transfer function; it queries certain analysis states and sets other states.
The function is expected to create dependencies on queried states and propagate updates on changed states. A dependency can be created by calling addDependency
between the input state and a program point, indicating that, if the state is updated, the solver should invoke solve
on the program point. The dependent point does not have to be the same as the provided point. An update to a state is propagated by calling propagateIfChange
on the state. If the state has changed, then all its dependents are placed on the worklist.
The dependency graph does not need to be static. Each invocation of visit
can add new dependencies, but these dependencies will not be dynamically added to the worklist because the solver doesn't know what will provide a value for then.
Implemented in mlir::dataflow::AbstractSparseBackwardDataFlowAnalysis, mlir::dataflow::AbstractSparseForwardDataFlowAnalysis, mlir::dataflow::AbstractDenseBackwardDataFlowAnalysis, mlir::dataflow::AbstractDenseForwardDataFlowAnalysis, and mlir::dataflow::DeadCodeAnalysis.
|
friend |
Allow the data-flow solver to access the internals of this class.
Definition at line 436 of file DataFlowFramework.h.