deep

a Cross Development Platform for Java

User Tools

Site Tools


dev:crosscompiler:backend_ppc:register_allocation

This is an old revision of the document!


Register Allocation

The PowerPC architecture offers 32 GPR's and 32 FPR's.

Register Usage

Registers can be classified as dedicated, volatile or nonvolatile. Dedicated are register with a special purpose, such as the stackpointer. Volatile means, that this register might be used any time. It does not have to be stored when another method is called. Nonvolatile registers must be saved in the prologue of a method before they can be used and after use they must be restored. The number of volatile and nonvolatile registers must be equal for all methods.

Register State Use
R0 volatile method prologue, scratch register
R1 dedicated stack pointer
R2 volatile 1. parameter, return value
R3 volatile 2. parameter, return value (if long, lower 4 bytes of long)
R4-R10 volatile further parameters
R11-R12 volatile local variables, working registers
R13-R31 nonvolatile local variables, working registers
F0 volatile working register
F1 volatile 1. parameter, return value
F2-F8 volatile further parameters
F9-F12 volatile local variables, working registers
F13-F19 nonvolatile local variables, working registers
F20-F22 volatile utility register for compiler specific subroutines
F23-F31 nonvolatile local variables, working registers

Local variables are assigned volatile registers. However, if the live range of an SSA value incorporates a method call, a nonvolatile register has to be used. These will be assigned in decreasing order from R31/F31. As working registers volatile registers are used. If there are not enough of them, nonvolatiles (just below the locals) are assigned.
Optimization: If a method is a leaf method, it would not be necessary to copy the parameters from their volatile registers into nonvolatile registers.
For the translation of certain SSA instructions (e.g. of type long) further auxiliary registers are needed. They are assigned and reserved by the register allocator as well. If FPR's are needed for auxiliary registers, they are not reserved but F20..F22 will be used. They are exclusively used in compiler specific subroutines and never need saving.

Parameter Passing

Parameters are passed in R2..R10 and F1..F8.
In the interface cgPPC/Registers you can find the definitions about which registers are used for volatiles and nonvolatiles and which are used for parameter passing. Important: the number of parameter registers must be smaller or equal than the number of volatiles.

dev/crosscompiler/backend_ppc/register_allocation.1544545495.txt.gz · Last modified: 2018/12/11 17:24 by ursgraf