Skip to main content

Cfg

Struct Cfg 

Source
pub struct Cfg { /* private fields */ }
Expand description

Who goes where in a function, and in what order to walk it.

Built with Cfg::new and read only. Nothing here holds a borrow of the function, so a pass can compute the graph, then edit the code, and the compiler will not stop it. What stops it is the pass manager, which throws this away when a pass says it changed the shape.

Implementations§

Source§

impl Cfg

Source

pub fn new(func: &Func) -> Self

Reads the graph out of the function.

Linear in the blocks and the edges between them. A function with no blocks gives an empty graph rather than an error, because a declaration is a perfectly ordinary thing for a pipeline to be handed and refusing it here would put the check in every caller.

Source

pub fn entry(&self) -> Option<Block>

Where control arrives, which is None for a function that is only declared.

Source

pub fn successors(&self, block: Block) -> &[Block]

The blocks this one branches to, each named once however many edges go to it.

Source

pub fn predecessors(&self, block: Block) -> &[Block]

The blocks that branch to this one, each named once however many edges come from it.

Source

pub fn postorder(&self) -> &[Block]

Every block the entry reaches, children before parents.

This is the order to run a backwards analysis in, and reversing it is the order to run a forwards one in. It is computed here rather than in each pass that wants it, which is how a compiler avoids acquiring six traversals that differ in ways nobody wrote down.

Source

pub fn reverse_postorder( &self, ) -> impl DoubleEndedIterator<Item = Block> + use<'_>

Every block the entry reaches, parents before children.

A block appears after at least one of its predecessors, and after all of them when the graph has no back edges. That is what makes it the order a forwards fixed point settles in fastest.

Source

pub fn rank(&self, block: Block) -> Option<u32>

Where a block sits in reverse postorder, and None for one the entry does not reach.

Source

pub fn reaches(&self, block: Block) -> bool

Whether control can arrive at this block at all.

An unreachable block is not an error and the front end makes them constantly: the block after a return, the arm of an if on a constant, the code after __builtin_unreachable. Section 6.5 of the design states the rule for the whole optimizer, which is that such a block is invisible to every analysis and every transformation, and is deleted by CFG simplification rather than by whoever noticed it. A pass that deletes blocks as a side effect of doing something else is a pass whose fuel accounting is wrong and whose dumps cannot be read.

Source

pub fn capacity(&self) -> usize

How many blocks the function has room for, counting the removed ones.

This is the length of every array indexed by block number, and is what somebody sizing their own array wants. It is not how many blocks there are.

Trait Implementations§

Source§

impl Clone for Cfg

Source§

fn clone(&self) -> Cfg

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Cfg

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Cfg

Source§

impl PartialEq for Cfg

Source§

fn eq(&self, other: &Cfg) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Cfg

Auto Trait Implementations§

§

impl Freeze for Cfg

§

impl RefUnwindSafe for Cfg

§

impl Send for Cfg

§

impl Sync for Cfg

§

impl Unpin for Cfg

§

impl UnsafeUnpin for Cfg

§

impl UnwindSafe for Cfg

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.