0% found this document useful (0 votes)
11 views

lecture2

Interprocedural analysis is necessary to accurately understand variable usage and parameter values across different procedures in a program, despite being slower than intraprocedural analysis. The document discusses the construction of call graphs, the distinction between context-sensitive and context-insensitive analyses, and the algorithms for interprocedural constant propagation. It also covers the precision of analysis and the concepts of jump and return-jump functions in relation to parameter values and return values in procedures.

Uploaded by

Naruto Hinata
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

lecture2

Interprocedural analysis is necessary to accurately understand variable usage and parameter values across different procedures in a program, despite being slower than intraprocedural analysis. The document discusses the construction of call graphs, the distinction between context-sensitive and context-insensitive analyses, and the algorithms for interprocedural constant propagation. It also covers the precision of analysis and the concepts of jump and return-jump functions in relation to parameter values and return values in procedures.

Uploaded by

Naruto Hinata
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Interprocedural Analysis

• Why do we need this?


• We must conservatively assume that:
1. a callee may use or change any variable it might be able to access,
2. a caller can provide arbitrary values as parameters
• Intraprocedural analysis is fast, but the results are imprecise and
conservative.
• Is procedure inlining always possible?
• Virtual calls make it not possible
• It also increases the memory footprint
Interprocedural Control-flow Analysis
• Deals with construction of program’s call graph
• Given a program P with procedures p1, p2,..pn, call graph G = ⟨N,S,E,r⟩
• N is {p1, p2,..pn}
• S is set of call-site labels
• r is entry node
• E ⊆ N × S × N: An edge from (pi, sk, pj) represents a call from pi to pj at
site sk.
Call graph
Construction
Algorithm

Iterate over call sites


and add edges
Call Graph Construction with Function Pointers
int (*fp)

int f1(int x) {
if(x == 0) return x; s3
Main f2
return (*fp)(x-1); // s1
}
s2
int f2(int y) {
fp = &f1; f1
return (*fp)(y); //s2
}
s1
void main(){
fp = &f2;
(*fp)(10); //s3
}
Context Sensitive vs. Context Insensitive
• Example: Interprocedural Constant Propagation
• Context Insensitive:
• Does not distinguish between different call sites (call site independent)
• For each procedure in a program, identifies subset of its parameter such that
each parameter has the same constant value in every invocation.
• Context Sensitive:
• Distinguishes between different call sites (call site dependent)
• For each particular procedure called from each particular call site, the subset of
parameters have the same constant values each time the procedure is called.
Interprocedural Constant Propagation
• Outline:
• The constant value of each formal argument is initialized to ⊤.
• Compute the actuals of a call site s using the formals of a procedure p
• Compute the meet of the current values for the formals of callee q
and the actuals at s
• Add q to the worklist if its constant values changed in the previous
step
Jump Function

• A function that does all the computation required to compute the


actual arguments to the callee in terms of the formal arguments of
the caller.

• Jump function: J(p,i,L,x)


• i - call site
• p - caller procedure
• L - formal arguments of caller
• x - a formal parameter of the callee.
Example
Algorithm

Initialize constant values


for parameters

Initialize actual
arguments at call sites
Algorithm Take meet of the
evaluated value and the
previous value of
parameter of a callee.
Precision of the Analysis
• The precision of the constant propagation will depend on the
precision of J and Eval
• Examples:
• Literal constant: If the argument passed is a constant, then a
constant, else ⊥
• Pass-through parameter: If a formal parameter is directly passed or
a constant, then pass the constant value, else ⊥
• Constant if intra-procedural constant.
• Do a full-fledged analysis to determine its value.
Return-jump function
• Return-jump function: R(p, L)
• p – procedure
• L - formal parameters
• Maps the formal parameters to the return value of the function.
• If the language admits call-by references:
R(p, L, x), where x - a formal parameter of the callee.
Maps the value returned by the formal parameter x.

v = compute the meet of all the return values of p;


Set the return value of p to v;
foreach call function q that calls p do
add q to the worklist
Algorithm Take meet of the
evaluated value and the
previous value of
parameter of a callee.

v = compute the meet of all the return values of p;


Set the return value of p to v;
foreach call function q that calls p do
add q to the worklist

You might also like