Skip to main content

Cfg

Struct Cfg 

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

Control-flow graph for a single function.

Block indices map directly to BlockId(i as u32). The entry block is always BlockId(0).

§Reachability

The CFG stores edges for all blocks, including those unreachable from the entry. Methods that return block counts or iterate over blocks document whether they include or exclude unreachable blocks:

MethodIncludes unreachable?
num_blocks()yes
num_reachable_blocks()no
rpo() / post_order()no
is_reachable()

Implementations§

Source§

impl Cfg

Source

pub fn compute(func: &Function) -> Self

Build the CFG for func by walking each block’s terminator.

Source

pub fn entry(&self) -> BlockId

The function entry block (always index 0).

Source

pub fn num_blocks(&self) -> usize

Total number of blocks in the function, including unreachable blocks.

To iterate only reachable blocks use rpo. To count only reachable blocks use num_reachable_blocks.

Source

pub fn num_reachable_blocks(&self) -> usize

Number of blocks reachable from the entry block.

This is an O(1) operation. Equivalent to cfg.rpo().len() but without the allocation or DFS traversal cost.

Source

pub fn is_reachable(&self, bid: BlockId) -> bool

Returns true if bid is reachable from the entry block.

§Panics

Panics if bid is not a valid block index for this function (same behaviour as successors and predecessors).

Source

pub fn successors(&self, bid: BlockId) -> &[BlockId]

Successor blocks of bid.

Source

pub fn predecessors(&self, bid: BlockId) -> &[BlockId]

Predecessor blocks of bid.

Source

pub fn post_order(&self) -> Vec<BlockId>

Blocks in post-order (a block appears after all blocks it can reach).

Unreachable blocks are omitted. Use num_blocks if you need a count that includes them.

Source

pub fn rpo(&self) -> Vec<BlockId>

Blocks in reverse post-order (RPO). The entry block is first; a block always appears before any block it dominates.

Unreachable blocks are omitted. Use num_blocks if you need a count that includes them.

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.