Chapter 12
Putting It All Together

powered by FreeFind

Modified: 

Text - divided compiler into two parts:

Text Chapter 2 Lexical Analysis JVM
  Chapter 3 Parsing  
  Chapter 4 Abstract Syntax  
Front Chapter 5 Semantic Analysis  
end Chapter 6 Activation Records  
  Chapter 7 Translation to Intermediate Code  
  Chapter 8 Basic Blocks and Traces  
Back Chapter 9 Instruction Selection  
end Chapter 10 Liveness Analysis  
  Chapter 11 Register Allocation  

JVM - stack machine target architecture with no registers eliminated opportunity for several optimizing methods of text.

PROCEDURE ENTRY/EXIT

The JVM method entry and exit was relatively simple, requiring:

Procedure entry and exit on register machines is considerably more complicated due to:

Frame generation

Frame generation is specific to an architecture.

JVM

Frame generation was performed by:

  1. visiting each method declaration (FrameVisitor)
  2. computing the offsets (JVMFrame) and
  3. storing to the symbol table
  4. visiting each method declaration and use (CodeVisitor)
  5. using frame offsets when accessing frame variables

 

Other

In the text, frame information on registers used for parameter passing, etc. was separate from the IR generation.

The steps to code generation follow:

  1. IR with TEMPs
  2. IR to machine-specific code with TEMPs
  3. machine specific frame with precolored registers
  4. color machine-specific code TEMPs to registers

The steps for generating a register machine frame (Step 3 above) for each method of each class are:

  1. define registers of machine - literally a list of programmer accessible registers
  2. define precolored registers - frame pointer, stack pointer, function result
  3. compute offset of each in-frame parameter or local - these variables must occupy a memory location for one of the following reasons:
    • pass by reference since must have memory address in frame
    • local variable accessed by inner function, although register allocation over function boundaries can sometimes keep in register
    • value too big for a register but can sometimes use multiple registers
    • array parameter which is in many languages (C++) a reference anyway. Pointer arithmetic used to access array components
    • register conflict though can often copy to another to avoid saving to memory
    • more locals and parameters than registers, some are spilled into frame memory
  4. assign parameters to registers