Multi-path circulation summarization method and system based on path dependence analysis

A path-dependence automaton model is constructed through path-dependence analysis, and loop summary is performed based on the breadth-first algorithm, which solves the problem that loop unrolling in existing technologies cannot optimize the loop structure, and achieves the goal of saving loop execution time and improving efficiency.

CN120803459APending Publication Date: 2025-10-17AGRICULTURAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511023943.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-24
Publication Date
2025-10-17

AI Technical Summary

Technical Problem

In the existing technology, loop optimization methods mainly rely on loop unrolling, which cannot effectively reduce the loop execution time and cannot optimize the loop structure.

Method used

A path-dependency automaton model is constructed through path-dependency analysis, and loop summary is performed based on the breadth-first algorithm to automatically deduce the input and output results of the loop program, avoiding the step-by-step execution of each loop.

Benefits of technology

The loop structure is optimized, the execution time of the target loop program is saved, and the loop execution efficiency is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120803459A_ABST
    Figure CN120803459A_ABST
Patent Text Reader

Abstract

The invention provides a multipath loop summarization method and system based on path dependency analysis. The method comprises the following steps: acquiring a target loop program; constructing a program flow diagram of the target loop program, and slicing the program flow diagram to obtain a sliced program flow diagram; constructing a path-dependent automaton model on the basis of the sliced program flow graph; and based on a preset breadth-first algorithm and the path-dependent automaton model, performing cyclic summarization to obtain a cyclic summarization result. In the scheme, the loop summary result used for optimizing the target loop program is obtained by constructing the path-dependent automaton, performing loop summary based on the path-dependent automaton and automatically deducing the input and output results of the target loop program, and each loop of the target loop program is prevented from being executed step by step, so that optimization of the loop structure is realized, and the optimization efficiency is improved. And the execution time of the target loop program is saved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of software engineering, in particular to a multi-path loop summarization method and system based on path dependence analysis. BACKGROUND

[0002] Ensuring software code correctness is always one of the core goals of software engineering, and ensuring the correctness of financial systems is even more important. Loop is one of the most commonly used structures by developers and one of the most error-prone structures, and is also one of the most difficult structures in program verification.

[0003] At present, the commonly used loop optimization method in the industry is loop unrolling, which only reduces the loop execution time through parallel technology. This method still needs to execute each step of the loop gradually, which not only consumes time, but also cannot optimize the loop structure. SUMMARY

[0004] Therefore, the embodiments of the present application provide a multi-path loop summarization method and system based on path dependence analysis to optimize the loop structure and save the execution time of the target loop program.

[0005] To achieve the above purpose, the embodiments of the present application provide the following technical solutions:

[0006] The first aspect of the embodiments of the present application discloses a multi-path loop summarization method based on path dependence analysis, which comprises:

[0007] Obtaining a target loop program;

[0008] Constructing a program flow graph of the target loop program and performing slicing processing on the program flow graph to obtain a sliced program flow graph;

[0009] Based on the sliced program flow graph, a path dependence automaton model is constructed;

[0010] Based on a preset breadth-first algorithm and the path dependence automaton model, loop summarization is performed to obtain a loop summarization result.

[0011] Preferably, the construction of the program flow graph of the target loop program and the slicing processing of the program flow graph to obtain the sliced program flow graph comprises:

[0012] Based on a preset program flow graph construction algorithm, the program flow graph of the target loop program is constructed;

[0013] Verifying whether the target loop program meets a preset target type; the target type includes: an integer multi-path inductive type loop;

[0014] If not, it is determined that the target loop program cannot be analyzed, and the process is ended.

[0015] If yes, read the loop variables in the program flow graph, and add the loop variables to a preset loop variable set; the loop variables include variables involved in a loop condition in the program flow graph and variables involved in a jump statement in the program flow graph;

[0016] Scan each statement in the program flow graph;

[0017] If there is a target variable in the statement that affects the value of any loop variable in the loop variable set, add the statement to a reduced program flow graph, and add the target variable to the loop variable set; the reduced program flow graph is a blank program flow graph in an initial state;

[0018] Return to the step of scanning each statement in the program flow graph until there is no target variable in each statement that affects the value of any loop variable in the loop variable set, and take the reduced program flow graph as a first sliced program flow graph;

[0019] Remove predefined useless statements from the first sliced program flow graph to obtain a sliced program flow graph.

[0020] Preferably, the constructing a path-dependent automaton model based on the sliced program flow graph comprises:

[0021] Perform a breadth-first scan on the sliced program flow graph to construct a path result set; the path result set includes multiple loop paths and symbolic constraints that need to be met for executing each loop path;

[0022] For each loop path, establish a corresponding dependency automaton state based on the symbolic constraint corresponding to the loop path;

[0023] Establish an automaton state transition relationship according to the loop path relationship between each loop path represented in the sliced program flow graph;

[0024] For each dependency automaton state transition relationship, calculate a corresponding transition condition; the transition condition includes the number of times of executing the loop path before transition, a transition trigger condition, and a calculation method of a loop variable result after transition;

[0025] Construct a path-dependent automaton model based on each dependency automaton state, the automaton state transition relationship, and each transition condition.

[0026] Preferably, the performing a breadth-first scan on the sliced program flow graph to construct a path result set comprises:

[0027] creating a path result set and a first node queue, and initializing the path result set and the first node queue to be empty;

[0028] adding an initial node in the sliced program flow graph to the first node queue;

[0029] judging whether the first node queue is empty;

[0030] if the first node queue is not empty, taking a first node in the first node queue as a target node;

[0031] obtaining a path adjacent node adjacent to the target node from the sliced program flow graph, and calculating a target path from the target node to the path adjacent node and a first symbol constraint to be satisfied for executing the target path;

[0032] judging whether the path adjacent node is a loop node or an end node; if yes, adding the target path and the first symbol constraint to the path result set; if no, adding the path adjacent node to the first node queue;

[0033] returning to the step of judging whether the first node queue is empty;

