Presentation is loading. Please wait.

Presentation is loading. Please wait.

Detecting Equality of Variables in Programs Bowen Alpern, Mark N. Wegman, F. Kenneth Zadeck Presented by: Abdulrahman Mahmoud.

Similar presentations


Presentation on theme: "Detecting Equality of Variables in Programs Bowen Alpern, Mark N. Wegman, F. Kenneth Zadeck Presented by: Abdulrahman Mahmoud."— Presentation transcript:

1 Detecting Equality of Variables in Programs Bowen Alpern, Mark N. Wegman, F. Kenneth Zadeck Presented by: Abdulrahman Mahmoud

2 Introduction Paper deals with detecting when two computations produce equivalent values Undecidable Present an optimistic, efficient algorithm that detects a large subclass of all the possible equivalences in a program

3 Equivalence Two variables are said to be equivalent at a point p if those variables contain the same values whenever control reaches p during any possible execution of the program.

4 Approach Difficult to find ALL possible executions of a program. Instead, they develop a static property called congruence, which implies equivalence. Their method is conservative: any variables detected to be equivalent will in fact be equivalent, but not all equivalences are detected

5 Technique Apply a technique called value numbering This is a symbolic execution method.

6 Previous Techniques Apply a technique called value numbering This is a symbolic execution method. B <- A + 3 C <- B * 5 D <- (A + 3) * 5

7 Technique Apply a technique called value numbering This is a symbolic execution method. B <- A + 3 C <- B * 5 D <- (A + 3) * 5 C and D have the same hash value.

8 Technique Apply a technique called value numbering This is a symbolic execution method. B <- A + 3 C <- B * 5 D <- (A * 5) + 15

9 Technique Apply a technique called value numbering This is a symbolic execution method. B <- A + 3 C <- B * 5 D <- (A * 5) + 15 C and D do NOT have the same hash value

10 Previous Techniques 2.0 Reif and Lewis [RL77] present a slightly complex algorithm, but even that cannot find the equivalence in the following sequence: if P then J <- 5; else J <- 6; if P then K <- 5; else K <- 6;

11 Proposed Method Define congruence An efficient algorithm for detecting equality in the presence of control structures (such as if-then-else) Optimistic: initially assume all values are equal and then separate them into more and more sets of possibly equal variables.

12 Uses of this Algorithm 1)Register Allocation 2)Common Sub-Expression Elimination 3)Movement of Invariant Code 4)Branch Elimination 5)Branch Fusion and Loop Jamming

13 Example IF Q then do I <- 5 J <- 5 END else do I <- 6 J <- 7 END

14 Example IF Q then do I <- 5 J <- 5 END else do I <- 6 J <- 7 END Are they equivalent?

15 Example IF Q then do I <- 5 J <- 5 END else do I <- 6 J <- 7 END Are they equivalent? Dynamically?

16 Example IF Q then do I <- 5 J <- 5 END else do I <- 6 J <- 7 END Are they equivalent? Dynamically? Depends on Q

17 Example IF Q then do I <- 5 J <- 5 END else do I <- 6 J <- 7 END Are they equivalent? Dynamically? Depends on Q Statically?

18 Example IF Q then do I <- 5 J <- 5 END else do I <- 6 J <- 7 END Are they equivalent? Dynamically? Depends on Q Statically? No.

19 Congruence A relationship between two variables without respect to location in the program. Thus, need to break up variables into multiple variables at different parts in the program (hint.. SSA)

20 High Level View of Algorithm 1)Build a control flow graph 2)Replace each variable in the original program with several new variables (static single assignment, or SSA) 3)Build auxiliary structure called a value graph that represents the symbolic execution of the program 4)Determine congruence of nodes in the value structure. Two variables will be equivalent at a point P if their assignments dominate P and are labeled congruent nodes.

21 1. Control Flow Graph

22 2. Translate to SSA form

23 3. Building a Value Graph It is a labeled, directed graph An edge is a connection between the use of a variable and the assignment at which the value of that variable is generated Each node corresponds to an individual function in the program Two types of Nodes: Executable Function Phi Function (join point)

24 3. Building a Value Graph

25 4. Congruence Two nodes in a graph are congruent if both of these conditions hold: 1) the nodes have identical function labels 2) the corresponding destinations of the edges leaving the nodes are congruent. Congruence is symmetric, reflexive, and transitive

26 4. Congruence In this example, the following are congruence classes: -(J1, K1, L1) -(J2, K2, L2) -(J3, K3) -(L3)

27 4. Congruence In this example, the following are congruence classes: -(J1, K1, L1) -(J2, K2, L2) -(J3, K3) -(L3) Anything interesting about these classes?

28 Loop example

29 Partitioning Algorithms

30 Partition nodes by label At each step, partitions are split (only split if need be) Needs split if two nodes in it point to nodes in separate partitions Splitting creates new partitions. Partitions are put on a queue to be examined. Complexity: O(ElogE)

31 Taking advantage of Control Structure High level control can provide even more information. Look into different control structures (IF-THEN-ELSE and LOOPS)

32 Conditional Statements

33 Conditional: Example

34 Loop

35 Loop Example

36 Simple Modifications Constant Propagation: can do more statically Symmetry: 33 + 17 is the same as 17 + 13


Download ppt "Detecting Equality of Variables in Programs Bowen Alpern, Mark N. Wegman, F. Kenneth Zadeck Presented by: Abdulrahman Mahmoud."

Similar presentations


Ads by Google