CS 406/534 Compiler Construction Putting It All Together
|
|
- Lambert Bartholomew Fitzgerald
- 6 years ago
- Views:
Transcription
1 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 and Dr. Linda Torczon s teaching materials at Rice University. All rights reserved. 1
2 Administravia Last lecture today Lab2 and lab3 graded Final exam now handed out, due 12/20 Deadline is firm: late exam will not be graded Extra credit lab3 presentation today CS406/534 Fall 2004, Prof. Li Xu 2 2
3 What We Did Last Time Program analysis and optimization Overview of compiler optimization Local optimization DAG Value numbering Control flow analysis CFG, DOM tree, natural loops Data flow analysis SSA Generic framework Typical data flow problems AVAIL, REACH, LIVE CS406/534 Fall 2004, Prof. Li Xu 3 3
4 Today s Goals Summary of the subjects we ve covered Perspectives and final remarks How will you use /534 knowledge? CS406/534 Fall 2004, Prof. Li Xu 4 4
5 High-level View Source code Compiler Machine code Errors Definitions Compiler consumes source code & produces target code usually translate high-level language programs into machine code Interpreter consumes executables & produces results virtual machine for the input code CS406/534 Fall 2004, Prof. Li Xu 5 5
6 Why Study Compilers? Compilers are important Enabling technology for languages, software development Allow programmers to focus on problem solving, hiding the hardware complexity Responsible for good system performance Compilers are useful Language processing is broadly applicable Compilers are fun Combine theory and practice Overlap with other CS subjects Hard problems Engineering and trade-offs Got a taste in the labs! CS406/534 Fall 2004, Prof. Li Xu 6 6
7 Structure of Compilers Front Middle End Back End 7 Register Allocation Instruction Scheduling Instruction Selection IR Optimization n Optimization 2 Optimization 1 IR CSA Parser Scanner Infrastructure: symbol tables, trees, graphs, intermediate representations, sets, tuples CS406/534 Fall 2004, Prof. Li Xu 7 Analysis
8 The Front-end Front Middle End Back End 8 Register Allocation Instruction Scheduling Instruction Selection IR Optimization n Optimization 2 Optimization 1 IR CSA Parser Scanner Infrastructure: symbol tables, trees, graphs, intermediate representations, sets, tuples CS406/534 Fall 2004, Prof. Li Xu 8 Analysis
9 Scanner Lexical Analysis Maps character stream into tokens Automate scanner construction Define tokens using Regular Expressions Construct NFA (Nondeterministic Finite Automata) to recognize REs Transform NFA to DFA Convert NFA to DFA through subset construction DFA minimization (set split) Building scanners from DFA Tools ANTLR, lex CS406/534 Fall 2004, Prof. Li Xu 9 9
10 Syntax Analysis Parsing language using CFG (context-free grammar) CFG grammar theory Derivation Parse tree Grammar ambiguity Parsing Top-down parsing recursive descent table-driven LL(1) Bottom-up parsing LR(1) shift reduce parsing CS406/534 Fall 2004, Prof. Li Xu 10 10
11 Top-down Predictive Parsing Basic idea Build parse tree from root. Given A α β, use look-ahead symbol to choose between α & β Recursive descent Table-driven LL(1) Left recursion elimination CS406/534 Fall 2004, Prof. Li Xu 11 11
12 Bottom-up Shift-Reduce Parsing Build reverse rightmost derivation The key is to find handle (rhs of production) All active handles include top of stack (TOS) Shift inputs until TOS is right end of a handle Language of handles is regular (finite) Build a handle-recognizing DFA ACTION & GOTO tables encode the DFA CS406/534 Fall 2004, Prof. Li Xu 12 12
13 Semantic Analysis Analyze context and semantics types and other semantic checks Attribute grammar associate evaluation rules with grammar production Ad-hoc build symbol table CS406/534 Fall 2004, Prof. Li Xu 13 13
14 Intermediate Representation Front Middle End Back End 14 Register Allocation Instruction Scheduling Instruction Selection IR Optimization n Optimization 2 Optimization 1 IR CSA Parser Scanner Infrastructure: symbol tables, trees, graphs, intermediate representations, sets, tuples CS406/534 Fall 2004, Prof. Li Xu 14 Analysis
15 Intermediate Representation Front-end translates program into IR format for further analysis and optimization IR encodes the compiler s knowledge of the program Largely machine-independent Move closer to standard machine model AST Tree: high-level Linear IR: low-level ILOC 3-address code Assembly-level operations Expose control flow, memory addressing unlimited virtual registers CS406/534 Fall 2004, Prof. Li Xu 15 15
16 Procedure Abstraction Procedure is key language construct for building large systems Name Space Caller-callee interface: linkage convention Control transfer Context protection Parameter passing and return value Run-time support for nested scopes Activation record, access link, display Inheritance and dynamic dispatch for OO multiple inheritance virtual method table CS406/534 Fall 2004, Prof. Li Xu 16 16
17 The Back-end Front Middle End Back End 17 Register Allocation Instruction Scheduling Instruction Selection IR Optimization n Optimization 2 Optimization 1 IR CSA Parser Scanner Infrastructure: symbol tables, trees, graphs, intermediate representations, sets, tuples CS406/534 Fall 2004, Prof. Li Xu 17 Analysis
18 Instruction selection Mapping IR into assembly code The Back-end Assumes a fixed storage mapping & code shape Combining operations, using address modes Instruction scheduling Reordering operations to hide latencies Assumes a fixed program (set of operations) Changes demand for registers Register allocation Deciding which values will reside in registers Changes the storage mapping, may add false sharing Concerns about placement of data & memory operations CS406/534 Fall 2004, Prof. Li Xu 18 18
19 Expressions Code Generation Recursive tree walk on AST Direct integration with parser Assignment Array reference Boolean & Relational Values If-then-else Case Loop Procedure call CS406/534 Fall 2004, Prof. Li Xu 19 19
20 Instruction Selection Hand-coded tree-walk code generator Automatic instruction selection Pattern matching Peephole Matching Tree-pattern matching through tiling CS406/534 Fall 2004, Prof. Li Xu 20 20
21 The Problem Instruction Scheduling Given a code fragment for some target machine and the latencies for each individual operation, reorder the operations to minimize execution time Build Precedence Graph List scheduling NP-complete problem Heuristics work well for basic blocks forward list scheduling backward list scheduling Scheduling for larger regions EBB and cloning Trace scheduling CS406/534 Fall 2004, Prof. Li Xu 21 21
22 Register Allocation Local register allocation top-down bottom-up Global register allocation Find live-range Build an interference graph G I Construct a k-coloring of interference graph Map colors onto physical registers CS406/534 Fall 2004, Prof. Li Xu 22 22
23 Web-based Live Ranges Connect common defs and uses Solve the Reaching data-flow problem! l1 def x def y def y def x use y l4 use x use y l3 use x def x l2 use x CS406/534 Fall 2004, Prof. Li Xu 23 23
24 Interference Graph The interference graph, G I Nodes in G I represent live ranges Edges in G I represent individual interferences For x, y G I, <x,y> iff x and y interfere A k-coloring of G I can be mapped into an allocation to k registers 3-colorable CS406/534 Fall 2004, Prof. Li Xu 24 24
25 Key Observation on Coloring Any vertex n that has fewer than k neighbors in the interference graph (n < k) can always be colored! Remove nodes n < k for G I, coloring for G I is also coloring for G I. CS406/534 Fall 2004, Prof. Li Xu 25 25
26 Chaitin s Algorithm 1. While vertices with < k neighbors in G I > Pick any vertex n such that n < k and put it on the stack > Remove that vertex and all edges incident to it from G I This will lower the degree of n s neighbors 2. If G I is non-empty (all vertices have k or more neighbors) then: > Pick a vertex n (using some heuristic) and spill the live range associated with n > Remove vertex n from G I, along with all edges incident to it and put it on the stack > If this causes some vertex in G I to have fewer than k neighbors, then go to step 1; otherwise, repeat step 2 3. If no spill, successively pop vertices off the stack and color them in the lowest color not used by some neighbor; otherwise, insert spill code, recompute G I and start from step 1 CS406/534 Fall 2004, Prof. Li Xu 26 26
27 Brigg s Improvement Nodes can still be colored even with > k neighbors if some neighbors have same color 1. While vertices with < k neighbors in G I > Pick any vertex n such that n < k and put it on the stack > Remove that vertex and all edges incident to it from G I This may create vertices with fewer than k neighbors 2. If G I is non-empty (all vertices have k or more neighbors) then: > Pick a vertex n (using some heuristic condition), push n on the stack and remove n from G I, along with all edges incident to it > If this causes some vertex in G I to have fewer than k neighbors, then go to step 1; otherwise, repeat step 2 3. Successively pop vertices off the stack and color them in the lowest color not used by some neighbor > If some vertex cannot be colored, then pick an uncolored vertex to spill, spill it, and restart at step 1 CS406/534 Fall 2004, Prof. Li Xu 27 27
28 The Middle-end: Optimizer Front Middle End Back End 28 Register Allocation Instruction Scheduling Instruction Selection IR Optimization n Optimization 2 Optimization 1 IR CSA Parser Scanner Infrastructure: symbol tables, trees, graphs, intermediate representations, sets, tuples CS406/534 Fall 2004, Prof. Li Xu 28 Analysis
29 Principles of Compiler Optimization safety Does applying the transformation change the results of executing the code? profitability Is there a reasonable expectation that applying the transformation will improve the code? opportunity Can we efficiently and frequently find places to apply optimization Optimizing compiler Program Analysis Program Transformation CS406/534 Fall 2004, Prof. Li Xu 29 29
30 Control-flow analysis Data-flow analysis Program Analysis CS406/534 Fall 2004, Prof. Li Xu 30 30
31 Control Flow Analysis Basic blocks Control flow graph Dominator tree Natural loops Dominance frontier the join points for SSA insert Ф node CFG DOM Tree CS406/534 Fall 2004, Prof. Li Xu 31 31
32 Data Flow Analysis compile-time reasoning about the runtime flow of values represent effects of each basic block propagate facts around control flow graph CS406/534 Fall 2004, Prof. Li Xu 32 32
33 DFA: The Big Picture Set up a set of equations that relate program properties at different program points in terms of the properties at "nearby" program points B IN(B) local(b) OUT(B) Transfer function Forward analysis: compute OUT(B) in terms IN(B) Available expressions Reaching definition Backward analysis: compute IN(B) in terms of OUT(B) Variable liveness Very busy expressions Meet function for join points Forward analysis: combine OUT(p) of predecessors to form IN(B) Backward analysis: combine IN(s) of successors to form OUT(B) CS406/534 Fall 2004, Prof. Li Xu 33 33
34 Available Expression Basic block b IN(b): expressions available at b s entry OUT(b): expressions available at b s exit Local sets : expressions defined in b and available on exit : expressions killed in b An expression is killed in b if operands are assigned in b Transfer function Meet function CS406/534 Fall 2004, Prof. Li Xu 34 34
35 More Data Flow Problems AVAIL Equations More data flow problems Reaching Definition Liveness CS406/534 Fall 2004, Prof. Li Xu 35 35
36 Compiler Optimization Local optimization DAG CSE Value numbering Global optimization enabled by DFA Global CSE (AVAIL) Constant propagation (Def-Use) Dead code elimination (Use-Def) Advanced topic: SSA CS406/534 Fall 2004, Prof. Li Xu 36 36
37 Perspective Front End Middle End Back End Scanner Parser CSA IR Optimization 1 Optimization 2 Analysis Optimization n IR Instruction Selection Instruction Scheduling Register Allocation Infrastructure: symbol tables, trees, graphs, intermediate representations, sets, tuples Front end: essentially solved problem Middle end: domain-specific language Back end: new architecture Verifying compiler, reliability, security CS406/534 Fall 2004, Prof. Li Xu 37 37
38 Interesting Stuff We Skipped Interprocedural analysis Alias (pointer) analysis Garbage collection Check the literature reference in EaC CS406/534 Fall 2004, Prof. Li Xu 38 38
39 How will you use /534 knowledge? As informed programmer As informed small language designer As informed hardware engineer As compiler writer CS406/534 Fall 2004, Prof. Li Xu 39 39
40 Informed Programmer Knowledge is power Compiler is no longer a black box Know how compiler works Implications Use of language features Avoid those can cause problem Give compiler hints Code optimization Don t optimize prematurely Don t write complicated code Debugging Understand the compiled code CS406/534 Fall 2004, Prof. Li Xu 40 40
41 Solving Problem the Compiler Way Solve problems from language/compiler perspective Implement simple language Extend language CS406/534 Fall 2004, Prof. Li Xu 41 41
42 Informed Hardware Engineer Compiler support for programmable hardware pervasive computing new back-ends for new processors Design new architectures what can compiler do and not do how to expose and use compiler to manage hardware resources CS406/534 Fall 2004, Prof. Li Xu 42 42
43 Compiler Writer Make a living by writing compilers! Theory Algorithms Engineering We have built: scanner parser AST tree builder, type checker register allocator instruction scheduler Used compiler generation tools ANTLR, lex, yacc, etc On track to jump into compiler development! CS406/534 Fall 2004, Prof. Li Xu 43 43
44 Compiler construction Theory Implementation Final Remarks How to use what you learned in /534? As informed programmer As informed small language designer As informed hardware engineer As compiler writer and live happily ever after CS406/534 Fall 2004, Prof. Li Xu 44 44
45 CS406/534 Fall 2004, Prof. Li Xu 45 45
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 informationIntroduction to Optimization, Instruction Selection and Scheduling, and Register Allocation
Introduction to Optimization, Instruction Selection and Scheduling, and Register Allocation Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Traditional Three-pass Compiler
More informationParsing III. CS434 Lecture 8 Spring 2005 Department of Computer Science University of Alabama Joel Jones
Parsing III (Top-down parsing: recursive descent & LL(1) ) (Bottom-up parsing) CS434 Lecture 8 Spring 2005 Department of Computer Science University of Alabama Joel Jones Copyright 2003, Keith D. Cooper,
More informationCS 406/534 Compiler Construction Parsing Part I
CS 406/534 Compiler Construction Parsing Part I 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 and Dr.
More informationRegister Allocation. Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice.
Register Allocation Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP at Rice. Copyright 00, Keith D. Cooper & Linda Torczon, all rights reserved.
More informationCS415 Compilers. Lexical Analysis
CS415 Compilers Lexical Analysis These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Lecture 7 1 Announcements First project and second homework
More informationCS 406/534 Compiler Construction Instruction Selection and Global Register Allocation
CS 406/534 Compiler Construction Instruction Selection and Global Register Allocation Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on Prof. Keith
More informationAbout the Authors... iii Introduction... xvii. Chapter 1: System Software... 1
Table of Contents About the Authors... iii Introduction... xvii Chapter 1: System Software... 1 1.1 Concept of System Software... 2 Types of Software Programs... 2 Software Programs and the Computing Machine...
More informationCompiler Design. Register Allocation. Hwansoo Han
Compiler Design Register Allocation Hwansoo Han Big Picture of Code Generation Register allocation Decides which values will reside in registers Changes the storage mapping Concerns about placement of
More informationFaculty 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 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 informationFaculty 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 in4020 July 5, 2007 14.00-15.30 This exam (8 pages) consists of 60 True/False
More informationTorben./Egidius Mogensen. Introduction. to Compiler Design. ^ Springer
Torben./Egidius Mogensen Introduction to Compiler Design ^ Springer Contents 1 Lexical Analysis 1 1.1 Regular Expressions 2 1.1.1 Shorthands 4 1.1.2 Examples 5 1.2 Nondeterministic Finite Automata 6 1.3
More informationCJT^jL rafting Cm ompiler
CJT^jL rafting Cm ompiler ij CHARLES N. FISCHER Computer Sciences University of Wisconsin Madison RON K. CYTRON Computer Science and Engineering Washington University RICHARD J. LeBLANC, Jr. Computer Science
More informationCS 406/534 Compiler Construction Instruction Scheduling
CS 406/534 Compiler Construction Instruction Scheduling 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 informationCS /534 Compiler Construction University of Massachusetts Lowell
CS 91.406/534 Compiler Construction University of Massachusetts Lowell Professor Li Xu Fall 2004 Lab Project 2: Parser and Type Checker for NOTHING Due: Sunday, November 14, 2004, 11:59 PM 1 Introduction
More informationAlternatives for semantic processing
Semantic Processing Copyright c 2000 by Antony L. Hosking. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies
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 informationCS 406/534 Compiler Construction Parsing Part II LL(1) and LR(1) Parsing
CS 406/534 Compiler Construction Parsing Part II LL(1) and LR(1) Parsing Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on Prof. Keith Cooper, Prof.
More informationCS 406/534 Compiler Construction Intermediate Representation and Procedure Abstraction
CS 406/534 Compiler Construction Intermediate Representation and Procedure Abstraction Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on Prof. Keith
More informationRegister Allocation. Global Register Allocation Webs and Graph Coloring Node Splitting and Other Transformations
Register Allocation Global Register Allocation Webs and Graph Coloring Node Splitting and Other Transformations Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class
More informationCS415 Compilers. Syntax Analysis. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
CS415 Compilers Syntax Analysis These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Limits of Regular Languages Advantages of Regular Expressions
More informationOutline. Lecture 17: Putting it all together. Example (input program) How to make the computer understand? Example (Output assembly code) Fall 2002
Outline 5 Fall 2002 Lecture 17: Putting it all together From parsing to code generation Saman Amarasinghe 2 6.035 MIT Fall 1998 How to make the computer understand? Write a program using a programming
More informationParsing III. (Top-down parsing: recursive descent & LL(1) )
Parsing III (Top-down parsing: recursive descent & LL(1) ) Roadmap (Where are we?) Previously We set out to study parsing Specifying syntax Context-free grammars Ambiguity Top-down parsers Algorithm &
More informationAgenda. CSE P 501 Compilers. Big Picture. Compiler Organization. Intermediate Representations. IR for Code Generation. CSE P 501 Au05 N-1
Agenda CSE P 501 Compilers Instruction Selection Hal Perkins Autumn 2005 Compiler back-end organization Low-level intermediate representations Trees Linear Instruction selection algorithms Tree pattern
More informationG.PULLAIH COLLEGE OF ENGINEERING & TECHNOLOGY
G.PULLAI COLLEGE OF ENGINEERING & TECNOLOGY Nandikotkur Road, Kurnool 518002 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Semester VI (2017-2018) COURSE DESCRIPTION Course Code : 15A05601 Course Title
More informationSYED AMMAL ENGINEERING COLLEGE (An ISO 9001:2008 Certified Institution) Dr. E.M. Abdullah Campus, Ramanathapuram
CS6660 COMPILER DESIGN Question Bank UNIT I-INTRODUCTION TO COMPILERS 1. Define compiler. 2. Differentiate compiler and interpreter. 3. What is a language processing system? 4. List four software tools
More informationCS415 Compilers Overview of the Course. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
CS415 Compilers Overview of the Course These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Critical Facts Welcome to CS415 Compilers Topics in the
More informationReview. Pat Morin COMP 3002
Review Pat Morin COMP 3002 What is a Compiler A compiler translates from a source language S to a target language T while preserving the meaning of the input 2 Structure of a Compiler program text syntactic
More informationThe View from 35,000 Feet
The View from 35,000 Feet This lecture is taken directly from the Engineering a Compiler web site with only minor adaptations for EECS 6083 at University of Cincinnati Copyright 2003, Keith D. Cooper,
More information2068 (I) Attempt all questions.
2068 (I) 1. What do you mean by compiler? How source program analyzed? Explain in brief. 2. Discuss the role of symbol table in compiler design. 3. Convert the regular expression 0 + (1 + 0)* 00 first
More informationParsing II Top-down parsing. Comp 412
COMP 412 FALL 2018 Parsing II Top-down parsing Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled
More informationSyntax-Directed Translation. Lecture 14
Syntax-Directed Translation Lecture 14 (adapted from slides by R. Bodik) 9/27/2006 Prof. Hilfinger, Lecture 14 1 Motivation: parser as a translator syntax-directed translation stream of tokens parser ASTs,
More informationCSCI312 Principles of Programming Languages
Copyright 2006 The McGraw-Hill Companies, Inc. CSCI312 Principles of Programming Languages! LL Parsing!! Xu Liu Derived from Keith Cooper s COMP 412 at Rice University Recap Copyright 2006 The McGraw-Hill
More informationCS606- compiler instruction Solved MCQS From Midterm Papers
CS606- compiler instruction Solved MCQS From Midterm Papers March 06,2014 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 Final Term MCQ s and Quizzes CS606- compiler instruction If X is a
More informationAppendix Set Notation and Concepts
Appendix Set Notation and Concepts In mathematics you don t understand things. You just get used to them. John von Neumann (1903 1957) This appendix is primarily a brief run-through of basic concepts from
More informationComputing Inside The Parser Syntax-Directed Translation. Comp 412 COMP 412 FALL Chapter 4 in EaC2e. source code. IR IR target.
COMP 412 FALL 2017 Computing Inside The Parser Syntax-Directed Translation Comp 412 source code IR IR target Front End Optimizer Back End code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights
More informationIntroduction to Parsing. Comp 412
COMP 412 FALL 2010 Introduction to Parsing Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit permission to make
More informationSyntax Analysis, V Bottom-up Parsing & The Magic of Handles Comp 412
Midterm Exam: Thursday October 18, 7PM Herzstein Amphitheater Syntax Analysis, V Bottom-up Parsing & The Magic of Handles Comp 412 COMP 412 FALL 2018 source code IR Front End Optimizer Back End IR target
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 informationCS415 Compilers. Instruction Scheduling and Lexical Analysis
CS415 Compilers Instruction Scheduling and Lexical Analysis These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Instruction Scheduling (Engineer
More informationRegister allocation. TDT4205 Lecture 31
1 Register allocation TDT4205 Lecture 31 2 Variables vs. registers TAC has any number of variables Assembly code has to deal with memory and registers Compiler back end must decide how to juggle the contents
More informationBottom-Up Parsing. Lecture 11-12
Bottom-Up Parsing Lecture 11-12 (From slides by G. Necula & R. Bodik) 9/22/06 Prof. Hilfinger CS164 Lecture 11 1 Bottom-Up Parsing Bottom-up parsing is more general than topdown parsing And just as efficient
More informationFaculty 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 in4020 January 19, 2006 14.00-15.30 This exam (8 pages) consists of 60 True/False
More informationPSD3A Principles of Compiler Design Unit : I-V. PSD3A- Principles of Compiler Design
PSD3A Principles of Compiler Design Unit : I-V 1 UNIT I - SYLLABUS Compiler Assembler Language Processing System Phases of Compiler Lexical Analyser Finite Automata NFA DFA Compiler Tools 2 Compiler -
More informationCSE 401 Final Exam. March 14, 2017 Happy π Day! (3/14) This exam is closed book, closed notes, closed electronics, closed neighbors, open mind,...
CSE 401 Final Exam March 14, 2017 Happy π Day! (3/14) Name This exam is closed book, closed notes, closed electronics, closed neighbors, open mind,.... Please wait to turn the page until everyone has their
More informationLECTURE NOTES ON COMPILER DESIGN P a g e 2
LECTURE NOTES ON COMPILER DESIGN P a g e 1 (PCCS4305) COMPILER DESIGN KISHORE KUMAR SAHU SR. LECTURER, DEPARTMENT OF INFORMATION TECHNOLOGY ROLAND INSTITUTE OF TECHNOLOGY, BERHAMPUR LECTURE NOTES ON COMPILER
More informationCS Lecture 2. The Front End. Lecture 2 Lexical Analysis
CS 1622 Lecture 2 Lexical Analysis CS 1622 Lecture 2 1 Lecture 2 Review of last lecture and finish up overview The first compiler phase: lexical analysis Reading: Chapter 2 in text (by 1/18) CS 1622 Lecture
More informationEDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised:
EDAN65: Compilers, Lecture 06 A LR parsing Görel Hedin Revised: 2017-09-11 This lecture Regular expressions Context-free grammar Attribute grammar Lexical analyzer (scanner) Syntactic analyzer (parser)
More informationCompiler Optimisation
Compiler Optimisation 1 Introductory Lecture Hugh Leather IF 1.18a hleather@inf.ed.ac.uk Institute for Computing Systems Architecture School of Informatics University of Edinburgh 2018 Textbooks Engineering
More informationregister allocation saves energy register allocation reduces memory accesses.
Lesson 10 Register Allocation Full Compiler Structure Embedded systems need highly optimized code. This part of the course will focus on Back end code generation. Back end: generation of assembly instructions
More informationCSE 582 Autumn 2002 Exam 11/26/02
Name There are 8 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. You may refer to the following reference materials:
More informationQuestion Bank. 10CS63:Compiler Design
Question Bank 10CS63:Compiler Design 1.Determine whether the following regular expressions define the same language? (ab)* and a*b* 2.List the properties of an operator grammar 3. Is macro processing a
More informationCS 4120 Introduction to Compilers
CS 4120 Introduction to Compilers Andrew Myers Cornell University Lecture 6: Bottom-Up Parsing 9/9/09 Bottom-up parsing A more powerful parsing technology LR grammars -- more expressive than LL can handle
More informationInstruction Selection: Preliminaries. Comp 412
COMP 412 FALL 2017 Instruction Selection: Preliminaries Comp 412 source code Front End Optimizer Back End target code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled
More informationBSCS Fall Mid Term Examination December 2012
PUNJAB UNIVERSITY COLLEGE OF INFORMATION TECHNOLOGY University of the Punjab Sheet No.: Invigilator Sign: BSCS Fall 2009 Date: 14-12-2012 Mid Term Examination December 2012 Student ID: Section: Morning
More informationBottom-Up Parsing. Lecture 11-12
Bottom-Up Parsing Lecture 11-12 (From slides by G. Necula & R. Bodik) 2/20/08 Prof. Hilfinger CS164 Lecture 11 1 Administrivia Test I during class on 10 March. 2/20/08 Prof. Hilfinger CS164 Lecture 11
More informationCS 406/534 Compiler Construction Instruction Scheduling beyond Basic Block and Code Generation
CS 406/534 Compiler Construction Instruction Scheduling beyond Basic Block and Code Generation Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on
More informationCS 2210 Sample Midterm. 1. Determine if each of the following claims is true (T) or false (F).
CS 2210 Sample Midterm 1. Determine if each of the following claims is true (T) or false (F). F A language consists of a set of strings, its grammar structure, and a set of operations. (Note: a language
More informationCSE P 501 Compilers. LR Parsing Hal Perkins Spring UW CSE P 501 Spring 2018 D-1
CSE P 501 Compilers LR Parsing Hal Perkins Spring 2018 UW CSE P 501 Spring 2018 D-1 Agenda LR Parsing Table-driven Parsers Parser States Shift-Reduce and Reduce-Reduce conflicts UW CSE P 501 Spring 2018
More informationFront End. Hwansoo Han
Front nd Hwansoo Han Traditional Two-pass Compiler Source code Front nd IR Back nd Machine code rrors High level functions Recognize legal program, generate correct code (OS & linker can accept) Manage
More informationInstruction Selection: Peephole Matching. Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Instruction Selection: Peephole Matching Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. The Problem Writing a compiler is a lot of work Would like to reuse components
More informationCompilers. Computer Science 431
Compilers Computer Science 431 Instructor: Erik Krohn E-mail: krohne@uwosh.edu Text Message Only: 608-492-1106 Class Time: Tuesday & Thursday: 9:40am - 11:10am Classroom: Halsey 237 Office Location: Halsey
More informationComputing Inside The Parser Syntax-Directed Translation. Comp 412
COMP 412 FALL 2018 Computing Inside The Parser Syntax-Directed Translation Comp 412 source code IR IR target Front End Optimizer Back End code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights
More informationLecture 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 informationEvaluation Scheme L T P Total Credit Theory Mid Sem Exam
DESIGN OF LANGUAGE PROCESSORS Semester II (Computer Engineering) SUB CODE: MECE201 Teaching Scheme (Credits and Hours): Teaching scheme Total Evaluation Scheme L T P Total Credit Theory Mid Sem Exam CIA
More informationDerivations vs Parses. Example. Parse Tree. Ambiguity. Different Parse Trees. Context Free Grammars 9/18/2012
Derivations vs Parses Grammar is used to derive string or construct parser Context ree Grammars A derivation is a sequence of applications of rules Starting from the start symbol S......... (sentence)
More informationCSE 401 Midterm Exam Sample Solution 2/11/15
Question 1. (10 points) Regular expression warmup. For regular expression questions, you must restrict yourself to the basic regular expression operations covered in class and on homework assignments:
More informationLexical Analysis - An Introduction. Lecture 4 Spring 2005 Department of Computer Science University of Alabama Joel Jones
Lexical Analysis - An Introduction Lecture 4 Spring 2005 Department of Computer Science University of Alabama Joel Jones Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
More informationCSCI 565 Compiler Design and Implementation Spring 2014
CSCI 565 Compiler Design and Implementation Spring 2014 Instructor: Description: Prerequisites: Dr. Pedro C. Diniz, e-mail pedro@isi.edu Lectures: Thursday, 8.00 10.50 AM, RTH 217, phone: (213) 740 4518
More informationCOLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR
Pune Vidyarthi Griha s COLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR By Prof. Anand N. Gharu (Assistant Professor) PVGCOE Computer Dept.. 22nd Jan 2018 CONTENTS :- 1. Role of lexical analysis 2.
More informationLecture 8: Deterministic Bottom-Up Parsing
Lecture 8: Deterministic Bottom-Up Parsing (From slides by G. Necula & R. Bodik) Last modified: Fri Feb 12 13:02:57 2010 CS164: Lecture #8 1 Avoiding nondeterministic choice: LR We ve been looking at general
More informationSyntax Analysis Part I
Syntax Analysis Part I Chapter 4: Context-Free Grammars Slides adapted from : Robert van Engelen, Florida State University Position of a Parser in the Compiler Model Source Program Lexical Analyzer Token,
More informationIntroduction to Lexing and Parsing
Introduction to Lexing and Parsing ECE 351: Compilers Jon Eyolfson University of Waterloo June 18, 2012 1 Riddle Me This, Riddle Me That What is a compiler? 1 Riddle Me This, Riddle Me That What is a compiler?
More informationIntermediate Representations
COMP 506 Rice University Spring 2018 Intermediate Representations source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students
More informationIntermediate Representations
Most of the material in this lecture comes from Chapter 5 of EaC2 Intermediate Representations Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP
More informationCode Merge. Flow Analysis. bookkeeping
Historic Compilers Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit permission to make copies of these materials
More informationCompilers. Yannis Smaragdakis, U. Athens (original slides by Sam
Compilers Parsing Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Next step text chars Lexical analyzer tokens Parser IR Errors Parsing: Organize tokens into sentences Do tokens conform
More informationSyntax Analysis, VI Examples from LR Parsing. Comp 412
Midterm Exam: Thursday October 18, 7PM Herzstein Amphitheater Syntax Analysis, VI Examples from LR Parsing Comp 412 COMP 412 FALL 2018 source code IR IR target Front End Optimizer Back End code Copyright
More informationSyntactic Analysis. Top-Down Parsing
Syntactic Analysis Top-Down Parsing Copyright 2017, Pedro C. Diniz, all rights reserved. Students enrolled in Compilers class at University of Southern California (USC) have explicit permission to make
More informationSyntax Analysis, III Comp 412
Updated algorithm for removal of indirect left recursion to match EaC3e (3/2018) COMP 412 FALL 2018 Midterm Exam: Thursday October 18, 7PM Herzstein Amphitheater Syntax Analysis, III Comp 412 source code
More informationParsing. Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice.
Parsing Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice. Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students
More informationReview main idea syntax-directed evaluation and translation. Recall syntax-directed interpretation in recursive descent parsers
Plan for Today Review main idea syntax-directed evaluation and translation Recall syntax-directed interpretation in recursive descent parsers Syntax-directed evaluation and translation in shift-reduce
More informationCSE P 501 Compilers. Intermediate Representations Hal Perkins Spring UW CSE P 501 Spring 2018 G-1
CSE P 501 Compilers Intermediate Representations Hal Perkins Spring 2018 UW CSE P 501 Spring 2018 G-1 Administrivia Semantics/types/symbol table project due ~2 weeks how goes it? Should be caught up on
More informationSyntax Analysis, VII One more LR(1) example, plus some more stuff. Comp 412 COMP 412 FALL Chapter 3 in EaC2e. target code.
COMP 412 FALL 2017 Syntax Analysis, VII One more LR(1) example, plus some more stuff Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2017, Keith D. Cooper & Linda Torczon,
More informationCompilers and Interpreters
Overview Roadmap Language Translators: Interpreters & Compilers Context of a compiler Phases of a compiler Compiler Construction tools Terminology How related to other CS Goals of a good compiler 1 Compilers
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 informationLecture 7: Deterministic Bottom-Up Parsing
Lecture 7: Deterministic Bottom-Up Parsing (From slides by G. Necula & R. Bodik) Last modified: Tue Sep 20 12:50:42 2011 CS164: Lecture #7 1 Avoiding nondeterministic choice: LR We ve been looking at general
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 informationWhy Global Dataflow Analysis?
Why Global Dataflow Analysis? Answer key questions at compile-time about the flow of values and other program properties over control-flow paths Compiler fundamentals What defs. of x reach a given use
More informationLocal Optimization: Value Numbering The Desert Island Optimization. Comp 412 COMP 412 FALL Chapter 8 in EaC2e. target code
COMP 412 FALL 2017 Local Optimization: Value Numbering The Desert Island Optimization Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2017, Keith D. Cooper & Linda Torczon,
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 informationCSE P 501 Compilers. Parsing & Context-Free Grammars Hal Perkins Spring UW CSE P 501 Spring 2018 C-1
CSE P 501 Compilers Parsing & Context-Free Grammars Hal Perkins Spring 2018 UW CSE P 501 Spring 2018 C-1 Administrivia Project partner signup: please find a partner and fill out the signup form by noon
More informationCSE 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 informationDEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI UNIT I - LEXICAL ANALYSIS 1. What is the role of Lexical Analyzer? [NOV 2014] 2. Write
More informationCSc 553. Principles of Compilation. 23 : Register Allocation. Department of Computer Science University of Arizona
CSc 553 Principles of Compilation 3 : egister Allocation Department of Computer Science University of Arizona collberg@gmail.com Copyright c 0 Christian Collberg Introduction Lexing, Parsing Semantic Analysis,
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 informationCS415 Compilers. Procedure Abstractions. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
CS415 Compilers Procedure Abstractions These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Where are we? Well understood Engineering Source Code
More informationCompiler phases. Non-tokens
Compiler phases Compiler Construction Scanning Lexical Analysis source code scanner tokens regular expressions lexical analysis Lennart Andersson parser context free grammar Revision 2011 01 21 parse tree
More informationRYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 INSTRUCTIONS
RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 STUDENT ID: INSTRUCTIONS Please write your student ID on this page. Do not write it or your name
More information