The graph these dominators were computed on, for analyses that need both, such as dominance
frontiers (Java: graph()).
Time: O(1).
Returns the immediate dominator of node, or -1 if it has none.
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).
node ID in 0..nodeCount-1
immediate dominator, or -1
StaticofReturns the dominators of graph with the single entry entry. Equivalent to
of(graph, [entry]).
Time: O((nodeCount + edgeCount) log nodeCount). Memory: 4 x nodeCount bytes and 1 bit per node for the result; while it runs, up to 32 x nodeCount bytes more.
the graph
node ID in 0..nodeCount-1
the dominators
Returns the dominators of graph with the given entries.
Several entries act like one virtual root above all of them, as the class documentation describes. Their order does not matter. An entry given twice counts once, and with no entries, no node is reachable.
Time: O(number of entries + (nodeCount + edgeCount) log nodeCount). Memory: 4 x nodeCount bytes and 1 bit per node for the result; while it runs, up to 32 x nodeCount bytes more.
the graph
node IDs, each in 0..nodeCount-1
the dominators
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
ddominates a nodenif every path from an entry tonpasses throughd; every node dominates itself. The immediate dominator ofnis the dominator closest tonother thannitself. The immediate dominators form the dominator tree, which Graphs.dominatorTree 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; Dominators.isReachable tells the two apart.Whether one node dominates another is an ancestor query on the dominator tree. Ancestry.of answers it in O(log nodeCount) 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
loadfrom itsentry, and whetherbodyandthendominatenext:The post-dominators are the dominators of the transposed graph, with the exits as entries. A node
ppost-dominatesnif every path fromnto an exit passes throughp. Here,nextis the first block that every path frombodyto theexitofloadpasses through:A 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 package
@kobayami/graphity-controlflow.Instances are immutable.
Memory: 4 x nodeCount bytes and 1 bit per node, plus the graph, which stays reachable as long as the dominators are.