Algorithm Search⌘K

Definitioncore

Distributive dataflow framework

Also called distributive framework.

A monotone framework whose transfer functions distribute over the meet, f(x meet y) = f(x) meet f(y), as gen-kill problems do.

A distributive dataflow framework is a monotone dataflow framework in which every transfer function distributes over the meet: f(x⊓y)=f(x)⊓f(y)f(x \sqcap y) = f(x) \sqcap f(y). This was Kildall's original condition in 1973. It is the condition under which merging facts early loses nothing, so the maximal fixed-point solution that an iterative solver computes equals the ideal meet-over-all-paths solution. Every gen-kill problem is distributive, which covers reaching definitions, live variables, available expressions and very busy expressions. Constant propagation is the standard monotone framework that is not distributive.

Definition

The dataflow pages use the meet convention: (L,⊓)(L, \sqcap) is a meet semilattice, x⊑yx \sqsubseteq y means x⊓y=xx \sqcap y = x, ⊤\top is the identity of meet, and the height hh of LL is the largest number of strict steps in a chain x0⊐x1⊐⋯x_0 \sqsupset x_1 \sqsupset \cdots. A function f:L→Lf : L \to L is monotone if x⊑yx \sqsubseteq y implies f(x)⊑f(y)f(x) \sqsubseteq f(y).

Definition. A monotone framework (L,⊓,F)(L, \sqcap, F) is distributive if every f∈Ff \in F satisfies

f(x⊓y)=f(x)⊓f(y)for all x,y∈L.f(x \sqcap y) = f(x) \sqcap f(y) \quad \text{for all } x, y \in L.

A monotone function always satisfies f(x⊓y)⊑f(x)⊓f(y)f(x \sqcap y) \sqsubseteq f(x) \sqcap f(y) (proved on the monotone dataflow framework page). Distributivity asks for equality: applying ff after a meet loses nothing compared with applying it before.

Distributive implies monotone. Let x⊑yx \sqsubseteq y, so x=x⊓yx = x \sqcap y. Then f(x)=f(x⊓y)=f(x)⊓f(y)f(x) = f(x \sqcap y) = f(x) \sqcap f(y), which says f(x)⊑f(y)f(x) \sqsubseteq f(y). □\square

Closed under composition. If ff and gg distribute, then (g∘f)(x⊓y)=g(f(x)⊓f(y))=g(f(x))⊓g(f(y))(g \circ f)(x \sqcap y) = g(f(x) \sqcap f(y)) = g(f(x)) \sqcap g(f(y)). The identity distributes too. So the functions of all paths of a distributive instance are distributive. □\square

Finite meets. By induction on kk, f(x1⊓⋯⊓xk)=f(x1)⊓⋯⊓f(xk)f(x_1 \sqcap \cdots \sqcap x_k) = f(x_1) \sqcap \cdots \sqcap f(x_k) for every k≥1k \ge 1. The case k=0k = 0 fails in general: the empty meet is ⊤\top, and f(⊤)f(\top) need not be ⊤\top. For example f(X)={d}∪Xf(X) = \{d\} \cup X in a may problem maps ⊤=∅\top = \emptyset to {d}\{d\}.

Infinite meets reduce to finite ones. In a semilattice of finite height hh with a top, every nonempty set S⊆LS \subseteq L has a greatest lower bound, and it is the meet of at most h+1h + 1 members of SS. Proof. Pick s0∈Ss_0 \in S and set c=s0c = s_0. While some s∈Ss \in S has c⊓s≠cc \sqcap s \ne c, replace cc with c⊓sc \sqcap s. Each replacement makes cc strictly smaller, so there are at most hh of them. At the end c⊑sc \sqsubseteq s for all s∈Ss \in S, and any lower bound of SS is below each of the chosen members and hence below cc. □\square So f(⊓S)=⊓s∈Sf(s)f(\mathop{\large\sqcap} S) = \mathop{\large\sqcap}_{s \in S} f(s) for every nonempty SS, even when SS is the infinite set of paths through a loop.

The main consequence: MFP = MOP. Take a forward instance on a CFG in which every block is reachable from the entry, with boundary value ι\iota. Then the maximal fixed-point solution equals the meet-over-all-paths solution at every block.

Proof. In every monotone framework MFP ⊑\sqsubseteq MOP, as proved on the maximal fixed-point solution page. For the other direction it is enough to show that MOP satisfies the equations, because MFP is the greatest solution. The paths from the entry to the start of BB are the empty path if BB is the entry, together with, for each predecessor PP, every path to the start of PP followed by PP. Write ΠP\Pi_P for the paths to the start of PP. Each ΠP\Pi_P is nonempty, since PP is reachable. Then

MOP[B]=(ι if B is the entry)⊓⊓P⊓π∈ΠPfP(fπ(ι))=(ι if B is the entry)⊓⊓PfP(⊓π∈ΠPfπ(ι))=(ι if B is the entry)⊓⊓PfP(MOP[P]).\mathrm{MOP}[B] = \Big(\iota \text{ if } B \text{ is the entry}\Big) \sqcap \mathop{\large\sqcap}_{P} \mathop{\large\sqcap}_{\pi \in \Pi_P} f_P(f_\pi(\iota)) = \Big(\iota \text{ if } B \text{ is the entry}\Big) \sqcap \mathop{\large\sqcap}_{P} f_P\Big(\mathop{\large\sqcap}_{\pi \in \Pi_P} f_\pi(\iota)\Big) = \Big(\iota \text{ if } B \text{ is the entry}\Big) \sqcap \mathop{\large\sqcap}_{P} f_P(\mathrm{MOP}[P]).

