0% found this document useful (0 votes)
8 views67 pages

CCimp

The document outlines various dataflow analysis techniques, including value numbering, copy propagation, and dead code elimination, focusing on algorithms for transforming and analyzing basic blocks in programming. It introduces concepts such as reaching definitions, available expressions, and liveness, detailing how to determine the availability of expressions and the propagation of definitions through control flow graphs. The document also discusses the formalization of analysis through dataflow equations and the use of fixed point algorithms to solve them.

Uploaded by

riddaazainab512
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views67 pages

CCimp

The document outlines various dataflow analysis techniques, including value numbering, copy propagation, and dead code elimination, focusing on algorithms for transforming and analyzing basic blocks in programming. It introduces concepts such as reaching definitions, available expressions, and liveness, detailing how to determine the availability of expressions and the propagation of definitions through control flow graphs. The document also discusses the formalization of analysis through dataflow equations and the use of fixed point algorithms to solve them.

Uploaded by

riddaazainab512
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

Spring 2010

Lecture
Lect e 10:
10 Introduction
Int od ction to
to
Dataflow Analysis
Value Numbering
g Summary
y
• Forward symbolic execution of basic block
• Maps
– Var2Val – symbolic value for each variable
– Exp2Val – value of each evaluated expression
– Exp2Tmp – tmp that holds value of each evaluated expression
• Algorithm
– For each statement
• If variables in RHS not in the Var2Val add it with a new value
• If RHS expression in Exp2Tmp use that Temp
• If nott add 2V l with
dd RHS expressiion tto Exp2Val ith new vallue
• Copy the value into a new tmp and add to EXp2Tmp

Saman Amarasinghe 2 6.035 ©MIT Fall 1998


Copy
py Propagation
p g Summary
y
• Forward Propagation within basic block
• Maps
– tmp2var: tells which variable to use instead of a given temporary
variable
– var2set: inverse of tmp to var. tells which temps are mapped to a
given variable by tmp to var
• Algorithm
– For each statement
• If any tmp variable in the RHS is in tmp2var replace it with var
• If LHS var in var2set remove the variables in the set in tmp2var

Saman Amarasinghe 3 6.035 ©MIT Fall 1998


Dead Code Elimination Summary
y
• Backward Propagation within basic block
• Map
– A set of variables that are needed later in computation
• Algorithm
– Every statement encountered
• If LHS is not in the set, remove the statement
• Else
El put allll the
h variables
i bl ini the
h RHS into
i th
he set

Saman Amarasinghe 4 6.035 ©MIT Fall 1998


Summary
y So far… what’s next
• Till now: How to analyze
y and transform
within a basic block

• Next: How to do it for the entire procedure

Saman Amarasinghe 5 6.035 ©MIT Fall 1998


Outline

• Reaching Definitions
• Available Expressions
• Liveness
Reaching
g Definitions
• Concept
p of definition and use
– a = x+y
– is a d o o
definition of a
– is a use of x and y
• A definition reaches a use if
– value written by definition
– may be read by use

Saman Amarasinghe 7 6.035 ©MIT Fall 1998


Reaching
g Definitions
s = 0;
a = 4;
i = 0;
k == 0

b = 1; b = 2;

i<n

s = s + a*b;
i = i + 1; return s

Saman Amarasinghe 8 6.035 ©MIT Fall 2006


Reaching Definitions and
Constant Propagation
• Is a use of a variable a constant?
– Check all reaching definitions
– If all
a assign
a g variable
a ab to o same
a constant
o a
– Then use is in fact a constant
• Can replace variable with constant

Saman Amarasinghe 9 6.035 ©MIT Fall 1998


Is a Constant in s = s+a*b?
s = 0; Yes!
a = 4;
i = 0;
On all reaching
k == 0 definitions
a=4
b = 1;; b = 2;;

i<n

s = s + a*b;
i = i + 1;; return s

Saman Amarasinghe 10 6.035 ©MIT Fall 2006


