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 live intervals for all virtual registers in a function.
Performs a single forward pass over all blocks (in function.blocks
order) counting instructions globally. Each VirtualReg:
startis set at its first definition,endis updated at every use.
Function parameters are treated as defined at instruction 0.
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).
Auto Trait Implementations§
impl Freeze for LinearScanAllocator
impl RefUnwindSafe for LinearScanAllocator
impl Send for LinearScanAllocator
impl Sync for LinearScanAllocator
impl Unpin for LinearScanAllocator
impl UnsafeUnpin for LinearScanAllocator
impl UnwindSafe for LinearScanAllocator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more