MLIR
20.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 lattice anchors 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 lattice anchor on this analysis. More... | |
void | propagateIfChanged (AnalysisState *state, ChangeResult changed) |
Propagate an update to a state if it changed. More... | |
template<typename AnchorT > | |
void | registerAnchorKind () |
Register a custom lattice anchor class. More... | |
template<typename AnchorT , typename... Args> | |
AnchorT * | getLatticeAnchor (Args &&...args) |
Get or create a custom lattice anchor. More... | |
template<typename StateT , typename AnchorT > | |
StateT * | getOrCreate (AnchorT anchor) |
Get the analysis state associated with the lattice anchor. More... | |
template<typename StateT , typename AnchorT > | |
const StateT * | getOrCreateFor (ProgramPoint *dependent, AnchorT anchor) |
Get a read-only analysis state for the given point and create a dependency on dependent . More... | |
ProgramPoint * | getProgramPointBefore (Operation *op) |
Get a uniqued program point instance. More... | |
ProgramPoint * | getProgramPointBefore (Block *block) |
ProgramPoint * | getProgramPointAfter (Operation *op) |
ProgramPoint * | getProgramPointAfter (Block *block) |
const DataFlowConfig & | getSolverConfig () const |
Return the configuration of the solver used for this analysis. 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 520 of file DataFlowFramework.h.
|
virtualdefault |
|
explicit |
Create an analysis with a reference to the parent solver.
Definition at line 151 of file DataFlowFramework.cpp.
|
protected |
Create a dependency between the given analysis state and lattice anchor on this analysis.
Definition at line 153 of file DataFlowFramework.cpp.
|
inlineprotected |
Get or create a custom lattice anchor.
Definition at line 572 of file DataFlowFramework.h.
References mlir::DataFlowSolver::getLatticeAnchor().
|
inlineprotected |
Get the analysis state associated with the lattice anchor.
The returned state is expected to be "write-only", and any updates need to be propagated by propagateIfChanged
.
Definition at line 580 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 588 of file DataFlowFramework.h.
|
inlineprotected |
Definition at line 607 of file DataFlowFramework.h.
References mlir::DataFlowSolver::getProgramPointAfter().
|
inlineprotected |
Definition at line 603 of file DataFlowFramework.h.
|
inlineprotected |
Definition at line 599 of file DataFlowFramework.h.
References mlir::DataFlowSolver::getProgramPointBefore().
|
inlineprotected |
Get a uniqued program point instance.
Definition at line 595 of file DataFlowFramework.h.
|
inlineprotected |
Return the configuration of the solver used for this analysis.
Definition at line 612 of file DataFlowFramework.h.
References mlir::DataFlowSolver::getConfig().
|
pure virtual |
Initialize the analysis from the provided top-level operation by building an initial dependency graph between all lattice anchors 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 158 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 lattice anchor class.
Definition at line 566 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 624 of file DataFlowFramework.h.