The Correctness of LR(0) parsingTopGenerating Code for Methods Saving Registers during Calls

Saving Registers during Calls

  1. When generating calls within expression and code for non-void methods, you must include code to ensure that register values are preserved during all calls.
    1. Registers are typically partitioned into:
      Callee saved registers
      whose values the called method must save and restore (if it uses them).
      Caller saved registers
      whose value the calling method must save and restore (if it depends on them after the call).
      It is possible (and not uncommon) to put all registers in one group or the other (callee-saved is the favorite).
    2. Callee saving has the advantage of keeping the total size of your code small (each proc only contains one set of instructions to save registers).

      Note: You have to generate the register saving instructions before you know what registers need to be saved. The fact that you are generating assembly code lets you leave this problem to the assembler by using a symbolic name for the mask that determines what registers need to be saved.

    3. Caller saving has the advantage that you only save the registers in use at a particular call rather than all registers ever used in the procedure (although you may end up saving registers that aren't altered by the called procedure).
  2. A register allocator can be designed to take advantage of these two classes of registers:
  3. Where are register values saved?
    1. In the caller's frame -- for caller saved registers.
    2. In the called method's frame -- for callee saved.

    In both cases, the stack pointer will be incremented as part of the register saving (rather than treating them as locals counted in determining localsize).


Computer Science 434
Department of Computer Science
Williams College

 The Correctness of LR(0) parsingTopGenerating Code for Methods Saving Registers during Calls