CS453 Register Allocation

Similar documents
COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

Course Administration

Function Calling Conventions 2 CS 64: Computer Organization and Design Logic Lecture #10

Separate compilation. Topic 6: Runtime Environments p.1/21. CS 526 Topic 6: Runtime Environments The linkage convention

Plan. Regression testing: Demo of how to use the regress.sh script.

Stack Frames. September 2, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 September 2, / 15

Functions and the MIPS Calling Convention 2 CS 64: Computer Organization and Design Logic Lecture #11

CSE Lecture In Class Example Handout

CIT Week13 Lecture

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

Implementing Procedure Calls

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

Topic 3-a. Calling Convention 2/29/2008 1

CSC 2400: Computer Systems. Using the Stack for Function Calls

Lectures 3-4: MIPS instructions

MIPS Procedure Calls. Lecture 6 CS301

The Activation Record (AR)

CS 314 Principles of Programming Languages. Lecture 13

System Software Assignment 1 Runtime Support for Procedures

ECE232: Hardware Organization and Design

The plot thickens. Some MIPS instructions you can write cannot be translated to a 32-bit number

The plot thickens. Some MIPS instructions you can write cannot be translated to a 32-bit number

Lecture 5: Procedure Calls

SPIM Procedure Calls

Implementing Functions at the Machine Level

Calling Conventions. See P&H 2.8 and Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University

Compiler Architecture

Assembly Language: Function Calls

CA Compiler Construction

CSC 2400: Computing Systems. X86 Assembly: Function Calls"

MIPS Datapath. MIPS Registers (and the conventions associated with them) MIPS Instruction Types

Using the MIPS Calling Convention. Recursive Functions in Assembly. CS 64: Computer Organization and Design Logic Lecture #10 Fall 2018

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Control Instructions

Assembly Language: Function Calls" Goals of this Lecture"

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

Subroutines. int main() { int i, j; i = 5; j = celtokel(i); i = j; return 0;}

Procedures and Stacks

Assembly Language: Function Calls" Goals of this Lecture"

Chapter 2A Instructions: Language of the Computer

Announcements. Class 7: Intro to SRC Simulator Procedure Calls HLL -> Assembly. Agenda. SRC Procedure Calls. SRC Memory Layout. High Level Program

CSC 2400: Computing Systems. X86 Assembly: Function Calls

CSC 8400: Computer Systems. Using the Stack for Function Calls

Register Allocation. CS 502 Lecture 14 11/25/08

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

Code Generation. The Main Idea of Today s Lecture. We can emit stack-machine-style code for expressions via recursion. Lecture Outline.

We can emit stack-machine-style code for expressions via recursion

COSC 6385 Computer Architecture. Instruction Set Architectures

Memory Usage 0x7fffffff. stack. dynamic data. static data 0x Code Reserved 0x x A software convention

Function Calling Conventions 1 CS 64: Computer Organization and Design Logic Lecture #9

Instructions: Assembly Language

IA32 Stack. Lecture 5 Machine-Level Programming III: Procedures. IA32 Stack Popping. IA32 Stack Pushing. Topics. Pushing. Popping

CS213. Machine-Level Programming III: Procedures

Run-Time Environments

Systems I. Machine-Level Programming V: Procedures

Code Genera*on for Control Flow Constructs

IR Lowering. Notation. Lowering Methodology. Nested Expressions. Nested Statements CS412/CS413. Introduction to Compilers Tim Teitelbaum

CS 316: Procedure Calls/Pipelining

Control Abstraction. Hwansoo Han

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

CS A331 Programming Language Concepts

comp 180 Lecture 10 Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions

2/16/2018. Procedures, the basic idea. MIPS Procedure convention. Example: compute multiplication. Re-write it as a MIPS procedure

CS61C : Machine Structures

Giving credit where credit is due

Wednesday, October 15, 14. Functions

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 19: Efficient IL Lowering 5 March 08

Run-time Environments - 2

Today More register allocation Clarifications from last time Finish improvements on basic graph coloring concept Procedure calls Interprocedural

Assembly Language: Function Calls. Goals of this Lecture. Function Call Problems

Processor Architecture. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Language of the Machine Recursive functions

See P&H 2.8 and 2.12, and A.5-6. Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University

Math 230 Assembly Programming (AKA Computer Organization) Spring MIPS Intro

CSCE 5610: Computer Architecture

Low-Level Issues. Register Allocation. Last lecture! Liveness analysis! Register allocation. ! More register allocation. ! Instruction scheduling

Programming Languages

Chapter 9 :: Subroutines and Control Abstraction

CSC 2400: Computer Systems. Using the Stack for Function Calls

Stack Frames. Compilers use the stack: to store the to to a subroutine for storage of declared in the subroutine and a place to