[0034] if the first node queue is empty, obtaining the path result set constructed.

[0035] Preferably, the loop summarization is performed based on the preset breadth-first algorithm and the path-dependent automaton model, and a loop summarization result is obtained, comprising:

[0036] creating a summarization result set and a second node queue, and initializing the summarization result set and the second node queue to be empty;

[0037] adding a first dependency automaton state in the path-dependent automaton model to the second node queue;

[0038] judging whether the second node queue is empty;

[0039] if the second node queue is not empty, taking a first node in the second node queue as a target node;

[0040] obtaining a dependency automaton state adjacent to the first dependency automaton state from the path-dependent automaton model as a state adjacent node;

[0041] From the path-dependent automaton model, the transition condition between the target node and the state adjacent node is obtained, and based on the calculation mode of the transition post-cycle variable result in the transition condition, a target variable result is calculated;

[0042] From the path-dependent automaton model, the symbol constraint corresponding to the state adjacent node is obtained, and is simplified into a second symbol constraint;

[0043] It is judged whether there is still the dependent automaton state adjacent to the state adjacent node in the path-dependent automaton model; if yes, the target variable result and the second symbol constraint are added to the summary result set; if no, the state adjacent node is added to the second node queue;

[0044] The step of judging whether the second node queue is empty is returned to execute;

[0045] If the second node queue is empty, the summary result set is determined as a cycle summary result.

[0046] The second aspect of the embodiment of the application discloses a multi-path cycle summary system based on path-dependent analysis, and the system comprises:

[0047] A cycle slicing unit is configured to obtain a target cycle program, construct a program flow graph of the target cycle program, and perform slicing processing on the program flow graph to obtain a sliced program flow graph;

[0048] A path-dependent automaton construction unit is configured to construct a path-dependent automaton model based on the sliced program flow graph;

[0049] A cycle summary unit is configured to perform cycle summary based on a preset breadth-first algorithm and the path-dependent automaton model to obtain a cycle summary result.

[0050] Preferably, the cycle slicing unit comprises a program flow graph constructor and a program flow graph slicer.

[0051] The program flow graph constructor is configured to obtain a target cycle program, and construct a program flow graph of the target cycle program based on a preset program flow graph construction algorithm.

[0052] The program flow graph slicer is configured to check whether the target loop program meets a preset target type; the target type includes an integer multi-path inductive type loop; if not, it is determined that the target loop program cannot be analyzed, and the process ends; if yes, a loop variable in the program flow graph is read, and the loop variable is added to a preset loop variable set; the loop variable includes a variable related to a loop condition in the program flow graph and a variable related to a jump statement in the program flow graph; each statement in the program flow graph is scanned; if there is a target variable in the statement that affects the value of any loop variable in the loop variable set, the statement is added to a reduced program flow graph, and the target variable is added to the loop variable set; the reduced program flow graph is a blank program flow graph in an initial state; the step of scanning each statement in the program flow graph is returned until there is no target variable in each statement that affects the value of any loop variable in the loop variable set, and the reduced program flow graph is used as a first sliced program flow graph; predefined useless statements are removed from the first sliced program flow graph to obtain a sliced program flow graph.

[0053] Preferably, the path-dependent automaton construction unit comprises a path extractor, a path-dependent automaton constructor, and a transition condition calculator.

[0054] The path extractor is configured to perform a breadth-first scan on the sliced program flow graph to construct a path result set; the path result set includes a plurality of loop paths and a symbolic constraint that needs to be met to execute each loop path.

[0055] The path-dependent automaton constructor is configured to, for each loop path, establish a corresponding dependent automaton state based on the symbolic constraint corresponding to the loop path, and establish an automaton state transition relationship based on a loop path relationship between each loop path represented in the sliced program flow graph.

[0056] The transition condition calculator is configured to, for each dependent automaton state transition relationship, calculate a corresponding transition condition; the transition condition includes the number of executions of the loop path before the transition, a transition trigger condition, and a calculation method of a loop variable result after the transition; and a path-dependent automaton model is constructed based on each dependent automaton state, the automaton state transition relationship, and each transition condition.

[0057] Preferably, the path extractor is specifically configured to:

[0058] create a path result set and a first node queue, and initialize the path result set and the first node queue to be empty; add an initial node in the sliced program flow graph to the first node queue; determine whether the first node queue is empty; if the first node queue is not empty, take a first node in the first node queue as a target node; obtain a path adjacent node adjacent to the target node from the sliced program flow graph, and calculate a target path from the target node to the path adjacent node and a first symbolic constraint to be satisfied for executing the target path; determine whether the path adjacent node is a loop node or an end node; if yes, add the target path and the first symbolic constraint to the path result set; if no, add the path adjacent node to the first node queue; return to execute the step of determining whether the first node queue is empty; and if the first node queue is empty, obtain the path result set constructed.

[0059] Preferably, the loop summarization unit comprises a path-dependent automaton traverser.

[0060] The path-dependent automaton traverser is configured to create a summary result set and a second node queue, and initialize the summary result set and the second node queue to be empty; add a first dependent automaton state in the path-dependent automaton model to the second node queue; determine whether the second node queue is empty; if the second node queue is not empty, take a first node in the second node queue as a target node; obtain a dependent automaton state adjacent to the first dependent automaton state from the path-dependent automaton model as a state adjacent node; obtain a transition condition between the target node and the state adjacent node from the path-dependent automaton model, and calculate a target variable result based on a calculation manner of a transition-after loop variable result in the transition condition; obtain a symbolic constraint corresponding to the state adjacent node from the path-dependent automaton model, and simplify the symbolic constraint into a second symbolic constraint; determine whether there is still a dependent automaton state adjacent to the state adjacent node in the path-dependent automaton model; if yes, add the target variable result and the second symbolic constraint to the summary result set; if no, add the state adjacent node to the second node queue; return to execute the step of determining whether the second node queue is empty; and if the second node queue is empty, determine the summary result set as a loop summary result.