Constant Propagation
Transform
s = 0; Yes!
a = 4;
i = 0;
On all reaching
k == 0 definitions
a=4
b = 1;; b = 2;;

i<n

s = s + 4*b;
i = i + 1;; return s

Saman Amarasinghe 11 6.035 ©MIT Fall 2006


Is b Constant in s = s+a*b?
s = 0; No!
a = 4;
i = 0;
One reaching
k == 0 definition with
b=1
b = 1;; b = 2;; One reachingg
definition with
i<n
b=2
s = s + a*b;
i = i + 1;; return s

Saman Amarasinghe 12 6.035 ©MIT Fall 2006


s = 0;
a = 4; Splitting
p g
i = 0; Preserves Information Lost At Merges
k == 0

b = 1; b = 2;

i<n
s = s + a*b; s = 0;
i = i + 1; return s a = 4;
i = 0;
k == 0

b = 1; b = 2;

i<n i<n
s = s + aa*b;
b; s = s + aa*b;
b;
i = i + 1; return s i = i + 1; return s

Saman Amarasinghe 13 6.035 ©MIT Fall 2006


s = 0;
a = 4; Splitting
p g
i = 0; Preserves Information Lost At Merges
k == 0

b = 1; b = 2;

i<n
s = s + a*b; s = 0;
i = i + 1; return s a = 4;
i = 0;
k == 0

b = 1; b = 2;

i<n i<n

s = s + a**1; return s s = s + a**2; return s


i = i + 1; i = i + 1;
Saman Amarasinghe 14 6.035 ©MIT Fall 2006
Computing Reaching
Definitions
• Compute
p with sets of definitions
– represent sets using bit vectors
a definition
– each d o has
a a position
po o in bit b vector
o
• At each basic block, compute
– definitions that reach start of block
– definitions that reach end of block
• Do computation by simulating execution
execution of
program until reach fixed point

Saman Amarasinghe 15 6.035 ©MIT Fall 1998


1234567
0000000
1: s = 0;;
2: a = 4;
3: i = 0;
k == 0
1110000

1234567 1234567
1110000 1110000
4: b = 1; 5: b = 2;
1111000 1110100

1234567
1111100
1111111
i<n
1234567 1111111
1111100
1234567
1111111
1111100 1111111
1111100
6: s = s + a*b; return s
7:
7 i = i + 1;
1 1111111
1111100
0101111

Saman Amarasinghe 16 6.035 ©MIT Fall 2006


Formalizing
g Analysis
y
• Each basic block has
– IN - set of definitions that reach beginning of block
– OUT - set of definitions that reach end of block
– GEN - set of definitions generated in block
– KILL - set of definitions killed in block
• GEN[s = s + a *b i = i + 1
a*b; 1;]] = 0000011
• KILL[s = s + a*b; i = i + 1;] = 1010000
• Compiler
C il scans each h basic
b i block
bl k tot derive
d i GEN
and KILL sets

Saman Amarasinghe 17 6.035 ©MIT Fall 1998


Dataflow Equations
q
• IN[b] = OUT[b1] U ... U OUT[bn]
– where b1, ..., bn are predecessors of b in CFG
• OUT[b] = (IN[b] - KILL[b]) U GEN[b]
• IN[entry] = 0000000
• Result: system of equations

Saman Amarasinghe 18 6.035 ©MIT Fall 1998


Solving
g Equations
q
• Use fixed point algorithm
• Initialize with solution of OUT[b] = 0000000
• Repeatedly apply equations
– IN[b] = OUT[b1] U ... U OUT[bn]
– OUT[b] = (IN[b] - KILL[b]) U GEN[b]
• Until reach fixed point
• Until equation application has no further effect
• Use a worklist to track which equation
applications may have a further effect

Saman Amarasinghe 19 6.035 ©MIT Fall 1998


