Skip to main content

MachineFunction

Struct MachineFunction 

Source
pub struct MachineFunction {
    pub name: String,
    pub blocks: Vec<MachineBlock>,
    pub allocatable_pregs: Vec<PReg>,
    pub callee_saved_pregs: Vec<PReg>,
    pub frame_size: u32,
    pub spill_slots: HashMap<VReg, u32>,
    pub used_callee_saved: Vec<PReg>,
    pub debug_source: Option<String>,
    pub debug_line_start: Option<u32>,
    pub current_debug_loc: Option<DebugLoc>,
    /* private fields */
}
Expand description

Machine-level representation of a function, ready for register allocation and code emission.

Fields§

§name: String

Name of the function.

§blocks: Vec<MachineBlock>

Basic blocks in layout order (block 0 is the entry).

§allocatable_pregs: Vec<PReg>

Physical registers available for allocation (set by the target).

§callee_saved_pregs: Vec<PReg>

Callee-saved physical registers (set by the target).

§frame_size: u32

Frame size in bytes (spill slots only; set by insert_spill_reloads).

§spill_slots: HashMap<VReg, u32>

Map from spilled VReg → frame slot index (0-based; emitter converts to byte offset).

§used_callee_saved: Vec<PReg>

Callee-saved physical registers actually used by this function (populated by apply_allocation).

§debug_source: Option<String>

Source filename used for debug line tables.

§debug_line_start: Option<u32>

First source line observed from IR !dbg metadata.

§current_debug_loc: Option<DebugLoc>

Debug location automatically attached by MachineFunction::push.

Implementations§

Source§

impl MachineFunction

Source

pub fn new(name: String) -> Self

Public API for new.

Source

pub fn fresh_vreg(&mut self) -> VReg

Allocate a fresh virtual register.

Source

pub fn alloc_spill_slot(&mut self, vreg: VReg) -> u32

Allocate a fresh frame slot for a spilled VReg and return its index.

Slot 0 is the first 8-byte slot below the frame pointer. The emitter converts a slot index n to a byte offset (e.g. x86: -(n+1)*8 from RBP; AArch64: (n+2)*8 above the saved FP/LR pair).

Source

pub fn add_block(&mut self, label: impl Into<String>) -> usize

Append a new empty machine block and return its index.

Source

pub fn push(&mut self, block_idx: usize, instr: MInstr)

Append instr to block block_idx.

Trait Implementations§

Source§

impl Clone for MachineFunction

Source§

fn clone(&self) -> MachineFunction

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MachineFunction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.