Intra-procedural Data Flow Analysis Introduction

Size: px
Start display at page:

Download "Intra-procedural Data Flow Analysis Introduction"

Transcription

1 The Setting: Optimising Compilers The Essence of Program Analysis Reaching Definitions Analysis Intra-procedural Data Flow Analysis Introduction Hanne Riis Nielson and Flemming Nielson Informatics and Mathematical Modelling Technical University of Denmark c Hanne Riis Nielson & Flemming Nielson c HRN&FN (cf slide 2) October 23,

2 Copyright This set of transparencies is mainly based on Flemming Nielson, Hanne Riis Nielson, Chris Hankin: Principles of Program Analysis Springer, 1999; ISBN They may be used by instructors for presentations based on the book but may not be copied and distributed electronically or by other means A handout version with four slides per page may be used for producing paper copies of the slides for students; the students may be charged no fee beyond reasonable production cost The handout version of the transparancies is available from the webpage riis/ppahtm c HRN&FN (cf slide 2) October 23,

3 The Setting: Optimising Compilers The Setting: Optimising Compilers source program front intermediate back end representation end target code the programmer can: profile program change algorithm transform program beyond the compiler the compiler can: improve loops procedure calls address calculations architecture independent the compiler can: use registers instruction selection peephole optimisation architecture dependent c HRN&FN (cf slide 2) October 23,

4 The Setting: Optimising Compilers Criteria for Optimisations an optimisation must preserve the meaning of programs must not change the output for any input must not cause errors (eg division by 0) that were not present before an optimisation must speed up programs by a measurable amount occationally one optimise for space not every optimisation succeeds in improving every program occationally an optimisation may slow down a program slightly but this is acceptable as long as it improves the avarage speed up an optimisation must be worth the effort the additional time spend by the compiler must be repayed when running the target program c HRN&FN (cf slide 2) October 23,

5 The Setting: Optimising Compilers The Level of Optimisations source level: language dependent eg references to array elements give rise to redundant computations Pascal and Fortran programs cannot be optimised at the source levels C programs allow both kinds of references and can be optimised intermediate level: language and architecture independent source 1 source K 3 intermediate representation optimiser 3 architecture 1 architecture N target/low level: architecture dependent less likely to be portable c HRN&FN (cf slide 2) October 23,

6 The Setting: Optimising Compilers What Optimisations are Worthwhile? Folklore: most programs spend 90% of their execution time in 10% of the code Inner loops are good candidates Experiment, profiling, collect statistics, Build on other people s experience, see eg Steven S Muchnick: Advanced Compiler Design and Implementation Morgan Kaufmann, 1997 c HRN&FN (cf slide 2) October 23,

7 The Setting: Optimising Compilers Organisation of an Optimiser front optimiser back end end control data flow flow analysis analysis transformation aim: to discover the hierarchical flow of control aim: to determine information about data aim: to modify the program c HRN&FN (cf slide 2) October 23,

8 The Setting: Optimising Compilers Example Example (ack Reinhard Wilhelm) Base(A) m i Algol-like arrays: C-like arrays: n j i := 0; while i <= n do j := 0; while j <= m do A[i,j] := B[i,j] + C[i,j]; j := j+1 od; i := i+1 od i := 0; while i <= n do j := 0; while j <= m do temp := Base(A) + i * (m+1) + j; Cont(temp) := Cont(Base(B) + i * (m+1) + j) + Cont(Base(C) + i * (m+1) + j); j := j+1 od; i := i+1 od c HRN&FN (cf slide 2) October 23,

9 The Setting: Optimising Compilers Example Typical Optimisations Avoid redundant computations reuse available results move loop invariant computations out of loops Avoid superfluous computations results known not to be needed results known already at compile time i := 0; while i <= n do j := 0; while j <= m do temp := Base(A) + i * (m+1) + j; Cont(temp) := Cont(Base(B) + i * (m+1) + j) + Cont(Base(C) + i * (m+1) + j); j := j+1 od; i := i+1 od c HRN&FN (cf slide 2) October 23,

10 The Setting: Optimising Compilers Example Available Expressions Analysis i := 0; while i <= n do j := 0; while j <= m do temp := Base(A) + i*(m+1) + j; Cont(temp) := Cont(Base(B) + i*(m+1) + j) + Cont(Base(C) + i*(m+1) + j); j := j+1 od; i := i+1 od first computation re-computations Common subexpression elimination: t1 := i * (m+1) + j; temp := Base(A) + t1; Cont(temp) := Cont(Base(B)+t1) + Cont(Base(C)+t1); c HRN&FN (cf slide 2) October 23,

11 The Setting: Optimising Compilers Example Detection of Loop Invariants i := 0; while i <= n do j := 0; while j <= m do t1 := i * (m+1) + j; temp := Base(A) + t1; Cont(temp) := Cont(Base(B) + t1) + Cont(Base(C) + t1); j := j+1 od; i := i+1 od loop invariant Invariant code motion: t2 := i * (m+1); while j <= m do t1 := t2 + j; temp := Cont(temp) := j := od c HRN&FN (cf slide 2) October 23,

12 The Setting: Optimising Compilers Example Detection of Induction Variables i := 0; 2 while i <= n do j := 0; t2 := i * (m+1); while j <= m do t1 := t2 + j; temp := Base(A) + t1; Cont(temp) := Cont(Base(B) + t1) + Cont(Base(C) + t1); j := j+1 od; i := i+1 od induction variable Strength reduction: i := 0; t3 := 0; while i <= n do j := 0; t2 := t3; while j <= m do i := i + 1; t3 := t3 + (m+1) od od c HRN&FN (cf slide 2) October 23,

13 The Setting: Optimising Compilers Example Copy Analysis i := 0; t3 := 0; while i <= n do j := 0; t2 := t3; t2 = t3 while j <= m do t1 := t2 + j; temp := Base(A) + t1; Cont(temp) := Cont(Base(B) + t1) + Cont(Base(C) + t1); j := j+1 od; i := i+1; t3 := t3 + (m+1) od Copy propagation: while j <= m do t1 := t3 + j; temp := ; Cont(temp) := ; j := od c HRN&FN (cf slide 2) October 23,

14 The Setting: Optimising Compilers Example Live Variables Analysis i := 0; t3 := 0; while i <= n do dead variable j := 0; t2 := t3; while j <= m do t1 := t3 + j; temp := Base(A) + t1; Cont(temp) := Cont(Base(B) + t1) + Cont(Base(C) + t1); j := j+1 od; i := i+1; t3 := t3 + (m+1) od Dead code elimination: i := 0; t3 := 0; while i <= n do j := 0; while j <= m do t1 := t3 + j; temp := Base(A) + t1; Cont(temp) := Cont(Base(B) + t1) + Cont(Base(C) + t1); j := j+1 od; i := i+1; t3 := t3 + (m+1) od c HRN&FN (cf slide 2) October 23,

