lecture-11-6up

# lecture-11-6up - Program optimizations Dataow Analysis So...

This preview shows pages 1–3. Sign up to view the full content.

Datafow Analysis Wednesday, November 9, 2011 Program optimizations So Far we have talked about diFFerent kinds oF optimizations Peephole optimizations Local common sub-expression elimination Loop optimizations What about global optimizations Optimizations across multiple basic blocks (usually a whole procedure) Not just a single loop Wednesday, November 9, 2011 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? Wednesday, November 9, 2011 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 Wednesday, November 9, 2011 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 . .. Wednesday, November 9, 2011 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 . .. Wednesday, November 9, 2011

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
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 . .. x = 1; y = 3; //dead code if (true) then y = 5 //simplify! ... y . .. Wednesday, November 9, 2011 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) Wednesday, November 9, 2011 Overview of algorithm Build control ±ow graph We’ll use statement-level C²G (with merge nodes) for this Perform symbolic evaluation Keep track of whether variables are constant or not Replace constant-valued variable uses with their values, try to simplify expressions and control ±ow Wednesday, November 9, 2011 Build C²G x = 1; y = x + 2; if (y > x) then y = 5; ... y . ..
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 8

lecture-11-6up - Program optimizations Dataow Analysis So...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online