Data Flow Analysis and Optimizations
Last Time
•
Control Flow Graphs
Today
•
Data Flow Analysis
•
Data Flow Frameworks
•
Constant Propagation
•
Reaching Definitions
CS 380C Lecture 3
1
Data Flow Analysis
Data Flow Analysis
Data flow analysis tells us things we want to know
about programs, for example:
•
Is this computation loop invariant?
•
Which definition reaches this use?
•
Is this value a constant?
Example:
B = 2
A = 3
C = A + B
X = true
if (X)
then
else
A = 2
B = 3
CS 380C Lecture 3
2
Data Flow Analysis
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Data Flow Analysis
Systems of equations that compute information (e.g.,
uses, definitions, values) about variables at program
points.
A
Monotone Data Flow Framework
•
point
 start and/or end of a basic block
•
Information for a forward problem
INFO
in
(
v
)
=
merge (INFO
out
predecessors
(
v
)
)
INFO
out
(
v
)
=
transfer (INFO
in
(
v
)
)
•
Transfer functions:
T
v
is the transfer function for
v
, how information is
changed by
v
.
T
q
is the transfer function for a path and describes
how information is carried on path
q
. All paths
start at the entry
entry
.
Given Q:
entry
+
→
x
, where
x
is a node in the CFG,
such that
Q
=
q
o
→
q
1
→
...
q
n
, the
transfer function
is:
t
q
n

1
(
t
q
n

2
(
...
(
t
2
(
t
1
(
t
0
(
)))
...
)
Meet Over All Paths Solution
mop
(
x
) =
Q
∈
Paths
(
x
)
t
Q
(
)
CS 380C Lecture 3
3
Data Flow Analysis
Data Flow Framework
1. A
semilattice
L
with a binary meet operation
,
such that
a
,
b
,
c
∈
L
:
•
a
a
=
a
(
idempotent
)
•
a
b
=
b
a
(
commutative
)
•
a
(
b
c
) = (
a
b
)
c
(
associative
)
2.
imposes an order on
L
,
∀
a
,
b
∈
L
•
a
b
⇔
a
b
=
b
•
a
b
⇔
a
b
and
a
=
b
3. A semilattice has a
bottom
element
⊥
,
i
ff
•
a
⊥
=
⊥
for every
a
∈
L
.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '08
 shmat
 Algebra, Hilbert space, Control Flow Graph, worklist, CS 380C Lecture

Click to edit the document details