Datafow Analysis
Monday, November 15, 2010
Program optimizations
•
So Far we have talked about diFFerent kinds oF optimizations
•
Peephole optimizations
•
Local common subexpression elimination
•
Loop optimizations
•
What about
global optimizations
•
Optimizations across multiple basic blocks (usually a
whole procedure)
•
Not just a single loop
Monday, November 15, 2010
UseFul optimizations
•
Common subexpression elimination (global)
•
Need to know which expressions are available at a point
•
Dead code elimination
•
Need to know iF the eFFects oF a piece oF code are never
needed, or iF code cannot be reached
•
Constant Folding
•
Need to know iF variable has a constant value
•
Loop invariant code motion
•
Need to know where and when variables are live
•
So how do we get this inFormation?
Monday, November 15, 2010
Datafow analysis
•
±ramework For doing compiler analyses to drive optimization
•
Works across basic blocks
•
Examples
•
Constant propagation: determine which variables are
constant
•
Liveness analysis: determine which variables are live
•
Available expressions: determine which expressions are
have valid computed values
•
Reaching de²nitions: determine which de²nitions could
“reach” a use
Monday, November 15, 2010
Example: constant propagation
•
Goal: determine when variables take on constant values
•
Why? Can enable many optimizations
•
Constant Folding
•
Create dead code
x = 1;
y = x + 2;
if (x > z) then y = 5
... y .
..
x = 1;
y = x + 2;
if (y > x) then y = 5
... y .
..
Monday, November 15, 2010
Example: constant propagation
•
Goal: determine when variables take on constant values
•
Why? Can enable many optimizations
•
Constant Folding
•
Create dead code
x = 1;
y = x + 2;
if (x > z) then y = 5
... y .
..
x = 1;
y = 3;
if (x > z) then y = 5
... y .
..
x = 1;
y = x + 2;
if (y > x) then y = 5
... y .
..
Monday, November 15, 2010
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentExample: constant propagation
•
Goal: determine when variables take on constant values
•
Why? Can enable many optimizations
•
Constant folding
•
Create dead code
x = 1;
y = x + 2;
if (x > z) then y = 5
... y .
..
x = 1;
y = 3;
if (x > z) then y = 5
... y .
..
x = 1;
y = x + 2;
if (y > x) then y = 5
... y .
..
x = 1;
y = 3; //dead code
if (true) then y = 5 //simplify!
... y .
..
Monday, November 15, 2010
How can we Fnd constants?
•
Ideal: run program and see which variables are constant
•
Problem: variables can be constant with some inputs, not
others – need an approach that works for all inputs!
•
Problem: program can run forever (inFnite loops?) –
need an approach that we know will Fnish
•
Idea: run program
symbolically
•
Essentially, keep track of whether a variable is constant
or not constant (but nothing else)
Monday, November 15, 2010
Overview of algorithm
•
Build control ±ow graph
•
We’ll use statementlevel C²G (with merge nodes) for
this
•
Perform symbolic evaluation
•
Keep track of whether variables are constant or not
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '08
 TEST
 Order theory, Monday, Partially ordered set, worklist

Click to edit the document details