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

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<PP>(&self, pp: PP) -> Blockwhere PP: Into<ExpandedProgramPoint>,

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 canonical_branch_inst( &self, dfg: &DataFlowGraph, block: Block ) -> Option<Inst>

Fetch the first instruction in a block’s terminal branch group.

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 block_likely_branches(&self, block: Block) -> Insts<'_>

Iterate over a limited set of instruction which are likely the branches of block in layout order. Any instruction not visited by this iterator is not a branch, but an instruction visited by this may not be a branch.

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 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<Layout> 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 ProgramOrder for Layout

source§

fn cmp<A, B>(&self, a: A, b: B) -> Orderingwhere A: Into<ExpandedProgramPoint>, B: Into<ExpandedProgramPoint>,

Compare the program points a and b relative to this program order. Read more
source§

fn is_block_gap(&self, inst: Inst, block: Block) -> bool

Is the range from inst to block just the gap between consecutive blocks? Read more
source§

impl StructuralPartialEq for Layout

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CallHasher for Twhere T: Hash + ?Sized,

source§

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64where H: Hash + ?Sized, B: BuildHasher,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.