Patent ID: 7131119

Claim:
A method of optimizing compiled code generated from a high level computer programming languages, wherein the compiled code includes loop constructs, the method comprising the steps: (a) storing a predetermined number a for a compiler; (b) providing a non-optimized loop code segment corresponding to a loop construct written in a high level programming language, wherein in the non-optimized loop code segment the loop construct may be executed at run time at least a loop repetition number of times n, depending upon a value at run time of a variable in a loop termination condition of the loop code segment, and the non-optimized loop code segment includes a call to a procedure; (c) providing a non-optimized pre-loop code segment corresponding to programming instructions preceding the loop construct, and a non-optimized post-loop code segment corresponding to instructions succeeding the loop construct; (d) performing a computation by the compiler for determining n+1 values for the variable in the loop termination condition, such that a first one of the values would, upon execution at run time, terminate the loop code segment in 0 iterations, a second one of the values would, upon execution at run time, terminate the loop code segment in 1 iteration, and an (n+1)th one of the values would, upon execution at run time, terminate the loop code segment in n iterations, wherein the call invokes the procedure responsive to arguments of the call, the arguments including ones of the program variables; (e) optimizing the non-optimized pre-loop, loop and post-loop code segments, wherein the optimizing includes the compiler; propagating the values to the loop code segment, the pre-loop code and the post-loop code; detecting effects on the loop code segment, the pre-loop code and the post-loop code of propagating the values, including detecting redundancies and invariant expressions in the loop code segment, the pre-loop code and the post-loop code resulting from the propagation of the values, so that the compiler may eliminate, or at least simplify, some of the loop code segment, pre-loop code and post-loop code to provide a consolidated code segment corresponding with conditions for execution of the loop said loop repetition number of times n, wherein the consolidated code includes certain code of the non-optimized loop code segment, the non-optimized pre-loop code and the non-optimized post-loop code and omits certain other code of the non-optimized loop code segment, the non-optimized pre-loop code and the non-optimized post-loop code and wherein the call is omitted from the consolidated loop code segment if the certain program variable values are such that the call invoking the procedure results in no change in program variables; (f) determining whether the consolidated code segment should be executed in preference to the non-optimized code segments; and (g) if said determination is favourable, including the consolidated code segment in optimized code for a program written in the high level programming language.