cranelift_codegen::ir::layout

Struct Layout

Source
pub struct Layout { /* private fields */ }
Expand description

The Layout struct determines the layout of blocks and instructions in a function. It does not contain definitions of instructions or blocks, but depends on Inst and Block entity references being defined elsewhere.

This data structure determines:

  • The order of blocks in the function.
  • Which block contains a given instruction.
  • The order of instructions with a block.

While data dependencies are not recorded, instruction ordering does affect control dependencies, so part of the semantics of the program are determined by the layout.

Implementations§

Source§

impl Layout

Source

pub fn new() -> Self

Create a new empty Layout.

Source

pub fn clear(&mut self)

Clear the layout.

Source

pub fn block_capacity(&self) -> usize

Returns the capacity of the BlockData map.

Source§

impl Layout

Source

pub fn pp_cmp<A, B>(&self, a: A, b: B) -> Ordering

Compare the program points a and b in the same block relative to this program order.

Return Less if a appears in the program before b.

This is declared as a generic such that it can be called with Inst and Block arguments directly. Depending on the implementation, there is a good chance performance will be improved for those cases where the type of either argument is known statically.

Source§

impl Layout

Methods for laying out blocks.

An unknown block starts out as not inserted in the block layout. The layout is a linear order of inserted blocks. Once a block has been inserted in the layout, instructions can be added. A block can only be removed from the layout when it is empty.

Since every block must end with a terminator instruction which cannot fall through, the layout of blocks do not affect the semantics of the program.

Source

pub fn is_block_inserted(&self, block: Block) -> bool

Is block currently part of the layout?

Source

pub fn append_block(&mut self, block: Block)

Insert block as the last block in the layout.

Source

pub fn insert_block(&mut self, block: Block, before: Block)

Insert block in the layout before the existing block before.

Source

pub fn insert_block_after(&mut self, block: Block, after: Block)

Insert block in the layout after the existing block after.

Source

pub fn remove_block(&mut self, block: Block)

Remove block from the layout.

Source

pub fn blocks(&self) -> Blocks<'_>

Return an iterator over all blocks in layout order.

Source

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

Get the function’s entry block. This is simply the first block in the layout order.

Source

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

Get the last block in the layout.

Source

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

Get the block preceding block in the layout order.

Source

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

Get the block following block in the layout order.

Source

pub fn set_cold(&mut self, block: Block)

Mark a block as “cold”.

This will try to move it out of the ordinary path of execution when lowered to machine code.

Source

pub fn is_cold(&self, block: Block) -> bool

Is the given block cold?

Source§

impl Layout

Methods for arranging instructions.

An instruction starts out as not inserted in the layout. An instruction can be inserted into a block at a given position.

Source

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

Get the block containing inst, or None if inst is not inserted in the layout.

Source

pub fn pp_block(&self, pp: ProgramPoint) -> Block

Get the block containing the program point pp. Panic if pp is not in the layout.

Source

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

Append inst to the end of block.

Source

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

Fetch a block’s first instruction.

Source

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

Fetch a block’s last instruction.

Source

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

Fetch the instruction following inst.

Source

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

Fetch the instruction preceding inst.

Source

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

Insert inst before the instruction before in the same block.

Source

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

Remove inst from the layout.

Source

pub fn block_insts(&self, block: Block) -> Insts<'_>

Iterate over the instructions in block in layout order.

Source

pub fn split_block(&mut self, new_block: Block, before: Inst)

Split the block containing before in two.

Insert new_block after the old block and move before and the following instructions to new_block:

old_block:
    i1
    i2
    i3 << before
    i4

becomes:

old_block:
    i1
    i2
new_block:
    i3 << before
    i4

Trait Implementations§

Source§

impl Clone for Layout

Source§

fn clone(&self) -> Layout

Returns a copy 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 Layout

Source§

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

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

impl<'de> Deserialize<'de> for Layout

Available on crate feature enable-serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Hash for Layout

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'f> IntoIterator for &'f Layout

Use a layout reference in a for loop.

Source§

type Item = Block

The type of the elements being iterated over.
Source§

type IntoIter = Blocks<'f>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Blocks<'f>

Creates an iterator from a value. Read more
Source§

impl PartialEq for Layout

Source§

fn eq(&self, other: &Layout) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Layout

Available on crate feature enable-serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Layout

Auto Trait Implementations§

§

impl Freeze for Layout

§

impl RefUnwindSafe for Layout

§

impl Send for Layout

§

impl Sync for Layout

§

impl Unpin for Layout

§

impl UnwindSafe for Layout

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,