Skip to main content

LinearScanAllocator

Struct LinearScanAllocator 

Source
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

Source

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:

  • start is set at its first definition,
  • end is updated at every use.

Function parameters are treated as defined at instruction 0.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.