Translation Validation for an Optimizing Compiler Guy Erez Based on George C. Necula article (ACM SIGPLAN 2000) Advanced Programming Languages Seminar,

Slides:



Advertisements
Similar presentations
Technology from seed Automatic Equivalence Checking of UF+IA Programs Nuno Lopes and José Monteiro.
Advertisements

Carnegie Mellon Lecture 7 Instruction Scheduling I. Basic Block Scheduling II.Global Scheduling (for Non-Numeric Code) Reading: Chapter 10.3 – 10.4 M.
Computer Architecture Lecture 7 Compiler Considerations and Optimizations.
Jeffrey D. Ullman Stanford University. 2  A never-published Stanford technical report by Fran Allen in  Fran won the Turing award in  Flow.
1 Regression-Verification Benny Godlin Ofer Strichman Technion.
The Assembly Language Level
FIT FIT1002 Computer Programming Unit 19 Testing and Debugging.
ISBN Chapter 3 Describing Syntax and Semantics.
Discovering Affine Equalities Using Random Interpretation Sumit Gulwani George Necula EECS Department University of California, Berkeley.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
CS 536 Spring Intermediate Code. Local Optimizations. Lecture 22.
1 Intermediate representation Goals: –encode knowledge about the program –facilitate analysis –facilitate retargeting –facilitate optimization scanning.
4/23/09Prof. Hilfinger CS 164 Lecture 261 IL for Arrays & Local Optimizations Lecture 26 (Adapted from notes by R. Bodik and G. Necula)
Prof. Bodik CS 164 Lecture 171 Register Allocation Lecture 19.
Program Design and Development
Register Allocation (via graph coloring)
Validating High-Level Synthesis Sudipta Kundu, Sorin Lerner, Rajesh Gupta Department of Computer Science and Engineering, University of California, San.
Register Allocation (via graph coloring). Lecture Outline Memory Hierarchy Management Register Allocation –Register interference graph –Graph coloring.
Intermediate Code. Local Optimizations
Describing Syntax and Semantics
Programming Fundamentals (750113) Ch1. Problem Solving
Data Flow Analysis Compiler Design Nov. 8, 2005.
Query Processing Presented by Aung S. Win.
CCSA 221 Programming in C CHAPTER 2 SOME FUNDAMENTALS 1 ALHANOUF ALAMR.
Topic #10: Optimization EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
1 Program Correctness CIS 375 Bruce R. Maxim UM-Dearborn.
Unit Testing 101 Black Box v. White Box. Definition of V&V Verification - is the product correct Validation - is it the correct product.
1 Homework HW5 due today Review a lot of things about allocation of storage that may not have been clear when we covered them in our initial pass Introduction.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
CSE Winter 2008 Introduction to Program Verification January 31 proofs through simplification.
5.2: Solving Systems of Equations using Substitution
A System to Generate Test Data and Symbolically Execute Programs Lori A. Clarke Presented by: Xia Cheng.
PLC '06 Experience in Testing Compiler Optimizers Using Comparison Checking Masataka Sassa and Daijiro Sudo Dept. of Mathematical and Computing Sciences.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
CS357 Lecture 13: Symbolic model checking without BDDs Alex Aiken David Dill 1.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
3/2/2016© Hal Perkins & UW CSES-1 CSE P 501 – Compilers Optimizing Transformations Hal Perkins Autumn 2009.
Copyright © 2014 Curt Hill Algorithms From the Mathematical Perspective.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
Software Engineering Algorithms, Compilers, & Lifecycle.
©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 Overview and Examples
Compiler Design (40-414) Main Text Book:
Types CSCE 314 Spring 2016.
Software Testing.
Weakest Precondition of Unstructured Programs
Static Single Assignment
Optimization Code Optimization ©SoftMoore Consulting.
Compiler Construction
3-2: Solving Systems of Equations using Substitution
Software Testing (Lecture 11-a)
Optimizing Transformations Hal Perkins Autumn 2011
3-2: Solving Systems of Equations using Substitution
Solving Systems of Equations using Substitution
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
3-2: Solving Systems of Equations using Substitution
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
Optimizing Transformations Hal Perkins Winter 2008
Computer Science Core Concepts
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
3-2: Solving Systems of Equations using Substitution
3-2: Solving Systems of Equations using Substitution
3-2: Solving Systems of Equations using Substitution
Programming Languages and Compilers (CS 421)
3-2: Solving Systems of Equations using Substitution
3-2: Solving Systems of Equations using Substitution
Presentation transcript:

Translation Validation for an Optimizing Compiler Guy Erez Based on George C. Necula article (ACM SIGPLAN 2000) Advanced Programming Languages Seminar, Winter 2000

2 In a Nutshell The Problem: Verify that the optimized and source code are equivalentThe Problem: Verify that the optimized and source code are equivalent Partial (heuristic) Solution: Independently prove the validity of each translation passPartial (heuristic) Solution: Independently prove the validity of each translation pass Motivation: Optimizer TestingMotivation: Optimizer Testing

3 Outline IntroductionIntroduction Intermediate LanguageIntermediate Language An extensive exampleAn extensive example –Simulation Relation –Execution Pair –Equivalence Checking Branch NavigationBranch Navigation Results and LimitationsResults and Limitations

