Class IteratedDominanceFrontier
- Namespace
- Graphity.ControlFlow
- Assembly
- Graphity.ControlFlow.dll
The iterated dominance frontiers of a control-flow graph, which tell where SSA (static single assignment) form places phi-nodes.
public sealed class IteratedDominanceFrontier
- Inheritance
-
IteratedDominanceFrontier
- Inherited Members
Examples
Here, for the loop variable i of a method load, whose control flow cfg has the
blocks entry and next:
Dominators dominators = Dominators.Of(BiAdjacentGraph.Of(cfg), entry);
IteratedDominanceFrontier phis = IteratedDominanceFrontier.Of(dominators);
// i is assigned in entry (i = 0) and in next (i++)
SortedIntView phiBlocks = phis.FrontierOf([entry, next]);
// phiBlocks: [1] - header
Remarks
In SSA form, every assignment to a variable creates a new version of it, and a phi-node merges the versions where paths of control flow meet. The phi-nodes of a variable go into the iterated dominance frontier of the blocks that assign it: the dominance frontier of these blocks, then the dominance frontier of the result, and so on until nothing new is added. A compiler asks this once per variable, so Of(Dominators) prepares the queries once per control-flow graph, and FrontierOf(ReadOnlySpan<int>) answers them.
Uses the algorithm of Sreedhar and Gao. A query walks the subtrees of the dominator tree below the nodes it is given and the nodes it adds, so its cost depends on the part of the graph it explores, not on the whole graph. It never builds the dominance frontiers themselves, which can grow quadratically with the node count; DominanceFrontiers(Dominators) returns them as a graph.
Instances are immutable and safe to share between threads.
Memory: 16 x NodeCount bytes, plus the Dominators it was built from, which stay reachable as long as it is held.
Methods
FrontierOf(ReadOnlySpan<int>)
Returns the iterated dominance frontier of nodes, in ascending order.
public SortedIntView FrontierOf(ReadOnlySpan<int> nodes)
Parameters
nodesReadOnlySpan<int>Node IDs in
0..NodeCount-1, such as the blocks that assign a variable.
Returns
- SortedIntView
The iterated dominance frontier.
Remarks
The result can contain given nodes, such as the header of a natural loop, which is in its own dominance frontier. Nodes that the entries do not reach are ignored, and so are duplicates.
Time: O(nodes.Length + e + (s + k) log(s + k)), where e is the number of nodes and edges
the query explores, at most NodeCount + EdgeCount; s is the number of distinct given nodes that
the entries reach, and k the size of the result.
Memory: 4 x k bytes for the result; while it runs, up to about 60 bytes per node the query
explores, and nothing sized by the whole graph.
Exceptions
- ArgumentOutOfRangeException
A node is out of range.
- ArgumentException
The query explores more than 805,306,368 nodes.
Of(Dominators)
Returns the iterated dominance frontiers of the graph that dominators were
computed on, ready for queries.
public static IteratedDominanceFrontier Of(Dominators dominators)
Parameters
dominatorsDominatorsThe dominators of the control-flow graph.
Returns
- IteratedDominanceFrontier
The iterated dominance frontiers.
Remarks
They are prepared anew on every call, not cached: keep the result and query it for every variable.
Time: O(NodeCount).
Memory: 16 x NodeCount bytes for the result; while it runs, 8 x NodeCount bytes more.