ECE1724F Compiler Primer Sept. 18, 2002.

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
Semantic analysis Parsing only verifies that the program consists of tokens arranged in a syntactically-valid combination, we now move on to semantic analysis,
Lecture 01 - Introduction Eran Yahav 1. 2 Who? Eran Yahav Taub 734 Tel: Monday 13:30-14:30
10/22/2002© 2002 Hal Perkins & UW CSEG-1 CSE 582 – Compilers Intermediate Representations Hal Perkins Autumn 2002.
Cpeg421-08S/final-review1 Course Review Tom St. John.
1 Semantic Processing. 2 Contents Introduction Introduction A Simple Compiler A Simple Compiler Scanning – Theory and Practice Scanning – Theory and Practice.
ECE1724F Compiler Primer Sept. 18, 2002.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
From Cooper & Torczon1 Implications Must recognize legal (and illegal) programs Must generate correct code Must manage storage of all variables (and code)
Compiler Construction1 A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University First Semester 2009/2010.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Lecture 2 Phases of Compiler. Preprocessors, Compilers, Assemblers, and Linkers Preprocessor Compiler Assembler Linker Skeletal Source Program Source.
ANTLR with ASTs. Abstract Syntax Trees ANTLR can be instructed to produce ASTs for the output of the parser ANTLR uses a prefix notation for representing.
CPSC 388 – Compiler Design and Construction Lecture: MWF 11:00am-12:20pm, Room 106 Colton.
ICS611 Introduction to Compilers Set 1. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
Getting Started with ANTLR Chapter 1. Domain Specific Languages DSLs are high-level languages designed for specific tasks DSLs include data formats, configuration.
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.
10/1/2015© Hal Perkins & UW CSEG-1 CSE P 501 – Compilers Intermediate Representations Hal Perkins Autumn 2009.
What’s in an optimizing compiler?
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
CSC 338: Compiler design and implementation
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.
COMPILER OVERVIEW. Compiler Phases  Syntactic Analysis (Lexing, Parsing)  c = (a + b) * (a + b);
Lexical and Syntax Analysis
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Compressed Abstract Syntax Trees as Mobile Code Christian H. Stork Vivek Haldar University of California, Irvine.
Towards the better software metrics tool motivation and the first experiences Gordana Rakić Zoran Budimac.
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
Introduction Lecture 1 Wed, Jan 12, The Stages of Compilation Lexical analysis. Syntactic analysis. Semantic analysis. Intermediate code generation.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
Introduction to Code Generation and Intermediate Representations
Chapter 1 Introduction Study Goals: Master: the phases of a compiler Understand: what is a compiler Know: interpreter,compiler structure.
Compilers: Overview/1 1 Compiler Structures Objective – –what are the main features (structures) in a compiler? , Semester 1,
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
INTRODUCTION TO COMPILERS(cond….) Prepared By: Mayank Varshney(04CS3019)
Intermediate Code Representations
Compiler Introduction 1 Kavita Patel. Outlines 2  1.1 What Do Compilers Do?  1.2 The Structure of a Compiler  1.3 Compilation Process  1.4 Phases.
12/18/2015© Hal Perkins & UW CSEG-1 CSE P 501 – Compilers Intermediate Representations Hal Perkins Winter 2008.
Compiler Optimizations ECE 454 Computer Systems Programming Topics: The Role of the Compiler Common Compiler (Automatic) Code Optimizations Cristiana Amza.
The Model of Compilation Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 2: Lexical Analysis.
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
What is a compiler? –A program that reads a program written in one language (source language) and translates it into an equivalent program in another language.
Compilers Computer Symbol Table Output Scanner (lexical analysis)
CSC 4181 Compiler Construction
LECTURE 3 Compiler Phases. COMPILER PHASES Compilation of a program proceeds through a fixed series of phases.  Each phase uses an (intermediate) form.
Language Implementation Overview John Keyser Spring 2016.
©SoftMoore ConsultingSlide 1 Structure of Compilers.
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
1 Compiler Construction Vana Doufexi office CS dept.
ECE 587 Hardware/Software Co- Design Lecture 23 LLVM and xPilot Professor Jia Wang Department of Electrical and Computer Engineering Illinois Institute.
Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)
Advanced Computer Systems
PRINCIPLES OF COMPILER DESIGN
Introduction to Compiler Construction
Introduction to Advanced Topics Chapter 1 Text Book: Advanced compiler Design implementation By Steven S Muchnick (Elsevier)
课程名 编译原理 Compiling Techniques
CS 536 / Fall 2017 Introduction to programming languages and compilers
CSc 453 Compilers & Systems Software 00. Background
Compiler Construction
An Overview to Compiler Design
Front End vs Back End of a Compilers
Compilers B V Sai Aravind (11CS10008).
CMPE 152: Compiler Design August 21/23 Lab
Faculty of Computer Science and Information System
Presentation transcript:

