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 callee function in the code, the callee function including store and restore instructions with respect to a non-volatile register, and further to identify in the code a call instruction to the callee function located inside a caller function; and modifying the code so as to move at least one of the store and restore instructions with respect to the non-volatile register from the callee function to the caller function.
- 2. A method according to claim 1, wherein modifying the code comprises moving the at least one of the store and restore instructions after determining that the non-volatile register is not used in the caller function.
- 3. A method according to claim 1, wherein modifying the code comprises locating an unused register in the caller function, and modifying the caller function to reference the unused register instead of the non-volatile register.
- 4. A method according to claim 1, wherein modifying the code comprises:
creating a copy of the callee function; removing the at least one of the store and restore instructions from the copy; and modifying the call instruction to reference the copy instead of the callee function.
- 5. A method according to claim 4, wherein the object code comprises a fixed sequence of code instructions ending with a last instruction, and creating the copy comprises adding a copy of the callee function after the last instruction.
- 6. A method according to claim 4, wherein analyzing the disassembled code comprises identifying call instructions to the callee function located in a plurality of caller functions, and wherein modifying the code comprises selecting at least one of the plurality of caller functions to modify.
- 7. A method according to claim 6, wherein modifying the code comprises moving the at least one of the store and restore instructions after determining that the non-volatile register is not used in the at least one of the plurality of caller functions that is selected.
- 8. A method according to claim 7, wherein modifying the code comprises, for each one of the plurality of caller functions, finding any use of the non-volatile register in the one of the plurality of caller functions, and inserting a store instruction before the call instruction and a restore instruction after the call instruction in the one of the plurality of caller functions.
- 9. A method according to claim 8, wherein modifying the code comprises, if the use is not found, adding the at least one of the store and restore instructions to the one of the plurality of caller functions.
- 10. A method according to claim 1, wherein the callee function has an original name, and wherein modifying the code comprises:
removing the at least one of the store and restore instructions from the callee function; renaming the callee function with a new name; and creating an added function with the original name of the callee function, the added function comprising the at least one of the store and restore instructions removed from the callee function and a call to the callee function using the new name.
- 11. A method according to claim 10, wherein the object code comprises a fixed sequence of code instructions ending with a last instruction, and creating the added function comprises inserting the added function after the last instruction.
- 12. A method according to claim 10, wherein analyzing the disassembled code comprises identifying call instructions to the callee function located in a plurality of caller functions, and wherein modifying the code comprises selecting at least one of the plurality of caller functions to modify.
- 13. A method according to claim 12, wherein modifying the code comprises moving the at least one of the store and restore instructions after determining that the non-volatile register is not used in the at least one of the plurality of caller functions that is selected.
- 14. A method according to claim 13, wherein modifying the code comprises, for each one of the plurality of caller functions, finding any use of the at least one of the non-volatile register in the one of the plurality of caller functions, and inserting a store instruction before the call instruction and a restore instruction after the call instruction in the one of the plurality of caller functions.
- 15. A method according to claim 14, wherein modifying the code comprises, if the use is not found, adding the at least one of the store and restore instructions to the one of the plurality of caller functions.
- 16. A method according to claim 10, wherein a function comprises a name, and creating the added function comprises renaming the callee function with a new name, and naming the added function with the name of the callee function.
- 17. A method according to claim 1, wherein modifying the code comprises adding the at least one of the store and restore instructions to the caller function.
- 18. A method according to claim 17, wherein the caller function comprises a fixed sequence of code instructions, and modifying the code comprises modifying the code without altering the fixed sequence.
- 19. A method according to claim 18, wherein adding the at least one of the store and restore instructions comprises replacing an instruction in at least one of the prolog and epilog of the caller function with an unconditional branch to a caller function wrapper code, and wherein the caller function wrapper code comprises the instruction so replaced and the at least one of the store and restore instructions.
- 20. A method according to claim 1, wherein analyzing the disassembled code comprises determining a sum of frequencies of executing the call instruction to the callee function within the caller function, and modifying the code comprises modifying the code conditional upon the sum of the frequencies of executing the call instruction being greater than of the sum of the frequencies of execution of call instructions to the caller function.
- 21. A method according to claim 1, wherein modifying the code comprises recompiling the object code.
- 22. 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 callee function in the code, the callee function including store and restore instructions with respect to a non-volatile register, and further to identify in the code a call instruction to the callee function located inside a caller function, and to modify the code so as to move at least one of the store and restore instructions with respect to the non-volatile register from the callee function to the caller function.
- 23. Apparatus according to claim 22, wherein the processor is arranged to move the at least one of the store and restore instructions after determining that the non-volatile register is not used in the caller function.
- 24. Apparatus according to claim 22, wherein the processor is arranged to locate an unused register in the caller function, and to modify the caller function to reference the unused register instead of the non-volatile register.
- 25. Apparatus according to claim 22, wherein the processor is arranged to create a copy of the callee function, to remove the at least one of the store and restore instructions from the copy, and to modify the call instruction to reference the copy instead of the callee function.
- 26. Apparatus according to claim 25, wherein the object code comprises a fixed sequence of code instructions ending with a last instruction, and the processor is arranged to add a copy of the callee function after the last instruction.
- 27. Apparatus according to claim 25, wherein the processor is arranged to identify call instructions to the callee function located in a plurality of caller functions, and to select at least one of the plurality of caller functions to modify.
- 28. Apparatus according to claim 27, wherein the processor is arranged to move the at least one of the store and restore instructions after determining that the non-volatile register is not used in the at least one of the plurality of caller functions that is selected.
- 29. Apparatus according to claim 28, wherein the processor is arranged, for each one of the plurality of caller functions, to find any use of the at least one of the non-volatile register in the one of the plurality of caller functions, and to insert a store instruction before the call instruction and a restore instruction after the call instruction in the one of the plurality of caller functions.
- 30. Apparatus according to claim 29, wherein the processor is arranged, if the use is not found, to add the at least one of the store and restore instructions to the one of the plurality of caller functions.
- 31. Apparatus according to claim 22, wherein the callee function has an original name, and wherein the processor is arranged to remove the at least one of the store and restore instructions from the callee function and to rename the callee function with a new name, and to create an added function with the original name of the callee function, the added function comprising the at least one of the store and restore instructions removed from the callee function and a call to the callee function using the new name.
- 32. Apparatus according to claim 31, wherein the object code comprises a fixed sequence of code instructions ending with a last instruction, and the processor is arranged to insert the added function after the last instruction.
- 33. Apparatus according to claim 31, wherein the processor is arranged to identify call instructions to the callee function located in a plurality of caller functions, and to select at least one of the plurality of caller functions to modify.
- 34. Apparatus according to claim 33, wherein the processor is arranged to move the at least one of the store and restore instructions after determining that the non-volatile register is not used in the at least one of the plurality of caller functions that is selected.
- 35. Apparatus according to claim 34, wherein the processor is arranged, for each one of the plurality of caller functions, to find any use of the at least one of the non-volatile register in the one of the plurality of caller functions, and to insert a store instruction before the call instruction and a restore instruction after the call instruction in the one of the plurality of caller functions.
- 36. Apparatus according to claim 35, wherein the processor is arranged, if the use is not found, to add the at least one of the store and restore instructions to the one of the plurality of caller functions.
- 37. Apparatus according to claim 31, wherein a function comprises a name, and the processor is arranged to rename the callee function with a new name, and name the added function with the name of the callee function.
- 38. Apparatus according to claim 22, wherein the processor is arranged to add the at least one of the store and restore instructions to the caller function.
- 39. Apparatus according to claim 38, wherein the caller function comprises a fixed sequence of code instructions, and the processor is arranged to modify the code without altering the fixed sequence.
- 40. Apparatus according to claim 39, wherein the processor is arranged to replace an instruction in at least one of the prolog and epilog of the caller function with an unconditional branch to a caller function wrapper code, and wherein the caller function wrapper code comprises the instruction so replaced and the at least one of the store and restore instructions.
- 41. Apparatus according to claim 22, wherein the processor is arranged to determine a sum of frequencies of executing the call instruction to the callee function within the caller function, and to modify the code conditional upon the sum of the frequencies of executing the call instruction being greater than of the sum of the frequencies of execution of call instructions to the caller function.
- 42. Apparatus according to claim 22, wherein the processor is arranged to modify the code by recompiling the object code.
- 43. 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 callee function in the code, the callee function including store and restore instructions with respect to a non-volatile register, and further to identify in the code a call instruction to the callee function located inside a caller function, and to modify the code so as to move at least one of the store and restore instructions with respect to the non-volatile register from the callee function to the caller function.
- 44. A product according to claim 43, wherein the software causes the computer to move the at least one of the store and restore instructions after determining that the non-volatile register is not used in the caller function.
- 45. A product according to claim 43, wherein the software causes the computer to locate an unused register in the caller function, and to modify the caller function to reference the unused register instead of the non-volatile register.
- 46. A product according to claim 43, wherein the software causes the computer to create a copy of the callee function, to remove the at least one of the store and restore instructions from the copy, and to modify the call instruction to reference the copy instead of the callee function.
- 47. A product according to claim 46, wherein the object code comprises a fixed sequence of code instructions ending with a last instruction, and the software causes the computer to add a copy of the callee function after the last instruction.
- 48. A product according to claim 46, wherein the software causes the computer to identify call instructions to the callee function located in a plurality of caller functions, and to select at least one of the plurality of caller functions to modify.
- 49. A product according to claim 48, wherein the software causes the computer to move the at least one of the store and restore instructions after determining that the non-volatile register is not used in the at least one of the plurality of caller functions that is selected.
- 50. A product according to claim 49, wherein the software causes the computer, for each one of the plurality of caller functions, to find any use of the at least one of the non-volatile register in the one of the plurality of caller functions, and to insert a store instruction before the call instruction and a restore instruction after the call instruction in the one of the plurality of caller functions.
- 51. A product according to claim 50, wherein the software causes the computer, if the use is not found, to add the at least one of the store and restore instructions to the one of the plurality of caller functions.
- 52. A product according to claim 43, wherein the callee function has an original name, and wherein the software causes the computer to remove the at least one of the store and restore instructions from the callee function and to rename the callee function with a new name, and to create an added function with the original name of the callee function, the added function comprising the at least one of the store and restore instructions removed from the callee function and a call to the callee function using the new name.
- 53. A product according to claim 52, wherein the object code comprises a fixed sequence of code instructions ending with a last instruction, and the software causes the computer to insert the added function after the last instruction.
- 54. A product according to claim 52, wherein the software causes the computer to identify call instructions to the callee function located in a plurality of caller functions, and to select at least one of the plurality of caller functions to modify.
- 55. A product according to claim 54, wherein the software causes the computer to move the at least one of the store and restore instructions after determining that the non-volatile register is not used in the at least one of the plurality of caller functions that is selected.
- 56. A product according to claim 55, wherein the software causes the computer, for each one of the plurality of caller functions, to find any use of the at least one of the non-volatile register in the one of the plurality of caller functions, and to insert a store instruction before the call instruction and a restore instruction after the call instruction in the one of the plurality of caller functions.
- 57. A product according to claim 56, wherein the software causes the computer, if the use is not found, to add the at least one of the store and restore instructions to the one of the plurality of caller functions.
- 58. A product according to claim 52, wherein a function comprises a name, and the software causes the computer to rename the callee function with a new name, and name the added function with the name of the callee function.
- 59. Apparatus according to claim 43, wherein the software causes the computer to add the at least one of the store and restore instructions to the caller function.
- 60. A product according to claim 59 wherein the caller function comprises a fixed sequence of code instructions, and the software causes the computer to modify the code without altering the fixed sequence.
- 61. A product according to claim 60, wherein the software causes the computer to replace an instruction in at least one of the prolog and epilog of the caller function with an unconditional branch to a caller function wrapper code, and wherein the caller function wrapper code comprises the instruction so replaced and the at least one of the store and restore instructions.
- 62. A product according to claim 43, wherein the software causes the computer to determine a sum of frequencies of executing the call instruction to the callee function within the caller function, and to modify the code conditional upon the sum of the frequencies of executing the call instruction being greater than of the sum of the frequencies of execution of call instructions to the caller function.
- 63. A product according to claim 43, wherein the software causes the computer to modify the code by recompiling the object code.
CROSS-REFERENCE TO RELATED APPLICATIONS
[0001] This application claims the benefit of U.S. Provisional Patent Application No. 60/278,487, 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 “Eliminating Store/Restores within Hot Function Prolog/Epilogs using Volatile Registers,” 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 |
|
60278487 |
Mar 2001 |
US |