Theoremadvanced
Kam-Ullman iteration bound
Also called rapid framework bound.
Round-robin dataflow iteration in reverse postorder stops after d + 2 passes for rapid distributive frameworks, where d is the loop-connectedness depth.
The Kam-Ullman iteration bound says how many sweeps a simple dataflow solver needs. The solver visits the blocks in a fixed order, again and again, and stops after a sweep that changes nothing. For a rapid distributive framework, which covers every gen-kill problem, and the visit order of reverse postorder, the solver stops after at most sweeps. Here is the largest number of back edges on a path without repeated blocks, a small number in real code. The bound does not depend on the height of the lattice or on the number of blocks.
Statement
The page uses the meet convention of the MOP-MFP coincidence theorem: a meet semilattice of finite height with top , lower facts are safer, and the answer is the greatest fixed point (MFP). Turning the order upside down gives the join convention, with the same proof.
The instance. A control flow graph with blocks and edges, an entry block , a transfer function for each block, and a boundary value . The set contains the identity and is closed under composition, as in every monotone dataflow framework. Let and for .
Rapid. The framework is rapid if
In words, running a function on a fact loses nothing beyond what it loses on the optimistic value and what itself already lacks. Gen-kill functions are rapid. With the meet , the order is and , so . With the meet , the order is and is the universe , so .
The solver (round robin). Fix a linear order of the blocks. Start with for every . A pass visits the blocks in this order and at each block sets
using the newest values of its predecessors. The solver runs passes until a pass changes no value.
Depth. An edge is retreating for the order if is not after , that is or comes before . Let be the largest number of retreating edges on a simple path, a path with no repeated block, starting at any block. For reverse postorder, the retreating edges are exactly the back edges of the depth-first spanning tree, the edges from a block to one of its ancestors in the tree. On a reducible flow graph they are the back edges of the natural loops, whatever tree the search builds, so is a property of the graph and is called its loop-connectedness depth.
Theorem. Let the framework be distributive and rapid, and let every block be reachable from . Then, for every visit order, the values after pass are the MFP solution, which here equals the meet over all paths, and the solver stops after at most passes. With reverse postorder, is the loop-connectedness depth.
A backward problem is the same on the reverse CFG, with the reverse postorder of the reverse CFG. Each pass applies transfer functions and at most meets, so the solver does lattice operations.
In plain words
Picture facts flowing along the edges of the program. In one sweep in the right order, a fact flows forward along every edge that goes down the page. It can only climb back up a loop edge at the next sweep. So a fact that travels along a route with three loop edges needs about four sweeps.
Routes in a loop can repeat blocks forever, so this alone gives no bound. The rapid property saves the day: going around a loop a second time never teaches anything that one turn plus the facts already present did not. So only routes without repeated blocks matter, and on those routes the number of loop edges is small. One more sweep then confirms that nothing changes.
Proof
Let denote the current value of the array , and let and be as on the MOP-MFP coincidence theorem page. Walks, paths and their functions are defined there: for , .
Lemma 1 (the solver goes down and stays above MFP). At every moment, each value of is at most its previous values and at least . When a pass changes nothing, , and the solver stops after finitely many passes.
Proof. Both claims are by induction on the number of updates. The first update of gives a value below . A later update uses the current values of the predecessors, which are below the values used by the previous update of , so by monotonicity the new value is below the old one. For the second claim, if every , then the new value , because MFP is a fixed point. A pass that changes nothing leaves equal to the right side of the equations, so is a fixed point. It is above the greatest fixed point MFP, so it equals MFP. Each value can fall at most times, so at most passes run.
Lemma 2 (how fast a route is covered). For a walk , let be the number of retreating edges among its edges, and the number among its edges except the first.
- (a) If is a path, so , then from the end of pass on.
- (b) For any walk with , from the end of pass on.
Proof. By Lemma 1, once a bound holds it holds forever, so it is enough to show it right after the visit of in the stated pass. For (a), use induction on , with the stronger claim that the bound holds right after the visit of in pass . For , the visit of in pass 1 meets in . For , let be without its last block, and . By induction, right after the visit of in pass . If the edge is not retreating, comes after , so its visit in the same pass meets in . If the edge is retreating, the visit of in pass does the same. For (b), the base case is : every value of is below , so the visit of in pass 1 meets in , whatever the order of and . The step is the same as in (a).
Call a walk with tail-simple if is a simple path; may equal one of the other blocks. A simple path has , and a tail-simple walk has , because counts the retreating edges of the simple path . For a block , let be the finite set of the values for the simple paths to and for the tail-simple walks that end at .
Lemma 3 (only simple routes matter). If the framework is distributive and rapid, then for every walk of length at least 1 that ends at , and for every path to .
Proof. The key step is this. Let be any walk with for some . Split it into the part , the cycle and the rest . Let be the start value of , either or , and . The function is in , so the rapid property gives . Apply , which is monotone, and then distributive:
Here is with the cycle cut out, of length , and is the walk , of length . When , is the identity and distributivity is not needed.
Walks. Induction on the length of . If is tail-simple, its value is in . Otherwise two of are equal, so the key step applies with . Both and are shorter than , have length at least 1 and end at . By induction, is below both values, hence below their meet, hence below .
Paths. Induction on the length of . If is simple, its value is in . Otherwise the key step applies with . The path is shorter, so the induction covers it, and the walk has length , so the walk case covers it.
The theorem. Look at the end of pass . Every element of comes from a simple path with or from a tail-simple walk with . By Lemma 2, is below each of them, so . By Lemma 3, this is below for every path to , so . Every block is reachable and the framework is distributive, so by the coincidence theorem. With Lemma 1, , so after pass . Pass recomputes every value from a fixed point and changes nothing, so the solver stops.
A worked example. Reaching definitions on the loop of the coincidence theorem page: entry defines , head defines , body defines , and the edges are entry to head, head to body, body to head and head to exit. A depth-first search from entry that visits body last gives the reverse postorder entry, head, exit, body. The only retreating edge is (body, head), so .
| pass | IN[head] | IN[exit] | IN[body] |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | no change | no change | no change |
In pass 1, head already gets from body, because ; this is the free first edge of Lemma 2 (b). The definition needs the walk (head, body, head), whose second edge is retreating, so it arrives in pass 2. Pass 3 only confirms the result.
Consequences
- Bit-vector problems are fast. Reaching definitions, live variables, available expressions and very busy expressions are gen-kill problems, so round robin in reverse postorder costs bit-vector operations. Loops in real programs are seldom nested deeply, so is small and the cost is close to linear.
- The order matters. For reverse postorder, the retreating edges are only the back edges of the search tree. A bad order makes many edges retreating and raises in the theorem.
- The bound does not need the lattice height. A general bound for the worklist dataflow algorithm is , because each value can fall times. For rapid frameworks the passes depend only on the loops, even when is the number of definitions.
- Each value is right after passes. A solver that knows can skip the last pass. Solvers usually do not compute , so they run the extra pass.
- Elimination methods are an alternative. Elimination dataflow methods solve the equations by substitution on the loop structure, so their cost does not depend on .
Tightness
passes can be needed. The loop above needs exactly passes. With two nested loops, entry to OH, OH to IH and exit, IH to IB1 and OL, IB1 to IB2, IB2 to IH, and OL to OH, and one definition in IB1, the depth is 2 and the solver needs exactly 4 passes. The definition reaches IB2 in pass 1, IH and OL in pass 2 after the retreating edge (IB2, IH), and OH and exit in pass 3 after the retreating edge (OL, OH). Pass 4 confirms.
The rapid property is needed. Constant propagation is not rapid. Take this loop, with and unknown parameters:
entry:
x1 = 0
x2 = 0
x3 = 0
x4 = 0
jump head
head:
br t body exit
body:
x1 = x2
x2 = x3
x3 = x4
x4 = n
jump head
exit:
ret x1
Here , so the bound would be 3 passes. Each pass moves "not a constant" one step along the chain: x4 at head in pass 2, x3 in pass 3, x2 in pass 4 and x1 in pass 5. Pass 6 confirms, so the solver needs 6 passes, and with variables in the chain it needs . The rapid property fails: for the environment with all four variables equal to 0, is all , so , but has not constant, which is not above 0.
A bad order is slow. On a straight chain of blocks, each adding a definition, reverse postorder needs 2 passes. Visiting the chain from its end makes every edge retreating, and the solver needs passes.
History
Hecht and Ullman proved an iteration bound for the bit-vector methods in depth-first order. Kam and Ullman (1976) asked when the depth-first version of Kildall's general algorithm meets the same bound. They found a condition on the function space that is both necessary and sufficient, the rapid condition, and showed that several techniques Kildall found useful fail it. In their 1977 paper they set out the monotone frameworks, where constant propagation is the standard example of a framework that is not distributive. The dragon book presents the bound through depth-first ordering and the depth of a flow graph, and counts passes. The version on this page proves the bound for any visit order and also assumes distributivity, which every gen-kill problem has.
References
- John B. Kam and Jeffrey D. Ullman, Global data flow analysis and iterative algorithms, Journal of the ACM 23(1), 1976, 158-171, the whole paper (the condition on the functions under which the depth-first version of Kildall's algorithm meets the bit-vector iteration bound, and examples that fail it)
- John B. Kam and Jeffrey D. Ullman, Monotone data flow analysis frameworks, Acta Informatica 7(3), 1977, 305-317, the whole paper (monotone frameworks, where constant propagation is the standard framework that is not distributive)
- Alfred V. Aho, Monica S. Lam, Ravi Sethi and Jeffrey D. Ullman, Compilers, Principles, Techniques, and Tools, second edition, Pearson Addison-Wesley, 2007, Section 9.6 (Loops in Flow Graphs, depth-first ordering, retreating edges, the depth of a flow graph) and Section 9.6.7 (Speed of Convergence of Iterative Data-Flow Algorithms)
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 ADH092 Edit this page History Report an error Markdown