Method for determining compilation optimization options, electronic device, and readable storage medium

By splitting source code into sections, extracting feature information, and using a prediction model to determine optimal compilation options, the method addresses the complexity of modern compilers, achieving improved compilation efficiency and performance.

JP2025510285AActive Publication Date: 2025-04-14ZTE CORP
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
JP2024557141
Authority / Receiving Office
JP · JP
Patent Type
Applications
Current Assignee / Owner
Priority Date
2022-03-28
Filing Date
2023-03-28
Publication Date
2025-04-14
Estimated Expiration
2043-03-28

AI Technical Summary

Technical Problem

The complexity of modern compilers, with hundreds of compilation optimization options, makes it impractical for software engineers to determine the best combination of options to achieve optimal performance for compiled code.

Method used

A method that splits source code into smaller sections, extracts feature information, and uses a pre-trained prediction model to determine optimal compilation options for each section, thereby improving compilation efficiency and performance.

Benefits of technology

This approach allows for more refined optimization of compilation options, leading to better operational performance of compiled software without requiring extensive manual configuration or repeated compilation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 2025510285000001_ABST
    Figure 2025510285000001_ABST
Patent Text Reader

Abstract

The present disclosure provides a method, an electronic device, and a computer-readable storage medium for determining compilation optimization options, the method including: dividing a first source code into at least one second source code according to a preset division level; 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.
Need to check novelty before this filing date? Find Prior Art

Description

[Technical field]

[0001] This application claims priority to Chinese Patent Application No. 202210315215.7, entitled "Method for determining compilation optimization options, electronic device, and readable storage medium," filed on March 28, 2022, the entire contents of which are incorporated herein by reference.

[0002] TECHNICAL FIELD The present application relates 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] The optimization capabilities of modern compilers are becoming stronger and stronger, and the compilation process can perform more and deeper optimizations on the compiled code, so that the compiled product has better runtime performance, such as consuming less memory resources during runtime or running at a faster speed. However, the complexity of compilers is also increasing. For example, the widely used GNU Compiler Kit (GCC, GNU Compiler Collection) compiler has 200 to 400 compilation optimization options, and the same compilation optimization option has different optimization effects on different codes, and different optimization options have different optimization effects on the same code, and even stacking multiple different compilation optimization options has different optimization effects. For a given source code, determining which compilation optimization option to use to ensure that the compiled output product has the best possible runtime performance involves applying hundreds of combinations of compilation optimization options. In theory, assuming that each compilation optimization option has only two states (i.e., use or not use), the search space for finding the optimal combination of compilation optimization options is 2 200~400This is far beyond the control of even the most skilled software engineers. 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 and finding the optimal combination of compilation optimization options is even more difficult.

[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 preset division level; 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.

[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, an embodiment of the present application provides a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a method for determining compilation optimization options according to the present application. [Brief description of the drawings]

[0008] [Figure 1] FIG. 1 is a block diagram showing the configuration of a general compiler in the related art. [Diagram 2] FIG. 1 is a block diagram of an intelligent compiler according to an embodiment of the present application. [Diagram 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. [Diagram 5] 1 is a flowchart of a model training method according to an embodiment of the present application. [Figure 6] FIG. 2 is a block diagram of a configuration of an apparatus for determining a compilation optimization option according to an embodiment of the present application. [Figure 7] FIG. 1 is a configuration block diagram of a model training device according to an embodiment of the present application. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS

[0009] In order to make the technical solutions of the present application easier for those skilled in the art, the following describes in detail the method for determining compilation optimization options, electronic device, and computer-readable storage medium provided in the present application in combination with the drawings.

[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 described herein, and may be embodied in different forms. On the contrary, the purpose of providing these embodiments is to make the present application clear and complete, and to allow those skilled in the art to fully understand the scope of the present application.

[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 specific embodiments and are not intended to limit the present application. As used herein, singular forms such as "a," "an," and "the" are also intended to include the plural unless the context clearly indicates 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 meaning of all terms (including technical and scientific terms) used herein is the same as that commonly understood by those skilled in the art. It will also be understood that terms defined in common dictionaries, unless otherwise specified herein, are to be interpreted as having a meaning consistent with the meaning in the context of the relevant art and this application, and are not to be interpreted as having an ideal or excessively formal meaning.

[0015] Before introducing the method for determining the compilation optimization option of 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 grammar 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 syntax 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, the syntax analysis module 102, and the 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 a target code according to the optimization result. The target code is an 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 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 (the input first source code is divided to obtain the second source code), that is, the plug-in 106 realizes the function of a prediction model described below. In addition, 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, so that the analysis target of the subsequent usage analysis module 101, syntax analysis module 102, and semantic analysis module 103 is not the first source code but the second 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, and may be implemented using code, i.e., by blending 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 realize the method of determining compilation optimization options of the embodiment of the present application.

[0021] FIG. 4 is a flow chart 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 a user or may be set as a default.

[0027] Operation 401: respectively obtain feature information corresponding to each second source code, and 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 a significantly better optimization effect than the default compilation optimization option (e.g., -02, -03, etc.) of the compiler.

[0031] In some exemplary embodiments, the feature information corresponding to each second source code is input into a pre-trained predictive model to obtain a first compilation optimization option corresponding to each second source code. In another exemplary embodiment, the feature information corresponding to each second source code and the target operating environment information corresponding to the second source code are input into a pre-trained predictive model to obtain a first compilation optimization option 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 Center Processing Unit (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 exemplary 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 exemplary embodiment, code optimization is performed on each second source code according to a 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 the different second source codes may be the same or different. If the first compilation optimization options corresponding to the different second source codes are different, the different second source codes need to be compiled using different first compilation optimization options.

[0037] In some demonstrative 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, 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 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 demonstrative embodiments, before splitting the first source code into at least one second source code according to a preset split level (i.e., operation 400), the method further includes: constructing a dataset including at least one data entry, each data entry including 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, wherein in the model training process, the feature information corresponding to the third source code is an input of the prediction model, and the second compilation optimization option is an output of the prediction model.

[0039] According to some exemplary embodiments of the present application, by applying the second compilation optimization option corresponding to the third source code to the compilation of the third source code, it is possible to obtain a significantly better optimization effect than the default compilation optimization option of the compiler (e.g., -02, -03, etc.). For example, in the following Table 1, 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 a better runtime performance than the normal compilation optimization options such as -03 when operating 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 option 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 option, and the target operating environment information corresponding to the third source code to obtain a predictive model, in which 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 option is an 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 illustrative 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 the connection weights between each neuron 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 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 the connection weights between each neuron 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 the embodiment of the present application, the third source code in all data entries in the dataset used for model training is source code in the same file, or the third source code in all data entries in the dataset used for model training is source code in the same function, or the third source code in some data entries in the dataset used for model training is source code in the same file, and the third source code in another part of data entries is source code in the same function. The embodiment of the present application is not limited to this.

[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 the vector is the same as the number of compilation optimization options in the compiler, and the value of an 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 the element.

[0053] In the embodiment of the present application, each compilation optimization option of the compiler may be numbered, and the number of the compilation optimization option is the same as the subscript of the element corresponding to the compilation optimization option. As shown in Table 2, the subscript may start from 0, and the number of the compilation optimization option may also start from 0. The vector in the first row shown in Table 1 may be represented 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 compilation optimization option state values ​​may include two state values, on and off, and may include other possible state values, for example, the "-fvect-cost-model" option may have three state values, unlimited, dynamic, and cheap.

[0056] The method for determining compilation optimization options provided by the embodiments of the present application does not perform prediction for a first source code in a lump, but divides the first source code according to a preset division level to obtain at least one second source code, and predicts the first compilation optimization option corresponding to the second source code based on a pre-trained prediction model for each second source code individually, thereby realizing more precise optimization of the compilation optimization option, so that the compilation output product corresponding to the software engineering has better running performance. Moreover, prediction based on the pre-trained prediction model does not require multiple compilations for the software engineering, does not require running the program to collect data, and shortens the optimization time of the compilation optimization option and improves the optimization efficiency.

[0057] FIG. 5 is a flow chart 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 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 a corresponding second compilation optimization option.

[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 a second compilation optimization option, or each of which includes feature information corresponding to the third source code, target operating environment information, and a second compilation optimization option.

[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 demonstrative 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 the embodiment of the present application, the third source code in all data entries in the dataset used for model training is source code in the same file, or the third source code in all data entries in the dataset used for model training is source code in the same function, or the third source code in some data entries in the dataset used for model training is source code in the same file, and the third source code in another part of 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, a 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: performing model training according to feature information corresponding to a third source code and a corresponding second compilation optimization option to obtain a prediction model. 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.

[0068] In some example embodiments, performing model training according to feature information corresponding to a 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, in which 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 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 illustrative 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 the connection weights between each neuron 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 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 the connection weights between each neuron 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.

[0072] In some example implementations, 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 the vector is the same as the number of compilation optimization options in the compiler, and the value of an 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 the element.

[0074] In the embodiment of the present application, each compilation optimization option of the compiler may be numbered, and the number of the compilation optimization option is the same as the subscript of the element corresponding to the compilation optimization option. As shown in Table 2, the subscript may start from 0, and the number of the compilation optimization option may also start from 0. The vector in the first row shown in Table 1 may be represented 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 compilation optimization option state values ​​may include two state values, on and off, and may include other possible state values, for example, the "-fvect-cost-model" option may 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 therein at least one program that, when executed by the at least one processor, realizes any one of the above-mentioned methods for determining a compilation optimization option or any one of the above-mentioned methods for training a model. A processor is a device having data processing capabilities, including but not limited to a central processor (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), 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 which, when executed by a processor, realizes 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 partitioning module 601 for partitioning a first source code into at least one second source code according to a preset partitioning 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 a compilation optimization option 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, in which 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.

[0084] In some exemplary 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, in which 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 demonstrative embodiments, the partitioning level includes a file level and the second source code includes source code in the same file, or the partitioning 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 the feature information corresponding to each second source code and the target operating environment information corresponding to the second source code into a pre-trained prediction model to obtain a first compilation optimization option 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 above-mentioned apparatus for determining compile optimization options is the same as the specific implementation process of the method for determining compile optimization options in the above-mentioned embodiment, and will not be described further here.

[0091] FIG. 7 is a configuration block diagram of a model training device according to an embodiment of the present application.

[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, in which 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.

[0093] In some exemplary 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, in which 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 above embodiment, so no further description will be given 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, and appropriate combinations 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 in cooperation. Some or all of the physical components can be implemented as software executed by a processor, such as a central processor, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as a dedicated integrated circuit. Such software can 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, etc.). Computer storage media includes, but is 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 know 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 the purpose of limitation. In some embodiments, the features, characteristics and / or elements described in combination with a particular embodiment may be used alone or in combination with the features, characteristics and / or elements described in combination with other embodiments, unless otherwise specified, as will be apparent to those skilled in the art. Thus, those skilled in the art will appreciate 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 preset division level; obtaining characteristic information corresponding to each of the second source codes; 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. How compilation optimization options are determined.

2. and code optimizing each of the second source codes in response to a first compilation optimization option corresponding to each of the second source codes. The method of determining a compilation optimization option according to claim 1 .

3. Prior to dividing the first source code into at least one second source code according to a predetermined division level, constructing a data set including at least one data entry, each said data entry including a third source code and a corresponding second compilation optimization option; obtaining characteristic information corresponding to the third source code in each of the data entries; and performing model training according to feature information corresponding to the 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. The method of determining a compilation optimization option according to claim 1 .

4. Prior to dividing the first source code into at least one second source code according to a predetermined division level, constructing a data set including at least one data entry, each said data entry including feature information corresponding to the third source code and corresponding second compilation optimization options; and performing model training according to feature information corresponding to the 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. The method of determining a compilation optimization option 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 a corresponding second compilation optimization option to obtain the prediction model; and performing model training according to feature information corresponding to the third source code, a second compilation optimization option corresponding thereto, and target operating environment information corresponding to the third source code to obtain the prediction model, in which 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 option is used as an output of the prediction model. A method for determining a compilation optimization option according to claim 3 or 4.

6. The third source code is Source code in the same file, or Contains source code for the same function A method for determining a compilation optimization option according to claim 3 or 4.

7. The preset split level includes a file level, and the second source code includes source code in the same file; or The predetermined decomposition level includes a function level, and the second source code includes source code in the same function. A method for determining a compilation optimization option according to any one of claims 1 to 4.

8. 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; 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. A method for determining a compilation optimization option according to any one of claims 1 to 4.

9. The target operating environment information includes hardware information and operating system environment information.

9. The method of determining compilation optimization options according to claim 8.

10. At least one processor; and a memory having stored thereon at least one program which, when executed by said at least one processor, implements the method for determining compilation optimization options according to any one of claims 1 to 9. electronic equipment.

11. A computer program is stored which, when executed by a processor, implements the method for determining compilation optimization options according to any one of claims 1 to 9. 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