Reaching
g Definitions Algorithm
g
for all nodes n in N
OUT[n] = emptyset; // OUT[n] = GEN[n];
IN[Entry] = emptyset;
OUT[Entry] = GEN[Entry];
Changed = N - { Entry }; // N = all nodes in graph

while (Changed != emptyset)


choose a node n in Changed;
Changed = Changed - { n };

IN[n] = emptyset;
for all nodes p in predecessors(n)
IN[n]
[ ] = IN[n]
[ ] U OUT[p];
[p];

OUT[n] = GEN[n] U (IN[n] - KILL[n]);

if (OUT[n] changed)
for all nodes s in successors(n)
Changed = Changed U { s };
Saman Amarasinghe 20 6.035 ©MIT Fall 1998
Q
Questions
• Does the algorithm halt?
– yes, because transfer function is monotonic
– if increase IN, increase OUT
– in limit, all bits are 1

• If bit is 0,
0 does the corresponding definition ever
reach basic block?
• If bit is 1,
1 is does the corresponding definition
always reach the basic block?

Saman Amarasinghe 21 6.035 ©MIT Fall 1998


1234567
0000000
1: s = 0;;
2: a = 4;
3: i = 0;
k == 0
1110000

1234567 1234567
1110000 1110000
4: b = 1; 5: b = 2;
1111000 1110100

1234567
1111100
1111111
i<n
1234567 1111111
1111100
1234567
1111111
1111100 1111111
1111100
6: s = s + a*b; return s
7:
7 i = i + 1;
1 1111111
1111100
0101111

Saman Amarasinghe 22 6.035 ©MIT Fall 2006


Outline

• Reaching Definitions
• Available Expressions
• Liveness
Available Expressions
p
• An expression x+y is available at a point p if
– every path from the initial node to p must evaluate
x+y before reaching p,
– and there are no assignments to x or y after the
evaluation but before p.
• Available Expression information can be used to
do global (across basic blocks) CSE
• If expression is available at use, no need to
reevaluate it

Saman Amarasinghe 24 6.035 ©MIT Fall 1998


Example:
p Available Expression
p
a=b+c
d=e+f
f=a+c

b=a+d
g=a+c
h=c+f

j=a+b+c+d

Saman Amarasinghe 25 6.035 ©MIT Fall 2006


Is the Expression
p Available?
a=b+c
YES!
d=e+f
f=a+c

b=a+d
g=a+c
h=c+f

j=a+b+c+d

Saman Amarasinghe 26 6.035 ©MIT Fall 2006


Is the Expression
p Available?
a=b+c
YES!
d=e+f
f=a+c

b=a+d
g=a+c
h=c+f

j=a+b+c+d

Saman Amarasinghe 27 6.035 ©MIT Fall 2006


Is the Expression
p Available?
a=b+c
NO!
d=e+f
f=a+c

b=a+d
g=a+c
h=c+f

j=a+b+c+d

Saman Amarasinghe 28 6.035 ©MIT Fall 2006


Is the Expression
p Available?
a=b+c
NO!
d=e+f
f=a+c

b=a+d
g=a+c
h=c+f

j=a+b+c+d

Saman Amarasinghe 29 6.035 ©MIT Fall 2006


Is the Expression
p Available?
a=b+c
NO!
d=e+f
f=a+c

b=a+d
g=a+c
h=c+f

j=a+b+c+d

Saman Amarasinghe 30 6.035 ©MIT Fall 2006


Is the Expression
p Available?
a=b+c
YES!
d=e+f
f=a+c

b=a+d
g=a+c
h=c+f

j=a+b+c+d

Saman Amarasinghe 31 6.035 ©MIT Fall 2006


Is the Expression
p Available?
a=b+c
YES!
d=e+f
f=a+c

b=a+d
g=a+c
h=c+f

j=a+b+c+d

Saman Amarasinghe 32 6.035 ©MIT Fall 2006


Use of Available Expressions
p
a=b+c
d=e+f
f=a+c

b=a+d
g=a+c
h=c+f

