Expand description
Public API for regalloc.
Linear-scan register allocator.
Reference: Poletto & Sarkar, “Linear Scan Register Allocation”, TOPLAS 1999.
Algorithm:
- Compute per-VReg live intervals by a single pass over all instructions.
- Sort intervals by start point.
- Scan forward: maintain an “active” set sorted by end point.
- Expire intervals whose end ≤ current start (return their regs to free pool).
- If a free register exists, assign it.
- Otherwise spill the interval with the largest end point.
Re-exports§
pub use crate::regalloc_gc::graph_color;
Structs§
- Live
Interval - Half-open live interval
[start, end)in flat instruction program order. - RegAlloc
Result - Maps each VReg to the PReg it was assigned, or records it as spilled.
Enums§
- RegAlloc
Strategy - Register allocation strategy used by
allocate_registers.
Functions§
- allocate_
registers - Allocate registers with the selected strategy.
- apply_
allocation - Replace
MOperand::VRegwithMOperand::PReginmfaccording toresult. Also rewritesinstr.dstso that the destination register number reflects the assigned physical register rather than the raw VReg counter. Spilled VRegs are left unchanged (the caller must handle them). - compute_
live_ intervals - Build live intervals by scanning all instructions of
mf. - insert_
spill_ reloads - Insert spill stores and reload loads for all spilled VRegs.
- linear_
scan - Run linear-scan allocation over
intervalsusingallocatableregisters.