[0061] Based on the above, the embodiment of the application provides a multi-path loop summarization method and system based on path dependence analysis, acquires a target loop program; constructs a program flow graph of the target loop program, and performs slicing processing on the program flow graph to obtain a sliced program flow graph; based on the sliced program flow graph, a path dependence automaton model is constructed; and based on a preset breadth-first algorithm and the path dependence automaton model, loop summarization is performed to obtain a loop summarization result. In the scheme, the path dependence automaton is constructed, the loop summarization is performed based on the path dependence automaton, the input and output results of the target loop program are automatically derived, the loop summarization result for optimizing the target loop program is obtained, and each loop of the target loop program is avoided to be executed step by step, so that the optimization of the loop structure is realized, and the purpose of saving the execution time of the target loop program is achieved. BRIEF DESCRIPTION OF DRAWINGS

[0062] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or the prior art description. Obviously, the drawings in the following description are only the embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor on the basis of the provided drawings.

[0063] Figure 1 The architecture diagram of the multi-path loop summarization system based on path dependence analysis disclosed by the embodiment of the present application is shown in the figure.

[0064] Figure 2 The working flowchart of the multi-path loop summarization system based on path dependence analysis disclosed by the embodiment of the present application is shown in the figure.

[0065] Figure 3 The flowchart of the multi-path loop summarization method based on path dependence analysis disclosed by the embodiment of the present application is shown in the figure.

[0066] Figure 4 The running flowchart of the loop slicing unit disclosed by the embodiment of the present application is shown in the figure.

[0067] Figure 5 The example diagram of an example program and the corresponding sliced program flow graph disclosed by the embodiment of the present application is shown in the figure.

[0068] Figure 6 The working flowchart of the path extractor disclosed by the embodiment of the present application is shown in the figure.

[0069] Figure 7 The working flowchart of the path dependence automaton constructor and the transition condition calculator disclosed by the embodiment of the present application is shown in the figure.

[0070] Figure 8An example graph for constructing a dependent path automaton model is disclosed for the embodiments of the present application.

[0071] Figure 9 A loop summary unit workflow diagram is disclosed for the embodiments of the present application. DETAILED DESCRIPTION

[0072] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative efforts fall within the scope of the present application.

[0073] In the present application, the terms “comprises”, “comprising”, or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or apparatus that comprises a list of elements does not only include those elements, but also includes other elements not expressly listed or inherent to such process, method, article, or apparatus. Without more limitations, an element defined by the phrase “comprises a” does not exclude the presence of additional identical elements in the process, method, article, or apparatus that includes the element.

[0074] First, the technical terms appearing in the present application are explained as follows:

[0075] Loop summary: Loop summary is a static analysis technique for calculating the relationship between loop input and output, given a loop and input, the loop output result is calculated without actually executing the loop. The loop summary result can be directly replaced by the loop structure, so as to optimize the loop structure and improve the efficiency of loop execution. In program analysis, replacing the loop with the loop summary result can avoid iterative loops, which has important significance in program verification, code optimization, etc.

[0076] Integer multi-path inductive type loop: a specific type of loop, the loop involves variables that are all integers, there are if, else and other multi-branch paths, and the variables are all inductive variables. Inductive variable is the value of the variable after executing n times. For example, x++, after n times of execution, the value of x can be inducted as x=x+n. For example, x=(x+1) 2 , after the first execution, the value of x is (x+1) 2 , after the second execution, the value of x is ((x+1) 2 +1) 2 , which cannot be inducted to the execution result of x after n times of execution.

[0077] Program flow graph: Also known as control flow graph. It is a data structure used to represent the control flow of a program, which is a directed graph. It can be visualized in the form of a graph to help developers understand, design and optimize the code structure.

[0078] Loop path: The execution path taken from the beginning of a loop to the next time the loop is executed.

[0079] Loop variable: Loop variable refers to the variable whose value determines the execution path of the loop. Generally, loop variables include variables in loop conditions and variables related to loop jump statements (break, continue, etc.).

[0080] Automaton: A finite state automaton, also known as a state machine. It is a mathematical model used to represent a finite number of states and the transitions and actions between these states. There are four types of actions: entry action, exit action, input action, and transition action. The initial state of an automaton is the state that has no arrow pointing to it in the finite state automaton, i.e. the initial state. The end state of an automaton is the end state of the finite state automaton, represented by a double circle. That is, the acceptance state of the automaton.

[0081] Path-dependent automaton (or path-dependent automaton model): An automaton used for loop summarization. The state of the automaton identifies the execution path of each loop, and the state transition condition is the transition condition of each loop execution path. The initial state of the automaton is the start state of the loop, and the end state is the loop exit state.

[0082] Symbolic constraint: A logical or mathematical constraint imposed on the symbolic representation of a program variable. It is usually a logical expression. For example, a == b && b < 5.

[0083] Program slicing: Program slicing is a program analysis technique used to decompose a program. A program that only contains statements and predicates related to a certain output statement is called a static slice of the source program.

[0084] Path explosion: Refers to the situation where, during program analysis, the presence of conditional branches and other structures in the program causes the program to have exponentially growing execution paths, making program analysis infeasible.

[0085] Loop unrolling: A program optimization technique that reduces the number of iterations of a loop and increases the amount of computation performed in each iteration, thereby reducing the overhead of loop control and improving program execution efficiency. The loop unrolling factor is an important parameter for loop unrolling, which controls the degree of loop unrolling. By reducing the overhead of loop structures, it improves instruction set parallelism and cache utilization. For example, when the loop unrolling factor is 2, the loop is iterated in parallel with 2 threads, thereby reducing the running time by half.

[0086] Breadth-first algorithm: This algorithm performs a breadth-first scan, which is an algorithm used to traverse or search a tree or graph. It starts from the starting point and gradually explores all adjacent nodes, and then continues to explore the adjacent nodes of these adjacent nodes until it finds the target node or traverses the entire data structure.

