Data Flow 2
Data Flow 2
Data Flow 2
Nov. 3, 2005
Recall: Data Flow Analysis
• A framework for proving facts about program
“top”
“bottom”
Partial Orders
If z · x and z · y then z · x u y
If x · z and y · z, then x t y · z
Lattices (cont.)
A finite partial order is a lattice if meet and join exist for
every pair of elements
xu?=? x t ? =x
xu>=x xt>=>
In a lattice
x · y iff x u y = x
x · y iff x t y = y
Useful Lattices
• (2S , µ) forms a lattice for any set S.
2S is the powerset of S (set of all subsets)
>
Note: order on integers is
… different from order in lattice
1 2 3
?
Forward Must Data Flow Algorithm
Out(s) = Gen(s) for all statements s
Repeat
Take s from W
Out(s) = temp
W = W [ succ(s)
Until W =
Monotonicity
Repeat
Take s from W
temp := fs(⊓s′ ∊ pred(s) Out(s′)) (fs monotonic transfer fn)
if (temp != Out(s)) {
Out(s) := temp
W := W [ succ(s)
}
until W = ∅
Lattices (P, ≤)
Available expressions
P = sets of expressions
S1 ⊓ S2 = S1 ∩ S2
Top = set of all expressions
Reaching Definitions
P = set of definitions (assignment
statements)
S1 ⊓ S2 = S1 [ S2
Top = empty set
Fixpoints -- Intuition
Live variables
P = sets of variables
S1 ⊓ S2 = S1 [ S2
Top = empty set
A function f is distributive if
Benefit of Distributivity
Constant propagation