j=a+b+c+d

Saman Amarasinghe 33 6.035 ©MIT Fall 2006


Use of Available Expressions
p
a=b+c
d=e+f
f=a+c

b=a+d
g=a+c
h=c+f

j=a+b+c+d

Saman Amarasinghe 34 6.035 ©MIT Fall 2006


Use of Available Expressions
p
a=b+c
d=e+f
f=a+c

b=a+d
g=a+c
h=c+f

j=a+b+c+d

Saman Amarasinghe 35 6.035 ©MIT Fall 2006


Use of Available Expressions
p
a=b+c
d=e+f
f=a+c

b=a+d
g=f
h=c+f

j=a+b+c+d

Saman Amarasinghe 36 6.035 ©MIT Fall 2006


Use of Available Expressions
p
a=b+c
d=e+f
f=a+c

b=a+d
g=f
h=c+f

j=a+b+c+d

Saman Amarasinghe 37 6.035 ©MIT Fall 2006


Use of Available Expressions
p
a=b+c
d=e+f
f=a+c

b=a+d
g=f
h=c+f

j=a+c+ b+d

Saman Amarasinghe 38 6.035 ©MIT Fall 2006


Use of Available Expressions
p
a=b+c
d=e+f
f=a+c

b=a+d
g=f
h=c+f

j=f+ b+d

Saman Amarasinghe 39 6.035 ©MIT Fall 2006


Use of Available Expressions
p
a=b+c
d=e+f
f=a+c

b=a+d
g=f
h=c+f

j=f+ b+d

Saman Amarasinghe 40 6.035 ©MIT Fall 2006


Computing Available
Expressions
• Represent sets of expressions using bit vectors
• Each expression corresponds to a bit
g
• Run dataflow algorithm similar to reaching
g
definitions
• Big difference
– definition reaches a basic block if it comes from ANY
predecessor in CFG
– expression
e p ession is a
available
ailable at
at a basic block only
onl if it is
is
available from ALL predecessors in CFG

Saman Amarasinghe 41 6.035 ©MIT Fall 1998


0000
a = x+y;
+
Expressions x == 0
1: x+yy 1001
2: i<n x = z;
3: i+c b = x+y;
4: x==0 1000
i = x+y;

1000
i<n

1100 1100
c = x+y; d = x+y
i = i+c;
Saman Amarasinghe 42 6.035 ©MIT Fall 2006
0000
Global CSE Transform a = x+y;
t=a
Expressions x == 0
1001
1: x+yy
x = z;
2: i<n
b = x+y;
3: i+c
t=b
4: x==0 1000
i = x+y;
must use same temp
for CSE in all blocks 1000
i<n

1100 1100
c = x+y; d = x+y
i = i+c;
Saman Amarasinghe 43 6.035 ©MIT Fall 2006
0000
Global CSE Transform a = x+y;
t=a
Expressions x == 0
1001
1: x+yy
x = z;
2: i<n
b = x+y;
3: i+c
t=b
4: x==0 1000
i = t;
must use same temp
for CSE in all blocks 1000
i<n

1100 1100
c = t; d=t
i = i+c;
Saman Amarasinghe 44 6.035 ©MIT Fall 2006
Formalizing
g Analysis
y
• Each basic block has
– IN - set of expressions available at start of block
– OUT - set of expressions available at end of block
– GEN - set of expressions computed in block
– KILL - set of expressions killed in in block
• GEN[[x = z;; b = x+y]
y] = 1000
• KILL[x = z; b = x+y] = 1001
• Compiler scans each basic block to derive GEN
and KILL sets

Saman Amarasinghe 45 6.035 ©MIT Fall 1998


Dataflow Equations
q
• IN[b] [ ]  ...  OUT[bn]
[ ] = OUT[b1] [ ]
– where b1, ..., bn are predecessors of b in CFG
• OUT[b] = (IN[b] - KILL[b]) U GEN[b]
• IN[entry] = 0000
y
• Result: system of equations
q

