Dataflow
dataflow
¶
Core datastructures and solver for dataflow analyses.
LatticeAnchor: TypeAlias = SSAValue | Block | ProgramPoint | GenericLatticeAnchor
module-attribute
¶
Union type for all possible lattice anchors.
AnchorInvT = TypeVar('AnchorInvT', bound=LatticeAnchor, default=LatticeAnchor)
module-attribute
¶
AnchorCovT = TypeVar('AnchorCovT', bound=LatticeAnchor, default=LatticeAnchor, covariant=True)
module-attribute
¶
AnalysisStateInvT = TypeVar('AnalysisStateInvT', bound='AnalysisState')
module-attribute
¶
DataFlowAnalysisInvT = TypeVar('DataFlowAnalysisInvT', bound='DataFlowAnalysis')
module-attribute
¶
ChangeResult
¶
GenericLatticeAnchor
dataclass
¶
Bases: ABC
Abstract base class for custom lattice anchors. In dataflow analysis, lattices are attached to 'anchors'. These are typically IR constructs like SSAValue or ProgramPoint, but can be custom constructs for concepts like control-flow edges.
Source code in xdsl/analysis/dataflow.py
ProgramPoint
dataclass
¶
A point in the program, either before an operation or at the end of a block. This is used as an anchor for dense analyses.
Source code in xdsl/analysis/dataflow.py
entity: Operation | Block
instance-attribute
¶
op: Operation | None
property
¶
The operation this point is before, or None if at the end of a block.
block: Block | None
property
¶
The block this point is in, or the block itself if at the end.
__init__(entity: Operation | Block) -> None
¶
before(op: Operation) -> ProgramPoint
staticmethod
¶
after(op: Operation) -> ProgramPoint
staticmethod
¶
Returns the program point just after an operation.
Source code in xdsl/analysis/dataflow.py
at_start_of_block(block: Block) -> ProgramPoint
staticmethod
¶
Returns the program point at the start of a block.
Source code in xdsl/analysis/dataflow.py
at_end_of_block(block: Block) -> ProgramPoint
staticmethod
¶
AnalysisState
¶
Bases: ABC, Generic[AnchorCovT]
Base class for all analysis states. States are attached to lattice anchors and evolve as the analysis iterates.
Source code in xdsl/analysis/dataflow.py
DataFlowSolver
dataclass
¶
The main dataflow analysis solver. It orchestrates child analyses, runs the fixed-point iteration, and manages analysis states.
Source code in xdsl/analysis/dataflow.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
context: Context
instance-attribute
¶
__init__(context: Context, _analyses: list[DataFlowAnalysis] = list['DataFlowAnalysis'](), _worklist: collections.deque[tuple[ProgramPoint, DataFlowAnalysis]] = collections.deque[tuple[ProgramPoint, 'DataFlowAnalysis']](), _analysis_states: dict[LatticeAnchor, dict[type[AnalysisState], AnalysisState]] = (lambda: collections.defaultdict(dict))(), _is_running: bool = False) -> None
¶
load(analysis_class: type[DataFlowAnalysisInvT], *args: Any) -> DataFlowAnalysisInvT
¶
Registers a new analysis with the solver.
Source code in xdsl/analysis/dataflow.py
initialize_and_run(op: Operation) -> None
¶
Initializes all analyses and runs the solver to a fixed point.
Source code in xdsl/analysis/dataflow.py
get_or_create_state(anchor: LatticeAnchor, state_type: type[AnalysisStateInvT]) -> AnalysisStateInvT
¶
Get the state for a given anchor. If it doesn't exist, create it.
Source code in xdsl/analysis/dataflow.py
lookup_state(anchor: LatticeAnchor, state_type: type[AnalysisStateInvT]) -> AnalysisStateInvT | None
¶
Look up an analysis state. Returns None if it doesn't exist.
Source code in xdsl/analysis/dataflow.py
enqueue(item: tuple[ProgramPoint, DataFlowAnalysis]) -> None
¶
Adds a work item to the solver's worklist.
Source code in xdsl/analysis/dataflow.py
propagate_if_changed(state: AnalysisState, changed: ChangeResult) -> None
¶
If the state has changed, trigger its on_update hook.
Source code in xdsl/analysis/dataflow.py
DataFlowAnalysis
¶
Bases: ABC
Base class for all dataflow analyses. An analysis implements transfer functions for IR constructs and is orchestrated by the DataFlowSolver.
Source code in xdsl/analysis/dataflow.py
solver: DataFlowSolver = solver
instance-attribute
¶
__init__(solver: DataFlowSolver)
¶
initialize(op: Operation) -> None
abstractmethod
¶
Initializes the analysis, setting up initial states and dependencies for a given top-level operation.
visit(point: ProgramPoint) -> None
abstractmethod
¶
The transfer function for a given program point. This is called by the solver when a dependency of this analysis at this point has changed.
get_or_create_state(anchor: LatticeAnchor, state_type: type[AnalysisStateInvT]) -> AnalysisStateInvT
¶
Helper to get or create a state from the solver.
get_state(anchor: LatticeAnchor, state_type: type[AnalysisStateInvT]) -> AnalysisStateInvT | None
¶
Helper to look up a state from the solver.
add_dependency(state: AnalysisState, dependent_point: ProgramPoint) -> None
¶
Adds a dependency: if state changes, self.visit(dependent_point)
will be called.