Google
 

Trailing-Edge - PDP-10 Archives - BB-4157D-BM - sources/alcblo.bli
There are 12 other files named alcblo.bli in the archive. Click here to see a list.
MODULE ALCB(SREG=#17,VREG=#15,FREG=#16,DREGS=4,RESERVE(0,1,2,3))=
BEGIN




!THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED
!  OR COPIED IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE.

!COPYRIGHT (C) 1973,1977 BY DIGITAL EQUIPMENT CORPORATION
!AUTHOR: S. MURPHY
GLOBAL BIND ALCBV=#2000057;	!SEPT 21, 1974

%(REVISION HISTORY
55	-----	-----	MUST END A BASIC BLOCK ON AN IF THAT CONTAINS A CALL
56	-----	-----	WHEN INSERT AN ENTRY IN REGSTATE TABLE
			MUST CLEAR VARINREGFLG OF A POSSIBLE ENTRY
			BEING WRITTEN OVER. THIS CAN HAPPEN FOR:
				A=B
				C=B
			WHERE B IS GLOBALLY ALLOCATED TO A REG
57	-----	-----	MUST CHECK FOR A BASIC BLOCK
		TERMINATED BY THE NEXT STMNT HAVING A LABEL BEFORE
			CHECK FOR IT TERMINATED BY THE PREVIOUS STMNT
		A DO STMNT (SINCE IN THAT CASE WE STILL REMEMBER THE
		LP INDEX
)%

FORWARD ALCBLOCK(0),AFREEREG(3),REGCONTAINING(1),VARCLOBB(1),CLOBBCOMEQV,
	CLOBBEQV,CLRRGSTATE,
	INIRGSTATE,SAVEREG(5),FREEPAIRS(1);

EXTERNAL CGERR;		!ROUTINE TO GIVE MESSAGE WHEN INTERNAL COMPILER ERROR
			! IS DETECTED


	!REQUIRE OF "FIRST.BLI" AND "TABLES.BLI" - DONT LIST THEM
	SWITCHES NOLIST;

	REQUIRE FIRST.BLI;
	REQUIRE TABLES.BLI;

	SWITCHES LIST;
BIND RGSENTSIZE=2;	!NUMBER OF WDS IN EACH ENTRY OF THE REGSTATE TABLE

OWN REGSTATE[RGSENTSIZE*16];	!THIS TABLE HAS AN ENTRY FOR EACH OF THE 16 ACS 
				! EACH ENTRY INDICATES WHICH VARS/CONSTS ARE IN EACH REG


OWN BLKISN;	!SEQ NUMBER WITHIN THIS BLOCK OF THE STMNT CURRENTLY BEING PROCESSED



GLOBAL ROUTINE ALCBLOCK=
%(**********
	THE TOP LEVEL ROUTINE FOR THE SECOND PASS OF THE BASIC BLOCK REGISTER ALLOCATOR.
	THIS ROUTINE CAUSES LOCAL REGISTER ALLOCATION TO BE PERFORMED FOR EVERY
	STATEMENT IN A BASIC BLOCK.
	A BASIC BLOCK IS TERMINATED BY
		1.  A LABEL WHICH IS REFERENCED OTHER THAN AS A FORMAT
		2.  A DO STATEMENT
		3.  FOR PURPOSES OF REGISTER ALLOCATION, A CALL STATEMENT (SINCE SUBROUTINES ARE
		    ASSUMED TO CLOBBER ALL REGISTERS)
		4. AN ENTRY POINT
	THIS ROUTINE IS CALLED WITH THE GLOBAL CSTMNT POINTING TO THE FIRST STATEMENT OF
	A BASIC BLOCK.  IT RETURNS WITH CSTMNT POINTING TO THE FIRST STATEMENT OF
	THE NEXT BASIC BLOCK.  IF THE END OF THE PROGRAM HAS BEEN REACHED IT
	RETURNS CSTMNT=0.
	THIS ROUTINE CLEARS THE REGSTATE TABLE WHEN IT HAS COMPLETED THE PASS OVER A
	BASIC BLOCK.  IF THE LAST STATEMENT OF THE BLOCK WAS A DO STATEMENT THEN IF THAT 
	DO STATEMENT HAS THE FLAGS "SAVEREGFLG" AND "NEDSMATRLZ" BOTH SET, IT SETS
	UP A REGSTATE TABLE ENTRY FOR THE DO LOOP INDEX SO THAT THE REGISTER CONTAINING
	THE INDEX CAN BE USED IN THE NEXT BASIC BLOCK.
	IT IS ASSUMED THAT WHEN THIS ROUTINE IS CALLED FOR A GIVEN BASIC BLOCK, THE
	REGSTATE TABLE IS IN THE STATE IN WHICH THIS ROUTINE LEFT IT AFTER
	PROCESSING THE PRECEEDING BASIC BLOCK.
**********)%
BEGIN
	REGISTER BASE PRVSTMNT;	!THE STMNT JUST PROCESSED
	EXTERNAL CSTMNT;			!POINTER TO CURRENT STATEMENT BEING PROCESSED
	MAP BASE CSTMNT;
	EXTERNAL ISN;		!INTERNAL SEQ NUMBER OF THE STMNT BEING PROCESSED
				! (THIS IS USED FOR ERROR MESSAGES)
	MAP RGSTBL REGSTATE;			!TABLE INDICATING WHICH VARIABLES/CONSTANTS ARE IN WHICH REGISTERS

	EXTERNAL CLRRGSTATE;			!ROUTINE TO CLEAR THE REGSTATE TABLE
	EXTERNAL SAVEREG;			!ROUTINE TO SET UP A REGSTATE TABLE ENTRY FOR A REGISTER
						!WHOSE VALUE SHOULD BE PRESERVED
	EXTERNAL ALCSTMN;			!ROUTINE TO PERFORM LOCAL REGISTER ALLOCATION
						!FOR A GIVEN STATEMENT

	EXTERNAL GBSYREGS;	!BIT PATTERN REPRESENTING THE REGS LEFT FREE BY THE
				! GLOBAL ALLOCATOR (A ONE REPRESENTS A FREE REG, A ZERO A BUSY ONE)
	EXTERNAL GBSYCT;	!NUMBER OF FREE REGS IN GBSYREGS
	EXTERNAL STBSYR;	!BIT PATTERN REPRESENTING THE REGS AVAILABLE FOR
				! USE WITHIN A GIVEN STMNT
	EXTERNAL STRGCT;	!NUMBER OF FREE REGS IN STBSYR
	EXTERNAL FRSTLNK;	!POINT TO THE FIRST TEMPORARY ON THE LINKED LIST
				! OF TEMPORARIES THAT HAVE HAD TO BE CREAETED
	EXTERNAL FTEMP;		!POINTER TO THE  TEMPORARY ON THE LINKED LIST
				! OF TEMPS THAT SHOULD BE USED NEXT
				! ZERO IF NONE IS AVAILABLE (AND HENCE A NEW ONE
				! MUST BE ADDED TO THE LIST)
	OWN PEXPRNODE STLABEL;			!POINTER TO THE LABEL TABLE ENTRY FOR THE LABEL ON THIS STATEMENT (IF ANY)

	EXTERNAL OLDGBSYREGS;	!BIT PATTERN SET UP BY THE GLOBAL OPTIMIZER TO
				! INDICATE REGS AVAILABLE OUTSIDE THE CURRENT DO LOOP
				! WHEN THE CURRENT LOOP WAS GLOBALLY ALLOCATED

	BLKISN_1;	!1ST STMNT IN BASIC BLOCK HAS BLOCK INTERNAL SEQ NO. 1
	%(***WALK THRU ALL STATEMENTS IN THE BLOCK***)%
	UNTIL .CSTMNT EQL 0			!UNTIL REACH THE END OF THE PROGRAM
	DO
	BEGIN
		ISN_.CSTMNT[SRCISN];	!GET INTERNAL SEQ NUMB OF THE STMNT TO BE PROCESSED NEXT
		STBSYR_.GBSYREGS;	!INIT SET OF REGS AVAILABLE FOR USE
					! IN THIS STMNT
		STRGCT_.GBSYCT;

		FTEMP_.FRSTLNK;	!INIT PTR TO NEXT TEMPORARY TO BE USED SO
					! THAT WILL REUSE THE TEMPORARIES THAT
					! WERE CREATED FOR PREVIOUS STMNTS
		ALCSTMN();			!PERFORM LOCAL REGISTER ALLOCATION FOR THIS STATEMENT

		IF .CSTMNT[SRCID] EQL CALLID	!IF THIS STATEMENT WAS A CALL STATEMENT, 
			OR .CSTMNT[SRCID] EQL SFNID	! OR A STMNT FN, THEN
			OR (IF .CSTMNT[SRCID] EQL IFLID	! OR A LOG IF
				THEN
				BEGIN
					REGISTER BASE SUBSTMNT;
					SUBSTMNT_.CSTMNT[LIFSTATE];
					IF .SUBSTMNT[SRCID] EQL CALLID	!THAT CONTAINS A CALL
					THEN TRUE
					ELSE FALSE
				END
				ELSE FALSE
			)
		THEN				!IT TERMINATES A BASIC BLOCK
		BEGIN
			CLRRGSTATE();		!CLEAR THE REGSTATE TABLE
			CSTMNT_.CSTMNT[SRCLINK]; !AND RETURN WITH CSTMNT POINTING TO THE
			RETURN			!STATEMENT AFTER THE CALL STATEMENT
		END;

	PRVSTMNT_.CSTMNT;
		CSTMNT_.CSTMNT[SRCLINK];	!GO ON TO THE NEXT STMNT


		IF .CSTMNT NEQ 0		!UNLESS THE END OF THE PROGRAM HAS BEEN REACHED
		THEN
		BEGIN
			IF .CSTMNT[SRCID] EQL ENTRID	!IF THE NEXT STMNT IS AN ENTRY
				OR .CSTMNT[SRCID] EQL SFNID	! OR A STMNT FN
							! IT WILL START A NEW BASIC BLOCK

			THEN 
			BEGIN
				CLRRGSTATE();	!CLEAR TABLE INDICATING VALS IN REGS
				RETURN;		! RETURN WITH CSTMNT POINTING TO THE ENTRY STMNT
			END

			ELSE
			IF (STLABEL_.CSTMNT[SRCLBL]) NEQ 0 !IF THE NEXT STATEMENT HAS A LABEL
			THEN
			BEGIN
				IF .STLABEL[SNREFNO] GTR 1 !WHICH IS REFERENCED OTHER THAN AS A FORMAT
				THEN		!(THE COUNT IN "SNREFNO" INCLUDES THE DEFINITION OF THE
				BEGIN		!LABEL AS A REFERENCE-DOES NOT INCLUDE FORMAT NEFS)
					IF .STLABEL[SNREFNO]-1 !IF THE NUMBER OF REFERENCES TO THIS LABEL
						GTR .STLABEL[SNDOLVL] !IS LARGER THAN THE NUMBER OF DO LOOPS IT TERMINATES
						!(I.E. IF THIS LABEL IS REFERENCED OTHER THAN AS A DO LOOP
						!TERMINATOR)-THEN THE STATEMENT PRECEEDING
						!IT TERMINATED A BASIC BLOCK
					THEN
					BEGIN
						CLRRGSTATE(); !CLEAR THE REGSTATE TABLE
						RETURN	      !AND RETURN WITH CSTMNT POINTING TO THE
              						      !STMNT WITH THE LABEL THAT IS REFERENCED OTHER
							      !THAN AS A FORMAT OR A LOOP TERMINATOR
					END
				END
			END
		END;



		IF .PRVSTMNT[SRCID] EQL DOID	!IF  STATEMENT JUST
					! PROCESSED  WAS A DO STATEMENT,
		THEN				!THEN IT TERMINATES A BASIC BLOCK
		BEGIN
			CLRRGSTATE();		!CLEAR THE REGSTATE TABLE (I.E. CAN NO LONGER ASSUME ANY
						!PREVIOUS VALUES IN REGISTERS)
			IF .PRVSTMNT[NEDSMATRLZ]  !IF THE LOOP INDEX HAS NOT BEEN REPLACED THRUOUT THE
				AND .PRVSTMNT[SAVREGFLG] !LOOP BY REGCONTENTS NODES, BUT THE VALUE OF THE
						!INDEX SHOULD BE LEFT IN A REG ACROSS THE
						!FIRST BASIC BLOCK OF THE LOOP
			THEN
			BEGIN
				REGISTER PEXPRNODE DOIX;	!PTR TO SYMBOL TABLE ENTRY FOR INDEX
				DOIX_.PRVSTMNT[DOSYM];
				IF .DOIX[DBLFLG]	!IF LOOP INDEX IS DP OR COMPLEX
				THEN BEGIN END		! DONT BOTHER (ON KA10, VAL WONT BE IN A REG)
				ELSE
				SAVEREG(.PRVSTMNT[DOIREG], !SET UP A REGSTATE TABLE ENTRY FOR THE REG
					.PRVSTMNT[DOSYM],0, !CONTAINING THE LOOP INDEX
					.PRVSTMNT[SRCSONNXTUSE]);

				%(***IF THE LOOP CONST WAS IN "AOBJN" FORM, MUST CHANGE IT
					SO THAT THE INITIAL VAL FOR THE LOOP INDEX WILL
					BE PICKED UP IN A REG BY ITSELF***)%
				IF .PRVSTMNT[FLCWD]	!IF CTL CONST HAD COUNT IN LEFT HALF
				THEN			! VAR IN RIGHT HALF
				BEGIN
					REGISTER CT;
					REGISTER PEXPRNODE AOBJNCNST;
					AOBJNCNST_.PRVSTMNT[DOLPCTL];	!PTR TO CONST TABLE ENTRY
								! FOR THE CONST THAT HAS NEG CT IN LEFT HALF
					CT_.AOBJNCNST[CONST2]^(-18)	!THE NEG  NUMBER OF ITERATIONS
						OR #777777000000;

					PRVSTMNT[DOLPCTL]_	!SET LOOP CTL CONST TO BE
						MAKECNST(INTEGER,0,-.CT);	!THE POS NUMBER OF ITERATIONS
					PRVSTMNT[CTLNEG]_1;	!SET FLAGS INDICATING THAT CT SHOULD
					PRVSTMNT[CTLIMMED]_1;	! BE PICKED UP WITH "MOVNI" INSTR

					PRVSTMNT[INITLIMMED]_1;	!SET FLAG INDICATING THAT INIT VAL
								! SHOULD BE PICKED UP WITH "MOVEI"
					PRVSTMNT[FLCWD]_0;	!TURN OFF FLAG FOR "USE AOBJN FORM"
					PRVSTMNT[SSIZONE]_1;	! AND IN ITS PLACE, LEAVE FLAG FOR
								! "STEP SIZE IS 1"

					PRVSTMNT[DOCREG]_		!PICK A FREE REG TO USE FOR THE CT
						AFREEREG(CLRBIT(.STBSYR,.PRVSTMNT[DOIREG]),FALSE,FALSE);
				END
			END;

			RETURN			!POINTING TO THE STATEMENT AFTER THE DO STATEMENT
		END;


		BLKISN_.BLKISN+1;	!INCR VAL OF "BLOCK INTERNAL SEQ NUMBER"
	END;					!END OF WALK THRU STMNTS
END;						!END OF ROUTINE "ALC BLOCK"

GLOBAL ROUTINE AFREEREG (BSYREGS,BLKFLG,DOUBLFLG)=
%(**********
	ROUTINE TO RETURN A REGISTER (OR REGISTER PAIR) TO BE USED FOR A GIVEN COMPUTATION.
	THE PARAMETERS FOR THIS ROUTINE ARE:
		1.  BSYREGS-SPECIFIES REGISTERS THAT IT IS POSSIBLE TO USE.  THAT IS, REGISTERS THAT
		    ARE NOT EITHER:
			A.  HOLDING INTERMEDIATE RESULTS IN THIS STATEMENT
			B.  ALLOCATED BY THE GLOBAL REGISTER ALLOCATOR
		    THE BITS IN BSYREGS EACH REPRESENT A REGISTER.  IF A BIT IS ZERO THE CORRESPONDING
		    REGISTER IS NOT AVAILABLE. 
		2.  BLKFLG-IF THIS FLAG IS "TRUE," THE REGISTER TO BE RETURNED WILL BE USED TO
		    HOLD A VALUE THAT WILL BE PRESERVED OVER SUCCEEDING STATEMENTS IN THIS BASIC BLOCK
		3.  DOUBLFLG-SPECIFIES WHETHER A SINGLE REGISTER OR A REGISTER PAIR IS REQUIRED

	THIS ROUTINE USES THE GLOBAL "BLOCKBSYREGS" WHICH SPECIFIES REGISTERS THAT WE PREFER TO
	NOT USE BECAUSE THEIR CONTENTS WILL BE NEEDED LATER IN THIS BASIC BLOCK.  THE
	FORMAT OF "BLOCKBSYREGS" IS SIMILAR TO THAT OF "BSYREGS" (I.E. IF A BIT IS ZERO, THE
	CORRESPONDING REGISTER SHOULD PREFERABLY NOT BE USED).

	WHEN ALL REGISTERS ARE BUSY AND HENCE SOME REGISTER FROM "BLOCKBSYREGS" MUST
	BE USED, WE SELECT THE REGISTER WHOSE NEXT USE IS THE FURTHEST IN THE
	FUTURE.  THE "REGSTATE" TABLE CONTAINS THE INTERNAL SEQUENCE NUMBER
	OF THE NEXT USE OF EACH REGISTER THAT BLOCKBSYREGS INDICATES SHOULD BE PRESERVED.
**********)%
BEGIN
	EXTERNAL BLOCKBSYREGS;			!SPECIFIES REGISTERS WHOSE CONTENTS WILL BE NEEDED LATER
						!IN THIS BASIC BLOCK.
	REGISTER BESTREGS;			!REGISTERS THAT ARE AVAILABLE ACCORDING TO "BSYREGS" AND
						!NOT OF FUTURE USE IN THIS BASIC BLOCK
	OWN RGTOUSE;				!REGISTER WHOSE NEXT USE IS FURTHEST IN THE FUTURE

	MAP RGSTBL REGSTATE;			!TABLE INDICATING WHICH VARIABLES/CONSTANTS ARE IN WHICH REGISTERS

	ROUTINE PAIRREGS(BSYRG1)=
	%(**********
		GIVEN A BIT PATTERN "BSYRG1" IN WHICH ZEROES REPRESENT REGISTERS THAT ARE
		BUSY AND ONES REPRESENT REGISTERS THAT ARE FREE, THIS ROUTINE RETURNS
		A BIT PATTERN IN WHICH ZEROES REPRESENT REGISTERS FOR WHICH THE OTHER
		HALF OF THEIR EVEN-ODD PAIR IS BUSY AND ONES REPRESENT REGISTERS
		FOR WHICH THE OTHER HALF OF THEIR EVEN-ODD PAIR IS FREE.

		FOR BOTTOMMOST FUNCTIONS, BIT 0 OF EACH BIT PATTERN REPRESENTS REGISTER 2
		BIT 1 REPRESENTS REGISTER 3, ETC. F