A search-based fault location method for compiler optimization sequences

Through search-based methods and genetic algorithms, we can locate compiler optimize sequence failures, solve the problem of low efficiency in compiler optimized sequence failure positioning in the existing technology, realize fast and accurate fault location and repair, and improve compiler quality.

CN113064821BActive Publication Date: 2025-01-17DALIAN UNIV OF TECH
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202110331114.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-03-29
Publication Date
2025-01-17
Estimated Expiration
2041-03-29

AI Technical Summary

Technical Problem

The prior art is difficult to efficiently and accurately locate compiler optimization sequence failures, especially in modern compilers with numerous and complex optimization techniques, resulting in low analysis and repair efficiency.

Method used

Using a search-based method, by obtaining compiler optimization collection and code coverage information, using genetic algorithms to find optimization sequences that do not trigger faults, calculate file suspicion and report possible locations of faults, realize automatic location of compiler optimization sequence failures.

Benefits of technology

It effectively improves the efficiency of compiler developers to analyze and repair compiler optimization sequence failures, improves compiler quality, can quickly and accurately locate fault locations, and reduces the time cost of repairing compiler failures.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113064821B_ABST
    Figure CN113064821B_ABST
Patent Text Reader

Abstract

The present invention provides a search-based compiler optimization sequence fault location method, which can be used for compiler optimization sequence fault location of C / C++ language, such as open source compiler LLVM, etc.; the relevant steps of the present invention can also be adapted according to the compiler characteristics of a specific programming language, so as to locate the compiler optimization sequence fault of the specific programming language. The present invention can effectively analyze and locate compiler optimization sequence faults, thereby helping compiler developers to better and faster understand and repair compiler optimization sequence-related faults and improve the quality of the compiler.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of software compilation, and relates to a technology for locating compiler optimization sequence faults, in particular to a search-based compiler optimization sequence fault locating method. Background Art

[0002] The compiler is an important and indispensable basic software in the entire software development process. It not only converts the program written by the developer in a high-level programming language into a machine code that can be recognized by the computer, but also optimizes the target program during the compilation process to maximize the performance of the target program. With the development of compilation technology, modern compilers have a large number of code optimization technologies. When users use compilers to compile programs, they generally use multiple optimizations to form an optimization sequence to optimize the target program. However, as a software, compilers will inevitably fail. In particular, compiler optimization is more prone to failures. Various optimizations may affect each other. A program optimized by one optimization technology may make other optimizations work better, or it may make other optimizations invalid or even fail. However, when compiler developers repair compiler failures, due to the large size of the compiler itself, repairing compiler failures is time-consuming, especially failures related to the compilation optimization sequence. Therefore, in order to help compiler developers quickly analyze and repair compiler optimization sequence failures and ensure compiler quality, automatic positioning of compiler optimization sequence failures is crucial.

[0003] Automatic location of compiler optimization sequence faults is an important way to improve the efficiency of compiler developers in analyzing compiler optimization sequence faults. It can not only automatically complete the analysis of compiler optimization sequence faults, but also accurately report the location where the optimization sequence faults occur. However, due to the large number of optimization technologies in modern compilers, the analysis and location of compiler optimization sequence faults are complex and time-consuming. Although there are some invention patents for compiler fault location technology, these existing invention patents still have difficulties in adaptation and low efficiency when facing the problem of locating compiler optimization sequence faults. For example, a compiler defect location method based on reinforcement learning (patent number: CN202010880640.1) uses structural mutation and reinforcement learning to generate a successfully compiled mutant program, thereby locating compiler faults by comparing the differences in the compiler execution path between the mutant program and the fault triggering program; however, this method takes a long time to generate a mutant program, and it is difficult to efficiently locate compiler optimization sequence faults. A method for automatically locating compiler errors (patent number: CN200510090093.2) and a method and device for automatically locating compiler errors (patent number: CN201010508986.5) locate compiler faults by comparing the executable programs output by the correct compiler and the faulty compiler. However, this method is not efficient for compilers with more optimizations, making it difficult to locate compiler optimization sequence faults.

[0004] Therefore, in order to efficiently and accurately locate compiler optimization sequence faults, the present invention searches the compiler optimization sequences to find an optimization sequence that contains all the optimizations in the faulty optimization sequence but does not trigger the fault, thereby locating the optimization sequence fault by utilizing the differences between the compiler execution paths under different optimization sequences. Summary of the invention

[0005] To solve the above problems, the present invention provides a search-based compiler optimization sequence fault location method. The present invention can be used to locate compiler optimization sequence faults in C / C++ languages, such as the open source compiler LLVM, etc.; the relevant steps of the present invention can also be adapted according to the compiler characteristics of a specific programming language to locate the compiler optimization sequence fault of the specific programming language.

[0006] The technical solution of the present invention:

[0007] A search-based compiler optimization sequence fault location method, the main steps are as follows:

[0008] Step 1: Compile the fault compiler to obtain the optimized set.

[0009] Compile the fault compiler C using the instrumentation method, and obtain the compilation optimization information to form an optimization set O.

[0010] Step 2: Get the program p and optimization sequence s that trigger the compiler optimization sequence failure.

[0011] Step 3: Get the compiler's code coverage information at the time of failure.

[0012] Compile program p using compiler C under optimization sequence s and obtain code coverage information t during the execution of compiler C s ; The code coverage information includes the files involved when the compiler is executed and the code statements executed in the files.

[0013] Step 4: Search for a trouble-free optimized sequence.

[0014] Let compiler C, optimization set O, program p and fault optimization sequence s, and code coverage information t s As the input of the search algorithm, the search algorithm is used to automatically find all optimizations in the fault optimization sequence s, but the optimization sequence that will not trigger the fault. If the set of fault-free optimization sequences obtained by the search algorithm is S = {s1, s2, ..., s n}, then the corresponding code coverage information set during the execution of compiler C is T = {t1, t2, ..., t n}.

[0015] Step 5: Calculate the file suspicion level.

[0016] First, according to t s and T, calculate the suspiciousness of each code statement executed by the compiler when the fault occurs; then take the average suspiciousness of all executed code statements in the file as the suspiciousness of the file.

[0017] The calculation formula for the suspiciousness of a code statement is as follows:

[0018]

[0019] ef l and nf l represents the number of fault optimization sequences that execute and do not execute code statement l, and ep l Then it represents the number of fault-free optimized sequences for executing code statement l. In the present invention, since only the code statements executed by the compiler when the fault occurs are considered, ef l and nf l 1 and 0 respectively. Therefore, the calculation formula of the suspiciousness of the code statement is simplified to:

[0020]

[0021] For t s The executed code statements of each file in the l Calculated by traversing T.

[0022] The specific calculation formula for file suspicion is as follows:

[0023]

[0024] Among them, n f is the number of executed code statements in file f, l i is the i-th code statement l that is executed.

[0025] Step 6: Report the suspicious file.

[0026] According to the file suspicion calculated in step 5, the source code files involved in the compiler when the fault occurs are sorted, and the files with higher suspicion are ranked higher; the sorted file list is then reported to the compiler developer as the possible location of the optimization sequence fault.

[0027] In step 4, the search algorithm is the key to the present invention. In the present invention, a genetic algorithm is used as the search algorithm, and the user can also design a search algorithm with composite target requirements according to the needs. The steps of the genetic algorithm mainly include initializing the population, fitness evaluation, crossover, mutation, and selection. The operation of each step is as follows:

[0028] Step a: Initialize the population.

[0029] Individuals are generated randomly, that is, k optimizations are randomly selected from the optimization set O to form an optimization sequence. During the initialization process, the k value can be any positive integer greater than the number of optimizations in the fault optimization sequence s. In actual use, users can adjust the value of k as needed. However, in this process, it is necessary to ensure that all optimizations in the fault optimization sequence s are included in the randomly generated optimization sequence.

