Early Program Optimizations Chapter 12 Mooly Sagiv.

Slides:



Advertisements
Similar presentations
Show 5 apples and 3 bananas
Advertisements

Code Generation for Control Flow Mooly Sagiv Ohad Shacham Chapter 6.4.
7. Optimization Prof. O. Nierstrasz Lecture notes by Marcus Denker.
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
Jeffrey D. Ullman Stanford University. 2  A never-published Stanford technical report by Fran Allen in  Fran won the Turing award in  Flow.
Some Properties of SSA Mooly Sagiv. Outline Why is it called Static Single Assignment form What does it buy us? How much does it cost us? Open questions.
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.
ISBN Chapter 7 Expressions and Assignment Statements.
Chapter 7:: Data Types Programming Language Pragmatics
Optimization Compiler Baojian Hua
Introduction to Advanced Topics Chapter 1 Mooly Sagiv Schrierber
Early Global Program Optimizations Chapter Mooly Sagiv.
ISBN Chapter 7 Expressions and Assignment Statements.
CS 536 Spring Intermediate Code. Local Optimizations. Lecture 22.
4/23/09Prof. Hilfinger CS 164 Lecture 261 IL for Arrays & Local Optimizations Lecture 26 (Adapted from notes by R. Bodik and G. Necula)
Code Generation for Basic Blocks Introduction Mooly Sagiv html:// Chapter
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.
ISBN Chapter 7 Expressions and Assignment Statements.
ISBN Chapter 7 Expressions and Assignment Statements.
ISBN Lecture 07 Expressions and Assignment Statements.
Procedure Optimizations and Interprocedural Analysis Chapter 15, 19 Mooly Sagiv.
Copyright © 1998 by Addison -Wesley Longman, Inc. 1 Chapter 6 Arithmetic Expressions - Their evaluation was one of the motivations for the development.
1-1 University of Hail College of Computer Science and Engineering Department of computer Science and Software Engineering Course: ICS313: Fundamentals.
C H A P T E R S E V E N Expressions and Assignment Statements.
Compiler Chapter# 5 Intermediate code generation.
Advanced Compiler Design Early Optimizations. Introduction Constant expression evaluation (constant folding)  dataflow independent Scalar replacement.
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
Simplifying Algebraic Expressions Show 5 apples and 3 bananas Write the algebraic expression.
1 Code optimization “Code optimization refers to the techniques used by the compiler to improve the execution efficiency of the generated object code”
Chapter 9: Perl Programming Practical Extraction and Report Language Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
Arithmetic Expressions
Expressions and Assignment Statements
ISBN Chapter 7 Expressions and Assignment Statements.
Chapter 7 © 1998 by Addison -Wesley Longman, Inc Arithmetic Expressions - Their evaluation was one of the motivations for the development of the.
Chapter 7 Expressions and Assignment Statements. Outline Introduction Arithmetic Expressions Overloaded Operators Type Conversions Assignment Statements.
 2007 Pearson Education, Inc. All rights reserved C Structures, Unions, Bit Manipulations and Enumerations.
