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
sourceimpl 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 blocks(&self) -> Blocks<'_>ⓘNotable traits for Blocks<'f>impl<'f> Iterator for Blocks<'f> type Item = Block;
pub fn blocks(&self) -> Blocks<'_>ⓘNotable traits for Blocks<'f>impl<'f> Iterator for Blocks<'f> type Item = Block;
Return an iterator over all blocks in layout order.
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.
sourceimpl 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<PP>(&self, pp: PP) -> Block where
PP: Into<ExpandedProgramPoint>,
pub fn pp_block<PP>(&self, pp: PP) -> Block where
PP: Into<ExpandedProgramPoint>,
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 canonical_branch_inst(
&self,
dfg: &DataFlowGraph,
block: Block
) -> Option<Inst>
pub fn canonical_branch_inst(
&self,
dfg: &DataFlowGraph,
block: Block
) -> Option<Inst>
Fetch the first instruction in a block’s terminal branch group.
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<'_>ⓘNotable traits for Insts<'f>impl<'f> Iterator for Insts<'f> type Item = Inst;
pub fn block_insts(&self, block: Block) -> Insts<'_>ⓘNotable traits for Insts<'f>impl<'f> Iterator for Insts<'f> type Item = Inst;
Iterate over the instructions in block
in layout order.
sourcepub fn block_likely_branches(&self, block: Block) -> Insts<'_>ⓘNotable traits for Insts<'f>impl<'f> Iterator for Insts<'f> type Item = Inst;
pub fn block_likely_branches(&self, block: Block) -> Insts<'_>ⓘNotable traits for Insts<'f>impl<'f> Iterator for Insts<'f> type Item = Inst;
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.
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
sourceimpl ProgramOrder for Layout
impl ProgramOrder for Layout
sourcefn cmp<A, B>(&self, a: A, b: B) -> Ordering where
A: Into<ExpandedProgramPoint>,
B: Into<ExpandedProgramPoint>,
fn cmp<A, B>(&self, a: A, b: B) -> Ordering where
A: Into<ExpandedProgramPoint>,
B: Into<ExpandedProgramPoint>,
Compare the program points a
and b
relative to this program order. Read more
Auto Trait Implementations
impl RefUnwindSafe for Layout
impl Send for Layout
impl Sync for Layout
impl Unpin for Layout
impl UnwindSafe for Layout
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more