Compilation optimization method and system based on C + + virtual function

Through PGO optimization and branch prediction technology, the running probability of virtual functions is calculated and converted into branch prediction, which solves the problem of performance loss of C++ virtual functions, and achieves the reduction of overhead and performance improvement of virtual functions.

CN119493570APending Publication Date: 2025-02-21SHANDONG INSPUR SCI RES INST CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410853374.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-28
Publication Date
2025-02-21

AI Technical Summary

Technical Problem

The performance loss of C++ virtual functions is large. When the existing technology uses virtual function tables for implementation, it leads to the inability to apply the compilation optimization, limiting the compilation optimization space.

Method used

Running information is generated through PGO optimization, the running probability of virtual functions is calculated, and the indirect call of virtual functions to be optimized is converted into branch prediction for optimization.

Benefits of technology

Reduces the performance overhead of virtual functions and improves runtime performance through branch prediction optimization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119493570A_ABST
    Figure CN119493570A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, and discloses a C + + virtual function-based compiling optimization method and system, and the method comprises the steps: compiling a code, executing PGO optimization, and generating an executable file; running the generated executable file to generate running information; compiling the code again based on the operation information; based on the currently generated operation information, checking the calling times of the virtual functions with the same name, and calculating the operation probability of each virtual function; determining a virtual function to be optimized based on the operation probability of the virtual function; and converting indirect calling of the virtual function to be optimized into branch prediction so as to carry out optimization. According to the method, dynamic calling of the virtual function is converted into branch judgment, and then branch prediction is performed, so that the branch judgment continues to be optimized. In addition, through PGO optimization, when the probability that a certain specific virtual function is called exceeds a threshold value, the optimization is used, and therefore the purpose of reducing the overhead of the virtual function can be achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a compilation optimization method and system based on C++ virtual functions. Background Art

[0002] The C++ programming language is a powerful, object-oriented programming language that inherits the procedural programming features of the C language and adds concepts such as object-based programming, classes, encapsulation, inheritance, and polymorphism.

[0003] C++ supports object-oriented programming, has the advantages of high performance, support for multi-paradigm programming, rich operator overloading and function overloading, and is widely used in game development, system development, scientific computing and other fields.

[0004] Since C++ supports object-oriented programming, the use of virtual functions is essential. However, the use of virtual functions will result in a large performance loss, and solving the performance loss of virtual functions is a problem that the current C++ programming language needs to solve.

[0005] However, in the existing process of implementing virtual functions by using virtual function tables, the main disadvantage of using pointers to call virtual functions each time is that in addition to the additional overhead of looking up the virtual function table, it is also a major disadvantage that the specific virtual function to be called can only be determined at runtime. This causes many compiler optimizations to be unable to be applied in the context of this call, limiting the optimization space for compilation.

[0006] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present application, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention

[0007] In order to provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. The summary is not an extensive review, nor is it intended to identify key / critical components or delineate the scope of protection of these embodiments, but rather serves as a prelude to the detailed description that follows.

[0008] The compilation optimization method based on C++ virtual functions provided by the embodiment of the present disclosure includes:

[0009] Compile the code and perform PGO optimization to generate an executable file;

[0010] Run the generated executable file to generate running information;

[0011] Compile the code again based on the running information;

[0012] Based on the currently generated running information, check the number of times the virtual functions with the same name are called and calculate the running probability of each virtual function;

[0013] Based on the running probability of the virtual function, determine the virtual function to be optimized;

[0014] The indirect call of the virtual function to be optimized is converted into a branch prediction for optimization.

[0015] In some embodiments, compiling the code, performing PGO optimization, and generating an executable file includes:

[0016] Compile the code, perform PGO optimization to instrument the code, and generate an executable file.

[0017] In some embodiments, determining the virtual function to be optimized based on the running probability of the virtual function includes:

[0018] Based on the running probability of the virtual function, the virtual function exceeding a preset threshold is determined as the virtual function to be optimized.

[0019] In some embodiments, converting the indirect call of the virtual function to be optimized into a branch prediction for optimization includes:

[0020] The function address corresponding to the virtual function to be optimized found in the virtual function table is compared with the virtual function address of the virtual function to be optimized in each category. If they are the same, the virtual function to be optimized is directly called for optimization.

[0021] In some embodiments, the appeal method further comprises:

