Download presentation

Presentation is loading. Please wait.

Published byPolly Fleming Modified over 3 years ago

1
Interprocedural Slicing using Dependence Graphs Susan Horwitz, Thomas Reps, and David Binkley University of Wisconsin-Madison

2
Contents Introduction Program Dependence Graphs and Program Slice System Dependence Graph Interprocedural Slicing

3
Introduction

4
Program Slice Mark Weiser Slicing criterion – A pair – p is program point – V is subset of program’s variables Program slice – Consist of all statements and predicates of the program that might affect the values of variables in V at point p

5
Program Slice helps Understand complicated code Debugging Automatic parallelization Determine whether two different modifications to P interfere

6
Program Slice in this paper A slice taken with respect to a variable x that is defined or used at p – Rather than a slice taken with respect to program point p and an arbitrary variable (Weiser’s) Variable x defined at p – Affected by variables used at p and by the loops and conditionals that enclose p Variable y used at p – Affected by assignments to y that reach p and by the loops and conditionals that enclose p

7
Interprocedural Slicing Slicing in monolithic procedure – Program dependence graph – Vertex-reachability problem Interprocedural slicing – Slice crosses boundaries of procedure calls – System dependence graph

8
Program Dependence Graphs and Program Slices

9
Program Dependence Graph A restricted language – Scalar variable / Assignment statements – Conditional statements / While loops / End statement Vertex – Assignment statements and control predicates – Entry vertex – InitialState(x) : used before being defined – FinalUse(x) : an access to the final value of x Edge – Represent dependences among program components – Control dependence and flow dependence Multi-graph – may have more than one edge of a given kind between two vertices

10
Control dependence edge v 1 c v 2 Case 1 – v 1 : entry vertex – v 2 : component which is not nested within any loop Case 2 – v 1 : control predicate – v 2 : component immediately nested within the loop or conditional whose predicate is represented by v 1 – While loop : edge is labeled T (true) – Conditional statement : edge is labeled T (true) or F (false)

11
Data dependence edge A data dependence edge from vertex v 1 to vertex v 2 means that the programs computation might be changed if the relative order of the components represented by v 1 and v 2 were reversed. Two kinds of data dependence edges – Flow dependences – Def-order dependences Computed using data-flow analysis

12
Flow dependence edge v 1 f v 2 v 1 is a vertex that defines variable x … (1) v 2 is a vertex that uses x … (2) Control can reach v 2 after v 1 via an execution path along which there is no intervening definition of x … (3) Loop carried if in addition to (1),(2), and (3) above – There is an execution path that both satisfies the condition (3) above and includes a backedge to the predicate of loop L – Both v 1 and v 2 are enclosed in loop L Loop independent if in addition to (1),(2), and (3) above – There is an execution path that satisfies (3) above and includes no backedge to the predicate of a loop that encloses both v 1 and v 2

13
Def-order dependence edge v 1 do v 2 v 1 and v 2 both define the same variable v 1 and v 2 are in the same branch or any conditional statement that encloses both of them There exists a program component v 3 such that v 1 v 3 and v 2 v 3 v 1 occurs to the left of v 2 in the program’s abstract syntax tree

14
Program Dependence Graph

15
Computing Slice using PDG For vertex S of the Program Dependence Graphs G of a program P, the slice of G with respect to S is a graph (denoted as G/S) containing all vertices of which S has a transitive flow or control dependence (i.e. all vertices that can reach S via flow or control edges) The edges in the slice graph G/S are data dependence (loop independent), control dependence, and def-order edges of the original graph G that have source and targets in vertices in G/S

16
Computing Slice using PDG Therefore the vertices of a slice G/S are: V(G/S) = {w | w in V(G) and w c,f * S} We can extend the definition to a slice with respect to a set of vertices S = U i S i V(G/S) = V(G/ U i S i ) = U i (V(G/S i )) The edges in a slice are: E(G/S) = {u f w | u w in E(G) and u, w in V(G/S)} U {u c w | u w in E(G) and u, w in V(G/S)} U {u do w | u w in E(G) and u, w in V(G/S)}

