Validation of Code-Improving Transformations for Embedded Systems

Slides:



Advertisements
Similar presentations
Static Single-Assignment ? ? Introduction: Over last few years [1991] SSA has been Stablished as… Intermediate program representation.
Advertisements

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
Compiler techniques for exposing ILP
Computer Architecture Lecture 7 Compiler Considerations and Optimizations.
Control-Flow Graphs & Dataflow Analysis CS153: Compilers Greg Morrisett.
Data-Flow Analysis Framework Domain – What kind of solution is the analysis looking for? Ex. Variables have not yet been defined – Algorithm assigns a.
Loop invariant code removal CS 480. Our sample calculation for i := 1 to n for j := 1 to m c [i, j] := 0 for k := 1 to p c[i, j] := c[i, j] + a[i, k]
SYSTEM PROGRAMMING & SYSTEM ADMINISTRATION
Whole-Program Linear-Constant Analysis with Applications to Link-Time Optimization Ludo Van Put – Dominique Chanet – Koen De Bosschere Ghent University.
Program Representations. Representing programs Goals.
Automated Soundness Proofs for Dataflow Analyses and Transformations via Local Rules Sorin Lerner* Todd Millstein** Erika Rice* Craig Chambers* * University.
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
Cpeg421-08S/final-review1 Course Review Tom St. John.
Program analysis Mooly Sagiv html://
Automatically Proving the Correctness of Compiler Optimizations Sorin Lerner Todd Millstein Craig Chambers University of Washington.
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 1 Introduction.
Validating High-Level Synthesis Sudipta Kundu, Sorin Lerner, Rajesh Gupta Department of Computer Science and Engineering, University of California, San.
1 Program Analysis Mooly Sagiv Tel Aviv University Textbook: Principles of Program Analysis.
Multiscalar processors
Hardware-Software Interface Machine Program Performance = t cyc x CPI x code size X Available resources statically fixed Designed to support wide variety.
Intermediate Code. Local Optimizations
Describing Syntax and Semantics
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Composing Dataflow Analyses and Transformations Sorin Lerner (University of Washington) David Grove (IBM T.J. Watson) Craig Chambers (University of Washington)
Precision Going back to constant prop, in what cases would we lose precision?
COP4020 Programming Languages
Introduction to Compiler Construction Robert van Engelen COP5621 Compiler Construction Copyright Robert.
Florida State University Symposium on Code Generation and Optimization Exhaustive Optimization Phase Order Space Exploration Prasad A. Kulkarni.
1 Code Generation Part II Chapter 8 (1 st ed. Ch.9) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University,
1 Code Generation Part II Chapter 9 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2005.
Predicated Static Single Assignment (PSSA) Presented by AbdulAziz Al-Shammari
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Florida State University Automatic Tuning of Libraries and Applications, LACSI 2006 In Search of Near-Optimal Optimization Phase Orderings Prasad A. Kulkarni.
1 CS 201 Compiler Construction Introduction. 2 Instructor Information Rajiv Gupta Office: WCH Room Tel: (951) Office.
Introduction to Code Generation and Intermediate Representations
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
Retargetting of VPO to the tms320c54x - a status report Presented by Joshua George Advisor: Dr. Jack Davidson.
SAFE KERNEL EXTENSIONS WITHOUT RUN-TIME CHECKING George C. Necula Peter Lee Carnegie Mellon U.
Control Flow Analysis Compiler Baojian Hua
Andrey Karaulov, Alexander Strabykin Institute for System Programming Russian Academy of Sciences SYRCoSE: Spring Young Researchers Colloquium on Software.
Chapter – 8 Software Tools.
ECE 750 Topic 8 Meta-programming languages, systems, and applications Automatic Program Specialization for J ava – U. P. Schultz, J. L. Lawall, C. Consel.
Review 1.Structure of the course Lexical Analysis Syntax Analysis Grammar & Language RG & DFA Top-down LL(1) Parsing Bottom-Up LR Layered Automation Semantic.
Credible Compilation With Pointers Martin Rinard and Darko Marinov Laboratory for Computer Science Massachusetts Institute of Technology.
CS 412/413 Spring 2005Introduction to Compilers1 CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 30: Loop Optimizations and Pointer Analysis.
Code Optimization Overview and Examples
Code Optimization.
Optimization Code Optimization ©SoftMoore Consulting.
idempotent (ī-dəm-pō-tənt) adj
Introduction to Compiler Construction
Code Generation Part III
Unit IV Code Generation
Programming Languages 2nd edition Tucker and Noonan
ECE-C662 Introduction to Behavioral Synthesis Knapp Text Ch
CS 201 Compiler Construction
Hyesoon Kim Onur Mutlu Jared Stark* Yale N. Patt
Code Optimization Overview and Examples Control Flow Graph
Code Generation Part III
Adapted from the slides of Prof
Validation of Code-Improving Transformations for Embedded Systems
In Search of Near-Optimal Optimization Phase Orderings
Easy IR generation Kai Nacke 3 February 2019 LLVM dev FOSDEM‘19
Introduction to Compiler Construction
Code Generation Part II
Introduction to Compiler Construction
Programming Languages 2nd edition Tucker and Noonan
Translating Imperative Code into SQL
CS 201 Compiler Construction
Presentation transcript:

Validation of Code-Improving Transformations for Embedded Systems Robert van Engelen David Whalley Xin Yuan

Introduction Validation of: Compiler optimizations Hand-crafted code optimizations VISTA: VPO Interactive System for Tuning Applications View of the program representation Allows orchestrating compiler optimizations applied to application code Supports the editing hand-crafted code optimizations Undo/redo facilities 11/30/2018 SAC03

VISTA 11/30/2018 SAC03

Motivation Embedded system software developers often write code in assembly to meet hardware/software design constraints Assembly optimized code is error-prone without tool support Validation of compiler optimizations is important for high-risk systems 11/30/2018 SAC03

Related Work Horwitz: “Identifying the Semantic and Textual Differences between Two Versions of a Program” [PLDI90] Limited number of high-level program constructs Rinard & Marinov: “Credible Compilation with Pointers” [FLoC99] Compiler writer must define invariants (formulas) for each transformation 11/30/2018 SAC03

Related Work (cont’d) Necula: “Translation Validation for an Optimizing Compiler” [PLDI00] Transformations cannot change branch structure Program slicing From a subset of program behavior reduce the program to a minimum form that produces the behavior Proving type and memory safeness Complementary to our approach 11/30/2018 SAC03

System Overview C source code Determine transformed region CFG VPO compiler or manual optimizations Get semantic effects at exit points Object code Compare normalized effects Ctadel algebraic simplifier 11/30/2018 SAC03

Register Transfer Lists RTLs are memory and register assignments r[8]=0; M[r[2]+.c]=r[8]; PC=IC<0,L14; Supports any ISA, e.g. predicated ILP forms M[r[2]]=0; r[2]=r[2]+4; M[r[2]]=IC<0,0; M[r[2]]=IC>=0,1; Translation between assembly and RTL form is easy and can be automated 11/30/2018 SAC03

Modeling ISA Semantics with RTL Effects RTL defines the semantics of an ISA using memory/register effects JMP Label in RTL: PC=Label; LD r0,sp+8 in RTL: r[0]=M[r[14]+8]; SUB r0,r1 in RTL: IC=r[0]?r[1]; r[0]=r[0]-r[1]; 11/30/2018 SAC03

Validation of Code-Improving Transformations entry entry optimize exit exit effects effects exit exit effects effects exit exit effects effects 11/30/2018 SAC03

Example Transformation IC=r[8]?0; PC=IC<0,L14; r[8]=r[9]; M[r[14]+.c]=r[8]; PC=L15; r[8]=r[9]; r[8]=-r[8]; M[r[14]+.c]=r[8]; Register allocation: replace M[r[14]+.c] with r[10] r[8]=M[r[14]+.c]; Dataflow analysis: M[r[14]+.c] is dead 11/30/2018 SAC03

Calculating the Extent of a Region After a Transformation IC=r[8]?0; PC=IC<0,L14; r[8]=r[9]; r[10]=r[8]; PC=L15; r[8]=r[9]; r[8]=-r[8]; r[10]=r[8]; Register allocation: replace M[r[14]+.c] with r[10] r[8]=r[10]; r[10]: Dataflow analysis: r[10] is dead 11/30/2018 SAC03

