Method of, system for, and computer program product for providing extended global value numbering6035124Abstract A fast and efficient way of performing extended global value numbering beyond basic blocks and extended basic blocks on a complete topological ordering of basic blocks in a program. Global value numbering is further extended with a Value Number List, an ordered list of value numbers of an expression, and iterative processing of a worklist containing expressions which are recursively defined. A hash table is used to reduce storage and processing time. Claims I claim: Description A portion of the Disclosure of this patent document contains material which is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document or the patent disclosure, as it appears in the Patent and Trademark Office patent file or records, but otherwise reserves all copyright rights whatsoever.
TABLE A
______________________________________
Value Numbering
An expression may receive more than one value number.
______________________________________
Example a:
= x0 + y0; VN for x0+y0= 10,VN for x0 = 9
if( )then
= x0 + y0; VN for x0+y0 = 10
else do;
x = VN for x1 = 11
= x1 + y0; VN for x1+y0: 12
end;
x2 = .phi.(x0,x1);
VN for x2 = 9 or 11
= x2 + y0; VN for x2+y0 = 10 or 12
x2+y0 is redundant here since it receives both VN 10 & 12.
Example b:
if( )then VN for x0 = 9
= x0 + y0; VN for x0+y0: 10
else do;
= x0 + y0; VN for x0+y0: 10
x1 = VN for x1: 11
end;
x2 = .phi.(x0,x1);
VN for x2 = 9,11
= x2 + y0; VN for x2+y0: 10,12
x2+y0 is partially redundant since it receives just VN 10
Example c:
if( )then VN for p0,q0 =9,10
p0 =; q0 =; VN for p0+q0: 11
= p0 + q0;
else do;
pl =; q1 =; VN for p1,q1 =12,13
= pl + q1;
VN for p1+q1: 14
end;
p2 = .phi.(p0,p1);
VN for p2 = 9,12
q2 = .phi.(q0,q1);
VN for q2 =10,13
= p2 + q2; VN for p2+q2=p0+q0 (left path) 11
p1+q1 (right path) 14
p2+q2 is redundant since it receives both VN 11,14
______________________________________
Value Number Set (VNSet) All expressions that look lexically the same (e.g., x.sub.0 +y.sub.0, x.sub.1 +y.sub.1, x.sub.2 +y.sub.2) together with all other expressions sharing the same value numbers with these lexically similar expressions, form a Value Number Set or VNSet. The construction of .phi.-functions and renaming are performed on a temporary holding these expressions as a group. Value Number List (VNList) The Value Number List is an ordered list of value numbers of an expression. In Example (a) of Table A above, the VNList of x2 is (9,11). The VNList of x2+y0 is (10,12) in Example (a) and Example (b) of Table A. In Example (c) of Table A, the VNlist of p2+q2 is (11,14). Extended Global Value Numbering Rules When two expressions have the same value number and this value number is unique, the following cases are possible: one of them is either redundant, or partially redundant, or none of them is redundant. If an expression has more than one value number, for example vn1 and vn2, and both vn1 and vn2 reach the expression, then that expression is redundant. The Value Number List of an incoming expression is computed and compared with the Value Number List of a current expression. If the two VNlists match in value, and in order, then the expression is redundant. The VNlist of the incoming expression is evaluated from the .phi.-function of the temporary holding the expression. The VNList of the current expression is computed from the .phi.-function of the source operands. If an expression has more than one value number, for example vn1 and vn2, and either vn1 or vn1, but not both, reaches the expression, then that expression is partially redundant. Although the basic blocks are processed in topological order, source operands of the .phi.-functions may be undefined when a .phi.-function is processed. This is illustrated in the example of Table B below. During a first pass in topological order, the source operand x2 of the .phi.-function .phi.(x0,x2) is undefined as the source operand x2 is defined later in the topological order.
TABLE B
______________________________________
Value Number
Value Number
Initial Pass
Subsequent Pass
______________________________________
do i = 1,10
x1 = .phi.(x0,x2)
10,undefined
10,11
= x1 + y0 9,12 9,12
x2 = 11 11
= x2 + y0 12 12
end
______________________________________
Procedure for Extended Global Value Numbering The Extended Global Value Numbering of the present invention may be performed by the following steps: Walk basic blocks in topological order and process each expression. Each expression (right hand side (RHS) and left hand side (LHS)) receives a value number. In SSA form, all definitions are exposed. All other operands, which do not have a value number yet, receive a LatticeCell of or a value number of unknown. If the expression contains an operand of unknown value, i.e., the LatticeCell equals to , then the corresponding text is put onto the worklist. A Hash table is used to speed up the storing and retrieval of value numbers. The hash key consists of the op-code plus all its operands. This also allows varying the number of operands. For single items, such as x.sub.0, X.sub.1, X.sub.2, X.sub.3, the value number is stored in an array in the dictionary. This saves space in the hash table. In general, for x.sub.0 +y.sub.0, both x.sub.0 +y.sub.0 and x+y are hashed. The later x+y is the lexical item used to store all corresponding VNSets. Since hashing is performed globally for all expressions, garbage collection allows reuse of entries in the hash table to conserve space. At the exit of the outermost loop, all expressions that are marked as variant may be removed from the hash table. This requires some copying of information from the hash table to the dictionary. The data structures are designed such that the hash table need not be referenced after the expressions are value numbered and the temporary is created. See section entitled "Hash Table" below for additional details describing how value numbers are assigned. The procedure terminates when the worklist becomes empty. This happens when all expressions and items are assigned with a VNlist. A text is taken off the worklist if the operands are defined already. Each time a new value number is formed, the expression is entered into the hash table. Value numbers and value number lists are evaluated and created using the following rules: for .phi.-functions:
______________________________________
any .andgate..sub. ==>.sub.
If any operand of the .phi.-function has an unknown
value number, then set the value number of the
.phi.-function to unknown.
VN.sub.i .andgate. VN.sub.j ==> VN.sub.k
If VN.sub.i not equal to VN.sub.j, then a new value number
is formed when the operands are involved in a recursive
definition, else VNList for VN.sub.i and VN.sub.j is formed.
VN.sub.i .andgate. VN.sub.j ==> VN.sub.i if i = j
If all value numbers of .phi.-function operands are equal, then set
.phi.-function value number to operand value number.
for other op-codes:
any .andgate..sub. ==>.sub.
If any operand of has unknown value number, then set the value
number to unknown.
VN.sub.i .andgate. VN.sub.j ==> VN.sub.k
______________________________________
If value numbers are not equal, then a new value number is formed and assigned if not already assigned. Note that .perp. does not exist in this meet operation. The application of these rules result in assigning a value number to each expression of a first subset of the expressions; assigning an unknown value number to each expression of a second subset of the expressions; and assigning a value number list to each expression of a third subset of the expressions, wherein the value number list comprises an ordered list of value numbers assigned to the expression. If the number of items on the worklist remains the same after a pass through it, then some .phi.-function operands are defined recursively in terms of one another. In this case, new value numbers are assigned to the targets of the .phi.-function. Referring now to FIG. 4, the operations preferred in carrying out Extended Global Value Numbering 400 are illustrated. The process begins at process block 405. Thereafter, process block 410 begins a loop that walks the basic blocks in topological order of the flow graph. Thereafter, process block 415 begins a loop for each expression and .phi.-function in a basic block to perform value numbering. The performance of value numbering is illustrated in greater detail in FIG. 5. Thereafter, decision block 430 determines if there are remaining expressions in the basic block to be processed. If there are remaining expressions in the basic block, then processing loops back to process block 415 to process the next expression and .phi.-function in the basic block. Returning now to decision block 430, if there are no remaining expressions in the basic block to be processed, then decision block 455 determines if there are remaining basic blocks to be processed by the loop. If there are remaining basic blocks to be processed, then processing loops back to process block 410 to process the next basic block in topological order of the flow graph. Returning now to decision block 455, if there are no remaining basic blocks to be processed by the loop, then decision block 460 determines if the worklist is empty. If the worklist is empty, then the process ends at process block 465. Returning now to decision block 460, if the worklist is not empty, then decision block 470 determines if the number of items on the worklist is the same as the number of items on the worklist during the last pass through the worklist. If the number of items on the worklist is the same, then process block 475 asigns new value numbers to the targets of recursively defined .phi.-functions. Thereafter, process block 480 reinitializes the loop starting at process block 410 to repeat the loop process for those items still on the worklist. Thereafter, processing continues to process block 410 to begin another loop to process those items still on the worklist. Returning now to decision block 470, if the number of items on the worklist is not the same as the number of items on the worklist during the last pass through the worklist, then processing continues to process block 480 to reinitialize the loop starting at process block 410 to repeat the loop process for those items still on the worklist. Referring now to FIG. 5, the operations preferred in carrying out the performance of value numbering of process block 415 are illustrated. The process begins at process block 505, and thereafter, decision block 510 determines if the current expression is a .phi.-function. If the current expression is not a .phi.-function, i.e., if it is an expression, then decision block 515 determines if the left hand side (LHS) of the expression has been assigned a value number. If no value number has been assigned to the LHS, then process block 520 creates and assigns a new unique value number to the LHS. Thereafter, decision block 525 determines if any right hand side (RHS) operands of the current expression have an unknown value number. If so, then decision block 530 determines if the operand with an unknown value number is a use before definition. If it is not a use before definition, then process block 535 creates and assigns a new unique value number to the operand. Process block 520 and process block 535 are portions of the processing which assign a value number to each expression of a first subset of the expressions. Thereafter, the process ends at process block 545. Returning now to decision block 515, if a value number has been assigned to the LHS, then processing continues to decision block 525 to determine if any right hand side (RHS) operands of the current expression have an unknown value number. Returning now to decision block 525, if any right hand side (RHS) operands of the current expression do not have an unknown value number, i.e., if all RHS operands have been assigned a value number, then the process ends at process block 545. Returning now to decision block 530, if the operand with an unknown value number is a use before definition, then process block 540 puts the corresponding text on a worklist, and then the process ends at process block 545. Returning now to decision block 510, if the current expression is a .phi.-function, then decision block 550 determines if any operand of the .phi.-function has an unknown value number. If any operand of the .phi.-function has an unknown value number, then process block 555 sets the value number of the .phi.-function equal to unknown. Process block 555 is that portion of the processing which assigns an unknown value number to each expression of the second subset of the expressions. Thereafter, process block 560 puts the corresponding text of the .phi.-function on the worklist, and then the process ends at process block 545. Returning now to decision block 550, if no operand of the .phi.-function has an unknown value number, then decision block 565 determines if all of the value numbers of the .phi.-function operands are equal. If all of the value numbers of the .phi.-function operands are equal, then process block 570 sets the value number of the .phi.-function to the value number of the operands. Thereafter, process block 590 removes any corresponding text from the worklist, and then the process ends at process block 545. Returning now to decision block 565, if all of the value numbers of the .phi.-function operands are not equal, then decision block 575 determines if the .phi.-function is involved in a recursive definition. If the .phi.-function is involved in a recursive definition, then process block 580 creates and assigns a new unique value number to the .phi.-function. Process block 580 is another portion of the processing which assigns a value number to each expression of a first subset of the expressions. Thereafter, processing continues to process block 590 to remove any corresponding text from the worklist. Returning now to decision block 575, if the .phi.-function is not involved in a recursive definition, then process block 585 forms a value number list for the .phi.-function, where the value number list is an ordered list of the value numbers of the .phi.-function operands. Process block 585 is that portion of the processing which assigns a value number list to each expression in the third subset of the expressions. Thereafter, processing continues to process block 590 to remove any corresponding text from the worklist. Determining Redundancy Some expressions become redundant only after code is moved to the preheader of a loop. The following Table C show an example of such a situation. This type of redundancy may be determined by a lookup each time any code is moved.
TABLE C
______________________________________
Redundancy discovered after code is moved
______________________________________
do while ()
if( ) then
do;
if () then z1=x + y;
end;
else z2 = x + y;
z3 = x + y;
end;
______________________________________
Other redundancies may be determined prior to code motion. The present invention determines redundancy prior to code motion by performing the following steps. Construct .phi.-functions and Do Renaming for Expressions For each expression in the same value number set, say x0+y0, x1+y1, x1+z1, .phi.-functions are constructed and renaming is perfomed. Techniques for the construction of .phi.-functions and renaming such as those of Cytron et al. are well known by those skilled in the art. The present invention extends these well known techniques by: only introducing .phi.-functions for expressions at the beginning of this process; treating each expression as a use followed by a set; and performing redundancy removal during renaming if the use of an expression is dominated by the set of the expression. The following Table D illustrates this extended construction of .phi.-functions for expressions.
TABLE D
______________________________________
Construct .phi.-functions for expressions
______________________________________
if () then a = x + y + z;
d = x + y;
Construct .phi.-functions. For expressions that have the same value
numbers,
treat it as a "Use followed by a Set". The "use" does not
form a new text. It exists just as a special operand
in RHS.
==>
if() then do;
= t;
t = x + y
end;
= t;
t = x + y
d = t3;
______________________________________
The following Table E illustrates the renaming of the operands of the constructed .phi.-functions.
TABLE E
______________________________________
Rename operands of .phi.-functions
______________________________________
After .phi.-functions are built, do renaming.
==>
if () then do;
= t0
t1 = x + y
= t1 + z
end;
s1: t2 = .phi.(t0,t1)
= t2
s2: t3 = x + y
d = t3
______________________________________
The following Table F illustrates performing redundancy removal during renaming if the use of an expression is dominated by the set of the expression.
TABLE F
______________________________________
Removing Redundancy During Renaming
______________________________________
= x + y + z
==> t1 = x + y ==> tl = x + y
= x + y = t1 = tl
= x + y = t1
______________________________________
After renaming and its redundancy removal, any source operands of .phi.-functions or "fake uses" which remain unnamed are undefined. This means the expression is not a candidate for redundancy removal or code motion. For these expressions, further processing determines if an expression is redundant, either fully redundant or partially redundant. Determining Redundancy and Partial Redundancy An expression is redundant if it is evaluated before on all paths. This redundancy occurs when: if an expression has more than one value number, for example vn1 and vn2, and both vn1 and vn2 reach the expression, or the Value Number List of the expression matches in value, and in order, the Value Number List of another expression in its path. An expression is partially redundant if it is evaluated before on some but not all paths. This occurs when: the value number of an expression is vn1, and both vn1 and vn2 reach the expression; or the value numbers of the expression are vn1 and vn2, and only vn1 reaches it. All expressions that are marked as loop invariants may be regarded as partial redundancies, without any further analysis. Partial redundancy may be determined together with the redundancy determination above. The present invention identifies redundancies and partial redundancies by performing the following: For every "fake" use, examine its definitions, if the value of its definition is equal to the expression, then the expression is redundant. If the "fake" use has more than one value, then the definition must define all these values. As given in the examples below, the values numbers of the temporary and those of receiving expression ("fake use" ) are constructed and compared. If the "fake" use has more than one value, and only one value reaches it, then it is partially redundant. The .phi.-functions for the temporary and source operands may appear in different join points. When tracing the source operand backwards, if a .phi.-function for the source operand appears alone, then the temporary needs to be spilt too. This way the VNLists always have the same number of elements. The tracing of the source operands in certain paths terminates when one of the following conditions is reached: when one .phi.-function dominates the other; when all .phi.-functions are processed; when the temporary is reached; when the source operand is defined; or when the source operands define one another via .phi.-functions. This happens when a definition appears inside a loop. In tracing the temporary backwards, if the temporary is defined in a loop but only in certain paths, this special pattern should be recognized and updated as shown on the right in the following Table G.
TABLE G
______________________________________
Temporary only defined in certain paths in a loop
______________________________________
t0 = x0 + y0
==> t0 = x0 + y0
do i = 1,10 do i = 1,10
t2 = .phi.(t3,t0)
if() then t1 = x0 + y0
if() = . . t0
. . .
t3 = .phi.(t2,t1)
end end
VN for t in this path consists of
one element
______________________________________
Redundant expressions are updated with inter-block temporaries, and resultant spurious .phi.-functions are also cleaned up. Inter-block temporaries are created to hold expressions. Source operands of the .phi.-functions are also updated.
TABLE H
__________________________________________________________________________
Determination of redundancy
__________________________________________________________________________
Case (a):
t1 = x0 + y0 vn = 10
. . .
= t1 "fake use"
t2 = x0 + y0 vn = 10 .fwdarw. redundant
Case (b):
##STR1## VN = 12, 13 VN = 9, 10 VNList =
(12, 13) "fake use" 12, 13 VNList = (12, 13) .fwdarw.
redundant
Case (c):
##STR2## VN = 20, 21 VN = 20, 21 "fake use"
20, 21 Vn = x0 + y0, x1 + y1 = 20, 21 .fwdarw. redundant
Notice that Vn for w4 is constructed of just two
combinations instead of four; the values can either come
in from the left or from the right, so x0 + y1 is an
invalid combination.
Case (d):
##STR3##
__________________________________________________________________________
Referring now to FIG. 7, operations preferred in carrying out the Determining Redundancy 700 portion of the present invention are illustrated. The process begins at process block 705. Thereafter, process block 710 begins a loop for each "fake use". Thereafter, process block 715 computes a Value Number list (VNlist) of the current expression from the .phi.-function of the source operands. Thereafter, process block 720 computes the VNlist of the incoming expression from the .phi.-function of a temporary holding the expression. Thereafter, decision block 725 determines if the VNlists of the incoming expression and the current expression are identical. If the VNlists are identical, then process block 730 marks current expression as redundant. Thereafter, decision block 735 determines if there is a remaining "fake use". If there is a remaining "fake use", then processing loops back to process block 710 to process the next "fake use". Returning now to decision block 725, if the VNlists of the incoming expression and the current expression are not identical, then decision block 740 determines if the Returning now to decision block 740, if the VNlists of the incoming expression and the current expression do not have a common value number, then processing continues to decision block 735 to determine if there is a remaining "fake use". Returning now to decision block 735, if there is not a remaining "fake use", then the processing ends at process block 750. Moving Invariants As mentioned earlier, expressions that are loop invariants may be regarded as partial redundancies. Loop invariants may be identified before other partial redundancies to speed up the process of moving the invariant expressions. In general, a partial redundancy is moved upwards basic block by basic block; whereas, an invariant is moved once to a loop preheader. If "unsafe" optimization is used, then an invariant may be moved to a loop preheader, even though the invariant is not anticipated in all paths. For "safe" optimization, an invariant expression that has side effects (e.g., floating divide) may only be moved if the same invariant expression exists in all paths. For C-language expressions, an invariant expression may only be moved if the invariant expression exists in all paths independent of whether or not the invariant expression can cause side effects. If an invariant exists in a basic block that dominates a loop exit, then the invariant may always be moved. This situation is shown in Table J below. If not, a .phi.-function should reside at a basic block that dominates the loop exit, and all the operands of the .phi.-function should have the same value number.
TABLE J
______________________________________
Moving invariants
Since t0 = t3 and assuming t4 resides in block that dominates the loop
exit,
then all x + y can be moved.
______________________________________
##STR6##
______________________________________
After an invariant is moved to the loop preheader, as shown in Table M, some previously processed expressions dominated by the preheader may become redundant as a result of moving the invariant. This may be determined by searching the use-definition chains. Variables that have uses that are upwardly exposed in the loop are treated as variants. The following Table K shows such a variant with upwardly exposed usage.
TABLE K
______________________________________
Variant with upwardly exposed usage
______________________________________
do while
= t
t =
end
______________________________________
Invariants without an upward exposed usage cannot be moved. The following Table L shows an example of an invariant without upward exposed usage which cannot be moved.
TABLE L
______________________________________
Invariant without upwardly exposed usage
SSA Form
______________________________________
i = 1 il = 1
do while ()
do while ()
if ( ) then i2 <== .phi.(i4,i1)
i = 2 if() then
i3 = 2
end i4 <== .phi.(i3, i2)
= i end
i5 <== .phi.(i4, i1)
= i5
______________________________________
In the following example of Table M, all x+y are marked as invariants and as partially redundant. The first two x+y cannot be moved because it is not anticipated in all paths. The last x+y dominates the loop exit, and therefore can be moved. After it is moved, all expressions that have the same value number inside the loop can be treated as redundant.
TABLE M
______________________________________
Redundancy discover after code is moved
______________________________________
do while ()
if ( ) then
do;
if () then z1 = x + y; -
end; - else z2 = x + y;
end;
______________________________________
Referring now to FIG. 8, operations preferred in carrying out the Moving Invariant 800 portion of the present invention are illustrated. The process begins at process block 805. Thereafter, process block 810 begins a loop for each invariant. Thereafter, decision block 815 determines if "unsafe" optimization is in use. If "unsafe" optimization is in use, then process block 820 moves the invariant to the loop preheader. Thereafter, decision block 825 determines if there are remaining invariants. If there are remaining invariants, then processing loops back to process block 810 to process the next invariant. Returning now to decision block 815, if "unsafe" optimization is not in use, then decision block 830 determines if the invariant is in a block that dominates a loop exit. If the invariant is in a block that dominates a loop exit, then processing continues to process block 820 to move the invariant to the loop preheader. Returning now to decision block 830, if the invariant is not in a block that dominates a loop exit, then decision block 835 determines if the invariant is a C-language expression. If the invariant is a C-language expression, then decision block 840 determines if the expression exists in all paths. If the expression exists in all paths, then processing continues to process block 820 to move the invariant to the loop preheader. Returning now to decision block 835, if the invariant is not a C-language expression, then decision block 845 determines if the expression has side effects. If the expression has side effects, then processing continues to decision block 840 to determine if the expression exists in all paths. Returning now to decision block 845, if the expression does not have side effects, then processing continues to process block 820 to move the invariant to the loop preheader. Returning now to decision block 840, if the expression does not exist in all paths, then processing continues to decision block 825 to determine if there are remaining invariants. Returning now to decision block 825, if there are no remaining invariants, then the process ends at process block 850. Moving Partial Redundancies An expression is marked as partially redundant if the expression is computed in some, but not all, paths. A loop invariant may be regarded as a partial redundancy because the expression is computed in each iteration, except the first iteration. As shown in Example (d) of Table N below, not all partial redundancies should be moved. In general, a partial redundancy should not be moved to a basic block that has multiple successors. If it is safe to move a partial redundancy, then it is moved to a basic block preceding the definition of its .phi.-function. In general, an expression that is marked as partially redundant may be moved if: the partially redundant expression dominates one of its source operands, as shown in Example (a) of Table N below; or the .phi.-function below the partially redundant expression has all source operands receiving the same value number, as shown in Example (c) of Table N below. After the partially redundant expression is moved upwards, it may still be partially redundant as shown in Example (b) of Table N below. The search repeats until the partially redundant expression is hoisted to a basic block which causes no redundancy. Additional .phi.-functions for temporaries may be created after expressions are moved. This is shown in Table T.
TABLE N
__________________________________________________________________________
Examples of partial redundancy
__________________________________________________________________________
Example (a):
if ( ) then .fwdarw. if ( ) then
t1 = p .fwdarw. q .fwdarw. x;
t1 = p .fwdarw. q .fwdarw. x;
else . . . ; else t3 = p .fwdarw. q .fwdarw. x;
t2 = .phi.(t0, t1) t2 = .phi.(t3, t1)y
t3 = p .fwdarw. q .fwdarw. x;
= t2;
Example (b):
##STR7##
Example (c):
if ( ) t = x + y;
if ( ) z = x + y;
else w = x + y;
This partial redundancy cannot be removed
Example (d):
if ( ) then
= p .fwdarw. q .fwdarw. x;
if ( ) then
= p .fwdarw. q .fwdarw. x;
__________________________________________________________________________
Referring now to FIG. 9, operations preferred in carrying out the Moving Partial Redundancies 900 portion of the present invention are illustrated. The process begins at process block 905. Thereafter, process block 910 begins a loop for each partially redundant expression. Thereafter, decision block 915 determines if the partially redundant expression dominates one of its source operands. If the partially redundant expression dominates one of its source operands, then process block 920 moves the partially redundant expression to a block preceding the definition of its .phi.-function. Thereafter, decision block 925 determines if the moved partially redundant expression is still partially redundant in its new location. If the moved partially redundant expression is still partially redundant in its new location, then processing loops back to decision block 915 to reprocess the still partially redundant expression. Returning now to decision block 915, if the partially redundant expression does not dominate one of its source operands, then decision block 930 determines if a .phi.-function below the partially redundant expression has all source operands receiving the same value number. If a .phi.-function below the partially redundant expression has all source operands receiving the same value number, then processing continues to process block 920 to move the partially redundant expression to a block preceding the definition of its .phi.-function. Returning now to decision block 930, if there is no .phi.-function below the partially redundant expression having all source operands receiving the same value number, then process block 935 determines if there is a remaining partially redundant expression. If there is a remaining partially redundant expression, then processing loops back to process block 910 to process the next partially redundant expression. Returning now to decision block 925, if the moved partially redundant expression is not partially redundant in its new location, then processing continues to decision block 935 to determine if there is a remaining partially redundant expression. Returning now to decision block 935, if there is no remaining partially redundant expression to be processed, then the process ends at process block 940. Hash Table The Hash Table holds entries of expressions. An example of a Hash Table 600 and its associated tables are shown in FIG. 6. HashLinks 605 is the table in which the keys are initially hashed. Each entry 610 contains an index to the Hash table 600. Hash Table records 615 are assigned sequentially. HashLinks indexes 620 are used wherever the keys are hashed. In general, the HashLinks index 620 to the Hash Table 600 equals to mod(valuenum, hash.sub.-- table.sub.-- size). Since Hash Table records 615 can be reused after garbage collection, in order to assure unique value numbers, the same value number cannot be used again the next time that record is reused. To assure this, the value number is incremented by deletion.sub.-- counter * hash.sub.-- table.sub.-- size. The deletion.sub.-- counter 625 shows how many times a Hash Table record is reused after garbage collection. A stack is used to hold entries of Hash Table records that are freed after garbage collection. The original names before the SSA renaming is also hashed. An entry, say x+y, points to a link list that has the text pointers for x0+y0, x1+y0, etc. The variants can be removed at the exit of a loop. Some expressions may evaluate to a text that does not exist. For an example of this, see x1+y0 in Table R. The Hash key, constructed primarily of the opcode and the operands, is stored instead of the text pointer. Each Hash Table record may contain the following fields: Text 630 containing the text of an expression; FakeUse 635 indicating which definition reaches the expression; VNL 640 holding the Value Number List of an expression; FakeLHS 645 which is a work field for the construction and renaming of a temporary expression. Interblock temporaries are created at the end when redundancies are found. Basic block pointer 650; Statement pointer 655; Text pointer or constructed Hash Key 660; Deletion counter 625; and NextLink 665 which points to the next record for items that have collisions. A Hash Table dictionary 670 holds an array of value numbers corresponding to each name used. Temporarys 675 are created to hold expressions for redundancy checking. The pointer (p) 680 to the linklist 685 is copied from the Hash Table 600 to the dictionary 670 when the temporary 675 is created. Referring now to Table P through Table U, various scenarios showing the practice of the present invention are shown. Table P shows the present invention identifying and removing a redundant expression. Table Q and Table R show the present invention identifying and moving a partially redundant expression. Table S shows the present invention identifying and moving a partially redundant expression up one basic block, after which the expression is still partially redundant at the moved location, and after which the expression is moved up one additional basic block. Table T shows a scenario in which the prior art fails to handle redundancies and partial redundancies, but in which the present invention identifies and moves a partial redundancy, and further identifies and removes a redundancy. Table U shows the application of the present invention to a sample program from the prior art, Rosen et al.
TABLE P
______________________________________
An example identifying and removing a redundant expression
______________________________________
a. Input in SSA form: ==>
b. Assign value number ==>
Value
Number
= x0 + y0 = x0 + y0 9
do i = 1, 10 do i = 1, 10
x1 = .phi.(x0, x2)
x1 = .phi.(x0, x2)
10, 11
= x1 + y0 = x1 + y0 9, 12
x2 = x2 = 11
x2 + y0 = x2 + y0 12
end end
c. Insert .phi.-functions for ==>
d. Rename variables ==>
expressions in same value
number set {9, 12}
= t = t0
t = x0 + y0 t1 = x0 + y0
do i = 1, 10 do i = 1, 10
t = .phi.(t, t)
t2 = .phi.(t1, t4)
x1 = .phi.(x0, x2)
x1 = .phi.(x0, x2)
= t = t2
t = x1 + y0 t3 = x1 + y0
x2 = x2 =
= t = t3
t = x2 + y0 t4 = x2 + y0
end end
e. Determines full and =>
f. Clean up links
partial redundancy ! removed
= t0
t2 = x0 + y0 t1 = x0 + y0
do i = 1, 10 do i = 1, 10
t2 = .phi.(t1, t4)
t2 = .phi.(t1, t4)
x1 = .phi.(x0, x2)
x1 = .phi.(x0, x2)
= t2
t3 = x1 + y0 ! Redundant
= t2
x2 = x2 =
= t3
t4 = x2 + y0 t4 = x2 + y0
end end
______________________________________
c. Assign value numbers
______________________________________
do forever Value Numbers
A2 = .phi.(A1, A4)
14 = 1, 15
D2 = .phi.(D1, D4)
19 = 4, 18
L2 = .phi.(L1, L5)
(5, 10)
M2 = .phi.(M1, M4)
13 = 6, 14
S2 = .phi.(S1, S4)
21 = 7, 22
T2 = .phi.(T1, T4)
23 = 8, 25
if ( ) { L3 = C1 * B1
10 = 3*2 *1
M3 = L3 + 4 11 = 10*94
A3 = C1} 3 = 3
else { D3 = C1 3 = 3
L4 = D3 * B1 10 = 3*2 *1
S3 = A2 * B1 20 = 14*2
T3 = S3 + 1 } 24 = 20 + 91
A4 = .phi.(A3, A2)
15 = 3, 14
D4 = .phi.(D2, D3)
18 = 19, 3
L5 = .phi.(L3, L4)
10 = 10, 10
M4 = .phi.(M3, M2)
14 = 11, 13
S4 = .phi.(S2, S3)
22 = 21, 20
T4 = .phi.(T2, T3)
25 = 23, 24
X1 = A4 * B1 16 = 15*2
Y1 = X1 + 1 17 = +91
enddo
______________________________________
Note: the partial redundancy for X1 and Y1 will not be attempted to be discovered here (at least initially) because A is modified. If A is not modified in the loop, then it could be found here. All the .phi.-functions here, except that of L, are involved in a recursive definitions. Unique values are assigned to the target. d. Insert .phi.-functions for expressions in same value number set & rename variables ##EQU1## e. Determines redundancy (RD) and partial redundancy (PR) ##EQU2## f. Moves invariants or partial redundancy up. Remove spurious .phi.-functions. ##EQU3## The other two partial redundancies, M3 & D3, cannot be moved due to safe conditions--it is not anticapable in all paths. Referring now to FIG. 10, a block diagram illustrates a computer system 1000 used in performing the method of the present invention, forming part of the apparatus of the present invention, and which may use the article of manufacture comprising a computer-readable storage medium having a computer program embodied in said medium which may cause the computer system to practice the present invention. The computer system 1000 includes a processor 1002, which includes a central processing unit (CPU) 1004, and a memory 1006. Additional memory, in the form of a hard disk file storage 1008 and a computer-readable storage device 1010, is connected to the processor 1002. Computer-readable storage device 1010 receives a computer-readable storage medium 1012 having a computer program embodied in said medium which may cause the computer system to implement the present invention in the computer system 1000. The computer system 1000 includes user interface hardware, including a mouse 1014 and a keyboard 1016 for allowing user input to the processor 1002 and a display 1018 for presenting visual data to the user. The computer system may also include a printer 1020. Although the present invention has been particularly shown and described with reference to a preferred embodiment, it will be understood by those skilled in the art that various changes in form and detail may be made without departing from the spirit and the scope of the invention.
|
Same subclass Same class Consider this |
||||||||||
