Docsity

Lecture Slides on Global Optimization | ECS 142, Study Guides, Projects, Research of Computer Science

Partial preview of the text

Download Lecture Slides on Global Optimization | ECS 142 and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

Global Optimization

Lecture 25 Dr. Sean Peisert – ECS 142 – Spring 2009 1

Status

Project 4 due June 5, 11:55pm

This Week:

Office Hours Wednesday at 4pm and Friday at 11am

Friday: Register Allocation

Next Week:

Monday: Automatic Memory Management

Wednesday: Static Analysis for Security

Friday: Final Exam Review 2

Correctness Diagrams

4

Correctness

5

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 **

Discussion

7

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

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 method body

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” 8

Global Constant Propagation

Global constant propagation can be

performed at any point where **holds

Consider the case of computing **for a

single variable X at all program points

10

Global Constant

Propagation (Cont.)

To make the problem precise, we associate

one of the following values with X at every

program point

11 value interpretation

this statement never executes c X = constant c

Don’t know if X is a constant

Using the Information

13

Given global constant information, it is easy to perform the optimization

Simply inspect the x = ?associated with a statement using x

If x is constant at that point replace that use of x by the constant

But how do we compute the properties x =?

The Idea

14

The analysis of a complicated program can be

expressed as a combination of simple rules

relating the change in information between

adjacent statements

Transfer Functions

Define a transfer function that transfers

information one statement to another

In the following rules, let statement save

immediate predecessor statements p 1 ,…,pn

16

Rules

1. if Cout(x, pi) = * for some i, then Cin(x, s) = *
2. if Cout(x, pi) = c and if Cout(x, pi) = d and d≠c,
then Cin(x, s) = *
3. if Cout(x, pi) = c or # for all i, then Cin(x, s) = c
4. if Cout(x, pi) = # for all i, then Cin(x, s) =

17

The Other Half

19

Rules 1-4 relate the out of one statement to the in of the successor statement

they propagate information forward across a CFG edge

Now we need rules relating the in of a statement to the out of the same statement

to propagate information across statements

Rules

  1. Cout(x, s) = # if Cin(x, s) = #
  2. Cout(x, x := c) = c if c is a constant
  3. Cout(x, x := (f...)) = *
  4. Cout(x, y := ...) = Cin(x, y := ...) if x ≠ y 20