Background of the Invention
The present invention relates to a program compiler and, more particularly, to a method of unrolling/optimizing a repetitive loop.
In a conventional method of consecutive access to the same memory bank by means of a loop, the execution time is undesirably prolonged because of repetitive processing by the loop. In order to minimize the execution time, the loop is optimized. For example, unroll/optimization of a DO loop in a FORTRAN compiler is performed by changing the incrementation value of the DO loop.
If, however, a DO loop is optimized by changing its incrementation value as in the conventional method, contention between memory banks may occur, resulting in an increase in execution time.
Summary of the Invention
It is an object of the present invention to provide a method of unrolling/optimizing a repetitive loop, which can shorten the execution time of a program.
It is another object of the present invention to provide a method of unrolling/optimizing a repetitive loop, which can prevent contention between memory banks.
In order to achieve the above objects, according to the present invention, there is provided a method of unrolling/optimizing a repetitive loop, in which a program compiler in a computer system unrolls and optimizes a repetitive loop instruction, comprising the steps of checking whether the number of times that a loop in an input source program is repeated is an even number, checking whether there are a definition and a reference which span the respective repetitions of the loop, if it is determined that the number of times of repetition is an even number, unrolling an instruction string in the loop a plurality of times in response to the loop instruction, if it is determined that there are neither definition nor reference, updating an index value of the newly unrolled instruction string by predetermined arithmetic processing including a calculation based on the initial, terminal, and incrementation values of the loop, and updating the terminal value of the loop by predetermined arithmetic processing including a calculation based on the initial, terminal, and incrementation values of the loop.
Brief Description of the Drawings
FIG. 1 is a block diagram showing an embodiment of the present invention;
FIG. 2 is a flow chart for explaining an operation of the present invention;
FIG. 3 is a view showing an instruction string of a source program; and
FIG. 4 is a view showing a new instruction string obtained by unrolling/optimizing the DO loop instruction string shown in FIG. 3.
Description of the Preferred Embodiment
The present invention will be described below with reference to the accompanying drawings.
FIG. 1 shows an embodiment of the present invention. In this embodiment, FORTRAN will be exemplified as a program language. A FORTRAN compiler 3 receives a source program from a FORTRAN source program file 1, and causes a DO loop unrolling permission determining section 31 to check whether the program satisfies predetermined conditions. With respect to a DO loop which satisfies the conditions, the FORTRAN compiler 3 causes a DO loop unrolling section 32 to perform an unrolling operation for optimization. In addition, the FORTRAN compiler 3 compiles a program which is optimized or to be optimized, and outputs the resultant program as a target program to a target program file 2.
FIG. 2 is a flow chart for explaining an operation of the present invention. FIG. 3 shows an instruction string of a source program. FIG. 4 shows a new instruction string obtained by unrolling/optimizing the DO loop instruction string shown in FIG. 3. The FORTRAN compiler 3 receives, for example, the instruction string of the source program shown in FIG. 3 from the FORTRAN program file 1, and checks (step 101) whether the number of times that a DO loop in the input instruction string is repeated is an even number. If it is an even number, it is checked (step 102) whether there are a definition and a reference which span the respective repetitions of the loop. If NO in step 102, the instruction string in the DO loop is unrolled a predetermined number of times, e.g., two times (step 103). The index variable of an instruction string unrolled after the second unrolling, i.e., a newly unrolled instruction string, is updated to become an index variable obtained by predetermined arithmetic processing including a calculation based on the initial, terminal, and incrementation values of the DO loop (step 104). For example, the index value is updated to become [index variable of first unrolling+(terminal value-initial value+incrementation value)/2].
Subsequently, the terminal value of the DO loop is updated to become a value obtained by predetermined arithmetic processing including a calculation based on the above-mentioned initial, terminal, and incrementation values of the DO loop (step 105). For example, the terminal value is updated to become [(terminal value+initial value-incrementation value)/2].
As a result of the optimization described above, the instruction string shown in FIG. 4 is obtained.
Subsequently, the flow returns to step 101 to perform similar processing. Note that since the number of times that the DO loop shown in FIG. 4 is repeated is not an even number, this loop cannot be unrolled any more.
If it is determined in step 101 that the number of times of repetition is not an even number, or if it is determined in step 102 that there are a definition and a reference which span the respective repetitions of the loop, the loop is terminated without unrolling/optimizing the loop, and control is transferred to normal compile processing.
In the embodiment, FORTRAN is used as a program language. However, it is apparent that the same effect as described above can be obtained with other languages.
According to the present invention, since loop unrolling is performed upon updating of the terminal value of a loop, no contention between memory banks occurs, and the execution of a program can be optimized, i.e., the execution time can be shortened, thus providing a remarkable effect.