Credible Compilation With Pointers Martin Rinard and Darko Marinov Laboratory for Computer Science Massachusetts Institute of Technology.

Slides:



Advertisements
Similar presentations
Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
Advertisements

Synopsys University Courseware Copyright © 2012 Synopsys, Inc. All rights reserved. Compiler Optimization and Code Generation Lecture - 3 Developed By:
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) SSA Guo, Yao.
Intermediate Code Generation
Lecture 11: Code Optimization CS 540 George Mason University.
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.
ECE 454 Computer Systems Programming Compiler and Optimization (I) Ding Yuan ECE Dept., University of Toronto
Control-Flow Graphs & Dataflow Analysis CS153: Compilers Greg Morrisett.
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-
Program Representations. Representing programs Goals.
1 CS 201 Compiler Construction Lecture 7 Code Optimizations: Partial Redundancy Elimination.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Automated Soundness Proofs for Dataflow Analyses and Transformations via Local Rules Sorin Lerner* Todd Millstein** Erika Rice* Craig Chambers* * University.
1 CS 201 Compiler Construction Lecture 5 Code Optimizations: Copy Propagation & Elimination.
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
Automatically Proving the Correctness of Compiler Optimizations Sorin Lerner Todd Millstein Craig Chambers University of Washington.
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)
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
Validating High-Level Synthesis Sudipta Kundu, Sorin Lerner, Rajesh Gupta Department of Computer Science and Engineering, University of California, San.
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.
Recap from last time: live variables x := 5 y := x + 2 x := x + 1 y := x y...
Describing Syntax and Semantics
Machine-Independent Optimizations Ⅰ CS308 Compiler Theory1.
Topic #10: Optimization EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
Λλ Fernando Magno Quintão Pereira P ROGRAMMING L ANGUAGES L ABORATORY Universidade Federal de Minas Gerais - Department of Computer Science P ROGRAM A.
1 Code optimization “Code optimization refers to the techniques used by the compiler to improve the execution efficiency of the generated object code”
Detecting Equality of Variables in Programs Bowen Alpern, Mark N. Wegman, F. Kenneth Zadeck Presented by: Abdulrahman Mahmoud.
1 Data Flow Analysis Data flow analysis is used to collect information about the flow of data values across basic blocks. Dominator analysis collected.
Compiler Optimizations ECE 454 Computer Systems Programming Topics: The Role of the Compiler Common Compiler (Automatic) Code Optimizations Cristiana Amza.
Program Representations. Representing programs Goals.
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.
PLC '06 Experience in Testing Compiler Optimizers Using Comparison Checking Masataka Sassa and Daijiro Sudo Dept. of Mathematical and Computing Sciences.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
©SoftMoore ConsultingSlide 1 Code Optimization. ©SoftMoore ConsultingSlide 2 Code Optimization Code generation techniques and transformations that result.
Code Optimization Data Flow Analysis. Data Flow Analysis (DFA)  General framework  Can be used for various optimization goals  Some terms  Basic block.
CS 412/413 Spring 2005Introduction to Compilers1 CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 30: Loop Optimizations and Pointer Analysis.
Single Static Assignment Intermediate Representation (or SSA IR) Many examples and pictures taken from Wikipedia.
Code Optimization Code produced by compilation algorithms can often be improved (ideally optimized) in terms of run-time speed and the amount of memory.
Code Optimization Overview and Examples
Introduction to Optimization
High-level optimization Jakub Yaghob
Code Optimization.
Data Flow Analysis Suman Jana
Lecture 5 Partial Redundancy Elimination
Proof Carrying Code and Proof Preserving Program Transformations
Graph-Based Operational Semantics
State your reasons or how to keep proofs while optimizing code
Fall Compiler Principles Lecture 6: Dataflow & Optimizations 1
Fall Compiler Principles Lecture 8: Loop Optimizations
Machine-Independent Optimization
Introduction to Optimization
University Of Virginia
Optimizing Transformations Hal Perkins Autumn 2011
1. Reaching Definitions Definition d of variable v: a statement d that assigns a value to v. Use of variable v: reference to value of v in an expression.
Compiler Code Optimizations
Code Optimization Overview and Examples Control Flow Graph
Fall Compiler Principles Lecture 10: Loop Optimizations
Data Flow Analysis Compiler Design
Introduction to Optimization
Fall Compiler Principles Lecture 6: Dataflow & Optimizations 1
Optimization 薛智文 (textbook ch# 9) 薛智文 96 Spring.
Intermediate Code Generation
Chapter 10: Compilers and Language Translation
Programming Languages and Compilers (CS 421)
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
Presentation transcript:

Credible Compilation With Pointers Martin Rinard and Darko Marinov Laboratory for Computer Science Massachusetts Institute of Technology

Goal Source Code (C, Java) Object Code Proof that Object Code Implements Source Code Compiler Proof Checker YesNo

Proposed Approach Source Internal Representation Parser Analysis & Transformation Binary Code Simple Code Generator Internal Representation Equivalence Proof Analysis & Transformation Internal Representation Equivalence Proof

Key Aspects Majority of compiler structured as a sequence of transformations on standard intermediate format Compiler generates a proof for each transformation Separate verification frameworks for Parser Transformations Code generator Today: Proving Transformations Correct

Overview of Framework Compiler operates on compilation units procedure, loop nest, method Set of externally visible variables global variables, instance variables Correctness condition transformation preserves final values of externally visible variables original and transformed programs terminate under same conditions

Example i  0 i  i + 3 g  2 * i i < 24 exit g  0 g  g + 6 g < 48 exit Externally visible variable: g

Structure of A Transformation Analysis to discover program properties reaching definitions available expressions Program transformation constant and copy propagation common subexpression elimination Correctness of transformation often depends on correctness of analysis result

Two Stage Proof Structure Prove analysis results correct Classic Floyd approach for proving program properties Use analysis results to prove simulation relations between original and transformed programs State equality of expressions at corresponding program points under certain execution conditions

Standard and Simulation Invariants Invariants for program analysis results p - “The condition c is always true at the program point p” Simulation invariants for transformations p 1 - p 2 “For all executions of the transformed program that reach the program point p 2 with the condition c 2 true, there exists an execution of the original program that reaches p 1 with c 1 true such that e 1 = e 2 ”

Example i  0 i  i + 3 g  2 * i i < 24 exit g  0 g  g + 6 g < 48 exit a b c d c 5 - d 2 - b Correctness Condition

Proving Standard Invariants Proof rules propagate invariants backwards through control flow graph Substitution at assignment statements Add condition in at conditional branches Propagate along all edges at join points g  2 * i i <

Proving Simulation Invariants Each proof rule propagates one of the two sides of invariant ( p 1 - p 2 ) Right side propagated in transformed program Propagate along all edges at join points Left side propagated in original program Propagate along one edge at join points Can use other invariants (both standard and simulation) to prove propagated invariant

Simulation Invariant Proof Example Given { 2 - b, 4 - c, 5 - d } and { 4} i  0 i  i + 3 g  2 * i i < 24 exit g  0 g  g + 6 g < 48 exit Prove 2 - b a b c d

Propagate Right Hand Side g  0 g  g + 6 g < 48 exit To prove 2 - b Propagate RHS to a, c Must Prove 2 - a 2 - c a b c d

Propagate Left Hand Side To prove 2 - a Propagate LHS to a To prove 2 - c Propagate LHS to c i  0 i  i + 3 g  2 * i i < 24 exit

Use Other Invariants Want to prove 4 - c But 4 - c is one of given invariants So we can substitute 2 * i in for g, and reduce our problem to proving 2 * i < 48 implies i < 24 2 * i = 2 * i

Primary Advantages Open Compilation Framework Anyone can provide transformations No need to trust provider Buggier Compilers Incorrect compilation much less serious problem Compiler writers can focus on Aggressive optimizations Latest language developments NOT on correct compilation in all cases

Key Challenge Compiler must be able to control machine at very low level for efficiency Pointers Register Allocation Instruction Selection Condition Codes

Pointer Problem Cannot use simple expression substitution in presence of pointers Aliasing may cause substitution to produce incorrect result Solution: Define substitution in the presence of a set of aliases Compiler uses pointer analysis to produce alias invariants at each program point Proof rules use alias invariants

Pointer Details Handling aliasing uncertainty Must prove result for both aliased and unaliased cases Flow-insensitive analyses Change semantics of source language slightly to make analysis results valid Provide derived rules specifically to support validation of flow-insensitive results

Low Level Details Register Allocation Instruction Selection Condition Codes

Standard Compiler Structure Source Machine-Independent Representation Parser Machine-Independent Analyses and Transformations Machine-Dependent Representation Machine-Specific Analyses and Transformations Binary Code Code Generation Lowering

Proposed Compiler Structure Source Single Standard Representation Parser Analyses and Transformations Single Standard Representation Analyses and Transformations Binary Code Code Generation Lowering

Simple Code Generation Basic Approach Each node in control flow graph Corresponds to single instruction in generated code Code generator can be very simple Issues: Registers in machine-independent IR Implicitly set state (condition codes) Instruction selection

Register Allocation Have a dedicated variable represent each register Not semantically distinct from other variables in intermediate representation But code generator for the specific machine understands representation Allocates dedicated variables in registers Can represent results of register allocation in an ostensibly machine-independent IR

Condition Codes Instruction may have multiple effects Write registers, set condition codes Solution: Macro Instructions Define macro instructions as a sequence of basic nodes in IR System automatically derives proof rules for macro instructions Code generator produces one instruction for each macro instruction Approach works for instruction selection

Limitation Proof rules are based on concepts of partial correctness Not designed to prove equivalences that depend on termination of loops g  0 g  g + 6 g < 48 exit g  48 exit

Proved Transformations Constant Propagation and Folding Copy Propagation Dead Code Elimination Branch Movement Induction Variable Elimination Loop Unrolling Branch Elimination

Related Work Totally Correct Compilation Verifix Guttman, Ramsdell, Wand Synchronous Languages Cimatti, Giunchiglia, Pecchiari, Pietra, Profeta, Romano, Traverso, Yu Pnueli, Siegal, Singerman Proof-Carrying Code Necula, Lee

Conclusion Credible Compilation for Imperative Languages Basic Concepts Standard Invariants Simulation Invariants Proof rules for propagating invariants Support for low-level details Pointers Registers and Condition Codes Instruction Selection