• Keine Ergebnisse gefunden

SECTION FIVE

Im Dokument FORTRAN FOR (Seite 159-169)

SECTION THREE

SECTION FIVE

Thc following discussion of Section Five i s divided into 4 p a r t s correspond- ing to the division into r e c o r d s on the F o r t r a n s y s t e m tape. In addition, following the description of p a r t s 1 and 4 i s a s u m m a r y of the frequently used subroutines for that part. Following p a r t 4 t h e r e i s a l s o a description of the tables used i n Section Five. Since s o m e of the concepts used a r e a l s o explain-

ed under the headings of the subroutines and tables, the r e a d e r may find i t useful to r e f e r t o them while reading the main text. Also, s e e illustration page VIII

-

12.

P A R T I

Section Five uses the information about basic blocks (which has been passed on f r o m Section F o u r ) to combine these basic blocks into l a r g e r groups called regions. The flow within a region i s simulated i n o r d e r to determine which symbolic tags a r e required and which index r e g i s t e r s should be assigned t o them. During the c o u r s e of simulation, flags a r e s e t t o indicate where a n SXD or LXD is required. When a region has been treated i t m a y be combined with other regions. Eventually a l l b a s i c blocks will have been combined into a single region, and the complete object p r o g r a m will have been treated.

T h c m o s t frequent paths of flow between basic blocks a r e handled f i r s t . Since a n SXD or LXD i s not inserted until n e c e s s a r y , this r e s u l t s i n the m o s t frequent paths having the l e a s t of them, and t h e r e f o r e a f a s t e r object program.

Region Formation

The f i r s t step of this treatment i s the formation of a looplist showing the path of flow through a new region. The starting point i n looplist formation i s the m o s t frequent link between basic blocks which h a s not yet been considered. (The PRED and SUCC tables have frequency counts which a r e examined t o find m o s t frequent p r e d e c e s s o r o r s u c c e s s o r basic blocks. When a link h a s been t r e a t e d , the entry which r e f e r s to i t i s marked with a minus sign s o i t will not be con- sidered again. ) Looplist i s expanded by including a s many of the m o s t frequent unconsidered p r e d e c e s s o r s a s possible and then a s many of the m o s t frequent s u c c e s s o r s a s possible. If the most frequent link i s t a a basic block which is i n a region previously treated, this whole region i s included i n the looplist. Thus a looplist may consist of a combination of untreated basic block and regions (or b a s i c blocks which have already been t r e a t e d ) .

Regions a r e classified a s either opaque o r transparent. An opaque region is one i n which a l l t h r e e index r e g i s t e r s a r e used. A t r a n s p a r e n t region h a s one o r m o r e index r e g i s t e r s s t i l l available. When an opaque region is encountered while forming looplist, no m o r e links a r e added to it. However, a t r a n s p a r e n t region may s t i l l be added to, since t h e r e a r e index r e g i s t e r s available within it t o which tags c a n b e assigned.

VIII-

1

- I -7--- 7

The looplist table consists of cne word entries for each basic block o r region.

A code i n the prefix of the word indicates whether i t r e f e r s to a basic b l o c k a transparent region, or an opaque region. If the entry is a basic block i t con- tains the BB number, and if the entry is a region i t contains the numbers of the basic blocks a t the entry and exit points of the region. The end of looplist i s in- dicated by a word of a l l sevens.

F r o m the starting point in looplist, the most frequent p r e d e c e s s o r s a r e added one at a t i m e until one of the following conditions have been encountered. If a n entry i s already i n the c u r r e n t looplist, this makes looplist a loop and prohibits further building. If an entry is an opaque region or i f t h e r e a r e no unconsidered predecessors, then additions a r e made at the other end, and the m o s t frequent s u c c e s s o r s a r e looked for. Again the s a m e conditions apply. B a s i c blocks o r regions a r e added until a loop o r a n opaque region is encountered, or there a r e no unconsidered s u c c e s s o r s t o the l a s t entry. When a looplist has been corn- plcted, it will reflect the flow in a section of the object program. It m a y havc a loop, reflecting a loop in the object program. In such a c a s e , i f t h e r e is a n end of looplist not included in the loop, that section is eliminated f r o m looplist.

Only the loop itself will r e m a i n i n looplist for further t r e a t m e n t i n this loop- list. On the other hand, the looplist may be a s t r i n g with no loops, having been

stopped in both directions by encountering an opaque region o r by finding no un- considered links to it.

