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

Create a new empty Layout.

Clear the layout.

Returns the capacity of the BlockData map.

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.

Is block currently part of the layout?

Insert block as the last block in the layout.

Insert block in the layout before the existing block before.

Insert block in the layout after the existing block after.

Remove block from the layout.

Return an iterator over all blocks in layout order.

Get the function’s entry block. This is simply the first block in the layout order.

Get the last block in the layout.

Get the block preceding block in the layout order.

Get the block following block in the layout order.

Mark a block as “cold”.

This will try to move it out of the ordinary path of execution when lowered to machine code.

Is the given block cold?

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.

Get the block containing inst, or None if inst is not inserted in the layout.

Get the block containing the program point pp. Panic if pp is not in the layout.

Append inst to the end of block.

Fetch a block’s first instruction.

Fetch a block’s last instruction.

Fetch the instruction following inst.

Fetch the instruction preceding inst.

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

Insert inst before the instruction before in the same block.

Remove inst from the layout.

Iterate over the instructions in block in layout order.

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Use a layout reference in a for loop.

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

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

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.