The middle step uses distributivity over the nonempty set {fπ(ι):π∈ΠP}\{f_\pi(\iota) : \pi \in \Pi_P\}. So MOP is a solution, MOP ⊑\sqsubseteq MFP, and with MFP ⊑\sqsubseteq MOP they are equal. For a backward instance, use the reverse CFG and require every block to reach a ret block. □\square

The MOP-MFP coincidence theorem states this result on its own page. Kam and Ullman (1977) proved that without distributivity no algorithm computes MOP for every monotone framework, which is why the distinction matters.

The reachability condition is needed. If PP is unreachable, ΠP\Pi_P is empty, MOP[P] is ⊤\top, and fP(⊤)f_P(\top) can be below ⊤\top: an unreachable block in a may problem still sends its gengen set to its successors in every solution of the equations, while no path from the entry carries it. Then MFP is strictly below MOP even in a distributive framework.

Soundness and precision. Distributivity does not change soundness, which every monotone framework has. It removes the loss of precision at joins: the computed answer is as precise as any answer that treats all CFG paths as possible. What it cannot remove is the loss from CFG paths that no run takes.

Cost. The same as for any monotone framework of height hh: a worklist solver applies O(nh)O(n h) transfer functions and O(mh)O(m h) meets on a CFG with nn blocks and mm edges. Distributivity buys exactness, not speed. Speed comes from the stronger rapid property of the Kam-Ullman iteration bound, which all gen-kill problems have.

Examples and non-examples

Gen-kill functions. On the subsets of a finite set UU, f(X)=g∪(X−k)f(X) = g \cup (X - k) distributes over both ∪\cup and ∩\cap, so the four bit-vector problems are distributive. The proof is on the gen-kill problem page.

Strongly live variables. In this variant of live variable analysis, the instruction x = y + z makes y and z live only if x is live after it: f(X)=(X−{x})∪({y,z} if x∈X)f(X) = (X - \{x\}) \cup (\{y, z\} \text{ if } x \in X). With union as the meet, f(X∪Y)f(X \cup Y) contains {y,z}\{y, z\} exactly when x∈Xx \in X or x∈Yx \in Y, so f(X∪Y)=f(X)∪f(Y)f(X \cup Y) = f(X) \cup f(Y). The function is distributive, but it is not of gen-kill form, because whether it adds yy depends on the input.

Distributive functions on sets. With union as the meet on the subsets of a finite set DD, a function ff is distributive if and only if f(X)=f(∅)∪⋃d∈Xf({d})f(X) = f(\emptyset) \cup \bigcup_{d \in X} f(\{d\}) for every XX. Proof. If ff distributes, write X=∅∪{d1}∪⋯∪{dk}X = \emptyset \cup \{d_1\} \cup \cdots \cup \{d_k\} and apply the finite-meet rule. Conversely, a function of this form clearly satisfies f(X∪Y)=f(X)∪f(Y)f(X \cup Y) = f(X) \cup f(Y). □\square So a distributive function on DD is fully described by ∣D∣+1|D| + 1 sets. The IFDS framework uses exactly this to turn interprocedural distributive problems into graph reachability, and the IDE framework extends the idea to environments.

Copy-constant propagation. Constant propagation restricted to x = c and x = y is distributive. With one flat lattice per variable and the pointwise meet, the function of x = y maps an environment σ\sigma to σ[x↦σ(y)]\sigma[x \mapsto \sigma(y)], and (σ⊓τ)(y)=σ(y)⊓τ(y)(\sigma \sqcap \tau)(y) = \sigma(y) \sqcap \tau(y), so the two sides agree in every variable.

Non-example: full constant propagation. Let one branch set x=2,y=3x = 2, y = 3, the other x=3,y=2x = 3, y = 2, and let them join before z = x + y. Call the two facts aa and bb, and let ff be the function of z = x + y.

fact xx yy zz after ff
aa 2 3 5
bb 3 2 5
f(a)⊓f(b)f(a) \sqcap f(b) not a constant not a constant 5
f(a⊓b)f(a \sqcap b) not a constant not a constant not a constant

So f(a⊓b)⊏f(a)⊓f(b)f(a \sqcap b) \sqsubset f(a) \sqcap f(b), and on this program MFP says z is not a constant while MOP says z = 5. The function combines two variables, and the meet has already forgotten that they move together.

Non-example: a constant that is lost at a join. Even one variable can break distributivity if the function is not one to one. For x = y * 0, the function sends y=2y = 2 and y=3y = 3 to x=0x = 0, but it sends their meet, "not a constant", to "not a constant" unless the folding rule knows that anything times 0 is 0.

References

  1. 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 distributive optimizing functions on a meet semilattice, and the result that the iterative algorithm then finds the meet over all paths)
  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 that are not distributive, such as constant propagation, where the maximal fixed point can be strictly below the meet over all paths)
  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.2 (Transfer Functions, monotone and distributive frameworks), Section 9.3.4 (Meaning of a Data-Flow Solution, MFP and MOP) and Section 9.4.5 (nondistributivity of the constant-propagation framework)
  4. Flemming Nielson, Hanne Riis Nielson and Chris Hankin, Principles of Program Analysis, Springer, 1999, Section 2.3 (Monotone Frameworks, including distributive frameworks) and Section 2.4 (Equation Solving, the MFP and MOP solutions and when they agree), in the join convention

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