After the looplist has been formed, the path of flow indicated i s r e a d y f o r t r e a t - ment. The next s t e p i s t o p r e p a r e for simulation which is done i n the 2nd LXing pass. If the looplist i s a string, then the only preparation n e c e s s a r y i s t o m a r k the initial conditions of the IRs. If the looplist is a loop, however, the 1 s t LXing pass i s entered.

1st LXing P a s s

The index r e g i s t e r s used by the object program a r e simulated i n Section F i v e by t h r e e s t o r a g e locations which a r e continually updated. T h e s e c e l l s a r e r e f e r r e d to a s IRs. During simulation they will contain the symbolic tags needed by the corresponding p a r t of the object program.

The 1st LXing p a s s simulates the loop i n o r d e r t o find out the condition of the IRs when the 2nd LXing p a s s is begun. Each basic block i n the looplist is

cxamined t o s e e which tags a r e necessary. This is done by r e f e r r i n g t o TAGLIST (which is a table containing a l i s t of all tagged instructions i n the object program. ) T a g s a r e placed i n the IR cells a s required. When a region is m e t i n looplist, the previously determined e x i t conditions f r o m the region a r e placed i n the IRs.

After the whole looplist has been done the IR cells contain the initial conditions f o r the 2nd LXing pass.

2nd LXing P a s s

Simulation i n the 2nd LXing p a s s is much m o r e complex then t h e c u r s o r y t r e a t - ment of the 1 s t LXing pass. E n t r i e s are made i n tables when a tag m u s t b e loaded

into o r displaced f r o m a n IR. STAG i s used t o r e c o r d LXs and SXs within

once a region has been t r e ~ t e d , nothing i s changed within it. Thus the SX will appear i n the link f r o m that region t o the c u r r e n t LPLST. The STAG entry, on the other hand, c a l l s f o r compilation of an SX immediately following the active instruction.

T'he appearance of an active instruction using a tag a l r e a d y p r e s e n t i n a n active IR will cause the section of

LPLST

t o be marked active.

When a DED pseudo instruction, compiled t o t e l l Section Five that a tag is now valueless, i s encountered and the tag i s not i n a n IR, nothing need be done. An

IR

containing that tag will be loaded with a "hash" symbol, indicating i t s con- tents a r e no longer of any value, and i f the IR was active, the section of LPLST will be marked active.

F o r each taglist instruction an entry i s made i n STAG t o r e c o r d which IR t o use.

After a l l the tagged instructions within a BB have been examined and p r o p e r

table e n t r i e s made, the entrance requirements (tags needed) and exit conditions

s

f o r the t h r e e IRs a r e stored in the B B B table. B B B a l s o will have b i t s indicating which IRs a r e active within the BB, and has information passed on f r o m Section Four about how the basic block ends and the numbers of the SUCC and PRED entries r e f e r r i n g t o this BB. Thus BBB is a s u m m a r y of the b a s i c block, and the individual instructions need not be looked a t again.

If the LPLST entry just trcatcd cndcd with an Assigncd GO TO, aomo extra t r c a t - ment i s required. If t h e r e a r e any active IRs a n SX i s recorded a s n e c e s s a r y . 2 . Treatment of a Transparent Region

E n t r i e s in LPLST which a r e regions have had a l l the BBs i n that region simulated at the t i m e that region was formed. Therefore, i t is not n e c e s s a r y t o go through i t s tagged instructions again. However, i t i s n e c e s s a r y t o take c a r e of the links t o and f r o m the region. The best match possible is made between the c u r r e n t IRs and the entrance requirements of the entry BB in the region. This m a y re- q u i r e permuting index r e g i s t e r assignment i n the region. F o r example, if a tag T1 i s in IR1, when a region's entrance requirement is

T I

i n IR2, then the region's index r e g i s t e r assignment may profitably be changed t o have T 1 i n IRl.

~ h c STAG, PRED, and BBB tables become obsolete by this change and m u s t be updated. The tables a r e not actually changed, however, since the tables a r e r e a d through permutation numbers in BBB, thus only these permutations a r e changed.

The numbers w e r e originally s e t t o 1, 2, 3, (octal 33) by Section F o u r , meaning entry 1 is IRl, etc. If they w e r e changed t o 2, 1, 3, they would m e a n e n t r y 1 is now IR2, entry 2 is now IR1, and entry 3 i s IR3.

LX

and SX bits i n PRED will take c a r e of problems not solved by permutations.

P r o c e s s i n g a t r a n s p a r e n t region entry i n LPLST begins after matching the region's entrance requirements. A p a s s i s made over the BBB e n t r i e s f o r the b a s i c blocks in the region. If the region's entrance requirement f o r a p a r t i c u l a r

IR

