Java Reference
In-Depth Information
An essential component of any code generator is therefore its register
allocator. Machine registers are assigned to program variables and expres-
sions. Since registers are limited in number, they must be reclaimed (reused)
throughout a program.
A register allocator may be a simple on-the-fly algorithm that assigns and
reclaims registers as code is generated. We will consider on-the-fly techniques
first. More thorough register allocators, that consider the register needs of an
entire subprogram or program will be considered next.
13.3.1 On-the-Fly Register Allocation
Most computers have distinct integer (general purpose) and floating register
sets. In organizing our register allocator, we will divide each register set into
a number of classes:
Allocatable registers
Reserved registers
Work registers
Allocatable registers are explicitly allocated and freed by compile-time calls
to register management routines. While allocated, registers are protected from
use by any but the current “owner” of the register. It is therefore possible
to guarantee that a register containing a data value will not be incorrectly
changed by another use of the same register.
Requests for allocatable registers are usually generic; that is, requests are
for any member of a register class, not for a particular register in that class.
Usually any member of a register class will do. Further, generic requests
eliminate the problem that arises if a particular requested register is already in
use but many other registers in the same class are available.
A register, once allocated, must be freed by the compiler when its assign-
ment to a particular task is completed. A register is usually freed in response
to an explicit directive issued by a semantic routine. This directive also allows
us to mark the last use of a register as dead. This is valuable information
because better code may be possible if the contents of a register do not need to
be preserved.
Reserved and work registers, on the other hand, are never explicitly allo-
cated or freed. Reserved registers are assigned a fixed function throughout
a program. Examples include display registers (Section 12.2.4 on page 453),
stack-top registers, argument and return value registers, and return address
registers. Since the function of reserved registers is set by the hardware or
operating system, and they are in use for all of a program or procedure, it is
unwise to use such registers for other than their designated purpose.
 
 
Search WWH ::




Custom Search