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

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

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

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

Advanced Compiler Design. CSE 231 Instructor: Sorin Lerner

Advanced Compiler Design. CSE 231 Instructor: Sorin Lerner

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

Running class Timing on Java HotSpot VM, 1

Why Global Dataflow Analysis?

Welcome to CSE131b: Compiler Construction

Chapter 11 Introduction to Programming in C

Introduction. CS 2210 Compiler Design Wonsun Ahn

Undergraduate Compilers in a Day

Tour of common optimizations

CS153: Compilers Lecture 15: Local Optimization

Compiler construction 2009

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

Introduction to Compiler Construction

Chapter 11 Introduction to Programming in C

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator

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

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

CS 426 Fall Machine Problem 4. Machine Problem 4. CS 426 Compiler Construction Fall Semester 2017

Introduction - CAP Course

Chapter 11 Introduction to Programming in C

The View from 35,000 Feet

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

Introduction to Compilers

Introduction to Compiler Construction

Chapter 11 Introduction to Programming in C

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

CS321 Languages and Compiler Design I. Winter 2012 Lecture 1

Chapter 11 Introduction to Programming in C

Compiling Techniques

Appendix A The DL Language

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

Intermediate Representations

Final CSE 131B Spring 2004

Code Merge. Flow Analysis. bookkeeping

Introduction to Code Optimization. Lecture 36: Local Optimization. Basic Blocks. Basic-Block Example

CJT^jL rafting Cm ompiler

CSE 307: Principles of Programming Languages

CS 406/534 Compiler Construction Putting It All Together

Chapter 11 Introduction to Programming in C

Final CSE 131B Winter 2003

An Architectural Overview of GCC

Where We Are. Lexical Analysis. Syntax Analysis. IR Generation. IR Optimization. Code Generation. Machine Code. Optimization.

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2

Lecture 4: OpenMP Open Multi-Processing

Overview of a Compiler

Principles of Programming Languages. Lecture Outline

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

Program Analysis And Its Support in Software Development

Advanced Compiler Construction

ECE 5775 (Fall 17) High-Level Digital Design Automation. Static Single Assignment

Goals of Program Optimization (1 of 2)

Compiler Optimization Intermediate Representation

Intermediate Code & Local Optimizations

6. Intermediate Representation

Simone Campanoni Loop transformations

COMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview

Outline. Lecture 17: Putting it all together. Example (input program) How to make the computer understand? Example (Output assembly code) Fall 2002

Introduction to Programming Languages and Compilers. CS164 11:00-12:30 TT 10 Evans. UPRM ICOM 4029 (Adapted from: Prof. Necula UCB CS 164)

Overview of a Compiler

Building a Compiler with. JoeQ. Outline of this lecture. Building a compiler: what pieces we need? AKA, how to solve Homework 2

Overview of a Compiler

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

From High Level to Machine Code. Compilation Overview. Computer Programs

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

The Environment Model

Online Judge and C. Roy Chan. January 12, Outline Information Online Judge Introduction to C. CSC2100B Data Structures Tutorial 1

Compilers and Code Optimization EDOARDO FUSELLA

Outline. Introduction Concepts and terminology The case for static typing. Implementing a static type system Basic typing relations Adding context

Chapter 11 Introduction to Programming in C

CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106

The Environment Model. Nate Foster Spring 2018

The structure of a compiler

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

BEAMJIT: An LLVM based just-in-time compiler for Erlang. Frej Drejhammar

Advanced Compiler Design. CSE 231 Instructor: Sorin Lerner

Intermediate representation

Welcome to CS 241 Systems Programming at Illinois

Final Exam Review Questions

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

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

Just-In-Time Compilation

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI

Compiler Code Generation COMP360

Semantic Analysis. How to Ensure Type-Safety. What Are Types? Static vs. Dynamic Typing. Type Checking. Last time: CS412/CS413

Lecture 3 Notes Arrays

Advanced Compiler Construction

GCC An Architectural Overview

15-411/ Compiler Design

Overview of the Course

CSE 303: Concepts and Tools for Software Development

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

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

Software Project. Lecturers: Ran Caneti, Gideon Dror Teaching assistants: Nathan Manor, Ben Riva

CPE 101. Overview. Programming vs. Cooking. Key Definitions/Concepts B-1

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

CS61C : Machine Structures

Transcription:

What is a Compiler? Compiler A program that translates code in one language (source code) to code in another language (target code). Usually, target code is semantically equivalent to source code, but not always! Examples C++ to Sparc assembly C++ to C (some C++ compilers work this way) Java to JVM bytecode High Performance Fortran (HPF: a parallel Fortran language) to Fortran: a parallelizing compiler C to C (or any language to itself): Why? Make code faster, or smaller, or instrument for performance... Lecture 1: Course Overview p.1/11