[0030] Step b: Fitness evaluation.

[0031] Fitness evaluation is to measure the degree to which each individual in the population, that is, each optimization sequence, meets the goal. In the present invention, the goal of the search algorithm is to find an optimization sequence that contains all optimizations in the faulty optimization sequence s and has a similar compiler execution path to the faulty optimization sequence s, but does not trigger a compiler fault. Therefore, the fitness of the optimization sequence i is the code coverage information t that it makes the compiler C execute i With t s The present invention uses the Jaccard similarity coefficient as a measure of t i With t s The similarity method is specifically defined as follows:

[0032]

[0033] Where stmt(·) represents all statements in the coverage information, and |·| represents the number of elements in the set. sim(t i , t s ) is larger, the better the fitness of the optimization sequence i. However, the optimization sequence i may still trigger a compiler failure, in which case the fitness of the optimization sequence i is 0. In actual use, users can also design fitness functions as needed.

[0034] If the termination condition of the algorithm (algorithm running time or algorithm iteration number) is not reached when the fitness evaluation of each optimized sequence in the population is completed, continue to execute the following steps, otherwise terminate the algorithm.

[0035] Step c: Select.

[0036] Selection refers to selecting optimized sequences with better fitness in a population to form a new population. In the present invention, the optimized sequences in the population are first arranged in descending order according to fitness, and then the first m optimized sequences are selected as the new population.

[0037] Step d: Crossover.

[0038] Crossover refers to splitting and rejoining two optimized sequences in the new population generated by the selection step with a certain probability to form a new optimized sequence. In the present invention, two optimized sequences are crossed by a single-point crossover method, that is, a point is selected in the optimized sequences i and j, each optimized sequence is divided into two, and then the first half of the optimized sequence i is joined with the second half of the optimized sequence j, and the first half of the optimized sequence j is joined with the second half of the optimized sequence i, thereby forming two new optimized sequences. However, the spliced ​​optimized sequence needs to ensure that all optimizations in the faulty optimized sequence s are included therein. Otherwise, the spliced ​​optimized sequence is discarded and the original optimized sequence is kept unchanged.

[0039] Step e: Mutation.

[0040] After the optimized sequences in the population are crossed, they enter the mutation step. Mutation refers to performing mutation operations on each optimization contained in each optimized sequence in the population with a certain probability to form a new optimized sequence. The mutation operations in the present invention mainly include deletion, insertion, replacement, and shift, and the specific meanings are as follows:

[0041] 1) Delete: refers to deleting a certain optimization in the optimization sequence from the optimization sequence;

[0042] 2) Insertion: refers to inserting an optimization at a certain position in the optimization sequence;

[0043] 3) Replacement: refers to replacing a certain optimization in the optimization sequence with another optimization;

[0044] 4) Shift: It means swapping the positions of two optimizations in the optimization sequence.

[0045] During the mutation process, one of the above mutation operations is randomly selected to mutate a certain optimization in the optimization sequence, where the probability of the optimization being mutated is 1 / size, and size is the number of optimizations included in the current optimization sequence. After mutation, if the new optimization sequence still contains all the optimizations in the faulty optimization sequence s, the mutation is successful; otherwise, the mutated optimization sequence is discarded and the original optimization sequence remains unchanged.

[0046] After mutation, go to step b to continue executing the algorithm.

[0047] Beneficial effects of the present invention: The present invention can effectively analyze and locate compiler optimization sequence faults, thereby helping compiler developers to better and faster analyze and repair compiler optimization sequence-related faults and improve the quality of the compiler. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] Figure 1 It is the main flow chart of compiler optimization sequence fault location.

[0049] Figure 2 It is the genetic algorithm flow chart. DETAILED DESCRIPTION

[0050] The following is a combination of the accompanying drawings and technical solutions, and takes locating LLVM compiler optimization sequence failures as an example to further illustrate the specific implementation of the present invention.

