Patent ID: 7386843

Claim:
A method of inserting spill code to handle a set of spilled variables, the spilled variables being identified by a register allocation procedure, into a plurality of instructions generated by a compiler, the spill code adapted for a CISC machine having registers used when executing instructions, comprising: processing each instruction in the plurality of instructions by: when a variable within the instruction is dead after the instruction: generating a spill code load instruction for each spilled variable included in a set of spilled variables to be loaded, the set of spilled variables to be loaded being a subset of the set of spilled variables; removing all variables for which a spill code load instruction was generated from the set of spilled variables to be loaded; and removing all entries for the variables within the instruction from a mapping from spilled variables to temporary variables; determining if the instruction includes a variable in the set of spilled variables, and if so, for each such variable: adding an entry to the mapping from spilled variables to temporary variables; and generating a store instruction to store the variable to a stack location if a store to the stack location for the variable is necessary, and generating a substitute instruction by applying the mapping from spilled variables to temporary variables such that the temporary variables are substituted for the spilled variables; generating a spill code load instruction for each variable in the set of spilled variables to be loaded; and inserting the generated instructions; wherein the instructions are adapted for the CISC machine having registers for executing instructions.