Algorithm Search⌘K

Definitioncore

Control dependence

Also called control dependence graph.

Node n is control dependent on branch b if one edge out of b forces n to run and another can skip it, found from post-dominance frontiers.

Control dependence says which branch decides whether a node of a control flow graph runs. Node YY is control dependent on node XX if one edge out of XX makes YY certain to run and another edge out of XX can skip YY. Ferrante, Ottenstein and Warren (1987) defined it through post-dominance, and Cytron et al. (1991) showed that the nodes that control YY are the dominance frontier of YY in the reverse graph. The relation, drawn as a graph with an edge from XX to each node that depends on it, is the control dependence graph. Together with data dependence it makes the program dependence graph, and it drives aggressive dead code elimination and program slicing.

Definition

Let G=(N,E)G = (N, E) be a control flow graph with an entry node and one exit node xx, in which every node reaches xx. Add a node START with an edge to the entry and an edge to xx. The second edge is not a real control transfer: it says that the procedure may not run at all, and it makes the nodes that run on every run depend on START, so that every node except START has a parent in the control dependence graph. Post-dominance is taken in this augmented graph, written p  pdom  vp \;\mathrm{pdom}\; v, with ipdom(v)\mathrm{ipdom}(v) the immediate post-dominator.

Path form (Ferrante, Ottenstein and Warren). YY is control dependent on XX if

  1. there is a path X→v1→⋯→vk=YX \to v_1 \to \dots \to v_k = Y with k≥1k \ge 1 on which Y  pdom  viY \;\mathrm{pdom}\; v_i for every ii, and
  2. YY does not strictly post-dominate XX.

Edge form. YY is control dependent on XX through the edge X→SX \to S if Y  pdom  SY \;\mathrm{pdom}\; S and YY does not strictly post-dominate XX. The successor SS is the label of the dependence: it records which way the branch at XX must go for YY to run. A two-way branch with a true edge and a false edge gives labels T and F.

Reverse dominance frontier. Let GTG^T be the transpose of the augmented graph, with xx as its start. The post-dominators in GG are the dominators in GTG^T, so the dominance frontier of YY in GTG^T is

RDF(Y)={X:Y  pdom  S for some successor S of X, and Y does not strictly post-dominate X}.\mathrm{RDF}(Y) = \{X : Y \;\mathrm{pdom}\; S \text{ for some successor } S \text{ of } X, \text{ and } Y \text{ does not strictly post-dominate } X\}.

The three forms define the same relation.

Theorem (Cytron et al. 1991). For all nodes XX and YY: YY is control dependent on XX by the path form, iff it is by the edge form through some successor of XX, iff X∈RDF(Y)X \in \mathrm{RDF}(Y).

Proof. The edge form and the formula for RDF(Y)\mathrm{RDF}(Y) are the same text, because the predecessors of XX in GTG^T are the successors of XX in GG, and "dominates in GTG^T" is "post-dominates in GG". It is left to show that the path form and the edge form agree. Condition 2 is the same in both. If a path as in condition 1 exists, its first node after XX is a successor S=v1S = v_1, and Y  pdom  v1Y \;\mathrm{pdom}\; v_1, so the edge form holds. Conversely, let Y  pdom  SY \;\mathrm{pdom}\; S for a successor SS of XX. Take any path from SS to xx. It contains YY, so cut it at the first occurrence of YY: S=v1,…,vk=YS = v_1, \dots, v_k = Y. Suppose some viv_i with i<ki < k were not post-dominated by YY. Then some path from viv_i to xx avoids YY, and the prefix v1,…,viv_1, \dots, v_i also avoids YY, so their join is a path from SS to xx that avoids YY, which contradicts Y  pdom  SY \;\mathrm{pdom}\; S. So X,v1,…,vkX, v_1, \dots, v_k is a path as in condition 1. □\square

Computing it from the post-dominator tree

The edge form gives a direct algorithm. Build the post-dominator tree, for example with the Cooper-Harvey-Kennedy iteration on GTG^T. Then:

for each edge a -> b of the augmented CFG:
    if b != ipdom(a):
        runner = b
        while runner != ipdom(a):
            record: runner is control dependent on a, label b
            runner = ipdom(runner)

