Register copy propagation optimization method, apparatus, device and storage medium
By constructing the intersection operation of register mapping management information and control flow graph, the problem of information intersection and merging across basic block boundaries is solved, global optimization and efficiency improvement of register copy propagation are achieved, and the correctness of code semantics is ensured.
Patent Information
- Application Number
- CN202611439446.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-16
- Publication Date
- 2026-11-17
AI Technical Summary
In existing technologies, register copy propagation algorithms are mainly limited to the basic block and have difficulty ensuring the correctness and security of information intersection and merging when crossing basic block boundaries. They also cannot effectively remove redundant transfer instructions on the cross-basic block path, resulting in limited overall optimization performance.
By constructing register mapping management information and performing intersection operations using the exit mapping management information of the control flow graph, the entry mapping management information of the current basic block is generated. It is then determined whether there is a mapping relationship between the registers read by the instruction and replaced with the source register. Candidate deletion instructions are marked. Combined with the analysis of cross-basic block usage, the security and accuracy of information merging are ensured.
It implements register copy propagation optimization across basic blocks, improves the overall efficiency of register copy propagation, expands the optimization scope to the global level, and ensures the correctness of code semantics.
Smart Images

Figure CN123114547A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer compiler technology, and more specifically to register copy propagation optimization methods, apparatus, devices, and storage media. Background Technology
[0002] During compiler backend optimization, register copy propagation aims to eliminate redundant register transfer instructions (such as R1 <- R0). By directly passing the source register (R0) of this instruction to subsequent instructions that use the destination register (R1), the number of instructions can be reduced, register pressure can be lowered, and program execution efficiency can be improved.
[0003] However, in existing technologies, most algorithms only propagate within a single basic block. When propagating across basic blocks, it is difficult to achieve the intersection and merging of information under the semantics of available expressions to ensure the correctness and security of propagated information at the merging point. At the same time, current code elimination mechanisms cannot securely identify and remove redundant transmission instructions on cross-basic block paths. Summary of the Invention
[0004] In view of this, the present invention provides a register copy propagation optimization method, apparatus, device and storage medium to solve the problem of low overall efficiency of register copy propagation.
[0005] In a first aspect, the present invention provides a register copy propagation optimization method, the method comprising: Construct register mapping management information, which includes at least first mapping information for recording the mapping relationship between the destination register and the source register; The intersection operation is performed on the exit mapping management information of each basic block in the control chart flow to generate the entry mapping management information of the current basic block; Based on the first mapping information, determine whether there is a mapping relationship between the registers read by the instruction in the current basic block and the entry mapping management information. If there is a mapping relationship between the registers read by the instruction and the entry mapping management information, replace the registers read by the instruction with the source registers in the mapping relationship, and mark the transfer instruction that provides the mapping relationship as a candidate deletion instruction. The usage of the candidate deletion instructions is analyzed in order to delete the candidate deletion instructions.
[0006] In one optional implementation, the register mapping management information further includes third mapping information, which is used to record the mapping relationship between the destination register and the source operation; the step of performing an intersection operation based on the exit mapping management information of each basic block in the control graph flow to generate the entry mapping management information of the current basic block includes: Traverse all predecessor basic blocks of the current basic block to obtain the exit mapping management information of each predecessor basic block; Use the exit mapping management information of the first predecessor basic block as the initial entry mapping management information; Obtain exit mapping management information from other precursor basic blocks, and determine whether each mapping entry in the first mapping information exists in the initial entry mapping management information, and determine whether the operation semantics of the mapping entries are consistent based on the third mapping information; If the mapping entry does not exist in the initial entry mapping management information, or if the operation semantics are determined to be inconsistent according to the third mapping information, then the mapping entry is deleted from the initial entry mapping management information to obtain the entry mapping management information of the current basic block.
[0007] In an optional implementation, determining whether the registers read by the instruction in the current basic block have a mapping relationship in the entry mapping management information based on the first mapping information includes: Detect whether there is a register read operation in the instructions of the current basic block; If the instructions in the current basic block contain an operation to read a register, then according to the first mapping information, query the entry mapping management information to see if there is a mapping entry with the read register as the destination register; If the entry mapping management information contains a mapping entry with the read register as the destination register, then it is determined that the read register has a mapping relationship in the entry mapping management information; If there is no mapping entry in the entry mapping management information that takes the read register as the destination register, then it is determined that the read register does not have a mapping relationship in the entry mapping management information.
[0008] In an optional implementation, if the register read by the instruction has a mapping relationship in the entry mapping management information, then the register read by the instruction is replaced with the source register in the mapping relationship, and the transfer instruction providing the mapping relationship is marked as a candidate deletion instruction, including: If the register read by the instruction has a mapping relationship in the entry mapping management information, obtain the source register in the mapping relationship; Replace the register read by the instruction with the source register; Obtain the transmission instruction that provides the mapping relationship, and mark the transmission instruction as a candidate deletion instruction.
[0009] In an optional implementation, the register mapping management information further includes second mapping information, which is used to record the mapping relationship between the source register and the destination register; if the register to be read by the instruction has a mapping relationship in the entry mapping management information, then the register to be read by the instruction is replaced with the source register in the mapping relationship, and the transfer instruction that provides the mapping relationship is marked as a candidate deletion instruction, further comprising: If a modification operation to the source register is detected, all destination registers that depend on the source register are obtained according to the second mapping information, and the mapping relationship of all destination registers in the register mapping management information is deleted. If a modification operation to the destination register is detected, the mapping relationship with the destination register as the primary key in the register mapping management information will be deleted. If a function call instruction is detected, the mapping relationship between the destination register and the caller's saved register in the register mapping management information will be deleted. Store the mapping management information after all instructions within the current basic block have been processed as the exit mapping management information. If the export mapping management information changes compared to the previous iteration, all successor basic blocks of the current basic block are added to the working list, and the iteration continues until the working list is empty.
[0010] In one optional implementation, analyzing the usage of the candidate deletion instructions to delete the candidate deletion instructions includes: Starting from the basic block where the candidate deletion instruction is located, recursively check the usage of the destination register in the candidate deletion instruction on each reachable path along the successor edge of the control flow graph; Determine whether each reachable path can be deleted based on the inspection results; If all reachable paths are deletable, then the candidate deletion instruction is removed from the instruction sequence.
[0011] In one optional implementation, after determining whether each reachable path can be deleted based on the inspection results, the method further includes: If a read of the destination register is detected on a reachable path, then the reachable path is determined to be a non-deletable path; If a redefinition operation on the destination register is detected first on the reachable path, and there was no prior reading or use of the destination register before the redefinition operation, then the reachable path is determined to be a deletable path.
[0012] The register copy propagation optimization method provided in this embodiment includes constructing register mapping management information; performing intersection operations on the exit mapping management information of each basic block in the control flow graph to generate the entry mapping management information of the current basic block; determining whether there is a mapping relationship between the register read by the instruction in the current basic block and the entry mapping management information based on the first mapping information; if there is a mapping relationship between the register read by the instruction and the entry mapping management information, replacing the register read by the instruction with the source register in the mapping relationship, and marking the transfer instruction that provides the mapping relationship as a candidate deletion instruction; and analyzing the usage of the candidate deletion instructions to delete them. This method ensures the safety and accuracy of information merging at the convergence point during cross-basic block propagation by constructing register mapping management information and performing intersection operations on the predecessor exit mapping management information based on the control flow graph; on this basis, it replaces the register read by the instruction with the first mapping information and marks the candidate deletion instructions; and combines the usage analysis across basic blocks to implement dead code elimination, thereby expanding the optimization scope from local to global, improving the overall efficiency of register copy propagation optimization while ensuring the semantic correctness of the code.
[0013] In a second aspect, the present invention provides a register copy propagation optimization apparatus, the apparatus comprising: A mapping information construction module is used to construct register mapping management information, wherein the register mapping management information includes at least first mapping information for recording the mapping relationship between the destination register and the source register; The intersection operation module is used to perform intersection operations based on the exit mapping management information of each basic block in the control graph flow to generate the entry mapping management information of the current basic block. The deletion instruction determination module is used to determine whether there is a mapping relationship between the register read by the instruction in the current basic block and the entry mapping management information based on the first mapping information. If there is a mapping relationship between the register read by the instruction and the entry mapping management information, the source register in the mapping relationship is used to replace the register read by the instruction, and the transfer instruction that provides the mapping relationship is marked as a candidate deletion instruction. The instruction deletion module is used to analyze the usage of the candidate deletion instructions in order to delete the candidate deletion instructions.
[0014] Thirdly, the present invention provides a computer device, comprising: a memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the computer instructions to perform the register copy propagation optimization method of the first aspect or any corresponding embodiment described above.
[0015] Fourthly, the present invention provides a computer-readable storage medium storing computer instructions for causing a computer to execute the register copy propagation optimization method of the first aspect or any corresponding embodiment thereof. Attached Figure Description
[0016] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0017] Figure 1 This is a flowchart illustrating the register copy propagation optimization method according to an embodiment of the present invention; Figure 2 This is a flowchart illustrating the register copy propagation optimization method according to an embodiment of the present invention; Figure 3 This is a flowchart illustrating the register copy propagation optimization method according to an embodiment of the present invention; Figure 4 This is a structural block diagram of a register copy propagation optimization apparatus according to an embodiment of the present invention; Figure 5 This is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. Detailed Implementation
[0018] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0019] In the field of computer compiler technology, instruction-level parallelism and register resource utilization have an increasingly significant impact on program execution efficiency. Compiler backend optimization, by eliminating redundant operations at the intermediate representation or machine instruction level, reduces the number of instructions and lowers register pressure while ensuring program semantic correctness, and is a key step in improving the quality of generated target code. Register copy propagation optimization aims to eliminate redundant register transfer instructions, thereby reducing the number of instructions, lowering register pressure, and improving program execution efficiency. However, most existing copy propagation techniques are limited to local optimization within basic blocks, making it difficult to accurately maintain the consistency of mapping information at control flow convergence points when crossing basic block boundaries, and also unable to safely identify and remove redundant transfer instructions on cross-basic block paths, thus limiting the overall optimization effect. Based on this, this application provides a register copy propagation optimization method.
[0020] According to an embodiment of the present invention, a register copy propagation optimization method embodiment is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0021] This embodiment provides a register copy propagation optimization method. Figure 1 This is a flowchart of the register copy propagation optimization method according to an embodiment of the present invention, such as... Figure 1 As shown, the process includes the following steps: Step S101: Construct register mapping management information.
[0022] The register mapping management information includes at least the first mapping information used to record the mapping relationship between the destination register and the source register. This first mapping information is the Dst2Src mapping (Destination register to source register), and its data structure is Map.<Reg, Reg> The first mapping information is used to record a one-to-one mapping relationship between destination registers and source registers, indicating that a destination register is defined by a source register through a certain operation. For example, after processing the transfer instruction R1<- R0, the first mapping information records the mapping entry R1->R0, indicating that the current value of destination register R1 comes from source register R0. When subsequent instructions read destination register R1, by querying the first mapping information, R1 can be replaced with its source R0, thereby eliminating the reference to destination register R1 in subsequent instructions.
[0023] In actual compiler implementations, the first mapping information can be implemented using data structures such as hash tables or balanced binary trees to ensure that the time complexity of query, insertion and deletion operations during propagation is O(1) or O(log n), which meets the compiler's requirements for efficiency.
[0024] In an optional embodiment, the register mapping management information may further include second mapping information and third mapping information, which respectively represent the mapping relationship between the source register and the destination register, and the mapping relationship between the destination register and the source operation.
[0025] Step S102: Perform an intersection operation based on the exit mapping management information of each basic block in the control diagram flow to generate the entry mapping management information of the current basic block.
[0026] A control graph is a directed graph created by the compiler during program optimization. It uses basic blocks as nodes and control flow transitions as edges to represent all possible paths a program can traverse during execution. A basic block is a sequence of instructions executed sequentially, with a unique entry and exit point. Control flow enters from the first instruction of the basic block and exits from the last instruction, without branches or jumps in between. At the intermediate representation level, the compiler divides the program into several basic blocks and constructs the complete jump relationships between them.
[0027] When this method is executed, the compiler maintains entry mapping management information (InDstSrcMgr) and exit mapping management information (OutDstSrcMgr) for each basic block in the control flow graph. The entry mapping management information represents the set of register mappings available when execution reaches the beginning of the basic block; the exit mapping management information represents the set of register mappings that are still valid after all instructions in the basic block have been executed.
[0028] Specifically, iterate through all predecessor basic blocks of the current basic block and obtain the exit mapping management information of each predecessor basic block. If it is the first predecessor basic block, directly copy its exit mapping management information as the initial value of the entry mapping management information; otherwise, perform an intersection operation on the currently retained entry mapping management information and the exit mapping management information of the next predecessor basic block.
[0029] The specific rules for intersection operations are as follows: a mapping is retained in the entry mapping management information only if a destination register has a mapping in the exit mapping management information of all its predecessor basic blocks and the source register corresponding to the destination register is completely consistent in all predecessors; if the mapping is missing or the source register is inconsistent, the mapping is removed from the entry mapping management information.
[0030] For example, suppose the current basic block has two predecessor basic blocks, BB1 and BB2. The Dst2Src mapping stored in the exit mapping management information of BB1 is {R1: R4, R2: R5}, and the Dst2Src mapping stored in the exit mapping management information of BB2 is {R2: R5, R3: R6}. When performing the intersection operation, R2->R5 exists in all predecessors and its source register is consistent, so it is retained; R1->R4 is missing in BB2, and R3->R6 is missing in BB1, so they are both deleted. The final intersection result is {R2:R5}.
[0031] It should be noted that the above intersection operation needs to be repeatedly executed iteratively throughout the data flow analysis process. If the exit mapping management information of a certain basic block changes, the entry mapping management information of its subsequent basic blocks needs to be recalculated based on the new exit mapping management information until the mapping management information of all basic blocks no longer changes, and the data flow analysis converges.
[0032] Step S103: Based on the first mapping information, determine whether there is a mapping relationship between the register read by the instruction in the current basic block and the entry mapping management information. If there is a mapping relationship between the register read by the instruction and the entry mapping management information, replace the register read by the instruction with the source register in the mapping relationship, and mark the transfer instruction that provides the mapping relationship as a candidate deletion instruction.
[0033] The system iterates through each instruction in the current basic block, checking for any register read operations. If a register read operation exists, the register read by that instruction is retrieved. Then, based on the first mapping information, the system checks the entry mapping management information for a mapping entry with that register as the destination register. The entry mapping management information itself contains all available first mapping information entries at the start of the current basic block.
[0034] If a mapping entry is found that targets the read register, the corresponding source register is retrieved from that mapping entry, and the register read in the current instruction is replaced with the source register. Simultaneously, the transfer instruction providing the mapping entry is marked as a candidate deletion instruction.
[0035] Specifically, assume that the entry mapping management information of the current basic block contains a first mapping information entry R1->R0, meaning the value of the destination register R1 originates from the source register R0. There is an instruction R3<-R1 + 1 in the current basic block that reads register R1. When this instruction is encountered, the entry mapping management information is checked to see if a mapping entry exists for register R1. The result is that an entry R1->R0 exists. Therefore, the source register R0 is retrieved from this mapping entry, and R1 in the instruction is replaced with R0, resulting in the optimized instruction R3<-R0+1. Simultaneously, the transfer instruction R1<-R0 that provides this mapping relationship is marked as a candidate deletion instruction.
[0036] In step S103, all replaceable register references within the current basic block are replaced, and all replaced transfer instructions are marked as candidate deletion instructions.
[0037] Step S104: Analyze the usage of candidate deletion instructions in order to delete the candidate deletion instructions.
[0038] Starting from the basic block containing each candidate delete instruction, recursively check the usage of the destination register in all reachable paths along the successor edges of the control flow graph. Usage refers to where the program reads the value of the destination register after the candidate delete instruction, and when the destination register is redefined.
[0039] If a read of the destination register is detected on a reachable path, it indicates that the value transmitted by the transfer instruction is still needed on that reachable path, and the reachable path is determined to be a non-deletable path. For example, if the candidate delete instruction is R1<- R0, and it reaches a subsequent basic block along the control flow graph, and if the subsequent basic block contains the instruction R3<- R1 + 1, meaning that the instruction read the value of the destination register R1, then the path is determined to be a non-deletable path.
[0040] If a redefinition operation on the destination register is detected first on the reachable path, and there was no prior reading of the destination register before the redefinition operation, it indicates that the value passed by the transfer instruction is no longer needed on that path, and the reachable path is determined to be a deletable path. For example, if the candidate deletion instruction is R1<-R0, and it reaches a subsequent basic block along the control flow graph, and if the subsequent basic block contains the instruction R1<-R4, meaning that R1 was redefined first on that path, and no instruction read the value of R1 before the redefinition, then subsequent calculations no longer depend on the old value passed by the candidate deletion instruction, and the path is determined to be a deletable path.
[0041] When all reachable paths of a candidate delete instruction are determined to be deleteable, it means that the value transmitted by the transfer instruction is no longer used on any subsequent execution path, and the candidate delete instruction is finally removed from the instruction sequence. If there is at least one non-deletable path, it means that the transfer instruction is still depended on by subsequent instructions on at least one execution path, and the candidate delete instruction is retained to ensure the correctness of the program semantics.
[0042] For example, suppose the candidate delete instruction is R1<- R0, located in basic block BB0, and BB0 is succeeded by BB1 and BB2. If the instruction R3<- R1 + 1 (R1 has been read) is detected in BB1, then the BB1 path is determined to be non-deletable; if only R1<- R4 (R1 has been redefined and has not been read before) is detected in BB2, then the BB2 path is determined to be deletable. Since the BB1 path is non-deletable, the candidate delete instruction is ultimately not deleted. If both BB1 and BB2 are determined to be deletable, then the candidate delete instruction is ultimately removed from the instruction sequence.
[0043] In this embodiment, during local propagation, if the right-hand side of a transfer instruction is successfully propagated to a subsequent user, the transfer instruction is marked as a candidate deletion instruction. The deletion determination recursively (checkDCEAvailable) for candidate instructions starts from the BB (Block Buffer) and recursively searches along the edges of the control flow graph. If, upon reaching a base block, the target register is found to have been redefined and was not used before this definition, it is determined that the definition on that path will not affect subsequent calculations, and deletion is returned. If a read of register R1 is found on the path, the transfer instruction is determined to be non-deletable, and non-deletable is recursively returned. Only when all reachable paths return deletion is the cross-base block transfer instruction finally removed from the IR (Instruction Register).
[0044] The register copy propagation optimization method provided in this embodiment includes: constructing register mapping management information; performing intersection operations on the exit mapping management information of each basic block in the control flow graph to generate the entry mapping management information of the current basic block; determining whether there is a mapping relationship between the register read by the instruction in the current basic block and the entry mapping management information based on the first mapping information; if there is a mapping relationship between the register read by the instruction and the entry mapping management information, replacing the register read by the instruction with the source register in the mapping relationship, and marking the transfer instruction that provides the mapping relationship as a candidate deletion instruction; analyzing the usage of the candidate deletion instructions to delete them. This method ensures the safety and accuracy of information merging at the convergence point during cross-basic block propagation by constructing register mapping management information and performing intersection operations on the predecessor exit mapping management information based on the control flow graph; on this basis, it replaces the register read by the instruction with the first mapping information and marks the candidate deletion instructions, and implements dead code elimination by combining the cross-basic block usage analysis, thereby expanding the optimization scope from local to global, and improving the overall efficiency of register copy propagation optimization while ensuring the semantic correctness of the code.
[0045] In some optional implementations, the register mapping management information also includes third mapping information, which records the mapping relationship between the destination register and the source operation. This third mapping information is a Dst2IR mapping (Destination register to source IR), and its data structure is Map.<Reg, IRTab> The type is used to record the one-to-one mapping relationship between the destination register and the source operation, indicating which source operation defined a certain destination register. The third mapping information not only supports the replacement of register numbers, but also supports the propagation of constants and zero registers, unifying constant assignment and register transfer into the propagation system.
[0046] For example, for the constant assignment instruction R1<- 0, the third mapping information records R1 ->0, indicating that the destination register R1 is defined by the constant zero; for the identity arithmetic operation R2<- R3 + 0, the third mapping information records R2 ->R3, indicating that the operation is semantically equivalent to a register move.
[0047] Based on the third mapping information, step S102 above includes: Step S201: Traverse all predecessor basic blocks of the current basic block to obtain the exit mapping management information of each predecessor basic block.
[0048] The current basic block represents the basic block currently to be processed. It iterates through all predecessor basic blocks in the control flow graph, reading the exit mapping management information for each predecessor basic block from the compiler's data flow buffer. The exit mapping management information contains all mapping entries that remain valid after all instructions within the predecessor basic block have been executed.
[0049] Step S202: Use the exit mapping management information of the first predecessor basic block as the initial entry mapping management information.
[0050] Take the exit mapping management information of the first predecessor basic block encountered during traversal, and copy it completely as the initial entry mapping management information of the current basic block. The initial entry mapping management information contains all available mapping relationships when reaching the current basic block from the first predecessor path.
[0051] Step S203: Obtain the exit mapping management information in other predecessor basic blocks, and determine whether each mapping entry in the first mapping information exists in the initial entry mapping management information, and determine whether the operation semantics of the mapping entries are consistent based on the third mapping information.
[0052] Obtain the exit mapping management information of each predecessor basic block except the first predecessor basic block, then retrieve each mapping entry from the currently retained initial entry mapping management information, and perform the following two judgments respectively: First, it is determined whether the mapping entry also exists in the exit mapping management information of other predecessor basic blocks. Specifically, using the destination register in the mapping entry as the key, the exit mapping management information is queried to see if a mapping entry with that destination register as the primary key exists. If it does not exist, it means that the destination register has no available mapping relationship on at least one predecessor path, and the mapping entry cannot be guaranteed to be valid on all predecessor paths.
[0053] Second, based on the third mapping information, it is determined whether the source operation semantics corresponding to the mapping entry in the exit mapping management information of each predecessor basic block are consistent. Specifically, for the destination register in the mapping entry, the source operation information corresponding to it in the exit mapping management information of each predecessor basic block is obtained, and the functions implemented by these source operations are compared to see if they are the same. Semantic consistency means that different operations implement the same function, not just comparing whether the opcode or instruction pointer is exactly the same. For example, in one predecessor basic block, R2 is defined by moving the R3 direct register (recorded as {R2: R3} in Dst2IR), and in another predecessor basic block, R2 is defined by R3+0 (recorded as {R2: R3+0} in Dst2IR). The two operations implement the same function (both assign the value of R3 to R2), and are considered consistent semantically. As another example, in one predecessor, R2 is defined by R3, and in another predecessor, R2 is defined by R4. Although the destination register is R2 in both cases, the source operation semantics are different, and are considered inconsistent.
[0054] Step S204: If the mapping entry does not exist in the initial entry mapping management information, or if the operation semantics are determined to be inconsistent based on the third mapping information, then the mapping entry is deleted from the initial entry mapping management information to obtain the entry mapping management information of the current basic block.
[0055] If a mapping entry does not exist in the exit mapping management information of other predecessor basic blocks currently being processed, it means that the mapping relationship is not available on the predecessor path. Not all predecessors can guarantee that the mapping is valid. Therefore, the mapping entry is deleted from the initial entry mapping management information.
[0056] If the mapping entry exists, but its source operation semantics are inconsistent with other predecessor paths according to the third mapping information, then even if the destination register is the same, the source semantics are different, and it cannot be regarded as the same mapping relationship at the merging point. The mapping entry is also deleted from the initial entry mapping management information.
[0057] After comparing and filtering all other predecessor basic blocks one by one, the mapping entries retained in the initial entry mapping management information all satisfy the condition that they exist in the exit mapping management information of all predecessor basic blocks and have completely consistent operation semantics. These mapping entries constitute the final reliable entry mapping management information of the current basic block.
[0058] For example, suppose the current basic block has two predecessor basic blocks, BB1 and BB2. The Dst2IR mapping stored in the exit mapping management information of BB1 is {R2: R3} (meaning R2 is defined by a direct register move of R3), and the Dst2IR mapping stored in the exit mapping management information of BB2 is {R2: R3+0} (meaning R2 is defined by R3+0). Both operations perform the same function and are considered semantically consistent; therefore, this mapping is retained in the intersection result. If the Dst2IR mapping stored in BB2 is {R2:0} or {R2:R4}, then due to semantic inconsistency, this mapping entry is deleted from the intersection result.
[0059] By introducing third mapping information, the above intersection operation can accurately perform mapping merging based on semantic equivalence, thereby achieving safer and more accurate information merging at the control flow convergence point.
[0060] In some alternative implementations, step S103 includes: Step S301: Detect whether there is a register read operation in the instructions of the current basic block.
[0061] The compiler iterates through each instruction in the current basic block, parsing each instruction and identifying its operand types. If an instruction's operands include a register-type operand that serves as the source operand in the instruction, then the instruction is determined to contain a register read operation. At the intermediate representation level, the compiler backend has a clear understanding of the operand types for each instruction; the presence of a register read operation can be identified by reading the operand field of the instruction.
[0062] Step S302: If there is a register read operation in the instructions of the current basic block, then according to the first mapping information, query the entry mapping management information to see if there is a mapping entry with the read register as the destination register.
[0063] If the instructions in the current basic block include a register read operation, the identifier of the read register (e.g., register number R1, R2, etc.) is obtained. This identifier is then used as the lookup key to search the entry mapping management information. The entry mapping management information stores all available first mapping information entries at the start of the current basic block, with each entry using the destination register as the key and the source register as the value. During a query, the identifier of the read register is used as the key to search the entry mapping management information for a mapping entry with the same key.
[0064] For example, suppose an instruction is R3<-R1+1, which reads register R1. Using R1 as the lookup key, the entry mapping management information is searched for a mapping entry with R1 as the destination register.
[0065] Step S303: If there is a mapping entry in the entry mapping management information that takes the read register as the destination register, then it is determined that the read register has a mapping relationship in the entry mapping management information.
[0066] If a corresponding mapping entry is found in the entry mapping management information using the read register as the key, it indicates that the register has a valid mapping relationship at the current basic block entry point, meaning that the current value of the register originates from a source register. At this point, it is determined that the read register has a mapping relationship in the entry mapping management information. Subsequently, the corresponding source register can be retrieved from the mapping entry, the register read in the current instruction can be replaced with the source register, and the transfer instruction providing the mapping relationship can be marked as a candidate deletion instruction.
[0067] Step S304: If there is no mapping entry in the entry mapping management information that takes the read register as the destination register, then it is determined that the read register does not have a mapping relationship in the entry mapping management information.
[0068] If no corresponding mapping entry is found in the entry mapping management information using the read register as the key, it means that there is no valid mapping relationship for that register at the current basic block entry point, i.e., the current value of that register has no available source mapping. In this case, it is determined that the read register has no mapping relationship in the entry mapping management information, and no propagation replacement is performed; the instruction remains unchanged.
[0069] Furthermore, if the register read by the instruction has a mapping relationship in the entry mapping management information, the register read by the instruction is replaced with the source register in the mapping relationship, and the transfer instruction that provides the mapping relationship is marked as a candidate deletion instruction, including: Step S305: If the register read by the instruction has a mapping relationship in the entry mapping management information, obtain the source register in the mapping relationship.
[0070] If the register read by the instruction has a mapping relationship in the entry mapping management information, the recorded source register is retrieved from the queried mapping entry. Mapping entries use the destination register as the key and the source register as the value; therefore, retrieving the value from the mapping entry yields the corresponding source register. For example, if the mapping entry is R1->R0, the destination register is R1, and the source register is R0, when the instruction reads register R1, the source register R0 is retrieved from the mapping entry.
[0071] Step S306: Replace the register read by the instruction with the source register.
[0072] The register read in the current instruction is replaced with the source register obtained in step S305. This replacement operation is performed in the operand field of the instruction, replacing the original destination register operand with the source register operand. This makes the instruction no longer dependent on the destination register, but directly uses the value of the source register. For example, if the original instruction is R3<- R1 + 1, after the register R1 read by the instruction is replaced with the source register R0, the optimized instruction R3<- R0 + 1 is obtained, achieving the propagation of register copying.
[0073] Step S307: Obtain the transmission instruction that provides the mapping relationship, and mark the transmission instruction as a candidate deletion instruction.
[0074] After completing the above replacement operation, the transfer instruction that provides the mapping relationship is obtained. Each mapping relationship originates from a transfer instruction (e.g., R1 <- R0), and the compiler records the identifier or position information of this transfer instruction when constructing the mapping entry. The transfer instruction that provides the mapping relationship is found using the recorded information, and this transfer instruction is marked as a candidate deletion instruction.
[0075] In some optional implementations, the register mapping management information may further include second mapping information, which is used to record the mapping relationship between the source register and the destination register.
[0076] The second mapping information is the Src2Dst mapping (Source register to destination register), and its data structure is Map. <Reg, List <reg>The `>` type is used to record a one-to-many mapping relationship between source registers and destination register lists, indicating which destination registers are defined by a given source register. For example, after processing the transfer instruction `R1<-R0`, the second mapping information records `R0->[R1]`, indicating that the value of source register R0 was transferred to destination register R1. When source register R0 is overwritten by a new write operation, all destination registers that need to be cleaned up (e.g., R1) can be found immediately through this second mapping information, without traversing the entire mapping table, significantly improving the efficiency of iterative analysis.
[0077] If the register to be read by the instruction has a mapping relationship in the entry mapping management information, then the register to be read by the instruction is replaced with the source register in the mapping relationship, and the transfer instruction that provides the mapping relationship is marked as a candidate deletion instruction. This also includes: Step S401: If a modification operation on the source register is detected, then all destination registers that depend on the source register are obtained according to the second mapping information, and the mapping relationship of all destination registers in the register mapping management information is deleted.
[0078] During the traversal of the current basic block instructions, if a modification operation on a source register is detected (i.e., the register is reassigned), the original value of that register changes, and all mapping relationships dependent on that source register become invalid. By querying the second mapping information, a list of all destination registers dependent on that source register is obtained, and then all mapping entries for these destination registers in the register mapping management information (including the first mapping information) are deleted. For example, if the current first mapping information is recorded as {R2: R3} and the second mapping information is recorded as {R3: [R2]}, when processing the operation R3=R4+1, the source register R3 is reassigned. The list of destination registers dependent on R3, [R2], is obtained through the second mapping information, and the mapping entry {R2: R3} for R2 in the first mapping information is deleted.
[0079] In step S402, if a modification operation on the destination register is detected, the mapping relationship with the destination register as the primary key in the register mapping management information is deleted.
[0080] During the traversal of the current basic block instructions, if a modification operation on a destination register is detected (i.e., the destination register is reassigned), the mapping relationship of that register becomes invalid. At this time, the mapping entry with that destination register as the primary key in the register mapping management information is deleted. For example, if the current first mapping information record is {R2: R3}, when the operation R2 = R4 + 1 is processed, R2 is reassigned, the original record {R2: R3} becomes invalid, and is deleted from the mapping table.
[0081] Step S403: If a function call instruction is detected, delete the mapping relationship between the destination register and the caller's saved register in the register mapping management information.
[0082] During the traversal of the current basic block instructions, if a function call instruction is detected, the caller-saved register may be implicitly modified within the function. Therefore, the mapping relationship between the destination register and the caller-saved register in the register mapping management information becomes invalid and needs to be deleted. The caller-saved register refers to the register that is saved and restored by the caller, and its value may be modified by the sub-function during the function call.
[0083] When performing mapping invalidation cleanup according to steps S401 to S403 above, it is also necessary to process the register alias relationships. If register R0 is modified, the system queries the register alias table and deletes all register mappings that overlap with R0 (e.g., sub-registers or vector element registers) to prevent invalid mapping relationships from being incorrectly propagated to subsequent instructions. For example, if register R0 is modified and there is a mapping entry with R0's sub-register R0L as the destination register, that mapping entry also needs to be deleted.
[0084] When performing mapping failure cleanup according to steps S401 to S403 above, it is also necessary to process the register alias relationships. The register alias relationships refer to the following: if register R0 is modified, the system queries the register alias table (getOverlapSRegSet) and simultaneously deletes all register mappings that overlap with R0 (e.g., sub-registers or vector element registers) to prevent the incorrect propagation of invalid mapping relationships to subsequent instructions. For example, if register R0 is modified and there is a mapping entry with R0's sub-register R0L as the destination register, that mapping entry also needs to be deleted.
[0085] Step S404: Store the mapping management information after all instructions in the current basic block have been processed as the exit mapping management information.
[0086] After traversing all instructions within the current basic block, replacing all propagable register references, and cleaning up all invalid mappings based on the modification operations, the final mapping management information of the current basic block is stored as its exit mapping management information. This exit mapping management information will be used by all subsequent basic blocks of the current basic block when calculating their entry mapping management information.
[0087] Step S405: If the exit mapping management information has changed compared to the previous iteration, add all successor basic blocks of the current basic block to the working list and continue iterating until the working list is empty.
[0088] After storing the exit mapping management information of the current basic block, it is compared with the exit mapping management information stored in the previous iteration. If the two are completely identical, that is, the number of entries and all key-value pairs in the first mapping information of the register mapping management information are completely identical, then it is considered that no change has occurred; if there are any differences (different number of entries, or different key-value pairs), then it is considered that a change has occurred.
[0089] If the exit mapping management information changes, the entry mapping management information of the successor basic blocks of the current basic block may be affected and needs to be recalculated. In this case, all successor basic blocks of the current basic block are added to the working list, and iterative processing continues until the working list is empty, at which point the data flow analysis converges.
[0090] In some optional implementations, to ensure that the propagation operation does not violate program semantics, this invention sets up checkpoint control. The `canBeCandidateCP` function determines whether the current propagation operation meets preset conditions. If it does, replacement is performed; otherwise, replacement is prohibited. The preset conditions include at least one of the following: (1) Propagation is prohibited when the destination register is a parameter register. For example, before executing a function call, the relevant parameters need to be stored in the parameter register (e.g., RPARAM = R2). The parameter register will be used during the function call (e.g., foo(RPARAM)). If R2 is propagated to the call point, it will result in an incorrect call form foo(R2), which directly violates the function calling convention.
[0091] (2) Propagation is prohibited when the destination register is the stack pointer (SP) or the frame pointer (FP). The program usually uses the frame pointer to store the value of the stack pointer to support the stack opening function (e.g., RFP = RSP), and uses FP to restore the value of SP at the end of the program (RSP = RFP). If RSP is propagated to the relevant usage of FP, it will cause the stack opening to fail and the program execution to fail.
[0092] (3) Propagation is prohibited when the target machine instruction requires the source register and destination register to be the same and the current propagation would break this constraint. Certain machine instructions on some architectures require the source register and destination register to be the same (i.e., satisfy specific register constraints). Propagating other registers to such instructions will cause the instruction execution to fail.
[0093] Through comprehensive control of the above checkpoints, this invention achieves radical global optimization while ensuring the integrity and correctness of program execution semantics.
[0094] In some optional implementations, step S104 above includes: Step S501: Starting from the basic block where the candidate deletion instruction is located, recursively check the usage of the destination register in the candidate deletion instruction on each reachable path along the successor edge of the control flow graph.
[0095] Obtain the basic block where each candidate deletion instruction is located, and starting from the basic block where the candidate deletion instruction is located, traverse the control flow graph layer by layer along the successor edges (i.e. the jump relationship between basic blocks), checking all basic blocks that can be reached from the basic block.
[0096] If the current basic block has multiple successor basic blocks, the traversal continues downwards along each successor edge until the end of the control flow graph is reached (e.g., the function return basic block), thus covering all possible execution paths originating from the candidate deletion instruction. During the traversal, it is checked whether there are any read, use, or redefinition operations on the destination register of the candidate deletion instruction on each reachable path.
[0097] For example, if the candidate deletion instruction R1<- R0 is located in basic block BB0, and BB0 has two successor basic blocks BB1 and BB2, then starting from BB0, recursively check along the two paths BB0→BB1 and BB0→BB2 respectively, covering all possible execution paths.
[0098] Step S502: Determine whether each reachable path can be deleted based on the inspection results.
[0099] If a read of the destination register is detected on the reachable path, it means that the value passed by the transfer instruction is still relied upon by subsequent instructions on that path. The candidate delete instruction cannot delete on that reachable path, and it is determined to be a non-deletable path.
[0100] If a redefinition operation on the destination register is detected first on the reachable path, and there was no prior reading or use of the destination register before the redefinition operation, it means that the value passed by the transfer instruction will not be used again on the reachable path. Therefore, the candidate delete instruction can be safely deleted on this path, and the reachable path is determined to be a deleteable path.
[0101] For example, for a candidate deletion instruction R1<- R0, if there is an instruction R1<-R4 (redefining R1) on a reachable path, and no instruction has read the value of R1 before this, then the reachable path can be deleted.
[0102] If there is no reading or redefinition of the destination register on a reachable path, meaning the destination register is not involved by any instruction on that path, then the value passed by the candidate delete instruction is also not used on that path, and the reachable path is also determined to be a deleteable path.
[0103] Step S503: If all reachable paths are deletable paths, then remove the candidate deletion instruction from the instruction sequence.
[0104] A candidate delete instruction is removed from the instruction sequence only if it is determined to be a deleteable path on all reachable paths. This is because if at least one path is not deleteable, the program will still use the value passed by the transfer instruction when executing along the reachable path. Deleting the transfer instruction would prevent the program from correctly obtaining the value, thus violating the program's semantics. The delete operation is only safe when all reachable paths no longer depend on the value passed by the transfer instruction.
[0105] For example, a candidate deletion instruction is R1<- R0, located in basic block BB0, whose successors are BB1 and BB2. If the instruction R3<- R1 + 1 (R1 has been read) is detected in BB1, then the BB1 path is determined to be non-deletable; if only R1<- R4 (R1 has been redefined and has not been read before) is detected in BB2, then the BB2 path is determined to be deletable. Since the BB1 path is a non-deletable path, and not all reachable paths are deletable, this candidate deletion instruction is ultimately not deleted to ensure that the program can correctly read the value of R1 when executing along the BB1 path. If both BB1 and BB2 are determined to be deletable paths, then this candidate deletion instruction is ultimately removed from the instruction sequence.
[0106] Furthermore, after step S502, the method further includes: Step S5021: If reading and using the destination register is detected on the reachable path, the reachable path is determined to be a non-deletable path.
[0107] When the recursive check reaches a basic block, if a read operation on the destination register of a candidate delete instruction is detected in the instruction sequence of that basic block, it means that the value of that destination register is still being used on that path. Since the original purpose of the candidate delete instruction is to pass the correct value to the destination register for subsequent instructions to read, if this transfer instruction is deleted at this point, subsequent instructions reading the destination register will not be able to obtain the correct value. Therefore, as long as there is a read of the destination register on a reachable path, that path is determined to be a non-deletable path.
[0108] For example, if the candidate deletion instruction is R1<- R0, when it reaches the subsequent basic block BB1, the instruction R3<- R1 +1 is detected. This instruction reads the value of the destination register R1, so the BB1 path is determined to be a non-deletable path.
[0109] Step S5022: If a redefinition operation on the destination register is detected first on the reachable path, and there was no reading or use of the destination register before the redefinition operation, then the reachable path is determined to be a deletable path.
[0110] When the recursive check reaches a basic block, if a redefinition operation (i.e., a write operation to the register) is detected first in the instruction sequence of that basic block on the destination register of the candidate delete instruction, and there was no prior reading or use of the destination register before the redefinition operation, then it means that subsequent calculations on the reachable path have completely overwritten the value of the register and no longer depend on the old value passed by the candidate delete instruction. Therefore, the candidate delete instruction can be deleted on this reachable path, and the reachable path is determined to be a deleteable path.
[0111] For example, if the candidate deletion instruction is R1<- R0, and the instruction sequence is detected as R1<- R4 (R1 is redefined) when the subsequent basic block BB2 is reached, and there is no read operation on R1 before this instruction, then the subsequent calculation on this reachable path no longer depends on the value passed by R1<- R0, and the BB2 path is determined to be a deleteable path.
[0112] It should be noted that the judgment order of steps S5021 and S5022 is to first check for read usage, and then check for redefinition. If both read usage and redefinition exist on a path, then as long as read usage exists, the path is a non-deletable path, because read usage depends on the value passed by the candidate deletion instruction. Redefinition can only constitute a basis for determining a deletable path if read usage does not exist.
[0113] Figure 2 A flowchart illustrating the register copy propagation optimization method according to an embodiment of the present invention is shown, as follows: Figure 2 As shown, the process includes the following steps: First, the list of basic blocks is initialized. The compiler adds all basic blocks in the control flow graph to the working list, forming a set of basic blocks to be processed.
[0114] Then, the iterative loop begins. It checks if the working list is empty; if it is, the data flow analysis has converged, and this phase ends. If it is not empty, a basic block is retrieved from the working list for processing.
[0115] For each extracted basic block, the entry mapping management information (InDstSrcMgr) of that basic block is calculated by first performing an intersection operation on the exit mapping management information of all its predecessor basic blocks. Then, based on the calculated entry mapping management information, register copy propagation is performed on all instructions within that basic block; that is, the registers read in the instructions are replaced with the corresponding source registers according to the first mapping information, and the transfer instructions that provide the mapping relationship are marked as candidate deletion instructions. During this process, mapping invalidation cleanup is also performed; that is, when a register write instruction or function call instruction is encountered, the overwritten or modified mapping relationship in the register mapping management information is deleted. After all instructions within that basic block have been processed, the exit mapping management information (OutDstSrcMgr) of that basic block is calculated.
[0116] Next, determine whether the exit mapping management information of the basic block has changed compared to the previous iteration. If the exit mapping management information has not changed, remove the basic block from the working list; if it has changed, retain the basic block in the working list, add all its successor basic blocks to the working list, and continue iterative processing.
[0117] Repeat the above iterative loop until the working list is empty. At this point, the entry mapping management information and exit mapping management information of all basic blocks have converged, the data flow analysis phase ends, and the dead code elimination phase begins.
[0118] Figure 3 A flowchart of the register copy propagation optimization method according to an embodiment of the present invention is shown, as follows: Figure 3 As shown, the process includes the following steps: After the global data flow iterative analysis converges, the code list to be eliminated is first initialized by adding all transmission instructions marked as candidate deletion instructions during the global data flow iterative analysis process to the code list to be eliminated.
[0119] Next, it is determined whether the list of codes to be eliminated is empty. If it is empty, it means that there are no candidate deletion instructions that need to be eliminated, and this stage ends; if it is not empty, a candidate deletion instruction is taken from the list of codes to be eliminated and processed.
[0120] For each candidate deletion instruction retrieved, the basic block in which the instruction is located is obtained. Then, all subsequent basic blocks of the basic block are traversed along the successor edge of the control flow graph, and the usage of the destination register in the candidate deletion instruction is recursively checked on each reachable path.
[0121] Based on the inspection results, determine whether the candidate deletion instruction is deletable. If all reachable paths of the candidate deletion instruction are deletable, the candidate deletion instruction is determined to be deletable and is removed from the instruction sequence; if there is at least one non-deletable path, the candidate deletion instruction is determined to be non-deletable and is retained.
[0122] Repeat the above judgment and elimination process until the list of codes to be eliminated is empty, complete the elimination operation of all deletable candidate deletion instructions, and output the optimized instruction sequence.
[0123] This invention defines a register mapping management class, DstSrcMgr. DstSrcMgr comprises three core sub-mappings: Dst2Src, Src2Dst, and Dst2IR, which complement and work collaboratively. Dst2Src is used for forward lookup of register substitution relationships, supporting propagation substitution; Src2Dst acts as a reverse index, used to quickly clean up all related propagation when the source register is redefined; and Dst2IR records the complete semantics of the source operation, supporting semantic equivalence comparisons in intersection operations. These three mappings work together to provide a data management foundation that is both efficient and accurate for the iterative propagation of global data streams.
[0124] This invention expands the scope of register transfer operations by incorporating the following instructions into the propagation system: (1) Constant zero folding: When R1<- 0 is detected, it is regarded as R1<- ZeroRegister and included in the propagation system. The mapping relationship between the destination register and the zero register is recorded in the Dst2Src mapping, and the correspondence between the destination register and the constant zero is recorded in the Dst2IR mapping.
[0125] (2) Arithmetic identity: When R1<- R2 + 0 or R1<- R2 - 0 is detected, it is regarded as R1<- R2 and included in the propagation system. The mapping relationship between the destination register and the source register is recorded in both Dst2Src mapping and Dst2IR mapping.
[0126] This method constructs register mapping management information and performs intersection operations on the predecessor exit mapping management information based on the control flow graph, ensuring the safety and accuracy of information merging at the convergence point during cross-basic block propagation. On this basis, it uses the first mapping information to replace the registers read by the instruction and marks the candidate deletion instructions. Combined with the cross-basic block usage analysis, it implements dead code elimination, thereby expanding the optimization scope from local to global. While ensuring the semantic correctness of the code, it improves the overall efficiency of register copy propagation optimization.
[0127] This embodiment also provides a register copy propagation optimization apparatus for implementing the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that performs a predetermined function. Although the apparatus described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0128] This embodiment provides a register copy propagation optimization device, such as... Figure 4 As shown, it includes: A mapping information construction module is used to construct register mapping management information, wherein the register mapping management information includes at least first mapping information for recording the mapping relationship between the destination register and the source register; The intersection operation module is used to perform intersection operations based on the exit mapping management information of each basic block in the control graph flow to generate the entry mapping management information of the current basic block. The deletion instruction determination module is used to determine whether there is a mapping relationship between the register read by the instruction in the current basic block and the entry mapping management information based on the first mapping information. If there is a mapping relationship between the register read by the instruction and the entry mapping management information, the source register in the mapping relationship is used to replace the register read by the instruction, and the transfer instruction that provides the mapping relationship is marked as a candidate deletion instruction. The instruction deletion module is used to analyze the usage of the candidate deletion instructions in order to delete the candidate deletion instructions.
[0129] The further functional descriptions of each of the above modules are the same as those in the corresponding embodiments described above, and will not be repeated here.
[0130] In this embodiment, the register copy propagation optimization device is presented in the form of a functional unit. Here, a unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that execute one or more software or fixed programs, and / or other devices that can provide the above functions.
[0131] This invention also provides a computer device having the above-described register copy propagation optimization apparatus.
[0132] Please see Figure 5 , Figure 5 This is a schematic diagram of the structure of a computer device provided in an optional embodiment of the present invention, such as... Figure 5 As shown, the computer device includes one or more processors 10, memory 20, and interfaces for connecting the components, including high-speed interfaces and low-speed interfaces. The components communicate with each other via different buses and can be mounted on a common motherboard or otherwise installed as needed. The processors can process instructions executed within the computer device, including instructions stored in or on memory to display graphical information of a GUI on external input / output devices (such as display devices coupled to the interfaces). In some alternative implementations, multiple processors and / or multiple buses can be used with multiple memories and multiple memory modules, if desired. Similarly, multiple computer devices can be connected, each providing some of the necessary operations (e.g., as a server array, a group of blade servers, or a multiprocessor system). Figure 5 Take a processor 10 as an example.
[0133] Processor 10 may be a central processing unit, a network processor, or a combination thereof. Processor 10 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The programmable logic device may be a complex programmable logic device (CAMP), a field-programmable gate array (FPGA), a general-purpose array logic (GDA), or any combination thereof.
[0134] The memory 20 stores instructions executable by at least one processor 10 to cause the at least one processor 10 to perform the method shown in the above embodiments.
[0135] The memory 20 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the computer device. Furthermore, the memory 20 may include high-speed random access memory and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some alternative embodiments, the memory 20 may optionally include memory remotely located relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0136] The memory 20 may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as flash memory, hard disk or solid-state drive; the memory 20 may also include a combination of the above types of memory.
[0137] The computer device also includes a communication interface 30 for communicating with other devices or communication networks.
[0138] This invention also provides a computer-readable storage medium. The methods described above according to embodiments of the invention can be implemented in hardware or firmware, or implemented as computer code that can be recorded on a storage medium, or implemented as computer code downloaded via a network and originally stored on a remote storage medium or a non-transitory machine-readable storage medium and then stored on a local storage medium. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium can also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code, which, when accessed and executed by the computer, processor, or hardware, implements the methods shown in the above embodiments.
[0139] A portion of this invention can be applied as a computer program product, such as computer program instructions, which, when executed by a computer, can invoke or provide the methods and / or technical solutions according to the invention through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, installation package files, etc. Correspondingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions, or the computer compiling the instructions and then executing the corresponding compiled program, or the computer reading and executing the instructions, or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.
[0140] Although embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the invention, and such modifications and variations all fall within the scope defined by the appended claims.< / reg>
Claims
1. A register copy propagation optimization method, characterized in that, The method includes: Construct register mapping management information, which includes at least first mapping information for recording the mapping relationship between the destination register and the source register; The intersection operation is performed on the exit mapping management information of each basic block in the control chart flow to generate the entry mapping management information of the current basic block; Based on the first mapping information, determine whether there is a mapping relationship between the registers read by the instruction in the current basic block and the entry mapping management information. If there is a mapping relationship between the registers read by the instruction and the entry mapping management information, replace the registers read by the instruction with the source registers in the mapping relationship, and mark the transfer instruction that provides the mapping relationship as a candidate deletion instruction. The usage of the candidate deletion instructions is analyzed in order to delete the candidate deletion instructions.
2. The method according to claim 1, characterized in that, The register mapping management information also includes third mapping information, which is used to record the mapping relationship between the destination register and the source operation; The step of performing an intersection operation based on the exit mapping management information of each basic block in the control graph flow to generate the entry mapping management information of the current basic block includes: Traverse all predecessor basic blocks of the current basic block to obtain the exit mapping management information of each predecessor basic block; Use the exit mapping management information of the first predecessor basic block as the initial entry mapping management information; Obtain exit mapping management information from other precursor basic blocks, and determine whether each mapping entry in the first mapping information exists in the initial entry mapping management information, and determine whether the operation semantics of the mapping entries are consistent based on the third mapping information; If the mapping entry does not exist in the initial entry mapping management information, or if the operation semantics are determined to be inconsistent according to the third mapping information, then the mapping entry is deleted from the initial entry mapping management information to obtain the entry mapping management information of the current basic block.
3. The method according to claim 1, characterized in that, The step of determining whether the registers read by the instruction in the current basic block have a mapping relationship in the entry mapping management information based on the first mapping information includes: Detect whether there is a register read operation in the instructions of the current basic block; If the instructions in the current basic block contain an operation to read a register, then according to the first mapping information, query the entry mapping management information to see if there is a mapping entry with the read register as the destination register; If the entry mapping management information contains a mapping entry with the read register as the destination register, then it is determined that the read register has a mapping relationship in the entry mapping management information; If there is no mapping entry in the entry mapping management information that takes the read register as the destination register, then it is determined that the read register does not have a mapping relationship in the entry mapping management information.
4. The method according to claim 1, characterized in that, If the register read by the instruction has a mapping relationship in the entry mapping management information, then the register read by the instruction is replaced with the source register in the mapping relationship, and the transfer instruction that provides the mapping relationship is marked as a candidate deletion instruction, including: If the register read by the instruction has a mapping relationship in the entry mapping management information, obtain the source register in the mapping relationship; Replace the register read by the instruction with the source register; Obtain the transmission instruction that provides the mapping relationship, and mark the transmission instruction as a candidate deletion instruction.
5. The method according to claim 4, characterized in that, The register mapping management information further includes second mapping information, which is used to record the mapping relationship between the source register and the destination register; if the register to be read by the instruction has a mapping relationship in the entry mapping management information, then the register to be read by the instruction is replaced with the source register in the mapping relationship, and the transfer instruction that provides the mapping relationship is marked as a candidate deletion instruction, further comprising: If a modification operation to the source register is detected, all destination registers that depend on the source register are obtained according to the second mapping information, and the mapping relationship of all destination registers in the register mapping management information is deleted. If a modification operation to the destination register is detected, the mapping relationship with the destination register as the primary key in the register mapping management information will be deleted. If a function call instruction is detected, the mapping relationship between the destination register and the caller's saved register in the register mapping management information will be deleted. Store the mapping management information after all instructions within the current basic block have been processed as the exit mapping management information. If the export mapping management information changes compared to the previous iteration, all successor basic blocks of the current basic block are added to the working list, and the iteration continues until the working list is empty.
6. The method according to claim 1, characterized in that, The analysis of the usage of the candidate deletion instructions, in order to delete the candidate deletion instructions, includes: Starting from the basic block where the candidate deletion instruction is located, recursively check the usage of the destination register in the candidate deletion instruction on each reachable path along the successor edge of the control flow graph; Determine whether each reachable path can be deleted based on the inspection results; If all reachable paths are deletable, then the candidate deletion instruction is removed from the instruction sequence.
7. The method according to claim 6, characterized in that, After determining whether each reachable path can be deleted based on the inspection results, the process also includes: If a read of the destination register is detected on a reachable path, then the reachable path is determined to be a non-deletable path; If a redefinition operation on the destination register is detected first on the reachable path, and there was no prior reading or use of the destination register before the redefinition operation, then the reachable path is determined to be a deletable path.
8. A register copy propagation optimization device, characterized in that, The device includes: A mapping information construction module is used to construct register mapping management information, wherein the register mapping management information includes at least first mapping information for recording the mapping relationship between the destination register and the source register; The intersection operation module is used to perform intersection operations based on the exit mapping management information of each basic block in the control graph flow to generate the entry mapping management information of the current basic block. The deletion instruction determination module is used to determine whether there is a mapping relationship between the register read by the instruction in the current basic block and the entry mapping management information based on the first mapping information. If there is a mapping relationship between the register read by the instruction and the entry mapping management information, the source register in the mapping relationship is used to replace the register read by the instruction, and the transfer instruction that provides the mapping relationship is marked as a candidate deletion instruction. The instruction deletion module is used to analyze the usage of the candidate deletion instructions in order to delete the candidate deletion instructions.
9. A computer device, characterized in that, include: A memory and a processor are communicatively connected, the memory stores computer instructions, and the processor executes the computer instructions to perform the register copy propagation optimization method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing the computer to execute the register copy propagation optimization method according to any one of claims 1 to 7.