[0087] As can be seen from the background technology, at present, the commonly used loop optimization method in the industry is loop unrolling, which only reduces the loop execution time through parallel technology. This method still requires executing each step of the loop step by step, which is not only time-consuming but also fails to optimize the loop structure.

[0088] Therefore, an embodiment of the present invention discloses a multi-path loop summary method and system based on path dependency analysis. In this solution, by constructing a path dependency automaton, loop summary is performed based on the path dependency automaton, and the input and output results of the target loop program are automatically derived to obtain a loop summary result for optimizing the target loop program, avoiding the step-by-step execution of each loop of the target loop program, thereby achieving the purpose of optimizing the loop structure and saving the execution time of the target loop program.

[0089] like Figure 1 , which is an architecture diagram of a multi-path loop summary system based on path dependency analysis disclosed in an embodiment of the present invention, including: a loop slicing unit, a path dependency automaton construction unit and a loop summary unit.

[0090] The loop slicing unit is used to obtain the target loop program; construct the program flow graph of the target loop program, and slice the program flow graph to obtain the sliced ​​program flow graph; the path-dependent automaton construction unit is used to construct a path-dependent automaton model based on the sliced ​​program flow graph; the loop summary unit is used to perform loop summary based on the preset breadth-first algorithm and path-dependent automaton model to obtain the loop summary result.

[0091] Among them, the loop slicing unit is composed of a program flow graph builder and a program flow graph slicer. The loop slicing unit is used to simplify the target loop program, delete useless branches in the loop, retain the core logic of the target loop program, and reduce the program complexity; the path-dependent automaton construction unit is composed of a path extractor, a path-dependent automaton builder, and a transfer condition calculator; the loop summary unit includes a path-dependent automaton traverser.

[0092] Based on the multi-path cycle summary system based on path dependency analysis disclosed in the above embodiment of the present invention, Figure 2 FIG. 1 is a flowchart of a multi-path cycle summary system based on path dependency analysis disclosed in an embodiment of the present invention. The main process includes:

[0093] 1. In the loop slicing unit, the program flow graph builder is used to statically scan the input target loop program and build a program flow graph. The program flow graph slicer is then used to slice and simplify the program based on the program flow graph to exclude loop-irrelevant code.

[0094] Specifically, the program flow graph builder is used to obtain a target loop program; and build a program flow graph of the target loop program based on a preset program flow graph building algorithm;

[0095] A program flow graph slicer is used to check whether the target loop program meets the preset target type; the target type includes: integer multi-path inductive type loop; if not, it is determined that the target loop program cannot be analyzed and the process ends; if so, the loop variables in the program flow graph are read and the loop variables are added to the preset loop variable set; the loop variables include: variables involved in the loop conditions in the program flow graph and variables involved in the jump statements in the program flow graph; each statement in the program flow graph is scanned; if there is a target variable in the statement that affects the value of any loop variable in the loop variable set, the statement is added to the simplified program flow graph and the target variable is added to the loop variable set; the simplified program flow graph is a blank program flow graph in the initial state; return to execute the step of scanning each statement in the program flow graph until there is no target variable in each statement that affects the value of any loop variable in the loop variable set, and the simplified program flow graph is used as the program flow graph after the first slice; remove the predefined useless statements from the program flow graph after the first slice to obtain the sliced ​​program flow graph.

[0096] 2. In the path-dependent automaton construction unit, the path extractor receives the sliced ​​program flow graph output by the loop slicing unit and performs loop path calculation and extraction; the path-dependent automaton builder constructs dependent automaton states and automaton state transition relationships based on the path-dependent automaton construction algorithm; the transition condition calculator calculates the transition conditions corresponding to the automaton state transition relationships, and finally, based on each dependent automaton state, automaton state transition relationship, and each transition condition, constructs and outputs a path-dependent automaton model.

[0097] Specifically, the path extractor is used to perform a breadth-first scan on the sliced ​​program flow graph to construct a path result set; the path result set includes: multiple loop paths and symbolic constraints that must be met when executing each loop path.

[0098] Optional, path extractor, specifically used for:

[0099] The path result set and the first node queue are created and initialized to be empty, an initial node in the sliced program flow graph is added to the first node queue, it is determined whether the first node queue is empty, if the first node queue is not empty, a first node in the first node queue is taken as a target node, a path adjacent node adjacent to the target node is obtained from the sliced program flow graph, a target path from the target node to the path adjacent node and a first symbolic constraint required for executing the target path are calculated, it is determined whether the path adjacent node is a loop node or an end node, if the path adjacent node is the loop node or the end node, the target path and the first symbolic constraint are added to the path result set, if the path adjacent node is not the loop node or the end node, the path adjacent node is added to the first node queue, the step of determining whether the first node queue is empty is returned, and if the first node queue is empty, a constructed path result set is obtained.

[0100] The path-dependent automaton builder is configured to, for each loop path, establish a corresponding dependent automaton state based on a symbolic constraint corresponding to the loop path, and establish an automaton state transition relationship based on a loop path relationship between each loop path represented in the sliced program flow graph.

[0101] The transition condition calculator is configured to, for each dependent automaton state transition relationship, calculate a corresponding transition condition, and the transition condition includes an execution frequency of a loop path before transition, a transition trigger condition, and a calculation manner of a loop variable result after transition, and the path-dependent automaton model is constructed based on each dependent automaton state, the automaton state transition relationship, and each transition condition.

[0102] 3. In the loop summarization unit, the path-dependent automaton traverser traverses and summarizes the path-dependent automaton model output by the path-dependent automaton building unit based on the path-dependent automaton model through a breadth-first algorithm, and outputs a loop summary result.

