Java Reference
In-Depth Information
CG with the labeled tree of Figure 13.10
and three registers, ($10, $11 and $12), we obtain the code sequence shown in
Figure 13.11.
tree
As an example, if we call
tree
CG illustrates nicely the principle of register targeting . Code is gener-
ated in such a way that the final result appears in the targeted register without
any unnecessary moves.
Because our simple machine model requires that all operands be loaded
into registers, commutative operators (for which exp 1 op exp 2isidenticalto
exp 2 op exp 1) cannot be exploited by the
GC algorithm to reduce register
usage. However, most computer architectures are not entirely symmetric.
Thus, in the MIPS R3000 architecture, some operations (like add and subtract)
allow the right operand to be immediate. Immediate operands are small literal
values included directly into an instruction; they need not be explicitly loaded
into registers (see Exercise 8). For commutative operators, a small literal used
as a left operand can be treated as if it were a right operand.
Some operations, like addition and multiplication are associative .Oper-
ands of an associative operator may be processed in any order. Thus, math-
ematically, ( a + b )
tree
( b + c ) are identical. Regrouping operands of
associative operators can reduce the number of registers needed to evaluate
an expression (see Exercise 9). For example, using
+ c and a +
we can
establish that (a+b)+(c+d) requires three registers whereas a+b+c+d requires
only two registers. Unfortunately, because of overflow and rounding issues,
computer arithmetic is often not truly associative. For example, if a and b
equal 1, c equals maxint,andd equals
register
N
eeds
10, (a+b)+(c+d) will evaluate cor-
rectly, whereas a+b+c+d may overflow. Most languages are careful to specify
when such reordering is allowed, so that compilers can move operands only
when it is absolutely safe to do so.
13.3 Register Allocation
Modern RISC architectures require that most operands reside in registers. The
techniques explained in Section 13.2 use registers as necessary for translating
expression trees, but each use of a variable name causes its value to be loaded
into some register.
A machine's registers can be used to greater advantage if the association
between a variable name and a register persists over several uses of that
variable. For example, if register $11 can be allocated to the variable a for a
reasonable portion of a method's execution, then loads and stores for a could
be satisfied by the relatively fast machine register instead of the relatively
slower program memory. Reducing memory tra
c in this manner can have a
substantial impact on program performance.
 
 
Search WWH ::




Custom Search