Algorithm Search⌘K

Definitioncore

Monotone dataflow framework

Also called monotone framework, Kam-Ullman framework.

A dataflow problem given by a semilattice of facts of finite height, a direction and monotone transfer functions for the nodes.

A monotone dataflow framework is the general form of a dataflow analysis: a semilattice of facts with no infinite descending chains, together with a set of transfer functions that are monotone, contain the identity and are closed under composition. Kam and Ullman (1977) defined it to cover analyses such as constant propagation that fail Kildall's condition of distributivity. This page gives the definition and what follows from monotonicity alone. The stronger distributive dataflow framework adds f(x⊓y)=f(x)⊓f(y)f(x \sqcap y) = f(x) \sqcap f(y); the gen-kill problems are the distributive bit-vector special case; the answers are defined on meet-over-all-paths solution and maximal fixed-point solution, and the solver is the worklist dataflow algorithm.

Definition

This page uses the meet convention of Kildall and the dragon book. A partial order is reflexive, antisymmetric and transitive. A meet semilattice (L,⊓)(L, \sqcap) is a set LL with an operation ⊓\sqcap that is idempotent, commutative and associative. It defines the order x⊑y  ⟺  x⊓y=xx \sqsubseteq y \iff x \sqcap y = x, and x⊓yx \sqcap y is then the greatest lower bound of xx and yy. The element ⊤\top is the identity of meet, so x⊑⊤x \sqsubseteq \top for all xx. Lower facts claim less. A strict descending chain is x0⊐x1⊐⋯x_0 \sqsupset x_1 \sqsupset \cdots, and the height hh of LL is the largest number of strict steps in such a chain.

The framework. A monotone dataflow framework is a triple (L,⊓,F)(L, \sqcap, F) where:

  1. (L,⊓)(L, \sqcap) is a meet semilattice with a top element ⊤\top in which every strict descending chain is finite. Most texts, and the bounds on these pages, ask for the stronger condition that the height hh is finite.
  2. FF is a set of functions L→LL \to L, and each f∈Ff \in F is monotone: x⊑yx \sqsubseteq y implies f(x)⊑f(y)f(x) \sqsubseteq f(y).
  3. FF contains the identity function and is closed under composition.

Condition 3 makes the function of a path, the composition of the functions of its blocks, a member of FF; the empty path has the identity.

An equivalent form of monotonicity. A function ff is monotone if and only if f(x⊓y)⊑f(x)⊓f(y)f(x \sqcap y) \sqsubseteq f(x) \sqcap f(y) for all x,yx, y.

Proof. Assume ff is monotone. Since x⊓y⊑xx \sqcap y \sqsubseteq x and x⊓y⊑yx \sqcap y \sqsubseteq y, we get f(x⊓y)⊑f(x)f(x \sqcap y) \sqsubseteq f(x) and f(x⊓y)⊑f(y)f(x \sqcap y) \sqsubseteq f(y). So f(x⊓y)f(x \sqcap y) is a lower bound of f(x)f(x) and f(y)f(y), and it is below their greatest lower bound f(x)⊓f(y)f(x) \sqcap f(y). Conversely, assume the inequality and let x⊑yx \sqsubseteq y. Then x=x⊓yx = x \sqcap y, so f(x)=f(x⊓y)⊑f(x)⊓f(y)⊑f(y)f(x) = f(x \sqcap y) \sqsubseteq f(x) \sqcap f(y) \sqsubseteq f(y). □\square

So a monotone function may lose information at a meet: applying ff after the meet can give a strictly lower fact than meeting the results of ff. A distributive function never does.

An instance. An instance of the framework is a control flow graph G=(V,E)G = (V, E) with nn blocks and mm edges, a direction (forward or backward), a map B↦fB∈FB \mapsto f_B \in F, and a boundary value ι∈L\iota \in L. A forward instance starts at the entry block. A backward instance runs on the reverse CFG and starts after each block that ends in ret. The boundary value describes what is known where the program starts (forward) or ends (backward). It is chosen by the problem, and it is ⊤\top only by coincidence.

The equations. For a forward instance, with the empty meet equal to ⊤\top:

IN[B]=(ι if B is the entry)⊓⊓(P,B)∈EOUT[P],OUT[B]=fB(IN[B]).\mathrm{IN}[B] = \Big(\iota \text{ if } B \text{ is the entry}\Big) \sqcap \mathop{\large\sqcap}_{(P, B) \in E} \mathrm{OUT}[P], \qquad \mathrm{OUT}[B] = f_B(\mathrm{IN}[B]).

A backward instance has the same equations on the reverse CFG, with ι\iota in the meet of each exit block.

The two answers. The ideal answer is MOP[B]=⊓πfπ(ι)\mathrm{MOP}[B] = \mathop{\large\sqcap}_{\pi} f_\pi(\iota), the meet over all paths π\pi from the start to BB. The equations have a greatest solution, the maximal fixed point MFP, and iteration from ⊤\top computes it. In every monotone framework MFP ⊑\sqsubseteq MOP, so the computed answer is safe. The proofs are on the maximal fixed-point solution page.