[0103] Specifically, the path-dependent automaton traverser is configured to create a summary result set and a second node queue, and initialize the summary result set and the second node queue to be empty; add a first dependent automaton state in the path-dependent automaton model as a node to the second node queue; determine whether the second node queue is empty; if the second node queue is not empty, take a first node in the second node queue as a target node; obtain a dependent automaton state adjacent to the first dependent automaton state from the path-dependent automaton model as a state adjacent node; obtain a transition condition between the target node and the state adjacent node from the path-dependent automaton model, and calculate a target variable result based on a calculation manner of a post-transition loop variable result in the transition condition; obtain a symbolic constraint corresponding to the state adjacent node from the path-dependent automaton model, and simplify the symbolic constraint into a second symbolic constraint; determine whether there is a dependent automaton state adjacent to the state adjacent node in the path-dependent automaton model; if yes, add the target variable result and the second symbolic constraint to the summary result set; if no, add the state adjacent node to the second node queue; return to the step of determining whether the second node queue is empty; and if the second node queue is empty, determine the summary result set as a loop summary result.

[0104] Based on the path-dependent analysis-based multi-path loop summarization system disclosed in the above embodiments of the present application, as shown in Figure 3 the flowchart of the path-dependent analysis-based multi-path loop summarization method disclosed in the embodiments of the present application includes the following steps:

[0105] Step S101: Obtain a target loop program.

[0106] Step S102: Construct a program flowchart of the target loop program, and perform slicing processing on the program flowchart to obtain a sliced program flowchart.

[0107] As shown in Figure 4 the loop slicing unit running flowchart disclosed in the embodiments of the present application.

[0108] In the specific implementation process of step S102, the program flowchart constructor performs the following process:

[0109] Based on a preset program flowchart construction algorithm, construct a program flowchart of the target loop program; determine whether the target loop program meets a preset target type; if not, determine that the target loop program cannot be analyzed, and end the flowchart; if yes, read a loop variable in the program flowchart, and add the loop variable to a preset loop variable set.

[0110] The target type includes: an integer multi-path inductively type loop; and the loop variable includes: a variable involved in a loop condition in the program flowchart and a variable involved in a jump statement in the program flowchart.

[0111] The program flow graph slicer performs the following process:

[0112] Scan each statement in the program flow graph; if there is a target variable in the statement that can affect the value of any loop variable in the loop variable set, add the statement to the reduced program flow graph and add the target variable to the loop variable set; return to the step of scanning each statement in the program flow graph until there is no target variable in each statement that can affect the value of any loop variable in the loop variable set, and take the reduced program flow graph as the first sliced program flow graph; remove the predefined useless statements from the first sliced program flow graph to obtain the sliced program flow graph.

[0113] In the initial state, the reduced program flow graph is a blank program flow graph.

[0114] As shown in Figure 5 , it is an example diagram of an example program and a corresponding sliced program flow graph disclosed by an embodiment of the present application.

[0115] For example, the program flow graph constructor reads in the target loop program and generates the program flow graph of the target loop program according to the program flow graph construction algorithm.

[0116] For example, the target loop program is shown on the left side, and the program flow graph of the target loop program is shown on the right side. Figure 5 Figure 5

[0117] Then, the program flow graph constructor checks whether the target loop program is an integer multi-path inductive type loop. If not, it directly returns that the target type is not met and cannot be analyzed.

[0118] If yes, the program flow graph slicer scans the program flow graph in a loop, and adds the variables involved in the loop condition and the variables involved in the jump statement to the loop variable set.

[0119] In each scanning loop, if there is a variable of a statement that can affect the loop variable and the variable is not in the loop variable set, the variable is added to the loop variable set, and the statement is added to the reduced program flow graph.

[0120] After each scanning loop, if the loop variable set is increased, the scanning loop is performed again, otherwise the scanning is ended.

[0121] Finally, the program flow graph slicer reduces the useless statements to generate the final sliced program flow graph, as shown on the right side. Figure 5 The final sliced program flow graph is the node in the gray filled box.

[0122] ​​The node with the frame line of the gray filled box being red is a loop node, the node with the frame line of the gray filled box being blue is an end node, and the white filled box is a useless statement (which can be predefined) and is deleted from the program flow graph. The node in which the gray filled box is located is the program flow graph after slicing.

[0123] Step S103: based on the program flow graph after slicing, a path-dependent automaton model is constructed.

[0124] In step S103, first, the path extractor calculates and extracts the loop path, summarizes all loop paths in the target program flow graph, the path-dependent automaton constructor receives all loop paths, constructs the dependent automaton state according to the path-dependent automaton construction algorithm, and then the transition condition calculator calculates the transition condition of the generated path-dependent automaton, and based on each dependent automaton state, the automaton state transition relationship and each transition condition, the path-dependent automaton model is constructed and output.

[0125] In the specific implementation process of step S103, the following steps are included:

[0126] Step S201: breadth-first scanning is performed on the program flow graph after slicing to construct a path result set.

[0127] The path result set includes: multiple loop paths and the symbolic constraints that need to be met for executing each loop path.

[0128] It should be noted that the loop path is used to identify a path of a loop and show the situation of one loop execution. The path extractor obtains all loop paths in the target loop program and the symbolic constraints of the loop path by scanning the program flow graph and performing breadth-first scanning.

[0129] In the workflow of the path extractor constructing the path result set, the path flow graph output by the loop slicing unit is read; the path result set and the path queue are initialized to be empty; the node at the beginning of the program flow graph is added to the path queue; when the path queue is not empty, the following loop is executed: the node at the head of the path queue is taken, the adjacent nodes are scanned according to the program flow graph, and the symbolic constraints of the reached nodes are recorded; if the node is a loop node or an end node, the node and the previous path and symbolic constraints are added to the path result set; if the node is not a loop node or an end node, the node is added to the path queue; the path result set is output, and the workflow of the path extractor is completed.

[0130] As shown in FIG. 8, it is a workflow diagram of the path extractor disclosed in the embodiment of the present application. Figure 6

