Algorithm Search⌘K

Definitioncore

Dominance frontier

Also called DF set.

The nodes where the dominance of a node n ends, that is, nodes with a predecessor dominated by n that are not strictly dominated by n.

The dominance frontier of a node xx in a flow graph is the set of nodes where the dominance of xx stops. A node yy is in it if xx dominates a predecessor of yy but does not strictly dominate yy itself. So yy can be reached from xx, and also along a path that avoids xx. If a variable is assigned in xx, then yy is the first place where that value can meet a different value of the same variable. This is why the dominance frontier tells a compiler where to put phi-functions when it builds static single assignment form. Cytron, Ferrante, Rosen, Wegman and Zadeck defined it in 1991, together with the iterated dominance frontier and a fast way to compute both.

Definition

The frontier of one node

Let G=(N,E,r)G = (N, E, r) be a control flow graph with entry rr, in which every node is reachable from rr. A node xx dominates yy, written xdom⁡yx \operatorname{dom} y, if every path from rr to yy passes through xx. It strictly dominates yy if also x≠yx \ne y. The dominance frontier of xx is

DF(x)={ y∈N:∃ (p,y)∈E with xdom⁡p and not xsdom⁡y }.DF(x) = \{\, y \in N : \exists\, (p, y) \in E \text{ with } x \operatorname{dom} p \text{ and not } x \operatorname{sdom} y \,\}.

The node xx itself can be in DF(x)DF(x). This happens when xx dominates a predecessor of xx, as a loop header does with its latch.

The frontier of a set, and the iterated frontier

For a set SS of nodes, DF(S)=⋃x∈SDF(x)DF(S) = \bigcup_{x \in S} DF(x). The iterated dominance frontier DF+(S)DF^+(S) is the limit of

DF1=DF(S),DFi+1=DF(S∪DFi).DF_1 = DF(S), \qquad DF_{i+1} = DF(S \cup DF_i).

The sequence grows and NN is finite, so it stops. DF+(S)DF^+(S) is the smallest set TT with DF(S∪T)⊆TDF(S \cup T) \subseteq T. A worklist computes it: start with the nodes of SS, and add the frontier of each node taken from the list, putting each new node on the list once.

The main theorem

Let SS be the set of blocks that assign a variable vv, plus the entry rr, which holds the initial value. A block yy is a join point of SS if there are two non-empty paths that start at two different nodes of SS, end at yy, and have no other node in common. Cytron et al. proved that the join points of SS are exactly DF+(S)DF^+(S). So minimal SSA form puts a phi-function for vv at each block of DF+(S)DF^+(S), and at no other block. The SSA construction problem page proves this.

Two other ways to write it

By the dominator tree, bottom up. Let idom(y)\mathrm{idom}(y) be the parent of yy in the dominator tree. Cytron et al. split DF(x)DF(x) into a local part and a part that comes up from the children:

DFlocal(x)={ y:(x,y)∈E, idom(y)≠x },DF_{\text{local}}(x) = \{\, y : (x, y) \in E,\ \mathrm{idom}(y) \ne x \,\},
DFup(z)={ y∈DF(z):idom(y)≠idom(z) },DF_{\text{up}}(z) = \{\, y \in DF(z) : \mathrm{idom}(y) \ne \mathrm{idom}(z) \,\},
DF(x)=DFlocal(x)∪⋃z : idom(z)=xDFup(z).DF(x) = DF_{\text{local}}(x) \cup \bigcup_{z \,:\, \mathrm{idom}(z) = x} DF_{\text{up}}(z).

This gives an algorithm that visits the tree in postorder. See dominance frontier computation.

By the edges. Every node dd that strictly dominates yy also dominates every predecessor pp of yy: a path from rr to pp that avoids dd, followed by the edge (p,y)(p, y), would avoid dd too. So idom(y)\mathrm{idom}(y) is an ancestor of pp in the dominator tree, and the ancestors of pp form a chain. A node xx that dominates pp is on this chain. It strictly dominates yy if and only if it is idom(y)\mathrm{idom}(y) or above it. So

y∈DF(x)  ⟺  some predecessor p of y has x on the tree path from p up to idom(y), with idom(y) excluded.y \in DF(x) \iff \text{some predecessor } p \text{ of } y \text{ has } x \text{ on the tree path from } p \text{ up to } \mathrm{idom}(y), \text{ with } \mathrm{idom}(y) \text{ excluded}.

If y=ry = r, no node strictly dominates yy, and the whole path from pp up to rr counts. The walk of Cooper, Harvey and Kennedy uses this form. A node yy with one predecessor pp has idom(y)=p\mathrm{idom}(y) = p, so the path is empty and yy is in no frontier. Only join nodes appear in dominance frontiers.

Size

The sum ∑x∣DF(x)∣\sum_x |DF(x)| can be quadratic in the size of the graph. Take nn nested repeat-until loops. The nodes are headers h1,…,hnh_1, \ldots, h_n, latches l1,…,lnl_1, \ldots, l_n and an exit ee, with entry h1h_1. The edges are hi→hi+1h_i \to h_{i+1} for i<ni < n, hn→lnh_n \to l_n, the back edges li→hil_i \to h_i, the loop exits li→li−1l_i \to l_{i-1} for i>1i > 1, and l1→el_1 \to e. The graph has 2n+12n + 1 nodes and 3n3n edges. Its dominator tree is the path h1,…,hn,ln,ln−1,…,l1,eh_1, \ldots, h_n, l_n, l_{n-1}, \ldots, l_1, e. For each ii,

