Compilation 2012 Static Analysis

Size: px
Start display at page:

Download "Compilation 2012 Static Analysis"

Transcription

1 Compilation 2012 Jan Midtgaard Michael I. Schwartzbach Aarhus University

2 Interesting Questions Is every statement reachable? Does every non-void method return a value? Will local variables definitely be assigned before they are read? Will the current value of a variable ever be read?... How much heap space will the program need? Does the program always terminate? Will the output always be correct? 2

3 Rice s Theorem Theorem 11.9 (Martin p. 420) If R is a property of languages that is satisfied by some but not all recursively enumerable languages then the decision problem P R : Given a TM T, does L(T) have property R? is unsolvable. 3

4 Rice s Theorem Explained Theorem 11.9 (Martin, p. 420) "Every non-trivial question about the behavior of a program is undecidable." 4

5 Static analysis provides approximate answers to non-trivial questions about programs The approximation is conservative, meaning that the answers only err to one side Compilers spend most of their time performing static analysis so they may: understand the semantics of programs provide safety guarantees generate efficient code 5

6 Conservative Approximation A typical scenario for a boolean property: if the analysis says yes, the property definitely holds if it says no, the property may or may not hold only the yes answer will help the compiler a trivial analysis will say no always the engineering challenge is to say yes often enough For other kinds of properties, the notion of approximation may be more subtle 6

7 A Range of Static Analyses Static analysis may take place: at the source code level at some intermediate level at the machine code level Static analysis may look at: statement blocks only an entire method (intraprocedural) the whole program (interprocedural) The precision and cost both rise as we include more information 7

8 The Phases of GCC (1/2) Parsing Tree optimization RTL generation Sibling call optimization Jump optimization Register scan Jump threading Common subexpression elimination Loop optimizations Jump bypassing Data flow analysis Instruction combination If-conversion Register movement Instruction scheduling Register allocation Basic block reordering Delayed branch scheduling Branch shortening Assembly output Debugging output 8

9 The Phases of GCC (2/2) Parsing Tree optimization RTL generation Sibling call optimization Jump optimization Register scan Jump threading Common subexpression elimination Loop optimizations Jump bypassing Data flow analysis Instruction combination If-conversion Register movement Instruction scheduling Register allocation Basic block reordering Delayed branch scheduling Branch shortening Assembly output Debugging output Static analysis uses 60% of the compilation time 9

10 Reachability Analysis Java requires two reachability guarantees: all statements must be reachable (avoid dead code) all non-void methods must return a value These are non-trivial properties and thus they are undecidable But a static analysis may provide conservative approximations To ensure that different compilers accept the same programs, the Java language specification mandates a specific static analysis 10

11 Constraint-Based Analysis For every node S that represents a statement in the AST, we define two boolean properties: C[[S]] denotes that S may complete normally R[[S]] denotes that S is possibly reachable A statement may only complete if it is reachable For each syntactic kind of statement, we generate constraints that relate C[[...]] and R[[...]] 11

12 Information Flow The values of R[[...]] are inherited The values of C[[...]] are synthesized R C AST 12

13 Reachability Constraints (1/3) if(e) S: R[[S]] = R[[if(E) S]] C[[if (E) S]] = R[[if(E) S]] if(e) S 1 else S 2 : R[[S i ]] = R[[if(E) S 1 else S 2 ]] C[[if(E) S 1 else S 2 ]] = C[[S 1 ]] C[[S 2 ]] while(true) S: R[[S]] = R[[while(true) S]] C[[while(true) S]] = false while(false) S: R[[S]] = false C[[while(false) S]] = R[[while(false) S]] 13

14 Reachability Constraints (2/3) while(e) S: R[[S]] = R[[while(E) S]] C[[while(E) S]] = R[[while(E) S]] return: C[[return]] = false return E: C[[return E]] = false throw E: C[[throw E]] = false {σ x; S}: R[[S]] = R[[{σ x; S}]] C[[{σ x; S}]] = C[[S]] 14

15 Reachability Constraints (3/3) S 1 S 2 : R[[S 1 ]] = R[[S 1 S 2 ]] R[[S 2 ]] = C[[S 1 ]] C[[S 1 S 2 ]] = C[[S 2 ]] for any simple statement S: C[[S]] = R[[S]] for any method or constructor body {S}: R[[S]] = true 15

16 Exploiting the Information For any statement S where R[[S]] = false: unreachable statement For any non-void method with body {S} where C[[S]] = true: missing return statement These guarantees are sound but conservative 16

17 Approximations C[[S]] may be true too often: some unfair missing return errors may occur if (b) return 17; if (!b) return 42; R[[S]] may be true too often: some dead code is not detected if (b==!b) {... } 17

18 Definite Assignment Analysis Java requires that a local variable is assigned before its value is used This is a non-trivial property and thus it is undecidable But a static analysis may provide a conservative approximation To ensure that different compilers accept the same programs, the Java language specification mandates a specific static analysis 18

19 Constraint-Based Analysis For every node S that represents a statement in the AST, we define some set-valued properties: B[[S]] denotes the variables that are definitely assigned before S is executed A[[S]] denotes the variables that are definitely assigned after S is executed For every node E that represents an expression in the AST, we similarly define B[[E]] and A[[E]] 19

20 Increased Precision To handle cases such as: { int k; if (a>0 && (k=system.in.read())>0) System.out.print(k); } we also use two refinements of A[[...]]: A t [[E]] which assumes that E evaluates to true A f [[E]] which assumes that E evaluates to false 20

21 Information Flow The values of B[[...]] are inherited The values of A[[...]], A t [[...]] and A f [[...]] are synthesized B A, A t, A f AST 21

22 Definite Assignment Constraints (1/7) if(e) S: B[[E]] = B[[if(E) S]] B[[S]] = A t [[E]] A[[if(E) S]] = A[[S]] A f [[E]] if(e) S 1 else S 2 : B[[E]] = B[[if(E) S 1 else S 2 ]] B[[S 1 ]] = A t [[E]] B[[S 2 ]] = A f [[E]] A[[if(E) S 1 else S 2 ]] = A[[S 1 ]] A[[S 2 ]] 22

23 Definite Assignment Constraints (2/7) while(e) S: B[[E]] = B[[while(E) S]] B[[S]] = A t [[E]] A[[while(E) S]] = A f [[E]] return: A[[return]] = return E: B[[E]] = B[[return E]] A[[return E]] = throw E: B[[E]] = B[[throw E]] A[[throw E]] = the set of all variables in scope 23

24 Definite Assignment Constraints (3/7) E;: B[[E]] = B[[E;]] A[[E;]] = A[[E]] {σ x=e; S}: B[[E]] = B[[{σ x=e; S}]] B[[S]] = A[[E]] {x} A[[{σ x=e; S}]] = A[[S]] {σ x; S}: B[[S]] = B[[{σ x; S}]] A[[{σ x; S}]] = A[[S]] 24

25 Definite Assignment Constraints (4/7) S 1 S 2 : B[[S 1 ]] = B[[S 1 S 2 ]] B[[S 2 ]] = A[[S 1 ]] A[[S 1 S 2 ]] = A[[S 2 ]] x = E: B[[E]] = B[[x = E]] A[[x = E]] = A[[E]] {x} x[e 1 ] = E 2 : B[[E 1 ]] = B[[x[E 1 ] = E 2 ]] B[[E 2 ]] = A[[E 1 ]] A[[x[E 1 ] = E 2 ]] = A[[E 2 ]] 25

26 Definite Assignment Constraints (5/7) true: A t [[true]] = B[[true]] A f [[true]] = A[[true]] = B[[true]] false: A t [[false]] = A f [[false]] = B[[false]] A[[false]] = B[[false]]!E: B[[E]] = B[[!E]] A f [[!E]] = A t [[E]] A[[!E]] = A[[E]] A t [[!E]] = A f [[E]] 26

27 Definite Assignment Constraints (6/7) E 1 && E 2 : B[[E 1 ]] = B[[E 1 && E 2 ]] B[[E 2 ]] = A t [[E 1 ]] A t [[E 1 && E 2 ]] = A t [[E 2 ]] A f [[E 1 && E 2 ]] = A f [[E 1 ]] A f [[E 2 ]] A[[E 1 && E 2 ]] = A t [[E 1 && E 2 ]] A f [[E 1 && E 2 ]] E 1 E 2 : B[[E 1 ]] = B[[E 1 E 2 ]] B[[E 2 ]] = A f [[E 1 ]] A t [[E 1 E 2 ]] = A t [[E 1 ]] A t [[E 2 ]] A f [[E 1 E 2 ]] = A f [[E 2 ]] A[[E 1 E 2 ]] = A t [[E 1 E 2 ]] A f [[E 1 E 2 ]] 27

28 Definite Assignment Constraints (7/7) EXP(E 1,...,E k ): (any other expression with subexpressions) B[[E 1 ]] = B[[EXP(E 1,...,E k )]] B[[E i+1 ]] = A[[E i ]] A[[EXP(E 1,...,E k )]] = A[[E k ]] When not specified otherwise: A t [[E]] = A f [[E]] = A[[E]] 28

29 Exploiting the Information For every expression E of the form: x x++ x-- x[e'] where x B[[E]]: variable might not have been initialized 29

30 Approximation A[[...]] and B[[...]] may be too small: some unfair uninitialized variable errors may occur { int x; } if (b) x = 17; if (!b) x = 42; System.out.print(x); 30

31 A Simpler Guarantee In Joos 1, definite assignment is guaranteed by: requiring initializers for all local declarations forbidding a local variable to appear in its own initializer This is an even coarser approximation: { int x = (x=1)+42; System.out.print(x); } 31

32 Flow-Sensitive Analysis The analyses for: reachability definite assignment may simply be computed by traversing the AST Other analyses are defined on the control flow graph of a program and require more complex techniques 32

33 Motivation: Register Optimization For native code, we may want to optimize the use of registers: mov 1,R3 mov 1,R1 mov R3,R1 This optimization is only sound if the value in R3 is not used in the future 33

34 Motivation: Register Spills When pushing a new frame, we write back all variables from registers to memory It would be better to only write back those registers whose values may be used in the future x y a b c R1 R2 R3 34

35 Liveness In both examples, we need to know if the value of some register R i might be read in the future If so, it is called live (and otherwise dead) Exact liveness is of course undecidable A static analysis may conservatively approximate liveness at each program point A trivial analysis thinks everything is live A superior analysis identifies more dead registers 35

36 Liveness Analysis For every program point S i we define the following set-valued properties: B[[S i ]] denotes the set of registers that are possibly live before S i A[[S i ]] denotes the set of registers that are possibly live after S i For every program point we generate a constraint that relates A[[...]] and B[[...]] for neighboring program points We no longer just use the AST... 36

37 Terminology succ(s i ) denotes the set of program points to which execution may continue (by falling through or jumping) uses(s i ) denotes the set of registers that S i reads defs(s i ) denotes the set of registers that S i writes 37

38 A Tiny Example uses(s i ) defs(s i ) succ(s i ) S1: mov 3,R1 {} {R1} {S2} S2: mov 4,R2 {} {R2} {S3} S3: add R1,R2,R3 {R1,R2} {R3} {S4} S4: mov R3,R0 {R3} {R0} {S5} S5: return {R0} {} {} 38

39 Dataflow Constraints For every program point S i we have: B[[S i ]] = uses(s i ) (A[[S i ]] \ defs(s i )) A[[S i ]] = x succ(s i ) B[[x]] A cyclic control flow graph will generate a cyclic collection of constraints 39

40 Dataflow Example B[[S7]]={R1,R2} ({R4,R1,R3}\{R3})={R1,R2,R4} S7: add R1,R2,R3 B[[S8]]={R4} S8 S9 B[[S9]]={R1} B[[S17]]={R3} S17 40

41 A Small Example { int i, even, odd, sum; i = 1; even = 0; odd = 0; sum = 0; while (i < 10) { if (i%2 == 0) even = even+i; else odd = odd+i; sum = sum+i; i++; } } 41

42 Generated Native Code mov 1,R1 // R1 is i mov 0,R2 // R2 is even mov 0,R3 // R3 is odd mov 0,R4 // R4 is sum loop: andcc R1,1,R5 // R5 = R1 & 1 cmp R5,0 bne else // if R5!=0 goto else add R2,R1,R2 // R2 = R2+R1 b endif else: add R3,R1,R3 // R3 = R3+R1 endif: add R4,R1,R4 // R4 = R4+R1 add R1,1,R1 // R1 = R1+1 cmp R1,9 ble loop // if i<=9 goto loop 42

43 The Control Flow Graph S5: andcc R1,1,R5 S1: mov 1,R1 S6: cmp R5,0 S8: add R2,R1,R2 S2: mov 0,R2 S7: bne S9 S10: add R4,R1,R4 S9: add R3,R1,R3 S3: mov 0,R3 S11: add R1,1,R1 S4: mov 0,R4 S12: cmp R1,9 S13: ble S5 43

44 Cyclic Constraints B[[S1]] = f 1 (B[[S2]]) B[[S2]] = f 2 (B[[S3]]) B[[S3]] = f 3 (B[[S4]]) B[[S4]] = f 4 (B[[S5]]) B[[S5]] = f 5 (B[[S6]]) B[[S6]] = f 6 (B[[S7]]) B[[S7]] = f 7 (B[[S8]],B[[S9]]) B[[S8]] = f 8 (B[[S10]]) B[[S9]] = f 9 (B[[S10]]) B[[S10]] = f 10 (B[[S11]]) B[[S11]] = f 11 (B[[S12]]) B[[S12]] = f 12 (B[[S13]]) B[[S13]] = f 13 (B[[S5]]) where the f i (...) functions express the local constraints 44

45 Fixed-Point Solutions Reminder: x is a fixed point of a function f iff f(x)=x Define = (,,,,,,,,,,, ) Define R = {R0,R1,R2,R3,R4,R5}, (R) = Powerset of R Define F: (R) 13 (R) 13 as: F(X 1,X 2,X 3,X 4,X 5,X 6,X 7,X 8,X 9,X 10,X 11,X 12,X 13 ) = (f 1 (X 2 ),f 2 (X 3 ),f 3 (X 4 ),f 4 (X 5 ),f 5 (X 6 ),f 6 (X 7 ),f 7 (X 8,X 9 ), f 8 (X 9 ),f 9 (X 10 ),f 10 (X 11 ),f 11 (X 12 ),f 12 (X 13 ),f 13 (X 5 )) A solution is now a fixed point X (R) 13 such that F(X)=X The least fixed point is computed as a Kleene iteration: F n ( ) for some n 0 45

46 Computing the Least Fixed Point (1/3) F( ) F 2 ( ) F 3 ( ) S1 {} {} {} {} S2 {} {} {} {} S3 {} {} {} {R1} S4 {} {} {R1} {R1} S5 {} {R1} {R1} {R1} S6 {} {R5} {R5} {R1,R2,R3,R5} S7 {} {} {R1,R2,R3} {R1,R2,R3,R4} S8 {} {R1,R2} {R1,R2,R4} {R1,R2,R4} S9 {} {R1,R3} {R1,R3,R4} {R1,R3,R4} S10 {} {R1,R4} {R1,R4} {R1,R4} S11 {} {R1} {R1} {R1} S12 {} {R1} {R1} {R1} S13 {} {R1} {R1} {R1} 46

47 Computing the Least Fixed Point (2/3) F 4 ( ) F 5 ( ) F 6 ( ) S1 {} {} {} S2 {R1} {R1} {R1} S3 {R1} {R1} {R1,R2} S4 {R1} {R1,R2,R3} {R1,R2,R3} S5 {R1,R2,R3} {R1,R2,R3,R4} {R1,R2,R3,R4} S6 {R1,R2,R3,R4,R5} {R1,R2,R3,R4,R5} {R1,R2,R3,R4,R5} S7 {R1,R2,R3,R4} {R1,R2,R3,R4} {R1,R2,R3,R4} S8 {R1,R2,R4} {R1,R2,R4} {R1,R2,R4} S9 {R1,R3,R4} {R1,R3,R4} {R1,R3,R4} S10 {R1,R4} {R1,R4} {R1,R4} S11 {R1} {R1} {R1,R2,R3} S12 {R1} {R1,R2,R3} {R1,R2,R3,R4} S13 {R1,R2,R3} {R1,R2,R3,R4} {R1,R2,R3,R4} 47

48 Computing the Least Fixed Point (3/3) F 7 ( ) F 8 ( ) S1 {} {} S2 {R1} {R1} S3 {R1,R2} {R1,R2} S4 {R1,R2,R3} {R1,R2,R3} S5 {R1,R2,R3,R4} {R1,R2,R3,R4} S6 {R1,R2,R3,R4,R5} {R1,R2,R3,R4,R5} S7 {R1,R2,R3,R4} {R1,R2,R3,R4} S8 {R1,R2,R4} {R1,R2,R3,R4} S9 {R1,R3,R4} {R1,R2,R3,R4} S10 {R1,R2,R3,R4} {R1,R2,R3,R4} S11 {R1,R2,R3,R4} {R1,R2,R3,R4} S12 {R1,R2,R3,R4} {R1,R2,R3,R4} S13 {R1,R2,R3,R4} {R1,R2,R3,R4} F 8 ( )= F 9 ( ) 48

49 Background: Why does this work? (R), the powerset of R, forms a lattice: It is a partial order, i.e., it is reflexive: S S transitive: if S 1 S 2 and S 2 S 3 then S 1 S 3 anti-symmetric: if S 1 S 2 and S 2 S 1 then S 1 =S 2 It has a least element ( ) and a greatest element (R) Any two elements have a join S 1 S 2 and a meet S 1 S 2 Fixed point theorem: In a finite lattice L a monotone function F: L L has a unique least fixed point: n 0 F n ( ) computable by Kleene iteration 49

50 Application: Register Allocation Variables that are never live at the same time may share the same register Create a graph of variables where edges indicate simultaneous liveness: a b c d e Register allocation is done by finding a minimal graph coloring and assigning a register to each color: {{a,d,f}, {b,e}, {c}} f 50

Introduction A Tiny Example Language Type Analysis Static Analysis 2009

Introduction A Tiny Example Language Type Analysis Static Analysis 2009 Introduction A Tiny Example Language Type Analysis 2009 Michael I. Schwartzbach Computer Science, University of Aarhus 1 Questions About Programs Does the program terminate? How large can the heap become

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

Static Program Analysis Part 1 the TIP language

Static Program Analysis Part 1 the TIP language Static Program Analysis Part 1 the TIP language http://cs.au.dk/~amoeller/spa/ Anders Møller & Michael I. Schwartzbach Computer Science, Aarhus University Questions about programs Does the program terminate

More information

Compilation 2012 Code Generation

Compilation 2012 Code Generation Compilation 2012 Jan Midtgaard Michael I. Schwartzbach Aarhus University Phases Computing resources, such as: layout of data structures offsets register allocation Generating an internal representation

More information

Compilation 2012 Static Type Checking

Compilation 2012 Static Type Checking Compilation 2012 Jan Midtgaard Michael I. Schwartzbach Aarhus University The Type Checker The type checker has several tasks: determine the types of all expressions check that values and variables are

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

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

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 21 Tuesday, April 15, 2014 1 Static program analyses For the last few weeks, we have been considering type systems.

More information

Static Type Checking. Static Type Checking. The Type Checker. Type Annotations. Types Describe Possible Values

Static Type Checking. Static Type Checking. The Type Checker. Type Annotations. Types Describe Possible Values The Type Checker Compilation 2007 The type checker has several tasks: determine the types of all expressions check that values and variables are used correctly resolve certain ambiguities by transformations

More information

CSC 7101: Programming Language Structures 1. Operational Semantics. Winskel, Ch. 2 Slonneger and Kurtz Ch 8.4, 8.5, 8.6. Operational vs.

CSC 7101: Programming Language Structures 1. Operational Semantics. Winskel, Ch. 2 Slonneger and Kurtz Ch 8.4, 8.5, 8.6. Operational vs. Operational Semantics Winskel, Ch. 2 Slonneger and Kurtz Ch 8.4, 8.5, 8.6 1 Operational vs. Axiomatic Axiomatic semantics Describes properties of program state, using first-order logic Concerned with constructing

More information

CS5363 Final Review. cs5363 1

CS5363 Final Review. cs5363 1 CS5363 Final Review cs5363 1 Programming language implementation Programming languages Tools for describing data and algorithms Instructing machines what to do Communicate between computers and programmers

More information

Flow Analysis. Data-flow analysis, Control-flow analysis, Abstract interpretation, AAM

Flow Analysis. Data-flow analysis, Control-flow analysis, Abstract interpretation, AAM Flow Analysis Data-flow analysis, Control-flow analysis, Abstract interpretation, AAM Helpful Reading: Sections 1.1-1.5, 2.1 Data-flow analysis (DFA) A framework for statically proving facts about program

More information

Principles of Program Analysis. Lecture 1 Harry Xu Spring 2013

Principles of Program Analysis. Lecture 1 Harry Xu Spring 2013 Principles of Program Analysis Lecture 1 Harry Xu Spring 2013 An Imperfect World Software has bugs The northeast blackout of 2003, affected 10 million people in Ontario and 45 million in eight U.S. states

More information

CS 132 Compiler Construction, Fall 2011 Instructor: Jens Palsberg Multiple Choice Exam, Dec 6, 2011

CS 132 Compiler Construction, Fall 2011 Instructor: Jens Palsberg Multiple Choice Exam, Dec 6, 2011 CS 132 Compiler Construction, Fall 2011 Instructor: Jens Palsberg Multiple Choice Eam, Dec 6, 2011 ID Name This eam consists of 22 questions. Each question has four options, eactl one of which is correct,

More information

Operational Semantics. One-Slide Summary. Lecture Outline

Operational Semantics. One-Slide Summary. Lecture Outline Operational Semantics #1 One-Slide Summary Operational semantics are a precise way of specifying how to evaluate a program. A formal semantics tells you what each expression means. Meaning depends on context:

More information

Note that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m.

Note that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m. CS 6110 S18 Lecture 8 Structural Operational Semantics and IMP Today we introduce a very simple imperative language, IMP, along with two systems of rules for evaluation called small-step and big-step semantics.

More information

Ordering Within Expressions. Control Flow. Side-effects. Side-effects. Order of Evaluation. Misbehaving Floating-Point Numbers.

Ordering Within Expressions. Control Flow. Side-effects. Side-effects. Order of Evaluation. Misbehaving Floating-Point Numbers. Control Flow COMS W4115 Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science Control Flow Time is Nature s way of preventing everything from happening at once. Scott

More information

Control Flow COMS W4115. Prof. Stephen A. Edwards Fall 2006 Columbia University Department of Computer Science

Control Flow COMS W4115. Prof. Stephen A. Edwards Fall 2006 Columbia University Department of Computer Science Control Flow COMS W4115 Prof. Stephen A. Edwards Fall 2006 Columbia University Department of Computer Science Control Flow Time is Nature s way of preventing everything from happening at once. Scott identifies

More information

Operational Semantics of Cool

Operational Semantics of Cool Operational Semantics of Cool Key Concepts semantics: the meaning of a program, what does program do? how the code is executed? operational semantics: high level code generation steps of calculating values

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

CS 406/534 Compiler Construction Putting It All Together

CS 406/534 Compiler Construction Putting It All Together CS 406/534 Compiler Construction Putting It All Together Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on Prof. Keith Cooper, Prof. Ken Kennedy

More information

CS422 - Programming Language Design

CS422 - Programming Language Design 1 CS422 - Programming Language Design Denotational Semantics Grigore Roşu Department of Computer Science University of Illinois at Urbana-Champaign 2 Denotational semantics, alsoknownasfix-point semantics,

More information

Application: Programming Language Semantics

Application: Programming Language Semantics Chapter 8 Application: Programming Language Semantics Prof. Dr. K. Madlener: Specification and Verification in Higher Order Logic 527 Introduction to Programming Language Semantics Programming Language

More information

Control Flow. Stephen A. Edwards. Fall Columbia University

Control Flow. Stephen A. Edwards. Fall Columbia University Control Flow Stephen A. Edwards Columbia University Fall 2013 Control Flow Time is Nature s way of preventing everything from happening at once. Scott identifies seven manifestations of this: 1. Sequencing

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Rupesh Nasre. CS3300 Compiler Design IIT Madras Aug 2015 Character stream Lexical Analyzer Machine-Independent Code Optimizer F r o n t e n d Token stream Syntax Analyzer Syntax

More information

Combining Analyses, Combining Optimizations - Summary

Combining Analyses, Combining Optimizations - Summary Combining Analyses, Combining Optimizations - Summary 1. INTRODUCTION Cliff Click s thesis Combining Analysis, Combining Optimizations [Click and Cooper 1995] uses a structurally different intermediate

More information

int foo() { x += 5; return x; } int a = foo() + x + foo(); Side-effects GCC sets a=25. int x = 0; int foo() { x += 5; return x; }

int foo() { x += 5; return x; } int a = foo() + x + foo(); Side-effects GCC sets a=25. int x = 0; int foo() { x += 5; return x; } Control Flow COMS W4115 Prof. Stephen A. Edwards Fall 2007 Columbia University Department of Computer Science Order of Evaluation Why would you care? Expression evaluation can have side-effects. Floating-point

More information

Programming Assignment 5 Interpreter and Static Analysis

Programming Assignment 5 Interpreter and Static Analysis Lund University Computer Science Niklas Fors, Görel Hedin, Christoff Bürger Compilers EDAN65 2016-09-24 Programming Assignment 5 Interpreter and Static Analysis The goal of this assignment is to implement

More information

Program Static Analysis. Overview

Program Static Analysis. Overview Program Static Analysis Overview Program static analysis Abstract interpretation Data flow analysis Intra-procedural Inter-procedural 2 1 What is static analysis? The analysis to understand computer software

More information

Compilers. Optimization. Yannis Smaragdakis, U. Athens

Compilers. Optimization. Yannis Smaragdakis, U. Athens Compilers Optimization Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) What we already saw Lowering From language-level l l constructs t to machine-level l constructs t At this point

More information

Lecture Note: Types. 1 Introduction 2. 2 Simple Types 3. 3 Type Soundness 6. 4 Recursive Types Subtyping 17

Lecture Note: Types. 1 Introduction 2. 2 Simple Types 3. 3 Type Soundness 6. 4 Recursive Types Subtyping 17 Jens Palsberg Sep 24, 1999 Contents Lecture Note: Types 1 Introduction 2 2 Simple Types 3 3 Type Soundness 6 4 Recursive Types 12 5 Subtyping 17 6 Decision Procedure for Subtyping 19 7 First-Order Unification

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Intermediate Representations. Reading & Topics. Intermediate Representations CS2210

Intermediate Representations. Reading & Topics. Intermediate Representations CS2210 Intermediate Representations CS2210 Lecture 11 Reading & Topics Muchnick: chapter 6 Topics today: Intermediate representations Automatic code generation with pattern matching Optimization Overview Control

More information

(How Not To Do) Global Optimizations

(How Not To Do) Global Optimizations (How Not To Do) Global Optimizations #1 One-Slide Summary A global optimization changes an entire method (consisting of multiple basic blocks). We must be conservative and only apply global optimizations

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

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Rupesh Nasre. CS3300 Compiler Design IIT Madras July 2018 Character stream Lexical Analyzer Machine-Independent Code Code Optimizer F r o n t e n d Token stream Syntax Analyzer

More information

Static Program Analysis Part 9 pointer analysis. Anders Møller & Michael I. Schwartzbach Computer Science, Aarhus University

Static Program Analysis Part 9 pointer analysis. Anders Møller & Michael I. Schwartzbach Computer Science, Aarhus University Static Program Analysis Part 9 pointer analysis Anders Møller & Michael I. Schwartzbach Computer Science, Aarhus University Agenda Introduction to points-to analysis Andersen s analysis Steensgaards s

More information

Topic 7: Intermediate Representations

Topic 7: Intermediate Representations Topic 7: Intermediate Representations COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 2 Intermediate Representations 3 Intermediate Representations 4 Intermediate Representations

More information

An example of optimization in LLVM. Compiler construction Step 1: Naive translation to LLVM. Step 2: Translating to SSA form (opt -mem2reg)

An example of optimization in LLVM. Compiler construction Step 1: Naive translation to LLVM. Step 2: Translating to SSA form (opt -mem2reg) Compiler construction 2014 An example of optimization in LLVM Lecture 8 More on code optimization SSA form Constant propagation Common subexpression elimination Loop optimizations int f () { int i, j,

More information

Mosig M1 - PLSCD Written exam

Mosig M1 - PLSCD Written exam Mosig M1 - PLSCD 0809 - Written exam 1 Exercise I : Operational semantics - a debugger In this exercise we consider program execution with the help of a debugger. This execution will be defined on an intermediate

More information

Control Flow Analysis & Def-Use. Hwansoo Han

Control Flow Analysis & Def-Use. Hwansoo Han Control Flow Analysis & Def-Use Hwansoo Han Control Flow Graph What is CFG? Represents program structure for internal use of compilers Used in various program analyses Generated from AST or a sequential

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

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

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation Language Implementation Methods The Design and Implementation of Programming Languages Compilation Interpretation Hybrid In Text: Chapter 1 2 Compilation Interpretation Translate high-level programs to

More information

Fall Compiler Principles Lecture 12: Register Allocation. Roman Manevich Ben-Gurion University

Fall Compiler Principles Lecture 12: Register Allocation. Roman Manevich Ben-Gurion University Fall 2014-2015 Compiler Principles Lecture 12: Register Allocation Roman Manevich Ben-Gurion University Syllabus Front End Intermediate Representation Optimizations Code Generation Scanning Lowering Local

More information

Abstract Interpretation Continued

Abstract Interpretation Continued Abstract Interpretation Continued Height of Lattice: Length of Max. Chain height=5 size=14 T height=2 size = T -2-1 0 1 2 Chain of Length n A set of elements x 0,x 1,..., x n in D that are linearly ordered,

More information

Group B Assignment 9. Code generation using DAG. Title of Assignment: Problem Definition: Code generation using DAG / labeled tree.

Group B Assignment 9. Code generation using DAG. Title of Assignment: Problem Definition: Code generation using DAG / labeled tree. Group B Assignment 9 Att (2) Perm(3) Oral(5) Total(10) Sign Title of Assignment: Code generation using DAG. 9.1.1 Problem Definition: Code generation using DAG / labeled tree. 9.1.2 Perquisite: Lex, Yacc,

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design i About the Tutorial A compiler translates the codes written in one language to some other language without changing the meaning of the program. It is also expected that a compiler should make the target

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

ECS 142 Project: Code generation hints

ECS 142 Project: Code generation hints ECS 142 Project: Code generation hints Winter 2011 1 Overview This document provides hints for the code generation phase of the project. I have written this in a rather informal way. However, you should

More information

CS 4120 Lecture 31 Interprocedural analysis, fixed-point algorithms 9 November 2011 Lecturer: Andrew Myers

CS 4120 Lecture 31 Interprocedural analysis, fixed-point algorithms 9 November 2011 Lecturer: Andrew Myers CS 4120 Lecture 31 Interprocedural analysis, fixed-point algorithms 9 November 2011 Lecturer: Andrew Myers These notes are not yet complete. 1 Interprocedural analysis Some analyses are not sufficiently

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

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

Running class Timing on Java HotSpot VM, 1

Running class Timing on Java HotSpot VM, 1 Compiler construction 2009 Lecture 3. A first look at optimization: Peephole optimization. A simple example A Java class public class A { public static int f (int x) { int r = 3; int s = r + 5; return

More information

Intermediate representation

Intermediate representation Intermediate representation Goals: encode knowledge about the program facilitate analysis facilitate retargeting facilitate optimization scanning parsing HIR semantic analysis HIR intermediate code gen.

More information

4/24/18. Overview. Program Static Analysis. Has anyone done static analysis? What is static analysis? Why static analysis?

4/24/18. Overview. Program Static Analysis. Has anyone done static analysis? What is static analysis? Why static analysis? Overview Program Static Analysis Program static analysis Abstract interpretation Static analysis techniques 2 What is static analysis? The analysis to understand computer software without executing programs

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/ws-1617/spa/ Schedule of Lectures Jan 17/19: Interprocedural DFA

More information

From IMP to Java. Andreas Lochbihler. parts based on work by Gerwin Klein and Tobias Nipkow ETH Zurich

From IMP to Java. Andreas Lochbihler. parts based on work by Gerwin Klein and Tobias Nipkow ETH Zurich From IMP to Java Andreas Lochbihler ETH Zurich parts based on work by Gerwin Klein and Tobias Nipkow 2015-07-14 1 Subtyping 2 Objects and Inheritance 3 Multithreading 1 Subtyping 2 Objects and Inheritance

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

Control Flow Analysis. Reading & Topics. Optimization Overview CS2210. Muchnick: chapter 7

Control Flow Analysis. Reading & Topics. Optimization Overview CS2210. Muchnick: chapter 7 Control Flow Analysis CS2210 Lecture 11 Reading & Topics Muchnick: chapter 7 Optimization Overview Control Flow Analysis Maybe start data flow analysis Optimization Overview Two step process Analyze program

More information

Data Structures and Algorithms in Compiler Optimization. Comp314 Lecture Dave Peixotto

Data Structures and Algorithms in Compiler Optimization. Comp314 Lecture Dave Peixotto Data Structures and Algorithms in Compiler Optimization Comp314 Lecture Dave Peixotto 1 What is a compiler Compilers translate between program representations Interpreters evaluate their input to produce

More information

Static Program Analysis

Static Program Analysis Static Program Analysis Anders Møller and Michael I. Schwartzbach October 5, 2017 Copyright c 2008 2017 Anders Møller and Michael I. Schwartzbach Department of Computer Science Aarhus University, Denmark

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

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

Fall Compiler Principles Lecture 5: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev

Fall Compiler Principles Lecture 5: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev Fall 2016-2017 Compiler Principles Lecture 5: Intermediate Representation Roman Manevich Ben-Gurion University of the Negev Tentative syllabus Front End Intermediate Representation Optimizations Code Generation

More information

Assignment 4: Semantics

Assignment 4: Semantics Assignment 4: Semantics 15-411: Compiler Design Jan Hoffmann Jonathan Burns, DeeDee Han, Anatol Liu, Alice Rao Due Thursday, November 3, 2016 (9:00am) Reminder: Assignments are individual assignments,

More information

Programming Language Processor Theory

Programming Language Processor Theory Programming Language Processor Theory Munehiro Takimoto Course Descriptions Method of Evaluation: made through your technical reports Purposes: understanding various theories and implementations of modern

More information

Project Compiler. CS031 TA Help Session November 28, 2011

Project Compiler. CS031 TA Help Session November 28, 2011 Project Compiler CS031 TA Help Session November 28, 2011 Motivation Generally, it s easier to program in higher-level languages than in assembly. Our goal is to automate the conversion from a higher-level

More information

CS322 Languages and Compiler Design II. Spring 2012 Lecture 7

CS322 Languages and Compiler Design II. Spring 2012 Lecture 7 CS322 Languages and Compiler Design II Spring 2012 Lecture 7 1 USES OF BOOLEAN EXPRESSIONS Used to drive conditional execution of program sections, e.g. IF (a < 17) OR (b = 12) THEN... ELSE...; WHILE NOT

More information

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Lecture 13. Notation. The rules. Evaluation Rules So Far

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Lecture 13. Notation. The rules. Evaluation Rules So Far Lecture Outline Operational Semantics of Cool Lecture 13 COOL operational semantics Motivation Notation The rules Prof. Aiken CS 143 Lecture 13 1 Prof. Aiken CS 143 Lecture 13 2 Motivation We must specify

More information

CS153: Compilers Lecture 17: Control Flow Graph and Data Flow Analysis

CS153: Compilers Lecture 17: Control Flow Graph and Data Flow Analysis CS153: Compilers Lecture 17: Control Flow Graph and Data Flow Analysis Stephen Chong https://www.seas.harvard.edu/courses/cs153 Announcements Project 5 out Due Tuesday Nov 13 (14 days) Project 6 out Due

More information

Operational Semantics 1 / 13

Operational Semantics 1 / 13 Operational Semantics 1 / 13 Outline What is semantics? Operational Semantics What is semantics? 2 / 13 What is the meaning of a program? Recall: aspects of a language syntax: the structure of its programs

More information

CS 432 Fall Mike Lam, Professor. Code Generation

CS 432 Fall Mike Lam, Professor. Code Generation CS 432 Fall 2015 Mike Lam, Professor Code Generation Compilers "Back end" Source code Tokens Syntax tree Machine code char data[20]; int main() { float x = 42.0; return 7; } 7f 45 4c 46 01 01 01 00 00

More information

Crafting a Compiler with C (II) Compiler V. S. Interpreter

Crafting a Compiler with C (II) Compiler V. S. Interpreter Crafting a Compiler with C (II) 資科系 林偉川 Compiler V S Interpreter Compilation - Translate high-level program to machine code Lexical Analyzer, Syntax Analyzer, Intermediate code generator(semantics Analyzer),

More information

Introduction to Denotational Semantics (1/2)

Introduction to Denotational Semantics (1/2) Introduction to Denotational Semantics (1/2) Gone in Sixty Seconds Denotation semantics is a formal way of assigning meanings to programs. In it, the meaning of a program is a mathematical object. Denotation

More information

Global Optimization. Lecture Outline. Global flow analysis. Global constant propagation. Liveness analysis. Local Optimization. Global Optimization

Global Optimization. Lecture Outline. Global flow analysis. Global constant propagation. Liveness analysis. Local Optimization. Global Optimization Lecture Outline Global Optimization Global flow analysis Global constant propagation Liveness analysis Compiler Design I (2011) 2 Local Optimization Recall the simple basic-block optimizations Constant

More information

axiomatic semantics involving logical rules for deriving relations between preconditions and postconditions.

axiomatic semantics involving logical rules for deriving relations between preconditions and postconditions. CS 6110 S18 Lecture 18 Denotational Semantics 1 What is Denotational Semantics? So far we have looked at operational semantics involving rules for state transitions, definitional semantics involving translations

More information

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1 Agenda CSE P 501 Compilers Java Implementation JVMs, JITs &c Hal Perkins Summer 2004 Java virtual machine architecture.class files Class loading Execution engines Interpreters & JITs various strategies

More information

Introduction to Syntax Analysis. The Second Phase of Front-End

Introduction to Syntax Analysis. The Second Phase of Front-End Compiler Design IIIT Kalyani, WB 1 Introduction to Syntax Analysis The Second Phase of Front-End Compiler Design IIIT Kalyani, WB 2 Syntax Analysis The syntactic or the structural correctness of a program

More information

What is a compiler? Xiaokang Qiu Purdue University. August 21, 2017 ECE 573

What is a compiler? Xiaokang Qiu Purdue University. August 21, 2017 ECE 573 What is a compiler? Xiaokang Qiu Purdue University ECE 573 August 21, 2017 What is a compiler? What is a compiler? Traditionally: Program that analyzes and translates from a high level language (e.g.,

More information

Object Code (Machine Code) Dr. D. M. Akbar Hussain Department of Software Engineering & Media Technology. Three Address Code

Object Code (Machine Code) Dr. D. M. Akbar Hussain Department of Software Engineering & Media Technology. Three Address Code Code Generation Intermediate Code? Assembly Code Object Code (Machine Code) 1 Intermediate Code P-Code Three Address Code 2 Compiler Construction F6S 1 Intermediate Representation Abstract Syntax Tree

More information

COMP 520 Fall 2009 Virtual machines (1) Virtual machines

COMP 520 Fall 2009 Virtual machines (1) Virtual machines COMP 520 Fall 2009 Virtual machines (1) Virtual machines COMP 520 Fall 2009 Virtual machines (2) Compilation and execution modes of Virtual machines: Abstract syntax trees Interpreter AOT-compile Virtual

More information

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done What is a compiler? What is a compiler? Traditionally: Program that analyzes and translates from a high level language (e.g., C++) to low-level assembly language that can be executed by hardware int a,

More information

Compiler construction 2009

Compiler construction 2009 Compiler construction 2009 Lecture 3 JVM and optimization. A first look at optimization: Peephole optimization. A simple example A Java class public class A { public static int f (int x) { int r = 3; int

More information

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics Recall Architecture of Compilers, Interpreters CMSC 330: Organization of Programming Languages Source Scanner Parser Static Analyzer Operational Semantics Intermediate Representation Front End Back End

More information

Programming Languages and Compilers Qualifying Examination. Answer 4 of 6 questions.

Programming Languages and Compilers Qualifying Examination. Answer 4 of 6 questions. Programming Languages and Compilers Qualifying Examination Fall 2017 Answer 4 of 6 questions. GENERAL INSTRUCTIONS 1. Answer each question in a separate book. 2. Indicate on the cover of each book the

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

CSE 5317 Midterm Examination 4 March Solutions

CSE 5317 Midterm Examination 4 March Solutions CSE 5317 Midterm Examination 4 March 2010 1. / [20 pts] Solutions (parts a j; -1 point for each wrong answer, 0 points for each blank answer, 2 point for each correct answer. Therefore, the score for this

More information

Fall Compiler Principles Lecture 6: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev

Fall Compiler Principles Lecture 6: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev Fall 2015-2016 Compiler Principles Lecture 6: Intermediate Representation Roman Manevich Ben-Gurion University of the Negev Tentative syllabus Front End Intermediate Representation Optimizations Code Generation

More information

Principles of Compiler Design

Principles of Compiler Design Principles of Compiler Design Code Generation Compiler Lexical Analysis Syntax Analysis Semantic Analysis Source Program Token stream Abstract Syntax tree Intermediate Code Code Generation Target Program

More information

Escape Analysis for Java

Escape Analysis for Java Escape Analysis for Java Michael Bohn Based on the paper by Jong-Deok Choi, Manish Gupta, Mauricio Serrano, Vugranam Sreedhar and Sam Midkiff Escape Analysis? What is Escape Analysis and why do I need

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/ws-1617/spa/ Recap: Taking Conditional Branches into Account Extending

More information

A CRASH COURSE IN SEMANTICS

A CRASH COURSE IN SEMANTICS LAST TIME Recdef More induction NICTA Advanced Course Well founded orders Slide 1 Theorem Proving Principles, Techniques, Applications Slide 3 Well founded recursion Calculations: also/finally {P}... {Q}

More information

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology exam Compiler Construction in4303 April 9, 2010 14.00-15.30 This exam (6 pages) consists of 52 True/False

More information

Estimating the Impact of Heap Liveness Information on Space Consumption in Java

Estimating the Impact of Heap Liveness Information on Space Consumption in Java Estimating the Impact of Heap Liveness Information on Space Consumption in Java by R. Shaham, E. Kolodner and M. Sagiv first presented at ISSM'02 presentation: Adrian Moos Contents what is this about?

More information

CMSC430 Spring 2014 Midterm 2 Solutions

CMSC430 Spring 2014 Midterm 2 Solutions CMSC430 Spring 2014 Midterm 2 Solutions 1. (12 pts) Syntax directed translation & type checking Consider the following grammar fragment for an expression for C--: exp CONST IDENT 1 IDENT 2 [ exp 1 ] Assume

More information

Write Barrier Removal by Static Analysis

Write Barrier Removal by Static Analysis Write Barrier Removal by Static Analysis Karen Zee and Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Cambridge, MA 02139 {kkz, rinard@lcs.mit.edu ABSTRACT We present

More information

Register Allocation. CS 502 Lecture 14 11/25/08

Register Allocation. CS 502 Lecture 14 11/25/08 Register Allocation CS 502 Lecture 14 11/25/08 Where we are... Reasonably low-level intermediate representation: sequence of simple instructions followed by a transfer of control. a representation of static

More information

Lecture Notes on Common Subexpression Elimination

Lecture Notes on Common Subexpression Elimination Lecture Notes on Common Subexpression Elimination 15-411: Compiler Design Frank Pfenning Lecture 18 October 29, 2015 1 Introduction Copy propagation allows us to have optimizations with this form: l :

More information

Challenges in the back end. CS Compiler Design. Basic blocks. Compiler analysis

Challenges in the back end. CS Compiler Design. Basic blocks. Compiler analysis Challenges in the back end CS3300 - Compiler Design Basic Blocks and CFG V. Krishna Nandivada IIT Madras The input to the backend (What?). The target program instruction set, constraints, relocatable or

More information