ECE1724F Compiler Primer Sept. 18, 2002

What’s in an optimizing compiler? Front EndOptimizer High-level language (C, C++, Java) Low-level language (mc68000, ia32, etc…) HLLIR (Usually very naive) IR (Better, we hope) Code Generator LLL

What are compiler optimizations? Optimization:the transformation of a program P into a program P’, that has the same input/output behavior, but is somehow “better”. “better” means:  faster  or smaller  or uses less power  or whatever you care about P’ is not optimal, may even be worse than P

An optimizations must: Preserve correctness  the speed of an incorrect program is irrelevant On average improve performance  P’ is not optimal, but it should usually be better Be “worth the effort”  1 person-year of work, 2x increase in compilation time, a 0.1% improvement in speed?  Find the bottlenecks  90/10 rule: 90% of the gain for 10% of the work

Compiler High-level language C, C++, Java Low-level language mc68000 Lexical Analyzer Parser IR Code Generator Optimizer m/c Code Generator tokensASTIR IR: Intermediate Representation Compiler Phases (Passes)

We’ll talk about: Lexing & Parsing Control Flow Analysis Data Flow Analysis

Lexing, Parsing and Intermediate Representations

Lexers & Parsers The lexer identifies tokens in a program The parser identifies grammatical phrases, or constructs in the program There are freely available lexer and parser generators… The parser usually constructs some intermediate form of the program as output

Intermediate Representation The representation or language on which the compiler performs it’s optimizations As many IRs as compiler suites  2x as many IRs as compiler suites (Muchnick) Some IRs are better for some optimizations  different information is maintained  easier to find certain types of information

Why Use an IR? IR Java Fortran C C++ Voss++ MIPS Sun SPARC IA32 / Pentium IA64 / Itanium PowerPC Good Software Engineering  Portability  Reuse

Example: float a[20][10]; … = a[i][j+2] … t1 ← a[i,j + 2] t1 ← j+2 t2 ← i*10 t3 ← t1 + t2 t4 ← 4 * t3 t5 ← addr a t6 ← t5 + t4 t7 ← *t6 r1 ← [fp-4] r2 ← r1 + 2 r3 ← [fp-8] r4 ← r3*10 r5 ← r4 + r2 r6 ← 4 * r5 r7 ← fp f1 ← [r7 + r6] (a) High-Level(b) Medium-Level(c) Low-Level

High-Level: Abstract Syntax Tree (AST) int f(a,b) int a,b; { int c; c = a +2; print(b,c); } function ident paramlist body f ident paramlist decllist stmtlist a ident end ident end = stmlist b c ident + call end c ident const ident arglist c printf ident arglist b ident end c

Linear List (Very Similar to Source) S12 FLOWENTRY {succ = S1, line = 1, } S1 ENTRY simple() {succ = S2, pred = S12, line = 1, } S2 DO i = 1, 100, 1 { follow = S7, succ = S3, S8, pred = S1, S7, out_refs * = i, line = 3, assertions = { AS_PARALLEL (i) } {AS_PRIVATE j,i } * { AS_LOOPLABEL SIMPLE_do100 } { AS_SHARED a } S3 DO j = 1, 100, 1 { follow = S6, succ = S4, S7, pred = S6, S2, out_refs * = j, outer = S2, line = 4, assertions = * { AS_LOOPLABEL SIMPLE_do100/2 } } S4 100 LABEL 100 {succ = S5, pred = S3, outer = S3, line = 5, } S5 a(j, i) = i*j {succ = S6, pred = S4, in_refs = i, j, j, i, out_refs = * a(j, i), outer = S3, line = 5, } S6 ENDDO { follow = S3, succ = S3, pred = S5, outer = S3, line = 5, } S7 ENDDO { follow = S2, succ = S2, pred = S3, outer = S2, line = 5 } S8 WRITE ([UNIT, 6], [FMT, *]) a {succ = S9, pred = S2, in_refs = a, * line = 6, } S9 STOP {succ = S10, pred = S8, line = 7, } S10 FLOWEXIT {pred = S9, line = 7, } PROGRAM SIMPLE REAL A(100,100) DO 100 I = 1,100 DO 100 J = 1, A(J,I) = J*I WRITE (6,*) A END