Docsity

Program Analysis - Advanced Topics in Computer Graphics - Slides | CMPS 290, Study notes of Computer Graphics

Partial preview of the text

Download Program Analysis - Advanced Topics in Computer Graphics - Slides | CMPS 290 and more Study notes Computer Graphics in PDF only on Docsity!

Program Analysis

6 Jan 2004

290G - Lecture 1a

What is Program Analysis For?

6 Jan 2004

290G - Lecture 1a

  • Historically: Optimizing compilers • More recently:
    • Finding bugs

Dataflow Analysis

Part 1

6 Jan 2004

290G - Lecture 1a

Control-Flow Graphs

6 Jan 2004

290G - Lecture 1a

x := a + b; y := a * b; while y > a + b {

a := a + 1;^ x := a + b

}

if y > a + b a := a + 1 x := a + b x := a + b y := a * b

Available Expressions

6 Jan 2004

290G - Lecture 1a

For each program pointp, which expressionsmust have already beencomputed, and not latermodified, on all paths top.

if y > a + b a := a + 1 x := a + b x := a + b y := a * b

a+b isavailablehere

Optimization: Whereavailable, expressionsneed not berecomputed.

Dataflow Equations

6 Jan 2004

290G - Lecture 1a

8 / 39

(

)

if

otherwise

|if

in

out

s

pred

s

out

in

p

red s

A

s

A

s

A

s

A

s

a

S

write s

V

a

s

write s

read s

′∈

I

Liveness Analysis

6 Jan 2004

290G - Lecture 1a

For each program pointp, which of thevariables defined atthat point are used onsome execution path?

if y > a + b a := a + 1 x := a + b x := a + b y := a * b

x is notlive here

Optimization: If avariable is not live, noneed to keep it in aregister.

Dataflow Equations

6 Jan 2004

290G - Lecture 1a

11 / 39

(

)

(

)

(

(

)

(

))

(

)

if

(

)

(

)

(

)

otherwise

out

in out

in

s

succ s

L

s

L

s

write s

read s

succ s

L

s

L

s

′∈

=

−

∪

∅

= ∅

⎧

⎫

⎪

⎪

= ⎨

⎬

′

⎪

⎪

⎩

⎭

U

Available Expressions Again

6 Jan 2004

290G - Lecture 1a

13 / 39

(

)

if

otherwise

in

out

s

pred

s

out

in

p

red s

A

s

A

s

A

s

A

s

a

S

write s

V

a

s

write s

read s

′∈

I

Available Expressions: Schematic

6 Jan 2004

290G - Lecture 1a

(

)

1

2

out

in

s

pred

s

out

in

A

s

A

s

A

s

A

s

C

C

′∈

I

Transfer function:

Must analysis: property holds on all paths Forwards analysis: from inputs to outputs

Live Variables: Schematic

6 Jan 2004

290G - Lecture 1a

1

2

(

)

(

)

(

)

(

)

(

)

out

in out

in

s

succ s

L

s

L

s

C

C

L

s

L

s

′∈

=

−

∪

′

=

U

Transfer function:

May analysis: property holds on some path Backwards analysis: from outputs to inputs

Very Busy Expressions

6 Jan 2004

290G - Lecture 1a

  • An expression

e is very busy at program point

p if every path from p must evaluate e beforeany variable in e is redefined

  • Optimization: hoisting expressions • A must-analysis • A backwards analysis

One Cut at the Dataflow Design Space

6 Jan 2004

290G - Lecture 1a

May

Must

Forwards

Reachingdefinitions

Availableexpressions

Backwards

Live variables

Very busyexpressions

The Literature

6 Jan 2004

290G - Lecture 1a

  • Vast literature of dataflow analyses • 90+% can be described by
    • Forwards or backwards – May or must
      • Some oddballs, but not many
        • Bidirectional analyses