MLIR  20.0.0git
Public Member Functions | Protected Member Functions | Friends | List of all members
mlir::DataFlowAnalysis Class Referenceabstract

Base class for all data-flow analyses. More...

#include "mlir/Analysis/DataFlowFramework.h"

+ Inheritance diagram for mlir::DataFlowAnalysis:

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...
 
ProgramPointgetProgramPointBefore (Operation *op)
 Get a uniqued program point instance. More...
 
ProgramPointgetProgramPointBefore (Block *block)
 
ProgramPointgetProgramPointAfter (Operation *op)
 
ProgramPointgetProgramPointAfter (Block *block)
 
const DataFlowConfiggetSolverConfig () 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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ~DataFlowAnalysis()

DataFlowAnalysis::~DataFlowAnalysis ( )
virtualdefault

◆ DataFlowAnalysis()

DataFlowAnalysis::DataFlowAnalysis ( DataFlowSolver solver)
explicit

Create an analysis with a reference to the parent solver.

Definition at line 151 of file DataFlowFramework.cpp.

Member Function Documentation

◆ addDependency()

void DataFlowAnalysis::addDependency ( AnalysisState state,
ProgramPoint point 
)
protected

Create a dependency between the given analysis state and lattice anchor on this analysis.

Definition at line 153 of file DataFlowFramework.cpp.

◆ getLatticeAnchor()

template<typename AnchorT , typename... Args>
AnchorT* mlir::DataFlowAnalysis::getLatticeAnchor ( Args &&...  args)
inlineprotected

Get or create a custom lattice anchor.

Definition at line 572 of file DataFlowFramework.h.

References mlir::DataFlowSolver::getLatticeAnchor().

◆ getOrCreate()

template<typename StateT , typename AnchorT >
StateT* mlir::DataFlowAnalysis::getOrCreate ( AnchorT  anchor)
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().

◆ getOrCreateFor()

template<typename StateT , typename AnchorT >
const StateT* mlir::DataFlowAnalysis::getOrCreateFor ( ProgramPoint dependent,
AnchorT  anchor 
)
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.

◆ getProgramPointAfter() [1/2]

ProgramPoint* mlir::DataFlowAnalysis::getProgramPointAfter ( Block block)
inlineprotected

Definition at line 607 of file DataFlowFramework.h.

References mlir::DataFlowSolver::getProgramPointAfter().

◆ getProgramPointAfter() [2/2]

ProgramPoint* mlir::DataFlowAnalysis::getProgramPointAfter ( Operation op)
inlineprotected

Definition at line 603 of file DataFlowFramework.h.

◆ getProgramPointBefore() [1/2]

ProgramPoint* mlir::DataFlowAnalysis::getProgramPointBefore ( Block block)
inlineprotected

◆ getProgramPointBefore() [2/2]

ProgramPoint* mlir::DataFlowAnalysis::getProgramPointBefore ( Operation op)
inlineprotected

Get a uniqued program point instance.

Definition at line 595 of file DataFlowFramework.h.

◆ getSolverConfig()

const DataFlowConfig& mlir::DataFlowAnalysis::getSolverConfig ( ) const
inlineprotected

Return the configuration of the solver used for this analysis.

Definition at line 612 of file DataFlowFramework.h.

References mlir::DataFlowSolver::getConfig().

◆ initialize()

virtual LogicalResult mlir::DataFlowAnalysis::initialize ( Operation top)
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.

◆ propagateIfChanged()

void DataFlowAnalysis::propagateIfChanged ( AnalysisState state,
ChangeResult  changed 
)
protected

◆ registerAnchorKind()

template<typename AnchorT >
void mlir::DataFlowAnalysis::registerAnchorKind ( )
inlineprotected

Register a custom lattice anchor class.

Definition at line 566 of file DataFlowFramework.h.

References mlir::StorageUniquer::registerParametricStorageType().

◆ visit()

virtual LogicalResult mlir::DataFlowAnalysis::visit ( ProgramPoint point)
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.

Friends And Related Function Documentation

◆ DataFlowSolver

friend class DataFlowSolver
friend

Allow the data-flow solver to access the internals of this class.

Definition at line 624 of file DataFlowFramework.h.


The documentation for this class was generated from the following files: