Compilation system and compilation execution method
The compilation system optimizes program development efficiency by generating and comparing executable files with and without optimization, reducing recompilation frequency and ensuring valid operations.
Patent Information
- Application Number
- JP2023055069
- Authority / Receiving Office
- JP · JP
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-03-30
- Publication Date
- 2024-10-11
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Conventional program optimization methods require repeated recompilation for each change in optimization type, leading to decreased development efficiency due to lengthy compilation times.
A compilation system and method that generates multiple executable files with and without optimization, compares return values using log files, and selectively enables optimization based on the comparison results to reduce unnecessary recompilation.
Improves development efficiency by minimizing the need for repeated program checks during recompilation, ensuring valid operations without optimization changes.
Smart Images

Figure 2024142758000001_ABST
Abstract
Description
[Technical field]
[0001] The present invention relates to a compilation system and a compilation execution method for optimizing a source program (source code). [Background technology]
[0002] It is already known to use a compiler that optimizes a source program when compiling the source program.
[0003] Generally, in order to improve the performance of a source program, the creator of the program uses a compiler to perform program optimization when compiling the source program. Program optimization, for example, aims to reduce the code size and shorten the execution time by removing unnecessary parts in the program.
[0004] For example, Patent Document 1 discloses a compiler that converts source code describing the functions of an integrated circuit in a language that allows parallel processing into hardware-dependent code. The compiler includes an optimizer that optimizes the performance or cost of the integrated circuit by rescheduling communications within the integrated circuit without changing the chronological order of the communications, and a generator that generates output code representing the circuit configuration of the integrated circuit based on the output of the optimizer. [Prior art documents] [Patent documents]
[0005] [Patent Document 1] JP 2011-155351 A Summary of the Invention [Problem to be solved by the invention]
[0006] However, there is a concern that program optimization may unintentionally change the behavior of a program. To address this concern, program creators have traditionally adopted a method of repeating the following operations (1) to (4) to obtain the desired performance. (1) Selecting optimization options and inserting pragmas to control optimization (2) Compiling the program (3) Program execution (4) Performance evaluation However, with this conventional method, it is necessary to re-compile every time the optimization type is switched, and there was an issue that repeated compilation leads to a decrease in development efficiency when the compilation time is very long. Therefore, program creators are desired to select optimizations that can obtain high performance by reducing the number of compilations as much as possible when optimizing a program.
[0007] SUMMARY OF THE PRESENT EMBODIMENT An object of the present invention is to provide a compilation system and a compilation execution method for the compilation system that can reduce the number of compilations and improve development efficiency. [Means for solving the problem]
[0008] The compilation system of the present invention includes a source code generation device that generates a first source code for passing arguments for each function, receiving a return value for each function, and storing the return value for each function in a global variable for monitoring; a first compiler that performs compilation in mutually different modes on the first source code to generate first and second executable files; an execution device that executes a program recorded in the first executable file, generates a first log file indicating values of the global variables for each function, and executes a program recorded in the second executable file, and generates a second log file indicating the values of the global variables for each function; and a result comparison device that compares the values of the global variables for each function indicated by the first and second log files, and generates a result comparison file indicating the comparison result.
[0009] A compilation execution method of the compilation system of the present invention includes the steps of: a source code generation device generating a first source code for passing arguments for each function, receiving a return value for each function, and storing the return value for each function in a global variable for monitoring; a compiler generating first and second executable files by compiling the first source code in mutually different modes; an execution device executing a program recorded in the first executable file and generating a first log file indicating values of the global variables for each function, and executing a program recorded in the second executable file and generating a second log file indicating values of the global variables for each function; and a result comparison device comparing values of the global variables indicated by the first and second log files and generating a result comparison file indicating a comparison result. Effect of the Invention
[0010] According to the compilation system and compilation execution method of the present invention, different modes of compilation are applied to source code and the return values are compared for each function. From the resulting comparison, it is possible to determine which mode of compilation is valid or invalid for each function, thereby eliminating the need for the program creator to recompile and check the operation of the program, which is expected to improve development efficiency. [Brief description of the drawings]
[0011] [Figure 1] 1 is a conceptual diagram of a compilation system according to a first embodiment of the present invention. [Diagram 2] FIG. 2 is a conceptual diagram illustrating a continuation of the conceptual diagram of FIG. 1. [Diagram 3] FIG. 11 is a conceptual diagram of a compilation system according to a second embodiment of the present invention. [Figure 4] FIG. 3 is a conceptual diagram illustrating a continuation of the conceptual diagram of FIG. 2. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0012] Hereinafter, embodiments of the present invention will be described in detail with reference to the drawings. EXAMPLES
[0013] 1 and 2 show conceptual diagrams of a compilation system according to a first embodiment of the present invention. In the compilation system according to the present invention, a case will be described in which three source files 1-1, 1-2, and 1-3 written in the C language are compiled as an example.
[0014] In Fig. 1, source file 1-1 is a second source file showing source code including a main function. Source files 1-2 and 1-3 are source files showing functions that are called when compiling source file 1-1, receive arguments as input values, process the functions, and generate return values. Source files 1-2 and 1-3 process different functions.
[0015] The source file 1-1 is supplied to a source code conversion device 11. The source code conversion device 11 is a source code generation device that generates source code (first source code) by adding code for storing a return value of a function in a global variable for monitoring to the source code indicated by the source file 1-1. The source code to which the code for storing the return value in a global variable for monitoring has been added is output as a source file 1-4.
[0016] The source file 1-4 is supplied to the compiler 12 together with the source files 1-2 and 1-3. The compiler 12 compiles the source code of the source file 1-4 using the functions of each of the source files 1-2 and 1-3 to convert it into machine code. The compiler 12 executes compilations in different modes. That is, it executes a process of converting the program into machine code without optimizing it, and a process of converting the program into machine code after optimizing it. The compiler 12 generates an executable file 1-5 (first executable file) by processing without optimization, and generates an executable file 1-6 (second executable file) by processing with optimization. Thus, the executable file 1-5 records machine code without optimization, and the executable file 1-6 records machine code with optimization.
[0017] The executable files 1-5 and 1-6 are supplied to an execution unit 13. The execution unit 13 reads and executes the machine codes of the executable files 1-5 and 1-6. The execution unit 13 also outputs, as the execution results, log files 1-7 and 1-8 that indicate the values of global variables for monitoring embedded in the executable files 1-5 and 1-6, respectively.
[0018] The log files 1-7 and 1-8 are supplied to a result comparison device 14. The executable files 1-5 and 1-6 are also supplied to the result comparison device 14. The result comparison device 14 compares the executable files 1-5 and 1-6 and the log files 1-7 and 1-8 with and without program optimization, and outputs a comparison result file 1-9. The comparison result file 1-9 is a file that indicates OK (valid) if the same return value is obtained without and with optimization for each called function, and indicates NG (invalid) if the same return value is not obtained.
[0019] 2, source files 1-1, 1-2, 1-3 and comparison result file 1-9 are supplied to a compiler 21. The compiler 21 converts the source files 1-1, 1-2, 1-3 into an executable file 2-1, and in the conversion, optimizes only those functions for which the comparison result file 1-9 indicates OK. Optimization is not performed on functions that indicate NG. The compiler 21 outputs the executable file 2-1 as a compilation result.
[0020] Each of the above-mentioned source code conversion device 11, compiler 12, execution device 13, result comparison device 14, and compiler 21 can be configured by a computer.
[0021] Next, an example of the operation of the compilation system of the first embodiment will be described, with func1() and func2() being the functions called when compiling a source file 1-1 having a main function.
[0022] In source file 1-1, void main(){ int func1_ret = func1(); int func2_ret = func2(); } Assume that the following source code (source program) is recorded.
[0023] In source file 1-2, the called function is: int func1() Similarly, in source file 1-3, the called function is defined as int func2() Note that the int placed before func1() and func2() indicates that the return type is an integer.
[0024] The source file 1-1 becomes the source file 1-4 by adding a global variable for monitoring by the source code conversion device 11. When the source code conversion device 11 finds a call of the functions func1() and func2() with return values in the source file 1-1, it automatically generates global variables for monitoring func1_mon and func2_mon, and code func1_mon = func1_ret and func2_mon = func2_ret that stores the functions func1() and func2() in the global variables for monitoring.
[0025] In source file 1-4, int func1_mon; int func2_mon; void main(){ int func1_ret = func1(); func1_mon = func1_ret; int func2_ret = func2(); func2_mon = func2_ret; } This specifies that the return values of functions func1() and func2() in source file 1-4 are to be stored in global variables func1_mon and func2_mon.
[0026] In the compiler 12, the source file 1-4 is compiled both with and without optimization using the source files 1-2 and 1-3. The compiled executable file 1-5 is an executable file without optimization, and the executable file 1-6 is an executable file with optimization.
[0027] The executable files 1-5 and 1-6 are executed by the execution device 13, and the log files 1-7 and 1-8 are obtained as the execution results. The return values of the functions func1() and func2() without optimization are recorded as the func1_mon value and the func2_mon value in the log file 1-7, and the return values of the functions func1() and func2() with optimization are recorded as the func1_mon value and the func2_mon value in the log file 1-8. 、 It is written as the func2_mon value.
[0028] When such log files 1-7, 1-8 are supplied to a result comparison device 14 together with the executable files 1-5, 1-6, the result comparison device 14 compares the executable files 1-5, 1-6 with and without optimization and the log files 1-7, 1-8, respectively, and outputs a comparison result file 1-9.
[0029] Here, for example, log files 1-7 are without optimization: func1_mon = 1 func2_mon = 2 and in log files 1-8, with optimization func1_mon = 1 func2_mon = 0 are obtained. The result comparison device 14 compares the return values of the functions func1() and func2(). Since func1_mon = 1 without optimization is equivalent to func1_mon = 1 with optimization, the function func1() is judged as OK. On the other hand, func2_mon = 2 without optimization is different from func2_mon = 0 with optimization, so the function func2() is judged as NG. Therefore, for example, the comparison results are shown in the comparison result file 1-9 as follows: func1() (1 vs 1): OK func2() (2 vs 0): NG The source files 1-1, 1-2, 1-3 and the comparison result file 1-9 are read into the compiler 21. The compiler 21 compiles the functions in the source file 1-1 that are OK in the comparison result file 1-9 with optimization enabled, and compiles the functions that are NG in the comparison result file 1-9 with optimization disabled, and generates an executable file 2-1 as a compilation result. In the above example, the function func1() is compiled with optimization, while the function func2() is compiled without optimization.
[0030] As described above, according to the first embodiment, optimization during compilation is disabled for functions whose operation results would change due to optimization, which saves the program creator the trouble of having to recompile and check the operation of the program, thereby improving development efficiency. EXAMPLES
[0031] 3 and 4 are conceptual diagrams showing a compilation system according to a second embodiment of the present invention. In the compilation system according to the present invention, the case of compiling two source files 3-1 and 3-2 written in the C language will be described as an example.
[0032] In FIG. 3, each of source files 3-1 and 3-2 is a source file in which source code (third source code) for processing a function called during compilation is recorded.
[0033] The source files 3-1 and 3-2 are supplied to an automatic use case generation device 31. The automatic use case generation device 31 analyzes the input source files 3-1 and 3-2, automatically determines a min value (minimum value) and a max value (maximum value) as argument input values of the functions indicated by the source files 3-1 and 3-2, and automatically generates a source file 3-3 indicating source code (first source code) including a main function that calls the function using the min value and max value as input values. The source code of the source file 3-3 includes code that stores the return values of the function for the min value and max value in global variables for monitoring.
[0034] The source file 3-3 is supplied to the compiler 32 together with the source files 3-1 and 3-2. The compiler 32, like the compiler 12 in the first embodiment, generates an executable file without program optimization and an executable file with optimization during compilation. Thus, the compiler 32 converts the source files 3-3, 3-1, and 3-2 into executable files 3-4 and 3-5. Here, the executable file 3-4 is a first executable file without program optimization, and the executable file 3-5 is a second executable file with program optimization.
[0035] The executable files 3-4 and 3-5 are supplied to an execution unit 33. The execution unit 33 reads and executes the executable files 3-4 and 3-5. In addition, the execution unit 33 outputs, as the execution result, log files 3-6 and 3-7, respectively, which indicate the values of global variables for monitoring embedded in the executable files 3-4 and 3-5.
[0036] The log files 3-6 and 3-7 are supplied to a result comparing device 34. The executable files 3-4 and 3-5 are also supplied to the result comparing device 34. The result comparing device 34, like the result comparing device 14 in the first embodiment, compares the executable files 3-4 and 3-5 and the log files 3-6 and 3-7 with and without program optimization, respectively, and outputs a comparison result file 3-8. Like the comparison result file 1-9 in the first embodiment, the comparison result file 3-8 is a file that indicates OK if the same return value is obtained without and with optimization for each called function, and indicates NG if the same return value is not obtained.
[0037] In Fig. 4, source file 4-1 is a source file indicating the main function, and source code that calls the functions indicated in source files 3-1 and 3-2 during compilation is recorded in source file 4-1. When compiling the source code of source file 4-1, source file 4-1, source files 3-1 and 3-2, and comparison result file 3-8 are supplied to compiler 41. Compiler 41 converts source files 4-1, 3-1 and 3-2 into executable file 4-1, and in the conversion, optimization is performed only on functions indicated as OK by comparison result file 3-8. Optimization is not performed on functions indicated as NG. Compiler 41 outputs executable file 4-2 as the compilation result.
[0038] Each of the above-mentioned automatic use case generation device 31, compiler 32, execution device 33, result comparison device 24, and compiler 41 can be configured by a computer.
[0039] Next, an example of the operation of the compilation system of the second embodiment will be described assuming that a function is defined as int func1(int in1) in source file 3-1 and as int func2(long in2) in source file 3-2.
[0040] Here, the parentheses in int func1(int in1) in source file 3-1 represent the int (integer) type argument in1, and the parentheses in int func2(long in2) in source file 3-2 represent the long (long integer) type argument in2.
[0041] The source files 3-1 and 3-2 are supplied to an automatic use case generation device 31, which automatically creates a source file 3-3 indicating a main function that calls the functions described in the source files 3-1 and 3-2. As shown in Table 1, for the input values of the call, the min value is in1_min and the max value is in1_max for function func1 (int in1), and the min value is in2_min and the max value is in2_max for function func2 (long in2).
[0042] [Table 1]
[0043] These min and max values are, for example, the minimum and maximum values that can be substituted as argument values for the functions func1 (int in1) and func2 (long in2), and are assumed to be determined in advance.
[0044] Therefore, in source file 3-3, int func1_mon_min; int func1_mon_max; int func2_mon_min; int func2_mon_max; void main(){ func1_mon_min = func1(in1_min); func1_mon_max = func1(in1_max); func2_mon_min = func2(in2_min); func2_mon_max = func2(in2_max); } This source program file 3-3 specifies that the return values of functions func1 (int in1) and func2 (long in2) are to be stored in global variables func1_mon_min, func1_mon_max, func2_mon_min, and func2_mon_max.
[0045] In the compiler 32, the source file 3-3 is compiled both with and without optimization using the source files 3-1 and 3-2. The compiled executable file 3-4 is an executable file without optimization, and the executable file 3-5 is an executable file with optimization.
[0046] The executable files 3-4 and 3-5 are each executed by the execution device 33, and log files 3-6 and 3-7 are obtained as the execution results. In the log file 3-6, the return values in the case without optimization are recorded as the func1_mon_min value, func1_mon_max value, func2_mon_min value, and func2_mon_max value, and in the log file 3-7, the return values in the case with optimization are similarly recorded as the func1_mon_min value, func1_mon_max value, func2_mon_min value, and func2_mon_max value.
[0047] When such log files 3-6, 3-7 are supplied to a result comparison device 34 together with the executable files 3-4, 3-5, the result comparison device 34 compares the executable files 3-4, 3-5 with and without optimization and the log files 3-6, 3-7, respectively, and outputs a comparison result file 3-8.
[0048] Here, for example, in log files 3-6, without optimization: func1_mon_min = 1 func1_mon_max = 20 func2_mon_min = 0 func2_mon_max = 40 In log files 3-7, the following is obtained with optimization: func1_mon_min = 1 func1_mon_max = 20 func2_mon_min = 1 func2_mon_max = 30 Assume that the following has been obtained. The result comparison device 34 compares the return values of the functions func1 (int in1) and func2 (long in2). For the part func1_mon_min = 1, func1_mon_max = 20, the case without optimization 1 and the case with optimization are equal to each other, so the function func1 (int in1) is judged as OK. On the other hand, for func2_mon_min and func2_mon_max, the cases without optimization and with optimization are different from each other, so the function func2 (long in2) is judged as NG. Therefore, for example, the comparison result is shown in the comparison result file 3-8 as follows: func1:min (1 vs 1): OK func1:max (20vs20): OK func2:min (0 vs 1): NG func2:max (40vs30): NG Once the comparison result file 3-8 has been obtained in this manner, the source code of the source file 4-1 is then compiled.
[0049] For example, in source file 4-1, void main(){ int func1_ret = func1(in1_user); int func2_ret = func2(in2_user); } The source code (source program) is recorded.
[0050] The source files 4-1, 3-1, 3-2 and the comparison result file 3-9 are read into the compiler 41. The compiler 41 compiles the functions in the source file 4-1 that are OK and are shown in the comparison result file 1-9 with optimization enabled, and compiles the functions that are NG and are shown in the comparison result file 1-9 with optimization disabled, and generates an executable file 4-2 as a compilation result. In the above example, the function func1 (int in1) is compiled with optimization, while the function func2 (long in2) is compiled without optimization.
[0051] In this way, according to the second embodiment, argument values for each function are automatically generated, and it is possible to determine for each function whether or not optimization will change the operation results. For functions where the operation results will change, optimization during compilation is disabled, so that the program creator is saved the trouble of having to repeatedly recompile the program to check its operation, which is expected to improve development efficiency.
[0052] In the above-mentioned first and second embodiments, the cases where the optimization is not performed and the case where the optimization is performed are described as examples of compilation in different modes. However, the type of optimization may be changed.
[0053] Furthermore, in the above-mentioned first and second embodiments, a one-to-one comparison is made between no optimization and optimization, but it is also possible to make a one-to-multiple comparison at the same time, such as a comparison of no optimization with multiple types of optimization, such as code size optimization and speed optimization.
[0054] In the above-mentioned first and second embodiments, the return values of the log files are compared by the result comparison device, but the executable files may be treated as the objects of comparison. For example, the execution speed or size of the first and second executable files may be compared.
[0055] In the above-mentioned first and second embodiments, a global variable for monitoring is added to the source code, and the value of the global variable for monitoring after the program is executed is used as the subject of comparison, but if the expected behavior for the input value of the function is known, it is also possible to use the expected behavior as the subject of comparison without adding a global variable for monitoring. For example, if there is an operation in the function that stores a value in a global variable, the value of the global variable may be used as the subject of comparison.
[0056] In the first embodiment, the source code conversion device 11 performs processing before the compiler 12 , but the function of the source code conversion device 11 may be incorporated into the compiler 12 .
[0057] Similarly, in the second embodiment, the automatic use case generation device 31 performs processing before the compiler 32 , but the functions of the automatic use case generation device 31 may be incorporated into the compiler 32 . [Explanation of symbols]
[0058] 11 Source code conversion device 12, 32, 21, 41 Compiler 13, 33 Execution device 14, 34 Results comparison device 31 Automatic Use Case Generation Device 1-1~1-4, 3-1~3-3, 4-1 source files 1-5, 1-6, 2-1, 3-4, 3-5, 4-2 Executable files 1-7, 1-8, 3-6, 3-7 Log files 1-9, 3-8 Comparison result file
Claims
1. a source code generating device that generates a first source code for passing an argument to each function, receiving a return value from each function, and storing the return value from each function in a global variable for monitoring; a first compiler that performs compilation in different ways on the first source code to generate first and second executable files; an execution device that executes a program recorded in the first executable file, generates a first log file indicating the values of the global variables for each of the functions, and executes a program recorded in the second executable file, and generates a second log file indicating the values of the global variables for each of the functions; a result comparison device that compares the values of the global variables for each of the functions indicated by the first and second log files and generates a result comparison file that indicates a comparison result.
2. 2. The compilation system according to claim 1, wherein the source code generation device comprises a source code conversion device that generates the first source code by adding code for storing the return value of each function in a global variable for monitoring to second source code for passing the arguments for each function and receiving the return value for each function.
3. 2. The compilation system according to claim 1, wherein the source code generation device comprises a use case automatic generation device that automatically generates the first source code based on a third source code for generating the return value by processing the function for each of the functions in accordance with the arguments.
4. 4. The compilation system according to claim 3, wherein the first source code is source code for passing minimum and maximum argument values for each of the functions and receiving the return value for each of the functions for the minimum and maximum argument values.
5. The different aspects of compilation include compilation without optimization and compilation with optimization, 2. The compilation system according to claim 1, wherein the first compiler generates the first executable file by compiling without optimization and generates the second executable file by compiling with optimization.
6. 6. The compilation system according to claim 5, wherein the result comparison device determines that optimization is effective for functions for which the first and second log files indicate that the global variables have the same values, and determines that optimization is ineffective for functions for which the first and second log files indicate that the global variables have different values, and generates the result comparison file indicating whether optimization is effective or ineffective for each function.
7. 7. The compilation system according to claim 6, further comprising: a fourth source code for passing the arguments for each of the functions and receiving and processing the return value for each of the functions; a fifth source code for processing each of the functions in accordance with the arguments to generate the return value; and a second compiler that receives the result comparison file, and when compiling the fourth source code and the fifth source code, performs compilation with optimization on functions for which the result comparison file indicates that optimization is enabled, and performs compilation without optimization on functions for which the result comparison file indicates that optimization is disabled.
8. a step of generating a first source code for passing an argument to each function, receiving a return value from each function, and storing the return value from each function in a global variable for monitoring by a source code generating device; A compiler performs compilation in different manners on the first source code to generate first and second executable files; an execution device executing a program recorded in the first executable file, generating a first log file indicating the values of the global variables for each of the functions, and executing a program recorded in the second executable file, generating a second log file indicating the values of the global variables for each of the functions; a result comparison device comparing the values of the global variables indicated by the first and second log files and generating a result comparison file indicating a result of the comparison.
Citation Information
Patent Citations
Semiconductor device
JP2011155351A
