CS426 Compiler Construction Fall 2006

Similar documents
CS 526 Advanced Topics in Compiler Construction. 1 of 12

Introduction to Compiler Construction

Introduction to Compiler Construction

Compiler Design (40-414)

CS415 Compilers Overview of the Course. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

Formal Languages and Compilers Lecture I: Introduction to Compilers

Compiler Design. Dr. Chengwei Lei CEECS California State University, Bakersfield

CS131: Programming Languages and Compilers. Spring 2017

ECE573 Introduction to Compilers & Translators

CST-402(T): Language Processors

Introduction. Compilers and Interpreters

Compiler Design Overview. Compiler Design 1

Earlier edition Dragon book has been revised. Course Outline Contact Room 124, tel , rvvliet(at)liacs(dot)nl

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

CS 536. Class Meets. Introduction to Programming Languages and Compilers. Instructor. Key Dates. Teaching Assistant. Charles N. Fischer.

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

CA Compiler Construction

CS Compiler Construction West Virginia fall semester 2014 August 18, 2014 syllabus 1.0

UG3 Compiling Techniques Overview of the Course

Compiling Regular Expressions COMP360

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

CS/SE 153 Concepts of Compiler Design

CS 415 Midterm Exam Spring 2002

SEM / YEAR : VI / III CS2352 PRINCIPLES OF COMPLIERS DESIGN UNIT I - LEXICAL ANALYSIS PART - A

LECTURE NOTES ON COMPILER DESIGN P a g e 2

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF CSE COURSE PLAN

Programming Language Processor Theory

Administrivia. Compilers. CS143 10:30-11:50TT Gates B01. Text. Staff. Instructor. TAs. The Purple Dragon Book. Alex Aiken. Aho, Lam, Sethi & Ullman

CS 4120 and 5120 are really the same course. CS 4121 (5121) is required! Outline CS 4120 / 4121 CS 5120/ = 5 & 0 = 1. Course Information

CS/SE 153 Concepts of Compiler Design

What do Compilers Produce?


PLAGIARISM. Administrivia. Compilers. CS143 11:00-12:15TT B03 Gates. Text. Staff. Instructor. TAs. Office hours, contact info on 143 web site

CMPE 152 Compiler Design

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY

CS415 Compilers Overview of the Course. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILING

Lexical Scanning COMP360

Working of the Compilers

Compiling Techniques

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

CSCI 565 Compiler Design and Implementation Spring 2014

COMP 3002: Compiler Construction. Pat Morin School of Computer Science

History of Compilers The term

General Course Information. Catalogue Description. Objectives

Compilers. Prerequisites

COMPILER DESIGN. For COMPUTER SCIENCE

CMPE 152 Compiler Design

Dixita Kagathara Page 1

Application Specific Signal Processors S

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

Introduction to Compiler

CSCI 334: Principles of Programming Languages. Lecture 2: Lisp Wrapup & Fundamentals. Higher-Order Functions. Activity

CS 415 Midterm Exam Spring SOLUTION

Introduction to Syntax Analysis. Compiler Design Syntax Analysis s.l. dr. ing. Ciprian-Bogdan Chirila

BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE, Pilani Pilani Campus Instruction Division

CMPE 152 Compiler Design

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS

Question Points Score

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

Compilers and Code Optimization EDOARDO FUSELLA

Formats of Translated Programs

Compiler Construction Lecture 1: Introduction Winter Semester 2018/19 Thomas Noll Software Modeling and Verification Group RWTH Aachen University

Compilers Crash Course

Compilers and Interpreters

Compilers for Modern Architectures Course Syllabus, Spring 2015

Introduction to Compiler Construction

SYED AMMAL ENGINEERING COLLEGE (An ISO 9001:2008 Certified Institution) Dr. E.M. Abdullah Campus, Ramanathapuram

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

Compiler Structure. Lexical. Scanning/ Screening. Analysis. Syntax. Parsing. Analysis. Semantic. Context Analysis. Analysis.

CSC488S/CSC2107S - Compilers and Interpreters. CSC 488S/CSC 2107S Lecture Notes

CSC488S/CSC2107S - Compilers and Interpreters. CSC 488S/CSC 2107S Lecture Notes

KALASALINGAM UNIVERSITY ANAND NAGAR, KRISHNAN KOIL DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING ODD SEMESTER COURSE PLAN

CD Assignment I. 1. Explain the various phases of the compiler with a simple example.

names names identifiers variables subroutines constants

G.PULLAIH COLLEGE OF ENGINEERING & TECHNOLOGY


Compiler Construction LECTURE # 1

When do We Run a Compiler?

An Overview to Compiler Design. 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1

Pioneering Compiler Design

Evaluation Scheme L T P Total Credit Theory Mid Sem Exam

Group A Assignment 3(2)

A Simple Syntax-Directed Translator

ECE Introduction to Compilers and Translation Engineering

Theory and Compiling COMP360

Compilers. History of Compilers. A compiler allows programmers to ignore the machine-dependent details of programming.

Translator Design CRN Course Administration CMSC 4173 Spring 2017

Introduction. Interpreters High-level language intermediate code which is interpreted. Translators. e.g.

INF5110 Compiler Construction

An Overview of Compilation

CS 4201 Compilers 2014/2015 Handout: Lab 1

MidTerm Papers Solved MCQS with Reference (1 to 22 lectures)

Compiler Code Generation COMP360

The analysis part breaks up the source program into constituent pieces and creates an intermediate representation of the source program.

Important Project Dates

Transcription:

CS426 Compiler Construction David Padua Department of Computer Science University of Illinois at Urbana-Champaign

0. Course organization 2 of 23

Instructor: David A. Padua 4227 SC, 333-4223 Office Hours: By appointment padua@uiuc.edu http://polaris.cs.uiuc.edu/~padua/cs426 TA: Time & Place: Credit: Text: James Brodman 4301 SC, 333-6578 Office hours: brodman@gmail.com 12:30 PM - 01:45 PM TR 1103 SC 3 or 4 hours Compilers: Principles, Techniques, and Tools:2/e 2007 Not Yet Published ISBN-13: 9780321486813 A. Aho, M. Lam, R. Sethi, and J. Ullman Evaluation: Midterm (Oct. 12) 25% Final exam (Dec. 14 [7-10pm]) 40% Term project (Dec. 14) 35% Term paper for 4th hour (Dec. 14) 3 of 23

1. Introduction 4 of 23

What is a compiler? Compilers are programming language translators. Accept source language. Translate into target language. Numerous source and target languages, but fairly general techniques have been developed, and some reuse of software and automatic generation of compiler modules is possible. Although much progress has been made since the first commercial optimizing compiler (Fortran I), compiler development is still a challenging task. 5 of 23

Importance of compilers Compilers facilitate programming by -- Presenting a high-level interface -- Enabling portability In some domains, the acceptance of a programming language is influenced by the availability of effective compilers. That is, compilers that generate fast target code. 6 of 23

For that reason, an important objective of compilers has always been code optimization: It was our belief that if FORTRAN, during its first months, were to translate any reasonable scientific source program into an object program only half as fast as its hand coded counterpart, then acceptance of our system would be in serious danger. John Backus Fortran I, II and III Annals of the History of Computing, July 1979. 7 of 23

Compiler optimization attempts to completely liberate programmers from machine concerns and thus enable portability without loss of performance. Goal is for programmers to focus on the development of clean (easy to understand and debug) programs and ignore machine details. Today s compilers are not always 100% successful at these tasks and some human involvement is usually required to obtain highly efficient code. 8 of 23

The analysis-synthesis model of compilation The two mains tasks of compilers are: analysis intermediate representation synthesis source program target program 9 of 23

Analysis -- breaks up source program into constitutent parts. -- gathers information implicit in the source code and detects errors. -- creates an intermediate representation. -- the textbook gives in Chapter 1 a narrow definition of analysis as applying only to the source code. As we will see later, analysis is often also performed on the internal representation. Synthesis -- Generate the target code by manipulating and transforming the source code. -- Translates and often also optimizes 10 of 23

Syntax analysis The first type of analysis that must be performed in syntax analysis. It produces parse trees and abstract syntax trees whose shape follow the structure of the source program. For example, even a simple the statement like position = initial + rate * 60 has an structure determined by operator precedence. For example, its abstract syntax tree has the following form: = position + initial * rate 60 11 of 23

The abstract syntax tree is the culmination of a process that involves lexical analysis or scanning and parsing. Lexical scanners read sequence of characters and organizes them into tokens. These are elementary components of programs such a keywords (or reserved words), variables, special characters, numerical constants, etc. Parsing builds a parse tree (but it may not save it) from the tokenized input based on a grammar that describes the language accepted by the compiler. Parsing detects syntax errors. 12 of 23

A simple grammar for assignment statements is A id = E E E + T E T T T * F T F F (E) F id number The parse tree is then: A id = E position E + T lexical scanner returns token class and token value T T * F F F number id initial id rate 60 13 of 23

Semantic analysis Gathers information for the subsequent code generation phase Check code for semantic errors -- Type of objects -- Undefined variables -- Parameters to intrisic functions -- Java compiler / VM do extensive semantic analysis 14 of 23

Overall organization of a compiler Source program High level representation (abstract syntax tree) Lexical scanner Parser Semantic analyzer Front end Intermediate code generator Low level Intermediate representation Low level optimizations High level representation (abstract syntax tree) High-level optimizations Low level Intermediate representation Machine code generator Back end Target program

The context of a compiler skeletal source program preprocessor Book source program source program compiler target assembly language program assembler light gray boxes are not always present compiler target JVM assembly language program assembler relocatable machine code.class file loader/link editor absolute machine code Java Vitual Machine Interpreter target machine (hardware interpreter) Course project 16 of 23

Compiler Optimizations First, a note about the word optimization. It is a misnomer since there is no guarantee of optimality. Many problems are NP complete or undecidable. We could call the operation code improvement, but we should follow tradition. In any case, real implementations not always improve the code since compiler transformations are not guaranteed to improve the performance of the generated code. 17 of 23

A classification of compiler optimizations By the scope Peephole optimizations. A local inspection of the code to identify and modify inefficient sequence of instructions. Intraprocedural. Transform the body of a procedure or method using information from the procedure itself. Interprocedural. Uses information from several procedures to transform the program. Because of separate compilation this type of optimization is infrequently applied to complete programs. 18 of 23

By the time of application Static. At compile-time -- Source-to-source -- Low-level optimizations Dynamic. At execution time. By the source of the information Code only Code plus user assertions Code plus profile information. 19 of 23

Which optimizations to include? The optimizations must be effective across the broad range of programs typically encountered. Also important is the time it takes to apply the optimization. A slow compiler is not desirable (and for some transformations the compiler can become very slow). 20 of 23

Order and repetition of optimizations A possible order of optimizations, shown in the figure below, is from S. Muchnick s book Advanced compiler design implementation. Two quotes from that book: One can easily invent examples to show that no order can be optimal for all programs. It is easy to invent programs that will benefit from any number of repetitions of a sequence of optimizing transformations. While such examples can be constructed, it is important to note that they occur very rarely in practice. It is usually sufficient to apply the transformations that make up an optimizer once, or at most twice to get all or almost all the benefit one is likely to derive from them. 21 of 23

23 of 23