Introduction to Advanced Topics Chapter 1 Mooly Sagiv Schrierber 317 03-640-7606 www.math.tau.ac.il/~sagiv/courses/acd.html.

Slides:



Advertisements
Similar presentations
Chapt.2 Machine Architecture Impact of languages –Support – faster, more secure Primitive Operations –e.g. nested subroutine calls »Subroutines implemented.
Advertisements

Optimizing Compilers for Modern Architectures Syllabus Allen and Kennedy, Preface Optimizing Compilers for Modern Architectures.
7. Optimization Prof. O. Nierstrasz Lecture notes by Marcus Denker.
The University of Adelaide, School of Computer Science
Software & Services Group, Developer Products Division Copyright© 2010, Intel Corporation. All rights reserved. *Other brands and names are the property.
Interprocedural Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday
Compilation 2011 Static Analysis Johnni Winther Michael I. Schwartzbach Aarhus University.
ECE 454 Computer Systems Programming Compiler and Optimization (I) Ding Yuan ECE Dept., University of Toronto
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-
Control Flow Analysis (Chapter 7) Mooly Sagiv (with Contributions by Hanne Riis Nielson)
Optimization Compiler Baojian Hua
Intermediate Representation I High-Level to Low-Level IR Translation EECS 483 – Lecture 17 University of Michigan Monday, November 6, 2006.
Chapter 14: Building a Runnable Program Chapter 14: Building a runnable program 14.1 Back-End Compiler Structure 14.2 Intermediate Forms 14.3 Code.
Code Generation Mooly Sagiv html:// Chapter 4.
TM Pro64™: Performance Compilers For IA-64™ Jim Dehnert Principal Engineer 5 June 2000.
Introduction to Code Generation Mooly Sagiv html:// Chapter 4.
Compiler Optimizations for Memory Hierarchy Chapter 20 High Performance Compilers.
Recap Mooly Sagiv. Outline Subjects Studied Questions & Answers.
1 Intermediate representation Goals: –encode knowledge about the program –facilitate analysis –facilitate retargeting –facilitate optimization scanning.
9. Optimization Marcus Denker. 2 © Marcus Denker Optimization Roadmap  Introduction  Optimizations in the Back-end  The Optimizer  SSA Optimizations.
Tentative Schedule 20/12 Interpreter+ Code Generation 27/12 Code Generation for Control Flow 3/1 Activation Records 10/1 Program Analysis 17/1 Register.
Introduction to Program Optimizations Chapter 11 Mooly Sagiv.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
Case Studies of Compilers and Future Trends Chapter 21 Mooly Sagiv.
Data-Flow Analysis (Chapter 11-12) Mooly Sagiv Make-up class 18/ :00 Kaplun 324.
Compiler Summary Mooly Sagiv html://
Hardware-Software Interface Machine Program Performance = t cyc x CPI x code size X Available resources statically fixed Designed to support wide variety.
The Structure of the GNAT Compiler. A target-independent Ada95 front-end for GCC Ada components C components SyntaxSemExpandgigiGCC AST Annotated AST.
Overview of program analysis Mooly Sagiv html://
Introduction to Code Generation Mooly Sagiv html:// Chapter 4.
Compiler Optimization Overview
Lecture 1CS 380C 1 380C Last Time –Course organization –Read Backus et al. Announcements –Hadi lab Q&A Wed 1-2 in Painter 5.38N –UT Texas Learning Center:
CMPUT Compiler Design and Optimization1 CMPUT680 - Winter 2006 Topic0: Introduction José Nelson Amaral
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
LLVM Developed by University of Illinois at Urbana-Champaign CIS dept Cisc 471 Matthew Warner.
Procedure Optimizations and Interprocedural Analysis Chapter 15, 19 Mooly Sagiv.
CPSC 388 – Compiler Design and Construction Lecture: MWF 11:00am-12:20pm, Room 106 Colton.
Optimizing Compilers Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
C Chuen-Liang Chen, NTUCS&IE / 1 COMPILER Chuen-Liang Chen Department of Computer Science and Information Engineering National Taiwan University Taipei,
Topic #10: Optimization EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
Compiler course 1. Introduction. Outline Scope of the course Disciplines involved in it Abstract view for a compiler Front-end and back-end tasks Modules.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Advanced Compiler Design Early Optimizations. Introduction Constant expression evaluation (constant folding)  dataflow independent Scalar replacement.
CS 671 Compilers Prof. Kim Hazelwood Spring 2008.
1 CS 201 Compiler Construction Introduction. 2 Instructor Information Rajiv Gupta Office: WCH Room Tel: (951) Office.
Synopsys University Courseware Copyright © 2012 Synopsys, Inc. All rights reserved. Compiler Optimization and Code Generation Lecture - 1 Developed By:
Lexical analyzer Parser Semantic analyzer Intermediate-code generator Optimizer Code Generator Postpass optimizer String of characters String of tokens.
Chapter 1 Introduction Study Goals: Master: the phases of a compiler Understand: what is a compiler Know: interpreter,compiler structure.
Introduction CPSC 388 Ellen Walker Hiram College.
Compiler Optimizations ECE 454 Computer Systems Programming Topics: The Role of the Compiler Common Compiler (Automatic) Code Optimizations Cristiana Amza.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
CS412/413 Introduction to Compilers and Translators April 2, 1999 Lecture 24: Introduction to Optimization.
©SoftMoore ConsultingSlide 1 Code Optimization. ©SoftMoore ConsultingSlide 2 Code Optimization Code generation techniques and transformations that result.
Chapter 1 Introduction Samuel College of Computer Science & Technology Harbin Engineering University.
Compiler Summary Lexical analysis—scanner – String of characters  token – Finite automata. Syntactical analysis – parser – Sequence of tokens –> language.
CS 404 Introduction to Compiler Design
Code Optimization Overview and Examples
Chapter 1 Introduction.
Introduction to Advanced Topics Chapter 1 Text Book: Advanced compiler Design implementation By Steven S Muchnick (Elsevier)
Compiler Construction (CS-636)
CMPUT Compiler Design and Optimization
Chapter 1 Introduction.
课程名 编译原理 Compiling Techniques
Optimization Code Optimization ©SoftMoore Consulting.
CMPE 152: Compiler Design December 5 Class Meeting
An Overview to Compiler Design
CSE401 Introduction to Compiler Construction
Compilers B V Sai Aravind (11CS10008).
Intermediate Code Generation
CMPE 152: Compiler Design April 30 Class Meeting
Presentation transcript:

Introduction to Advanced Topics Chapter 1 Mooly Sagiv Schrierber

Outline Course requirements Review of compiler structure Advanced issues in elementary topics The importance of optimizations Structure of optimizing compilers Placement of optimizations Advanced topics

Course Requirements Prepare course notes 10% Theoretical assignments 30% Final home exam 60%

Compiler Structure Symbol table and access routines OS Interface String of characters Scanner tokens Semantic analyzer Parser Code Generator IR AST Object code

Advanced Issues in Elementary Topics Symbol table management(3) –Efficiency –Overloading Type Inference Intermediate Language Selection(4) Run-Time Support(5) Producing Code Generators (6)

procedure BACH is procedure put (x: boolean) is begin null; end; procedure put (x: float) is begin null; end; procedure put (x: integer) is begin null; end; package x is type boolean is (false, true); function f return boolean; -- (D1) end x; package body x is function f return boolean is begin null; end; end x; function f return float is begin null; end; -- (D2) use x; begin put (f); -- (A1) A: declare f: integer; -- (D3) begin put (f); -- (A2) B: declare function f return integer is begin null; end; -- (D4) begin put (f); -- (A3) end B; end A; end BACH;

Advanced Issues in Elementary Topics Symbol table management(3) –Efficiency –Overloading Type Inference Intermediate Language Selection(4) Run-Time Support(5) Producing Code Generators (6)

Advanced Issues in Elementary Topics Symbol table management(3) –Efficiency –Overloading Type Inference Intermediate Language Selection(4) Run-Time Support(5) Producing Code Generators (6)

Intermediate Language Selection Low Vs. High level control flow structures Flat Vs. Hierarchical (tree) Machine Vs. High level of instructions (Symbolic) Registers Vs. Stack Normal forms (SSA) Intermediate forms: Control Flow Graph, Call Graph, Program Dependence Graph Issues: Engineering, efficiency, portability, optimization level

HIR for v  v1 by v2 to v3 do a[i] :=2 endfor MIR v  v1 t2  v2 t3  v3 L1: if v >t3 goto L2 t4  addr a t5  4*i t6  t4+t5 *t6  2 v  v + t2 goto L1 L2: LIR s2  s1 s4  s3 s6  s5 L1: if s2 >s6 goto L2 s7  addr a s8  4*s9 s10  s7+s8 [s10]  2 s2  s2 + s4 goto L1 L2: IRs in the Book

Single Static Assignment Form (SSA) s2  s1 s4  s3 s6  s5 L1: if s2 >s6 goto L2 s7  addr a s8  4*s9 s10  s7+s8 [s10]  2 s2  s2 + s4 L2: B2 s2 1  s1 s4  s3 B1 s2 2   (s2 1, s2 3 ) s2 2 >=s6 N s7  addr a s8  4*s9 s10  s7+s8 [s10]  2 s2 3  s2 2 + s4 Y B3

