Struct cranelift_codegen::ir::layout::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

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.

§

type Item = Block

The type of the elements being iterated over.
§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Layout

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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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>,