Register allocation method and device, electronic equipment and computer readable storage medium
By selecting the optimal register allocation algorithm for each execution body in GCC for register allocation, the problem of GCC ignoring other algorithms during compilation is solved, and the execution speed of the program and the reliability of the compilation effect are improved.
Patent Information
- Application Number
- CN202411288570.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-13
- Publication Date
- 2024-12-03
AI Technical Summary
When GCC compiles a program, it will ignore other algorithms after selecting the register allocation algorithm, resulting in different register allocation results generated by different algorithms, which will affect the program execution speed.
During the program compilation process, the optimal register allocation algorithm is determined for each execution body. By comparing the evaluation index values of each algorithm, the algorithm with the optimal allocation result is selected for register allocation, and the results are saved in the preset structure and deleted The results of other algorithms to improve execution speed.
By using the optimal register allocation algorithm for register allocation, the execution speed of the program is improved, and the reliability of the compilation effect and execution reliability are improved.
Smart Images

Figure CN119065677A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of program compilation, and in particular to a register allocation method, device, electronic device and computer-readable storage medium. Background Art
[0002] GCC (GNU Compiler Collection) is a programming language compiler that can compile program source code written in multiple programming languages such as C, C++, Fortran and Go into executable programs on the target machine. When GCC compiles a program, it uses a register allocation algorithm to allocate program variables to registers in the program.
[0003] Currently, GCC supports multiple algorithms including the CB (Chaitin-Briggs, a heuristic graph coloring algorithm) algorithm and the priority algorithm (a priority-based register allocation algorithm). However, when compiling a program, once a register allocation algorithm is selected, other algorithms will be completely ignored during the compilation process. However, using different register allocation algorithms may produce different register allocation results, resulting in different execution speeds of the final compiled program. Therefore, based on the current solution, there is still room for improvement in program execution speed. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a register allocation method, device, electronic device and computer-readable storage medium to improve program execution speed.
[0005] An embodiment of the present application provides a register allocation method, comprising: during a program compilation process, determining a target register allocation algorithm corresponding to a target executable body in the program; wherein: the target executable body is an executable body currently performing register allocation in the program; the executable body is a function in the program or a variable allocation area within a function; the target register allocation algorithm is a register allocation algorithm with an optimal algorithm evaluation index value among various preset register allocation algorithms; the algorithm evaluation index value represents an allocation level of variables in the target executable body under the register allocation algorithm; and saving a register allocation result of register allocation to the target executable body using the target register allocation algorithm.
[0006] Based on the above implementation scheme, the optimal register allocation algorithm can be used for register allocation for each executable body in the program. In this way, when the entire program is compiled, since the register allocation result of each executable body in the program is obtained by the register allocation algorithm with the highest allocation level among the register allocation algorithms relative to the executable body, when the program is executed, the execution speed of each executable body in the program will be the best among the cases after register allocation according to the register allocation algorithms. Compared with the case where the entire program can only use a single register allocation algorithm for register allocation, the execution speed of the program can undoubtedly be optimized after register allocation using the above implementation scheme of the present application. That is, compared with the case where the entire program can only use a single register allocation algorithm for register allocation, the execution speed of the program can be improved after register allocation using the above implementation scheme of the present application.
[0007] Further, the determining of the target register allocation algorithm corresponding to the target executable body in the program includes: using each of the register allocation algorithms to perform register allocation on the target executable body respectively, and obtaining the register allocation results and algorithm evaluation index values corresponding to the target executable body under each of the register allocation algorithms; wherein the register allocation algorithm with the best algorithm evaluation index value is the target register allocation algorithm; saving the register allocation results of register allocation on the target executable body using the target register allocation algorithm includes: saving the register allocation results corresponding to the target register allocation algorithm in a preset structure, and deleting the register allocation results corresponding to each of the register allocation algorithms except the target register allocation algorithm.
[0008] In the above implementation, registers are allocated to the target execution body using each register allocation algorithm respectively, and the register allocation results and algorithm evaluation index values corresponding to the target execution body under each register allocation algorithm are obtained, and then only the register allocation results corresponding to the target register allocation algorithm with the highest algorithm evaluation index value are saved in the preset structure, and the register allocation results corresponding to each register allocation algorithm other than the target register allocation algorithm are deleted. In this way, it is possible to accurately obtain which register allocation algorithm is the target register allocation algorithm relative to the target execution body, thereby improving the reliability of the scheme. At the same time, the register allocation results of each register allocation algorithm are retained, and after the target register allocation algorithm is determined, only the register allocation results corresponding to the target register allocation algorithm with the highest algorithm evaluation index value are saved in the preset structure, and the register allocation results corresponding to each register allocation algorithm other than the target register allocation algorithm are deleted, so as to avoid the situation where the target register allocation algorithm needs to be reused to re-allocate registers to the target execution body in the future, saving overhead.
[0009] Further, the register allocation algorithm includes a first register allocation algorithm and at least one second register allocation algorithm; each of the register allocation algorithms is used to perform register allocation on the target execution body, and the register allocation result and algorithm evaluation index value corresponding to the target execution body under each of the register allocation algorithms are obtained, including: creating a structure copy of the structure for each of the second register allocation algorithms; using the first register allocation algorithm to perform register allocation on the target execution body, and storing the register allocation result in the structure; using each of the second register allocation algorithms to perform register allocation on the target execution body, and storing the register allocation result in the structure copy of each of the second register allocation algorithms; saving the register allocation result corresponding to the target register allocation algorithm with the best algorithm evaluation index value in a preset structure, and deleting the register allocation results corresponding to each of the register allocation algorithms except the target register allocation algorithm, including: if the target register allocation algorithm with the best algorithm evaluation index value is the first register allocation algorithm, then deleting all of the structure copies; if the target register allocation algorithm with the best algorithm evaluation index value is a second register allocation algorithm, then replacing the data in the structure with the data in the structure copy of the second register allocation algorithm, and deleting all of the structure copies.
[0010] It can be understood that for program compilation, the register allocation result needs to be stored in a specified structure (i.e., the preset structure described in this application) according to the requirements of the compiler. In the above implementation, by storing the register allocation result corresponding to the first register allocation algorithm in the preset structure, and storing the register allocation result corresponding to each second register allocation algorithm in the structure copy created for each second register allocation algorithm, and then when the target register allocation algorithm is the first register allocation algorithm, directly delete each structure copy, and when the target register allocation algorithm is a second register allocation algorithm, use the data in the structure copy of the second register allocation algorithm to replace the data in the preset structure, and delete all structure copies, so that by setting the structure copy, while saving the register allocation results corresponding to all register allocation algorithms, the register allocation result corresponding to the target register allocation algorithm that is finally retained can be correctly stored in the preset structure, thereby improving the reliability of the program compilation effect and improving the execution reliability of the compiled program.
[0011] Further, the algorithm evaluation index value includes a first algorithm evaluation index value and a second algorithm evaluation index value; determining the target register allocation algorithm corresponding to the target executable body in the program includes: obtaining a preliminary screening register allocation algorithm with the best first algorithm evaluation index value; if there is only one preliminary screening register allocation algorithm, determining the preliminary screening register allocation algorithm as the target register allocation algorithm; if there are multiple preliminary screening register allocation algorithms, using the preliminary screening register allocation algorithm with the best second algorithm evaluation index value as the target register allocation algorithm.
[0012] In the above implementation, a primary screening is performed based on the first algorithm evaluation index value. When there are multiple primary screening register allocation algorithms, a secondary screening is performed based on the second algorithm evaluation index value. In this way, the target register allocation algorithm can be quickly screened.
[0013] Furthermore, the algorithm evaluation index value includes a first algorithm evaluation index value and a second algorithm evaluation index value; determining the target register allocation algorithm corresponding to the target executable body in the program includes: calculating the comprehensive evaluation index value corresponding to each of the register allocation algorithms according to the first algorithm evaluation index value and the second algorithm evaluation index value corresponding to each of the register allocation algorithms; and taking the register allocation algorithm with the best comprehensive evaluation index value as the target register allocation algorithm.
[0014] In the above implementation, a comprehensive evaluation index value is obtained by combining the first algorithm evaluation index value and the second algorithm evaluation index value, and then a target register allocation algorithm is determined based on the comprehensive evaluation index value, so that the target register allocation algorithm obtained has the best comprehensive performance.
[0015] Furthermore, the first algorithm evaluation index value corresponding to each of the register allocation algorithms is: the number of overflow registers existing when each of the register allocation algorithms is used to allocate registers to the target execution body; the second algorithm evaluation index value corresponding to each of the register allocation algorithms is: the allocation cost existing when each of the register allocation algorithms is used to allocate registers to the target execution body.
[0016] In the above implementation, it is found through analysis and experiments that the number of overflow registers existing when register allocation is performed and the allocation cost existing when register allocation is performed can better reflect the register allocation level performed by the register allocation algorithm. Therefore, by using the number of overflow registers existing when register allocation is performed and the allocation cost existing when register allocation is performed as the first algorithm evaluation index value and the second algorithm evaluation index value respectively, the register allocation level of each register allocation algorithm when performing register allocation on the target execution body can be better reflected, thereby making the selected target register allocation algorithm more accurate.
[0017] Furthermore, determining the target register allocation algorithm corresponding to the target executable body in the program includes: inputting the characteristics of the target executable body into a pre-trained classification model to obtain the algorithm evaluation index value of each register allocation algorithm relative to the target executable body; the algorithm evaluation index value is the probability that the target executable body output by the classification model corresponds to each category; each category is each register allocation algorithm; and the register allocation algorithm with the best algorithm evaluation index value is used as the target register allocation algorithm.
[0018] In the above implementation, since the classification model learns the intrinsic relationship between the intrinsic features of the execution body and the register allocation algorithm to be used, and the result output speed is also fast after the classification model training is completed, the target register allocation algorithm can be determined more accurately and quickly by setting the classification model.
[0019] Furthermore, the characteristics of the target executable body include at least one of the following: the number of code blocks of the target executable body; the number of branches in the target executable body; the number of instructions of the target executable body; the intermediate representation of the target executable body generated during the compilation process; and the calling relationship of the target executable body in the program.
[0020] In the above implementation, by taking at least one of the number of code blocks of the target execution body, the number of branches in the target execution body, the number of instructions of the target execution body, the intermediate representation generated by the target execution body during the compilation process, the calling relationship of the target execution body in the program, etc. as the characteristics of the target execution body, these characteristics are directly or indirectly related to the register allocation requirements of the target execution body, so these characteristics are used as model inputs to make the determined target register allocation algorithm more accurate.
[0021] Furthermore, during the program compilation process, determining the target register allocation algorithm corresponding to the target executable body in the program includes: obtaining identification information of the program; obtaining a target correspondence relationship associated with the identification information from a preset storage body according to the identification information; the target correspondence relationship includes a pre-stored correspondence relationship between each executable body in the program and the target register allocation algorithm of each executable body; and determining the target register allocation algorithm corresponding to the target executable body from the target correspondence relationship.
[0022] In the above implementation, by storing the determined correspondence between each executable body and the target register allocation algorithm corresponding to each executable body in a preset storage body, during the program compilation process, when it is determined based on the identification information of the program that a target correspondence already exists for the program, the target register allocation algorithm corresponding to the target executable body can be quickly determined directly based on the target correspondence. In this process, there is no need to pre-allocate different register allocation algorithms, nor is there a need to use a classification model for identification, and the efficiency of determining the target register allocation algorithm is faster.
[0023] Furthermore, the register allocation algorithm includes a CB algorithm and a priority algorithm.
[0024] Furthermore, before the program is compiled, the method further includes: determining to adopt an algorithm optimization mode.
[0025] In the above implementation, by setting the algorithm optimization mode, the user can freely choose whether to adopt the algorithm optimization mode and then execute the solution provided by the embodiment of the present application, thereby improving the flexibility of the solution.
[0026] The embodiment of the present application also provides a register allocation device, including: a determination module, used to determine the target register allocation algorithm corresponding to the target executable body in the program during the program compilation process; wherein: the target executable body is the executable body currently performing register allocation in the program; the executable body is a function in the program or a variable allocation area within the function; the target register allocation algorithm is the register allocation algorithm with the best algorithm evaluation index value among the preset register allocation algorithms; the algorithm evaluation index value represents the allocation level of the variables in the target executable body under the register allocation algorithm; and a processing module, used to save the register allocation result of using the target register allocation algorithm to allocate registers to the target executable body.
[0027] An embodiment of the present application also provides an electronic device, including a processor and a memory; the processor is used to execute one or more programs stored in the memory to implement any of the above-mentioned register allocation methods.
[0028] An embodiment of the present application also provides a computer-readable storage medium, which stores one or more programs. The one or more programs can be executed by one or more processors to implement any of the above-mentioned register allocation methods. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0030] Figure 1 A basic flow chart of a register allocation method provided in an embodiment of the present application;
[0031] Figure 2 A schematic diagram of a specific flow chart of a register allocation method provided in an embodiment of the present application;
[0032] Figure 3 A schematic diagram of the number of overflow registers and allocation cost of the hotspot function when the CB and priority algorithms are used for the 503.bwaves_r load respectively provided in an embodiment of the present application;
[0033] Figure 4 A schematic diagram of the number of overflow registers and allocation cost of the shell function when the 503.bwaves_r load uses the CB and priority algorithms respectively, provided in an embodiment of the present application;
[0034] Figure 5 A schematic diagram of a flow chart of a target register allocation algorithm provided in an embodiment of the present application;
[0035] Figure 6 A schematic diagram of the structure of a register allocation device provided in an embodiment of the present application;
[0036] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0037] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0038] Register allocation is a method of allocating program variables to physical registers in the target machine as much as possible, thereby improving the execution speed of the program. Register allocation algorithm is an algorithm that implements register allocation.
[0039] Currently, when GCC compiles a program, once a register allocation algorithm is selected in the register allocation process, other algorithms will be completely ignored during the compilation process. Using different register allocation algorithms may produce different register allocation results, resulting in different execution speeds of the compiled program. However, research has found that different register allocation algorithms may also produce different register allocation results for different executables in the same program, resulting in different execution speeds of different executables in the compiled program. Therefore, there is still room for improvement in program execution speed based on the current solution.
[0040] The executable body in the program may be a function in the program, or a variable allocation area in a function in the program. In the embodiment of the present application, the variable allocation area in the function may be a loop structure in the function.
[0041] In order to improve the execution speed of the compiled program, an embodiment of the present application provides a register allocation method, which allocates registers to each executable body in the program separately by adopting a register allocation algorithm that is more suitable for each executable body in the program, thereby making the register allocation of the entire program more reasonable, and further making the execution speed of the compiled program higher.
[0042] See also Figure 1 As shown, Figure 1 A basic flow chart of the register allocation method provided in the embodiment of the present application includes:
[0043] S101: During program compilation, a target register allocation algorithm corresponding to a target executable body in the program is determined.
[0044] Among them: the target executable body is the executable body currently performing register allocation in the program; the target register allocation algorithm is the register allocation algorithm with the best algorithm evaluation index value among the preset register allocation algorithms; the algorithm evaluation index value represents the allocation level of variables in the target executable body under the register allocation algorithm.
[0045] In the embodiment of the present application, the higher the variable allocation level is, the more reasonable the result of the algorithm allocating variables in the execution body to physical registers is.
[0046] S102: Save the register allocation result of register allocation for the target execution body using the target register allocation algorithm.
[0047] In an embodiment of the present application, the register allocation result corresponding to the target register allocation algorithm of the executable body is saved for each executable body in the program. In this way, after the program is compiled, the register allocation results obtained by each executable body in the program are all the results obtained by using the register allocation algorithm that is optimal for each executable body. Then, when the program is executed, the execution speed of each executable body in the program will be the best among the cases where registers are allocated according to each register allocation algorithm. Then, compared to the case where the entire program can only use a single register allocation algorithm for register allocation, the execution speed of the program can undoubtedly be optimized after register allocation is performed using the above implementation scheme of the present application. That is, compared to the case where the entire program can only use a single register allocation algorithm for register allocation, the execution speed of the program can be improved after register allocation is performed using the above implementation scheme of the present application.
[0048] In a feasible implementation of the embodiment of the present application, see Figure 2 As shown:
[0049] The specific method of step S101 may include:
[0050] S201: Using each register allocation algorithm to allocate registers to a target execution body, respectively, to obtain a register allocation result and an algorithm evaluation index value corresponding to the target execution body under each register allocation algorithm.
[0051] Among them, the register allocation algorithm with the best algorithm evaluation index value is the target register allocation algorithm.
[0052] The specific method of step S102 may include:
[0053] S202: Save the register allocation result corresponding to the target register allocation algorithm in a preset structure, and delete the register allocation results corresponding to each register allocation algorithm except the target register allocation algorithm.
[0054] In the embodiment of the present application, the preset structure is a required structure of the compiler.
[0055] In this way, by using each register allocation algorithm to allocate registers to the target execution body, and obtaining the register allocation results and algorithm evaluation index values corresponding to the target execution body under each register allocation algorithm, only the register allocation results corresponding to the target register allocation algorithm with the highest algorithm evaluation index value are saved in the preset structure, and the register allocation results corresponding to each register allocation algorithm other than the target register allocation algorithm are deleted. In this way, it is possible to accurately obtain which register allocation algorithm is the target register allocation algorithm relative to the target execution body, thereby improving the reliability of the solution. At the same time, the register allocation results of each register allocation algorithm are retained, and after the target register allocation algorithm is determined, only the register allocation results corresponding to the target register allocation algorithm with the highest algorithm evaluation index value are saved in the preset structure, and the register allocation results corresponding to each register allocation algorithm other than the target register allocation algorithm are deleted. This can avoid the situation where the target register allocation algorithm needs to be reused to re-allocate registers to the target execution body in the future, saving overhead.
[0056] Optionally, in an embodiment of the present application, multiple register algorithms may be divided into a first register allocation algorithm and at least one second register allocation algorithm.
[0057] At this time, when executing step S201, a structure copy of the preset structure can be created for each second register allocation algorithm, and then the first register allocation algorithm is used to allocate registers to the target execution body, and the register allocation results are stored in the preset structure, and each second register allocation algorithm is used to allocate registers to the target execution body, and the register allocation results are stored in the structure copies of each second register allocation algorithm.
[0058] When executing step S202, if the target register allocation algorithm with the best algorithm evaluation index value is the first register allocation algorithm, all structure copies can be directly deleted, and only the register allocation result of the first register allocation algorithm can be retained; if the target register allocation algorithm with the best algorithm evaluation index value is a second register allocation algorithm, the data in the structure copy of the second register allocation algorithm is used to replace the data in the structure, and all structure copies are deleted.
[0059] In this way, by storing the register allocation result corresponding to the first register allocation algorithm in a preset structure, and storing the register allocation result corresponding to each second register allocation algorithm in the structure copy created for each second register allocation algorithm, and then when the target register allocation algorithm is the first register allocation algorithm, directly delete each structure copy, and when the target register allocation algorithm is a second register allocation algorithm, use the data in the structure copy of the second register allocation algorithm to replace the data in the preset structure, and delete all structure copies. In this way, by setting the structure copy, while saving the register allocation results corresponding to all register allocation algorithms, the register allocation result corresponding to the target register allocation algorithm that is finally retained can be correctly stored in the preset structure, thereby improving the reliability of the program compilation effect and the execution reliability of the compiled program.
[0060] It can be understood that in another feasible implementation of the embodiment of the present application, after using each register allocation algorithm to allocate registers to the target execution body respectively, only the algorithm evaluation index value corresponding to each register allocation algorithm can be saved. After determining the target register allocation algorithm with the optimal algorithm evaluation index value, the target register allocation algorithm is used to allocate registers to the target execution body, and then the register allocation result of the target register allocation algorithm is saved in a preset structure.
[0061] In an embodiment of the present application, the algorithm evaluation index value includes a first algorithm evaluation index value and a second algorithm evaluation index value. When determining the target register allocation algorithm corresponding to the target executable body in the program based on the first algorithm evaluation index value and the second algorithm evaluation index value, the determination of the target register allocation algorithm can be achieved in at least the following two ways:
[0062] Method 1: Obtain the preliminary screening register allocation algorithm with the best first algorithm evaluation index value. If there is only one preliminary screening register allocation algorithm, determine the preliminary screening register allocation algorithm as the target register allocation algorithm; if there are multiple preliminary screening register allocation algorithms, determine the preliminary screening register allocation algorithm with the best second algorithm evaluation index value as the target register allocation algorithm.
[0063] It can be understood that based on the first method, the target register allocation algorithm may be directly obtained based on the first algorithm evaluation value, so the target register allocation algorithm can be determined at a higher speed. In addition, based on the first method, it can be ensured that the first algorithm evaluation index value of the selected target register allocation algorithm is optimal, so it is suitable for the situation where the first algorithm evaluation index value has a greater impact on the register allocation result.
[0064] Method 2: Calculate the comprehensive evaluation index value corresponding to each register allocation algorithm according to the first algorithm evaluation index value and the second algorithm evaluation index value corresponding to each register allocation algorithm, and use the register allocation algorithm with the best comprehensive evaluation index value as the target register allocation algorithm.
[0065] Based on the second method, a comprehensive evaluation index value is obtained by combining the first algorithm evaluation index value and the second algorithm evaluation index value, and then a target register allocation algorithm is determined based on the comprehensive evaluation index value. The target register allocation algorithm obtained in this way has the best comprehensive performance.
[0066] In method 2, considering that the first algorithm evaluation index value and the second algorithm evaluation index value may belong to different dimensions and have different measurement units, and therefore cannot be directly integrated, the first algorithm evaluation index value and the second algorithm evaluation index value can be normalized first to eliminate the measurement difference, and then the normalized first algorithm evaluation index value and the second algorithm evaluation index value can be integrated respectively.
[0067] In the second method, the comprehensive method includes but is not limited to weighted summation, wherein the weight can be set during engineering according to the influence of each algorithm evaluation index value on the register allocation result.
[0068] In a feasible implementation of the embodiment of the present application, the first algorithm evaluation index value corresponding to each register allocation algorithm may be: the number of overflow registers existing when each register allocation algorithm is used to allocate registers to the target execution body.
[0069] The second algorithm evaluation index value corresponding to each register allocation algorithm may be: an allocation cost existing when each register allocation algorithm is used to allocate registers to a target execution body.
[0070] It can be understood that the first algorithm evaluation index value and the second algorithm evaluation index value used in the above-mentioned feasible implementation mode are obtained through analysis and experiments. These two algorithm evaluation index values can better reflect the register allocation level performed by the register allocation algorithm, so that the number of overflow registers existing when performing register allocation and the allocation cost existing when performing register allocation are used as the first algorithm evaluation index value and the second algorithm evaluation index value respectively, which can better reflect the register allocation level of each register allocation algorithm when performing register allocation for the target execution body, thereby making the selected target register allocation algorithm more accurate.
[0071] The analysis and experimental process are as follows:
[0072] The CB algorithm and priority algorithm commonly used in GCC are used as analysis objects, and the color_allocnos function that implements the CB algorithm and the priority algorithm in the GCC source code is analyzed. Among them, the color_allocnos function is an allocation meta-coloring function, which implements the function of allocating physical registers or memory for variables in the program through the graph coloring algorithm. In the GCC source code, this function contains the execution code of the CB and priority algorithms.
[0073] The compiler determines the value of the variable flag_ira_algorithm (the value of this variable indicates which register allocation algorithm to use). When the value of flag_ira_algorithm is IRA_ALGORITHM_PRIORITY, it indicates that the priority algorithm is used for register allocation. The code analysis of the priority algorithm is as follows:
[0074] First, traverse the allocation element (the allocation element is a data structure used to describe register allocation information in the GCC code, and is also the basic unit for describing register allocation). If the register type corresponding to the allocation element is NO_REGS (indicating that it does not contain any registers), the virtual register corresponding to the allocation element (that is, the variable in the execution body, one variable corresponds to one virtual register) will be overflowed, and then the setup_allocno_priorities function (a function that establishes a priority for the allocation element) and the qsort function (a sorting function) are used to establish priorities and sort the allocation elements, and registers are allocated according to priority, and those that cannot be allocated will overflow.
[0075] When the value of flag_ira_algorithm is IRA_ALGORITHM_CB, it indicates that the CB algorithm is used for register allocation. The code analysis of the CB algorithm is as follows:
[0076] First, through the form_allocno_hard_regs_nodes_forest function (physical register node forest establishment function, which builds the physical registers into a forest, and then allocates a node in the forest for each allocation element), a physical register node forest (a forest composed of multiple physical registers) is established for the allocation element, and the allocation element is traversed. If the corresponding register type in the allocation element is NO_REGS or it is not profitable to allocate a physical register, the virtual register corresponding to the allocation element will be overflowed, otherwise the cost is updated, and then the allocation element is placed in the corresponding colorable bucket or non-colorable bucket, and then the push_allocnos_to_stack function (allocation element stack function) is executed to push the allocation element into the shading stack, and finally the pop_allocnos_from_stack function (allocation element pop function) is executed to pop the allocation elements from the shading stack one by one, and those that cannot be allocated will overflow.
[0077] From the similarities and differences of the two algorithm codes, in the color_allocnos function, there are two register overflows in the CB algorithm branch: one is when the register type is NO_REGS or the allocation of physical registers is unprofitable, and the other is when the coloring is not possible in the pop_allocnos_from_stack function; and there are also two register overflows in the priority algorithm branch: one is when the register type is NO_REGS, and the other is during the priority allocation process. The rest of the code in the color_allocnos function, such as the improve_allocation function (used to further improve the allocation from the perspective of cost), is executed by both algorithms, and the number of register overflows can most intuitively compare the register allocation in the unified register allocation process. Therefore, it is believed that the sum of the two register overflows in the CB branch and the sum of the two register overflows in the priority branch can reflect the difference between the two algorithm branches and can be used as an indicator to compare the advantages and disadvantages of the two algorithms.
[0078] In an embodiment of the present application, the number of register types judged as NO_REGS or the number of physical registers that are unprofitable to allocate before coloring during the execution of the CB algorithm is counted and can be stored in the cb_spill_num variable. The number of register overflows in the pop_allocnos_from_stack function is counted and can be stored in the cb_pop_spill_num variable. The sum of the two can be stored in the sum_cb variable.
[0079] In an embodiment of the present application, the number of registers judged as NO_REGS during the execution of the priority algorithm is counted and can be stored in the p_spill_num variable, and the number of registers overflowed during the priority allocation process is counted and can be stored in the p_qsort_assign_mem_num variable, and the sum of the two can be stored in the sum_p variable.
[0080] At the same time, in order to further enrich and improve the algorithm evaluation index value, in an embodiment of the present application, the allocation cost of the region after using the CB algorithm and the priority algorithm can be statistically analyzed based on the function calculate_allocation_cost for calculating the allocation cost in the unified register allocation, and stored in the cb_ira_overall_cost and p_ira_overall_cost variables. The allocation cost is the sum of the memory allocation cost and the register allocation cost.
[0081] To illustrate the selection of the evaluation index values of the above algorithm and the basis for algorithm design, according to the performance test results of SPEC CPU 2017, the 503.bwaves_r load, which has a large performance gap when using the CB and priority algorithms, is selected to analyze its hotspot functions. The perf command (perf is a performance analysis tool under the Linux system, which can display the proportion of CPU time spent by each function by analyzing the collected performance data) is used to output the hotspot function of the 503.bwaves_r load, and the hotspot function is mat_times_vec. In order to obtain more data, the shell function, which accounts for the second largest proportion, is also analyzed.
[0082] According to the .ira output file in the unified register allocation process (the file output after the unified register allocation is completed, which records the information of the unified register allocation process), the relevant data of the 503.bwaves_r load when using the CB and priority algorithms are counted, such as Figure 3 and 4As shown (in the figure, -O3-fira-algorithm=CB(4.29) represents the CB algorithm, and -O3-fira-algorithm=priority(4.49) represents the priority algorithm). From the results, we can see that in more loops (variable allocation areas), sum_cb and sum_p are equal. If the CB algorithm is used by default at this time, the CB algorithm will be selected when sum_cb and sum_p are equal. This may make the algorithm selection more biased towards CB, which will cause an imbalance in the algorithm selection, resulting in most or even all loops using the CB algorithm. However, from the data information, we can see that when sum_cb and sum_p are equal, their respective allocation costs are not necessarily the same. Therefore, on the basis of judging the number of overflow registers, we can further judge the register allocation algorithm to be used based on the allocation cost. Figure 4 Taking loop20 and loop21 as an example, when the number of overflow registers is equal, if no further comparison is made based on the allocation cost, the CB algorithm will be selected by default. After further comparison of their respective allocation costs cb_ira_overall_cost and p_ira_overall_cost, the priority algorithm will be selected.
[0083] In summary, it can be seen from analysis and experiments that using the number of overflow registers existing when register allocation and the allocation cost existing when register allocation as the first algorithm evaluation index value and the second algorithm evaluation index value respectively can make the selected target register allocation algorithm more accurate.
[0084] In another possible implementation of the embodiment of the present application, see Figure 5 As shown, executing step S101 can also be implemented in the following manner:
[0085] S501: Input the characteristics of the target executable body into a pre-trained classification model to obtain algorithm evaluation index values of each register allocation algorithm relative to the target executable body.
[0086] S502: Using the register allocation algorithm with the best algorithm evaluation index value as the target register allocation algorithm.
[0087] It can be understood that after the characteristics of the target executable body are input into the classification model, the classification model will output the probability that the target executable body corresponds to each category. In the embodiment of the present application, each category is a register allocation algorithm. For example, there are two types of target register allocation algorithms, the CB algorithm and the priority algorithm. The classification model can be a two-classification model, one class represents the CB algorithm, and the other class represents the priority algorithm. After the characteristics of the target executable body are input into the classification model, the classification model will output the probability that the target executable body belongs to the CB algorithm and the probability that it belongs to the priority algorithm. The probability output by the classification model is the algorithm evaluation index value of each register allocation algorithm relative to the target executable body in this feasible implementation mode.
[0088] It can also be understood that some classification models will eventually directly output the category with the highest probability. In this case, essentially, the above steps S501 and S502 are directly executed within the classification model.
[0089] In the embodiment of the present application, the characteristics of the target execution body may include at least one of the following:
[0090] The number of code blocks in the target executable;
[0091] The number of branches in the target executable;
[0092] The number of instructions in the target executable;
[0093] The intermediate representation of the target executable generated during the compilation process;
[0094] The calling relationship of the target executable in the program.
[0095] Optionally, the characteristics of the target executable may include all of the above characteristics.
[0096] It can be understood that these features are directly or indirectly related to the register allocation requirements of the target executable body, so using these features as model inputs can make the determined target register allocation algorithm more accurate.
[0097] In the embodiment of the present application, the classification model needs to be trained. When training the classification model, the target register algorithm corresponding to each sample execution body in each sample program can be obtained based on the above-mentioned method of using each register allocation algorithm to allocate registers to the target execution body, and then annotated and input into the classification model for training.
[0098] In another feasible implementation of the embodiment of the present application, when executing step S101, the identification information of the program may be obtained first, and then the target correspondence relationship associated with the identification information may be obtained from the preset storage body according to the identification information, and finally the target register allocation algorithm corresponding to the target executable body may be determined from the target correspondence relationship. Among them, the target correspondence relationship includes the correspondence relationship between each executable body in the pre-stored program and the target register allocation algorithm of each executable body. In this way, there is no need to pre-allocate different register allocation algorithms in the process, nor is there a need to use a classification model for identification, and the efficiency of determining the target register allocation algorithm is faster.
[0099] In the embodiment of the present application, the identification information of the program includes but is not limited to the program name, the program unique code, etc.
[0100] In the above feasible implementation manner, if the target corresponding relationship associated with the identification information cannot be obtained from the preset storage body according to the identification information, the above Figure 2 or Figure 5 The method introduced determines the target register allocation algorithm corresponding to the target executable.
[0101] In the above feasible implementation mode, based on the above Figure 2 or Figure 5 After the target register allocation algorithm corresponding to the target execution body is determined by the method introduced, the determined target execution body and the target register allocation algorithm can be associated and saved in a corresponding relationship, and the corresponding relationship can be associated with the identification information of the program, thereby enriching the corresponding relationship in the preset storage body, and providing a basis for directly obtaining the target register allocation algorithm based on the corresponding relationship in the future.
[0102] In the embodiment of the present application, an algorithm optimization mode can also be set. When the user adopts the algorithm optimization mode, the register algorithm selection scheme provided in the embodiment of the present application is executed, otherwise the program is compiled according to the existing method.
[0103] To facilitate understanding of the solution of the embodiment of the present application, the following is an example of a register allocation algorithm including a CB algorithm and a priority algorithm, and the first algorithm evaluation index value is: the number of overflow registers when registers are allocated to the target execution body using each register allocation algorithm; the second algorithm evaluation index value is: the allocation cost when registers are allocated to the target execution body using each register allocation algorithm; the execution body is a variable allocation area (hereinafter referred to as an area) as an example, and the solution of the embodiment of the present application is exemplarily described:
[0104] After entering the color_allocnos function, first create corresponding copies of some variables involved in the coloring process, such as creating a copy of the allocation meta-information variable ira_allocnos, new_ira_allocnos, and at the same time create corresponding copies of some global variables used by both register allocation algorithms, such as creating a copy store_allocated_hardreg_p for the variable allocated_hardreg_p that stores the allocation physical register information. In the actual code, new_X represents the corresponding copy variable involved in the coloring process, and store_X represents the copy of the corresponding global variable, where X represents the original variable name. Then, the CB and priority algorithms are applied to pre-allocate registers respectively. The original variables and global variables are modified in the pre-allocation process using the CB algorithm, and the copy variables and copy global variables are modified in the pre-allocation process using the priority algorithm. After the two pre-allocations are completed, the better register allocation algorithm is selected according to the value of the algorithm evaluation index as the target register allocation algorithm actually used in the region. If the CB algorithm is selected, the values of the original variables and global variables are kept. If the priority algorithm is selected, the values of the original variables and global variables are updated using new_X and store_X.
[0105] The so-called pre-allocation refers to the process of using each register allocation algorithm to allocate registers to the target executable body before determining the target register allocation algorithm of the target executable body.
[0106] Among them, a parameter option is added in the compiler, and when the value IRA_ALGORITHM_BOTH is used, it indicates that the algorithm optimization mode is adopted.
[0107] When flag_ira_algorithm is judged to be IRA_ALGORITHM_BOTH, the scheme of the embodiment of the present application is selected for register allocation. The add_new_ira_allocnos function (a function for creating a copy) creates copies of the related structures ira_allocnos, ira_copies and allocno_add_data (i.e., the structures preset in the present application, wherein ira_allocnos represents the allocation element structure, ira_copies represents the structure with a copy relationship between two allocation elements, and allocno_add_data represents the additional information of the allocation element, such as the structure of the information used during shading), etc. The store_global_variables function (used to pass in the original global variables, which can be used to create copies of global variables) creates copies of global variables such as allocno_priorities (allocation element priority), sorted_allocnos (allocation elements arranged by priority) and allocated_hardreg_p (a variable indicating whether a physical register is used or not) used by both CB and priority algorithms. Then use the priority algorithm for pre-allocation and get the values of p_spill_num, p_qsort_assign_mem_num and p_ira_overall_cost. After the priority algorithm is executed, use the restore_global_variables function (replace the modification information of the global variables by the priority algorithm with the previously created copy, that is, restore the value of the global variable to the initial value before the execution of the priority algorithm, and save the value of the global variable after the execution of the priority algorithm) and the restore_objects function (replace the modification information of the structure ira_object related content by the priority algorithm with the previously created copy, ira_object is a structure related to the allocation element conflict information) to temporarily store the modification information of the global variables and the structure ira_object related content by the priority algorithm, and restore it to the initial value. Use the CB algorithm for pre-allocation and get the values of cb_spill_num, cb_pop_spill_num and cb_ira_overall_cost.
[0108] The number of register overflows is used as the first-level algorithm evaluation index value for judgment. When sum_p is less than sum_cb, the priority algorithm is determined to be used as the final allocation algorithm, and the relevant results temporarily stored in the pre-allocation process of the priority algorithm are used to replace each variable; when sum_cb is less than sum_p, the CB algorithm is determined to be used as the final allocation algorithm (no replacement is required at this time); when sum_p is equal to sum_cb, the second-level algorithm evaluation index value is further judged. When p_ira_overall_cost is less than cb_ira_overall_cost, the priority algorithm is determined to be used as the final allocation algorithm, and the relevant results temporarily stored in the pre-allocation process of the priority algorithm are used to replace each variable, otherwise the CB algorithm is used as the final allocation algorithm (no replacement is required at this time), and finally the free_new_ira_allocnos function is used to release the space of each created structure variable copy.
[0109] In order to analyze the impact of the above scheme of the embodiment of the present application on performance, the performance benchmark tool SPEC CPU 2017 was used for testing, and the performance results of each integer and floating-point load after using the CB algorithm, the priority algorithm and the algorithm of the present application (denoted as both) were summarized to obtain the following Table 1 (integer load test results) and Table 2 (floating-point load test results):
[0110] Table 1
[0111]
[0112] Table 2
[0113]
[0114]
[0115] The comparison shows that when the CB algorithm and the priority algorithm are used for integer loads, the performance gap is not obvious on most loads. After using the preferred both algorithm, the performance is close to the original performance, avoiding low scores. The total score of the floating-point type using both algorithms is 4.4% higher than that using the CB algorithm, and 2.6% higher than that using the priority algorithm. The highest increase is 43.6% on the 503.bwaves_r load, 2.8% on the 507.cactuBSSN_r load, and 8.1% on the 549.fotonik3d_r load. The performance improvement is more significant than that of the integer load, and the performance improvement effect is more obvious for the load whose programming language is Fortran.
[0116] Based on the same inventive concept, the present application also provides a register allocation device 600. Figure 6 As shown, Figure 6 Shows the use of Figure 1 The register allocation device of the method shown. It should be understood that the specific functions of the device 600 can be referred to the description above, and the detailed description is appropriately omitted here to avoid repetition. The device 600 includes at least one software function module that can be stored in a memory in the form of software or firmware or fixed in the operating system of the device 600. Specifically:
[0117] See also Figure 6 As shown, the apparatus 600 includes: a determination module 601 and a processing module 602. Among them:
[0118] The determination module 601 is used to determine the target register allocation algorithm corresponding to the target executable body in the program during the program compilation process; wherein: the target executable body is the executable body currently performing register allocation in the program; the executable body is a function in the program or a variable allocation area in the function; the target register allocation algorithm is the register allocation algorithm with the best algorithm evaluation index value among the preset register allocation algorithms; the algorithm evaluation index value represents the allocation level of the variables in the target executable body under the register allocation algorithm;
[0119] The processing module 602 is used to save the register allocation result of performing register allocation on the target execution body using the target register allocation algorithm.
[0120] In a feasible implementation of the embodiment of the present application, the determination module 601 is specifically used to use each of the register allocation algorithms to perform register allocation on the target execution body, and obtain the register allocation results and algorithm evaluation index values corresponding to the target execution body under each of the register allocation algorithms; wherein the register allocation algorithm with the best algorithm evaluation index value is the target register allocation algorithm;
[0121] The processing module 602 is specifically configured to save the register allocation result corresponding to the target register allocation algorithm in a preset structure, and delete the register allocation results corresponding to each register allocation algorithm except the target register allocation algorithm.
[0122] In an optional embodiment of the above feasible implementation mode, the register allocation algorithm includes a first register allocation algorithm and at least one second register allocation algorithm;
[0123] The determination module 601 is specifically used to: create a structure copy of the structure for each of the second register allocation algorithms; use the first register allocation algorithm to perform register allocation on the target execution body, and store the register allocation result in the structure; use each of the second register allocation algorithms to perform register allocation on the target execution body, and store the register allocation result in the structure copy of each of the second register allocation algorithms;
[0124] The processing module 602 is specifically used for: if the target register allocation algorithm with the best algorithm evaluation index value is the first register allocation algorithm, deleting all the structure copies; if the target register allocation algorithm with the best algorithm evaluation index value is a second register allocation algorithm, replacing the data in the structure with the data in the structure copy of the second register allocation algorithm, and deleting all the structure copies.
[0125] In a feasible implementation of the embodiment of the present application, the algorithm evaluation index value includes a first algorithm evaluation index value and a second algorithm evaluation index value;
[0126] The determination module 601 is specifically used to: obtain a preliminary screening register allocation algorithm with the best evaluation index value of the first algorithm; if there is only one preliminary screening register allocation algorithm, determine the preliminary screening register allocation algorithm as the target register allocation algorithm; if there are multiple preliminary screening register allocation algorithms, use the preliminary screening register allocation algorithm with the best evaluation index value of the second algorithm as the target register allocation algorithm.
[0127] In another feasible implementation of the embodiment of the present application, the algorithm evaluation index value includes a first algorithm evaluation index value and a second algorithm evaluation index value;
[0128] The determination module 601 is specifically used for: calculating the comprehensive evaluation index value corresponding to each of the register allocation algorithms according to the first algorithm evaluation index value and the second algorithm evaluation index value corresponding to each of the register allocation algorithms; and taking the register allocation algorithm with the best comprehensive evaluation index value as the target register allocation algorithm.
[0129] In the above two feasible implementations, the first algorithm evaluation index value corresponding to each of the register allocation algorithms is: the number of overflow registers that exist when each of the register allocation algorithms is used to allocate registers to the target execution body; the second algorithm evaluation index value corresponding to each of the register allocation algorithms is: the allocation cost that exists when each of the register allocation algorithms is used to allocate registers to the target execution body.
[0130] In a feasible implementation of the embodiment of the present application, the determination module 601 is specifically used to: input the characteristics of the target executable body into a pre-trained classification model to obtain the algorithm evaluation index value of each register allocation algorithm relative to the target executable body; the algorithm evaluation index value is the probability that the target executable body output by the classification model corresponds to each category; each category is each register allocation algorithm; and the register allocation algorithm with the best algorithm evaluation index value is used as the target register allocation algorithm.
[0131] In this feasible implementation manner, the characteristics of the target executable body include at least one of the following: the number of code blocks of the target executable body; the number of branches in the target executable body; the number of instructions of the target executable body; the intermediate representation of the target executable body generated during the compilation process; and the calling relationship of the target executable body in the program.
[0132] In a feasible implementation of an embodiment of the present application, the determination module 601 is specifically used to: obtain identification information of the program; obtain a target correspondence relationship associated with the identification information from a preset storage body according to the identification information; the target correspondence relationship includes a pre-stored correspondence relationship between each executable body in the program and a target register allocation algorithm of each executable body; and determine the target register allocation algorithm corresponding to the target executable body from the target correspondence relationship.
[0133] In the embodiment of the present application, the register allocation algorithm includes a CB algorithm and a priority algorithm.
[0134] In the embodiment of the present application, the determination module 601 is further used to: determine to adopt an algorithm optimization mode before compiling the program.
[0135] It should be understood that, for the sake of brevity, some of the contents described in the method embodiments will not be repeated in this embodiment.
[0136] Based on the same inventive concept, the present application embodiment provides an electronic device, see Figure 7 As shown, it includes a processor 701 and a memory 702. Among them:
[0137] The processor 701 is used to execute one or more programs stored in the memory 702 to implement the above register allocation method.
[0138] It is understood that the processor 701 may be a processor core or a processor chip, or other circuits capable of program configuration and operation, and the memory 702 may be a RAM (Random Access Memory), a ROM (Read-Only Memory), a flash memory, etc., but is not limited thereto.
[0139] It is understandable. Figure 7 The structure shown is for illustration only. The electronic device may also include Figure 7 More or fewer components as shown, or with Figure 7 For example, it may also have an internal communication bus for realizing communication between the processor 701 and the memory 702; for another example, it may also have an external communication interface, such as a USB (Universal Serial Bus) interface, a CAN (Controller Area Network) bus interface, etc.; for another example, it may also have an information display component such as a display screen, but this is not a limitation.
[0140] Based on the same inventive concept, this embodiment also provides a computer-readable storage medium, such as a floppy disk, an optical disk, a hard disk, a flash memory, a USB flash disk, an SD (Secure Digital Memory Card) card, an MMC (Multimedia Card) card, etc., in which one or more programs for implementing the above steps are stored, and the one or more programs can be executed by one or more processors to implement the above register allocation method. No further details will be given here.
[0141] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0142] In addition, the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0143] Furthermore, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0144] In this document, relational terms such as first and second, etc. are used merely to distinguish one entity or operation from another entity or operation, but do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0145] As used herein, a plurality refers to two or more than two.
[0146] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A register allocation method, characterized in that: include: During the program compilation process, a target register allocation algorithm corresponding to a target executable body in the program is determined; wherein: the target executable body is an executable body currently performing register allocation in the program; the executable body is a function in the program or a variable allocation area within a function; the target register allocation algorithm is a register allocation algorithm with an optimal algorithm evaluation index value among various preset register allocation algorithms; the algorithm evaluation index value represents the allocation level of variables in the target executable body under the register allocation algorithm; A register allocation result of performing register allocation on the target execution body using the target register allocation algorithm is saved.
2. The register allocation method according to claim 1, wherein: The step of determining a target register allocation algorithm corresponding to a target executable body in the program includes: Using each of the register allocation algorithms to perform register allocation on the target execution body, respectively, to obtain register allocation results and algorithm evaluation index values corresponding to the target execution body under each of the register allocation algorithms; wherein the register allocation algorithm with the best algorithm evaluation index value is the target register allocation algorithm; Saving a register allocation result of register allocation for the target execution body using the target register allocation algorithm includes: The register allocation result corresponding to the target register allocation algorithm is saved in a preset structure, and the register allocation results corresponding to each of the register allocation algorithms except the target register allocation algorithm are deleted.
3. The register allocation method according to claim 2, characterized in that: The register allocation algorithm includes a first register allocation algorithm and at least one second register allocation algorithm; Using each of the register allocation algorithms to allocate registers to the target execution body respectively, and obtaining register allocation results and algorithm evaluation index values corresponding to the target execution body under each of the register allocation algorithms, including: creating a structure copy of the structure for each of the second register allocation algorithms; Perform register allocation on the target execution body using the first register allocation algorithm, and store the register allocation result in the structure; Using each second register allocation algorithm to perform register allocation on the target execution body, and storing the register allocation results in the structure copies of each second register allocation algorithm; The register allocation result corresponding to the target register allocation algorithm with the best algorithm evaluation index value is saved in a preset structure, and the register allocation results corresponding to each register allocation algorithm except the target register allocation algorithm are deleted, including: If the target register allocation algorithm with the best algorithm evaluation index value is the first register allocation algorithm, deleting all copies of the structure; If the target register allocation algorithm with the best algorithm evaluation index value is a second register allocation algorithm, the data in the structure copy of the second register allocation algorithm is used to replace the data in the structure, and all the structure copies are deleted.
4. The register allocation method according to claim 1, wherein: The algorithm evaluation index value includes a first algorithm evaluation index value and a second algorithm evaluation index value; Determining a target register allocation algorithm corresponding to a target executable body in the program includes: Obtaining a preliminary screening register allocation algorithm with an optimal evaluation index value of the first algorithm; If there is only one register allocation algorithm in the preliminary screening, determining the register allocation algorithm in the preliminary screening as the target register allocation algorithm; If there are multiple preliminary screening register allocation algorithms, the preliminary screening register allocation algorithm with the best second algorithm evaluation index value is used as the target register allocation algorithm.
5. The register allocation method according to claim 1, wherein: The algorithm evaluation index value includes a first algorithm evaluation index value and a second algorithm evaluation index value; Determining a target register allocation algorithm corresponding to a target executable body in the program includes: The comprehensive evaluation index value corresponding to each of the register allocation algorithms is calculated according to the first algorithm evaluation index value and the second algorithm evaluation index value corresponding to each of the register allocation algorithms; The register allocation algorithm with the best comprehensive evaluation index value is used as the target register allocation algorithm.
6. The register allocation method according to claim 4 or 5, characterized in that: The first algorithm evaluation index value corresponding to each of the register allocation algorithms is: the number of overflow registers existing when each of the register allocation algorithms is used to allocate registers to the target execution body; The second algorithm evaluation index value corresponding to each of the register allocation algorithms is: the allocation cost existing when each of the register allocation algorithms is used to allocate registers to the target execution body.
7. The register allocation method according to claim 1, wherein: The step of determining a target register allocation algorithm corresponding to a target executable body in the program includes: Input the characteristics of the target executable body into a pre-trained classification model to obtain the algorithm evaluation index value of each register allocation algorithm relative to the target executable body; the algorithm evaluation index value is the probability of the target executable body corresponding to each category output by the classification model; each category is each register allocation algorithm; The register allocation algorithm with the best algorithm evaluation index value is used as the target register allocation algorithm.
8. The register allocation method according to claim 7, characterized in that: The characteristics of the target executable include at least one of the following: The number of code blocks of the target executable body; The number of branches in the target executable; The number of instructions of the target executable body; The intermediate representation of the target executable generated during the compilation process; The calling relationship of the target executable in the program.
9. The register allocation method according to claim 1, wherein: During the program compilation process, determining a target register allocation algorithm corresponding to a target executable body in the program includes: Obtaining identification information of the program; Acquire a target correspondence relationship associated with the identification information from a preset storage body according to the identification information; the target correspondence relationship includes a pre-stored correspondence relationship between each executable body in the program and a target register allocation algorithm of each executable body; A target register allocation algorithm corresponding to the target execution body is determined from the target corresponding relationship.
10. The register allocation method according to any one of claims 1 to 9, characterized in that: The register allocation algorithm includes a CB algorithm and a priority algorithm.
11. The register allocation method according to any one of claims 1 to 10, characterized in that: Before the program is compiled, the method further includes: determining to adopt an algorithm optimization mode.
12. A register allocation device, characterized in that: include: A determination module, used to determine, during the program compilation process, a target register allocation algorithm corresponding to a target executable body in the program; wherein: the target executable body is an executable body currently performing register allocation in the program; the executable body is a function in the program or a variable allocation area within a function; the target register allocation algorithm is a register allocation algorithm with an optimal algorithm evaluation index value among various preset register allocation algorithms; the algorithm evaluation index value represents an allocation level of variables in the target executable body under the register allocation algorithm; The processing module is used to save the register allocation result of performing register allocation on the target execution body using the target register allocation algorithm.
13. An electronic device, characterized in that: include: Processor and memory; The processor is used to execute one or more programs stored in the memory to implement the register allocation method according to any one of claims 1 to 11.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the register allocation method according to any one of claims 1 to 11.
Citation Information
Cited By
Overflow optimization method for overlength instruction word architecture and related device
CN119536809A
Register allocation method and device, computer program product and readable storage medium
CN121658010A
Register allocation method, device, computer program product and readable storage medium
CN121658010B
