Hardware-Software Interface Machine Program Performance = t cyc x CPI x code size X Available resources statically fixed Designed to support wide variety.

Slides:



Advertisements
Similar presentations
CSC 4181 Compiler Construction Code Generation & Optimization.
Advertisements

Course Outline Traditional Static Program Analysis Software Testing
19 Classic Examples of Local and Global Code Optimizations Local Constant folding Constant combining Strength reduction.
ECE 454 Computer Systems Programming Compiler and Optimization (I) Ding Yuan ECE Dept., University of Toronto
Computer Architecture Lecture 7 Compiler Considerations and Optimizations.
8. Code Generation. Generate executable code for a target machine that is a faithful representation of the semantics of the source code Depends not only.
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-
C Chuen-Liang Chen, NTUCS&IE / 321 OPTIMIZATION Chuen-Liang Chen Department of Computer Science and Information Engineering National Taiwan University.
1 Code Optimization Code produced by compilation algorithms can often be improved (ideally optimized) in terms of run-time speed and the amount of memory.
Introduction to Advanced Topics Chapter 1 Mooly Sagiv Schrierber
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.
Introduction to Program Optimizations Chapter 11 Mooly Sagiv.
Case Studies of Compilers and Future Trends Chapter 21 Mooly Sagiv.
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
From Cooper & Torczon1 Implications Must recognize legal (and illegal) programs Must generate correct code Must manage storage of all variables (and code)
1 Lecture 7: Computer Arithmetic Today’s topics:  Chapter 2 wrap-up  Numerical representations  Addition and subtraction Reminder: Assignment 3 will.
1 Lecture 6: Compilers, the SPIM Simulator Today’s topics:  SPIM simulator  The compilation process Additional TA hours: Liqun Cheng, legion at.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
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.
Compiler Code Optimizations. Introduction Introduction Optimized codeOptimized code Executes faster Executes faster efficient memory usage efficient memory.
Topic #10: Optimization EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
Optimization software for apeNEXT Max Lukyanov,  apeNEXT : a VLIW architecture  Optimization basics  Software optimizer for apeNEXT  Current.
What’s in an optimizing compiler?
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.
CSc 453 Final Code Generation Saumya Debray The University of Arizona Tucson.
1 Code optimization “Code optimization refers to the techniques used by the compiler to improve the execution efficiency of the generated object code”
CIS 662 – Computer Architecture – Fall Class 16 – 11/09/04 1 Compiler Techniques for ILP  So far we have explored dynamic hardware techniques for.
Synopsys University Courseware Copyright © 2012 Synopsys, Inc. All rights reserved. Compiler Optimization and Code Generation Lecture - 1 Developed By:
High-Level Transformations for Embedded Computing
Lexical analyzer Parser Semantic analyzer Intermediate-code generator Optimizer Code Generator Postpass optimizer String of characters String of tokens.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Introduction CPSC 388 Ellen Walker Hiram College.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Compiler Introduction 1 Kavita Patel. Outlines 2  1.1 What Do Compilers Do?  1.2 The Structure of a Compiler  1.3 Compilation Process  1.4 Phases.
Compiler Optimizations ECE 454 Computer Systems Programming Topics: The Role of the Compiler Common Compiler (Automatic) Code Optimizations Cristiana Amza.
High Performance Embedded Computing © 2007 Elsevier Lecture 10: Code Generation Embedded Computing Systems Michael Schulte Based on slides and textbook.
3/2/2016© Hal Perkins & UW CSES-1 CSE P 501 – Compilers Optimizing Transformations Hal Perkins Autumn 2009.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
CS412/413 Introduction to Compilers and Translators April 2, 1999 Lecture 24: Introduction to Optimization.
Presented by : A best website designer company. Chapter 1 Introduction Prof Chung. 1.
Dr. Hussien Sharaf Dr Emad Nabil. Dr. Hussien M. Sharaf 2 position := initial + rate * Lexical analyzer 2. Syntax analyzer id 1 := id 2 + id 3 *
©SoftMoore ConsultingSlide 1 Code Optimization. ©SoftMoore ConsultingSlide 2 Code Optimization Code generation techniques and transformations that result.
Code Optimization More Optimization Techniques. More Optimization Techniques  Loop optimization  Code motion  Strength reduction for induction variables.
CHAPTER 1 INTRODUCTION TO COMPILER SUNG-DONG KIM, DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
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
Compiler Design (40-414) Main Text Book:
Code Optimization.
Chapter 1 Introduction.
Introduction to Advanced Topics Chapter 1 Text Book: Advanced compiler Design implementation By Steven S Muchnick (Elsevier)
Compilers.
Chapter 1 Introduction.
Optimization Code Optimization ©SoftMoore Consulting.
Machine-Independent Optimization
Optimizing Transformations Hal Perkins Autumn 2011
Wrapping Up Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit.
Optimizing Transformations Hal Perkins Winter 2008
Compiler Code Optimizations
Code Optimization Overview and Examples Control Flow Graph
Fall Compiler Principles Lecture 10: Loop Optimizations
Intermediate Code Generation
Lecture 19: Code Optimisation
Lecture 4: Instruction Set Design/Pipelining
CSc 453 Final Code Generation
CMPE 152: Compiler Design April 30 Class Meeting
Code Optimization.
Presentation transcript:

