Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 The System Dependence Graph and its use in Program Slicing.

Similar presentations


Presentation on theme: "1 The System Dependence Graph and its use in Program Slicing."— Presentation transcript:

1 1 The System Dependence Graph and its use in Program Slicing

2 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 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 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 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 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 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 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 ICFG 2.Propagate keeping call stack

9 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

10 10 System Dependence Graph (SDG) Enter main Call p Enter p

11 11 SDG for the Sum Program Enter main sum = 0i = 1 while(i < 11) printf(sum) printf(i) Call add x in = sum y in = i sum = x out x in = iy in = 1i = x out Enter add x = x in y = y in x = x + yx out = x

12 12 Slicing via Reachability Enter main sum = 0i = 1 while(i < 11) printf(sum) printf(i) Call add x in = sum y in = i sum = x out x in = iy in = 1i = x out Enter add x = x in y = y in x = x + yx out = x printf(i)

13 13 Slicing via Reachability Enter main sum = 0i = 1 while(i < 11) printf(sum) printf(i) Call add x in = sum y in = i sum = x out x in = iy in = 1i = x out Enter add x = x in y = y in x = x + yx out = x

14 14 Imprecision Enter main sum = 0i = 1 while(i < 11) printf(sum) printf(i) Call add x in = sum y in = i sum = x out x in = iy in = 1i = x out Enter add x = x in y = y in x = x + yx out = x

15 15 Precise Interprocedural Slicing Enter main sum = 0i = 1 while(i < 11) printf(sum) printf(i) Call add x in = sum y in = i sum = x out x in = iy in = 1i = x out Enter add x = x in y = y in x = x + yx out = x

16 16 Two-phase Reachability Slicing Algorithm To avoid the mismatches of procedure returns and procedure calls when traversing the graph Phase 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 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 18 SDG with Summary Edges Enter main sum = 0i = 1 while(i < 11) printf(sum) printf(i) Call add x in = sum y in = i sum = x out x in = iy in = 1i = x out Enter add x = x in y = y in x = x + yx out = x Add summary edges

19 19 Summary Edges Enter main Call p Enter p

20 20 SDG with Summary Edges Enter main sum = 0i = 1 while(i < 11) printf(sum) printf(i) Call add x in = sum y in = i sum = x out x in = iy in = 1i = x out Enter add x = x in y = y in x = x + yx out = x 2-phase slicing

21 21 Two-Phase Slicing: Phase I Enter main sum = 0i = 1 while(i < 11) printf(sum) printf(i) Call add x in = sum y in = i sum = x out x in = iy in = 1i = x out Enter add x = x in y = y in x = x + yx out = x

22 22 Two-Phase Slicing: Phase II Enter main sum = 0i = 1 while(i < 11) printf(sum) printf(i) Call add x in = sum y in = i sum = x out x in = iy in = 1i = x out Enter add x = x in y = y in x = x + yx out = x

23 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


Download ppt "1 The System Dependence Graph and its use in Program Slicing."

Similar presentations


Ads by Google