摘要 |
A method, system, and apparatus for inserting spill code optimized for a complex instruction set computing (CISC) two-address machine, such as a machine utilizing an 80x86 processor is described. The spill code is generated in a single pass. Copy propagation and dead-code elimination are performed to remove unnecessary loads and stores from the stack. Instructions contained within the code block are processed in reverse order. Temporary variables are not extended to the point that they may become spilled by a register allocation procedure. A store to a stack location is inserted if the stack location is not dead, saving the use of a register. Memory operands are substituted when possible in place of load and store instructions on CISC machines. As the instructions are being processed, the number of occurrences and location of a temporary variable associated with a spilled variable within the instructions is maintained. The number of occurrences of the temporary variable is checked before a load is inserted into the new instructions as well as before a temporary variable is removed from use. If the variable has only occurred once then the memory operand of the temporary is used in place of the load of the temporary variable saving a load instruction. If the temporary variable is about to be removed from use and the temporary variable has only occurred one time then the variable is not stored saving a store instruction within the spill code.
|