Skip to main content

Module regalloc

Module regalloc 

Source
Expand description

Public API for regalloc. Linear-scan register allocator.

Reference: Poletto & Sarkar, “Linear Scan Register Allocation”, TOPLAS 1999.

Algorithm:

  1. Compute per-VReg live intervals by a single pass over all instructions.
  2. Sort intervals by start point.
  3. 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§

LiveInterval
Half-open live interval [start, end) in flat instruction program order.
RegAllocResult
Maps each VReg to the PReg it was assigned, or records it as spilled.

Enums§

RegAllocStrategy
Register allocation strategy used by allocate_registers.

Functions§

allocate_registers
Allocate registers with the selected strategy.
apply_allocation
Replace MOperand::VReg with MOperand::PReg in mf according to result. Also rewrites instr.dst so 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 intervals using allocatable registers.