Algorithm Search⌘K

Definitioncore

Meet-over-all-paths solution

Also called MOP solution, merge over all paths.

The meet, over all paths from the entry to a point, of the composed transfer functions of the path, which is the ideal dataflow answer.

The meet-over-all-paths (MOP) solution of a dataflow analysis gives each program point the meet, over every path in the control flow graph from the start to that point, of the fact that the path produces. It treats each path on its own and merges only at the end, so it is the most precise answer that an analysis can give when it assumes that every CFG path can run. It is the yardstick for the computed answer, the maximal fixed-point solution: in every monotone dataflow framework MFP ⊑\sqsubseteq MOP, and in a distributive dataflow framework the two are equal. A loop gives infinitely many paths, and Kam and Ullman (1977) proved that no algorithm computes MOP for every monotone framework.

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 is finite. Lower facts are weaker, safer claims.

The instance. A control flow graph G=(V,E)G = (V, E) with an entry block, a transfer function fB:L→Lf_B : L \to L for each block, and a boundary value ι∈L\iota \in L that holds at the start of the entry.

Paths and path functions. A path to BB is a sequence of blocks π=(B0,B1,…,Bk)\pi = (B_0, B_1, \ldots, B_k) with B0B_0 the entry, Bk=BB_k = B, and an edge from each block to the next. Its function applies the blocks before BB in order:

fπ=fBk−1∘⋯∘fB1∘fB0,f_\pi = f_{B_{k-1}} \circ \cdots \circ f_{B_1} \circ f_{B_0},

and fπf_\pi is the identity for the path (B0)(B_0) of length zero. The fact that π\pi produces at the start of BB is fπ(ι)f_\pi(\iota).

Definition. For each block BB,

MOP[B]=⊓π∈Paths(B)fπ(ι),\mathrm{MOP}[B] = \mathop{\large\sqcap}_{\pi \in \mathrm{Paths}(B)} f_\pi(\iota),

where Paths(B)\mathrm{Paths}(B) is the set of paths to BB. The value at the end of BB uses the paths that go through BB itself: MOPout[B]=⊓πfB(fπ(ι))\mathrm{MOP}_{\mathrm{out}}[B] = \mathop{\large\sqcap}_{\pi} f_B(f_\pi(\iota)). For a backward problem, the paths run from the end of a block to the end of a ret block, on the reverse CFG, and ι\iota holds after each ret block.

The meet exists. A loop makes Paths(B)\mathrm{Paths}(B) infinite, so the meet needs care. In a semilattice of finite height hh with a top, every set SS has a greatest lower bound, and when SS is not empty it is the meet of at most h+1h + 1 members of SS. Proof. Start with any c∈Sc \in S. While some s∈Ss \in S has c⊓s≠cc \sqcap s \ne c, replace cc with c⊓sc \sqcap s; each replacement goes strictly down, so there are at most hh. At the end c⊑sc \sqsubseteq s for all s∈Ss \in S, and every lower bound of SS is below the members used and hence below cc. The empty set has meet ⊤\top. □\square So MOP[B]\mathrm{MOP}[B] is well defined, and it is ⊤\top exactly when no path reaches BB or all paths give ⊤\top.

MOP is the ideal answer for CFG paths. Assume each fBf_B is safe: if a fact xx describes the state at the start of BB, then fB(x)f_B(x) describes the state at the end, and a lower fact describes every state that a higher one describes. A run that reaches BB follows some path π∈Paths(B)\pi \in \mathrm{Paths}(B), so by induction along π\pi the fact fπ(ι)f_\pi(\iota) describes its state at BB, and so does the lower fact MOP[B]\mathrm{MOP}[B]. This is soundness. Conversely, any answer at BB that is safe for every path taken on its own must be below each fπ(ι)f_\pi(\iota), so below their meet. MOP is the greatest such answer. It can still be below the truth, because some CFG paths are never run.

