Program compiling method and device, equipment, medium and program product
The target program variables are renamed through the static single-assignment SSA algorithm and a collection of SSA formal names is constructed, which solves the problem that existing compilers take a long time to create DU chains and UD chains, and improves compilation efficiency.
Patent Information
- Application Number
- CN202310396523.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-12
- Publication Date
- 2024-10-18
AI Technical Summary
When existing compilers create DU chains and UD chains, the process takes a long time, resulting in low compilation efficiency.
The static single-assignment SSA algorithm is used to rename variables in the target program so that they have fixed value points, and a set of SSA formal names is constructed, thereby reducing the number of traversals of the target program and improving the creation efficiency of DU chains and UD chains.
Renaming variables through the SSA algorithm enables rapid compilation of the target program and improves compilation efficiency.
Smart Images

Figure CN118796205A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of computer program compilation, and in particular to a program compilation method, apparatus, device, medium and program product. Background Art
[0002] Compiler, also known as compiler, refers to the process of translating source programs written in high-level programming languages into equivalent machine language target programs. Definite value-use chain (abbreviated as: DU chain) and use-definite value chain (abbreviated as: UD chain) are very important structures in all compilers. They are the prerequisites for compilers to optimize programs when compiling programs. In the process of compiler compiling programs, the program needs to be analyzed first, and then the DU chain and UD chain need to be created.
[0003] Currently, the data stream iterative fixed point algorithm is used to create DU chains and UD chains. However, the creation process of the algorithm is time-consuming, resulting in low creation efficiency, which in turn leads to low program compilation efficiency. Summary of the invention
[0004] The embodiments of the present application provide a program compilation method, apparatus, device, medium and program product to solve the technical problem in the prior art that the creation process is time-consuming, resulting in low creation efficiency, and further resulting in low program compilation efficiency.
[0005] In a first aspect, the present application provides a program compiling method, comprising:
[0006] Get the target program to be compiled;
[0007] Rename at least one variable in the target program using a static single assignment (SSA) algorithm so that each renamed variable has a corresponding fixed value point;
[0008] For each renamed variable, construct an SSA formal name set, wherein the SSA formal name set includes an SSA formal name, a setting point, and a use point corresponding to each renamed variable;
[0009] According to the SSA formal name set, construct a target constant value-use DU chain and a target use-constant value UD chain corresponding to the target program;
[0010] The target program is compiled based on the target DU chain and the UD chain.
[0011] In a second aspect, the present application provides a program compiling device, comprising:
[0012] An acquisition module is used to acquire the target program to be compiled;
[0013] A renaming module, used for renaming at least one variable in the target program by using a static single assignment SSA algorithm, so that each renamed variable has a corresponding fixed value point;
[0014] A first construction module is used to construct an SSA formal name set for each renamed variable, wherein the SSA formal name set includes an SSA formal name, a setting point and a use point corresponding to each renamed variable;
[0015] The second construction module is used to construct a target fixed value-use DU chain and a target use-fixed value UD chain corresponding to the target program according to the SSA formal name set;
[0016] A compiling module is used to compile the target program based on the target DU chain and the UD chain.
[0017] In a third aspect, an embodiment of the present application provides a program compiling device, comprising: a processor, and a memory communicatively connected to the processor;
[0018] The memory stores computer-executable instructions;
[0019] The processor executes the computer-executable instructions stored in the memory to implement the method according to the first aspect.
[0020] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by at least one processor, the method described in the first aspect is implemented.
[0021] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which implements the method described in the first aspect when executed by a processor.
[0022] The program compilation method, device, equipment, medium and program product provided by the embodiment of the present application obtain the target program to be compiled; rename at least one variable in the target program using the static single assignment SSA algorithm so that each renamed variable has a corresponding fixed value point; for each renamed variable, construct an SSA formal name set, the SSA formal name set has the SSA formal name, fixed value point and use point corresponding to each renamed variable; according to the SSA formal name set, construct the target fixed value-use DU chain and target use-fixed value UD chain corresponding to the target program; compile the target program based on the target DU chain and UD chain. Since the SSA algorithm is used to rename at least one variable in the target program, each renamed variable has a corresponding fixed value point to form an SSA formal name set. Therefore, only a small amount of traversal of the target program is required to construct the target fixed value-use DU chain and target use-fixed value UD chain corresponding to the target program based on the SSA formal name, fixed value point and use point corresponding to each renamed variable in the SSA formal name set. Therefore, the number of traversals of the target program is effectively reduced, thereby effectively improving the efficiency of creating DU chains and UD chains and the efficiency of compiling programs. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0024] Figure 1 An application scenario diagram of a program compilation method provided by an embodiment of the present application;
[0025] Figure 2 A flowchart of a program compiling method provided in one embodiment of the present application;
[0026] Figure 3 A flowchart of a program compiling method provided by another embodiment of the present application;
[0027] Figure 4 A schematic diagram of a target program in a program compilation method provided in an embodiment of the present application;
[0028] Figure 5 A schematic diagram of a target program in which a Phi instruction is inserted in a program compilation method provided in an embodiment of the present application;
[0029] Figure 6 A schematic diagram of a target program after renaming at least one variable in a target program with a variable merging instruction in the program compilation method provided in an embodiment of the present application;
[0030] Figure 7 A schematic diagram of the structure of a program compiling device provided in one embodiment of the present application;
[0031] Figure 8 A schematic diagram of the structure of a program compiling device provided in one embodiment of the present application;
[0032] Fig. 9 is a structural diagram showing a board according to an embodiment of the present application;
[0033] Fig.10 is a structural diagram showing a combined processing device according to an embodiment of the present application;
[0034] Fig.11 is a schematic diagram showing the internal structure of a single-core computing device according to an embodiment of the present application;
[0035] Fig.12 is a schematic diagram showing the internal structure of a multi-core computing device according to an embodiment of the present application;
[0036] Fig.13 Schematic diagram showing the internal structure of a processor core according to an embodiment of the present application.
[0037] The above drawings show clear embodiments of the present disclosure, which will be described in more detail below. These drawings and text descriptions are not intended to limit the scope of the present disclosure in any way, but to illustrate the concepts of the present disclosure to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0038] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0039] First, the terms in this application are introduced in detail:
[0040] Constant value: The value assigned to a variable in a program is called a constant value.
[0041] Define-use chain: Define-use chain, referred to as DU chain. For a variable in a program, there is a defined value. The set of all possible uses of this defined value is called the defined value-use chain of the variable at this defined value. So the DU chain connects the defined value of the variable to all possible uses of it.
[0042] Use-define chain: Use-define chain, referred to as UD chain. For a use of a variable in a program, the set of all defined values that reach the use is called a use-define chain. The UD chain connects a use to all possible defined values that flow through the use.
[0043] Basic Block: A representation of program code. Each basic block is the largest contiguous sequence of instructions that satisfies the following conditions: (1) Control flow can only enter the basic block from the first instruction in the basic block; (2) Except for the last instruction in the basic block, control flow will not stop or jump before leaving the basic block. Basic blocks form nodes of the control flow graph.
[0044] In order to clearly understand the technical solution of the present application, the solution of the prior art is first introduced in detail.
[0045] DU chain and UD chain are very important structures in all compilers. They can be used to analyze the dependency relationship of variables in the program, and then can be used for compilation optimization such as constant propagation, common subexpression elimination and dead code elimination. Therefore, they are the prerequisites for the compiler to optimize the program when compiling the program.
[0046] At present, the compiler uses the data flow iteration fixed point algorithm to create DU chains and UD chains. When using the data flow iteration fixed point algorithm to create DU chains and UD chains, it will iterate the basic program blocks multiple times along the order of the basic program blocks of the target program to collect semantic information until the semantic information no longer changes, and it is considered that the target program has been fully collected, thereby completing the accurate and complete creation of the DU chain and UD chain. Therefore, when using the data flow iteration fixed point algorithm to create DU chains and UD chains, it is necessary to iterate the basic program blocks of the target program multiple times, which makes the creation process more time-consuming, resulting in low creation efficiency, and then leads to low compilation efficiency of the program.
[0047] Therefore, when facing the technical problems in the prior art, in order to avoid multiple iterations of the basic program blocks, the semantic analysis of the target program can be completed by traversing the target program in a small amount, and the collection of the fixed value points and use points of all variables in the target program can be completed, and then the target DU chain and target UD chain of the target program can be created based on the collected fixed value points and use points of each variable. In the target program, the same variable may be set multiple times. In order to be able to perform a small amount of traversal, the collection of the fixed value points and use points of all variables in the target program can be completed. When traversing the target program once, the SSA algorithm can be used to rename at least one variable in the target program, so that each renamed variable has a corresponding fixed value point, and for each renamed variable, an SSA formal name set is constructed. The SSA formal name set has the SSA formal name, fixed value point and use point corresponding to each renamed variable, and then based on the SSA formal name set, the target fixed value-use DU chain and target use-fixed value UD chain corresponding to the target program are constructed. Since the SSA algorithm is used to rename at least one variable in the target program, each renamed variable has a corresponding fixed value point, forming an SSA formal name set. Therefore, only a small amount of traversal of the target program is required to construct the target fixed value-use DU chain and target use-fixed value UD chain corresponding to the target program based on the SSA formal name, fixed value point and use point corresponding to each renamed variable in the SSA formal name set. Therefore, the number of traversals of the target program is effectively reduced, thereby effectively improving the creation efficiency of the DU chain and UD chain and the compilation efficiency of the program.
[0048] Figure 1 An application scenario diagram of a program compilation method provided in one embodiment of the present application, such as Figure 1As shown, the system corresponding to the program compilation method may include a client device 1 and a server device 2. When a user develops or tests a target program for a target service and has a compilation requirement for the target program, a compilation request for the target program may be sent to the server device 2. The compilation request may include the identifier of the target program. Based on the identifier of the target program, the server device 2 obtains the target program to be compiled from the database or storage area or storage device storing the target program to be compiled, and compiles the target program to be compiled using the program compilation method provided by the present application. Specifically, the SSA algorithm is used to rename at least one variable in the target program so that each renamed variable has a corresponding fixed value point; for each renamed variable, an SSA formal name set is constructed, and the SSA formal name set has the SSA formal name corresponding to each renamed variable, the fixed value point and the use point; according to the SSA formal name set, a target fixed value-use DU chain and a target use-fixed value UD chain corresponding to the target program are constructed; the target program is compiled based on the target DU chain and the UD chain. After the compilation is completed, the compilation result is fed back to the client device 1.
[0049] It is understandable that the program compilation method provided in this embodiment can also be applied in other application scenarios, which is not limited in this embodiment.
[0050] The following specific embodiments are used to describe in detail the technical solutions of the present invention and how the technical solutions of the present application solve the above-mentioned technical problems. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present invention will be described below in conjunction with the accompanying drawings.
[0051] Figure 2 A flowchart of a program compiling method provided in an embodiment of the present application is shown in FIG. Figure 2 As shown, the execution subject of the program compilation method provided in this embodiment is a program compilation device. Then the program compilation method provided in this embodiment includes the following steps:
[0052] Step 201, obtaining the target program to be compiled.
[0053] The target program is a program to be compiled, which may be a program corresponding to the target service, or other types of programs, which are not limited in this embodiment.
[0054] The target program includes a program code. The target program can be represented in the form of a control flow graph, which includes at least one basic program block. The basic program block is a sequentially executed program sequence with only one entry and one exit. It can be understood that the program code has at least one variable, as well as a setting instruction and a use instruction for at least one variable.
[0055] Specifically, in this embodiment, the target program may be stored in a database or a preset storage area or storage device in advance, and the target program may be obtained by accessing the database or the preset storage area or storage device.
[0056] Step 202: rename at least one variable in the target program using a static single assignment SSA algorithm so that each renamed variable has a corresponding fixed value point.
[0057] Among them, static single assignment is an intermediate representation, and all assignments in SSA are performed on variables with different names. Therefore, after using the static single assignment SSA algorithm to rename at least one variable in the target program, each renamed variable has a corresponding fixed value point.
[0058] Specifically, in this embodiment, since a variable may be assigned different values in the target program, that is, a variable has multiple fixed value points. Therefore, in order to enable each variable to have a corresponding fixed value point, the static single assignment SSA algorithm needs to first merge multiple fixed values of the same variable, define a new variable after merging, and then rename the new variable and other variables in the target program, so that each renamed variable in the target program has a corresponding fixed value point.
[0059] The name of the renamed variable is the SSA form name of the renamed variable.
[0060] Step 203, construct an SSA formal name set for each renamed variable, the SSA formal name set having the SSA formal name, setting point and use point corresponding to each renamed variable.
[0061] Specifically, the variables can be renamed while traversing the target program, and after traversing a renamed variable, the SSA formal name, setting point and use point of the renamed variable are determined. Then, the SSA formal name, setting point and use point of the renamed variable are stored in the SSA formal name set. After traversing the target program, the SSA formal name set has the SSA formal name, setting point and use point of each renamed variable.
[0062] Step 204, construct the target constant value-use DU chain and target use-constant value UD chain corresponding to the target program according to the SSA formal name set.
[0063] The target DU chain is the DU chain corresponding to the target program, and the target UD chain is the DU chain corresponding to the target program.
[0064] Specifically, in this embodiment, the initial DU chain and the initial DU chain can be constructed based on each renamed variable in the SSA formal name set. Since the number of renamed variables in the SSA formal name set is greater than the number of original variables in the target program, and the extra variables are generated based on the original variables in the target program, the initial DU chain and the initial DU chain can be converted based on the relationship between the renamed variables and the original variables to obtain the target DU chain and the target UD chain.
[0065] Step 205, compile the target program based on the target DU chain and UD chain.
[0066] In this embodiment, the target program is optimized and analyzed based on the target DU chain and the UD chain, and then the target program is compiled based on the optimization analysis results. Optionally, the optimization analysis method can be a compilation optimization such as constant propagation, common subexpression elimination, and dead code elimination, which is only used for example description and is not used to limit the optimization analysis method.
[0067] The specific optimization analysis method and the method for completing the compilation of the target program based on the optimization analysis result are both existing technologies and will not be described in detail here.
[0068] The program compilation method provided in this embodiment obtains the target program to be compiled; renames at least one variable in the target program using the static single assignment SSA algorithm so that each renamed variable has a corresponding fixed value point; constructs an SSA formal name set for each renamed variable, and the SSA formal name set has the SSA formal name, fixed value point and use point corresponding to each renamed variable; constructs the target fixed value-use DU chain and the target use-fixed value UD chain corresponding to the target program according to the SSA formal name set; and compiles the target program based on the target DU chain and the UD chain. Since the SSA algorithm is used to rename at least one variable in the target program, each renamed variable has a corresponding fixed value point to form an SSA formal name set. Therefore, only a small amount of traversal of the target program is required to construct the target fixed value-use DU chain and the target use-fixed value UD chain corresponding to the target program based on the SSA formal name, fixed value point and use point corresponding to each renamed variable in the SSA formal name set. Therefore, the number of traversals of the target program is effectively reduced, thereby effectively improving the efficiency of creating DU chains and UD chains and the efficiency of compiling programs.
[0069] Figure 3 A flowchart of a program compiling method provided in another embodiment of the present application is shown in FIG. Figure 3As shown, the program compiling method provided in this embodiment is based on the program compiling method provided in the above embodiment, and steps 202 to 203 are further refined. The program compiling method provided in this embodiment includes the following steps:
[0070] Step 301, obtaining the target program to be compiled.
[0071] In this embodiment, the implementation of step 301 is similar to the implementation of step 201 in the above embodiment, and will not be described in detail here.
[0072] Step 302, using the static single assignment SSA algorithm to determine the location that meets the variable merging condition in the target program.
[0073] Among them, the position that meets the variable merging condition is the position where the variable merging instruction is inserted.
[0074] The variable merging instruction is also called the Phi (symbol ф) instruction. The Phi instruction is used to merge multiple fixed values of the same variable in the target program to define a new variable.
[0075] As an optional implementation, step 302 includes the following steps:
[0076] Step 302a, determining a variable set across basic program blocks in the target program, and a fixed value variable set corresponding to each basic program block in the target program.
[0077] In order to better illustrate the scheme, in this embodiment, Figure 4 The specific plan is introduced using the target program in as an example.
[0078] Among them, the variable across basic program blocks refers to the variable whose value is used in different basic program blocks. On the contrary, the variable that does not cross basic program blocks refers to the basic program block whose value is used only in the basic program block.
[0079] Among them, the fixed-value variables in the fixed-value variable set are variables that are set in value.
[0080] Specifically, in this embodiment, in order to insert Phi instructions at positions that meet the variable merging conditions and reduce the number of inserted Phi instructions, after obtaining the variables in the target program, the set of fixed-value variables corresponding to each basic program block in the target program is determined. In addition, the variables in the non-cross-basic program blocks where it is unnecessary to insert Phi instructions can be deleted, and then the cross-basic program block variables in the target program are obtained, and the cross-basic program block variable set is constructed from the cross-basic program block variables.
[0081] The set of fixed value variables can be represented as effect_prs. The set of variables across basic program blocks can be represented as global_prs. Figure 4 In the example shown, there are 7 basic blocks: entry and BB1-BB6. The fixed variables included in effect_prs are {a, b, c, x, p, y}, so the fixed variable set can be expressed as effect_prs = {a, b, c, x, p, y}. The variables included in global_prs are {a, b, x, p}, so the variable set across basic blocks can be expressed as global_prs = {a, b, x, p}.
[0082] Step 302b: For the auxiliary basic program block to which each variable in the variable set across basic program blocks belongs, calculate the dominance boundary of the auxiliary basic program block.
[0083] The auxiliary basic program block is a basic program block to which each variable in the variable set across basic program blocks belongs. In the above exemplary description, the basic program block set to which each variable in global_prs={a,b,x,p} belongs is BB={BB1,BB2,BB3,BB4,BB5,BB6}.
[0084] Among them, when determining the dominating boundary (abbreviated as: DF) of the auxiliary basic program block, it is determined in the following way: the second basic program block is called the dominating boundary of the first basic program block if and only if the first basic program block dominates a predecessor basic program block of the second basic program block and the first basic program block does not strictly dominate the second basic program block.
[0085] In the above exemplary description, the dominating boundaries corresponding to the basic program blocks to which the variables in the variable set across basic program blocks belong are shown in Table 1:
[0086] Table 1: Example description of dominance boundaries
[0087]
[0088] Exemplarily, the dominant boundary of BB2 is BB2, and the dominant boundary of BB4 is BB2.
[0089] Specifically, since BB2 dominates BB2's predecessor node BB5, and BB2 does not strictly dominate BB2, BB2 is the dominating boundary of BB2. Since BB2's predecessors include BB1 and BB5, BB4 dominates BB2's predecessor BB5, and BB4 does not strictly dominate BB2, BB2 is the dominating boundary of BB4.
[0090] Step 302c: determine the starting position of the dominating boundary of the basic program block where the active variable is located as the position that meets the variable merging condition.
[0091] Among them, active variables are variables that are active in both the variable set across basic program blocks and the set variable set. An active variable is a variable that is set in a basic program block and is used at the entry of other basic program blocks and thereafter, which means that the variable is an active variable in other program blocks and subsequent basic program blocks.
[0092] In the above exemplary example, the variable that is active in both the variable set across basic blocks and the fixed value variable set and is also the variable after the entry of the dominating boundaries BB2 and BB4 is x. Then the starting position of the dominating boundaries BB2 and BB4 is determined as the position that meets the variable merging condition.
[0093] The program compilation method provided in this embodiment, when using the static single assignment SSA algorithm to determine the position that meets the variable merging condition in the target program, determines the variable set across basic program blocks in the target program, and the set of fixed-value variables corresponding to each basic program block in the target program; for the auxiliary basic program block to which each variable in the variable set across basic program blocks belongs, determines the dominant boundary of the auxiliary basic program block; determines the starting position of the dominant boundary of the basic program block where the active variable is located as the position that meets the variable merging condition. Since only the auxiliary basic program block to which each variable in the variable set across basic program blocks belongs is determined, the dominant boundary of the auxiliary basic program block is determined; and the starting position of the dominant boundary of the basic program block where the active variable is located is determined as the position that meets the variable merging condition. It can effectively reduce the insertion of Phi instructions into non-cross-basic program blocks.
[0094] Step 303: insert corresponding variable merging instructions at positions that meet the variable merging conditions.
[0095] In this embodiment, when there are multiple dominating boundaries, the corresponding Phi instructions can be inserted at the positions that meet the variable merging conditions according to the execution order of the basic program blocks, or the corresponding Phi instructions can be inserted at the positions that meet the variable merging conditions in parallel. This is not limited in this embodiment.
[0096] In the above exemplary description, Figure 5 The target program shown in Figure 1 is the target program in which the Phi instruction is inserted. Figure 5 In the example, Phi instructions for active variables are inserted at the beginning of BB2 and BB4 respectively.
[0097] Step 304: rename at least one variable in the target program with the variable merging instruction so that each renamed variable has a corresponding fixed value point.
[0098] As an optional implementation, in this embodiment, step 304 includes the following steps:
[0099] Step 304a, determining the dominator tree corresponding to the target program with the variable merge instruction.
[0100] Among them, in the target program, except for the entry basic program block, each basic program block (such as: A) has a unique direct dominating basic program block (expressed as: idom(A)), and does not form a cycle. The edges between all basic program blocks and the dominating basic program block (expressed as: (idom(A), A) form a tree, which is called the dominator tree.
[0101] In this embodiment, the method of determining the dominator tree of the target program with variable merge instructions is similar to the method of determining the dominator tree of the target program without variable merge instructions. The method of determining the dominator tree of the target program without variable merge instructions is a prior art, so it will not be described in detail.
[0102] In the above exemplary description, the corresponding dominator tree is specifically: the edge derived from the entry basic program block points to BB1, the edge derived from BB1 points to BB2, the edge derived from BB2 points to BB3 and BB4, the edge derived from BB4 points to BB5, and the edge derived from BB5 points to BB6.
[0103] Step 304b: rename the variables of the non-variable merge instructions and the constant values of the variable merge instructions in the basic program blocks in the dominator tree.
[0104] Among them, the non-variable merge Phi instruction is an instruction that is not a Phi instruction in the target program.
[0105] In this embodiment, the constant values and usages corresponding to the variables of each non-variable merge instruction in the basic program block in the dominator tree are renamed, and the constant values of the variables in the Phi instruction are renamed.
[0106] As an optional implementation, in this embodiment, step 304b includes the following steps:
[0107] Step 304b1, traverse the basic program blocks in the dominator tree.
[0108] In this embodiment, the basic program blocks in the dominator tree are traversed in the execution order of the basic program blocks. When traversing each basic program block, the variables of the non-variable merging instructions and the constants of the variable merging instructions are renamed.
[0109] As an optional implementation, step 304b1 also includes the following solution:
[0110] In response to traversing to a new basic variable, a stack and a corresponding counter are created for the new basic variable, and the new basic variable is pushed onto the stack in the initial SSA form.
[0111] The basic variables are the variables in the dominator tree. As in the above exemplary description, the basic variables form a set of {a, b, c, x, y, p}.
[0112] Specifically, in this embodiment, when traversing the basic program blocks in the dominator tree, if a new basic variable is traversed, a stack is created for the new basic variable, and the stack is used to store at least one SSA formal name of the basic variable. A counter is also created for the new basic variable, and the counter is used to count the number of formal names of the new basic variable. The count of the counter is monotonically increasing, ensuring that each basic variable is continuously assigned a unique SSA formal name.
[0113] Each basic variable has a basic name, and the basic name is combined with a corresponding version number to form at least one corresponding SSA form name.
[0114] Among them, the version number corresponding to the initial SSA form name is V1. For example, the basic variable is PR1. When PR1 is set for the first time, it is renamed to the initial SSA form name, PR1V1. When it is set for the second time, it is renamed to PR1V2, and so on. Then in the above exemplary description, for variables a, b, c, x, p, y, when traversed for the first time, they are all new basic variables, and stacks and corresponding counters are created for each of them, and the new basic variables are pushed onto the stack with the initial SSA form name. Then the corresponding initial SSA form names are a1, b1, c1, x1, p1, y1 respectively.
[0115] The program compilation method provided by the present embodiment, when traversing the basic program blocks in the dominator tree, also includes, in response to traversing to a new basic variable, creating a stack and a corresponding counter for the new basic variable, and pushing the new basic variable onto the stack with an initial SSA form name. By creating a stack and a corresponding counter for the new basic variable, the new basic variable can be renamed according to the SSA form name and the monotonically increasing counter in the stack, which can effectively ensure that each renamed variable has a unique SSA form name.
[0116] Step 304b2, in response to traversing to the variables of the non-variable merge instruction, the operands corresponding to the variables of the non-variable merge instruction are rewritten according to the current SSA form names corresponding to the operands, and a new SSA form name is created for the constant value corresponding to the variable of the non-variable merge instruction to complete the renaming of the variables of the non-variable merge instruction.
[0117] In this embodiment, for the operands corresponding to the variables of the non-variable merge instruction, the operands are rewritten into the current SSA form names of the corresponding basic variables, and the operands corresponding to the variables of the non-variable merge instruction are renamed. For the constant values corresponding to the variables of the non-variable merge instruction, a new SSA form name is created based on the current SSA form name of the basic variable, and the constant values corresponding to the variables of the non-variable merge instruction are renamed.
[0118] Optionally, step 304b2 includes the following steps:
[0119] Step 304b2a, for the operand corresponding to the variable of the current non-variable merge instruction, read the corresponding current SSA form name from the stack of basic variables to which the operand belongs, and rewrite it according to the current SSA form name corresponding to the operand.
[0120] Let's continue with the above example. For example, the operands corresponding to the variables of the current non-variable merge instruction are a and c in the non-variable merge instruction x=a+c in BB1. The corresponding current SSA form names read from the stack corresponding to the basic variables a and c are a1 and c1 respectively. Then a1 and c1 are used to replace a and c, completing the rewriting of operands a and c.
[0121] Step 304b2b, obtain the stack of basic variables to which the fixed value corresponds to the variable of the current non-variable merge instruction, read the corresponding current SSA form name from the stack of basic variables to which the fixed value belongs, create a new SSA form name based on the corresponding current SSA form name and the corresponding counter, and the new SSA form name is used to write into the stack of basic variables to which it belongs.
[0122] The constant value corresponding to the variable of the non-variable merging instruction is the result of operating the operand in the non-variable merging instruction.
[0123] Among them, the current SSA form name is the SSA form name at the top of the stack.
[0124] Specifically, when a new SSA form name is created based on the corresponding current SSA form name and the corresponding counter, the basic name in the current SSA form name is obtained, and the value of the count in the counter is obtained, the value of the count is added to the preset value to obtain the version number of the new SSA form name, and the basic name and version number in the current SSA form name are concatenated to obtain the new SSA form name.
[0125] Among them, the preset value can be 1.
[0126] Continue to use the above example for explanation. For example, the constant corresponding to the variable of the current non-variable merge instruction is x in the non-variable merge instruction @px=a+c in BB3. Get the stack of the basic variable x to which x belongs. The current SSA form name stored in the stack is x4. Based on x4 and the corresponding counter, a new SSA form name x5 is created, and x5 is written into the stack of x. And x5 is used to replace x, so the top SSA form name in the stack of x is x5.
[0127] Step 304b3, in response to traversing to the fixed value of the variable merging instruction, create a new SSA formal name for the fixed value of the variable merging instruction to complete the renaming of the fixed value of the variable merging instruction.
[0128] Optionally, in step 304b3, a new SSA formal name is created for the value of the variable merge instruction, including the following schemes:
[0129] Get the stack of basic variables to which the fixed value of the variable merge instruction belongs, read the corresponding current SSA form name from the stack of basic variables to which the fixed value belongs, create a new SSA form name based on the corresponding current SSA form name and the corresponding counter, and the new SSA form name is used to write into the stack of basic variables to which it belongs.
[0130] Specifically, when a new SSA form name is created based on the corresponding current SSA form name and the corresponding counter, it is similar to step 304b2b and will not be described in detail again.
[0131] Let's continue with the above example. If the variable merge instruction traversed is x<-phi(x,x) in the basic program block BB2, where the first x is the fixed value of the variable merge instruction, determine the stack of the basic variable x, read the corresponding current SSA form name x1 from the stack of the basic variable x, and create a new SSA form name x2 based on x1 and the corresponding counter. Write x2 into the stack of x. Then the top SSA form name in the stack of x is x2.
[0132] In this embodiment, after creating a new SSA form name x2 for the constant x of x<-phi(x,x), the constant of the variable merging instruction is renamed, so x<-phi(x,x) is renamed to x2<-phi(x,x).
[0133] Step 304c, rename the operands of the variable merging instructions in the basic program block so that each renamed variable has a corresponding fixed value point.
[0134] In this embodiment, after the variables of non-variable merging instructions and the constants of variable merging instructions in the basic program blocks in the dominator tree are renamed, the operands of the variable merging instructions in the basic program blocks are renamed.
[0135] Continuing with the above example, after renaming the variables of the non-variable merge instructions and the fixed values of the variable merge instructions in the basic program blocks in the dominator tree, the variable merge instruction in BB2 becomes x2<-phi(x,x). Then rename the two operands x in the brackets.
[0136] As an optional implementation, in this embodiment, step 304c includes the following steps:
[0137] Step 304c1, determine the predecessor basic program block of the operand of the variable merge instruction.
[0138] Step 304c2, determining the rewritten SSA form name of the corresponding variable in the predecessor basic program block as the SSA form name of the operand of the variable merging instruction to complete the renaming of the operand.
[0139] The predecessor basic program block of the operand of the variable merge instruction is the basic program block corresponding to the source of the operand.
[0140] In this embodiment, the predecessor basic program block of the operand of the variable merging instruction can be determined based on the relationship between the basic variables in the basic program block including the variable merging instruction in the dominator tree. The SSA form name of the corresponding variable in the predecessor basic program block that has been rewritten is obtained, the rewritten SSA form name is read, and the rewritten SSA form name is determined as the SSA form name of the operand of the variable merging instruction, and the operand is rewritten according to the SSA form name to complete the renaming of the operand.
[0141] The above example is continued. The predecessor basic blocks of the variable merge instruction in BB2 are BB1 and BB5. The rewritten SSA form of the variable x in BB1 is named x1. The rewritten SSA form of the variable x in BB5 is named x4, so x1 and x4 replace the two operands x in x2<-phi(x,x), and the rewriting of the operands is completed. The rewritten variable merge instruction is x2<-phi(x1,x4).
[0142] It should be noted that step 302 to step 304 are an optional implementation of step 202 .
[0143] The program compilation method provided in this embodiment, when using the static single assignment SSA algorithm to rename at least one variable in the target program so that each renamed variable has a corresponding fixed value point, uses the static single assignment SSA algorithm to determine the position that meets the variable merging condition in the target program; inserts the corresponding variable merging instruction at the position that meets the variable merging condition; renames at least one variable in the target program with the variable merging instruction so that each renamed variable has a corresponding fixed value point. By determining the position that meets the variable merging condition, and inserting the corresponding variable merging instruction at the position that meets the variable merging condition, renaming at least one variable in the target program with the variable merging instruction, it is possible to merge multiple fixed values of the same variable through the variable merging instruction, define a new variable, and then rename the new variable and other variables in the target program, and accurately control each renamed variable in the target program to have a corresponding fixed value point.
[0144] The program compilation method provided in this embodiment determines the dominator tree corresponding to the target program with the variable merging instruction when renaming at least one variable in the target program with the variable merging instruction so that each renamed variable has a corresponding fixed value point; renames the variables of the non-variable merging instruction and the fixed value of the variable merging instruction in the basic program block in the dominator tree; renames the operands of the variable merging instruction in the basic program block so that each renamed variable has a corresponding fixed value point. When renaming the variables, the order of the variables of the non-merging instruction and the fixed value and operand of the variable merging instruction is followed, which can effectively ensure that each renamed variable has a corresponding fixed value point.
[0145] Continuing with the above example, after executing steps 302 to 304, the corresponding target program is Figure 6 The variables in each basic program block have been renamed in terms of their values and usage, and each renamed variable has a corresponding value point.
[0146] As an optional implementation, before step 304, the following solutions may also be included:
[0147] It is determined whether there is a variable merging instruction satisfying a removal condition in a target program with the variable merging instruction; and the variable merging instruction satisfying the removal condition is removed.
[0148] Specifically, before renaming at least one variable in the target program with the Phi instruction, it is necessary to determine whether the target program with the Phi instruction inserted has redundant Phi instructions. If there are redundant Phi instructions, it means that the removal condition is met. After removing the Phi instructions that meet the removal condition, at least one variable in the target program with the Phi instruction is renamed. This can effectively reduce the amount of calculation for renaming variables and effectively improve the efficiency of renaming.
[0149] Optionally, the variable merging instructions that meet the removal conditions include any of the following:
[0150] The operands of the variable merge instruction have the same evaluation point.
[0151] The evaluation of the variable merge instruction has no use point and no dependency chain with other instructions.
[0152] Specifically, when determining whether the removal condition is met, it is determined whether the operands of the variable merging instruction have the same setting point, and / or whether the setting of the variable merging instruction has no usage point and no dependency chain with other instructions.
[0153] Specifically, when judging whether the operands of the variable merging instruction have the same fixed value point, if the fixed value points of the operands used by the variable merging instruction are located at the same position, it means that the operands of the variable merging instruction have the same fixed value point. Conversely, if the fixed value points of the operands used by the variable merging instruction are located at different positions, it means that the operands of the variable merging instruction have different fixed value points. As a special case, if the fixed value point of the operand of the variable merging instruction is the operand of the variable merging instruction, it also satisfies the condition that the fixed value points of the operands used by the variable merging instruction are located at the same position.
[0154] Specifically, when judging whether the fixed value of the variable merge instruction has no use point and no dependency chain with other instructions, first judge whether the fixed value of the variable merge instruction has no use point. If it is determined that there is no use point, it is determined that the variable merge instruction meets the preliminary removal condition. However, when renaming variables, when the instruction contains a predicate, a linked list will be used to link multiple instructions to form a dependency chain. However, if there is no variable merge instruction in the dependency chain, it means that the variable merge instruction has met the removal condition. On the contrary, if it is determined that there is a use point, or there is no use point, but the variable merge instruction is in the dependency chain, it means that the removal condition is not met.
[0155] The program compilation method provided in this embodiment, the variable merging instructions that meet the removal conditions include any of the following: the operands of the variable merging instructions have the same fixed value point; the fixed value of the variable merging instruction has no usage point and has no dependency chain with other instructions. Each variable merging instruction that meets the removal conditions can be removed, further reducing the amount of calculation for renaming the variables.
[0156] Step 305, during the traversal of the basic program blocks in the dominator tree, determine the SSA form name, the setting point and the use point of the renamed variable.
[0157] In this embodiment, in the process of traversing the basic program blocks of the dominator tree, when traversing to the variable of the non-variable merge instruction, the operand corresponding to the variable is rewritten with the SSA form name at the top of the stack of the basic variable to which it belongs, wherein the operand comes from the variable of the predecessor basic program block, and the variable of the predecessor basic program block has been renamed and has the renamed SSA form name. And the operand is the use point of the renamed variable in the predecessor basic program block, so the use point of the renamed variable can be associated with the corresponding SSA form name of the renamed variable and stored.
[0158] When traversing to the variable of the non-variable merge instruction, a new SSA formal name is also created for the fixed value of the variable of the non-variable merge instruction, and the fixed value is rewritten. Therefore, the new SSA formal name can be used as the SSA formal name of the renamed variable of the variable, and is associated with the fixed value point for storage.
[0159] It is understandable that, in the process of traversing the basic program blocks of the dominator tree, when the fixed value and operand of the variable merge instruction are traversed, the SSA formal name of the renamed variable and the corresponding use point are associated and stored in a similar manner. And the SSA formal name of the renamed variable and the corresponding fixed value point are associated and stored.
[0160] Therefore, after obtaining the SSA formal name of a newly renamed variable, when traversing to the fixed value of the newly renamed variable, the SSA formal name of the newly renamed variable is associated with the corresponding fixed value point and stored. Later, when traversing to the use of the newly renamed variable, that is, when the newly renamed variable is used as an operand, the use point of the newly renamed variable is also associated with the SSA formal name of the newly renamed variable and stored, so that the SSA formal name, fixed value point and use point of the newly renamed variable can be obtained.
[0161] Step 306, construct an SSA formal name set based on the SSA formal names of the renamed variables, the setting points and the use points.
[0162] In this embodiment, the SSA formal name, setting point and use point of each renamed variable can be stored in an empty set according to the variable appearance order and the execution order of the basic program block, thereby constructing an SSA formal name set. Among them, the SSA formal name, setting point and use point of each renamed variable can be used as an element in the SSA formal name set as a whole.
[0163] The program compilation method provided in this embodiment, when constructing an SSA formal name set for each renamed variable, determines the SSA formal name, setting point and use point of the renamed variable during the traversal of the basic program blocks in the dominator tree; and constructs the SSA formal name set based on the SSA formal name, setting point and use point of the renamed variable. It can effectively ensure that after traversing the target program once, the SSA formal name set including the SSA formal name, setting point and use point of the named variable corresponding to at least one variable can be determined.
[0164] As an optional implementation, step 306 also includes the following solution:
[0165] In response to the existence of a fixed value instruction with a predicate in the target program, a linked list is used to store multiple fixed value points in the fixed value instruction with the predicate; the fixed value rename of the instruction with the predicate is inserted at the end of the linked list where the previous same fixed value variable is renamed.
[0166] In this embodiment, as a specific case, it is determined whether there is a fixed value instruction with a predicate in the target program. Exemplarily, if there is a fixed value instruction with an @ character in the target program, it is determined that there is an instruction with a predicate. Since the fixed value instruction with a predicate is not necessarily executed, there may be multiple fixed values of the corresponding variable at this time. In the case where there are multiple fixed values, a linked list can be used to store multiple fixed value points in the fixed value instruction with a predicate.
[0167] The above example illustrates that BB5 contains two value instructions with predicates in BB3 and BB4 for the value point of variable X. Therefore, when storing the value points corresponding to the SSA form name of the renamed variable X, there will be two linked lists x2<--->x5 and x3<--->x4.
[0168] In this embodiment, after storing multiple fixed value points in a fixed value instruction with a predicate in a linked list, the fixed value of the instruction with the predicate is renamed and inserted at the end of the linked list where the previous same fixed value variable is renamed, to ensure that the fixed value point after the use point of the renamed variable will not be mistakenly added to the DU chain and the UD chain.
[0169] In this embodiment, for each renamed variable, when constructing the SSA formal name set, in response to the existence of a fixed value instruction with a predicate in the target program, a linked list is used to store multiple fixed value points in the fixed value instruction with a predicate; the linked list is inserted into the end of the corresponding renamed variable in the SSA formal name set. When there is a fixed value instruction with a predicate in the target program, the fixed value points of the renamed variable can be accurately stored in the form of a linked list, and the accuracy of constructing the DU chain and the UD chain can be effectively guaranteed.
[0170] It should be noted that step 305 - step 306 is an optional implementation of step 203 .
[0171] Step 307, constructing the initial DU chain and UD chain corresponding to the target program with the variable merging instruction according to the SSA formal name set.
[0172] In this embodiment, since the SSA form name, setting point and use point of each renamed variable are associated and stored in the SSA form name set, the SSA form name, setting point and use point of the corresponding renamed variable in the instruction are obtained from the SSA form name set according to the order of instructions in the target program, and then the initial DU chain and UD chain corresponding to the target program with variable merging instructions are constructed.
[0173] Continuing with the above example, as shown in Table 2, there are the initial Def list and the initial Use list corresponding to the constructed target program with the variable merging instruction.
[0174] Each statement in Table 2 corresponds to an instruction in the target program with a variable merging instruction. Deflist: represents the list of fixed value points used by the right value. The Def list with id information represents the initial UD chain corresponding to the renamed variable in this instruction. Use list: represents the list of use points of the left value fixed value. The Use list with id information represents the initial DU chain corresponding to the renamed variable in this instruction.
[0175] Table 2: Initial Def list and initial Use list corresponding to the target program with variable merge instructions
[0176] Statement 1: a1 = 3 Def list Use list a1(id:1) Id:5 13 20 Statement 2: b1 = 4 Def list Use list b1(id:2) Id:14 21 Statement 3: c1 = 5 Def list Use list c1(id:3) Id:6 Statement 4: x1 = a1 + c1 Def list Use list x1(id:4) Id:9 a1(id:5) Id:1 c1(id:6) Id:3 Statement 5: setp p1 Def list Use list p1(id:7) Id:11 18 Statement 6: x2←phi(x1 x4) Def list Use list x2(id:8) Id:16 17 x1(id:9) Id:4 x4(id:10) Id:15 19 Statement 7: @p1 x5=a1+b1 Def list Use list x5(id:12) Id:17 p1(id:11) Id:7 a1(id:13) Id:1 b1(id:14) id:2 Statement 8: x3←phi(x2,x5) Def list Use list x3(id:15) Id:10 23 x2(id:16) Id:8 x5(id:17) Id:8 12 Statement 9: @p1 x4 = a1-b1 Def list Use list x4(id:19) Id:10 23 p1(id:18) Id:7 a1(id:20) Id:1 b1(id:21) id:2 Statement 10: y1 = x4 Def list Use list y1(id:22) x4(id:23) Id:15 19
[0177] Step 308, merge the fixed value points of all operands in the variable merge instruction into the fixed value points of the non-variable merge instruction, and merge the use points of the fixed values in the variable merge instruction into the use points of the non-variable merge instruction.
[0178] In this embodiment, since there is no variable merge instruction in the original target program, the phi instruction is a pseudo-instruction. Therefore, in order to obtain the target DU chain and target UD chain corresponding to the target program without the phi instruction, it is necessary to merge the fixed value points of all operands in the phi instruction into the fixed value points of the non-variable merge instruction, and merge the use points of the fixed values in the phi instruction into the use points of the non-variable merge instruction, so as to separate the operands and fixed values of the variables in the phi instruction.
[0179] As an optional implementation, step 308 includes the following steps:
[0180] Step 3081, traverse the non-variable merge instructions in the basic program block.
[0181] Step 3082, in response to the fact that the evaluation point of the operand of the non-variable merge instruction is the variable merge instruction, the non-variable merge instruction whose evaluation point is the variable merge instruction is determined as the target non-variable merge instruction.
[0182] Specifically, in this embodiment, the non-variable merge instruction is traversed according to the execution order of the basic program block. It is determined whether the fixed value point of the operand of the non-variable merge instruction is a phi instruction. If it is determined that the fixed value point of the operand of the non-variable merge instruction is a phi instruction, the non-variable merge instruction is determined to be a target variable merge instruction.
[0183] Continue with the above example for explanation. Traverse to statements 1 to 3 in the target program, which do not use variables, that is, there are no operands and no processing is required. When traversing to statement 4, the operands of statement 4 are a1 and c1. However, the values of a1 and c1 are not phi statements, so it is determined that it is not the target non-variable merge instruction. Traverse to statement 5, there are no operands and no processing is required. Traverse to statement 7, its corresponding operands are p1, a1 and b1, but the values of p1, a1 and b1 are not phi instructions, so it is determined that it is not the target non-variable merge instruction. Traverse to statement 9, the operands are p1, a1 and b1, but the values of p1, a1 and b1 are not phi instructions, so it is determined that it is not the target non-variable merge instruction. Traverse to statement 10, the operand of statement 10 is x4, and the value statement of x4 comes from statements 8 and 9. Statement 8 is a phi instruction, so statement 10 is the target variable merge instruction.
[0184] Step 3083, merge the fixed value points of all operands in the variable merge instruction into the fixed value points of the target non-variable merge instruction to form a non-variable merge instruction after the fixed value points are merged.
[0185] Let's continue with the above example. The fixed value points of all operands in statement 8 include: id = {4, 12, 19}. Therefore, the fixed value points of all operands in statement 8 are merged into the fixed value points of the variables in statement 10. Then the deflist corresponding to statement 10 includes: id = {4, 12, 15, 19}. Since id: 15 is a phi instruction, after executing step 309, the deflist corresponding to statement 10 includes: id = {4, 12, 19}.
[0186] Step 3084, merge the use point of the fixed value in the variable merge instruction into the use point of the non-variable merge instruction corresponding to the fixed value point in the non-variable merge instruction after the fixed value point is merged.
[0187] The above example is continued for explanation. The usage point of the fixed value in statement 8 is id={10, 23}. Since id=10 is a phi instruction, after executing step 309, id=10 will be deleted, and id=10 and id=23 will be merged into the usage points of the non-variable merge instruction statements 4, 7, and 9 corresponding to the fixed value point of statement 10. After executing step 309, id=10 will be deleted, so as shown in Table 3, the usage points in statements 4, 7, and 9 only include id=23.
[0188] Step 309, delete the DU relationship related to the variable merge instruction in the initial DU chain and delete the UD relationship related to the variable merge instruction in the DU chain, and remove the SSA form name of the variables in the deleted DU chain and UD chain to form a target DU chain and a target UD chain.
[0189] In this embodiment, after executing step 308, since the fixed value points of all operands of the variables in the variable merge instruction are included in the fixed value of the non-variable merge instruction, and the use points of the fixed values in the variable merge instruction are included in the use points of the non-variable merge instruction, the DU relationship related to the variable merge instruction and the UD relationship related to the variable merge instruction can be deleted.
[0190] Specifically, when deleting the DU relationship related to the variable merge instruction, the deletion can be performed in the Use list, specifically deleting the use point in the Use list. When deleting the UD relationship related to the variable merge instruction, the deletion can be performed in the Def list, specifically deleting the fixed value point in the Def list.
[0191] In this embodiment, after deleting the DU relationship related to the variable merge instruction and the UD relationship related to the variable merge instruction, since the target program only includes the basic names of the variables, the version numbers in the SSA formal names of the variables in the DU chain and UD chain after the deletion are removed, and only the basic names remain, forming the final target DU chain and target UD chain.
[0192] The above example is used to illustrate that the target DU chain and the target UD chain corresponding to the target program are shown in Table 3.
[0193] Among them, in Table 3, Def list: represents the list of fixed value points used by the right value, and the ones with id information in the Def list represent the fixed value points of the variable. The variable combined with all the corresponding fixed value points represent the target UD chain corresponding to the variable. Use list: represents the list of use points of the left value fixed value. The ones with id information in the Use list represent the use points of the variable. The variable combined with all the corresponding use points represent the target DU chain corresponding to the variable.
[0194] Table 3: Target Def list and target Use list corresponding to the target program
[0195] Statement 1: a = 3 Def list Use list a(id:1) id:5,13,20 Statement 2: b = 4 Def list Use list b(id:2) id:14,21 Statement 3: c = 5 Def list Use list c(id:3) id:6 Statement 4: x = a + c Def list Use list x(id:4) id:23 a(id:5) id:1 c(id:6) id:3 Statement 5: setp p Def list Use list p(id:7) id:11,18 Statement 7: @px=a+b Def list Use list p(id:11) id:7 x(id:12) id:23 a(id:13) id:1 b(id:14) id:2 Statement 9: @px=ab Def list Use list p(id:18) id:7 x(id:19) id:23 a(id:20) id:1 b(id:21) id:2 Statement 10: y = x Def list Use list y(id:22) x(id:23) id:4,12,19
[0196] It should be noted that step 307 to step 309 are an optional implementation of step 204 .
[0197] The program compilation method provided in this embodiment, when constructing the target constant-use DU chain and target use-constant UD chain corresponding to the target program according to the SSA form name set, constructs the initial DU chain and UD chain corresponding to the target program with variable merging instructions according to the SSA form name set; merges the fixed value points of all operands in the variable merging instructions into the fixed value points of non-variable merging instructions, and merges the fixed value use points in the variable merging instructions into the use points of non-variable merging instructions; deletes the DU relationship related to the variable merging instructions in the initial DU chain and deletes the UD relationship related to the variable merging instructions in the DU chain, and removes the version number in the SSA form name of the variables in the DU chain and UD chain after the deletion to form a target DU chain and a target UD chain. First, based on the SSA formal name set, the initial DU chain and UD chain corresponding to the target program with variable merging instructions are constructed, and then the fixed value points and usage points of the variables in the variable merging instructions are merged into the non-variable merging instructions and the DU relationship related to the variable merging instructions in the initial DU chain is deleted. Finally, the UD relationship related to the variable merging instructions in the DU chain is deleted and the version number in the SSA formal name is removed. In this way, a target DU chain and a target UD chain with the same accuracy as in the prior art can be constructed, and the problem of reducing the number of fixed value usage points in the target DU chain and the target UD chain can be effectively avoided.
[0198] Step 310, compile the target program based on the target DU chain and UD chain.
[0199] In this embodiment, the implementation of step 310 is similar to the implementation of step 205 in the above embodiment, and will not be described in detail here.
[0200] Figure 7 A schematic diagram of the structure of a program compiling device provided in one embodiment of the present application is shown in FIG. Figure 7 As shown, the program compiling device 40 provided in this embodiment includes: an acquisition module 41 , a renaming module 42 , a first construction module 43 , a second construction module 44 and a compiling module 45 .
[0201] Among them, the acquisition module 41 is used to obtain the target program to be compiled. The renaming module 42 is used to rename at least one variable in the target program using the static single assignment SSA algorithm so that each renamed variable has a corresponding fixed value point. The first construction module 43 is used to construct an SSA formal name set for each renamed variable, and the SSA formal name set has the SSA formal name, fixed value point and use point corresponding to each renamed variable. The second construction module 44 is used to construct a target fixed value-use DU chain and a target use-fixed value UD chain corresponding to the target program according to the SSA formal name set. The compilation module 45 is used to compile the target program based on the target DU chain and UD chain.
[0202] Optionally, the renaming module 42 is specifically used for:
[0203] A static single assignment (SSA) algorithm is used to determine a position in a target program that satisfies a variable merging condition; a corresponding variable merging instruction is inserted at the position that satisfies the variable merging condition; and at least one variable in the target program with the variable merging instruction is renamed so that each renamed variable has a corresponding fixed value point.
[0204] Optionally, the renaming module 42, when using the static single assignment SSA algorithm to determine the position that meets the variable merging condition in the target program, is specifically used to determine the variable set across basic program blocks in the target program, and the fixed-value variable set corresponding to each basic program block in the target program; for the auxiliary basic program block to which each variable in the variable set across basic program blocks belongs, determine the dominating boundary of the auxiliary basic program block; determine the starting position of the dominating boundary of the basic program block where the active variable is located as the position that meets the variable merging condition; the active variable is a variable that is active in both the variable set across basic program blocks and the fixed-value variable set.
[0205] Optionally, the renaming module 42, when renaming at least one variable in the target program with the variable merging instruction so that each renamed variable has a corresponding fixed value point, is specifically used to:
[0206] Determine a dominator tree corresponding to a target program with variable merge instructions; rename variables of non-variable merge instructions and constants of variable merge instructions in a basic program block in the dominator tree; rename operands of variable merge instructions in the basic program block so that each renamed variable has a corresponding constant point.
[0207] Optionally, when renaming the variables of the non-variable merge instructions and the fixed values of the variable merge instructions in the basic program blocks in the dominator tree, the renaming module 42 is specifically configured to:
[0208] The basic program blocks in the dominator tree are traversed; in response to the traversal to the variable of the non-variable merge instruction, the operand corresponding to the variable of the non-variable merge instruction is rewritten according to the current SSA form name corresponding to the operand, and a new SSA form name is created for the constant value corresponding to the variable of the non-variable merge instruction to complete the renaming of the variable of the non-variable merge instruction; in response to the traversal to the constant value of the variable merge instruction, a new SSA form name is created for the constant value of the variable merge instruction to complete the renaming of the constant value of the variable merge instruction.
[0209] Optionally, the renaming module 42, when traversing the basic program blocks in the dominator tree, is further configured to:
[0210] In response to traversing to a new basic variable, a stack and a corresponding counter are created for the new basic variable, and the new basic variable is pushed onto the stack in the initial SSA form.
[0211] Optionally, the renaming module 42, when rewriting the operands corresponding to the variables of the non-variable merge instruction according to the current SSA form names corresponding to the operands and creating new SSA form names for the constant values corresponding to the variables of the non-variable merge instruction, is specifically used to:
[0212] For the operand corresponding to the variable of the current non-variable merge instruction, the corresponding current SSA form name is read from the stack of basic variables to which the operand belongs, and rewritten according to the current SSA form name corresponding to the operand; the stack of basic variables to which the fixed value belongs corresponding to the variable of the current non-variable merge instruction is obtained, the corresponding current SSA form name is read from the stack of basic variables to which the fixed value belongs, and a new SSA form name is created based on the corresponding current SSA form name and the corresponding counter, and the new SSA form name is used to write into the stack of basic variables to which it belongs.
[0213] Optionally, the renaming module 42, when creating a new SSA formal name for the value of the variable merge instruction, is specifically used to:
[0214] Get the stack of basic variables to which the fixed value of the variable merge instruction belongs, read the corresponding current SSA form name from the stack of basic variables to which the fixed value belongs, create a new SSA form name based on the corresponding current SSA form name and the corresponding counter, and the new SSA form name is used to write into the stack of basic variables to which it belongs.
[0215] Optionally, the renaming module 42, when renaming the operands of the variable merging instruction in the basic program block, is specifically used to:
[0216] Determine the predecessor basic program block of the operand of the variable merging instruction; determine the rewritten SSA form name of the corresponding variable in the predecessor basic program block as the SSA form name of the operand of the variable merging instruction to complete the renaming of the operand.
[0217] Optionally, it also includes: removing the module.
[0218] The removal module is used to determine whether there is a variable merging instruction that meets the removal condition in the target program with the variable merging instruction; and remove the variable merging instruction that meets the removal condition.
[0219] Optionally, the variable merging instructions that meet the removal conditions include any of the following:
[0220] The operands of the variable merge instruction have the same evaluation point; the evaluation of the variable merge instruction has no use point and has no dependency chain with other instructions.
[0221] Optionally, the first building module 43 is specifically configured to:
[0222] During the traversal of the basic program blocks in the dominator tree, the SSA formal names, setting points and use points of the renamed variables are determined; and an SSA formal name set is constructed based on the SSA formal names, setting points and use points of the renamed variables.
[0223] Optionally, the first construction module 43, when constructing the SSA formal name set for each renamed variable, is further used to:
[0224] In response to the existence of a fixed value instruction with a predicate in the target program, a linked list is used to store multiple fixed value points in the fixed value instruction with the predicate; the fixed value rename of the instruction with the predicate is inserted at the end of the linked list where the previous same fixed value variable is renamed.
[0225] Optionally, the second building module 44 is specifically configured to:
[0226] According to the SSA formal name set, construct the initial DU chain and UD chain corresponding to the target program with variable merging instructions; merge the fixed value points of all operands in the variable merging instructions into the fixed value points of the non-variable merging instructions, and merge the use points of the fixed values in the variable merging instructions into the use points of the non-variable merging instructions; delete the DU relationship related to the variable merging instructions in the initial DU chain and delete the UD relationship related to the variable merging instructions in the DU chain, and remove the version number in the SSA formal name of the variables in the DU chain and UD chain after the deletion to form a target DU chain and a target UD chain.
[0227] Optionally, the second construction module 44, when merging the fixed value points of all operands in the variable merging instruction into the fixed value points of the non-variable merging instruction, and merging the use points of the fixed values in the variable merging instruction into the use points of the non-variable merging instruction, is specifically used to:
[0228] The non-variable merge instructions in the basic program block are traversed; in response to the fixed value point of the operand of the non-variable merge instruction being the variable merge instruction, the non-variable merge instruction whose fixed value point is the variable merge instruction is determined as the target non-variable merge instruction; the fixed value points of all operands in the variable merge instruction are merged into the fixed value point of the target non-variable merge instruction to form a non-variable merge instruction after the fixed value points are merged; the use point of the fixed value in the variable merge instruction is merged into the use point of the non-variable merge instruction corresponding to the fixed value point in the non-variable merge instruction after the fixed value points are merged.
[0229] The program compilation device provided in this embodiment can execute the program compilation provided in any of the above method embodiments. Its implementation principle and technical effect are similar and will not be described in detail here.
[0230] Figure 8 A schematic diagram of the structure of a program compiling device provided in one embodiment of the present application. Figure 8 As shown, the program compiling device 70 provided in this embodiment includes:
[0231] The method comprises: a processor 72 and a memory 71; wherein the memory 71 is used to store program codes; and the processor 72 is used to call the program codes stored in the memory to execute the program compiling method provided by any of the above embodiments. The relevant descriptions can be understood by referring to the relevant descriptions and effects corresponding to the steps in the accompanying drawings, and no further elaboration is made here.
[0232] The program may include program code, and the program code includes computer-executable instructions. The memory 801 may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory.
[0233] In this embodiment, the memory 71 and the processor 72 are connected via a bus. The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 8 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0234] An embodiment of the present application also provides a computer-readable storage medium, in which instructions are stored. When the instructions are executed on a computer, the computer executes the program compilation method provided by any one of the above embodiments.
[0235] An embodiment of the present application also provides a computer program product, including a computer program, which implements the program compilation method provided in any one of the above embodiments when the computer program is executed by a processor.
[0236] The present application also provides an artificial intelligence chip and board. The program compilation method provided in any of the above embodiments is executed using an artificial intelligence chip or board. Fig. 9 is a structural diagram showing a board according to an embodiment of the present application. Fig. 9 As shown, the board 80 includes a chip 801, which is a system-on-chip (SoC), or system on chip, integrated with one or more combined processing devices, which are artificial intelligence computing units that support various deep learning and machine learning algorithms to meet the intelligent processing needs in complex scenarios in the fields of computer vision, speech, natural language processing, data mining, etc. In particular, deep learning technology is widely used in the field of cloud intelligence. A notable feature of cloud intelligence applications is the large amount of input data, which places high demands on the storage capacity and computing power of the platform. The board 80 of this embodiment is suitable for cloud intelligence applications and has huge off-chip storage, on-chip storage, and powerful computing power.
[0237] The chip 801 is connected to an external device 803 via an external interface device 802. The external device 803 is, for example, a server, a computer, a camera, a display, a mouse, a keyboard, a network card, or a wifi interface. The data to be processed can be transmitted from the external device 803 to the chip 801 via the external interface device 802. The calculation result of the chip 801 can be transmitted back to the external device 803 via the external interface device 802. According to different application scenarios, the external interface device 802 can have different interface forms, such as a PCIe interface.
[0238] The board 80 also includes a storage device 804 for storing data, which includes one or more storage units 805. The storage device 804 is connected to the control device 806 and the chip 801 through a bus and transmits data. The control device 806 in the board 80 is configured to regulate the state of the chip 801. To this end, in an application scenario, the control device 806 may include a single-chip microcomputer (Micro Controller Unit, MCU).
[0239] In a possible implementation, a combined processing device is also provided. Fig.10 is a structural diagram showing a combined processing device according to an embodiment of the present application. Fig.10 As shown in , the combined processing device 90 includes a computing device 901 , an interface device 902 , a processing device 903 and a storage device 904 .
[0240] The computing device 901 is configured to perform user-specified operations, and is mainly implemented as a single-core intelligent processor or a multi-core intelligent processor to perform deep learning or machine learning calculations. It can interact with the processing device 903 through the interface device 902 to jointly complete the user-specified operations.
[0241] The interface device 902 is used to transmit data and control instructions between the computing device 901 and the processing device 903. For example, the computing device 901 can obtain input data from the processing device 903 via the interface device 902 and write it into the storage device on the computing device 901 chip. Further, the computing device 901 can obtain control instructions from the processing device 903 via the interface device 902 and write them into the control cache on the computing device 901 chip. Alternatively or optionally, the interface device 902 can also read data in the storage device of the computing device 901 and transmit it to the processing device 903.
[0242] The processing device 903, as a general processing device, performs basic controls including but not limited to data handling, starting and / or stopping the computing device 901. Depending on the implementation, the processing device 903 can be a central processing unit (CPU), a graphics processing unit (GPU) or one or more types of processors in other general and / or special processors, these processors include but are not limited to digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc., and their number can be determined according to actual needs. As before, only with respect to the computing device 901 of the present application, it can be regarded as having a single-core structure or a homogeneous multi-core structure. However, when the computing device 901 and the processing device 903 are integrated and considered together, the two are regarded as forming a heterogeneous multi-core structure.
[0243] The storage device 904 is used to store data to be processed, which may be DRAM 904 , which is a DDR memory, and is usually 16G or larger in size, and is used to store data of the computing device 901 and / or the processing device 903 .
[0244] Fig.11 , which is a schematic diagram of the internal structure of a single-core computing device. The single-core computing device 1000 is used to process input data such as computer vision, speech, natural language, and data mining. The single-core computing device 1000 includes three modules: a control module 1001, a computing module 1002, and a storage module 1003.
[0245] The control module 1001 is used to coordinate and control the operation of the computing module 1002 and the storage module 1003 to complete the deep learning task, and includes an instruction fetch unit (IFU) 10011 and an instruction decode unit (IDU) 10012. The instruction fetch unit 10011 is used to obtain instructions from the processing device, and the instruction decode unit 10012 decodes the obtained instructions and sends the decoding results to the computing module 1002 and the storage module 1003 as control information.
[0246] The operation module 1002 includes a vector operation unit 10021 and a matrix operation unit 10022. The vector operation unit 10021 is used to perform vector operations and can support complex operations such as vector multiplication, addition, and nonlinear transformation; the matrix operation unit 10022 is responsible for the core calculation of the deep learning algorithm, namely matrix multiplication and convolution.
[0247] The storage module 1003 is used to store or transfer relevant data, including a neuron RAM (NRAM) 10031, a parameter RAM (WRAM) 10032, and a direct memory access module (DMA) 10033. NRAM 10031 is used to store input neurons, output neurons, and intermediate results after calculation; WRAM 10032 is used to store the convolution kernel of the deep learning network, that is, the weight; DMA 10033 is connected to DRAM 904 through bus 1004, and is responsible for data transfer between the single-core computing device 1000 and DRAM 904.
[0248] Fig.12 , a schematic diagram of the internal structure of a computing device with multiple cores is shown. The multi-core computing device 1100 adopts a hierarchical structure design. The multi-core computing device 1100 is a system on chip, which includes at least one cluster, and each cluster includes multiple processor cores. In other words, the multi-core computing device 1100 is composed of a hierarchy of system on chip-cluster-processor core.
[0249] At the system-on-chip level, Fig.12 As shown, the multi-core computing device 1100 includes an external storage controller 1101 , a peripheral communication module 1102 , an on-chip interconnect module 1103 , a synchronization module 1104 and multiple clusters 1105 .
[0250] There may be multiple external storage controllers 1101, and two are shown in the figure as an example, which are used to respond to access requests issued by the processor core and access external storage devices, such as Fig.10DRAM 904 in the chip, thereby reading data from outside the chip or writing data. The peripheral communication module 1102 is used to receive control signals from the processing device through the interface device 902 to start the computing device 901 to perform tasks. The on-chip interconnect module 1103 connects the external storage controller 1101, the peripheral communication module 1102 and multiple clusters 1105 to transmit data and control signals between each module. The synchronization module 1104 is a global synchronization barrier controller (GBC) used to coordinate the work progress of each cluster and ensure information synchronization. Multiple clusters 1105 are the computing cores of the multi-core computing device 1100, and 4 are shown as an example in the figure. From the perspective of the cluster level, Fig.12 As shown, each cluster 1105 includes multiple processor cores (IPU cores) 1106 and a memory core (MEM core) 1107. Exemplarily, each cluster 1105 includes 4 processor cores and 1 memory, and the memory may be DRAM 904.
[0251] The figure shows four processor cores 1106 as an example, but the present application does not limit the number of processor cores 1106. Fig.10 Each processor core 1106 is similar to Fig.13 The single-core computing device 1200 also includes three modules: a control module 1201, a computing module 1202 and a storage module 1203. The functions and structures of the control module 1201, the computing module 1202 and the storage module 1203 are roughly the same as those of the control module 1001, the computing module 1002 and the storage module 1003. The control module 1201 includes an instruction fetch unit 12011 and an instruction decoding unit 12012. The computing module 1202 includes a vector computing unit 12021 and a matrix computing unit 12022. No further details are given. It should be noted that the storage module 1203 includes an input / output direct memory access module (IODMA) 12033 and a move direct memory access module (MVDMA) 12034. IODMA 12033 controls memory access between NRAM 12031 / WRAM 12032 and DRAM 904 via broadcast bus 1109 ; MVDMA 12034 is used to control memory access between NRAM 12031 / WRAM 12032 and storage unit (SRAM) 1108 .
[0252] Back to Fig.12The storage core 1107 is mainly used for storage and communication, that is, to store shared data or intermediate results between the processor cores 1106, and to perform communication between the cluster 1105 and the DRAM 904, communication between the clusters 1105, and communication between the processor cores 1106. In other embodiments, the storage core 1107 has the ability of scalar operations and is used to perform scalar operations.
[0253] The storage core 1107 includes an SRAM 1108, a broadcast bus 1109, a cluster direct memory access module (cluster direct memory access, CDMA) 1110 and a global direct memory access module (global direct memory access, GDMA) 1111. The SRAM 1108 plays the role of a high-performance data transfer station. The data reused between different processor cores 1106 in the same cluster 1105 does not need to be obtained from the DRAM 904 by each processor core 1106, but is transferred between the processor cores 1106 via the SRAM 1108. The storage core 1107 only needs to quickly distribute the reused data from the SRAM 1108 to multiple processor cores 1106, so as to improve the efficiency of inter-core communication and greatly reduce on-chip and off-chip input / output access.
[0254] The broadcast bus 1109, CDMA 910 and GDMA 1111 are respectively used to perform communication between processor cores 1106, communication between clusters 1105 and data transmission between clusters 1105 and DRAM 904. They will be described below.
[0255] The broadcast bus 1109 is used to complete high-speed communication between the processor cores 1106 in the cluster 1105. The broadcast bus 1109 of this embodiment supports inter-core communication modes including unicast, multicast and broadcast. Unicast refers to point-to-point (e.g., single processor core to single processor core) data transmission, multicast is a communication mode of transmitting a copy of data from SRAM 1108 to specific processor cores 1106, and broadcast is a communication mode of transmitting a copy of data from SRAM 1108 to all processor cores 1106, which is a special case of multicast.
[0256] CDMA 1110 is used to control memory access to SRAM 1108 between different clusters 1105 within the same computing device.
[0257] GDMA 1111 cooperates with external memory controller 1101 to control the access of SRAM 1108 of cluster 1105 to DRAM 904, or reads data from DRAM 904 to SRAM 1108. As can be seen from the above, DRAM 904 and NRAM 10031 or WRAM
[0258] The communication between 10032 can be realized through two channels. The first channel is to directly connect DRAM 904 and NRAM 10031 or WRAM 10032 through IODAM; the second channel is to first transmit data between DRAM 904 and SRAM 1108 through GDMA 1111, and then transmit data between SRAM 1108 and NRAM 10031 or WRAM 10032 through MVDMA. Although it seems that the second channel requires more components to participate and the data flow is longer, in fact, in some embodiments, the bandwidth of the second channel is much greater than the first channel, so the communication between DRAM 904 and NRAM 10031 or WRAM 10032 may be more efficient through the second channel. The embodiments of the present application can select the data transmission channel according to their own hardware conditions.
[0259] In other embodiments, the functions of GDMA 1111 and IODMA can be integrated into the same component. For the convenience of description, this application regards GDMA 1111 and IODMA as different components. For those skilled in the art, as long as the functions implemented and the technical effects achieved are similar to those of this application, they belong to the protection scope of this application. Furthermore, the functions of GDMA 1111, IODMA, CDMA 1110, and MVDMA can also be implemented by the same component.
[0260] An embodiment of the present application also provides an electronic device, which includes an artificial intelligence chip or board.
[0261] The foregoing may be better understood in view of the following clauses:
[0262] Clause 1. A method for compiling a program, comprising:
[0263] Get the target program to be compiled;
[0264] Rename at least one variable in the target program using a static single assignment (SSA) algorithm so that each renamed variable has a corresponding fixed value point;
[0265] For each renamed variable, construct an SSA formal name set, wherein the SSA formal name set includes an SSA formal name, a setting point, and a use point corresponding to each renamed variable;
[0266] According to the SSA formal name set, construct a target constant value-use DU chain and a target use-constant value UD chain corresponding to the target program;
[0267] The target program is compiled based on the target DU chain and the UD chain.
[0268] Clause 2. The method according to clause 1, wherein the step of renaming at least one variable in the target program using a static single assignment (SSA) algorithm so that each renamed variable has a corresponding fixed value point comprises:
[0269] The static single assignment SSA algorithm is used to determine the location that meets the variable merging conditions in the target program;
[0270] Insert a corresponding variable merging instruction at the position satisfying the variable merging condition;
[0271] At least one variable in a target program with a variable merging instruction is renamed so that each renamed variable has a corresponding fixed value point.
[0272] Clause 3. The method according to clause 2, wherein the step of using a static single assignment (SSA) algorithm to determine a location in the target program that satisfies a variable merging condition comprises:
[0273] Determine a variable set across basic program blocks in the target program, and a fixed value variable set corresponding to each basic program block in the target program;
[0274] For the auxiliary basic program block to which each variable in the variable set across the basic program blocks belongs, determining the dominating boundary of the auxiliary basic program block;
[0275] The starting position of the dominant boundary of the basic program block where the active variable is located is determined as a position that meets the variable merging condition; the active variable is a variable that is active in both the variable set across the basic program blocks and the fixed value variable set.
[0276] Clause 4. The method according to clause 2, wherein the step of renaming at least one variable in the target program with the variable merging instruction so that each renamed variable has a corresponding fixed value point comprises:
[0277] Determine the dominator tree corresponding to the target program with variable merge instructions;
[0278] renaming variables of non-variable merge instructions and constant values of variable merge instructions in basic program blocks in the dominator tree;
[0279] The operands of the variable merging instructions in the basic program block are renamed so that each renamed variable has a corresponding fixed value point.
[0280] Clause 5. The method of clause 4, wherein renaming the variables of the non-variable merge instructions and the constant values of the variable merge instructions in the basic program blocks in the dominator tree comprises:
[0281] Traverse the basic program blocks in the dominator tree;
[0282] In response to traversing to a variable of a non-variable merge instruction, rewriting an operand corresponding to the variable of the non-variable merge instruction according to a current SSA form name corresponding to the operand, and creating a new SSA form name for a constant corresponding to the variable of the non-variable merge instruction to complete the renaming of the variable of the non-variable merge instruction;
[0283] In response to traversing to a value of the variable merging instruction, a new SSA form name is created for the value of the variable merging instruction to complete the renaming of the value of the variable merging instruction.
[0284] Clause 6. The method of clause 5, wherein traversing the basic blocks in the dominator tree further comprises:
[0285] In response to traversing to a new basic variable, a stack and a corresponding counter are created for the new basic variable, and the new basic variable is pushed onto the stack in an initial SSA form.
[0286] Clause 7. A method according to clause 6, wherein the rewriting of operands corresponding to the variables of the non-variable merge instruction according to the current SSA formal names corresponding to the operands and the creation of new SSA formal names for the constant values corresponding to the variables of the non-variable merge instruction comprises:
[0287] For the operand corresponding to the variable of the current non-variable merge instruction, read the corresponding current SSA form name from the stack of basic variables to which the operand belongs, and rewrite it according to the current SSA form name corresponding to the operand;
[0288] Obtain the stack of basic variables to which the fixed value corresponds to the variable of the current non-variable merge instruction, read the corresponding current SSA form name from the stack of basic variables to which the fixed value belongs, create a new SSA form name based on the corresponding current SSA form name and the corresponding counter, and the new SSA form name is used to write into the stack of basic variables to which it belongs.
[0289] Clause 8. The method of clause 6, wherein the step of creating a new SSA formal name for the evaluation of the variable merge instruction comprises:
[0290] Obtain the stack of basic variables to which the fixed value of the variable merging instruction belongs, read the corresponding current SSA form name from the stack of basic variables to which the fixed value belongs, create a new SSA form name based on the corresponding current SSA form name and the corresponding counter, and the new SSA form name is used to write into the stack of basic variables to which it belongs.
[0291] Clause 9. The method according to clause 4, wherein the renaming of operands of the variable merging instructions in the basic program block comprises:
[0292] Determine a predecessor basic block of an operand of the variable merge instruction;
[0293] The rewritten SSA form name of the corresponding variable in the predecessor basic program block is determined as the SSA form name of the operand of the variable merging instruction to complete the renaming of the operand.
[0294] Clause 10. The method according to clause 2, wherein before renaming at least one variable in the target program with the variable merging instruction so that each renamed variable has a corresponding fixed value point, the method further comprises:
[0295] Determine whether there is a variable merging instruction satisfying a removal condition in a target program with the variable merging instruction;
[0296] Remove the variable merge instructions that meet the removal conditions.
[0297] Clause 11. The method according to clause 10, wherein the variable merge instruction that satisfies the removal condition comprises any one of the following:
[0298] The operands of the variable merge instruction have the same evaluation point;
[0299] The evaluation of the variable merge instruction has no use point and no dependency chain with other instructions.
[0300] Clause 12. A method according to any one of clauses 4 to 11, wherein constructing a set of SSA formal names for each renamed variable comprises:
[0301] During the traversal of the basic blocks in the dominator tree, determining the SSA form name, the setting point and the use point of the renamed variable;
[0302] An SSA formal name set is constructed based on the SSA formal names of the renamed variables, the setting points and the use points.
[0303] Clause 13. The method of clause 12, wherein constructing a set of SSA-form names for each renamed variable further comprises:
[0304] In response to the existence of a fixed-value instruction with a predicate in the target program, a linked list is used to store a plurality of fixed-value points in the fixed-value instruction with the predicate;
[0305] The fixed value rename of the instruction with the predicate is inserted at the end of the linked list where the previous fixed value variable rename is located.
[0306] Clause 14. A method according to any one of clauses 1 to 11, wherein constructing a target value-use DU chain and a target use-value UD chain corresponding to the target program according to the SSA formal name set comprises:
[0307] According to the SSA form name set, construct an initial DU chain and an UD chain corresponding to the target program with variable merging instructions;
[0308] Merge the fixed value points of all operands in the variable merging instruction into the fixed value points of the non-variable merging instruction, and merge the use points of the fixed values in the variable merging instruction into the use points of the non-variable merging instruction;
[0309] Delete the DU relationship related to the variable merge instruction in the initial DU chain and delete the UD relationship related to the variable merge instruction in the DU chain, and remove the version number in the SSA form name of the variables in the DU chain and UD chain after the deletion to form a target DU chain and a target UD chain.
[0310] Clause 15. The method of clause 14, wherein the step of merging the fixed value points of all operands in the variable merge instruction into the fixed value points of the non-variable merge instruction, and merging the use points of the fixed values in the variable merge instruction into the use points of the non-variable merge instruction, comprises:
[0311] Traverse the non-variable merging instructions in the basic program block;
[0312] In response to the fact that a value point of an operand of a non-variable merge instruction is a variable merge instruction, determining the non-variable merge instruction whose value point is the variable merge instruction as a target non-variable merge instruction;
[0313] Merge the fixed value points of all operands in the variable merge instruction into the fixed value points of the target non-variable merge instruction to form a non-variable merge instruction after the fixed value points are merged;
[0314] The use point of the fixed value in the variable merging instruction is merged into the use point of the non-variable merging instruction corresponding to the fixed value point in the non-variable merging instruction after the fixed value point is merged.
[0315] Clause 16. A program compiling apparatus, comprising:
[0316] An acquisition module is used to acquire the target program to be compiled;
[0317] A renaming module, used for renaming at least one variable in the target program by using a static single assignment SSA algorithm, so that each renamed variable has a corresponding fixed value point;
[0318] A first construction module is used to construct an SSA formal name set for each renamed variable, wherein the SSA formal name set includes an SSA formal name, a setting point and a use point corresponding to each renamed variable;
[0319] The second construction module is used to construct a target fixed value-use DU chain and a target use-fixed value UD chain corresponding to the target program according to the SSA formal name set;
[0320] A compiling module is used to compile the target program based on the target DU chain and the UD chain.
[0321] Clause 17. A program compiling device, comprising: a processor, and a memory communicatively connected to the processor;
[0322] The memory stores computer-executable instructions;
[0323] The processor executes the computer-executable instructions stored in the memory to implement the method as described in any of clauses 1-15.
[0324] Clause 18. A computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the method as described in any one of Clauses 1-15.
[0325] Clause 19. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the method according to any one of clauses 1 to 15 is implemented.
[0326] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.
[0327] It should be further noted that, although the various steps in the flowchart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowchart may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
[0328] It should be understood that the above-mentioned device embodiments are only illustrative, and the device of the present application can also be implemented in other ways. For example, the division of units / modules in the above-mentioned embodiments is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units, modules or components can be combined, or can be integrated into another system, or some features can be ignored or not executed.
[0329] In addition, unless otherwise specified, each functional unit / module in each embodiment of the present application may be integrated into one unit / module, each unit / module may exist physically separately, or two or more units / modules may be integrated together. The above-mentioned integrated unit / module may be implemented in the form of hardware or in the form of a software program module.
[0330] If the integrated unit / module is implemented in the form of hardware, the hardware can be a digital circuit, an analog circuit, etc. The physical implementation of the hardware structure includes but is not limited to transistors, memristors, etc. Unless otherwise specified, the artificial intelligence processor can be any appropriate hardware processor, such as CPU, GPU, FPGA, DSP, and ASIC, etc. Unless otherwise specified, the storage unit can be any appropriate magnetic storage medium or magneto-optical storage medium, such as resistive random access memory RRAM (Resistive Random Access Memory), dynamic random access memory DRAM (Dynamic Random Access Memory), static random access memory SRAM (Static Random-Access Memory), enhanced dynamic random access memory EDRAM (Enhanced Dynamic Random Access Memory), high-bandwidth memory HBM (High-Bandwidth Memory), hybrid memory cube HMC (Hybrid Memory Cube), etc.
[0331] If the integrated unit / module is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or all or part of the technical solution, can be embodied in the form of a software product, which is stored in a memory and includes several instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the various embodiments of the present application. The aforementioned memory includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.
[0332] In the above embodiments, the description of each embodiment has its own emphasis. For the part not described in detail in a certain embodiment, please refer to the relevant description of other embodiments. The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
Claims
1. A program compiling method, characterized in that: include: Get the target program to be compiled; Rename at least one variable in the target program using a static single assignment (SSA) algorithm so that each renamed variable has a corresponding fixed value point; For each renamed variable, construct an SSA formal name set, wherein the SSA formal name set includes an SSA formal name, a setting point, and a use point corresponding to each renamed variable; According to the SSA formal name set, construct a target constant value-use DU chain and a target use-constant value UD chain corresponding to the target program; The target program is compiled based on the target DU chain and the UD chain.
2. The method according to claim 1, characterized in that The step of renaming at least one variable in the target program by using a static single assignment (SSA) algorithm so that each renamed variable has a corresponding fixed value point includes: The static single assignment SSA algorithm is used to determine the location that meets the variable merging conditions in the target program; Insert a corresponding variable merging instruction at the position satisfying the variable merging condition; At least one variable in a target program with a variable merging instruction is renamed so that each renamed variable has a corresponding fixed value point.
3. The method according to claim 2, characterized in that The method of using the static single assignment SSA algorithm to determine the location that satisfies the variable merging condition in the target program includes: Determine a variable set across basic program blocks in the target program, and a fixed value variable set corresponding to each basic program block in the target program; For the auxiliary basic program block to which each variable in the variable set across the basic program blocks belongs, determining the dominating boundary of the auxiliary basic program block; The starting position of the dominant boundary of the basic program block where the active variable is located is determined as a position that meets the variable merging condition; the active variable is a variable that is active in both the variable set across the basic program blocks and the fixed value variable set.
4. The method according to claim 2, characterized in that: The step of renaming at least one variable in the target program with the variable merging instruction so that each renamed variable has a corresponding fixed value point includes: Determine the dominator tree corresponding to the target program with variable merge instructions; renaming variables of non-variable merge instructions and constant values of variable merge instructions in basic program blocks in the dominator tree; The operands of the variable merging instructions in the basic program block are renamed so that each renamed variable has a corresponding fixed value point.
5. The method according to claim 4, characterized in that The step of renaming the variables of the non-variable merge instructions and the fixed values of the variable merge instructions in the basic program blocks in the dominator tree includes: Traverse the basic program blocks in the dominator tree; In response to traversing to a variable of a non-variable merge instruction, rewriting an operand corresponding to the variable of the non-variable merge instruction according to a current SSA form name corresponding to the operand, and creating a new SSA form name for a constant corresponding to the variable of the non-variable merge instruction to complete the renaming of the variable of the non-variable merge instruction; In response to traversing to a value of the variable merging instruction, a new SSA form name is created for the value of the variable merging instruction to complete the renaming of the value of the variable merging instruction.
6. The method according to claim 5, characterized in that The traversing of the basic program blocks in the dominator tree also includes: In response to traversing to a new basic variable, a stack and a corresponding counter are created for the new basic variable, and the new basic variable is pushed onto the stack in an initial SSA form.
7. The method according to claim 6, characterized in that The operands corresponding to the variables of the non-variable merge instruction are rewritten according to the current SSA form names corresponding to the operands, and a new SSA form name is created for the constant values corresponding to the variables of the non-variable merge instruction, including: For the operand corresponding to the variable of the current non-variable merge instruction, read the corresponding current SSA form name from the stack of basic variables to which the operand belongs, and rewrite it according to the current SSA form name corresponding to the operand; Obtain the stack of basic variables to which the fixed value corresponds to the variable of the current non-variable merge instruction, read the corresponding current SSA form name from the stack of basic variables to which the fixed value belongs, create a new SSA form name based on the corresponding current SSA form name and the corresponding counter, and the new SSA form name is used to write into the stack of basic variables to which it belongs.
8. The method according to claim 6, characterized in that The new SSA form name is created for the variable merging instruction, including: Obtain the stack of basic variables to which the fixed value of the variable merging instruction belongs, read the corresponding current SSA form name from the stack of basic variables to which the fixed value belongs, create a new SSA form name based on the corresponding current SSA form name and the corresponding counter, and the new SSA form name is used to write into the stack of basic variables to which it belongs.
9. The method according to claim 4, characterized in that The step of renaming operands of the variable merging instruction in the basic program block includes: Determine a predecessor basic block of an operand of the variable merge instruction; The rewritten SSA form name of the corresponding variable in the predecessor basic program block is determined as the SSA form name of the operand of the variable merging instruction to complete the renaming of the operand.
10. The method according to claim 2, characterized in that Before renaming at least one variable in the target program with the variable merging instruction so that each renamed variable has a corresponding fixed value point, the method further includes: Determine whether there is a variable merging instruction satisfying a removal condition in a target program with the variable merging instruction; Remove the variable merge instructions that meet the removal conditions.
11. The method according to claim 10, characterized in that Variable merge instructions that meet the removal conditions include any of the following: The operands of the variable merge instruction have the same evaluation point; The evaluation of the variable merge instruction has no use point and no dependency chain with other instructions.
12. The method according to any one of claims 4 to 11, characterized in that: For each renamed variable, a SSA form name set is constructed, including: During the traversal of the basic blocks in the dominator tree, determining the SSA form name, the setting point and the use point of the renamed variable; An SSA formal name set is constructed based on the SSA formal names of the renamed variables, the setting points and the use points.
13. The method according to claim 12, characterized in that The step of constructing a set of SSA formal names for each renamed variable further includes: In response to the existence of a fixed-value instruction with a predicate in the target program, a linked list is used to store a plurality of fixed-value points in the fixed-value instruction with the predicate; The fixed value rename of the instruction with the predicate is inserted at the end of the linked list where the previous fixed value variable rename is located.
14. The method according to any one of claims 1 to 11, characterized in that: The step of constructing a target fixed value-use DU chain and a target use-fixed value UD chain corresponding to the target program according to the SSA formal name set includes: According to the SSA form name set, construct an initial DU chain and an UD chain corresponding to the target program with variable merging instructions; Merge the fixed value points of all operands in the variable merging instruction into the fixed value points of the non-variable merging instruction, and merge the use points of the fixed values in the variable merging instruction into the use points of the non-variable merging instruction; Delete the DU relationship related to the variable merge instruction in the initial DU chain and delete the UD relationship related to the variable merge instruction in the DU chain, and remove the version number in the SSA form name of the variables in the DU chain and UD chain after the deletion to form a target DU chain and a target UD chain.
15. The method according to claim 14, characterized in that The step of merging the fixed value points of all operands in the variable merging instruction into the fixed value points of the non-variable merging instruction, and merging the use points of the fixed values in the variable merging instruction into the use points of the non-variable merging instruction, comprises: Traverse the non-variable merging instructions in the basic program block; In response to the fact that a value point of an operand of a non-variable merge instruction is a variable merge instruction, determining the non-variable merge instruction whose value point is the variable merge instruction as a target non-variable merge instruction; Merge the fixed value points of all operands in the variable merge instruction into the fixed value points of the target non-variable merge instruction to form a non-variable merge instruction after the fixed value points are merged; The use point of the fixed value in the variable merging instruction is merged into the use point of the non-variable merging instruction corresponding to the fixed value point in the non-variable merging instruction after the fixed value point is merged.
16. A program compiling device, characterized in that: include: An acquisition module is used to acquire the target program to be compiled; A renaming module, used for renaming at least one variable in the target program by using a static single assignment SSA algorithm, so that each renamed variable has a corresponding fixed value point; A first construction module is used to construct an SSA formal name set for each renamed variable, wherein the SSA formal name set includes an SSA formal name, a setting point and a use point corresponding to each renamed variable; The second construction module is used to construct a target fixed value-use DU chain and a target use-fixed value UD chain corresponding to the target program according to the SSA formal name set; A compiling module is used to compile the target program based on the target DU chain and the UD chain.
17. A program compiling device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 15.
18. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 15 when executed by a processor.
19. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 15 is implemented.
Citation Information
Cited By
Instruction fusion method and device, electronic equipment, storage medium and program product
CN121658078A
