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

Material Type: Project; Professor: Peisert; Class: Compilers; Subject: Engineering Computer Science; University: University of California - Davis; Term: Spring 2009;

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 09/17/2009

koofers-user-syv
koofers-user-syv 🇺🇸

5

(1)

10 documents

1 / 41

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29

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