Simone Campanoni simonec@eecs.northwestern.edu Welcome! Simone Campanoni simonec@eecs.northwestern.edu.

Slides:



Advertisements
Similar presentations
Software & Services Group, Developer Products Division Copyright© 2010, Intel Corporation. All rights reserved. *Other brands and names are the property.
Advertisements

ECE 454 Computer Systems Programming Compiler and Optimization (I) Ding Yuan ECE Dept., University of Toronto
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Intermediate Representation I High-Level to Low-Level IR Translation EECS 483 – Lecture 17 University of Michigan Monday, November 6, 2006.
Lecture 01 - Introduction Eran Yahav 1. 2 Who? Eran Yahav Taub 734 Tel: Monday 13:30-14:30
Cpeg421-08S/final-review1 Course Review Tom St. John.
From Cooper & Torczon1 Implications Must recognize legal (and illegal) programs Must generate correct code Must manage storage of all variables (and code)
Compiler Construction
CS 153: Concepts of Compiler Design August 25 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
CPSC 388 – Compiler Design and Construction Lecture: MWF 11:00am-12:20pm, Room 106 Colton.
Topic #10: Optimization EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
COP4020 Programming Languages
Chapter 1. Introduction.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Software Overview. Why review software? Software is the set of instructions that tells hardware what to do The reason for hardware is to execute a program.
CS412/413 Introduction to Compilers and Translators May 3, 1999 Lecture 34: Compiler-like Systems JIT bytecode interpreter src-to-src translator bytecode.
Compiler course 1. Introduction. Outline Scope of the course Disciplines involved in it Abstract view for a compiler Front-end and back-end tasks Modules.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Elements of Computing Systems, Nisan & Schocken, MIT Press, 2005, Chapter 11: Compiler II: Code Generation slide 1www.idc.ac.il/tecs.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm Computer Science Building 470 TA: tba
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Programming Languages
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 11: Functions and stack frames.
CS453 LectureIntroduction1 CS453 Compiler Construction Original Design: Michelle Strout Instructor:Wim Bohm
LECTURE 3 Compiler Phases. COMPILER PHASES Compilation of a program proceeds through a fixed series of phases.  Each phase uses an (intermediate) form.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 10 Ahmed Ezzat.
Welcome! Simone Campanoni
Compilers: History and Context COMP Outline Compilers and languages Compilers and architectures – parallelism – memory hierarchies Other uses.
Compiler Summary Lexical analysis—scanner – String of characters  token – Finite automata. Syntactical analysis – parser – Sequence of tokens –> language.
Chapter 1. Introduction.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
CS 404 Introduction to Compiler Design
Simone Campanoni LLVM Simone Campanoni
COMP Compilers Lecture 1: Introduction
Advanced Computer Systems
Component 1.6.
Intro to compilers Based on end of Ch. 1 and start of Ch. 2 of textbook, plus a few additional references.
Compiler Design (40-414) Main Text Book:
Concepts of Programming Languages
Chapter 1 Introduction.
Final exam: Wednesday, March 20, 2:30pm
CS 3304 Comparative Languages
PROGRAMMING LANGUAGES
Compiler Construction (CS-636)
Chapter 1 Introduction.
课程名 编译原理 Compiling Techniques
Run-time organization
Simone Campanoni LLVM Simone Campanoni
CS 153: Concepts of Compiler Design November 28 Class Meeting
Compiler Lecture 1 CS510.
CS 536 / Fall 2017 Introduction to programming languages and compilers
Programming Languages and Translators
CS416 Compiler Design lec00-outline September 19, 2018
An Overview to Compiler Design
Course supervisor: Lubna Siddiqui
Lecture 2: General Structure of a Compiler
COMP Compilers Lecture 1: Introduction
CSE401 Introduction to Compiler Construction
COP4020 Programming Languages
CS416 Compiler Design lec00-outline February 23, 2019
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Compiler Construction
A Tour of Language Implementation
Week 1 - Friday COMP 1600.
Presentation transcript:

Simone Campanoni simonec@eecs.northwestern.edu Welcome! Simone Campanoni simonec@eecs.northwestern.edu

