Java Reference
In-Depth Information
In this case, seven virtual registers V32 { V38 are allocated to the LIR computation. Two
physical registers, $a0 for the argument n and $v0 for the return value, are referred to
by their symbolic names; that we use these physical registers indicates that SPIM expects
values to be stored in them. Notice that LIR instructions are read from left to right. For
example, the load constant instruction
0:LDC[1][V32|I]
in block B1, loads the constant integer 1 into the integer virtual register V32 ; the |I notation
types the virtual register as an integer. Notice that we start enumerating virtual registers
beginning at 32; the numbers 0 through 31 are reserved for enumerating physical registers.
The next instruction,
5:MOVE$a0[V33|I]
copies the value from the integer physical register $a0 into the integer virtual register V33 .
The add instruction in block B3,
30:ADD[V33|I][V36|I][V37|I]
adds the integer values from registers V33 and V36 and puts the sum in V37 .
Notice that we enumerate the LIR instructions by multiples of five. This eases the
insertion of spill (and restore) instructions, which may be required for register allocation
(and are discussed in Chapter 7).
The process of translating HIR to LIR is relatively straightforward and is a two-step
process.
1. First, the NEmitter constructor invokes the NControlFlowGraph method hirToLir()
on the control-flow graph:
cfg.hirToLir();
The method hitToLir() iterates through the array of HIR instructions for the control-
flow graph translating each to an LIR instruction, relying on a method toLir() , which
is defined for each HIR instruction.
2. NEmitter invokes the NControlFlowGraph method resolvePhiFunctions() on the
control-flow graph:
cfg.resolvePhiFunctions();
This method resolves Phi function instructions, replacing them by move instructions
near the end of the predecessor blocks. For example, the Phi function from Figure
6.10 and now repeated in Figure 6.12(a) resolves to the moves in Figure 6.12(b). One
must make sure to place any move instructions before any branches in the predecessor
blocks.
 
Search WWH ::




Custom Search