MLIR 22.0.0git
mlir::DataFlowSolver Class Reference

The general data-flow analysis solver. More...

#include "mlir/Analysis/DataFlowFramework.h"

Public Types

using WorkItem = std::pair<ProgramPoint *, DataFlowAnalysis *>
 A work item on the solver queue is a program point, child analysis pair.

Public Member Functions

 DataFlowSolver (const DataFlowConfig &config=DataFlowConfig())
template<typename AnalysisT, typename... Args>
AnalysisT * load (Args &&...args)
 Load an analysis into the solver. Return the analysis instance.
LogicalResult initializeAndRun (Operation *top)
 Initialize the children analyses starting from the provided top-level operation and run the analysis until fixpoint.
template<typename StateT, typename AnchorT>
const StateT * lookupState (AnchorT anchor) const
 Lookup an analysis state for the given lattice anchor.
template<typename AnchorT>
void eraseState (AnchorT anchor)
 Erase any analysis state associated with the given lattice anchor.
void eraseAllStates ()
 Erase all analysis states.
template<typename AnchorT, typename... Args>
AnchorT * getLatticeAnchor (Args &&...args)
 Get a uniqued lattice anchor instance.
ProgramPointgetProgramPointBefore (Operation *op)
 Get a uniqued program point instance.
ProgramPointgetProgramPointBefore (Block *block)
ProgramPointgetProgramPointAfter (Operation *op)
ProgramPointgetProgramPointAfter (Block *block)
void enqueue (WorkItem item)
 Push a work item onto the worklist.
template<typename StateT, typename AnchorT>
StateT * getOrCreateState (AnchorT anchor)
 Get the state associated with the given lattice anchor.
template<typename StateT>
LatticeAnchor getLeaderAnchorOrSelf (LatticeAnchor latticeAnchor) const
 Get leader lattice anchor in equivalence lattice anchor group, return input lattice anchor if input not found in equivalece lattice anchor group.
template<typename StateT, typename AnchorT>
void unionLatticeAnchors (AnchorT anchor, AnchorT other)
 Union input anchors under the given state.
template<typename StateT>
bool isEquivalent (LatticeAnchor lhs, LatticeAnchor rhs) const
 Return given lattice is equivalent on given state.
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 the queue.
const DataFlowConfiggetConfig () const
 Get the configuration of the solver.

Friends

class DataFlowAnalysis
 Allow the base child analysis class to access the internals of the solver.

Detailed Description

The general data-flow analysis solver.

This class is responsible for orchestrating child data-flow analyses, running the fixed-point iteration algorithm, managing analysis state and lattice anchor memory, and tracking dependencies between analyses, lattice anchor, and analysis states.

Steps to run a data-flow analysis:

  1. Load and initialize children analyses. Children analyses are instantiated in the solver and initialized, building their dependency relations.
  2. Configure and run the analysis. The solver invokes the children analyses according to their dependency relations until a fixed point is reached.
  3. Query analysis state results from the solver.

Steps to re-run a data-flow analysis when IR changes:

  1. Erase all analysis states as they are no longer valid.
  2. Re-run the analysis using initializeAndRun.

TODO: Optimize the internal implementation of the solver.

Definition at line 325 of file DataFlowFramework.h.

Member Typedef Documentation

◆ WorkItem

A work item on the solver queue is a program point, child analysis pair.

Each item is processed by invoking the child analysis at the program point.

Definition at line 404 of file DataFlowFramework.h.

Constructor & Destructor Documentation

◆ DataFlowSolver()

mlir::DataFlowSolver::DataFlowSolver ( const DataFlowConfig & config = DataFlowConfig())
inlineexplicit

Definition at line 327 of file DataFlowFramework.h.

Member Function Documentation

◆ enqueue()

void mlir::DataFlowSolver::enqueue ( WorkItem item)
inline

◆ eraseAllStates()

void mlir::DataFlowSolver::eraseAllStates ( )
inline

Erase all analysis states.

Definition at line 360 of file DataFlowFramework.h.

◆ eraseState()

template<typename AnchorT>
void mlir::DataFlowSolver::eraseState ( AnchorT anchor)

Erase any analysis state associated with the given lattice anchor.

Definition at line 547 of file DataFlowFramework.h.

Referenced by mlir::dataflow::maybeReplaceWithConstant().

◆ getConfig()

const DataFlowConfig & mlir::DataFlowSolver::getConfig ( ) const
inline

Get the configuration of the solver.

Definition at line 434 of file DataFlowFramework.h.

◆ getLatticeAnchor()

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

Get a uniqued lattice anchor instance.

If one is not present, it is created with the provided arguments.

Definition at line 368 of file DataFlowFramework.h.

◆ getLeaderAnchorOrSelf()

