MLIR  16.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 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 assiocated 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...
 

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 347 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 126 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 program point on this analysis.

Definition at line 128 of file DataFlowFramework.cpp.

References mlir::DataFlowSolver::addDependency().

Referenced by mlir::dataflow::AbstractSparseDataFlowAnalysis::getLatticeElementFor(), and mlir::dataflow::AbstractDenseDataFlowAnalysis::getLatticeFor().

◆ getOrCreate()

template<typename StateT , typename PointT >
StateT* mlir::DataFlowAnalysis::getOrCreate ( PointT  point)
inlineprotected

Get the analysis state assiocated 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 407 of file DataFlowFramework.h.

References mlir::DataFlowSolver::getOrCreateState().

◆ getOrCreateFor()

template<typename StateT , typename PointT >
const StateT* mlir::DataFlowAnalysis::getOrCreateFor ( ProgramPoint  dependent,
PointT  point 
)
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 415 of file DataFlowFramework.h.

◆ getProgramPoint()

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

Get or create a custom program point.

Definition at line 399 of file DataFlowFramework.h.

References mlir::DataFlowSolver::getProgramPoint().

◆ 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 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::DeadCodeAnalysis, mlir::dataflow::AbstractSparseDataFlowAnalysis, and mlir::dataflow::AbstractDenseDataFlowAnalysis.

◆ propagateIfChanged()

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

◆ registerPointKind()

template<typename PointT >
void mlir::DataFlowAnalysis::registerPointKind ( )
inlineprotected

Register a custom program point class.

Definition at line 393 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 dependecies 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::DeadCodeAnalysis, mlir::dataflow::AbstractSparseDataFlowAnalysis, and mlir::dataflow::AbstractDenseDataFlowAnalysis.

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 431 of file DataFlowFramework.h.


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