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
impl Layout
sourcepub fn pp_cmp<A, B>(&self, a: A, b: B) -> Ordering
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
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.
sourcepub fn is_block_inserted(&self, block: Block) -> bool
pub fn is_block_inserted(&self, block: Block) -> bool
Is block
currently part of the layout?
sourcepub fn append_block(&mut self, block: Block)
pub fn append_block(&mut self, block: Block)
Insert block
as the last block in the layout.
sourcepub fn insert_block(&mut self, block: Block, before: Block)
pub fn insert_block(&mut self, block: Block, before: Block)
Insert block
in the layout before the existing block before
.
sourcepub fn insert_block_after(&mut self, block: Block, after: Block)
pub fn insert_block_after(&mut self, block: Block, after: Block)
Insert block
in the layout after the existing block after
.
sourcepub fn remove_block(&mut self, block: Block)
pub fn remove_block(&mut self, block: Block)
Remove block
from the layout.
sourcepub fn entry_block(&self) -> Option<Block>
pub fn entry_block(&self) -> Option<Block>
Get the function’s entry block. This is simply the first block in the layout order.
sourcepub fn last_block(&self) -> Option<Block>
pub fn last_block(&self) -> Option<Block>
Get the last block in the layout.
sourcepub fn prev_block(&self, block: Block) -> Option<Block>
pub fn prev_block(&self, block: Block) -> Option<Block>
Get the block preceding block
in the layout order.
sourcepub fn next_block(&self, block: Block) -> Option<Block>
pub fn next_block(&self, block: Block) -> Option<Block>
Get the block following block
in the layout order.
source§impl Layout
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.
sourcepub fn inst_block(&self, inst: Inst) -> Option<Block>
pub fn inst_block(&self, inst: Inst) -> Option<Block>
Get the block containing inst
, or None
if inst
is not inserted in the layout.
sourcepub fn pp_block(&self, pp: ProgramPoint) -> Block
pub fn pp_block(&self, pp: ProgramPoint) -> Block
Get the block containing the program point pp
. Panic if pp
is not in the layout.
sourcepub fn append_inst(&mut self, inst: Inst, block: Block)
pub fn append_inst(&mut self, inst: Inst, block: Block)
Append inst
to the end of block
.
sourcepub fn first_inst(&self, block: Block) -> Option<Inst>
pub fn first_inst(&self, block: Block) -> Option<Inst>
Fetch a block’s first instruction.
sourcepub fn insert_inst(&mut self, inst: Inst, before: Inst)
pub fn insert_inst(&mut self, inst: Inst, before: Inst)
Insert inst
before the instruction before
in the same block.
sourcepub fn remove_inst(&mut self, inst: Inst)
pub fn remove_inst(&mut self, inst: Inst)
Remove inst
from the layout.
sourcepub fn block_insts(&self, block: Block) -> Insts<'_> ⓘ
pub fn block_insts(&self, block: Block) -> Insts<'_> ⓘ
Iterate over the instructions in block
in layout order.
sourcepub fn split_block(&mut self, new_block: Block, before: Inst)
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<'f> IntoIterator for &'f Layout
impl<'f> IntoIterator for &'f Layout
Use a layout reference in a for loop.