Advanced Issues in Elementary Topics Symbol table management(3) –Efficiency –Overloading Type Inference Intermediate Language Selection(4) Run-Time Support(5) Producing Code Generators (6)

Run-Time Support Data representation and instructions Register usage Stack frames (activation records) Parameter passing disciplines Symbolic and polymorphic language support Garbage Collection

Advanced Issues in Elementary Topics Symbol table management(3) –Efficiency –Overloading Type Inference Intermediate Language Selection(4) Run-Time Support(5) Producing Code Generators (6)

The Importance of Optimizations One pass compilers produce slow code Much of the time spent in loops –optimize loops Machines can be simpler and faster if optimizing compilers are used (RISC, VLIW) Programs are complex and general Compilers need to be modular

C code int a, b, c, d; c = a + b; d = c + 1; SPARC code ldw a, r1 ldw b, r2 add r1, r2, r3 stw r3, c ldw c, r3 add r3, 1, r4 stw r4, d Optimized SPARC code add r1, r2, r3 add r3, 1, r4 10 cycles 2 cycles

Application Dependent Optimizations Functional programs –replacement of recursion by loops (tail-calls elimination) –replacement of heap by stack Object Oriented Programs –Dead member elimination –Replacement of virtual by static function Numeric Code Database Code

String Object Scanner Parser Semantic LIR generator Optimizer Fin. assembly Tokens AST LIR Object String Scanner Parser Semantic IR generator Optimizer Code generator Tokens AST MIR LIR Post. optimizer

Mixed vs. Low Level Optimizers Mixed –Sun-SPARC, Dec. Alpha, SGI-MIPS, Intel’s 386 Easier to port More efficient compilation? Supports CISC Low Level HP-PA-RISC/IBM-Power PC More efficient code Conceptually simpler (in RISC) Used for multiple programming languages

Translation by Preprocessing Some programming languages are translated into C –Elimination of includes, C++(cfront), Haskel Quick and portable solution C supports some indirect source level debugging Other examples: Fortran into “vector” Fortran program

Data-Cache Optimizations(20) String Object Scanner Parser Semantic Data-cache optimizer Tokens AST HIR MIR 

IBM PowerPC compiler String Object Scanner Parser Semantic LIR generator Optimizer Fin. assembly Tokens AST LIR=XIL LIR Data-cache optimizer Low-to-High High-to-Low HIR=YIL

Outline Review of compiler structure Advanced issues in elementary topics The importance of optimizations Structure of optimizing compilers Placement of optimizations Advanced Topics

Scalar replacement of array references Data-cache optimizations Procedure integration Tail-call elimination Scalar replacement of aggregates Sparse constant propagation Interprocedural constant propagation Procedure specialization and cloning Sparse conditional constant propagation Global value numbering Local and global copy propagation Sparse conditional constant propagation Dead code elimination Common Subexpression Elimination Loop invariant code motion Partial redundency Elimination Inline expansion Leaf-routine optimizations Instruction Scheduling 1 Register allocation Instruction Scheduling 2 Intraprocedural I-cache optimizations Instruction prefetching Data prefertching Branch predication Interprocedural register allocation Interprocedural I-cache optimization

Scalar replacement after constant propagation a  1 a= 1 Y N B.x  1.0 B.y  1.0 read B.x read B.y B.x = 1.0 Y N c c c  B.x

Scalar replacement before constant propagation B.x  1.0 c  2 read B.y B.x = 1.0 Y N B.x  B.x + c d d d d d  B.x

Theoretically Open Questions Picking the “right” order Combining optimizations Proving correctness

Tentative Schedule 30/3 Introduction(1) 13/4 No class (read Chapter 2 and solve Homework #1) 20/4 Yom Hazikaron 24/4 9am, Intermediate Representations(4) 27/4 Control Flow Analysis (7) 4/5 Data Flow Analysis (8) 11/5 Dependence Analysis and Dependence Graphs(9) 18/5 Introduction to Optimization(11) 25/5 Early Optimizations (12) 1/6 Redundancy Elimination (13) 8/6 Loop Optimizations (14) 7/6 Interprocedural Analysis and Optimizations (19) 14/6 Optimizations for memory hierarchy (20) 21/6 Case Studies of Compilers and Future Trends (21)

Uncovered Chapters Symbol tables(3) Run-time support(5) Producing code generators automatically (6) Alias analysis(10) Procedure optimizations (15) Register allocation (16) Code scheduling (17) Control-Flow and Low-Level Optimizations (18)

Uncovered Topics Code profiling Source level debugging Parallelization and vectorization Just in time compilation

Advanced Topics Code Profiling Parallelization and vectorization Just in time compilation Optimize for Power Trusted compilers