Uses of Compiler Technology Code generation: To translate a program in a high-level language to machine code for a particular processor Optimization: Improve program performance for a given target machine Text formatters: translate TeX to dvi, dvi to postscript, etc. Interpreters: on-the-fly translation of code, e.g., Java, Perl, csh, Postscript Automatic parallelization or vectorization Debugging aids: e.g., purify for debugging memory access errors Performance instrumentation: e.g., -pg option of cc or gcc for profiling Security: JavaVM uses compiler analysis to prove safety of Java code Many more cool uses! Power management, code compression, fast simulation of architectures, transparent fault-tolerance, global distributed computing,... Key: Ability to extract properties of a program (analysis), and optionally transform it (synthesis) Lecture 1: Course Overview p.2/11

A Code Optimization Example What machine-independent optimizations are applicable to the following C example? When are they safe? 1 /* A, B, C are double arrays; X, Y are double scalars; rest are int scalars. */ 2 int main(int argc, char** argv) { 3... /* Declare and initialize variables. */ 4 X =...; 5 N = 1; i = 1; 6 while (i <= 100) { 7 j = i * 4; 8 N = j * N; 9 Y = X * 2.0; 10 A[i] = X * 4.0; 11 B[j] = Y * N; 12 C[j] = N * Y * C[j]; 13 i = i + 1; 14 } 15 printarray(b, 400); 16 printarray(c, 400); 17 } Lecture 1: Course Overview p.3/11

A Code Optimization Example: Result 1 X =... 2 N = 1; 3 j = 4; // Induction Variable Substitution (SUBST), 4 // Strength Reduction 5 Y = X * 2.0; // Loop-Invariant Code Motion (LICM) 6 while (j <= 400) { // Linear Function Test Replacement (LFTR) 7 // Dead Code Elimination (DCE) for i * 4 8 N = j * N; 9 // DCE of A, since A not aliased to B or C 10 tmp = Y * N; 11 B[j] = tmp; 12 C[j] = tmp * C[j]; // Common Subexpression Elimination (CSE) 13 j = j + 4; // Induction Variable Substitution, 14 // Strength Reduction 15 } 16 printarray(b, 400); 17 printarray(c, 400); Lecture 1: Course Overview p.4/11

General Structure of a Compiler Lecture 1: Course Overview p.5/11

Topical Outline 1. The structure of a compiler 2. Intermediate representations 3. Runtime storage management (excluding garbage collection) 4. Intermediate code generation 5. Code Optimization Peephole optimizations Control flow graphs and analysis Static Single Assignment (SSA) form Introduction to iterative dataflow analysis SSA and iterative dataflow optimizations 6. Global Register allocation 7. Global Instruction Scheduling (if time permits) Lecture 1: Course Overview p.6/11

Programming Projects Source Language: COOL An Optimizing Compiler for COOL using C++ Object-oriented language similar to Java But small and very well-defined: syntax and semantics Target Language: LLVM Virtual Instruction Set Both intermediate representation and assembly language Designed for effective language-independent optimization Project phases MP1: Scanning and Parsing: COOL to Abstract Syntax Tree (AST) MP2: Intermediate code gen., Part 1: AST to LLVM, local expressions only MP3: Intermediate code gen., Part 2: AST to LLVM, all of COOL MP4: Dataflow (SSA) Optimizations: ADCE, LICM Unit Project (Teams of 2): Write a graph-coloring register allocator for LLVM on X86 Lecture 1: Course Overview p.7/11

Getting Started on the Programming Projects 1. Login and set up your account on the EWS machines. 2. Print and read the COOL manual, Chapters 1-11 (through syntax) at least. The manual is on the class web site under the Project/ link. 3. Download and read the COOL examples from the file cool-examples.tar.gz. Write a COOL program to get familiar with the syntax. 4. DON T download or install LLVM! We will release a reduced version for your use in this class. Lecture 1: Course Overview p.8/11

Getting The Most Out Of AnyClass Education is what survives when what has been learned has been forgotten. B. F. Skinner, New Scientist, May 21, 1964. Get the big picture: Why are we doing this? Why is it important? Understand the basic principles: If you know how to apply them, you can work out the details Learn why things work a certain way: Automatic vs. manual, elegant vs. ad hoc, solved problem vs. open Think about the cost-benefit trade-offs: Performance vs. correctness, compile-time vs. payoff Lecture 1: Course Overview p.9/11

Getting The Most Out Of ThisClass Sir, I can give you an explanation but not an understanding! British parliamentarian Do the exercises in class; read the text and notes Start the assignment the day it s handed out, not the day it s due Pay attention to the discussions Ask questions, and participate Lecture 1: Course Overview p.10/11

Getting Started: Summary Read the CS 426 Web site all pages Register for Piazza (or contact me ASAP if you have concerns) Log in and set up your EWS account Download and read the COOL manual and examples Write a few simple COOL programs Lecture 1: Course Overview p.11/11