[0131] ​In a specific implementation, a path result set and a first node queue (i.e., a path queue) are created, and are initialized to be empty; an initial node in the sliced program flow graph is added to the first node queue; it is determined whether the first node queue is empty; if the first node queue is not empty, a first node in the first node queue is taken as a target node; a path adjacent node adjacent to the target node is obtained from the sliced program flow graph, and a target path from the target node to the path adjacent node and a first symbolic constraint required for executing the target path are calculated; it is determined whether the path adjacent node is a loop node or an end node; if yes, the target path and the first symbolic constraint are added to the path result set; if no, the path adjacent node is added to the first node queue; the step of determining whether the first node queue is empty is returned; and if the first node queue is empty, a constructed path result set is obtained.

[0132] Step S202: For each loop path, a corresponding dependency automaton state is established based on a symbolic constraint corresponding to the loop path, and an automaton state transition relationship is established according to a loop path relationship between each loop path represented in the sliced program flow graph.

[0133] The dependency automaton state corresponding to the loop path includes a path execution condition of the loop path and a path execution result of the loop path.

[0134] It should be noted that the path dependency automaton builder, according to the path dependency automaton building algorithm, takes each loop path output by the path extractor as a path dependency automaton state, and takes a transition relationship between loop paths as an automaton state transition relationship.

[0135] Step S203: For each dependency automaton state transition relationship, a corresponding transition condition is calculated, and a path dependency automaton model is constructed based on each dependency automaton state, the automaton state transition relationship, and each transition condition.

[0136] The transition condition includes a number of executions of the loop path before the transition, a transition trigger condition, and a calculation method of a loop variable result after the transition.

[0137] It should be noted that the number of executions of the loop path before the transition is a precondition for the transition to occur.

[0138] It can be understood that step S202 is performed by the path dependency automaton builder, and step S203 is performed by the transition condition calculator.

[0139] As shown in FIG. 2, it is a working flow chart of the path dependency automaton builder and the transition condition calculator disclosed in the embodiment of the present application. Figure 7

[0140] ​Specifically, the path-dependent automaton builder reads the loop paths and the program flow graph output by the path extractor; according to the path-dependent automaton building algorithm, the path-dependent automaton state (including the path execution condition and the path execution result) is established for each loop path; according to the relationship between the loop paths in the program flow graph, the automaton state transition relationship is established; the transition condition calculator traverses each automaton state transition relationship to perform transition condition calculation (the transition condition includes: the execution number of the loop path before transition, the transition trigger condition and the calculation method of the loop variable result after transition); after all state transitions are calculated, the path-dependent automaton model is output (which is constructed based on each dependent automaton state, the automaton state transition relationship and each transition condition).

[0141] As shown in Figure 8 , it is an example diagram for constructing a dependent path automaton model disclosed in an embodiment of the application.

[0142] Among them, Figure 8 The right side is the dependent automaton model, and the transition condition generated by the transition condition calculator is the transition condition on the state transition arrow in the right side dependent automaton model. Figure 8 The loop node is Figure 8 The red node on the left side, the end node is Figure 7 The blue node on the left side.

[0143] For example, the path extractor can extract the loop paths of the program flow graph shown in Figure 5 , which includes four paths (R1-R4), and the corresponding symbolic constraints are the total symbolic constraints of all path executions, for example, the constraint of R2 is x<n^z>x^True.

[0144] The path-dependent automaton builder establishes the corresponding dependent automaton state for each loop path according to the path-dependent automaton building algorithm, and the dependent automaton state includes: the path execution condition and the path execution result (the Figure 8 The right circular part is the dependent automaton state).

[0145] For example, the dependent automaton state of the loop path R2 is constructed, R2 path includes four states b->c->e->b, the constraint of b->c is x<n, the constraint of c->e is z>x, and the constraint of e->b is True, so the path execution condition of R2 is x<n^z>x^True, which is simplified to x<n^z>x. R2 path only contains x++ operation, and the path execution result of R2 is x++.

[0146] The transition condition calculator calculates the transition condition of each dependent automaton state transition relationship (i.e. between each dependent automaton state), and the transition condition includes: the execution number of the loop path before transition, the transition trigger condition and the calculation method of the loop variable result after transition.

[0147] For example Figure 8 As shown in the state transition of R1->R3, the first row represents the number of executions K 1,3 The second row represents the transition trigger condition x<n^z<=x, which means that if the variable satisfies the expression before R1 is executed, R1 will be transferred to R3. The third row represents the variable results x'=x, n'=n, and z'=z after R1 is executed, which means that when R1 is transferred to R3, the execution results of each variable after R1 is executed (i.e., the calculation method of the loop variable results after the transition).

[0148] wherein, Figure 8 The right arrow is the state transition relationship of the dependency automaton, Figure 8 and the right box is the transition condition.

[0149] For example, R2 and R3. The tail node of R2 is b, and the head node of R3 is b, so there is a state transition R2->R3. Assuming that R2 is transferred from the state R2 to the state R3 after executing α=K 2,3 times, then the condition x+α-1<n^z>x+α-1^x+α<n^z<=x+α should be satisfied. After solving, it is found that when z<n is satisfied, the solution is α=z-x, and the transition condition before R2 is transferred to R3 is x'=z, z'=z, and n'=n. That is, when z<n is satisfied, R2 is transferred to R3 after executing z-x times, and before the transition to R3, the value of x is z, the value of z is z, and the value of n is n.

[0150] Finally, the transition condition calculator can construct and output Figure 8 the path-dependent automaton model on the right side based on each dependency automaton state, automaton state transition relationship, and each transition condition.

[0151] Step S104: performing loop summarization based on the preset breadth-first algorithm and the path-dependent automaton model to obtain a loop summarization result.

[0152] As Figure 9 shown in the figure is a loop summarization unit workflow diagram disclosed in an embodiment of the present application.