[0022] If the probability of the virtual function running is less than a preset threshold, the optimization of the virtual function is abandoned.

[0023] In some embodiments, the above-mentioned operation information includes hot spots of specific execution codes.

[0024] The compilation optimization system based on C++ virtual functions provided by the embodiment of the present disclosure includes:

[0025] Compilation module, used to compile the code, perform PGO optimization, and generate executable files;

[0026] A generation module is used to run the generated executable file and generate operation information;

[0027] The compiling module is further used to compile the code again based on the running information;

[0028] A processing module is used to check the number of times virtual functions with the same name are called based on the currently generated running information, and calculate the running probability of each virtual function;

[0029] The processing module is further used to determine the virtual function to be optimized based on the running probability of the virtual function;

[0030] The processing module is also used to convert the indirect call of the virtual function to be optimized into branch prediction for optimization.

[0031] In some embodiments, compiling the code, performing PGO optimization, and generating an executable file includes:

[0032] Compile the code, perform PGO optimization to instrument the code, and generate an executable file.

[0033] In some embodiments, determining the virtual function to be optimized based on the running probability of the virtual function includes:

[0034] Based on the running probability of the virtual function, the virtual function exceeding a preset threshold is determined as the virtual function to be optimized.

[0035] The compilation optimization method and system based on C++ virtual functions provided by the embodiments of the present disclosure can achieve the following technical effects:

[0036] Because the performance of virtual functions in C++ is a problem criticized by users, compilers generally use virtual function tables to support virtual functions. However, due to the fact that they can only run dynamically, indirect calls are required, which results in the inability to perform compilation optimization. The present invention converts dynamic calls to virtual functions into branch judgments. Although this increases the overhead of branch judgments, the compiler will perform branch predictions based on the characteristics of CPU pipeline operation, thereby continuing to optimize branch judgments. In addition, through PGO optimization, the compiler will analyze the hot spots of the source code. When the probability of a specific virtual function being called exceeds a threshold set in advance, this optimization will be used, thereby achieving the purpose of reducing the overhead of virtual functions.

[0037] The above general description and the following description are exemplary and explanatory only and are not intended to limit the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] One or more embodiments are exemplarily described by corresponding drawings, which do not limit the embodiments. Elements with the same reference numerals in the drawings are shown as similar elements, and the drawings do not constitute a scale limitation, and wherein:

[0039] Figure 1 It is a flowchart of a compilation optimization method based on C++ virtual functions provided by an embodiment of the present disclosure;

[0040] Figure 2It is a flowchart of another compilation optimization method based on C++ virtual functions provided by an embodiment of the present disclosure;

[0041] Figure 3 It is an implementation diagram of a virtual function table provided by an embodiment of the present disclosure;

[0042] Figure 4 It is a specific embodiment effect diagram of a compilation optimization method based on C++ virtual function provided by the embodiment of the present disclosure;

[0043] Figure 5 It is a structural diagram of a compilation optimization system based on C++ virtual functions provided by an embodiment of the present disclosure;

[0044] Figure 6 It is a schematic diagram of another structure of a compilation optimization system based on C++ virtual functions provided by an embodiment of the present disclosure. DETAILED DESCRIPTION

[0045] In order to be able to understand the features and technical contents of the embodiments of the present disclosure in more detail, the implementation of the embodiments of the present disclosure is described in detail below in conjunction with the accompanying drawings. The attached drawings are for reference only and are not used to limit the embodiments of the present disclosure. In the following technical description, for the convenience of explanation, a full understanding of the disclosed embodiments is provided through multiple details. However, one or more embodiments can still be implemented without these details. In other cases, to simplify the drawings, well-known structures and devices can be simplified for display.

[0046] The terms "first", "second", etc. in the embodiments of the present disclosure are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged where appropriate, so as to describe the embodiments of the present disclosure described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions.

[0047] Unless otherwise stated, the term "plurality" means two or more.

[0048] In the embodiment of the present disclosure, the character " / " indicates that the preceding and following objects are in an "or" relationship. For example, A / B indicates: A or B.

[0049] The term "and / or" is a description of the association relationship between objects, indicating that three relationships can exist. For example, A and / or B means: A or B, or, A and B.

[0050] The term "correspondence" may refer to an association relationship or a binding relationship. The correspondence between A and B means that there is an association relationship or a binding relationship between A and B.

