Method and apparatus for an improved optimizing compiler
First Claim
1. A computer system having a central processing unit (CPU) and random access memory (RAM) coupled to said CPU, for use in compiling a target program to run on a target computer architecture having a fixed number of CPU registers, said target program having at least one basic block and wherein "use" blocks are inserted in a control flow graph which inhibit needless variable spilling to memory, said computer system comprising:
- a compiler system resident in said computer system having a front end compiler, a code optimizer and a back end code generator; and
said code optimizer configured to determine a set of live variables for said basic block in said target program, wherein said fixed number of CPU registers in said target computer architecture can be allocated to said set of live variables in a manner which minimizes a number of variables in said set of live variables that must be stored in said memory instead of in said fixed number of CPU registers,wherein said code optimizer inserts, in at least a portion of a control flow graph, a dummy block representing usage of a variable in said control flow graph prior to a phi-function node and determines said set of live variables by considering said dummy block, and wherein said code optimizer is further configured to perform a static single assignment transform on said target program and to add said phi function node to said control flow graph representation of said target program, and wherein said dummy block is a use block.
1 Assignment
0 Petitions
Accused Products
Abstract
An optimizing compiler process and apparatus is disclosed for more accurately and efficiently identifying live variable sets in a portion of a target computer program, so as to more efficiently allocate registers in a computer central processing unit. The process of the invention includes the steps of performing a static single assignment transform to a computer program, including the addition of phi functions to a control flow graph. Basic blocks representing a use of a variable are further added to the control flow graph between the phi functions and definitions of the variables converging at the phi functions. A backward dataflow analysis is then performed to identify the live variable sets. The variables in the argument of phi functions are not included as a use of those variables in this dataflow analysis. The dataflow analysis may be iteratively performed until the live variable sets remain constant between iterations. The apparatus of the present invention includes a computer system having a memory storing a set of variables that are live during the execution of a portion of a computer program. This memory may include CPU registers, cache memory, conventional RAM and other types of memory.
143 Citations
22 Claims
-
1. A computer system having a central processing unit (CPU) and random access memory (RAM) coupled to said CPU, for use in compiling a target program to run on a target computer architecture having a fixed number of CPU registers, said target program having at least one basic block and wherein "use" blocks are inserted in a control flow graph which inhibit needless variable spilling to memory, said computer system comprising:
-
a compiler system resident in said computer system having a front end compiler, a code optimizer and a back end code generator; and said code optimizer configured to determine a set of live variables for said basic block in said target program, wherein said fixed number of CPU registers in said target computer architecture can be allocated to said set of live variables in a manner which minimizes a number of variables in said set of live variables that must be stored in said memory instead of in said fixed number of CPU registers, wherein said code optimizer inserts, in at least a portion of a control flow graph, a dummy block representing usage of a variable in said control flow graph prior to a phi-function node and determines said set of live variables by considering said dummy block, and wherein said code optimizer is further configured to perform a static single assignment transform on said target program and to add said phi function node to said control flow graph representation of said target program, and wherein said dummy block is a use block. - View Dependent Claims (2, 3, 4, 5, 6)
-
-
7. A compiler system for compiling a target program to run on a target computer architecture having a memory and a plurality of CPU registers, said compiler system comprising:
-
a front end portion configured to accept source code of said target program as input and to output a corresponding intermediate code set; a code optimizer portion coupled to said front end portion and configured to accept said intermediate code set as input and to output a second intermediate code set, wherein said second intermediate code set comprises code for said target program that allocates said plurality of CPU registers of said target computer architecture to a set of live variables for basic blocks in said target program in a manner which minimizes a number of variables in said set of live variables that must be stored in said memory instead of in said plurality of CPU registers, wherein said code optimizer inserts, in at least a portion of a control flow graph, a dummy block representing usage of a variable in said control flow graph prior to a phi-function node and determines said set of live variables by considering said dummy block;
wherein said code optimizer is further configured to perform a static single assignment transform on said target program, and to add said phi function node to said control flow graph representation of said target program and wherein said dummy block is a use block; anda back end code generator portion coupled to said code optimizer configured to accept said second intermediate code set as input and to generate binary code which will run on said target computer architecture. - View Dependent Claims (8, 9, 10, 11, 12)
-
-
13. A code optimizer for use in an compiler system for compiling a target program to run on a target computer architecture having a memory and a plurality of CPU registers, said code optimizer comprising:
-
a first portion configured to accept as input an intermediate code representation of said target program; a second portion, coupled to said first portion, configured to determine a set of live variables for at least one basic block of said target program; and a third portion, coupled to said second portion, configured to allocate said plurality of CPU registers of said target computer architecture to said set of live variables for said basic blocks of said target program in a manner that minimizes a number of variables in said set of live variables that must be stored in said memory instead of in said plurality of CPU registers, wherein said third portion inserts, in at least a portion of a control flow graph, a dummy block representing usage of a variable in said control flow graph prior to a phi-function node and determines said set of live variables by considering said dummy block, wherein the third portion is further configured to perform a static single assignment transform on said target program and to add said phi function node to said control flow graph representation of said target program, and wherein said dummy block is a use block. - View Dependent Claims (14, 15, 16, 17, 18)
-
-
19. A computer controlled method of allocating a live set of variables in a target program to a fixed number of CPU registers in a target computer architecture in a manner that minimizes a number of variables in said live set of variables that must be stored in a memory instead of in said fixed number of CPU registers;
- said target program having at least one basic block said method comprising steps of;
a) constructing an interference graph representing a procedure of said target program; b) determining said live set of variables for said target program by sub-steps of; b1) performing a static single assignment transform of said procedure of said target program, including a step of adding a phi function to a control flow graph of said target program; b2) inserting a use block representative of a use of a variable in said control flow graph between said phi function and a block containing a definition of said variable; and b3) determining said live set of variables for said basic block in said target program by a backward dataflow analysis of said control flow graph without including arguments of said phi function wherein said backward dataflow analysis is performed beginning at an end of said basic block, initially adding to said live set of variables those variables live at a beginning of one or more children blocks of said basic block and adding to said live set of variables each instance of a use of a variable and deleting from said live set of variables each subsequent definition of said variable; and c) mapping said live set of variables to said fixed number of CPU registers. - View Dependent Claims (20, 21)
- said target program having at least one basic block said method comprising steps of;
-
22. A computer controlled method of optimizing binary code of a target program which is compiled to run on a target computer architecture having a memory and a fixed number of CPU registers, said method comprising steps of:
-
a) providing a compiler system configured to accept source code of said target program and to output binary code representing said target program which is capable of being processed on said target computer architecture, said compiler system comprising a front end portion, a code optimizer portion and a back end code generator; b) providing said code optimizer portion of said compiler system configured to accept intermediate code from said front end portion of said compiler system and to allocate a live set of variables in said intermediate code representing said target program to said fixed number of CPU registers in said target computer architecture in a manner that minimizes a number of variables in said live set of variables that must be stored in said memory instead of in said fixed number of CPU registers, wherein allocation of said live set of variables in said intermediate code representing said target program to said fixed number of CPU registers is performed by sub-steps; (b1) constructing an interference graph representing a procedure of said target program;
determining said live set of variables for said target program by sub-steps of;(b1a) performing a static single assignment transform of said procedure of said target program, including adding a phi function to a control flow graph of said target program; (b1b) inserting a use block representing usage of a variable in said control flow graph between said phi function and a defining block containing a definition of said variable; and (b1c) determining said live set of variables for basic blocks in said target program by a backward dataflow analysis of said control flow graph; (b2) mapping said live set of variables to said fixed number of CPU registers; and (c) outputting a second intermediate code version of said target program to said back end code generator, said second intermediate code version of said target program containing the allocation of said live set of variables in said target program to said fixed number of CPU registers in said target computer architecture in a manner that minimizes a number of variables in said live set of variables that must be stored in said memory instead of in said fixed number of CPU registers, whereby said target program binary code is optimized.
-
Specification