: Compiler Design
|
|
- Sheryl Berry
- 5 years ago
- Views:
Transcription
1 : Compiler Design 9.0 Data- Flow Analysis Thomas R. Gross Computer Science Department ETH Zurich, Switzerland
2 Global program analysis is a crucial part of all real compilers. Global : beyond a statement or small group of statements Details to follow Program analysis : understanding a program s behavior without execumon No need to have input Analysis valid for all possible inputs Program analysis for a purpose Understand =ming behavior How long does it take un=l an interrupt is no=ced? Here: analyze for op=miza=ons and for error checking 2
3 Program analysis FoundaMon to reason about correctness of programs Need to make sure program computes defined value for given input Need to make sure program does not access values outside its data space 3
4 Program analysis FoundaMon for error checking and/or repormng May be required by the programming language The Java Language Specification, Third Edition, CHAPTER 16: Definite Assignment Each local variable ( 14.4) [..] must have a definitely assigned value when any access of its value occurs. [..] A Java compiler must carry out a specific conservative flow analysis to make sure that, for every access of a local variable [..] f, f is definitely assigned before the access; otherwise a compile-time error must occur. 4
5 IllustraMve examples (mostly from Java Language Spec) int k = 1; system.out.println(k); 5
6 IllustraMve examples int k = 1; system.out.println(k); [ok] 6
7 IllustraMve examples int k = 1; system.out.println(k); [ok] void flow(boolean flag) { } int k; if (flag) k = 3; else k = 4; System.out.println(k); 7
8 IllustraMve examples int k = 1; system.out.println(k); void flow(boolean flag) { } int k; if (flag) k = 3; else k = 4; System.out.println(k); [ok] [ok] 8
9 Program analysis Must understand the flow of assignments From assignment to use as an argument Must understand the structure of the program If- then- else 9
10 Program analysis Should the compiler look at the expression of a condimonal statement? 10
11 Example, conmnued { int k; int n = 5; if (n > 2) k = 3; System.out.println(k); } 11
12 Example, conmnued { } [Not OK] int k; int n = 5; if (n > 2) k = 3; System.out.println(k); // k is not "definitely assigned" // before this call 12
13 Examples, conmnued { } int k; while (true) { k = n; if (k >= 5) break; n = 6; } System.out.println(k); 13
14 Examples, conmnued { } int k; while (true) { k = n; if (k >= 5) break; n = 6; } System.out.println(k); [OK] 14
15 Examples, conmnued { int k; while (n < 4) { k = n; if (k >= 5) break; n = 6; } System.out.println(k); } 15
16 Examples, conmnued { int k; while (n < 4) { } k = n; if (k >= 5) break; n = 6; System.out.println(k); // k is not //"definitely assigned" before this call } [Not OK] 16
17 Program analysis Just the Mp of the Java (Language Spec) iceberg The chapter (16) on definite assignments has 15 pages 17
18 Program analysis FoundaMon to reason about correctness of programs Need to make sure program computes defined value for given input Need to make sure program does not access values outside its data space FoundaMon for opmmizamon 18
19 Example void foo( ) { int j; j = 0; a[j] = } Can we replace a[j] with a[0]? Faster 19
20 Example void foo( ) { int j; j = 0; a[j] = } Can we replace a[j] with a[0]? Faster Yes, provided j does not change in shaded region 20
21 VariaMons void foo( ) { int a, b, c; a = 1; b = 2; c = a * b ; } Can we set c to 2? Faster May open more opportuni=es (see last example) 21
22 VariaMons void foo( ) { int a, b, c; a = 1; b = 2; c = a * b ; } Can we set c to 2? Faster Yes, provided a and b do not change in shaded region 22
23 Program analysis FoundaMon to reason about correctness of programs Need to make sure program computes defined value for given input Need to make sure program does not access values outside its data space FoundaMon for opmmizamon May be useful (essenmal) for tools Find statements that modify elements of an array A Must inspect all methods that are given a reference to A 23
24 Program analysis Tied to the intended use of analysis informamon Check definite assignment in Java Do not propagate informa=on into expression of if- statement See example Find opportunimes to remove unused code Evaluate expression at compile =me Remove code if it is never executed 24
25 EvaluaMon expression in compiler int j, k, m ; k = 1; j = 1; if ( j ==0 ) k = 2; m = k; 25
26 int j, k, m ; k = 1; j = 1; if ( j ==0 ) k = 2; m = 1; //?? Let there be no changes to k in the shaded region 26
27 int j, k, m ; k = 1; j = 1; if ( false ) k = 2; m = 1; //?? Let there be no changes to k in the shaded region 27
28 int j, k, m ; k = 1; j = 1; m = 1; // OK Let there be no changes to k in the shaded region 28
29 Program analysis Analysis must be correct Depends on use Do not mislead the compiler Analysis should be accurate As accurate as possible (given the informa=on in the program) As accurate as feasible (may not be able to keep all details) 29
30 9.1 Program representamon Current IR forest of trees Edges between root nodes indicate sequencing Structure of program not directly visible in IR Sequencing of statements is enough but blurs big picture Must deal with control- flow ( big picture ) before we can consider data- flow 30
31 int foo(int max, int [] A) { int k = 1; int minval = A[0]; while (k < max) { if (A[k] < minval) { minval = A[k]; } k = k + 1; } return minval; } 31
32 int foo(int max, int [] A) { k = 1 minval = A[0] L: TCond1 = k < max if (TCond1) TCond2 = A[k] < minval if (TCond2) minval = A[k] k = k + 1 Goto L return minval } 32
33 int foo(int max, int [] A) { k = 1 minval = A[0] L: TCond1 = k < max if (TCond1) TCond2 = A[k] < minval if (TCond2) minval = A[k] k = k + 1 Goto L return minval } 33
34 int foo(int max, int [] A) { k = 1 minval = A[0] L: TCond1 = k < max if (TCond1) TCond2 = A[k] < minval if (TCond2) minval = A[k] k = k + 1 Goto L return minval } 34
35 All instrucmons in a box are executed together We ignore for now that there could be excep=ons if (ConditionVariable) Test CondiMonVariable and proceed accordingly TRUE path FALSE path Only one path is taken Goto Label has the obvious meaning 35
36 Basic block The maximal sequence of instrucmons that is executed together is known as a basic block Together means w/o control flow change You can form basic blocks directly from the JavaLi IR May be harder in other languages ObservaMons An if- statement ends a basic block We do not know which statement will be executed next A Goto- statement ends a basic block A Return statement ends a basic block A label starts a basic block (and ends the previous block) Method call does not end a basic block For some compilers a method call ends a basic block 36
37 We can build a graph that captures the control flow CFG: control- flow graph Nodes: basic blocks Edges: There is an edge between block B 1 and block B 2 if B 2 may be executed immediately ager B 1. Two special nodes: START and EXIT START has no in- edges EXIT has no out- edges All other nodes have at least one in- edge and one out- edge 37
38 k = 1 minval = A[0] L: TCond1 = k < max B0 B1 if (TCond1) TCond2 = A[k] < minval if (TCond2) B2 minval = A[k] B3 k = k + 1 Goto L B4 return minval B5 38
39 k = 1 minval = A[0] L: TCond1 = k < max if (TCond1) B0 B1 START TCond2 = A[k] < minval if (TCond2) B2 minval = A[k] B3 k = k + 1 Goto L B4 return minval B5 EXIT 39
40 Control- Flow graph Edge defines successor/predecessor relamonship A block can be its own predecessor Edges capture possible successor (predecessor) relamonships Upon further inspec=on may want to remove edges and/or blocks Always built for one method/funcmon May want to include header block to deal with parameters Some compilers may include in header code to free registers etc and may have an exit block for restore opera=ons ExcepMonal control flow discussion postponed try- throw- catch Excep=on triggered by hardware 40
41 CFG construcmon Basic blocks a convenient abstracmon Not necessary for compiler Some algorithms easier to describe when using basic blocks, with control flow edges between blocks But many algorithms easy to explain in flat IR (sequences of statements) If you must/want to construct a CFG (and idenmfy blocks): single pass over current IR, form basic blocks (CFG nodes) on the fly 41
42 Comments on intermediate representamons Previous example close to JavaLi source For illustra=on Statements: JavaLi statements (almost) Basic block concept applies also to low- level (assembler) languages Statement: asm instruc=on Or to other kinds of internal representamons 42
43 Comments, conmnued Many algorithms easier to explain/discuss for simple statements des=na=on = source 1 op source 2 Instead of des=na=on = source 1 op source 2 op source 3 op source 4 We assume that our programs have this form It s easy to transform a program a = b + c + d turns into temp1 = c + d a = b + temp1 43
44 Why bother? Now it s easy (e.g.) to see that there is a common sub- expression a = b + c + d; x = a + 1; y = c + d; turns into temp1 = c + d; a = b + temp1; x = a + 1; y = c + d; 44
45 Why bother? Now it s easy (e.g.) to see that there is a common sub- expression a = b + c + d; x = a + 1; y = c + d; turns into temp1 = c + d; a = b + temp1; x = a + 1; y = c + d; temp1 = c + d; a = b + temp1; x = a + 1; y = temp1; 45
46 Once we idenmfy c+d as a common sub- expression (i.e., an expression that s evaluated more than once) it s easy to change the program We could also work on large trees but it s painful Of course it s not clear if the compiler should replace the second occurrence of c+d by temp1. 46
47 Analysis inside a basic block As the compiler knows that all instrucmons are executed together, it s easy to analyze a basic block It s smll far from trivial to consider transformamons or to idenmfy operands 47
48 Example a = b + c + d ; x = b + d; There is a common sub- expression but the compiler (most likely) won t find it Even if we deal with integer operands 48
49 a[k] = 1; a[m] = 2; b = a[k] + 1; Can the compiler assume a[k]= 1? k, m method parameters (int) a some (large) array (int) no mul=- threading, no hidden changes to k, m 49
50 a[k] = 1; a[m] = 2; b = a[k] + 1; Can the compiler assume a[k] = 1? k, m method parameters (int) a some (large) array (int) no mul=- threading, no hidden changes to k, m No, as k = m is possible. 50
51 Analysis (and opmmizamon) of basic blocks postponed. Not difficult 51
52 Terminology Local {analysis transformamon}: inside a basic block Global {analysis transformamon}: inside a method/funcmon Intra- procedural.. Inter- procedural {analysis transformamon}: across methods/funcmons 52
53 9.2 Paths and points Want to talk about flow of data in program Point: a place in the program Given a statement S P before_s : point before statement S is executed P aker_s : point aker statement S is executed Drop S if no risk of confusion Example a = b + c; //S1 x = a + 2; //S2 53
54 54
55 Point: a place in a program Given a basic block B P before_b : point before basic block B is executed P aker_b : point aker basic block B is executed Drop B if no risk of confusion 55
56 k = 1 minval = A[0] L: TCond1 = k < max B0 B1 if (TCond1) TCond2 = A[k] < minval if (TCond2) B2 minval = A[k] B3 k = k + 1 Goto L B4 return minval B5 56
57 A path is a sequence of points (x 0, x 1, x 2,, x n ) such that for any pair (x j, x j+1 ) with 0 j<n one of these condimons holds 1. x j is the point before basic block B and x j+1 is the point aker basic block B 2. x j is the point aker basic block B k and x j+1 is the point before basic block B m and there is an edge from B k to B m in the CFG DefiniMon can be extended to deal with points before statements. 57
58 Comments Points may have mulmple predecessors Join points Join nodes (in the CFG) Points may have mulmple successors Split points Split nodes When summarizing paths we may just list the basic blocks 58
59 Paths B0 B1 B2 B3 59
60 Paths i = 0 if (i>0) B0 B1 B2 B3 60
61 Paths if (i>0) B0 B1 if (i<0) B2 B3 B4 B5 B6 61
62 Paths We are interested in all paths in a CFG Even if they can never be taken in an execu=on Need summary informamon There can be arbitrarily many paths 62
63 Loops B0 if (COND) B1 B2 B3 63
64 Loops B0 if (COND) B1 B2 B3 B0 B1 B3 B0 B1 B2 B1 B3 B0 B1 B2 B1 B2 B1 B3 64 B0 B1 B2 B1 B2 B1 B2 B1 B2 B1 B2 B1 B2 B1 B2 B1 B2 B1 B2
65 Paths We deal only with finite paths PracMcal view: what has happened when program execumon reaches B3 P before_b3 Execu=on (for some input) may never reach B3. Summary informamon is needed 65
66 9.3 Transfer funcmons 66
67 Greek αααααβδερργλλλµµµννννωωω 67
68 68
Compiler Design Spring 2017
Compiler Design Spring 2017 8.0 Data-Flow Analysis Dr. Zoltán Majó Compiler Group Java HotSpot Virtual Machine Oracle Corporation Admin issues There will be a code review session next week On Thursday
More informationThe ILOC Virtual Machine (Lab 1 Background Material) Comp 412
COMP 12 FALL 20 The ILOC Virtual Machine (Lab 1 Background Material) Comp 12 source code IR Front End OpMmizer Back End IR target code Copyright 20, Keith D. Cooper & Linda Torczon, all rights reserved.
More information: Compiler Design. 9.6 Available expressions 9.7 Busy expressions. Thomas R. Gross. Computer Science Department ETH Zurich, Switzerland
252-210: Compiler Design 9.6 Available expressions 9.7 Busy expressions Thomas R. Gross Computer Science Department ETH Zurich, Switzerland Available expressions An expression a+b is available at a point
More information: Compiler Design
252-210: Compiler Design 7.2 Assignment statement 7.3 Condi2onal statement 7.4 Loops 7.5 Method invoca2on Thomas R. Gross Computer Science Department ETH Zurich, Switzerland Outline 7.1 Access to operands
More information9/9/12. New- School Machine Structures (It s a bit more complicated!) CS 61C: Great Ideas in Computer Architecture IntroducMon to Machine Language
CS 61C: Great Ideas in Computer Architecture IntroducMon to Machine Language Instructors: Krste Asanovic Randy H. Katz h
More informationResource Oriented Architecture. Jeremy Deane Director of Research & Architecture h7p://jeremydeane.net/
Resource Oriented Architecture Jeremy Deane Director of Research & Architecture h7p://jeremydeane.net/ WS- * Complexity A survey of 278 IT pros found that 32% of those using SOA said those projects fell
More information: Advanced Compiler Design. 8.0 Instruc?on scheduling
6-80: Advanced Compiler Design 8.0 Instruc?on scheduling Thomas R. Gross Computer Science Department ETH Zurich, Switzerland Overview 8. Instruc?on scheduling basics 8. Scheduling for ILP processors 8.
More informationApproximation of the Worst-Case Execution Time Using Structural Analysis. Matteo Corti and Thomas Gross Zürich
Approximation of the Worst-Case Execution Time Using Structural Analysis Matteo Corti and Thomas Gross Zürich Goal Worst-case execution time estimation of softreal time Java applications. We focus on semantic
More informationCompiler Optimization Intermediate Representation
Compiler Optimization Intermediate Representation Virendra Singh Associate Professor Computer Architecture and Dependable Systems Lab Department of Electrical Engineering Indian Institute of Technology
More informationProcessor Architecture
ECPE 170 Jeff Shafer University of the Pacific Processor Architecture 2 Lab Schedule Ac=vi=es Assignments Due Today Wednesday Apr 24 th Processor Architecture Lab 12 due by 11:59pm Wednesday Network Programming
More informationCFG (Control flow graph)
CFG (Control flow graph) Class B T12 오지은 200814189 신승우 201011340 이종선 200811448 Introduction to CFG Algorithm to construct Control Flow Graph Statement of Purpose Q & A Introduction to CFG Algorithm to
More informationCompiler: Control Flow Optimization
Compiler: Control Flow Optimization Virendra Singh Computer Architecture and Dependable Systems Lab Department of Electrical Engineering Indian Institute of Technology Bombay http://www.ee.iitb.ac.in/~viren/
More informationIntermediate Code Generation
Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target
More informationIntermediate representations IR #1: CPS/L 3. Code example. Advanced Compiler Construction Michel Schinz
Intermediate representations Intermediate representations Advanced Compiler Construction Michel Schinz 2016 03 03 The term intermediate representation (IR) or intermediate language designates the data-structure(s)
More informationELEC 876: Software Reengineering
ELEC 876: Software Reengineering () Dr. Ying Zou Department of Electrical & Computer Engineering Queen s University Compiler and Interpreter Compiler Source Code Object Compile Execute Code Results data
More informationCompiler Design Spring 2018
Compiler Design Spring 2018 2.3 Templates (for code generation) 2.4 Template-based code generator Thomas R. Gross Computer Science Department ETH Zurich, Switzerland 26 2.3 Templates Templates decide how
More informationData 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: Advanced Compiler Design
263-2810: Advanced Compiler Design Thomas R. Gross Computer Science Department ETH Zurich, Switzerland Topics Program opgmizagon Op%miza%on Op%mize for (execu%on) speed Op%mize for (code) size Op%mize
More informationLecture 1 Introduc-on
Lecture 1 Introduc-on What would you get out of this course? Structure of a Compiler Op9miza9on Example 15-745: Introduc9on 1 What Do Compilers Do? 1. Translate one language into another e.g., convert
More informationGlobal 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 informationCSSE232 Computer Architecture I. Datapath
CSSE232 Computer Architecture I Datapath Class Status Reading Sec;ons 4.1-3 Project Project group milestone assigned Indicate who you want to work with Indicate who you don t want to work with Due next
More informationLecture 3 Local Optimizations, Intro to SSA
Lecture 3 Local Optimizations, Intro to SSA I. Basic blocks & Flow graphs II. Abstraction 1: DAG III. Abstraction 2: Value numbering IV. Intro to SSA ALSU 8.4-8.5, 6.2.4 Phillip B. Gibbons 15-745: Local
More informationx = 3 * y + 1; // x becomes 3 * y + 1 a = b = 0; // multiple assignment: a and b both get the value 0
6 Statements 43 6 Statements The statements of C# do not differ very much from those of other programming languages. In addition to assignments and method calls there are various sorts of selections and
More informationCompilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam
Compilers Type checking Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Summary of parsing Parsing A solid foundation: context-free grammars A simple parser: LL(1) A more powerful parser:
More informationCS4215 Programming Language Implementation
CS4215 Programming Language Implementation You have 45 minutes to complete the exam. Use a B2 pencil to fill up the provided MCQ form. Leave Section A blank. Fill up Sections B and C. After finishing,
More informationData 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 informationIntermediate 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 informationAgenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures
The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF
More informationAdministration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator
CS 412/413 Introduction to Compilers and Translators Andrew Myers Cornell University Administration Design reports due Friday Current demo schedule on web page send mail with preferred times if you haven
More informationCSc 120. Introduction to Computer Programming II. 07: Excep*ons. Adapted from slides by Dr. Saumya Debray
CSc 120 Introduction to Computer Programming II Adapted from slides by Dr. Saumya Debray 07: Excep*ons EXERCISE Type in the following code: def foo(): n = int(input("enter a number:")) print("n = ", n)
More informationInstructor: Randy H. Katz hap://inst.eecs.berkeley.edu/~cs61c/fa13. Fall Lecture #7. Warehouse Scale Computer
CS 61C: Great Ideas in Computer Architecture Everything is a Number Instructor: Randy H. Katz hap://inst.eecs.berkeley.edu/~cs61c/fa13 9/19/13 Fall 2013 - - Lecture #7 1 New- School Machine Structures
More informationCMPT 379 Compilers. Anoop Sarkar. 11/13/07 1. TAC: Intermediate Representation. Language + Machine Independent TAC
CMPT 379 Compilers Anoop Sarkar http://www.cs.sfu.ca/~anoop 11/13/07 1 TAC: Intermediate Representation Language Specific Language + Machine Independent Machine Dependent Front End AST Intermediate Code
More informationSardar 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 informationAP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS
AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this
More informationMore 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 informationOn the Challenges in Extracting Metrics from Java Bytecode. A/Prof. Jean-Guy Schneider
On the Challenges in Extracting Metrics from Java Bytecode A/Prof. Jean-Guy Schneider jschneider@swin.edu.au Where it all began Gini Coefficient of Synthetic Fields.3.4.5.6.7 4.7: 0.4664 4.6: 0.3484 12.7:
More informationRegister 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 informationCompiler 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 informationOperators and Control Flow. CS449 Fall 2017
Operators and Control Flow CS449 Fall 2017 Running Example #include /* header file */ int main() { int grade, count, total, average; /* declaramons */ count = 0; /* inimalizamon */ total = 0;
More informationUNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger
UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS 164 Spring 2009 P. N. Hilfinger CS 164: Final Examination (corrected) Name: Login: You have
More informationFounda'ons of So,ware Engineering. Sta$c analysis (1/2) Claire Le Goues
Founda'ons of So,ware Engineering Sta$c analysis (1/2) Claire Le Goues 1 Two fundamental concepts Abstrac'on. Elide details of a specific implementa$on. Capture seman$cally relevant details; ignore the
More informationCompilers and Assemblers
ECPE 170 Jeff Shafer University of the Pacific Compilers and Assemblers 2 Schedule Today and Friday Compilers & Assemblers Quiz 6 Wednesday, April 11 th Input / Output (HW #16) OperaMng Systems (HW #17)
More informationHomework I - Solution
CS 426 Fall 2017 1 Homework I - Solution Homework I - Solution CS 426 Compiler Construction Fall Semester 2017 1. (50 points) Intermediate representations: (a) (25 points) Construct a Control-Flow Graph
More informationJVM Independent Replay in Java
JVM Independent Replay in Java RV 04 April 3, 2004, Barcelona, Spain Viktor Schuppan, Marcel Baur, Armin Biere Computer Systems Institute, ETH Zürich http://www.inf.ethz.ch/ schuppan/ Introduction 1 How
More informationSequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;
Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The
More informationCompiler 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 informationAssignment 1c: Compiler organization and backend programming
Assignment 1c: Compiler organization and backend programming Roel Jordans 2016 Organization Welcome to the third and final part of assignment 1. This time we will try to further improve the code generation
More informationCompiler 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 informationStatic 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 informationCrash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++
Crash Course in Java Netprog: Java Intro 1 Why Java? Network Programming in Java is very different than in C/C++ much more language support error handling no pointers! (garbage collection) Threads are
More informationSSA Construction. Daniel Grund & Sebastian Hack. CC Winter Term 09/10. Saarland University
SSA Construction Daniel Grund & Sebastian Hack Saarland University CC Winter Term 09/10 Outline Overview Intermediate Representations Why? How? IR Concepts Static Single Assignment Form Introduction Theory
More informationData 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 informationCompiler Theory. (GCC the GNU Compiler Collection) Sandro Spina 2009
Compiler Theory (GCC the GNU Compiler Collection) Sandro Spina 2009 GCC Probably the most used compiler. Not only a native compiler but it can also cross-compile any program, producing executables for
More informationThe Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.
The Compiler So Far CSC 4181 Compiler Construction Scanner - Lexical analysis Detects inputs with illegal tokens e.g.: main 5 (); Parser - Syntactic analysis Detects inputs with ill-formed parse trees
More informationControl 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 informationChapter 3: Instruc0on Level Parallelism and Its Exploita0on
Chapter 3: Instruc0on Level Parallelism and Its Exploita0on - Abdullah Muzahid Hardware- Based Specula0on (Sec0on 3.6) In mul0ple issue processors, stalls due to branches would be frequent: You may need
More informationCS193k, Stanford Handout #12. Threads 4 / RMI
CS193k, Stanford Handout #12 Spring, 99-00 Nick Parlante Threads 4 / RMI Semaphore1 Semaphore1 from last time uses the count in a precise way to know exactly how many threads are waiting. In this way,
More informationCompiler 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 informationint 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 informationCS 351 Final Exam Solutions
CS 351 Final Exam Solutions Notes: You must explain your answers to receive partial credit. You will lose points for incorrect extraneous information, even if the answer is otherwise correct. Question
More information15-451/651: Design & Analysis of Algorithms October 11, 2018 Lecture #13: Linear Programming I last changed: October 9, 2018
15-451/651: Design & Analysis of Algorithms October 11, 2018 Lecture #13: Linear Programming I last changed: October 9, 2018 In this lecture, we describe a very general problem called linear programming
More informationProgramming 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 informationIntermediate Code & Local Optimizations
Lecture Outline Intermediate Code & Local Optimizations Intermediate code Local optimizations Compiler Design I (2011) 2 Code Generation Summary We have so far discussed Runtime organization Simple stack
More informationEECS 583 Class 3 More on loops, Region Formation
EECS 583 Class 3 More on loops, Region Formation University of Michigan September 19, 2016 Announcements & Reading Material HW1 is out Get busy on it!» Course servers are ready to go Today s class» Trace
More informationComputer Architecture. CSE 1019Y Week 16. Introduc>on to MARIE
Computer Architecture CSE 1019Y Week 16 Introduc>on to MARIE MARIE Simple model computer used in this class MARIE Machine Architecture that is Really Intui>ve and Easy Designed for educa>on only While
More informationCS1622. 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 informationModel-Based Testing. (DIT848 / DAT261) Spring Lecture 3 White Box Testing - Coverage
Model-Based Testing (DIT848 / DAT261) Spring 2017 Lecture 3 White Box Testing - Coverage Gerardo Schneider Dept. of Computer Science and Engineering Chalmers University of Gothenburg Some slides based
More informationLanguages 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 informationThe Go Programming Language. Frank Roberts
The Go Programming Language Frank Roberts frank.roberts@uky.edu - C++ (1983), Java (1995), Python (1991): not modern - Java is 18 years old; how has computing changed in 10? - multi/many core - web programming
More informationCOMP 181. Prelude. Intermediate representations. Today. High-level IR. Types of IRs. Intermediate representations and code generation
Prelude COMP 181 Lecture 14 Intermediate representations and code generation October 19, 2006 Who is Seth Lloyd? Professor of mechanical engineering at MIT, pioneer in quantum computing Article in Nature:
More informationEfficient JIT to 32-bit Arches
Efficient JIT to 32-bit Arches Jiong Wang Linux Plumbers Conference Vancouver, Nov, 2018 1 Background ISA specification and impact on JIT compiler Default code-gen use 64-bit register, ALU64, JMP64 test_l4lb_noinline.c
More informationIMPLEMENTING PARSERS AND STATE MACHINES IN JAVA. Terence Parr University of San Francisco Java VM Language Summit 2009
IMPLEMENTING PARSERS AND STATE MACHINES IN JAVA Terence Parr University of San Francisco Java VM Language Summit 2009 ISSUES Generated method size in parsers Why I need DFA in my parsers Implementing DFA
More informationCS415 Compilers. Intermediate Represeation & Code Generation
CS415 Compilers Intermediate Represeation & Code Generation These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Review - Types of Intermediate Representations
More informationLecture 23 CIS 341: COMPILERS
Lecture 23 CIS 341: COMPILERS Announcements HW6: Analysis & Optimizations Alias analysis, constant propagation, dead code elimination, register allocation Due: Wednesday, April 25 th Zdancewic CIS 341:
More informationSemantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End
Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors
More informationIntermediate Representations Part II
Intermediate Representations Part II Types of Intermediate Representations Three major categories Structural Linear Hybrid Directed Acyclic Graph A directed acyclic graph (DAG) is an AST with a unique
More informationConcurrency Quiz: Java Threads
Concurrency Quiz: Java Threads First name, last name:................................................................. Background information In this part of the quiz, we would like to collect some information
More informationEiffel: Analysis, Design and Programming. ETH Zurich, September-December Exception handling
Eiffel: Analysis, Design and Programming ETH Zurich, September-December 2008-6- Exception handling What is an exception? An abnormal event Not a very precise definition Informally: something that you don
More informationWhat 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 informationChallenges 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 informationCODE GENERATION Monday, May 31, 2010
CODE GENERATION memory management returned value actual parameters commonly placed in registers (when possible) optional control link optional access link saved machine status local data temporaries A.R.
More informationGoals 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 information1 Lexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler
More informationCSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige
CSC 308 2.0 System Development with Java Exception Handling Department of Statistics and Computer Science 1 2 Errors Errors can be categorized as several ways; Syntax Errors Logical Errors Runtime Errors
More informationFun facts about recursion
Outline examples of recursion principles of recursion review: recursive linked list methods binary search more examples of recursion problem solving using recursion 1 Fun facts about recursion every loop
More informationCS 61C: Great Ideas in Computer Architecture Strings and Func.ons. Anything can be represented as a number, i.e., data or instruc\ons
CS 61C: Great Ideas in Computer Architecture Strings and Func.ons Instructor: Krste Asanovic, Randy H. Katz hdp://inst.eecs.berkeley.edu/~cs61c/sp12 Fall 2012 - - Lecture #7 1 New- School Machine Structures
More informationIntermediate Code & Local Optimizations. Lecture 20
Intermediate Code & Local Optimizations Lecture 20 Lecture Outline Intermediate code Local optimizations Next time: global optimizations 2 Code Generation Summary We have discussed Runtime organization
More informationTopic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History
Topic 6: A Quick Intro To C Reading Assumption: All of you know basic Java. Much of C syntax is the same. Also: Some of you have used C or C++. Goal for this topic: you can write & run a simple C program
More informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a
More informationIntermediate Representations
Intermediate Representations Intermediate Representations (EaC Chaper 5) Source Code Front End IR Middle End IR Back End Target Code Front end - produces an intermediate representation (IR) Middle end
More informationInstruction Selection and Scheduling
Instruction Selection and Scheduling The Problem Writing a compiler is a lot of work Would like to reuse components whenever possible Would like to automate construction of components Front End Middle
More informationDocumen(ng code, Javadoc, Defensive Programming, Asserts, Excep(ons & Try/Catch
Documen(ng code, Javadoc, Defensive Programming, Asserts, Excep(ons & Try/Catch 1 Most important reason to comment A) To summarize the code B) To explain how the code works C) To mark loca(ons that need
More informationExceptions. CS162: Introduction to Computer Science II. Exceptions. Exceptions. Exceptions. Exceptions. Exceptions
CS162: Introduction to Computer Science II A typical way to handle error conditions is through the return value. For example, suppose we create a loadfile() function that returns true if it loaded the
More informationB.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University
Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are
More informationCONTROL FLOW ANALYSIS. The slides adapted from Vikram Adve
CONTROL FLOW ANALYSIS The slides adapted from Vikram Adve Flow Graphs Flow Graph: A triple G=(N,A,s), where (N,A) is a (finite) directed graph, s N is a designated initial node, and there is a path from
More informationLanguages and Compiler Design II IR Code Generation I
Languages and Compiler Design II IR Code Generation I 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 Grammar G1
More informationGlobal Register Allocation via Graph Coloring
Global Register Allocation via Graph Coloring Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit permission
More informationFlow Control. CSC215 Lecture
Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements
More informationSuperscalar Architectures: Part 2
Superscalar Architectures: Part 2 Dynamic (Out-of-Order) Scheduling Lecture 3.2 August 23 rd, 2017 Jae W. Lee (jaewlee@snu.ac.kr) Computer Science and Engineering Seoul NaMonal University Download this
More informationMachine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine
Machine Language Instructions Introduction Instructions Words of a language understood by machine Instruction set Vocabulary of the machine Current goal: to relate a high level language to instruction
More information