Outline Structure of the course CAT and compilers CAT and computer architecture CAT and programming language

CAT in a nutshell About: understanding and transforming code automatically EECS 395/495 Satisfy the system depth for CS major Tuesday/Thursday 2:00pm – 3:20pm at L221 Tech (here ;)) Office hours: Friday 2:00pm – 5:00pm But feel free to stop by at my office (2.217@Ford) any time CAT is on Canvas Materials/Calendar/Assignments/Grades on Canvas You’ll upload your assignments on Canvas

CAT materials Modern compiler implementation Slides and assigned papers LLVM documentation http://llvm.org

The CAT structure Topic & homework Week Today 12/8 Tuesday Thursday

The CAT grading Grade Points Homework: 100 points Extra points A 95 – 100 A - 90 – 94 B + 80 – 89 B 70 – 79 B - 61 – 69 C + 57 – 60 C 50 – 56 D 25 – 49 F 0 – 24 Homework: 100 points 10 points per assignment The first 2 assignments are trivial Extra points Extra homework Answering (correctly) make-concepts-in-action questions during pre-announced lectures Last year best: 114 points!

Rules for homework No copying of code is allowed Tool, infrastructure help is allowed First try it on your own (google and tool documentation are your friends) Avoid plagiarism www.northwestern.edu/provost/policies/academic-integrity/how-to-avoid-plagiarism.html If you don’t know, please ask: simonec@eecs.northwestern.edu

No final exam Summary My duties Your duties Teach you code analysis and transformation And how to implement them in a production compiler (LLVM) Your duties Learn code analysis and transformation Implement a few of them in LLVM Write code Test your code Then, think much harder about how to actually test your code (Sometimes) Answer my questions about your code No final exam

Structure & flexibility CAT is structured w/ topics Best way to learn is to be excited about a topic Interested in something? Speak I’ll do my best to include your topic on the fly

Topic & homework Week 1 Today Thursday Welcome/Structure Compiler/CAT F.E. M.E. B.E. Thursday LLVM

