1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 36: Global Optimization, Loop Improvement and Profiling COMP 144 Programming Language.

Slides:



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

Code Optimization and Performance Chapter 5 CS 105 Tour of the Black Holes of Computing.
Compiler Support for Superscalar Processors. Loop Unrolling Assumption: Standard five stage pipeline Empty cycles between instructions before the result.
8. Static Single Assignment Form Marcus Denker. © Marcus Denker SSA Roadmap  Static Single Assignment Form (SSA)  Converting to SSA Form  Examples.
Synopsys University Courseware Copyright © 2012 Synopsys, Inc. All rights reserved. Compiler Optimization and Code Generation Lecture - 3 Developed By:
P3 / 2004 Register Allocation. Kostis Sagonas 2 Spring 2004 Outline What is register allocation Webs Interference Graphs Graph coloring Spilling Live-Range.
1 Optimizing compilers Managing Cache Bercovici Sivan.
1 Optimization Optimization = transformation that improves the performance of the target code Optimization must not change the output must not cause errors.
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.
19 Classic Examples of Local and Global Code Optimizations Local Constant folding Constant combining Strength reduction.
Carnegie Mellon Lecture 7 Instruction Scheduling I. Basic Block Scheduling II.Global Scheduling (for Non-Numeric Code) Reading: Chapter 10.3 – 10.4 M.
ECE 454 Computer Systems Programming Compiler and Optimization (I) Ding Yuan ECE Dept., University of Toronto
1 CS 201 Compiler Construction Machine Code Generation.
Computer Architecture Lecture 7 Compiler Considerations and Optimizations.
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 CS 201 Compiler Construction Lecture 7 Code Optimizations: Partial Redundancy Elimination.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 3: Lexical Analysis COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 12: Semantic Analysis COMP 144 Programming Language Concepts Spring 2002 Felix.
1 CS 201 Compiler Construction Lecture 5 Code Optimizations: Copy Propagation & Elimination.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 33: Code Generation and Linking COMP 144 Programming Language Concepts Spring 2002.
Recap from last time Saw several examples of optimizations –Constant folding –Constant Prop –Copy Prop –Common Sub-expression Elim –Partial Redundancy.
CS 536 Spring Intermediate Code. Local Optimizations. Lecture 22.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 31: Building a Runnable Program COMP 144 Programming Language Concepts Spring 2002.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 26: Introduction to Logic Programming with Prolog COMP 144 Programming Language.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 37: Beyond Sequential Programs COMP 144 Programming Language Concepts Spring 2002.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Parallel Programming in C with MPI and OpenMP Michael J. Quinn.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 32: The Java Virtual Machine COMP 144 Programming Language Concepts Spring 2002.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 5: Syntax Analysis COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos.
Introduction to Program Optimizations Chapter 11 Mooly Sagiv.
CS 412/413 Spring 2007Introduction to Compilers1 Lecture 29: Control Flow Analysis 9 Apr 07 CS412/413 Introduction to Compilers Tim Teitelbaum.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 38: Implementing Concurrency COMP 144 Programming Language Concepts Spring 2002.
CMPUT Compiler Design and Optimization1 CMPUT680 - Winter 2006 Topic B: Loop Restructuring José Nelson Amaral
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 34: Code Optimization COMP 144 Programming Language Concepts Spring 2002 Felix.
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
Wrapping Up Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
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:
Machine-Independent Optimizations Ⅰ CS308 Compiler Theory1.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 35: In-line Expansion and Local Optimization COMP 144 Programming Language Concepts.
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.
Copyright © 2005 Elsevier Chapter 15:: Code Improvement Programming Language Pragmatics Michael L. Scott.
Optimization software for apeNEXT Max Lukyanov,  apeNEXT : a VLIW architecture  Optimization basics  Software optimizer for apeNEXT  Current.
1 Code optimization “Code optimization refers to the techniques used by the compiler to improve the execution efficiency of the generated object code”
Lecture 4 TTH 03:30AM-04:45PM Dr. Jianjun Hu CSCE569 Parallel Computing University of South Carolina Department of.
More on Loop Optimization Data Flow Analysis CS 480.
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.
©SoftMoore ConsultingSlide 1 Code Optimization. ©SoftMoore ConsultingSlide 2 Code Optimization Code generation techniques and transformations that result.
Code Optimization Overview and Examples
High-level optimization Jakub Yaghob
Code Optimization.
Optimization Code Optimization ©SoftMoore Consulting.
Princeton University Spring 2016
Machine-Independent Optimization
Code Generation Part III
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
Code Optimization Overview and Examples Control Flow Graph
Code Generation Part III
Exam Topics Hal Perkins Autumn 2009
Introduction to Computer Science
Parallel Programming in C with MPI and OpenMP
Code Optimization.
Presentation transcript:

1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 36: Global Optimization, Loop Improvement and Profiling COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos April 22 The University of North Carolina at Chapel Hill

2 COMP 144 Programming Language Concepts Felix Hernandez-Campos Phases We will discuss very briefly global optimization techniques and loop improvementWe will discuss very briefly global optimization techniques and loop improvement

3 COMP 144 Programming Language Concepts Felix Hernandez-Campos Global Optimization Local optimization focuses on eliminating redundancies within basic blockLocal optimization focuses on eliminating redundancies within basic block Global optimization focuses on eliminating redundancies across the boundaries between basic blocksGlobal optimization focuses on eliminating redundancies across the boundaries between basic blocks –Static Single Assignment (SSA) form –Global value numbering

4 COMP 144 Programming Language Concepts Felix Hernandez-Campos Redundancy Elimination in Basic Blocks We will consider the example on the rightWe will consider the example on the right It computes the binomial coefficientsIt computes the binomial coefficients for 0  m  n It is based onIt is based on

5 COMP 144 Programming Language Concepts Felix Hernandez-Campos Naïve Control Flow Graph for the combinations subroutine

6 COMP 144 Programming Language Concepts Felix Hernandez-Campos Control Flow Graph for combinations after local redundancy elimination and strength reduction

7 COMP 144 Programming Language Concepts Felix Hernandez-Campos Global Optimization Control Flow Graph for combinations in Static Single Assignment (SSA) form Subscriptedvariables Selection Function  Block 2 is always entered from Block 3

8 COMP 144 Programming Language Concepts Felix Hernandez-Campos Control Flow Graph for combinations after global value numbering

9 COMP 144 Programming Language Concepts Felix Hernandez-Campos Global Optimization After global value numbering, data flow analysis is used to determine redundancies across block boundariesAfter global value numbering, data flow analysis is used to determine redundancies across block boundaries The main two tasks are common subexpression elimination and live variable analysisThe main two tasks are common subexpression elimination and live variable analysis

10 COMP 144 Programming Language Concepts Felix Hernandez-Campos Loop Improvement Programs spend most of their time in loopsPrograms spend most of their time in loops Consequently, it is particularly important to generate good code for loopsConsequently, it is particularly important to generate good code for loops Common techniques:Common techniques: –Relocate loop invariant expressions outside the loop –Reduce the amount of time spent maintaining induction variables (i.e., loop indexes) Advanced techniques:Advanced techniques: –Loop unrolling for improved instruction scheduling –Loop reordering for optimized cache access patterns and concurrent execution

11 COMP 144 Programming Language Concepts Felix Hernandez-Campos Memory Latency Is Critical There is a huge gap between memory latency and processor latency (including cache latency)There is a huge gap between memory latency and processor latency (including cache latency) It is critical to optimize the use of the cache to reduce as much as possible the number of memory accessesIt is critical to optimize the use of the cache to reduce as much as possible the number of memory accesses

12 COMP 144 Programming Language Concepts Felix Hernandez-Campos Optimization Programming language performance varies greatlyProgramming language performance varies greatly –The Great Computer Language Shootout » Programming language constructs within the same language may varies greatly in their performanceProgramming language constructs within the same language may varies greatly in their performance –Python Patterns - An Optimization Anecdote » –Time() » –Python Performance Tips »

13 COMP 144 Programming Language Concepts Felix Hernandez-Campos Reading Assignment Read ScottRead Scott –Sect –Rest of chapter 13 (only general ideas, no details)