lecture15

lecture15 - 1 Prof Aiken CS 143 Lecture 15 1 Global...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Prof. Aiken CS 143 Lecture 15 1 Global Optimization Lecture 15 Prof. Aiken CS 143 Lecture 15 2 Lecture Outline • Global flow analysis • Global constant propagation • Liveness analysis Prof. Aiken CS 143 Lecture 15 3 Local Optimization Recall the simple basic-block optimizations – Constant propagation – Dead code elimination X := 3 Y := Z * W Q := X + Y X := 3 Y := Z * W Q := 3 + Y Y := Z * W Q := 3 + Y Prof. Aiken CS 143 Lecture 15 4 Global Optimization These optimizations can be extended to an entire control-flow graph X := 3 B > 0 Y := Z + W Y := 0 A := 2 * X Prof. Aiken CS 143 Lecture 15 5 Global Optimization These optimizations can be extended to an entire control-flow graph X := 3 B > 0 Y := Z + W Y := 0 A := 2 * X Prof. Aiken CS 143 Lecture 15 6 Global Optimization These optimizations can be extended to an entire control-flow graph X := 3 B > 0 Y := Z + W Y := 0 A := 2 * 3 2 Prof. Aiken CS 143 Lecture 15 7 Correctness • How do we know it is OK to globally propagate constants? • There are situations where it is incorrect: X := 3 B > 0 Y := Z + W X := 4 Y := 0 A := 2 * X Prof. Aiken CS 143 Lecture 15 8 Correctness (Cont.) To replace a use of x by a constant k we must know that: On every path to the use of x , the last assignment to x is x := k ** Prof. Aiken CS 143 Lecture 15 9 Example 1 Revisited X := 3 B > 0 Y := Z + W Y := 0 A := 2 * X Prof. Aiken CS 143 Lecture 15 10 Example 2 Revisited X := 3 B > 0 Y := Z + W X := 4 Y := 0 A := 2 * X Prof. Aiken CS 143 Lecture 15 11 Discussion • The correctness condition is not trivial to check • “All paths” includes paths around loops and through branches of conditionals • Checking the condition requires global analysis – An analysis of the entire control-flow graph Prof. Aiken CS 143 Lecture 15 12 Global Analysis Global optimization tasks share several traits: – The optimization depends on knowing a property X at a particular point in program execution – Proving X at any point requires knowledge of the entire program – It is OK to be conservative. If the optimization requires X to be true, then want to know either • X is definitely true • Don’t know if X is true – It is always safe to say “don’t know” 3 Prof. Aiken CS 143 Lecture 15 13 Global Analysis (Cont.) • Global dataflow analysis is a standard technique for solving problems with these characteristics • Global constant propagation is one example of an optimization that requires global dataflow analysis Prof. Aiken CS 143 Lecture 15 14 Global Constant Propagation • Global constant propagation can be performed...
View Full Document

This note was uploaded on 01/12/2010 for the course CS 143 at Stanford.

Page1 / 9

lecture15 - 1 Prof Aiken CS 143 Lecture 15 1 Global...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online