Claims
- 1. A method for code optimization, comprising:
disassembling object code that has been compiled and linked; analyzing the disassembled code so as to identify a first function in the code, the first function including store and restore instructions with respect to one or more non-volatile registers and further including a call instruction to a second function that is performed infrequently when the first function is run; identifying one or more volatile registers unused in the first function; and modifying the code so as to replace each reference in the first function to at least one of the non-volatile registers with a reference to a corresponding one of the unused volatile registers, and so as to eliminate at least one pair of the store and restore instructions in the first function with respect to the at least one of the non-volatile registers while storing the corresponding one of the volatile registers before the call instruction to the second function and restoring the corresponding one of the volatile registers after the call instruction to the second function.
- 2. A method according to claim 1, wherein analyzing the disassembled code comprises profiling the code so as to determine a frequency of calls made by the first function, including the call instruction to the second function, and wherein modifying the code comprises modifying the first function only if the frequency of the calls is less than about one call each time the first function is run.
- 3. A method according to claim 1, wherein modifying the code comprises replacing the call instruction with a branch to a wrapper code that contains the call instruction, together with store and restore instructions with respect to the corresponding one of the volatile registers.
- 4. A method according to claim 3, wherein the object code comprises a fixed sequence of code instructions ending with a last instruction, and wherein the wrapper code is added to the code after the last instruction, and wherein replacing the call instruction comprises replacing the instruction with the branch to the wrapper code without altering the fixed sequence within the code.
- 5. A method according to claim 3, wherein analyzing the code comprises identifying a further one of the non-volatile registers to which there is no reference made in the first function, and modifying the code comprises eliminating at least one pair of the store and restore instructions in the first function with respect to the further one of the non-volatile registers, while adding store and restore instructions to the wrapper code with respect to the further non-volatile registers.
- 6. A method according to claim 1, wherein the function comprises a fixed sequence of code instructions, and modifying the code comprises eliminating the at least one pair of the store and restore instructions without altering the fixed sequence.
- 7. A method according to claim 1, wherein modifying the code to eliminate the at least one pair of the store and restore instructions comprises reordering the instructions so as to make the store instruction a first instruction in the function, and further modifying control transfers to the function in the code so as to skip over the store instruction.
- 8. A method according to claim 1, wherein the function comprises a final instruction to transfer control upon completion of the function, and wherein modifying the code to eliminate the at least one pair of the store and restore instructions comprises reordering the instructions so as to make the restore instruction a last instruction in the function before the instruction to transfer control, and further replacing the restore instruction with the control transfer instruction.
- 9. A method according to claim 1, wherein the at least one pair of the store and restore instructions comprises a single instruction that acts upon a plurality of registers, and wherein modifying the code to eliminate the at least one pair of the store and restore instructions comprises modifying the single instruction to act upon a subset of the plurality of registers.
- 10. A method according to claim 1, wherein modifying the code comprises recompiling the object code.
- 11. A method according to claim 1, wherein storing the corresponding one of the volatile registers comprises saving a value of the corresponding one of the volatile registers to a memory location reserved on a program stack for the at least one of the non-volatile registers.
- 12. Apparatus for code optimization, comprising a code processor, which is arranged to disassemble object code that has been compiled and linked, to analyze the disassembled code so as to identify a first function in the code, the first function including store and restore instructions with respect to one or more non-volatile registers and further including a call instruction to a second function that is performed infrequently when the first function is run, to identify one or more volatile registers unused in the first function, and to modify the code so as to replace each reference in the first function to at least one of the non-volatile registers with a reference to a corresponding one of the unused volatile registers, and so as to eliminate at least one pair of the store and restore instructions in the first function with respect to the at least one of the non-volatile registers while storing the corresponding one of the volatile registers before the call instruction to the second function and restoring the corresponding one of the volatile registers after the call instruction to the second function.
- 13. Apparatus according to claim 12, wherein the code processor is arranged to profile the code so as to determine a frequency of calls made by the first function, including the call instruction to the second function, and wherein the code processor is arranged to modify the code only if the frequency of the calls is less than about one call each time the first function is run.
- 14. Apparatus according to claim 2, wherein the code processor is arranged to replace the existing call instruction with a branch to a wrapper code that contains the call instruction, together with store and restore instructions with respect to the corresponding one of the volatile registers.
- 15. Apparatus according to claim 14, wherein the object code comprises a fixed sequence of code instructions ending with a last instruction, and wherein the code processor is arranged to add the wrapper code after the last instruction, and to replace the call instruction with the branch to the wrapper code without altering the fixed sequence within the code.
- 16. Apparatus according to claim 14, wherein the code processor is arranged to identify a further one of the non-volatile registers to which there is no reference made in the first function, to eliminate at least one pair of the store and restore instructions in the first function with respect to the further one of the non-volatile registers, and to add store and restore instructions to the wrapper code with respect to the further non-volatile registers.
- 17. Apparatus according to claim 12, wherein the function comprises a fixed sequence of code instructions, and wherein the code processor is arranged to modify the code so as to eliminate the at least one pair of the store and restore instructions without altering the fixed sequence.
- 18. Apparatus according to claim 12, wherein the code processor is arranged to modify the code by reordering the instructions so as to make the store instruction a first instruction in the function, and by modifying control transfers to the function in the code so as to skip over the store instruction.
- 19. Apparatus according to claim 12, wherein the function comprises a final instruction to transfer control upon completion of the function, and wherein the code processor is arranged to reorder the instructions so as to make the restore instruction a last instruction in the function before the instruction to transfer control, and further by replacing the restore instruction with the control transfer instruction.
- 20. Apparatus according to claim 12, wherein the at least one pair of the store and restore instructions comprises a single instruction that acts upon a plurality of registers, and wherein the code processor is arranged to eliminate the at least one pair of the store and restore instructions by modifying the single instruction to act upon a subset of the plurality of registers.
- 21. Apparatus according to claim 12, wherein the code processor is arranged to modify the code by recompiling the object code.
- 22. Apparatus according to claim 12, wherein the code processor is arranged to modify the code so that a value of the corresponding one of the volatile registers is saved to a memory location reserved on a program stack for the at least one of the non-volatile registers.
- 23. A computer software product, comprising a computer-readable medium in which software is stored, which software, when read by a computer, causes the computer to disassemble object code that has been compiled and linked, to analyze the disassembled code so as to identify a first function in the code, the first function including store and restore instructions with respect to one or more non-volatile registers and further including a call instruction to a second function that is performed infrequently when the first function is run, to identify one or more volatile registers unused in the first function, and to modify the code so as to replace each reference in the first function to at least one of the non-volatile registers with a reference to a corresponding one of the unused volatile registers, and so as to eliminate at least one pair of the store and restore instructions in the first function with respect to the at least one of the non-volatile registers while storing the corresponding one of the volatile registers before the call instruction to the second function and restoring the corresponding one of the volatile registers after the call instruction to the second function.
- 24. A product according to claim 23, wherein the software causes the computer to profile the code so as to determine a frequency of calls made by the first function, including the call instruction to the second function, and wherein the software causes the computer to modify the code only if the frequency of calls is less than about one call each time the first function is run.
- 25. A product according to claim 23, wherein the software causes the computer to replace the call instruction with a branch to a wrapper code that contains the call instruction, together with store and restore instructions with respect to the corresponding one of the volatile registers.
- 26. A product according to claim 25, wherein the object code comprises a fixed sequence of code instructions ending with a last instruction, and wherein the software causes the computer to add the wrapper code after the last instruction, and to replace the call instruction with the branch to the wrapper code without altering the fixed sequence within the code.
- 27. A product according to claim 25, wherein the software causes the computer to identify a further one of the non-volatile registers to which there is no reference made in the first function, to eliminate at least one pair of the store and restore instructions in the first function with respect to the further one of the non-volatile registers, and to add store and restore instructions to the wrapper code with respect to the further non-volatile registers.
- 28. A product according to claim 23, wherein the function comprises a fixed sequence of code instructions, and the software causes the computer to modify the code so as to eliminate the at least one pair of the store and restore instructions without altering the fixed sequence.
- 29. A product according to claim 23, wherein the software causes the computer to modify the code by reordering the instructions so as to make the store instruction a first instruction in the function, and by modifying control transfers to the function in the code so as to skip over the store instruction.
- 30. A product according to claim 23, wherein the function comprises a final instruction to transfer control upon completion of the function, and wherein the software causes the computer to reorder the instructions so as to make the restore instruction a last instruction in the function before the instruction to transfer control, and further to replace the restore instruction with the control transfer instruction.
- 31. A product according to claim 23, wherein the at least one pair of the store and restore instructions comprises a single instruction that acts upon a plurality of registers, and wherein the software causes the computer to eliminate the at least one pair of the store and restore instructions by modifying the single instruction to act upon a subset of the plurality of registers.
- 32. A product according to claim 23, wherein the software causes the computer to modify the code by causing a recompilation of the object code.
- 33. A product according to claim 23, wherein the software causes the computer to modify the code so that a value of the corresponding one of the volatile registers is saved to a memory location reserved on a program stack for the at least one of the non-volatile registers.
CROSS-REFERENCE TO RELATED APPLICATIONS
[0001] This application claims the benefit of U.S. Provisional Patent Application No. 60/278,488, filed Mar. 23, 2001. It is also related to co-pending U.S. patent application Ser. No. 09/798,879, filed Mar. 2, 2001, and to a U.S. patent application entitled, “Eliminating Cold Register Store/Restores Within Hot Function Prolog/Epilogs,” and another U.S. patent application entitled “Percolating Hot Function Store/Restores to Colder Calling Functions,” both filed on even date. All of these applications are assigned to the assignee of the present patent application, and their disclosures are incorporated herein by reference.
Provisional Applications (1)
|
Number |
Date |
Country |
|
60278488 |
Mar 2001 |
US |