0% found this document useful (0 votes)
12 views

PDFsam Merge

Uploaded by

Atharva Tambat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

PDFsam Merge

Uploaded by

Atharva Tambat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Register Categories for Spim

All Registers
IIT Bombay
cs302: Implementation
of Programming Not Available
Available to Compiler
Languages to Compiler
Topic:
Code Generation
Section: General Floating Point
Global Register (on co-processor)
Allocation
Managing Registers
Across Calls
GPRs Fixed
Registers Usage in
sclp (address + data)
Instruction Selection
Address Data
Caller-saved Callee-saved

30/61
Registers in Spim
Name No. Sizes Use Category Name No. Sizes Use Category
constant s0 16 32,64 temporary callee-saved
$zero 00 32
data s1 17 32 temporary callee-saved
IIT Bombay at 01 32 NA s2 18 32,64 result callee-saved
cs302: Implementation
of Programming
v0 02 32,64 expr result caller-saved s3 19 32 result callee-saved
Languages v1 03 32 function result caller-saved s4 20 32,64 temporary callee-saved
a0 04 32,64 argument caller-saved
Topic: s5 21 32 temporary callee-saved
Code Generation a1 05 32 argument caller-saved
s6 22 32,64 temporary callee-saved
Section: a2 06 32,64 argument caller-saved
s7 23 32 temporary callee-saved
Global Register
Allocation
a3 07 32 argument caller-saved
t8 24 32,64 temporary caller-saved
Managing Registers
t0 08 32,64 temporary caller-saved
Across Calls t1 09 32 temporary caller-saved t9 25 32 temporary caller-saved
Registers Usage in t2 10 32,64 temporary caller-saved k0 26 32,64 NA
sclp
t3 11 32 temporary caller-saved k1 27 32 NA
Instruction Selection
t4 12 32,64 temporary caller-saved gp 28 32,64 global pointer address
t5 13 32 temporary caller-saved sp 29 32 stack pointer address
t6 14 32,64 temporary caller-saved fp 30 32,64 frame pointer address
t7 15 32 temporary caller-saved ra 31 32 return address address
31/61
Co-Processor Registers in Spim

Name Number Sizes Name Number Sizes


f0 00 32,64 f16 16 32,64
f1 01 32 f17 17 32
IIT Bombay
cs302: Implementation f2 02 32,64 f19 18 32,64
of Programming
Languages
f3 03 32 f19 19 32
f4 04 32,64 f20 20 32,64
Topic:
f5 05 32 f21 21 32
Code Generation
Section:
f6 06 32,64 f22 22 32,64
Global Register f7 07 32 f23 23 32
Allocation
f8 08 32,64 f24 24 32,64
Managing Registers
Across Calls f9 09 32 f25 25 32
Registers Usage in f10 10 32,64 f26 26 32,64
sclp
f11 11 32 f27 27 32
Instruction Selection
f12 12 32,64 f28 28 32,64
f13 13 32 f29 29 32
f14 14 32,64 f30 30 32,64
f15 15 32 f31 31 32

32/61
Registers Used By SCLP for Storing Intermediate Results

Register Register Register


IIT Bombay Type Type Type
cs302: Implementation
Name Pair Name Pair Name Pair
of Programming
Languages v0 int s0 int f8 f8,f9 float
v1 int s1 int f10 f10,f11 float
Topic:
Code Generation
t0 int s2 int f12 f12,f13 float
Section: t1 int s3 int f14 f14,f15 float
Global Register t2 int s4 int f16 f16,f17 float
Allocation
Managing Registers
t3 int s5 int f18 f18,f19 float
Across Calls t4 int s6 int f20 f20,f21 float
Registers Usage in
sclp
t5 int s7 int f22 f22,f23 float
Instruction Selection t6 int f0 f0,f1 float f24 f24,f25 float
t7 int f2 f2,f3 float f26 f26,f27 float
t8 int f4 f4,f5 float f28 f28,f29 float
t9 int f6 f5,f6 float f30 f30,f31 float

33/61
Registers Used By SCLP for Storing Intermediate Results
Designated for function result, hence ignored

Register Register Register


IIT Bombay Type Type Type
cs302: Implementation
Name Pair Name Pair Name Pair
of Programming
Languages v0 int s0 int f8 f8,f9 float
v1 int s1 int f10 f10,f11 float
Topic:
Code Generation
t0 int s2 int f12 f12,f13 float
Section: t1 int s3 int f14 f14,f15 float
Global Register t2 int s4 int f16 f16,f17 float
Allocation
Managing Registers
t3 int s5 int f18 f18,f19 float
Across Calls t4 int s6 int f20 f20,f21 float
Registers Usage in
sclp
t5 int s7 int f22 f22,f23 float
Instruction Selection t6 int f0 f0,f1 float f24 f24,f25 float
t7 int f2 f2,f3 float f26 f26,f27 float
t8 int f4 f4,f5 float f28 f28,f29 float
t9 int f6 f5,f6 float f30 f30,f31 float