[0051] The following describes a video edge detection method and system based on a vector matrix operation acceleration core provided by an embodiment of the present disclosure in conjunction with the accompanying drawings.

[0052] Figure 1 is a flow chart of a compilation optimization method based on C++ virtual functions provided by an embodiment of the present disclosure, such as Figure 1 As shown, the compilation optimization method based on C++ virtual function may include:

[0053] S101, compile the code and perform PGO optimization to generate an executable file;

[0054] S102, running the generated executable file to generate running information;

[0055] S103, compile the code again based on the running information;

[0056] S104, based on the currently generated running information, checking the number of times the virtual function with the same name is called, and calculating the running probability of each virtual function;

[0057] S105, determining a virtual function to be optimized based on the running probability of the virtual function;

[0058] S106, converting the indirect call of the virtual function to be optimized into branch prediction for optimization.

[0059] Figure 2 is a flowchart of another C++ virtual function-based compilation optimization method provided by the present disclosure, combined with Figure 2 right Figure 1 The compilation optimization method based on C++ virtual functions is continued to be described.

[0060] In some embodiments, compiling the code, performing PGO optimization, and generating an executable file includes:

[0061] Compile the code, perform PGO optimization to instrument the code, and generate an executable file.

[0062] In some embodiments, determining the virtual function to be optimized based on the running probability of the virtual function includes:

[0063] Based on the running probability of the virtual function, the virtual function exceeding a preset threshold is determined as the virtual function to be optimized.

[0064] In some embodiments, converting an indirect call of a virtual function to be optimized into a branch prediction for optimization includes:

[0065] The function address corresponding to the virtual function to be optimized found in the virtual function table is compared with the virtual function address of the virtual function to be optimized in each category. If they are the same, the virtual function to be optimized is directly called for optimization.

[0066] In some embodiments, Figure 1 The method may also include:

[0067] If the probability of the virtual function running is less than a preset threshold, the optimization of the virtual function is abandoned.

[0068] In some embodiments, the above-mentioned operation information may include hot spots of specific execution codes.

[0069] In a specific example, Figure 3 This is a diagram of a virtual function table implementation provided by the embodiment of the present disclosure. The implementation mechanism of virtual functions in mainstream compilers generally uses virtual function tables. The virtual function table is a key mechanism for implementing virtual functions and C++ polymorphism, which allows us to dynamically decide which function to call at runtime. The implementation mechanism of the virtual function table is as follows Figure 3 Taking the example of calling a virtual function with a pointer, the specific steps to implement a virtual function by using a virtual function table are as follows:

[0070] 1. First, construct an object using a base class or a subclass, and assign the address of the object to the base class pointer.

[0071] 2. Use the base class pointer to call the virtual function defined in the base class.

[0072] 3. Taking a 32-bit operating system as an example, the first 4 bytes of the memory pointed to by the base class pointer are pointers to the virtual function table. The virtual function table is constructed by the compiler. The location of the virtual function table is generally in the code segment. This virtual function table is bound to the class. The virtual function table stores the function pointers of the virtual functions defined in this class and its parent class. The virtual function implemented by the subclass will overwrite the virtual function of the base class with the same name and the same parameters.

[0073] 4. The base class pointer searches for a specific virtual function through the virtual function table. When the virtual function found is consistent with the virtual function to be called, the virtual function pointer is called to implement the virtual function.

[0074] exist Figure 3 In the corresponding steps above, the main disadvantage of using a pointer to call a virtual function each time is that in addition to the additional overhead of looking up the virtual function table, the need to determine which virtual function to call at runtime is also a major disadvantage, because it causes many compiler optimizations to be unable to be applied in the context of this call, thus limiting the optimization space for compilation.

[0075] Based on the underlying mechanism and main disadvantages of using virtual functions shown above, the present invention proposes an optimization method for C++ virtual functions. Specifically, the address of the virtual function that can only be called at runtime is optimized to be predicted in the compiler. With the help of the branch prediction optimization means and PGO optimization means in the compiler, the CPU performs branch prediction. If the prediction is correct, the runtime performance will be greatly improved. If the prediction fails, negative feedback will be generated. Therefore, PGO optimization needs to be performed in advance. The process of this method is as follows Figure 2 As shown, the specific steps are as follows:

[0076] 1. First, compile the code and perform PGO optimization, which will instrument the code during compilation and then generate an executable file.