Soundness. Assume that each fBf_B is a safe description of block BB: if a fact xx holds before the block runs, then fB(x)f_B(x) holds after it. Every execution follows some path of the CFG, so the fact after an execution is at least fπ(ι)f_\pi(\iota) for its path π\pi, and MOP and MFP are below that. Paths of the CFG that no input follows only lower the answer, which keeps it safe.

Precision. MFP can be strictly below MOP. In constant propagation, let one branch set x=2,y=3x = 2, y = 3 and the other x=3,y=2x = 3, y = 2, and let them join before z = x + y. On each path the transfer function gives z=5z = 5, so MOP gives z=5z = 5. MFP meets first: xx and yy both become "not a constant", and then zz is "not a constant" too. Here f(a⊓b)⊏f(a)⊓f(b)f(a \sqcap b) \sqsubset f(a) \sqcap f(b).

Cost. Each fact can fall at most hh times. A worklist solver therefore applies O(nh)O(n h) transfer functions and O(mh)O(m h) meets. MOP itself is not computable in general: Kam and Ullman (1977) show that no algorithm computes the MOP solution of every instance of every monotone framework.

Examples and non-examples

The four bit-vector problems. Each is a monotone framework whose lattice is the set of subsets of a finite universe UU, with height h=∣U∣h = |U|. The transfer functions have the form f(x)=gen∪(x−kill)f(x) = gen \cup (x - kill), which is monotone (in fact distributive, as the gen-kill problem page proves).

problem direction may or must meet order ⊑\sqsubseteq ⊤\top ⊥\bot boundary ι\iota start value elsewhere
reaching definitions forward may ∪\cup ⊇\supseteq ∅\emptyset all definitions ∅\emptyset at the entry ∅\emptyset
live variables backward may ∪\cup ⊇\supseteq ∅\emptyset all variables ∅\emptyset after each exit ∅\emptyset
available expressions forward must ∩\cap ⊆\subseteq all expressions ∅\emptyset ∅\emptyset at the entry all expressions
very busy expressions backward must ∩\cap ⊆\subseteq all expressions ∅\emptyset ∅\emptyset after each exit all expressions

On the running example of dataflow analysis the universes have 7 definitions, 7 variables (n, x, i, s, t, a, u) and 5 expressions (i < n, x * 2, i & 1, s + a, i + 1), so the heights are 7, 7, 5 and 5.

Constant propagation. For each variable the lattice is flat: ⊤\top ("no value seen yet") above every integer, and every integer above ⊥\bot ("not a constant"). Two different integers are incomparable, so the meet of 22 and 33 is ⊥\bot. The fact at a point is a map from the vv variables to this lattice, ordered pointwise. A strict step lowers at least one variable, and each variable can fall at most twice, so the height is 2v2v; the chain that lowers the variables one by one to a constant and then to ⊥\bot has exactly 2v2v steps. The transfer function of z = x + y is monotone but not distributive, as the precision example above shows. So constant propagation is a monotone framework and not a distributive one. Its lattice has infinitely many elements but finite height, which is all the iteration needs.

Non-example: a function that is not monotone. Let the universe be one definition dd, with meet ∪\cup, and let a block BB with a self-loop have fB(X)={d}−Xf_B(X) = \{d\} - X, the complement. The equations IN[B]=∅∪OUT[B]\mathrm{IN}[B] = \emptyset \cup \mathrm{OUT}[B] and OUT[B]={d}−IN[B]\mathrm{OUT}[B] = \{d\} - \mathrm{IN}[B] give IN[B]={d}−IN[B]\mathrm{IN}[B] = \{d\} - \mathrm{IN}[B], which no set satisfies. The equations have no fixed point at all. A solver that only lowers facts still stops, but the values it stops at do not solve the equations.

Non-example: infinite height. Let the fact be the set of values that i can hold, as a may problem over all integers. In the loop i = 0, then i = i + 1 back to the loop head, the fact at the head grows {0}\{0\}, {0,1}\{0, 1\}, {0,1,2}\{0, 1, 2\} and so on, and iteration never stops. The meet semilattice here has strictly descending chains that never end. Analyses of this kind use abstract interpretation with a widening operator instead.

Non-example: no identity. If FF held only the transfer functions of blocks, then the function of the empty path, the identity, could be missing, and so could compositions. The MOP definition needs both. Adding them never breaks monotonicity, since the identity and compositions of monotone functions are monotone.

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 definition of a monotone framework, the existence of the maximal fixed point and its computation by Kildall's algorithm, MFP below MOP, and the undecidability of MOP for monotone frameworks)
  2. 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 semilattice formulation and the analysis of round-robin iteration)
  3. 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 meet semilattice of facts and the distributive optimizing functions that monotone frameworks generalize)
  4. 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 (9.3.1 Semilattices, 9.3.2 Transfer Functions, 9.3.3 The Iterative Algorithm for General Frameworks, 9.3.4 Meaning of a Data-Flow Solution) and Section 9.4 (constant propagation, 9.4.4 monotonicity and 9.4.5 nondistributivity)
  5. Flemming Nielson, Hanne Riis Nielson and Chris Hankin, Principles of Program Analysis, Springer, 1999, Section 2.3 (Monotone Frameworks, stated with a join, the ascending chain condition and least solutions)

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