[0153] In a specific implementation, a summary result set and a second node queue are created and initialized to be empty; a first dependency automaton state in the path-dependent automaton model is added to the second node queue as a node; it is determined whether the second node queue is empty; if the second node queue is not empty, a first node in the second node queue is taken out as a target node; a dependency automaton state adjacent to the first dependency automaton state is obtained from the path-dependent automaton model as a state-adjacent node; a transition condition between the target node and the state-adjacent node is obtained from the path-dependent automaton model, and a target variable result is calculated based on a calculation manner of a post-transition loop variable result in the transition condition; a symbol constraint corresponding to the state-adjacent node is obtained from the path-dependent automaton model and is simplified as a second symbol constraint; it is determined whether there is still a dependency automaton state adjacent to the state-adjacent node in the path-dependent automaton model (i.e., it is determined whether the state-adjacent node is an end node); if yes, the target variable result and the second symbol constraint are added to the summary result set; if no, the state-adjacent node is added to the second node queue; the step of determining whether the second node queue is empty is returned; and if the second node queue is empty, the summary result set is determined as a loop summary result.

[0154] For example, the R1->R2->R4 state transition path of the path-dependent automaton model on the right is summarized. Figure 8 For example, the R1->R2->R4 state transition path of the path-dependent automaton model on the right is summarized.

[0155] Firstly, the R1 node has a node variable result of x’=x, z’=z, n’=n, and a node constraint of True. According to the R1->R2 transition relationship, the node variable result is x’=x, z’=z, n’=n, and the node symbol constraint is True^x<n^z>x, which is simplified to x<n^z>x. According to the R2->R4 transition relationship, the node variable result is x’=n, z’=z, n’=n, and the node symbol constraint is True^x<n^z>x^z>=n, which is simplified to z>=n^n>x. Since R4 is an end node, the summary result of the path [z>=n^n>x; x’=n, z’=z, n’=n] is output, that is, for the example program in Figure 5

[0156] ​Based on the above-mentioned embodiment of the application, the method for summarizing a multi-path cycle based on path dependence analysis is disclosed, in the present scheme, by constructing a path dependence automaton, performing cycle summarization based on the path dependence automaton, automatically deriving the input and output results of the target cycle program, obtaining the cycle summarization result for optimizing the target cycle program, avoiding step-by-step execution of each cycle of the target cycle program, thereby realizing the optimization of the cycle structure and saving the execution time of the target cycle program.

[0157] Each embodiment in the specification is described in a progressive manner, and the same or similar parts between each embodiment can be referred to each other. Each embodiment mainly describes the difference from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, it is described more simply, and the related parts can be referred to the part of the method embodiment. The above-described system and system embodiment are only illustrative, and the units described as separate components can be or can not be physically separated, and the components displayed as units can be or can not be physical units, that is, they can be located in one place or distributed on multiple network units. Part or all of the modules can be selected to achieve the purpose of the embodiment according to actual needs. Those skilled in the art can understand and implement without creative labor.

[0158] The skilled person can further realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be realized by electronic hardware, computer software or a combination of both. In order to clearly illustrate the interchangeability of hardware and software, the components and steps of the examples have been described in general terms in the above description. Whether the functions are realized in hardware or software depends on the specific application and design constraints of the technical solution. The skilled person can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.

[0159] The above description of the disclosed embodiments enables a person skilled in the art to implement or use the present application. Various modifications to the embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A multi-path cycle summary method based on path dependency analysis, characterized in that: The method comprises: Get the target loop program; Constructing a program flow graph of the target loop program, and slicing the program flow graph to obtain a sliced ​​program flow graph; Based on the sliced ​​program flow graph, a path-dependent automaton model is constructed; Based on the preset breadth-first algorithm and the path-dependent automaton model, a cyclic summary is performed to obtain a cyclic summary result.

2. The method according to claim 1, characterized in that The step of constructing a program flow graph of the target loop program and slicing the program flow graph to obtain a sliced ​​program flow graph includes: Based on a preset program flow graph construction algorithm, construct a program flow graph of the target loop program; Checking whether the target cycle program meets the preset target type; the target type includes: integer multi-path inductive type cycle; If not, it is determined that the target cycle program cannot be analyzed, and the process ends; If so, read the loop variables in the program flow graph and add the loop variables to a preset loop variable set; the loop variables include: variables involved in the loop conditions in the program flow graph and variables involved in the jump statements in the program flow graph; Scanning each statement in the program flow graph; If the statement contains a target variable that affects the value of any of the loop variables in the loop variable set, then adding the statement to a simplified program flow graph, and adding the target variable to the loop variable set; the simplified program flow graph is initially blank; Returning to the step of scanning each statement in the program flow graph until no target variable that affects the value of any loop variable in the loop variable set exists in each statement, and using the simplified program flow graph as the program flow graph after the first slicing; Predefined useless statements are removed from the program flow graph after the first slicing to obtain a program flow graph after slicing.

3. The method according to claim 1, characterized in that The step of constructing a path-dependent automaton model based on the sliced ​​program flow graph includes: Performing a breadth-first scan on the sliced ​​program flow graph to construct a path result set; the path result set includes: multiple loop paths and symbolic constraints that must be satisfied when executing each of the loop paths; For each of the loop paths, establishing a corresponding dependent automaton state based on the symbolic constraint corresponding to the loop path; Establishing an automaton state transition relationship according to a loop path relationship between the loop paths represented in the sliced ​​program flow graph; For each of the dependent automaton state transition relationships, a corresponding transition condition is calculated; the transition condition includes: the number of executions of the loop path before the transition, the transition triggering condition, and the calculation method of the loop variable result after the transition; A path-dependent automaton model is constructed based on the dependent automaton states, the automaton state transition relations, and the transition conditions.

4. The method according to claim 3, characterized in that The breadth-first scanning is performed on the sliced ​​program flow graph to construct a path result set, including: Creating a path result set and a first node queue, and initializing the path result set and the first node queue to be empty; Adding the initial node in the sliced ​​program flow graph to the first node queue; Determine whether the first node queue is empty; If the first node queue is not empty, taking the first node in the first node queue as the target node; Acquire path adjacent nodes adjacent to the target node from the sliced ​​program flow graph, and calculate a target path from the target node to the path adjacent nodes and a first symbol constraint that needs to be satisfied when executing the target path; Determine whether the path adjacent node is a loop node or an end node; if so, add the target path and the first symbol constraint to the path result set; if not, add the path adjacent node to the first node queue; Return to the step of determining whether the first node queue is empty; If the first node queue is empty, the constructed path result set is obtained.