is empty (there m u s t be a t l e a s t one of these, since by definition a t r a n s p a r e n t r e g i o n has one o r m o r e empty Ifis), the c u r r e n t tag for that

IR

m a y b e c a r r i e d through the

region. The new entrance and exit conditions of the IR a r e s t o r e d for e a c h BB.

O n the other hand, if the entrance r e q u i r e m e n t i s not empty and does not m a t c h the c u r r e n t tag i n the corresponding IR, and if the IR i s active, i t becomes n e c e s s a r y to examine the exit conditions of the BB. When the BB exit condition does not match the corresponding

IR

but does m a t c h a different IR, an SX i s r e - corded necessary. If the B B exit does m a t c h and the IR i s e i t h e r active o r does not m a t c h a t the region exit, the

IR

i s m a r k e d active i n this BB. After e a c h B B has been t r e a t e d i n this fashion, the new permutation n u m b e r s and active indicators a r e s t o r e d i n BBB.

When a l l the BBs i n the region have been examined the region is considered a s a whole. If the e n t r a n c e condition for a n IR i s empty but the IR m a t c h e s a

different region exit, a "hasht1 symbol is put i n the IR since the s a m e tag should not appear i n m o r e than one

IR

simultaneously. When the region e n t r a n c e con- dition i s "hash" and the IR is active, a n SX i s called for. If the region e n t r a n c e r e q u i r e m e n t m a t c h e s the IR but the region exit i s "hash", empty, o r active, then the section of LPLST i s recorded active by marking the n e c e s s a r y BBB e n t r i e s active f o r the corresponding IR. When the region e n t r a n c e r e q u i r e m e n t is a symbolic tag which i s not already i n a n

IR,

an L X is called f o r i n the link t o the region, and if the IR was active, a n SX is a l s o indicated. At the conclusion of t h i s processing the region's exit conditions a r e i n the IRs, the active i n d i c a t o r s a r e s e t , the region is permuted for the b e s t possible m a t c h t o the preceding

section of LPLST, and any remaining empty IKs a r e noted.

3 . T r e a t m e n t of a n Opaque Region

The processing of a n opaque region i n LPLST is simpler than that of a t r a n s p a r e n t region. This i s t r u e because t h e r e i s no possibility of c a r r y i n g a tag through the region, s i n c e t h e r e a r e no empty IRs. A m a t c h of the r e g i o n ' s e n t r a n c e r e - q u i r e m e n t is m a d e if possible, and the permutation numbers updated. When t h e entrance m a t c h e s the

IR

but the IR is not active, nothing f u r t h e r need b e done.

But when under t h e s a m e conditions, the

IR

is active, either bkcause of a n

LX

within the region o r , if the region is the s a m e one that s t a r t e d L P L S T (a loop condition), the IR was not active a t the s t a r t of LPLST, then a n SX is n e c e s s a r y . If t h e r e was no L X for the

IR

i n the region, and the region is not the s a m e one that s t a r t e d LPLST o r the IR was not active a t the s t a r t of LPLST, then a n SX is not yet n e c e s s a r y , but the B B s i n the region and the section of LPLST t o t h i s point a r e m a r k e d active.

When the contents of a n

IR

do not m a t c h the tag r e q u i r e d a t the e n t r a n c e of a n opaque region a n L X i s recorded a s n e c e s s a r y , and if the IR was a c t i v e , a n SX i s of c o u r s e a l s o indicated.

After the 2nd LXing pass has been finished and a l l the LPLST e n t r i e s dealt with, any remaining activity m u s t be taken c a r e of. If the LPLST was a s t r i n g t h i s is done v e r y simply. It is only n e c e s s a r y to m a r k a section of LPLST a c t i v e f o r any remaining active IRs. In the c a s e of a loop, however, the p r o b l e m is m o r e

complex. The e n t r a n c e r e q u i r e m e n t s a t the beginning of the loop a r e examined.

Lf a r e q u i r e m e n t is not a real tag (it is either "hash" o r empty) and the

IR

is

active, then an SX than the contents o have taken c a r e of is solved.

is recorded. If the entrance requirement i s a tag different f the

IR,

an SX and LX a r e recorded. At this point if the SXs

the activity and t h e r e a r e no m o r e active IRs, the problem

Active P a s s

If t h e r e a r e still active IRs remaining, just a s the 1st LXing pass was required, another pass, the active pass, is executed. LPLST entries a r e examined and treated again in a manner similar t o that of the 2nd LXing pass, with SXs called f o r where necessary. After each LPLST entry has been dealt with, a test is made to s e e i f there is s t i l l an active IR. Eventually they will have a l l been taken c a r e of and the active p a s s finished.

