Skip to main content

Func

Struct Func 

Source
pub struct Func {
    pub name: Symbol,
    /* private fields */
}
Expand description

One function, in machine instructions.

Fields§

§name: Symbol

The name it is called by, which is the name of the IR function it was lowered from.

Implementations§

Source§

impl Func

Source

pub fn new(name: Symbol) -> Self

A function of that name with nothing in it.

Source

pub fn new_vreg(&mut self, class: RegClass) -> Reg

A virtual register of that class, which nothing has defined yet.

§Panics

Panics if the function already has two billion of them, which no function does.

Source

pub fn vregs(&self) -> usize

How many virtual registers the function has, which is what the allocator sizes itself against.

Source

pub fn class_of(&self, reg: Reg) -> Option<RegClass>

The class of a virtual register, or None for a physical one or a number this function never handed out.

Source

pub fn create_block(&mut self) -> Block

Creates a block with no parameters and nothing in it, at the end of the layout.

Source

pub fn entry(&self) -> Option<Block>

The entry block, which is the first in layout order, or None before there is one.

Source

pub fn block_count(&self) -> usize

How many blocks the function has ever had, which is what a table indexed by block is sized against. A block taken out of the layout still counts, because it keeps its index.

Source

pub fn inst_count(&self) -> usize

How many instructions the function has ever had, which is what a table indexed by instruction is sized against. One taken out of a block still counts, because it keeps its index.

Source

pub fn blocks(&self) -> impl Iterator<Item = Block> + use<'_>

Its blocks, in layout order, which is the order they are printed and emitted in.

Source

pub fn set_block_order(&mut self, order: &[Block])

Puts the blocks in that order, which is the order they are printed and emitted in.

A block keeps its index, so nothing holding one is invalidated and nothing else in the function has to be touched: the order is a linked list and this relinks it. That is the whole reason the list is a list rather than the order the blocks were created in.

The first block in the order becomes the entry, which is a real decision rather than a consequence: on this machine a function is entered at its first byte, so the block that runs first has to be laid out first.

§Panics

Panics unless order is every block of the function exactly once. A block left out would be unreachable in a way nothing later could notice, and one named twice would make the list a loop, so both are worth finding here rather than in the encoder.

Source

pub fn append_param(&mut self, block: Block, class: RegClass) -> Reg

Adds a parameter of that class to a block, and gives back the virtual register it arrives as.

Every predecessor’s arm has to grow an argument to match, which is what Func::succs_mut is for.

Source

pub fn append_given_param(&mut self, block: Block, param: Param)

Adds a parameter that is already a particular register, which is what allocation leaves behind.

Source

pub fn params_mut(&mut self, block: Block) -> &mut Vec<Param>

What arrives in a block, to be read or replaced.

Allocation is what replaces it: once every parameter is a place and every argument is a place, an edge is a set of moves and the parameters are what those moves write, so the block stops asking for anything and the machine IR stops being in SSA form.

Source

pub fn succs_mut(&mut self, block: Block) -> &mut Vec<BlockCall>

Where a block goes, to be read or replaced.

The arms are in the order the terminator’s own arms run, so the first is the arm a conditional branch takes when its condition holds.

Source

pub fn insts(&self, block: Block) -> impl Iterator<Item = Inst> + use<'_>

The instructions of a block, in order.

Source

pub fn terminator(&self, block: Block) -> Option<Inst>

The last instruction of a block, which is its terminator once it has one.

Source

pub fn block_of(&self, inst: Inst) -> Option<Block>

Which block an instruction is in, or None for one that has been taken out of its block.

Source

pub fn span(&self, inst: Inst) -> Span

Where an instruction came from.

Source

pub fn build(&mut self, block: Block, opcode: Opcode) -> InstBuilder<'_>

Starts an instruction at the end of that block.

Nothing is added to the function until InstBuilder::finish, so a builder that is dropped leaves no trace.

Source

pub fn append_inst(&mut self, block: Block, inst: Inst)

Puts an instruction that is in no block at the end of one.

§Panics

Panics if the instruction is already in a block, because an instruction in two blocks is the kind of thing that is found much later and somewhere else.

Source

pub fn insert_after(&mut self, after: Inst, inst: Inst)

Puts an instruction that is in no block immediately after another one.

§Panics

Panics if the instruction is already in a block, or if the one it is to follow is in none.

Source

pub fn build_loose(&mut self, opcode: Opcode) -> InstBuilder<'_>

Starts an instruction that will be in no block until something puts it in one.

This is what a pass that inserts rather than appends builds with, and it hands the instruction to Func::prepend_inst, Func::insert_before or Func::insert_after. Everything else about it is the same, which is the point: the operand order is the builder’s invariant wherever the instruction ends up.

Source

pub fn prepend_inst(&mut self, block: Block, inst: Inst)

Puts an instruction that is in no block at the start of one, in front of everything in it.

§Panics

Panics if the instruction is already in a block.

Source

pub fn insert_before(&mut self, before: Inst, inst: Inst)

Puts an instruction that is in no block immediately before another one.

This is what a reload is: the instruction that wants the value has to see it already read in, so the load goes in front of it rather than behind whatever came before, which is the same place only when something came before.

§Panics

Panics if the instruction is already in a block, or if the one it is to precede is in none.

Source

pub fn remove_inst(&mut self, inst: Inst)

Takes an instruction out of its block, leaving it in the function’s tables.

It keeps its index, the way a removed block keeps its number, because renumbering would invalidate every index anything else was holding.

Source

pub fn push_operands(&mut self, operands: &[Operand]) -> OperandList

Puts a run of operands in the operand table and gives back the run.

Source

pub fn add_imm(&mut self, value: i64) -> ImmRef

Puts an immediate in the immediate table.

Source

pub fn add_amode(&mut self, amode: Amode) -> MemRef

Puts an addressing mode in the table of them.

Source

pub fn create_inst(&mut self, data: InstData, span: Span) -> Inst

Creates an instruction that is in no block yet.

Trait Implementations§

Source§

impl Debug for Func

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Index<Idx<Amode>> for Func

Source§

type Output = Amode

The returned type after indexing.
Source§

fn index(&self, at: MemRef) -> &Amode

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<Idx<BlockData>> for Func

Source§

type Output = BlockData

The returned type after indexing.
Source§

fn index(&self, block: Block) -> &BlockData

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<Idx<Imm>> for Func

Source§

type Output = Imm

The returned type after indexing.
Source§

fn index(&self, at: ImmRef) -> &Imm

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<Idx<InstData>> for Func

Source§

type Output = InstData

The returned type after indexing.
Source§

fn index(&self, inst: Inst) -> &InstData

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<IdxRange<Operand>> for Func

Source§

type Output = [Operand]

The returned type after indexing.
Source§

fn index(&self, list: OperandList) -> &[Operand]

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<Idx<Amode>> for Func

Source§

fn index_mut(&mut self, at: MemRef) -> &mut Amode

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<Idx<InstData>> for Func

Source§

fn index_mut(&mut self, inst: Inst) -> &mut InstData

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<IdxRange<Operand>> for Func

Source§

fn index_mut(&mut self, list: OperandList) -> &mut [Operand]

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl Freeze for Func

§

impl RefUnwindSafe for Func

§

impl Send for Func

§

impl Sync for Func

§

impl Unpin for Func

§

impl UnsafeUnpin for Func

§

impl UnwindSafe for Func

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.