17
Algorithm for Intraprocedural Slice using Program Dependence Graph

18
T T T T T T T ENTRY sum := 0 i := 1 while i < 11 FinalUse(i) FinalUse(sum) sum:=sum+i i := i +1 Slicing on FinalUse(i)

19
T T T T ENTRY i := 1 while i < 11 FinalUse(i) i := i +1 program Main sum := 0; i := 1; while i < 11 do sum := sum +i; i := i+1 od End(sum,i) program Main i := 1; while i < 11 do i := i+1; od End(i) Slice on FinalUse(i) Slicing on FinalUse(i)

20
System Dependence Graph

21
Language Properties A complete system consists of a single (main) program and a collection of auxiliary procedures Procedures end with return statements instead of end statements. A return statement does not include a list of variables Parameters are passed by value-result Assumptions – No call sites of the form P(x,x) or of the form P(g), where g is a global variable

22
System Dependence Graph Program dependence graph – Represents the system’s main program Procedure dependence graphs – Represent the system’s auxiliary procedures Some additional edges. – Edges that represent direct dependence between a call site and the called procedure – Edges that represent transitive dependences due to calls

23
Five new vertices for SDG Call-site vertex Actual-in – Control dependent on call-site vertex – Copy values of actual parameters to call temporaries Actual-out – Control dependent on call-site vertex – Copy from return temporaries Formal-in – Control dependent on procedure’s entry vertex – Copy value of formal parameters from call temporaries Formal-out – Control dependent on procedure’s entry vertex – Copy to return temporaries

24
Three new edges for SDG Call edge – Call-site Procedure-entry – From each call-site vertex to the corresponding procedure-entry vertex Parameter-in edge – Actual-in Formal-in – From each actual-in vertex at a call site to the corresponding formal-in vertex in the called procedure Parameter-out edge – Formal-out Actual-out – From each formal-out vertex in the called procedure to the corresponding actual-out vertex at the call site

25
System dependence graph Flow dependences – Computed in the usual way, using data flow analysis on the procedure’s control-flow graph Procedure’s control-flow graph – Starts with a sequence of assignments that copy values from call temporaries to formal parameters – Ends with a sequence of assignments that copy values from formal parameters to return temporaries Each call statement within the procedure – Represented in the procedure’s control-flow graph by a sequence of assignments that copy values from actual parameters to call temporaries – Followed by a sequence of assignments that copy values from return temporaries to actual parameters

26
Program and Procedure Dependence Graph

27
A problematic case causing redundant slice

28
Transitive dependence Solution to Redundant Slice Problem – Add an additional kind of edge to the system dependence graph to represent transitive dependences due to the effects of procedure calls Additional Information required – Linkage Grammar – Attribute Equations

29
Linkage Grammar Context-free part of linkage grammar models the system’s procedure-call structure Grammar includes one nonterminal and one production for each procedure in the system If procedure P contains no calls, the right-hand side of the production for P is ε; other wise there is one right-hand-side nonterminal for each call site in P. Example Main A A Add Increment Add ε Increment Add

30
Attributes of Linkage Grammar Nonterminal’s inherited attributes are placed to its left Synthesized attributes are placed to its right

31
Attribute Equations For each attribute occurrence X.a of a production p, let v be the vertex of the procedure dependence graph G p that corresponds to X.a. Associate with p an attribute equation of the form X.a = f(..,Y.b,..) where the arguments Y.b to the equation consist of the attribute occurrences of p that correspond to the parameter vertices in G p /v Example: A.x_in = f1(A.x_out, A.y_out) A.y_in = f2(A.y_out) A.x_out = f3(A.y_out) A.y_out = f4(A.y_out)

32
Attribute Dependences A.x_in = f1(A.x_out, A.y_out) – Main: “sum := x_out” Main: “x_in := sum” – Main: “i := y_out” Main: “while i < 11” Main: “call A” Main: “x_in := sum” A.y_out = f4(A.y_out) – Main: “i := y_out” Main: “while i < 11” Main: “call A” Main: “i := y_out”

