lecture2
lecture2
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
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.