Table U ~ d a t i n ~

It only remains to bring the appropriate tables up t o date. The PRED and SUCC entries that have been treated a r e flagged negative. BBB has the new region references entered. And finally the region table is updated by wiping out obsolete e n t r i e s (regions absorbed into the new one) and making the entry for the new region.

P a r t 1 repeats the cycle of looplist formation and treatment, with new, l a r g e regions absorbing old ones, until all links between basic blocks have been treated and the object program consists of a single, all encompassing region.

SUBROUTINES USED IN PART I SE GROUP

These routines compute the c o r r e c t references to the STAG, SUCC, PRED, and BBB tables for a desired entry. They a r e entered with the item number i n the AC and r e t u r n with index r e g i s t e r 1 loaded appropriately.

This routine selects the most replaceable

IR

by scanning ahead through LPLST and noting how long i t will be before the present tags will be required again. That LR whose contents will be needed l a s t i s the most replaceable. If this routine is entered at S l l l i t does the r e v e r s e , that is s e a r c h for the l e a s t replaceable IR, the one whose tag will be needed f i r s t . This routine a l s o uses S2 a s a subroutine.

This routine can exist i n two states, "Feed LPLST" o r "Feed Tag". In the

"Feed LPLST" s t a t e i t will feed the next item i n LPLST and take the LPLST Feed exit. It switches t o the "Feed Tag" state when the l a s t LPLST item i t fed was a BB and not a region. It then will feed the next item i n TAGLIST and take the tag feed exit until i t h a s fed the l a s t TAGLIST item for that BB, when it r e t u r n s t o

the "Feed LPLST" state. When the end LPLST sentinel is fed i t re-initializes itself to the beginning of LPLST and to the "Feed LPLST" state. The routine uses the S4 subroutine for handling the taglist tape.

This routine will specify the permutation of index r e g i s t e r s which will provide the best match between the IRs and the entrance requirements of a region.

During treatment of a LPLST, the object program index r e g i s t e r s a r e simulated by the IR cells, which contain a symbolic tag, the empty symbol (octal 777777),

or the hash symbol (777776). Entrance requirements for a region will be placed by S5 into the E n 1,2, 3, cells which S5 will t r y to match against the IRs. The optimal match for the IRs will be in the IN cells, and similarly, the b e s t m a t c h f o r E N 1 , 2 , 3, will be in EN 4,5,6. F o r example, IN 1 i s s e t t o 3 , 2 , or 1 de- pending upon whether the correspondent of IR1 is EN 1,2, or 3. Also EN 4 will be s e t to 3 , 2 , o r 1, depending upon whether the correspondent of E N 1 is IR1,

2 , o r 3. Thus if IR1 matches EN 1, IN 1 will contain 3 and E N 4 will contain 3.

S5 uses S1, S6, S7 and S9 a s subroutines.

This routine is used by S5 to load E N 1 , 2 , and 3 with the tags needed by the f i r s t BB i n a region a s entrance conditions for the index r e g i s t e r s .

This routine loads the E X 1 , 2 , 3 and ACT 1 , 2 , 3 cells f r o m the exit conditions and activity bits i n the BBB table of the exit BB in a region.

This routine e n t e r s the P R E D or STAG bits to record that an SX i s to be compiled.

The appropriate activity cell, A C 1 , 2 , or 3, is examined. These cells d e s c r i b e the status of IR 1,2,3. They may contain plus 0, indicating that the

IR

is not active; plus activity, meaning that the active instruction occurred i n a BB which has not been treated until this LPLS'I'; or minus activity, meaning that the active instruction was i n a BB which is i n an already treated region. If SB finds plus activity, the SX bit i s placed in the STAG entry for the active instruction. If i t finds minus activity, the SX bit is entered i n PRED i n the link f r o m the region.

This routine is used t o m a r k a section of LPLST active.

An index r e g i s t e r becomes active when, i n the simulation of a new BB i n the 2nd LXing p a s s , an active instruction (LX, TXI, or T M ) is encountered. The activity produced is plus activity. If while treating the s a m e LPLST the contents

of the IR must be displaced, SB i s entered and will record an

SX

necessary in STAG. This SX completely takes c a r e of the activity problem, and the activity i s ended.

But if at the end of LPLST an

IR

is still active and the need for an SX has not yet arisen, the compiling of the SX may be postponed. However, i t is not safe t o destroy a l l record of the activity, for an SX may be needed i n treating a l a t e r

