CPSC 325 - Compiler Tutorial 8 Code Generator (unoptimized)

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
Chapter 8: Central Processing Unit
CPU Review and Programming Models CT101 – Computing Systems.
Chapter 9 TRAP Routines and Subroutines. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9-2 Subroutines.
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.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Computer Architecture CSCE 350
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
The University of Adelaide, School of Computer Science
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
Chapter 16 Control Unit Operation No HW problems on this chapter. It is important to understand this material on the architecture of computer control units,
CS 536 Spring Code generation I Lecture 20.
1 Lecture 9 Runtime Environment. 2 Outline Basic computer execution model Procedure abstraction run-time storage management Procedure linkage We need.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
Chapter 16 Control Unit Implemntation. A Basic Computer Model.
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
Chapter 15 IA 64 Architecture Review Predication Predication Registers Speculation Control Data Software Pipelining Prolog, Kernel, & Epilog phases Automatic.
Computer Organization and Assembly language
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Computer Science 210 Computer Organization The Instruction Execution Cycle.
System Calls 1.
An Introduction Chapter Chapter 1 Introduction2 Computer Systems  Programmable machines  Hardware + Software (program) HardwareProgram.
Machine Instruction Characteristics
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
Computer Architecture Instruction Set Architecture Lynn Choi Korea University.
Copyright © 2005 Elsevier Chapter 8 :: Subroutines and Control Abstraction Programming Language Pragmatics Michael L. Scott.
Computer architecture Lecture 11: Reduced Instruction Set Computers Piotr Bilski.
Topic 2d High-Level languages and Systems Software
Procedure Basics Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Procedure Support From previous study of high-level languages,
6.S078 - Computer Architecture: A Constructive Approach Introduction to SMIPS Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Lecture 4: MIPS Instruction Set
ECEG-3202 Computer Architecture and Organization Chapter 3 Top Level View of Computer Function and Interconnection.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
COMPUTER ORGANIZATION LECTURE 3: ISA YASSER MOHAMMAD.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 10 Ahmed Ezzat.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
F453 Module 8: Low Level Languages 8.1: Use of Computer Architecture.
A Single Intermediate Language That Supports Multiple Implemtntation of Exceptions Delvin Defoe Washington University in Saint Louis Department of Computer.
Lecture 3 Translation.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Computer Science 210 Computer Organization
Assembly language.
Computer Architecture Instruction Set Architecture
Overview Introduction General Register Organization Stack Organization
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Introduction to Compilers Tim Teitelbaum
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Chap. 8 :: Subroutines and Control Abstraction
Chap. 8 :: Subroutines and Control Abstraction
MIPS Instructions.
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
ECEG-3202 Computer Architecture and Organization
BIC 10503: COMPUTER ARCHITECTURE
Where is all the knowledge we lost with information? T. S. Eliot
Lecture 4: Instruction Set Design/Pipelining
Program Assembly.
Presentation transcript:

CPSC Compiler Tutorial 8 Code Generator (unoptimized)

What is Code Generator?

Intermediate Representation

What Code Generator should do? Translate all the instructions in the intermediate representation to assembly language Allocate space for the variables, arrays etc. Create the necessary symbolic information Gather all of the necessary information

What does computer understand?

Assembly language Advantages – Simplifies code generation due to use of symbolic instructions and symbolic names – Logical abstraction layer – Multiple Architectures can describe by a single assembly language Can modify the implementation – Macro assembly instructions Disadvantages – Additional process of assembling and linking – Assembler adds overhead

Assembly langauge Relocatable machine language (object modules) – All locations (addresses) represented by symbols – Mapped to memory addresses at link and load time – Flexibility of separate compilation Absolute machine language – Addresses are hard-coded – Simple and straightforward implementation – Inflexible – hard to reload generated code – Used in interrupt handlers and device drivers

Assembly example

Modern CPU ALU Control Memory Registers Memory RegistersALU Control

Arithmetic and Logic Unit (ALU) Performs most of the data operations Has the form: – OP R dest, R src1, R src2 Operations are: – Arithmetic operations (add, sub, mulo) – Logical operations (and, sll) – Comparison operations (seq, sge, slt)

Arithmetic and Logic Unit (ALU) Many arithmetic operations can cause an exception – Overflow and underflow Can operate on different data types – 8, 16, 32 bits – Signed and unsigned arithmetic – Floating-point operations (separate ALU)

Control Handles the instruction sequencing Executing instructions – All instructions are in memory – Fetch the instruction pointed by the PC and execute it – For general instructions, increment the PC to point to the next location in memory

Control Unconditional Branches – Fetch the next instruction from a different location – Unconditional jump to an address j label – Unconditional jump to an address in a register jr r src – To handle procedure calls, do an unconditional jump, but save the next address in the current stream in a register jal labeljalr r src

Control Conditional Branches – Perform a test, if successful fetch instructions from a new address, otherwise fetch the next instruction – Instructions are of the form: brelop R src1, R src2, label – relop is of the form: eq, ne, gt, ge, lt, le

Control Control transfer in special (rare) cases – traps and exceptions – Mechanism save the next (or current) instruction location find the address to jump to (from an exception vector) jump to that location

Others, additional information… Please refer to your CPSC231 text book… In the book; there is all of the details.

Memory layout Stack Heap Data segment Text Segment Reserved

Register – – 23 8 – 15 4 – 7 2 – return addressra frame pointerfp stack pointersp pointer to global areagp caller saved temporaryt8, t9 calliee saved temporarys0 – s7 caller saved temporaryt0 – t7 arguments 1 to 4a0 – a3 expr. eval and return of resultv0 – v1 Reserved for asmat hard-wired to zerozero

Stack (cont.) Please refer to the hand out for more details..

Guidelines for the code generator Lower the abstraction level slowly – Do many passes, that do few things (or one things) Easier to break the project down, generate and debug Keep the abstraction level consistent – IR should have ‘correct’ semantics at all time at least you should know the semantics Use assertions liberally – Use an assertion to check your assumption

Guidelines for the code generator Do the simplest but dump thing – it is ok to generate 0 + 1*x + 0*y Make sure you know what can be done at… – Compile time in the compiler – Runtime in a runtime library – Runtime using generated code Runtime library is your friend! – Don’t generate complex code sequences when it can be done in a runtime library assembly hack

Guidelines for the code generator Remember that optimizations will come later – Let the optimizer do the optimizations – Think about what optimizer will need and structure you code accordingly – Example: Register allocation, algebraic simplification, constant propagation Setup a good testing program