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

Slides:



Advertisements
Similar presentations
Example of Constructing the DAG (1)t 1 := 4 * iStep (1):create node 4 and i 0 Step (2):create node Step (3):attach identifier t 1 (2)t 2 := a[t 1 ]Step.
Advertisements

SSA and CPS CS153: Compilers Greg Morrisett. Monadic Form vs CFGs Consider CFG available exp. analysis: statement gen's kill's x:=v 1 p v 2 x:=v 1 p v.
Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
8. Static Single Assignment Form Marcus Denker. © Marcus Denker SSA Roadmap  Static Single Assignment Form (SSA)  Converting to SSA Form  Examples.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) SSA Guo, Yao.
P3 / 2004 Register Allocation. Kostis Sagonas 2 Spring 2004 Outline What is register allocation Webs Interference Graphs Graph coloring Spilling Live-Range.
1 Authors: Vugranam C. Sreedhar, Roy Dz-Ching Ju, David M. Gilles and Vatsa Santhanam Reader: Pushpinder Kaur Chouhan Translating Out of Static Single.
Chapter 9 Code optimization Section 0 overview 1.Position of code optimizer 2.Purpose of code optimizer to get better efficiency –Run faster –Take less.
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
Context-Sensitive Interprocedural Points-to Analysis in the Presence of Function Pointers Presentation by Patrick Kaleem Justin.
1 Chapter 8: Code Generation. 2 Generating Instructions from Three-address Code Example: D = (A*B)+C =* A B T1 =+ T1 C T2 = T2 D.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
SSA.
Static Single Assignment CS 540. Spring Efficient Representations for Reachability Efficiency is measured in terms of the size of the representation.
Some Properties of SSA Mooly Sagiv. Outline Why is it called Static Single Assignment form What does it buy us? How much does it cost us? Open questions.
Stanford University CS243 Winter 2006 Wei Li 1 Register Allocation.
Chapter 10 Code Optimization. A main goal is to achieve a better performance Front End Code Gen Intermediate Code source Code target Code user Machine-
Register Allocation CS 671 March 27, CS 671 – Spring Register Allocation - Motivation Consider adding two numbers together: Advantages: Fewer.
1.6 Behavioral Equivalence. 2 Two very important concepts in the study and analysis of programs –Equivalence between programs –Congruence between statements.
Introduction to Graph “theory”
Stanford University CS243 Winter 2006 Wei Li 1 SSA.
Preliminary Transformations Chapter 4 of Allen and Kennedy Harel Paz.
1 CS 201 Compiler Construction Lecture 7 Code Optimizations: Partial Redundancy Elimination.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Partial Redundancy Elimination Guo, Yao.
Example in SSA X := Y op Z in out F X := Y op Z (in) = in [ { X ! Y op Z } X :=  (Y,Z) in 0 out F X :=   (in 0, in 1 ) = (in 0 Å in 1 ) [ { X ! E |
6/9/2015© Hal Perkins & UW CSEU-1 CSE P 501 – Compilers SSA Hal Perkins Winter 2008.
Early Global Program Optimizations Chapter Mooly Sagiv.
Recap from last time We were trying to do Common Subexpression Elimination Compute expressions that are available at each program point.
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
1 Intermediate representation Goals: –encode knowledge about the program –facilitate analysis –facilitate retargeting –facilitate optimization scanning.
Global optimization. Data flow analysis To generate better code, need to examine definitions and uses of variables beyond basic blocks. With use- definition.
4/25/08Prof. Hilfinger CS164 Lecture 371 Global Optimization Lecture 37 (From notes by R. Bodik & G. Necula)
1 Intermediate representation Goals: encode knowledge about the program facilitate analysis facilitate retargeting facilitate optimization scanning parsing.
Code Generation for Basic Blocks Introduction Mooly Sagiv html:// Chapter
CS 201 Compiler Construction
CMPUT Compiler Design and Optimization1 CMPUT680 - Winter 2006 Topic H: SSA for Predicated Code José Nelson Amaral
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
Improving Code Generation Honors Compilers April 16 th 2002.
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
Compiler Construction A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University Second Semester 2008/2009.
Machine-Independent Optimizations Ⅰ CS308 Compiler Theory1.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
Global optimization. Data flow analysis To generate better code, need to examine definitions and uses of variables beyond basic blocks. With use- definition.
Data Flow Analysis Compiler Design Nov. 8, 2005.
PSUCS322 HM 1 Languages and Compiler Design II IR Code Optimization Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU.
Eliminating Memory References Joshua Dunfield Alina Oprea.
Topic #10: Optimization EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 20 Slide 1 Defect testing l Testing programs to establish the presence of system defects.
Static Program Analyses of DSP Software Systems Ramakrishnan Venkitaraman and Gopal Gupta.
1 June 4, June 4, 2016June 4, 2016June 4, 2016 Azusa, CA Sheldon X. Liang Ph. D. Azusa Pacific University, Azusa, CA 91702, Tel: (800)
Compiler Principles Fall Compiler Principles Lecture 0: Local Optimizations Roman Manevich Ben-Gurion University.
1 Data Flow Analysis Data flow analysis is used to collect information about the flow of data values across basic blocks. Dominator analysis collected.
CS412/413 Introduction to Compilers Radu Rugina Lecture 18: Control Flow Graphs 29 Feb 02.
1 Control Flow Graphs. 2 Optimizations Code transformations to improve program –Mainly: improve execution time –Also: reduce program size Can be done.
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
©SoftMoore ConsultingSlide 1 Code Optimization. ©SoftMoore ConsultingSlide 2 Code Optimization Code generation techniques and transformations that result.
Credible Compilation With Pointers Martin Rinard and Darko Marinov Laboratory for Computer Science Massachusetts Institute of Technology.
Code Optimization.
Static Single Assignment
Optimization Code Optimization ©SoftMoore Consulting.
SSA in Scheme Static single assignment (SSA) :
Finding Global Redundancies with Hopcroft’s DFA Minimization Algorithm
Securing A Compiler Transformation
Topic 10: Dataflow Analysis
CS 201 Compiler Construction
Code Optimization Overview and Examples Control Flow Graph
Interval Partitioning of a Flow Graph
8 Code Generation Topics A simple code generator algorithm
The Partitioning Algorithm for Detecting Congruent Expressions COMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper.
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
Presentation transcript:

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

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

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.

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

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

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

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.

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

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

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;

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.

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

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

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

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

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

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?

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.

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)

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.

1. Control Flow Graph

2. Translate to SSA form

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)

3. Building a Value Graph

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

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

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

Loop example

Partitioning Algorithms

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)

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

Conditional Statements

Conditional: Example

Loop

Loop Example

Simple Modifications Constant Propagation: can do more statically Symmetry: is the same as