Information processing device, compilation program, and compilation method
The information processing device optimizes loop fusion by analyzing loop information to determine optimal combinations, addressing inefficiencies in register usage and arithmetic unit allocation, thereby improving processing performance.
Patent Information
- Application Number
- JP2021041104
- Authority / Receiving Office
- JP · JP
- Patent Type
- Patents
- Current Assignee / Owner
- Filing Date
- 2021-03-15
- Publication Date
- 2024-11-14
- Estimated Expiration
- 2041-03-15
AI Technical Summary
Inefficient loop fusion in compilers leads to insufficient register usage and inefficient allocation of arithmetic units, resulting in deteriorated processing performance of object code.
An information processing device and method that analyzes loop information, including the number of variables, registers, and memory instructions to determine optimal loop combinations for fusion, ensuring efficient register usage and balanced arithmetic unit allocation.
Improves processing performance by preventing register spills and efficiently utilizing arithmetic units, thereby enhancing the execution speed of fused loops.
Smart Images

Figure 0007583270000001 
Figure 0007583270000002 
Figure 0007583270000003
Abstract
Description
[Technical field]
[0001] The present invention relates to an information processing device, a compilation program, and a compilation method. [Background technology]
[0002] In software development, compilers are often used to convert source code written in a high-level language into object code written in a low-level language such as machine code. In the process of converting source code into object code, compilers may perform various optimizations to improve the execution efficiency of the object code. Optimization may involve loop optimization such as loop fusion, loop unrolling, and loop division. For example, loop fusion may analyze the structure of loops present in the code and fuse multiple loops to improve data locality and reduce the number of loop evaluations, thereby improving execution efficiency.
[0003] Here, there has been proposed a loop optimization method in which a compiler estimates the number of registers to be used from a set of instructions constituting a loop, thereby limiting the number of loop unrolls to a range that does not cause register spills.
[0004] Also, a compiler device has been proposed that does not perform a plurality of loop optimizations individually, but analyzes the characteristics of a program / hardware according to the optimization level, and performs a combination of loop optimizations according to the analysis.
[0005] Furthermore, a compilation program has been proposed that calculates the ratio between the number of operations executed in each loop and the number of data transfers, and determines whether or not loop fusion is possible based on whether or not this ratio meets a reference value specified by the performance conditions of the system. [Prior art documents] [Patent documents]
[0006] [Patent Document 1] Japanese Patent Application Publication No. 7-121381 [Patent Document 2] Japanese Patent Application Publication No. 8-101776 [Patent Document 3] JP 2014-228891 A Summary of the Invention [Problem to be solved by the invention]
[0007] If the combination of loops to be fused is inappropriate, the execution efficiency of the object code cannot be sufficiently improved. For example, in the processing of the fused loops, there may be a shortage of registers to store the values of variables, or the allocation of multiple arithmetic units to multiple instructions may be inefficient, resulting in insufficient use of the arithmetic units, resulting in poor processing performance when the object code is executed.
[0008] According to one aspect, the present invention has an object to provide an information processing device, a compilation program, and a compilation method that improve processing performance. [Means for solving the problem]
[0009] In one embodiment, an information processing device that performs compilation is provided. The information processing device has a storage unit and a processing unit. The storage unit stores code to be processed. The processing unit acquires loop information for each of a plurality of loops included in the code, the information including the number of variables used in the loop, the number of registers, the number of memory instructions for inputting and outputting the values of the variables between the registers and a main storage device, and the number of operation instructions for the values of the variables stored in the registers, and calculates the number of variables, the number of registers, the number of memory instructions, and the number of operation instructions corresponding to the combination of loops that is a candidate for loop fusion for each of a plurality of combinations of loops based on the loop information, and determines a combination to which loop fusion is applied from among the plurality of combinations based on a comparison between the number of variables, the number of registers, and the number of memory instructions calculated for each of the plurality of combinations and the number of operation instructions, and executes loop fusion for the determined combination.
[0010] Also, in one embodiment, a compilation program is provided. Also, in one aspect, a compilation method is provided. Effect of the Invention
[0011] On the one hand, processing performance can be improved. [Brief description of the drawings]
[0012] [Figure 1] FIG. 1 is a diagram illustrating an information processing apparatus according to a first embodiment. [Diagram 2] FIG. 11 illustrates an example of hardware of an information processing apparatus according to a second embodiment. [Diagram 3] FIG. 2 illustrates an example of CPU hardware. [Figure 4] FIG. 2 is a diagram illustrating an example of functions of an information processing device. [Diagram 5] FIG. 13 illustrates a first example of loop fusion. [Figure 6] FIG. 13 illustrates a second example of loop fusion. [Figure 7] FIG. 13 is a diagram illustrating an example of loop fusion determination from the viewpoint of a reduction loop. [Figure 8] FIG. 13 is a diagram illustrating an example of loop fusion determination from the viewpoint of time. [Figure 9] FIG. 13 is a diagram illustrating another example of loop fusion determination from the viewpoint of time. [Figure 10] FIG. 13 illustrates an example of loop fusion determination in terms of data dependence; [Figure 11] FIG. 13 illustrates another example of loop fusion determination in terms of data dependence; [Figure 12] FIG. 13 is a diagram illustrating an example of code that is a target for determining whether loop fusion is performed. [Figure 13] FIG. 13 is a diagram illustrating an example of a loop fusion possible list. [Figure 14] FIG. 11 is a diagram illustrating an example of loop information. [Figure 15] FIG. 13 is a diagram showing an example of loop information (continuation). [Figure 16]FIG. 13 is a diagram showing an example of loop information (continuation). [Figure 17] FIG. 13 is a diagram illustrating an example of loop fusion candidate information. [Figure 18] FIG. 13 is a diagram showing an example of loop fusion candidate information (continued). [Figure 19] 13 is a flowchart illustrating an example of an overall compilation process. [Figure 20] 11 is a flowchart illustrating an example of loop fusion possible list generation. [Figure 21] 13 is a flowchart illustrating an example of loop information generation. [Figure 22] 13 is a flowchart illustrating an example of loop fusion candidate information generation. [Diagram 23] 13 is a flowchart illustrating an example of calculation of item values of loop fusion candidates. [Figure 24] 13 is a flowchart showing an example of fusion target determination. [Diagram 25] FIG. 13 is a diagram illustrating an example of a result of determining loop fusion targets. [Figure 26] FIG. 13 is a diagram illustrating another example of code that is a target for determining whether loop fusion is performed. [Figure 27] FIG. 13 is a diagram illustrating an example of code after loop fusion. [Figure 28] FIG. 1 illustrates an example of instruction scheduling. [Figure 29] FIG. 13 is a diagram illustrating a comparative example of instruction scheduling. [Diagram 30] FIG. 13 is a diagram showing a comparative example of instruction scheduling (continuation). DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0013] The present embodiment will be described below with reference to the drawings. [First embodiment] A first embodiment will be described.
[0014] FIG. 1 is a diagram illustrating an information processing apparatus according to a first embodiment. The information processing device 10 has a compiler function that converts a source code 20 into an object code 30. The information processing device 10 has a storage unit 11 and a processing unit 12.
[0015] The storage unit 11 may be a volatile storage device such as a random access memory (RAM) or a non-volatile storage device such as a hard disk drive (HDD) or a flash memory. The processing unit 12 may include a central processing unit (CPU), a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), etc. The processing unit 12 may be a processor that executes a program. The "processor" may also include a set of multiple processors (multiprocessor).
[0016] The storage unit 11 stores information used in the compilation process of the processing unit 12. For example, the storage unit 11 stores source code 20 to be compiled. For example, the source code 20 includes a description of the processes of loops #1, #2, #3, and #4.
[0017] The processing unit 12 generates intermediate code 20a, which is code written in an intermediate language, based on the source code 20, and stores the intermediate code 20a in the storage unit 11. The intermediate code is code used inside a compiler. The intermediate code 20a includes descriptions corresponding to loops #1 to #4.
[0018] The processing unit 12 acquires loop information 21 for each loop based on the intermediate code 20a, the loop information 21 including the number of variables, the number of registers, the number of memory instructions, and the number of operation instructions used in the loop. The loop information 21 is stored in the storage unit 11.
[0019] Memory instructions are instructions written in the intermediate code 20a that input and output the values of variables between a register and the main memory. Memory instructions include a LOAD instruction that stores the value of a variable from the main memory to a register, and a STORE instruction that stores the value of a variable from a register to the main memory. Arithmetic instructions are instructions written in the intermediate code 20a that perform arithmetic operations on the value of a variable stored in a register. Arithmetic instructions include the ADD instruction, SUB instruction, MULT instruction, and DIV instruction.
[0020] For example, the number of variables may be the number of variables other than the control variables of the loop. Also, the number of registers may be acquired for each type of register, such as integer registers and floating-point registers. For example, the number of variables, the number of registers, the number of memory instructions, and the number of operation instructions acquired for each of loops #1 to #4 are registered in the loop information 21.
[0021] The processing unit 12 calculates the number of variables, the number of registers, the number of memory instructions, and the number of operation instructions corresponding to each of a plurality of combinations of loops that are candidates for loop fusion, based on the loop information 21. The processing unit 12 records the calculation results in the loop fusion candidate information 22. The loop fusion candidate information 22 records the number of variables, the number of registers, the number of memory instructions, and the number of operation instructions calculated for each combination of loops that are candidates for loop fusion. The loop fusion candidate information 22 is stored in the storage unit 11.
[0022] Here, the processing unit 12 extracts combinations of loops that are candidates for loop fusion based on the structure of each loop, such as reduction or titre, and the dependency relationship between variables included in the loops. The combinations of loops that are candidates for loop fusion may include not only combinations of loops whose control variables have the same possible values, but also combinations of loops whose control variables have different possible values.
[0023] For example, for loops #1 to #4, there are three candidate combinations for loop fusion: (#1, #2), (#2, #3), and (#3, #4). Based on loop information 21, processing unit 12 obtains the sums of the numbers of variables, registers, memory instructions, and operation instructions of the loops belonging to the combination, thereby obtaining the numbers of variables, registers, memory instructions, and operation instructions corresponding to the combination.
[0024] For example, according to the loop information 21, the number of variables in loop #1 is a1, and the number of variables in loop #2 is a2. Therefore, the number of variables A1 for the combination of loops #1 and #2 is A1=a1+a2. Also, for example, according to the loop information 21, the number of memory instructions in loop #1 is c1, and the number of memory instructions in loop #2 is c2. Therefore, the number of memory instructions C1 for the combination of loops #1 and #2 is C1=c1+c2.
[0025] The processing unit 12 determines a combination to which loop fusion is to be applied from among the multiple combinations based on a comparison of the number of variables, the number of registers, and the number of memory instructions and the number of operation instructions calculated for each of the multiple combinations of loops.
[0026] For example, the processing unit 12 prioritizes combinations of loops with a larger number of variables among the combinations of loops that are candidates for fusion. Also, the processing unit 12 determines, as a combination to which loop fusion is applied, a combination of loops that is a candidate for fusion and whose corresponding number of registers is equal to or less than the number of registers of the information processing device that is to execute the object code 30. The information processing device that is to execute the object code 30 may be the information processing device 10.
[0027] Furthermore, the processing unit 12 determines a combination in which the number of arithmetic instructions is smaller than the number of memory instructions as a combination to which loop fusion is applied. For example, the processing unit 12 determines a combination in which the value obtained by subtracting a predetermined value from the number of memory instructions is equal to or greater than the number of arithmetic instructions as a combination to which loop fusion is applied. The predetermined value may be determined according to the number of memory instructions that can be simultaneously executed by a plurality of arithmetic units that execute arithmetic instructions and that are provided in an information processing device that is to execute the object code 30.
[0028] The processing unit 12 executes loop fusion on the determined loop combination. For example, the processing unit 12 determines to apply loop fusion to (#2,#3) among the loop combinations (#1,#2), (#2,#3), and (#3,#4) that are fusion candidates based on the loop fusion candidate information 22. In this case, the processing unit 12 executes loop fusion on the loop combination (#2,#3) that is a fusion candidate, and generates intermediate code 20b after loop fusion execution. The intermediate code 20b is stored in the storage unit 11.
[0029] The processing unit 12 generates an object code 30 based on the intermediate code 20b. For example, the processing unit 12 generates an assembly language from the intermediate code 20b, generates an object code 30 from the assembly language, and stores the object code 30 in the storage unit 11.
[0030] According to the information processing device 10, for each of a plurality of loops included in the code to be processed, loop information 21 including the number of variables, the number of registers, the number of memory instructions, and the number of operation instructions used in the loop is acquired. Based on the loop information 21, the number of variables, the number of registers, the number of memory instructions, and the number of operation instructions corresponding to a combination of loops that is a candidate for loop fusion are calculated for each of a plurality of combinations of loops. Based on a comparison of the number of variables, the number of registers, and the number of memory instructions calculated for each of the plurality of combinations with the number of operation instructions, a combination to which loop fusion is to be applied is determined from among the plurality of combinations. Loop fusion is executed for the determined combination.
[0031] This makes it possible to improve processing performance. Here, in optimization by loop fusion at compile time, if the combination of loops to be fused is inappropriate, the execution efficiency of the object code cannot be sufficiently improved. For example, in the processing of the fused loops, there may be a shortage of registers for storing the values of variables, or the allocation of multiple arithmetic units to multiple instructions may be inefficient, resulting in insufficient use of the arithmetic units, and this may result in poor processing performance when the object code is executed.
[0032] Therefore, the information processing device 10 determines a combination of loops to be fused using the number of variables, the number of registers, the number of memory instructions, and the number of arithmetic instructions for the combination of loops as fusion candidates, thereby preventing spills due to a lack of registers and efficiently using the arithmetic units. For example, as described above, the information processing device 10 preferentially fuses loops with a large number of variables among combinations in which the number of registers corresponding to the combination of loops is equal to or less than the number of physical registers mounted on the device and the number of arithmetic instructions is equal to or less than a reference value based on the number of memory instructions. This makes it possible to select, as a fusion target, a combination of loops that does not exceed the number of physical registers, contains arithmetic instructions and memory instructions in a balanced manner, has a large number of variables, and is likely to fill the arithmetic units.
[0033] As a result, it is possible to efficiently allocate a plurality of instructions to the arithmetic units so that the vacancies of the arithmetic units are reduced during each cycle of execution of the fused loop in the object code 30, thereby improving processing performance. For example, it is possible to improve the processing speed of the fused loop. It is also possible to efficiently use registers.
[0034] The function of the compiler in the information processing device 10 will be described in more detail below. [Second embodiment] Next, a second embodiment will be described.
[0035] FIG. 2 illustrates an example of hardware of an information processing apparatus according to the second embodiment. The information processing device 100 includes a CPU 101, a RAM 102, a HDD 103, a GPU (Graphics Processing Unit) 104, an input interface 105, a medium reader 106, and a NIC (Network Interface Card) 107. The CPU 101 is an example of the processing unit 12 of the first embodiment. The RAM 102 or the HDD 103 is an example of the storage unit 11 of the first embodiment.
[0036] CPU 101 is a processor that executes program instructions. CPU 101 loads at least a part of the programs and data stored in HDD 103 into RAM 102 and executes the programs. CPU 101 may include multiple processor cores. Information processing device 100 may have multiple processors. The processes described below may be executed in parallel using multiple processors or processor cores. A set of multiple processors may be called a "multiprocessor" or simply a "processor."
[0037] The RAM 102 is a volatile semiconductor memory that temporarily stores programs executed by the CPU 101 and data used by the CPU 101 for calculations. The RAM 102 is used as a main storage device of the information processing device 100. The main storage device may be called a main memory or simply a memory. Note that the information processing device 100 may be provided with a type of memory other than a RAM, or may be provided with multiple memories.
[0038] The HDD 103 is a non-volatile storage device that stores software programs such as an OS (Operating System), middleware, and application software, as well as data. The information processing device 100 may include other types of storage devices, such as a flash memory or an SSD (Solid State Drive), or may include multiple non-volatile storage devices.
[0039] The GPU 104 outputs an image to a display 51 connected to the information processing device 100 in accordance with an instruction from the CPU 101. As the display 51, any type of display can be used, such as a CRT (Cathode Ray Tube) display, a liquid crystal display (LCD: Liquid Crystal Display), a plasma display, or an organic EL (OEL: Organic Electro-Luminescence) display.
[0040] The input interface 105 acquires an input signal from an input device 52 connected to the information processing device 100, and outputs the signal to the CPU 101. As the input device 52, a pointing device such as a mouse, a touch panel, a touch pad, or a trackball, a keyboard, a remote controller, a button switch, or the like can be used. In addition, a plurality of types of input devices may be connected to the information processing device 100.
[0041] The medium reader 106 is a reading device that reads programs and data recorded on the recording medium 53. For example, a magnetic disk, an optical disk, a magneto-optical disk (MO: Magneto-Optical disk), a semiconductor memory, etc. can be used as the recording medium 53. The magnetic disk includes a flexible disk (FD: Flexible Disk) and a HDD. The optical disk includes a compact disc (CD) and a digital versatile disc (DVD).
[0042] The medium reader 106 copies, for example, the program or data read from the recording medium 53 to another recording medium such as the RAM 102 or the HDD 103. The read program is executed, for example, by the CPU 101. Note that the recording medium 53 may be a portable recording medium, and may be used for distributing the program or data. The recording medium 53 and the HDD 103 may also be referred to as computer-readable recording media.
[0043] The NIC 107 is an interface that is connected to the network 50 and communicates with other computers via the network 50. The NIC 107 is connected to a communication device such as a switch or a router via a cable.
[0044] FIG. 3 is a diagram illustrating an example of CPU hardware. The CPU 101 has a group of arithmetic units 101a and a group of registers 101b. The group of arithmetic units 101a is a group of arithmetic units included in the CPU 101. The group of registers 101b is a group of general-purpose registers included in the CPU 101. Hereinafter, the general-purpose registers are simply referred to as registers. The registers include integer registers that store integer values and floating-point registers that store floating-point values. The register group 101b includes a plurality of integer registers and a plurality of floating-point registers.
[0045] The arithmetic unit is an arithmetic execution circuit that performs numerical calculations on values stored in a register, and is also called an ALU (Arithmetic and Logic Unit). In one example, the CPU 101 has four arithmetic units. Each arithmetic unit performs calculations on data in a register and writes the calculation results to the register.
[0046] FIG. 4 is a diagram illustrating an example of functions of the information processing device. The information processing device 100 has a storage unit 110, an intermediate language storage unit 120, a control information storage unit 130, a compiler 140, and a linker 150. The storage unit 110, the intermediate language storage unit 120, and the control information storage unit 130 use storage areas of a RAM 102 and a HDD 103. The compiler 140 and the linker 150 are realized by the CPU 101 executing a program stored in the RAM 102.
[0047] The storage unit 110 stores information used in the processing of the compiler 140 and the linker 150. For example, the storage unit 110 stores a source program 111, an object file 112, and an execution file 113.
[0048] The source program 111 is a file including source code written in a high-level language. The object file 112 is a file including object code generated by compiling the source program 111 with a compiler 140. As described above, the object code is written in a low-level language such as machine language. The executable file 113 is a file generated by linking the object file 112 and a library file with a linker 150.
[0049] The intermediate language storage unit 120 stores the intermediate language generated by the compiler 140 . The control information storage unit 130 stores control information used in the optimization process of the compiler 140 .
[0050] The compiler 140 compiles the source program 111, and outputs an object file 112 as a compilation result. The compiler 140 has a source program input unit 141, an input / output control unit 142, an intermediate language generation unit 143, an optimization unit 144, a code generation unit 145, and an object file output unit 146.
[0051] The source program input unit 141 opens the specified source program 111. For example, when instructed to start compiling, the source program input unit 141 reads the source program 111 stored in the storage unit 110 and outputs it to the input / output control unit 142.
[0052] The input / output control unit 142 selects various processes according to options and file types. For example, when the source program 111 is input from the source program input unit 141, the input / output control unit 142 outputs the source program 111 to the intermediate language generation unit 143. When an assembly language is input from the code generation unit 145, the input / output control unit 142 outputs the assembly language to the object file output unit 146.
[0053] The intermediate language generation unit 143 generates an intermediate language from the source program 111 input from the input / output control unit 142, and stores the intermediate language in the intermediate language storage unit 120. Specifically, the intermediate language generation unit 143 converts the source program 111 into intermediate code used by the optimization unit 144, i.e., code used within the compiler. Then, the intermediate language generation unit 143 stores the converted intermediate language in the intermediate language storage unit 120.
[0054] The optimization unit 144 performs optimization including source analysis and loop fusion in order to speed up the execution of object code corresponding to the source program 111 . In the source analysis, the optimizer 144 analyzes the intermediate language. For example, the optimizer 144 reads the intermediate language from the intermediate language storage unit 120 and performs line reconstruction, lexical analysis, syntactic analysis, semantic analysis, and the like.
[0055] The optimization unit 144 determines a combination of loops as candidates for fusion based on the loop conditions of each of a plurality of loops existing in the source program 111 or the intermediate language generated from the source program 111 from the result of the source analysis. For example, the optimization unit 144 determines a combination of loops as candidates for fusion based on a loop structure such as reduction or titre and data dependency within the loop. The optimization unit 144 can determine a combination of loops as candidates for fusion regardless of whether the initial value, final value, and increment value of the loops are the same or not.
[0056] During optimization by loop fusion, the optimization unit 144 calculates, for each combination of loops of the fusion candidates, the sum of the numbers of variables, the sum of the numbers of integer registers, the sum of the numbers of floating-point registers, the sum of the numbers of memory instructions, and the sum of the numbers of arithmetic instructions of the loops belonging to the combination. The optimization unit 144 stores the calculation results in the control information storage unit 130. The optimization unit 144 determines a combination of the loop combinations of the fusion candidates to which loop fusion is to be applied, based on the number of variables, the number of integer registers, the number of floating-point registers, and a comparison of the number of memory instructions and the number of arithmetic instructions calculated for each combination of loops of the fusion candidates. The optimization unit 144 executes loop fusion for the determined combination of loops, and outputs the intermediate language after the loop fusion to the code generation unit 145.
[0057] The code generation unit 145 generates an assembly language from the intermediate language optimized by the optimization unit 144. The code generation unit 145 outputs the generated assembly language to the input / output control unit 142.
[0058] When an assembly language is input from the input / output control unit 142 , the object file output unit 146 generates an object file 112 from the assembly language and stores it in the storage unit 110 .
[0059] The linker 150 reads the object file 112 generated by the object file output unit 146 from the storage unit 110, and combines the object file 112 with a library file to generate an executable file 113. The linker 150 then stores the generated executable file 113 in the storage unit 110.
[0060] Next, an example of loop fusion by the optimization unit 144 will be described. FIG. 5 is a diagram illustrating a first example of loop fusion. For example, when the optimization unit 144 determines that loop a1 and loop b1 in code 61 can be fused, it converts code 61 into code 62 by inserting the arithmetic expression of loop b1 next to the arithmetic expression of loop a1, and processes them as one loop. In this way, it is possible to reduce the cost of repeated processing for loop determination and speed up execution performance. Note that loops a1 and b1 are both identical in that the initial value of the loop control variable i is "1", the final value is "10", and the increment value is "1". Here, when the increment value is "1", the description of it in the code is omitted.
[0061] FIG. 6 illustrates a second example of loop fusion. For example, the optimization unit 144 may determine that loop a2 and loop b2 in the code 63 can be fused. Here, in loop a2, the initial value of loop control variable i is "1", the final value is "10", and the increment value is "2". On the other hand, in loop b2, the initial value of loop control variable j is "3", the final value is "30", and the increment value is "1". That is, the possible values of the loop control variables are different between loop a2 and loop b2.
[0062] In this case, the optimization unit 144 converts the code 63 into the code 64 by fusing the loop a2 and the loop b2 using, for example, a mask variable "mask1(i)" or a mask variable "mask2(i)". The mask variable is used for a branch instruction in the fused loop. However, an if statement using the mask variable may be inserted as a branch instruction in the fused loop, which may result in inefficient loop fusion.
[0063] Next, an example of loop fusion determination by the optimization unit 144 is illustrated. FIG. 7 is a diagram illustrating an example of loop fusion determination from the viewpoint of a reduction loop. A reduction or reduction operation is an accumulation over the iterations of a loop. A reduction loop is a loop that contains a reduction. In the example in Figure 7, the variable a is assigned the result of the reduction.
[0064] 7A illustrates a code 71 including loops 1a and 2a that can be fused. In the code 71, a reduction is performed in the loop 1a, but a, which stores the result of the reduction in the loop 1a, is not referenced in the loop 2a. Therefore, the optimization unit 144 determines that the loops 1a and 2a can be fused.
[0065] 7B illustrates code 72 including loops 1b and 2b that cannot be fused. In code 72, there is a reduction in loop 1b. The result of the reduction in loop 1b is stored in a, which is referenced in loop 2b. Therefore, the optimization unit 144 determines that loops 1b and 2b cannot be fused.
[0066] FIG. 8 is a diagram illustrating an example of loop fusion determination from the viewpoint of time. A tight loop is a loop in which only the innermost loop has an operation among multiple loops. If an operation is included between intermediate loops, the loop below the loop including the operation is considered to be tight. In other words, the optimization unit 144 determines a loop in which only the innermost loop has an operation among multiple loops as a fusion candidate, and if an operation is included between intermediate loops, the loop below the loop including the operation is considered to be tight and is excluded from the fusion candidates.
[0067] FIG. 8A illustrates a code 73 including loops 1c and 2c that can be fused. Both loops 1c and 2c are tightly coupled. Therefore, the optimization unit 144 determines that loops 1c and 2c can be fused.
[0068] FIG. (8)(B) illustrates code 74 including loops 1d and 2d that cannot be fused. Loop 2d is a tightrift. On the other hand, loop 1d is not a tightrift because an arithmetic expression "c=d*i" exists outside the innermost loop. Therefore, the optimization unit 144 determines that loops 1d and 2d cannot be fused.
[0069] FIG. 9 is a diagram illustrating another example of loop fusion determination from the viewpoint of time. Code 75 includes loops 1e, 2e, 3e, and 4e. Loops 2e and 3e are inner loops of loop 1e. Loop 1e is not tightly bound because the arithmetic expression "c=d*x" exists in a loop other than the innermost loop. Therefore, the optimization unit 144 determines that loop 1e and loop 4e cannot be fused.
[0070] On the other hand, both loops 2e and 3e are tightly coupled, so the optimization unit 144 determines that loop 2e and loop 3e can be fused. FIG. 10 is a diagram illustrating an example of loop fusion determination from the viewpoint of data dependence.
[0071] 10A illustrates an example of code 81 including loops 1f and 2f that can be fused. In loops 1f and 2f, A(j) and A(j+1) are dependent on each other, but the dependence is in the forward direction, so the optimization unit 144 determines that data will not be destroyed even if the loops are fused. Therefore, the optimization unit 144 determines that loops 1f and 2f can be fused.
[0072] 10B illustrates an example of code 82 including loops 1g and 2g that cannot be fused. In loops 1g and 2g, A(j+1) and A(j) depend on each other, but the dependence is in the opposite direction. The optimization unit 144 determines that data will be destroyed if loops 1g and 2g are fused. Therefore, the optimization unit 144 determines that loops 1g and 2g cannot be fused.
[0073] FIG. 11 is a diagram illustrating another example of loop fusion determination from the viewpoint of data dependence. 11A illustrates an example of code 83 including loops 1h and 2h that can be fused. In the example of code 83, when a pair of loops 1h and 2h is selected as a fusion candidate, the optimization unit 144 determines that loops 2h and 3h are not in a dependent relationship because loop 3h does not use the calculation result of loop 2h. Therefore, the optimization unit 144 determines that loops 1h and 2h can be fused.
[0074] 11B illustrates an example of code 84 including loops 1i and 2i that cannot be fused. In the example of code 84, when loop 1i and loop 2i are candidates for fusion, the optimization unit 144 determines that loop 2i and loop 3i have a dependency relationship because loop 3i uses the calculation result of loop 2i. Therefore, the optimization unit 144 determines that loop 1i and loop 2i cannot be fused.
[0075] FIG. 12 illustrates an example of code that is a target for determining whether or not loop fusion should be performed. The source code 111a is an example of code included in the source program 111. For example, the source code 111a includes five loops, loops 1 to 5. The optimization unit 144 extracts combinations of loops that are candidates for merging from the intermediate language of the source code 111a generated by the intermediate language generation unit 143. In the case of the intermediate language of the source code 111a, the optimization unit 144 first extracts candidates using loop 1 as a trigger, and then performs determination in order using loops 2, 3, 4, and 5 as triggers. Note that for the description of the intermediate language (intermediate code), reference can be made to FIG. 12 in JP 2014-228891 A, for example.
[0076] FIG. 13 is a diagram illustrating an example of a loop fusion possible list. The loop fusion possible list 131 is generated by the optimization unit 144 and stored in the control information storage unit 130. The optimization unit 144 determines whether or not a trigger loop can be fused with another loop based on the loop structure such as the reduction loop or tie loop described above, and sets the loop fusion possible list 131.
[0077] The loop fusible list 131 includes items of trigger and fusible loop. The trigger item registers the number of the loop that will be the trigger. The fusible loop item registers the number of the loop that can be fusible with the trigger loop.
[0078] For example, a record of trigger "1" and fusible loops "2, 4, 5" is registered in the fusible loop list 131. This record indicates that loops 2, 4, and 5 can be fused with loop 1. Fusible loops are similarly registered in the fusible loop list 131 for other triggers.
[0079] FIG. 14 is a diagram illustrating an example of loop information. The loop information 132 is generated by the optimization unit 144 and stored in the control information storage unit 130. The optimization unit 144 acquires variable information, the number of registers, the loop shape, and instruction information for each loop based on the intermediate language of the source code 111a, and records them in the loop information 132 for each loop.
[0080] Variable information is information about variables used in a loop. Variable information includes variables used in arithmetic operations (variables other than the control variable of the loop) and information about the final loop in which the variable survives (surviving loop). Surviving loop information is used to identify variables to be checked when checking the dependency of variables between loops. Variable information also includes the variables used and flag information indicating whether the variable is a control variable of the loop. For the flag information indicating whether a variable is a control variable, "Yes" indicates that it is a controlled variable and "No" indicates that it is not a controlled variable.
[0081] The number of registers is information about the number of integer registers and the number of floating-point registers used in the loop. The loop shape is information about the initial value, the final value, and the increment value that represent the possible values of the control variable of the loop.
[0082] The instruction information is information on the number of memory instructions and the number of arithmetic operation instructions. The memory instructions are the LOAD instruction and the STORE instruction. The arithmetic operation instructions are the ADD instruction, the SUB instruction, the MULT instruction, and the DIV instruction. The numbers counted as the number of memory instructions and the number of arithmetic operation instructions may be the number of memory instructions and the number of arithmetic operation instructions for variables other than the control variable of the loop.
[0083] In the example of loop 1, the optimization unit 144 records a variable "a" used in arithmetic operations of floating-point numbers and a final loop "loop 3" in which the variable "a" exists in the loop information 132. The optimization unit 144 also records control variable flag information "No", "Yes", and "Yes" for the used variable names "a", "i", and "j", respectively, in the loop information 132. The optimization unit 144 also records, for example, an integer register "2" and a floating-point register "1" as the number of registers in loop 1 in the loop information 132. The optimization unit 144 also records, for example, an initial value "1", a final value "10", and an increment value "1" as the loop shape of loop 1 in the loop information 132. The optimization unit 144 also records, for example, a memory instruction count "-" (none) and a number of arithmetic operation instructions "1" as instruction information for loop 1 in the loop information 132.
[0084] Similarly, for loop 2 , the optimization unit 144 obtains variable information, the number of registers, the loop shape, and instruction information, and records them in the loop information 132 . FIG. 15 is a diagram showing an example of the loop information (continuation).
[0085] The optimization unit 144 also obtains variable information, the number of registers, the loop shape, and instruction information for the loops 3 and 4 , and records them in the loop information 132 . FIG. 16 is a diagram showing an example (continuation) of the loop information.
[0086] The optimization unit 144 also obtains variable information, the number of registers, the loop shape, and instruction information for the loop 5 , and records them in the loop information 132 . FIG. 17 is a diagram illustrating an example of loop fusion candidate information.
[0087] The loop fusion candidate information 133 is generated by the optimization unit 144 based on the loop fusion possible list 131 and the loop information 132, and is stored in the control information storage unit 130. The loop fusion candidate information 133 is information indicating, for each combination of a trigger loop and a fusion candidate loop, whether masking is required, the number of variables, the number of registers, the presence or absence of variable dependency, the number of memory instructions, and the number of operation instructions.
[0088] Here, the optimization unit 144 extracts combinations of loops that are candidates for fusion for each trigger based on the possible loop fusion list 131 , and registers them in the loop fusion candidate information 133 . In the example of the loop fusion possible list 131, the fusion possible loops for trigger "1" are loops 2, 4, and 5. Therefore, the optimization unit 144 records combinations of loops "1,2", "1,4", and "1,5" as candidates in the loop item of the loop fusion candidate information 133.
[0089] Next, the optimization unit 144 searches for the next fusible loop for loops 2, 4, and 5 combined with loop 1. For example, in the loop fusible list 131, fusible loop "3" is listed for trigger "2". However, loop 3 is not listed as a fusible loop for trigger "1". For this reason, the optimization unit 144 does not list a combination including loop 3 in the loop item of the loop fusion candidate information 133 for trigger "1".
[0090] Next, in the loop fusion possible list 131, a fusible loop "4" is written for trigger "2". The fusible loops for trigger "1" include loop 4. Therefore, the optimization unit 144 records the combination of loops "1, 2, 4" as candidates for trigger "1" in the loop item of the loop fusion candidate information 133. Similarly, the optimization unit 144 records the combinations of loops "1, 2, 5", "1, 4, 5", and "1, 2, 4, 5" as candidates for trigger "1" in the loop item of the loop fusion candidate information 133. The optimization unit 144 then moves on to trigger "2" and similarly records the combinations of loops as fusion candidates in the loop fusion candidate information 133, and repeats this until there are no more triggers.
[0091] Here, the information registered in the loop fusion candidate information 133 based on the loop information 132 will be described. The necessity of mask processing refers to whether or not mask processing using a mask variable needs to be added during merging, and if necessary, it is "true", otherwise it is "false". Mask processing is a branch process that is added when merging combinations of loops that have different initial values, final values, and increment values of the loop control variables.
[0092] The number of variables is the sum of the numbers of variables used in each loop belonging to the corresponding combination of loops. The number of registers is the sum of the number of registers used by each loop in the corresponding loop combination, and is calculated for each integer register and floating-point register. In the diagram, the number of registers is written as "r1, r2". r1 is the number of integer registers. r2 is the number of floating-point registers.
[0093] The presence or absence of a variable dependency is the presence or absence of a variable dependency across loops in each loop belonging to the loop combination in question. Examples of variable dependency, i.e., data dependency, are the dependencies shown in Figures 10 and 11. Dependence is "true" and no dependency is "false".
[0094] The number of memory instructions is the sum of the number of memory instructions in each loop belonging to the corresponding combination of loops. The number of operation instructions is the sum of the numbers of operation instructions in each loop belonging to the corresponding combination of loops.
[0095] For example, in the loop fusion candidate information 133, for loop combination "1,2" that is a fusion candidate for trigger "1", a record is registered with the following: mask "true", number of variables "2", number of registers "4,2", dependency "false", number of memory instructions "2", and number of operation instructions "2". This record indicates that when merging the combination of loops "1,2", mask processing must be added, and that the number of variables other than the control variables of the loops is "2", the number of integer registers is "4", the number of floating-point registers is "2", the number of memory instructions is "2", and the number of operation instructions is "2". This record also indicates that there is no variable dependency relationship in loops 1 and 2 that belong to the combination of loops "1,2".
[0096] Similarly, for other combinations of trigger “1”, the optimization unit 144 registers records of the mask, the number of variables, the number of registers, the dependency, the number of memory instructions, and the number of operation instructions in the loop fusion candidate information 133.
[0097] Similarly, for the combination of loops that are candidates for fusion with respect to trigger “2”, the optimization unit 144 registers records of the mask, the number of variables, the number of registers, the dependency, the number of memory instructions, and the number of operation instructions in the loop fusion candidate information 133.
[0098] FIG. 18 is a diagram illustrating an example of the loop fusion candidate information (continued). Similarly, for the combinations of loops that are candidates for fusion for triggers “3” and “4”, the optimization unit 144 registers records of the mask, the number of variables, the number of registers, the dependency, the number of memory instructions, and the number of operation instructions in the loop fusion candidate information 133.
[0099] For trigger “5”, there is no fusible loop in the possible loop fusion list 131. Therefore, the optimization unit 144 does not need to register information for trigger “5” in the loop fusion candidate information 133.
[0100] Next, the processing procedure of the information processing device 100 will be described. FIG. 19 is a flowchart showing an example of the overall compilation process. (S10) The intermediate language generation unit 143 acquires the source program 111 input by the source program input unit 141 from the input / output control unit 142, and generates an intermediate language for the source program 111. The source program 111 includes, for example, the source code 111a illustrated in FIG. 12. The intermediate language generation unit 143 stores the generated intermediate language in the intermediate language storage unit 120.
[0101] (S11) The optimization unit 144 generates a loop fusion possible list 131 based on the intermediate language stored in the intermediate language storage unit 120, and stores the generated loop fusion possible list 131 in the control information storage unit 130. The details of the generation of the loop fusion possible list will be described later.
[0102] (S12) The optimization unit 144 generates loop information 132 based on the intermediate language stored in the intermediate language storage unit 120, and stores the generated loop information 132 in the control information storage unit 130. Details of loop information generation will be described later.
[0103] (S13) The optimization unit 144 generates loop fusion candidate information 133 based on the possible loop fusion list 131 and the loop information 132 stored in the control information storage unit 130, and stores the generated loop fusion candidate information 133 in the control information storage unit 130. Details of the generation of loop fusion candidate information will be described later.
[0104] (S14) The optimization unit 144 determines a combination of loops to be fused, based on the loop fusion candidate information 133 stored in the control information storage unit 130. The details of determining which loops are to be fused will be described later.
[0105] (S15) The optimization unit 144 generates an intermediate language after loop fusion by performing loop fusion on the combination of loops to be fused determined in step S14 in the intermediate language stored in the intermediate language storage unit 120. Note that when performing loop fusion on a combination of loops whose mask is "true" in the loop fusion candidate information 133, the optimization unit 144 performs loop fusion by adding a mask process to the loop initialization process.
[0106] (S16) Code generation unit 145 generates an assembly language based on the intermediate language after loop fusion, and outputs it to input / output control unit 142. Object file output unit 146 acquires the generated assembly language from input / output control unit 142, and generates object file 112 based on the assembly language. Object file output unit 146 stores the generated object file 112 in storage unit 110. Then, compiling ends.
[0107] FIG. 20 is a flowchart showing an example of loop fusion possible list generation. The loop fusion possible list generation corresponds to step S11. (S20) The optimization unit 144 initializes the trigger loop number I. For example, the optimization unit 144 initializes I to 1.
[0108] (S21) The optimization unit 144 generates an empty list, which is a template for the loop fusion possible list 131, and stores it in the control information storage unit . (S22) The optimization unit 144 sets the loop number J to be judged to J=I+1.
[0109] (S23) The optimization unit 144 determines whether or not loop I and loop J included in the intermediate language can be fused based on loop structures such as reduction loops and tie trees. If they can be fused, the process proceeds to step S24. If they cannot be fused, the process proceeds to step S25.
[0110] (S24) The optimization unit 144 adds a fusible loop J, which has the trigger loop number I, to the fusible loop list 131. Then, the process proceeds to step S25. (S25) The optimization unit 144 judges whether or not the fusion possibility has been judged for all judgment targets for the trigger loop number I. When the judgment target loop number J reaches the last loop number, judgment has been completed for all judgment targets. If judgment has been completed for all judgment targets, the process proceeds to step S27. If judgment has not been completed for all judgment targets, the process proceeds to step S26.
[0111] (S26) The optimization unit 144 increments J. That is, the optimization unit 144 sets J=J+1. Then, the process proceeds to step S23. (S27) The optimization unit 144 determines whether or not all trigger loops have been processed. When the trigger loop number I reaches the last loop number, all trigger loops have been processed. If all trigger loops have been processed, the generation of the loop fusion possible list is completed. If all trigger loops have not been processed, the process proceeds to step S28.
[0112] (S28) The optimization unit 144 increments I. That is, the optimization unit 144 sets I=I+1. Then, the process proceeds to step S21. FIG. 21 is a flowchart showing an example of loop information generation.
[0113] The loop information generation corresponds to step S12. (S30) The optimization unit 144 initializes the trigger loop number I. For example, the optimization unit 144 initializes I to 1.
[0114] (S31) The optimization unit 144 generates template data of the loop information 132 and stores it in the control information storage unit 130. (S32) The optimization unit 144 obtains variable information of loop I based on the intermediate language, and writes it to the loop information 132.
[0115] (S33) The optimization unit 144 obtains the number of registers for loop I based on the intermediate language, and writes the number of registers to the loop information 132. The optimization unit 144 obtains the number of registers separately for integer registers and floating-point registers.
[0116] (S34) The optimization unit 144 obtains the loop shape of loop I, that is, the initial value, final value, and increment value of the control variables, based on the intermediate language, and writes them to the loop information 132. (S35) The optimization unit 144 obtains instruction information for loop I based on the intermediate language, and writes this information to the loop information 132. The optimization unit 144 obtains the number of memory instructions and the number of operation instructions as the instruction information.
[0117] (S36) The optimization unit 144 determines whether or not all trigger loops have been processed. If all trigger loops have been processed, the loop information generation ends. If all trigger loops have not been processed, the process proceeds to step S37.
[0118] (S37) The optimization unit 144 increments I. That is, the optimization unit 144 sets I=I+1. Then, the process proceeds to step S31. FIG. 22 is a flowchart showing an example of loop fusion candidate information generation.
[0119] The generation of loop fusion candidate information corresponds to step S13. (S40) The optimization unit 144 initializes the trigger loop number I. For example, the optimization unit 144 initializes I to 1.
[0120] (S41) The optimization unit 144 generates a template data structure of the loop fusion candidate information 133 for the trigger loop I, and stores it in the control information storage unit 130. (S42) The optimization unit 144 extracts a combination of loops that are candidates for loop fusion with respect to the corresponding trigger loop I based on the possible loop fusion list 131, and adds the combination to the loop item of the loop fusion candidate information 133.
[0121] (S43) The optimization unit 144 determines whether or not all trigger loops have been processed. If all trigger loops have been processed, the process proceeds to step S45. If all trigger loops have not been processed, the process proceeds to step S44.
[0122] (S44) The optimization unit 144 increments I. That is, the optimization unit 144 sets I=I+1. Then, the process proceeds to step S41. (S45) The optimization unit 144 initializes the trigger loop number I. For example, the optimization unit 144 initializes I to 1.
[0123] (S46) The optimization unit 144 extracts, for the trigger loop I, one combination of loops as a fusion candidate from the loop fusion candidate information 133. (S47) The optimization unit 144 obtains information about the loops belonging to the extracted combination from the loop information 132.
[0124] (S48) Based on the information acquired in step S47, the optimization unit 144 calculates item values including the number of variables, the number of registers, the number of memory instructions, and the number of operation instructions for each combination of loops that is a loop fusion candidate, and registers the calculated item values in the loop fusion candidate information 133. Details of the calculation of the item values for the loop fusion candidates will be described later.
[0125] (S49) The optimization unit 144 determines whether or not all trigger loops have been processed. If all trigger loops have been processed, the loop fusion candidate information generation ends. If all trigger loops have not been processed, the process proceeds to step S50.
[0126] (S50) The optimization unit 144 increments I. That is, the optimization unit 144 sets I=I+1. Then, the process proceeds to step S46. FIG. 23 is a flowchart showing an example of calculation of item values of loop fusion candidates.
[0127] Calculating the item values of the loop fusion candidates corresponds to step S48. (S60) The optimization unit 144 determines whether or not the loop shapes, i.e., the initial values, final values, and increment values of the control variables of the loops, of all the loops belonging to the loop combination in question are the same. If the loop shapes of all the loops in question are the same, the process proceeds to step S61. If the loop shapes of at least any of the loops are not the same, the process proceeds to step S62.
[0128] (S61) The optimization unit 144 sets the mask item for the corresponding loop combination to "false" in the loop fusion candidate information 133. Then, the process proceeds to step S63.
[0129] (S62) The optimization unit 144 sets the mask item for the corresponding combination of loops to "true" in the loop fusion candidate information 133. Then, the process proceeds to step S63.
[0130] (S63) The optimization unit 144 calculates the number of variables for the combination of loops in question, and sets the calculation result in the item for the number of variables in the loop fusion candidate information 133. The optimization unit 144 calculates the sum of the numbers of variables other than the loop control variables in the loops belonging to the combination in question, which are obtained from the loop information 132, as the number of variables corresponding to the combination in question.
[0131] (S64) The optimization unit 144 calculates the number of registers for the combination of loops in question, and sets the calculation result in the number of registers item in the loop fusion candidate information 133. The optimization unit 144 calculates the sum of the numbers of integer registers and the sum of the numbers of floating point registers in the loops belonging to the combination in question, which are obtained from the loop information 132, as the number of registers corresponding to the combination.
[0132] (S65) The optimization unit 144 determines whether or not there is a variable dependency in the combination of loops. If there is a variable dependency, the process proceeds to step S66. If there is no variable dependency, the process proceeds to step S67. An example of variable dependency is the data dependency described in FIGS. 10 and 11.
[0133] (S66) The optimization unit 144 sets the dependency item to "true" for the corresponding combination of loops in the loop fusion candidate information 133. Then, the process proceeds to step S68.
[0134] (S67) The optimization unit 144 sets the dependency item for the corresponding loop combination to “false” in the loop fusion candidate information 133. Then, the process proceeds to step S68.
[0135] (S68) The optimization unit 144 calculates the number of memory instructions for the combination of loops in question, and sets the calculation result in the item for the number of memory instructions in the loop fusion candidate information 133. The optimization unit 144 calculates the sum of the numbers of memory instructions in the loops belonging to the combination in question, obtained from the loop information 132, as the number of memory instructions corresponding to the combination.
[0136] (S69) The optimization unit 144 calculates the number of operation instructions for the combination of loops in question, and sets the calculation result in the item "number of operation instructions" in the loop fusion candidate information 133. The optimization unit 144 calculates the sum of the numbers of operation instructions in the loops belonging to the combination in question, obtained from the loop information 132, as the number of operation instructions corresponding to the combination. Then, calculation of the item values of the loop fusion candidates is completed.
[0137] FIG. 24 is a flowchart showing an example of fusion target determination. The fusion target determination corresponds to step S14. (S70) The optimization unit 144 initializes a record number J of the loop fusion candidate information 133. For example, the optimization unit 144 initializes J to 0. Here, the record number J identifies a combination of loops of one fusion candidate in the loop fusion candidate information 133.
[0138] (S71) The optimization unit 144 determines whether or not the dependency item value for the corresponding loop combination is "true" based on the loop fusion candidate information 133. If the dependency item value is "true", the process proceeds to step S78. If the dependency item value is "false", the process proceeds to step S72.
[0139] (S72) The optimization unit 144 determines whether or not there is a tentatively determined fusion candidate as a loop fusion target. If there is a tentatively determined fusion candidate, the process proceeds to step S74. If there is no tentatively determined fusion candidate, the process proceeds to step S73.
[0140] (S73) The optimization unit 144 provisionally determines, as a fusion target, the combination of loops that is a fusion candidate having record number J. Then, the process proceeds to step S78. (S74) The optimization unit 144 determines whether the number of variables corresponding to the loop combination of record number J is greater than the number of variables corresponding to the tentatively determined fusion candidate, based on the loop fusion candidate information 133. If the number of variables corresponding to the loop combination of record number J is greater than the number of variables corresponding to the tentatively determined fusion candidate, the process proceeds to step S75. If the number of variables corresponding to the loop combination of record number J is equal to or less than the number of variables corresponding to the tentatively determined fusion candidate, the process proceeds to step S78.
[0141] (S75) The optimization unit 144 determines, based on the loop fusion candidate information 133, whether the number of registers corresponding to the combination of loops with record number J is equal to or less than the number of available registers in the device that is to execute the executable file 113 including the object file 112. If the number of registers corresponding to the combination is equal to or less than the number of available registers, the process proceeds to step S76. If the number of registers corresponding to the combination is greater than the number of available registers, the process proceeds to step S78.
[0142] Here, the number of available registers in the device that is to execute the executable file 113 is set in advance in the control information storage unit 130. The available number corresponds to the number of physical registers that the device has, and is set for each of the integer registers and the floating-point registers. That is, the optimization unit 144 determines whether the number of integer registers and the number of floating-point registers are equal to or less than the available number, and if both the number of integer registers and the number of floating-point registers are equal to or less than the available number, the optimization unit 144 proceeds to step S76. On the other hand, if at least one of the number of integer registers and the number of floating-point registers is greater than the available number, the optimization unit 144 proceeds to step S78. The device that is to execute the executable file 113 may be the information processing device 100.
[0143] (S76) The optimization unit 144 determines whether the number obtained by subtracting a predetermined value from the number of memory instructions corresponding to the combination of loops with record number J is equal to or greater than the number of operation instructions corresponding to the combination, based on the loop fusion candidate information 133. If the number obtained by subtracting the predetermined value from the number of memory instructions is equal to or greater than the number of operation instructions corresponding to the combination, the process proceeds to step S77. If the number obtained by subtracting the predetermined value from the number of memory instructions is less than the number of operation instructions corresponding to the combination, the process proceeds to step S78.
[0144] Here, the predetermined value used in step S76 is determined in advance according to, for example, the number of memory instructions that can be simultaneously executed in a plurality of arithmetic units included in the device that is to execute the executable file 113. For example, if the number of memory instructions that can be simultaneously executed in a plurality of arithmetic units included in the device is "2", the predetermined value used in step S76 may be "2". Alternatively, if the number of memory instructions that can be simultaneously executed is "1", the predetermined value used in step S76 may be "1". Since a memory instruction is executed before an arithmetic instruction can be executed, the optimization unit 144 subtracts the number of memory instructions that can be simultaneously executed first from the number of memory instructions in the loop fusion candidate information 133 and compares it with the number of arithmetic instructions.
[0145] (S77) The optimization unit 144 replaces the tentatively determined fusion target with the fusion candidate of record number J. That is, the optimization unit 144 tentatively determines the combination of loops of the fusion candidate of record number J as the fusion target, and cancels the tentative determination of the fusion candidate tentatively determined before step S77.
[0146] (S78) The optimization unit 144 determines whether or not all records in the loop fusion candidate information 133 have been processed. When the record number J reaches the last record number, all records have been processed. If all records have been processed, the optimization unit 144 determines the combination of loops tentatively determined at the stage of step S78 as the fusion target, and ends the fusion target determination. If all records have not been processed, the process proceeds to step S79.
[0147] (S79) The optimization unit 144 increments J. That is, the optimization unit 144 sets J=J+1. Then, the process proceeds to step S71. FIG. 25 is a diagram illustrating an example of a result of determining loop fusion targets.
[0148] 24, the optimization unit 144 determines, for example, a combination of loops "1, 2, 4, 5" as a loop fusion target for the loop fusion candidate information 133 shown in FIG. 17 and FIG. 18. Note that the combination of loops "1, 2, 4, 5" is masked as "true" in the loop fusion candidate information 133. Therefore, the optimization unit 144 performs loop fusion on the combination of loops "1, 2, 4, 5" by adding a mask process to the loop initialization process.
[0149] In this way, the optimization unit 144 preferentially determines, as targets for loop fusion, combinations of loops in which the number of registers is equal to or less than the number available, the number of memory instructions and the number of operation instructions are well balanced, and the combination has a larger number of variables.
[0150] This makes it possible to prevent data saving / restoring (spill / fill) to memory due to a lack of registers, i.e., to prevent spill / fill and to use the arithmetic units efficiently. In each cycle during execution of the loop in the executable file 113, it becomes possible to efficiently assign multiple instructions to multiple arithmetic units, improving processing performance. For example, the processing speed of the fused loop can be improved compared to when loop fusion is not performed. Also, it is possible to use the registers efficiently.
[0151] FIG. 26 illustrates another example of code that is the target of loop fusion determination. Source code 111b is an example of code included in source program 111. For example, source code 111b includes three loops: loops 1j, 2j, and 3j. The optimization unit 144 extracts combinations of loops that are candidates for merging from the intermediate language of source code 111b generated by the intermediate language generation unit 143. Loops 1j and 2j have the same loop shape. However, in loops 1j and 2j, B1 determined in loop 1j is used in loop 2j, and there is a strong dependency between the variables. Loops 1j and 3j have different loop shapes. Loops 2j and 3j have different loop shapes.
[0152] For example, the optimization unit 144 merges the combination of loops 1j and 3j, which have different loop shapes, in the source code 111b. FIG. 27 is a diagram illustrating an example of code after loop fusion.
[0153] The source code 111c shows, on a source code basis, a code after fusion when the loops 1j and 3j in the source code 111b are fused. The optimization unit 144 generates an intermediate language corresponding to the source code 111c by applying loop fusion to the intermediate language of the source code 111b. The source code 111c shows an example in which a process for determining the end value of the fused loop and a process for generating a mask used in the fused loop are added.
[0154] Next, an example of instruction scheduling for a fused loop when the loop fusion shown in FIG. 27 is performed will be described. FIG. 28 is a diagram illustrating an example of instruction scheduling.
[0155] Table 201 shows an example of allocation of instructions to each arithmetic unit for each cycle for the fused loop illustrated in FIG. 27. It is assumed that the number of arithmetic units is four, and the number of memory instructions that can be executed simultaneously is two. Each column listed under the arithmetic unit item corresponds to one arithmetic unit. As an example, it is assumed that the latency of a LOAD instruction that loads from a register to memory is 8τ, and the latency of a SUB instruction that performs subtraction is 4τ. Here, τ is the time per cycle. Furthermore, it is assumed that memory address calculation is omitted.
[0156] In Table 201, numbers enclosed in parentheses such as "(1)" represent the processing to be performed for an instruction assigned to one arithmetic unit in the corresponding cycle. For example, the numbers enclosed in parentheses represent the following processing:
[0157] (1) The first calculator loads V(k,i,j). (2) The second calculator loads V(k-1,i,j). (3) The third calculator subtracts the result of (2) from the result of (1).
[0158] (4) The first calculator loads V(k+1,i,j). (5) The second calculator loads V(k-2,i,j). (6) The third calculator subtracts the result of (5) from the result of (4).
[0159] (7) The third calculator subtracts the result of (6) from the result of (3). (8) The first calculator stores the result of (7) in A1. (9) The first calculator loads A1(k,i,j).
[0160] (17) The first calculator loads D2(k,i,j). (18) The second calculator loads D2(k-1,i,j). (19) The fourth calculator subtracts the result of (18) from the result of (17).
[0161] (20) The first calculator loads D2(k+1,i,j). (21) The second calculator loads D2(k-2,i,j). (22) The fourth calculator subtracts the result of (21) from the result of (20).
[0162] (23) The fourth calculator subtracts the result of (22) from the result of (19). (24) The fourth calculator stores the result of (23) in D1. The schedule for executing each process in table 201 is as follows: (1) and (2) are executed in the first cycle. (4) and (5) are executed in the second cycle. (17) and (18) are executed in the third cycle. (20) and (21) are executed in the fourth cycle. (3) is executed in the ninth cycle. (6) and (19) are executed in the tenth cycle. (22) is executed in the eleventh cycle. (7) is executed in the fourteenth cycle. (23) is executed in the fifteenth cycle. (8) is executed in the seventeenth cycle. (9) and (24) are executed in the eighteenth cycle. In the figure, the processes related to B1 from the nineteenth cycle onwards are omitted.
[0163] In this way, loop fusion makes it possible to perform operations related to A1 and D1 in 18 cycles, and it can be seen that the arithmetic units can be used more effectively than in the comparative examples in FIGS. 29 and 30 below.
[0164] Next, a comparative example of instruction scheduling when the loops 1j and 2j in the source code 111b are fused will be described. FIG. 29 is a diagram illustrating a comparative example of instruction scheduling.
[0165] Source code 91 shows an example of code when loops 1j and 2j are fused. Table 202 shows an example of allocation of instructions to each arithmetic unit for each cycle for the fused loop when loops 1j and 2j are fused. As in FIG. 28, the number of arithmetic units is four, and the number of memory instructions that can be executed simultaneously is two. Each column listed under the arithmetic unit item corresponds to one arithmetic unit. As an example, the latency of the LOAD instruction is 8τ, and the latency of the SUB instruction is 4τ. In Table 202, the values in parentheses indicate the following processing.
[0166] (1) The first calculator loads V(k,i,j). (2) The second calculator loads V(k-1,i,j). (3) The third calculator subtracts the result of (2) from the result of (1).
[0167] (4) The first calculator loads V(k+1,i,j). (5) The second calculator loads V(k-2,i,j). (6) The third calculator subtracts the result of (5) from the result of (4).
[0168] (7) The third calculator subtracts the result of (6) from the result of (3). (8) The first calculator stores the result of (7) in A1. (9) The first calculator loads A1(k,i,j).
[0169] In the figure, the processing of cycles 19 to 35 for B1 is omitted. FIG. 30 is a diagram showing a comparative example of instruction scheduling (continuation). (17) The first calculator loads B1(k,i,j).
[0170] (18) The second calculator loads B1(k-1,i,j). (19) The third calculator subtracts the result of (18) from the result of (17). (20) The first calculator loads B1(k+1,i,j).
[0171] (21) The second calculator loads B1(k-2,i,j). (22) The third calculator subtracts the result of (21) from the result of (20). (23) The third calculator subtracts the result of (22) from the result of (19).
[0172] (24) The first calculator stores the result of (23) in C1. The schedule for executing each process in table 202 is as follows: (1) and (2) are executed in the first cycle. (4) and (5) are executed in the second cycle. (3) is executed in the ninth cycle. (6) is executed in the tenth cycle. (7) is executed in the fourteenth cycle. (8) is executed in the seventeenth cycle. (9) is executed in the eighteenth cycle. Processes related to B1 are executed in the nineteenth to thirty-fifth cycles. (17) and (18) are executed in the thirty-sixth cycle. (20) and (21) are executed in the thirty-seventh cycle. (19) is executed in the forty-fourth cycle. (22) is executed in the forty-fifth cycle. (23) is executed in the forty-ninth cycle. (24) is executed in the fifty-second cycle. The number of cycles required for the process of B1 is the same in the case of FIG. 28 as in the cases of FIGS. 29 and 30.
[0173] In this way, when loops 1j and 2j are fused, it takes 52 cycles to finish processing C1. Because the calculation result of loop 1j is used in loop 2j, the calculation of loop 2j has to wait until the calculation of loop 1j is finished, resulting in a loop fusion that does not increase the parallelism of instruction execution. Therefore, even if loops 1j and 2j are fused, the arithmetic units will not be fully used because there will be a relatively large amount of free space in each cycle, and efficient loop fusion will not be possible. Furthermore, loop fusion can result in a shortage of registers, which increases memory accesses for saving and restoring, resulting in a deterioration in performance.
[0174] In contrast, as illustrated in FIG. 28, the information processing device 100 can improve the efficiency of use of the arithmetic units and the processing performance during execution of the loop processing. For example, it is possible to increase the parallelism of instruction execution for the loops 1j and 3j so that operations exceeding the actual number of arithmetic units are not performed simultaneously, and the number of cycles required for executing the loop processing can be efficiently reduced. In addition, it is possible to suppress memory accesses for spill / fill due to a shortage of registers. As a result, the processing speed can be improved.
[0175] Furthermore, according to the information processing device 100, combinations of loops with different loop shapes, i.e., loops with different initial values, final values, and increment values of loop control variables, can also be fused. When a combination of loops with different loop shapes is fused, the operations in the fused loops tend to become bloated, leading to inefficient loop fusion, but the function of the information processing device 100 suppresses inefficient loop fusion. This increases the degree of freedom in the combination of loops to be fused, and increases the possibility of more efficient loop fusion.
[0176] Furthermore, the compiler function of the information processing device 100 is particularly effective for an architecture in which the number of registers is relatively small and the number of register cycles is relatively long. In the second embodiment, various data for determining loop fusion is extracted from an intermediate language (intermediate code), but the present invention is not limited to this. For example, the compiler 140 can extract the various data from the source program 111. The compiler 140 may specify a combination of loops as candidates for fusion using the source program 111, and may extract data such as the number of variables, the number of registers, the number of memory instructions, and the number of operation instructions for each loop using the intermediate language.
[0177] The information processing device 100 described in the second embodiment executes, for example, the following process. The optimization unit 144 acquires loop information 132 including the number of variables, the number of registers, the number of memory instructions, and the number of operation instructions used in each of a plurality of loops included in the intermediate code. Based on the loop information 132, the optimization unit 144 calculates the number of variables, the number of registers, the number of memory instructions, and the number of operation instructions corresponding to a combination of loops that is a candidate for loop fusion, for each of a plurality of combinations of loops. Based on a comparison between the number of variables, the number of registers, and the number of memory instructions calculated for each of the plurality of combinations and the number of operation instructions, the optimization unit 144 determines a combination to which loop fusion is to be applied from among the plurality of combinations. The optimization unit 144 executes loop fusion for the determined combination.
[0178] This makes it possible to improve the processing performance of the executable file 113 that includes the object code generated using the intermediate code after loop fusion. Based on the intermediate code, the optimization unit 144 acquires, as candidates for loop fusion, combinations including two or more loops whose control variables have different possible values.
[0179] This increases the degree of freedom for loop fusion and increases the possibility of more efficient loop fusion. The optimization unit 144 prioritizes combinations with a larger number of calculated variables among multiple combinations of loops that are candidates for fusion, and determines these combinations as combinations to which loop fusion is to be applied.
[0180] This increases the possibility of improving the parallelism of operations and efficiently utilizing the computing units. The optimization unit 144 determines, from among multiple combinations of loops that are candidates for fusion, a combination in which the calculated number of registers is equal to or less than the number of registers available in the device on which the object code generated by compilation is to be executed, as a combination to which loop fusion is to be applied.
[0181] This reduces the chance of spills and fills occurring and increases the chance of efficient register utilization. The optimization unit 144 determines, from among a plurality of combinations of loops that are candidates for fusion, a combination for which the number obtained by subtracting a predetermined value from the calculated number of memory instructions is equal to or greater than the number of operation instructions, as a combination to which loop fusion is to be applied.
[0182] In this way, by applying loop fusion to a combination of loops in which the number of calculation instructions is not excessive compared to the number of memory instructions, multiple instructions can be appropriately distributed and assigned to multiple calculation units, thereby increasing the possibility of efficient use of registers and calculation units.
[0183] The optimization unit 144 may determine a predetermined value to be subtracted from the number of memory instructions depending on the number of memory instructions that can be simultaneously executed by a device on which the object code generated by compilation is to be executed. For example, the optimization unit 144 may set the number of memory instructions that can be simultaneously executed by the device as the predetermined value.
[0184] This allows the number of operation instructions to be compared appropriately with the number of memory instructions, and further increases the possibility of efficient use of registers and operation units through loop fusion. Moreover, the information processing in the first embodiment can be realized by causing the processing unit 12 to execute a program. Moreover, the information processing in the second embodiment can be realized by causing the CPU 101 to execute a program. The program can be recorded in a computer-readable recording medium 53.
[0185] For example, the program can be distributed by distributing recording medium 53 on which the program is recorded. The program may also be stored in another computer and distributed via a network. The computer may store (install) the program recorded in recording medium 53 or a program received from another computer in a storage device such as RAM 102 or HDD 103, and read and execute the program from the storage device. [Explanation of symbols]
[0186] 10. Information processing device 11 Storage section 12 Processing section 20 Source Code 20a, 20b Intermediate code 21 Loop Information 22 Loop fusion candidate information 30 Object Code
Claims
1. An information processing device that performs compilation, A storage unit that stores a code to be processed; acquiring loop information for each of a plurality of loops included in the code, the loop information including the number of variables used in the loop, the number of registers, the number of memory instructions for inputting and outputting the values of the variables between the registers and a main memory device, and the number of operation instructions for the values of the variables stored in the registers; calculating the number of variables, the number of registers, the number of memory instructions, and the number of operation instructions corresponding to each of a plurality of combinations of loops that are candidates for loop fusion based on the acquired loop information; determining a combination to which the loop fusion is to be applied from among the plurality of combinations based on a comparison between the number of variables, the number of registers, and the number of memory instructions and the number of operation instructions calculated for each of the plurality of combinations; a processing unit that executes the loop fusion for the determined combination; An information processing device having the above configuration.
2. the processing unit acquires, based on the code, the combinations including two or more loops whose control variables have different possible values as candidates for the loop fusion; 2. The information processing device according to claim 1.
3. the processing unit determines, from among the plurality of combinations, a combination having a larger number of calculated variables as a combination to which the loop fusion is to be applied, with priority given to the combination; 3. The information processing device according to claim 1 or 2.
4. the processing unit determines, from among the plurality of combinations, a combination in which the calculated number of registers is equal to or less than the number of registers available in a device in which the object code generated by the compilation is to be executed, as a combination to which the loop fusion is to be applied; The information processing device according to claim 1 .
5. the processing unit determines, from among the plurality of combinations, a combination for which a number obtained by subtracting a predetermined value from the calculated number of memory instructions is equal to or greater than the number of operation instructions, as a combination to which the loop fusion is to be applied; The information processing device according to claim 1 .
6. the processing unit determines the predetermined value in accordance with the number of memory instructions that can be simultaneously executed by a device on which the object code generated by the compilation is to be executed.
6. The information processing device according to claim 5.
7. On the computer, obtain loop information for each of a plurality of loops included in the code to be processed, the loop information including the number of variables used in the loop, the number of registers, the number of memory instructions for inputting and outputting the values of the variables between the registers and a main memory device, and the number of operation instructions for the values of the variables stored in the registers; calculating the number of variables, the number of registers, the number of memory instructions, and the number of operation instructions corresponding to each of a plurality of combinations of loops that are candidates for loop fusion based on the acquired loop information; determining a combination to which the loop fusion is to be applied from among the plurality of combinations based on a comparison between the number of variables, the number of registers, and the number of memory instructions and the number of operation instructions calculated for each of the plurality of combinations; performing the loop fusion on the determined combination; A compiled program that performs a process.
8. The computer obtain loop information for each of a plurality of loops included in the code to be processed, the loop information including the number of variables used in the loop, the number of registers, the number of memory instructions for inputting and outputting the values of the variables between the registers and a main memory device, and the number of operation instructions for the values of the variables stored in the registers; calculating the number of variables, the number of registers, the number of memory instructions, and the number of operation instructions corresponding to each of a plurality of combinations of loops that are candidates for loop fusion based on the acquired loop information; determining a combination to which the loop fusion is to be applied from among the plurality of combinations based on a comparison between the number of variables, the number of registers, and the number of memory instructions and the number of operation instructions calculated for each of the plurality of combinations; performing the loop fusion on the determined combination; How to compile.
Citation Information
Patent Citations
Loop optimizing method
JP1995121381A
Compiler device and loop optimizing control method
JP1996101776A
Loop merging method and program code generation method
JP2005222262A
Compiler and compilation method
JP2014228891A
Compilation device, compilation program, and compilation method
JP2015194881A