15 The Setting: Optimising Compilers Example Analyses and Transformations Data Flow Analysis Transformation Available expressions analysis Common subexpression elimination Detection of loop invariants Invariant code motion Detection of induction variables Strength reduction Copy analysis Copy propagation Live variables analysis Dead code elimination c HRN&FN (cf slide 2) October 23,

16 The Essence of Program Analysis The Essence of Program Analysis Program analysis offers techniques for predicting statically at compile-time safe & efficient approximations to the set of configurations or behaviours arising dynamically at run-time we cannot expect exact answers! Safe: faithful to the semantics Efficient: implementation with good time performance and low space consumption c HRN&FN (cf slide 2) October 23,

17 The Essence of Program Analysis The Nature of Approximation The exact world Over-approximation Under-approximation universe exact set of configurations or behaviours overapproximation underapproximation unacceptable! Slogans: Err on the safe side! Trade precision for efficiency! c HRN&FN (cf slide 2) October 23,

18 The Essence of Program Analysis Example Example Program with labels for elementary blocks: [y := x] 1 ; [z := 1] 2 ; while [y > 0] 3 do [z := z y] 4 ; Flow graph: [y := x] 1 [z := 1] 2 [y > 0] 3 [y := 0] 6 [y := y 1] 5 od; [z := z y] 4 [y := 0] 6 [y := y 1] 5 c HRN&FN (cf slide 2) October 23,

19 The Essence of Program Analysis Example Example: Reaching Definitions Analysis Problem: which definitions reach which program points For a simple while language: a definition of a variable x is an assignment [x := a] l to x The assignment [x := a] l reaches l if there is an execution where x was last assigned at l [y := x] 1 [z := 1] 2 [y > 0] 3 [z := z y] 4 [y := y 1] 5 [y := 0] 6 c HRN&FN (cf slide 2) October 23,

20 The Essence of Program Analysis Example Analysing the Program by Hand (1) [y := x] 1 ; [z := 1] 2 ; while [y > 0] 3 od; [z := z y] 4 ; do [y := y 1] 5 {(x,?), (y,?), (z,?)} {(x,?), (y, 1), (z,?)} {(x,?), (y, 1), (z, 2)} {(x,?), (y, 1), (z, 2)} [y := 0] 6 {(x,?), (y, 1), (z, 2)} c HRN&FN (cf slide 2) October 23,

21 The Essence of Program Analysis Example Analysing the Program by Hand (2) [y := x] 1 ; [z := 1] 2 ; while [y > 0] 3 do [z := z y] 4 ; {(x,?), (y,?), (z,?)} {(x,?), (y, 1), (z,?)} {(x,?), (y, 1), (z, 2)} {(y, 5), (z, 4)} {(x,?), (y, 1), (z, 2)} [y := y 1] 5 {(x,?), (y, 1), (z, 4)} od; {(x,?), (y, 5), (z, 4)} [y := 0] 6 {(x,?), (y, 1), (z, 2)} c HRN&FN (cf slide 2) October 23,

22 The Essence of Program Analysis Example Analysing the Program by Hand (3) [y := x] 1 ; [z := 1] 2 ; while [y > 0] 3 do [z := z y] 4 ; {(x,?), (y,?), (z,?)} {(x,?), (y, 1), (z,?)} {(x,?), (y, 1), (z, 2), (y, 5), (z, 4)} {(y, 5), (z, 4)} {(x,?), (y, 1), (z, 2), (y, 5), (z, 4)} [y := y 1] 5 {(x,?), (y, 1), (y, 5), (z, 4)} od; {(x,?), (y, 5), (z, 4)} [y := 0] 6 {(x,?), (y, 1), (z, 2), (y, 5), (z, 4)} {(x,?), (y, 6), (z, 2), (z, 4)} c HRN&FN (cf slide 2) October 23,

23 The Essence of Program Analysis Example The Best Solution [y := x] 1 ; [z := 1] 2 ; {(x,?), (y,?), (z,?)} {(x,?), (y, 1), (z,?)} while [y > 0] 3 do {(x,?), (y, 1), (z, 2), (y, 5), (z, 4)} [z := z y] 4 ; {(x,?), (y, 1), (z, 2), (y, 5), (z, 4)} [y := y 1] 5 {(x,?), (y, 1), (y, 5), (z, 4)} od; {(x,?), (y, 5), (z, 4)} [y := 0] 6 {(x,?), (y, 1), (z, 2), (y, 5), (z, 4)} {(x,?), (y, 6), (z, 2), (z, 4)} c HRN&FN (cf slide 2) October 23,

24 The Essence of Program Analysis Example A Safe Solution but not the Best [y := x] 1 ; [z := 1] 2 ; while [y > 0] 3 [z := z y] 4 ; do {(x,?), (y,?), (z,?)} {(x,?), (y, 1), (z,?)} {(x,?), (y, 1), (z, 2), (y, 5), (z, 4)} {(x,?), (y, 1), (z, 2), (y, 5), (z, 4)} [y := y 1] 5 {(x,?), (y, 1), (y, 5), (z,2), (z, 4)} od; {(x,?), (y,1), (y, 5), (z,2), (z, 4)} [y := 0] 6 {(x,?), (y, 1), (z, 2), (y, 5), (z, 4)} {(x,?), (y, 6), (z, 2), (z, 4)} c HRN&FN (cf slide 2) October 23,

25 The Essence of Program Analysis Example An Unsafe Solution [y := x] 1 ; [z := 1] 2 ; {(x,?), (y,?), (z,?)} {(x,?), (y, 1), (z,?)} while [y > 0] 3 do {(x,?), (y, 1), (z, 2), (y, 5), (z, 4)} [z := z y] 4 ; {(x,?), (y,1), (z,2), (y, 5), (z, 4)} [y := y 1] 5 {(x,?), (y,1), (y, 5), (z, 4)} od; {(x,?), (y, 5), (z, 4)} [y := 0] 6 {(x,?), (y,1), (z,2), (y, 5), (z, 4)} {(x,?), (y, 6), (z,2), (z, 4)} c HRN&FN (cf slide 2) October 23,