LPLST. In such a c a s e SC i s entered and will t r a n s f e r the activity from AC 1,2,3 to the BBB table for a l l BBs during which the IR i s active. When entered, SC examines the designated A C cell. If i t i s not active, nothing is done. If i t is active, an entry i s made i n the prefix of word 2 of BBB for every BB between the origin of the activity and the present point of LPLST, and the A C is turned off.

The activity has now become minus activity, and can never be ended. The appear- ance of such a BB is a subsequent LPLST will cause the appropriate AC to contain minus activity, and whenever the contents of the corresponding IR must be dis- placed, the SB routine will put an SX bit into the P R E D link.

This scheme of postponing the compilation of an SX whenever possible, has the gcneral property of producing a l a r g e r number of SXs than strictly necessary.

However, sincd the high frequency paths a r e treated f i r s t , the SXs will appear i n the lower frequency paths. Thus t o save object program time, Section Five will t r a d e object program space.

The SC routine uses SD a s a subroutine.

This routine is used t o m a r k the BBs in any one region active.

This routine f o r m s the appropriate AC 1 , 2 , 3 entry when an active instruction i s encountered.

This routine does the permutation of a REG entry a s indicated by E N 4 , 5 , 6 .

This routine finds the highest frequency unconsidered PRED entry for a given BB.

This routine finds the highest frequency unconsidered SUCC entry for a given BB.

PART

2

In p a r t 1, tags w e r e continually reassigned t o index r e g i s t e r s on the b a s i s of the optimal match that could be achieved. This reassignment was done by changing the permutation numbers in the 2nd word of the BBB table. P a r t 2 makes the actual changes in the appropriate tables on the b a s i s of the final p e r - mutation numbers. It also combines BBLIST (and some information about Assigned GO TO statements), with BBB for convenience l a t e r on.

Each basic block is examined i n sequence. The location word of CIT f o r the f i r s t instruction i n each BB (which has been put i n

BBLIST

by Section F o u r ) is placed i n word 6 of BBB. Then the L X and SX bits i n the PRED e n t r i e s a r e changed according t o the permutation numbers. Next, the STAG e n t r i e s a r e s i m i l a r l y up- dated. Then, for each BB which ends with a n Assigned GO TO, the BB number of the l a s t assigned GO TO i s stored in word 2 of BBR. This is done i n o r d e r that p a r t 3 may find a l l GO TO N B B s easily. Finally, the entrance and exit conditions in words 3 , 4 and 5 of BBB a r e reentered i n accordance with the permutation numbers.

PART 3

Section Five may i n s e r t SXDs and LXDs a t points in the object p r o g r a m which

a r e t r a n s f e r r e d t o by an Assigned GO TO. It may therefore happen that the trans- f e r should no longer go t o i t s original a d d r e s s , but t o one of the SXs or LXs.

P a r t 3 handles this by making the n e c e s s a r y changes i n the a s s i g n constants.

F o r each BB which ends with an Assigned GO TO, p a r t 3 finds the s u c c e s s o r B B s and their appropriate PRED entries. F r o m the SX and LX bits i n PRED, the

c o r r e c t t r a n s f e r a d d r e s s i s prepared. The Assign Constants a r e then compared to the f i r s t instruction of each s u c c e s s o r BB, and w h e n a match i s found the assign i s replaced by the hew symbol. The SX bits a r e a l s o s t o r e d in the prefix of word 2 i n BBB for use by p a r t 4.

When all the Assigned GO TO BBs have been treated, the altered a s s i g n constants a r e written back on tape for Section Six, and p a r t 3 is finished.

PART 4

Part 4 does the actual compilation of instructions on the b a s i s of the information passed on by the previous p a r t s of Section Five. The b i t s i n PRED indicate when inter-block SX and LX instructions a r e required. STAG has the n e c e s s a r y in- formation about when to compile a n L X or SX immediately preceding or following a tagged instruction i n CIT. The r e a l index r e g i s t e r assignment f o r each tag is a l s o indicated by b i t s i n STAG. P a r t 4 follows these directions while compiling.

In addition, some minor optimizing i s done.

A p a s s over CIT is made, and the method used t o bring in blocks of instructions and s c a n them for tagged instructions and endings of B B s is s i m i l a r t o that used by Section Four. This is the only t i m e that Section Five looks a t the CIT. The

instructions a r e brought in f r o m tape and examined i n groups, and when the necessary modifications have been made, they a r e rewritten on tape f o r

instructions a r e brought in f r o m tape and examined i n groups, and when the necessary modifications have been made, they a r e rewritten on tape f o r

Im Dokument FORTRAN FOR (Seite 159-169)