TopManaging data temporaries Handling Address Temporaries

Handling Address Temporaries

  1. When allocating memory to allocate temporary values (i.e. results of evaluating sub-expressions), we will want to distinguish situations where it is better to use an address register than a data register or memory temporary.

  2. Temporarly location for values computed for use as addresses pose more challenges for your code generator because:

  3. We will employ three "strategies" to address these issues when allocating address temporaries:
    Procrastination
    We will try to avoid committing an address register to hold a value for as long as possible.
    Indirection
    We will let an operand descriptor that refers to a memory location use another operand to describe the base address.
    Reclamation
    We will make sure that, when necessary, we can steal a busy address register by moving its value into a data register or into memory (even more) temporarily.

  4. Indirection -- Because operand descriptors can refer to address registers indirectly, it makes sense to define the operand descriptor type recursively:

  5. Procrastination -- We can take advantage of the idea of using an operand descriptor within an operand descriptor to reduce the total demand for address registers.

  6. While complex variable such as a[3*i+j] require the use of a temporary for a base address, a simple reference (to a non-local and non-global variable) such as "x" can be handled by either:

    1. immediately loading the needed static link pointer into a register and then returning an operand descriptor identifying the register and giving x's displacement from it, or

    2. simply returning a descriptor identifying the static link needed to reference x and giving x's displacement from this pointer.

      • A reference to a static link pointer can be described by an operand descriptor specifying a displacement relative to the frame pointer, object pointer or another static link.

      In this case, the routine that is eventually asked to generate an instruction referencing the operand may first have to generate instructions to load the needed static link pointer.

  7. The second approach avoids reserving a register unnecessarily. Consider the forms that code for an expression like x + big expression might take using the two approaches.

    1. move static-link-pointer,a1
      code for big expression
      add disp(a1),result-of-big-expr

    2. code for big expression
      move static-link-pointer,a1
      add disp(a1),result-of-big-expr

    The second approach reduces the total demand for registers by reducing the range of instruction during which a register must be reserved for a base address.

  8. This means that the low-level code generation routine to output an instruction may actually output several instructions.

  9. Reclamation -- Even using this technique to avoid reserving address registers to hold static link pointers, you might still run out of address registers:

    a[i]+ (a[j] + (a[k] + ( a[l] + ( a[m] + a[n]))))

  10. Luckily, when you do run out of address registers, you can always free one by moving its contents to a data temporary.

  11. With Woolite, it is possible to make a slight improvement on this scheme.

Computer Science 434
Department of Computer Science
Williams College

TopManaging data temporaries Handling Address Temporaries