Twobit Pass 5: local optimizations.

Pass 5 is an optional pass that performs local optimizations. Its main effect is to remove nop instructions and save -1 and pop -1 instructions, which would be ignored by the assembler anyway. In the current version of Twobit, pass 5 has little if any effect on the quality of the generated code.

In a previous version of Twobit, pass 5 removed some redundant loads and stores that are now eliminated by an improved pass 4. Pass 5 has been retained because it has proved useful for debugging and for research, and might be used in the future for optimizations such as instruction scheduling.

Invariants

To simplify the debugger and to provide ready access to constants and non-local variables, register 0 always contains the currently executing procedure. The local optimizer must never eliminate an instruction that changes register 0.

To make local optimization more effective, the code generator annotates each branch instruction with a conservative estimate of the set of registers that are live at the target of the branch.