Algorithm Search⌘K

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 d+2d + 2 sweeps. Here dd 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 (L,⊓)(L, \sqcap) of finite height with top ⊤\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 nn blocks and mm edges, an entry block ss, a transfer function fB∈Ff_B \in F for each block, and a boundary value ι\iota. The set FF contains the identity and is closed under composition, as in every monotone dataflow framework. Let init(s)=ιinit(s) = \iota and init(B)=⊤init(B) = \top for B≠sB \ne s.

Rapid. The framework is rapid if

x⊓f(⊤)  ⊑  f(x)for all f∈F and x∈L.x \sqcap f(\top) \;\sqsubseteq\; f(x) \qquad \text{for all } f \in F \text{ and } x \in L.

In words, running a function on a fact xx loses nothing beyond what it loses on the optimistic value ⊤\top and what xx itself already lacks. Gen-kill functions f(x)=g∪(x−k)f(x) = g \cup (x - k) are rapid. With the meet ∪\cup, the order is ⊇\supseteq and ⊤=∅\top = \emptyset, so x⊓f(⊤)=x∪g⊇g∪(x−k)=f(x)x \sqcap f(\top) = x \cup g \supseteq g \cup (x - k) = f(x). With the meet ∩\cap, the order is ⊆\subseteq and ⊤\top is the universe UU, so x∩f(U)=x∩(g∪(U−k))=(x∩g)∪(x−k)⊆f(x)x \cap f(U) = x \cap (g \cup (U - k)) = (x \cap g) \cup (x - k) \subseteq f(x).

The solver (round robin). Fix a linear order B1,…,BnB_1, \ldots, B_n of the blocks. Start with IN[B]=⊤IN[B] = \top for every BB. A pass visits the blocks in this order and at each block uu sets

IN[u]:=init(u)⊓⊓(p,u)∈Efp(IN[p]),IN[u] := init(u) \sqcap \mathop{\large\sqcap}_{(p, u) \in E} f_p(IN[p]),

using the newest values of its predecessors. The solver runs passes until a pass changes no value.

Depth. An edge (u,v)(u, v) is retreating for the order if vv is not after uu, that is v=uv = u or vv comes before uu. Let dd 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 dd 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 ss. Then, for every visit order, the values after pass d+1d + 1 are the MFP solution, which here equals the meet over all paths, and the solver stops after at most d+2d + 2 passes. With reverse postorder, dd 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 nn transfer functions and at most mm meets, so the solver does O((d+2)(n+m))O((d + 2)(n + m)) 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 XX denote the current value of the array ININ, and let MFP\mathrm{MFP} and MOP\mathrm{MOP} be as on the MOP-MFP coincidence theorem page. Walks, paths and their functions fwf_w are defined there: for w=(u0,…,uk)w = (u_0, \ldots, u_k), fw=fuk−1∘⋯∘fu0f_w = f_{u_{k-1}} \circ \cdots \circ f_{u_0}.

Lemma 1 (the solver goes down and stays above MFP). At every moment, each value of ININ is at most its previous values and at least MFP\mathrm{MFP}. When a pass changes nothing, IN=MFPIN = \mathrm{MFP}, and the solver stops after finitely many passes.

Proof. Both claims are by induction on the number of updates. The first update of IN[u]IN[u] gives a value below ⊤\top. A later update uses the current values of the predecessors, which are below the values used by the previous update of uu, so by monotonicity the new value is below the old one. For the second claim, if every IN[p]⊒MFP[p]IN[p] \sqsupseteq \mathrm{MFP}[p], then the new value init(u)⊓⊓pfp(IN[p])⊒init(u)⊓⊓pfp(MFP[p])=MFP[u]init(u) \sqcap \mathop{\large\sqcap}_p f_p(IN[p]) \sqsupseteq init(u) \sqcap \mathop{\large\sqcap}_p f_p(\mathrm{MFP}[p]) = \mathrm{MFP}[u], because MFP is a fixed point. A pass that changes nothing leaves ININ equal to the right side of the equations, so ININ is a fixed point. It is above the greatest fixed point MFP, so it equals MFP. Each value can fall at most hh times, so at most nh+1n h + 1 passes run. □\square

Lemma 2 (how fast a route is covered). For a walk w=(u0,…,uk)w = (u_0, \ldots, u_k), let r(w)r(w) be the number of retreating edges among its edges, and r′(w)r'(w) the number among its edges except the first.

  • (a) If ww is a path, so u0=su_0 = s, then IN[uk]⊑fw(ι)IN[u_k] \sqsubseteq f_w(\iota) from the end of pass r(w)+1r(w) + 1 on.
  • (b) For any walk with k≥1k \ge 1, IN[uk]⊑fw(⊤)IN[u_k] \sqsubseteq f_w(\top) from the end of pass r′(w)+1r'(w) + 1 on.

