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

Slides:



Advertisements
Similar presentations
Overview Structural Testing Introduction – General Concepts
Advertisements

A Survey of Program Slicing Techniques A Survey of Program Slicing Techniques Sections 3.1,3.6 Swathy Shankar
Semantics Static semantics Dynamic semantics attribute grammars
Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
P3 / 2004 Register Allocation. Kostis Sagonas 2 Spring 2004 Outline What is register allocation Webs Interference Graphs Graph coloring Spilling Live-Range.
Intermediate Code Generation
Lecture 11: Code Optimization CS 540 George Mason University.
SSA.
1 Introduction to Data Flow Analysis. 2 Data Flow Analysis Construct representations for the structure of flow-of-data of programs based on the structure.
SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
 Program Slicing Long Li. Program Slicing ? It is an important way to help developers and maintainers to understand and analyze the structure.
Program Slicing; Andreas Linder eXtreme Programming lab course 2004.
Graph Coverage for Design Elements 1.  Use of data abstraction and object oriented software has increased importance on modularity and reuse.  Therefore.
A survey of techniques for precise program slicing Komondoor V. Raghavan Indian Institute of Science, Bangalore.
Program Slicing. 2 CS510 S o f t w a r e E n g i n e e r i n g Outline What is slicing? Why use slicing? Static slicing of programs Dynamic Program Slicing.
Program Slicing Mark Weiser and Precise Dynamic Slicing Algorithms Xiangyu Zhang, Rajiv Gupta & Youtao Zhang Presented by Harini Ramaprasad.
1 Program Slicing Purvi Patel. 2 Contents Introduction What is program slicing? Principle of dependences Variants of program slicing Slicing classifications.
Introduction to Program Slicing Presenter: M. Amin Alipour Software Design Laboratory
The Application of Graph Criteria: Source Code  It is usually defined with the control flow graph (CFG)  Node coverage is used to execute every statement.
1 CS 201 Compiler Construction Lecture 7 Code Optimizations: Partial Redundancy Elimination.
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
CS 536 Spring Global Optimizations Lecture 23.
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
4/25/08Prof. Hilfinger CS164 Lecture 371 Global Optimization Lecture 37 (From notes by R. Bodik & G. Necula)
Program Slicing for Refactoring Advanced SW Tools Seminar Jan 2005Yossi Peery.
Semantic analysis Enforce context-dependent language rules that are not reflected in the BNF, e.g.a function must have a return statement. Decorate AST.
Data Flow Analysis Compiler Design October 5, 2004 These slides live on the Web. I obtained them from Jeff Foster and he said that he obtained.
Improving Code Generation Honors Compilers April 16 th 2002.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Loops Guo, Yao.
Machine-Independent Optimizations Ⅰ CS308 Compiler Theory1.
Data Flow Analysis Compiler Design Nov. 8, 2005.
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
Survey of program slicing techniques
Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
Chapter 4: A Universal Program 1. Coding programs Example : For our programs P we have variables that are arranged in a certain order: Y 1 X 1 Z 1 X 2.
Precision Going back to constant prop, in what cases would we lose precision?
1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Instructor Kostas Kontogiannis.
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
Semantic Analysis Legality checks –Check that program obey all rules of the language that are not described by a context-free grammar Disambiguation –Name.
Attribute Grammars Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 17.
Software (Program) Analysis. Automated Static Analysis Static analyzers are software tools for source text processing They parse the program text and.
1 Program Slicing Amir Saeidi PhD Student UTRECHT UNIVERSITY.
Compiler Principles Fall Compiler Principles Lecture 0: Local Optimizations Roman Manevich Ben-Gurion University.
Chapter 3 Part II Describing Syntax and Semantics.
1 The System Dependence Graph and its use in Program Slicing.
NP-Complete Problems. Running Time v.s. Input Size Concern with problems whose complexity may be described by exponential functions. Tractable problems.
1 Control Flow Analysis Topic today Representation and Analysis Paper (Sections 1, 2) For next class: Read Representation and Analysis Paper (Section 3)
Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin.
Graph Coverage for Design Elements 1.  Use of data abstraction and object oriented software has increased importance on modularity and reuse.  Therefore.
SOFTWARE TESTING. Introduction Software Testing is the process of executing a program or system with the intent of finding errors. It involves any activity.
Program Slicing Techniques CSE 6329 Spring 2013 Parikksit Bhisay
1 Software Testing & Quality Assurance Lecture 13 Created by: Paulo Alencar Modified by: Frank Xu.
Control Flow Graphs : The if Statement 1 if (x < y) { y = 0; x = x + 1; } else { x = y; } x >= yx < y x = y y = 0 x = x + 1 if (x < y) { y = 0;
1 Test Coverage Coverage can be based on: –source code –object code –model –control flow graph –(extended) finite state machines –data flow graph –requirements.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
PZ03CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03CX - Language semantics Programming Language Design.
Programming Language Concepts
Software Testing.
Control Flow Testing Handouts
Outline of the Chapter Basic Idea Outline of Control Flow Testing
A Survey of Program Slicing Techniques: Section 4
Program Slicing Baishakhi Ray University of Virginia
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Sudipto Ghosh CS 406 Fall 99 November 16, 1999
Control Flow Analysis (Chapter 7)
Data Flow Analysis Compiler Design
UNIT V Run Time Environments.
Taken largely from University of Delaware Compiler Notes
Software Testing and QA Theory and Practice (Chapter 5: Data Flow Testing) © Naik & Tripathy 1 Software Testing and Quality Assurance Theory and Practice.
Presentation transcript:

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

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

Introduction

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

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

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

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

Program Dependence Graphs and Program Slices

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

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)

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

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

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

Program Dependence Graph

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

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)}

Algorithm for Intraprocedural Slice using Program Dependence Graph

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)

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)

System Dependence Graph

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

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

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

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

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

Program and Procedure Dependence Graph

A problematic case causing redundant slice

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

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

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

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)

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”

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

System Dependence Graph

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

Interprocedural Slicing

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.

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

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

Algorithm for Interprocedural Slice G/S

System Dependence Graph

Slices from each phase Phase 1 Phase 2

Complete Slice

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.

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

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