Saman Amarasinghe 46 6.035 ©MIT Fall 1998


Solving
g Equations
q
• Use fixed point algorithm
• IN[entry] = 0000
• Initialize OUT[b] = 1111
• Repeatedly apply equations
– IN[b] = OUT[b1]  ...  OUT[bn]
– OUT[b] = (IN[b] - KILL[b]) U GEN[b]
• Use a worklist algorithm to reach fixed point

Saman Amarasinghe 47 6.035 ©MIT Fall 1998


Available Expressions
for all nodes n in N
Algorithm
OUT[n] = E; // OUT[n] = E - KILL[n];
IN[Entry] = emptyset;
OUT[Entry] = GEN[Entry];
Changed = N - { Entry }; // N = all nodes in graph

while (Changed != emptyset)


choose a node n in Changed;
Changed = Changed - { n };

IN[n] = E; // E is set of all expressions


for all nodes p in predecessors(n)
IN[n] = IN[n]  OUT[p];
OUT[p]

OUT[n] = GEN[n] U (IN[n] - KILL[n]);

if (OUT[n] changed)
for all nodes s in successors(n)
Saman Amarasinghe Changed = Changed U { s48}; 6.035 ©MIT Fall 1998
Q
Questions
• Does algorithm always halt?

• If expression is available in some execution, is it


always marked as available in analysis?

• Iff expression
i isi not available
il bl in
i some execution,
i
can it be marked as available in analysis?

Saman Amarasinghe 49 6.035 ©MIT Fall 1998


General Correctness
• Concept in actual program execution
– Reaching definition: definition D, execution E at program point P
– Available expression: expression X,X execution E at program point P
• Analysis reasons about all possible executions
• For all executions E at program point P,
– if a definition D reaches P in E
– then D is in the set of reaching definitions at P from analysis
• Other way around
– if D is not in the set of reaching
g definitions at P from analysis
y
– then D never reaches P in any execution E
• For all executions E at program point P,
– if an expression X is in set of available expressions at P from analysis
– then X is available in E at P
• Concept of being conservative

Saman Amarasinghe 50 6.035 ©MIT Fall 1998


Duality
y In Two Algorithms
g
• Reaching definitions
– Confluence operation is set union
– OUT[b] initialized to empty set
• Available expressions
– Confluence operation is set intersection
– OUT[b] initialized t sett off available
i iti li d to il bl expressions
i
• General framework for dataflow algorithms.
• Build
B ild parameterized
t i d dataflow
d t fl analyzer
l once, use
for all dataflow problems

Saman Amarasinghe 51 6.035 ©MIT Fall 1998


Outline

• Reaching Definitions
• Available Expressions
• Liveness
Liveness Analysis
y
• A variable v is live at point p if
– v is used along some path starting at p, and
– no definition of v along the path before the use.
• When is a variable v dead at point p?
– No use of v on any path from p to exit node, or
– If allll paths
th ffrom p redefine
d fi v before
b f using
i v.

Saman Amarasinghe 53 6.035 ©MIT Fall 1998


What Use is Liveness
Information?
• Register allocation.
– If a variable is dead, can reassign its register
• Dead code elimination.
– Eliminate assignments to variables not read later.
– But must not eliminate last assignment to variable
(such as instance variable) visible outside CFG.
CFG
– Can eliminate other dead assignments.
– Handle byy makingg all externallyy visible variables live on
exit from CFG

Saman Amarasinghe 54 6.035 ©MIT Fall 1998


Conceptual
p Idea of Analysis
y
• Simulate execution
• But start from exit and go backwards in CFG
p
• Compute liveness information from end to
beginning of basic blocks

Saman Amarasinghe 55 6.035 ©MIT Fall 1998