template<typename StateT>
LatticeAnchor mlir::DataFlowSolver::getLeaderAnchorOrSelf ( LatticeAnchor latticeAnchor) const

Get leader lattice anchor in equivalence lattice anchor group, return input lattice anchor if input not found in equivalece lattice anchor group.

Definition at line 725 of file DataFlowFramework.h.

References mlir::TypeID::get().

Referenced by getOrCreateState(), and lookupState().

◆ getOrCreateState()

template<typename StateT, typename AnchorT>
StateT * mlir::DataFlowSolver::getOrCreateState ( AnchorT anchor)

Get the state associated with the given lattice anchor.

If it does not exist, create an uninitialized state.

Definition at line 740 of file DataFlowFramework.h.

References mlir::TypeID::get(), and getLeaderAnchorOrSelf().

Referenced by copyIntegerRange(), and mlir::dataflow::IntegerValueRangeLattice::onUpdate().

◆ getProgramPointAfter() [1/2]

ProgramPoint * mlir::DataFlowSolver::getProgramPointAfter ( Block * block)
inline

Definition at line 396 of file DataFlowFramework.h.

References mlir::Block::end().

◆ getProgramPointAfter() [2/2]

ProgramPoint * mlir::DataFlowSolver::getProgramPointAfter ( Operation * op)
inline

◆ getProgramPointBefore() [1/2]

ProgramPoint * mlir::DataFlowSolver::getProgramPointBefore ( Block * block)
inline

Definition at line 382 of file DataFlowFramework.h.

References mlir::Block::begin().

◆ getProgramPointBefore() [2/2]

ProgramPoint * mlir::DataFlowSolver::getProgramPointBefore ( Operation * op)
inline

Get a uniqued program point instance.

Definition at line 373 of file DataFlowFramework.h.

References mlir::Operation::getBlock().

Referenced by mlir::dataflow::Executable::onUpdate().

◆ initializeAndRun()

LogicalResult DataFlowSolver::initializeAndRun ( Operation * top)

Initialize the children analyses starting from the provided top-level operation and run the analysis until fixpoint.

Definition at line 108 of file DataFlowFramework.cpp.

References DATAFLOW_DEBUG, DataFlowAnalysis, mlir::Operation::hasTrait(), and success().

◆ isEquivalent()

template<typename StateT>
bool mlir::DataFlowSolver::isEquivalent ( LatticeAnchor lhs,
LatticeAnchor rhs ) const

Return given lattice is equivalent on given state.

Definition at line 756 of file DataFlowFramework.h.

References mlir::TypeID::get(), lhs, and rhs.

◆ load()

template<typename AnalysisT, typename... Args>
AnalysisT * mlir::DataFlowSolver::load ( Args &&... args)

Load an analysis into the solver. Return the analysis instance.

Definition at line 715 of file DataFlowFramework.h.

References mlir::get().

Referenced by mlir::dataflow::loadBaselineAnalyses().

◆ lookupState()

template<typename StateT, typename AnchorT>
const StateT * mlir::DataFlowSolver::lookupState ( AnchorT anchor) const
inline

Lookup an analysis state for the given lattice anchor.

Returns null if one does not exist.

Definition at line 343 of file DataFlowFramework.h.

References mlir::TypeID::get(), and getLeaderAnchorOrSelf().

Referenced by copyIntegerRange(), getMaybeConstantValue(), mlir::dataflow::maybeReplaceWithConstant(), replaceWithConstant(), and mlir::dataflow::staticallyNonNegative().

◆ propagateIfChanged()

void DataFlowSolver::propagateIfChanged ( AnalysisState * state,
ChangeResult changed )

Propagate an update to an analysis state if it changed by pushing dependent work items to the back of the queue.

This should only be used when DataFlowSolver is running. Otherwise, the solver won't process the work items.

Definition at line 147 of file DataFlowFramework.cpp.

References mlir::AnalysisState::anchor, mlir::Change, mlir::changed, DATAFLOW_DEBUG, and mlir::AnalysisState::onUpdate().

Referenced by mlir::dataflow::IntegerValueRangeLattice::onUpdate().

◆ unionLatticeAnchors()

template<typename StateT, typename AnchorT>
void mlir::DataFlowSolver::unionLatticeAnchors ( AnchorT anchor,
AnchorT other )

Union input anchors under the given state.

Definition at line 768 of file DataFlowFramework.h.

References mlir::TypeID::get().

◆ DataFlowAnalysis

friend class DataFlowAnalysis
friend

Allow the base child analysis class to access the internals of the solver.

Definition at line 467 of file DataFlowFramework.h.

References DataFlowAnalysis.

Referenced by DataFlowAnalysis, and initializeAndRun().


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