pub struct Function {Show 19 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: BlockOffsets,
pub jt_offsets: JumpTableOffsets,
pub srclocs: SourceLocs,
pub prologue_end: Option<Inst>,
pub epilogues_start: Vec<(Inst, Block)>,
pub stack_limit: Option<GlobalValue>,
}
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, blocks and values.
layout: Layout
Layout of blocks 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: BlockOffsets
Code offsets of the block 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 ABIs to generate unwind information.
epilogues_start: Vec<(Inst, Block)>
The instructions that mark the start (inclusive) of an epilogue in the function.
This is used for some ABIs to generate unwind information.
stack_limit: Option<GlobalValue>
An optional global value which represents an expression evaluating to
the stack limit for this function. This GlobalValue
will be
interpreted in the prologue, if necessary, to insert a stack check to
ensure that a trap happens if the stack pointer goes below the
threshold specified here.
Implementations
sourceimpl Function
impl Function
sourcepub fn with_name_signature(name: ExternalName, sig: Signature) -> Self
pub fn with_name_signature(name: ExternalName, sig: Signature) -> Self
Create a function with the given name and signature.
sourcepub fn create_jump_table(&mut self, data: JumpTableData) -> JumpTable
pub fn create_jump_table(&mut self, data: JumpTableData) -> JumpTable
Creates a jump table in the function, to be used by br_table
instructions.
sourcepub fn create_stack_slot(&mut self, data: StackSlotData) -> StackSlot
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.
sourcepub fn import_signature(&mut self, signature: Signature) -> SigRef
pub fn import_signature(&mut self, signature: Signature) -> SigRef
Adds a signature which can later be used to declare an external function import.
sourcepub fn import_function(&mut self, data: ExtFuncData) -> FuncRef
pub fn import_function(&mut self, data: ExtFuncData) -> FuncRef
Declare an external function import.
sourcepub fn create_global_value(&mut self, data: GlobalValueData) -> GlobalValue
pub fn create_global_value(&mut self, data: GlobalValueData) -> GlobalValue
Declares a global value accessible to the function.
sourcepub fn create_heap(&mut self, data: HeapData) -> Heap
pub fn create_heap(&mut self, data: HeapData) -> Heap
Declares a heap accessible to the function.
sourcepub fn create_table(&mut self, data: TableData) -> Table
pub fn create_table(&mut self, data: TableData) -> Table
Declares a table accessible to the function.
sourcepub fn display<'a, I: Into<Option<&'a dyn TargetIsa>>>(
&'a self,
isa: I
) -> DisplayFunction<'a>
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.
sourcepub fn display_with<'a>(
&'a self,
annotations: DisplayFunctionAnnotations<'a>
) -> DisplayFunction<'a>
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.
sourcepub fn special_param(&self, purpose: ArgumentPurpose) -> Option<Value>
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.
sourcepub fn inst_offsets<'a>(
&'a self,
block: Block,
encinfo: &EncInfo
) -> InstOffsetIter<'a>ⓘNotable traits for InstOffsetIter<'a>impl<'a> Iterator for InstOffsetIter<'a> type Item = (CodeOffset, Inst, CodeOffset);
pub fn inst_offsets<'a>(
&'a self,
block: Block,
encinfo: &EncInfo
) -> InstOffsetIter<'a>ⓘNotable traits for InstOffsetIter<'a>impl<'a> Iterator for InstOffsetIter<'a> type Item = (CodeOffset, Inst, CodeOffset);
Get an iterator over the instructions in block
, 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.
sourcepub fn update_encoding(
&mut self,
inst: Inst,
isa: &dyn TargetIsa
) -> Result<(), Legalize>
pub fn update_encoding(
&mut self,
inst: Inst,
isa: &dyn TargetIsa
) -> Result<(), Legalize>
Wrapper around encode
which assigns inst
the resulting encoding.
sourcepub fn encode(
&self,
inst: Inst,
isa: &dyn TargetIsa
) -> Result<Encoding, Legalize>
pub fn encode(
&self,
inst: Inst,
isa: &dyn TargetIsa
) -> Result<Encoding, Legalize>
Wrapper around TargetIsa::encode
for encoding an existing instruction
in the Function
.
sourcepub fn collect_debug_info(&mut self)
pub fn collect_debug_info(&mut self)
Starts collection of debug information.
sourcepub fn change_branch_destination(&mut self, inst: Inst, new_dest: Block)
pub fn change_branch_destination(&mut self, inst: Inst, new_dest: Block)
Changes the destination of a jump or branch instruction. Does nothing if called with a non-jump or non-branch instruction.
Note that this method ignores multi-destination branches like br_table
.
sourcepub fn rewrite_branch_destination(
&mut self,
inst: Inst,
old_dest: Block,
new_dest: Block
)
pub fn rewrite_branch_destination(
&mut self,
inst: Inst,
old_dest: Block,
new_dest: Block
)
Rewrite the branch destination to new_dest
if the destination matches old_dest
.
Does nothing if called with a non-jump or non-branch instruction.
Unlike change_branch_destination, this method rewrite the destinations of
multi-destination branches like br_table
.
sourcepub fn is_block_basic(&self, block: Block) -> Result<(), (Inst, &'static str)>
pub fn is_block_basic(&self, block: Block) -> Result<(), (Inst, &'static str)>
Checks that the specified block can be encoded as a basic block.
On error, returns the first invalid instruction and an error message.
sourcepub fn is_leaf(&self) -> bool
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.
sourcepub fn transplant_inst(&mut self, dst: Inst, src: Inst)
pub fn transplant_inst(&mut self, dst: Inst, src: Inst)
Replace the dst
instruction’s data with the src
instruction’s data
and then remove src
.
src
and its result values should not be used at all, as any uses would
be left dangling after calling this method.
src
and dst
must have the same number of resulting values, and
src
’s i^th value must have the same type as dst
’s i^th value.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Function
impl Send for Function
impl Sync for Function
impl Unpin for Function
impl UnwindSafe for Function
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more