pub struct Dominators { /* private fields */ }Expand description
The dominators of a graph with one or more entries, such as the control flow of a method, given by the immediate dominator of every node.
A node d dominates a node n if every path from an entry to n passes through d; every node
dominates itself. The immediate dominator of n is the dominator closest to n other than n
itself. The immediate dominators form the dominator tree, which
graphs::dominator_tree returns as a graph. Several entries act
like one virtual root above all of them. A node that only this virtual root dominates, such as an
entry, has no immediate dominator and is a root of the dominator tree, which is then a forest. A
node that no entry reaches has no immediate dominator either; is_reachable
tells the two apart.
Whether one node dominates another is an ancestor query on the dominator tree.
Ancestry::of_dominators answers it in O(log node_count) and
PreorderAncestry in O(1). The analysis follows the edges against their
direction, so it takes a BiAdjacentGraph. Here, the dominators of the basic blocks of the
method load from its entry, and whether body and then dominate next:
let dominators = Dominators::of(&BiAdjacentGraph::of(&cfg), entry);
let idom = dominators.immediate_dominator_of(next); // Some(2) - the block body
let dominance = Ancestry::of_dominators(&dominators);
let body_dominates_next = dominance.is_ancestor_of(body, next); // true
let then_dominates_next = dominance.is_ancestor_of(then, next); // falseThe post-dominators are the dominators of the transposed graph, with the exits as entries. A node
p post-dominates n if every path from n to an exit passes through p. Here, next is the
first block that every path from body to the exit of load passes through:
let post_dominators = Dominators::of(&BiAdjacentGraph::of(&cfg).transposed(), exit);
let join = post_dominators.immediate_dominator_of(body); // Some(4) - the block nextA node from which no exit can be reached, such as one in an endless loop, has no post-dominator, unless an extra exit with an edge from that loop is added to the graph first.
Uses the algorithm of Lengauer and Tarjan,
without recursion. Dominance frontiers and control dependence are in the crate
graphity-controlflow.
Instances are immutable and safe to share between threads (Send and Sync).
Memory: 4 x node_count bytes and 1 bit per node, plus the graph, which stays reachable as long as the dominators are.
Implementations§
Source§impl Dominators
impl Dominators
Sourcepub fn of(graph: &BiAdjacentGraph, entry: u32) -> Dominators
pub fn of(graph: &BiAdjacentGraph, entry: u32) -> Dominators
Returns the dominators of graph with the single entry entry. Equivalent to
of_entries(graph, &[entry]) - Java’s overload of(BiAdjacentGraph, int).
Time: O((node_count + edge_count) log node_count). Memory: 4 x node_count bytes and 1 bit per node for the result; while it runs, up to 32 x node_count bytes more.
§Panics
With an index out of bounds message if entry is not in 0..node_count; with an
invalid argument message if graph has more than 2^30 - 6 nodes.
Sourcepub fn of_entries(graph: &BiAdjacentGraph, entries: &[u32]) -> Dominators
pub fn of_entries(graph: &BiAdjacentGraph, entries: &[u32]) -> Dominators
Returns the dominators of graph with the given entries - Java’s overload
of(BiAdjacentGraph, IntList).
Several entries act like one virtual root above all of them, as the type documentation describes. Their order does not matter. An entry given twice counts once, and with no entries, no node is reachable.
Time: O(entries.len() + (node_count + edge_count) log node_count). Memory: 4 x node_count bytes and 1 bit per node for the result; while it runs, up to 32 x node_count bytes more.
§Panics
With an index out of bounds message if an entry is not in 0..node_count; with an
invalid argument message if graph has more than 2^30 - 6 nodes.
Sourcepub fn graph(&self) -> &BiAdjacentGraph
pub fn graph(&self) -> &BiAdjacentGraph
Returns the graph these dominators were computed on, for analyses that need both, such as dominance frontiers. It shares its arrays with the graph passed in.
Time: O(1).
Sourcepub fn immediate_dominator_of(&self, node: u32) -> Option<u32>
pub fn immediate_dominator_of(&self, node: u32) -> Option<u32>
Returns the immediate dominator of node, or None if it has none - Java’s -1.
A node has none if it is an entry, if only the virtual root above several entries dominates it, or if no entry reaches it.
Time: O(1).
§Panics
With an index out of bounds message if node is not in 0..node_count.
Sourcepub fn is_reachable(&self, node: u32) -> bool
pub fn is_reachable(&self, node: u32) -> bool
Returns whether node is reachable from an entry.
Time: O(1).
§Panics
With an index out of bounds message if node is not in 0..node_count.
Trait Implementations§
Source§impl Clone for Dominators
impl Clone for Dominators
Source§fn clone(&self) -> Dominators
fn clone(&self) -> Dominators
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more