Optimizing cobol object code instruction path length with respect to perform statements4567574Abstract A method for optimizing instruction path lengths in a compilation of COBOL source code with reference to PERFORM statements requires a two-step procedure in which the control transfer relationship among the PERFORM statements and associated procedures is characterized as a vector of attributes, and a second step in which the vectors are interpreted for any given PERFORM statement such that, where indicated, the code of the procedure or simplified linkage code will be substituted for the PERFORM statement. Claims We claim: Description TECHNICAL FIELD
TABLE 1
______________________________________
FORMAT 1 PERFORM LINKAGE MECHANISM
GENERATED
SOURCE LANGUAGE LINKAGE MECHANISM
______________________________________
1 PERFORM P1
THRU P2 MVC PFSV,VN
2 LA R,GNret
3 ST R,VN
4 B P1
5 GNret EQU *
6 MVC VN,PFSV
7 P0 . . . PO EQU *
8 . . .
9 P1 . . . P1 EQU *
10 . . .
11 P2 . . . P2 EQU *
12 . . .
13 L R,VN
14 BR R
15 P3 . . . P3 EQU *
16 . . .
17 PFSV DS AL4
18 VN DC A(P3)
______________________________________
In the Tables, System/370 instructions used include move character (MVC) load address (LA), store (ST), branch (B), equate (EQU), load (L), branch register (BR), define storage (DS), define constant (DC), branch and link (BAL), and branch and link register (BALR). The function and purpose of the linkage mechanism of Table 1 is as follows. At line 1, the current value of the variable name cell (VN) is saved in a PERFORM save cell (PFSV). This copies the contents of storage defined by line 18 (the VN cell) into storage defined by line 17 (the PERFORM save cell). There is one VN for each procedure name appearing as the last or only procedure name of a PERFORM statement, which in this case is P2. There is one PERFORM save cell for each PERFORM statement in the source language program, which in this case is the PERFORM at line 1. The VN is initialized to point to the statement immediately following the last statement of the PERFORMed procedure. In Table 1, the VN initially points to the statement at P3 (line 15). Thus, if the last statement of the PERFORMed procedure at P2 can be reached (such as by GO TO or fall through), without having explicitly set the VN, control will simply pass to the next sequential statement at P3. In Table 1, lines 13 and 14 constitute the PERFORM return, and line 18, the VN. This save and restore mechanism also permits two different PERFORM statements to share the same VN, even when one of the PERFORM statements is a part of the other's PERFORMed procedure. The subsequent PERFORM statement saves and restores the VN value that the earlier PERFORM statement has set. At lines 2 and 3 of Table 1, the value of the VN is set so that after the last statement of the PERFORMed procedure P1, P2 has been executed, control will return to the instruction after the label "GNret". At line 4, control is transferred to the first statement of the PERFORMed procedure at P1. Lines 5-6 are the PERFORM epilogue. The value of VN, saved at the earlier MVC (line 1), is restored to what it was before the PERFORM statement was executed (the address of statement P3). At lines 13 and 14, following execution of the procedure P1,P2, control is returned to the epilogue (line 5) of the PERFORM statement, where the original value of the VN will be restored. Pursuant to the invention, under some circumstances, not one of the linkage instruction in Table 1 is required. In accordance with the invention, the special cases in which optimized linkages can be used in connection with compiled PERFORM statements or procedures are represented in terms of four Boolean variables: MOVE, COPY, SAVE, and Branch-and-link (BAL). Each such Boolean variable can take the values YES or NO. The initial settings are MOVE is YES, COPY is YES, BAL is YES, and SAVE is NO. There is one set of these Boolean variables for each PERFORM statement in the program. The circumstances under which MOVE, COPY, and BAL remain set to YES, and SAVE to NO, as well as the transformations that can then be made, will next be summarized. Move remains set to YES if a procedure is PERFORMed by only the single PERFORM statement, and there is no way that control can pass to the procedure other than be executing this PERFORM statement. Under these conditions, the PERFORM statement can be completely replaced by the (no longer) PERFORMed procedure. This transformation is referred to as "procedure integration". The procedure is deleted from its original position. Copy remains set to YES for each of several PERFORM statements whose common PERFORMed procedure contains no compiler-generated or user-provided labels, and is not too large. Under these conditions, the PERFORM statements can be completely replaced by copies of the (no longer) PERFORMed procedure. If there is no way that control can pass to the procedure, other than by executing one of these PERFORM statements, the procedure is deleted from its original position. Otherwise, a copy of the procedure must remain at its original position. SAVE remains set to NO for a given PERFORM statement if both (1) control can not fall through the last statement of its PERFORMed procedure to the statement immediately following the PERFORMed procedure; and (2) there is not another PERFORM statement whose PERFORMed procedure has the same last statement as that of the given PERFORM statement (also referred to as having the same end of range), such that control can pass from either PERFORM statement to the other without first passing to this last statement. Under these circumstances the value of the VN does not have to be saved and restored. BAL remains set to YES if the interconnections between the given PERFORM statement and any other PERFORM statements permit the BAL linkage to be used in place of the standard linkage. This will be further described hereinafter. At its best, this involves only a single instruction at the PERFORM statement and another at the end of the PERFORMed procedure. With a group of nested PERFORMed procedures, only the innermost procedure can use this short-form linkage. In Tables 2-6, code sequences for each PERFORM format are illustrated for the valid combinations of Boolean variables which can be detected. In these tables, RL denotes the linkage register, the usual choice for which in System/370 architecture is register 15. Table 2 illustrates Type O optimized linkage, or procedure integration. This is the result when MOVE or COPY is YES. SAVE and BAL may be anything. There are no instructions in Table 2, and thus is the most efficient. Procedures P1 and P2 are copied into the location of the PERFORM and deleted from their previous position in the text stream. Table 3 illustrates Type 1 optimized linkage. MOVE and COPY are NO, and BAL is YES, and SAVE is NO. In table 3, two instructions do what standard linkage requires seven instructions to do. Table 4 illustrates Type 2 optimized linkage. MOVE and COPY are NO, and BAL is NO, and SAVE is NO. This linkage type eliminates the two expensive MVC instructions from the standard linkage. Table 5 illustrates Type 3 optimized linkage. MOVE and COPY are NO, and BAL is YES, and SAVE is YES. In this linkage type, the two expensive MVC instructions of the standard linkage are eliminated at the cost of a relatively efficient (or cheap) ST instruction. Table 6 illustrates standard linkage. MOVE and COPY are NO, and BAL is NO, and SAVE is YES. In each of Tables 1-6, P0, P1, P2, P3, represent labels in the code, and the ellipses (. . . ) represent some sequence of code statements.
TABLE 2
______________________________________
TYPE O OPTIMIZED LINKAGE
(PROCEDURE INTEGRATION)
SOURCE GENERATED LINKAGE
LANGUAGE MECHANISM
______________________________________
PERFORM P1
THRU P2 P1 EQU *
. . .
P2 EQU *
. . .
P0 . . . P0 EQU *
. . .
P1 . . .
P2 . . .
P3 . . . P3 EQU *
. . .
______________________________________
According to the invention, PERFORM optimization comprises PERFORM analysis (FIG. 8), followed by PERFORM transformation, which is a response to the quantities determined during PERFORM analysis. PERFORM transformation includes PERFORM statement transformation (FIG. 3) and PERFORM return transformation (FIG. 4). During a previous phase of the compiler, as will be described hereafter in connection with Tables 9-12, all relevant data structures have been allocated and initialized. Before proceding with a description of the procedure of the invention, an example will be given of a simple COBOL program and of a preferred embodiment of the above mentioned relevant data structures used to describe the structure and characteristics of that program. Referring to FIG. 1, COBOL program 10 includes a PERFORM statement at A, followed by STOP RUN, and a MOVE statement at B. This sequence of statements is divided into three basic blocks L 12, M 14, and N 16. Each of these basic blocks may be considered a node of a control flow graph, having edges X 22 and Y 24 connecting the nodes as will be further described in connection with FIG. 2. Referring now to FIG. 2, in which all the field entries are shown in hexadecimal, basic blocks L, M, and N are illustrated at 42, 44, and 46, respectively, and are represented by entries 41, 43, 45, 47, 48, and 49 in Basic Block Descriptor (BBD) table 40, which includes the pointers or indexes from the BBD entries to the other data structures 70 and 60 illustrated. A description will now be given of the Basic Block Descriptor (BBD) Table 40. This table includes a plurality of fixed-length entries 41, 43, 45, 47-49. Each node of the control flow graph for the program being compiled is represented by one or more BBD Table 40 entries. For example, basic block L 42 is described by entries 41, 43 and 45. The edges X and Y of the graph, which represent transfers of control from one node to another, are described by information in auxiliary tables 60 and 70, to be described hereafter. A BBD entry 41, . . . , 49 contains information about the basic block (node) This information, set forth in Table 13 in greater detail, includes (1) a plurality of flag bits TBBGFLGS 606 and TBBPFLGS 618 which are the repository for control flow information that the optimizer discovers during its analysis; (2) a text counter field TBBTXCTR 638 contains the number of instructions in the block, and is used during PERFORM optimization to decide whether a PERFORMed range is sufficiently small to be copied in line; (3) the number of predecessors TBBNUMPR 640 of (paths by which control can reach) the BBD; and (4) information TBBSCSOR 642 about any successors of (that is, BBDs which can be reached from) this BBD. The Perform Descriptor Table (PDT) 60 is built by a control flow graph construction module for use by the PERFORM analysis procedure. There are as many fixed-length entries 72 as there are PERFORM statements, whether in the source program or generated by the compiler. A PERFORM descriptor table 60 entry 72 contains a variety of information about a given PERFORM statement and its environment, including (1) pointer TPFBBDPT 702 to the PERFORM header BBD 41, the BBD corresponding with the start of the PERFORM statement; (2) pointer TPFREPTR 62 to the PERFORM procedure integration point BBD 43, the BBD after which the PERFORMed procedure can be inserted if procedure integration optimization is to be done; (3) pointer TPFSORPT 704 to the start-of-range BBD 45 which describes the statement to which control is passed from the PERFORM statement; (4) pointer TPFVNPTR 706 to the end of range VN 75, the VN Header Table 70 entry for the PERFORM return 49 at the end of the PERFORMed procedure; and (5) pointer TPFGNPTR 64 to the PERFORM EPILOGUE 47. When a given PERFORM is called by other PERFORMs, TPFCLDBY 66 denotes a list of these calling PERFORMs (not shown in FIG. 2). The flag bytes 712-732 and TPFRNGSZ (range size) 68 of PDT 60 are used to record the information discovered during PERFORM analysis and then acted on by PERFORM optimization. Table 14 sets forth the contents of the PERFORM Description Table. The Variable Name (VN) Table 70 will next be described. The VN mechanism is used, among other things, for the return to a PERFORM statement at the end of its PERFORMed procedure. A VN is illustrated at line 18 of Table 1. VNs are allocated in the dynamic storage for a COBOL program, for example. PERFORM statements set the VN values (see Table 1, lines 2 and 3), which are then acted on by PERFORM returns, as is illustrated in Table 1 lines 13 and 14. Thus, the VN tables are used as an edge representation in the control flow graph. VN Table 70 has as many entries 75 as there are VNs (in this example, one), and points (88) to the BBD 49 that terminates with a PERFORM return. Entries for a given VN are distributed through the table, connected by the link fields 76, 78. The link field 78 of the last entry in the list is zero. Table 15 sets forth the format of the VN Table. Referring further to FIG. 2 in connection with FIG. 1, a description will be given of the two edges X and Y. Edge X is implemented as follows. BBD entry PERFORM SOR 45 includes a pointer 76 to PD Table entry 72, which in turn includes a pointer TPFSORPT 704 represented by line 89 to start of range BBD Table 40 entry 49, labeled MOVE. Edge Y is implemented as follows. BBD Table 40 entry 49 (MOVE), in this example, is the end of range as well as the start of range of the PERFORM, and includes a pointer TBBSCSOR 642, represented by line 73, to VNT 70 entry VN HEADER 75. VN HEADER 75 includes a pointer TVNLSTHD 758, represented by line 79, to a corresponding VN TARGET entry, which in turn includes a pointer TVNPNPFM 762, represented by line 85, to PDT 60 entry 72. This PDT 60 entry 72 finally includes a pointer TPFGNPTR 64, represented by line 94, to the PERFORM EPILOG (BBD Table 40 entry 47). This completes the representation of edge Y. All other lines, 77, 83, 88, 92, 93, do not denote control flow but are provided for relating the information in the data structures represented by tables 40, 60, and 70. Referring to FIG. 3, a description will be given of PERFORM statement transformation for a given PERFORM statement having the MOVE, COPY, BAL, and SAVE characterization in its PDT 60 entry. In steps 802 and 804, responsive to MOVE being yes, the PERFORM statement is completely replaced by its PERFORMed procedure (procedure integration), and the PERFORMed procedure is deleted from its original position in the source program. In steps 806 and 808, responsive to COPY being yes, procedure integration is performed. In steps 810, 812, if the delete flag is set to yes in the start-of-range BBD (for example, BBD 49 in FIG. 2), then the PERFORMed procedure is deleted from its original position in the source program. In steps 814 and 816, responsive to BAL being yes and SAVE being no, type 1 optimized linkage is generated, similar to that illustrated in Table 3. In steps 818 and 820, responsive to BAL being no and SAVE being no, type 2 optimized linkage is generated, similar to that illustrated in Table 4. In steps 822 and 824, responsive to BAL bing yes and SAVE being yes, type 3 optimized linkage is generated, similar to that illustrated in Table 5. In step 826, where BAL is no and SAVE is yes, the standard, or not optimized, linkage is generated, similar to that illustrated in Table 6. Referring now to FIG. 4, a description of PERFORM return transformation will be be given. This phase responds to the end-of-range flag TBBPFEOR in the BBD table 40 entry for the PERFORM return being transformed (such as statement 49 in FIG. 2), and to the LOAD flag TVNHFLOD and BALR flag TVNHFBAL characterization found in the VN Table 70 TVNHFLGS field for VN header entry (such as statement 75 in FIG. 2). In step 840 the end-of-range flag bit is tested. Only if it is on is this PERFORM return truly an end-of-range. If it is not, in step 842 a PERFORM return is not generated. In this embodiment, this is accomplished by deleting the PERFORM return that the compiler had previously inserted at the end-of-range. If this PERFORM return is truly and end-of-range, then in steps 844 and 846, responsive to LOAD being yes, PERFORM return instructions common to type 2 and standard linkages are generated, similar to that illustrated in Tables 4 and 6 (L and BR). In steps 848 and 850, responsive to BALR being no (and LOAD being no, step 844), optimized PERFORM return instructions for type 1 linkage are generated, similar to that illustrated in Table 3. Otherwise (LOAD being no, BALR being yes), in step 852 optimized PERFORM return instructions for type 3 linkage are generated, similar to that illustrated in Table 5. PERFORM analysis (Table 9) determines the environment of each PERFORM statement and PERFORMed procedure in the source program, and comprises the steps of (1) PERFORM exploration (FIG. 9, lines 102-254) and (2) PERFORM linkage assignment (FIG. 13, lines 260-246). Initially, every PERFORM statement in the program is characterized by optimistic settings of the Boolean quantities: MOVE is YES, and COPY is YES, and BAL is YES, and SAVE is NO. This characterization implies that each PERFORM can be optimized by procedure integration, which is the most effective transformation. As PERFORM analysis is executed against the program, and discovers circumstances that are in conflict with this characterization, it changes these optimistic initial settings of the Boolean quantities, which may deteriorate toward: MOVE is NO, and COPY is NO, and BAL is NO, and SAVE is YES. These latter settings characterize the standard linkage mechanism. Because initialization of the data structures is done by setting them to binary zeros, which in the case of flags is interpreted as NO, the MOVE, COPY, and BAL characterizations are implemented in the preferred embodiment by negative logic. For example, the optimistic setting MOVE is YES becomes NO-MOVE is NO (TPFFLNMV 726) in the preferred embodiment described in Tables 9-15. A description will now be given of PERFORM exploration. For each reachable PERFORM statement in the program being compiled, referred to as the current PERFORM, a depth-first search of the control flow graph is pursued from the first basic block in the PERFORMed procedure. This first block of the procedure is referred to as the "start of range". The last basic block in the PERFORMed procedure is known as the "end of range", and is regarded as having no successors. As is described in Table 10, depth-first search is a strategy for exploring a graph, whereby, so long as there are unexplored successors of a node, the frontier of the search is extended to these successors. A node is visited only when all of its successors have already been visited. Implementation of the search uses the stack described in FIG. 5, including fields DFSNXSUC 860 and DFSBBDPT 862. Field 860 is a pointer to a BBD from which the search is to be pursued, and field 862 is an indicator of which of this BBD's successors should be explored next. The search begins at step 170 by pushing onto the search stack (FIG. 5) an entry for the start-of-range BBD. The search progresses at line 431 by selecting the BBD 40 denoted by the topmost stack entry. If the BBD still has an unvisited successor, CSUCCPTR is non-null at line 432, and an entry for this successor is pushed onto the stack to become the new topmost entry. For each successor, whether visited or not, the Successor-action procedure of Table 11 is called. If all of the successors of the BBD have already been visited, then the BBD is itself visited, by calling the POP-action procedure of Table 12. After the BBD has been visited, its entry is popped from the stack. The search continues in this way until the stack is empty. During the exploration for a given PERFORM STATEMENT, the flow of control from any PERFORM statements that are incountered is ignored. These encountered PERFORM statements are referred to as reached, or called, PERFORMs. For example, referring to FIG. 7, the physical range 888 of current PERFORM 880, is defined by the contiguous sequence of statement beginning with start of range SOR 882 and ending with end of range EOR 886. While the true successor of reached PERFORM statement 884 is its start of range, exploration for current PERFORM 880 assumes that the successor is the epilogue of PERFORM 884, thus effectively assuming the successful execution of the PERFORMed procedure of the reached PERFORM 884. This assumption is implemented by procedure step 432. The linear sequence of statements from the first in the PERFORMed procedure to the last is referred to as the "physical range" of the PERFORM statement, as is illustrated by FIG. 7. The actual range of a PERFORMed procedure may include statements outside the physical range, since control can validly pass outside the limits of the physical range. If control can pass to the current PERFORM statement from another PERFORM statement without first passing to the epilogue of the other PERFORM, the current PERFORM statement is said to be "called" by the other PERFORM. The end of range basic block for a PERFORM statement Q that cannot call the current PERFORM is regarded as having only a single successor (the fall-through successor): the basic block that immediately follows Q's end of range basic block. The end of range basic block for a PERFORM statement R that can call the current PERFORM is regarded as having two successors: (1) the basic block that immediately follows R's end of range basic block, and (2) the basic block representing R's epilogue, to which control passes after the last statement in R's PERFORMed procedure has been executed. If, during the exploration of steps 128-250 for the current PERFORM statement, another PERFORM statement is encountered at step 522, the exploration does not immediately follow the flow of control from this called PERFORM. Instead, at steps 538-552 the linkage between the two PERFORM statements is recorded, and the other PERFORM is marked to be explored, or to be explored again if it has already been explored. A PERFORM may be explored again because it may reach more than before due to the extra successor of the calling PERFORM statement's end of range. As PERFORM exploration progresses, the following events are recorded. First, at steps 480-482 if control can fall through a basic block, this is noted in the basic block descriptor field TBBPFDOU. Second, at steps 484-486 if the path by which the basic block was reached is being traversed for the first time, the "predecessor count" field TBBNUMPR in the block descriptor is incremented. Third, at steps 488-496 if the basic block represents the start of range of a PERFORM statement, then the basic block descriptor is marked so that the range will not be deleted from its original position. If the block is the start of range for the current PERFORM, then the current PERFORM descriptor is marked COPY is NO. Fourth, at step 506 the number of instructions in the basic block is added to the range size field TPFRNGSZ in the current PERFORM descriptor. Fifth, at steps 508-512 if the basic block contains a label and is not the start of range of the current PERFORM, then the current PERFORM descriptor is marked COPY is NO in field TPFFLNCP, because the program cannot contain duplicate labels. Sixth, at steps 514-516, if the counter register (used in format 2 PERFORMs) is modified in the basic block, then the current PERFORM descriptor is marked in field TPFFLSVC to show that the contents of the counter register cannot be relied on across execution of the PERFORMed procedure. Seventh, at steps 518-520, if the linkage register RL is modified in the basic block, then the current PERFORM descriptor is marked in field TPFFLSVL to show that the contents of the linkage register cannot be relied on across execution of the PERFORMed procedure. Eighth, at steps 522, 532-534, if the basic block represents the current PERFORM STATEMENT, then there is a potential loop in PERFORM control flow. The subsequent process of PERFORM linkage assignment of steps 260-426 requires that the flow graph representing the calling relation between PERFORM statements be cycle free, so at step 218 an error message is given. Although PERFORM exploration of steps 128-250 continues, PERFORM linkage assignment is not done. Ninth, at steps 522, 536, if the basic block represents a PERFORM statement other than the current PERFORM, then at steps 538-552 the link between the two PERFORM statements is added to the PERFORM called-by list, described hereafter, of the other PERFORM descriptor. The other PERFORM is marked to be explored, or to be explored again if it has already been explored. Tenth, at steps 560-562, if the basic block represents an EXIT PROGRAM or GO BACK statement, then there is a potential loop in PERFORM control flow, so at step 230 an error message is given. Although PERFORM exploration continues, PERFORM linkage assignment is not done. Eleventh, at steps 564-566, if the basic block is the end of range of the current PERFORM, then at step 568 a flag reached-exit is set to yes to show that the current PERFORM can reach its exit. This reached-exit flag is tested at step 206, an error message is given at step 208 if reached-exit is no. Twelfth, if the basic block is the end of range of another PERFORM statement, then the current PERFORM descriptor is marked to show that the contents of the linkage register cannot be relied on across execution of the PERFORMed procedure. This is done in case the linkage mechanism adopted by the other PERFORM statement involves the linkage register. Finally, if the basic block lies outside the physical range of the PERFORMed procedure, in steps 578-580 the current PERFORM descriptor is marked MOVE is NO in field TPFFLNMV and COPY is NO in field TPFFLNCP. At the end of the exploration for the current PERFORM statement, in steps 176-190 each basic block in the physical range of the PERFORMed procedure is examined. If any of these basic blocks contains a label, but was not visited during the search, in steps 184-186 the current PERFORM descriptor is marked MOVE is NO in field TPFFLNMV and COPY is NO in field TPFFLNCP. This is done because failure to visit every block of a PERFORMed procedure is evidence of complicated control flow. Such cases are not considered worth the effort of optimizing by procedure integration. A description will now be given of PERFORM linkage assignment, set forth in steps 260-426 consisting of PERFORM statement linkage assignment at step 260-372, followed by PERFORM return linkage assignment at steps 374-426. PERFORM statement linkage assignment starts at steps 260-320 by determining the linkage for the current PERFORM statement. Then during linkage propagation steps 322-358 each PERFORM statement that can call the current PERFORM statement, directly or indirectly, is informed of the linkage decisions that were made for the current PERFORM, so that its own linkage decisions can be made properly. A breadth-first search is a strategy for exploring a graph familiar to those skilled in the art of computer science, and is described by Narsingh Deo, "Graph Theory with Applications to Engineering and Computer Science", Prentice-Hall, N.J., 1974, at pages 301-302. PERFORM statements are processed in breadth-first order with respect to the called-by graph determined at steps 538-552 during the preceding PERFORM exploration. The called-by graph is a directed, acyclic graph such that if a PERFORM statement can be called directly by another PERFORM statement, there is an edge in the called-by graph going from the node representing the called PERFORM statement to the node representing the calling PERFORM statement. A given node has a successor if its corresponding PERFORM statement can be called by another PERFORM. The graph is guaranteed to be cycle free. If at step 532 PERFORM exploration detects a cycle, PERFORM linkage assignment does not process the graph. The first PERFORM statements to be assigned linkages are those that cannot call any other PERFORM statements. By the cycle-free property, there is guaranteed to be at least one. These PERFORM statements may be called by other PERFORM statements. If so, at steps 260-320 any decisions about the linkages of the called PERFORM statements are made before assigning the linkage of the calling PERFORM statements. This is because the linkage of the calling PERFORM statements may be affected by the linkage characteristics of any PERFORM statements that can be called. The breadth-first ordering on the called-by graph ensures this property. During PERFORM STATEMENT linkage determination at steps 260-320, the context of the current PERFORM, discovered by the preceding PERFORM exploration, is examined to determine the appropriate linkage mechanism, as follows: First, at steps 272-274 if control can fall through to the start of range from the basic block preceding it, or if the start of range is the first basic block in the program, the current PERFORM descriptor is marked MOVE is NO. In general, if control can fall into or fall out of a procedure, then a copy of the procedure must remain at its original location. In effect, the procedure may be locked at either end in this way. Second, at steps 276-278 if the number of instructions in the current PERFORMed procedure is larger than an implementation-defined limit, then the current PERFORM descriptor is marked COPY is NO. Third, at steps 280-288 if control can fall through the end of range basic block of the current PERFORM, then the current PERFORM descriptor is marked MOVE is NO and SAVE is YES. Fourth, at steps 290-292, if the current PERFORM descriptor is marked SAVE is NO but the linkage register must be saved, then the current PERFORM descriptor is marked BAL is NO. Type 0 optimized linkage cannot be used because it depends on the linkage register. Type 2 optimized linkage (BAL is NO, and SAVE is NO) has one fewer instructions than type 3 optimized linkage (BAL is YES, and SAVE is NO). Fifth, at steps 294-296, if the basic block representing the current start of range has more than one predecessor, the current PERFORM descriptor is marked MOVE is NO. Finally, at steps 298-300, if any PERFORM that can call the current PERFORM, directly of indirectly, has the same end of range as the current PERFORM, and if the current PERFORM descriptor is marked MOVE is NO and COPY is NO and either SAVE is NO or BAL is YES (that is if procedure integration would not be done and the linkage would be anything other than the standard linkage), then the current PERFORM descriptor is marked SAVE is YES in field TPFFLSVV and BAL is NO in field TPFFLNBL. This means that nested PERFORM procedures with the same end of range executed by PERFORM statements, one of which calls the other, do not get the most efficient linkage, but are forced to use the VN mechanism instead. During linkage propagation of steps 298-300, 328-332, the first propagation is for every PERFORM statement in the transitive closure of the called-by relation of the current PERFORM statement. Referring to FIG. 6, the transitive closure 878 of the called-by relation of PERFORM statement 876 includes PERFORM statements 870, 872, and 874: every PERFORM that can call the current PERFORM, directly (872 and 874) or indirectly (870). The calling PERFORM descriptor is marked in field TPFFLAGS to show that the PERFORM linkage register should be saved if the current PERFORM descriptor is marked to show (1) that the PERFORM linkage register should be saved, or (2) that the BAL form of linkage, which involves the linkage register, can be used (MOVE is NO and COPY is NO and BAL is YES). At steps 338-358, the final propagation is done for every PERFORM statement that has the same end of range as the current PERFORM statement, regardless of whether or not it can call the current PERFORM statement. If the current PERFORM has been assigned one of the forms of linkage that use the VN mechanism (MOVE is NO and COPY is NO and either SAVE is YES or BAL is NO), then at step 348 the descriptors of fields TPFFLNBL for every other PERFORM statement with the same VN are marked BAL is NO, to make sure that they also use one of the VN-based linkages. If the current PERFORM is to be optimized by procedure integration, and the PERFORMed procedure is to be deleted from its original position, then in step 356 the descriptors for every other PERFORM statement with the same VN are marked in field TPFFLSVV SAVE is YES. The value of the VN must be saved by these other PERFORM statements since control can now fall through the end of range of their PERFORM procedures due to the procedure integration. PERFORM return linkage assignment will now be described. All end-of-range BBDs (such as BBD Table 40 entry 47 of FIG. 2) are initialized with TBBPFEOR 626 (of Table 13) set to NO. This implies that no PERFORM instructins will be generated, on the assumption that procedure integration will be done. All VN Header Table entries, for instance entry 75 in FIG. 2, are initialized to LOAD is NO (TVNHFLOD 754 of Table 15) and BALR is NO (TVNFLBAL 756 of Table 15). These setting simply that if any PERFORM return instructions will be generated (TBBPFEOR of the end-of-range BBD is YES), then the most optimal form of PERFORM return, as used in type 1 linkage Table 3, will be generated. As PERFORM return linkage assignment progresses, these initial optimistic settings may deteriorate toward TBBPFEOR is YES, LOAD is YES, and BALR is YES. These settings cause the standard linkage return mechanism, also used in type 2 linkage Table 4, to be generated. During PERFORM return linkage assignment steps 374-426, for each unique PERFORM end of range, the context of every PERFORM statement that has this end-of-range is examined to determine the appropriate PERFORM return linkage mechanism. At step 398, if all of these PERFORMs will be optimized by procedure integration (MOVE is YES or COPY is YES), then no PERFORM return instructions are generated. Otherwise, if any of these PERFORMs will not be optimized by procedure integration (MOVE is NO and COPY is NO), the TBBPFEOR flag is set at step 388, causing some PERFORM return instruction to be generated. The type of PERFORM return linkage generated depends on the SAVE and BAL characterization of the PEFORM statement as follows. If at steps 406-408, any of these PEFORMs cannot use the BAL linkage mechanism (BAL is NO), then the current VN Header Table entry is marked LOAD is YES (TVNHFLOD 754 of Table 15), thereby forcing use of the VN mechanism for the PERFORM return. This kind of PERFORM return is used in type 2 and standard linkage, Tables 4 and 6, respectively. Otherwise, if at steps 410-412, any of these PERFORMs must save the VN value (SAVE is YES), then the current VN Header Table entry is marked BALR is YES (TVNHFBAL 756 of Table 15), which means that the style of PERFORM return used in type 3 linkage Table 5 will be generated. Otherwise, LOAD and BALR remain NO, which causes generation of the optimized PERFORM return, as used in type 1 linkage Table 3. In Table 7 is set forth an example program in COBOL for demonstrating all of the optimized forms of PERFORM linkage, and in Table 8 is set forth the code generated in System/370 assembly language therefrom by PERFORM optimization. The procedure of the invention is set forth in pseudo-code representation in Tables 9-12. As will be apparent to those skilled in the art, the structured psuedo-code representation of the procedure set forth in Tables 9-12 may be coded without undue experimentation into a source language of the programmer's choice, such as Pascal or PL/I, for compilation and execution on a computing system, such as the IBM System/370. While a structured psuedo-code representation clearly sets forth the procedure of the invention to those skilled in the art, to provide a complete source code or object code listing would tend to hide the invention in a prolixity of unnecessary, language-dependent, detail. Throughout these tables, explanatory comments are enclosed in brackets [comment].
TABLE 7
______________________________________
A SAMPLE COBOL PROGRAM
______________________________________
16 I. PERFORM A THRU C.
17 PERFORM B THRU D.
18 PERFORM E THRU F.
19 PERFORM E THRU F.
20 PERFORM G THRU H.
21 STOP RUN.
22 A. ADD X1 TO Y.
23 B. ADD X2 TO Y.
24 C. ADD X3 TO Y.
25 D. ADD X4 TO Y.
26 E. ADD X5 TO Y.
27 F. ADD X6 TO Y.
28 G. ADD X7 TO Y.
29 H. ADD X8 TO Y.
______________________________________
As previously described, the method of the invention comprises a new use for a stored program controlled, digital computer of the type described in U.S. Pat. No. 3,400,371 by G. M. Amdahl, et al, entitled "Data Processing Systems", and in Ibm System/370 Principles of Operation, IBM Publication GA22-7000, the teachings of which are incorporated herein by reference. Such a computing apparatus includes data and program storage areas and registers, and a program execution controller or central processing unit (CPU), which comprise computing resources, the use of which is optimized or improved by use of the method of the invention. The apparatus of the invention includes a stored program controlled digital computer of the type described by Amdahl, et al characterized by the data and control structures described primarily in connection with FIG. 2; also, as characterized by stored program control means operated according to the steps set forth in connection with FIGS. 3-4 and 8-21. While the invention has been described in connection with preferred embodiments, primarily described as an improved feature or version of a compiler such as the IBM COBOL compiler it is not limited to any such specific product. Consequently, the foregoing and other modifications may be made thereto without departing from the spirit and scope of the invention.
|
Same subclass Same class Consider this |
||||||||||