Processor Architecture

Calling Conventions. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See P&H 2.8 and 2.12

CS558 Programming Languages

Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27

April 15, 2015 More Register Allocation 1. Problem Register values may change across procedure calls The allocator must be sensitive to this

CS153: Compilers Lecture 8: Compiling Calls

Chapter 10 Memory Model for Program Execution. Problem

EE 361 University of Hawaii Fall

Compilers. Intermediate representations and code generation. Yannis Smaragdakis, U. Athens (original slides by Sam

MIPS Functions and Instruction Formats

CS 110 Computer Architecture Lecture 6: More MIPS, MIPS Functions

Chapter 2. lw $s1,100($s2) $s1 = Memory[$s2+100] sw $s1,100($s2) Memory[$s2+100] = $s1

Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology

Lectures 5. Announcements: Today: Oops in Strings/pointers (example from last time) Functions in MIPS

Code generation scheme for RCMA

ECE251: Tuesday September 18

CS356: Discussion #6 Assembly Procedures and Arrays. Marco Paolieri

MIPS Programming. A basic rule is: try to be mechanical (that is, don't be "tricky") when you translate high-level code into assembler code.

Topic 7: Activation Records

Implementing Threads. Operating Systems In Depth II 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

Transcription:

CS453 Register Allocation

Quick quiz In C, how can r=(a+b)+(c+d) be evaluated? e.g. as follows? t1 = a+d t2 = b+c r = t1+t2 (page 207 of ANSI and traditional C ref. manual 3 rd edition) How about in Java? CS453 Lecture Register Allocation 2

Register Use so far So far we have used registers mostly as temporaries: 1. operator Expression: pop operand(s) into register(s) perform operation into result register push result register 2. method call caller passes actual parameters through registers to callee r24:r25 down to r8:r9 callee pushes them into the stack frame 3. this is loaded from stack location (Y+1, Y+2) into r30:r31 (Z) when needed Longer lived: SP has one specific role FP (r28:r39) lives during one method activation, caller FP gets saved in callee stack frame CS453 Lecture Register Allocation 3

More register use We have more registers and want to use these WHY? to avoid push / pop data movement (executing fewer instructions) register access is faster than memory access We want to minimize the number of registers to be used WHY? there are only a few registers (32 in AVR) fewer registers require fewer moves more variables can be associated with registers CS453 Lecture Register Allocation 4

Two new forms of register use 1. registers for (temporary) expressions - these don t have to have an identifier associated with them i+1 - currently live on the RTS if they live in a register, push and pop can be avoided 2. registers for parameters and locals - longer lifetime (method activation) - may need to be saved on the stack when another method is called who saves which registers? (callee saved / caller saved) CS453 Lecture Register Allocation 5

Register allocation for expressions What is the smallest number of registers (or temporary positions) we need for a certain expression? a+b a*b+c*d for this expresssion tree? CS453 Lecture Register Allocation 6

Register allocation for expressions What is the smallest number of registers (or temporary positions) we need for a certain expression? a+b a*b+c*d for this expresssion tree? r1 r1 r2 r1 r2 r2 r3 r1 r2 r3 r4 CS453 Lecture Register Allocation 7

Code generation for expressions with (some) registers - if k registers available, associate as many expressions with these registers as possible (using the symbol table) - now some expressions have a register associated with them and some don t - adjust regpair helper functions storeexpression() and loadexpression() to deal with this regpair loadexpression(backup_reg(s)) if expression associated with reg(s) return these else pop values into backup reg(s) and return these storeexpression(src_reg(s)) if expression associated with reg(s) move src_reg(s) into these else push src_reg(s) CS453 Lecture Register Allocation 8

Callee and caller saved registers Register saving Callee: if callee is going to use certain callee saved registers, then it saves at function prolog (and restores at function epilog) their current value same for caller saved registers (save just before call, restore right after) Callee saving occurs once per method activation Why callee and caller saved registers? so we can play optimization games e.g. method f calls method h many times (e.g. in a loop) method h calls no other methods then f can use callee saved regs and h can use caller saved regs (no need for saving these) CS453 Lecture Register Allocation 9

Register allocation for parameters and locals We can now assign left over registers to locals and parameters - Instead of fetching and storing locals from to stack we use their allocated registers - Incoming parameter values are moved into registers instead of copied to the stack - Adjust regpair loadvar() and storevar() helper functions: regpair loadvar(backup_reg(s)) if var in reg(s) return these else fetch Var (base+offset) and copy to backup_reg(s) regpair storevar(src_reg(s)) if var in reg(s) copy src_reg(s) to these else copy src_reg(s) to Var (base+offset) CS453 Lecture Register Allocation 10