• Keine Ergebnisse gefunden

SECTION FOUR PART 1

Im Dokument FORTRAN FOR (Seite 148-159)

SECTION THREE

SECTION FOUR PART 1

The f i r s t task of this part i s to divide the object program into basic blocke, a basic block being a s t r e t c h of program with but one entry point, and one exit point. In o r d e r to do this, a pass i s made over

CIT

looking f o r t r a n d e r e a

tests and skip type instructions. Transfer and conditional transfer a d d r e s s e s and the locations of instructions following skip type instructions o r TXLs (end t e s t s of Dos), a r e a l l entered in the BBLIST table once only, in algebraic o r d e r , by means of a binary s e a r c h technique. The assigned G o To instructions a r e ignored for the moment.

During this p a s s , when a T X L is encountered, both its location and addrescl are entered in the DOLIST table, thus providing a l i s t of the beginning and end

locations of a l l Doe, in end location o r d e r ; Routine As sign

A new table, TLFRD, i s now formed from the Assign and Assigned

GO

To entries in the TWGO table, together with the associated e n t r i e s in

TRAD.

(Tifgo

e n t r i e s a r e of a fixed word length, and the T r a d table was therefore created to accomodate a l l possible Assign Go To transfer addresses.) At the same time, a l l the t r a n s f e r a d d r e s s e s a r e entered in BBLIST..

BBLIST now constitutes a l i s t of the beginnings of all basic blocks in the program, i n the o r d e r in which they occur. The baeic block number which i s r e f e r r e d to l a t e r , is the relative address of the particular basic block within the BBLIST table.

Subroutine F r eq

T h e r e a r e two types of Frequency Statements in the F o r t r a n language:

1) A type r e f e r r i n g to conditional t r a n s f e r s , estimating the frequencies of the various branches taken.

2) A type estimating the loop counts of Dos with variable p a r a m e t e r s . The f i r s t type gives rise to a frequency table e n t r y containing the internal formula number of the corresponding coding, followed by as many frequency estimates a s branches. Given frequencies ( i t , La , i s ,

., . . . . . . . .

, i, ) this

routine modifies them to f o r m quantities The significance of this will be explained

The second type gives r i s e to a 2 word entry containing the internal formula number corresponding to the Do followed by the estimated loop count. (The length of this type of frequency entry

-

2 words

-

distinguishes i t f r o m the f i r s t type, which is always longer. ) These Do entries a r e t r a n s f e r r e d to the Dofret table, and the remaining frequencies a r e moved up to occupy the

vacated positions.

Routine SORTDO

The table Dolist, created in the f i r s t pass and ordered on the ends of the Dos, by nature of the way i t was built up, is now sorted into the order of beginnings of DOS. When these a r e equal, the Do with the l a r g e s t terminating location takes precedence. The table i s now compared with BBLIST, and the internal formula numbers in Dolist a r e replaced by basic block numbers.

Routine LOADDO

Dos a r e f u r t h e r processed in this routine, Each Dolist entry i s matched with the corresponding Dotag table entry, and if the l a t t e r indicates a t r a n s f e r out of the Do range, a tag of 7 indicator i s s e t in Dolist. Such a Do i s r e f e r r e d to in this Section a s a 'Do with an if'. Also the loopcount I&- N,

+N3

is

*

N3

calculated and entered in Dolist, unless the p a r a m e t e r s a r e variable; in the l a t t e r c a s e , if a Dofret entry exists f o r the Do, the loopcount given t h e r e is used, otherwise the a r b i t r a r y loopcount 5 i s used. If t h e ' c u r r e n t Do i s a c a r r y c a s e , i. e. in the Docare table written by Section 2, the loopcount is multiplied by that of the previous Do.

PART 2

A second p a s s is now made over Cit, producing the t h r e e principal tables with which simulation i s accomplished, namely BBTABL, SET and TRATABLE.

T h e r e i s one 1-word entry in BBTAL for each basic block in the program, but t h e r e may be s e v e r a l SET and TRATABLE entries corresponding t o this one BBTABL entry. At the beginning of each basic block, the next available

