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
Methods for laying out blocks.
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
Methods for arranging instructions.
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
Use a layout reference in a for loop.
impl<'f> IntoIterator for &'f Layout
Use a layout reference in a for loop.