pub struct DominatorTree { /* private fields */ }
Expand description
The dominator tree for a single function, computed using Semi-NCA algorithm.
Implementations§
Source§impl DominatorTree
Methods for querying the dominator tree.
impl DominatorTree
Methods for querying the dominator tree.
Sourcepub fn is_reachable(&self, block: Block) -> bool
pub fn is_reachable(&self, block: Block) -> bool
Is block
reachable from the entry block?
Sourcepub fn cfg_postorder(&self) -> &[Block]
pub fn cfg_postorder(&self) -> &[Block]
Get the CFG post-order of blocks that was used to compute the dominator tree.
Note that this post-order is not updated automatically when the CFG is modified. It is
computed from scratch and cached by compute()
.
Sourcepub fn cfg_rpo(&self) -> impl Iterator<Item = &Block>
pub fn cfg_rpo(&self) -> impl Iterator<Item = &Block>
Get an iterator over CFG reverse post-order of blocks used to compute the dominator tree.
Note that the post-order is not updated automatically when the CFG is modified. It is
computed from scratch and cached by compute()
.
Sourcepub fn idom(&self, block: Block) -> Option<Block>
pub fn idom(&self, block: Block) -> Option<Block>
Returns the immediate dominator of block
.
block_a
is said to dominate block_b
if all control flow paths from the function
entry to block_b
must go through block_a
.
The immediate dominator is the dominator that is closest to block
. All other dominators
also dominate the immediate dominator.
This returns None
if block
is not reachable from the entry block, or if it is the entry block
which has no dominators.
Sourcepub fn dominates<A, B>(&self, a: A, b: B, layout: &Layout) -> bool
pub fn dominates<A, B>(&self, a: A, b: B, layout: &Layout) -> bool
Returns true
if a
dominates b
.
This means that every control-flow path from the function entry to b
must go through a
.
Dominance is ill defined for unreachable blocks. This function can always determine
dominance for instructions in the same block, but otherwise returns false
if either block
is unreachable.
An instruction is considered to dominate itself. A block is also considered to dominate itself.
Source§impl DominatorTree
impl DominatorTree
Sourcepub fn new() -> Self
pub fn new() -> Self
Allocate a new blank dominator tree. Use compute
to compute the dominator tree for a
function.
Sourcepub fn with_function(func: &Function, cfg: &ControlFlowGraph) -> Self
pub fn with_function(func: &Function, cfg: &ControlFlowGraph) -> Self
Allocate and compute a dominator tree.
Sourcepub fn compute(&mut self, func: &Function, cfg: &ControlFlowGraph)
pub fn compute(&mut self, func: &Function, cfg: &ControlFlowGraph)
Reset and compute a CFG post-order and dominator tree, using Semi-NCA algorithm, described in the paper:
Linear-Time Algorithms for Dominators and Related Problems. Loukas Georgiadis, Princeton University, November 2005.
The same algorithm is used by Julia, SpiderMonkey and LLVM, the implementation is heavily inspired by them.