Index
Apply
dataclass
¶
BasicBlock
¶
Linear sequence of statements with a single entry and exit.
Successor/predecessor lists encode the CFG edges. Statements execute in order; no internal branching occurs within a BasicBlock.
Source code in src/finch/symbolic/dataflow.py
__str__()
¶
String representation of BasicBlock in LLVM style.
Source code in src/finch/symbolic/dataflow.py
CallTerm
dataclass
¶
A tree term which applies the operator computed by the expression op to args.
Source code in src/finch/symbolic/term.py
Chain
¶
Bases: Generic[T]
A rewriter which rewrites using each rewriter in itr. If all rewriters
return nothing, return nothing.
Attributes:
| Name | Type | Description |
|---|---|---|
rws |
Iterable[RwCallable]
|
A collection of rewriter functions to apply. |
Source code in src/finch/symbolic/rewriters.py
CompilerMode
dataclass
¶
Safe mode checks shared dimensions and tensor extents; debug also checks buffer accesses.
Source code in src/finch/symbolic/stage.py
Constant
dataclass
¶
Bases: Value
a literal, interned by its exact type and bits, so 0.0 and -0.0 differ
Source code in src/finch/symbolic/value_numbering.py
Context
¶
Bases: ABC
Source code in src/finch/symbolic/environment.py
block()
¶
Create a new block. Preambles and epilogues will stay within this block.
Source code in src/finch/symbolic/environment.py
ControlFlowGraph
¶
Collection of BasicBlocks plus explicit ENTRY and EXIT nodes.
Provides helpers to allocate uniquely named blocks and holds the global block mapping used by dataflow analyses.
Source code in src/finch/symbolic/dataflow.py
__str__()
¶
Print the CFG in LLVM style format.
Source code in src/finch/symbolic/dataflow.py
DataFlowAnalysis
¶
Bases: ABC
Base class for performing data flow analyses over a ControlFlowGraph.
This abstract class implements a generic work-list algorithm that can run either in a "forward" or "backward" direction. Subclasses must provide IR-specific semantics by implementing the abstract methods: transfer, join, stmt_str and direction, and may override boundary_state.
only blocks reachable from the boundary block (ENTRY for forward, EXIT for
backward) are visited, and joins skip neighbors that weren't processed yet.
so loops start optimistic and dead blocks (e.g. after a return) never get
joined in. transfer must not mutate its input.
blocks are visited in reverse postorder, so a block is joined after the neighbors before it.
Key attributes
- cfg: the ControlFlowGraph to analyze.
- input_states: a mapping from basic block id to the state flowing into the
block's transfer (its entry for forward, its exit for backward).
- output_states: a mapping from basic block id to the state the block's
transfer produces.
- reached: ids of the blocks visited by analyze.
Source code in src/finch/symbolic/dataflow.py
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 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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
__str__()
¶
Return a string representation describing the current dataflow analysis state over the control-flow graph (CFG).
The output lists each basic block in the order produced by self.cfg.blocks.values(). For every block the printed form is:
<block.id>: #succs=[<succ_id>, ...]
<stmt_representation_for_first_stmt>
<stmt_representation_for_second_stmt>
...
statements are annotated with the state flowing into their transfer (before them for forward, after them for backward), statements of unreached blocks without annotations.
Source code in src/finch/symbolic/dataflow.py
analyze()
¶
run the work list until the states of all reached blocks are stable
Source code in src/finch/symbolic/dataflow.py
boundary_state()
¶
direction()
abstractmethod
¶
Return the direction of the data flow analysis, either "forward" or "backward". This should be implemented by subclasses.
join(state_1, state_2)
abstractmethod
¶
Join function for the data flow analysis. This should be implemented by subclasses.
stmt_str(stmt, state)
abstractmethod
¶
Format a single statement given the current lattice state. Implement in subclasses or IR-specific abstract bases.
transfer(stmts, state)
abstractmethod
¶
Transfer function for the data flow analysis. This should be implemented by subclasses.
Fixpoint
¶
Bases: Generic[T]
A rewriter which repeatedly applies rw to x until no changes are made. If
the rewriter first returns nothing, returns nothing.
Attributes:
| Name | Type | Description |
|---|---|---|
rw |
RwCallable
|
The rewriter function to apply. |
Source code in src/finch/symbolic/rewriters.py
Form
¶
Bases: ABC
A Form represents the invariants that must hold for the inputs to be valid for a given stage. It will typically be a combination of a grammar and a set of constraints on the inputs. Stages should inherit from a Form to validate their inputs.
Source code in src/finch/symbolic/stage.py
HashCons
¶
Source code in src/finch/symbolic/hashcons.py
canonicalize(a)
staticmethod
¶
Canonicalize an instance of this class into a (type, hashable) pair.
Generic version provided, but one can override for speed.
Source code in src/finch/symbolic/hashcons.py
hash_key(*args)
classmethod
¶
The hash key for this class, when it is constructed with *args.
Generic version provided, but one can specialize for speed.
Source code in src/finch/symbolic/hashcons.py
Leaf
dataclass
¶
LiteralTerm
dataclass
¶
Memo
¶
Bases: Generic[T]
A rewriter which caches the results of rw in cache and returns the
result.
Attributes:
| Name | Type | Description |
|---|---|---|
rw |
RwCallable
|
The rewriter function to apply. |
cache |
dict
|
A dictionary to store cached results. |
Source code in src/finch/symbolic/rewriters.py
NamedTerm
¶
Namespace
¶
Namespace
A namespace for managing variable names and aesthetic fresh variable
generation. You can construct a namespace from an existing tree of Terms
to avoid name collisions.
Source code in src/finch/symbolic/environment.py
freshen(*tags)
¶
Generate a fresh variable name based on the provided tags.
Source code in src/finch/symbolic/environment.py
resolve(*names)
¶
Resolve a list of namespaced variable names to a unique name.
e.g. resolve("a", "b") might return a_b_1 if a_b has already been
used in scope.
Source code in src/finch/symbolic/environment.py
PostWalk
¶
A rewriter which recursively rewrites the arguments of each node using
rw, then rewrites the resulting node. If all rewriters return nothing,
returns nothing.
Attributes:
| Name | Type | Description |
|---|---|---|
rw |
RwCallable
|
The rewriter function to apply. |
Source code in src/finch/symbolic/rewriters.py
PreWalk
¶
A rewriter which recursively rewrites each node using rw, then rewrites
the arguments of the resulting node. If all rewriters return nothing,
returns nothing.
Attributes:
| Name | Type | Description |
|---|---|---|
rw |
RwCallable
|
The rewriter function to apply. |
Source code in src/finch/symbolic/rewriters.py
Rewrite
¶
Bases: Generic[T]
A rewriter which returns the original argument even if rw returns nothing.
Attributes:
| Name | Type | Description |
|---|---|---|
rw |
RwCallable
|
The rewriter function to apply. |
Source code in src/finch/symbolic/rewriters.py
ScopedDict
¶
Bases: Generic[T]
A dictionary that allows for scoped variable resolution.
Source code in src/finch/symbolic/environment.py
Term
¶
Source code in src/finch/symbolic/term.py
TermTree
dataclass
¶
Source code in src/finch/symbolic/term.py
children
abstractmethod
property
¶
Return the children (AKA tail) of the S-expression.
UnvalidatedForm
¶
Bases: Form
UnvalidatedForm does not perform any validation on the input logic. This is essentially a to-do for validation and should be replaced.
Source code in src/finch/symbolic/stage.py
Value
¶
ValueUniverse
¶
a finite set of values, closed under taking args. a state is a tuple giving each value the index of the first value in its class.
Source code in src/finch/symbolic/value_numbering.py
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 163 164 165 166 167 | |
assign(state, leaf, value=None)
¶
the state after writing value to leaf, or an unknown value if None
Source code in src/finch/symbolic/value_numbering.py
empty()
¶
meet(state_1, state_2)
¶
the equalities both states have
Source code in src/finch/symbolic/value_numbering.py
number(state, value)
¶
the class of value in state, or None if it isn't in the universe