Dataflow
oqd_compiler_infrastructure.dataflow
¶
GraphProtocol
¶
Bases: Protocol[NodeType]
Any object passed to DataflowAnalysis.analyze must provide this interface.
The protocol is intentionally minimal so it can adapt to Control Flow Graphs (CFGs),
dependency graphs, custom IR graphs, etc.
Source code in oqd-compiler-infrastructure/src/oqd_compiler_infrastructure/dataflow.py
DataflowResult
dataclass
¶
Bases: Generic[NodeType, LatticeValue]
The result of a dataflow analysis.
Source code in oqd-compiler-infrastructure/src/oqd_compiler_infrastructure/dataflow.py
DataflowAnalysis
¶
Bases: ABC, Generic[NodeType, LatticeValue]
Base class that defines what every dataflow analysis must implement.
Source code in oqd-compiler-infrastructure/src/oqd_compiler_infrastructure/dataflow.py
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
transfer(node: NodeType, state_in: LatticeValue) -> LatticeValue
abstractmethod
¶
Returns the state of a given node after transfer.
sources(graph: GraphProtocol[NodeType], node: NodeType) -> Iterable[NodeType]
abstractmethod
¶
Neighbors whose results flow into node.
targets(graph: GraphProtocol[NodeType], node: NodeType) -> Iterable[NodeType]
abstractmethod
¶
Neighbors to reschedule when node's result changes.
result(boundary: dict[NodeType, LatticeValue], result: dict[NodeType, LatticeValue], iterations: int) -> DataflowResult[NodeType, LatticeValue]
abstractmethod
¶
Maps boundary/result states onto in/out states.
Source code in oqd-compiler-infrastructure/src/oqd_compiler_infrastructure/dataflow.py
init_state() -> LatticeValue
¶
merge_union(states: Iterable[LatticeValue]) -> LatticeValue
¶
Joins incoming states using the lattice's join operation.
Source code in oqd-compiler-infrastructure/src/oqd_compiler_infrastructure/dataflow.py
merge_intersection(states: Iterable[LatticeValue]) -> LatticeValue
¶
Meets incoming states using the lattice's meet operation.
Source code in oqd-compiler-infrastructure/src/oqd_compiler_infrastructure/dataflow.py
analyze(graph: GraphProtocol[NodeType], merge_function: Callable[[Iterable[LatticeValue]], LatticeValue]) -> DataflowResult[NodeType, LatticeValue]
¶
Runs the worklist algorithm and returns the result of the dataflow analysis.
Steps:
- Initializes every node's state with init_state().
- Puts all nodes in a worklist.
- Recomputes each node from predecessor outputs.
- If a node output changes, schedules its targets again.
- Returns final states and iteration count.
Source code in oqd-compiler-infrastructure/src/oqd_compiler_infrastructure/dataflow.py
ForwardDataflowAnalysis
¶
Bases: DataflowAnalysis[NodeType, LatticeValue], Generic[NodeType, LatticeValue]
Forward dataflow analysis framework.
Source code in oqd-compiler-infrastructure/src/oqd_compiler_infrastructure/dataflow.py
BackwardDataflowAnalysis
¶
Bases: DataflowAnalysis[NodeType, LatticeValue], Generic[NodeType, LatticeValue]
Backward dataflow analysis framework.