Professional Documents
Culture Documents
04 Data Flow Analysis Handout
04 Data Flow Analysis Handout
IN(s1 )
◮ An expression e is available at a point p if
d :x =y +z s1
◮ Every path from the Entry to p has at least one evaluation
of e
◮ There is no assignment to any component variable of e OUT(s1 )
after the last evaluation of e prior to p
◮ Expression e is generated by its evaluation
OUT(s1 ) = IN(s1 ) − KILL(s1 ) ∪ GEN(s1 )
◮ Expression e is killed by assignment to its component
GEN(s1 ) = {y + z}
variables
KILL(s1 ) = Ex
where Ex : set of all expression having x as a component
This may not work in general – WHY?
AvE Analysis of a Structured Program AvE Analysis of a Structured Program
IN(s1 )
IN(s1 )
x =x +z s1
lhs = rhs s1
OUT(s1 )
OUT(s1 )
IN(S)
IN(S)
S
s1 S
s1 s2
s2
OUT(S)
OUT(S)
IN(S)
S
IN(S) = {x + y }
s1
S
s1 : nop
OUT(S)
IN(S) IN(S)
S S
s1 s2 s1 s2
OUT(S) OUT(S)
◮ Assumption: All paths are feasible. ◮ Thus,
◮ Example: true GEN(S) ⊇ analysis GEN(S)
if (true) s1; true KILL(S) ⊆ analysis KILL(S)
else s2; ◮ Fewer expressions marked available than actually do!
Fact Computed Actual ◮ Later we shall see that this is SAFE approximation
GEN(S) = GEN(s1 ) ∩ GEN(s2 ) ⊆ GEN(s1 ) ◮ prevents optimizations
◮ but NO wrong optimization
KILL(S) = KILL(s1 ) ∪ KILL(s2 ) ⊇ KILL(s1 )
AvE for Basic Blocks Solving AvE Constraints
Some Issues
Pass# Pt B1 B2 B3 B4
Init IN - - - -
BB GEN KILL OUT U U U U
B1 {a*b, c+d} {} 1 IN ∅ a*b, c+d c+d
c+d
B2 {c+d} {a*b} OUT a*b, c+d a*b, a*b
B3 {a*b} {} c+d c+d
2 IN ∅ a*b c+d c+d
B4 {a*b} {c+d} OUT a*b, c+d a*b, a*b
c+d c+d
3 IN ∅ a*b c+d c+d
U = {a*b, c+d} OUT a*b, c+d a*b, a*b
c+d c+d
◮ Set-theoretic definitions:
\
a bit for each expression: IN(B) = OUT(P)
a*b c+d
P∈PRED(B)
Pass# Pt B1 B2 B3 B4
Init IN - - - - OUT(B) = IN(B) − KILL(B) ∪ GEN(B)
OUT 11 11 11 11
1 IN 00 11 01 01 ◮ Bitvector definitions:
OUT 11 01 11 10
2 IN 00 10 01 01
^
OUT 11 01 11 10 IN(B) = OUT(P)
3 IN 00 10 01 01 P∈PRED(B)
OUT 11 01 11 10
OUT(B) = IN(B) ∧ ¬KILL(B) ∨ GEN(B)
◮ Bitwise ∨, ∧, ¬ operators
Available Expressions: Application Comparison of RD and AvE
◮ What if we Initialize:
◮ A variable x is live at a point p if
OUT(B) = ∅, ∀B including Entry ◮ There is a point p′ along some path in the flow graph
starting at p to the Exit
◮ Would we find “extra” available expressions? ◮ Value of x could be used at p′
◮ More opportunity to optimize? ◮ There is no definition of x between p and p′ along this path
◮ OR would we miss some expressions that are available? ◮ Otherwise x is dead at p
◮ Loose on opportunity to optimize?
Live Variables: GEN Live Variables: KILL
◮ GEN(B): Set of variables whose values may be used in ◮ KILL(B): Set of variables defined in block B prior to any
block B prior to any definition use
◮ Also called “use(B)” ◮ Also called “def(B)”
◮ “upward exposed use” of a variable in B ◮ “upward exposed definition” of a variable in B
◮ Set-theoretic definitions:
[
OUT(B) = IN(S)
S∈SUCC(B) ◮ Expression e is very busy at a point p if
◮ Every path from p to Exit has at least one evaluation of e
IN(B) = OUT(B) − KILL(B) ∪ GEN(B) ◮ On every path, there is no assignment to any component
◮ Bitvector definitions: variable of e before the first evaluation of e following p
_ ◮ Also called Anticipable expression
OUT(B) = OUT(S)
S∈SUCC(B)