[0077] 2. Run the generated executable file. Because the code was instrumented during compilation, an information file will be generated when the code is run. The file records the running information of the code, such as the hot spots of the specific execution code.

[0078] 3. Compile the code again and optimize the code using the previously generated runtime information file. Many optimization methods in the compiler will use this runtime information file.

[0079] 4. The optimization method proposed in the present invention will also use the currently generated operation information file to check the number of times the virtual function with the same name is called and calculate the operation probability of each virtual function.

[0080] 5. When the probability of a virtual function running exceeds the set threshold, it will be optimized. Indirect calls will no longer be used in the generated instructions. Instead, the indirect calls of this virtual function will be converted into branch predictions. In simple terms, the function address found in the virtual function table is compared with the virtual function address of this virtual function in each category. If they are the same, the virtual function is called directly.

[0081] 6. If the probability of each virtual function running is less than the set threshold, the optimization of this virtual function is abandoned, where the threshold is the preset threshold.

[0082] The above steps complete the compilation optimization of C++ virtual functions. The core of this disclosure is to compile the code, turn on PGO optimization, and then run the executable program to collect source code information, such as hot functions, and generate specific information files. Compile the source code again, and then use the information file to analyze the probability of virtual functions defined in each class. If the running probability of a virtual function exceeds the set threshold, it will be converted into branch processing and optimized by means of branch prediction.

[0083] Beneficial effects of the present invention: Since the performance of virtual functions in C++ is a problem criticized by users, compilers generally use virtual function tables to support virtual functions. However, due to the fact that they can only run dynamically, indirect calls are required, which results in the inability to perform compilation optimization. The present invention converts dynamic calls to virtual functions into branch judgments. Although this increases the overhead of branch judgments, the compiler will perform branch predictions based on the characteristics of CPU pipeline operation, thereby continuing to optimize branch judgments. In addition, through PGO optimization, the compiler will analyze the hot spots of the source code. When the probability of a specific virtual function being called exceeds a threshold set in advance, this optimization will be used, thereby achieving the purpose of reducing the overhead of virtual functions.

[0084] Figure 4 It is a specific embodiment effect diagram of a compilation optimization method based on C++ virtual functions provided by an embodiment of the present disclosure.

[0085] Combination Figure 4 In a specific example, the input C++ source code is as follows:

[0086] class Base{

[0087] public:

[0088] virtual void fun(){

[0089] std::cout<<"Base fun"< <std::endl;

[0090] }

[0091] };

[0092] class Derive:public Base{

[0093] public:

[0094] virtual void fun(){

[0095] std::cout<<"Derive fun"< <std::endl;

[0096] }

[0097] };

[0098] int main(){

[0099] Base*p=nullptr;

[0100] Base*p_array

[10000] ;

[0101] for(int i=0;i<10000;++i){

[0102] if (i%100==0){

[0103] p = new Base();

[0104] }else{

[0105] p = new Derive();

[0106] }

[0107] p_array[i] = p;

[0108] }

[0109] for(int i=0; i<10000; ++i)

[0110] p_array[i]->fun();

[0111] return 0;

[0112] }

[0113] The compiler first compiles the input C++ source code. At this time, the PGO option is turned on. The compiler will insert stubs into the input source code and generate an executable program after the compilation is completed. Then, when the executable program is executed, a specific information file will be generated. This information file stores the information of the source code at runtime, including the hot functions.

[0114] Compile the input C++ source code again, and do not open the PGO option by default. At this time, the information file generated by the last execution of the program will be imported during the compilation process. This optimization mainly uses the number of virtual function version calls recorded in the information file. Taking the source code input this time as an example, the number of virtual functions executed is 10,000 times, the number of Base::fun functions called is 1,000 times, the call probability is 10%, and the number of Derive::fun functions called is 9,000 times, and the call probability is 90%. If the optimization threshold of the virtual function set by the present invention is 90%, then this optimization will be performed, that is, the indirect call of the virtual function that can only be determined at runtime will be converted into a branch judgment, and then branch prediction will be performed at compile time. The pseudo code of the generated branch prediction is as follows:

[0115] for(int i=0;i<10000;++i){

[0116] addr=p_array[i]->vtable.fun.addr;

[0117] if (addr == Derive:: fun)

[0118] Derive::fun();

[0119] else if (addr == Base:: fun)

[0120] Base::fun();

[0121] else

[0122] error();

[0123] }

[0124] Although the branch judgment code is added at this time, the branch prediction optimization will be performed later. Because the running probability of the first branch is 90%, the Derive::fun function will be executed first most of the time in the CPU execution pipeline, and only 10% of the time will get negative feedback. In addition, inlining and other optimizations can be performed later based on this optimization, so the overall positive benefits are considerable.

[0125] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present disclosure is not limited by the order of the actions described, because according to the present disclosure, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present disclosure.

[0126] and Figure 1 Corresponding to the compilation optimization method based on C++ virtual functions, the present disclosure also provides a compilation optimization system based on C++ virtual functions.

[0127] Figure 5 is a schematic diagram of a structure of a compilation optimization system based on C++ virtual functions provided by an embodiment of the present disclosure, such as Figure 5 As shown, the system includes:

[0128] Compilation module 501, used to compile the code, perform PGO optimization, and generate an executable file;

[0129] A generating module 502, used to run the generated executable file and generate running information;

[0130] The compiling module 501 is further used to compile the code again based on the running information;

[0131] The processing module 503 is used to check the number of times the virtual function with the same name is called based on the currently generated running information, and calculate the running probability of each virtual function;

[0132] The processing module 503 is further used to determine the virtual function to be optimized based on the running probability of the virtual function;

[0133] The processing module 503 is further used to convert the indirect call of the virtual function to be optimized into a branch prediction for optimization.

[0134] In some embodiments, compiling the code, performing PGO optimization, and generating an executable file includes:

[0135] Compile the code, perform PGO optimization to instrument the code, and generate an executable file.

[0136] In some embodiments, determining the virtual function to be optimized based on the running probability of the virtual function includes:

[0137] Based on the running probability of the virtual function, the virtual function exceeding a preset threshold is determined as the virtual function to be optimized.

[0138] In some embodiments, converting the indirect call of the virtual function to be optimized into a branch prediction for optimization includes:

[0139] The function address corresponding to the virtual function to be optimized found in the virtual function table is compared with the virtual function address of the virtual function to be optimized in each category. If they are the same, the virtual function to be optimized is directly called for optimization.

[0140] In some embodiments, the processing module 503 may also be configured to abandon the optimization of the virtual function if the probability of the virtual function running is less than a preset threshold.

[0141] In some embodiments, the execution information includes hot spots of specific execution codes.

[0142] Combination Figure 6 As shown, the embodiment of the present disclosure provides another compilation optimization system 600 based on C++ virtual functions, including a processor 604 and a memory 601. Optionally, the system may also include a communication interface 602 and a bus 603. Among them, the processor 604, the communication interface 602, and the memory 601 can communicate with each other through the bus 603. The communication interface 602 can be used for information transmission. The processor 604 can call the logic instructions in the memory 601 to execute the compilation optimization method based on C++ virtual functions of the above embodiment.

[0143] In addition, the logic instructions in the memory 601 described above can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.

[0144] The memory 601 is a computer-readable storage medium that can be used to store software programs and computer executable programs, such as program instructions / modules corresponding to the method in the embodiment of the present disclosure. The processor 604 executes the function application and data processing by running the program instructions / modules stored in the memory 601, that is, implementing the compilation optimization method based on C++ virtual functions in the above embodiment.

[0145] The memory 601 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 601 may include a high-speed random access memory and may also include a non-volatile memory.

[0146] An embodiment of the present disclosure provides a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are configured to execute a compilation optimization method based on C++ virtual functions.

[0147] The computer-readable storage medium mentioned above may be a transient computer-readable storage medium or a non-transitory computer-readable storage medium.

[0148] The technical solution of the embodiment of the present disclosure can be embodied in the form of a software product, which is stored in a storage medium and includes one or more instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method of the embodiment of the present disclosure. The aforementioned storage medium may be a non-transient storage medium, including: a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a disk or an optical disk, and other media that can store program codes, or a transient storage medium.

