Equations
- Sparkle.IR.Optimize.instInhabitedExpr = { default := Sparkle.IR.AST.Expr.const 0 0 }
O(1) lookup maps built from module data
Instances For
Equations
Instances For
Build a name → defining-expression map from assign statements
Equations
- One or more equations did not get rendered due to their size.
Instances For
Build name → bit-width map from module ports and wires
Equations
- One or more equations did not get rendered due to their size.
Instances For
Infer the bit-width of an expression
Try to resolve a slice of a concat to a direct reference or narrower slice.
For concat [a(wa), b(wb), c(wc), ...] with total width T:
- a occupies [T-1 : T-wa]
- b occupies [T-wa-1 : T-wa-wb]
- etc. (MSB-first layout, same as Verilog {a, b, c, ...})
Returns the replacement if the slice maps entirely within one arg.
Resolve a slice of a named wire through the defMap, recursively following:
- Ref aliases: X = Y → slice(Y, hi, lo)
- Slice chains: X = Y[h:l] → slice(Y, l+hi, l+lo)
- Concat args: X = {a, b} → a (if slice matches exactly) Depth-limited to prevent infinite recursion on malformed IR.
Fold constant expressions
Equations
- One or more equations did not get rendered due to their size.
- Sparkle.IR.Optimize.foldConstants (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.mux [Sparkle.IR.AST.Expr.const 1 1, t, head]) = t
- Sparkle.IR.Optimize.foldConstants (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.mux [Sparkle.IR.AST.Expr.const 0 1, head, e]) = e
- Sparkle.IR.Optimize.foldConstants (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.add [Sparkle.IR.AST.Expr.const 0 width, e]) = e
- Sparkle.IR.Optimize.foldConstants (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.add [e, Sparkle.IR.AST.Expr.const 0 width]) = e
- Sparkle.IR.Optimize.foldConstants (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.or [Sparkle.IR.AST.Expr.const 0 width, e]) = e
- Sparkle.IR.Optimize.foldConstants (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.or [e, Sparkle.IR.AST.Expr.const 0 width]) = e
- Sparkle.IR.Optimize.foldConstants (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.and [Sparkle.IR.AST.Expr.const 0 w, head]) = Sparkle.IR.AST.Expr.const 0 w
- Sparkle.IR.Optimize.foldConstants (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.and [head, Sparkle.IR.AST.Expr.const 0 w]) = Sparkle.IR.AST.Expr.const 0 w
- Sparkle.IR.Optimize.foldConstants (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.mux [Sparkle.IR.AST.Expr.const 0 width, head, e]) = e
- Sparkle.IR.Optimize.foldConstants (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.mux [cond, Sparkle.IR.AST.Expr.const 1 1, Sparkle.IR.AST.Expr.const 0 1]) = cond
- Sparkle.IR.Optimize.foldConstants (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.not [Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.not [x_1]]) = x_1
- Sparkle.IR.Optimize.foldConstants x✝ = x✝
Instances For
Collect all reference names from an expression.
Count uses of each wire across all statements
Equations
- One or more equations did not get rendered due to their size.
Instances For
Optimize a single statement's expressions
Equations
- One or more equations did not get rendered due to their size.
- Sparkle.IR.Optimize.optimizeStmt dm wm (Sparkle.IR.AST.Stmt.assign lhs rhs) = Sparkle.IR.AST.Stmt.assign lhs (Sparkle.IR.Optimize.optimizeExpr dm wm rhs)
Instances For
Recursively substitute inlinable references with their defining expressions
Inline single-use wires: replace references with their defining expressions and remove the now-dead assign statements.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Propagate constant and simple-ref assignments into all uses. x = const → replace all refs to x with const x = y → replace all refs to x with y (alias elimination) This runs even for gen (JIT-observable) wires since they're just aliases.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Sparkle.IR.Optimize.propagateConstants.substExpr constMap (Sparkle.IR.AST.Expr.ref name) = match constMap.get? name with | some replacement => replacement | none => Sparkle.IR.AST.Expr.ref name
- Sparkle.IR.Optimize.propagateConstants.substExpr constMap (Sparkle.IR.AST.Expr.const value width) = Sparkle.IR.AST.Expr.const value width
- Sparkle.IR.Optimize.propagateConstants.substExpr constMap (inner.slice hi lo) = (Sparkle.IR.Optimize.propagateConstants.substExpr constMap inner).slice hi lo
- Sparkle.IR.Optimize.propagateConstants.substExpr constMap (Sparkle.IR.AST.Expr.concat args) = Sparkle.IR.AST.Expr.concat (List.map (Sparkle.IR.Optimize.propagateConstants.substExpr constMap) args)
Instances For
Filter zero-bit elements out of an Expr tree.
lowerExpr / runCircuitH-style elaborators can produce IR
nodes that thread a bitVector 0 "empty payload" through
.concat and .slice chains — for instance bundle2 X (Signal.pure ()) lowers to .concat [X, <0-bit ref>], and
the matching Signal.map Prod.fst lowers to a slice that
discards the 0-bit tail.
Emitting these into SystemVerilog produces invalid constructs
like assign x = 0'd0; (a zero-width literal is not legal SV).
This pass rewrites the IR so that:
.const v 0is dropped from.concatarg lists;.concat [x](after dropping zero-bit args) collapses to the single remaining arg;.concat []collapses to a 1-bit zero placeholder (should be unreachable in practice — pruned later by DCE);.slice e hi lowherehi - lo + 1 == 0is rewritten to a 0-bit constant (later dropped at the use site).
Sub-expressions are rewritten recursively.
Drop Stmt.assign whose LHS has zero width — these only exist as
leftover bookkeeping from 0-bit IR construction (see
eliminateZeroBitInExpr). Other Stmt kinds are kept as is.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Run the 0-bit elimination pass over a module's body and wire list.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Optimize a module: strip zero-bit shapes, eliminate concat/slice chains, then remove dead code.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Optimize all modules in a design
Equations
- One or more equations did not get rendered due to their size.