Title: Interprocedural%20Analysis%20Chapter%2019
1Interprocedural Analysis Chapter 19
2Outline
- Modularity Issues
- Interprocedural Optimizations
- Challenges
- The Call Graph
- Flow insensitive information
- Flow sensitive information
- Conclusions
3Modularity 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
4Interprocedural 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 dont change) - Register allocation
- Improve intraprocedural information
5 char Red red char Yellow
yellow char Orange orange char
color(FRUIT CurrentFruit) switch
(currentFruit-gtvariety) case
APPLE return Red
break case BANANA
return Yellow
break 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 t3Yellow
break case
ORANGE t3Orange printf(s\n, t3)
6Pascal Examplewith value parameters
type vector array11000 of integer procedure
p(v vector) procedure q var a vector p(a)
7C Example For Constant Propagation
int g p() q() g100 p() y g
8Challenges in Interprocedral Analysis
- Handling recursion
- Parameter passing mechanisms
- Virtual methods/function pointers/procedural
parameters/higher order functions - Scalability
- Supporting separate compilation mode
9The 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
10Example 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()
11Obstacles
- Procedural parameters (P-SPACE hard)
- Higher order functions
- Virtual methods
- Solutions
- Conservative approximation
- Data-Flow information
- Specialization
12Flow 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
13program test var a. b integer procedure g(var
f1 integer) begin 1 f1 f1
1 end procedure f(var f2, f3 integer) begin 2
g(f2) 3 f3 f2 4
g(f3) end begin ( main) 5 a 5 6
f(a, b) end.
14program test var a. b integer procedure g(var
f1 integer) begin 1 f1 f1
1 end procedure f(var f2, f3 integer) begin 2
g(f2) 3 f3 f2 4
g(f3) end begin ( main) 5 a 5 6
f(a, b) end.
15Flow 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
16Non trivial constants
int x void p(int a) int c scanf(\d,
c) if (c gt 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)
17Conclusions
- 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?