1 /*------------------------------------------------------------------------
3 SDCCralloc.c - source file for register allocation. (8051) specific
5 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998)
6 Added Pic Port T.scott Dattalo scott@dattalo.com (2000)
8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 In other words, you are welcome to use, share and improve this program.
23 You are forbidden to forbid anyone else to use, share and improve
24 what you give them. Help stamp out software-hoarding!
25 -------------------------------------------------------------------------*/
33 #if defined(__BORLANDC__) || defined(_MSC_VER)
34 #define STRCASECMP stricmp
35 #define FENTRY2 1 ? (void)0 : printf
37 #define STRCASECMP strcasecmp
38 //#define FENTRY2(fmt,...) do { fprintf (stderr, "%s:%d: called.\n", __FUNCTION__, __LINE__); fprintf (stderr, fmt, ## __VA_ARGS__); } while (0)
39 #define FENTRY2 1 ? (void)0 : printf
42 /* this should go in SDCCicode.h, but it doesn't. */
43 #define IS_REF(op) (IS_SYMOP(op) && op->operand.symOperand->isref == 1)
45 /*-----------------------------------------------------------------*/
46 /* At this point we start getting processor specific although */
47 /* some routines are non-processor specific & can be reused when */
48 /* targetting other processors. The decision for this will have */
49 /* to be made on a routine by routine basis */
50 /* routines used to pack registers are most definitely not reusable */
51 /* since the pack the registers depending strictly on the MCU */
52 /*-----------------------------------------------------------------*/
54 extern void genpic14Code (iCode *);
55 extern void pic14_assignConfigWordValue(int address, int value);
65 bitVect *funcrUsed; /* registers used in a function */
71 /* Shared with gen.c */
72 int pic14_ptrRegReq; /* one byte pointer register required */
75 set *dynAllocRegs=NULL;
76 set *dynStackRegs=NULL;
77 set *dynProcessorRegs=NULL;
78 set *dynDirectRegs=NULL;
79 set *dynDirectBitRegs=NULL;
80 set *dynInternalRegs=NULL;
82 static hTab *dynDirectRegNames= NULL;
83 // static hTab *regHash = NULL; /* a hash table containing ALL registers */
85 static int dynrIdx = 0x1000;
86 static int rDirectIdx = 0x5000;
88 int pic14_nRegs = 128; // = sizeof (regspic14) / sizeof (regs);
90 int Gstack_base_addr=0; /* The starting address of registers that
91 * are used to pass and return parameters */
97 static void spillThis (symbol *);
99 static FILE *debugF = NULL;
100 /*-----------------------------------------------------------------*/
101 /* debugLog - open a file for debugging information */
102 /*-----------------------------------------------------------------*/
103 //static void debugLog(char *inst,char *fmt, ...)
105 debugLog (char *fmt,...)
107 static int append = 0; // First time through, open the file without append.
110 //char *bufferP=buffer;
113 if (!debug || !dstFileName)
119 /* create the file name */
120 strcpy (buffer, dstFileName);
121 strcat (buffer, ".d");
123 if (!(debugF = fopen (buffer, (append ? "a+" : "w"))))
125 werror (E_FILE_OPEN_ERR, buffer);
128 append = 1; // Next time debubLog is called, we'll append the debug info
134 vsprintf (buffer, fmt, ap);
136 fprintf (debugF, "%s", buffer);
137 //if (options.verbose) fprintf (stderr, "%s: %s", __FUNCTION__, buffer);
139 while (isspace((unsigned char)*bufferP)) bufferP++;
141 if (bufferP && *bufferP)
142 lineCurr = (lineCurr ?
143 connectLine(lineCurr,newLineNode(lb)) :
144 (lineHead = newLineNode(lb)));
145 lineCurr->isInline = _G.inLine;
146 lineCurr->isDebug = _G.debugLine;
156 fputc ('\n', debugF);
158 /*-----------------------------------------------------------------*/
159 /* debugLogClose - closes the debug log file (if opened) */
160 /*-----------------------------------------------------------------*/
170 #define AOP(op) op->aop
173 debugAopGet (char *str, operand * op)
178 printOperand (op, debugF);
186 decodeOp (unsigned int op)
189 if (op < 128 && op > ' ')
191 buffer[0] = (op & 0xff);
198 case IDENTIFIER: return "IDENTIFIER";
199 case TYPE_NAME: return "TYPE_NAME";
200 case CONSTANT: return "CONSTANT";
201 case STRING_LITERAL: return "STRING_LITERAL";
202 case SIZEOF: return "SIZEOF";
203 case PTR_OP: return "PTR_OP";
204 case INC_OP: return "INC_OP";
205 case DEC_OP: return "DEC_OP";
206 case LEFT_OP: return "LEFT_OP";
207 case RIGHT_OP: return "RIGHT_OP";
208 case LE_OP: return "LE_OP";
209 case GE_OP: return "GE_OP";
210 case EQ_OP: return "EQ_OP";
211 case NE_OP: return "NE_OP";
212 case AND_OP: return "AND_OP";
213 case OR_OP: return "OR_OP";
214 case MUL_ASSIGN: return "MUL_ASSIGN";
215 case DIV_ASSIGN: return "DIV_ASSIGN";
216 case MOD_ASSIGN: return "MOD_ASSIGN";
217 case ADD_ASSIGN: return "ADD_ASSIGN";
218 case SUB_ASSIGN: return "SUB_ASSIGN";
219 case LEFT_ASSIGN: return "LEFT_ASSIGN";
220 case RIGHT_ASSIGN: return "RIGHT_ASSIGN";
221 case AND_ASSIGN: return "AND_ASSIGN";
222 case XOR_ASSIGN: return "XOR_ASSIGN";
223 case OR_ASSIGN: return "OR_ASSIGN";
224 case TYPEDEF: return "TYPEDEF";
225 case EXTERN: return "EXTERN";
226 case STATIC: return "STATIC";
227 case AUTO: return "AUTO";
228 case REGISTER: return "REGISTER";
229 case CODE: return "CODE";
230 case EEPROM: return "EEPROM";
231 case INTERRUPT: return "INTERRUPT";
232 case SFR: return "SFR";
233 case AT: return "AT";
234 case SBIT: return "SBIT";
235 case REENTRANT: return "REENTRANT";
236 case USING: return "USING";
237 case XDATA: return "XDATA";
238 case DATA: return "DATA";
239 case IDATA: return "IDATA";
240 case PDATA: return "PDATA";
241 case VAR_ARGS: return "VAR_ARGS";
242 case CRITICAL: return "CRITICAL";
243 case NONBANKED: return "NONBANKED";
244 case BANKED: return "BANKED";
245 case CHAR: return "CHAR";
246 case SHORT: return "SHORT";
247 case INT: return "INT";
248 case LONG: return "LONG";
249 case SIGNED: return "SIGNED";
250 case UNSIGNED: return "UNSIGNED";
251 case FLOAT: return "FLOAT";
252 case DOUBLE: return "DOUBLE";
253 case CONST: return "CONST";
254 case VOLATILE: return "VOLATILE";
255 case VOID: return "VOID";
256 case BIT: return "BIT";
257 case STRUCT: return "STRUCT";
258 case UNION: return "UNION";
259 case ENUM: return "ENUM";
260 case ELIPSIS: return "ELIPSIS";
261 case RANGE: return "RANGE";
262 case FAR: return "FAR";
263 case CASE: return "CASE";
264 case DEFAULT: return "DEFAULT";
265 case IF: return "IF";
266 case ELSE: return "ELSE";
267 case SWITCH: return "SWITCH";
268 case WHILE: return "WHILE";
269 case DO: return "DO";
270 case FOR: return "FOR";
271 case GOTO: return "GOTO";
272 case CONTINUE: return "CONTINUE";
273 case BREAK: return "BREAK";
274 case RETURN: return "RETURN";
275 case INLINEASM: return "INLINEASM";
276 case IFX: return "IFX";
277 case ADDRESS_OF: return "ADDRESS_OF";
278 case GET_VALUE_AT_ADDRESS: return "GET_VALUE_AT_ADDRESS";
279 case SPIL: return "SPIL";
280 case UNSPIL: return "UNSPIL";
281 case GETHBIT: return "GETHBIT";
282 case BITWISEAND: return "BITWISEAND";
283 case UNARYMINUS: return "UNARYMINUS";
284 case IPUSH: return "IPUSH";
285 case IPOP: return "IPOP";
286 case PCALL: return "PCALL";
287 case ENDFUNCTION: return "ENDFUNCTION";
288 case JUMPTABLE: return "JUMPTABLE";
289 case RRC: return "RRC";
290 case RLC: return "RLC";
291 case CAST: return "CAST";
292 case CALL: return "CALL";
293 case PARAM: return "PARAM ";
294 case NULLOP: return "NULLOP";
295 case BLOCK: return "BLOCK";
296 case LABEL: return "LABEL";
297 case RECEIVE: return "RECEIVE";
298 case SEND: return "SEND";
300 sprintf (buffer, "unknown op %d %c", op, op & 0xff);
303 /*-----------------------------------------------------------------*/
304 /*-----------------------------------------------------------------*/
306 debugLogRegType (short type)
311 case REG_GPR: return "REG_GPR";
312 case REG_PTR: return "REG_PTR";
313 case REG_CND: return "REG_CND";
316 sprintf (buffer, "unknown reg type %d", type);
320 /*-----------------------------------------------------------------*/
321 /*-----------------------------------------------------------------*/
322 static int regname2key(char const *name)
331 key += (*name++) + 1;
335 return ( (key + (key >> 4) + (key>>8)) & 0x3f);
339 static regs *regWithIdx (set *dRegs, int idx, int fixed);
340 /*-----------------------------------------------------------------*/
341 /* newReg - allocate and init memory for a new register */
342 /*-----------------------------------------------------------------*/
343 static regs* newReg(short type, PIC_OPTYPE pc_type, int rIdx, char *name, int size, int alias)
346 regs *dReg, *reg_alias;
348 /* check whether a matching register already exists */
349 dReg = dirregWithName( name );
351 //printf( "%s: already present: %s\n", __FUNCTION__, name );
355 // check whether a register at that location exists
356 reg_alias = regWithIdx( dynDirectRegs, rIdx, 0 );
357 if (!reg_alias) reg_alias = regWithIdx( dynDirectRegs, rIdx, 1 );
359 // create a new register
360 dReg = Safe_calloc(1,sizeof(regs));
362 dReg->pc_type = pc_type;
365 dReg->name = Safe_strdup(name);
367 sprintf(buffer,"r0x%02X", dReg->rIdx);
368 dReg->name = Safe_strdup(buffer);
384 dReg->reg_alias = reg_alias;
385 dReg->reglives.usedpFlows = newSet();
386 dReg->reglives.assignedpFlows = newSet();
387 hTabAddItem(&dynDirectRegNames, regname2key(dReg->name), dReg);
388 debugLog( "%s: Created register %s.\n", __FUNCTION__, dReg->name);
393 /*-----------------------------------------------------------------*/
394 /* regWithIdx - Search through a set of registers that matches idx */
395 /*-----------------------------------------------------------------*/
397 regWithIdx (set *dRegs, int idx, int fixed)
401 for (dReg = setFirstItem(dRegs) ; dReg ;
402 dReg = setNextItem(dRegs)) {
404 if(idx == dReg->rIdx && (fixed == (int)dReg->isFixed)) {
405 while (dReg->reg_alias) dReg = dReg->reg_alias;
413 /*-----------------------------------------------------------------*/
414 /* regWithName - Search through a set of registers that matches name */
415 /*-----------------------------------------------------------------*/
417 regWithName (set *dRegs, const char *name)
421 for (dReg = setFirstItem(dRegs) ; dReg ;
422 dReg = setNextItem(dRegs)) {
424 if((strcmp(name,dReg->name)==0)) {
432 /*-----------------------------------------------------------------*/
433 /* regWithName - Search for a registers that matches name */
434 /*-----------------------------------------------------------------*/
436 regFindWithName (const char *name)
440 if( (dReg = regWithName ( dynDirectRegs, name)) != NULL ) {
441 debugLog ("Found a Direct Register!\n");
444 if( (dReg = regWithName ( dynDirectBitRegs, name)) != NULL) {
445 debugLog ("Found a Direct Bit Register!\n");
449 if (*name=='_') name++; // Step passed '_'
451 if( (dReg = regWithName ( dynAllocRegs, name)) != NULL) {
452 debugLog ("Found a Dynamic Register!\n");
455 if( (dReg = regWithName ( dynProcessorRegs, name)) != NULL) {
456 debugLog ("Found a Processor Register!\n");
459 if( (dReg = regWithName ( dynInternalRegs, name)) != NULL) {
460 debugLog ("Found an Internal Register!\n");
463 if( (dReg = regWithName ( dynStackRegs, name)) != NULL) {
464 debugLog ("Found an Stack Register!\n");
471 /*-----------------------------------------------------------------*/
472 /* regFindFree - Search for a free register in a set of registers */
473 /*-----------------------------------------------------------------*/
475 regFindFree (set *dRegs)
479 for (dReg = setFirstItem(dRegs) ; dReg ;
480 dReg = setNextItem(dRegs)) {
488 /*-----------------------------------------------------------------*/
489 /* initStack - allocate registers for a pseudo stack */
490 /*-----------------------------------------------------------------*/
491 void initStack(int base_address, int size)
496 Gstack_base_addr = base_address;
498 //fprintf(stderr,"initStack [base:0x%02x, size:%d]\n", base_address, size);
500 for(i = 0; i<size; i++) {
503 SNPRINTF(&buffer[0], 16, "STK%02d", i);
504 r = newReg(REG_STK, PO_GPR_TEMP,base_address,buffer,1,0);
505 r->address = base_address; // Pseudo stack needs a fixed location that can be known by all modules
509 r->alias = 0x180; // Using shared memory for pseudo stack
510 addSet(&dynStackRegs,r);
515 /*-----------------------------------------------------------------*
516 *-----------------------------------------------------------------*/
518 allocProcessorRegister(int rIdx, char * name, short po_type, int alias)
521 //fprintf(stderr,"allocProcessorRegister %s addr =0x%x\n",name,rIdx);
522 return addSet(&dynProcessorRegs,newReg(REG_SFR, po_type, rIdx, name,1,alias));
525 /*-----------------------------------------------------------------*
526 *-----------------------------------------------------------------*/
529 allocInternalRegister(int rIdx, char * name, PIC_OPTYPE po_type, int alias)
531 regs * reg = newReg(REG_GPR, po_type, rIdx, name,1,alias);
533 //fprintf(stderr,"allocInternalRegister %s addr =0x%x\n",name,rIdx);
536 return addSet(&dynInternalRegs,reg);
541 /*-----------------------------------------------------------------*/
542 /* allocReg - allocates register of given type */
543 /*-----------------------------------------------------------------*/
545 allocReg (short type)
549 debugLog ("%s of type %s\n", __FUNCTION__, debugLogRegType (type));
550 //fprintf(stderr,"allocReg\n");
552 reg = pic14_findFreeReg (type);
560 //return addSet(&dynAllocRegs,newReg(REG_GPR, PO_GPR_TEMP,dynrIdx++,NULL,1,0));
565 /*-----------------------------------------------------------------*/
566 /* dirregWithName - search for register by name */
567 /*-----------------------------------------------------------------*/
569 dirregWithName (char *name)
577 /* hash the name to get a key */
579 hkey = regname2key(name);
581 reg = hTabFirstItemWK(dynDirectRegNames, hkey);
585 if(STRCASECMP(reg->name, name) == 0) {
586 // handle registers with multiple names
587 while (reg->reg_alias) reg = reg->reg_alias;
591 reg = hTabNextItemWK (dynDirectRegNames);
595 return NULL; // name wasn't found in the hash table
598 int IS_CONFIG_ADDRESS(int address)
601 return ((address == 0x2007) || (address == 0x2008));
604 /*-----------------------------------------------------------------*/
605 /* allocNewDirReg - allocates a new register of given type */
606 /*-----------------------------------------------------------------*/
608 allocNewDirReg (sym_link *symlnk,const char *name)
612 sym_link *spec = getSpec (symlnk);
614 /* if this is at an absolute address, then get the address. */
615 if (SPEC_ABSA (spec) ) {
616 address = SPEC_ADDR (spec);
617 //fprintf(stderr,"reg %s is at an absolute address: 0x%03x\n",name,address);
620 /* Register wasn't found in hash, so let's create
621 * a new one and put it in the hash table AND in the
622 * dynDirectRegNames set */
623 if (IS_CONFIG_ADDRESS(address)) {
624 debugLog (" -- %s is declared at address 0x2007\n",name);
629 if (IS_BITVAR (spec))
636 reg = newReg(REG_GPR, PO_DIR, idx, (char*)name,getSize (symlnk),0 );
637 debugLog (" -- added %s to hash, size = %d\n", (char*)name,reg->size);
639 if (SPEC_ABSA (spec) ) {
643 if (IS_BITVAR (spec)) {
644 addSet(&dynDirectBitRegs, reg);
647 addSet(&dynDirectRegs, reg);
649 if (!IS_STATIC (spec)) {
652 if (IS_EXTERN (spec)) {
658 if (address && reg) {
660 reg->address = address;
661 debugLog (" -- and it is at a fixed address 0x%02x\n",reg->address);
667 /*-----------------------------------------------------------------*/
668 /* allocDirReg - allocates register of given type */
669 /*-----------------------------------------------------------------*/
671 allocDirReg (operand *op )
678 debugLog ("%s BAD, op is NULL\n", __FUNCTION__);
682 name = OP_SYMBOL (op)->rname[0] ? OP_SYMBOL (op)->rname : OP_SYMBOL (op)->name;
684 /* If the symbol is at a fixed address, then remove the leading underscore
685 * from the name. This is hack to allow the .asm include file named registers
686 * to match the .c declared register names */
688 //if (SPEC_ABSA ( OP_SYM_ETYPE(op)) && (*name == '_'))
691 debugLog ("%s symbol name %s\n", __FUNCTION__,name);
693 if(SPEC_CONST ( OP_SYM_ETYPE(op)) && (IS_CHAR ( OP_SYM_ETYPE(op)) )) {
694 debugLog(" %d const char\n",__LINE__);
695 debugLog(" value = %s \n",SPEC_CVAL( OP_SYM_ETYPE(op)));
698 debugLog(" %d storage class %d \n",__LINE__,SPEC_SCLS( OP_SYM_ETYPE(op)));
699 if (IS_CODE ( OP_SYM_ETYPE(op)) )
700 debugLog(" %d code space\n",__LINE__);
702 if (IS_INTEGRAL ( OP_SYM_ETYPE(op)) )
703 debugLog(" %d integral\n",__LINE__);
704 if (IS_LITERAL ( OP_SYM_ETYPE(op)) )
705 debugLog(" %d literal\n",__LINE__);
706 if (IS_SPEC ( OP_SYM_ETYPE(op)) )
707 debugLog(" %d specifier\n",__LINE__);
708 debugAopGet(NULL, op);
711 if (IS_CODE ( OP_SYM_ETYPE(op)) )
714 /* First, search the hash table to see if there is a register with this name */
715 if (SPEC_ABSA ( OP_SYM_ETYPE(op)) && !(IS_BITVAR (OP_SYM_ETYPE(op))) ) {
716 reg = regWithIdx (dynProcessorRegs, SPEC_ADDR ( OP_SYM_ETYPE(op)), 1);
719 fprintf(stderr,"ralloc %s is at fixed address but not a processor reg, addr=0x%x\n",
720 name, SPEC_ADDR ( OP_SYM_ETYPE(op)));
722 fprintf(stderr,"ralloc %s at fixed address has already been declared, addr=0x%x\n",
723 name, SPEC_ADDR ( OP_SYM_ETYPE(op)));
726 //fprintf(stderr,"ralloc:%d %s \n", __LINE__,name);
728 reg = dirregWithName(name);
735 /* if this is at an absolute address, then get the address. */
736 if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) {
737 address = SPEC_ADDR ( OP_SYM_ETYPE(op));
738 //fprintf(stderr,"reg %s is at an absolute address: 0x%03x\n",name,address);
741 /* Register wasn't found in hash, so let's create
742 * a new one and put it in the hash table AND in the
743 * dynDirectRegNames set */
744 if(!IS_CONFIG_ADDRESS(address)) {
745 //fprintf(stderr,"allocating new reg %s\n",name);
747 reg = newReg(REG_GPR, PO_DIR, rDirectIdx++, name,getSize (OP_SYMBOL (op)->type),0 );
748 debugLog (" -- added %s to hash, size = %d\n", name,reg->size);
750 //hTabAddItem(&dynDirectRegNames, regname2key(name), reg);
752 if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) {
754 //fprintf(stderr, " ralloc.c at fixed address: %s - changing to REG_SFR\n",name);
758 if (IS_BITVAR (OP_SYM_ETYPE(op))) {
759 addSet(&dynDirectBitRegs, reg);
762 addSet(&dynDirectRegs, reg);
764 if (!IS_STATIC (OP_SYM_ETYPE(op))) {
767 if (IS_EXTERN (OP_SYM_ETYPE(op))) {
773 debugLog (" -- %s is declared at address 0x2007\n",name);
778 if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) {
780 reg->address = SPEC_ADDR ( OP_SYM_ETYPE(op));
781 debugLog (" -- and it is at a fixed address 0x%02x\n",reg->address);
786 if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) {
788 reg->address = SPEC_ADDR ( OP_SYM_ETYPE(op));
789 debugLog (" -- and it is at a fixed address 0x%02x\n",reg->address);
792 allocNewDirReg (OP_SYM_TYPE(op),name);
799 /*-----------------------------------------------------------------*/
800 /* allocRegByName - allocates register with given name */
801 /*-----------------------------------------------------------------*/
803 allocRegByName (char *name, int size)
809 fprintf(stderr, "%s - allocating a NULL register\n",__FUNCTION__);
813 /* First, search the hash table to see if there is a register with this name */
814 reg = dirregWithName(name);
820 /* Register wasn't found in hash, so let's create
821 * a new one and put it in the hash table AND in the
822 * dynDirectRegNames set */
823 //fprintf (stderr,"%s symbol name %s, size:%d\n", __FUNCTION__,name,size);
824 reg = newReg(REG_GPR, PO_DIR, rDirectIdx++, name,size,0 );
825 for (sym = setFirstItem(sfr->syms); sym; sym = setNextItem(sfr->syms)) {
826 if (strcmp(reg->name+1,sym->name)==0) {
827 unsigned a = SPEC_ADDR(sym->etype);
831 if (!IS_STATIC (sym->etype)) {
834 if (IS_EXTERN (sym->etype)) {
837 if (IS_BITVAR (sym->etype))
844 for (sym = setFirstItem(data->syms); sym; sym = setNextItem(data->syms)) {
845 if (strcmp(reg->name+1,sym->name)==0) {
846 unsigned a = SPEC_ADDR(sym->etype);
848 if (!IS_STATIC (sym->etype)) {
851 if (IS_EXTERN (sym->etype)) {
854 if (IS_BITVAR (sym->etype))
862 debugLog (" -- added %s to hash, size = %d\n", name,reg->size);
864 //hTabAddItem(&dynDirectRegNames, regname2key(name), reg);
865 if (reg->isBitField) {
866 addSet(&dynDirectBitRegs, reg);
868 addSet(&dynDirectRegs, reg);
874 /*-----------------------------------------------------------------*/
875 /* RegWithIdx - returns pointer to register with index number */
876 /*-----------------------------------------------------------------*/
878 typeRegWithIdx (int idx, int type, int fixed)
883 debugLog ("%s - requesting index = 0x%x\n", __FUNCTION__,idx);
888 if( (dReg = regWithIdx ( dynAllocRegs, idx, fixed)) != NULL) {
890 debugLog ("Found a Dynamic Register!\n");
893 if( (dReg = regWithIdx ( dynDirectRegs, idx, fixed)) != NULL ) {
894 debugLog ("Found a Direct Register!\n");
900 if( (dReg = regWithIdx ( dynStackRegs, idx, fixed)) != NULL ) {
901 debugLog ("Found a Stack Register!\n");
905 werror (E_STACK_OUT, "Register");
906 /* return an existing register just to avoid the SDCC crash */
907 return regWithIdx ( dynStackRegs, 0x7f, fixed);
911 if( (dReg = regWithIdx ( dynProcessorRegs, idx, fixed)) != NULL ) {
912 debugLog ("Found a Processor Register!\n");
926 /*-----------------------------------------------------------------*/
927 /* pic14_regWithIdx - returns pointer to register with index number*/
928 /*-----------------------------------------------------------------*/
930 pic14_regWithIdx (int idx)
934 if( (dReg = typeRegWithIdx(idx,REG_GPR,0)) != NULL)
937 if( (dReg = typeRegWithIdx(idx,REG_SFR,0)) != NULL)
943 /*-----------------------------------------------------------------*/
944 /* pic14_regWithIdx - returns pointer to register with index number */
945 /*-----------------------------------------------------------------*/
947 pic14_allocWithIdx (int idx)
952 debugLog ("%s - allocating with index = 0x%x\n", __FUNCTION__,idx);
954 if( (dReg = regWithIdx ( dynAllocRegs, idx,0)) != NULL) {
956 debugLog ("Found a Dynamic Register!\n");
957 } else if( (dReg = regWithIdx ( dynStackRegs, idx,0)) != NULL ) {
958 debugLog ("Found a Stack Register!\n");
959 } else if( (dReg = regWithIdx ( dynProcessorRegs, idx,0)) != NULL ) {
960 debugLog ("Found a Processor Register!\n");
961 } else if( (dReg = regWithIdx ( dynInternalRegs, idx,0)) != NULL ) {
962 debugLog ("Found an Internal Register!\n");
963 } else if( (dReg = regWithIdx ( dynInternalRegs, idx,1)) != NULL ) {
964 debugLog ("Found an Internal Register!\n");
967 debugLog ("Dynamic Register not found\n");
970 //fprintf(stderr,"%s %d - requested register: 0x%x\n",__FUNCTION__,__LINE__,idx);
971 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
972 "regWithIdx not found");
982 /*-----------------------------------------------------------------*/
983 /*-----------------------------------------------------------------*/
985 pic14_findFreeReg(short type)
992 if((dReg = regFindFree(dynAllocRegs)) != NULL)
994 return addSet(&dynAllocRegs,newReg(REG_GPR, PO_GPR_TEMP,dynrIdx++,NULL,1,0));
998 if((dReg = regFindFree(dynStackRegs)) != NULL)
1010 /*-----------------------------------------------------------------*/
1011 /* freeReg - frees a register */
1012 /*-----------------------------------------------------------------*/
1014 freeReg (regs * reg)
1016 debugLog ("%s\n", __FUNCTION__);
1021 /*-----------------------------------------------------------------*/
1022 /* nFreeRegs - returns number of free registers */
1023 /*-----------------------------------------------------------------*/
1025 nFreeRegs (int type)
1027 /* dynamically allocate as many as we need and worry about
1028 * fitting them into a PIC later */
1035 debugLog ("%s\n", __FUNCTION__);
1036 for (i = 0; i < pic14_nRegs; i++)
1037 if (regspic14[i].isFree && regspic14[i].type == type)
1043 /*-----------------------------------------------------------------*/
1044 /* nfreeRegsType - free registers with type */
1045 /*-----------------------------------------------------------------*/
1047 nfreeRegsType (int type)
1050 debugLog ("%s\n", __FUNCTION__);
1051 if (type == REG_PTR)
1053 if ((nfr = nFreeRegs (type)) == 0)
1054 return nFreeRegs (REG_GPR);
1057 return nFreeRegs (type);
1060 void writeSetUsedRegs(FILE *of, set *dRegs)
1065 for (dReg = setFirstItem(dRegs) ; dReg ;
1066 dReg = setNextItem(dRegs)) {
1069 fprintf (of, "\t%s\n",dReg->name);
1073 extern void assignFixedRegisters(set *regset);
1074 extern void assignRelocatableRegisters(set *regset,int used);
1075 extern void dump_map(void);
1076 extern void dump_sfr(FILE *of);
1078 void packBits(set *bregs)
1082 regs *bitfield=NULL;
1083 regs *relocbitfield=NULL;
1089 for (regset = bregs ; regset ;
1090 regset = regset->next) {
1092 breg = regset->item;
1093 breg->isBitField = 1;
1094 //fprintf(stderr,"bit reg: %s\n",breg->name);
1097 //fprintf(stderr,"packing bit at fixed address = 0x%03x\n",breg->address);
1099 bitfield = typeRegWithIdx (breg->address >> 3, -1 , 1);
1100 breg->rIdx = breg->address & 7;
1101 breg->address >>= 3;
1104 //sprintf (buffer, "fbitfield%02x", breg->address);
1105 sprintf (buffer, "0x%02x", breg->address);
1106 //fprintf(stderr,"new bit field\n");
1107 bitfield = newReg(REG_SFR, PO_GPR_BIT,breg->address,buffer,1,0);
1108 bitfield->isBitField = 1;
1109 bitfield->isFixed = 1;
1110 bitfield->address = breg->address;
1111 //addSet(&dynDirectRegs,bitfield);
1112 addSet(&dynInternalRegs,bitfield);
1113 //hTabAddItem(&dynDirectRegNames, regname2key(buffer), bitfield);
1115 //fprintf(stderr," which is occupied by %s (addr = %d)\n",bitfield->name,bitfield->address);
1118 breg->reg_alias = bitfield;
1122 if(!relocbitfield || bit_no >7) {
1125 sprintf (buffer, "bitfield%d", byte_no);
1126 //fprintf(stderr,"new relocatable bit field\n");
1127 relocbitfield = newReg(REG_GPR, PO_GPR_BIT,rDirectIdx++,buffer,1,0);
1128 relocbitfield->isBitField = 1;
1129 //addSet(&dynDirectRegs,relocbitfield);
1130 addSet(&dynInternalRegs,relocbitfield);
1131 //hTabAddItem(&dynDirectRegNames, regname2key(buffer), relocbitfield);
1135 breg->reg_alias = relocbitfield;
1136 breg->address = rDirectIdx; /* byte_no; */
1137 breg->rIdx = bit_no++;
1145 void bitEQUs(FILE *of, set *bregs)
1147 regs *breg,*bytereg;
1150 //fprintf(stderr," %s\n",__FUNCTION__);
1151 for (breg = setFirstItem(bregs) ; breg ;
1152 breg = setNextItem(bregs)) {
1154 //fprintf(stderr,"bit reg: %s\n",breg->name);
1156 bytereg = breg->reg_alias;
1158 fprintf (of, "%s\tEQU\t( (%s<<3)+%d)\n",
1161 breg->rIdx & 0x0007);
1164 //fprintf(stderr, "bit field is not assigned to a register\n");
1165 fprintf (of, "%s\tEQU\t( (bitfield%d<<3)+%d)\n",
1175 void aliasEQUs(FILE *of, set *fregs, int use_rIdx)
1180 for (reg = setFirstItem(fregs) ; reg ;
1181 reg = setNextItem(fregs)) {
1183 //if(!reg->isEmitted && reg->wasUsed) {
1186 fprintf (of, "%s\tEQU\t0x%03x\n",
1190 fprintf (of, "%s\tEQU\t0x%03x\n",
1198 void writeUsedRegs(FILE *of)
1200 packBits(dynDirectBitRegs);
1202 assignFixedRegisters(dynInternalRegs);
1203 assignFixedRegisters(dynAllocRegs);
1204 assignFixedRegisters(dynStackRegs);
1205 assignFixedRegisters(dynDirectRegs);
1207 assignRelocatableRegisters(dynInternalRegs,0);
1208 assignRelocatableRegisters(dynAllocRegs,0);
1209 assignRelocatableRegisters(dynStackRegs,0);
1211 assignRelocatableRegisters(dynDirectRegs,0);
1213 assignRelocatableRegisters(dynDirectRegs,0);
1214 printf("assignRelocatableRegisters(dynDirectRegs,0);\n");
1219 bitEQUs(of,dynDirectBitRegs);
1221 aliasEQUs(of,dynAllocRegs,0);
1222 aliasEQUs(of,dynDirectRegs,0);
1223 aliasEQUs(of,dynStackRegs,0);
1224 aliasEQUs(of,dynProcessorRegs,1);
1229 /*-----------------------------------------------------------------*/
1230 /* allDefsOutOfRange - all definitions are out of a range */
1231 /*-----------------------------------------------------------------*/
1233 allDefsOutOfRange (bitVect * defs, int fseq, int toseq)
1237 debugLog ("%s\n", __FUNCTION__);
1241 for (i = 0; i < defs->size; i++)
1245 if (bitVectBitValue (defs, i) &&
1246 (ic = hTabItemWithKey (iCodehTab, i)) &&
1247 (ic->seq >= fseq && ic->seq <= toseq))
1257 /*-----------------------------------------------------------------*/
1258 /* computeSpillable - given a point find the spillable live ranges */
1259 /*-----------------------------------------------------------------*/
1261 computeSpillable (iCode * ic)
1265 debugLog ("%s\n", __FUNCTION__);
1266 /* spillable live ranges are those that are live at this
1267 point . the following categories need to be subtracted
1269 a) - those that are already spilt
1270 b) - if being used by this one
1271 c) - defined by this one */
1273 spillable = bitVectCopy (ic->rlive);
1275 bitVectCplAnd (spillable, _G.spiltSet); /* those already spilt */
1277 bitVectCplAnd (spillable, ic->uses); /* used in this one */
1278 bitVectUnSetBit (spillable, ic->defKey);
1279 spillable = bitVectIntersect (spillable, _G.regAssigned);
1284 /*-----------------------------------------------------------------*/
1285 /* noSpilLoc - return true if a variable has no spil location */
1286 /*-----------------------------------------------------------------*/
1288 noSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
1290 debugLog ("%s\n", __FUNCTION__);
1291 return (sym->usl.spillLoc ? 0 : 1);
1294 /*-----------------------------------------------------------------*/
1295 /* hasSpilLoc - will return 1 if the symbol has spil location */
1296 /*-----------------------------------------------------------------*/
1298 hasSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
1300 debugLog ("%s\n", __FUNCTION__);
1301 return (sym->usl.spillLoc ? 1 : 0);
1304 /*-----------------------------------------------------------------*/
1305 /* directSpilLoc - will return 1 if the splilocation is in direct */
1306 /*-----------------------------------------------------------------*/
1308 directSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
1310 debugLog ("%s\n", __FUNCTION__);
1311 if (sym->usl.spillLoc &&
1312 (IN_DIRSPACE (SPEC_OCLS (sym->usl.spillLoc->etype))))
1318 /*-----------------------------------------------------------------*/
1319 /* hasSpilLocnoUptr - will return 1 if the symbol has spil location */
1320 /* but is not used as a pointer */
1321 /*-----------------------------------------------------------------*/
1323 hasSpilLocnoUptr (symbol * sym, eBBlock * ebp, iCode * ic)
1325 debugLog ("%s\n", __FUNCTION__);
1326 return ((sym->usl.spillLoc && !sym->uptr) ? 1 : 0);
1329 /*-----------------------------------------------------------------*/
1330 /* rematable - will return 1 if the remat flag is set */
1331 /*-----------------------------------------------------------------*/
1333 rematable (symbol * sym, eBBlock * ebp, iCode * ic)
1335 debugLog ("%s\n", __FUNCTION__);
1339 /*-----------------------------------------------------------------*/
1340 /* notUsedInRemaining - not used or defined in remain of the block */
1341 /*-----------------------------------------------------------------*/
1343 notUsedInRemaining (symbol * sym, eBBlock * ebp, iCode * ic)
1345 debugLog ("%s\n", __FUNCTION__);
1346 return ((usedInRemaining (operandFromSymbol (sym), ic) ? 0 : 1) &&
1347 allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq));
1350 /*-----------------------------------------------------------------*/
1351 /* allLRs - return true for all */
1352 /*-----------------------------------------------------------------*/
1354 allLRs (symbol * sym, eBBlock * ebp, iCode * ic)
1356 debugLog ("%s\n", __FUNCTION__);
1360 /*-----------------------------------------------------------------*/
1361 /* liveRangesWith - applies function to a given set of live range */
1362 /*-----------------------------------------------------------------*/
1364 liveRangesWith (bitVect * lrs, int (func) (symbol *, eBBlock *, iCode *),
1365 eBBlock * ebp, iCode * ic)
1370 debugLog ("%s\n", __FUNCTION__);
1371 if (!lrs || !lrs->size)
1374 for (i = 1; i < lrs->size; i++)
1377 if (!bitVectBitValue (lrs, i))
1380 /* if we don't find it in the live range
1381 hash table we are in serious trouble */
1382 if (!(sym = hTabItemWithKey (liveRanges, i)))
1384 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
1385 "liveRangesWith could not find liveRange");
1389 if (func (sym, ebp, ic) && bitVectBitValue (_G.regAssigned, sym->key))
1390 addSetHead (&rset, sym);
1397 /*-----------------------------------------------------------------*/
1398 /* leastUsedLR - given a set determines which is the least used */
1399 /*-----------------------------------------------------------------*/
1401 leastUsedLR (set * sset)
1403 symbol *sym = NULL, *lsym = NULL;
1405 debugLog ("%s\n", __FUNCTION__);
1406 sym = lsym = setFirstItem (sset);
1411 for (; lsym; lsym = setNextItem (sset))
1414 /* if usage is the same then prefer
1415 the spill the smaller of the two */
1416 if (lsym->used == sym->used)
1417 if (getSize (lsym->type) < getSize (sym->type))
1421 if (lsym->used < sym->used)
1426 setToNull ((void *) &sset);
1431 /*-----------------------------------------------------------------*/
1432 /* noOverLap - will iterate through the list looking for over lap */
1433 /*-----------------------------------------------------------------*/
1435 noOverLap (set * itmpStack, symbol * fsym)
1438 debugLog ("%s\n", __FUNCTION__);
1441 for (sym = setFirstItem (itmpStack); sym;
1442 sym = setNextItem (itmpStack))
1444 if (sym->liveTo > fsym->liveFrom)
1452 /*-----------------------------------------------------------------*/
1453 /* isFree - will return 1 if the a free spil location is found */
1454 /*-----------------------------------------------------------------*/
1459 V_ARG (symbol **, sloc);
1460 V_ARG (symbol *, fsym);
1462 debugLog ("%s\n", __FUNCTION__);
1463 /* if already found */
1467 /* if it is free && and the itmp assigned to
1468 this does not have any overlapping live ranges
1469 with the one currently being assigned and
1470 the size can be accomodated */
1472 noOverLap (sym->usl.itmpStack, fsym) &&
1473 getSize (sym->type) >= getSize (fsym->type))
1482 /*-----------------------------------------------------------------*/
1483 /* spillLRWithPtrReg :- will spil those live ranges which use PTR */
1484 /*-----------------------------------------------------------------*/
1486 spillLRWithPtrReg (symbol * forSym)
1492 debugLog ("%s\n", __FUNCTION__);
1493 if (!_G.regAssigned ||
1494 bitVectIsZero (_G.regAssigned))
1497 r0 = pic14_regWithIdx (R0_IDX);
1498 r1 = pic14_regWithIdx (R1_IDX);
1500 /* for all live ranges */
1501 for (lrsym = hTabFirstItem (liveRanges, &k); lrsym;
1502 lrsym = hTabNextItem (liveRanges, &k))
1506 /* if no registers assigned to it or
1508 /* if it does not overlap with this then
1509 not need to spill it */
1511 if (lrsym->isspilt || !lrsym->nRegs ||
1512 (lrsym->liveTo < forSym->liveFrom))
1515 /* go thru the registers : if it is either
1516 r0 or r1 then spil it */
1517 for (j = 0; j < lrsym->nRegs; j++)
1518 if (lrsym->regs[j] == r0 ||
1519 lrsym->regs[j] == r1)
1528 /*-----------------------------------------------------------------*/
1529 /* createStackSpil - create a location on the stack to spil */
1530 /*-----------------------------------------------------------------*/
1532 createStackSpil (symbol * sym)
1534 symbol *sloc = NULL;
1535 int useXstack, model, noOverlay;
1537 char slocBuffer[30];
1538 debugLog ("%s\n", __FUNCTION__);
1542 /* first go try and find a free one that is already
1543 existing on the stack */
1544 if (applyToSet (_G.stackSpil, isFree, &sloc, sym))
1546 /* found a free one : just update & return */
1547 sym->usl.spillLoc = sloc;
1550 addSetHead (&sloc->usl.itmpStack, sym);
1554 /* could not then have to create one , this is the hard part
1555 we need to allocate this on the stack : this is really a
1556 hack!! but cannot think of anything better at this time */
1558 if (sprintf (slocBuffer, "sloc%d", _G.slocNum++) >= sizeof (slocBuffer))
1560 fprintf (stderr, "kkkInternal error: slocBuffer overflowed: %s:%d\n",
1561 __FILE__, __LINE__);
1565 sloc = newiTemp (slocBuffer);
1567 /* set the type to the spilling symbol */
1568 sloc->type = copyLinkChain (sym->type);
1569 sloc->etype = getSpec (sloc->type);
1570 SPEC_SCLS (sloc->etype) = S_DATA;
1571 SPEC_EXTR (sloc->etype) = 0;
1572 SPEC_STAT (sloc->etype) = 0;
1574 /* we don't allow it to be allocated`
1575 onto the external stack since : so we
1576 temporarily turn it off ; we also
1577 turn off memory model to prevent
1578 the spil from going to the external storage
1579 and turn off overlaying
1582 useXstack = options.useXstack;
1583 model = options.model;
1584 noOverlay = options.noOverlay;
1585 options.noOverlay = 1;
1586 options.model = options.useXstack = 0;
1590 options.useXstack = useXstack;
1591 options.model = model;
1592 options.noOverlay = noOverlay;
1593 sloc->isref = 1; /* to prevent compiler warning */
1595 /* if it is on the stack then update the stack */
1596 if (IN_STACK (sloc->etype))
1598 currFunc->stack += getSize (sloc->type);
1599 _G.stackExtend += getSize (sloc->type);
1602 _G.dataExtend += getSize (sloc->type);
1604 /* add it to the _G.stackSpil set */
1605 addSetHead (&_G.stackSpil, sloc);
1606 sym->usl.spillLoc = sloc;
1609 /* add it to the set of itempStack set
1610 of the spill location */
1611 addSetHead (&sloc->usl.itmpStack, sym);
1615 /*-----------------------------------------------------------------*/
1616 /* isSpiltOnStack - returns true if the spil location is on stack */
1617 /*-----------------------------------------------------------------*/
1619 isSpiltOnStack (symbol * sym)
1623 debugLog ("%s\n", __FUNCTION__);
1632 /* if (sym->_G.stackSpil) */
1635 if (!sym->usl.spillLoc)
1638 etype = getSpec (sym->usl.spillLoc->type);
1639 if (IN_STACK (etype))
1645 /*-----------------------------------------------------------------*/
1646 /* spillThis - spils a specific operand */
1647 /*-----------------------------------------------------------------*/
1649 spillThis (symbol * sym)
1652 debugLog ("%s : %s\n", __FUNCTION__, sym->rname);
1653 FENTRY2("sym: %s, spillLoc:%p (%s)\n", sym->rname, sym->usl.spillLoc, sym->usl.spillLoc ? sym->usl.spillLoc->rname : "<unknown>");
1655 /* if this is rematerializable or has a spillLocation
1656 we are okay, else we need to create a spillLocation
1658 if (!(sym->remat || sym->usl.spillLoc))
1659 createStackSpil (sym);
1662 /* mark it has spilt & put it in the spilt set */
1664 _G.spiltSet = bitVectSetBit (_G.spiltSet, sym->key);
1666 bitVectUnSetBit (_G.regAssigned, sym->key);
1668 for (i = 0; i < sym->nRegs; i++)
1672 freeReg (sym->regs[i]);
1673 sym->regs[i] = NULL;
1677 /* if spilt on stack then free up r0 & r1
1678 if they could have been assigned to some
1680 if (!pic14_ptrRegReq && isSpiltOnStack (sym))
1683 spillLRWithPtrReg (sym);
1686 if (sym->usl.spillLoc && !sym->remat)
1687 sym->usl.spillLoc->allocreq = 1;
1692 /*-----------------------------------------------------------------*/
1693 /* selectSpil - select a iTemp to spil : rather a simple procedure */
1694 /*-----------------------------------------------------------------*/
1696 selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
1698 bitVect *lrcs = NULL;
1702 debugLog ("%s\n", __FUNCTION__);
1704 /* get the spillable live ranges */
1705 lrcs = computeSpillable (ic);
1708 /* get all live ranges that are rematerizable */
1709 if ((selectS = liveRangesWith (lrcs, rematable, ebp, ic)))
1711 /* return the least used of these */
1712 return leastUsedLR (selectS);
1715 /* get live ranges with spillLocations in direct space */
1716 if ((selectS = liveRangesWith (lrcs, directSpilLoc, ebp, ic)))
1718 sym = leastUsedLR (selectS);
1719 strcpy (sym->rname, (sym->usl.spillLoc->rname[0] ?
1720 sym->usl.spillLoc->rname :
1721 sym->usl.spillLoc->name));
1723 /* mark it as allocation required */
1724 sym->usl.spillLoc->allocreq = 1;
1728 /* if the symbol is local to the block then */
1729 if (forSym->liveTo < ebp->lSeq)
1732 /* check if there are any live ranges allocated
1733 to registers that are not used in this block */
1734 if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInBlock, ebp, ic)))
1736 sym = leastUsedLR (selectS);
1737 /* if this is not rematerializable */
1746 /* check if there are any live ranges that not
1747 used in the remainder of the block */
1748 if (!_G.blockSpil &&
1749 !isiCodeInFunctionCall (ic) &&
1750 (selectS = liveRangesWith (lrcs, notUsedInRemaining, ebp, ic)))
1752 sym = leastUsedLR (selectS);
1755 sym->remainSpil = 1;
1762 /* find live ranges with spillocation && not used as pointers */
1763 if ((selectS = liveRangesWith (lrcs, hasSpilLocnoUptr, ebp, ic)))
1766 sym = leastUsedLR (selectS);
1767 /* mark this as allocation required */
1768 sym->usl.spillLoc->allocreq = 1;
1772 /* find live ranges with spillocation */
1773 if ((selectS = liveRangesWith (lrcs, hasSpilLoc, ebp, ic)))
1776 sym = leastUsedLR (selectS);
1777 sym->usl.spillLoc->allocreq = 1;
1781 /* couldn't find then we need to create a spil
1782 location on the stack , for which one? the least
1784 if ((selectS = liveRangesWith (lrcs, noSpilLoc, ebp, ic)))
1787 /* return a created spil location */
1788 sym = createStackSpil (leastUsedLR (selectS));
1789 sym->usl.spillLoc->allocreq = 1;
1793 /* this is an extreme situation we will spill
1794 this one : happens very rarely but it does happen */
1800 /*-----------------------------------------------------------------*/
1801 /* spilSomething - spil some variable & mark registers as free */
1802 /*-----------------------------------------------------------------*/
1804 spilSomething (iCode * ic, eBBlock * ebp, symbol * forSym)
1809 debugLog ("%s\n", __FUNCTION__);
1810 /* get something we can spil */
1811 ssym = selectSpil (ic, ebp, forSym);
1813 /* mark it as spilt */
1815 _G.spiltSet = bitVectSetBit (_G.spiltSet, ssym->key);
1817 /* mark it as not register assigned &
1818 take it away from the set */
1819 bitVectUnSetBit (_G.regAssigned, ssym->key);
1821 /* mark the registers as free */
1822 for (i = 0; i < ssym->nRegs; i++)
1824 freeReg (ssym->regs[i]);
1826 /* if spilt on stack then free up r0 & r1
1827 if they could have been assigned to as gprs */
1828 if (!pic14_ptrRegReq && isSpiltOnStack (ssym))
1831 spillLRWithPtrReg (ssym);
1834 /* if this was a block level spil then insert push & pop
1835 at the start & end of block respectively */
1836 if (ssym->blockSpil)
1838 iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
1839 /* add push to the start of the block */
1840 addiCodeToeBBlock (ebp, nic, (ebp->sch->op == LABEL ?
1841 ebp->sch->next : ebp->sch));
1842 nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
1843 /* add pop to the end of the block */
1844 addiCodeToeBBlock (ebp, nic, NULL);
1847 /* if spilt because not used in the remainder of the
1848 block then add a push before this instruction and
1849 a pop at the end of the block */
1850 if (ssym->remainSpil)
1853 iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
1854 /* add push just before this instruction */
1855 addiCodeToeBBlock (ebp, nic, ic);
1857 nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
1858 /* add pop to the end of the block */
1859 addiCodeToeBBlock (ebp, nic, NULL);
1868 /*-----------------------------------------------------------------*/
1869 /* getRegPtr - will try for PTR if not a GPR type if not spil */
1870 /*-----------------------------------------------------------------*/
1872 getRegPtr (iCode * ic, eBBlock * ebp, symbol * sym)
1877 debugLog ("%s\n", __FUNCTION__);
1879 /* try for a ptr type */
1880 if ((reg = allocReg (REG_PTR)))
1883 /* try for gpr type */
1884 if ((reg = allocReg (REG_GPR)))
1887 /* we have to spil */
1888 if (!spilSomething (ic, ebp, sym))
1891 /* make sure partially assigned registers aren't reused */
1892 for (j=0; j<=sym->nRegs; j++)
1894 sym->regs[j]->isFree = 0;
1896 /* this looks like an infinite loop but
1897 in really selectSpil will abort */
1901 /*-----------------------------------------------------------------*/
1902 /* getRegGpr - will try for GPR if not spil */
1903 /*-----------------------------------------------------------------*/
1905 getRegGpr (iCode * ic, eBBlock * ebp, symbol * sym)
1910 debugLog ("%s\n", __FUNCTION__);
1912 /* try for gpr type */
1913 if ((reg = allocReg (REG_GPR)))
1916 if (!pic14_ptrRegReq)
1917 if ((reg = allocReg (REG_PTR)))
1920 /* we have to spil */
1921 if (!spilSomething (ic, ebp, sym))
1924 /* make sure partially assigned registers aren't reused */
1925 for (j=0; j<=sym->nRegs; j++)
1927 sym->regs[j]->isFree = 0;
1929 /* this looks like an infinite loop but
1930 in really selectSpil will abort */
1934 /*-----------------------------------------------------------------*/
1935 /* symHasReg - symbol has a given register */
1936 /*-----------------------------------------------------------------*/
1938 symHasReg (symbol * sym, regs * reg)
1942 debugLog ("%s\n", __FUNCTION__);
1943 for (i = 0; i < sym->nRegs; i++)
1944 if (sym->regs[i] == reg)
1950 /*-----------------------------------------------------------------*/
1951 /* deassignLRs - check the live to and if they have registers & are */
1952 /* not spilt then free up the registers */
1953 /*-----------------------------------------------------------------*/
1955 deassignLRs (iCode * ic, eBBlock * ebp)
1961 debugLog ("%s\n", __FUNCTION__);
1962 for (sym = hTabFirstItem (liveRanges, &k); sym;
1963 sym = hTabNextItem (liveRanges, &k))
1966 symbol *psym = NULL;
1967 /* if it does not end here */
1968 if (sym->liveTo > ic->seq)
1971 /* Prevent the result from being assigned the same registers as (one)
1972 * operand as many genXXX-functions fail otherwise.
1973 * POINTER_GET(ic) || ic->op == LEFT_OP || ic->op == RIGHT_OP || ic->op == NOT
1974 * are known to fail. */
1975 if (sym->liveTo == ic->seq && IC_RESULT(ic))
1979 case '=': /* assignment */
1980 case BITWISEAND: /* bitwise AND */
1981 case '|': /* bitwise OR */
1982 case '^': /* bitwise XOR */
1983 case '~': /* bitwise negate */
1984 case RLC: /* rotate through carry */
1987 case '+': /* addition */
1988 case '-': /* subtraction */
1989 /* go ahead, these are safe to use with
1990 * non-disjoint register sets */
1994 /* do not release operand registers */
1995 //fprintf (stderr, "%s:%u: operand not freed: ", __FILE__, __LINE__); piCode (ic, stderr); fprintf (stderr, "\n");
2000 /* if it was spilt on stack then we can
2001 mark the stack spil location as free */
2006 sym->usl.spillLoc->isFree = 1;
2012 if (!bitVectBitValue (_G.regAssigned, sym->key))
2014 /* special case check if this is an IFX &
2015 the privious one was a pop and the
2016 previous one was not spilt then keep track
2018 if (ic->op == IFX && ic->prev &&
2019 ic->prev->op == IPOP &&
2020 !ic->prev->parmPush &&
2021 IS_SYMOP(IC_LEFT (ic->prev)) &&
2022 !OP_SYMBOL (IC_LEFT (ic->prev))->isspilt)
2023 psym = OP_SYMBOL (IC_LEFT (ic->prev));
2029 bitVectUnSetBit (_G.regAssigned, sym->key);
2031 /* if the result of this one needs registers
2032 and does not have it then assign it right
2034 if (IC_RESULT (ic) &&
2035 !(SKIP_IC2 (ic) || /* not a special icode */
2036 ic->op == JUMPTABLE ||
2041 POINTER_SET (ic)) &&
2042 IS_SYMOP (IC_RESULT (ic)) &&
2043 (result = OP_SYMBOL (IC_RESULT (ic))) && /* has a result */
2044 result->liveTo > ic->seq && /* and will live beyond this */
2045 result->liveTo <= ebp->lSeq && /* does not go beyond this block */
2046 result->liveFrom == ic->seq && /* does not start before here */
2047 result->regType == sym->regType && /* same register types */
2048 result->regType == sym->regType && /* same register types */
2049 result->nRegs && /* which needs registers */
2050 !result->isspilt && /* and does not already have them */
2052 !bitVectBitValue (_G.regAssigned, result->key) &&
2053 /* the number of free regs + number of regs in this LR
2054 can accomodate the what result Needs */
2055 ((nfreeRegsType (result->regType) +
2056 sym->nRegs) >= result->nRegs)
2060 for (i = 0; i < max (sym->nRegs, result->nRegs); i++)
2062 result->regs[i] = sym->regs[i];
2064 result->regs[i] = getRegGpr (ic, ebp, result);
2066 _G.regAssigned = bitVectSetBit (_G.regAssigned, result->key);
2070 /* free the remaining */
2071 for (; i < sym->nRegs; i++)
2075 if (!symHasReg (psym, sym->regs[i]))
2076 freeReg (sym->regs[i]);
2079 freeReg (sym->regs[i]);
2086 /*-----------------------------------------------------------------*/
2087 /* reassignLR - reassign this to registers */
2088 /*-----------------------------------------------------------------*/
2090 reassignLR (operand * op)
2092 symbol *sym = OP_SYMBOL (op);
2095 debugLog ("%s\n", __FUNCTION__);
2096 /* not spilt any more */
2097 sym->isspilt = sym->blockSpil = sym->remainSpil = 0;
2098 bitVectUnSetBit (_G.spiltSet, sym->key);
2100 _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
2104 for (i = 0; i < sym->nRegs; i++)
2105 sym->regs[i]->isFree = 0;
2108 /*-----------------------------------------------------------------*/
2109 /* willCauseSpill - determines if allocating will cause a spill */
2110 /*-----------------------------------------------------------------*/
2112 willCauseSpill (int nr, int rt)
2114 debugLog ("%s\n", __FUNCTION__);
2115 /* first check if there are any avlb registers
2116 of te type required */
2119 /* special case for pointer type
2120 if pointer type not avlb then
2121 check for type gpr */
2122 if (nFreeRegs (rt) >= nr)
2124 if (nFreeRegs (REG_GPR) >= nr)
2129 if (pic14_ptrRegReq)
2131 if (nFreeRegs (rt) >= nr)
2136 if (nFreeRegs (REG_PTR) +
2137 nFreeRegs (REG_GPR) >= nr)
2142 debugLog (" ... yep it will (cause a spill)\n");
2143 /* it will cause a spil */
2147 /*-----------------------------------------------------------------*/
2148 /* positionRegs - the allocator can allocate same registers to res- */
2149 /* ult and operand, if this happens make sure they are in the same */
2150 /* position as the operand otherwise chaos results */
2151 /*-----------------------------------------------------------------*/
2153 positionRegs (symbol * result, symbol * opsym, int lineno)
2155 int count = min (result->nRegs, opsym->nRegs);
2156 int i, j = 0, shared = 0;
2158 debugLog ("%s\n", __FUNCTION__);
2159 /* if the result has been spilt then cannot share */
2164 /* first make sure that they actually share */
2165 for (i = 0; i < count; i++)
2167 for (j = 0; j < count; j++)
2169 if (result->regs[i] == opsym->regs[j] && i != j)
2179 regs *tmp = result->regs[i];
2180 result->regs[i] = result->regs[j];
2181 result->regs[j] = tmp;
2186 /*------------------------------------------------------------------*/
2187 /* verifyRegsAssigned - make sure an iTemp is properly initialized; */
2188 /* it should either have registers or have beed spilled. Otherwise, */
2189 /* there was an uninitialized variable, so just spill this to get */
2190 /* the operand in a valid state. */
2191 /*------------------------------------------------------------------*/
2193 verifyRegsAssigned (operand *op, iCode * ic)
2198 if (!IS_ITEMP (op)) return;
2200 sym = OP_SYMBOL (op);
2201 if (sym->isspilt) return;
2202 if (!sym->nRegs) return;
2203 if (sym->regs[0]) return;
2205 werrorfl (ic->filename, ic->lineno, W_LOCAL_NOINIT,
2206 sym->prereqv ? sym->prereqv->name : sym->name);
2211 /*-----------------------------------------------------------------*/
2212 /* serialRegAssign - serially allocate registers to the variables */
2213 /*-----------------------------------------------------------------*/
2215 serialRegAssign (eBBlock ** ebbs, int count)
2219 debugLog ("%s\n", __FUNCTION__);
2220 /* for all blocks */
2221 for (i = 0; i < count; i++)
2226 if (ebbs[i]->noPath &&
2227 (ebbs[i]->entryLabel != entryLabel &&
2228 ebbs[i]->entryLabel != returnLabel))
2231 /* of all instructions do */
2232 for (ic = ebbs[i]->sch; ic; ic = ic->next)
2234 debugLog (" op: %s\n", decodeOp (ic->op));
2236 /* if this is an ipop that means some live
2237 range will have to be assigned again */
2239 reassignLR (IC_LEFT (ic));
2241 /* if result is present && is a true symbol */
2242 if (IC_RESULT (ic) && ic->op != IFX &&
2243 IS_TRUE_SYMOP (IC_RESULT (ic)))
2244 OP_SYMBOL (IC_RESULT (ic))->allocreq = 1;
2246 /* take away registers from live
2247 ranges that end at this instruction */
2248 deassignLRs (ic, ebbs[i]);
2250 /* some don't need registers */
2251 if (SKIP_IC2 (ic) ||
2252 ic->op == JUMPTABLE ||
2256 (IC_RESULT (ic) && POINTER_SET (ic)))
2259 /* now we need to allocate registers
2260 only for the result */
2261 if (IC_RESULT (ic) && IS_SYMOP (IC_RESULT (ic)))
2263 symbol *sym = OP_SYMBOL (IC_RESULT (ic));
2269 /* Make sure any spill location is definately allocated */
2270 if (sym->isspilt && !sym->remat && sym->usl.spillLoc &&
2271 !sym->usl.spillLoc->allocreq)
2273 sym->usl.spillLoc->allocreq++;
2276 /* if it does not need or is spilt
2277 or is already assigned to registers
2278 or will not live beyond this instructions */
2281 bitVectBitValue (_G.regAssigned, sym->key) ||
2282 sym->liveTo <= ic->seq)
2285 /* if some liverange has been spilt at the block level
2286 and this one live beyond this block then spil this
2288 if (_G.blockSpil && sym->liveTo > ebbs[i]->lSeq)
2293 /* if trying to allocate this will cause
2294 a spill and there is nothing to spill
2295 or this one is rematerializable then
2297 willCS = willCauseSpill (sym->nRegs, sym->regType);
2298 spillable = computeSpillable (ic);
2300 (willCS && bitVectIsZero (spillable)))
2308 /* If the live range preceeds the point of definition
2309 then ideally we must take into account registers that
2310 have been allocated after sym->liveFrom but freed
2311 before ic->seq. This is complicated, so spill this
2312 symbol instead and let fillGaps handle the allocation. */
2313 if (sym->liveFrom < ic->seq)
2319 /* if it has a spillocation & is used less than
2320 all other live ranges then spill this */
2322 if (sym->usl.spillLoc) {
2323 symbol *leastUsed = leastUsedLR (liveRangesWith (spillable,
2324 allLRs, ebbs[i], ic));
2325 if (leastUsed && leastUsed->used > sym->used) {
2330 /* if none of the liveRanges have a spillLocation then better
2331 to spill this one than anything else already assigned to registers */
2332 if (liveRangesWith(spillable,noSpilLoc,ebbs[i],ic)) {
2333 /* if this is local to this block then we might find a block spil */
2334 if (!(sym->liveFrom >= ebbs[i]->fSeq && sym->liveTo <= ebbs[i]->lSeq)) {
2342 if (ic->op == RECEIVE)
2343 debugLog ("When I get clever, I'll optimize the receive logic\n");
2345 /* if we need ptr regs for the right side
2347 if (POINTER_GET (ic)
2348 && IS_SYMOP(IC_LEFT(ic))
2349 && getSize (OP_SYMBOL (IC_LEFT (ic))->type)
2350 <= (unsigned) PTRSIZE)
2355 /* else we assign registers to it */
2356 _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
2358 debugLog (" %d - \n", __LINE__);
2360 bitVectDebugOn(_G.regAssigned, debugF);
2361 for (j = 0; j < sym->nRegs; j++)
2363 if (sym->regType == REG_PTR)
2364 sym->regs[j] = getRegPtr (ic, ebbs[i], sym);
2366 sym->regs[j] = getRegGpr (ic, ebbs[i], sym);
2368 /* if the allocation failed which means
2369 this was spilt then break */
2373 debugLog (" %d - \n", __LINE__);
2375 /* if it shares registers with operands make sure
2376 that they are in the same position */
2377 if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)) &&
2378 IS_SYMOP(IC_RESULT(ic)) &&
2379 OP_SYMBOL (IC_LEFT (ic))->nRegs && ic->op != '=')
2380 positionRegs (OP_SYMBOL (IC_RESULT (ic)),
2381 OP_SYMBOL (IC_LEFT (ic)), ic->lineno);
2382 /* do the same for the right operand */
2383 if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)) &&
2384 IS_SYMOP(IC_RESULT(ic)) &&
2385 OP_SYMBOL (IC_RIGHT (ic))->nRegs && ic->op != '=')
2386 positionRegs (OP_SYMBOL (IC_RESULT (ic)),
2387 OP_SYMBOL (IC_RIGHT (ic)), ic->lineno);
2389 debugLog (" %d - \n", __LINE__);
2392 debugLog (" %d - \n", __LINE__);
2401 /* Check for and fix any problems with uninitialized operands */
2402 for (i = 0; i < count; i++)
2406 if (ebbs[i]->noPath &&
2407 (ebbs[i]->entryLabel != entryLabel &&
2408 ebbs[i]->entryLabel != returnLabel))
2411 for (ic = ebbs[i]->sch; ic; ic = ic->next)
2418 verifyRegsAssigned (IC_COND (ic), ic);
2422 if (ic->op == JUMPTABLE)
2424 verifyRegsAssigned (IC_JTCOND (ic), ic);
2428 verifyRegsAssigned (IC_RESULT (ic), ic);
2429 verifyRegsAssigned (IC_LEFT (ic), ic);
2430 verifyRegsAssigned (IC_RIGHT (ic), ic);
2436 /*-----------------------------------------------------------------*/
2437 /* rUmaskForOp :- returns register mask for an operand */
2438 /*-----------------------------------------------------------------*/
2440 rUmaskForOp (operand * op)
2446 debugLog ("%s\n", __FUNCTION__);
2447 /* only temporaries are assigned registers */
2451 sym = OP_SYMBOL (op);
2453 /* if spilt or no registers assigned to it
2455 if (sym->isspilt || !sym->nRegs)
2458 rumask = newBitVect (pic14_nRegs);
2460 for (j = 0; j < sym->nRegs; j++)
2462 rumask = bitVectSetBit (rumask,
2463 sym->regs[j]->rIdx);
2469 /*-----------------------------------------------------------------*/
2470 /* regsUsedIniCode :- returns bit vector of registers used in iCode */
2471 /*-----------------------------------------------------------------*/
2473 regsUsedIniCode (iCode * ic)
2475 bitVect *rmask = newBitVect (pic14_nRegs);
2477 debugLog ("%s\n", __FUNCTION__);
2478 /* do the special cases first */
2481 rmask = bitVectUnion (rmask,
2482 rUmaskForOp (IC_COND (ic)));
2486 /* for the jumptable */
2487 if (ic->op == JUMPTABLE)
2489 rmask = bitVectUnion (rmask,
2490 rUmaskForOp (IC_JTCOND (ic)));
2495 /* of all other cases */
2497 rmask = bitVectUnion (rmask,
2498 rUmaskForOp (IC_LEFT (ic)));
2502 rmask = bitVectUnion (rmask,
2503 rUmaskForOp (IC_RIGHT (ic)));
2506 rmask = bitVectUnion (rmask,
2507 rUmaskForOp (IC_RESULT (ic)));
2513 /*-----------------------------------------------------------------*/
2514 /* createRegMask - for each instruction will determine the regsUsed */
2515 /*-----------------------------------------------------------------*/
2517 createRegMask (eBBlock ** ebbs, int count)
2521 debugLog ("%s\n", __FUNCTION__);
2522 /* for all blocks */
2523 for (i = 0; i < count; i++)
2527 if (ebbs[i]->noPath &&
2528 (ebbs[i]->entryLabel != entryLabel &&
2529 ebbs[i]->entryLabel != returnLabel))
2532 /* for all instructions */
2533 for (ic = ebbs[i]->sch; ic; ic = ic->next)
2538 if (SKIP_IC2 (ic) || !ic->rlive)
2541 /* first mark the registers used in this
2543 ic->rUsed = regsUsedIniCode (ic);
2544 _G.funcrUsed = bitVectUnion (_G.funcrUsed, ic->rUsed);
2546 /* now create the register mask for those
2547 registers that are in use : this is a
2548 super set of ic->rUsed */
2549 ic->rMask = newBitVect (pic14_nRegs + 1);
2551 /* for all live Ranges alive at this point */
2552 for (j = 1; j < ic->rlive->size; j++)
2557 /* if not alive then continue */
2558 if (!bitVectBitValue (ic->rlive, j))
2561 /* find the live range we are interested in */
2562 if (!(sym = hTabItemWithKey (liveRanges, j)))
2564 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
2565 "createRegMask cannot find live range");
2569 /* if no register assigned to it */
2570 if (!sym->nRegs || sym->isspilt)
2573 /* for all the registers allocated to it */
2574 for (k = 0; k < sym->nRegs; k++)
2577 bitVectSetBit (ic->rMask, sym->regs[k]->rIdx);
2583 /* This was the active version */
2584 /*-----------------------------------------------------------------*/
2585 /* rematStr - returns the rematerialized string for a remat var */
2586 /*-----------------------------------------------------------------*/
2588 rematStr (symbol * sym)
2591 iCode *ic = sym->rematiCode;
2592 symbol *psym = NULL;
2594 debugLog ("%s\n", __FUNCTION__);
2596 //printf ("%s\n", s);
2598 /* if plus or minus print the right hand side */
2600 if (ic->op == '+' || ic->op == '-') {
2602 iCode *ric = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
2604 sprintf (s, "(%s %c 0x%04x)",
2605 OP_SYMBOL (IC_LEFT (ric))->rname,
2607 (int) operandLitValue (IC_RIGHT (ic)));
2610 //fprintf(stderr, "ralloc.c:%d OOPS %s\n",__LINE__,s);
2612 psym = newSymbol (OP_SYMBOL (IC_LEFT (ric))->rname, 1);
2613 psym->offset = (int) operandLitValue (IC_RIGHT (ic));
2618 sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
2619 psym = newSymbol (OP_SYMBOL (IC_LEFT (ic))->rname, 1);
2621 //printf ("ralloc.c:%d %s\n", __LINE__,buffer);
2627 /* deprecated version */
2628 /*-----------------------------------------------------------------*/
2629 /* rematStr - returns the rematerialized string for a remat var */
2630 /*-----------------------------------------------------------------*/
2632 rematStr (symbol * sym)
2635 iCode *ic = sym->rematiCode;
2637 debugLog ("%s\n", __FUNCTION__);
2642 /* if plus or minus print the right hand side */
2644 if (ic->op == '+' || ic->op == '-') {
2645 sprintf(s,"0x%04x %c ",(int) operandLitValue(IC_RIGHT(ic)),
2648 ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
2652 if (ic->op == '+' || ic->op == '-')
2654 iCode *ric = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
2655 sprintf (s, "(%s %c 0x%04x)",
2656 OP_SYMBOL (IC_LEFT (ric))->rname,
2658 (int) operandLitValue (IC_RIGHT (ic)));
2661 //ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
2663 //fprintf(stderr, "ralloc.c:%d OOPS %s\n",__LINE__,s);
2667 /* we reached the end */
2668 sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
2672 printf ("%s\n", buffer);
2677 /*-----------------------------------------------------------------*/
2678 /* regTypeNum - computes the type & number of registers required */
2679 /*-----------------------------------------------------------------*/
2687 debugLog ("%s\n", __FUNCTION__);
2688 /* for each live range do */
2689 for (sym = hTabFirstItem (liveRanges, &k); sym;
2690 sym = hTabNextItem (liveRanges, &k)) {
2692 debugLog (" %d - %s\n", __LINE__, sym->rname);
2694 /* if used zero times then no registers needed */
2695 if ((sym->liveTo - sym->liveFrom) == 0)
2699 /* if the live range is a temporary */
2702 debugLog (" %d - itemp register\n", __LINE__);
2704 /* if the type is marked as a conditional */
2705 if (sym->regType == REG_CND)
2708 /* if used in return only then we don't
2711 if (IS_AGGREGATE (sym->type) || sym->isptr)
2712 sym->type = aggrToPtr (sym->type, FALSE);
2713 debugLog (" %d - no reg needed - accumulator used\n", __LINE__);
2719 //if (IS_AGGREGATE (sym->type) || sym->isptr)
2720 // sym->type = aggrToPtr (sym->type, FALSE);
2721 debugLog (" %d - used as a return\n", __LINE__);
2726 /* if the symbol has only one definition &
2727 that definition is a get_pointer and the
2728 pointer we are getting is rematerializable and
2732 if (bitVectnBitsOn (sym->defs) == 1 &&
2733 (ic = hTabItemWithKey (iCodehTab,
2734 bitVectFirstBit (sym->defs))) &&
2736 !IS_BITVAR (sym->etype) &&
2737 (aggrToPtrDclType (operandType (IC_LEFT (ic)), FALSE) == POINTER)) {
2739 if (ptrPseudoSymSafe (sym, ic)) {
2743 debugLog (" %d - \n", __LINE__);
2745 /* create a pseudo symbol & force a spil */
2746 //X symbol *psym = newSymbol (rematStr (OP_SYMBOL (IC_LEFT (ic))), 1);
2747 psym = rematStr (OP_SYMBOL (IC_LEFT (ic)));
2748 psym->type = sym->type;
2749 psym->etype = sym->etype;
2750 psym->psbase = ptrBaseRematSym (OP_SYMBOL (IC_LEFT (ic)));
2751 strcpy (psym->rname, psym->name);
2753 sym->usl.spillLoc = psym;
2757 /* if in data space or idata space then try to
2758 allocate pointer register */
2763 /* if not then we require registers */
2764 sym->nRegs = ((IS_AGGREGATE (sym->type) || sym->isptr) ?
2765 getSize (sym->type = aggrToPtr (sym->type, FALSE)) :
2766 getSize (sym->type));
2769 if(IS_PTR_CONST (sym->type)) {
2770 debugLog (" %d const pointer type requires %d registers, changing to 2\n",__LINE__,sym->nRegs);
2774 if (sym->nRegs > 4) {
2775 fprintf (stderr, "allocated more than 4 or 0 registers for type ");
2776 printTypeChain (sym->type, stderr);
2777 fprintf (stderr, "\n");
2780 /* determine the type of register required */
2781 if (sym->nRegs == 1 &&
2782 IS_PTR (sym->type) &&
2784 sym->regType = REG_PTR;
2786 sym->regType = REG_GPR;
2789 debugLog (" reg name %s, reg type %s\n", sym->rname, debugLogRegType (sym->regType));
2793 /* for the first run we don't provide */
2794 /* registers for true symbols we will */
2795 /* see how things go */
2800 DEFSETFUNC (markRegFree)
2802 ((regs *)item)->isFree = 1;
2807 DEFSETFUNC (deallocReg)
2809 fprintf(stderr,"deallocting register %s\n",((regs *)item)->name);
2810 ((regs *)item)->isFree = 1;
2811 ((regs *)item)->wasUsed = 0;
2815 /*-----------------------------------------------------------------*/
2816 /* freeAllRegs - mark all registers as free */
2817 /*-----------------------------------------------------------------*/
2819 pic14_freeAllRegs ()
2823 debugLog ("%s\n", __FUNCTION__);
2825 applyToSet(dynAllocRegs,markRegFree);
2826 applyToSet(dynStackRegs,markRegFree);
2829 for (i = 0; i < pic14_nRegs; i++)
2830 regspic14[i].isFree = 1;
2834 /*-----------------------------------------------------------------*/
2835 /*-----------------------------------------------------------------*/
2837 pic14_deallocateAllRegs ()
2841 debugLog ("%s\n", __FUNCTION__);
2843 applyToSet(dynAllocRegs,deallocReg);
2846 for (i = 0; i < pic14_nRegs; i++) {
2847 if(regspic14[i].pc_type == PO_GPR_TEMP) {
2848 regspic14[i].isFree = 1;
2849 regspic14[i].wasUsed = 0;
2856 /*-----------------------------------------------------------------*/
2857 /* deallocStackSpil - this will set the stack pointer back */
2858 /*-----------------------------------------------------------------*/
2860 DEFSETFUNC (deallocStackSpil)
2864 debugLog ("%s\n", __FUNCTION__);
2869 /*-----------------------------------------------------------------*/
2870 /* farSpacePackable - returns the packable icode for far variables */
2871 /*-----------------------------------------------------------------*/
2873 farSpacePackable (iCode * ic)
2877 debugLog ("%s\n", __FUNCTION__);
2878 /* go thru till we find a definition for the
2879 symbol on the right */
2880 for (dic = ic->prev; dic; dic = dic->prev)
2883 /* if the definition is a call then no */
2884 if ((dic->op == CALL || dic->op == PCALL) &&
2885 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
2890 /* if shift by unknown amount then not */
2891 if ((dic->op == LEFT_OP || dic->op == RIGHT_OP) &&
2892 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
2895 /* if pointer get and size > 1 */
2896 if (POINTER_GET (dic) &&
2897 getSize (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)) > 1)
2900 if (POINTER_SET (dic) &&
2901 getSize (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)) > 1)
2904 /* if any three is a true symbol in far space */
2905 if (IC_RESULT (dic) &&
2906 IS_TRUE_SYMOP (IC_RESULT (dic)) &&
2907 isOperandInFarSpace (IC_RESULT (dic)))
2910 if (IC_RIGHT (dic) &&
2911 IS_TRUE_SYMOP (IC_RIGHT (dic)) &&
2912 isOperandInFarSpace (IC_RIGHT (dic)) &&
2913 !isOperandEqual (IC_RIGHT (dic), IC_RESULT (ic)))
2916 if (IC_LEFT (dic) &&
2917 IS_TRUE_SYMOP (IC_LEFT (dic)) &&
2918 isOperandInFarSpace (IC_LEFT (dic)) &&
2919 !isOperandEqual (IC_LEFT (dic), IC_RESULT (ic)))
2922 if (isOperandEqual (IC_RIGHT (ic), IC_RESULT (dic)))
2924 if ((dic->op == LEFT_OP ||
2925 dic->op == RIGHT_OP ||
2927 IS_OP_LITERAL (IC_RIGHT (dic)))
2937 /*-----------------------------------------------------------------*/
2938 /* packRegsForAssign - register reduction for assignment */
2939 /*-----------------------------------------------------------------*/
2941 packRegsForAssign (iCode * ic, eBBlock * ebp)
2946 debugLog ("%s\n", __FUNCTION__);
2948 debugAopGet (" result:", IC_RESULT (ic));
2949 debugAopGet (" left:", IC_LEFT (ic));
2950 debugAopGet (" right:", IC_RIGHT (ic));
2952 /* if this is at an absolute address, then get the address. */
2953 if (SPEC_ABSA ( OP_SYM_ETYPE(IC_RESULT(ic))) ) {
2954 if(IS_CONFIG_ADDRESS( SPEC_ADDR ( OP_SYM_ETYPE(IC_RESULT(ic))))) {
2955 debugLog (" %d - found config word declaration\n", __LINE__);
2956 if(IS_VALOP(IC_RIGHT(ic))) {
2957 debugLog (" setting config word to %x\n",
2958 (int) floatFromVal (IC_RIGHT(ic)->operand.valOperand));
2959 pic14_assignConfigWordValue( SPEC_ADDR ( OP_SYM_ETYPE(IC_RESULT(ic))),
2960 (int) floatFromVal (IC_RIGHT(ic)->operand.valOperand));
2963 /* remove the assignment from the iCode chain. */
2965 remiCodeFromeBBlock (ebp, ic);
2966 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
2967 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
2974 if (!IS_ITEMP (IC_RESULT (ic))) {
2975 allocDirReg(IC_RESULT (ic));
2976 debugLog (" %d - result is not temp\n", __LINE__);
2979 if (IC_LEFT (ic) && !IS_ITEMP (IC_LEFT (ic))) {
2980 debugLog (" %d - left is not temp, allocating\n", __LINE__);
2981 allocDirReg(IC_LEFT (ic));
2985 if (!IS_ITEMP (IC_RIGHT (ic))) {
2986 debugLog (" %d - not packing - right is not temp\n", __LINE__);
2988 /* only pack if this is not a function pointer */
2989 if (!IS_REF (IC_RIGHT (ic)))
2990 allocDirReg(IC_RIGHT (ic));
2994 if (OP_SYMBOL (IC_RIGHT (ic))->isind ||
2995 OP_LIVETO (IC_RIGHT (ic)) > ic->seq)
2997 debugLog (" %d - not packing - right side fails \n", __LINE__);
3001 /* if the true symbol is defined in far space or on stack
3002 then we should not since this will increase register pressure */
3003 if (isOperandInFarSpace (IC_RESULT (ic)))
3005 if ((dic = farSpacePackable (ic)))
3011 /* find the definition of iTempNN scanning backwards if we find a
3012 a use of the true symbol before we find the definition then
3014 for (dic = ic->prev; dic; dic = dic->prev)
3017 /* if there is a function call and this is
3018 a parameter & not my parameter then don't pack it */
3019 if ((dic->op == CALL || dic->op == PCALL) &&
3020 (OP_SYMBOL (IC_RESULT (ic))->_isparm &&
3021 !OP_SYMBOL (IC_RESULT (ic))->ismyparm))
3023 debugLog (" %d - \n", __LINE__);
3031 if (IS_TRUE_SYMOP (IC_RESULT (dic)) &&
3032 IS_OP_VOLATILE (IC_RESULT (dic)))
3034 debugLog (" %d - dic is VOLATILE \n", __LINE__);
3039 if (IS_SYMOP (IC_RESULT (dic)) &&
3040 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
3042 /* A previous result was assigned to the same register - we'll our definition */
3043 debugLog (" %d - dic result key == ic right key -- pointer set=%c\n",
3044 __LINE__, ((POINTER_SET (dic)) ? 'Y' : 'N'));
3045 if (POINTER_SET (dic))
3051 if (IS_SYMOP (IC_RIGHT (dic)) &&
3052 (IC_RIGHT (dic)->key == IC_RESULT (ic)->key ||
3053 IC_RIGHT (dic)->key == IC_RIGHT (ic)->key))
3055 debugLog (" %d - dic right key == ic rightor result key\n", __LINE__);
3060 if (IS_SYMOP (IC_LEFT (dic)) &&
3061 (IC_LEFT (dic)->key == IC_RESULT (ic)->key ||
3062 IC_LEFT (dic)->key == IC_RIGHT (ic)->key))
3064 debugLog (" %d - dic left key == ic rightor result key\n", __LINE__);
3069 if (POINTER_SET (dic) &&
3070 IC_RESULT (dic)->key == IC_RESULT (ic)->key)
3072 debugLog (" %d - dic result key == ic result key -- pointer set=Y\n",
3080 return 0; /* did not find */
3082 /* if assignment then check that right is not a bit */
3083 if (ASSIGNMENT (ic) && !POINTER_SET (ic))
3085 sym_link *etype = operandType (IC_RESULT (dic));
3086 if (IS_BITFIELD (etype))
3088 /* if result is a bit too then it's ok */
3089 etype = operandType (IC_RESULT (ic));
3090 if (!IS_BITFIELD (etype))
3095 /* if the result is on stack or iaccess then it must be
3096 the same at least one of the operands */
3097 if (OP_SYMBOL (IC_RESULT (ic))->onStack ||
3098 OP_SYMBOL (IC_RESULT (ic))->iaccess)
3101 /* the operation has only one symbol
3102 operator then we can pack */
3103 if ((IC_LEFT (dic) && !IS_SYMOP (IC_LEFT (dic))) ||
3104 (IC_RIGHT (dic) && !IS_SYMOP (IC_RIGHT (dic))))
3107 if (!((IC_LEFT (dic) &&
3108 IC_RESULT (ic)->key == IC_LEFT (dic)->key) ||
3110 IC_RESULT (ic)->key == IC_RIGHT (dic)->key)))
3114 debugLog (" packing. removing %s\n", OP_SYMBOL (IC_RIGHT (ic))->rname);
3115 debugLog (" replacing with %s\n", OP_SYMBOL (IC_RESULT (dic))->rname);
3116 /* found the definition */
3117 /* replace the result with the result of */
3118 /* this assignment and remove this assignment */
3119 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
3120 IC_RESULT (dic) = IC_RESULT (ic);
3122 if (IS_ITEMP (IC_RESULT (dic)) && OP_SYMBOL (IC_RESULT (dic))->liveFrom > dic->seq)
3124 OP_SYMBOL (IC_RESULT (dic))->liveFrom = dic->seq;
3126 /* delete from liverange table also
3127 delete from all the points inbetween and the new
3129 for (sic = dic; sic != ic; sic = sic->next)
3131 bitVectUnSetBit (sic->rlive, IC_RESULT (ic)->key);
3132 if (IS_ITEMP (IC_RESULT (dic)))
3133 bitVectSetBit (sic->rlive, IC_RESULT (dic)->key);
3136 remiCodeFromeBBlock (ebp, ic);
3137 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
3138 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
3139 OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
3145 /*-----------------------------------------------------------------*/
3146 /* findAssignToSym : scanning backwards looks for first assig found */
3147 /*-----------------------------------------------------------------*/
3149 findAssignToSym (operand * op, iCode * ic)
3153 debugLog ("%s\n", __FUNCTION__);
3154 for (dic = ic->prev; dic; dic = dic->prev)
3157 /* if definition by assignment */
3158 if (dic->op == '=' &&
3159 !POINTER_SET (dic) &&
3160 IC_RESULT (dic)->key == op->key
3161 /* && IS_TRUE_SYMOP(IC_RIGHT(dic)) */
3165 /* we are interested only if defined in far space */
3166 /* or in stack space in case of + & - */
3168 /* if assigned to a non-symbol then return
3170 if (!IS_SYMOP (IC_RIGHT (dic)))
3173 /* if the symbol is in far space then
3175 if (isOperandInFarSpace (IC_RIGHT (dic)))
3178 /* for + & - operations make sure that
3179 if it is on the stack it is the same
3180 as one of the three operands */
3181 if ((ic->op == '+' || ic->op == '-') &&
3182 OP_SYMBOL (IC_RIGHT (dic))->onStack)
3185 if (IC_RESULT (ic)->key != IC_RIGHT (dic)->key &&
3186 IC_LEFT (ic)->key != IC_RIGHT (dic)->key &&
3187 IC_RIGHT (ic)->key != IC_RIGHT (dic)->key)
3195 /* if we find an usage then we cannot delete it */
3196 if (IC_LEFT (dic) && IC_LEFT (dic)->key == op->key)
3199 if (IC_RIGHT (dic) && IC_RIGHT (dic)->key == op->key)
3202 if (POINTER_SET (dic) && IC_RESULT (dic)->key == op->key)
3206 /* now make sure that the right side of dic
3207 is not defined between ic & dic */
3210 iCode *sic = dic->next;
3212 for (; sic != ic; sic = sic->next)
3213 if (IC_RESULT (sic) &&
3214 IC_RESULT (sic)->key == IC_RIGHT (dic)->key)
3223 /*-----------------------------------------------------------------*/
3224 /* packRegsForSupport :- reduce some registers for support calls */
3225 /*-----------------------------------------------------------------*/
3227 packRegsForSupport (iCode * ic, eBBlock * ebp)
3231 debugLog ("%s\n", __FUNCTION__);
3232 /* for the left & right operand :- look to see if the
3233 left was assigned a true symbol in far space in that
3234 case replace them */
3235 if (IS_ITEMP (IC_LEFT (ic)) &&
3236 OP_SYMBOL (IC_LEFT (ic))->liveTo <= ic->seq)
3238 iCode *dic = findAssignToSym (IC_LEFT (ic), ic);
3244 debugAopGet ("removing left:", IC_LEFT (ic));
3246 /* found it we need to remove it from the
3248 for (sic = dic; sic != ic; sic = sic->next)
3249 bitVectUnSetBit (sic->rlive, IC_LEFT (ic)->key);
3251 IC_LEFT (ic)->operand.symOperand =
3252 IC_RIGHT (dic)->operand.symOperand;
3253 IC_LEFT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
3254 remiCodeFromeBBlock (ebp, dic);
3255 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
3256 hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
3260 /* do the same for the right operand */
3263 IS_ITEMP (IC_RIGHT (ic)) &&
3264 OP_SYMBOL (IC_RIGHT (ic))->liveTo <= ic->seq)
3266 iCode *dic = findAssignToSym (IC_RIGHT (ic), ic);
3272 /* if this is a subtraction & the result
3273 is a true symbol in far space then don't pack */
3274 if (ic->op == '-' && IS_TRUE_SYMOP (IC_RESULT (dic)))
3276 sym_link *etype = getSpec (operandType (IC_RESULT (dic)));
3277 if (IN_FARSPACE (SPEC_OCLS (etype)))
3281 debugAopGet ("removing right:", IC_RIGHT (ic));
3283 /* found it we need to remove it from the
3285 for (sic = dic; sic != ic; sic = sic->next)
3286 bitVectUnSetBit (sic->rlive, IC_RIGHT (ic)->key);
3288 IC_RIGHT (ic)->operand.symOperand =
3289 IC_RIGHT (dic)->operand.symOperand;
3290 IC_RIGHT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
3292 remiCodeFromeBBlock (ebp, dic);
3293 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
3294 hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
3301 #define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
3304 /*-----------------------------------------------------------------*/
3305 /* packRegsForOneuse : - will reduce some registers for single Use */
3306 /*-----------------------------------------------------------------*/
3308 packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
3313 debugLog ("%s\n", __FUNCTION__);
3314 /* if returning a literal then do nothing */
3318 /* only upto 2 bytes since we cannot predict
3319 the usage of b, & acc */
3320 if (getSize (operandType (op)) > (fReturnSizePic - 2) &&
3325 /* this routine will mark the a symbol as used in one
3326 instruction use only && if the definition is local
3327 (ie. within the basic block) && has only one definition &&
3328 that definition is either a return value from a
3329 function or does not contain any variables in
3331 uses = bitVectCopy (OP_USES (op));
3332 bitVectUnSetBit (uses, ic->key); /* take away this iCode */
3333 if (!bitVectIsZero (uses)) /* has other uses */
3336 /* if it has only one defintion */
3337 if (bitVectnBitsOn (OP_DEFS (op)) > 1)
3338 return NULL; /* has more than one definition */
3340 /* get that definition */
3342 hTabItemWithKey (iCodehTab,
3343 bitVectFirstBit (OP_DEFS (op)))))
3346 /* found the definition now check if it is local */
3347 if (dic->seq < ebp->fSeq ||
3348 dic->seq > ebp->lSeq)
3349 return NULL; /* non-local */
3351 /* now check if it is the return from
3353 if (dic->op == CALL || dic->op == PCALL)
3355 if (ic->op != SEND && ic->op != RETURN &&
3356 !POINTER_SET(ic) && !POINTER_GET(ic))
3358 OP_SYMBOL (op)->ruonly = 1;
3365 /* otherwise check that the definition does
3366 not contain any symbols in far space */
3367 if (isOperandInFarSpace (IC_LEFT (dic)) ||
3368 isOperandInFarSpace (IC_RIGHT (dic)) ||
3369 IS_OP_RUONLY (IC_LEFT (ic)) ||
3370 IS_OP_RUONLY (IC_RIGHT (ic)))
3375 /* if pointer set then make sure the pointer
3377 if (POINTER_SET (dic) &&
3378 !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)))
3381 if (POINTER_GET (dic) &&
3382 !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)))
3387 /* also make sure the intervenening instructions
3388 don't have any thing in far space */
3389 for (dic = dic->next; dic && dic != ic; dic = dic->next)
3392 /* if there is an intervening function call then no */
3393 if (dic->op == CALL || dic->op == PCALL)
3395 /* if pointer set then make sure the pointer
3397 if (POINTER_SET (dic) &&
3398 !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)))
3401 if (POINTER_GET (dic) &&
3402 !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)))
3405 /* if address of & the result is remat then okay */
3406 if (dic->op == ADDRESS_OF &&
3407 OP_SYMBOL (IC_RESULT (dic))->remat)
3410 /* if operand has size of three or more & this
3411 operation is a '*','/' or '%' then 'b' may
3413 if ((dic->op == '%' || dic->op == '/' || dic->op == '*') &&
3414 getSize (operandType (op)) >= 3)
3417 /* if left or right or result is in far space */
3418 if (isOperandInFarSpace (IC_LEFT (dic)) ||
3419 isOperandInFarSpace (IC_RIGHT (dic)) ||
3420 isOperandInFarSpace (IC_RESULT (dic)) ||
3421 IS_OP_RUONLY (IC_LEFT (dic)) ||
3422 IS_OP_RUONLY (IC_RIGHT (dic)) ||
3423 IS_OP_RUONLY (IC_RESULT (dic)))
3429 OP_SYMBOL (op)->ruonly = 1;
3434 /*-----------------------------------------------------------------*/
3435 /* isBitwiseOptimizable - requirements of JEAN LOUIS VERN */
3436 /*-----------------------------------------------------------------*/
3438 isBitwiseOptimizable (iCode * ic)
3440 sym_link *ltype = getSpec (operandType (IC_LEFT (ic)));
3441 sym_link *rtype = getSpec (operandType (IC_RIGHT (ic)));
3443 debugLog ("%s\n", __FUNCTION__);
3444 /* bitwise operations are considered optimizable
3445 under the following conditions (Jean-Louis VERN)
3457 if (IS_LITERAL (rtype) ||
3458 (IS_BITVAR (ltype) && IN_BITSPACE (SPEC_OCLS (ltype))))
3464 /*-----------------------------------------------------------------*/
3465 /* packRegsForAccUse - pack registers for acc use */
3466 /*-----------------------------------------------------------------*/
3468 packRegsForAccUse (iCode * ic)
3472 debugLog ("%s\n", __FUNCTION__);
3474 /* result too large for WREG? */
3475 if (getSize (operandType (IC_RESULT (ic))) > 1)
3478 /* We have to make sure that OP_SYMBOL(IC_RESULT(ic))
3479 * is never used as an operand to an instruction that
3480 * cannot have WREG as an operand (e.g. BTFSx cannot
3481 * operate on WREG...
3482 * For now, store all results into proper registers. */
3486 /* if this is an aggregate, e.g. a one byte char array */
3487 if (IS_AGGREGATE(operandType(IC_RESULT(ic)))) {
3490 debugLog (" %s:%d\n", __FUNCTION__,__LINE__);
3492 /* if + or - then it has to be one byte result */
3493 if ((ic->op == '+' || ic->op == '-')
3494 && getSize (operandType (IC_RESULT (ic))) > 1)
3497 debugLog (" %s:%d\n", __FUNCTION__,__LINE__);
3498 /* if shift operation make sure right side is not a literal */
3499 if (ic->op == RIGHT_OP &&
3500 (isOperandLiteral (IC_RIGHT (ic)) ||
3501 getSize (operandType (IC_RESULT (ic))) > 1))
3504 if (ic->op == LEFT_OP &&
3505 (isOperandLiteral (IC_RIGHT (ic)) ||
3506 getSize (operandType (IC_RESULT (ic))) > 1))
3509 if (IS_BITWISE_OP (ic) &&
3510 getSize (operandType (IC_RESULT (ic))) > 1)
3514 /* has only one definition */
3515 if (bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) > 1)
3518 /* has only one use */
3519 if (bitVectnBitsOn (OP_USES (IC_RESULT (ic))) > 1)
3522 /* and the usage immediately follows this iCode */
3523 if (!(uic = hTabItemWithKey (iCodehTab,
3524 bitVectFirstBit (OP_USES (IC_RESULT (ic))))))
3527 debugLog (" %s:%d\n", __FUNCTION__,__LINE__);
3528 if (ic->next != uic)
3531 /* if it is a conditional branch then we definitely can */
3535 if (uic->op == JUMPTABLE)
3538 /* if the usage is not is an assignment
3539 or an arithmetic / bitwise / shift operation then not */
3540 if (POINTER_SET (uic) &&
3541 getSize (aggrToPtr (operandType (IC_RESULT (uic)), FALSE)) > 1)
3544 debugLog (" %s:%d\n", __FUNCTION__,__LINE__);
3545 if (uic->op != '=' &&
3546 !IS_ARITHMETIC_OP (uic) &&
3547 !IS_BITWISE_OP (uic) &&
3548 uic->op != LEFT_OP &&
3549 uic->op != RIGHT_OP)
3552 debugLog (" %s:%d\n", __FUNCTION__,__LINE__);
3553 /* if used in ^ operation then make sure right is not a
3555 if (uic->op == '^' && isOperandLiteral (IC_RIGHT (uic)))
3558 /* if shift operation make sure right side is not a literal */
3559 if (uic->op == RIGHT_OP &&
3560 (isOperandLiteral (IC_RIGHT (uic)) ||
3561 getSize (operandType (IC_RESULT (uic))) > 1))
3564 if (uic->op == LEFT_OP &&
3565 (isOperandLiteral (IC_RIGHT (uic)) ||
3566 getSize (operandType (IC_RESULT (uic))) > 1))
3569 /* make sure that the result of this icode is not on the
3570 stack, since acc is used to compute stack offset */
3571 if (IS_TRUE_SYMOP (IC_RESULT (uic)) &&
3572 OP_SYMBOL (IC_RESULT (uic))->onStack)
3575 /* if either one of them in far space then we cannot */
3576 if ((IS_TRUE_SYMOP (IC_LEFT (uic)) &&
3577 isOperandInFarSpace (IC_LEFT (uic))) ||
3578 (IS_TRUE_SYMOP (IC_RIGHT (uic)) &&
3579 isOperandInFarSpace (IC_RIGHT (uic))))
3582 /* if the usage has only one operand then we can */
3583 if (IC_LEFT (uic) == NULL ||
3584 IC_RIGHT (uic) == NULL)
3587 /* make sure this is on the left side if not
3588 a '+' since '+' is commutative */
3589 if (ic->op != '+' &&
3590 IC_LEFT (uic)->key != IC_RESULT (ic)->key)
3593 debugLog (" %s:%d\n", __FUNCTION__,__LINE__);
3594 /* if one of them is a literal then we can */
3595 if ( ((IC_LEFT (uic) && IS_OP_LITERAL (IC_LEFT (uic))) ||
3596 (IC_RIGHT (uic) && IS_OP_LITERAL (IC_RIGHT (uic)))) &&
3597 (getSize (operandType (IC_RESULT (uic))) <= 1))
3599 OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
3603 debugLog (" %s:%d\n", __FUNCTION__,__LINE__);
3604 /* if the other one is not on stack then we can */
3605 if (IC_LEFT (uic)->key == IC_RESULT (ic)->key &&
3606 (IS_ITEMP (IC_RIGHT (uic)) ||
3607 (IS_TRUE_SYMOP (IC_RIGHT (uic)) &&
3608 !OP_SYMBOL (IC_RIGHT (uic))->onStack)))
3611 if (IC_RIGHT (uic)->key == IC_RESULT (ic)->key &&
3612 (IS_ITEMP (IC_LEFT (uic)) ||
3613 (IS_TRUE_SYMOP (IC_LEFT (uic)) &&
3614 !OP_SYMBOL (IC_LEFT (uic))->onStack)))
3620 debugLog ("%s - Yes we are using the accumulator\n", __FUNCTION__);
3621 OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
3625 /*-----------------------------------------------------------------*/
3626 /* packForPush - hueristics to reduce iCode for pushing */
3627 /*-----------------------------------------------------------------*/
3629 packForReceive (iCode * ic, eBBlock * ebp)
3633 debugLog ("%s\n", __FUNCTION__);
3634 debugAopGet (" result:", IC_RESULT (ic));
3635 debugAopGet (" left:", IC_LEFT (ic));
3636 debugAopGet (" right:", IC_RIGHT (ic));
3641 for (dic = ic->next; dic; dic = dic->next)
3646 if (IC_LEFT (dic) && (IC_RESULT (ic)->key == IC_LEFT (dic)->key))
3647 debugLog (" used on left\n");
3648 if (IC_RIGHT (dic) && IC_RESULT (ic)->key == IC_RIGHT (dic)->key)
3649 debugLog (" used on right\n");
3650 if (IC_RESULT (dic) && IC_RESULT (ic)->key == IC_RESULT (dic)->key)
3651 debugLog (" used on result\n");
3653 if ((IC_LEFT (dic) && (IC_RESULT (ic)->key == IC_LEFT (dic)->key)) ||
3654 (IC_RESULT (dic) && IC_RESULT (ic)->key == IC_RESULT (dic)->key))
3659 debugLog (" hey we can remove this unnecessary assign\n");
3661 /*-----------------------------------------------------------------*/
3662 /* packForPush - hueristics to reduce iCode for pushing */
3663 /*-----------------------------------------------------------------*/
3665 packForPush (iCode * ic, eBBlock * ebp)
3669 debugLog ("%s\n", __FUNCTION__);
3670 if (ic->op != IPUSH || !IS_ITEMP (IC_LEFT (ic)))
3673 /* must have only definition & one usage */
3674 if (bitVectnBitsOn (OP_DEFS (IC_LEFT (ic))) != 1 ||
3675 bitVectnBitsOn (OP_USES (IC_LEFT (ic))) != 1)
3678 /* find the definition */
3679 if (!(dic = hTabItemWithKey (iCodehTab,
3680 bitVectFirstBit (OP_DEFS (IC_LEFT (ic))))))
3683 if (dic->op != '=' || POINTER_SET (dic))
3686 /* we now we know that it has one & only one def & use
3687 and the that the definition is an assignment */
3688 IC_LEFT (ic) = IC_RIGHT (dic);
3690 remiCodeFromeBBlock (ebp, dic);
3691 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
3692 hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
3695 void printSymType(char * str, sym_link *sl)
3697 debugLog (" %s Symbol type: ",str);
3698 printTypeChain( sl, debugF);
3703 /*-----------------------------------------------------------------*/
3704 /* some debug code to print the symbol S_TYPE. Note that
3705 * the function checkSClass in src/SDCCsymt.c dinks with
3706 * the S_TYPE in ways the PIC port doesn't fully like...*/
3707 /*-----------------------------------------------------------------*/
3708 void isData(sym_link *sl)
3718 for ( ; sl; sl=sl->next) {
3720 switch (SPEC_SCLS(sl)) {
3722 case S_DATA: fprintf (of, "data "); break;
3723 case S_XDATA: fprintf (of, "xdata "); break;
3724 case S_SFR: fprintf (of, "sfr "); break;
3725 case S_SBIT: fprintf (of, "sbit "); break;
3726 case S_CODE: fprintf (of, "code "); break;
3727 case S_IDATA: fprintf (of, "idata "); break;
3728 case S_PDATA: fprintf (of, "pdata "); break;
3729 case S_LITERAL: fprintf (of, "literal "); break;
3730 case S_STACK: fprintf (of, "stack "); break;
3731 case S_XSTACK: fprintf (of, "xstack "); break;
3732 case S_BIT: fprintf (of, "bit "); break;
3733 case S_EEPROM: fprintf (of, "eeprom "); break;
3743 /*-----------------------------------------------------------------*/
3744 /* packRegisters - does some transformations to reduce register */
3746 /*-----------------------------------------------------------------*/
3748 packRegisters (eBBlock * ebp)
3753 debugLog ("%s\n", __FUNCTION__);
3759 /* look for assignments of the form */
3760 /* iTempNN = TRueSym (someoperation) SomeOperand */
3762 /* TrueSym := iTempNN:1 */
3763 for (ic = ebp->sch; ic; ic = ic->next)
3766 /* find assignment of the form TrueSym := iTempNN:1 */
3767 if (ic->op == '=' && !POINTER_SET (ic))
3768 change += packRegsForAssign (ic, ebp);
3772 if (POINTER_SET (ic))
3773 debugLog ("pointer is set\n");
3774 debugAopGet (" result:", IC_RESULT (ic));
3775 debugAopGet (" left:", IC_LEFT (ic));
3776 debugAopGet (" right:", IC_RIGHT (ic));
3785 for (ic = ebp->sch; ic; ic = ic->next) {
3787 if(IS_SYMOP ( IC_LEFT(ic))) {
3788 sym_link *etype = getSpec (operandType (IC_LEFT (ic)));
3790 debugAopGet (" left:", IC_LEFT (ic));
3791 if(IS_PTR_CONST(OP_SYMBOL(IC_LEFT(ic))->type))
3792 debugLog (" is a pointer\n");
3794 if(IS_OP_VOLATILE(IC_LEFT(ic)))
3795 debugLog (" is volatile\n");
3799 printSymType(" ", OP_SYMBOL(IC_LEFT(ic))->type);
3802 if(IS_SYMOP ( IC_RIGHT(ic))) {
3803 debugAopGet (" right:", IC_RIGHT (ic));
3804 printSymType(" ", OP_SYMBOL(IC_RIGHT(ic))->type);
3807 if(IS_SYMOP ( IC_RESULT(ic))) {
3808 debugAopGet (" result:", IC_RESULT (ic));
3809 printSymType(" ", OP_SYMBOL(IC_RESULT(ic))->type);
3812 if (POINTER_SET (ic))
3813 debugLog (" %d - Pointer set\n", __LINE__);
3816 /* Look for two subsequent iCodes with */
3818 /* _c = iTemp & op; */
3819 /* and replace them by */
3822 if ((ic->op == BITWISEAND || ic->op == '|' || ic->op == '^') &&
3824 ic->prev->op == '=' &&
3825 IS_ITEMP (IC_LEFT (ic)) &&
3826 IC_LEFT (ic) == IC_RESULT (ic->prev) &&
3827 isOperandEqual (IC_RESULT(ic), IC_RIGHT(ic->prev)))
3829 iCode* ic_prev = ic->prev;
3830 symbol* prev_result_sym = OP_SYMBOL (IC_RESULT (ic_prev));
3832 ReplaceOpWithCheaperOp (&IC_LEFT (ic), IC_RESULT (ic));
3833 if (IC_RESULT (ic_prev) != IC_RIGHT (ic))
3835 bitVectUnSetBit (OP_USES (IC_RESULT (ic_prev)), ic->key);
3836 if (/*IS_ITEMP (IC_RESULT (ic_prev)) && */
3837 prev_result_sym->liveTo == ic->seq)
3839 prev_result_sym->liveTo = ic_prev->seq;
3842 bitVectSetBit (OP_USES (IC_RESULT (ic)), ic->key);
3844 bitVectSetBit (ic->rlive, IC_RESULT (ic)->key);
3846 if (bitVectIsZero (OP_USES (IC_RESULT (ic_prev))))
3848 bitVectUnSetBit (ic->rlive, IC_RESULT (ic)->key);
3849 bitVectUnSetBit (OP_DEFS (IC_RESULT (ic_prev)), ic_prev->key);
3850 remiCodeFromeBBlock (ebp, ic_prev);
3851 hTabDeleteItem (&iCodehTab, ic_prev->key, ic_prev, DELETE_ITEM, NULL);
3855 /* if this is an itemp & result of a address of a true sym
3856 then mark this as rematerialisable */
3857 if (ic->op == ADDRESS_OF &&
3858 IS_ITEMP (IC_RESULT (ic)) &&
3859 IS_TRUE_SYMOP (IC_LEFT (ic)) &&
3860 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
3861 !OP_SYMBOL (IC_LEFT (ic))->onStack)
3864 debugLog (" %d - %s. result is rematerializable\n", __LINE__,__FUNCTION__);
3866 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
3867 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
3868 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
3872 /* if straight assignment then carry remat flag if
3873 this is the only definition */
3874 if (ic->op == '=' &&
3875 !POINTER_SET (ic) &&
3876 IS_SYMOP (IC_RIGHT (ic)) &&
3877 OP_SYMBOL (IC_RIGHT (ic))->remat &&
3878 bitVectnBitsOn (OP_SYMBOL (IC_RESULT (ic))->defs) <= 1)
3880 debugLog (" %d - %s. straight rematerializable\n", __LINE__,__FUNCTION__);
3882 OP_SYMBOL (IC_RESULT (ic))->remat =
3883 OP_SYMBOL (IC_RIGHT (ic))->remat;
3884 OP_SYMBOL (IC_RESULT (ic))->rematiCode =
3885 OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
3888 /* if this is a +/- operation with a rematerizable
3889 then mark this as rematerializable as well */
3890 if ((ic->op == '+' || ic->op == '-') &&
3891 (IS_SYMOP (IC_LEFT (ic)) &&
3892 IS_ITEMP (IC_RESULT (ic)) &&
3893 OP_SYMBOL (IC_LEFT (ic))->remat &&
3894 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
3895 IS_OP_LITERAL (IC_RIGHT (ic))))
3897 debugLog (" %d - %s. rematerializable because op is +/-\n", __LINE__,__FUNCTION__);
3899 operandLitValue (IC_RIGHT (ic));
3900 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
3901 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
3902 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
3905 /* mark the pointer usages */
3906 if (POINTER_SET (ic) && IS_SYMOP(IC_RESULT(ic)))
3908 OP_SYMBOL (IC_RESULT (ic))->uptr = 1;
3909 debugLog (" marking as a pointer (set) =>");
3910 debugAopGet (" result:", IC_RESULT (ic));
3912 if (POINTER_GET (ic) && IS_SYMOP(IC_LEFT(ic)))
3914 OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
3915 debugLog (" marking as a pointer (get) =>");
3916 debugAopGet (" left:", IC_LEFT (ic));
3921 /* if we are using a symbol on the stack
3922 then we should say pic14_ptrRegReq */
3923 if (ic->op == IFX && IS_SYMOP (IC_COND (ic)))
3924 pic14_ptrRegReq += ((OP_SYMBOL (IC_COND (ic))->onStack ||
3925 OP_SYMBOL (IC_COND (ic))->iaccess) ? 1 : 0);
3926 else if (ic->op == JUMPTABLE && IS_SYMOP (IC_JTCOND (ic)))
3927 pic14_ptrRegReq += ((OP_SYMBOL (IC_JTCOND (ic))->onStack ||
3928 OP_SYMBOL (IC_JTCOND (ic))->iaccess) ? 1 : 0);
3931 if (IS_SYMOP (IC_LEFT (ic)))
3932 pic14_ptrRegReq += ((OP_SYMBOL (IC_LEFT (ic))->onStack ||
3933 OP_SYMBOL (IC_LEFT (ic))->iaccess) ? 1 : 0);
3934 if (IS_SYMOP (IC_RIGHT (ic)))
3935 pic14_ptrRegReq += ((OP_SYMBOL (IC_RIGHT (ic))->onStack ||
3936 OP_SYMBOL (IC_RIGHT (ic))->iaccess) ? 1 : 0);
3937 if (IS_SYMOP (IC_RESULT (ic)))
3938 pic14_ptrRegReq += ((OP_SYMBOL (IC_RESULT (ic))->onStack ||
3939 OP_SYMBOL (IC_RESULT (ic))->iaccess) ? 1 : 0);
3942 debugLog (" %d - pointer reg req = %d\n", __LINE__,pic14_ptrRegReq);
3946 /* if the condition of an if instruction
3947 is defined in the previous instruction then
3948 mark the itemp as a conditional */
3949 if ((IS_CONDITIONAL (ic) ||
3950 ((ic->op == BITWISEAND ||
3953 isBitwiseOptimizable (ic))) &&
3954 ic->next && ic->next->op == IFX &&
3955 isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
3956 OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
3959 debugLog (" %d\n", __LINE__);
3960 OP_SYMBOL (IC_RESULT (ic))->regType = REG_CND;
3964 /* reduce for support function calls */
3965 if (ic->supportRtn || ic->op == '+' || ic->op == '-')
3966 packRegsForSupport (ic, ebp);
3968 /* if a parameter is passed, it's in W, so we may not
3969 need to place a copy in a register */
3970 if (ic->op == RECEIVE)
3971 packForReceive (ic, ebp);
3973 /* some cases the redundant moves can
3974 can be eliminated for return statements */
3975 if ((ic->op == RETURN || ic->op == SEND) &&
3976 !isOperandInFarSpace (IC_LEFT (ic)) &&
3978 packRegsForOneuse (ic, IC_LEFT (ic), ebp);
3980 /* if pointer set & left has a size more than
3981 one and right is not in far space */
3982 if (POINTER_SET (ic) &&
3983 !isOperandInFarSpace (IC_RIGHT (ic)) &&
3984 IS_SYMOP(IC_RESULT(ic)) &&
3985 !OP_SYMBOL (IC_RESULT (ic))->remat &&
3986 !IS_OP_RUONLY (IC_RIGHT (ic)) &&
3987 getSize (aggrToPtr (operandType (IC_RESULT (ic)), FALSE)) > 1)
3989 packRegsForOneuse (ic, IC_RESULT (ic), ebp);
3991 /* if pointer get */
3992 if (POINTER_GET (ic) &&
3993 !isOperandInFarSpace (IC_RESULT (ic)) &&
3994 IS_SYMOP(IC_LEFT(ic)) &&
3995 !OP_SYMBOL (IC_LEFT (ic))->remat &&
3996 !IS_OP_RUONLY (IC_RESULT (ic)) &&
3997 getSize (aggrToPtr (operandType (IC_LEFT (ic)), FALSE)) > 1)
3999 packRegsForOneuse (ic, IC_LEFT (ic), ebp);
4002 /* if this is cast for intergral promotion then
4003 check if only use of the definition of the
4004 operand being casted/ if yes then replace
4005 the result of that arithmetic operation with
4006 this result and get rid of the cast */
4007 if (ic->op == CAST) {
4009 sym_link *fromType = operandType (IC_RIGHT (ic));
4010 sym_link *toType = operandType (IC_LEFT (ic));
4012 debugLog (" %d - casting\n", __LINE__);
4014 if (IS_INTEGRAL (fromType) && IS_INTEGRAL (toType) &&
4015 getSize (fromType) != getSize (toType)) {
4018 iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
4021 if (IS_ARITHMETIC_OP (dic)) {
4023 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
4024 IC_RESULT (dic) = IC_RESULT (ic);
4025 remiCodeFromeBBlock (ebp, ic);
4026 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
4027 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
4028 OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
4032 OP_SYMBOL (IC_RIGHT (ic))->ruonly = 0;
4036 /* if the type from and type to are the same
4037 then if this is the only use then packit */
4038 if (compareType (operandType (IC_RIGHT (ic)),
4039 operandType (IC_LEFT (ic))) == 1) {
4041 iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
4044 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
4045 IC_RESULT (dic) = IC_RESULT (ic);
4046 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
4047 remiCodeFromeBBlock (ebp, ic);
4048 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
4049 OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
4057 iTempNN := (some variable in farspace) V1
4062 if (ic->op == IPUSH)
4064 packForPush (ic, ebp);
4068 /* pack registers for accumulator use, when the
4069 result of an arithmetic or bit wise operation
4070 has only one use, that use is immediately following
4071 the defintion and the using iCode has only one
4072 operand or has two operands but one is literal &
4073 the result of that operation is not on stack then
4074 we can leave the result of this operation in acc:b
4076 if ((IS_ARITHMETIC_OP (ic)
4078 || IS_BITWISE_OP (ic)
4080 || ic->op == LEFT_OP || ic->op == RIGHT_OP
4083 IS_ITEMP (IC_RESULT (ic)) &&
4084 getSize (operandType (IC_RESULT (ic))) <= 2)
4086 packRegsForAccUse (ic);
4092 dumpEbbsToDebug (eBBlock ** ebbs, int count)
4096 if (!debug || !debugF)
4099 for (i = 0; i < count; i++)
4101 fprintf (debugF, "\n----------------------------------------------------------------\n");
4102 fprintf (debugF, "Basic Block %s : loop Depth = %d noPath = %d , lastinLoop = %d\n",
4103 ebbs[i]->entryLabel->name,
4106 ebbs[i]->isLastInLoop);
4107 fprintf (debugF, "depth 1st num %d : bbnum = %d 1st iCode = %d , last iCode = %d\n",
4112 fprintf (debugF, "visited %d : hasFcall = %d\n",
4116 fprintf (debugF, "\ndefines bitVector :");
4117 bitVectDebugOn (ebbs[i]->defSet, debugF);
4118 fprintf (debugF, "\nlocal defines bitVector :");
4119 bitVectDebugOn (ebbs[i]->ldefs, debugF);
4120 fprintf (debugF, "\npointers Set bitvector :");
4121 bitVectDebugOn (ebbs[i]->ptrsSet, debugF);
4122 fprintf (debugF, "\nin pointers Set bitvector :");
4123 bitVectDebugOn (ebbs[i]->inPtrsSet, debugF);
4124 fprintf (debugF, "\ninDefs Set bitvector :");
4125 bitVectDebugOn (ebbs[i]->inDefs, debugF);
4126 fprintf (debugF, "\noutDefs Set bitvector :");
4127 bitVectDebugOn (ebbs[i]->outDefs, debugF);
4128 fprintf (debugF, "\nusesDefs Set bitvector :");
4129 bitVectDebugOn (ebbs[i]->usesDefs, debugF);
4130 fprintf (debugF, "\n----------------------------------------------------------------\n");
4131 printiCChain (ebbs[i]->sch, debugF);
4134 /*-----------------------------------------------------------------*/
4135 /* assignRegisters - assigns registers to each live range as need */
4136 /*-----------------------------------------------------------------*/
4138 pic14_assignRegisters (ebbIndex * ebbi)
4140 eBBlock ** ebbs = ebbi->bbOrder;
4141 int count = ebbi->count;
4145 debugLog ("<><><><><><><><><><><><><><><><><>\nstarting\t%s:%s\n", __FILE__, __FUNCTION__);
4146 debugLog ("ebbs before optimizing:\n");
4147 dumpEbbsToDebug (ebbs, count);
4149 setToNull ((void *) &_G.funcrUsed);
4150 pic14_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
4153 /* change assignments this will remove some
4154 live ranges reducing some register pressure */
4155 for (i = 0; i < count; i++)
4156 packRegisters (ebbs[i]);
4163 debugLog("dir registers allocated so far:\n");
4164 reg = hTabFirstItem(dynDirectRegNames, &hkey);
4167 debugLog(" -- #%d reg = %s key %d, rIdx = %d, size %d\n",i++,reg->name,hkey, reg->rIdx,reg->size);
4168 reg = hTabNextItem(dynDirectRegNames, &hkey);
4173 if (options.dump_pack)
4174 dumpEbbsToFileExt (DUMP_PACK, ebbi);
4176 /* first determine for each live range the number of
4177 registers & the type of registers required for each */
4180 /* and serially allocate registers */
4181 serialRegAssign (ebbs, count);
4183 /* if stack was extended then tell the user */
4186 /* werror(W_TOOMANY_SPILS,"stack", */
4187 /* _G.stackExtend,currFunc->name,""); */
4193 /* werror(W_TOOMANY_SPILS,"data space", */
4194 /* _G.dataExtend,currFunc->name,""); */
4198 /* after that create the register mask
4199 for each of the instruction */
4200 createRegMask (ebbs, count);
4202 /* redo that offsets for stacked automatic variables */
4203 redoStackOffsets ();
4205 if (options.dump_rassgn)
4206 dumpEbbsToFileExt (DUMP_RASSGN, ebbi);
4208 /* now get back the chain */
4209 ic = iCodeLabelOptimize (iCodeFromeBBlock (ebbs, count));
4211 debugLog ("ebbs after optimizing:\n");
4212 dumpEbbsToDebug (ebbs, count);
4217 /* free up any _G.stackSpil locations allocated */
4218 applyToSet (_G.stackSpil, deallocStackSpil);
4220 setToNull ((void *) &_G.stackSpil);
4221 setToNull ((void *) &_G.spiltSet);
4222 /* mark all registers as free */
4223 //pic14_freeAllRegs ();
4225 debugLog ("leaving\n<><><><><><><><><><><><><><><><><>\n");