An Overview to Compiler Design

Slides:



Advertisements
Similar presentations
The University of Adelaide, School of Computer Science
Advertisements

MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
10/6: Lecture Topics Procedure call Calling conventions The stack
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
The University of Adelaide, School of Computer Science
Computer Architecture CSCE 350
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Ch. 8 Functions.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 4 Assembly Language Programming 2.
Procedures II (1) Fall 2005 Lecture 07: Procedure Calls (Part 2)
The University of Adelaide, School of Computer Science
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
The University of Adelaide, School of Computer Science
Procedure call frame: Hold values passed to a procedure as arguments
Prof. Necula CS 164 Lecture 141 Run-time Environments Lecture 8.
Register Conventions (1/4) °CalleR: the calling function °CalleE: the function being called °When callee returns from executing, the caller needs to know.
CS 536 Spring Run-time organization Lecture 19.
3/17/2008Prof. Hilfinger CS 164 Lecture 231 Run-time organization Lecture 23.
Run-time Environment and Program Organization
CMPUT Compiler Design and Optimization1 CMPUT680 - Winter 2006 Topic0: Introduction José Nelson Amaral
Compiler design Computer Science Rensselaer Polytechnic Lecture 1.
Lecture 2 Phases of Compiler. Preprocessors, Compilers, Assemblers, and Linkers Preprocessor Compiler Assembler Linker Skeletal Source Program Source.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
The Stack Pointer and the Frame Pointer (Lecture #19) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Compiler Run-time Organization Lecture 7. 2 What we have covered so far… We have covered the front-end phases –Lexical analysis –Parsing –Semantic analysis.
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.
Computer Architecture Instruction Set Architecture Lynn Choi Korea University.
1 Control Abstraction (Section ) CSCI 431 Programming Languages Fall 2003 A compilation of material developed by Felix Hernandez-Campos and Michael.
Activation Records (in Tiger) CS 471 October 24, 2007.
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.
CSC 8505 Compiler Construction Runtime Environments.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 11: Functions and stack frames.
RUNTIME ENVIRONMENT AND VARIABLE BINDINGS How to manage local variables.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
CSC 4181 Compiler Construction
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
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.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
Computer Architecture & Operations I
Lecture 5: Procedure Calls
MIPS Assembly Language Programming
PRINCIPLES OF COMPILER DESIGN
Chapter 1 Introduction.
Introduction to Compiler Construction
Computer Architecture Instruction Set Architecture
Introduction to Advanced Topics Chapter 1 Text Book: Advanced compiler Design implementation By Steven S Muchnick (Elsevier)
CMPUT Compiler Design and Optimization
Chapter 1 Introduction.
Run-time organization
Introduction to Compilers Tim Teitelbaum
Procedures (Functions)
Procedures (Functions)
Chapter 1: Introduction to Compiling (Cont.)
Compiler Lecture 1 CS510.
Compilers B V Sai Aravind (11CS10008).
The University of Adelaide, School of Computer Science
Topic 3-a Calling Convention 1/10/2019.
Systems Architecture I
Runtime Environments What is in the memory?.
Computer Architecture
Program and memory layout
Compiler Structures 1. Overview Objective
Intermediate Code Generating machine-independent intermediate form.
Topic 2b ISA Support for High-Level Languages
Presentation transcript:

An Overview to Compiler Design 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt

Outline An Overview of Compiler Structure Front End Middle End Back End 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt

Reading Slides and Lecture Notes Aho,Lam,Sethi,Ullman: Chapter 1.4 ~ 1.5 Chapter 2.1 ~ 2.7 Chapter 3.1 ~ 3.5 Chapter 4.1 ~ 4.5 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt

A Review on Compiler Structure/Design Overall structure Front-end: lexical and syntax analysis Middle-end: machine independent code analysis and (scalar, and sometimes loop nest ) optimization Back-end: Machine dependent code analysis and optimization 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt

Motivation for Compiler optimization Source Program COMPILER Machine Code Input program example: int foo( ) { int x; return (x + x) ; } 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt

Output Assembly Code (non-optimized) foo: sub $sp, $sp, 8 sw $fp, 8($sp) add $fp, $sp, 8 sw $ra, -4($fp) add $t0, $a0 $a0 move $v0, $t0 lw $ra, -4($fp) lw $fp, 0($fp) add $sp, $sp, 8 jr $ra 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt

Output Assembly Code (non-optimized) foo: sub $sp, $sp, 8 % Push stack frame sw $fp, 8($sp) % Save old frame pointer add $fp, $sp, 8 % Set new frame pointer sw $ra, -4($fp) % Save return address add $t0, $a0 $a0 % Addition move $v0, $t0 % Copy return value lw $ra, -4($fp) % Restore return address lw $fp, 0($fp) % Restore frame pointer add $sp, $sp, 8 % Pop stack frame jr $ra % Jump to return address 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt

Output Assembly Code -- Revisited (non-optimized) foo: sub $sp, $sp, 8 % Push stack frame (for what?) sw $fp, 8($sp) % Save old frame pointer (for what?) add $fp, $sp, 8 % Set new frame pointer sw $ra, -4($fp) % Save return address (for what?) add $t0, $a0, $a0 % Addition move $v0, $t0 % Copy return value lw $ra, -4($fp) % Restore return address lw $fp, 0($fp) % Restore frame pointer add $sp, $sp, 8 % Pop stack frame jr $ra % Jump to return address 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt

Output Assembly Code (optimized) foo: add $v0, $a0, $a0 % Set result jr $ra % Jump to return address 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt

Runtime Memory Organization frame-1 Entry point for procedure 1 code for procedure 1 Space for arguments (parameters) frame-2 code area Space for bookkeeping Information, including Return address code for procedure 2 frame-3 global/static area Entry point for procedure 2 … stack Space in local data … free space Space for local temporaries code for procedure n Runtime stack Entry point for procedure n A stack frame heap Code memory Address space 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt

Phases of a Compiler Source program Intermediate-code Generator Lexical Analyzer (Scanner) Non-optimized Intermediate Code Tokens Intermediate-code Optimizer Syntax Analyzer (Parser) Optimized Intermediate Code Parse tree Target-code Generator/Opt Semantic Analyzer Target machine code Abstract Syntax Tree w/ Attributes 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt

Two models of compiler structures Low-level Model Mixed-level Model String of characters String of tokens Parse tree Abstract Syntax tree Medium-level intermediate code Low-level intermediate code Relocatable object module or runnable machine code Lexical analyzer Abstract syntax tree Low-level intermediate code Relocatable object module or runnable machine code String of characters String of tokens Parse tree Lexical analyzer Parser Parser Semantic analyzer Semantic analyzer Intermediate-code generator Translator Optimizer Optimizer Code generator Final assembly Postpass optimizer Two models of compiler structures (Muchnick, pp. 08) 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt

A Good Compiler Infrastructure Needed – A modern View Front end Interprocedural Analysis and Optimization Good IR Loop Nest Optimization and Parallelization Global (Scalar) Optimization Middle-End Backend Code Generation 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt