Expand description
Studio easter egg — certified linear-scan register allocation, visualised.
Pure data → SVG (no Z3, no JS): a basic block’s variable live ranges are laid on an instruction
timeline as bars, coloured by the physical register they’re assigned. When the block is
over-pressure, the bars that provably must spill are flagged red and the certified Hall/clique
witness is reported. The allocation comes straight from the certified register_alloc engine,
so the picture is a faithful view of a re-checkable result — the same engine that crushes Z3 on
the colouring encoding, here rendered for a one-glance “watch the allocator decide” demo.
Structs§
- RegSpec
- A parsed register-allocation spec: named variable live ranges + the physical register budget.
Functions§
- allocation_
report - A textual allocation report for the Studio output panel: the physical register assigned to each
variable, or — when the block is over-pressure — the spill verdict naming its mutually-interfering
clique. This is the “compiler back-end output” view that pairs with the
rendertimeline; the per-variable registers come from the samelinear_scan_assignmentthe animation replays, and the feasibility/clique verdict from the certifiedallocateresult, so the two views agree. - interference_
edges - The interference graph’s edges: every pair of variables
(i, j)(i < j) whose live ranges overlap, so they cannot share a register. Register allocation is exactly colouring this graph; for straight-line code it is an interval graph (perfect), so its chromatic number equals the largest clique equals the register pressure. - is_
register_ alloc_ spec - Whether
specis a register-allocation spec (aregisters:budget plus at least one live range). This is the single source of truth the Studio uses to route Hardware-mode input to the allocator easter egg, so the wiring (panel visibility, output panel, viz panel) can never drift from what the parser actually accepts. - is_
valid_ linear_ scan - Re-check a linear-scan assignment: every assigned register is within budget, and no two variables
that are live at the same time are given the same register — the soundness property any register
allocation must satisfy. (Spilled variables,
None, impose no constraint: they live in memory.) - linear_
scan_ assignment - A deterministic linear-scan assignment: variable index
i→ the physical register it is given, orNoneif linear-scan must spill it (no register was free when it became live). This is the data the animated view replays — each variable becomes one bar that lights up in its register’s lane while it is live. Re-checkable viais_valid_linear_scan. It spills nothing exactly when the block fits the budget (peak pressure ≤registers), so it agrees with the certifiedallocatedecision while also showing which value gets evicted when it does not. - parse_
register_ spec - Parse a spec of the form (one
name: start-endper line, plus aregisters: Nbudget): - pressure_
profile - Register pressure sampled at each instruction in
tmin..tmax:profile[i]is how many variables are live at instructiontmin + i. Its maximum is the register pressure (the fewest registers the block could ever need), which is what the budget line is drawn against — wherever the profile rises above the budget, spilling is unavoidable. - render
- Render the certified allocation of
specas(svg, verdict). The SVG is an animated linear-scan: a live-range timeline above an animated register file, with a sweep line crossing both so you can watch each value claim and release its register (and, when over capacity, drop to a spill lane). The verdict is the plain-language, certified summary.