The present invention relates generally to compiler systems and, more particularly, to a system and method to reduce the size of source code in a processing system.
Increasingly, the size of compiled code has an impact on the performance and economics of computer systems. From embedded systems, such as cellular phones, to applets shipped over the World Wide Web, the impact of compile-time decisions that expand the size of the source code has a direct effect on cost and power consumption, as well as on the transmission and execution time of the code.
Several techniques have been proposed to reduce the size of the source code. One known technique turns repeated code fragments into procedures and is usually applied to intermediary code or even source code. However, this technique appears to miss repeated code fragments introduced during code generation. Another known technique reuses the common tail of two merging code sequences and is usually performed after code generation. However, syntactic mismatches seem to affect the efficiency of this technique.
The present invention is illustrated by way of example and not limitation in the figures of the accompanying drawings, in which like references indicate similar elements and in which:
In the following descriptions for the purposes of explanation, numerous details are set forth in order to provide a thorough understanding of the present invention. However, it will be apparent to one skilled in the art that these specific details are not required in order to practice the present invention. In other instances, well-known electrical structures or circuits are shown in block diagram form in order not to obscure the present invention unnecessarily.
A system and method to reduce the size of source code in a processing system are described. Multiple subgraph structures are identified within a graph structure constructed for multiple source code instructions in a program. Unifiable variables that are not simultaneously used in the source code instructions are identified within each subgraph structure. Finally, one or more unifiable instructions from a tine of a corresponding subgraph structure are transferred to a handle of the corresponding subgraph structure, each unifiable instruction containing one or more unifiable variables.
In one embodiment, if a known “omega motion” procedure is used, wherein source code instructions are moved downwardly past join points, matching instructions within the basic blocks 202, 203 are unified and subsequently transferred to common successor block 204, while being removed from their respective locations in the basic blocks 202 and 203. Alternatively, if a known “alpha motion” procedure is used, wherein source code instructions are moved upwardly past fork points, matching instructions within the basic blocks 202, 203 are unified and subsequently transferred to common predecessor block 201, while being removed from their respective locations within the blocks 202 and 203.
For example, in the case of an “omega motion” procedure, the instruction “z=x*y”, located within basic block 202, and the instruction “z=a*b”, located within basic block 203, may be unified by unifying the variables x and b, and unifying the variables y and a, and by exploiting the fact that each multiplication is commutative. Once the two unifiable instructions are unified, the pair of matching instructions may be removed from the basic blocks 202, 203 and a single copy of the unified instruction may be inserted past the join point. The process of identification and unification of the matching unifiable instructions will be described in further detail below.
At processing block 320, an interference graph structure is constructed for local variables mentioned on the tines of each subgraph structures. In one embodiment, the interference graph structure indicates which variables of the local variables are simultaneously used in the source code instructions within the tines and cannot be unified, i.e., the variables that have overlapping live ranges.
The interference graph structure is represented as a symmetric matrix INTERFERE (i,j), where i and j correspond to local variables. INTERFERE(i,j,) is true if variables i and j are both live at some point in the program. In one embodiment, determining whether the variables have overlapping live ranges can be achieved using one of many known methods of determination. One of such methods is data-flow analysis. In the exemplary source code of
Variable z does not interfere with any other local variable. For example, variable z is assigned immediately after x and y are last used, so the live range of variable z abuts, but does not overlap, the live ranges of variables x and y. Global variables, for example variable w, are not included in the interference graph structure 400 because they are presumed to have unknown live ranges. In one embodiment, the interference graph structure 400 also includes self loops for each local variable x, y, z, a, and b.
Referring back to
Referring back to
At processing block 620, a decision is made whether a search for the flags returns true, i.e. initialized flags are found. One embodiment of processing block 620 is implemented in pseudo-code as follows:
A “transaction stack” is a stack of information about tentative unifications that might have to be rolled back, i.e. undone. In the pseudo-code, the phrase “roll back transaction stack to depth r” means to iteratively pop transactions, and undo their effects, until the stack has depth r again.
In order to match variables, a look up for their union-find representatives is performed to assess if the representatives are equal. If so, the variables are already identical, or have already been unified (possibly tentatively). Otherwise, a check is performed to assess if the variables' union-find representatives do not interfere (i.e. have disjoint live ranges). If two variables do not interfere, then the variables are tentatively unified. A transaction for this unification is then pushed onto the transaction stack, so that it can be undone at a later time if considered necessary.
If no flags are found and the search returns false, then the procedure ends. Otherwise, if the search for flags returns true, at processing block 630, the instructions associated with the initialized flags are unified. One embodiment of processing block 630 is implemented in pseudo-code as follows:
At processing block 640, for each tine, dependence counts for the instructions dependent on the unified instructions are decremented. One embodiment of processing block 640 is implemented in pseudo-code as follows:
At processing block 650, the unified instruction is moved from the first corresponding tine to the handle. Finally, at processing block 660, any unified instruction is removed from any subsequent corresponding tines. Processing blocks 620 through 660 are subsequently repeated.
Memory 710 can be a hard disk, a floppy disk, random access memory (RAM), read only memory (ROM), flash memory, or any other type of machine medium readable by the processor 720. Memory 710 can store instructions to perform the execution of the various method embodiments of the present invention.
In the foregoing specification, the invention has been described with reference to specific exemplary embodiments thereof. It will, however, be evident that various modifications and changes may be made thereto without departing from the broader spirit and scope of the invention as set forth in the appended claims. The specification and drawings are, accordingly, to be regarded in an illustrative sense rather than a restrictive sense.
| Number | Name | Date | Kind |
|---|---|---|---|
| 4833606 | Iwasawa et al. | May 1989 | A |
| 5822593 | Lamping et al. | Oct 1998 | A |
| 5835776 | Tirumalai et al. | Nov 1998 | A |
| 5854934 | Hsu et al. | Dec 1998 | A |
| 5867711 | Subramanian et al. | Feb 1999 | A |
| 5930510 | Beylin et al. | Jul 1999 | A |
| 6173444 | Archambault | Jan 2001 | B1 |
| 6438747 | Schreiber et al. | Aug 2002 | B1 |
| 6516305 | Fraser | Feb 2003 | B1 |
| 6594824 | Volkonsky et al. | Jul 2003 | B1 |
| 6651246 | Archambault et al. | Nov 2003 | B1 |
| 6665865 | Ruf | Dec 2003 | B1 |
| 6823514 | Degenaro et al. | Nov 2004 | B1 |
| 6918111 | Damron et al. | Jul 2005 | B1 |
| Number | Date | Country | |
|---|---|---|---|
| 20030131344 A1 | Jul 2003 | US |