Merging the Effects of a Region IC=r[8]?0; PC=IC<0,L14; effects r[8]=r[9]; r[10]=r[8]; PC=L15; r[8]=r[9]; r[8]=-r[8]; r[10]=r[8]; r[8]=r[9]; r[10]=r[9]; r[8]=-r[9]; r[10]=-r[9]; Register allocation: replace M[r[14]+.c] with r[10] r[8]=r[10]; r[10]: Dataflow analysis: r[10] is dead { -r[9] if IC<0 r[8]= r[9] if IC>=0 11/30/2018 SAC03

Merging the Effects Within a Single Block region effects Merging (Before Transformation) Merging (After Transformation) r[16]=0; r[17]=HI[_s]; r[19]=r[17]+LO[_s]; r[17]: r[17]=r[16]+r[19]; r[16]: r[16]=0; r[16]: r[17]=HI[_s]; r[19]=r[17]+LO[_s]; r[17]: r[17]=r[19]; r[16]=0; r[17]=HI[_s]; r[19]=r[17]+LO[_s]; r[17]: r[17]=r[16]+r[19]; r[16]: r[17]=HI[_s]; r[19]=r[17]+LO[_s]; r[17]: r[17]=r[19]; r[16]=0; r[19]=HI[_s]+LO[_s]; r[17]=r[16]+r[19]; r[16]: r[19]=HI[_s]+LO[_s]; r[17]=r[19]; r[17]=HI[_s]+LO[_s]; r[19]=HI[_s]+LO[_s]; 11/30/2018 SAC03

Extending the Scope of a Region effects Before Transformation After Transformation r[16]=0; r[17]=HI[_s]; r[19]=r[17]+LO[_s]; r[17]: r[17]=r[16]+r[19]; r[16]: r[16]=0; r[16]: r[17]=HI[_s]; r[19]=r[17]+LO[_s]; r[17]: r[17]=r[19]; r[17]=HI[_s]+LO[_s]; r[19]=HI[_s]+LO[_s]; r[17]=r[16]+r[19]; r[17]=HI[_s]+LO[_s]; r[19]=HI[_s]+LO[_s]; r[17]=r[19]; Not equivalent Equivalent 11/30/2018 SAC03

Merging Potential Set/Use Alias region effects M[r[2]] and M[r[3]] are potential aliases M[r[2]]=r[4]; r[5]=M[r[3]]; { r[4] if r[2]==r[3] M[r[2]]=r[4]; r[5]= M[r[3]] if r[2]!=r[3] 11/30/2018 SAC03

Merging Potential Set/Set Alias region effects M[r[2]] and M[r[3]] are potential aliases M[r[2]]=r[4]; M[r[3]]=r[5]; { r[5] if r[2]==r[3] M[r[3]]=r[5]; M[r[2]]= r[4] if r[2]!=r[3] 11/30/2018 SAC03

Merging Conditional Effects B1 M[r[14]+.v]=r[8]; IC=r[8]?0; PC=IC>=0,B3; M[r[14]+.v]=(r[8] if r[8]>=0); M[r[14]+.v]=(r[8] if r[8]<0); B2 r[9]=-r[8]; M[r[14]+.v]=r[9]; r[9]: r[9] is dead M[r[14]+.v]=(-r[8] if r[8]<0); { join r[8] if r[8]>=0 M[r[14]+.v]= -r[8] if r[8]<0 B3 r[8]=M[r[14]+.v]; .v: .v is dead { r[8] if r[8]>=0 r[8]= -r[8] if r[8]<0 11/30/2018 SAC03

Loop Effects B1 M[r[14]]=0; r[14]=r[14]+4; IC=r[8]?0; r[8]=r[8]-1; PC=IC>=0,B1; M[r[14]..r[14]+4*i]=0; r[8]=r[8]-i; M[y(B1,w+4,r[14]) until y(B1,w-1,r[8])<0]=0; r[8]=y(B2,w-1,r[8]) until y(B1,w-1,r[8])<0; 11/30/2018 SAC03

Normalization of Effects { 0+r[8] if r[8]==0 -r[8] if r[8]<0 and r[8]!=0 r[8] if r[8]>0 and r[8]!=0 Get semantic effects at exit points Ctadel algebraic simplifier Fixed set of rewrite rules DNF Logic+guards Arithmetic Normalized effects at exit points r[8]= { r[8] if r[8]>=0 -r[8] if r[8]<0 11/30/2018 SAC03

Normalization of Effects with DAGs M[r[14]]+.v]=r[8]; IC=r[8]?0; PC=IC>=0,B3 M[r[14]+.v]=(r[8] if r[8]>=0); M[r[14]+.v]=(r[8] if r[8]<0); r[9]=-r[8]; M[r[14]+.v]=r[9]; r[9]: M[r[14]+.v]=(-r[8] if r[8]<0); >=0 M[r[14].v] r[8] if = <0 if = - = if 11/30/2018 SAC03

Benchmarks 11/30/2018 SAC03

Benchmarks 11/30/2018 SAC03

Benchmarks 11/30/2018 SAC03

Conclusions Validation of both compiler and hand-specified optimizations Keeps memory requirement low with DAG representation Overhead is reasonable to justify assurance 11/30/2018 SAC03