4 Methods of Proving Compiler Correctness Prove compiler general correctness:Prove compiler general correctness: +absolute –tedious –impractical for large programs –very dependent of compiler code

5 Methods of Proving Compiler Corr. (cont.) Show that each translation phase was validShow that each translation phase was valid –weaker +proof per program +applicable for large programs +independent of compiler code

6 Compilation Process Source Code Intermediate Language (IL) Target Code

7 Optimization Process IL Code 0 Optimize Pass IL Code 1 IL Code n Validator

8 The IL in GNU C (subset) Instructions: Expressions:Instructions: Expressions: Operators:Operators:

9 An Example extern int g; extern int a[…]; main() { int n=… /* n contains the length of the array */ int i; for (i=0; i<n; i++) a[i]=g*i+3; return i; }

10 And in IL … for (i=0;i<n; i++) a[i]=g*i+3; return i;

11 After Transformation … Use registers Transform while to a repeat loop ?

12 Equivalence x 1, …,x n – variables in sourcex 1, …,x n – variables in source y 1, …,y m – variables in targety 1, …,y m – variables in target Variable Equivalence: x 1 = y 3Variable Equivalence: x 1 = y 3 Expression Equivalence: x 1 +x 2 = y 3 +6Expression Equivalence: x 1 +x 2 = y 3 +6

13 Simulation Relation A set of equivalences between a source block and a target blockA set of equivalences between a source block and a target block

14 Execution Pair Definition: An execution path in the source and its corresponding path in the targetDefinition: An execution path in the source and its corresponding path in the target Source Target

15 Checking Equivalence Equivalence is checked at the end of a specific execution pairEquivalence is checked at the end of a specific execution pair A variable value after the run is marked with a primeA variable value after the run is marked with a prime x x’=x+1 yy’=y*3 Symbolic Substitution

16 Equivalence Simplification An equivalence can be simplified using:An equivalence can be simplified using: –Arithmetic rules –Already proven equivalences Example: If x ’ =x+1 and y ’ =y*5 then: 3*x ’ =y ’  3*(x+1)=y*5  3*x+3=y*5Example: If x ’ =x+1 and y ’ =y*5 then: 3*x ’ =y ’  3*(x+1)=y*5  3*x+3=y*5 An equivalence holds if it can be simplified to an already proven equivalenceAn equivalence holds if it can be simplified to an already proven equivalence

17 Checking Simulation Relations A relation is correct if for each execution pair entering it, all of its equivalences holdA relation is correct if for each execution pair entering it, all of its equivalences hold xy x=y+1

18 Something fishy SimplerSimpler Provides an independent perspective on the final codeProvides an independent perspective on the final code What ’ s the point of proving something using the same rules that created it?What ’ s the point of proving something using the same rules that created it?

19 Showtime … A. Element #1 holds C. Prove elem. #2 (Trivial) B. There is only one execution pair (no cond.)

20 Element #5 Two execution pairs: b3-b1-b2 and b7-b5

21 Element #5 (cont.) The other pair: b3-b1-b3 and b7-b7

22 Known Equivalences Equivalences from the start of the run:Equivalences from the start of the run: Equivalences at the end of run:Equivalences at the end of run:

23 Need to Prove The path condition is correct:The path condition is correct: The equivalences hold, mainly:The equivalences hold, mainly:

24 Elem #5: Path Cond.

25 Elem #5: The Equivalence distributivitycommutativity Q.E.D

26 Algorithm Parts Inferring Simulation RelationsInferring Simulation Relations Finding execution pairsFinding execution pairs Solving ConstraintsSolving Constraints

27 Navigating Branches An optimizer might eliminate or reverse branchesAn optimizer might eliminate or reverse branches Problem: did branch B ’ originate from branch B in the sourceProblem: did branch B ’ originate from branch B in the source Solution: Use heuristicsSolution: Use heuristics

28 A Typical Case

29 Similarity The similarity between two branches depend on the similarity of their:The similarity between two branches depend on the similarity of their: –preceding instruction sequence –boolean conditions –the two branching sequences

30 Similarity (cont.) Formally:Formally: ~ is a numeric relation(0..1)~ is a numeric relation(0..1) “ and ” is multiplication“ and ” is multiplication “ or ” is maximum“ or ” is maximum

31 Boolean Similarity Branches are similar if:Branches are similar if: –one can be simplified into the other using simple transforms, such as:

32 Instruction Similarity Instructions similarityInstructions similarity –amount of function calls –lead to already related branches (in that case, similarity is 1.0)

33 Instruction Similarity … gcc specific featuresgcc specific features –IL instructions serial number –source line number information (for code duplication detection)

34 Results Detected a known bug in gcc Detected a known bug in gcc Used on large programs:Used on large programs: Increased compile time x4Increased compile time x4

35 Limitations Cannot handle loop unrollingCannot handle loop unrolling Cannot resolve all types of equivalencesCannot resolve all types of equivalences Produces several false alarms (i.e. the gcc bug was accompanied by 3 false alarms)Produces several false alarms (i.e. the gcc bug was accompanied by 3 false alarms)

36 Conclusion Automatically infer equivalencesAutomatically infer equivalences Uses:Uses: –simple rules and substitution –heuristics Good resultsGood results Problems:Problems: –false alarms –runtime overhead