View
228
Download
1
Category
Preview:
Citation preview
2
int main() {int sum = 0;int i = 1;while (i < 11) {
sum = add(sum,i);i = add(i,1);
}printf(“%d\n”,sum);printf(“%d\n”,i);
}
int add(int x, int y) {return x + y;
}
Slicing Multiple Procedures
3
int main() {int sum = 0;int i = 1;while (i < 11) {
sum = add(sum,i);i = add(i,1);
}printf(“%d\n”,sum);printf(“%d\n”,i);
}
int add(int x, int y) {return x + y;
}
Slicing Multiple Procedures
What is the slice for i at this statement?
4
int main() {int sum = 0;int i = 1;while (i < 11) {
sum = add(sum,i);i = add(i,1);
}printf(“%d\n”,sum);printf(“%d\n”,i);
}
int add(int x, int y) {return x + y;
}
Slicing Multiple Procedures
5
x = 3
p(x)
print(x)
start main
If …
q(a)
print(a)
start p(a)
a =2
Interprocedural Analysis and the Calling Context Problem
If …
print(d)
start q(d))
exit
x = 5
q(x)
exit
print(x)
exit
6
Some Solutions
1. In-line called procedures
2. Keep call stack
3. Interval-type analysis (won’t discuss)
4. System dependence graph traversal
7
x = 3
p(x)
print(x)
start main
If …
q(a)
print(a)
start p(a)
a =2
In-Line Called Procedures
If …
print(d)
start q(d))
exit
x = 5
q(x)
exit
print(x)
exit
8
x = 3
p(x)
print(x)
start main
If …
q(a)
print(a)
start p(a)
a =2
Keep Call Stack
If …
print(d)
start q(d))
exit
x = 5
q(x)
exit
print(x)
exit
1. Get ICFG2. Propagate
keeping call stack
9
• Based on PDGs• Each PDG has nodes for
– entry point– procedure parameters and function result
• Each call site has nodes for– call– arguments and function result
• Appropriate edges– entry node to parameters (control-dependence)– call node to arguments (control-dependence)– call node to entry node (call relation)– arguments to parameters (data-dependence)
System Dependence Graph (SDG) Approach
11
SDG for the Sum ProgramEnter main
sum = 0 i = 1 while(i < 11) printf(sum) printf(i)
Call add Call add
xin = sum yin = i sum = xout xin = i yin= 1 i = xout
Enter add
x = xin y = yin x = x + y xout = x
12
Slicing via ReachabilityEnter main
sum = 0 i = 1 while(i < 11) printf(sum) printf(i)
Call add Call add
xin = sum yin = i sum = xout xin = i yin= 1 i = xout
Enter add
x = xin y = yin x = x + y xout = x
printf(i)
13
Slicing via ReachabilityEnter main
sum = 0 i = 1 while(i < 11) printf(sum) printf(i)
Call add Call add
xin = sum yin = i sum = xout xin = i yin= 1 i = xout
Enter add
x = xin y = yin x = x + y xout = x
14
ImprecisionEnter main
sum = 0 i = 1 while(i < 11) printf(sum) printf(i)
Call add Call add
xin = sum yin = i sum = xout xin = i yin= 1 i = xout
Enter add
x = xin y = yin x = x + y xout = x
15
Precise Interprocedural SlicingEnter main
sum = 0 i = 1 while(i < 11) printf(sum) printf(i)
Call add Call add
xin = sum yin = i sum = xout xin = i yin= 1 i = xout
Enter add
x = xin y = yin x = x + y xout = x
16
Two-phase Reachability Slicing Algorithm
To avoid the mismatches of procedure returns and procedure calls when traversing the graphPhase I: find the statements in the current procedure
and the callers of the current procedure that may affect the slicing criterion Do not traverse return edges Use summary information to continue the slicing at each
callsite
Phase II: Find the statements in the callees of the current procedure that may affect the slicing criterion Do not traverse call edges
17
Add Flow Dependence (Summary, Transitive Dependence) Edges
For each actual-out parameter in the SDG, determine whether that parameter is dependent (data or control) on any actual-in parameters.
Could use the linkage grammar, a slice down into called procedures, or the graph reachability method presented in FSE95.
If a dependence exists, introduce flow dependence edges to the SDG.
18
SDG with Summary EdgesEnter main
sum = 0 i = 1 while(i < 11) printf(sum) printf(i)
Call add Call add
xin = sum yin = i sum = xout xin = i yin= 1 i = xout
Enter add
x = xin y = yin x = x + y xout = x
Add summary edges
20
SDG with Summary EdgesEnter main
sum = 0 i = 1 while(i < 11) printf(sum) printf(i)
Call add Call add
xin = sum yin = i sum = xout xin = i yin= 1 i = xout
Enter add
x = xin y = yin x = x + y xout = x
2-phase slicing
21
Two-Phase Slicing: Phase IEnter main
sum = 0 i = 1 while(i < 11) printf(sum) printf(i)
Call add Call add
xin = sum yin = i sum = xout xin = i yin= 1 i = xout
Enter add
x = xin y = yin x = x + y xout = x
22
Two-Phase Slicing: Phase IIEnter main
sum = 0 i = 1 while(i < 11) printf(sum) printf(i)
Call add Call add
xin = sum yin = i sum = xout xin = i yin= 1 i = xout
Enter add
x = xin y = yin x = x + y xout = x
23
Iterative Computation of Summary Edges
Step 1: compute the reachability from formal-in nodes to formal-out nodes in each procedure
Step 2: create the summary edges in each caller according to the reachability from formal-in nodes to formal-out nodes in a procedure
Step 3: update the reachability from fromal-in nodes to formal-out nodes of each caller
Step 4: if Step 3 produces new results, go to step 2
Recommended