Proof. By Lemma 1, once a bound holds it holds forever, so it is enough to show it right after the visit of uku_k in the stated pass. For (a), use induction on kk, with the stronger claim that the bound holds right after the visit of uku_k in pass r(w)+1r(w) + 1. For k=0k = 0, the visit of ss in pass 1 meets in init(s)=ιinit(s) = \iota. For k≥1k \ge 1, let w′w' be ww without its last block, and q=r(w′)+1q = r(w') + 1. By induction, IN[uk−1]⊑fw′(ι)IN[u_{k-1}] \sqsubseteq f_{w'}(\iota) right after the visit of uk−1u_{k-1} in pass qq. If the edge (uk−1,uk)(u_{k-1}, u_k) is not retreating, uku_k comes after uk−1u_{k-1}, so its visit in the same pass q=r(w)+1q = r(w) + 1 meets in fuk−1(IN[uk−1])⊑fuk−1(fw′(ι))=fw(ι)f_{u_{k-1}}(IN[u_{k-1}]) \sqsubseteq f_{u_{k-1}}(f_{w'}(\iota)) = f_w(\iota). If the edge is retreating, the visit of uku_k in pass q+1=r(w)+1q + 1 = r(w) + 1 does the same. For (b), the base case is k=1k = 1: every value of IN[u0]IN[u_0] is below ⊤\top, so the visit of u1u_1 in pass 1 meets in fu0(IN[u0])⊑fu0(⊤)f_{u_0}(IN[u_0]) \sqsubseteq f_{u_0}(\top), whatever the order of u0u_0 and u1u_1. The step is the same as in (a). □\square

Call a walk w=(u0,…,uk)w = (u_0, \ldots, u_k) with k≥1k \ge 1 tail-simple if (u1,…,uk)(u_1, \ldots, u_k) is a simple path; u0u_0 may equal one of the other blocks. A simple path σ\sigma has r(σ)≤dr(\sigma) \le d, and a tail-simple walk ww has r′(w)≤dr'(w) \le d, because r′(w)r'(w) counts the retreating edges of the simple path (u1,…,uk)(u_1, \ldots, u_k). For a block vv, let T(v)T(v) be the finite set of the values fσ(ι)f_\sigma(\iota) for the simple paths σ\sigma to vv and fw(⊤)f_w(\top) for the tail-simple walks ww that end at vv.

Lemma 3 (only simple routes matter). If the framework is distributive and rapid, then ⊓T(v)⊑fw(⊤)\mathop{\large\sqcap} T(v) \sqsubseteq f_w(\top) for every walk ww of length at least 1 that ends at vv, and ⊓T(v)⊑fπ(ι)\mathop{\large\sqcap} T(v) \sqsubseteq f_\pi(\iota) for every path π\pi to vv.

Proof. The key step is this. Let w=(u0,…,uk)w = (u_0, \ldots, u_k) be any walk with ui=uju_i = u_j for some i<ji < j. Split it into the part α=(u0,…,ui)\alpha = (u_0, \ldots, u_i), the cycle γ=(ui,…,uj)\gamma = (u_i, \ldots, u_j) and the rest δ=(uj,…,uk)\delta = (u_j, \ldots, u_k). Let yy be the start value of ww, either ι\iota or ⊤\top, and x=fα(y)x = f_\alpha(y). The function fγf_\gamma is in FF, so the rapid property gives fγ(x)⊒x⊓fγ(⊤)f_\gamma(x) \sqsupseteq x \sqcap f_\gamma(\top). Apply fδf_\delta, which is monotone, and then distributive:

fw(y)=fδ(fγ(x))  ⊒  fδ(x⊓fγ(⊤))=fδ(fα(y))⊓fδ(fγ(⊤))=fαδ(y)⊓fγδ(⊤).f_w(y) = f_\delta(f_\gamma(x)) \;\sqsupseteq\; f_\delta(x \sqcap f_\gamma(\top)) = f_\delta(f_\alpha(y)) \sqcap f_\delta(f_\gamma(\top)) = f_{\alpha\delta}(y) \sqcap f_{\gamma\delta}(\top).

Here αδ\alpha\delta is ww with the cycle cut out, of length k−(j−i)k - (j - i), and γδ\gamma\delta is the walk (ui,…,uk)(u_i, \ldots, u_k), of length k−ik - i. When j=kj = k, fδf_\delta is the identity and distributivity is not needed.

Walks. Induction on the length kk of ww. If ww is tail-simple, its value is in T(v)T(v). Otherwise two of u1,…,uku_1, \ldots, u_k are equal, so the key step applies with 1≤i<j1 \le i < j. Both αδ\alpha\delta and γδ\gamma\delta are shorter than kk, have length at least 1 and end at vv. By induction, ⊓T(v)\mathop{\large\sqcap} T(v) is below both values, hence below their meet, hence below fw(⊤)f_w(\top).

Paths. Induction on the length of π\pi. If π\pi is simple, its value is in T(v)T(v). Otherwise the key step applies with y=ιy = \iota. The path αδ\alpha\delta is shorter, so the induction covers it, and the walk γδ\gamma\delta has length k−i≥j−i≥1k - i \ge j - i \ge 1, so the walk case covers it. □\square

The theorem. Look at the end of pass d+1d + 1. Every element of T(v)T(v) comes from a simple path σ\sigma with r(σ)+1≤d+1r(\sigma) + 1 \le d + 1 or from a tail-simple walk ww with r′(w)+1≤d+1r'(w) + 1 \le d + 1. By Lemma 2, IN[v]IN[v] is below each of them, so IN[v]⊑⊓T(v)IN[v] \sqsubseteq \mathop{\large\sqcap} T(v). By Lemma 3, this is below fπ(ι)f_\pi(\iota) for every path π\pi to vv, so IN[v]⊑MOP[v]IN[v] \sqsubseteq \mathrm{MOP}[v]. Every block is reachable and the framework is distributive, so MOP=MFP\mathrm{MOP} = \mathrm{MFP} by the coincidence theorem. With Lemma 1, MFP⊑IN⊑MFP\mathrm{MFP} \sqsubseteq IN \sqsubseteq \mathrm{MFP}, so IN=MFPIN = \mathrm{MFP} after pass d+1d + 1. Pass d+2d + 2 recomputes every value from a fixed point and changes nothing, so the solver stops. ■\blacksquare

A worked example. Reaching definitions on the loop of the coincidence theorem page: entry defines d1d_1, head defines d3d_3, body defines d2d_2, 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 d=1d = 1.

pass IN[head] IN[exit] IN[body]
1 {d1,d2}\{d_1, d_2\} {d1,d2,d3}\{d_1, d_2, d_3\} {d1,d2,d3}\{d_1, d_2, d_3\}
2 {d1,d2,d3}\{d_1, d_2, d_3\} {d1,d2,d3}\{d_1, d_2, d_3\} {d1,d2,d3}\{d_1, d_2, d_3\}
3 no change no change no change

In pass 1, head already gets d2d_2 from body, because fbody(∅)={d2}f_{body}(\emptyset) = \{d_2\}; this is the free first edge of Lemma 2 (b). The definition d3d_3 needs the walk (head, body, head), whose second edge is retreating, so it arrives in pass 2. Pass 3 =d+2= d + 2 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 O((d+2)(n+m))O((d + 2)(n + m)) bit-vector operations. Loops in real programs are seldom nested deeply, so dd 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 dd in the theorem.
  • The bound does not need the lattice height. A general bound for the worklist dataflow algorithm is O((n+m)h)O((n + m) h), because each value can fall hh times. For rapid frameworks the passes depend only on the loops, even when hh is the number of definitions.
  • Each value is right after d+1d + 1 passes. A solver that knows dd can skip the last pass. Solvers usually do not compute dd, 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 dd.

Tightness

d+2d + 2 passes can be needed. The loop above needs exactly 3=d+23 = d + 2 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 nn and tt 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 d=1d = 1, 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 kk variables in the chain it needs k+2k + 2. The rapid property fails: for the environment xx with all four variables equal to 0, fbody(⊤)f_{body}(\top) is all ⊤\top, so x⊓fbody(⊤)=xx \sqcap f_{body}(\top) = x, but fbody(x)f_{body}(x) has x4x_4 not constant, which is not above 0.

A bad order is slow. On a straight chain of nn blocks, each adding a definition, reverse postorder needs 2 passes. Visiting the chain from its end makes every edge retreating, and the solver needs nn 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 d+2d + 2 passes. The version on this page proves the bound for any visit order and also assumes distributivity, which every gen-kill problem has.

References

  1. 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)
  2. 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)
  3. 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.

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