pub struct LinearScanAllocator;Expand description
Classic linear scan register allocator (Poletto & Sarkar, 1999).
Usage:
let intervals = LinearScanAllocator::compute_intervals(&function);
let free_regs = vec!["r12", "r13", "r14", "r15", "rbx"];
let alloc_map = LinearScanAllocator::allocate(&intervals, &free_regs);Implementations§
Source§impl LinearScanAllocator
impl LinearScanAllocator
Sourcepub fn compute_intervals(function: &Function) -> Vec<LiveInterval>
pub fn compute_intervals(function: &Function) -> Vec<LiveInterval>
Compute interval hulls from instruction operands and control-flow liveness.
Positions are handed out by walking function.blocks in storage order and
counting instructions. Backends compare start and end against positions they
number the same way — the clobber ranges that keep a value out of a caller-saved
register across a call are built like this — so the two numberings are one index
space and changing the order here without changing every backend that shares it
silently assigns a live value to a clobbered register.
Sourcepub fn allocate<R: Copy + Eq>(
intervals: &[LiveInterval],
available_regs: &[R],
) -> HashMap<VirtualReg, Allocation<R>>
pub fn allocate<R: Copy + Eq>( intervals: &[LiveInterval], available_regs: &[R], ) -> HashMap<VirtualReg, Allocation<R>>
Run the linear scan allocation algorithm.
intervals must be sorted by start (as returned by compute_intervals).
available_regs is the pool of physical registers to draw from (any Copy + Eq
type works — for x86_64 pass &["r12", "r13", ...]).
Returns a map from each VirtualReg to either a physical register or a
spill slot (negative byte offset from frame base).
Sourcepub fn allocate_with_constraints<R: Copy + Eq>(
intervals: &[LiveInterval],
available_regs: &[R],
allowed: impl Fn(&LiveInterval, R) -> bool,
) -> HashMap<VirtualReg, Allocation<R>>
pub fn allocate_with_constraints<R: Copy + Eq>( intervals: &[LiveInterval], available_regs: &[R], allowed: impl Fn(&LiveInterval, R) -> bool, ) -> HashMap<VirtualReg, Allocation<R>>
Allocate registers permitted by each interval’s target constraints.