Struct Function

Source
pub struct Function {
Show 18 fields pub name: ExternalName, pub signature: Signature, pub old_signature: Option<Signature>, pub stack_slots: StackSlots, pub global_values: PrimaryMap<GlobalValue, GlobalValueData>, pub heaps: PrimaryMap<Heap, HeapData>, pub tables: PrimaryMap<Table, TableData>, pub jump_tables: JumpTables, pub dfg: DataFlowGraph, pub layout: Layout, pub encodings: InstEncodings, pub locations: ValueLocations, pub entry_diversions: EntryRegDiversions, pub offsets: EbbOffsets, pub jt_offsets: JumpTableOffsets, pub srclocs: SourceLocs, pub prologue_end: Option<Inst>, pub frame_layout: Option<FrameLayout>,
}
Expand description

A function.

Functions can be cloned, but it is not a very fast operation. The clone will have all the same entity numbers as the original.

Fields§

§name: ExternalName

Name of this function. Mostly used by .clif files.

§signature: Signature

Signature of this function.

§old_signature: Option<Signature>

The old signature of this function, before the most recent legalization, if any.

§stack_slots: StackSlots

Stack slots allocated in this function.

§global_values: PrimaryMap<GlobalValue, GlobalValueData>

Global values referenced.

§heaps: PrimaryMap<Heap, HeapData>

Heaps referenced.

§tables: PrimaryMap<Table, TableData>

Tables referenced.

§jump_tables: JumpTables

Jump tables used in this function.

§dfg: DataFlowGraph

Data flow graph containing the primary definition of all instructions, EBBs and values.

§layout: Layout

Layout of EBBs and instructions in the function body.

§encodings: InstEncodings

Encoding recipe and bits for the legal instructions. Illegal instructions have the Encoding::default() value.

§locations: ValueLocations

Location assigned to every value.

§entry_diversions: EntryRegDiversions

Non-default locations assigned to value at the entry of basic blocks.

At the entry of each basic block, we might have values which are not in their default ValueLocation. This field records these register-to-register moves as Diversions.

§offsets: EbbOffsets

Code offsets of the EBB headers.

This information is only transiently available after the binemit::relax_branches function computes it, and it can easily be recomputed by calling that function. It is not included in the textual IR format.

§jt_offsets: JumpTableOffsets

Code offsets of Jump Table headers.

§srclocs: SourceLocs

Source locations.

Track the original source location for each instruction. The source locations are not interpreted by Cranelift, only preserved.

§prologue_end: Option<Inst>

Instruction that marks the end (inclusive) of the function’s prologue.

This is used for some calling conventions to track the end of unwind information.

§frame_layout: Option<FrameLayout>

Frame layout for the instructions.

The stack unwinding requires to have information about which registers and where they are saved in the frame. This information is created during the prologue and epilogue passes.

Implementations§

Source§

impl Function

Source

pub fn with_name_signature(name: ExternalName, sig: Signature) -> Self

Create a function with the given name and signature.

Source

pub fn clear(&mut self)

Clear all data structures in this function.

Source

pub fn new() -> Self

Create a new empty, anonymous function with a Fast calling convention.

Source

pub fn create_jump_table(&mut self, data: JumpTableData) -> JumpTable

Creates a jump table in the function, to be used by br_table instructions.

Source

pub fn create_stack_slot(&mut self, data: StackSlotData) -> StackSlot

Creates a stack slot in the function, to be used by stack_load, stack_store and stack_addr instructions.

Source

pub fn import_signature(&mut self, signature: Signature) -> SigRef

Adds a signature which can later be used to declare an external function import.

Source

pub fn import_function(&mut self, data: ExtFuncData) -> FuncRef

Declare an external function import.

Source

pub fn create_global_value(&mut self, data: GlobalValueData) -> GlobalValue

Declares a global value accessible to the function.

Source

pub fn create_heap(&mut self, data: HeapData) -> Heap

Declares a heap accessible to the function.

Source

pub fn create_table(&mut self, data: TableData) -> Table

Declares a table accessible to the function.

Source

pub fn display<'a, I: Into<Option<&'a dyn TargetIsa>>>( &'a self, isa: I, ) -> DisplayFunction<'a>

Return an object that can display this function with correct ISA-specific annotations.

Source

pub fn display_with<'a>( &'a self, annotations: DisplayFunctionAnnotations<'a>, ) -> DisplayFunction<'a>

Return an object that can display this function with correct ISA-specific annotations.

Source

pub fn special_param(&self, purpose: ArgumentPurpose) -> Option<Value>

Find a presumed unique special-purpose function parameter value.

Returns the value of the last purpose parameter, or None if no such parameter exists.

Source

pub fn inst_offsets<'a>( &'a self, ebb: Ebb, encinfo: &EncInfo, ) -> InstOffsetIter<'a>

Get an iterator over the instructions in ebb, including offsets and encoded instruction sizes.

The iterator returns (offset, inst, size) tuples, where offset if the offset in bytes from the beginning of the function to the instruction, and size is the size of the instruction in bytes, or 0 for unencoded instructions.

This function can only be used after the code layout has been computed by the binemit::relax_branches() function.

Source

pub fn update_encoding( &mut self, inst: Inst, isa: &dyn TargetIsa, ) -> Result<(), Legalize>

Wrapper around encode which assigns inst the resulting encoding.

Source

pub fn encode( &self, inst: Inst, isa: &dyn TargetIsa, ) -> Result<Encoding, Legalize>

Wrapper around TargetIsa::encode for encoding an existing instruction in the Function.

Source

pub fn collect_debug_info(&mut self)

Starts collection of debug information.

Source

pub fn change_branch_destination(&mut self, inst: Inst, new_dest: Ebb)

Changes the destination of a jump or branch instruction. Does nothing if called with a non-jump or non-branch instruction.

Source

pub fn is_ebb_basic(&self, ebb: Ebb) -> Result<(), (Inst, &'static str)>

Checks that the specified EBB can be encoded as a basic block.

On error, returns the first invalid instruction and an error message.

Source

pub fn is_leaf(&self) -> bool

Returns true if the function is function that doesn’t call any other functions. This is not to be confused with a “leaf function” in Windows terminology.

Trait Implementations§

Source§

impl Clone for Function

Source§

fn clone(&self) -> Function

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Function

Source§

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

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

impl Display for Function

Source§

fn fmt(&self, fmt: &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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.