Compiling optimization option grouping method, computer device and storage medium
By grouping the compiler's function call relationship information, the search space for compiler optimization options is reduced, the search efficiency of the compiler optimization option tuning algorithm is improved, and the problem of low search efficiency caused by an excessive number of compiler optimization options is solved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZTE CORP
- Filing Date
- 2023-05-29
- Publication Date
- 2026-07-24
AI Technical Summary
There are too many existing compiler optimization options, making it difficult to find a suitable combination of compiler optimization options for the target program in a short time. The search efficiency of compiler optimization option tuning algorithms is also low.
By using the compiler's function call relationship information, all compiler optimization options in the compiler are grouped to obtain multiple target compiler optimization option groups, which are then used as the compiler's target search space to reduce the search space.
It improves the search efficiency of the compiler optimization option tuning algorithm and shortens the time to find a suitable combination of compiler optimization options for the target program.
Smart Images

Figure CN119088664B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method for grouping compiler optimization options, a computer device, and a storage medium. Background Technology
[0002] The compiler is one of the most critical foundational software components in the computer hardware and software ecosystem. After years of research and development, modern compilers possess strong optimization capabilities. Compiler developers have designed and implemented a large number of compiler optimization options, and the appropriate use of these options can significantly improve program performance. However, the sheer number of optimization options makes it difficult to manually find the most suitable combination for the target program. Related technologies primarily rely on compiler optimization option tuning algorithms to select the most suitable combination of optimization options from the compiler's built-in options. However, the large number of compiler optimization options makes it difficult to find the right combination quickly, resulting in low search efficiency for compiler optimization option tuning algorithms. Summary of the Invention
[0003] This invention provides a method for grouping compiler optimization options, a computer device, and a storage medium, aiming to reduce the search space of compiler optimization option tuning algorithms, thereby improving the search efficiency of compiler optimization option tuning algorithms.
[0004] In a first aspect, embodiments of the present invention provide a method for grouping compiler optimization options, including:
[0005] Obtain function call relationship information from the compiler;
[0006] Based on the function call relationship information, all compilation optimization options in the compiler are grouped to obtain multiple target compilation optimization option groups, each target compilation optimization option group including one or more of the compilation optimization options.
[0007] The target compilation optimization option groups are used as the target search space of the compiler, wherein the target search space includes multiple search objects, and one target compilation optimization option group corresponds to one search object.
[0008] In a second aspect, embodiments of the present invention also provide a computer device, the computer device including a processor, a memory, a computer program stored in the memory and executable by the processor, and a data bus for implementing connection communication between the processor and the memory, wherein when the computer program is executed by the processor, it implements the compilation optimization option grouping method as described in the first aspect.
[0009] Thirdly, embodiments of the present invention also provide a storage medium for computer-readable storage, the storage medium storing one or more programs, the one or more programs being executable by one or more processors to implement the compilation optimization option grouping method as described in the first aspect.
[0010] This invention provides a method for grouping compiler optimization options, a computer device, and a storage medium. This invention uses the compiler's function call relationship information to group all compiler optimization options in the compiler, obtaining multiple target compiler optimization option groups. These multiple target compiler optimization option groups are then used as the compiler's target search space, which can greatly reduce the search space of the compiler optimization option tuning algorithm, thereby improving the search efficiency of the algorithm. Attached Figure Description
[0011] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 This is a schematic block diagram of the structure of a computer device provided in an embodiment of the present invention;
[0013] Figure 2 This is a flowchart illustrating a compilation optimization option grouping method provided in an embodiment of the present invention;
[0014] Figure 3 yes Figure 2 A flowchart illustrating the sub-steps of the compilation optimization option grouping method;
[0015] Figure 4 yes Figure 2 A flowchart illustrating the sub-steps of the compilation optimization option grouping method;
[0016] Figure 5 yes Figure 2 A flowchart illustrating the sub-steps of the compilation optimization option grouping method;
[0017] Figure 6 yes Figure 2 A flowchart illustrating the sub-steps of the compilation optimization option grouping method;
[0018] Figure 7 yes Figure 2 A flowchart illustrating the sub-steps of the compilation optimization option grouping method. Detailed Implementation
[0019] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0020] The flowchart shown in the attached diagram is for illustrative purposes only and does not necessarily include all content and operations / steps, nor does it necessarily have to be performed in the order described. For example, some operations / steps can be broken down, combined, or partially merged, so the actual execution order may change depending on the actual situation.
[0021] It should be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0022] The compiler is one of the most critical foundational software components in the computer hardware and software ecosystem. After years of research and development, modern compilers possess strong optimization capabilities. Compiler developers have designed and implemented a large number of compiler optimization options, and the appropriate use of these options can significantly improve program performance. However, the sheer number of optimization options makes it difficult to manually find the most suitable combination for the target program. Related technologies primarily rely on compiler optimization option tuning algorithms to select the most suitable combination of optimization options from the compiler's built-in options. However, the large number of compiler optimization options makes it difficult to find the right combination quickly, resulting in low search efficiency for compiler optimization option tuning algorithms.
[0023] To address the aforementioned problems, embodiments of the present invention provide a method for grouping compiler optimization options, a computer device, and a storage medium. By grouping all compiler optimization options in the compiler using function call relationship information, multiple target compiler optimization option groups are obtained. These multiple target compiler optimization option groups serve as the compiler's target search space, which significantly reduces the search space of the compiler optimization option tuning algorithm, thereby improving the search efficiency of the algorithm.
[0024] In this embodiment of the invention, the computer device can be a server or an electronic device. The server can be a standalone server or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms. The electronic device includes, but is not limited to, smartphones, tablets, laptops, desktop computers, personal digital assistants, and wearable devices.
[0025] The following detailed description of some embodiments of the present invention is provided in conjunction with the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0026] Please see Figure 1 , Figure 1 This is a schematic block diagram of the structure of a computer device provided in an embodiment of the present invention.
[0027] like Figure 1 As shown, the computer device 100 includes a processor 101 and a memory 102, which are connected via a bus 103, such as an I2C (Inter-integrated Circuit) bus.
[0028] Specifically, processor 101 provides computing and control capabilities to support the operation of the entire computer device. Processor 101 can be a Central Processing Unit (CPU), but it can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among these, the general-purpose processor can be a microprocessor or any conventional processor.
[0029] Specifically, the memory 102 can be a Flash chip, a read-only memory (ROM) disk, an optical disk, a USB flash drive, or a portable hard drive, etc.
[0030] Those skilled in the art will understand that Figure 1The structures shown are merely block diagrams of some structures related to the embodiments of the present invention, and do not constitute a limitation on the computer devices on which the embodiments of the present invention are applied. Specific computer devices may include more or fewer components than those shown in the figures, or combine certain components, or have different component arrangements.
[0031] The processor 101 is used to run a computer program stored in the memory 102, and implements any of the compilation optimization option grouping methods provided in the embodiments of the present invention when executing the computer program.
[0032] In one embodiment, the processor 101 is configured to run a computer program stored in memory, and to perform the following steps when executing the computer program:
[0033] Obtain function call relationship information from the compiler;
[0034] Based on the function call relationship information, all compilation optimization options in the compiler are grouped to obtain multiple target compilation optimization option groups, each target compilation optimization option group including one or more of the compilation optimization options.
[0035] The compiler uses multiple target compilation optimization option groups as its target search space, which includes multiple search objects, with one target compilation optimization option group corresponding to one search object.
[0036] In one embodiment, the function call relationship information includes the compiler's function call relationship graph and / or the function call stack recorded when each of the called compilation optimization options is invoked. When the processor 101 implements the grouping of all compilation optimization options in the compiler according to the function call relationship information to obtain multiple target compilation optimization option groups, it is used to:
[0037] Based on the function call graph and / or the function call stack recorded when each of the compiler optimization options is called, all compiler optimization options in the compiler are grouped to obtain multiple target compiler optimization option groups.
[0038] In one embodiment, when the processor 101 groups all compilation optimization options in the compiler to obtain multiple target compilation optimization option groups based on the function call graph and / or the function call stack recorded when each of the called compilation optimization options is invoked, the processor 101 is configured to:
[0039] Based on the function call graph and the function to which each compilation optimization option belongs, determine the first optimization process to which each compilation optimization option belongs;
[0040] Based on the first optimization process to which each of the compiler optimization options belongs, all compiler optimization options in the compiler are grouped to obtain multiple first compiler optimization option groups;
[0041] And / or, based on the function call stack recorded when each of the called compiler optimization options is invoked, determine the second optimization process to which each of the called compiler optimization options belongs;
[0042] Based on the second optimization process to which each of the invoked compilation optimization options belongs, all compilation optimization options in the compiler are grouped to obtain multiple second compilation optimization option groups;
[0043] The target compilation optimization option group of the compiler is determined based on each of the first compilation optimization option group and / or each of the second compilation optimization option group.
[0044] In one embodiment, when the processor 101 implements the process of grouping all compilation optimization options in the compiler according to the first optimization processing flow to which each of the compilation optimization options belongs, to obtain multiple first compilation optimization option groups, the processor 101 is configured to:
[0045] All compilation optimization options that have the same first optimization process are grouped into a first compilation optimization option group;
[0046] If there are ungrouped compiler optimization options, then the ungrouped compiler optimization options belonging to the same first optimization process are divided into a first compiler optimization option group.
[0047] In one embodiment, after implementing the division of ungrouped compiler optimization options belonging to the same first optimization processing flow into a first compiler optimization option group, the processor 101 is further configured to implement:
[0048] If there are multiple compiler optimization options that are not grouped, then each of the ungrouped compiler optimization options will be identified as a compiler optimization option to be grouped.
[0049] Based on the function call relationship graph and the function to which each of the compilation optimization options to be grouped belongs, determine the common function to which each of the compilation optimization options to be grouped belongs;
[0050] All the compiler optimization options to be grouped that belong to the same public function are grouped into a new first compiler optimization option group.
[0051] In one embodiment, when the processor 101 determines the target compilation optimization option group of the compiler based on each of the first compilation optimization option group and / or each of the second compilation optimization option group, it is configured to:
[0052] Each of the first compiler optimization option group and / or each of the second compiler optimization option group is determined as the target compiler optimization option group;
[0053] Alternatively, at least two first compilation optimization options that have an intersection in multiple first compilation optimization option groups are combined into a group to obtain multiple third compilation optimization option groups, and each third compilation optimization option group is determined as the target compilation optimization option group of the compiler.
[0054] Alternatively, each of the third compiler optimization option groups and each of the second compiler optimization option groups can be determined as the target compiler optimization option group;
[0055] Alternatively, at least two second compilation optimization options that have an intersection in multiple second compilation optimization option groups are combined into a group to obtain multiple fourth compilation optimization option groups, and each of the fourth compilation optimization option groups is determined as the target compilation optimization option group of the compiler.
[0056] Alternatively, each of the fourth compiler optimization option groups and each of the first compiler optimization option groups can be determined as the target compiler optimization option groups;
[0057] Alternatively, each of the third and fourth compiler optimization option groups can be determined as the target compiler optimization option group.
[0058] In one embodiment, when the processor 101 determines the target compilation optimization option group of the compiler based on each of the first compilation optimization option group and each of the second compilation optimization option group, it is configured to:
[0059] Obtain unused compiler optimization options, which are determined during dynamic debugging of the compiler's compilation process using preset debugging tools;
[0060] Remove the uncalled compiler optimization option from the first compiler optimization option group that contains the uncalled uncalled compiler optimization option, and update the first compiler optimization option group;
[0061] The target compilation optimization option group of the compiler is determined based on each of the second compilation optimization option groups and each of the updated first compilation optimization option groups.
[0062] In one embodiment, when the processor 101 obtains the compiler's function call relationship information, it is used to:
[0063] The compiler's compilation process is dynamically debugged using a preset debugging tool, and the function call stack of the called compilation optimization options is recorded during the dynamic debugging process.
[0064] At the end of the dynamic debugging of the compiler's compilation process, obtain the function call stack for each of the aforementioned compilation optimization options that were invoked.
[0065] In one embodiment, when the processor 101 obtains the compiler's function call relationship information, it is used to:
[0066] Obtain the source code analysis results of the compiler;
[0067] Based on the source code analysis results, construct the function call graph of the compiler.
[0068] In one embodiment, the processor 101 is further configured to perform the following steps:
[0069] Extract the variables used by each function from the source code analysis results, and obtain the variables corresponding to each of the compilation optimization options;
[0070] Based on the variables used by each function and the variables corresponding to each compilation optimization option, determine the function to which each compilation optimization option belongs.
[0071] It should be noted that those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of the computer device described above can be referred to the corresponding process in the following embodiments of the compilation optimization option grouping method, and will not be repeated here.
[0072] The following will combine Figure 1 The computer device described in the invention provides a detailed explanation of the compilation optimization option grouping method provided by embodiments of the invention. It should be noted that... Figure 1 The computer equipment described herein is only used to explain the compilation optimization option grouping method provided in the embodiments of the present invention, but does not constitute a limitation on the application scenarios of the compilation optimization option grouping method provided in the embodiments of the present invention.
[0073] Please see Figure 2 , Figure 2 This is a flowchart illustrating a compilation optimization option grouping method provided in an embodiment of the present invention.
[0074] like Figure 2 As shown, the compilation optimization option grouping method includes steps S101 to S103.
[0075] Step S101: Obtain the compiler's function call relationship information.
[0076] In this embodiment, the compiler's function call relationship information may include the compiler's function call relationship graph and / or the function call stack recorded when each called compiler optimization option is invoked. The compiler's function call relationship graph is used to describe the call relationship between each function in the compiler's source code, and the function call stack corresponding to the called compiler optimization option is used to describe the call relationship between each function involved when the compiler optimization option is invoked. The compiler can be the GCC (GNU Compiler Collection) compiler, or any other compiler containing compiler optimization options; this embodiment of the invention does not specifically limit this.
[0077] In some embodiments, such as Figure 3 As shown, step S101 includes sub-steps S1011 to S1012.
[0078] Sub-step S1011: Use a preset debugging tool to dynamically debug the compiler's compilation process, and record the function call stack of the called compilation optimization options during the dynamic debugging process.
[0079] In this embodiment, the preset debugging tool can be GDB (a debugging tool provided by the GNU Software Systems Community). Of course, the preset debugging tool can also be any other debugging tool capable of debugging the compiler; this embodiment of the invention does not specifically limit this. A preset buffer can be used to record the function call stack of the invoked compiler optimization options.
[0080] In some embodiments, the compiler's compilation process is dynamically debugged using a preset debugging tool. During this dynamic debugging process, the function call stack of the invoked compiler optimization options is recorded as follows: each compiler optimization option is set as an observation point for the preset debugging tool; a compilation test case is selected from the preset compilation test case library; the compiler is started to compile the test case, and the preset debugging tool is started to monitor the compiler's compilation process; during the compiler's compilation of the test case, if the preset debugging tool detects an observation point, it is determined that the compiler optimization option corresponding to that observation point has been invoked, and the function call stack of the invoked compiler optimization option is recorded; if there are invoked compiler optimization options that have not been invoked, the selection of a compilation test case from the preset compilation test case library continues, and the process of starting the compiler to compile the test case and starting the preset debugging tool to monitor the compiler's compilation process is returned, until each compilation test case in the preset compilation test case library has been selected once or each compiler optimization option has been invoked; when each compilation test case in the preset compilation test case library has been selected once or each compiler optimization option has been invoked, the preset debugging tool is exited. The preset compilation test case library includes multiple compilation test cases, and each compilation test case in the preset compilation test case library can be set by the user based on the actual situation. This embodiment of the invention does not impose specific limitations on this.
[0081] In some embodiments, setting each compiler optimization option as an observation point of a preset debugging tool can be done by setting all compiler optimization options as observation points of the preset debugging tool in batches. For example, if the compiler includes compilation optimization options A, B, C, D, and E, compilation optimization options A, B, and C can be set as observation points a, b, and c of the preset debugging tool, respectively. After the detection of observation points a, b, and c is completed, compilation optimization options D and E can be set as observation points d and e of the preset debugging tool, respectively.
[0082] Sub-step S1012: At the end of the dynamic debugging of the compiler's compilation process, obtain the function call stack of each called compilation optimization option.
[0083] In this embodiment, after the preset debugging tool exits, it can be determined that the dynamic debugging of the compiler's compilation process has ended. At this point, the function call stack of each called compilation optimization option can be obtained. For example, at the end of the dynamic debugging of the compiler's compilation process, the function call stack of each called compilation optimization option is obtained from the preset buffer. This embodiment, by dynamically debugging the compiler's compilation process, can accurately record the function call stack of the called compilation optimization options during the dynamic debugging process.
[0084] In some embodiments, such as Figure 4 As shown, step S101 includes sub-steps S1013 to S1014.
[0085] Sub-step S1013: Obtain the source code analysis results from the compiler.
[0086] In this embodiment, the compiler's source code analysis result is the result of the compiler's source code analysis. Source code analysis tools such as Source Insight and Linux Cross Reference can be used to analyze the compiler's source code to obtain the compiler's source code analysis result.
[0087] Sub-step S1014: Based on the source code analysis results, construct the compiler's function call relationship graph.
[0088] In this embodiment, by performing static analysis on the compiler's source code, the source code analysis results can be obtained. Based on the source code analysis results, the compiler's function call relationship graph can be accurately constructed, improving the accuracy of the function call relationship graph construction.
[0089] In some embodiments, the method for constructing the compiler's function call graph based on source code analysis results can be as follows: the computer device extracts each function from the compiler's source code based on the source code analysis results, and determines the functions called by each function during execution based on the source code analysis results; a compiler function call graph is constructed based on each function and the functions called by each function during execution. The function call graph can be a directed graph.
[0090] It should be noted that the computer device may execute only sub-steps S1011 and S1012, or only sub-steps S1013 and S1014, or it may execute sub-steps S1013 and S1014 simultaneously with sub-steps S1011 and S1012. In other words, the computer device may perform only static analysis on the compiler and construct the compiler's function call graph based on the results of the static analysis, or it may use a preset debugging tool to dynamically debug the compiler's compilation process and obtain the function call stack of the compiler optimization options invoked during the dynamic debugging process. Alternatively, it may not only perform static analysis on the compiler and construct the compiler's function call graph based on the results of the static analysis, but also use a preset debugging tool to dynamically debug the compiler's compilation process and obtain the function call stack of the compiler optimization options invoked during the dynamic debugging process. This embodiment of the invention does not specifically limit this approach.
[0091] Step S102: Based on the function call relationship information, group all compilation optimization options in the compiler to obtain multiple target compilation optimization option groups.
[0092] In this embodiment, the target compilation optimization option group includes one or more compilation optimization options. That is, one compilation optimization option can be divided into a target compilation optimization option group, or multiple compilation optimization options can be divided into a target compilation optimization option group. This embodiment of the invention does not make specific limitations in this regard.
[0093] In some embodiments, grouping all compiler optimization options in the compiler according to function call relationship information to obtain multiple target compiler optimization option groups can be achieved by the computer device grouping all compiler optimization options in the compiler according to the function call relationship graph and / or the function call stack recorded when each called compiler optimization option is invoked, thus obtaining multiple target compiler optimization option groups. This embodiment, by performing static analysis on the compiler, can quickly group compiler optimization options, greatly improving the efficiency of compiler optimization option grouping. Alternatively, this embodiment, by performing dynamic analysis on the compiler, can accurately group compiler optimization options, greatly improving the accuracy of compiler optimization option grouping. Or, this embodiment, by performing both static and dynamic analysis on the compiler to group compiler optimization options, can further improve the accuracy of compiler optimization option grouping.
[0094] In some embodiments, such as Figure 5 As shown, step S102 includes sub-steps S1021 to S1023.
[0095] Sub-step S1021: Based on the function call relationship diagram and the function to which each compilation optimization option belongs, determine the first optimization process to which each compilation optimization option belongs.
[0096] In this embodiment, the first optimization process (Pass) to which the compilation optimization option belongs can be one or more, and this embodiment of the invention does not specifically limit this. The function to which each compilation optimization option belongs is determined by the computer device based on the compiler's source code analysis results.
[0097] In some embodiments, the variables used by each function are extracted from the compiler's source code analysis results, and the variables corresponding to each compilation optimization option are obtained. Based on the variables used by each function and the variables corresponding to each compilation optimization option, the function to which each compilation optimization option belongs is determined. This embodiment can accurately determine the function to which each compilation optimization option belongs by using the variables used by each function and the variables corresponding to each compilation optimization option in the source code analysis results. For example, if the compiler's source code analysis results include functions A, B, C, and D, and the variables used by functions A, B, C, and D are variables a, b, c, and d, respectively, and let variable c be the variable corresponding to compilation optimization option F, then the function to which compilation optimization option F belongs is function C.
[0098] In some embodiments, the method for determining the first optimization process to which each compilation optimization option belongs, based on the function call graph and the function to which each compilation optimization option belongs, can be as follows: For each compilation optimization option, a function call path containing the function to which the compilation optimization option belongs is determined in the function call graph, and the end function of the function call path is a preset function; the optimization process corresponding to the end function of the function call path is determined as the first optimization process to which the compilation optimization option belongs. Here, the preset function is the execute function or the gate function, and the function call path containing the function to which the compilation optimization option belongs can be one or multiple, which is not specifically limited in this embodiment. For example, if the function to which compilation optimization option G belongs is function E, and the function call path containing function E determined in the function call graph is function E→function F→function G→function H, where function H is the end function and function H is the execute function of the optimization process pass_rtl_pre, therefore, the first optimization process to which compilation optimization option G belongs is pass_rtl_pre.
[0099] Sub-step S1022: Based on the first optimization process to which each compilation optimization option belongs, group all compilation optimization options in the compiler to obtain multiple first compilation optimization option groups.
[0100] In this embodiment, the computer device can group all compilation optimization options that have the same first optimization process into a first compilation optimization option group; if there are ungrouped compilation optimization options, then the ungrouped compilation optimization options belonging to the same first optimization process are grouped into a first compilation optimization option group; if there are no ungrouped compilation optimization options, then the grouping ends. One first compilation optimization option group corresponds to one first optimization process.
[0101] For example, the compiler includes compilation optimization options N1, N2, N3, N4, N5, and N6. The first optimization process to which compilation optimization option N1 belongs includes first Pass1 and first Pass2, the first optimization process to which compilation optimization option N2 belongs is first Pass2, the first optimization process to which compilation optimization option N3 belongs is first Pass3, the first optimization process to which compilation optimization option N4 belongs is first Pass3, the first optimization process to which compilation optimization option N5 belongs is first Pass4, and the first optimization process to which compilation optimization option N6 belongs is first Pass5.
[0102] Therefore, compilation optimization options N1 and N2, which share the same first Pass2, can be grouped into one first compilation optimization option group, and compilation optimization options N3 and N4, which share the same first Pass3, can be grouped into another first compilation optimization option group. Compilation optimization options N5 and N6 remain ungrouped. Therefore, compilation optimization option N5 can be grouped into a separate first compilation optimization option group, and compilation optimization option N6 can be grouped into a separate first compilation optimization option group, resulting in four first compilation optimization option groups.
[0103] In some embodiments, if multiple compiler optimization options are not grouped, each ungrouped compiler optimization option is identified as a compiler optimization option to be grouped; based on the function call graph and the function to which each compiler optimization option to be grouped belongs, the common function to which each compiler optimization option to be grouped belongs is determined; all compiler optimization options belonging to the same common function are grouped into a new first compiler optimization option group. This embodiment, by grouping ungrouped compiler optimization options belonging to the same common function into a new first compiler optimization option group when there are compiler optimization options that cannot be grouped according to the first optimization process, can further reduce the search space for compiler optimization options.
[0104] For example, the compiler includes compilation optimization options N1, N2, N3, N4, N5, and N6. The first optimization process to which compilation optimization option N1 belongs includes first Pass1 and first Pass2, the first optimization process to which compilation optimization option N2 belongs includes first Pass3 and first Pass4, the first optimization process to which compilation optimization option N3 belongs is first Pass5, the first optimization process to which compilation optimization option N4 belongs is first Pass5, the first optimization process to which compilation optimization option N5 belongs is first Pass6, and the first optimization process to which compilation optimization option N6 belongs is first Pass7.
[0105] Therefore, optimization options N3 and N5 with the same first Pass5 can be grouped into one first optimization option group. Optimization options N1, N2, N5, and N6 remain ungrouped. Optimization option N5 and N6 can then be grouped into separate first optimization option groups. Next, the common functions to which optimization option N1 and N2 belong are determined. If the common functions to which optimization option N1 and N2 belong are the same, they can be grouped into a new first optimization option group, resulting in four first optimization option groups. Conversely, if the common functions to which optimization option N1 and N2 belong are different, optimization option N1 and N2 can be grouped into separate first optimization option groups, resulting in five first optimization option groups.
[0106] Sub-step S1023: Determine the target compilation optimization option group for the compiler based on each first compilation optimization option group.
[0107] In this embodiment, each first compilation optimization option group can be determined as the compiler's target compilation optimization option group. In some embodiments, at least two first compilation optimization options that have overlap among multiple first compilation optimization option groups can be combined into a group to obtain multiple third compilation optimization option groups, and each third compilation optimization option group can be determined as the compiler's target compilation optimization option group.
[0108] For example, there are a total of 5 first compiler optimization option groups, namely first compiler optimization option group P1, first compiler optimization option group P2, first compiler optimization option group P3, first compiler optimization option group P4 and first compiler optimization option group P5. Therefore, first compiler optimization option groups P1, P2, P3, P4 and P5 can all be used as the compiler's target compiler optimization option groups, thus obtaining 5 target compiler optimization option groups.
[0109] For example, since the first compiler optimization option group P4 and the first compiler optimization option group P5 have overlap, the first compiler optimization option group P4 and the first compiler optimization option group P5 in the first compiler optimization option group P1, the first compiler optimization option group P2, the first compiler optimization option group P3, the first compiler optimization option group P4 and the first compiler optimization option group P5 can be merged into one group to obtain the third compiler optimization option group Q1 (same as the first compiler optimization option group P1), the third compiler optimization option group Q2 (same as the first compiler optimization option group P2), the third compiler optimization option group Q3 (same as the first compiler optimization option group P3) and the third compiler optimization option group Q4 (obtained by merging the first compiler optimization option group P4 and the first compiler optimization option group P5).
[0110] In some embodiments, such as Figure 6 As shown, step S102 includes sub-steps S1024 to S1026.
[0111] Sub-step S1024: Determine the second optimization process to which each of the called compilation optimization options belongs based on the function call stack recorded when each of the called compilation optimization options is invoked.
[0112] In this embodiment, for each called compiler optimization option, the computer device can generate a function call path for the called compiler optimization option based on the function call stack recorded when the called compiler optimization option is called, and the end function of the function call path is a preset function; the optimization process corresponding to the end function of the function call path is determined as the second optimization process to which the called compiler optimization option belongs.
[0113] Sub-step S1025: Based on the second optimization process to which each called compiler optimization option belongs, group all compiler optimization options in the compiler to obtain multiple second compiler optimization option groups.
[0114] In this embodiment, all compilation optimization options belonging to the same second optimization process can be grouped together to obtain multiple second compilation optimization option groups. For example, if the compiler includes 10 compilation optimization options, all 10 options are invoked during dynamic debugging of the compiler. Therefore, the function call stack of each of these 10 optimization options can be obtained. Based on the function call stack of each of these 10 optimization options, the second optimization process to which each optimization option belongs can be determined.
[0115] If the second optimization process for compilation optimization options N1, N2, and N3 among these 10 compilation optimization options is the same, and the second optimization process for compilation optimization options N4, N5, and N6 is the same, and the second optimization process for compilation optimization options N7, N8, N9, and N10 is the same, then compilation optimization options N1, N2, and N3 can be grouped into one second compilation optimization option group, compilation optimization options N4, N5, and N6 into another second compilation optimization option group, and compilation optimization options N7, N8, N9, and N10 into yet another second compilation optimization option group, resulting in a total of 3 second compilation optimization option groups.
[0116] For example, during dynamic debugging of the compiler, optimization options N1, N2, N3, N4, N5, N6, N7, N8, and N9 are all invoked, while optimization option N10 is not invoked. Therefore, based on the function call stacks of each of these optimization options, the second optimization process to which they belong can be determined.
[0117] If the second optimization process to which compilation optimization option N1 and compilation optimization option N2 belong is the same, and the second optimization process to which compilation optimization option N3, compilation optimization option N4, and compilation optimization option N5 belong is the same, and the second optimization process to which compilation optimization option N6, compilation optimization option N7, and compilation optimization option N8, compilation optimization option N9 belong to the same, then compilation optimization option N1 and compilation optimization option N2 can be grouped into one second compilation optimization option group, compilation optimization option N3, compilation optimization option N4, and compilation optimization option N5 can be grouped into one second compilation optimization option group, compilation optimization option N6 and compilation optimization option N7 can be grouped into one second compilation optimization option group, and compilation optimization option N8 and compilation optimization option N9 can be grouped into one second compilation optimization option group. Compilation optimization option N10 is not grouped.
[0118] Sub-step S1026: Determine the target compilation optimization option group for the compiler based on each second compilation optimization option group.
[0119] In this embodiment, the computer device can determine each second compiler optimization option group as the compiler's target compiler optimization option group. In some embodiments, at least two second compiler optimization option groups that have overlap can be combined into one group to obtain multiple fourth compiler optimization option groups, and each fourth compiler optimization option group can be determined as the compiler's target compiler optimization option group. For example, if there are a total of 5 second compiler optimization option groups, namely second compiler optimization option group T1, second compiler optimization option group T2, second compiler optimization option group T3, second compiler optimization option group T4, and second compiler optimization option group T5, then second compiler optimization option groups T1, T2, T3, T4, and T5 can all be used as the compiler's target compiler optimization option groups, thereby obtaining 5 target compiler optimization option groups.
[0120] For example, since the second compiler optimization option group T1 and the second compiler optimization option group T2 have an intersection, the second compiler optimization option group T1 and the second compiler optimization option group T2 in the second compiler optimization option group T1, the second compiler optimization option group T2, the second compiler optimization option group T3, the second compiler optimization option group T4 and the second compiler optimization option group T5 can be merged into one group to obtain the fourth compiler optimization option group Y1 (obtained by merging the second compiler optimization option group T1 and the second compiler optimization option group T2), the fourth compiler optimization option group Y2 (same as the second compiler optimization option group T3), the fourth compiler optimization option group Y3 (same as the second compiler optimization option group T4) and the fourth compiler optimization option group Y4 (same as the second compiler optimization option group T5).
[0121] In some embodiments, such as Figure 7 As shown, step S102 also includes sub-step S1027.
[0122] Sub-step S1027: Determine the target compilation optimization option group for the compiler based on each first compilation optimization option group and each second compilation optimization option group.
[0123] In this embodiment, the computer device can determine each first compilation optimization option group and each second compilation optimization option group as the compiler's target compilation optimization option group. For example, there are a total of 5 first compilation optimization option groups, namely first compilation optimization option group P1, first compilation optimization option group P2, first compilation optimization option group P3, first compilation optimization option group P4 and first compilation optimization option group P5, and a total of 5 second compilation optimization option groups, namely second compilation optimization option group T1, second compilation optimization option group T2, second compilation optimization option group T3, second compilation optimization option group T4 and second compilation optimization option group T5. Therefore, the first compilation optimization option groups P1, P2, P3, P4 and P5, as well as the second compilation optimization option groups T1, T2, T3, T4 and T5, can all be used as the compiler's target compilation optimization option groups, thus obtaining 10 target compilation optimization option groups.
[0124] In some embodiments, the computer device may combine at least two overlapping first compiler optimization options from multiple first compiler optimization option groups to obtain multiple third compiler optimization option groups; and determine each third compiler optimization option group and each second compiler optimization option group as the compiler's target compiler optimization option group. Alternatively, it may combine at least two overlapping second compiler optimization options from multiple second compiler optimization option groups to obtain multiple fourth compiler optimization option groups; and determine each fourth compiler optimization option group and each first compiler optimization option group as the compiler's target compiler optimization option group. Or, it may determine each third compiler optimization option group and each fourth compiler optimization option group as the compiler's target compiler optimization option group.
[0125] In some embodiments, the target compilation optimization option group of the compiler can be determined based on each first compilation optimization option group and each second compilation optimization option group by: the computer device acquiring unused compilation optimization options, which are determined during dynamic debugging of the compiler's compilation process using a preset debugging tool; deleting the unused compilation optimization options from the first compilation optimization option group containing them to update the first compilation optimization option group; and determining the target compilation optimization option group of the compiler based on each second compilation optimization option group and each updated first compilation optimization option group. This embodiment reduces the search space by deleting unused compilation optimization options from the first compilation optimization option group containing them.
[0126] For example, during dynamic debugging of the compiler, compilation optimization options N1, N2, N3, N4, N5, N6, N7, N8, and N9 are all invoked, while optimization option N10 is not invoked. There are a total of five first compilation optimization option groups: P1, P2, P3, P4, and P5. First compilation optimization option group P2 contains the uninvoked optimization option N10. Therefore, the uninvoked optimization option N10 can be removed from first compilation optimization option group P2 to obtain the updated first compilation optimization option group P2.
[0127] Step S103: Use multiple target compilation optimization option groups as the compiler's target search space.
[0128] In this embodiment, the target search space includes multiple search objects, with one target compiler optimization option group corresponding to one search object. For example, if the compiler includes 100 compiler optimization options, without grouping, the compiler optimization option tuning algorithm would need to select from these 100 options. However, by using the compiler optimization option grouping method provided in this embodiment, these 100 options can be grouped into 10 target compiler optimization option groups. Thus, when using the compiler optimization option tuning algorithm, only one or more target compiler optimization option groups need to be selected from these 10 groups, significantly reducing the search space and improving the search efficiency of the algorithm.
[0129] This invention also provides a storage medium for computer-readable storage, wherein the storage medium stores one or more programs that can be executed by one or more processors to implement any of the compiler optimization option grouping methods provided in the specification of this invention.
[0130] The storage medium can be an internal storage unit of the computer device described in the foregoing embodiments, such as the hard disk or memory of the computer device. The storage medium can also be an external storage device of the computer device, such as a plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card equipped on the computer device.
[0131] It will be understood by those skilled in the art that all or some of the steps, systems, or apparatuses disclosed above, and their functional modules / units, can be implemented as software, firmware, hardware, or suitable combinations thereof. In hardware embodiments, the division between functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed collaboratively by several physical components. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include computer storage media (or non-transitory media) and communication media (or transient media). As is known to those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. Furthermore, it is well known to those skilled in the art that communication media typically contain computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.
[0132] It should be understood that the term "and / or" as used in this specification and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes such combinations. It should be noted that, herein, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.
[0133] The sequence numbers of the above embodiments of the present invention are merely for descriptive purposes and do not represent the superiority or inferiority of the embodiments. The above descriptions are only specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for grouping compiler optimization options, characterized in that, include: Obtain function call relationship information from the compiler; The function call relationship information includes the compiler's function call relationship graph and / or the function call stack recorded when each of the called compilation optimization options is invoked; the function call relationship graph is constructed based on the compiler's source code analysis results; Based on the function call relationship information, the function call relationship path of the function to which each compilation optimization option belongs is determined, and all compilation optimization options are grouped according to the optimization process corresponding to the end function of the function call relationship path to obtain multiple target compilation optimization option groups, wherein the target compilation optimization option group includes one or more of the compilation optimization options; The target compilation optimization option groups are used as the target search space of the compiler. The target search space includes multiple search objects, and one target compilation optimization option group corresponds to one search object.
2. The compilation optimization option grouping method according to claim 1, characterized in that, The process involves determining the function call path of each compilation optimization option based on the function call relationship information, and grouping all compilation optimization options according to the optimization process corresponding to the tail function of the function call path, resulting in multiple target compilation optimization option groups, including: Based on the function call graph and / or the function call stack recorded when each of the compiled optimization options is called, the function call path of the function to which each compiled optimization option belongs is determined, and all compiled optimization options are grouped according to the optimization process corresponding to the end function of the function call path to obtain multiple target compiled optimization option groups.
3. The compilation optimization option grouping method according to claim 2, characterized in that, The process involves determining the function call path of each compilation optimization option based on the function call graph and / or the function call stack recorded when each of the called optimization options is invoked, and grouping all compilation optimization options according to the optimization process corresponding to the end function of the function call path to obtain multiple target compilation optimization option groups, including: For each compilation optimization option, a function call path containing the function to which the compilation optimization option belongs is determined in the function call graph, and the optimization process corresponding to the function at the end of the function call path is determined as the first optimization process to which the compilation optimization option belongs. Based on the first optimization process to which each of the compiler optimization options belongs, all compiler optimization options in the compiler are grouped to obtain multiple first compiler optimization option groups; And / or, based on the function call stack recorded when the called compiler optimization option is called, generate the function call relationship path of the called compiler optimization option, and determine the optimization process corresponding to the end function of the function call relationship path as the second optimization process to which the called compiler optimization option belongs; Based on the second optimization process to which each of the invoked compilation optimization options belongs, all compilation optimization options in the compiler are grouped to obtain multiple second compilation optimization option groups; The target compilation optimization option group of the compiler is determined based on each of the first compilation optimization option group and / or each of the second compilation optimization option group.
4. The compilation optimization option grouping method according to claim 3, characterized in that, The compiler optimizes all its options into multiple first optimization option groups based on the first optimization process to which each of the compiler optimizes options belongs, including: All compilation optimization options that have the same first optimization process are grouped into a first compilation optimization option group; If there are ungrouped compiler optimization options, then the ungrouped compiler optimization options belonging to the same first optimization process are divided into a first compiler optimization option group.
5. The compilation optimization option grouping method according to claim 4, characterized in that, After grouping the ungrouped compilation optimization options belonging to the same first optimization process into a first compilation optimization option group, the method further includes: If there are multiple compiler optimization options that are not grouped, then each of the ungrouped compiler optimization options will be identified as a compiler optimization option to be grouped. Based on the function call relationship graph and the function to which each of the compilation optimization options to be grouped belongs, determine the common function to which each of the compilation optimization options to be grouped belongs; All the compiler optimization options to be grouped that belong to the same public function are grouped into a new first compiler optimization option group.
6. The compilation optimization option grouping method according to claim 3, characterized in that, Determining the target compilation optimization option group for the compiler based on each of the first compilation optimization option group and / or each of the second compilation optimization option group includes: Each of the first compiler optimization option group and / or each of the second compiler optimization option group is determined as the target compiler optimization option group; Alternatively, at least two first compilation optimization options that have an intersection in multiple first compilation optimization option groups are combined into a group to obtain multiple third compilation optimization option groups, and each third compilation optimization option group is determined as the target compilation optimization option group of the compiler; Alternatively, each of the third compiler optimization option groups and each of the second compiler optimization option groups can be determined as the target compiler optimization option group; Alternatively, at least two second compilation optimization options that have an intersection in multiple second compilation optimization option groups are combined into a group to obtain multiple fourth compilation optimization option groups, and each of the fourth compilation optimization option groups is determined as the target compilation optimization option group of the compiler. Alternatively, each of the fourth compiler optimization option groups and each of the first compiler optimization option groups can be determined as the target compiler optimization option groups; Alternatively, each of the third and fourth compiler optimization option groups can be determined as the target compiler optimization option group.
7. The compilation optimization option grouping method according to claim 3, characterized in that, The step of determining the target compilation optimization option group for the compiler based on each of the first compilation optimization option group and each of the second compilation optimization option group includes: Obtain unused compiler optimization options, which are determined during dynamic debugging of the compiler's compilation process using preset debugging tools; Remove the uncalled compiler optimization option from the first compiler optimization option group that contains the uncalled uncalled compiler optimization option, and update the first compiler optimization option group; The target compilation optimization option group of the compiler is determined based on each of the second compilation optimization option groups and each of the updated first compilation optimization option groups.
8. The method for grouping compiler optimization options according to any one of claims 1-7, characterized in that, The process of obtaining compiler function call relationship information includes: The compiler's compilation process is dynamically debugged using a preset debugging tool, and the function call stack of the called compilation optimization options is recorded during the dynamic debugging process. At the end of the dynamic debugging of the compiler's compilation process, obtain the function call stack for each of the aforementioned compilation optimization options that were invoked.
9. The method for grouping compiler optimization options according to any one of claims 1-7, characterized in that, The process of obtaining compiler function call relationship information includes: Obtain the source code analysis results of the compiler; Based on the source code analysis results, construct the function call graph of the compiler.
10. The compilation optimization option grouping method according to claim 9, characterized in that, The method further includes: Extract the variables used by each function from the source code analysis results, and obtain the variables corresponding to each of the compilation optimization options; Based on the variables used by each function and the variables corresponding to each compilation optimization option, determine the function to which each compilation optimization option belongs.
11. A computer device, characterized in that, The computer device includes a processor, a memory, a computer program stored in the memory and executable by the processor, and a data bus for implementing communication between the processor and the memory, wherein when the computer program is executed by the processor, it implements the steps of the compilation optimization option grouping method as described in any one of claims 1 to 10.
12. A storage medium for computer-readable storage, characterized in that, The storage medium stores one or more programs, which can be executed by one or more processors to implement the steps of the method for grouping compiler optimization options according to any one of claims 1 to 10.