Precision with an example. For constant propagation on the diamond below, the two paths to join give (x,y)=(2,3)(x, y) = (2, 3) and (3,2)(3, 2), and the function of join gives z=5z = 5 on each, so MOPout[join]\mathrm{MOP}_{\mathrm{out}}[\mathrm{join}] has z=5z = 5. The maximal fixed point merges xx and yy at the start of join first and gets "not a constant" for zz.

entry:
  br c left right
left:
  x = 2
  y = 3
  jump join
right:
  x = 3
  y = 2
  jump join
join:
  z = x + y
  ret z

Relation to the fixed point. In every monotone framework, every solution of the dataflow equations is below MOP at every block, and in particular MFP ⊑\sqsubseteq MOP; the proof is on the maximal fixed-point solution page. If the functions are distributive and every block is reachable, MOP itself solves the equations, so MFP = MOP; the proof is on the distributive dataflow framework page, and the MOP-MFP coincidence theorem states it.

Cost and computability.

  • Acyclic CFG. The paths are finite in number, so MOP is computable by enumeration. Their number can be exponential: a chain of kk diamonds has 2k2^k paths from the first block to the last.
  • Distributive frameworks. MOP = MFP, and a worklist solver finds it with O(nh)O(n h) transfer functions and O(mh)O(m h) meets on nn blocks and mm edges.
  • Finite lattices. If LL has finitely many elements, MOP is computable for any monotone framework. Solve the problem on sets of facts instead: the fact at a point is the set R[B]⊆LR[B] \subseteq L of values fπ(ι)f_\pi(\iota) over paths to BB, with R[entry]∋ιR[\mathrm{entry}] \ni \iota, union as the merge, and fBf_B applied to each element. This lifted problem is distributive over union and has height at most ∣L∣|L|, so iteration finds the exact sets, and MOP[B]=⊓R[B]\mathrm{MOP}[B] = \mathop{\large\sqcap} R[B]. The cost grows with ∣L∣|L|, which is usually huge.
  • Infinite lattices of finite height. Kam and Ullman (1977) showed that no algorithm computes MOP for every instance of every monotone framework. Constant propagation is of this kind: its lattice is infinite, so the method for finite lattices does not apply. This is why analyses compute MFP.

Examples and non-examples

Live variables on the running example. The loop of the running example of dataflow analysis gives infinitely many paths from each block to done. Live variables is distributive, so MOP equals the MFP shown on the live variable analysis page; for instance MOP[entry]={n,x}\mathrm{MOP}[\mathrm{entry}] = \{n, x\}. By the lemma above, a finite number of these paths already gives the whole meet.

An unreachable block. If no path reaches BB, then MOP[B]=⊤\mathrm{MOP}[B] = \top, the empty meet: every claim holds vacuously, since no run gets there. MFP need not agree: in a may problem an unreachable block that generates a fact still sends it to its successors in every solution of the equations, while MOP does not count it.

Non-example: the meet over runs. The meet over the paths that some input actually follows is more precise than MOP, as in the example of two branches on the same condition. But deciding which paths can run is undecidable in general, by Rice's theorem, so this is not a definition that any analysis can compute; MOP is the ideal relative to the CFG.

Non-example: the meet over valid paths. Across procedures, a CFG path that enters a callee from one call site and returns to another call site is not a real path. The interprocedural ideal is the meet over valid paths only, with matched calls and returns. The IFDS framework computes it exactly for distributive problems over finite sets.

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 meet over all paths to a node as the meaning of a solution, and the proof that the iterative algorithm reaches it for distributive functions)
  2. John B. Kam and Jeffrey D. Ullman, Monotone data flow analysis frameworks, Acta Informatica 7(3), 1977, 305-317, the whole paper (the MOP solution of a monotone framework, MFP below MOP, and the proof that no algorithm computes the MOP solution of every instance of every monotone framework)
  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.4 (Meaning of a Data-Flow Solution, the ideal solution, the meet-over-paths solution and the maximum fixed point)
  4. Flemming Nielson, Hanne Riis Nielson and Chris Hankin, Principles of Program Analysis, Springer, 1999, Section 2.4 (Equation Solving, the MOP solution and its relation to the MFP solution), stated with a join

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