Recapitulation: Data Flow Analysis
What are goals of data flow analysis?
•
statically collect information about values of variables and expressions at certain program points
•
statically collect information about the usage of variables at certain program points
•
use collected information for program optimization
A variable
vis
liveat a program point S if there is an execution path starting in S on which an application of v preceds a definition of v.
S
x = v + y;
v live
v dead
Liveness Analysis (2)
•
What kind of data flow analysis is liveness analysis?
! backwardanalysis
! information on exit of basic blocks is theunion of the information at the entry of all successors
•
How are the data flow equations for liveness analysis defined?
! gen(B): variables applied in B without prior definition
! kill(B): variables defined in B
! in(B) =gen(B)∪(out(B)\kill(B))
! out(B) =!
s∈succ(B)in(s)
Liveness Analysis (4)
Computation of liveness information by least fixpoint iteration:
for each basic block B {
in(B) = {}; out(B) = {};
} repeat {
for each basic block B {
in’(B) = in(B); out’(B) = out(B);
in(B) = union(gen(B),setminus(out(B), kill(B));
out(B) = union(in(S)) for all successors S of B;
} }
until in’(B) = in(B) and out’(B) = out(B) for all B
Further Aspects:
•
Can a variable be live and contained in dead code at the same time?
yes, e.g., if live variable is contained in a branch that is never executed.
•
How can live variable information be efficiently represented and computed?
by bit vectors and bit vector operations
Available Expressions
An expression
x⊕yis
availableat a program point S if
on all paths from the start to S
x⊕yis computed at least once and there are no definition of x and y since the most recent
occurrence of
x⊕y.Information about available expressions can be used for common
subexpression elimination.
Forward analysis
where entry information is
intersectionof exit information of predecessors:
•
gen(B): all expressions
x ⊕ythat are computed in B where
xor
yare not defined afterwards
•
kill(B): any definition of
xor
yin B kills the expressions
x⊕y• in(B) =!
s∈pred(B)out(s)
• out(B) =gen(B)∪(in(B))\kill(B)
Available Expressions (3)
Computation by greatest fixpoint iteration:
for each basic block B {
in(B) = {all expressions};
out(B) = {all expressions};
}
in(start) = {};
repeat {
for each basic block B {
in’(B) = in(B); out’(B) = out(B);
in(B) = intersection(out(S)) for all predecessors S of B;
out(B) = union(gen(B),setminus(in(B), kill(B));
} }
until in’(B) = in(B) and out’(B) = out(B) for all B
Recommended Reading:
•
Appel: Chapter 10 and Chapter 17
•