The role of compilers If there is no coffee, if I still have work to do, I’ll keep working, I’ll go to the coffee shop If there is no coffee{ if I still have work to do{ I’ll keep working; } I’ll go to the coffee shop; Code analysis and transformation Compilers ??? 00101010111001010101001010101011010

Theory Inter-fields Practice Compilers& CATs

Example of CAT varX = 5 … print varX What will it print?

Example of CAT varX = 5 … print 5 print varX What will it print?

Example of CAT Analysis Transformation Code Property varX = 5 … print 5 varX = 5 … print varX Analysis Property Transformation Is it worth transforming? Transformed code

Designing CATs Choose a goal Performance, energy, identifying bugs, discovering code properties Design automatic analysis to obtain the required information Occasionally design the code transformation

Use of CATs Compilers Optimize performance energy efficiency code generation Developing tools (e.g., VIM, EMACS) Understanding code (e.g., scopes, variables) Computer architecture

Structure of a compiler Character stream (Source code) i n t m a i n … Lexical analysis INT SPACE STRING SPACE … Tokens Syntactic & semantic analysis int main (){ printf(“Hello World!\n”); return 0; } Function signature Return type Function name AST INT STRING

Structure of a compiler Character stream (Source code) i n t m a i n … Lexical analysis INT SPACE STRING SPACE … Tokens Syntactic & semantic analysis AST Function signature Return type INT Function name STRING

Structure of a compiler Syntactic & semantic analysis Function signature Return type Function name AST INT STRING IR code generation ; Function Attrs: nounwind uwtable define int @main() { IR

Structure of a compiler Character stream (Source code) i n t m a i n … EECS 322: Compiler Construction Front-end ; Function Attrs: nounwind uwtable define int @main() { IR Middle-end Code analysis and transformation ; Function Attrs: nounwind uwtable define int @main() { IR EECS 322: Compiler Construction Back-end Machine code 010101110101010101

Structure of a compiler Character stream (Source code) Character stream (Source code) Front-end Front-end Middle-end Back-end IR Middle-end IR Back-end Machine code Machine code

Structure of a compiler Java C C Front-end Front-end Middle-end Back-end IR Middle-end IR Back-end Machine code Machine code

Structure of a compiler Java C Front-end Front-end Middle-end Back-end IR Middle-end IR Back-end Machine code Machine code

Structure of a compiler Java C Java Front-end FE Front-end Middle-end Back-end IR Middle-end IR Back-end Machine code M2 Machine code

Structure of a compiler Java C Java Front-end FE Front-end Middle-end Back-end IR Middle-end IR Back-end BE Machine code M2 M2

Structure of a compiler Front-end 2 Front-end 1 IR Middle-end IR Back-end A Back-end B M A M B

Multiple IRs IR needs to be easy to produce to translate into machine code to transform/optimize Multiple IRs Abstract Syntax Tree Register-based representation (three-address code) R1 = R2 add R3 Stack-based representation push 5; push 3; add; pop ; R1 + R2 R3

Example of IR LLVM define i32 @main(i32 %argc, i8** %argv) { entry: %add = add i32 %argc, 1 ret i32 %add }

Multiple IRs used together Static compiler IR1 Dynamic compiler FE IR2 Dynamic compiler BE Machine code

Multiple IRs used together Java Java compiler Java bytecode Java VM FE IR2 Java VM BE Machine code

CATs that we’ll focus on Semantics-preserving transformations Correctness guaranteed Goal: performance Automatic Efficient

Evolution of CATs (hardware point of view) Simple hardware (few resources), simple CATs Core Size Registers Latency Cache L1 Cache L2 Memory

Evolution of CATs (hardware point of view) Simple hardware (few resources), simple CATs More hardware resources available to compilers Opportunities to improve programs Challenging CATs Execution model mismatch between source code and hardware Compilers/CATs are developed in the processor-design stage!

Evolution of CATs (hardware point of view) (2) 1960 - ?: Complex instruction set computing (CISC) 1980 - ?: Reduced instruction set computer (RISC)

Evolution of CATs (hardware point of view) (3) Superscalar Very long instruction word (VLIW) Inst 1 Inst 1 Inst 4 Inst 7 Inst 8 Inst 2 CATs Inst 3 Inst 2 Inst 5 Inst 3 Inst 6 Inst 4 Inst 5 Inst 6 Inst 7 Inst 8

Evolution of CATs (PL point of view) First electronic computers appeared in the ’40s They were programmed in machine language Low level operations only Move data from one location to another Add the contexts of two registers Compare two values Programming: slow, tedious, and error prone 00101010111001010101001010101011010

Evolution of CATs (PL point of view) Low level programming language, simple CATs Not very productive More abstraction in programming language, more work for CATs to reduce their performance overhead Macros -> Fortran, Cobol, Lisp -> C, C++, Java, C#, Python, PHP, SQL, … CATs enable new programming languages

Evolution of CATs (PL point of view) Abstractions are great for productivity CATs remove their overhead But abstractions must be carefully evaluated considering CATs A simple abstraction in PL can generate challenges for CATs CATs need to be understood

Evolution of CATs (PL point of view)(2) PL without procedures void main (){ Int v1,v2; v1 = 1; v2 = 2; … }

Evolution of CATs (PL point of view)(3) Let’s add procedures to our PL Call-by-Value void proc1 (int a){…} proc1(myVar1); Call-by-Reference void proc1 (int *a){…} proc1(&myVar1);

Evolution of CATs (PL point of view)(2) void myProc (int *v1, int *v2){ (*v1) = 1; (*v2) = 2; } What’s the problem for CATs? … if v1 and v2 alias … Understanding if pointers alias: pointer alias analysis This is one of the most challenging problem in CATs

Conclusion CATs used for multiple goals Enable PLs Enable hardware features CATs are effected by Their input language The target hardware When you design a PL or a new hardware platform, you need to understand what CATs can and can’t do Some cant’s become can thanks to research on CATs

Ideal CATs Proved to be correct Improve performance of many important programs Minor compilation time Negligible implementation efforts

As Linus Torvalds says … Talk is cheap. Show me the code. Demo time