[0149] The above description and the accompanying drawings fully illustrate the embodiments of the present disclosure so that those skilled in the art can practice them. Other embodiments may include structural, logical, electrical, process and other changes. The embodiments represent possible changes only. Unless explicitly required, separate components and functions are optional, and the order of operations may vary. Parts and features of some embodiments may be included in or replace parts and features of other embodiments. As used in the description of the embodiments, unless the context clearly indicates otherwise, the singular forms of "a", "an" and "the" are intended to include plural forms as well. Similarly, the term "and / or" as used in this application refers to any and all possible combinations of one or more associated listings. In addition, when used in this application, the term "comprise" and its variants "comprises" and / or including (comprising) refer to the existence of stated features, wholes, steps, operations, elements, and / or components, but do not exclude the existence or addition of one or more other features, wholes, steps, operations, elements, components and / or these groups. In the absence of further restrictions, the elements defined by the sentence "comprising a ..." do not exclude the existence of other identical elements in the process, method or device comprising the elements. In this article, each embodiment may focus on the differences from other embodiments, and the same or similar parts between the embodiments may refer to each other. For the methods, products, etc. disclosed in the embodiments, if they correspond to the method part disclosed in the embodiments, then the relevant parts can refer to the description of the method part.

[0150] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software may depend on the specific application and design constraints of the technical solution. Technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the embodiments of the present disclosure. Technicians can clearly understand that for the convenience and simplicity of description, the specific working process of the systems, devices and units described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0151] In the embodiments disclosed herein, the disclosed methods and products (including but not limited to devices, equipment, etc.) can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units can be only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between each other shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms. The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to implement this embodiment. In addition, each functional unit in the embodiment of the present disclosure may be integrated in a processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit.

[0152] The flowchart and block diagram in the accompanying drawings show the possible architecture, functions and operations of the system, method and computer program product according to the embodiment of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and a part of the module, program segment or code contains one or more executable instructions for realizing the specified logical function. In some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. In the description corresponding to the flowchart and block diagram in the accompanying drawings, the operations or steps corresponding to different boxes can also occur in a different order from the order disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. Each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented by a dedicated hardware-based system that performs the specified functions or actions, or may be implemented by a combination of dedicated hardware and computer instructions.

Claims

1. A compilation optimization method based on C++ virtual functions, characterized in that: The method comprises: Compile the code and perform PGO optimization to generate an executable file; Run the generated executable file to generate running information; Compile the code again based on the running information; Based on the currently generated running information, check the number of times the virtual functions with the same name are called and calculate the running probability of each virtual function; Based on the running probability of the virtual function, determine the virtual function to be optimized; The indirect call of the virtual function to be optimized is converted into branch prediction for optimization.

2. The method according to claim 1, characterized in that The code is compiled, PGO optimization is performed, and an executable file is generated, including: Compile the code, perform PGO optimization to instrument the code, and generate an executable file.

3. The method according to claim 1, characterized in that The step of determining the virtual function to be optimized based on the running probability of the virtual function includes: Based on the running probability of the virtual function, the virtual function exceeding a preset threshold is determined as the virtual function to be optimized.

4. The method according to claim 1, characterized in that: The step of converting the indirect call of the virtual function to be optimized into branch prediction for optimization includes: The function address corresponding to the virtual function to be optimized found in the virtual function table is compared with the virtual function address of the virtual function to be optimized in each category. If they are the same, the virtual function to be optimized is directly called for optimization.

5. The method according to claim 1, characterized in that The method further comprises: If the probability of the virtual function running is less than a preset threshold, the optimization of the virtual function is abandoned.

6. The method according to claim 1, characterized in that The running information includes hot spots of specific execution codes.

7. A compilation optimization system based on C++ virtual functions, characterized in that: The system comprises: Compilation module, used to compile the code, perform PGO optimization, and generate executable files; A generation module is used to run the generated executable file and generate operation information; The compiling module is further used to compile the code again based on the running information; A processing module is used to check the number of times virtual functions with the same name are called based on the currently generated running information, and calculate the running probability of each virtual function; The processing module is further used to determine the virtual function to be optimized based on the running probability of the virtual function; The processing module is also used to convert the indirect call of the virtual function to be optimized into branch prediction for optimization.

8. The system according to claim 7, characterized in that The code is compiled, PGO optimization is performed, and an executable file is generated, including: Compile the code, perform PGO optimization to instrument the code, and generate an executable file.

9. The system according to claim 7, characterized in that The step of determining the virtual function to be optimized based on the running probability of the virtual function includes: Based on the running probability of the virtual function, the virtual function exceeding a preset threshold is determined as the virtual function to be optimized.