Patent ID: 7707568

Claim:
An optimization method that optimizes programs for a specific computer architecture, wherein, a pattern for multiple predetermined instructions is used to replace one of a plurality of partial programs having first instructions, within programs to be optimized based on the pattern, and at least a part of the one of the plurality of partial programs detected is replaced and optimized with second instructions corresponding to the pattern, wherein the second instructions contain at least one specific computer architecture instruction, the method comprising: detecting the partial program within a series of said first instructions within programs to be optimized, such that the series of first instructions has at least one absent instruction that is included in the pattern but not within the partial program, and detecting the partial program within the series of the first instructions on condition that a ratio of the first instructions corresponding to all the first instructions included in the pattern in the partial program is equal to or greater than a predetermined reference ratio; wherein based on the detecting of the partial program and the condition, replacing a part of the one of the plurality of partial programs which includes replacing the series of first instructions that have been transformed in the partial program with the second instructions; transforming instructions included in the series of first instructions corresponding to the pattern by adding the absent instruction to the partial program, and further adding a pair of cancel instructions for maintaining processing results achieved by the partial program, wherein adding the pair of cancel instructions further comprises adding a first cancel instruction of the pair of cancel instructions before the absent instruction and adding a second cancel instruction after the absent instruction; and wherein adding the first and second cancel instructions further includes adding the first cancel instruction before a save instruction, wherein the first cancel instruction uses the save instruction to save a value in a storage area, and wherein adding the second cancel instruction includes adding a recovery instruction to be invoked prior to the second cancel instruction to recover the value saved in the storage area, where the saved value is used to restore control flow of the transformed partial program from the point where the absent instruction is added.