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 is control dependent on node if one edge out of makes certain to run and another edge out of can skip . Ferrante, Ottenstein and Warren (1987) defined it through post-dominance, and Cytron et al. (1991) showed that the nodes that control are the dominance frontier of in the reverse graph. The relation, drawn as a graph with an edge from 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 be a control flow graph with an entry node and one exit node , in which every node reaches . Add a node START with an edge to the entry and an edge to . 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 , with the immediate post-dominator.
Path form (Ferrante, Ottenstein and Warren). is control dependent on if
- there is a path with on which for every , and
- does not strictly post-dominate .
Edge form. is control dependent on through the edge if and does not strictly post-dominate . The successor is the label of the dependence: it records which way the branch at must go for to run. A two-way branch with a true edge and a false edge gives labels T and F.
Reverse dominance frontier. Let be the transpose of the augmented graph, with as its start. The post-dominators in are the dominators in , so the dominance frontier of in is
The three forms define the same relation.
Theorem (Cytron et al. 1991). For all nodes and : is control dependent on by the path form, iff it is by the edge form through some successor of , iff .
Proof. The edge form and the formula for are the same text, because the predecessors of in are the successors of in , and "dominates in " is "post-dominates in ". 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 is a successor , and , so the edge form holds. Conversely, let for a successor of . Take any path from to . It contains , so cut it at the first occurrence of : . Suppose some with were not post-dominated by . Then some path from to avoids , and the prefix also avoids , so their join is a path from to that avoids , which contradicts . So is a path as in condition 1.
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 . 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 . By the edge form, the nodes that depend on through it are the post-dominators of that are not strict post-dominators of . In the post-dominator tree, the post-dominators of are the ancestors of (with itself), and the strict post-dominators of are and its ancestors. Now post-dominates : a path from to , with the edge in front, is a path from to , so it holds , and , so lies on the part after . So is an ancestor of , and the wanted set is the tree path from up to with left out. That is what the walk visits. If the set is empty, and these are the only edges that give nothing: if strictly post-dominates , then is or above it, and also below it, so .
Cost. The post-dominator tree costs what dominators cost on a graph with nodes and edges. Each step of the walk records one new triple, so the walks cost , where is the number of (node, branch, label) triples in the answer. The answer itself can have pairs with only edges, as the chain example below shows. Pingali and Bilardi (1997) avoid building it: their augmented post-dominator tree takes 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 has a successor with , that is, when is a loop test and one edge stays in the loop.
- Only branches control. If has one successor , then , so no node depends on .
- The parents of a node. The nodes that depends on are , so they can also be found with the dominance frontier computation run on , 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 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 , , , , and .
Of the ten edges, seven end at the immediate post-dominator of their source and give nothing: , , , , , and . The other three walk:
| edge | stop at | walk visits | dependences recorded |
|---|---|---|---|
| EXIT | B1, B2, B6 | B1, B2, B6 on START | |
| B6 | B3, B5, B2 | B3, B5, B2 on B2, label B3 | |
| 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 with the edges , an edge , and an edge from every . Every path to passes through all of in order, so . The edge walks , so depends on for every . That is dependences from 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 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 , and the definition does not apply until a fake exit edge is added, as discussed under post-dominance.
Related definitions
- 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.
- 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
- 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
- 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
- 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
- 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
- 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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 10RK1C Edit this page History Report an error Markdown