33/61
Registers Used By SCLP for Storing Intermediate Results
Designated for function result, hence ignored

Register Register Register


IIT Bombay Type Type Type
cs302: Implementation
Name Pair Name Pair Name Pair
of Programming
Languages v0 int s0 int f8 f8,f9 float
v1 int s1 int f10 f10,f11 float
Topic:
Code Generation
t0 int s2 int f12 f12,f13 float
Section: t1 int s3 int f14 f14,f15 float
Global Register t2 int s4 int f16 f16,f17 float
Allocation
Managing Registers
t3 int s5 int f18 f18,f19 float
Across Calls t4 int s6 int f20 f20,f21 float
Registers Usage in
sclp
t5 int s7 int f22 f22,f23 float
Instruction Selection t6 int f0 f0,f1 float f24 f24,f25 float
t7 int f2 f2,f3 float f26 f26,f27 float
t8 int f4 f4,f5 float f28 f28,f29 float
t9 int f6 f5,f6 float f30 f30,f31 float

33/61
Register Allocation Policy Used by sclp
Very simple strategy
• No register is occupied across any assignment in the source program
The result is stored in memory for the LHS variable and the result register is freed
IIT Bombay
cs302: Implementation • Within an expression, values of source variables are loaded into registers
of Programming
Languages
• Intermediate values within an expression (stored in a temporary variable) are
Topic: assigned a register
Code Generation
The result of a ternary expression is a “saved” temporary which is treated like a
Section:
Global Register
source variable
Allocation
• Getting a new register
Managing Registers
Across Calls
◦ When a temporary is assigned a register, mark it as occupied
Registers Usage in
sclp ◦ When a temporary is used in a TAC statement, mark the register as free
Instruction Selection ◦ To get a new register,
− Traverse the list of registers and assign the first free register
− Need to match the type
• Registers are chosen for a TAC statement in this order: first operand, result,
second operand (because second operand may not exist)
34/61
Instruction Selection in sclp
Asgn TAC Stmt Move RTL Stmt Move ASM Stmt

Compute TAC Stmt Compute RTL Stmt Compute ASM Stmt


IIT Bombay
cs302: Implementation
Call RTL Stmt
of Programming Call TAC Stmt Call ASM Stmt
Languages

Topic:
Goto RTL Stmt
Goto TAC Stmt Goto ASM Stmt
Code Generation
Section: IfGoto RTL Stmt
Global Register IfGoto TAC Stmt IfGoto ASM Stmt
Allocation
Return RTL Stmt
Managing Registers
Across Calls Return TAC Stmt Return ASM Stmt
Registers Usage in Label RTL Stmt
sclp
Instruction Selection Label TAC Stmt Label ASM Stmt
Read RTL Stmt
IO TAC Stmt Write RTL Stmt Syscall ASM Stmt

NOP TAC Stmt NOP RTL Stmt NOP ASM Stmt


35/61
Instruction Selection in sclp
Asgn TAC Stmt Move RTL Stmt Move ASM Stmt
Represents
Compute RTL theStmt
Compute TAC Stmt Compute ASM Stmt
IIT Bombay
source assignment
cs302: Implementation statement
Call RTL Stmt
of Programming Call TAC Stmt Call ASM Stmt
Languages

Topic:
Goto RTL Stmt
Goto TAC Stmt Goto ASM Stmt
Code Generation
Section:
Represents
IfGoto RTLthe
Stmt
Global Register IfGoto TAC Stmt computations stored IfGoto ASM Stmt
Allocation
in temporaries
Return RTL Stmt
Managing Registers
Across Calls Return TAC Stmt Return ASM Stmt
Registers Usage in Label RTL Stmt
sclp
Instruction Selection Label TAC Stmt Label ASM Stmt
Read RTL Stmt
IO TAC Stmt Write RTL Stmt Syscall ASM Stmt

NOP TAC Stmt NOP RTL Stmt NOP ASM Stmt


35/61
Instruction Selection in sclp
Asgn TAC Stmt Move RTL Stmt Move ASM Stmt

Compute TAC Stmt Compute RTL Stmt Compute ASM Stmt


IIT Bombay
cs302: Implementation
Call RTL Stmt
of Programming Call TAC Stmt Call ASM Stmt
Languages

Topic:
Goto RTL Stmt
Goto TAC Stmt Goto ASM Stmt
Code Generation
Section: IfGoto RTL Stmt
Global Register IfGoto TAC Stmt IfGoto ASM Stmt
Allocation
Return RTL Stmt
Managing Registers
Across Calls Return TAC Stmt Return ASM Stmt
Registers Usage in Label RTL Stmt
sclp
Instruction Selection Label TAC Stmt Label ASM Stmt
Read RTL Stmt
IO TAC Stmt Write RTL Stmt Syscall ASM Stmt

NOP TAC Stmt NOP RTL Stmt NOP ASM Stmt


35/61

You might also like