Compiler program, information processing device, and compiler method
The compiler program optimizes multidimensional array processing by converting n-dimensional arrays to n-1-dimensional arrays, addressing inefficiencies in existing techniques and improving loop execution and cache performance.
Patent Information
- Application Number
- JP2022077718
- Authority / Receiving Office
- JP · JP
- Patent Type
- Patents
- Current Assignee / Owner
- Filing Date
- 2022-05-10
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2042-05-10
AI Technical Summary
Existing compiler optimization techniques for multidimensional array processing, such as loop collapse and loop unroll, face challenges in optimizing source code that cannot be completely replaced with a single loop dimension or result in increased code size and reduced cache efficiency.
A compiler program that determines matching array sizes and indices in multidimensional loops, allowing for the conversion of n-dimensional arrays to n-1-dimensional arrays, thereby integrating loops and reducing loop nests.
Optimizes compilation of source code with multidimensional array processing by reducing branch instructions, improving loop execution density, and enhancing cache efficiency.
Smart Images

Figure 0007782367000001 
Figure 0007782367000002 
Figure 0007782367000003
Abstract
Description
[Technical Field]
[0001] The present invention relates to a compiler program and the like. [Background technology]
[0002] Loop collapse (hereafter sometimes referred to as Lc) is a compiler optimization technique that reduces array processing in a multidimensional loop to a single loop. For example, loop collapse treats a process that accesses a three-dimensional array area with three loops as if it were accessing a one-dimensional array area with a single loop.
[0003] Figure 12 is a reference diagram showing the single-loop processing of a three-dimensional array. As shown in Figure 12, three-dimensional arrays C(k,j,i), A(k,j,i), and B(k,j,i) processed in triple loops are replaced with one-dimensional arrays CX(I), CA(I), and CB(I), each processed in a single loop.
[0004] As a result, the Lc optimization process reduces loop nesting, thereby reducing the number of branch instructions within the loop. By reducing the number of branch instructions, the Lc optimization process can efficiently use the branch table used for branch prediction, which is a finite hardware resource. In addition, because the loop length (the number of instructions in the loop) increases, optimizations such as software pipelining, which are effective when loop length is long, become easier to implement. Furthermore, the Lc optimization process optimizes the loop index prior to the simplex process, changing access to memory from the inside of the array in the innermost loop, thereby enabling continuous access instead of discrete access. As a result, cache efficiency improves, and hardware prefetching for continuous access can be applied, improving data access efficiency.
[0005] In other words, loop collapse is an optimization technique that focuses on making arrays one-dimensional and resulting in continuous memory access.
[0006] Another compiler optimization technique is the loop unroll function. The loop unroll function reduces the number of loop processes by expanding simple repetitive processing, thereby increasing the processing speed of a program. By reducing branch instructions, the loop unroll function makes efficient use of the branch table used for branch prediction, which is a finite hardware resource. Furthermore, the loop unroll function lengthens the length of instruction sequences (basic blocks) that do not contain branch instructions, allowing for a wider range of combinations of instruction swapping and register usage, thereby promoting optimization. [Prior art documents] [Patent documents]
[0007] [Patent Document 1] Japanese Patent Application Publication No. 2017-21726 Summary of the Invention [Problem to be solved by the invention]
[0008] However, there is a problem in that source code that includes array processing in a multidimensional loop may not be able to be optimized during compilation. For example, while Lc optimization, which reduces the loop to a single loop, is expected to improve performance by reducing the array to a single dimension and accessing it in a continuous area, optimization is not possible if the access is not in a continuous area. In other words, optimization is not possible if the array cannot be completely replaced with a one-dimensional array processed in a single loop.
[0009] Furthermore, while optimization using the loop unroll function can contribute to reducing the branch table size of hardware resources, it also increases the code size of basic blocks, resulting in a phenomenon in which the number of executions per code unit in a basic block decreases. In other words, code efficiency decreases. Furthermore, an increase in the code size of basic blocks reduces the application efficiency of a hardware mechanism (short loop mechanism) that temporarily stores instruction sequences in an instruction buffer and executes instructions directly from the instruction buffer without decoding. Furthermore, an increase in the code size of basic blocks increases the number of instructions in a basic block, resulting in reduced cache efficiency.
[0010] One aspect of the present invention aims to optimize compilation of source code that includes array processing of a multidimensional loop. [Means for solving the problem]
[0011] In one aspect, a compiler program, in source code including multiple hierarchical loops, determines whether the array sizes of a first argument and a second argument for an n-dimensional array (n≧3) included in an instruction code in an innermost loop match the rotation numbers of a first index corresponding to the first argument and a second index corresponding to the second argument in the loop, respectively; if they match, and if the first index and the second index each start at 1 and the increment value of the first index and the second index is 1, replaces the first argument and the second argument of the n-dimensional array included in the instruction code with a third argument to change it into an n-1-dimensional array, and causes a computer to execute a process of integrating the loops of the first index and the second index. [Effects of the Invention]
[0012] According to one embodiment, compilation of source code including array processing of a multidimensional loop can be optimized. [Brief explanation of the drawings]
[0013] [Figure 1] FIG. 1 is a block diagram illustrating an example of a functional configuration of an information processing apparatus according to an embodiment. [Figure 2] FIG. 2 is a diagram illustrating an example of a source program. [Figure 3] FIG. 3 is a diagram illustrating an example of the loop management table. [Figure 4] FIG. 4 is a diagram showing an example of array syntax information. [Figure 5] FIG. 5 is a diagram illustrating an example of array definition information. [Figure 6A] FIG. 6A is a diagram (1) for explaining optimization according to the embodiment. [Figure 6B] FIG. 6B is a diagram (2) illustrating optimization according to the embodiment. [Figure 6C] FIG. 6C is a diagram (3) for explaining optimization according to the embodiment. [Figure 6D] FIG. 6D is a diagram (4) illustrating optimization according to the embodiment. [Figure 7] FIG. 7 is a diagram illustrating optimization using the memory area of an array. [Figure 8A] FIG. 8A is a diagram (1) showing an example of optimization according to the embodiment. [Figure 8B] FIG. 8B is a diagram (2) showing an example of optimization according to the embodiment. [Figure 8C] FIG. 8C is a diagram (3) showing an example of optimization according to the embodiment. [Figure 9] FIG. 9 is a diagram illustrating another example of optimization according to the embodiment. [Figure 10] FIG. 10 is a diagram illustrating an example of a flowchart of the optimization process according to the embodiment. [Figure 11] FIG. 11 illustrates an example of a computer that executes a compiler program. [Figure 12] FIG. 12 is a reference diagram showing a single loop for a three-dimensional array. DETAILED DESCRIPTION OF THE INVENTION
[0014] Hereinafter, embodiments of the compiler program, information processing device, and compiler method disclosed in the present application will be described in detail with reference to the accompanying drawings. However, the present invention is not limited to the embodiments. [Example]
[0015] [Functional configuration of the information processing device according to the embodiment] FIG. 1 is a block diagram illustrating an example of a functional configuration of an information processing device according to an embodiment. The information processing device 1 illustrated in FIG. 1 is involved in a compiler optimization method for a source program 21 including multiple loops, reducing loop nests, increasing the number of loop iterations, and increasing the number of executions per code unit of a basic block. By reducing loop nests, the information processing device 1 can reduce the number of branch instructions in loops and efficiently utilize branch tables used for branch prediction. Furthermore, by reducing loop nests, the information processing device 1 can increase the number of executions per code unit of a basic block, thereby increasing the loop execution density. Furthermore, the information processing device 1 can improve the application efficiency of a hardware mechanism (short loop mechanism) that temporarily stores an instruction sequence in an instruction buffer and executes the instruction directly from the instruction buffer without instruction decoding. A multiple loop refers to a hierarchical structure of nested loops. A basic block refers to an instruction sequence that does not include a branch instruction.
[0016] An example of a source program 21 handled by the information processing device 1 according to the embodiment will now be described with reference to FIG. 2. FIG. 2 illustrates an example of a source program. FIG. 2 shows the source program 21 written in FORTRAN. The source program 21 illustrated in FIG. 2 processes a three-dimensional array using a triple loop. For each DO loop, a control variable "x" indicating a nesting level of "1" has an initial value of "1," a final value of "10," and an increment value of "1." A control variable "y" indicating a nesting level of "2" has an initial value of "1," a final value of "20," and an increment value of "1." A control variable "z" indicating a nesting level of "3" has an initial value of "1," a final value of "30," and an increment value of "1." The size of the array, although not illustrated, is described as an array declaration in the source program 21. Here, the source program 21 shows an example of processing a three-dimensional array in a triple loop, but the number of dimensions of the array and the number of loops are not limited. The language is also not limited to FORTRAN, and may be C or other languages.
[0017] Returning to FIG. 1 , the information processing device 1 has a control unit 10 and a memory unit 20. The control unit 10 has a syntax analysis unit 11, an optimization unit 12, and a code generation unit 13. The memory unit 20 has a loop data memory unit 20-1 and an array data memory unit 20-2. The loop data memory unit 20-1 stores information about loops described in a source program 21. The loop data memory unit 20-1 has a loop management table 22. The array data memory unit 20-2 stores information about arrays described in the source program 21. The array data memory unit 20-2 has array syntax information 23 and array definition information 24.
[0018] The loop management table 22 contains information about each of the multiple loops described in the source program 21. The loop management table 22 is generated by the syntax analysis unit 11, which will be described later.
[0019] An example of the loop management table 22 will now be described with reference to FIG. 3. FIG. 3 is a diagram showing an example of the loop management table. As shown in FIG. 3, the loop management table 22 stores, for one multiple loop, a nesting level, a control variable, an initial value, an end value, an increment value, array syntax information, and a sibling flag in association with each other. The nesting level indicates the nesting depth of the loop, with the innermost loop being 1. The control variable is a variable that controls the index. The initial value indicates the initial value of the control variable. The end value indicates the end value of the control variable. The end value is a constant. The increment value indicates the increment value of the control variable. The array syntax information indicates the address of the array syntax information 23 of the array corresponding to the multiple loops. The array syntax information 23 will be described later.
[0020] The sibling flag indicates whether or not a loop contains any other processes in parallel within the nested hierarchical structure of the loop. For example, in the case of FORTRAN, the sibling flag is set to "1" if a loop contains any other processes in parallel within the nested hierarchical structure of the loop other than a DO statement, and is set to "0" if a loop does not contain any other processes in parallel within the nested hierarchical structure of the loop.
[0021] As an example, when the nesting level is "1," the control variable is "x," the initial value is "1," the closing value is "10," the increment value is "1," the array syntax information address is "array syntax information," and the sibling flag is "0." When the nesting level is "2," the control variable is "y," the initial value is "1," the closing value is "20," the increment value is "1," the array syntax information is "-," and the sibling flag is "0." When the nesting level is "3," the control variable is "z," the initial value is "1," the closing value is "30," the increment value is "1," the array syntax information is "-," and the sibling flag is "0."
[0022] The array syntax information 23 is syntax information of an array written in the source program 21. The array syntax information 23 is a table that stores subscripts for each subscript dimension of an array corresponding to the nesting level of a loop. The array syntax information 23 is generated by the syntax analysis unit 11, which will be described later.
[0023] An example of array syntax information 23 will now be described with reference to FIG. 4. FIG. 4 is a diagram showing an example of array syntax information. As shown in FIG. 4, array syntax information 23 is information that associates a subscript dimension with a subscript, with an array name. A subscript indicates a number for each subscript dimension assigned to an element indicated by the array, and is given by a variable. A subscript may also be given by a function. As an example, if the array name is "a3", the subscript for the subscript dimension "1" is stored as the function "mod(x,3)+1", the subscript for the subscript dimension "2" is stored as the variable "y", and the subscript for the subscript dimension "3" is stored as the variable "z". This information is for the case where the array is a3(mod(x,3)+1,y,z). Similarly, if the array name is "b3", the subscript with subscript dimension "1" stores the function "mod(x,3)+1", the subscript with subscript dimension "2" stores the variable "y", and the subscript with subscript dimension "3" stores the variable "z". This information is for the case where the array is b3(mod(x,3)+1,y,z).
[0024] 1, the array definition information 24 is definition information of an array written in the source program 21. The array definition information 24 is generated by the syntax analysis unit 11, which will be described later.
[0025] An example of array definition information 24 will now be described with reference to Fig. 5. Fig. 5 is a diagram showing an example of array definition information. As shown in Fig. 5, array definition information 24 is information that associates an array name, the number of dimensions, a subscript dimension, and a definition size. The number of dimensions indicates the number of dimensions of the array indicated by the array name. The subscript dimension corresponds to the subscript dimension in array syntax information 23. The definition size is the size of the array for each subscript dimension.
[0026] For example, if the array name is "a3", the number of dimensions is stored as "3". The defined size of the subscript dimension "1" is "10", the defined size of the subscript dimension "2" is "20", and the defined size of the subscript dimension "3" is "30".
[0027] Returning to FIG. 1 , the syntax analysis unit 11 analyzes the syntax of the source program 21. For example, the syntax analysis unit 11 analyzes a loop written in the source program 21 and stores the analysis result in a loop management table 22. The syntax analysis unit 11 analyzes an array within a loop written in the source program 21 and stores the analysis result in array syntax information 23 and array definition information 24. As an example, the syntax analysis unit 11 analyzes an array declaration written in the source program 21 and stores the definition size for each subscript dimension for the analyzed array name in the array definition information 24.
[0028] The optimization unit 12 optimizes the source program 21. The optimization unit 12 has a sequence analysis unit 121, an extraction unit 122, and an integration unit 123. The sequence analysis unit 121 is an example of a determination unit and a modification unit. The extraction unit 122 is an example of a modification unit. The integration unit 123 is an example of an integration unit.
[0029] The array analysis unit 121 determines whether the array sizes of the first subscript and the second subscript match the rotation counts of the first index corresponding to the first subscript and the second index corresponding to the second subscript in the loop for an n-dimensional array (n≧3) included in the instruction code in the innermost loop. The array analysis unit 121 refers to the loop management table 22, and if a sibling flag is set at any nest level of the target multiple loop, the array analysis unit 121 separates the sibling operations. That is, the array analysis unit 121 splits the sibling operations into loops, converts them into a multiple loop configuration that does not include sibling operations, and then analyzes the array. After this, or in parallel, the array analysis unit 121 analyzes the arrays of the sibling operations.
[0030] For example, the array analysis unit 121 selects an array included in an instruction code in the innermost loop of a multiple loop. The array analysis unit 121 performs the following for the subscript dimension k from 1 to n (number of dimensions) of the selected array. <1> <2> Determine whether the conditions are met. <1> The subscript corresponding to the subscript dimension k of the target array in the array syntax information 23 matches the control variable corresponding to the nesting level k that is the same as the subscript dimension k in the loop management table 22. <2> The initial value corresponding to the nest level k in the loop management table 22 is "1", the increment value is "1", and the end value matches the definition size corresponding to the subscript dimension k in the array definition information 24. That is, <2> The condition determines whether the number of turns of the loop at nest level k matches the defined size of the array of subscript dimension k.
[0031] The extraction unit 122 extracts the following for consecutive subscript dimensions of the n-dimensional array included in the instruction code: <1> <2> If it is determined that the above condition is satisfied, loops at nest levels corresponding to consecutive subscript dimensions are extracted as targets for reduction.
[0032] The integrating unit 123 replaces the first subscript and the second subscript of the n-dimensional array included in the instruction code with the subscript of the alias, and changes it to an n-1-dimensional array. In addition, the integrating unit 123 deletes the loop using the first index corresponding to the first subscript, and changes the ending value of the second index corresponding to the subscript of the alias, thereby integrating the loop.
[0033] For example, the integration unit 123 may perform the following on the array: <1> <2> The smaller of the consecutive subscript dimensions that is determined to satisfy the condition is set as the replacement dimension, and the subscript of the replacement dimension is replaced with the subscript (control variable) obtained by combining the subscripts (control variables) of each dimension. Then, the integration unit 123 replaces the array in the loop.
[0034] Additionally, the integrating unit 123 deletes loops at nesting levels other than the maximum dimension among the consecutive subscript dimensions.Then, the integrating unit 123 refers to the loop management table 22 and changes the end value of the loop at the maximum dimension to a value obtained by multiplying the end value of the nesting level corresponding to the consecutive subscript dimensions.Then, the integrating unit 123 changes the control variable of the corresponding loop to the control variable (subscript) replaced in the array.
[0035] The code generation unit 13 converts the changed source program into intermediate code, and then converts the intermediate code into a machine language program 30.
[0036] [Optimization Description] Here, optimization according to the embodiment will be described with reference to Figures 6A to 6D. Figures 6A to 6D are diagrams for explaining optimization according to the embodiment.
[0037] First, using FIG. 6A, consider memory access to a two-dimensional array A(i,j) whose array size is (x,y). Here, the array size is declared with x set to "5" and y set to "10" as shown in the right diagram of FIG. 6A. The source program 21 includes the program shown in the left diagram of FIG. 6A as a part thereof. A two-dimensional array A(i,j) is written in the innermost loop. In this source program 21, when the subscript j is 1, the addresses of the two-dimensional array A(i,1) are accessed in the order of the subscript i of the innermost loop from 1 to 5. Next, when the subscript j is 2, the addresses of the two-dimensional array A(i,2) are accessed in the order of the subscript i of the innermost loop from 1 to 5.
[0038] The relative position of the array element with subscript (i, j) from the beginning of such two-dimensional array A can be calculated by the following formula (1), where L is the element size. If L is an integer, it is 4 bytes. Relative position of array element with subscript (i,j) = {(i-1)+(j-1)*x}*L (1)
[0039] For example, as shown in the middle diagram of FIG. 6A, the relative position of the array element A(1,1) is 0. The relative position of the array element A(2,1) is 1. The relative position of the array element A(5,1) is 4. The relative position of the array element A(5,2) is 9. Therefore, in the case of such a source program 21 and array size, the memory of such an array size is accessed in ascending order.
[0040] Similarly, for a three-dimensional array A(i,j,k) whose array size is L, the relative position of the array element with subscript (i,j,k) from the beginning of the three-dimensional array A can be calculated using the following formula (2). Relative position of array element with subscript (i,j,k) = {(i-1)+(j-1)*x+(k-1)*(x*y)}*L (2)
[0041] In other words, as a prerequisite, in order to access memory in the direction of the allocation addresses of array A (in ascending order), it is necessary to associate a loop so that memory is accessed in ascending order of the dimensions of the subscripts of array A.
[0042] As shown in FIG. 6B, suppose memory access is performed for a three-dimensional array A(i, j, k) whose array size is (x, y, z). Here, the source program 21 is the program shown in the upper part of FIG. 6B. A three-dimensional array A(i, j, t(k)) is written in the innermost loop. The subscript of the subscript dimension "3" of the three-dimensional array A is "t(k)", which is a number calculated by the function "t(k)" using the loop variable k of the outermost loop.
[0043] The offset Offset3 of the position from the beginning of the three-dimensional array A can be calculated by the following equation (3) using equation (2), where L is the element size. Offset3(A(i,j,t(k)))={(i-1)+(j-1)*x+(t(k)-1)*(x*y)}*L··(3)
[0044] Here, for a three-dimensional array A, if the subscript of the subscript dimension is "2" is "1" and the subscript of the subscript dimension is "1", the offset offset3 of the position from the beginning of the three-dimensional array A(ij,1,t(k)) can be calculated using equation (2) as follows: Offset3(A(ij,1,t(k)))={(ij-1)+(t(k)-1)*(x*y)}*L··(4)
[0045] The source program 21 for such three-dimensional array A is shown in the middle of Figure 6B. That is, for three-dimensional array A, the subscript for subscript dimension "2" is "1", and the subscript for subscript dimension "1" is "ij". In addition, the final value of control variable "j" at nesting level "2" is "1", and the final value of control variable "ij" at nesting level "1" is "xy", the value (number of rotations) obtained by multiplying the final value "y" of control variable "j" before the change by the final value "x" of control variable "i".
[0046] On the other hand, the offset offset2 of the position from the beginning of the two-dimensional array A(ij,t(k)) whose array size is ((x*y),*) can be calculated using equation (1) by the following equation (5). Offset2(A(ij,t(k)))={(ij-1)+(t(k)-1)*(x*y}}*L··(5) The source program 21 for such two-dimensional array A is shown in the lower part of FIG. 6B.
[0047] Such equation (5) coincides with equation (4). Offset2(A(ij,t(k)))=Offset3(A(ij,1,t(k))) In other words, the offset of the position accessed from the beginning of the two-dimensional array A(ij, t(k)) matches the offset of the position from the beginning of the three-dimensional array A(ij, 1, t(k)).
[0048] In other words, when the access size (defined size) of an array is equal to the number of loop iterations (x * y), a three-dimensional array can be regarded as a loop access of a two-dimensional array. This means that the loop nest can be reduced by replacing n-dimensional array A with n-1-dimensional array A and integrating the loop. In other words, since the n-1-dimensional array A is accessed by reducing the array dimension of n-dimensional array A by one, the source program 21 can reduce the loop nest by integrating the loop. By reducing the loop nest, the source program 21 can reduce branches in loops, increase the number of executions of basic blocks, and improve the loop execution density. Furthermore, the source program 21 can efficiently use the branch table used for branch prediction. The source program 21 can efficiently apply a hardware mechanism (short loop mechanism) that temporarily stores instruction sequences in an instruction buffer and executes instructions directly from the instruction buffer without instruction decoding.
[0049] The three-dimensional array shown in the left diagram of Figure 6C can also be considered as a loop access of the two-dimensional array shown in the right diagram of Figure 6C. Here, the relative position of the array element with subscript (i, j, k) from the beginning of the three-dimensional array A with array size (x, y, z) is Offset3(A(i, j, k), d(x, y, z)). Similarly, the relative position of the array element with subscript (i, j) from the beginning of the two-dimensional array A with array size (x, y) is Offset2(A(i, j), d(x, y)).
[0050] Then, the offset of the position from the beginning of the three-dimensional array A, Offset3(A(i,j,k),d(x,y,*)), can be calculated as follows: Offset3(A(i,j,k),d(x,y,*))={(i-1)+(j-1)*x+(k-1)*(x*y)}*L
[0051] Furthermore, when the subscript dimension is "2" and the subscript is "1", Offset3(A(ij,1,k),d(x,y,*)) can be calculated as follows: Offset3(A(ij,1,k),d(x,y,*))={(ij-1)+(k-1)*(x*y)}*L Such Offset3(A(ij,1,k),d(x,y,*)) matches Offset2(A(ij,k),d(x,y,*)) because the access size of the two-dimensional array is equal to the number of loop iterations (x*y).
[0052] Furthermore, when the subscript dimension is "3" and the subscript is "1", Offset3(A(i,jk,1),d(x,y,*)) can be calculated as follows: Offset3(A(i,jk,1),d(x,y,*))={(i-1)+(jk-1)*(x*y)}*L Such Offset3(A(i,jk,1),d(x,y,*)) matches Offset2(A(i,jk),d(x,y,*)) because the access size of the two-dimensional array is equal to the number of loop rotations (x*y).
[0053] Therefore, even if the subscript with a subscript dimension of "1" is the function i(k), as shown in Figure 6C, the three-dimensional array A(i(k),j,k) can be considered as a loop access of the two-dimensional array A(i(k),jk). This is because the access size (defined size) of the array is equal to the number of loop iterations (x*y).
[0054] The four-dimensional array shown in the left diagram of Figure 6D can also be considered as a loop access of the three-dimensional array shown in the right diagram of Figure 6D. Here, the relative position of the array element with subscript (i, j, k, m) from the top area of the four-dimensional array A with array size (x, y, z, w) is Offset4(A(i, j, k, m), d(x, y, z, w)).
[0055] Then, the offset of the position from the beginning of the four-dimensional array A, Offset4(A(i,j,k,m),d(x,y,z,*)), can be calculated as follows: Offset4(A(i,j,k,m),d(x,y,z,*))={(i-1)+(j-1)*x+(k-1)*(x*y)+(m-1)*(x*y*z)}*L
[0056] Furthermore, when the subscript dimension is "2" and the subscript is "1", Offset4(A(ij,1,k,m),d(x,y,z,*)) can be calculated as follows: Offset4(A(ij,1,k,m),d(x,y,z,*))={(ij-1)+(k-1)*(x*y)+(m-1)*(x*y*z)}*L Such Offset4(A(ij,1,k,m),d(x,y,z,*)) matches Offset3(A(ij,k,m),d(x*y,z,*)).
[0057] Therefore, even if the subscript with a subscript dimension of "4" is the function "t(m)," as shown in Figure 6D, the four-dimensional array A(i,j,k,t(m)) can be considered as a loop access of a three-dimensional array A(ij,k,t(m)). This is because the access size (defined size) of the array is equal to the number of loop iterations (x*y).
[0058] Similarly, for adjacent subscripts j and k in a four-dimensional array A(i,j,k,m), if the loop rotation count y*z matches the defined size, the four-dimensional array A(i,jk,1,m) can be regarded as a three-dimensional array A(i,jk,m), and the loop nest can be reduced from four to three loops. Similarly, the four-dimensional array A(i,j,km,1) can be regarded as a three-dimensional array A(i,j,km) with loop rotation count x*y, and the loop nest can be reduced from four to three loops. Similarly, the four-dimensional array A(ijk,1,1,m) can be regarded as a two-dimensional array A(ijk,m) with loop rotation count x*y*z, and the loop nest can be reduced from four to two loops. Similarly, by transforming the four-dimensional array A(i,j,k,m) into A(ij,1,km,1) and regarding the number of loop rotations as a two-dimensional array A(ij,kj) of x*y and z*w, the loop nest can be reduced from four loops to two loops.
[0059] Fig. 7 is a diagram illustrating optimization using the memory area of an array. In Fig. 7, it is assumed that the array size of a three-dimensional array is (4, 6, 2).
[0060] The upper part of Figure 7 shows the position offset Offset3(A3(i,j,k)) of the memory area in a three-dimensional array A3(i,j,k) with an array size of (4,6,2). Elements with subscript i corresponding to 1 to 4 are located in the memory area of the array in each row. Elements with subscript j corresponding to 1 to 6 are located in the memory area of the array in each column. Elements with subscript k corresponding to 1 are located in the memory area of the array in rows 1 to 6, and elements with subscript k corresponding to 2 are located in the memory area of the array in rows 7 to 12.
[0061] The middle section of Figure 7 shows the position offset Offset3(A3(i,1,k)) of the memory area in the three-dimensional array A3(i,1,k) with an array size of (24,1,2). In the memory area of the array in rows 1 to 6, the elements corresponding to subscript k = 1 and subscript j = 1 are positioned in the address direction by changing the subscript i (1 to 24). In the memory area of the array in rows 7 to 12, the elements corresponding to subscript k = 2 and subscript j = 1 are positioned in the address direction by changing the subscript i (1 to 24). In other words, the offset of the position accessed from the head area of A3(i,j,k) with an array size of (4,6,2) matches the offset of the position from the head area of A3(i,1,k) with an array size of (24,1,2). It can be seen that both arrays are accessed in ascending order from the head area of the array.
[0062] Meanwhile, the lower part of Figure 7 shows the position offset Offset2(A2(i,k)) of the memory area in the two-dimensional array A2(i,k) with an array size of (24,2). In the memory area of the array from rows 1 to 6, the element whose subscript k corresponds to 1 is positioned in the address direction by changing the subscript i (1 to 24). In the memory area of the array from rows 7 to 12, the element whose subscript k corresponds to 2 is positioned in the address direction by changing the subscript i (1 to 24).
[0063] In this case, Offset2(A2(i,k)) is the same as Offset3(A3(i,1,k)). In other words, the offset of the position accessed from the beginning of the two-dimensional array A2(i,k) is the same as the offset of the position accessed from the beginning of the three-dimensional array A3(i,1,k). Both arrays are accessed in ascending order from the beginning of the array.
[0064] In other words, if the access size (defined size) of the array is equal to the number of loop iterations (6 * 4), the three-dimensional array can be regarded as a two-dimensional array loop access. This means that the loop nest can be reduced by replacing the n-dimensional array A with the n-1-dimensional array A and integrating the loop. In other words, the n-1-dimensional array A is accessed by reducing the array dimension of the n-dimensional array A by one, so the source program 21 can reduce the loop nest by integrating the loop.
[0065] As described above, in the optimization process according to the embodiment, it has been explained that loop nests can be reduced by replacing a three-dimensional array A(i,j,k) with a two-dimensional array A(ij,k) and integrating the loop. Here, by treating the subscript portion to be integrated as "1" within the compiler (replaced with A(ij,1,k)), it is possible to use array definition information 24 with the same number of dimensions without reducing the array dimensions. Therefore, hereinafter, an example will be described in which array definition information 24 with the same number of dimensions is used, with the subscript of the dimension to be reduced set to "1."
[0066] [Example of optimization] Fig. 8A is a diagram (1) showing an example of optimization according to the embodiment. The left diagram of Fig. 8A shows a source program 21. It is assumed that the syntax analysis unit 11 analyzes a loop described in this source program 21 and stores the analysis results in the loop management table 22 shown in Fig. 3. It is assumed that the syntax analysis unit 11 analyzes an array within the loop described in the source program 21 and stores the analysis results in the array syntax information 23 shown in Fig. 4 and the array definition information 24 shown in Fig. 5.
[0067] The array analysis unit 121 searches the nesting levels of the loop management table 22 from 1 to the final level. The array analysis unit 121 searches the loop management table 22 for a control variable corresponding to the nesting level k and a subscript corresponding to the subscript dimension k of the target array in the array syntax information 23 ( <1> ) or not. In addition, the array analysis unit 121 determines whether the initial value corresponding to the nest level k in the loop management table 22 is "1", the increment value is "1", and the final value matches the definition size corresponding to the subscript dimension k in the array definition information 24 ( <2> ) or not. <2> The condition (1) determines whether the number of loop turns at nest level k of the loop matches the array size of subscript dimension k.
[0068] Here, if the nesting level is "1", <1> Regarding the above, the control variable at nesting level k (=1) is "x", but the subscript of the subscript dimension k (=1) of array a3 is "mod(x,3)+1", which does not match, so the condition is not met.
[0069] If the nesting level is "2", <1> The control variable of nesting level k (=2) is "y", and the subscript of the subscript dimension k (=2) of array a3 is "y", so the condition is met. <2> The initial value corresponding to the nesting level k (=2) is "1", the increment value is "1", and the final value "10" matches the defined size "10" corresponding to the subscript dimension k (=2) of the array definition information 24, so the condition is met. The number of loop iterations matches the array definition (array access size).
[0070] Next, if the nesting level is "3", <1> The control variable of nesting level k (=3) is "z", and the subscript of the subscript dimension k (=3) of array a3 is "z", so the condition is met. <2> The initial value corresponding to the nesting level k (=3) is "1", the increment value is "1", and the final value "30" matches the defined size "30" corresponding to the subscript dimension k (=3) of the array definition information 24, so the condition is met. The number of loop iterations matches the array definition (array access size).
[0071] Array b3 will produce the same results as array a3.
[0072] Then, at successive nesting levels k <1> <2> Since the above condition is satisfied, the extraction unit 122 extracts the target arrays a3 and b3. The extraction unit 122 extracts the consecutive loops 2 and 3 at the nesting level k as reducible loops.
[0073] The integrating unit 123 then sets the smaller of the consecutive dimensions "2" and "3" as the replacement dimension, "2", and replaces it with the variable "yz" obtained by combining the subscripts of each dimension. The integrating unit 123 also replaces the subscript "z" of the non-replacement dimension "3" with the constant "1". Here, the arrays a3 and b3 are replaced from the following left expression to the right expression. a3(mod(x,3)+1,y,z)→a3(mod(x,3)+1,yz,1) b3(mod(x,3)+1,y,z)→a3(mod(x,3)+1,yz,1)
[0074] The integrating unit 123 then removes the loop at nest level "2" corresponding to the smaller consecutive dimension "2". The integrating unit 123 then refers to the loop management table 22 and changes the end value of the loop to be integrated to the number of rotations (20*30) multiplied by the end value of each loop at consecutive nest levels. The integrating unit 123 then changes the control variable of the loop to be integrated to the variable yz replaced with an array. Here, "do y=1,20" is deleted. And "do z=1,30" is changed to "do yz=1,20*30".
[0075] As a result, the source program 21 shown in the left diagram of FIG. 8A is changed to the program shown in the right diagram of FIG. 8A.
[0076] 8A illustrates a case where two loops are combined into one loop. However, the case is not limited to the case where two loops are combined into one loop, and three or more loops may be combined into one loop. Therefore, a case where three or more loops are combined into one loop will be described with reference to FIG. 8B.
[0077] FIG. 8B is a diagram (2) showing an example of optimization according to the embodiment. It is assumed that the defined sizes of the array names a4 and b4 shown in FIG. 8B are (10, 20, 30, 40), respectively. The left diagram in FIG. 8B shows a source program 21. When the nesting level is "1", <1> Regarding the above, the control variable at nesting level k (=1) is "x", but the subscript of the subscript dimension k (=1) of array a4 is "mod(x,3)+1", which does not match, so the condition is not met.
[0078] If the nesting level is "2", <1> The control variable of nesting level k (=2) is "y", and the subscript of the subscript dimension k (=2) of array a4 is "y", so the condition is met. <2> The initial value corresponding to the nesting level k (=2) is "1", the increment value is "1", and the final value "20" matches the defined size "20" corresponding to the subscript dimension k (=2) of the array definition information 24, so the condition is met. The number of loop iterations matches the array definition (array access size).
[0079] Next, if the nesting level is "3", <1> The control variable of nesting level k (=3) is "z", and the subscript of the subscript dimension k (=3) of array a4 is "z", so the condition is met. <2> The initial value corresponding to the nesting level k (=3) is "1", the increment value is "1", and the final value "30" matches the defined size "30" corresponding to the subscript dimension k (=3) of the array definition information 24, so the condition is met. The number of loop iterations matches the array definition (array access size).
[0080] Next, if the nesting level is "4", <1> The control variable of nesting level k (=4) is "w", and the subscript of the subscript dimension k (=4) of array a4 is "w", so the condition is met. <2> The initial value corresponding to the nesting level k (=4) is "1", the increment value is "1", and the final value "40" matches the defined size "40" corresponding to the subscript dimension k (=4) of the array definition information 24, so the condition is met. The number of loop iterations matches the array definition (array access size).
[0081] Array b4 will produce the same results as array a4.
[0082] Then, at successive nesting levels k <1> <2> Since the above condition is satisfied, the extraction unit 122 extracts the target arrays a4 and b4. The extraction unit 122 extracts the consecutive loops 2, 3, and 4 at the nesting level k as reducible loops.
[0083] The integrating unit 123 then sets the smaller of the consecutive dimensions "2", "3", and "4" as the replacement dimension, "2", and replaces it with the variable "yzw" obtained by combining the subscripts of each dimension. The integrating unit 123 also replaces the subscripts "z" and "w" of the non-replacement dimensions "3" and "4" with the constant "1". Here, the arrays a4 and b4 are replaced from the following left expression to the right expression. a4(mod(x,3)+1,y,z,w)→a4(mod(x,3)+1,yzw,1,1) b4(mod(x,3)+1,y,z,w)→a4(mod(x,3)+1,yzw,1,1)
[0084] The integrating unit 123 then reduces the loops at nesting levels "2" and "3" corresponding to the smaller consecutive dimensions "2" and "3." The integrating unit 123 then refers to the loop management table 22 and changes the end value of the loop to be integrated to the number of rotations (20*30*40) multiplied by the end value of each loop at consecutive nesting levels. The integrating unit 123 then changes the control variable of the loop to be integrated to the variable yzw replaced with an array. Here, "do y=1,20" and "do z=1,30" are deleted. Then, "do w=1,40" is changed to "do yzw=1,20*30*40."
[0085] Also, in Fig. 8A, a case where two loops are combined into one loop has been described. In Fig. 8B, a case where three or more loops are combined into one loop has been described. However, this is not limited to the case where three or more loops are combined into one loop, and it may also be the case where there are multiple loops to be reduced within a loop. Therefore, a case where there are multiple loops to be reduced within a loop will be described with reference to Fig. 8C.
[0086] 8C is a diagram (3) showing an example of optimization according to the embodiment. It is assumed that the defined sizes of the array names a5 and b5 shown in FIG. 8C are (10, 20, 30, 40, 50), respectively. The left diagram in FIG. 8C shows a source program 21.
[0087] If the nesting level is "3", <1> Regarding the above, the control variable at nesting level k (= 3) is "z", but the subscript of the subscript dimension k (= 3) of array a5 is "mod(z,DV1)+1", which does not match, so the condition is not met.
[0088] If the nesting level is "1", <1> The control variable of nesting level k (=1) is "x", and the subscript of the subscript dimension k (=1) of array a5 is "x", so the condition is met. <2> The initial value corresponding to the nesting level k (=1) is "1", the increment value is "1", and the final value "10" matches the defined size "10" corresponding to the subscript dimension k (=1) of the array definition information 24, so the condition is met. The number of loop iterations matches the array definition (array access size).
[0089] Also, if the nesting level is 2, <1> The control variable of nesting level k (=2) is "y", and the subscript of the subscript dimension k (=2) of array a5 is "y", so the condition is met. <2> The initial value corresponding to the nesting level k (=2) is "1", the increment value is "1", and the final value "20" matches the defined size "20" corresponding to the subscript dimension k (=2) of the array definition information 24, so the condition is met. The number of loop iterations matches the array definition (array access size).
[0090] Next, if the nesting level is 4, <1> The control variable of nesting level k (=4) is "w", and the subscript of the subscript dimension k (=4) of array a5 is "w", so the condition is met. <2> The initial value corresponding to the nesting level k (=4) is "1", the increment value is "1", and the final value "40" matches the defined size "40" corresponding to the subscript dimension k (=4) of the array definition information 24, so the condition is met. The number of loop iterations matches the array definition (array access size).
[0091] Also, if the nesting level is 5, <1> The control variable of nesting level k (=5) is "a", and the subscript of the subscript dimension k (=5) of array a5 is "a", so the condition is met. <2> The initial value corresponding to the nesting level k (=5) is "1", the increment value is "1", and the final value "50" matches the defined size "50" corresponding to the subscript dimension k (=5) of the array definition information 24, so the condition is met. The number of loop iterations matches the array definition (array access size).
[0092] Array b4 will produce the same results as array a4.
[0093] And at successive nesting levels "1", "2" and "4", "5" <1> <2> Since the above condition is satisfied, the extraction unit 122 extracts the target arrays a5 and b5. The extraction unit 122 extracts the consecutive loops "1", "2" and "4", "5" at nesting level k as reducible loops.
[0094] The integrating unit 123 then sets the smaller of the consecutive dimensions "1" and "2" as the replacement dimension, and replaces it with the variable "xy" obtained by combining the subscripts of each dimension. The integrating unit 123 also replaces the subscript "y" of "2", which is not the replacement dimension, with the constant "1". The integrating unit 123 also sets the smaller of the consecutive dimensions "4" and "5", which is the replacement dimension, with the variable "wa" obtained by combining the subscripts of each dimension. The integrating unit 123 also replaces the subscript "a" of "5", which is not the replacement dimension, with the constant "1". Here, the arrays a5 and b5 are replaced from the following left expression to the right expression. a5(x,y,mod(z,DV1)+1,w,a)→a5(xy,1,mod(z,DV1)+1,wa,1) b5(x,y,mod(z,DV1)+1,w,a)→b5(xy,1,mod(z,DV1)+1,wa,1)
[0095] The integrating unit 123 then reduces the loop at nesting level "1" corresponding to the smaller consecutive dimension "1." The integrating unit 123 then refers to the loop management table 22 and changes the end value of the loop to be integrated to the number of rotations (10*20) multiplied by the end values of the loops at the smaller consecutive nesting levels. The integrating unit 123 then changes the control variable of the loop to be integrated to the variable "xy" replaced with an array. The integrating unit 123 also reduces the loop at nesting level "4" corresponding to the smaller consecutive dimension "4." The integrating unit 123 then refers to the loop management table 22 and changes the end value of the loop to the number of rotations (40*50) multiplied by the end values of the loops at the smaller consecutive nesting levels. The integrating unit 123 then changes the control variable of the loop to be integrated to the variable "wa" replaced with an array. In this example, "do x=1,10" and "do w=1,40" are deleted. Then, "do y=1,20" is changed to "do xy=1,10*20". "do a=1,50" is changed to "do wa=1,40*50".
[0096] [Another example of optimization] 9 is a diagram illustrating another example of optimization according to the embodiment. In the source program 21 shown in FIG. 9, a sibling process is included in a loop with a nesting level of "2." The sibling flag corresponding to the nesting level "2" in the loop management table 22 is set to "1."
[0097] The array analysis unit 121 refers to the loop management table 22 and determines that the sibling flag is set at nesting level "2" of the multiple loops, so the sibling processes are treated as separate processes. That is, the array analysis unit 121 splits the sibling processes into loops, as shown by reference symbol d1. The array analysis unit 121 then creates a multiple loop configuration that does not include sibling processes, as shown by reference symbol d2, and then analyzes the array. The array analysis unit 121 also analyzes the array of the multiple loop configuration of the split sibling processes. By splitting the sibling processes into separate processes, the array analysis unit 121 can simplify optimization.
[0098] [Optimization process flowchart] 10 is a diagram showing an example of a flowchart of the optimization process according to the embodiment. It is assumed that the syntax analysis unit 11 generates a loop management table 22, array syntax information 23, and array definition information 24 for a source program 21.
[0099] As shown in FIG. 10, the sequence analysis unit 121 selects the nest level (lvl) of the loop management table 22 (abbreviated as DOTBL) (step S11).
[0100] The sequence analysis unit 121 then determines whether a sibling flag corresponding to the nesting level is set (step S12). If it determines that a sibling flag is set (step S12; Yes), the sequence analysis unit 121 splits the sibling process into loops (step S13). The sequence analysis unit 121 then proceeds to step S14 to perform optimization processing on the multiple loop configuration that does not include sibling processes and the sibling processes, respectively.
[0101] On the other hand, if it is determined that the sibling flag is not set (step S12; No), the sequence analysis unit 121 proceeds to step S14.
[0102] In step S14, the array analysis unit 121 refers to the array syntax information 23 (step S14). The array analysis unit 121 determines whether the description ASTR corresponding to the subscript dimension (lvl) of the array name matches the control variable of DOTBL (step S15). That is, the array analysis unit 121 determines whether the subscript corresponding to the subscript dimension lvl of the target array in the array syntax information 23 matches the control variable corresponding to the same nesting level lvl as the subscript dimension in the loop management table 22 ( <1> conditions).
[0103] If it is determined that the description ASTR corresponding to the subscript dimension (lvl) of the array name does not match the control variable of DOTBL (step S15; No), the array analysis unit 121 proceeds to step S18 to select the next nesting level (lvl).
[0104] On the other hand, if it is determined that the description ASTR corresponding to the subscript dimension (lvl) of the array name matches the control variable of DOTBL (step S15; Yes), the array analysis unit 121 performs the following process. The array analysis unit 121 determines whether the initial value of DOTBL is "1", the increment value is "1", and the final value matches the defined size of the array definition information 24 ( <2> (condition (1)) (step S16). That is, the array analysis unit 121 determines whether the number of turns of the nest level (lvl) of the loop matches the defined size of the array of the subscript dimension (lvl).
[0105] If it is determined that the initial value of DOTBL is "1", the increment value is "1", or the final value does not match the defined size of the array definition information 24 (step S16; No), the array analysis unit 121 proceeds to step S18 to select the next nesting level (lvl).
[0106] On the other hand, if it is determined that the initial value of DOTBL is "1", the increment value is "1", and the end value matches the defined size of the array definition information 24 (step S16; Yes), the array analysis unit 121 stores the subscript dimension (lvl) and subscript corresponding to the nesting level for the array name in the integrated array candidate table (step S17). Then, the array analysis unit 121 proceeds to step S18. The integrated array candidate table indicates a table used for integrating loops. The integrated array candidate table stores, for each array name, a subscript for each subscript dimension corresponding to the nesting level of the loop of the integration candidate.
[0107] In step S18, the sequence analysis unit 121 determines whether or not all nesting levels (lvl) have been selected (step S18). If it is determined that all nesting levels (lvl) have not been selected (step S18; No), the sequence analysis unit 121 proceeds to step S11 to select the next nesting level.
[0108] On the other hand, if it is determined that all nesting levels (lvl) have been selected (step S18; Yes), the extraction unit 122 refers to the integrated sequence candidate table and determines whether the number of dimensions is continuous (step S19). If it is determined that the number of dimensions is not continuous (step S19; No), the extraction unit 122 cannot integrate the loops, and therefore ends the optimization process.
[0109] If it is determined that the number of dimensions is consecutive (step S19; Yes), the extraction unit 122 extracts the loop at the nest level corresponding to the consecutive number of dimensions as a target for reduction. Then, the integration unit 123 sets the smallest value of the consecutive dimensions as a replacement dimension and replaces the subscript of the replacement dimension with a subscript obtained by combining the subscripts (control variables) of each dimension. Then, the integration unit 123 replaces the subscripts (control variables) of the dimension other than the smallest dimension with the constant "1" (step S20). For example, for the array name a3, the integrated array candidate table stores "y" as the subscript (control variable) corresponding to the number of dimensions "2" and "z" as the subscript (control variable) corresponding to the number of dimensions "3". Then, the integration unit 123 replaces the array a3(x, y, z) with the array a3(x, yz, 1).
[0110] The integrating unit 123 then deletes the loop of the loop nest corresponding to a dimension other than the maximum dimension of the consecutive dimensions (step S21). The integrating unit 123 then changes the end value and the control variable name of the loop of the maximum consecutive dimension (step S22). For example, the consecutive dimensions are "2" and "3". The loop nest corresponding to dimension "2" is "2", and the control variable of the loop of loop nest "2" is "y". The loop nest corresponding to dimension "3" is "3", and the control variable of the loop of loop nest "3" is "z". Then, the integrating unit 123 deletes, for example, "do y=1,20". The integrating unit 123 then changes "do z=1,30" to "do yz=1,20*30".
[0111] Then, the code generation unit 13 translates the replaced source program 21 (step S23). For example, the code generation unit 13 converts the replaced source program 21 into intermediate code. Then, the code generation unit 13 converts the intermediate code into a machine language program. Then, the code generation unit 13 ends the optimization process.
[0112] As a result, the information processing device 1 can reduce the number of branch instructions in a loop by reducing loop nests, and can efficiently use the branch table used for branch prediction. Furthermore, by reducing loop nests, the information processing device 1 can increase the number of executions per code of a basic block, and can increase the loop execution density (number of executions / code size). Furthermore, the information processing device 1 can improve the application efficiency of a hardware mechanism (short loop mechanism) that temporarily stores an instruction sequence in an instruction buffer and executes the instruction directly from the instruction buffer without instruction decoding.
[0113] In the embodiment, the array analysis unit 121 extracts loops to be reduced from the source program 21 using the array size of consecutive subscripts in an n-dimensional array (n≧3) in the innermost loop and the number of iterations of the control variable corresponding to the consecutive subscripts in the loop. The array analysis unit 121 then reduces the loop nest of the extracted loop. However, the array analysis unit 121 may also extract cost-effective loops to be reduced based on profile information, and reduce the loop nest. The profile information here refers to information that associates the loop length, loop count, and array access count for each loop. The loop length (L) refers to the length of the code in the loop. The loop count (M) refers to the number of iterations of the loop from the initial value to the final value of the loop. The array access count (D) refers to the number of times an array is accessed in one loop. The profile information is information output when an object obtained as a result of translating the source program 21 is executed.
[0114] For example, if the loop length (L) is too long, instruction decoding and instruction fetching cannot be omitted. Therefore, the cost of instruction decoding and instruction fetching for a program can be reduced by keeping the loop length (L) below a certain threshold. The loop execution density can be increased by increasing the number of array accesses (D) and the number of loops (M) in the loop. Therefore, performance improvement can be expected when M, L, and D are large. Therefore, evaluation values (weighting coefficients) that become more effective as M, L, and D increase are prepared in advance. The array analysis unit 121 then obtains the loop length (L), the number of array accesses (D), and the number of loops (M) for each loop i from the profile information, multiplies these values by weighting coefficients corresponding to the values, and calculates the sum (L(i)*I(i)+M(i)*m(i)+D(i)*d(i)). Note that I(i), m(i), and d(i) are the weighting coefficients for the loop length, the number of array accesses, and the number of loops for loop i, respectively. The sequence analysis unit 121 may then compare the calculated value for each loop with a predetermined threshold to extract candidates for loops to be reduced.The sequence analysis unit 121 may then extract loops to be reduced and reduce loop nests using the candidates for loops to be reduced extracted by the optimization process according to the embodiment and the candidates for loops to be reduced extracted by referring to the profile information.
[0115] The evaluation function is not limited to (L(i)*I(i)+M(i)*m(i)+D(i)*d(i)). In addition, the evaluation function may include or combine attributes other than M, L, and D. In addition, the predetermined threshold may be an actual measurement value (empirical value) obtained by the processor or a logical value, and is not limited to this.
[0116] In the embodiment, the array analysis unit 121 extracts a loop to be reduced from the source program 21 using the array size of consecutive subscripts in an n-dimensional array (n≧3) in the innermost loop and the number of iterations of the control variable corresponding to the consecutive subscripts in the loop, and reduces the loop nest. However, the array analysis unit 121 is not limited to this, and may acquire a loop specified by a user and reduce the loop nest. For example, the user explicitly specifies the loop to be reduced in an OCL (Object Constraint Language) statement in the source program 21. Then, the array analysis unit 121 acquires the loop specified by the OCL statement from the source program 21 and reduces the loop nest.
[0117] In the embodiment, the end value of the loop in the loop management table 22 is a constant. However, the number of rotations may be a variable instead of a constant, as long as the array analysis unit 121 can determine whether the end value storing the number of rotations is the same as the defined size of the array.
[0118] In the above embodiment, the information processing device 1 internally replaces the source program 21 with another source program and performs object expansion from the intermediate language to machine language. However, the information processing device 1 may expand the source program 21 into an intermediate language, then perform array replacement and loop integration at the intermediate language level, and then perform object expansion into machine language.
[0119] In the above embodiment, the defined size of the array is a fixed size determined at the time of translation. However, the defined size of the array may be a defined size of the array acquired dynamically at the time of execution. In other words, it is sufficient if the array analysis unit 121 can determine whether the final value that stores the number of rotations is the same as the defined size of the array.
[0120] [Effects of the Example] According to the above embodiment, the information processing device 1 determines whether the array sizes of the first and second arguments of an n-dimensional array (n≧3) included in the instruction code of the innermost loop in source code containing multiple hierarchical loops match the rotation numbers of the first index corresponding to the first argument and the second index corresponding to the second argument in the loop. If the array sizes match, and if the first and second indexes each start at 1 and the increment values of the first and second indexes are 1, the information processing device 1 replaces the first and second arguments of the n-dimensional array included in the instruction code with the third argument to change the array to an n-1-dimensional array. Then, the information processing device 1 merges the loops of the first and second indexes. With this configuration, the information processing device 1 can reduce loop nests by merging the loops. As a result, the information processing device 1 can reduce branch instructions in loops and efficiently use branch tables available for branch prediction. Furthermore, by reducing loop nests, the information processing device 1 can increase the number of executions per code of a basic block, thereby increasing the loop execution density.
[0121] Furthermore, according to the above embodiment, the information processing device 1 further changes an n-dimensional array to an (n-1)-dimensional array when the variable indicating the first argument matches the control variable of the first index and the variable of the second argument matches the control variable of the second index. According to this configuration, when the variable indicating the argument of an array at the same level matches the control variable of the loop index, the information processing device 1 performs continuous access to the memory area allocated based on the array size, thereby realizing a reduction in loop nesting. On the other hand, when the variable indicating the argument of an array at the same level does not match the control variable of the loop index, the information processing device 1 performs discontinuous access, thereby failing to reduce loop nesting.
[0122] Furthermore, according to the above embodiment, the information processing device 1 further changes an n-dimensional array to an n-1-dimensional array when the first argument and the second argument are adjacent to each other. With this configuration, the information processing device 1 can reduce the dimensions of the array. As a result, the information processing device 1 can reduce the loop corresponding to the reduced argument.
[0123] Furthermore, according to the above embodiment, the information processing device 1 deletes the loop using the first index corresponding to the first argument and changes the closing value of the second index corresponding to the third argument. With this configuration, the information processing device 1 can reduce the loop nest.
[0124] Furthermore, according to the above embodiment, the information processing device 1 acquires candidates for loops to be integrated using profile information acquired when executing source code, the profile information including the length of code within each loop, the number of loop iterations, and the number of times an n-dimensional array is accessed in one loop, and determines loops to be integrated including the acquired candidates for loop. With this configuration, the information processing device 1 can further optimize compilation of source code.
[0125] Furthermore, according to the above embodiment, the information processing device 1 determines the loops to be integrated based on a user specification. With this configuration, the information processing device 1 can flexibly optimize the compilation of source code.
[0126] [others] It should be noted that the components of the illustrated information processing device 1 do not necessarily have to be physically configured as shown in the drawing. In other words, the specific manner of distribution and integration of the information processing device 1 is not limited to that shown in the drawing, and all or part of it can be functionally or physically distributed and integrated in any unit depending on various loads, usage conditions, etc. For example, the sequence analysis unit 121 can be configured as follows: <1> a determination unit that determines whether the condition is satisfied; <2> and a determination unit that determines whether the above condition is satisfied. On the other hand, the sequence analysis unit 121 and the extraction unit 122 may be integrated into one unit. Furthermore, the storage unit 20 may be connected to the information processing device 1 as an external device via a network.
[0127] The various processes described in the above embodiments can be realized by executing a prepared program on a computer such as a personal computer or a workstation. Therefore, an example of a computer that executes a compiler program that realizes the same functions as the information processing device 1 shown in Fig. 1 will be described below. Fig. 11 is a diagram showing an example of a computer that executes a compiler program.
[0128] 11, computer 700 includes a CPU 703 that executes various types of arithmetic processing, an input device 715 that accepts data input from a user, and a display control unit 707 that controls a display device 709. Computer 700 also includes a drive device 713 that reads programs and the like from a storage medium, and a communication control unit 717 that transmits and receives data to and from other computers via a network. Computer 700 also includes a memory 701 that temporarily stores various types of information, and a HDD 705. Memory 701, CPU 703, HDD 705, display control unit 707, drive device 713, input device 715, and communication control unit 717 are connected by a bus 719.
[0129] The drive device 713 is, for example, a device for the removable disk 711. The HDD 705 stores a compiler program 705a and compiler processing related information 705b.
[0130] The CPU 703 reads out the compiler program 705a, expands it in the memory 701, and executes it as a process. Such a process corresponds to each functional unit of the information processing device 1. The compiler processing related information 705b corresponds to the loop management table 22, the array syntax information 23, the array definition information 24, etc. For example, a removable disk 711 stores each piece of information such as the compiler program 705a.
[0131] It should be noted that compiler program 705a does not necessarily have to be stored in HDD 705 from the beginning. For example, the program may be stored in a "portable physical medium" such as a flexible disk (FD), CD-ROM, DVD disk, magneto-optical disk, or IC card that is inserted into computer 700. Then, computer 700 may read and execute compiler program 705a from these. [Explanation of symbols]
[0132] 1. Information processing equipment 10 Control Unit 11 Parser 12 Optimization Section 121 Sequence Analysis Department 122 Extraction part 123 Integration Department 13 Code Generation 20 Memory section 20-1 Loop data storage section 22 Loop Management Table 20-2 Array data storage section 21 Source Program 23 Array Syntax Information 24 Array definition information 30 Machine Language Program
Claims
1. In source code that contains multiple levels of loops, determining whether or not the array sizes of a first argument and a second argument of an n-dimensional array (n≧3) included in an instruction code in the innermost loop match the rotation numbers of a first index corresponding to the first argument and a second index corresponding to the second argument in the loop, respectively; If they match, and if the first index and the second index each start at 1 and the increment value of the first index and the second index is 1, replace the first argument and the second argument of the n-dimensional array included in the instruction code with a third argument to change it into an (n-1)-dimensional array; Merging the loops for the first index and the second index. A compiler program that causes a computer to execute a process.
2. The changing process further changes the array to the n-1-dimensional array when the variable indicating the first argument matches the control variable of the first index and the variable of the second argument matches the control variable of the second index.
2. The compiler program according to claim 1.
3. The changing process further includes changing the first argument and the second argument to the n-1-dimensional array when the first argument and the second argument are adjacent to each other.
3. The compiler program according to claim 2.
4. The integrating process deletes a loop using the first index corresponding to the first argument and changes the closing value of the second index corresponding to the third argument.
2. The compiler program according to claim 1.
5. The merging process acquires candidates for loops to be merged using profile information acquired when the source code is executed, the profile information including the length of code in each loop, the number of loop iterations, and the number of times the n-dimensional array is accessed in one loop, and determines the loops to be merged, including the acquired candidates for loops.
2. The compiler program according to claim 1, further comprising:
6. The merging process determines the loops to be merged based on the user's designation.
2. The compiler program according to claim 1, further comprising:
7. In source code that contains multiple levels of loops, a determination unit that determines whether or not, for an n-dimensional array (n≧3) included in an instruction code in an innermost loop, the array sizes of a first argument and a second argument match the rotation numbers of a first index corresponding to the first argument and a second index corresponding to the second argument in the loop; a modification unit that, when they match, replaces the first argument and the second argument of the n-dimensional array included in the instruction code with a third argument and modifies the n-dimensional array into an (n-1)-dimensional array if the first index and the second index each start at 1 and an increment value of the first index and the second index is 1; a merging unit that merges loops of the first index and loops of the second index; An information processing device comprising:
8. In source code that contains multiple levels of loops, determining whether or not the array sizes of a first argument and a second argument of an n-dimensional array (n≧3) included in an instruction code in the innermost loop match the rotation numbers of a first index corresponding to the first argument and a second index corresponding to the second argument in the loop, respectively; If they match, and if the first index and the second index each start at 1 and the increment value of the first index and the second index is 1, replace the first argument and the second argument of the n-dimensional array included in the instruction code with a third argument to change it into an (n-1)-dimensional array; Merging the loops for the first index and the second index. A compiler method in which processing is performed by a computer.
Citation Information
Patent Citations
Automatic vectorizing system
JP1988127367A
Fan device
JP1989041696A
Do loop optimizing processing system for input / output library
JP1990191040A
Information processor, compilation method, and compilation program
JP2017021726A
Compiler optimization techniques for exploiting a zero overhead loop mechanism
US6367071B1