Presentation is loading. Please wait.

Presentation is loading. Please wait.

Interprocedural Analysis Chapter 19

Similar presentations


Presentation on theme: "Interprocedural Analysis Chapter 19"— Presentation transcript:

1 Interprocedural Analysis Chapter 19
Mooly Sagiv

2 Outline Modularity Issues Interprocedural Optimizations Challenges
The Call Graph Flow insensitive information Flow sensitive information Conclusions

3 Modularity Issues Procedures provide a mechanism for modularity
Procedure bodies become smaller Machines becomes stronger Often procedures implement general algorithms How to achieve performance of single procedure in a complex software? Two solutions: procedure integration/inline/tail call elimination interprocedural analysis

4 Interprocedural Optimizations
Can be used for procedure integration Constant propagation can be used to optimize procedure bodies Constant propagation can be used to “clone” procedures Call-by-value parameters can be passed by reference (if they don’t change) Register allocation Improve intraprocedural information

5 char * Red = “red”; char * Yellow = “yellow”; char * Orange = “orange”; char * color(FRUIT CurrentFruit); { switch (currentFruit->variety) { case APPLE: return Red; break; case BANANA: return Yellow; case ORANGE: return Orange; }} main() { FRUIT snack; snack.variety = APPLE; snack.shape = ROUND; printf(“%s\n”, color(&snack));} char * Red = “red”; char * Yellow = “yellow”; char * Orange = “orange”; main() { FRUIT snack; VARIETY t1; SHAPE t2; COLOR t3; t1 = APPLE; t2 = ROUND; switch (t1) { case APPLE: t3= Red; break; case BANANA: t3=Yellow; case ORANGE: t3=Orange; }} printf(“%s\n”, t3);}

6 Pascal Example with value parameters
type vector = array[1…1000] of integer procedure p(v: vector); procedure q; var a: vector; p(a);

7 C Example For Constant Propagation
int g; p() { } q(){ g=100; p(); y = g;

8 Challenges in Interprocedral Analysis
Handling recursion Parameter passing mechanisms Virtual methods/function pointers/procedural parameters/higher order functions Scalability Supporting separate compilation mode

9 The Call Graph A finite directed multi-graph A node per procedure
A labeled edge per call site Can be constructed incrementaly to support separate compilation mode Difficult to construct in the presence of virtual functions/function pointers

10 Example for Call Graph Construction
1: void f() { 2: g(); 3: g(); 4: h();} 5: void g() { 6: h(); 7: i(); } 8: void h() {} 9: void i() { 10: g() ;}

11 Obstacles Procedural parameters (P-SPACE hard) Higher order functions
Virtual methods Solutions Conservative approximation Data-Flow information Specialization

12 Flow insensitive side effect analysis
Ignore control flow Compute for every call site: MOD - the variables that may be modified DEF - the variables must be defined USE - the set of variables that may be used before set Can be computed efficiently for programs with small number of parameters (Cooper & Kennedy) Can be used for: program understanding replacing value by reference parameter improving intraprocedural information Becomes tricky with nesting and aliases

13 program test; var a. b: integer; procedure g(var f1: integer) begin 1: f1 := f1 + 1; end procedure f(var f2, f3: integer) 2: g(f2); 3: f3 := f2 ; 4: g(f3); begin (* main) 5: a := 5; 6: f(a, b); end.

14 program test; var a. b: integer; procedure g(var f1: integer) begin 1: f1 := f1 + 1; end procedure f(var f2, f3: integer) 2: g(f2); 3: f3 := f2 ; 4: g(f3); begin (* main) 5: a := 5; 6: f(a, b); end.

15 Flow Sensitive Data-Flow Information
Integrate control flow graph and call graph (the program super-graph) In the presence of reference parameters even bit vector problems are hard Two main solutions: call strings functional Scaling is an issue

16 Non trivial constants int x void p(int a) { int c; scanf(“%\d”, &c);
if (c > 0) { a = a -2; p(a); a := a +2; } x := -2 * a + 5 printf(“%s\n”, x);} void main() { p(7); printf(“%s\n”, x) ; }

17 Conclusions Interprocedural analysis will be integrated into compilers
Can be implemented at link time Will lead to simpler programming Flow insensitive analysis scales But what about flow sensitive?


Download ppt "Interprocedural Analysis Chapter 19"

Similar presentations


Ads by Google