[0051] The method of the present invention is deployed on a fault analysis server, and corresponding software such as LLVM compiler, script interpreter Python, etc. are installed according to the compiler optimization sequence fault location steps.

[0052] like Figure 1 As shown, the compiler optimization sequence fault is located according to the following process. In the compiler optimization sequence fault location environment, in addition to the determination factors specified in the compilation environment, other factors, such as the initial population size of the genetic algorithm, the crossover mutation probability, and the termination condition, are set according to specific location requirements.

[0053] Step 1: Compile the fault compiler to obtain the optimized set.

[0054] Compile the LLVM compiler containing the fault using the instrumentation method, and obtain the compilation optimization information to form the optimization set O. When compiling the LLVM compiler containing the fault, use the GCC compiler with the -coverage option to compile it, so that during the operation of the LLVM compiler, the relevant information of the execution process can be automatically generated, and the GCOV tool can be used to automatically analyze and obtain the code coverage information. LLVM, GCC, and GCOV are all open source and free software. In actual use, users can adjust which tool to use to compile the faulty compiler and obtain code coverage information as needed. The optimization set O is obtained by checking the optimization options of the faulty LLVM compiler. Table 1 is an example of the LLVM compiler optimization set, and there may be differences between different compilers and different versions of the same compiler.

[0055] Table 1 LLVM compiler optimization set examples

[0056]

[0057] Step 2: Get the program p and optimization sequence s that trigger the compiler optimization sequence failure.

[0058] The program p obtained in this step can be a C / C++ language program or a bytecode program recognizable by the LLVM compiler. The optimization sequence s is a sequence composed of optimizations, such as "-adce-dse-early-cse-gvn". Under the effect of this sequence, the LLVM compiler may crash or misoptimize the compiled program p.

[0059] Step 3: Get the compiler's code coverage information at the time of failure.

[0060] Use the program p and optimized sequence s in step 2 as the input of the LLVM compiler, and use GCOV to obtain the code coverage information t during the execution of the LLVM compiler s The code coverage information includes the files involved in the execution of the LLVM compiler and the code statements executed in the files.

[0061] Step 4: Search for a trouble-free optimized sequence.

[0062] The LLVM compiler containing the fault, the optimization set O, the program p and the faulty optimization sequence s, as well as the coverage information t s As the input of the search algorithm, the search algorithm is used to automatically find all optimizations in the fault optimization sequence s but the optimization sequence that will not trigger the fault.

[0063] The present invention uses a genetic algorithm as a search algorithm. In the genetic algorithm, each individual in the population, that is, each optimized sequence is represented as a list, for example, individual ind1 = [-adce, -dse, -early-cse, -gvn, -lcssa], individual ind2 = [-adce, -early-cse, -gvn, -dse, -lcssa]. The number of individuals in the population is determined according to the computing resources of the server. Then the fitness of each individual in the population is evaluated, and the greater the fitness, the better the fitness of the individual. After that, the m optimized sequences with the best fitness are selected as the new population. After the new population is determined, a single-point crossover is performed on each pair of individuals in the population. For example, for individuals ind1 and ind2, if the third element is the crossover point, then after the crossover, individual ind1′=[-adce,-early-cse,-early-cse,-dse,-lcssa], and individual ind2′=[-adce,-dse,-gvn,-gvn,-lcssa]. After the crossover, each individual is mutated. In the present invention, one of the four mutation operators, deletion, insertion, replacement, and shift, is randomly selected to mutate each optimization in the individual. The probability of each optimization being mutated is 1 / size, where size is the number of optimizations contained in the current individual. For example, the first optimization -adce of individual ind1′ can be replaced with -dse, that is, ind1′=[-dse,-early-cse,-early-cse,-dse,-lcssa]. During the crossover or mutation process, it is necessary to ensure that the individual after the crossover or mutation still contains all the optimizations in the fault optimization sequence, otherwise the individual of this crossover or mutation is discarded and the original individual remains unchanged. Finally, the individuals in the population are evaluated for fitness, selected, crossover, and mutated again. This process is iterated until the termination condition (algorithm running time or number of algorithm iterations) is reached.