Liveness Example
p
0101110
• Assume a,b,c visible a = x+y;
t = a;
outside method
c = a+x;
• So are live on exit x == 0
• Assume x,y,z,t not 1100111
abcxyzt
visible
• Represent Liveness 1000111
Using Bit Vector b = t+z;
1100100
– order
d isi abcxyzt
b abcxyzt 1100100
c = y+1;
1110000
abcxyzt

Saman Amarasinghe 56 6.035 ©MIT Fall 2006


Dead Code Elimination
0101110
• Assume a,b,c visible a = x+y;
t = a;
outside method
c = a+x;
• So are live on exit x == 0
• Assume x,y,z,t not 1100111
abcxyzt
visible
• Represent Liveness 1000111
Using Bit Vector b = t+z;
1100100
– order
d isi abcxyzt
b abcxyzt 1100100
c = y+1;
1110000
abcxyzt

Saman Amarasinghe 57 6.035 ©MIT Fall 2006


Formalizing
g Analysis
y
• Each basic block has
– IN - set of variables live at start of block
– OUT - set of variables live at end of block
– USE - set of variables with upwards exposed uses in block
– DEF - set of variables defined in block
;] = { z } (x
• USE[[x = z;; x = x+1;] ( not in USE))
• DEF[x = z; x = x+1;y = 1;] = {x, y}
• Compiler scans each basic block to derive USE and
DEF sets

Saman Amarasinghe 58 6.035 ©MIT Fall 1998


Algorithm
f allll nodes
for d n ini N-{EExit
it }
IN[n] = emptyset;
OUT[Exit] = emptyset;
IN[[Exit]] = use[
u [Exit];
];
Changed = N - { Exit };

while (Changed != emptyset)


choose a node n in Changed;
Changed = Changed - { n };

OUT[[n]] = empptyyset;;
for all nodes s in successors(n)
OUT[n] = OUT[n] U IN[p];

IN[n] = use[n] U (out[n] - def[n]);

if (IN[n] changed)
for all nodes p in predecessors(n)
Changed = Changed U { p };

Saman Amarasinghe 59 6.035 ©MIT Fall 1998


Similar to Other Dataflow
Algorithms
• Backwards analysis,
y , not forwards
• Still have transfer functions
• Still have confluence operators
• Can generalize framework to work for both
fo a ds an
forwards andd backwards
back a ds analyses
anal ses

Saman Amarasinghe 60 6.035 ©MIT Fall 1998


Comparison
p
Reaching Definitions Available Expressions Liveness
for all nodes n in N for all nodes n in N for all nodes n in N - { Exit }
OUT[n] = emptyset; OUT[n] = E; IN[n] = emptyset;
IN[Entry] = emptyset; IN[Entry] = emptyset; OUT[Exit] = emptyset;
OUT[Entry] = GEN[Entry]; OUT[Entry] = GEN[Entry]; IN[Exit] = use[Exit];
Changed = N - { Entry }; Changed = N - { Entry }; Changed = N - { Exit };

while (Changed != emptyset) while (Changed != emptyset) while (Changed != emptyset)


choose a node n in Changed; choose a node n in Changed; choose a node n in Changed;
Changed = Changed - { n }; Changed = Changed - { n }; Changed = Changed - { n };

IN[n] = emptyset; IN[n] = E; OUT[n] = emptyset;


for all nodes p in predecessors(n) for all nodes p in predecessors(n) for all nodes s in successors(n)
IN[n] = IN[n] U OUT[p]; IN[n] = IN[n]  OUT[p]; OUT[n] = OUT[n] U IN[p];

OUT[n] = GEN[n] U (IN[n] - KILL[n]); OUT[n] = GEN[n] U (IN[n] - KILL[n]); IN[n] = use[n] U (out[n] - def[n]);

if (OUT[n] changed) if (OUT[n] changed) if (IN[n] changed)


for all nodes s in successors(n) for all nodes s in successors(n) for all nodes p in predecessors(n)
Changed = Changed U { s }; Changed = Changed U { s }; Changed = Changed U { p };

Saman Amarasinghe 61 6.035 ©MIT Fall 1998


Comparison
p
Reaching Definitions Available Expressions
for all nodes n in N for all nodes n in N
OUT[n] = emptyset; OUT[n] = E;
IN[Entry] = emptyset; IN[Entry] = emptyset;
OUT[Entry] = GEN[Entry]; OUT[Entry] = GEN[Entry];
Changed = N - { Entry }; Changed = N - { Entry };

while (Changed != emptyset) while (Changed != emptyset)


choose a node n in Changed; choose a node n in Changed;
Changed = Changed - { n }; Changed = Changed - { n };

IN[n] = emptyset; IN[n] = E;


for all nodes p in predecessors(n) for all nodes p in predecessors(n)
IN[n] = IN[n] U OUT[p]; IN[n] = IN[n]  OUT[p];

OUT[n] = GEN[n] U (IN[n] - KILL[n]); OUT[n] = GEN[n] U (IN[n] - KILL[n]);

if (OUT[n] changed) if (OUT[n] changed)


for all nodes s in successors(n) for all nodes s in successors(n)
Changed = Changed U { s }; Changed = Changed U { s };

Saman Amarasinghe 62 6.035 ©MIT Fall 1998


Comparison
p
Reaching Definitions Liveness
for all nodes n in N for all nodes n in N
OUT[n] = emptyset; IN[n] = emptyset;
IN[Entry] = emptyset; OUT[Exit] = emptyset;
OUT[Entry] = GEN[Entry]; IN[Exit] = use[Exit];
Changed = N - { Entry }; Changed = N - { Exit };

while (Changed != emptyset) while (Changed != emptyset)


choose a node n in Changed; choose a node n in Changed;
Changed = Changed - { n }; Changed = Changed - { n };

IN[n] = emptyset; OUT[n] = emptyset;


for all nodes p in predecessors(n) for all nodes s in successors(n)
IN[n] = IN[n] U OUT[p]; OUT[n] = OUT[n] U IN[p];

OUT[n] = GEN[n] U (IN[n] - KILL[n]); IN[n] = use[n] U (out[n] - def[n]);

if (OUT[n] changed) if (IN[n] changed)


for all nodes s in successors(n) for all nodes p in predecessors(n)
Changed = Changed U { s }; Changed = Changed U { p };

Saman Amarasinghe 63 6.035 ©MIT Fall 1998


Analysis Information Inside
Basic Blocks
• One detail:
– Given dataflow information at IN and OUT of node
– Also need to compute information at each statement of
basic block
– Simple propagation algorithm usually works fine
– Can be viewed as restricted case of dataflow analysis

Saman Amarasinghe 64 6.035 ©MIT Fall 1998


Pessimistic vs. Optimistic
Analyses
• Available expressions is optimistic
(for common sub
(f b-expressiion elilimiinati
tion))
– Assume expressions are available at start of analysis
– Analysis eliminates all that are not available
– Cannot stop analysis early and use current result
• Live variables is pessimistic (for dead code elimination)
– Assume all variables are live at start of analysis
– Analysis finds variables that are dead
– Can stop analysis early and use current result
• Dataflow setup same for both analyses
• Optimism/pessimism depends on intended use

Saman Amarasinghe 65 6.035 ©MIT Fall 1998


Summary
y
• Basic Blocks and Basic Block Optimizations
– Copy and constant propagation
– Common sub-expression
sub expression elimination
– Dead code elimination

• Dataflow
D t fl Anallysiis
– Control flow graph
– IN[b], OUT[b], transfer functions, join points

• Paired analyses and transformations


– Reachinggdefinitions /constant prop
pag
gation
– Available expressions/common sub-expression elimination
– Liveness analysis/Dead code elimination

• Stacked analysis and transformations work together


Saman Amarasinghe 66 6.035 ©MIT Fall 1998
MIT OpenCourseWare
http://ocw.mit.edu

6.035 Computer Language Engineering


Spring 2010

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy