Algorithm Search⌘K

Definitioncore

Maximal fixed-point solution

Also called MFP solution, maximum fixed point.

The greatest solution of the dataflow equations of a monotone framework, which iterative algorithms compute and which is below the MOP.

The maximal fixed-point (MFP) solution of a dataflow problem is the greatest solution of its dataflow equations. It is what iterative solvers such as the worklist dataflow algorithm compute: start every value at ⊤\top, the most optimistic fact, and lower values until the equations hold. In every monotone dataflow framework the MFP solution exists, is unique, is reached by iteration, and is below the ideal meet-over-all-paths solution, so it is safe. In a distributive dataflow framework it equals MOP. "Maximal" means greatest in the meet order used by Kildall, Kam and Ullman, and the dragon book. Turning the order upside down gives the convention of abstract interpretation and of Nielson, Nielson and Hankin, where the same solution is the least fixed point and the start value is ⊥\bot.

Definition

The dataflow pages use the meet convention. (L,⊓)(L, \sqcap) is a meet semilattice: ⊓\sqcap is idempotent, commutative and associative, and x⊑yx \sqsubseteq y means x⊓y=xx \sqcap y = x, a partial order (reflexive, antisymmetric, transitive) in which x⊓yx \sqcap y is the greatest lower bound. ⊤\top is the identity of meet. The height hh is the largest number of strict steps in a chain x0⊐x1⊐⋯x_0 \sqsupset x_1 \sqsupset \cdots, and it is finite. Lower facts are weaker, safer claims.

The equations as one function. Take a forward instance on a control flow graph with blocks VV, ∣V∣=n|V| = n, mm edges, transfer functions fBf_B that are monotone, and boundary value ι\iota at the entry. An assignment gives each block a value X[B]∈LX[B] \in L, the fact at its start. Assignments are ordered block by block: X⊑YX \sqsubseteq Y if X[B]⊑Y[B]X[B] \sqsubseteq Y[B] for all BB. Define

F(X)[B]=(ι if B is the entry)⊓⊓(P,B)∈EfP(X[P]),F(X)[B] = \Big(\iota \text{ if } B \text{ is the entry}\Big) \sqcap \mathop{\large\sqcap}_{(P, B) \in E} f_P(X[P]),

with the empty meet equal to ⊤\top. A solution of the dataflow equations is an XX with X=F(X)X = F(X), a fixed point of FF. The facts at the ends of the blocks are then fB(X[B])f_B(X[B]). A backward instance is the same on the reverse CFG, with ι\iota after each ret block.

Definition. The maximal fixed-point solution is the greatest fixed point of FF: the solution MFP\mathrm{MFP} with X⊑MFPX \sqsubseteq \mathrm{MFP} for every solution XX.

Facts about FF. FF is monotone, because each fPf_P is monotone and the meet is monotone in each argument. The assignments form a semilattice of height nhn h, since a strict step lowers at least one of the nn entries, and each entry can fall at most hh times.

Existence, uniqueness and iteration. Let X0=⊤X_0 = \top (every entry ⊤\top) and Xi+1=F(Xi)X_{i+1} = F(X_i). Then:

  1. The sequence goes down. X1⊑⊤=X0X_1 \sqsubseteq \top = X_0. If Xi+1⊑XiX_{i+1} \sqsubseteq X_i, then Xi+2=F(Xi+1)⊑F(Xi)=Xi+1X_{i+2} = F(X_{i+1}) \sqsubseteq F(X_i) = X_{i+1} by monotonicity.
  2. It stops. A strict step can happen at most nhn h times, so Xk+1=XkX_{k+1} = X_k for some k≤nhk \le n h. Then XkX_k is a fixed point.
  3. It is the greatest. Let YY be any assignment with Y⊑F(Y)Y \sqsubseteq F(Y), in particular any fixed point. Then Y⊑X0Y \sqsubseteq X_0, and if Y⊑XiY \sqsubseteq X_i then Y⊑F(Y)⊑F(Xi)=Xi+1Y \sqsubseteq F(Y) \sqsubseteq F(X_i) = X_{i+1}. So Y⊑XkY \sqsubseteq X_k.

So MFP=Xk\mathrm{MFP} = X_k exists, it is unique (two greatest elements are equal by antisymmetry), and it is also the greatest YY with Y⊑F(Y)Y \sqsubseteq F(Y). □\square This is the dual of Kleene's fixed-point theorem; with ⊤\top and finite height, LL and the assignments form complete lattices, and the Knaster-Tarski theorem gives the same greatest fixed point as the join of all YY with Y⊑F(Y)Y \sqsubseteq F(Y).

MFP is below MOP. For every block BB, MFP[B]⊑MOP[B]\mathrm{MFP}[B] \sqsubseteq \mathrm{MOP}[B].

Proof. Let XX be any assignment with X⊑F(X)X \sqsubseteq F(X). We show X[B]⊑fπ(ι)X[B] \sqsubseteq f_\pi(\iota) for every path π\pi from the entry to BB, by induction on the length of π\pi. If π\pi has length zero, BB is the entry, and X[B]⊑F(X)[B]⊑ι=fπ(ι)X[B] \sqsubseteq F(X)[B] \sqsubseteq \iota = f_\pi(\iota). Otherwise π\pi is a path π′\pi' to some PP followed by the edge (P,B)(P, B), and fπ=fP∘fπ′f_\pi = f_P \circ f_{\pi'}. Then

X[B]⊑F(X)[B]⊑fP(X[P])⊑fP(fπ′(ι))=fπ(ι),X[B] \sqsubseteq F(X)[B] \sqsubseteq f_P(X[P]) \sqsubseteq f_P(f_{\pi'}(\iota)) = f_\pi(\iota),

using the induction hypothesis X[P]⊑fπ′(ι)X[P] \sqsubseteq f_{\pi'}(\iota) and the monotonicity of fPf_P. So X[B]X[B] is a lower bound of all fπ(ι)f_\pi(\iota), and hence below their meet MOP[B]\mathrm{MOP}[B]. Take X=MFPX = \mathrm{MFP}. □\square

Soundness. If every fBf_B is a safe description of its block, then every run that reaches BB follows a path π\pi, the fact fπ(ι)f_\pi(\iota) describes its state there, and the lower facts MOP[B]\mathrm{MOP}[B] and MFP[B]\mathrm{MFP}[B] describe it too. The proof uses only monotonicity.

Precision, with an example. MFP merges facts at every join before it applies the next function, while MOP applies the functions along each path and merges only at the end. For a monotone ff, f(x⊓y)⊑f(x)⊓f(y)f(x \sqcap y) \sqsubseteq f(x) \sqcap f(y), so merging early can only lose. In constant propagation on the diamond where one branch sets (x,y)=(2,3)(x, y) = (2, 3) and the other (3,2)(3, 2), followed by z = x + y, MFP says z is not a constant and MOP says z=5z = 5. In a distributive framework with every block reachable, MFP = MOP (proved on the distributive dataflow framework page).

Cost. The plain iteration Xi+1=F(Xi)X_{i+1} = F(X_i) takes at most nh+1n h + 1 rounds, each with nn transfer functions and mm meets. The worklist dataflow algorithm recomputes only what can change: each entry falls at most hh times, so it uses at most n(h+1)n(h + 1) transfer functions and m(h+1)m(h + 1) meets. For rapid frameworks, round-robin iteration in reverse postorder needs only d+2d + 2 rounds, with dd the loop-connectedness depth (Kam-Ullman iteration bound).

Any fair order gives MFP. The result does not depend on the order in which blocks are updated. Any update X[B]←F(X)[B]X[B] \leftarrow F(X)[B] applied to an X⊒MFPX \sqsupseteq \mathrm{MFP} gives a value ⊒MFP[B]\sqsupseteq \mathrm{MFP}[B], since F(X)[B]⊒F(MFP)[B]=MFP[B]F(X)[B] \sqsupseteq F(\mathrm{MFP})[B] = \mathrm{MFP}[B]. So every order stays above MFP, and an order that stops only when no update changes anything stops at a fixed point, which must then be MFP. This is why round-robin, worklist and other chaotic iteration orders of fixed-point iteration all agree.

Examples and non-examples

Live variables on the running example. For the loop of the running example of dataflow analysis, the MFP of live variable analysis has {n,x}\{n, x\} live at the start of entry and {a,i,n,s,x}\{a, i, n, s, x\} at the start of odd. Liveness is distributive and every block reaches the return, so this is also MOP.

Non-example: a fixed point that is not the greatest. Add w = 0 to entry in the running example, and let nothing read w. Putting w into the live sets of head, body, odd and next gives another solution of the equations: around the loop, each block passes w to the block before it, and no block in the loop writes w. The facts justify each other in a cycle. This solution has larger sets, so in the order ⊇\supseteq of a may problem it is strictly below the MFP. Iteration from ⊤=∅\top = \emptyset never adds w, because no read of w starts the chain. The MFP, the greatest fixed point, is the one without such self-supporting claims.

Non-example: the wrong start value in a must problem. For available expressions, starting the blocks other than the entry at ∅\emptyset (⊥\bot) instead of ⊤\top also ends at a fixed point, but often a smaller one: an expression computed before a loop and not changed inside it is lost at the loop head, because the back edge brings ∅\emptyset. Only the start at ⊤\top gives the greatest fixed point.

Non-example: a framework that is not monotone. If a transfer function is not monotone, FF need not have a fixed point at all. With one item dd, union as the meet, and a block with a self-loop whose function is X↦{d}−XX \mapsto \{d\} - X, the equation is X={d}−XX = \{d\} - X, which no set satisfies.

References

  1. John B. Kam and Jeffrey D. Ullman, Monotone data flow analysis frameworks, Acta Informatica 7(3), 1977, 305-317, the whole paper (the maximal fixed point of a monotone framework, the proof that Kildall's algorithm computes it, and the proof that it is below the meet over all paths)
  2. Gary A. Kildall, A unified approach to global program optimization, Proceedings of the 1st ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages (POPL 1973), 194-206, the whole paper (the iterative algorithm from the top element, and its result for distributive functions)
  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.3.3 (The Iterative Algorithm for General Frameworks) and Section 9.3.4 (Meaning of a Data-Flow Solution, the maximum fixedpoint and its relation to the meet-over-paths solution)
  4. Flemming Nielson, Hanne Riis Nielson and Chris Hankin, Principles of Program Analysis, Springer, 1999, Section 2.4 (Equation Solving, the worklist algorithm for the MFP solution and the comparison with the MOP solution), in the join convention where the same solution is the least one

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