[0064] During the search process, if the LLVM compiler compiles the program p without failure under a certain optimization sequence, GCOV is used to obtain the code coverage information of the LLVM compiler during execution. After the search is completed, if the set of optimization sequences obtained by the search algorithm without failure is S = {s1, s2, ..., s n}, then the corresponding code coverage information set during the execution of the LLVM compiler is T = {t1, t2, ..., t n}.

[0065] Step 5: Calculate the file suspicion level.

[0066] First, according to t sand T, calculate the suspiciousness of each code statement executed by the LLVM compiler when the fault occurs. Then take the average suspiciousness of all executed code statements in the file as the suspiciousness of the file. The suspiciousness calculation formula of the code statement is as follows:

[0067]

[0068] Among them, ef l and nf l represents the number of fault optimization sequences that execute and do not execute code statement l, and ep l Then it represents the number of fault-free optimized sequences for executing code statement l. In the present invention, since only the code statements executed by the compiler when the fault occurs are considered, ef l and nf l 1 and 0 respectively. Therefore, the above formula can be simplified to:

[0069]

[0070] For t s The executed code statements of each file in the l Calculated by traversing T.

[0071] After obtaining the suspiciousness of each code statement executed by the LLVM compiler when the fault occurs, the average suspiciousness of all executed code statements in each file is calculated as the suspiciousness of the file. The specific calculation formula is as follows:

[0072]

[0073] Among them, n f is the number of executed code statements in file f, l i is the i-th executed code statement l. In actual use, users can also design the above suspicious degree formula according to their needs to meet specific needs.

[0074] Step 6: Report the suspicious file.

[0075] According to the file suspicion calculated in step 5, the source code files involved in the LLVM compiler when the fault occurs are sorted, and the files with higher suspicion are ranked higher. Then the sorted file list is reported to the compiler developer as the possible location of the optimization sequence fault. In this embodiment, the top 5 files are selected and reported to the compiler developer. In actual use, the user can also decide the number of files to report to the compiler developer according to the needs.

Claims

1. A search-based compiler optimization sequence fault location method, characterized in that: Here are the steps: Step 1: Compile the fault compiler and obtain the optimization set; Compile the fault compiler C using the instrumentation method and obtain the compilation optimization information to form an optimization set O; Step 2: Get the program p and optimization sequence s that trigger the compiler optimization sequence failure; Step 3: Get the compiler's code coverage information at the time of failure; Compile program p using compiler C under optimization sequence s and obtain code coverage information t during the execution of compiler C s ; The code coverage information includes the files involved in the compiler execution and the code statements executed in the files; Step 4: Search for a trouble-free optimization sequence; Let compiler C, optimization set O, program p and fault optimization sequence s, and code coverage information t s As the input of the search algorithm, the search algorithm is used to automatically find all optimizations in the fault optimization sequence s, but the optimization sequence that will not trigger the fault; if the set of fault-free optimization sequences obtained by the search algorithm is S = {s1, s2, ..., s n }, then the corresponding code coverage information set during the execution of compiler C is T = {t1, t2, …, t n }; Step 5: Calculate the file suspicion level; First, according to t s and T, calculate the suspiciousness of each code statement executed by the compiler when the fault occurs; then take the average suspiciousness of all executed code statements in the file as the suspiciousness of the file; The calculation formula for the suspiciousness of a code statement is as follows: ef l and nf l represents the number of fault optimization sequences that execute and do not execute code statement l, and ep l It represents the number of fault-free optimization sequences for executing code statement l. Since only the code statements executed by the compiler when the fault occurs are considered, ef l and nf l 1 and 0 respectively; therefore, the calculation formula for the suspiciousness of a code statement is simplified to: For t s The executed code statements of each file in the l Calculated by traversing T; The specific calculation formula for file suspicion is as follows: Among them, n f is the number of executed code statements in file f, l i is the i-th executed code statement l; Step 6: Report suspicious files; According to the file suspicion calculated in step 5, the source code files involved in the compiler when the fault occurs are sorted, and the files with higher suspicion are ranked higher; the sorted file list is then reported to the compiler developer as the possible location of the optimization sequence fault.