Lexical analyzer Parser Semantic analyzer Intermediate-code generator Optimizer Code Generator Postpass optimizer String of characters String of tokens.
Types(1). Lecture 52 Type(1)  A type is a collection of values and operations on those values. Integer type  values..., -2, -1, 0, 1, 2,...  operations.
ISBN Chapter 7 Expressions and Assignment Statements.
Data Types Declarations Expressions Data storage C++ Basics.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
March 31, ICE 1341 – Programming Languages (Lecture #11) In-Young Ko Programming Languages (ICE 1341) Lecture #11 Programming Languages (ICE 1341)
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Data Types (1) 1 Programming Languages – Principles and Practice by Kenneth C Louden.
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
7-1/27 Chapter 7 Expressions and Assignment Statements Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean.
More Code Generation and Optimization Pat Morin COMP 3002.
Expressions and Assignment Statements
Notes Over 1.2.
Code Optimization Code produced by compilation algorithms can often be improved (ideally optimized) in terms of run-time speed and the amount of memory.
7.2 Arithmetic Expressions
Expressions and Assignment Statements
Revision Lecture
Expressions and Assignment Statements
Enumeration Types and typedef
Interprocedural Analysis Chapter 19
Semantic Analysis Chapter 6.
Expressions and Assignment Statements
Arithmetic Expressions
Expressions and Assignment Statements
College of Computer Science and Engineering
Semantic Analysis Chapter 6.
Chapter 7 Expressions and Assignment Statements.
Chapter 7: Expressions and Assignment Statements Sangho Ha
Do Now Evaluate each algebraic expression for y = 3. 3y + y y
PRESENTED BY ADNAN M. UZAIR NOMAN
Assistant Professor Rabia Koser Dept. of Computer Applications
Presentation transcript:

Early Program Optimizations Chapter 12 Mooly Sagiv

Outline Constant Folding Scalar Replacement of Aggregates Algebraic Simplification and Reassociation Value Numbering –Basic blocks –Procedure based data flow analysis Sparse conditional constant propagation

Constant Folding Evaluate expressions with constant value inside basic blocks Invoked at all levels Computations need to be conducted according to target machine Need to take care of overflow exceptions –Very problematic in floating point arithmetic

Scalar replacement of aggregates Replace structure elements by scalars Very simple but not common Depends on aliasing Makes other optimizations applicable

typedef enum { APPLE, BANANA, ORANGE} VARIETY; typedef enum { LONG, ROUND} SHAPE; typedef struct fruit { VARIETY variety; SHAPE shape ; } FRUIT;

char * Red = “red”; char * Yellow = “yellow”; char * Orange = “orange”; char * color(FRUIT CurrentFruit); { switch (currentFruit->variety) { case APPLE: return Red; break; case BANANA: return Yellow; break; case ORANGE: return Orange; }} main() { FRUIT snack; snack.variety = APPLE; snack.shape = ROUND; printf(“%s\n”, color(&snack));} char * Red = “red”; char * Yellow = “yellow”; char * Orange = “orange”; main() { FRUIT snack; VARIETY t1; SHAPE t2; COLOR t3; t1 = APPLE; t2 = ROUND; switch (t1) { case APPLE: t3= Red; break; case BANANA: t3=Yellow; break; case ORANGE: t3=Orange; }} printf(“%s\n”, t3);}

char * Red = “red”; char * Yellow = “yellow”; char * Orange = “orange”; main() { FRUIT snack; VARIETY t1; SHAPE t2; COLOR t3; t1 = APPLE; t2 = ROUND; switch (t1) { case APPLE: t3= Red; break; case BANANA: t3=Yellow; break; case ORANGE: t3=Orange; }} printf(“%s\n”, t3);} main() { printf(“%s\n”, “red”);}

Algebraic Simplification and Reassociations Use algebraic properties of operators in basic block Invoked at all levels Convert (HIR, MIR, LIR) in a basic block into a tree  rewrite trees according to rules (in an efficient way) Mainly for integer and address arithmetic

0/1/false/true Simplification

Simplifying Unary Operators

Simplifying Shift Operators

Strength Reduction in Operators t  i *5 t  i shl 2 t  t +i t  i *7 t  i shl 3 t  t - i

Commutativity and Associativity

Algebraic Simplifications of Addressing Expressions Cannot raise overflow Important for array references Use canonizations Integrate with other optimizations

var a:array[lo1..hi1, lo2..hi2] of eltype; i, j: integer;... for j :=lo2 to hi2 do a[i,j] := b+a[i, j]; end

Algebraic Simplifications of Floating Point Expressions Almost always impossible Removal of type coercions can be done eps:=1.0 ; while eps+1.0>1.0 do oldeps := eps; eps := 0.5*eps; od

Summary Algebraic association and constant folding are useful Compiler need to take into account the exact semantics Example: Floating point –IEEE Standards, C, Fortran77, Ada, Java