26 Formalising the development Formalising the Development Problem: which definitions reach which program points The assignment [x := a] l reaches l if there is an execution where x was last assigned at l extract compute the equations least solution from the program to the equations the programming language of interest abstract flow graphs extract and solve the equations c HRN&FN (cf slide 2) October 23,

27 Formalising the development The while language The While Language: a ::= x n a 1 op a a 2 b ::= true false not b b 1 op b b 2 a 1 op r a 2 S ::= [x := a] l [skip] l S 1 ; S 2 if [b] l then S 1 else S 2 while [b] l do S od Assignments and tests are (uniquely) labelled to allow the analyses to refer to these program fragments the labels corresponds to pointers into the syntax tree We use abstract syntax and insert paranthesis to disambiguate the syntax again this corresponds to thinking in terms of syntax trees OBS: the control structure is known there is no need for a control flow analysis! c HRN&FN (cf slide 2) October 23,

28 Formalising the development The while language Talking about Flow Graphs labels(s) init(s) final(s) flow(s) flow R (S) the set of nodes of the flow graphs of S the initial node of the flow graph of S; this is the unique node where the execution of the program starts the final nodes of the flow graphs for S; this is the set of nodes where the execution of the program may terminate the edges of the flow graphs for S; there is an edge from one node to another if the flow of control may go from the first node to the second used for forward analyses the reversed edges of the flow graphs of S; there is an edge from one node to another if the flow of control may go from the second node to the first used for backwards analyses c HRN&FN (cf slide 2) October 23,

29 Formalising the development The while language The Abstract Flow Graph Example: [z:=1] 1 ; while [x>0] 2 do [z:=z*y] 3 ; [x:=x-1] 4 od labels( ) = {1, 2, 3, 4} [z := 1] 1 init( ) = 1 final( ) = {2} flow( ) = {(1, 2), (2, 3), (3, 4), (4, 2)} [x > 0] 2 yes [z := z y] 3 no flow R ( ) = {(2, 1), (2, 4), (3, 2), (4, 3)} [x := x 1] 4 c HRN&FN (cf slide 2) October 23,

30 Formalising the development The while language Computing the Information (1) S labels(s) init(s) final(s) [x := a] l {l} l {l} [skip] l {l} l {l} S 1 ; S 2 labels(s 1 ) labels(s 2 ) init(s 1 ) final(s 2 ) if [b] l then S 1 {l} labels(s 1 ) l final(s 1 ) else S 2 labels(s 2 ) final(s 2 ) while [b] l do S od {l} labels(s) l {l} c HRN&FN (cf slide 2) October 23,

31 Formalising the development The while language Computing the Information (2) S flow(s) blocks(s) [x := a] l {[x := a] l } [skip] l {[skip] l } S 1 ; S 2 flow(s 1 ) flow(s 2 ) blocks(s 1 ) {(l, init(s 2 )) l final(s 1 )} blocks(s 2 ) if [b] l then S 1 flow(s 1 ) flow(s 2 ) {[b] l } blocks(s 1 ) else S 2 {(l, init(s 1 )), (l, init(s 2 ))} blocks(s 2 ) while [b] l do S od {(l, init(s))} flow(s) {[b] l } blocks(s) {(l, l) l final(s)} flow R (S) = {(l, l ) (l, l) flow(s)} c HRN&FN (cf slide 2) October 23,

32 Formalising the development The while language Simplifying assumptions The program of interest S is often assumed to satisfy: S has isolated entries if there are no edges leading into init(s ): l : (l, init(s )) / flow(s ) S has isolated exits if there are no edges leading out of labels in final(s ): S is label consistent if l final(s ), l : (l, l ) / flow(s ) [B l 1 1 ], [Bl 2 2 ] blocks(s ) : l 1 = l 2 B 1 = B 2 This holds if S is uniquely labelled c HRN&FN (cf slide 2) October 23,

33 Reaching Definitions Reaching Definitions Analysis The aim of the Reaching Definitions Analysis is to determine For each program point, which assignments may have been made and not overwritten, when program execution reaches this point along some path Example [y := x] 1 ; [z := 1] 2 ; while [y > 0] 3 do [z := z y] 4 ; [y := y 1] 5 od; [y := 0] 6 c HRN&FN (cf slide 2) October 23,

34 Reaching Definitions The Basic Idea RD (l) [x := a] l RD (l) Analysis information: [skip] l RD (l) RD (l) [b] l RD (l) RD (l) RD (l): the definitions that reach the entry of block l RD (l): the definitions that reach the exit of block l Auxiliary information: kill RD (l): the definitions that are killed by an elementary block gen RD (l): the definitions that are generated by an elementary block c HRN&FN (cf slide 2) October 23,

35 Reaching Definitions Analysis of the program RD (l) [x := a] l RD (l) [] l 1 [] l k [] l RD (l 1 ) RD (l k ) RD (l) RD (l) = (RD (l)\kill RD (B l )) gen RD (B l ) if B l blocks(s ) {(x,?) x FV(S )} if l = init(s ) RD (l) = {RD (l ) (l, l) flow(s )} otherwise kill RD ([x := a] l ) = {(x,?)} {(x, l ) B l is an assignment to x} gen RD ([x := a] l ) = {(x, l)} kill RD (B l ) = gen RD (B l ) = otherwise c HRN&FN (cf slide 2) October 23,

36 Reaching Definitions Example Example [y := x] 1 ; [z := 1] 2 ; while [y > 0] 3 do [z := z y] 4 ; [y := y 1] 5 od; [y := 0] 6 Equations: RD (1) = RD (1) \ {(y,?), (y, 1), (y, 5), (y, 6)} {(y, 1)} RD (2) = RD (2) \ {(z,?), (z, 2), (z, 4)} {(z, 2)} RD (3) = RD (3) \ RD (4) = RD (4) \ {(z,?), (z, 2), (z, 4)} {(z, 4)} RD (5) = RD (5) \ {(y,?), (y, 1), (y, 5), (y, 6)} {(y, 5)} RD (6) = RD (6) \ {(y,?), (y, 1), (y, 5), (y, 6)} {(y, 6)} RD (1) = {(x,?), (y,?), (z,?)} RD (2) = RD (1) RD (3) = RD (2) RD (5) RD (4) = RD (3) RD (5) = RD (4) RD (6) = RD (3) Compute the least solution to these equations c HRN&FN (cf slide 2) October 23,