2. The search-based compiler optimization sequence fault location method according to claim 1, characterized in that: In step 4, the steps of the search algorithm are as follows: Step a: Initialize the population; Generate individuals in a random manner: randomly select k optimizations from the optimization set O to form an optimization sequence; during the initialization process, the k value can be any positive integer greater than the number of optimizations in the fault optimization sequence s, and it is necessary to ensure that all optimizations in the fault optimization sequence s are included in the randomly generated optimization sequence; Step b: fitness evaluation; Fitness evaluation is used to measure the degree to which each individual in the population meets the goal, where each individual is each optimized sequence; The fitness of the optimized sequence i is the code coverage information t executed by compiler C i With t s The similarity of t is measured by using the Jaccard similarity coefficient. i With t s The similarity method is specifically defined as follows: in , stmt(·) represents all the statements in the coverage information, |·| represents the number of elements in the set; sim(t i ,t s ) is larger, the better the fitness of the optimization sequence i is; however, the optimization sequence i may still trigger a compiler failure, in which case the fitness of the optimization sequence i is 0; If the termination condition of the algorithm is not met when the fitness evaluation of each optimized sequence in the population is completed, continue to execute the following steps, otherwise the algorithm is terminated; Step c: Select; Selection refers to selecting optimized sequences with better fitness in the population to form a new population; first, the optimized sequences in the population are arranged in descending order according to the fitness size, and then the first m optimized sequences are selected as the new population; Step d: crossover; Crossover refers to splitting and rejoining two optimization sequences in the new population generated by the selection step with a certain probability to form a new optimization sequence; the two optimization sequences are crossed using a single-point crossover method: a point is selected in the optimization sequences i and j, each optimization sequence is split into two, and then the first half of the optimization sequence i is joined with the second half of the optimization sequence j, and the first half of the optimization sequence j is joined with the second half of the optimization sequence i, thereby forming two new optimization sequences; however, the optimization sequence after joining needs to ensure that all optimizations in the faulty optimization sequence s are included in it; Otherwise, the spliced ​​optimized sequence is discarded and the original optimized sequence is kept unchanged; Step e: mutation; Mutation refers to the operation of performing mutations on each optimization sequence in the population with a certain probability to form a new optimization sequence; mutation operations include deletion, insertion, replacement and shift, as follows: 1) Delete: refers to deleting a certain optimization in the optimization sequence from the optimization sequence; 2) Insertion: refers to inserting an optimization at a certain position in the optimization sequence; 3) Replacement: refers to replacing a certain optimization in the optimization sequence with another optimization; 4) Shift: refers to swapping the positions of two optimizations in the optimization sequence; During the mutation process, a mutation operation is randomly selected to mutate a certain optimization in the optimization sequence, where the probability of the optimization being mutated is 1 / size, and size is the number of optimizations included in the current optimization sequence; after mutation, if the new optimization sequence still contains all the optimizations in the faulty optimization sequence s, the mutation is successful; otherwise, the mutated optimization sequence is discarded and the original optimization sequence is kept unchanged; After mutation, go to step b to continue executing the algorithm.

Citation Information

Patent Citations

  • Method of automatic positioning for error in compiler

    CN100442243C

  • Automatic positioning method and device of compiler error

    CN102446134B

  • Reinforcement Learning-Based Compiler Defect Localization Method

    CN112181420B

  • Software failure positioning method based on machine learning algorithm

    CN105893256A

  • Diagnosis method for analyzing performance and fault of ASP. NET application software

    CN108089978A