Hardware-Software Interface Machine Program Performance = t cyc x CPI x code size X Available resources statically fixed Designed to support wide variety of programs Required resources dynamically varying Designed to run well on a variety of machines Interested in having itself run fast Interested in running many programs fast Reflects how well the machine resources match the program requirements

Compiler Tasks  Code Translation ­Source language  target language FORTRAN  C C  MIPS, PowerPC or Alpha machine code MIPS binary  Alpha binary  Code Optimization ­Code runs faster ­Match dynamic code behavior to static machine structure

Compiler Structure Frond EndOptimizer Back End Machine independentMachine dependent high-level source code IR machine code Dependence Analyzer (IR= intermediate representation) IR

Front End  Lexical Analysis ­Misspelling an identifier, keyword, or operator e.g. lex  Syntax Analysis ­Grammar errors, such as mismatched parentheses e.g. yacc  Semantic Analysis ­Type checking

Intermediate Representation  Achieve retargetability ­Different source languages ­Different target machines  Example (tree-based IR from CMCC) d = a * (b+c) A “a” int a, b, c, d; A “b” A “c” A “d” FND1 ADDRL A3 FND2 ADDRL A0 FND3 INDIRI FND2 FND4 ADDRL A1 FND5 INDIRI FND4 FND6 ADDRL A2 FND7 INDIRI FND6 FND8 ADDI FND5 FND7 FND9 MULI FND3 FND8 FND10 ASGI FND1 FND9 Linear form of ASGI &a &b&c &dMULI ADDIINDIRI Graphical Representation graphical representation

Code-Optimizing Transformations  Constant folding (1 + 2)  3 (100 > 0)  true  Copy propagation x = b + cx = b + c z = y * x z = y * (b + c)  Common subexpression x = b * c + 4t = b * c z = b * c - 1 x = t + 4 z = t - 1  Dead code elimination x = 1 x = b + cor if x is not referred to at all  

Code Optimization Example x = 1 y = a * b + 3 z = a * b +x + z + 2 x = 3 propagation x = 1 y = a * b + 3 z = a * b +1 + z +2 x = 3 constant folding x = 1 y = a * b + 3 z = a * b z x = 3 dead code elimination y =a * b + 3 z =a * b z x = 3 common subexpression t = a * b + 3 y = t z = t + z x = 3

Code Motion  Move code between basic blocks  E.g. move loop invariant computations outside of loops t = x / y while ( i < 100 ) {while ( i < 100 ) { *p = x / y + i*p = t + i i = i + 1i = i + 1}

Strength Reduction  Replace complex (and costly) expressions with simpler ones  E.g. a : = b*17a: = (b<<4) + b  E.g. p = & a[ i ] t = i * 100while ( i < 100 ) { a[ i ] = i * 100 *p = t i = i + 1t = t }p = p + 4 i = i + 1 } loop invariant: &a[i]==p, i*100==t

Induction Variable Elimination  Induction variables may become redundant  Test replacement instead p = & a[ i ] t = i * 100 while (i < 100) { *p = t i = i + 1 t = t p = p + 4 } p = & a[ i ] t = i * 100 while (p < limit) { *p = t i = i + 1 t = t p = p + 4 } limit = p i = 100

Importance of Loop Optimizations ProgramNo. of StaticDynamic% of LoopsB.B. CountB.B. CountTotal nasa M64% M72% M~100% matrix M98% M98+% tomcatv1726.1M50% M99+% M~100% Study of loop-intensive benchmarks in the SPEC92 suite [C.J. Newburn, 1991]

Loop Unrolling  Reduce loop overhead ­increment induction var ­loop condition test  Enlarged basic block (and analysis scope) ­Instruction-level parallelism ­More common subexpression ­Memory accesses (aggressive memory aliasing analysis) i = 1; while ( i < 100 ) { a[i] = b[i+1] + (i+1)/m b[i] = a[i-1] - i/m i = i + 1 } i = 1; while ( i < 100 ) { a[i] = b[i+1] + (i+1)/m b[i] = a[i-1] - i/m a[i+1] = b[i+2] + (i+2)/m b[i+1] = a[i] - (i+1)/m i = i + 2 }

Loop Unrolling vs. Loop Peeling common case

Software Pipelining i=0 while (i<99) { ;; a[ i ]=a[ i ]/10 x = a[ i ] y = x / 10 a[ i ] = y i++ } i=0 while (i<99) { x = a[ i ] y = x / 10 a[ i ] = y x = a[ i+1 ] y = x / 10 a[ i+1 ] = y x = a[ i+2 ] y = x / 10 a[ i+2 ] = y i=i+3 } i=0 y=a[ 0 ] / 10 x=a[ 1 ] while (i<97) { a[i]=y y=x / 10 x=a[i+2] i++ } a[97]=y a[98]=x / 10

Function inlining  Replace function calls with function body  Increase compilation scope (increase ILP) e.g. constant propagation, common subexpression  Reduce function call overhead e.g. passing arguments, reg. saves and restores [W.M. Hwu, 1991 (DEC 3100)] ProgramIn-line Speedupin-line Code Expansion cccp compress equ espresso lex tbl xlisp yacc

Back End IR Back End code selection code scheduling register allocation code emission Machine code Instruction-level IR map virtual registers into architect registers rearrange code target machine specific optimizations - delayed branch - conditional move - instruction combining auto increment addressing mode add carrying (PowerPC) hardware branch (PowerPC)