Program compiling device and method
By inserting instrumentation programs during program compilation, function heat data is dynamically collected, and biased compilation is performed, which solves the problem that the compiler has difficulty in balancing performance and code size, and generates updated programs that better meet user expectations.
Patent Information
- Application Number
- CN202511419729.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-29
- Publication Date
- 2026-01-06
AI Technical Summary
When compiling a program, the compiler struggles to simultaneously optimize program performance and reduce code size, lacking reliable decision-making criteria, resulting in compilation results that fail to meet user needs.
By inserting instrumentation programs into the target program, the heat data of functions is dynamically collected, and a compilation strategy that favors performance optimization or code area compression is determined based on the heat data to generate an updated target program.
It achieves the goal of reducing code size without affecting program performance, or improving performance without increasing code size, thereby better meeting user needs.
Smart Images

Figure CN121277516A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a program compilation device and method. Background Technology
[0002] When compiling programs using a compiler, users often expect the compiler to output programs with high performance and small code size. However, for the compiler, performance optimization usually requires increasing the code size, while compressing the code may lead to performance loss. Therefore, in many scenarios, it is often impossible to achieve both high performance and small code size simultaneously when compiling programs using a compiler. Furthermore, there is a lack of reliable decision-making criteria when the compiler chooses between optimization strategies that prioritize high performance and those that prioritize small code size, resulting in a final compiled program that fails to adequately meet user needs. Summary of the Invention
[0003] This application provides a program compilation apparatus and method that facilitates the production of programs that better meet user expectations.
[0004] In a first aspect, this application provides a program compilation apparatus, comprising: a receiving module for receiving logs collected by an instrumentation program during the execution of a target program, wherein the instrumentation program is part of the target program and the logs include heat data of at least one function in the target program; and a compilation module for performing biased compilation on the target program based on the heat data of at least one function to obtain an updated target program, wherein the biased compilation includes compilation biased towards performance optimization operations or compilation biased towards code area compression operations.
[0005] In some possible implementations, before receiving logs collected by the instrumentation program during the execution of the target program, the compilation module is also used to compile the code to obtain the target program, which includes function call instructions and the instrumentation program associated with the function call instructions; the device also includes: a deployment module, used to deploy the target program so that during the execution of the target program, the instrumentation program records the number of times at least one function called by the function call instructions to obtain heat data.
[0006] In some possible implementations, the input parameter of the instrumentation program is the address of at least one function called by the function call instruction, and the heat data recorded by the instrumentation program includes a call count sequence, which describes the order of the number of calls to each function.
[0007] In some possible implementations, the compilation module is used to: generate tags for each function that match the popularity data based on the popularity data of at least one function; and perform biased compilation of the function call instructions of each function in the target program according to the tags of each function to obtain an updated target program.
[0008] In some possible implementations, the compilation module is used to: generate a first label for a function based on the popularity data of at least one function, where the popularity of the function represented by the popularity data reaches a reference threshold, the first label being used to represent biased performance optimization operations; and generate a second label for a function based on the popularity data of at least one function, where the popularity of the function represented by the popularity data does not reach the reference threshold, the second label being used to represent biased code area compression operations.
[0009] Secondly, a program compilation method is provided, the method comprising: receiving logs collected by an instrumentation program during the execution of a target program, wherein the instrumentation program is part of the target program, and the logs include heat data of at least one function in the target program; and performing biased compilation on the target program based on the heat data of at least one function to obtain an updated target program, wherein the biased compilation includes compilation biased towards performance optimization operations or compilation biased towards code area compression operations.
[0010] In some possible implementations, before receiving logs collected by the instrumentation program during the execution of the target program, the method further includes: compiling the code to obtain the target program, which includes function call instructions and instrumentation programs associated with the function call instructions; deploying the target program so that during the execution of the target program, the instrumentation program records the number of times at least one function called by the function call instructions is called, thereby obtaining heat data.
[0011] In some possible implementations, the input parameter of the instrumentation program is the address of at least one function called by the function call instruction, and the heat data recorded by the instrumentation program includes a call count sequence, which describes the order of the number of calls to each function.
[0012] Among some possible implementations, biased compilation of the target program is performed based on the popularity data of at least one function to obtain an updated target program. This includes: generating tags for each function that match the popularity data based on the popularity data of at least one function; and performing biased compilation of the function call instructions of each function in the target program according to the tags of each function to obtain an updated target program.
[0013] In some possible implementations, based on the popularity data of at least one function, tags matching the popularity data are generated for each function, including: based on the popularity data of at least one function, if the popularity of the function represented by the popularity data reaches a reference threshold, a first tag is generated for the function, and the first tag is used to represent biased performance optimization operations; based on the popularity data of at least one function, if the popularity of the function represented by the popularity data does not reach the reference threshold, a second tag is generated for the function, and the second tag is used to represent biased code area compression operations.
[0014] Thirdly, a computer device is provided, comprising a processor and a memory, wherein at least one computer program is stored in the memory, and the at least one computer program is loaded and executed by the processor, so that the computer device implements the program compilation method in the second aspect and any implementation thereof.
[0015] Fourthly, a computer-readable storage medium is also provided, which stores at least one computer program, which is loaded and executed by a processor to enable a computer to implement the program compilation method in the second aspect and any of its implementations.
[0016] Fifthly, a computer program product or computer program is also provided, comprising computer instructions stored in a computer-readable storage medium. The processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the program compilation method described in the second aspect and any implementation thereof.
[0017] In a sixth aspect, a chip is provided, comprising: an input interface, an output interface, a processor, and a memory, wherein the input interface, the output interface, the processor, and the memory are connected via an internal connection path, and the processor is used to execute code in the memory. When the code is executed, the processor is used to execute the program compilation method in the first aspect and any implementation thereof described above.
[0018] The technical solution provided in this application brings at least the following beneficial effects:
[0019] In this application, an instrumentation program is inserted into the target program. The instrumentation program can dynamically collect the heat data of each function in the target program during the execution of the target program, and then decide whether to select the program to be compiled with biased performance optimization or code area compression based on the heat data. This allows for better recompilation of the target program, achieving optimization and upgrade, and making the optimized and upgraded (i.e. updated) target program better meet user needs. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 This is a schematic diagram of an implementation environment provided in an embodiment of this application;
[0022] Figure 2 This is a structural diagram of a computer device provided in an embodiment of this application;
[0023] Figure 3 This is a structural diagram of a program compilation device provided in an embodiment of this application;
[0024] Figure 4 This is a schematic diagram of the execution flow of a target program provided in an embodiment of this application;
[0025] Figure 5 This is a schematic diagram of a target program upgrade process provided in an embodiment of this application;
[0026] Figure 6 This is a flowchart illustrating a program compilation method provided in an embodiment of this application. Detailed Implementation
[0027] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0028] A toolchain is a set of tools for various processor architectures (such as x86, ARM, and RISC-V, but not limited to these) used to compile, link, debug, and ultimately generate machine code that can run on the target processor from high-level programming language code (such as C, C++, and Rust). The toolchain is a core infrastructure for developing software (especially low-level or system-level software) and mainly includes, but is not limited to, compilers, assemblers, and linkers. The compiler is used to convert high-level programming language code into machine code.
[0029] Code size refers to the physical space occupied by the machine code generated by the toolchain in memory or storage media.
[0030] The performance of the machine code (hereinafter referred to as code or program code) generated by the toolchain is a crucial metric for measuring toolchain performance. This metric directly impacts the sales of Central Processing Unit (CPU) intellectual property (IP) modules, as users prefer CPU IP supported by high-performance toolchains. In other words, the higher the performance of the code generated by the toolchain, the better the code integrates with the CPU, and the faster the code runs on the CPU. Furthermore, the size of the code files output by the compiler in the toolchain directly affects the memory cost of the System on a Chip (SOC) integrating CPU IP. This is especially true for Microcontroller Unit (MCU) SOCs, where smaller code areas are more readily accepted by the market.
[0031] Therefore, users expect both high code performance and fast execution speed, as well as a small code size.
[0032] This application proposes a program compilation apparatus that, during program execution, uses instrumentation to statistically analyze the popularity of each function in the target program. Based on this popularity, the apparatus performs recompilation processing that prioritizes performance or minimizes code area, resulting in an updated target program. Through one or more iterations, the updated target program can better meet user expectations and requirements.
[0033] To facilitate understanding of the technical solutions of this application, the implementation environment provided by the embodiments of this application will be described below.
[0034] For example, Figure 1 A schematic diagram of an implementation environment provided in an embodiment of this application is shown. For example... Figure 1 As shown, the implementation environment may include a first device 01 and a second device 02. The first device 01 can act as a host, and the second device 02 can be used to host the target platform. The host is used to compile the program (also referred to herein as the target program) and deploy the compiled target program to the target platform for execution. The host can also recompile the program on the target platform to optimize or upgrade the target program.
[0035] As an example, the first device 01 can be at least one node in a physical machine, a virtualized device, an embedded device, or a computer cluster, wherein the virtualized device can be a virtual machine or a container, and the embedded device can be a development board, but is not limited thereto.
[0036] As an example, the target platform can be the platform or environment in which the target program runs. The target platform can be a processor, such as a fifth-generation Reduced Instruction Set Computer (RISC-V), x86, or Advanced RISC Machine (ARM) architecture processor, or it can be an embedded system (e.g., a microcontroller). The second device 02 that loads the target platform can be a physical machine, a virtualized device, an embedded device, or at least one node in a computer cluster.
[0037] In this cross-compilation scenario, the host compiles the target program for the target platform, and then deploys the target program to the target platform of the second device 02 for execution.
[0038] In other examples, the target program compiled on the host can also run on the same host, i.e., it is compiled locally.
[0039] Alternatively, the target platform can be a host-side processor, and the target program compiled on the host can be deployed to run on that target platform.
[0040] Next, a computer device provided in an embodiment of this application will be described.
[0041] For example, Figure 2 A schematic diagram of the structure of a computer device according to an embodiment of this application is shown. This computer device can be implemented as follows: Figure 1 The host shown is not limited to this. For example... Figure 2 As shown, the computer device 10 may include a processor 110, a memory 120, and a communication interface 130. The processor 110 may include a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), a Neural Network Processing Unit (NPU), a Tensor Processing Unit (TPU), a System-on-Chip (SOC), or other forms of processor with data processing and / or program execution capabilities. The processor 110 may be a general-purpose processor or a special-purpose processor. The processor 110 may be implemented as a single processor, a multi-core processor, and / or a cluster of processors arranged for parallel processing (which may include homogeneous and / or heterogeneous processor architectures). The processor 110 may be deployed in the computing device to control other components in the computing device to perform desired functions.
[0042] For example, compiler 1110 in toolchain 111 is responsible for converting the program's high-level programming language into assembly language, and then, through conversion operations by other tools, finally converting it into machine code adapted to the target platform (e.g., Riscv architecture). Toolchain 111 can be stored in memory 120 and invoked by processor 110 for operation. It should be noted that... Figure 2 The positions of toolchain 111 and compiler 1110 are for illustrative purposes only. Those skilled in the art should know that toolchain 111 and compiler 1110 are software, and their relationship with hardware is only illustrative and does not imply inclusion or deployment.
[0043] For example, memory 120 may include one or more forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. Volatile memory may include, for example, random access memory (RAM) and / or cache memory, which can be used as memory to provide corresponding storage space and directly exchange data with processor 110. Non-volatile memory may include, for example, read-only memory (ROM), hard disk, erasable programmable read-only memory (EPROM), portable compact disc read-only memory (CD-ROM), USB memory, flash memory, etc., for use as external storage. External storage can be used to store various applications and data, such as storing one or more computer program modules, which processor 110 can run to implement various functions of the computer device.
[0044] For example, the communication interface 130 can be a wired interface or a wireless interface, used to communicate with devices under the control of the processor 110. The wired interface can be an Ethernet interface, a controller area network (CAN) interface, a local interconnect network (LIN) interface, or a FlexRay interface, while the wireless interface can be a cellular network interface or a wireless LAN interface, etc. The wired or wireless interface allows the computer device 10 to communicate with other devices over a network to exchange data.
[0045] It should be noted that Figure 2 The structures shown are merely illustrative of the possible structures of a computer device 10 provided in this application embodiment, and are not intended to be the sole limitation on the structure or function of the computer device 10. In fact, the computer device 10 can be implemented in a manner more complex than... Figure 2 The structure shown may have more or fewer components.
[0046] The following describes a program compilation apparatus provided in an embodiment of this application.
[0047] For example, Figure 3 The diagram shows a schematic representation of a program compilation apparatus according to an embodiment of this application. The apparatus 300 can be implemented as follows: Figure 1 The host shown, or implemented as such Figure 2 The computer device 10, processor 110, or compiler 1110 shown are illustrated. Please refer to [link / reference]. Figure 3 The device 300 may include a receiving module 301 and a compilation module 302. The compilation module 302 will be described first below.
[0048] In this example, compiler module 302 can be used to compile code to obtain a target program. For example, compiler module 302 can compile high-level programming language code into a target program that can run on the target platform, and the target program can be binary machine code.
[0049] In this example, the target program may include multiple function call instructions and instrumentation code associated with those instructions. Each function call instruction can call at least one function. After compiling the function call instructions in the target program, the compiler module 302 can insert the corresponding instrumentation code into the target program to monitor the number of times functions are called during program execution, thereby determining the "hotness" of these functions.
[0050] One possible implementation is that the compiler module 302 inserts the instrumentation program into the target program using static instrumentation. For example, after compiling each function call instruction, a corresponding instrumentation program is inserted. The instrumentation program is the function entry point provided by the compiler module 302, and its input parameter is the address of the function called by the currently monitored function call instruction. In this way, the number of times each function call instruction calls a function can be precisely monitored, thereby obtaining the popularity data of each function.
[0051] For example, the device 300 may also include a deployment module 303. Figure 3 (Not specified in the text) The deployment module 303 can be used to deploy the target program so that during the execution of the target program, the instrumentation program records the number of times at least one function called by the function call instruction is called, thereby obtaining heat data.
[0052] In this example, after compilation module 302 compiles the target program, the deployment module 303 sends the target program to the target platform for deployment according to actual needs. Subsequently, during runtime, the target program will undergo the following processes... Figure 4The process is illustrated in step S41, where function call instructions in the target program are executed, calling the corresponding functions to complete the task. During this period, in step S42, the instrumentation program records the functions called by each function call instruction and the number of times each function is called, obtaining function popularity data. When step S43 determines that the target program has finished executing, a log containing the aforementioned popularity data is obtained.
[0053] For example, function popularity data can include a call count sequence, which describes the order in which functions are called. For instance, this call count sequence can be obtained by arranging the call counts of various functions in descending order using an instrumentation program. Therefore, the logs collected by the instrumentation program can provide a clear understanding of which functions have a high number of calls (i.e., hot data) and which functions have a low number of calls (i.e., non-hot data). In other words, hot data reflects the popularity of each function.
[0054] In this embodiment, the receiving module 301 of the device 300 can be used to receive logs collected by the instrumentation program during the execution of the target program. Specifically, the receiving module 301 can receive the logs collected by the instrumentation program after triggering an upgrade operation on the target program.
[0055] As an example, refer to Figure 5 In the upgrade process shown, in S51, the device 300 can determine whether to upgrade the target program process based on built-in upgrade trigger conditions. These conditions may include: the target platform or device running the target program entering a hibernation state, or being in the target program's periodic upgrade check phase, or the user agreeing to the target program upgrade reminder message pushed by the host. If the upgrade trigger condition is met, S52 is executed, initiating the upgrade operation for the target program. Thus, the device 300 can compile the target program without affecting its runtime, or when the user sets or agrees to the upgrade, completing the upgrade operation. Otherwise, S53 is executed, the target program is not upgraded, and the instrumentation program continues to collect logs during the target program's execution.
[0056] For example, after an upgrade operation is triggered, the log can be returned by the device running the target program. For instance, if the target program is running on the target platform, the log can be returned to the receiving module 301 by the second device 02 that loads the target platform. Alternatively, if the target platform is on the host side, the log can be directly collected by the receiving module 301 on the host. This will not be elaborated further.
[0057] For example, after receiving the logs collected by the instrumentation program, the receiving module 301 transmits the logs to the compilation module 302. The compilation module 302 can be used to perform biased compilation on the target program based on the popularity data of at least one function, to obtain an updated target program. Biased compilation refers to prioritizing one of the following compilation effects when faced with multiple compilation effects, such as improving performance or reducing code area: performance optimization or code area compression. Therefore, as an example and not a limitation, biased compilation can include compilation biased towards performance optimization or compilation biased towards code area compression. Performance optimization means prioritizing performance improvement and performing performance optimization operations during compilation; code area compression means prioritizing code area reduction and performing code area compression operations during compilation.
[0058] In this example, during the upgrade of the target program, the compiler module 302 can perform corresponding compilation processing on the function call instructions based on the number of function calls.
[0059] One possible implementation is that compiler module 302 can be used to generate tags for each function that match the popularity data based on popularity data for at least one function. As an example, these tags can be used to distinguish between hot and non-hot functions, or to distinguish the corresponding operations performed on hot and non-hot functions.
[0060] An example of this implementation is that the compilation module 302 generates a first label for a function based on the popularity data of at least one function, provided that the popularity of the function represented by the popularity data reaches a reference threshold. In other words, the compilation module 302 can identify functions whose popularity reaches the reference threshold (i.e., hot functions) based on the call count sequence recorded in the popularity data, and attach the first label to these hot functions. The reference threshold can be a custom call count threshold. This first label can be used to characterize performance optimization biases.
[0061] When the number of function calls reaches this reference threshold, it indicates that the function is called frequently, and the execution efficiency of this function will have a significant impact on the overall performance of the target program. In other words, if the function takes a long time to execute, each call will incur a large time overhead, greatly slowing down the overall running efficiency of the target program. To address this, the compiler module 302 attaches a first tag to such hot functions. Thus, when the compiler module 302 encounters a function call instruction for a hot function, it can determine, based on the first tag, which indicates that performance-oriented optimization operations are needed for that function call instruction, thereby significantly improving the overall running speed of the target program.
[0062] For example, compiler module 302 can use the `__attribute__` feature to attach tags to functions. `__attribute__` is an attribute specifier that provides compiler module 302 (or the compiler) with additional metadata, such as specifying function calling conventions and code behavior to control the storage method, alignment, and optimization behavior of variables, functions, or structures. Based on this, compiler module 302 uses `__attribute__` to attach corresponding tags to functions so that biased compilation matching the tags can be performed during subsequent compilation of the target program.
[0063] As examples, and not limitations, performance-optimized compilation operations can include inlining, loop unrolling, or instruction-level parallelism. Inlining replaces function call instructions with function bodies, reducing call overhead. Loop unrolling expands multiple iterations of a loop function call instruction into multiple consecutive, sequentially executed code segments, reducing the use of branch instructions and eliminating the performance penalty of failed branch predictions. Instruction-level parallelism utilizes parallel processing to improve instruction execution efficiency. These methods can achieve the goal of improving program compilation performance.
[0064] Furthermore, the compilation module 302 can also generate a second label for a function based on the popularity data of at least one function, provided that the popularity data indicates the function's popularity has not reached a reference threshold. In other words, when the popularity data indicates that a function is a non-hotspot function, the compilation module 302 attaches a second label to this non-hotspot function. This second label can be used to characterize biased code area compression operations. Since non-hotspot functions are called less frequently, their execution time has a smaller impact on the overall performance of the target program. In this case, code size optimization is more important because smaller code size can reduce memory usage and improve cache hit rate, thereby indirectly improving the performance of the target program. This is especially important for embedded systems or resource-constrained environments. Based on this, when the compilation module 302 encounters a function call instruction for a non-hotspot function, it can determine, based on the second label of the hotspot function, that the compilation of the function call instruction should undergo biased code area compression operations, thereby reducing the overall code area of the target program.
[0065] As examples, and not limitations, compilation practices biased towards code size reduction can include disabling inlining or loop unrolling, or using code shrinking, simplified symbol tables, or more compact instruction encoding. Code shrinking involves removing unused code and simplifying expressions. Simplifying symbol tables involves removing unnecessary debugging information. Using more compact instruction encoding means using shorter machine code to represent the same operations. This achieves the effect of reducing program compilation size.
[0066] In this way, after the compiler module 302 adds tags to each function, it can perform biased compilation on the function call instructions of each function in the target program according to the tags, resulting in an updated target program. The updated target program, also known as the upgraded target program, has undergone biased performance optimization operations based on the actual runtime conditions of the target program. While ensuring the overall running efficiency of the target program, it also performs code area compression operations on functions that meet certain conditions, i.e., non-hotspot functions. Therefore, from a user experience perspective, the target program has high execution efficiency and a small code area.
[0067] Furthermore, in this embodiment, the target program can be subjected to multiple rounds of log collection and optimized compilation based on the above principles, and continuous iterative optimization can be performed to obtain a program that better meets user expectations.
[0068] It should be noted that Figure 3 The structures shown are merely illustrative of the possible structures of a program compilation apparatus provided in the embodiments of this application, and are not intended to be the sole limitation on the structure or function of the program compilation apparatus. In fact, the program compilation apparatus can be implemented in a manner more complex than... Figure 3 The structure shown may have more or fewer components.
[0069] Next, a program compilation method provided by an embodiment of this application will be described.
[0070] For example, Figure 6 The diagram illustrates a flowchart of a program compilation method provided in an embodiment of this application. This method can be executed on any suitable device, equipment, platform, or computer cluster, for example... Figure 1 The host shown or Figure 2 It may be executed on the computer device shown, but is not limited to this.
[0071] like Figure 6 As shown, this method may include steps S610 to S620.
[0072] S610 receives logs collected by the instrumentation program during the execution of the target program. The instrumentation program is part of the target program, and the logs include heat data of at least one function in the target program.
[0073] In some possible implementations, before receiving the logs collected by the instrumentation program during the execution of the target program via S610, the method also includes S710 to S720 (…). Figure 6 (Not marked in the text).
[0074] S710 compiles the code to obtain the target program, which includes function call instructions and instrumentation programs that associate function call instructions.
[0075] S720 deploys the target program to record the number of times at least one function called by the function call instruction is called during the execution of the target program, thereby obtaining heat data.
[0076] In some possible implementations, the input parameter of the instrumentation program is the address of at least one function called by the function call instruction, and the heat data recorded by the instrumentation program includes a call count sequence, which describes the order of the number of calls to each function.
[0077] In this way, once the target program is deployed, the instrumentation program will collect relevant logs during its operation. During the target program upgrade phase, these logs can be collected via S610 to implement S620.
[0078] S620 performs biased compilation on the target program based on the heat data of at least one function to obtain an updated target program. Biased compilation includes compilation biased towards performance optimization operations or compilation biased towards code area compression operations.
[0079] In some possible implementations, S620 may include sub-steps S621 to S622.
[0080] S621, Based on the popularity data of at least one function, generate tags for each function that match the popularity data;
[0081] For example, S621 may include generating a first label for a function based on the popularity data of at least one function, whereby the popularity of the function represented by the popularity data reaches a reference threshold, and the first label is used to represent a biased performance optimization operation; or, generating a second label for a function based on the popularity data of at least one function, whereby the popularity of the function represented by the popularity data does not reach a reference threshold, and the second label is used to represent a biased code area compression operation.
[0082] S622 performs biased compilation on the function call instructions of each function in the target program according to the labels of each function, and obtains an updated target program.
[0083] By tagging each function, biased compilation can be performed on the function call instructions of each function in the target program based on these tags, resulting in an updated target program. This updated target program, also known as the upgraded target program, undergoes performance-optimized compilation based on the actual runtime conditions of the target program. While ensuring overall program efficiency, it also compresses the code area of function call instructions related to functions that meet certain conditions—that is, non-hotspot functions. Therefore, from a user experience perspective, the target program has high execution efficiency and a small code size.
[0084] Furthermore, in this embodiment, the target program can be subjected to multiple rounds of log collection and optimized compilation based on the above principles, that is, the steps S710 to S720 and S610 to S620 are executed repeatedly to continuously perform iterative optimization and obtain a program that better meets the user's expectations.
[0085] It should be noted that, for information regarding the function or beneficial effects of each step in the above-mentioned program compilation method, please refer to the relevant description of the program compilation device in the foregoing embodiments, which will not be repeated here.
[0086] In an exemplary embodiment, a computer device is also provided, comprising a processor and a memory, wherein at least one computer program is stored in the memory. The at least one computer program is loaded and executed by one or more processors to enable the computer device to implement any of the program compilation methods described above.
[0087] In an exemplary embodiment, a computer-readable storage medium is also provided, storing at least one computer program. This computer program is loaded and executed by a processor of a computer device to enable the computer to implement any of the aforementioned program compilation methods. The aforementioned computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a compact disc read-only memory (CD-ROM), magnetic tape, floppy disk, or optical data storage device, etc.
[0088] In an exemplary embodiment, a computer program product or computer program is also provided, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform any of the above-described program compilation methods.
[0089] It should be noted that all information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.), and signals involved in this application have been authorized by the user or fully authorized by all parties, and the collection, use, and processing of related data must comply with the relevant laws, regulations, and standards of the relevant countries and regions. For example, the calibration data involved in this application were all obtained under fully authorized conditions.
[0090] It should be understood that "multiple" as used in this article refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.
[0091] The above description is merely an exemplary embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the principles of this application should be included within the protection scope of this application.
Claims
1. A program compiling apparatus characterized by comprising: The apparatus comprises: a receiving module configured to receive logs collected by a probe program during running of a target program, the probe program being part of the target program, the logs comprising heat data of at least one function in the target program; a compiling module configured to perform biased compilation on the target program based on the heat data of the at least one function, to obtain an updated target program, the biased compilation comprising compilation biased towards performance optimization operation or compilation biased towards code area compression operation.
2. The apparatus of claim 1, wherein, Before the receiving module receives the logs collected by the probe program during running of the target program, the compiling module is further configured to perform code compilation to obtain the target program, the target program comprising function call instructions and the probe program associated with the function call instructions; the apparatus further comprises: a deploying module configured to deploy the target program to record, by the probe program, the number of times of calling the at least one function by the function call instructions during running of the target program, to obtain the heat data.
3. The apparatus of claim 2, wherein, An input parameter of the probe program is an address of the at least one function called by the function call instructions, the heat data recorded by the probe program comprises a sequence of the number of times of calling, the sequence of the number of times of calling describing an order of the number of times of calling each function.
4. The device according to any of claims 1-3, characterized in that The compiling module is configured to: generate a label matching the heat data for each function based on the heat data of the at least one function; perform biased compilation on function call instructions for calling each function in the target program according to the label of each function, to obtain the updated target program.
5. The apparatus of claim 4, wherein The compiling module is configured to: generate a first label for a function based on the heat data of the at least one function, in a case where the heat data represents that the heat of the function reaches a reference threshold, the first label being used to represent bias towards performance optimization operation; generate a second label for the function based on the heat data of the at least one function, in a case where the heat data represents that the heat of the function does not reach the reference threshold, the second label being used to represent bias towards code area compression operation.
6. A program compiling method characterized by comprising: The method comprises: receiving logs collected by a probe program during running of a target program, the probe program being part of the target program, the logs comprising heat data of at least one function in the target program; performing biased compilation on the target program based on the heat data of the at least one function, to obtain an updated target program, the biased compilation comprising compilation biased towards performance optimization operation or compilation biased towards code area compression operation.
7. The method of claim 6, wherein, Before the receiving module receives the logs collected by the probe program during running of the target program, the method further comprises: performing code compilation to obtain the target program, the target program comprising function call instructions and the probe program associated with the function call instructions; deploying the target program to record, by the probe program, the number of times of calling the at least one function by the function call instructions during running of the target program, to obtain the heat data.
8. The method of claim 7, wherein, An input parameter of the instrumentation program is an address of the at least one function called by the function call instruction, The hotness data recorded by the instrumentation program comprises a call frequency sequence, and the call frequency sequence describes a size order of call frequencies of the functions.
9. The method according to any one of claims 6-8, characterized in that, The biasing compilation of the target program based on the hotness data of the at least one function comprises: Generating a label matching the hotness data for each function based on the hotness data of the at least one function; Biasing compiling function call instructions of each function in the target program according to the label of each function to obtain the updated target program.
10. The method of claim 9, wherein, The generating of the label matching the hotness data for each function based on the hotness data of the at least one function comprises: Generating a first label of the function based on the hotness data of the at least one function, in a case where the hotness data represents that the hotness of the function reaches a reference threshold, and the first label is used to represent a biasing performance optimization operation; Generating a second label of the function based on the hotness data of the at least one function, in a case where the hotness data represents that the hotness of the function does not reach the reference threshold, and the second label is used to represent a biasing code area compression operation.
11. A computer readable storage medium, characterized in that, The computer readable storage medium stores at least one computer program, and the at least one computer program is loaded and executed by the processor to make the computer execute the method in any one of claims 6-10.