Struct cranelift_codegen::machinst::buffer::MachBuffer [−][src]
pub struct MachBuffer<I: VCodeInst> { /* fields omitted */ }
Expand description
A buffer of output to be produced, fixed up, and then emitted to a CodeSink in bulk.
This struct uses SmallVecs to support small-ish function bodies without
any heap allocation. As such, it will be several kilobytes large. This is
likely fine as long as it is stack-allocated for function emission then
thrown away; but beware if many buffer objects are retained persistently.
Implementations
impl<I: VCodeInst> MachBuffer<I>[src]
impl<I: VCodeInst> MachBuffer<I>[src]pub fn new() -> MachBuffer<I>[src]
pub fn new() -> MachBuffer<I>[src]Create a new section, known to start at start_offset and with a size limited to
length_limit.
pub fn cur_offset(&self) -> CodeOffset[src]
pub fn cur_offset(&self) -> CodeOffset[src]Current offset from start of buffer.
pub fn get_appended_space(&mut self, len: usize) -> &mut [u8]ⓘ[src]
pub fn get_appended_space(&mut self, len: usize) -> &mut [u8]ⓘ[src]Reserve appended space and return a mutable slice referring to it.
pub fn align_to(&mut self, align_to: CodeOffset)[src]
pub fn align_to(&mut self, align_to: CodeOffset)[src]Align up to the given alignment.
pub fn get_label(&mut self) -> MachLabel[src]
pub fn get_label(&mut self) -> MachLabel[src]Allocate a Label to refer to some offset. May not be bound to a fixed
offset yet.
pub fn reserve_labels_for_blocks(&mut self, blocks: BlockIndex)[src]
pub fn reserve_labels_for_blocks(&mut self, blocks: BlockIndex)[src]Reserve the first N MachLabels for blocks.
pub fn reserve_labels_for_constants(&mut self, constants: &VCodeConstants)[src]
pub fn reserve_labels_for_constants(&mut self, constants: &VCodeConstants)[src]Reserve the next N MachLabels for constants.
pub fn get_label_for_constant(&self, constant: VCodeConstant) -> MachLabel[src]
pub fn get_label_for_constant(&self, constant: VCodeConstant) -> MachLabel[src]Retrieve the reserved label for a constant.
pub fn bind_label(&mut self, label: MachLabel)[src]
pub fn bind_label(&mut self, label: MachLabel)[src]Bind a label to the current offset. A label can only be bound once.
pub fn use_label_at_offset(
&mut self,
offset: CodeOffset,
label: MachLabel,
kind: I::LabelUse
)[src]
pub fn use_label_at_offset(
&mut self,
offset: CodeOffset,
label: MachLabel,
kind: I::LabelUse
)[src]Emit a reference to the given label with the given reference type (i.e., branch-instruction format) at the current offset. This is like a relocation, but handled internally.
This can be called before the branch is actually emitted; fixups will not happen until an island is emitted or the buffer is finished.
pub fn add_uncond_branch(
&mut self,
start: CodeOffset,
end: CodeOffset,
target: MachLabel
)[src]
pub fn add_uncond_branch(
&mut self,
start: CodeOffset,
end: CodeOffset,
target: MachLabel
)[src]Inform the buffer of an unconditional branch at the given offset,
targetting the given label. May be used to optimize branches.
The last added label-use must correspond to this branch.
This must be called when the current offset is equal to start; i.e.,
before actually emitting the branch. This implies that for a branch that
uses a label and is eligible for optimizations by the MachBuffer, the
proper sequence is:
- Call
use_label_at_offset()to emit the fixup record. - Call
add_uncond_branch()to make note of the branch. - Emit the bytes for the branch’s machine code.
Additional requirement: no labels may be bound between start and end
(exclusive on both ends).
pub fn add_cond_branch(
&mut self,
start: CodeOffset,
end: CodeOffset,
target: MachLabel,
inverted: &[u8]
)[src]
pub fn add_cond_branch(
&mut self,
start: CodeOffset,
end: CodeOffset,
target: MachLabel,
inverted: &[u8]
)[src]Inform the buffer of a conditional branch at the given offset, targetting the given label. May be used to optimize branches. The last added label-use must correspond to this branch.
Additional requirement: no labels may be bound between start and end
(exclusive on both ends).
pub fn defer_constant(
&mut self,
label: MachLabel,
align: CodeOffset,
data: &[u8],
max_distance: CodeOffset
)[src]
pub fn defer_constant(
&mut self,
label: MachLabel,
align: CodeOffset,
data: &[u8],
max_distance: CodeOffset
)[src]Emit a constant at some point in the future, binding the given label to
its offset. The constant will be placed at most max_distance from the
current offset.
pub fn island_needed(&self, distance: CodeOffset) -> bool[src]
pub fn island_needed(&self, distance: CodeOffset) -> bool[src]Is an island needed within the next N bytes?
pub fn emit_island(&mut self)[src]
pub fn emit_island(&mut self)[src]Emit all pending constants and veneers. Should only be called if
island_needed() returns true, i.e., if we actually reach a deadline:
otherwise, unnecessary veneers may be inserted.
pub fn finish(self) -> MachBufferFinalized[src]
pub fn finish(self) -> MachBufferFinalized[src]Finish any deferred emissions and/or fixups.
pub fn add_reloc(
&mut self,
srcloc: SourceLoc,
kind: Reloc,
name: &ExternalName,
addend: Addend
)[src]
pub fn add_reloc(
&mut self,
srcloc: SourceLoc,
kind: Reloc,
name: &ExternalName,
addend: Addend
)[src]Add an external relocation at the current offset.
pub fn add_trap(&mut self, srcloc: SourceLoc, code: TrapCode)[src]
pub fn add_trap(&mut self, srcloc: SourceLoc, code: TrapCode)[src]Add a trap record at the current offset.
pub fn add_call_site(&mut self, srcloc: SourceLoc, opcode: Opcode)[src]
pub fn add_call_site(&mut self, srcloc: SourceLoc, opcode: Opcode)[src]Add a call-site record at the current offset.
pub fn add_unwind(&mut self, unwind: UnwindInst)[src]
pub fn add_unwind(&mut self, unwind: UnwindInst)[src]Add an unwind record at the current offset.
pub fn start_srcloc(&mut self, loc: SourceLoc)[src]
pub fn start_srcloc(&mut self, loc: SourceLoc)[src]Set the SourceLoc for code from this offset until the offset at the
next call to end_srcloc().
pub fn end_srcloc(&mut self)[src]
pub fn end_srcloc(&mut self)[src]Mark the end of the SourceLoc segment started at the last
start_srcloc() call.
pub fn add_stack_map(&mut self, extent: StackMapExtent, stack_map: StackMap)[src]
pub fn add_stack_map(&mut self, extent: StackMapExtent, stack_map: StackMap)[src]Add stack map metadata for this program point: a set of stack offsets (from SP upward) that contain live references.
The offset_to_fp value is the offset from the nominal SP (at which the stack_offsets
are based) and the FP value. By subtracting offset_to_fp from each stack_offsets
element, one can obtain live-reference offsets from FP instead.
Auto Trait Implementations
impl<I> RefUnwindSafe for MachBuffer<I> where
<I as MachInst>::LabelUse: RefUnwindSafe,
<I as MachInst>::LabelUse: RefUnwindSafe,
impl<I> Send for MachBuffer<I> where
<I as MachInst>::LabelUse: Send,
<I as MachInst>::LabelUse: Send,
impl<I> Sync for MachBuffer<I> where
<I as MachInst>::LabelUse: Sync,
<I as MachInst>::LabelUse: Sync,
impl<I> Unpin for MachBuffer<I> where
<I as MachInst>::LabelUse: Unpin,
<I as MachInst>::LabelUse: Unpin,
impl<I> UnwindSafe for MachBuffer<I> where
<I as MachInst>::LabelUse: RefUnwindSafe + UnwindSafe,
<I as MachInst>::LabelUse: RefUnwindSafe + UnwindSafe,