Optimizing Compilers Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.

Slides:



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

Optimizing Compilers for Modern Architectures Syllabus Allen and Kennedy, Preface Optimizing Compilers for Modern Architectures.
Synopsys University Courseware Copyright © 2012 Synopsys, Inc. All rights reserved. Compiler Optimization and Code Generation Lecture - 3 Developed By:
7. Optimization Prof. O. Nierstrasz Lecture notes by Marcus Denker.
Course Outline Traditional Static Program Analysis Software Testing
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.
CMPUT Compiler Design and Optimization1 CMPUT680 - Winter 2006 Topic 5: Peep Hole Optimization José Nelson Amaral
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
1 Chapter 8: Code Generation. 2 Generating Instructions from Three-address Code Example: D = (A*B)+C =* A B T1 =+ T1 C T2 = T2 D.
Code optimization: –A transformation to a program to make it run faster and/or take up less space –Optimization should be safe, preserve the meaning of.
Jeffrey D. Ullman Stanford University. 2  A never-published Stanford technical report by Fran Allen in  Fran won the Turing award in  Flow.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
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.
1 Really Basic Stuff Flow Graphs Constant Folding Global Common Subexpressions Induction Variables/Reduction in Strength.
1 CS 201 Compiler Construction Lecture 5 Code Optimizations: Copy Propagation & Elimination.
CS 536 Spring Intermediate Code. Local Optimizations. Lecture 22.
9. Optimization Marcus Denker. 2 © Marcus Denker Optimization Roadmap  Introduction  Optimizations in the Back-end  The Optimizer  SSA Optimizations.
CStar Optimizing a C Compiler
Code Generation Professor Yihjia Tsai Tamkang University.
Introduction to Program Optimizations Chapter 11 Mooly Sagiv.
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.
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
Improving Code Generation Honors Compilers April 16 th 2002.
Compiler Construction A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University Second Semester 2008/2009.
Machine-Independent Optimizations Ⅰ CS308 Compiler Theory1.
Compiler Code Optimizations. Introduction Introduction Optimized codeOptimized code Executes faster Executes faster efficient memory usage efficient memory.
5.3 Machine-Independent Compiler Features
Topic #10: Optimization EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
Introduction For some compiler, the intermediate code is a pseudo code of a virtual machine. Interpreter of the virtual machine is invoked to execute the.
What’s in an optimizing compiler?
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.
1 Code optimization “Code optimization refers to the techniques used by the compiler to improve the execution efficiency of the generated object code”
1 CS 201 Compiler Construction Introduction. 2 Instructor Information Rajiv Gupta Office: WCH Room Tel: (951) Office.
Compiler Principles Fall Compiler Principles Lecture 0: Local Optimizations Roman Manevich Ben-Gurion University.
Lexical analyzer Parser Semantic analyzer Intermediate-code generator Optimizer Code Generator Postpass optimizer String of characters String of tokens.
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Overview of Compilers and JikesRVM John.
Winter Compilers Software Eng. Dept. – Ort Braude Compiling Assignments and Expressions Lecturer: Esti Stein brd4.ort.org.il/~esti2.
Compiler Optimizations ECE 454 Computer Systems Programming Topics: The Role of the Compiler Common Compiler (Automatic) Code Optimizations Cristiana Amza.
3/2/2016© Hal Perkins & UW CSES-1 CSE P 501 – Compilers Optimizing Transformations Hal Perkins Autumn 2009.
CS412/413 Introduction to Compilers and Translators April 2, 1999 Lecture 24: Introduction to Optimization.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 10 Ahmed Ezzat.
Optimization Simone Campanoni
Code Optimization More Optimization Techniques. More Optimization Techniques  Loop optimization  Code motion  Strength reduction for induction variables.
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
High-level optimization Jakub Yaghob
Code Optimization.
Introduction to Advanced Topics Chapter 1 Text Book: Advanced compiler Design implementation By Steven S Muchnick (Elsevier)
Fall Compiler Principles Lecture 8: Loop Optimizations
Machine-Independent Optimization
Optimizing Transformations Hal Perkins Autumn 2011
Optimizing Transformations Hal Perkins Winter 2008
Compiler Code Optimizations
Code Optimization Overview and Examples Control Flow Graph
Fall Compiler Principles Lecture 10: Loop Optimizations
Optimization 薛智文 (textbook ch# 9) 薛智文 96 Spring.
Intermediate Code Generation
Loop Optimization “Programs spend 90% of time in loops”
Lecture 19: Code Optimisation
Tour of common optimizations
Tour of common optimizations
Tour of common optimizations
Code Optimization.
Presentation transcript:

Optimizing Compilers Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University

Content Introduction Control flow analysis Data flow analysis Program transformations Case studies

Introduction

Optimizing Compilers Compilers that apply code-improving transformations Must preserve the meaning of programs Must improve programs by a measurable amount Must be worth the effort

Levels of Code Optimization Source code level –profile programs, change algorithms, transform loops Intermediate code level –analyze programs, inline procedure calls, improve loops, eliminate common subexpressions Target code level –use machine characteristics, do peephole optimizations

Organization of an Optimizing Compiler Front end Code optimization –control flow analysis –data flow analysis –code transformation Code generation

Program Transformations Statement level –common-subexpression elimination, copy propagation, dead-code elimination, constant folding, constant propagation Loop level –code motion, reduction in strength, induction variable elimination Procedure level –inline expansion, tail recursion optimization

Common Subexpression Elimination a = b + c b = a - d c = b + c d = a - d a = a + c c = a - d a = b + c b = a - d c = b + c d = b a = a + c c = a - d

Copy Propagation a = b + c b = a - d c = b + c d = b a = a + c c = a - d a = b + c b = a - d c = b + c d = b a = a + c c = a - b

Dead-Code Elimination a = b + c b = a - d c = b + c d = b a = a + c c = a - b a = b + c b = a - d c = b + c a = a + c c = a - b

Constant Folding a = 4 * 2 b = a + 3 a = 8 b = a + 3

Constant Propagation a = 8 b = a + 3 a = 8 b = 8 + 3

Code Motion t = 4 * i b = a[t] i = i + 1 if i < n- 1 goto L i = 0 L: t = 4 * i b = a[t] i = i + 1 if i < f goto L i = 0 f = n - 1 L:

Reduction in Strength t = 4 * i b = a[t] i = i + 1 if i < f goto L i = 0 f = n - 1 t = t + 4 b = a[t] i = i + 1 if i < f goto L i = 0 f = n - 1 t = -4

Induction Variable Elimination t = t + 4 b = a[t] if t < 4 * f goto L i = 0 f = n - 1 t = -4 t = t + 4 b = a[t] i = i + 1 if i < f goto L i = 0 f = n - 1 t = -4

Inline Expansion p: a = c + d b = a + c param a param b call q, 2 c = d + e return q: d = sp[0] + sp[1] return p: a = c + d b = a + c d = a + b c = d + e return q: d = sp[0] + sp[1] return

Tail Recursion Optimization p: a = sp[0] + c b = sp[1] + d param a param b call p, 2 return p: a = sp[0] + c b = sp[1] + d sp[0] = a sp[1] = b goto p return