Twobit Pass 4: Elimination of redundant stores and loads

Twobit's code generator and on-the-fly register allocator generally
assume that the contents of all registers have been saved into the
current stack frame.
To achieve this invariant, the code generator emits a phantom
store instruction for each variable or temporary value that is computed
into a register.
These phantom instructions are represented as nop
instructions whose operands encode a store instruction.
If the value that is stored by the phantom instruction must later
be loaded from the stack frame, then the phantom instruction is
converted into a real store instruction. If the value is never
loaded from the stack frame, then the phantom instruction remains
a nop and will be ignored by the
assembler.

When a phantom store instruction is converted into a real store
instruction, the stack slot to be used is selected by an on-the-fly
stack slot allocator according to the following algorithm:
If there exists a previously allocated stack slot that was no longer
in use when the phantom store instruction was generated, and that
slot has not been allocated for any other phantom store instruction,
then one of those slots will be allocated; otherwise a stack slot
will be allocated by expanding the size of the current stack frame.

For the
reverse-map
example, the real output from pass 4, complete with
nop instructions, is shown below.
In the phantom instruction

nop 13,0,-1

the 13 stands for the mnemonic of a store instruction,
the 0 is the register to be stored, and
the -1 indicates that the stack slot has not yet been determined
by the stack slot allocator.