



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




CMSC 631, Fall 2004 34
■ Take s from W
■ temp := fs(⊓ s pred(s)
Out(s )) (f s
monotonic transfer fn )
■ if (temp != Out(s)) {
■ (^) }
CMSC 631, Fall 2004 35
■ P = sets of expressions
■ (^) Top = set of all expressions
■ P = set of definitions (assignment statements)
■ (^) Top = empty set
36
CMSC 631, Fall 2004
■ (^) Every expression is available, no defns reach this point
■ (^) Most optimistic assumption
■ (^) Strongest possible hypothesis
■ (^) Always move down in the lattice (with meet)
37
CMSC 631, Fall 2004
■ (^) P = sets of variables
■ Top = empty set
■ P = set of expressions
■ (^) Top = set of all expressions
Out(s) = Top for all s
W := { all statements }
repeat
Take s from W
temp := f s
s pred(s)
Out(s ))
if (temp != Out(s)) {
Out(s) := temp
W := W succ(s)
until W =
In(s) = Top for all s
W := { all statements }
repeat
Take s from W
temp := f s
s succ(s)
In(s ))
if (temp != In(s)) {
In(s) := temp
W := W pred(s)
until W =
temp := f s
(⊓ s pred(s)
Out(s ))
if (temp != Out(s)) { ... }
■ Claim: Out(s) only shrinks
Then ⊓ s pred(s)
Out(s ) shrinks
Since f s
monotonic, f s
(⊓ s pred(s)
Out(s )) shrinks
CMSC 631, Fall 2004 40
■ x0 Ӹx1 Ӹx2 Ӹ...
■ (^) n = # of statements in program
■ (^) k = height of lattice
■ assumes meet operation takes O(1) time
CMSC 631, Fall 2004 41
■ To do this, we need a meet semilattice with top
■ (^) meet semilattice = meets defined for any set
■ (^) Computes greatest fixpoint
■ (^) Computes least fixpoint
42
CMSC 631, Fall 2004
f (x! y) ≤ f (x)! f (y)
f (x! y) = f (x)! f (y)
43
CMSC 631, Fall 2004
f g
h
k
k(h(f (!) " g(!))) =
k(h(f (!)) " h(g(!))) =
k(h(f (!))) " k(h(g(!)))
■ Let^ f s
be the transfer function for statement s
■ If^ p^ is a path^ {s 1
, ..., s n
}, let f p
= f n
;...;f 1
■ Let path(s) be the set of paths from the entry to s
MOP(s) =! p∈ path(s)
fp (")
■ (^) Live variables
■ (^) Available expressions
■ (^) Reaching definitions
■ (^) Very busy expressions
CMSC 631, Fall 2004 52
■ (Not always followed in literature)
CMSC 631, Fall 2004 53
■ “Collapse” larger constructs into smaller ones,
combining data flow equations
■ Eventually program collapsed into a single node!
■ “Expand out” back to original constructs, rebuilding
information
54
CMSC 631, Fall 2004
f
■
f
55
CMSC 631, Fall 2004
f ite
= (f then
◦ f if
) " (f else
◦ f if
Out(if) = f if
(In(ite)))
Out(then) = (f then
◦ f if
)(In(ite)))
Out(else) = (f else
◦ f if
)(In(ite)))
If
Then Else
z
IfThenElse
z
Head
Body
z
While
z
f while
= f head
f head
◦ f body
◦ f head
f head
◦ f body
◦ f head
◦ f body
◦ f head
i
■ (^) f
0 = id
■ Does such a thing exist?
g(j) = !i∈[0..j] (f head
◦ f body
i ◦ f head
CMSC 631, Fall 2004 58
■ What is height of lattice of monotonic functions?
■ (^) Claim: At most |P|×Height(P)
CMSC 631, Fall 2004 59
■ Ones that can be collapsed
■ Standard constructs yield only reducible flow graphs
■
A
B C
z w
60
CMSC 631, Fall 2004
■ (^) Not quite as nice (regions are usually single entry but
often not single exit )
■ (^) Easy to compose functions, compute meet, etc.
■ (^) Not really the case
61
CMSC 631, Fall 2004
■ (^) Lots of proposed solutions in data flow analysis
literature
■
■ Call to function kills all data flow facts
■ (^) May be able to improve depending on language, e.g.,
function call may not affect locals
■ (^) But what about values stored in the heap?
■ (^) Not modeled in traditional data flow
■ Assume all data flow facts killed (!)
■ Or, assume write through x may affect any variable
whose address has been taken