5. The method according to claim 3, characterized in that The loop summary is performed based on the preset breadth-first algorithm and the path-dependent automaton model to obtain a loop summary result, including: Creating a summary result set and a second node queue, and initializing the summary result set and the second node queue to be empty; Adding the first dependent automaton state in the path dependent automaton model as a node to the second node queue; Determine whether the second node queue is empty; If the second node queue is not empty, taking the first node in the second node queue as the target node; From the path-dependent automaton model, obtaining the dependent automaton state adjacent to the first dependent automaton state as a state adjacent node; Obtaining the transfer condition between the target node and the state-adjacent node from the path-dependent automaton model, and calculating the target variable result based on the calculation method of the post-transfer loop variable result in the transfer condition; Obtaining the symbolic constraints corresponding to the state adjacent nodes from the path-dependent automaton model and simplifying them into a second symbolic constraint; Determine whether there is still a dependent automaton state adjacent to the state adjacent node in the path dependent automaton model; if so, add the target variable result and the second symbolic constraint to the summary result set; if not, add the state adjacent node to the second node queue; Return to the step of determining whether the second node queue is empty; If the second node queue is empty, the summary result set is determined to be a circular summary result.

6. A multi-path cycle summary system based on path dependency analysis, characterized in that: The system comprises: A loop slicing unit is used to obtain a target loop program; construct a program flow graph of the target loop program, and slice the program flow graph to obtain a sliced ​​program flow graph; A path-dependent automaton construction unit, configured to construct a path-dependent automaton model based on the sliced ​​program flow graph; The loop summarizing unit is used to perform loop summarizing based on a preset breadth-first algorithm and the path-dependent automaton model to obtain a loop summarizing result.

7. The system according to claim 6, characterized in that The loop slicing unit includes: a program flow graph builder and a program flow graph slicer; The program flow graph builder is used to obtain a target cycle program; and build a program flow graph of the target cycle program based on a preset program flow graph building algorithm; The program flow graph slicer is used to check whether the target loop program meets a preset target type; the target type includes: an integer multi-path inductive type loop; if not, it is determined that the target loop program cannot be analyzed and the process is terminated; if so, the loop variables in the program flow graph are read and the loop variables are added to a preset loop variable set; the loop variables include: variables involved in the loop conditions in the program flow graph and variables involved in the jump statements in the program flow graph; each statement in the program flow graph is scanned; if the statement contains a target variable that affects the value of any of the loop variables in the loop variable set, the statement is added to a simplified program flow graph and the target variable is added to the loop variable set; the simplified program flow graph is initially a blank program flow graph; the step of scanning each statement in the program flow graph is returned to execute until there is no target variable that affects the value of any of the loop variables in the loop variable set in each statement, and the simplified program flow graph is used as the program flow graph after the first slicing; predefined useless statements are removed from the program flow graph after the first slicing to obtain a sliced ​​program flow graph.

8. The system according to claim 6, wherein: The path-dependent automaton construction unit includes: a path extractor, a path-dependent automaton builder, and a transfer condition calculator; The path extractor is configured to perform a breadth-first scan on the sliced ​​program flow graph to construct a path result set; the path result set includes: a plurality of loop paths and symbolic constraints that must be satisfied when executing each of the loop paths; The path-dependent automaton builder is configured to establish, for each loop path, a corresponding dependent automaton state based on the symbolic constraint corresponding to the loop path; and to establish an automaton state transition relationship based on the loop path relationship between the loop paths represented in the sliced ​​program flow graph; The transfer condition calculator is used to calculate the corresponding transfer condition for each dependent automaton state transfer relationship; the transfer condition includes: the number of executions of the loop path before the transfer, the transfer trigger condition and the calculation method of the loop variable result after the transfer; based on each dependent automaton state, the automaton state transfer relationship and each transfer condition, a path dependent automaton model is constructed.

9. The system according to claim 8, characterized in that The path extractor is specifically used to: Creating a path result set and a first node queue, and initializing the path result set and the first node queue to be empty; adding the initial node in the sliced ​​program flow graph to the first node queue; determining whether the first node queue is empty; and if the first node queue is not empty, taking the first node in the first node queue as the target node; Obtaining path adjacent nodes adjacent to the target node from the sliced ​​program flow graph, and calculating a target path from the target node to the path adjacent nodes and a first symbol constraint that needs to be satisfied for executing the target path; determining whether the path adjacent nodes are loop nodes or end nodes; if so, adding the target path and the first symbol constraint to the path result set; if not, adding the path adjacent nodes to the first node queue; Return to the step of determining whether the first node queue is empty; if the first node queue is empty, obtain the constructed path result set.

10. The system according to claim 8, wherein: The cycle summarizing unit includes: a path-dependent automaton traverser; The path-dependent automaton traverser is used to create a summary result set and a second node queue, and initialize the summary result set and the second node queue to be empty; add the first dependent automaton state in the path-dependent automaton model as a node to the second node queue; determine whether the second node queue is empty; if the second node queue is not empty, take out the first node in the second node queue as the target node; obtain the dependent automaton state adjacent to the first dependent automaton state from the path-dependent automaton model as a state adjacent node; obtain the transfer condition between the target node and the state adjacent node from the path-dependent automaton model, And based on the calculation method of the loop variable result after the transfer in the transfer condition, the target variable result is calculated; from the path-dependent automaton model, the symbolic constraint corresponding to the state adjacent node is obtained, and simplified into a second symbolic constraint; it is determined whether the dependent automaton state adjacent to the state adjacent node still exists in the path-dependent automaton model; if so, the target variable result and the second symbolic constraint are added to the summary result set; if not, the state adjacent node is added to the second node queue; return to execute the step of determining whether the second node queue is empty; if the second node queue is empty, it is determined that the summary result set is a loop summary result.