Why the walk is correct. Fix an edge a→ba \to b. By the edge form, the nodes that depend on aa through it are the post-dominators of bb that are not strict post-dominators of aa. In the post-dominator tree, the post-dominators of bb are the ancestors of bb (with bb itself), and the strict post-dominators of aa are ipdom(a)\mathrm{ipdom}(a) and its ancestors. Now ipdom(a)\mathrm{ipdom}(a) post-dominates bb: a path from bb to xx, with the edge a→ba \to b in front, is a path from aa to xx, so it holds ipdom(a)\mathrm{ipdom}(a), and ipdom(a)≠a\mathrm{ipdom}(a) \ne a, so ipdom(a)\mathrm{ipdom}(a) lies on the part after aa. So ipdom(a)\mathrm{ipdom}(a) is an ancestor of bb, and the wanted set is the tree path from bb up to ipdom(a)\mathrm{ipdom}(a) with ipdom(a)\mathrm{ipdom}(a) left out. That is what the walk visits. If b=ipdom(a)b = \mathrm{ipdom}(a) the set is empty, and these are the only edges that give nothing: if bb strictly post-dominates aa, then bb is ipdom(a)\mathrm{ipdom}(a) or above it, and also below it, so b=ipdom(a)b = \mathrm{ipdom}(a).

Cost. The post-dominator tree costs what dominators cost on a graph with nn nodes and mm edges. Each step of the walk records one new triple, so the walks cost O(m+c)O(m + c), where cc is the number of (node, branch, label) triples in the answer. The answer itself can have Θ(n2)\Theta(n^2) pairs with only O(n)O(n) edges, as the chain example below shows. Pingali and Bilardi (1997) avoid building it: their augmented post-dominator tree takes O(m)O(m) time and space to build and answers "which nodes depend on this edge", "which edges does this node depend on" and "which nodes have the same dependences" in time proportional to the size of the answer.

Properties

  • Self-dependence. A node can be control dependent on itself. This happens exactly when XX has a successor SS with X  pdom  SX \;\mathrm{pdom}\; S, that is, when XX is a loop test and one edge stays in the loop.
  • Only branches control. If XX has one successor SS, then S=ipdom(X)S = \mathrm{ipdom}(X), so no node depends on XX.
  • The parents of a node. The nodes that YY depends on are RDF(Y)\mathrm{RDF}(Y), so they can also be found with the dominance frontier computation run on GTG^T, one node at a time.
  • Regions. Two nodes with the same set of (branch, label) pairs run under the same conditions. Ferrante, Ottenstein and Warren group such nodes under one region node in the program dependence graph.

Examples and non-examples

The odd-sum loop

The toy IR program that adds the odd numbers below nn has blocks B1 to B6, where B2 is the loop test br t1 B3 B6, B3 is the parity test br t2 B4 B5, B4 adds, B5 increments and jumps back to B2, and B6 returns. After START and EXIT are added, the post-dominator tree has the edges ipdom(B1)=B2\mathrm{ipdom}(B1) = B2, ipdom(B2)=B6\mathrm{ipdom}(B2) = B6, ipdom(B3)=ipdom(B4)=B5\mathrm{ipdom}(B3) = \mathrm{ipdom}(B4) = B5, ipdom(B5)=B2\mathrm{ipdom}(B5) = B2, ipdom(B6)=EXIT\mathrm{ipdom}(B6) = \mathrm{EXIT} and ipdom(START)=EXIT\mathrm{ipdom}(\mathrm{START}) = \mathrm{EXIT}.

Of the ten edges, seven end at the immediate post-dominator of their source and give nothing: START→EXIT\mathrm{START} \to \mathrm{EXIT}, B1→B2B1 \to B2, B2→B6B2 \to B6, B3→B5B3 \to B5, B4→B5B4 \to B5, B5→B2B5 \to B2 and B6→EXITB6 \to \mathrm{EXIT}. The other three walk:

edge stop at walk visits dependences recorded
START→B1\mathrm{START} \to B1 EXIT B1, B2, B6 B1, B2, B6 on START
B2→B3B2 \to B3 B6 B3, B5, B2 B3, B5, B2 on B2, label B3
B3→B4B3 \to B4 B5 B4 B4 on B3, label B4

So B1, B2 and B6 run on every run, B3 and B5 run once per trip of the loop, B2 depends on itself because it is the loop test, and B4 runs only when the parity test takes its true edge. The post-dominance page derives the same block dependences from the edge form by hand.

A diamond

For B0: br a B1 B2, B1: x = 1; jump B3, B2: x = 2; jump B3, B3: ret x, the dependences are B0 and B3 on START, B1 on B0 with label B1, and B2 on B0 with label B2. The join block B3 depends on nothing inside the procedure, because both edges of B0 reach it.

A chain with back edges

