Presentation is loading. Please wait.

Presentation is loading. Please wait.

Recap from last time We saw various different issues related to program analysis and program transformations You were not expected to know all of these.

Similar presentations


Presentation on theme: "Recap from last time We saw various different issues related to program analysis and program transformations You were not expected to know all of these."— Presentation transcript:

1 Recap from last time We saw various different issues related to program analysis and program transformations You were not expected to know all of these things We will learn more about each one of the topics we touched upon last time

2 Program Analyzer Issues (discuss) Program Analyzer InputOutput

3 Input issues Input is a program, but… What language is the program written in? –imperative vs. functional vs. object-oriented? maybe even declarative? –what pointer model does the language use? –reflection, exceptions, continuations? –type system trusted or not? –one often analyzes an intermediate language... how does one design such a language? Instructor’s discussion notes Program Analyzer InputOutput

4 Input issues How much of the program do we see? –all? –one file at a time? –one library at a time? –reflection… Any additional inputs? –any human help? –profile info? Instructor’s discussion notes Program Analyzer InputOutput

5 Analysis issues Analysis/compilation model –Separate compilation/analysis quick, but no opportunities for interprocedural analysis –Link-time allows interprocedural and whole program analysis but what about shared precompiled libraries? and what about compile-time? –Run-time best optimization/analysis potential (can even use run-time state as additional information) can handle run-time extensions to the program but severe pressure to limit compilation time –Selective run-time compilation choose what part of compilation to delay until run-time can balance compile-time/benefit tradeoffs Instructor’s discussion notes Program Analyzer InputOutput

6 Analysis issues Does running-time matter? –for use in IDE? –or in overnight compile? Instructor’s discussion notes Program Analyzer InputOutput

7 Output issues Form of output varies widely, depending on analysis –alias information –constantness information –loop terminates/does not terminate Correctness of analysis results –depends on what the results are used for –are we attempting to design algorithsm for solving undecidable problems? –notion of approximation –statistical output Instructor’s discussion notes Program Analyzer InputOutput

8 Program Transformation Issues (discuss) Program Transformer InputOutput

9 Input issues A program, and … Program analysis results Profile info? Environment: # of CPUs, # of cores/CPU, cache size, etc. Anything else? Instructor’s discussion notes Program Transformer InputOutput

10 Transformation issues What is profitable? What order to perform transformations? What happens to the program representation? What happens to the computed information? For example alias information? Need to recompute? Instructor’s discussion notes Program Transformer InputOutput

11 Output issues Output in same IL as input? Should the output program behave the same way as the input program? Instructor’s discussion notes Program Transformer InputOutput

12 Tour of common optimizations

13 Simple example foo(z) { x := 3 + 6; y := x – 5 return z * y }

14 Simple example foo(z) { x := 3 + 6; y := x – 5 return z * y }

15 Another example x := a + b;... y := a + b;

16 Another example x := a + b;... y := a + b;

17 Another example if (...) { x := a + b; }... y := a + b;

18 Another example if (...) { x := a + b; }... y := a + b;

19 Another example x := y... z := z + x

20 Another example x := y... z := z + x

21 Another example x := y... z := z + y What if we run CSE now?

22 Another example x := y... z := z + y What if we run CSE now?

23 Another example x := y**z... x :=...

24 Another example Often used as a clean-up pass x := y**z... x :=... x := y z := z + x x := y z := z + y Copy propDAE x := y z := z + y

25 Another example if (false) {... }

26 Another example if (false) {... }

27 Another example In Java: a = new int [10]; for (index = 0; index < 10; index ++) { a[index] = 100; }

28 Another example In “lowered” Java: a = new int [10]; for (index = 0; index < 10; index ++) { if (index = a.length()) { throw OutOfBoundsException; } a[index] = 0; }

29 Another example In “lowered” Java: a = new int [10]; for (index = 0; index < 10; index ++) { if (index = a.length()) { throw OutOfBoundsException; } a[index] = 0; }

30 Another example p := &x; *p := 5 y := x + 1;

31 Another example p := &x; *p := 5 y := x + 1; x := 5; *p := 3 y := x + 1; ???

32 Another example for j := 1 to N for i := 1 to M a[i] := a[i] + b[j]

33 Another example for j := 1 to N for i := 1 to M a[i] := a[i] + b[j]

34 Another example area(h,w) { return h * w } h :=...; w := 4; a := area(h,w)

35 Another example area(h,w) { return h * w } h :=...; w := 4; a := area(h,w)

36 Optimization themes Don’t compute if you don’t have to –unused assignment elimination Compute at compile-time if possible –constant folding, loop unrolling, inlining Compute it as few times as possible –CSE, PRE, PDE, loop invariant code motion Compute it as cheaply as possible –strength reduction Enable other optimizations –constant and copy prop, pointer analysis Compute it with as little code space as possible –unreachable code elimination


Download ppt "Recap from last time We saw various different issues related to program analysis and program transformations You were not expected to know all of these."

Similar presentations


Ads by Google