37 Reaching Definitions Example Solving the equations 1 W := nil; for all (l, l ) in flow(s ) do W := cons((l, l ),W); for all l in labels(s ) do if l = init(s ) then RD (l) := {(x,?) x FV(S )} else RD (l) := 2 while W nil do (l, l ) := head(w); W := tail(w); if (RD (l) \ kill RD (l)) gen RD (l) }{{} RD (l) RD (l ) then RD (l ) := RD (l ) (RD (l) \ kill RD (l)) gen RD (l); }{{} RD (l) for all l with (l, l ) in flow(s ) do W := cons((l, l ),W); c HRN&FN (cf slide 2) October 23,

Principles of Program Analysis: A Sampler of Approaches

Principles of Program Analysis: A Sampler of Approaches Principles of Program Analysis: A Sampler of Approaches Transparencies based on Chapter 1 of the book: Flemming Nielson, Hanne Riis Nielson and Chris Hankin: Principles of Program Analysis Springer Verlag

More information

Principles of Program Analysis: Data Flow Analysis

Principles of Program Analysis: Data Flow Analysis Principles of Program Analysis: Data Flow Analysis Transparencies based on Chapter 2 of the book: Flemming Nielson, Hanne Riis Nielson and Chris Hankin: Principles of Program Analysis. Springer Verlag

More information

Static Program Analysis

Static Program Analysis Static Program Analysis Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-18/spa/ Preliminaries Outline of Lecture 1 Preliminaries Introduction

More information

Loop Optimizations. Outline. Loop Invariant Code Motion. Induction Variables. Loop Invariant Code Motion. Loop Invariant Code Motion

Loop Optimizations. Outline. Loop Invariant Code Motion. Induction Variables. Loop Invariant Code Motion. Loop Invariant Code Motion Outline Loop Optimizations Induction Variables Recognition Induction Variables Combination of Analyses Copyright 2010, Pedro C Diniz, all rights reserved Students enrolled in the Compilers class at the

More information

Static Program Analysis

Static Program Analysis Static Program Analysis Lecture 1: Introduction to Program Analysis Thomas Noll Lehrstuhl für Informatik 2 (Software Modeling and Verification) noll@cs.rwth-aachen.de http://moves.rwth-aachen.de/teaching/ws-1415/spa/

More information

Program Analysis And Its Support in Software Development

Program Analysis And Its Support in Software Development Program Analysis And Its Support in Software Development Qing Yi class web site: www.cs.utsa.edu/~qingyi/cs6463 cs6463 1 A little about myself Qing Yi B.S. Shandong University, China. Ph.D. Rice University,

More information

COP5621 Exam 4 - Spring 2005

COP5621 Exam 4 - Spring 2005 COP5621 Exam 4 - Spring 2005 Name: (Please print) Put the answers on these sheets. Use additional sheets when necessary. Show how you derived your answer when applicable (this is required for full credit

More information

Code optimization. Have we achieved optimal code? Impossible to answer! We make improvements to the code. Aim: faster code and/or less space

Code optimization. Have we achieved optimal code? Impossible to answer! We make improvements to the code. Aim: faster code and/or less space Code optimization Have we achieved optimal code? Impossible to answer! We make improvements to the code Aim: faster code and/or less space Types of optimization machine-independent In source code or internal

More information

Static analysis and all that

Static analysis and all that Static analysis and all that Martin Steffen IfI UiO Spring 2014 uio Static analysis and all that Martin Steffen IfI UiO Spring 2014 uio Plan approx. 15 lectures, details see web-page flexible time-schedule,

More information

Data Flow Analysis using Program Graphs

Data Flow Analysis using Program Graphs Data Flow Analysis using Program Graphs Michal Terepeta Supervised by Professor Hanne Riis Nielson Professor Andrzej Napieralski Kongens Lyngby 2010 Technical University of Denmark Informatics and Mathematical

More information

COMS W4115 Programming Languages and Translators Lecture 21: Code Optimization April 15, 2013

COMS W4115 Programming Languages and Translators Lecture 21: Code Optimization April 15, 2013 1 COMS W4115 Programming Languages and Translators Lecture 21: Code Optimization April 15, 2013 Lecture Outline 1. Code optimization strategies 2. Peephole optimization 3. Common subexpression elimination

More information

USC 227 Office hours: 3-4 Monday and Wednesday CS553 Lecture 1 Introduction 4

USC 227 Office hours: 3-4 Monday and Wednesday  CS553 Lecture 1 Introduction 4 CS553 Compiler Construction Instructor: URL: Michelle Strout mstrout@cs.colostate.edu USC 227 Office hours: 3-4 Monday and Wednesday http://www.cs.colostate.edu/~cs553 CS553 Lecture 1 Introduction 3 Plan

More information

Tour of common optimizations

Tour of common optimizations Tour of common optimizations Simple example foo(z) { x := 3 + 6; y := x 5 return z * y } Simple example foo(z) { x := 3 + 6; y := x 5; return z * y } x:=9; Applying Constant Folding Simple example foo(z)

More information

Comp 204: Computer Systems and Their Implementation. Lecture 22: Code Generation and Optimisation

Comp 204: Computer Systems and Their Implementation. Lecture 22: Code Generation and Optimisation Comp 204: Computer Systems and Their Implementation Lecture 22: Code Generation and Optimisation 1 Today Code generation Three address code Code optimisation Techniques Classification of optimisations

More information

MIT Introduction to Program Analysis and Optimization. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology

MIT Introduction to Program Analysis and Optimization. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology MIT 6.035 Introduction to Program Analysis and Optimization Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Program Analysis Compile-time reasoning about run-time behavior

More information

Machine-Independent Optimizations

Machine-Independent Optimizations Chapter 9 Machine-Independent Optimizations High-level language constructs can introduce substantial run-time overhead if we naively translate each construct independently into machine code. This chapter

More information

Compiler Optimization and Code Generation

Compiler Optimization and Code Generation Compiler Optimization and Code Generation Professor: Sc.D., Professor Vazgen Melikyan 1 Course Overview Introduction: Overview of Optimizations 1 lecture Intermediate-Code Generation 2 lectures Machine-Independent

More information

CS 701. Class Meets. Instructor. Teaching Assistant. Key Dates. Charles N. Fischer. Fall Tuesdays & Thursdays, 11:00 12: Engineering Hall

CS 701. Class Meets. Instructor. Teaching Assistant. Key Dates. Charles N. Fischer. Fall Tuesdays & Thursdays, 11:00 12: Engineering Hall CS 701 Charles N. Fischer Class Meets Tuesdays & Thursdays, 11:00 12:15 2321 Engineering Hall Fall 2003 Instructor http://www.cs.wisc.edu/~fischer/cs703.html Charles N. Fischer 5397 Computer Sciences Telephone:

More information

Data Flow Analysis. Agenda CS738: Advanced Compiler Optimizations. 3-address Code Format. Assumptions

Data Flow Analysis. Agenda CS738: Advanced Compiler Optimizations. 3-address Code Format. Assumptions Agenda CS738: Advanced Compiler Optimizations Data Flow Analysis Amey Karkare karkare@cse.iitk.ac.in http://www.cse.iitk.ac.in/~karkare/cs738 Department of CSE, IIT Kanpur Static analysis and compile-time

More information

CSE 501: Compiler Construction. Course outline. Goals for language implementation. Why study compilers? Models of compilation

CSE 501: Compiler Construction. Course outline. Goals for language implementation. Why study compilers? Models of compilation CSE 501: Compiler Construction Course outline Main focus: program analysis and transformation how to represent programs? how to analyze programs? what to analyze? how to transform programs? what transformations

More information

Chapter 1 Introduction

Chapter 1 Introduction Chapter 1 Course INF5906 / autum 2017 Chapter 1 Learning Targets of Chapter. Apart from a motivational introduction, the chapter gives a high-level overview over larger topics covered in the lecture. They

More information

Compiler Passes. Optimization. The Role of the Optimizer. Optimizations. The Optimizer (or Middle End) Traditional Three-pass Compiler

Compiler Passes. Optimization. The Role of the Optimizer. Optimizations. The Optimizer (or Middle End) Traditional Three-pass Compiler Compiler Passes Analysis of input program (front-end) character stream Lexical Analysis Synthesis of output program (back-end) Intermediate Code Generation Optimization Before and after generating machine

More information

Code Optimization. Code Optimization

Code Optimization. Code Optimization 161 Code Optimization Code Optimization 162 Two steps: 1. Analysis (to uncover optimization opportunities) 2. Optimizing transformation Optimization: must be semantically correct. shall improve program

More information

Goals of Program Optimization (1 of 2)

Goals of Program Optimization (1 of 2) Goals of Program Optimization (1 of 2) Goal: Improve program performance within some constraints Ask Three Key Questions for Every Optimization 1. Is it legal? 2. Is it profitable? 3. Is it compile-time

More information

COMPILER DESIGN - CODE OPTIMIZATION

COMPILER DESIGN - CODE OPTIMIZATION COMPILER DESIGN - CODE OPTIMIZATION http://www.tutorialspoint.com/compiler_design/compiler_design_code_optimization.htm Copyright tutorialspoint.com Optimization is a program transformation technique,

More information

Data Flow Analysis. Program Analysis

Data Flow Analysis. Program Analysis Program Analysis https://www.cse.iitb.ac.in/~karkare/cs618/ Data Flow Analysis Amey Karkare Dept of Computer Science and Engg IIT Kanpur Visiting IIT Bombay karkare@cse.iitk.ac.in karkare@cse.iitb.ac.in

More information

Why Global Dataflow Analysis?

Why Global Dataflow Analysis? Why Global Dataflow Analysis? Answer key questions at compile-time about the flow of values and other program properties over control-flow paths Compiler fundamentals What defs. of x reach a given use

More information

Thursday, December 23, The attack model: Static Program Analysis

Thursday, December 23, The attack model: Static Program Analysis The attack model: Static Program Analysis How making SPA? DFA - Data Flow Analysis CFA - Control Flow Analysis Proving invariance: theorem proving Checking models: model checking Giaco & Ranzato DFA:

More information

Languages and Compiler Design II IR Code Optimization

Languages and Compiler Design II IR Code Optimization Languages and Compiler Design II IR Code Optimization Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring 2010 rev.: 4/16/2010 PSU CS322 HM 1 Agenda IR Optimization

More information

Compiler Optimization Techniques

Compiler Optimization Techniques Compiler Optimization Techniques Department of Computer Science, Faculty of ICT February 5, 2014 Introduction Code optimisations usually involve the replacement (transformation) of code from one sequence

More information

Semantics with Applications 3. More on Operational Semantics

Semantics with Applications 3. More on Operational Semantics Semantics with Applications 3. More on Operational Semantics Hanne Riis Nielson, Flemming Nielson (thanks to Henrik Pilegaard) [SwA] Hanne Riis Nielson, Flemming Nielson Semantics with Applications: An

More information

Compiler Structure. Data Flow Analysis. Control-Flow Graph. Available Expressions. Data Flow Facts

Compiler Structure. Data Flow Analysis. Control-Flow Graph. Available Expressions. Data Flow Facts Compiler Structure Source Code Abstract Syntax Tree Control Flow Graph Object Code CMSC 631 Program Analysis and Understanding Fall 2003 Data Flow Analysis Source code parsed to produce AST AST transformed

More information

Resource-aware Computing Lecture 1- Grading, Rules and Introduction

Resource-aware Computing Lecture 1- Grading, Rules and Introduction Resource-aware Computing Lecture 1- Grading, Rules and Introduction Grading Seminar activity (4 assignments) :-50% 1. Oral Presentation of a given Research Paper: - 10% 2. Three written essays (after each

More information

More Dataflow Analysis

More Dataflow Analysis More Dataflow Analysis Steps to building analysis Step 1: Choose lattice Step 2: Choose direction of dataflow (forward or backward) Step 3: Create transfer function Step 4: Choose confluence operator (i.e.,

More information

Compiler Optimisation

Compiler Optimisation Compiler Optimisation 3 Dataflow Analysis Hugh Leather IF 1.18a hleather@inf.ed.ac.uk Institute for Computing Systems Architecture School of Informatics University of Edinburgh 2018 Introduction Optimisations

More information

Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Module No. # 10 Lecture No. # 16 Machine-Independent Optimizations Welcome to the

More information

Compiler Construction 2010/2011 Loop Optimizations

Compiler Construction 2010/2011 Loop Optimizations Compiler Construction 2010/2011 Loop Optimizations Peter Thiemann January 25, 2011 Outline 1 Loop Optimizations 2 Dominators 3 Loop-Invariant Computations 4 Induction Variables 5 Array-Bounds Checks 6

More information

A main goal is to achieve a better performance. Code Optimization. Chapter 9

A main goal is to achieve a better performance. Code Optimization. Chapter 9 1 A main goal is to achieve a better performance Code Optimization Chapter 9 2 A main goal is to achieve a better performance source Code Front End Intermediate Code Code Gen target Code user Machineindependent

More information

Advanced Compiler Construction

Advanced Compiler Construction Advanced Compiler Construction Qing Yi class web site: www.cs.utsa.edu/~qingyi/cs6363 cs6363 1 A little about myself Qing Yi Ph.D. Rice University, USA. Assistant Professor, Department of Computer Science

More information

PROGRAM ANALYSIS & SYNTHESIS

PROGRAM ANALYSIS & SYNTHESIS Lecture 02 Structural Operational Semantics (SOS) PROGRAM ANALYSIS & SYNTHESIS EranYahav 1 Previously static analysis over-approximation of program behavior abstract interpretation abstraction, transformers,

More information

Compiler Design and Construction Optimization

Compiler Design and Construction Optimization Compiler Design and Construction Optimization Generating Code via Macro Expansion Macroexpand each IR tuple or subtree A := B+C; D := A * C; lw $t0, B, lw $t1, C, add $t2, $t0, $t1 sw $t2, A lw $t0, A

More information

Office Hours: Mon/Wed 3:30-4:30 GDC Office Hours: Tue 3:30-4:30 Thu 3:30-4:30 GDC 5.

Office Hours: Mon/Wed 3:30-4:30 GDC Office Hours: Tue 3:30-4:30 Thu 3:30-4:30 GDC 5. CS380C Compilers Instructor: TA: lin@cs.utexas.edu Office Hours: Mon/Wed 3:30-4:30 GDC 5.512 Jia Chen jchen@cs.utexas.edu Office Hours: Tue 3:30-4:30 Thu 3:30-4:30 GDC 5.440 January 21, 2015 Introduction

More information

CS153: Compilers Lecture 15: Local Optimization

CS153: Compilers Lecture 15: Local Optimization CS153: Compilers Lecture 15: Local Optimization Stephen Chong https://www.seas.harvard.edu/courses/cs153 Announcements Project 4 out Due Thursday Oct 25 (2 days) Project 5 out Due Tuesday Nov 13 (21 days)

More information

Compiler Construction 2016/2017 Loop Optimizations

Compiler Construction 2016/2017 Loop Optimizations Compiler Construction 2016/2017 Loop Optimizations Peter Thiemann January 16, 2017 Outline 1 Loops 2 Dominators 3 Loop-Invariant Computations 4 Induction Variables 5 Array-Bounds Checks 6 Loop Unrolling

More information

Usually, target code is semantically equivalent to source code, but not always!

Usually, target code is semantically equivalent to source code, but not always! What is a Compiler? Compiler A program that translates code in one language (source code) to code in another language (target code). Usually, target code is semantically equivalent to source code, but

More information

Functional programming languages

Functional programming languages Functional programming languages Part V: functional intermediate representations Xavier Leroy INRIA Paris-Rocquencourt MPRI 2-4, 2015 2017 X. Leroy (INRIA) Functional programming languages MPRI 2-4, 2015

More information

Compiler Optimization

Compiler Optimization Compiler Optimization The compiler translates programs written in a high-level language to assembly language code Assembly language code is translated to object code by an assembler Object code modules

More information

PRINCIPLES OF COMPILER DESIGN

PRINCIPLES OF COMPILER DESIGN PRINCIPLES OF COMPILER DESIGN 2 MARK QUESTIONS WITH ANSWERS UNIT I 1. What is a Complier? A Complier is a program that reads a program written in one language-the source language-and translates it in to

More information

Introduction to Parsing

Introduction to Parsing Introduction to Parsing The Front End Source code Scanner tokens Parser IR Errors Parser Checks the stream of words and their parts of speech (produced by the scanner) for grammatical correctness Determines

More information

CS 2461: Computer Architecture 1

CS 2461: Computer Architecture 1 Next.. : Computer Architecture 1 Performance Optimization CODE OPTIMIZATION Code optimization for performance A quick look at some techniques that can improve the performance of your code Rewrite code

More information

Applications of Program analysis in Model-Based Design

Applications of Program analysis in Model-Based Design Applications of Program analysis in Model-Based Design Prahlad Sampath (Prahlad.Sampath@mathworks.com) 2018 by The MathWorks, Inc., MATLAB, Simulink, Stateflow, are registered trademarks of The MathWorks,

More information

Dataflow Analysis. Xiaokang Qiu Purdue University. October 17, 2018 ECE 468

Dataflow Analysis. Xiaokang Qiu Purdue University. October 17, 2018 ECE 468 Dataflow Analysis Xiaokang Qiu Purdue University ECE 468 October 17, 2018 Program optimizations So far we have talked about different kinds of optimizations Peephole optimizations Local common sub-expression

More information

The View from 35,000 Feet

The View from 35,000 Feet The View from 35,000 Feet This lecture is taken directly from the Engineering a Compiler web site with only minor adaptations for EECS 6083 at University of Cincinnati Copyright 2003, Keith D. Cooper,

More information

Introduction to Compilers

Introduction to Compilers Introduction to Compilers Compilers are language translators input: program in one language output: equivalent program in another language Introduction to Compilers Two types Compilers offline Data Program

More information

What Do Compilers Do? How Can the Compiler Improve Performance? What Do We Mean By Optimization?

What Do Compilers Do? How Can the Compiler Improve Performance? What Do We Mean By Optimization? What Do Compilers Do? Lecture 1 Introduction I What would you get out of this course? II Structure of a Compiler III Optimization Example Reference: Muchnick 1.3-1.5 1. Translate one language into another

More information

Data-flow Analysis. Y.N. Srikant. Department of Computer Science and Automation Indian Institute of Science Bangalore

Data-flow Analysis. Y.N. Srikant. Department of Computer Science and Automation Indian Institute of Science Bangalore Department of Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Compiler Design Data-flow analysis These are techniques that derive information about the flow

More information

CS 6353 Compiler Construction, Homework #3

CS 6353 Compiler Construction, Homework #3 CS 6353 Compiler Construction, Homework #3 1. Consider the following attribute grammar for code generation regarding array references. (Note that the attribute grammar is the same as the one in the notes.

More information

Lecture Notes on Loop-Invariant Code Motion

Lecture Notes on Loop-Invariant Code Motion Lecture Notes on Loop-Invariant Code Motion 15-411: Compiler Design André Platzer Lecture 17 1 Introduction In this lecture we discuss an important instance of Partial Redundancy Elimination (PRE) and

More information

Building a Runnable Program and Code Improvement. Dario Marasco, Greg Klepic, Tess DiStefano

Building a Runnable Program and Code Improvement. Dario Marasco, Greg Klepic, Tess DiStefano Building a Runnable Program and Code Improvement Dario Marasco, Greg Klepic, Tess DiStefano Building a Runnable Program Review Front end code Source code analysis Syntax tree Back end code Target code

More information

Lecture Compiler Middle-End

Lecture Compiler Middle-End Lecture 16-18 18 Compiler Middle-End Jianwen Zhu Electrical and Computer Engineering University of Toronto Jianwen Zhu 2009 - P. 1 What We Have Done A lot! Compiler Frontend Defining language Generating

More information

ECE468 Fall 2003, Final Exam

ECE468 Fall 2003, Final Exam Name ECE468 Fall 2003, Final Exam This test has 9 pages and 9 questions. When told to begin please check to make sure you have all 9 pages. Let us know immediately if it doesn t. This test is open book

More information

Loops. Lather, Rinse, Repeat. CS4410: Spring 2013

Loops. Lather, Rinse, Repeat. CS4410: Spring 2013 Loops or Lather, Rinse, Repeat CS4410: Spring 2013 Program Loops Reading: Appel Ch. 18 Loop = a computation repeatedly executed until a terminating condition is reached High-level loop constructs: While

More information

Constraint Based Analysis

Constraint Based Analysis Seminar Constraint Based Analysis Toni Suter Fall Term 2014 Supervised by Prof. Peter Sommerlad Abstract Static program analysis is used in compilers and refactoring tools as a means to examine the structure

More information

EECS 6083 Intro to Parsing Context Free Grammars

EECS 6083 Intro to Parsing Context Free Grammars EECS 6083 Intro to Parsing Context Free Grammars Based on slides from text web site: Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. 1 Parsing sequence of tokens parser

More information

Introduction to Machine-Independent Optimizations - 1

Introduction to Machine-Independent Optimizations - 1 Introduction to Machine-Independent Optimizations - 1 Department of Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler Design Outline of

More information

Static Analysis for Systems Biology

Static Analysis for Systems Biology Static Analysis for Systems Biology Flemming Nielson, Hanne Riis Nielson Technical University of enmark Corrado Priami, ebora Schuch da Rosa University of Trento Abstract This paper shows how static analysis

More information

Code generation and local optimization

Code generation and local optimization Code generation and local optimization Generating assembly How do we convert from three-address code to assembly? Seems easy! But easy solutions may not be the best option What we will cover: Instruction

More information

Lecture Notes on Liveness Analysis

Lecture Notes on Liveness Analysis Lecture Notes on Liveness Analysis 15-411: Compiler Design Frank Pfenning André Platzer Lecture 4 1 Introduction We will see different kinds of program analyses in the course, most of them for the purpose

More information

Supercomputing in Plain English Part IV: Henry Neeman, Director

Supercomputing in Plain English Part IV: Henry Neeman, Director Supercomputing in Plain English Part IV: Henry Neeman, Director OU Supercomputing Center for Education & Research University of Oklahoma Wednesday September 19 2007 Outline! Dependency Analysis! What is

More information

8 Optimisation. 8.2 Machine-Independent Optimisation

8 Optimisation. 8.2 Machine-Independent Optimisation 8 8.2 Machine-Independent 8.2.4 Replacing binary with Unary operations Replacing binary with Unary operators The following operations do not produce redundant quads: a=c-d; 1. (-, c, d, t1) b=d-c; => 2.

More information

Parsing II Top-down parsing. Comp 412

Parsing II Top-down parsing. Comp 412 COMP 412 FALL 2018 Parsing II Top-down parsing Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled

More information

Compiler Design. Fall Control-Flow Analysis. Prof. Pedro C. Diniz

Compiler Design. Fall Control-Flow Analysis. Prof. Pedro C. Diniz Compiler Design Fall 2015 Control-Flow Analysis Sample Exercises and Solutions Prof. Pedro C. Diniz USC / Information Sciences Institute 4676 Admiralty Way, Suite 1001 Marina del Rey, California 90292

More information

Overview of a Compiler

Overview of a Compiler High-level View of a Compiler Overview of a Compiler Compiler Copyright 2010, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern California have

More information

Symbolic Solver for Live Variable Analysis of High Level Design Languages

Symbolic Solver for Live Variable Analysis of High Level Design Languages Symbolic Solver for Live Variable Analysis of High Level Design Languages Debasish Das Department of EECS Northwestern University, USA dda902@ece.northwestern.edu ABSTRACT This paper presents an efficient

More information

Code generation and local optimization

Code generation and local optimization Code generation and local optimization Generating assembly How do we convert from three-address code to assembly? Seems easy! But easy solutions may not be the best option What we will cover: Instruction

More information

Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES ( ) (ODD) Code Optimization

Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES ( ) (ODD) Code Optimization Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES (2018-19) (ODD) Code Optimization Prof. Jonita Roman Date: 30/06/2018 Time: 9:45 to 10:45 Venue: MCA

More information

Middle End. Code Improvement (or Optimization) Analyzes IR and rewrites (or transforms) IR Primary goal is to reduce running time of the compiled code

Middle End. Code Improvement (or Optimization) Analyzes IR and rewrites (or transforms) IR Primary goal is to reduce running time of the compiled code Traditional Three-pass Compiler Source Code Front End IR Middle End IR Back End Machine code Errors Code Improvement (or Optimization) Analyzes IR and rewrites (or transforms) IR Primary goal is to reduce

More information

Optimization Prof. James L. Frankel Harvard University

Optimization Prof. James L. Frankel Harvard University Optimization Prof. James L. Frankel Harvard University Version of 4:24 PM 1-May-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reasons to Optimize Reduce execution time Reduce memory

More information

Group B Assignment 8. Title of Assignment: Problem Definition: Code optimization using DAG Perquisite: Lex, Yacc, Compiler Construction

Group B Assignment 8. Title of Assignment: Problem Definition: Code optimization using DAG Perquisite: Lex, Yacc, Compiler Construction Group B Assignment 8 Att (2) Perm(3) Oral(5) Total(10) Sign Title of Assignment: Code optimization using DAG. 8.1.1 Problem Definition: Code optimization using DAG. 8.1.2 Perquisite: Lex, Yacc, Compiler

More information

A Bad Name. CS 2210: Optimization. Register Allocation. Optimization. Reaching Definitions. Dataflow Analyses 4/10/2013

A Bad Name. CS 2210: Optimization. Register Allocation. Optimization. Reaching Definitions. Dataflow Analyses 4/10/2013 A Bad Name Optimization is the process by which we turn a program into a better one, for some definition of better. CS 2210: Optimization This is impossible in the general case. For instance, a fully optimizing

More information

Lecture Notes on Loop Optimizations

Lecture Notes on Loop Optimizations Lecture Notes on Loop Optimizations 15-411: Compiler Design Frank Pfenning Lecture 17 October 22, 2013 1 Introduction Optimizing loops is particularly important in compilation, since loops (and in particular

More information

CS415 Compilers. Syntax Analysis. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

CS415 Compilers. Syntax Analysis. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University CS415 Compilers Syntax Analysis These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Limits of Regular Languages Advantages of Regular Expressions

More information

INSTITUTE OF AERONAUTICAL ENGINEERING (AUTONOMOUS)

INSTITUTE OF AERONAUTICAL ENGINEERING (AUTONOMOUS) Name Code Class Branch INSTITUTE OF AERONAUTICAL ENGINEERING (AUTONOMOUS) Dundigal, Hyderabad - 500 043 Year 0-0 INFORMATION TECHNOLOGY ASSIGNMENT QUESTIONS AUTOMATA AND COMPILER DESIGN A50513 III B. Tech

More information

Lecture 9: Loop Invariant Computation and Code Motion

Lecture 9: Loop Invariant Computation and Code Motion Lecture 9: Loop Invariant Computation and Code Motion I. Loop-invariant computation II. III. Algorithm for code motion Partial redundancy elimination ALSU 9.5-9.5.2 Phillip B. Gibbons 15-745: Loop Invariance

More information

Loop Transformations! Part II!

Loop Transformations! Part II! Lecture 9! Loop Transformations! Part II! John Cavazos! Dept of Computer & Information Sciences! University of Delaware! www.cis.udel.edu/~cavazos/cisc879! Loop Unswitching Hoist invariant control-flow

More information

Compiler Code Generation COMP360

Compiler Code Generation COMP360 Compiler Code Generation COMP360 Students who acquire large debts putting themselves through school are unlikely to think about changing society. When you trap people in a system of debt, they can t afford

More information

Type checking. Jianguo Lu. November 27, slides adapted from Sean Treichler and Alex Aiken s. Jianguo Lu November 27, / 39

Type checking. Jianguo Lu. November 27, slides adapted from Sean Treichler and Alex Aiken s. Jianguo Lu November 27, / 39 Type checking Jianguo Lu November 27, 2014 slides adapted from Sean Treichler and Alex Aiken s Jianguo Lu November 27, 2014 1 / 39 Outline 1 Language translation 2 Type checking 3 optimization Jianguo

More information

CS 242. Fundamentals. Reading: See last slide

CS 242. Fundamentals. Reading: See last slide CS 242 Fundamentals Reading: See last slide Syntax and Semantics of Programs Syntax The symbols used to write a program Semantics The actions that occur when a program is executed Programming language

More information

16.10 Exercises. 372 Chapter 16 Code Improvement. be translated as

16.10 Exercises. 372 Chapter 16 Code Improvement. be translated as 372 Chapter 16 Code Improvement 16.10 Exercises 16.1 In Section 16.2 we suggested replacing the instruction r1 := r2 / 2 with the instruction r1 := r2 >> 1, and noted that the replacement may not be correct

More information

CS 403 Compiler Construction Lecture 10 Code Optimization [Based on Chapter 8.5, 9.1 of Aho2]

CS 403 Compiler Construction Lecture 10 Code Optimization [Based on Chapter 8.5, 9.1 of Aho2] CS 403 Compiler Construction Lecture 10 Code Optimization [Based on Chapter 8.5, 9.1 of Aho2] 1 his Lecture 2 1 Remember: Phases of a Compiler his lecture: Code Optimization means floating point 3 What

More information

Appendix A The DL Language

Appendix A The DL Language Appendix A The DL Language This appendix gives a description of the DL language used for many of the compiler examples in the book. DL is a simple high-level language, only operating on integer data, with

More information

CST-402(T): Language Processors

CST-402(T): Language Processors CST-402(T): Language Processors Course Outcomes: On successful completion of the course, students will be able to: 1. Exhibit role of various phases of compilation, with understanding of types of grammars

More information

CSC D70: Compiler Optimization LICM: Loop Invariant Code Motion

CSC D70: Compiler Optimization LICM: Loop Invariant Code Motion CSC D70: Compiler Optimization LICM: Loop Invariant Code Motion Prof. Gennady Pekhimenko University of Toronto Winter 2018 The content of this lecture is adapted from the lectures of Todd Mowry and Phillip

More information

7. Optimization! Prof. O. Nierstrasz! Lecture notes by Marcus Denker!

7. Optimization! Prof. O. Nierstrasz! Lecture notes by Marcus Denker! 7. Optimization! Prof. O. Nierstrasz! Lecture notes by Marcus Denker! Roadmap > Introduction! > Optimizations in the Back-end! > The Optimizer! > SSA Optimizations! > Advanced Optimizations! 2 Literature!

More information

Control flow graphs and loop optimizations. Thursday, October 24, 13

Control flow graphs and loop optimizations. Thursday, October 24, 13 Control flow graphs and loop optimizations Agenda Building control flow graphs Low level loop optimizations Code motion Strength reduction Unrolling High level loop optimizations Loop fusion Loop interchange

More information

Life Cycle of Source Program - Compiler Design

Life Cycle of Source Program - Compiler Design Life Cycle of Source Program - Compiler Design Vishal Trivedi * Gandhinagar Institute of Technology, Gandhinagar, Gujarat, India E-mail: raja.vishaltrivedi@gmail.com Abstract: This Research paper gives

More information

CS 132 Compiler Construction

CS 132 Compiler Construction CS 132 Compiler Construction 1. Introduction 2 2. Lexical analysis 31 3. LL parsing 58 4. LR parsing 110 5. JavaCC and JTB 127 6. Semantic analysis 150 7. Translation and simplification 165 8. Liveness

More information

Types and Static Type Checking (Introducing Micro-Haskell)

Types and Static Type Checking (Introducing Micro-Haskell) Types and Static (Introducing Micro-Haskell) Informatics 2A: Lecture 13 Alex Simpson School of Informatics University of Edinburgh als@inf.ed.ac.uk 16 October, 2012 1 / 21 1 Types 2 3 4 2 / 21 Thus far

More information

Simone Campanoni Loop transformations

Simone Campanoni Loop transformations Simone Campanoni simonec@eecs.northwestern.edu Loop transformations Outline Simple loop transformations Loop invariants Induction variables Complex loop transformations Simple loop transformations Simple

More information

Data Flow Information. already computed

Data Flow Information. already computed Data Flow Information Determine if Determine if a constant in loop modifies Determine if expression already computed Determine if not used later in program Data Flow Equations Local Information: Gen(B):

More information