PDFsam Merge
PDFsam Merge
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
32/61
Registers Used By SCLP for Storing Intermediate Results
33/61
Registers Used By SCLP for Storing Intermediate Results
Designated for function result, hence ignored
33/61
Registers Used By SCLP for Storing Intermediate Results
Designated for function result, hence ignored
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
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
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
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