This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full 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 basicblock 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 controlflow 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 controlflow 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 controlflow 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 controlflow 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 document was uploaded on 04/06/2012.
 Fall '09

Click to edit the document details