Take blocks v1,…,vkv_1, \dots, v_k with the edges vi→vi+1v_i \to v_{i+1}, an edge vk→xv_k \to x, and an edge vi→v1v_i \to v_1 from every viv_i. Every path to xx passes through all of v1,…,vkv_1, \dots, v_k in order, so ipdom(vi)=vi+1\mathrm{ipdom}(v_i) = v_{i+1}. The edge vi→v1v_i \to v_1 walks v1,v2,…,viv_1, v_2, \dots, v_i, so vjv_j depends on viv_i for every j≤ij \le i. That is k(k+1)/2k(k+1)/2 dependences from 2k2k edges, which is why an explicit control dependence graph can be quadratic in the size of the CFG.

Non-examples

  • Both edges reach the node. In the odd-sum loop, B5 is not control dependent on B3: B5 post-dominates both successors of B3, and it strictly post-dominates B3 itself.
  • One edge goes straight to the node. B6 is not control dependent on B2, even though the edge B2→B6B2 \to B6 reaches it at once. B6 strictly post-dominates B2, since leaving the loop is the only way to return, so condition 2 fails.
  • Reachability is not dependence. B4 is reachable from B2, but it is not control dependent on B2: B4 does not post-dominate B3, the only node after B2 on any path to B4.
  • Code after an infinite loop. If a loop may never stop, the code after it runs only if the loop stops. The standard (strong) definition ignores this: the node after a loop post-dominates the loop test, so it does not depend on it. A loop with no exit at all leaves nodes that cannot reach xx, and the definition does not apply until a fake exit edge is added, as discussed under post-dominance.
  • Weak control dependence. Podgurski and Clarke (1990) call the definition above strong control dependence, and define a weak form that also makes the code after a loop depend on the loop test, because the loop might not terminate. Analyses that must keep non-termination, such as some slicers, use the weak form.
  • Generalized control dependence. Bilardi and Pingali (1996) give one framework, parameterized by a set of paths, from which the strong and weak forms both follow.
  • Post-dominance and the dominator tree: the relation is read off the post-dominator tree.
  • Dominance frontier: control dependence is the dominance frontier of the reverse graph.
  • Data dependence: the other kind of edge in a program dependence graph.
  • Static single information form: it renames variables at the branch points that control dependence names.

References

  • Jeanne Ferrante, Karl J. Ottenstein and Joe D. Warren. The program dependence graph and its use in optimization. ACM TOPLAS 9(3), 1987, pages 319-349. The path definition and the walk over the post-dominator tree.
  • 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 TOPLAS 13(4), 1991, pages 451-490. Control dependence as reverse dominance frontiers.
  • Andy Podgurski and Lori A. Clarke. A formal model of program dependences and its implications for software testing, debugging, and maintenance. IEEE TSE 16(9), 1990, pages 965-979. Strong and weak control dependence.
  • Keshav Pingali and Gianfranco Bilardi. Optimal control dependence computation and the Roman chariots problem. ACM TOPLAS 19(3), 1997, pages 462-491.
  • Gianfranco Bilardi and Keshav Pingali. A framework for generalized control dependence. PLDI 1996, pages 291-300.
  • Steven S. Muchnick. Advanced Compiler Design and Implementation. Morgan Kaufmann, 1997. The chapter on dependence analysis and dependence graphs.
  1. Jeanne Ferrante, Karl J. Ottenstein and Joe D. Warren, The program dependence graph and its use in optimization, ACM Transactions on Programming Languages and Systems 9(3), 1987, pages 319-349, the definition of control dependence by paths and post-dominance, and its computation from the post-dominator tree
  2. 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 section on the control dependence graph, which proves that control dependences are the dominance frontiers of the reverse control flow graph
  3. Andy Podgurski and Lori A. Clarke, A formal model of program dependences and its implications for software testing, debugging, and maintenance, IEEE Transactions on Software Engineering 16(9), 1990, pages 965-979, strong and weak control dependence
  4. Keshav Pingali and Gianfranco Bilardi, Optimal control dependence computation and the Roman chariots problem, ACM Transactions on Programming Languages and Systems 19(3), 1997, pages 462-491, the augmented post-dominator tree, which answers control dependence queries in time proportional to the size of the answer after linear preprocessing
  5. Gianfranco Bilardi and Keshav Pingali, A framework for generalized control dependence, PLDI 1996, pages 291-300, control dependence relative to a family of path sets, which covers the strong and weak forms
  6. Steven S. Muchnick, Advanced Compiler Design and Implementation, Morgan Kaufmann, 1997, the chapter on dependence analysis and dependence graphs, control dependence and program dependence graphs

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/10RK1C/text.yaml