DF(hi)=DF(li)={h1,…,hi},DF(h_i) = DF(l_i) = \{h_1, \ldots, h_i\},

because the back edge lj→hjl_j \to h_j leaves the region dominated by hih_i and lil_i for each j≤ij \le i. The total is n(n+1)n(n + 1), which is Θ(N2)\Theta(N^2) for NN nodes. If a variable viv_i is assigned in lil_i, then DF+({h1,li})={h1,…,hi}DF^+(\{h_1, l_i\}) = \{h_1, \ldots, h_i\}, and minimal SSA form has n(n+1)/2n(n+1)/2 phi-functions for these nn variables. Cytron et al. measured the frontiers of real programs and found their total size grew about linearly. Sreedhar and Gao showed that DF+(S)DF^+(S) can be found in time linear in the size of the graph, without computing the frontiers at all.

The reverse graph

On the reverse graph, with the exit as the entry, dominance becomes post-dominance, and the dominance frontier becomes the post-dominance frontier. A block yy is control dependent on xx if and only if xx is in the post-dominance frontier of yy. Cytron et al. build the control dependence graph this way.

Examples and non-examples

A loop with a branch inside

The program that adds the odd numbers below nn, from the control flow graph page, has the edges B1 → B2, B2 → B3, B2 → B6, B3 → B4, B3 → B5, B4 → B5 and B5 → B2. The immediate dominators are B1 for B2, B2 for B3 and B6, and B3 for B4 and B5. The frontiers are:

node DF
B1 ∅
B2 {B2}
B3 {B2}
B4 {B5}
B5 {B2}
B6 ∅
  • DF(B4)={B5}DF(B4) = \{B5\}: B4 dominates itself, a predecessor of B5, but B5 can be reached through B3 → B5, so B4 does not dominate it.
  • DF(B2)={B2}DF(B2) = \{B2\}: B2 dominates the latch B5, which is a predecessor of B2, and B2 does not strictly dominate itself.
  • DF(B3)={B2}DF(B3) = \{B2\} and DF(B5)={B2}DF(B5) = \{B2\}: from the back edge B5 → B2. By the edge form, the walk from B5 up to idom(B2)=B1\mathrm{idom}(B2) = B1 passes B5, B3 and B2.

The variable s is assigned in B1 and B4. Then DF({B1,B4})={B5}DF(\{B1, B4\}) = \{B5\}, DF({B1,B4,B5})={B5,B2}DF(\{B1, B4, B5\}) = \{B5, B2\}, and adding B2 gives nothing new. So DF+={B2,B5}DF^+ = \{B2, B5\}, and these are the two blocks that get a phi-function for s in the SSA form of this program. The variable i is assigned in B1 and B5, and DF+={B2}DF^+ = \{B2\}.

Three nested repeat-until loops

For n=3n = 3 the quadratic family above has the nodes h1,h2,h3,l3,l2,l1,eh_1, h_2, h_3, l_3, l_2, l_1, e and

DF(h1)=DF(l1)={h1},DF(h2)=DF(l2)={h1,h2},DF(h3)=DF(l3)={h1,h2,h3},DF(e)=∅,DF(h_1) = DF(l_1) = \{h_1\},\quad DF(h_2) = DF(l_2) = \{h_1, h_2\},\quad DF(h_3) = DF(l_3) = \{h_1, h_2, h_3\},\quad DF(e) = \emptyset,

12 entries in total for 7 nodes and 9 edges.

Non-examples

  • A node with one predecessor. It is in no dominance frontier, since its predecessor is its immediate dominator.
  • A node dominated by xx. If xx strictly dominates yy, then yy is not in DF(x)DF(x), even if yy is a join node. In the example, B5 is a join node but is not in DF(B3)DF(B3), because B3 dominates B5.
  • The successors of xx. DF(x)DF(x) is not the set of successors of xx. A successor can be strictly dominated by xx, and a node far from xx can be in DF(x)DF(x), as h1∈DF(l3)h_1 \in DF(l_3) shows.

References

  1. Ron Cytron, Jeanne Ferrante, Barry K. Rosen, Mark N. Wegman and F. Kenneth Zadeck, Efficiently computing static single assignment form and the control dependence graph, ACM Transactions on Programming Languages and Systems 13(4), 1991, pages 451-490, the definition of the dominance frontier, of DF of a set and of the iterated dominance frontier, the split into DF_local and DF_up, the theorem that the join points of a variable are its iterated dominance frontier, and control dependence as the dominance frontier of the reverse graph
  2. Vugranam C. Sreedhar and Guang R. Gao, A linear time algorithm for placing phi-nodes, Proceedings of the 22nd ACM Symposium on Principles of Programming Languages (POPL), 1995, pages 62-73, DJ-graphs, and the iterated dominance frontier computed without the full dominance frontiers
  3. Keith D. Cooper, Timothy J. Harvey and Ken Kennedy, A simple, fast dominance algorithm, technical report, Department of Computer Science, Rice University, the dominance frontier algorithm that walks up the dominator tree from each predecessor of a join node to its immediate dominator
  4. Andrew W. Appel with Jens Palsberg, Modern Compiler Implementation in Java, second edition, Cambridge University Press, 2002, Chapter 19 (Static Single-Assignment Form), the dominance frontier criterion and the computation of DF
  5. Fabrice Rastello and Florent Bouchez Tichadou (editors), SSA-based Compiler Design, Springer, 2022, Chapter 3 (Standard Construction and Destruction Algorithms), join sets and dominance frontiers; Chapter 4 (Advanced Construction Algorithms for SSA), DJ-graphs and merge sets

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/BRKW75/text.yaml