locations i n SET and TRATABLE a r e entered i n the BBTABLE, thus providing a key to information which will be accumulated during the p a s s , for the basic block.

The SET table is made up of information which m a y influence future flowpaths taken in the object p r o g r a m , and is formed in the following way. On reaching a sense light instruction, this entry is m a d e :

Address of dummy 0 o r 1

A zero address would indicate that the light should be turned off, a 1 that it should be turned on. (Dummy lights only a r e maintained during the program simulation pass, i n P a r t 3, not the actual machine lights

.

)

An entry i s made if the current instruction i s derived from an Assign

statement, (i.e. if there is an 'assign' type TlFRD entry correspoz&q to the c u r r e n t location symbol.) The appropriate transfer location i s obtained from the Tifrd entry, and thence, by examining BBLXST, the b a s i c , b l o c k 3 ~ ~ m b e r is derived.

Also, the symbol NLIST. The SET

of the Assign,

"N"

for example, i s entered in a new tahle entry takes the following form:

v

T h e r e i s a f u r t h e r type of Set entry which will be discussed later.

LNLIST

address lljuccessor ' ~ ~ n u r n b e d

The remainder of the analysis during this pass ie concerned with obtaining information about basic block endings. If the irm truction following the c u r r e n t one begins a new basic block, ( i . e . i t s location is in BBLIST), then the current instruction c l e a r l y ends one. 4 1 ~ 0 , if the following instruction dods not begin a basic block, then it may be t+t the cur'rent one is a skip type instruction o r a conditional t r a n s f e r

,

both of which Qonstitute basic block endings.

The ending code of the basic block i s now placed in tbe BBTABLE, which

already contains the

TRATABLE

and SET a d d r e s s e s f o r this basic block. The different codes a r e given in this

list.

The TXL of a Do with an if.

Sense light ending

Probability ending. This i s entered f o r such

BB

endings the successor of which cannot be predicted. T h e s e might be s e n s e switches, conditional t r a n s f e r s ,

Go

to vectore.

Certainty ending. This is entered when the block en& with a tranefer

,

crr control, alwaye p s s e s to the following basic block.

The TXL of a Do without an if.

Assigned G o To ending.

Stop ending.

VII- 3

Thc t r a n s f e r a d d r e s s e s a t the basic block ending give all possible s u c c e s s o r

m u s t be in a s i m i l a r f o r m . For inetance t h r e e equiprobable b r a n c h e s would

J 2

produce probabilities of

(z

I I ). T h e probability f o r e a c h s u c c e s s o r BB is placed i n its T r a t a b l e e n t r y .

PART 3

The object p r o g r a m i s now simulated many t i m e s in o r d e r t o obtain statistical information concerning relative f r e q u e n c i e s of flow paths taken. The number of simulations is equal t o the total number of t r a n s f e r s in the p r o g r a m

multiplied -by 128, which m e a n s t h a t the m o r e complex t h e p r o g r a m , the g r e a t e r the number of simulations. T h e p r o g r a m i s stepped through b a e i c block, using t h e BBTABLE, s t a r t i n g with the f i r s t b a s i c block. No r e f e r e n c e is m a d e t o the complied in&ructions,

A BBTABLE e n t r y i s selected, and orr responding

SET

t a b l e e n t r i e s are obtained. Settings are m a d e a c c o r d i n g to t h e s e e n t r i e e , t h a t i s , t h e SET a d d r e s s , o r s e t t i n g , is stored

i n

t h e location given i n the d e c r e m e n t . F o r i n s t a n c e , a Set e n t r y turning a sense light o n would cause a 1 to be stored i n the dummy s e n s e light a d d r e s s . A Set entry t o reset the loopcount of a DO with a n if would cause the m a x i m u m loopcount t o be s t o r e d in the Tratable of the Do. (This is where the i t e r a t i o n s are counted during the simulation.) Routine DECODE

The b a s i c block ending code in

si table

is now examined. All possible

s u c c e s s o r basic blocks t o t h e c u r r e n t One a r e given i n i t s T r a t a b l e e n t r i e s , a n d t h e way in which the s u c c e s s o r is c h o s e n is d e s c r i b e d below under t h e d i f f e r e n t endings.

Probability. A random number l e s s than 1, is f o r m e d by multiplying a c o n s t a n t ' r a n d o m ' number by a second n u m b e r . T h i s new random n u m b e r now r e p l a c e s t h e second n u m b e r mentioned above to e n s u r e a different r a n d o m number next t i m e . T h e m e t h o d now used t o s e l e c t t h e s u c c e s s o r b a s i c block is b e s t

i l l u s t r a t e d by a n example. Suppose a 3-branch probability ending had a f r e q u e n c y s t a t e m e n t ( l , 2 , 3 ) , which was converted in Part 1 to

( j

t

7

3 1

1.

T h e s e quantities are e x p r e s s i b l e a8 c o o r d i n a t e s of points of a unit line:

T h e p a r t of the l i n e f r o m 0 t o ~ c o r r e s ~ o n d s t o the f i r e t s u c c e s s o r BB, from 6

1 t o 3 c o r r e s p o n d s t o the second, a n d f r o m 3 t o 1 t o the third. Ifthe random

-

6 6 6

number g e n e r a t e d as d e s c rlbed e a r l i e r l i e s within t h e f i r s t i n t e r v a l , t h e n the second successor is c h o s e n , and s o on.

VII- 5

-

T h e flow count of the successful successor BB is now increased by I , and control is returned to deal with this new block.

Certainty. In t h i s c a s e t h e r e i s only one s u c c e s s o r , s o i t s flow count is stepped up, and simulation continues with this block.

Sense light. The euccessor i n this c a s e i s determined by the status of t h e a p p r o p r i a t e d u m m y scnee light. If it ie e.et a t 1, then it i s r e s e t to z e r o and the 'light on' s u c c e s s o r i s chosen, otherwise, the 'light off' s u c c e s s o r ie chosen. The flow count i s stepped up, as f o r other endings.

Assigned Go To. T h e successor of this type of ending depends on the setting m a d e f o r the particular 'N'

,

e a r l i e r in the simulation. The BB number given f o r N in t h e NLIST table (entered t h e r e by a n e a r l i e r BB i n t h e

simulation) is matched with the c u r r e n t T r a t a b l e entries. If a match is not found, the f i r s t T r a t a b l e entry is taken. The s u c c e s s o r flow count is stepped

up a s before.

Do with an if. The simulated loopcount, held in i t s Tratable e n t r y , is stepped u p , and if the Do is complete, then the s u c c e s s o r BB following the Do is

selected. Otherwise, that beginning the Do is chosen.

Do without an if. At this point, such an ending is t r e a t e d a s if i t were a c e r t a i n t y ending. Such Dos a r e dealt with a f t e r the simulation pass.

Stop. The c u r r e n t simulation is now complete, and it i s recommended at the f i r s t basic block of the program, unless the r e q u i r e d number of simulations has been c a r r i e d out.

Routine DODO

After the simulation has been dealt with, this routine adjusts the flow counts of basic blocks which l i e within Dos without if s

.

If may be recalled that during the simulation, these Dos were not simulated a s were the Dos with ifs and t h e r e f o r e the flow counts of the basic blocks within them have not taken account of the loopcounts of the Dos. This i s now kemedied.

If a basic block l i e s within s e v e r a l nested Dos, then c l e a r l y not one loopcount, but all loopcounts multiplied together will be involved. Dos without i f s a r e obtained f r o m t h e DOLIST table, and a new table LCTR i s devised t o keep t r a c k of t h e loopcount nesting of the Dos as they occur. The f i r s t LCTR e n t r y is a dummy, 1. The next always corresponds t o the outer Do of a n e s t , and contains its loopcount. T h e following e n t r y is f o r any second level Do and contains its loopcount the outer Do loopcount. F o r example# in this

configuration quantities in LCTR words a r e indicated

1-- Ez $

LCTR-1 contains loopct

A

LCTR-2 contains loopct

B *

loopct A

1

rDo C

I l l

LCTR-3 contains loopct C

*

loopct B

*

loopct A

LCTR-2 contains loopct D

*

loopct A

i--

-The successor flow count of each basic block between the beginning of Do4 and the beginning of Do# i s multiplied by the contents of LCTR

-

1 i. e. l o o p c t ~ .

The successor flow count of each basic block between Don and Doc i s multiplied by the contents of LCTR

-

2 i. r . loopctdxloopctA

,

and the successor flow count of each BB except the ending BB. within DoC i s multiplied by loopctC 1( loopctg

x

loopctq

.

The successor of the ending BB in Docwill be the beginning of Doc for loopct

,,,

loopctg (loopct

-

1 ) t i m e s , and will be that following the Do, f o r loopct fi loopct,, t i m e s , s o these successor flow counts a r e adjusted accord- ingly. Remaining basic blocks in this nest and in other nesting configurations a r e dealt with similarly.

Routine DOSUCC

As described e a r l i e r , a TRATABLE entry consists of 2 words, the second word containing a successor BB number, with associated flow count, and the f i r s t - word containing various information used by this section but now no longer required. The o r d e r of entries corresponds t o the BQTABLE o r d e r , though there may be several successor BBs and therefore TRATABLE e n t r i e s t o a given BBTABLE entry. In this routine, the 2nd Tratable word i s rearranged slightly and placed in a new table called SUCC. This me a n s 'that f o r e v e r y b a s i c block in BBTABLE, t h e r e is one o r m o r e SUCC entry containing associated flow counts.

T h e r e is another way of looking a t it, namely, given a basic block, which a r e the preceding, o r ' p r e d e c e s s o r 1 basic blocks? This information is complied in the following manner. A pass i s made over Taratable, together with

BBTABLE, to enter in word 1 of each s u c c e s s o r BB Tratable i n t r y , the

I c u r r e n t BBtable number

,

which is of c o u r s e , their predecessor. This new f o r m of Tratable i s now s o r t e d in o r d e r of Successor BB number, and t h e

r e s u l t is that f o r each basic block in t u r n , all p r e d e c e s s o r s a r e grouped together. Now, word 1 of Tratable becomes the PRED table, and relative a d d r e s s e s of

PRED BBS

corresponding t o the Basic Blocks e r e entered i n BBtable. We now have t h r e e basic tables t o be passed on for the Section 5 analysis :

Routine TAGPAS BBTABLE

A d d r e s s of f i r s t relevant

t

,

SUCC e n t r y PRED e n t r y

-

1 14 21 35 1 14 21 3%

The third and final pass i s now made over CIT to collect tag information f o r Section 5, and during this pass two new tables a r e built up: TAG and BBTAG.

F o r each o c c u r r e n c e of a tagged instruction, a n entry is made i n TAG, consisting of the symbolic tag name, together with a code according t o the following list.

When the instruction begins a basic block, the sign of the entry i s s e t negative.

SUCC:

Each t i m e the beginning of a basic block i s encountered, a 'BBTAG e n t r y i s made, containing the number of e n t r i e s s o far in TAG, together with octal 33

,

the l a t t e r being f o r t h ~ convenience of Section 5. The l a s t BBTAG e n t r y is a dummy and contains the total number of

TAG

entries.

Finally, details concerning table lengths a r e left in locations called Keys, f o r Section 5, and the BBtable and BBtag tables a r e combined t o f o r m one table

-

BBBTABLE,

each entry of which c o n s i s t s of 6 word6 the l a s t four being zero.

Flow count P r e d e c e s s o r BB N u m b e r PRED:

Flow count

BB Number Successor

APPENDIX TABLES CREATED DURING SECTION 4

BBLIST T h i s is w r i t t e n i n P a r t 1 and is a n o r d e r e d l i s t of t h e beginning l o c a t i o n s of all b a s i c blocks within the object p r o g r a m .

BBTABLE T h i s is w r i t t e n d u r i n g the second p a s s o v e r C I T , i n P a r t 2.

BBTAG T h i s i s w r i t t e n d u r i n g t h e f i n a l p a s s o v e r CIT i n P a r t 3. An e n t r y is m a d e e v e r y t i m e a new b a s i c block is r e a c h e d , a n d i t c o n t a i n s t h e n u m b e r of TAG e n t r i e s m a d e s o f a r . T h e f i n a l e n t r y c o n t a i n s t h e t o t a l n u m b e r of TAG e n t r i e s made.

Pr ef i x D e c r e m e n t a d d r e s s

DOFHET S e e FRET.

DOLIST T h i s is w r i t t e n in the f i r s t p a s s , d u r i n g P a r t 1 , and o n e e n t r y is m a d e f o r e a c h Do i n t h e o b j e c t p r o g r a m . T h e e n t r y c o n s i s t s of 2 w o r d s :

*

S t a r t i n g l o c a t i o n of c o r r e s p o n d i n g S e t

e n t r i e s B B ending

c o d e

i

FIXDO T h i s is a m i n o r t a b l e , used only i n t h e 2nd p a r t . When i t i s found

n e c e s s a r y t o r e s e t t h e loopcount of a Do with a n i f , a n e n t r y is m a d e h e r e which c o n t a i n s the a d d r e s s of the S e t e n t r y d e s c r i b e d u n d e r S E T i n t h i s appendix.

S t a r t i n g l o c a t i o n of c o r r e s p o n d i n g T r a t a b l e e n t r i e s

Location of beginning of D and is r e p l a c e d by:

Location of e n d of Do

FRET T h i s tab1.e o r i g i n a t e s i n s e c t i o n 1 , and is modified i n P a r t 1. T h e f i r s t w o r d a l w a y s c o n t a i n s t h e i n t e r n a l f o r m u l a n u m b e r t o which the f r e q u e n c y a p p l i e s ,

BB No. of beginning BB No. of end

b

t o g e t h e r with a m i n u s sign. F r e q u e n c i e s f o l l o w s , one word p e r f r e q u e n c y . This a l s o a p p l i e s t o Do f r e q u e n c i e s . Do type f r e q u e n c i e s a r e then e r a s e d f r o m FRET and t r a n s f e r r e d to a new table DOFRET. Meanwhile

,

a r e changed f r o m t h e f o r m (

,

'

,

. . + t o (

L C T R T h i s is a n i n t e r n a l table. T h e flow c o u n t s of b a s i c blocks i y i n g within D o s

-

without if a a r e m u l t i p l i e d b y i t s c o n t e n t s a f t e r t h e simulation.

1st e n t r y D u m m y 1

2nd e n t r y Loopcount of o u t e r Do of a n e s t .

3 r d e n t r y Loopcount of a n y next i n n e r D o X 2nd e n t r y 4 t h e n t r y Loopcount of a n y next i n n e r Do X 3 r d e n t r y

. . .

a n d s o on.

NLIST This i s a l i s t of symbols of Assign statements.

SET This i s written in P a r t 2 , consists of settings made during the object

-

progra.m, and i s used in the simulation.

Sense light

Assign

Entry to r e s e t a Do with an if

Address(es) of dummy 0 if turned off

light(s ) 1 if turned on

I

BB No. of end of Do

I

Maximum 1oo.pcount

of Do

I

Reference to NLIST where As sign symbol is stored.

This i s replaced l a t e r by:

Successor BB No

TAG

-

This i s written during the final pass over

CLT,

in P a r t 3, and an entry is made for every tagged instruction. The code depends on the type of instruction,

?

and a full l i s t i s given in the main. text.

Address of 1st T r a - table entry of end of Do.

Maximum 100,pcount

I I

tag

1

Prefix Address

TWRD This table consists of the Assign entries f r o m TLFGO, which has code 6 in the f i r s t word with the internal formula number, and the Assigned Go To entries of Tifgo and Trad. The latter Tifgo entry has code 1 with the internal formula number, in the f i r s t word., and has the number of t r a n s f e r s ( L e . number of T r a d e n t r i e s ) in the second word.

Code

TRATABLE

This i s built u p during P a r t 2. Each basic blockending, except a stop, has a group of one o r m o r e Tratable entries, giving the successor basic

r

Symbolic

blocks. Different types of entry a r e s h ~ w n .

TRATABLE (cont. )

VIII

Im Dokument FORTRAN FOR (Seite 148-159)