33
Transitive Dependences between Input and Output of Procedure Called “Subordinate Characteristic Graph”

34
System Dependence Graph

35
Recap of Constructing SDG 1)For each procedure of the system, contruct its procedure dependence graph 2)For all call site, introduce a call edge from the call-site vertex to the corresponding procedure-entry vertex 3)For each actual-in vertex v at a call site, introduce a parameter-in edge from v to the corresponding formal-in vertex in the called procedure 4)For each actual-out vertex v at a call site, introduce a parameter-out edge to v from the corresponding formal-out vertex in the called procedure 5)Construct the linkage grammar corresponding to the system 6)Compute the subordinate characteristic graphs of the linkage grammar’s nonterminals 7)At all call sites that call procedure P, introduce flow dependence edges corresponding to the edges in the subordinate characteristic graph for P

36
Interprocedural Slicing

37
Difficulty is keeping track of calling context when a slice descends into a called procedure Key element is the use of the linkage grammar’s characteristic graph edges in the system dependence graph These edges represent transitive data dependences from actual-in vertices to actual-out vertices due to procedure call The presence of such edges permits us to sidestep the “calling context” problem; the slicing operation can move “across” a call without having to descend into it.

38
Two Phase The traversal in Phase 1 follows: – Flow edges – Control edges – Call edges – Parameter-in edges – Not def-order or parameter-out edges The traversal in Phase 2 follows: – Flow edges – Control edges – Parameter-out edges – Not def-order, call, parameter-in edges

39
Characteristics of Phase 1 and 2 Phase 1 – Identifies vertices that can reach s, and are either in P itself or in a procedure that calls P (either directly or transitively) – Traversal does not “descend” into procedures called by P – The presence of transitive flow dependence edges from actual-in to actual-out vertices permits the discovery of vertices that can reach s only through a procedure call Phase 2 – Identifies vertices that can reach s from procedures (transitively) called by P or from procedures called by procedures that (transitively) call P – Traversal does not “ascend” into calling procedures; the transitive flow dependence edges from actual-in to actual-out vertices make such “ascents” unnecessary

40
Algorithm for Interprocedural Slice G/S

41
System Dependence Graph

42
Slices from each phase Phase 1 Phase 2

43
Complete Slice

44
Improving precision with GMOD and GREF Because parameter b is not in GMOD(Add), Add’s procedure dependence graph should not include a formal-out vertex for b, and the call to Add from A should not include the corresponding actual-out vertex.

45
Slicing incomplete system dependence graph Incomplete Procedure Information – Libraries – Programs under development Missing called procedures information – Subordinate Characteristic Graphs Missing calling context – Superior Characteristic Graphs

46
Forward slicing Forward slice of a program with respect to a program point p and variable x consists of all statements and predicates of the program that might be affected by the value of x at point p The same concept can be employed for (backward) interprocedural slicing

Similar presentations

OK

4/25/08Prof. Hilfinger CS164 Lecture 371 Global Optimization Lecture 37 (From notes by R. Bodik & G. Necula)

4/25/08Prof. Hilfinger CS164 Lecture 371 Global Optimization Lecture 37 (From notes by R. Bodik & G. Necula)

© 2018 SlidePlayer.com Inc.

All rights reserved.

To ensure the functioning of the site, we use **cookies**. We share information about your activities on the site with our partners and Google partners: social networks and companies engaged in advertising and web analytics. For more information, see the Privacy Policy and Google Privacy & Terms.
Your consent to our cookies if you continue to use this website.

Ads by Google

Ppt on fiscal policy in india 2010 Ppt on social networking sites advantages and disadvantages Ppt on polynomials in maths games Ppt on dos operating system Ppt on diode transistor logic Ppt on stock market indices Ppt on endangered species of animals Ppt on business cycle theories Ppt on regular expression validator Ppt on product specification form