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
Bases: Enum
A result type used to indicate if a change happened.
Source code in xdsl/analysis/dataflow.py
19 20 21 22 23 24 25 26 27 28 | |
NO_CHANGE = 0
class-attribute
instance-attribute
CHANGE = 1
class-attribute
instance-attribute
__or__(other: ChangeResult) -> ChangeResult
Source code in xdsl/analysis/dataflow.py
27 28 | |
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
31 32 33 34 35 36 37 38 39 40 41 | |
__init__() -> None
__str__() -> str
abstractmethod
Source code in xdsl/analysis/dataflow.py
40 41 | |
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
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
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
Returns the program point just before an operation.
Source code in xdsl/analysis/dataflow.py
53 54 55 56 | |
after(op: Operation) -> ProgramPoint
staticmethod
Returns the program point just after an operation.
Source code in xdsl/analysis/dataflow.py
58 59 60 61 62 63 64 65 | |
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
67 68 69 70 71 72 73 | |
at_end_of_block(block: Block) -> ProgramPoint
staticmethod
Returns the program point at the end of a block.
Source code in xdsl/analysis/dataflow.py
75 76 77 78 | |
__str__() -> str
Source code in xdsl/analysis/dataflow.py
94 95 96 97 | |
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
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
dependents: set[tuple[ProgramPoint, DataFlowAnalysis]] = set()
instance-attribute
anchor: AnchorCovT
property
__init__(anchor: AnchorCovT)
Source code in xdsl/analysis/dataflow.py
121 122 123 | |
on_update(solver: DataFlowSolver) -> None
Called by the solver when the state is updated. Enqueues dependent work items.
Source code in xdsl/analysis/dataflow.py
129 130 131 132 133 134 135 | |
__str__() -> str
abstractmethod
Source code in xdsl/analysis/dataflow.py
137 138 | |
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
158 159 160 161 162 163 164 165 166 | |
initialize_and_run(op: Operation) -> None
Initializes all analyses and runs the solver to a fixed point.
Source code in xdsl/analysis/dataflow.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
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
183 184 185 186 187 188 189 190 191 | |
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
193 194 195 196 197 198 199 200 201 202 | |
enqueue(item: tuple[ProgramPoint, DataFlowAnalysis]) -> None
Adds a work item to the solver's worklist.
Source code in xdsl/analysis/dataflow.py
204 205 206 207 208 209 210 | |
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
212 213 214 215 216 217 218 219 | |
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
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
solver: DataFlowSolver = solver
instance-attribute
__init__(solver: DataFlowSolver)
Source code in xdsl/analysis/dataflow.py
230 231 | |
initialize(op: Operation) -> None
abstractmethod
Initializes the analysis, setting up initial states and dependencies for a given top-level operation.
Source code in xdsl/analysis/dataflow.py
233 234 235 236 237 238 239 | |
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.
Source code in xdsl/analysis/dataflow.py
241 242 243 244 245 246 247 | |
get_or_create_state(anchor: LatticeAnchor, state_type: type[AnalysisStateInvT]) -> AnalysisStateInvT
Helper to get or create a state from the solver.
Source code in xdsl/analysis/dataflow.py
249 250 251 252 253 | |
get_state(anchor: LatticeAnchor, state_type: type[AnalysisStateInvT]) -> AnalysisStateInvT | None
Helper to look up a state from the solver.
Source code in xdsl/analysis/dataflow.py
255 256 257 258 259 | |
add_dependency(state: AnalysisState, dependent_point: ProgramPoint) -> None
Adds a dependency: if state changes, self.visit(dependent_point)
will be called.
Source code in xdsl/analysis/dataflow.py
261 262 263 264 265 266 267 268 | |
propagate_if_changed(state: AnalysisState, changed: ChangeResult) -> None
Helper to propagate a state change to the solver.
Source code in xdsl/analysis/dataflow.py
270 271 272 | |