Method for determining compilation optimization options, electronic device, and readable storage medium
By dividing source code and using a pre-trained model to determine optimal compilation options for each segment, the method addresses the complexity of compiler optimization, enhancing performance and efficiency in software engineering.
Patent Information
- Application Number
- JP2024557141
- Authority / Receiving Office
- JP · JP
- Patent Type
- Patents
- Current Assignee / Owner
- Priority Date
- 2022-03-28
- Filing Date
- 2023-03-28
- Publication Date
- 2026-01-07
- Estimated Expiration
- 2043-03-28
AI Technical Summary
Modern compilers face a complex challenge in determining optimal compilation optimization options due to the vast search space and varying effects of these options on different code, leading to suboptimal performance in large-scale software engineering projects.
A method involving source code division, feature information extraction, and utilization of a pre-trained prediction model to determine individual compilation optimization options for each divided segment of the code, reducing the need for exhaustive trial and error.
This approach achieves more precise optimization, improving runtime performance and reducing the time required for finding optimal compilation settings.
Smart Images

Figure 0007795649000003 
Figure 0007795649000004 
Figure 0007795649000005
Abstract
Description
[Technical Field]
[0001] This application claims priority to Chinese Patent Application No. CN 202210315215.7, filed on March 28, 2022, and entitled "Method for determining compilation optimization options, electronic device, and readable storage medium," the entire contents of which are incorporated herein by reference.
[0002] TECHNICAL FIELD Embodiments of the present application relate to the field of software engineering technology, and more particularly to a method for determining compilation optimization options, an electronic device, and a computer-readable storage medium. [Background technology]
[0003] Modern compilers have increasingly powerful optimization capabilities, allowing them to perform more in-depth optimizations on compiled code during the compilation process. This allows the compiled product to have better runtime performance, such as consuming less memory resources or running faster. However, compiler complexity is also increasing. For example, the widely used GNU Compiler Kit (GCC, GNU Compiler Collection) compiler has 200-400 optimization options. The same optimization option has different optimization effects on different code, and even stacking multiple different optimization options can have different optimization effects. For a given source code, determining which optimization options to use to ensure the compiled output product has the best possible runtime performance involves applying hundreds of combinations of these options. Theoretically, assuming each optimization option has only two states (i.e., enabled or disabled), the search space for finding the optimal combination of optimization options is 2. 200~400This is far beyond the control of even the most skilled software engineer. Furthermore, many compilation optimization options can take on multiple different values rather than just two states; for example, the "-fvect-cost-model" option can take the values unlimited, dynamic, and cheap. This means that the actual search space is 2 200~400 The complexity of finding the optimal combination of compilation optimization options is even greater.
[0004] In addition, large-scale software engineering usually uses only one set of compilation optimization option combinations, or at most applies different compilation optimization option combinations to different subdirectories, but large-scale software engineering often contains thousands of files, and the same compilation optimization option combination may not necessarily be applied to all files, which reduces the overall operating performance of the software engineering. Summary of the Invention [Means for solving the problem]
[0005] The present application provides a method for determining a compilation optimization option, an electronic device, and a computer-readable storage medium. In a first aspect, the present application provides a method for determining a compilation optimization option, including: dividing a first source code into at least one second source code according to a predetermined division level; obtaining feature information corresponding to each second source code; and inputting the feature information corresponding to each second source code into a pre-trained prediction model to obtain a first compilation optimization option corresponding to each second source code.
[0006] In a second aspect, an embodiment of the present application provides an electronic device including at least one processor and a memory having stored thereon at least one program that, when executed by the at least one processor, implements a method for determining compilation optimization options according to the present application.
[0007] In a third aspect, embodiments of the present application provide a computer-readable storage medium having stored thereon a computer program that, when executed by a processor, implements a method for determining compilation optimization options according to the present application. [Brief explanation of the drawings]
[0008] [Figure 1] FIG. 1 is a block diagram illustrating the configuration of a general compiler in the related art. [Figure 2] FIG. 1 is a block diagram of an intelligent compiler according to an embodiment of the present invention. [Figure 3] FIG. 2 is another block diagram of an intelligent compiler according to an embodiment of the present application. [Figure 4] 1 is a flowchart of a method for determining compilation optimization options according to an embodiment of the present application. [Figure 5] 1 is a flowchart of a model training method according to an embodiment of the present application. [Figure 6] FIG. 1 is a block diagram of a device for determining compilation optimization options according to an embodiment of the present application. [Figure 7] FIG. 1 is a block diagram illustrating a configuration of a model training device according to an embodiment of the present application. DETAILED DESCRIPTION OF THE INVENTION
[0009] In order to enable those skilled in the art to better understand the technical solution of the present application, the following detailed description, in combination with drawings, of the method for determining compilation optimization options, electronic equipment, and computer-readable storage medium provided by the present application.
[0010] Exemplary embodiments will be described more fully below with reference to the drawings, but the exemplary embodiments should not be construed as being limited to the embodiments set forth herein, as they may be embodied in different forms. On the contrary, the purpose of providing these examples is to make the present application clear and complete, and to fully convey the scope of the present application to those skilled in the art.
[0011] Where not inconsistent, the embodiments and features of the embodiments of the present application may be combined with each other.
[0012] As used herein, the term "and / or" includes any and all combinations of at least one of the associated listed items.
[0013] The terms used herein are used only to describe particular embodiments and are not intended to limit the present application. As used herein, singular forms such as "a," "an," and "the" are intended to include the plural forms unless the context clearly dictates otherwise. It will also be understood that the use of the terms "comprising" and / or "consisting of" herein refers to the presence of such features, wholes, steps, operations, elements, and / or assemblies, but does not exclude the presence or addition of at least one other feature, whole, step, operation, element, assembly, and / or group thereof.
[0014] Unless otherwise specified, the meanings of all terms (including technical and scientific terms) used herein are the same as those commonly understood by those skilled in the art. It will also be understood that terms defined in common dictionaries, unless expressly limited herein, will be interpreted as having a meaning consistent with the meaning in the context of the relevant art and this application, and will not be interpreted as having an ideal or excessively formal meaning.
[0015] Before introducing the method for determining the compilation optimization options in the embodiment of the present application, the process of program compilation by a general compiler will be described. As shown in Figure 1, the general compiler includes a syntax analysis module 101, a syntax analysis module 102, a semantic analysis module 103, a code optimization module 104, and a target code generation module 105.
[0016] A source code and compilation optimization options input by a user are input to a general compiler, and the syntactic analysis module 102 outputs an abstract syntax tree (AST) of the source code, and the semantic analysis module 103 outputs a control flow graph (CFG) and a data flow graph (DFG). The compilation optimization options input by the user are transparently transmitted through the usage analysis module 101, syntactic analysis module 102, and semantic analysis module 103 and then input to the code optimization module 104. The code optimization module 104 performs code optimization according to the AST, CFG, DFG, and the compilation optimization options input by the user and the default compilation optimization options. The target code generation module 105 generates target code according to the optimization results. The target code is the output product obtained by compiling the source code.
[0017] In some example embodiments of the present application, a general compiler is modified and a plug-in 106 is added between the semantic analysis module 103 and the code optimization module 104 of the general compiler to obtain the intelligent compiler of the example embodiments of the present application.
[0018] As shown in FIG. 2, the added plug-in 106 predicts a first compilation optimization option corresponding to a second source code (obtained by dividing the input first source code), i.e., the plug-in 106 realizes the function of the prediction model described below. Furthermore, before the usage analysis module 101, the input first source code needs to be divided into at least one second source code according to a preset division level. Therefore, the analysis target of the subsequent usage analysis module 101, syntax analysis module 102, and semantic analysis module 103 is the second source code, not the first source code. In an exemplary embodiment, as shown in FIG. 2, a division module 107 can be added before the usage analysis module 101 to realize the division function.
[0019] In another exemplary embodiment of the present application, the prediction mode may be implemented without using a plug-in approach, but may be implemented using code, i.e., by combining the code for implementing the prediction model with the code of a regular compiler.
[0020] In another exemplary embodiment of the present application, the general compiler is improved by adding a prediction module 108 before the semantic analysis module 101 of the general compiler to obtain the intelligent compiler of the embodiment of the present application. As shown in Figure 3, the prediction module 108 is used to implement the method for determining compilation optimization options of the embodiment of the present application.
[0021] FIG. 4 is a flowchart of a method for determining compilation optimization options according to an embodiment of the present application.
[0022] Referring to FIG. 4, an embodiment of the present application provides a method for determining compilation optimization options, which may include the following operations 400, 401.
[0023] Operation 400 divides a first source code into at least one second source code according to a preset division level.
[0024] In an embodiment of the present application, the first source code may include all source code in one or more files, and the source code in the files may include at least one of one or more function and data structure definitions and variable declarations in the source code.
[0025] In the embodiments of the present application, the division level can be set according to actual circumstances. In some exemplary embodiments, the preset division level includes a file level, and the second source code includes source code in the same file, or the preset division level includes a function level, and the second source code includes source code in the same function.
[0026] In some example embodiments, the division level may be preset by the user or may be set as a default.
[0027] Operation 401: obtain feature information corresponding to each second source code, respectively; input the feature information corresponding to each second source code into a pre-trained prediction model to obtain a first compilation optimization option corresponding to each second source code.
[0028] In some demonstrative embodiments, the feature information includes at least one of an AST, a CFG, and a DFG.
[0029] In some exemplary embodiments, an AST corresponding to the second source code can be obtained by performing lexical analysis and syntactic analysis on the second source code, and a CFG and a DFG corresponding to the second source code can be obtained by performing lexical analysis, syntactic analysis, and semantic analysis on the second source code.
[0030] According to some example embodiments of the present application, by applying a first compilation optimization option corresponding to the second source code to the compilation of the second source code, it is possible to obtain significantly better optimization effects than the default compilation optimization options (e.g., -02, -03, etc.) of the compiler.
[0031] In some exemplary embodiments, feature information corresponding to each second source code is input into a pre-trained predictive model to obtain first compilation optimization options corresponding to each second source code. In other exemplary embodiments, feature information corresponding to each second source code and target operating environment information corresponding to the second source code are input into a pre-trained predictive model to obtain first compilation optimization options corresponding to each second source code.
[0032] In some exemplary embodiments, the target operating environment information corresponding to the second source code refers to the operating environment information in which the output product obtained by compiling the first source code exists. In some exemplary embodiments, the target operating environment information includes hardware information and operating system environment information.
[0033] In some demonstrative embodiments, the hardware information includes at least one of a central processor (CPU) type and a cache capacity. In some demonstrative embodiments, the operating system environment information includes at least one of an operating system (OS) type and an OS version number.
[0034] In some demonstrative embodiments, after inputting feature information corresponding to each second source code into a pre-trained prediction model to obtain first compilation optimization options corresponding to each second source code (i.e., operation 401), the method further includes performing code optimization on each second source code according to the first compilation optimization options corresponding to each second source code.
[0035] In some illustrative embodiments, code optimization is performed on each second source code according to a first compilation optimization option corresponding to each second source code. In another illustrative embodiment, code optimization is performed on each second source code according to the first compilation optimization option corresponding to each second source code and a third compilation optimization option input by a user. The third compilation optimization option input by a user can be customized by a user.
[0036] In the embodiment of the present application, the first compilation optimization options corresponding to different second source codes may be the same or different, and if the first compilation optimization options corresponding to different second source codes are different, the different second source codes need to be compiled using different first compilation optimization options.
[0037] In some example embodiments, before dividing the first source code into at least one second source code according to a preset division level (i.e., operation 400), the method further includes: constructing a dataset including at least one data entry, where each data entry includes a third source code and a corresponding second compilation optimization option; obtaining feature information corresponding to the third source code in each data entry; and performing model training according to the feature information corresponding to the third source code and the corresponding second compilation optimization option to obtain a prediction model, wherein in the model training process, the feature information corresponding to the third source code is used as an input of the prediction model, and the second compilation optimization option is used as an output of the prediction model.
[0038] In some example embodiments, before dividing the first source code into at least one second source code according to a preset division level (i.e., operation 400), the method further includes: constructing a dataset including at least one data entry, where each data entry includes feature information corresponding to a third source code and a corresponding second compilation optimization option; and performing model training according to the feature information corresponding to the third source code and the corresponding second compilation optimization option to obtain a prediction model, where in the model training process, the feature information corresponding to the third source code is used as an input of the prediction model, and the second compilation optimization option is used as an output of the prediction model.
[0039] According to some exemplary embodiments of the present application, by applying a second compilation optimization option corresponding to the third source code to the compilation of the third source code, it is possible to obtain significantly better optimization effects than the compiler's default compilation optimization options (e.g., -02, -03, etc.). For example, in Table 1 below, the output product obtained by compiling the third source code prog1 using the second compilation optimization options -falign-functions, -falign-labels, -fwrapv -fwrapv-pointer ... can obtain better runtime performance than a normal compilation optimization option such as -03 when run on the target operating environment (x86 CPU, 32 MB cache, OS is linux-4.9.299).
[0040] In some example embodiments, the data entry further includes target operating environment information corresponding to the third source code, and performing model training according to the feature information corresponding to the third source code and the corresponding second compilation optimization options to obtain a predictive model includes performing model training according to the feature information corresponding to the third source code, the corresponding second compilation optimization options, and the target operating environment information corresponding to the third source code to obtain a predictive model, wherein in the model training process, the feature information corresponding to the third source code and the target operating environment information corresponding to the third source code are inputs of the predictive model, and the second compilation optimization options are output of the predictive model.
[0041] For example, the data set shown in Table 1 has n data entries, and each data entry includes a third source code, target operating environment information, and a second compilation optimization option.
[0042] [Table 1]
[0043] In the embodiments of the present application, training of the predictive model can be achieved using model training methods well known to those skilled in the art.
[0044] In some example embodiments, performing model training according to feature information corresponding to the third source code and the corresponding second compilation optimization option to obtain a prediction model includes: inputting the feature information corresponding to the third source code in each data entry into the prediction model to obtain a predicted value of the corresponding compilation optimization option; calculating a loss function value according to the predicted value of the compilation optimization option corresponding to the third source code and the second compilation optimization option corresponding to the third source code; adjusting connection weights between neurons in the prediction model using a backpropagation algorithm such as random gradient descent; and continuously performing the steps of inputting the feature information corresponding to the third source code in each data entry into the adjusted prediction model to obtain a predicted value of the corresponding compilation optimization option until the value of the loss function satisfies a preset condition.
[0045] In another exemplary embodiment, performing model training according to feature information corresponding to the third source code, the corresponding second compilation optimization option, and the target operating environment information corresponding to the third source code to obtain a prediction model includes: inputting the feature information corresponding to the third source code in each data entry and the target operating environment information corresponding to the third source code into the prediction model, respectively, to obtain a predicted value of the corresponding compilation optimization option; calculating a loss function value according to the predicted value of the compilation optimization option corresponding to the third source code and the second compilation optimization option corresponding to the third source code; adjusting connection weights between neurons in the prediction model using a backpropagation algorithm such as random gradient descent; and continuously performing the steps of inputting the feature information corresponding to the third source code in each data entry and the target operating environment information corresponding to the third source code into the adjusted prediction model to obtain a predicted value of the corresponding compilation optimization option until the value of the loss function satisfies a preset condition.
[0046] In some demonstrative embodiments, the third source code includes source code in the same file or source code in the same function.
[0047] In an embodiment of the present application, the third source code in all data entries in a dataset used for model training is source code in the same file, or the third source code in all data entries in a dataset used for model training is source code in the same function, or the third source code in some data entries in a dataset used for model training is source code in the same file and the third source code in another part of the data entries is source code in the same function. The embodiment of the present application is not limited thereto.
[0048] In some exemplary embodiments, the target operating environment information corresponding to the third source code refers to the operating environment information in which the output product obtained by compiling the third source code exists. In some exemplary embodiments, the target operating environment information includes hardware information and operating system environment information.
[0049] In some demonstrative embodiments, the hardware information includes at least one of a central processor (CPU, Center Processing Unit) type and a cache capacity.
[0050] In some demonstrative embodiments, the operating system environment information includes at least one of an operating system (OS) type and an OS version number.
[0051] In some demonstrative examples, the predictive model may be any machine learning model known to those skilled in the art, such as a recurrent neural network, a fully connected neural network, a graph neural network, a hybrid neural network, etc.
[0052] In some example embodiments, the output of the prediction model is a vector, the number of elements of which is the same as the number of compilation optimization options in the compiler, and the value of each element of the vector represents the state value of the corresponding compilation optimization option. For example, as shown in Table 2, the compiler GCC-9.2.0 supports 243 compilation optimization options, so the output of the prediction model is a vector containing 243 elements, and the value of each element represents the state value of the compilation optimization option corresponding to that element.
[0053] In an embodiment of the present application, each compilation optimization option of a compiler can be assigned a number, and the number of a compilation optimization option is the same as the subscript of the element corresponding to that compilation optimization option. As shown in Table 2, the subscripts can start from 0, and the compilation optimization option numbers can also start from 0. The vector in the first row of Table 1 can be expressed as (0,1,0,1,0 ... 0,1), that is, the elements numbered 1, 3, and 242 are 1, and the remaining elements are 0. Here, it is assumed that each compilation optimization option has only two states, on and off, where 1 represents on and 0 represents off.
[0054] [Table 2]
[0055] In some example embodiments, the state values of a compilation optimization option may include two state values, on and off, and may also include other possible state values. For example, the "-fvect-cost-model" option can have three state values: unlimited, dynamic, and cheap.
[0056] A method for determining compilation optimization options provided by an embodiment of the present application does not perform predictions on a first source code in bulk, but rather divides the first source code at a predetermined division level to obtain at least one second source code, and predicts first compilation optimization options corresponding to each second source code individually based on a pre-trained prediction model, thereby achieving more precise optimization of compilation optimization options and thereby improving the runtime performance of a compilation output product corresponding to software engineering. Furthermore, predictions based on a pre-trained prediction model eliminate the need for multiple compilations of software engineering and the need to run programs to collect data, thereby shortening the optimization time for compilation optimization options and improving optimization efficiency.
[0057] FIG. 5 is a flowchart of a model training method according to an embodiment of the present application.
[0058] Referring to FIG. 5, an embodiment of the present application provides a model training method that may include the following operations 500, 501.
[0059] Operation 500 constructs a data set including at least one data entry, each data entry including third source code and corresponding second compilation optimization options, or each data entry including feature information corresponding to the third source code and corresponding second compilation optimization options.
[0060] In some example embodiments, the data entry further includes target operating environment information corresponding to the third source code. For example, the data set shown in Table 1 has n data entries, each of which includes a third source code, target operating environment information, and second compilation optimization options, or each of which includes feature information corresponding to the third source code, target operating environment information, and second compilation optimization options.
[0061] In some exemplary embodiments, the target operating environment information corresponding to the third source code refers to the operating environment information in which the output product obtained by compiling the third source code exists. In some exemplary embodiments, the target operating environment information includes hardware information and operating system environment information.
[0062] In some demonstrative embodiments, the hardware information includes at least one of a CPU type and a cache capacity.
[0063] In some example embodiments, the operating system environment information includes at least one of an OS type and an OS version number.
[0064] In some demonstrative embodiments, the third source code includes source code in the same file or source code in the same function.
[0065] In an embodiment of the present application, the third source code in all data entries in a dataset used for model training is source code in the same file, or the third source code in all data entries in a dataset used for model training is source code in the same function, or the third source code in some data entries in a dataset used for model training is source code in the same file, and the third source code in another part of the data entries is source code in the same function. The embodiment of the present application is not limited thereto.
[0066] In some exemplary embodiments, each data entry includes a third source code, target operating environment information, and a second compilation optimization option, and obtains feature information corresponding to the third source code in each data entry, respectively. In some demonstrative embodiments, the feature information includes at least one of an AST, a CFG, and a DFG.
[0067] Operation 501: perform model training according to the feature information corresponding to the third source code and the corresponding second compilation optimization option to obtain a prediction model. During the model training process, the feature information corresponding to the third source code is used as the input of the prediction model, and the second compilation optimization option is used as the output of the prediction model.
[0068] In some example embodiments, performing model training according to feature information corresponding to the third source code and the corresponding second compilation optimization options to obtain a predictive model (i.e., operation 501) includes performing model training according to feature information corresponding to the third source code, the corresponding second compilation optimization options, and target operating environment information corresponding to the third source code to obtain a predictive model, wherein in the model training process, the feature information corresponding to the third source code and the target operating environment information corresponding to the third source code are used as inputs of the predictive model, and the second compilation optimization options are used as outputs of the predictive model.
[0069] In the embodiments of the present application, training of the predictive model can be achieved using model training methods well known to those skilled in the art.
[0070] In some example embodiments, performing model training according to feature information corresponding to the third source code and the corresponding second compilation optimization option to obtain a prediction model includes: inputting the feature information corresponding to the third source code in each data entry into the prediction model to obtain a predicted value of the corresponding compilation optimization option; calculating a loss function value according to the predicted value of the compilation optimization option corresponding to the third source code and the second compilation optimization option corresponding to the third source code; adjusting connection weights between neurons in the prediction model using a backpropagation algorithm such as random gradient descent; and continuously performing the steps of inputting the feature information corresponding to the third source code in each data entry into the adjusted prediction model to obtain a predicted value of the corresponding compilation optimization option until the value of the loss function satisfies a preset condition.
[0071] In another exemplary embodiment, performing model training according to feature information corresponding to the third source code, the corresponding second compilation optimization option, and the target operating environment information corresponding to the third source code to obtain a prediction model includes: inputting the feature information corresponding to the third source code in each data entry and the target operating environment information corresponding to the third source code into the prediction model, respectively, to obtain a predicted value of the corresponding compilation optimization option; calculating a loss function value according to the predicted value of the compilation optimization option corresponding to the third source code and the second compilation optimization option corresponding to the third source code; adjusting connection weights between neurons in the prediction model using a backpropagation algorithm such as random gradient descent; and continuously performing the step of inputting the feature information corresponding to the third source code in each data entry and the target operating environment information corresponding to the third source code into the adjusted prediction model to obtain a predicted value of the corresponding compilation optimization option until the value of the loss function satisfies a preset condition.
[0072] In some example embodiments, the predictive model may be any machine learning model known to those skilled in the art, such as a recurrent neural network, a fully connected neural network, a graph neural network, a hybrid neural network, etc.
[0073] In some example embodiments, the output of the prediction model is a vector, the number of elements of which is the same as the number of compilation optimization options in the compiler, and the value of each element of the vector represents the state value of the corresponding compilation optimization option. For example, as shown in Table 2, the compiler GCC-9.2.0 supports 243 compilation optimization options, so the output of the prediction model is a vector containing 243 elements, and the value of each element represents the state value of the compilation optimization option corresponding to that element.
[0074] In an embodiment of the present application, each compilation optimization option of a compiler can be assigned a number, and the number of a compilation optimization option is the same as the subscript of the element corresponding to that compilation optimization option. As shown in Table 2, the subscripts can start from 0, and the compilation optimization option numbers can also start from 0. The vector in the first row of Table 1 can be expressed as (0,1,0,1,0 ... 0,1), that is, the elements numbered 1, 3, and 242 are 1, and the remaining elements are 0. Here, it is assumed that each compilation optimization option has only two states, on and off, where 1 represents on and 0 represents off.
[0075] In some example embodiments, the state values of a compilation optimization option may include two state values, on and off, and may also include other possible state values. For example, the "-fvect-cost-model" option can have three state values: unlimited, dynamic, and cheap.
[0076] An embodiment of the present application further provides an electronic device including at least one processor and a memory having stored thereon at least one program that, when executed by the at least one processor, implements any one of the above-described methods for determining compilation optimization options or any one of the above-described methods for training a model. A processor is a device having data processing capabilities, including, but not limited to, a central processor unit (CPU), etc. A memory is a device having data storage capabilities, including, but not limited to, a random access memory (RAM, more specifically, SDRAM, DDR, etc.), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), and a flash memory (FLASH).
[0077] In some embodiments, the processor and memory are interconnected via a bus, and further connected to other components of the computing device.
[0078] An embodiment of the present application further provides a computer-readable storage medium having stored thereon a computer program that, when executed by a processor, implements any one of the above methods for determining compilation optimization options or any one of the above methods for training a model.
[0079] FIG. 6 is a block diagram of an apparatus for determining compilation optimization options according to an embodiment of the present invention.
[0080] Referring to FIG. 6 , an embodiment of the present application provides an apparatus for determining compilation optimization options, including: a division module 601 for dividing a first source code into at least one second source code according to a preset division level; and a prediction module 602 for respectively obtaining feature information corresponding to each second source code, and inputting the feature information corresponding to each second source code into a pre-trained prediction model to obtain a first compilation optimization option corresponding to each second source code.
[0081] In some demonstrative embodiments, the apparatus for determining compilation optimization options further includes a compilation module 603 for performing code optimization on each second source code according to a first compilation optimization option corresponding to each second source code.
[0082] In some demonstrative embodiments, the apparatus for determining compilation optimization options further includes a first model training module 604 for constructing a dataset including at least one data entry, each data entry including a third source code and a corresponding second compilation optimization option; respectively obtaining feature information corresponding to the third source code in each data entry; and performing model training according to the feature information corresponding to the third source code and the corresponding second compilation optimization option to obtain a predictive model, wherein in the model training process, the feature information corresponding to the third source code is used as an input of the predictive model, and the second compilation optimization option is used as an output of the predictive model.
[0083] In some demonstrative embodiments, the first model training module 604 is used to construct a dataset including at least one data entry, where each data entry includes feature information corresponding to a third source code and a corresponding second compilation optimization option, and to perform model training according to the feature information corresponding to the third source code and the corresponding second compilation optimization option to obtain a predictive model, where in the model training process, the feature information corresponding to the third source code is used as the input of the predictive model, and the second compilation optimization option is used as the output of the predictive model.
[0084] In some example embodiments, the data entries further include target operating environment information corresponding to the third source code, and the first model training module 604 is used to perform model training according to the feature information corresponding to the third source code, the corresponding second compilation optimization options, and the target operating environment information corresponding to the third source code to obtain a predictive model, wherein in the model training process, the feature information corresponding to the third source code and the target operating environment information corresponding to the third source code are used as inputs of the predictive model, and the second compilation optimization options are used as outputs of the predictive model.
[0085] In some demonstrative embodiments, the third source code includes source code in the same file or source code in the same function.
[0086] In some example embodiments, the decomposition level includes a file level and the second source code includes source code in the same file, or the decomposition level includes a function level and the second source code includes source code in the same function.
[0087] In some demonstrative embodiments, the feature information includes at least one of an AST, a CFG, and a DFG.
[0088] In some demonstrative embodiments, the prediction module 602 is used to input feature information corresponding to each second source code and target operating environment information corresponding to the second source code into a pre-trained prediction model to obtain first compilation optimization options corresponding to each second source code.
[0089] In some demonstrative embodiments, the target operating environment information includes hardware information and operating system environment information.
[0090] The specific implementation process of the apparatus for determining compilation optimization options is the same as the specific implementation process of the method for determining compilation optimization options in the previous embodiment, and will not be further described here.
[0091] FIG. 7 is a block diagram of a model training device according to an embodiment of the present invention.
[0092] Referring to FIG. 7 , an embodiment of the present application provides a model training device, including: a construction module 701 for constructing a dataset, the dataset including at least one data entry, each data entry including a third source code and a corresponding second compilation optimization option, or each data entry including feature information corresponding to the third source code and the corresponding second compilation optimization option; and a second model training module 702 for performing model training according to the feature information corresponding to the third source code and the corresponding second compilation optimization option to obtain a predictive model, wherein in the model training process, the feature information corresponding to the third source code is used as the input of the predictive model, and the second compilation optimization option is used as the output of the predictive model.
[0093] In some example embodiments, the data entries further include target operating environment information corresponding to the third source code, and the second model training module 702 is used to perform model training according to the feature information corresponding to the third source code, the corresponding second compilation optimization options, and the target operating environment information corresponding to the third source code to obtain a predictive model, wherein in the model training process, the feature information corresponding to the third source code and the target operating environment information corresponding to the third source code are used as inputs of the predictive model, and the second compilation optimization options are used as outputs of the predictive model.
[0094] In some demonstrative embodiments, the target operating environment information includes hardware information and operating system environment information.
[0095] In some demonstrative embodiments, the third source code includes source code in the same file or source code in the same function.
[0096] In some demonstrative embodiments, the model training apparatus further includes a feature information obtaining module 703 for respectively obtaining feature information corresponding to the third source code in each data entry.
[0097] In some demonstrative embodiments, the feature information includes at least one of an AST, a CFG, and a DFG.
[0098] The specific implementation process of the model training device is the same as the specific implementation process of the model training method in the previous embodiment, and will not be further described here.
[0099] Those skilled in the art will understand that all or some of the steps of the methods, systems, and functional modules / units in the devices disclosed above can be realized as software, firmware, hardware, or any suitable combination thereof. In hardware embodiments, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components. For example, one physical component may have multiple functions, and one function or step may be performed by multiple physical components working together. Some or all of the physical components may be implemented as software executed by a processor, such as a central processor, digital signal processor, or microprocessor, as hardware, or as an integrated circuit, such as a dedicated integrated circuit. Such software may be distributed on computer-readable media, which may include computer storage media (or non-transitory media) and communication media (or transitory media). As 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 (e.g., 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 technology, CD-ROM, digital versatile disks (DVD) or other optical disk memory, magnetic cassettes, magnetic tape, magnetic disk memory or other magnetic memory, or any other medium used to store the desired information and accessible by a computer. Those skilled in the art will also recognize that communication media typically include computer-readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transmission mechanism and can include any information delivery media.
[0100] Although exemplary embodiments are disclosed herein and specific terms are used, they should be used and interpreted in a general, illustrative sense only, and not for purposes of limitation. It will be apparent to those skilled in the art that, in some embodiments, features, characteristics, and / or elements described in combination with a particular embodiment may be used alone or in combination with features, characteristics, and / or elements described in combination with other embodiments, unless otherwise specified. Accordingly, those skilled in the art will recognize that various modifications in form and detail are possible without departing from the scope of the present disclosure, as defined by the appended claims.
Claims
1. Dividing the first source code into at least one second source code according to a predetermined division level; acquiring characteristic information corresponding to each second source code; inputting feature information corresponding to each of the second source codes into a pre-trained prediction model to obtain first compilation optimization options corresponding to each of the second source codes; Before dividing the first source code into at least one second source code according to a predetermined division level, and performing model training according to feature information corresponding to a third source code and a corresponding second compilation optimization option to obtain the prediction model, wherein in the model training process, the feature information corresponding to the third source code is used as an input of the prediction model, and the second compilation optimization option is used as an output of the prediction model. A method for determining compilation optimization options to be performed by a processor in an electronic device.
2. and further comprising: optimizing each of the second source codes according to a first compilation optimization option corresponding to each of the second source codes. The method of determining compilation optimization options according to claim 1 .
3. before performing model training according to feature information corresponding to the third source code and the corresponding second compilation optimization option to obtain the predictive model, constructing a data set including at least one data entry, each data entry including the third source code and the corresponding second compilation optimization options; obtaining characteristic information corresponding to the third source code in each of the data entries; further comprising: The method of determining compilation optimization options according to claim 1 .
4. before performing model training according to feature information corresponding to the third source code and the corresponding second compilation optimization option to obtain the predictive model, constructing a data set including at least one data entry, each data entry including the feature information corresponding to the third source code and the corresponding second compilation optimization options; The method of determining compilation optimization options according to claim 1 .
5. The data entry further includes target operating environment information corresponding to the third source code; performing model training according to feature information corresponding to the third source code and corresponding second compilation optimization options to obtain the prediction model; and performing model training according to feature information corresponding to the third source code, corresponding second compilation optimization options, and target operating environment information corresponding to the third source code to obtain the prediction model, wherein in the model training process, the feature information corresponding to the third source code and the target operating environment information corresponding to the third source code are used as inputs of the prediction model, and the second compilation optimization options are used as outputs of the prediction model.
5. A method for determining compilation optimization options according to claim 3 or 4.
6. The third source code source code in the same file, or Contains source code for the same function 5. A method for determining compilation optimization options according to claim 3 or 4.
7. The predetermined division level includes a file level, and the second source code includes source code in the same file; or The predetermined division level includes a function level, and the second source code includes source code in the same function. The method for determining a compilation optimization option according to any one of claims 1 to 4.
8. Each of the data entries further includes target operating environment information corresponding to the third source code; performing model training according to feature information corresponding to the third source code and the corresponding second compilation optimization option to obtain the prediction model; performing model training according to feature information corresponding to the third source code, the corresponding second compilation optimization options, and target operating environment information corresponding to the third source code to obtain the prediction model, wherein in the model training process, the feature information corresponding to the third source code and the target operating environment information corresponding to the third source code are used as inputs of the prediction model, and the second compilation optimization options are used as outputs of the prediction model; inputting feature information corresponding to each of the second source codes into a pre-trained prediction model to obtain a first compilation optimization option corresponding to each of the second source codes; and inputting feature information corresponding to each of the second source codes and target operating environment information corresponding to the second source codes into a pre-trained prediction model to obtain a first compilation optimization option corresponding to each of the second source codes.
5. A method for determining compilation optimization options according to claim 3 or 4.
9. The target operating environment information includes hardware information and operating system environment information.
9. The method for determining compilation optimization options according to claim 8.
10. at least one processor; a memory having stored thereon at least one program that, when executed by said at least one processor, implements the method for determining compilation optimization options of claim 1. electronic equipment.
11. A computer program is stored which, when executed by a processor, implements the method for determining compilation optimization options according to claim 1. A computer-readable storage medium.
Citation Information
Patent Citations
Firmware compiling optimization option identification method and device for power grid embedded terminal
CN111444513A
Firmware formation system
JP2004021635A
Method for generating at least portion of executable control program by computer support
JP2014056579A
Method for the computer-aided generation of at least one part of an executable control program
US20140075409A1