1 /*------------------------------------------------------------------------
3 SDCCralloc.c - source file for register allocation. (8051) specific
5 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998)
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 In other words, you are welcome to use, share and improve this program.
22 You are forbidden to forbid anyone else to use, share and improve
23 what you give them. Help stamp out software-hoarding!
24 -------------------------------------------------------------------------*/
30 /*-----------------------------------------------------------------*/
31 /* At this point we start getting processor specific although */
32 /* some routines are non-processor specific & can be reused when */
33 /* targetting other processors. The decision for this will have */
34 /* to be made on a routine by routine basis */
35 /* routines used to pack registers are most definitely not reusable */
36 /* since the pack the registers depending strictly on the MCU */
37 /*-----------------------------------------------------------------*/
39 extern void gen51Code (iCode *);
48 bitVect *totRegAssigned; /* final set of LRs that got into registers */
51 bitVect *funcrUsed; /* registers used in a function */
54 bitVect *allBitregs; /* all bit registers */
58 /* Shared with gen.c */
59 int mcs51_ptrRegReq; /* one byte pointer register required */
65 {REG_GPR, R2_IDX, REG_GPR, "r2", "ar2", "0", 2, 1},
66 {REG_GPR, R3_IDX, REG_GPR, "r3", "ar3", "0", 3, 1},
67 {REG_GPR, R4_IDX, REG_GPR, "r4", "ar4", "0", 4, 1},
68 {REG_GPR, R5_IDX, REG_GPR, "r5", "ar5", "0", 5, 1},
69 {REG_GPR, R6_IDX, REG_GPR, "r6", "ar6", "0", 6, 1},
70 {REG_GPR, R7_IDX, REG_GPR, "r7", "ar7", "0", 7, 1},
71 {REG_PTR, R0_IDX, REG_PTR, "r0", "ar0", "0", 0, 1},
72 {REG_PTR, R1_IDX, REG_PTR, "r1", "ar1", "0", 1, 1},
73 {REG_BIT, B0_IDX, REG_BIT, "b0", "b0", "bits", 0, 1},
74 {REG_BIT, B1_IDX, REG_BIT, "b1", "b1", "bits", 1, 1},
75 {REG_BIT, B2_IDX, REG_BIT, "b2", "b2", "bits", 2, 1},
76 {REG_BIT, B3_IDX, REG_BIT, "b3", "b3", "bits", 3, 1},
77 {REG_BIT, B4_IDX, REG_BIT, "b4", "b4", "bits", 4, 1},
78 {REG_BIT, B5_IDX, REG_BIT, "b5", "b5", "bits", 5, 1},
79 {REG_BIT, B6_IDX, REG_BIT, "b6", "b6", "bits", 6, 1},
80 {REG_BIT, B7_IDX, REG_BIT, "b7", "b7", "bits", 7, 1},
81 {REG_GPR, X8_IDX, REG_GPR, "x8", "x8", "xreg", 0, 1},
82 {REG_GPR, X9_IDX, REG_GPR, "x9", "x9", "xreg", 1, 1},
83 {REG_GPR, X10_IDX, REG_GPR, "x10", "x10", "xreg", 2, 1},
84 {REG_GPR, X11_IDX, REG_GPR, "x11", "x11", "xreg", 3, 1},
85 {REG_GPR, X12_IDX, REG_GPR, "x12", "x12", "xreg", 4, 1},
86 {REG_CND, CND_IDX, REG_CND, "C", "psw", "0xd0", 0, 1},
87 {0, DPL_IDX, 0, "dpl", "dpl", "0x82", 0, 0},
88 {0, DPH_IDX, 0, "dph", "dph", "0x83", 0, 0},
89 {0, B_IDX, 0, "b", "b", "0xf0", 0, 0},
90 {0, A_IDX, 0, "a", "acc", "0xe0", 0, 0},
93 static void spillThis (symbol *);
94 static void freeAllRegs ();
96 /*-----------------------------------------------------------------*/
97 /* allocReg - allocates register of given type */
98 /*-----------------------------------------------------------------*/
100 allocReg (short type)
104 for (i = 0; i < mcs51_nRegs; i++)
107 /* if type is given as 0 then any
108 free register will do */
112 regs8051[i].isFree = 0;
115 bitVectSetBit (currFunc->regsUsed, i);
118 /* other wise look for specific type
120 if (regs8051[i].isFree &&
121 regs8051[i].type == type)
123 regs8051[i].isFree = 0;
126 bitVectSetBit (currFunc->regsUsed, i);
133 /*-----------------------------------------------------------------*/
134 /* allocThisReg - allocates a particular register (if free) */
135 /*-----------------------------------------------------------------*/
137 allocThisReg (regs * reg)
144 currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, reg->rIdx);
150 /*-----------------------------------------------------------------*/
151 /* mcs51_regWithIdx - returns pointer to register with index number*/
152 /*-----------------------------------------------------------------*/
154 mcs51_regWithIdx (int idx)
158 for (i = 0; i < sizeof(regs8051)/sizeof(regs); i++)
159 if (regs8051[i].rIdx == idx)
162 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
163 "regWithIdx not found");
167 /*-----------------------------------------------------------------*/
168 /* freeReg - frees a register */
169 /*-----------------------------------------------------------------*/
175 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
176 "freeReg - Freeing NULL register");
184 /*-----------------------------------------------------------------*/
185 /* nFreeRegs - returns number of free registers */
186 /*-----------------------------------------------------------------*/
193 for (i = 0; i < mcs51_nRegs; i++)
194 if (regs8051[i].isFree && regs8051[i].type == type)
199 /*-----------------------------------------------------------------*/
200 /* nfreeRegsType - free registers with type */
201 /*-----------------------------------------------------------------*/
203 nfreeRegsType (int type)
208 if ((nfr = nFreeRegs (type)) == 0)
209 return nFreeRegs (REG_GPR);
212 return nFreeRegs (type);
215 /*-----------------------------------------------------------------*/
216 /* useReg - marks a register as used */
217 /*-----------------------------------------------------------------*/
224 /*-----------------------------------------------------------------*/
225 /* computeSpillable - given a point find the spillable live ranges */
226 /*-----------------------------------------------------------------*/
228 computeSpillable (iCode * ic)
232 /* spillable live ranges are those that are live at this
233 point . the following categories need to be subtracted
235 a) - those that are already spilt
236 b) - if being used by this one
237 c) - defined by this one */
239 spillable = bitVectCopy (ic->rlive);
241 bitVectCplAnd (spillable, _G.spiltSet); /* those already spilt */
243 bitVectCplAnd (spillable, ic->uses); /* used in this one */
244 bitVectUnSetBit (spillable, ic->defKey);
245 spillable = bitVectIntersect (spillable, _G.regAssigned);
250 /*-----------------------------------------------------------------*/
251 /* bitType - will return 1 if the symbol has type REG_BIT */
252 /*-----------------------------------------------------------------*/
254 bitType (symbol * sym, eBBlock * ebp, iCode * ic)
256 return (sym->regType == REG_BIT ? 1 : 0);
259 /*-----------------------------------------------------------------*/
260 /* noSpilLoc - return true if a variable has no spil location */
261 /*-----------------------------------------------------------------*/
263 noSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
265 return (sym->usl.spillLoc ? 0 : 1);
268 /*-----------------------------------------------------------------*/
269 /* hasSpilLoc - will return 1 if the symbol has spil location */
270 /*-----------------------------------------------------------------*/
272 hasSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
274 return (sym->usl.spillLoc ? 1 : 0);
277 /*-----------------------------------------------------------------*/
278 /* directSpilLoc - will return 1 if the spillocation is in direct */
279 /*-----------------------------------------------------------------*/
281 directSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
283 if (sym->usl.spillLoc &&
284 (IN_DIRSPACE (SPEC_OCLS (sym->usl.spillLoc->etype))))
290 /*-----------------------------------------------------------------*/
291 /* hasSpilLocnoUptr - will return 1 if the symbol has spil location */
292 /* but is not used as a pointer */
293 /*-----------------------------------------------------------------*/
295 hasSpilLocnoUptr (symbol * sym, eBBlock * ebp, iCode * ic)
297 return ((sym->usl.spillLoc && !sym->uptr) ? 1 : 0);
300 /*-----------------------------------------------------------------*/
301 /* rematable - will return 1 if the remat flag is set */
302 /*-----------------------------------------------------------------*/
304 rematable (symbol * sym, eBBlock * ebp, iCode * ic)
309 /*-----------------------------------------------------------------*/
310 /* notUsedInRemaining - not used or defined in remain of the block */
311 /*-----------------------------------------------------------------*/
313 notUsedInRemaining (symbol * sym, eBBlock * ebp, iCode * ic)
315 return ((usedInRemaining (operandFromSymbol (sym), ic) ? 0 : 1) &&
316 allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq));
319 /*-----------------------------------------------------------------*/
320 /* allLRs - return true for all */
321 /*-----------------------------------------------------------------*/
323 allLRs (symbol * sym, eBBlock * ebp, iCode * ic)
328 /*-----------------------------------------------------------------*/
329 /* liveRangesWith - applies function to a given set of live range */
330 /*-----------------------------------------------------------------*/
332 liveRangesWith (bitVect * lrs, int (func) (symbol *, eBBlock *, iCode *),
333 eBBlock * ebp, iCode * ic)
338 if (!lrs || !lrs->size)
341 for (i = 1; i < lrs->size; i++)
344 if (!bitVectBitValue (lrs, i))
347 /* if we don't find it in the live range
348 hash table we are in serious trouble */
349 if (!(sym = hTabItemWithKey (liveRanges, i)))
351 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
352 "liveRangesWith could not find liveRange");
356 if (func (sym, ebp, ic) && bitVectBitValue (_G.regAssigned, sym->key))
357 addSetHead (&rset, sym);
364 /*-----------------------------------------------------------------*/
365 /* leastUsedLR - given a set determines which is the least used */
366 /*-----------------------------------------------------------------*/
368 leastUsedLR (set * sset)
370 symbol *sym = NULL, *lsym = NULL;
372 sym = lsym = setFirstItem (sset);
377 for (; lsym; lsym = setNextItem (sset))
380 /* if usage is the same then prefer
381 to spill the smaller of the two */
382 if (lsym->used == sym->used)
383 if (getSize (lsym->type) < getSize (sym->type))
387 if (lsym->used < sym->used)
392 setToNull ((void *) &sset);
397 /*-----------------------------------------------------------------*/
398 /* noOverLap - will iterate through the list looking for over lap */
399 /*-----------------------------------------------------------------*/
401 noOverLap (set * itmpStack, symbol * fsym)
405 for (sym = setFirstItem (itmpStack); sym;
406 sym = setNextItem (itmpStack))
408 if (bitVectBitValue(sym->clashes,fsym->key)) return 0;
413 /*-----------------------------------------------------------------*/
414 /* isFree - will return 1 if the a free spil location is found */
415 /*-----------------------------------------------------------------*/
420 V_ARG (symbol **, sloc);
421 V_ARG (symbol *, fsym);
423 /* if already found */
427 /* if it is free && and the itmp assigned to
428 this does not have any overlapping live ranges
429 with the one currently being assigned and
430 the size can be accomodated */
432 noOverLap (sym->usl.itmpStack, fsym) &&
433 getSize (sym->type) >= getSize (fsym->type))
442 /*-----------------------------------------------------------------*/
443 /* spillLRWithPtrReg :- will spil those live ranges which use PTR */
444 /*-----------------------------------------------------------------*/
446 spillLRWithPtrReg (symbol * forSym)
452 if (!_G.regAssigned ||
453 bitVectIsZero (_G.regAssigned))
456 r0 = mcs51_regWithIdx (R0_IDX);
457 r1 = mcs51_regWithIdx (R1_IDX);
459 /* for all live ranges */
460 for (lrsym = hTabFirstItem (liveRanges, &k); lrsym;
461 lrsym = hTabNextItem (liveRanges, &k))
465 /* if no registers assigned to it or spilt */
466 /* if it does not overlap this then
467 no need to spill it */
469 if (lrsym->isspilt || !lrsym->nRegs ||
470 (lrsym->liveTo < forSym->liveFrom))
473 /* go thru the registers : if it is either
474 r0 or r1 then spill it */
475 for (j = 0; j < lrsym->nRegs; j++)
476 if (lrsym->regs[j] == r0 ||
477 lrsym->regs[j] == r1)
486 /*-----------------------------------------------------------------*/
487 /* createStackSpil - create a location on the stack to spil */
488 /*-----------------------------------------------------------------*/
490 createStackSpil (symbol * sym)
493 int useXstack, model;
497 /* first go try and find a free one that is already
498 existing on the stack */
499 if (applyToSet (_G.stackSpil, isFree, &sloc, sym))
501 /* found a free one : just update & return */
502 sym->usl.spillLoc = sloc;
505 addSetHead (&sloc->usl.itmpStack, sym);
509 /* could not then have to create one , this is the hard part
510 we need to allocate this on the stack : this is really a
511 hack!! but cannot think of anything better at this time */
513 if (SNPRINTF (slocBuffer, sizeof(slocBuffer),
514 "sloc%d", _G.slocNum++) >= sizeof (slocBuffer))
516 fprintf (stderr, "***Internal error: slocBuffer overflowed: %s:%d\n",
521 sloc = newiTemp (slocBuffer);
523 /* set the type to the spilling symbol */
524 sloc->type = copyLinkChain (sym->type);
525 sloc->etype = getSpec (sloc->type);
526 if (!IS_BIT (sloc->etype))
528 SPEC_SCLS (sloc->etype) = S_DATA;
530 SPEC_EXTR (sloc->etype) = 0;
531 SPEC_STAT (sloc->etype) = 0;
532 SPEC_VOLATILE(sloc->etype) = 0;
533 SPEC_ABSA(sloc->etype) = 0;
535 /* we don't allow it to be allocated`
536 onto the external stack since : so we
537 temporarily turn it off ; we also
538 turn off memory model to prevent
539 the spil from going to the external storage
542 useXstack = options.useXstack;
543 model = options.model;
544 /* noOverlay = options.noOverlay; */
545 /* options.noOverlay = 1; */
546 options.model = options.useXstack = 0;
550 options.useXstack = useXstack;
551 options.model = model;
552 /* options.noOverlay = noOverlay; */
553 sloc->isref = 1; /* to prevent compiler warning */
555 /* if it is on the stack then update the stack */
556 if (IN_STACK (sloc->etype))
558 currFunc->stack += getSize (sloc->type);
559 _G.stackExtend += getSize (sloc->type);
562 _G.dataExtend += getSize (sloc->type);
564 /* add it to the _G.stackSpil set */
565 addSetHead (&_G.stackSpil, sloc);
566 sym->usl.spillLoc = sloc;
569 /* add it to the set of itempStack set
570 of the spill location */
571 addSetHead (&sloc->usl.itmpStack, sym);
575 /*-----------------------------------------------------------------*/
576 /* isSpiltOnStack - returns true if the spil location is on stack */
577 /*-----------------------------------------------------------------*/
579 isSpiltOnStack (symbol * sym)
589 /* if (sym->_G.stackSpil) */
592 if (!sym->usl.spillLoc)
595 etype = getSpec (sym->usl.spillLoc->type);
596 if (IN_STACK (etype))
602 /*-----------------------------------------------------------------*/
603 /* spillThis - spils a specific operand */
604 /*-----------------------------------------------------------------*/
606 spillThis (symbol * sym)
609 /* if this is rematerializable or has a spillLocation
610 we are okay, else we need to create a spillLocation
612 if (!(sym->remat || sym->usl.spillLoc))
613 createStackSpil (sym);
615 /* mark it has spilt & put it in the spilt set */
616 sym->isspilt = sym->spillA = 1;
617 _G.spiltSet = bitVectSetBit (_G.spiltSet, sym->key);
619 bitVectUnSetBit (_G.regAssigned, sym->key);
620 bitVectUnSetBit (_G.totRegAssigned, sym->key);
622 for (i = 0; i < sym->nRegs; i++)
626 freeReg (sym->regs[i]);
630 /* if spilt on stack then free up r0 & r1
631 if they could have been assigned to some
633 if (!mcs51_ptrRegReq && isSpiltOnStack (sym))
636 spillLRWithPtrReg (sym);
639 if (sym->usl.spillLoc && !sym->remat)
640 sym->usl.spillLoc->allocreq++;
644 /*-----------------------------------------------------------------*/
645 /* selectSpil - select a iTemp to spil : rather a simple procedure */
646 /*-----------------------------------------------------------------*/
648 selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
650 bitVect *lrcs = NULL;
654 /* get the spillable live ranges */
655 lrcs = computeSpillable (ic);
657 /* remove incompatible registers */
658 if ((forSym->regType == REG_PTR) || (forSym->regType == REG_GPR))
660 selectS = liveRangesWith (lrcs, bitType, ebp, ic);
662 for (sym = setFirstItem (selectS); sym; sym = setNextItem (selectS))
664 bitVectUnSetBit (lrcs, sym->key);
668 /* get all live ranges that are rematerializable */
669 if ((selectS = liveRangesWith (lrcs, rematable, ebp, ic)))
671 /* return the least used of these */
672 return leastUsedLR (selectS);
675 /* get live ranges with spillLocations in direct space */
676 if ((selectS = liveRangesWith (lrcs, directSpilLoc, ebp, ic)))
678 sym = leastUsedLR (selectS);
679 strncpyz (sym->rname,
680 sym->usl.spillLoc->rname[0] ?
681 sym->usl.spillLoc->rname : sym->usl.spillLoc->name,
684 /* mark it as allocation required */
685 sym->usl.spillLoc->allocreq++;
689 /* if the symbol is local to the block then */
690 if (forSym->liveTo < ebp->lSeq)
692 /* check if there are any live ranges allocated
693 to registers that are not used in this block */
694 if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInBlock, ebp, ic)))
696 sym = leastUsedLR (selectS);
697 /* if this is not rematerializable */
706 /* check if there are any live ranges that not
707 used in the remainder of the block */
709 !isiCodeInFunctionCall (ic) &&
710 (selectS = liveRangesWith (lrcs, notUsedInRemaining, ebp, ic)))
712 sym = leastUsedLR (selectS);
725 /* find live ranges with spillocation && not used as pointers */
726 if ((selectS = liveRangesWith (lrcs, hasSpilLocnoUptr, ebp, ic)))
728 sym = leastUsedLR (selectS);
729 /* mark this as allocation required */
730 sym->usl.spillLoc->allocreq++;
734 /* find live ranges with spillocation */
735 if ((selectS = liveRangesWith (lrcs, hasSpilLoc, ebp, ic)))
737 sym = leastUsedLR (selectS);
738 sym->usl.spillLoc->allocreq++;
742 /* couldn't find then we need to create a spil
743 location on the stack , for which one? the least
745 if ((selectS = liveRangesWith (lrcs, noSpilLoc, ebp, ic)))
747 /* return a created spil location */
748 sym = createStackSpil (leastUsedLR (selectS));
749 sym->usl.spillLoc->allocreq++;
753 /* this is an extreme situation we will spill
754 this one : happens very rarely but it does happen */
760 /*-----------------------------------------------------------------*/
761 /* spilSomething - spil some variable & mark registers as free */
762 /*-----------------------------------------------------------------*/
764 spilSomething (iCode * ic, eBBlock * ebp, symbol * forSym)
769 /* get something we can spil */
770 ssym = selectSpil (ic, ebp, forSym);
772 /* mark it as spilt */
773 ssym->isspilt = ssym->spillA = 1;
774 _G.spiltSet = bitVectSetBit (_G.spiltSet, ssym->key);
776 /* mark it as not register assigned &
777 take it away from the set */
778 bitVectUnSetBit (_G.regAssigned, ssym->key);
779 bitVectUnSetBit (_G.totRegAssigned, ssym->key);
781 /* mark the registers as free */
782 for (i = 0; i < ssym->nRegs; i++)
784 freeReg (ssym->regs[i]);
786 /* if spilt on stack then free up r0 & r1
787 if they could have been assigned to as gprs */
788 if (!mcs51_ptrRegReq && isSpiltOnStack (ssym))
791 spillLRWithPtrReg (ssym);
794 /* if this was a block level spil then insert push & pop
795 at the start & end of block respectively */
798 iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
799 /* add push to the start of the block */
800 addiCodeToeBBlock (ebp, nic, (ebp->sch->op == LABEL ?
801 ebp->sch->next : ebp->sch));
802 nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
803 /* add pop to the end of the block */
804 addiCodeToeBBlock (ebp, nic, NULL);
807 /* if spilt because not used in the remainder of the
808 block then add a push before this instruction and
809 a pop at the end of the block */
810 if (ssym->remainSpil)
813 iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
814 /* add push just before this instruction */
815 addiCodeToeBBlock (ebp, nic, ic);
817 nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
818 /* add pop to the end of the block */
819 addiCodeToeBBlock (ebp, nic, NULL);
828 /*-----------------------------------------------------------------*/
829 /* getRegPtr - will try for PTR if not a GPR type if not spil */
830 /*-----------------------------------------------------------------*/
832 getRegPtr (iCode * ic, eBBlock * ebp, symbol * sym)
838 /* try for a ptr type */
839 if ((reg = allocReg (REG_PTR)))
842 /* try for gpr type */
843 if ((reg = allocReg (REG_GPR)))
846 /* we have to spil */
847 if (!spilSomething (ic, ebp, sym))
850 /* make sure partially assigned registers aren't reused */
851 for (j=0; j<=sym->nRegs; j++)
853 sym->regs[j]->isFree = 0;
855 /* this looks like an infinite loop but
856 in really selectSpil will abort */
860 /*-----------------------------------------------------------------*/
861 /* getRegGpr - will try for GPR if not spil */
862 /*-----------------------------------------------------------------*/
864 getRegGpr (iCode * ic, eBBlock * ebp, symbol * sym)
870 /* try for gpr type */
871 if ((reg = allocReg (REG_GPR)))
874 if (!mcs51_ptrRegReq)
875 if ((reg = allocReg (REG_PTR)))
878 /* we have to spil */
879 if (!spilSomething (ic, ebp, sym))
882 /* make sure partially assigned registers aren't reused */
883 for (j=0; j<=sym->nRegs; j++)
885 sym->regs[j]->isFree = 0;
887 /* this looks like an infinite loop but
888 in really selectSpil will abort */
892 /*-----------------------------------------------------------------*/
893 /* getRegBit - will try for Bit if not spill this */
894 /*-----------------------------------------------------------------*/
895 static regs *getRegBit (symbol * sym)
899 /* try for a bit type */
900 if ((reg = allocReg (REG_BIT)))
907 /*-----------------------------------------------------------------*/
908 /* getRegPtrNoSpil - get it cannot be spilt */
909 /*-----------------------------------------------------------------*/
910 static regs *getRegPtrNoSpil()
914 /* try for a ptr type */
915 if ((reg = allocReg (REG_PTR)))
918 /* try for gpr type */
919 if ((reg = allocReg (REG_GPR)))
924 /* just to make the compiler happy */
928 /*-----------------------------------------------------------------*/
929 /* getRegGprNoSpil - get it cannot be spilt */
930 /*-----------------------------------------------------------------*/
931 static regs *getRegGprNoSpil()
935 if ((reg = allocReg (REG_GPR)))
938 if (!mcs51_ptrRegReq)
939 if ((reg = allocReg (REG_PTR)))
944 /* just to make the compiler happy */
948 /*-----------------------------------------------------------------*/
949 /* getRegBitNoSpil - get it cannot be spilt */
950 /*-----------------------------------------------------------------*/
951 static regs *getRegBitNoSpil()
955 /* try for a ptr type */
956 if ((reg = allocReg (REG_BIT)))
959 /* try for gpr type */
960 if ((reg = allocReg (REG_GPR)))
965 /* just to make the compiler happy */
969 /*-----------------------------------------------------------------*/
970 /* symHasReg - symbol has a given register */
971 /*-----------------------------------------------------------------*/
973 symHasReg (symbol * sym, regs * reg)
977 for (i = 0; i < sym->nRegs; i++)
978 if (sym->regs[i] == reg)
984 /*-----------------------------------------------------------------*/
985 /* updateRegUsage - update the registers in use at the start of */
987 /*-----------------------------------------------------------------*/
989 updateRegUsage (iCode * ic)
993 for (reg=0; reg<mcs51_nRegs; reg++)
995 if (regs8051[reg].isFree)
997 ic->riu &= ~(1<<regs8051[reg].offset);
1001 ic->riu |= (1<<regs8051[reg].offset);
1002 BitBankUsed |= (reg >= 8);
1007 /*-----------------------------------------------------------------*/
1008 /* deassignLRs - check the live to and if they have registers & are */
1009 /* not spilt then free up the registers */
1010 /*-----------------------------------------------------------------*/
1012 deassignLRs (iCode * ic, eBBlock * ebp)
1018 for (sym = hTabFirstItem (liveRanges, &k); sym;
1019 sym = hTabNextItem (liveRanges, &k))
1022 symbol *psym = NULL;
1023 /* if it does not end here */
1024 if (sym->liveTo > ic->seq)
1027 /* if it was spilt on stack then we can
1028 mark the stack spil location as free */
1033 sym->usl.spillLoc->isFree = 1;
1039 if (!bitVectBitValue (_G.regAssigned, sym->key))
1042 /* special case check if this is an IFX &
1043 the privious one was a pop and the
1044 previous one was not spilt then keep track
1046 if (ic->op == IFX && ic->prev &&
1047 ic->prev->op == IPOP &&
1048 !ic->prev->parmPush &&
1049 !OP_SYMBOL (IC_LEFT (ic->prev))->isspilt)
1050 psym = OP_SYMBOL (IC_LEFT (ic->prev));
1056 bitVectUnSetBit (_G.regAssigned, sym->key);
1058 /* if the result of this one needs registers
1059 and does not have it then assign it right
1061 if (IC_RESULT (ic) &&
1062 !(SKIP_IC2 (ic) || /* not a special icode */
1063 ic->op == JUMPTABLE ||
1068 POINTER_SET (ic)) &&
1069 (result = OP_SYMBOL (IC_RESULT (ic))) && /* has a result */
1070 result->liveTo > ic->seq && /* and will live beyond this */
1071 result->liveTo <= ebp->lSeq && /* does not go beyond this block */
1072 result->liveFrom == ic->seq && /* does not start before here */
1073 result->regType == sym->regType && /* same register types */
1074 result->nRegs && /* which needs registers */
1075 !result->isspilt && /* and does not already have them */
1077 !bitVectBitValue (_G.regAssigned, result->key) &&
1078 /* the number of free regs + number of regs in this LR
1079 can accomodate the what result Needs */
1080 ((nfreeRegsType (result->regType) +
1081 sym->nRegs) >= result->nRegs)
1085 for (i = 0; i < result->nRegs; i++)
1087 result->regs[i] = sym->regs[i];
1089 result->regs[i] = getRegGpr (ic, ebp, result);
1091 _G.regAssigned = bitVectSetBit (_G.regAssigned, result->key);
1092 _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, result->key);
1096 /* free the remaining */
1097 for (; i < sym->nRegs; i++)
1101 if (!symHasReg (psym, sym->regs[i]))
1102 freeReg (sym->regs[i]);
1105 freeReg (sym->regs[i]);
1112 /*-----------------------------------------------------------------*/
1113 /* reassignLR - reassign this to registers */
1114 /*-----------------------------------------------------------------*/
1116 reassignLR (operand * op)
1118 symbol *sym = OP_SYMBOL (op);
1121 /* not spilt any more */
1122 sym->isspilt = sym->spillA = sym->blockSpil = sym->remainSpil = 0;
1123 bitVectUnSetBit (_G.spiltSet, sym->key);
1125 _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
1126 _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, sym->key);
1130 for (i = 0; i < sym->nRegs; i++)
1131 sym->regs[i]->isFree = 0;
1134 /*-----------------------------------------------------------------*/
1135 /* willCauseSpill - determines if allocating will cause a spill */
1136 /*-----------------------------------------------------------------*/
1138 willCauseSpill (int nr, int rt)
1140 /* first check if there are any available registers
1141 of the type required */
1144 /* special case for pointer type
1145 if pointer type not avlb then
1146 check for type gpr */
1147 if (nFreeRegs (rt) >= nr)
1149 if (nFreeRegs (REG_GPR) >= nr)
1152 else if (rt == REG_BIT)
1154 if (nFreeRegs (rt) >= nr)
1159 if (mcs51_ptrRegReq)
1161 if (nFreeRegs (rt) >= nr)
1166 if (nFreeRegs (REG_PTR) +
1167 nFreeRegs (REG_GPR) >= nr)
1172 /* it will cause a spil */
1176 /*-----------------------------------------------------------------*/
1177 /* positionRegs - the allocator can allocate same registers to res- */
1178 /* ult and operand, if this happens make sure they are in the same */
1179 /* position as the operand otherwise chaos results */
1180 /*-----------------------------------------------------------------*/
1182 positionRegs (symbol * result, symbol * opsym)
1184 int count = min (result->nRegs, opsym->nRegs);
1185 int i, j = 0, shared = 0;
1188 /* if the result has been spilt then cannot share */
1193 /* first make sure that they actually share */
1194 for (i = 0; i < count; i++)
1196 for (j = 0; j < count; j++)
1198 if (result->regs[i] == opsym->regs[j] && i != j)
1208 regs *tmp = result->regs[i];
1209 result->regs[i] = result->regs[j];
1210 result->regs[j] = tmp;
1217 /*------------------------------------------------------------------*/
1218 /* verifyRegsAssigned - make sure an iTemp is properly initialized; */
1219 /* it should either have registers or have beed spilled. Otherwise, */
1220 /* there was an uninitialized variable, so just spill this to get */
1221 /* the operand in a valid state. */
1222 /*------------------------------------------------------------------*/
1224 verifyRegsAssigned (operand *op, iCode * ic)
1229 if (!IS_ITEMP (op)) return;
1231 sym = OP_SYMBOL (op);
1232 if (sym->isspilt) return;
1233 if (!sym->nRegs) return;
1234 if (sym->regs[0]) return;
1236 werrorfl (ic->filename, ic->lineno, W_LOCAL_NOINIT,
1237 sym->prereqv ? sym->prereqv->name : sym->name);
1242 /*-----------------------------------------------------------------*/
1243 /* serialRegAssign - serially allocate registers to the variables */
1244 /*-----------------------------------------------------------------*/
1246 serialRegAssign (eBBlock ** ebbs, int count)
1250 /* for all blocks */
1251 for (i = 0; i < count; i++)
1256 if (ebbs[i]->noPath &&
1257 (ebbs[i]->entryLabel != entryLabel &&
1258 ebbs[i]->entryLabel != returnLabel))
1261 /* for all instructions do */
1262 for (ic = ebbs[i]->sch; ic; ic = ic->next)
1266 /* if this is an ipop that means some live
1267 range will have to be assigned again */
1269 reassignLR (IC_LEFT (ic));
1271 /* if result is present && is a true symbol */
1272 if (IC_RESULT (ic) && ic->op != IFX &&
1273 IS_TRUE_SYMOP (IC_RESULT (ic)))
1274 OP_SYMBOL (IC_RESULT (ic))->allocreq++;
1276 /* take away registers from live
1277 ranges that end at this instruction */
1278 deassignLRs (ic, ebbs[i]);
1280 /* some don't need registers */
1281 if (SKIP_IC2 (ic) ||
1282 ic->op == JUMPTABLE ||
1286 (IC_RESULT (ic) && POINTER_SET (ic)))
1289 /* now we need to allocate registers
1290 only for the result */
1291 if (IC_RESULT (ic)) {
1292 symbol *sym = OP_SYMBOL (IC_RESULT (ic));
1298 /* Make sure any spill location is definitely allocated */
1299 if (sym->isspilt && !sym->remat && sym->usl.spillLoc &&
1300 !sym->usl.spillLoc->allocreq)
1302 sym->usl.spillLoc->allocreq++;
1305 /* if it does not need or is spilt
1306 or is already assigned to registers
1307 or will not live beyond this instructions */
1310 bitVectBitValue (_G.regAssigned, sym->key) ||
1311 sym->liveTo <= ic->seq)
1314 /* if some liverange has been spilt at the block level
1315 and this one live beyond this block then spil this
1317 if (_G.blockSpil && sym->liveTo > ebbs[i]->lSeq) {
1322 willCS = willCauseSpill (sym->nRegs, sym->regType);
1323 /* if this is a bit variable then don't use precious registers
1324 along with expensive bit-to-char conversions but just spill
1326 if (willCS && SPEC_NOUN(sym->etype) == V_BIT) {
1331 /* if trying to allocate this will cause
1332 a spill and there is nothing to spill
1333 or this one is rematerializable then
1335 spillable = computeSpillable (ic);
1336 if (sym->remat || (willCS && bitVectIsZero (spillable))) {
1341 /* If the live range preceeds the point of definition
1342 then ideally we must take into account registers that
1343 have been allocated after sym->liveFrom but freed
1344 before ic->seq. This is complicated, so spill this
1345 symbol instead and let fillGaps handle the allocation. */
1346 if (sym->liveFrom < ic->seq) {
1351 /* if it has a spillocation & is used less than
1352 all other live ranges then spill this */
1354 if (sym->usl.spillLoc) {
1355 symbol *leastUsed = leastUsedLR (liveRangesWith (spillable,
1356 allLRs, ebbs[i], ic));
1357 if (leastUsed && leastUsed->used > sym->used) {
1362 /* if none of the liveRanges have a spillLocation then better
1363 to spill this one than anything else already assigned to registers */
1364 if (liveRangesWith(spillable,noSpilLoc,ebbs[i],ic)) {
1365 /* if this is local to this block then we might find a block spil */
1366 if (!(sym->liveFrom >= ebbs[i]->fSeq && sym->liveTo <= ebbs[i]->lSeq)) {
1373 /* if we need ptr regs for the right side
1375 if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic))
1376 && getSize (OP_SYMBOL (IC_LEFT (ic))->type) <= (unsigned int) PTRSIZE) {
1380 if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic))
1381 && SPEC_OCLS(OP_SYMBOL (IC_LEFT (ic))->etype) == idata) {
1385 if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic))
1386 && SPEC_OCLS(OP_SYMBOL (IC_RIGHT (ic))->etype) == idata) {
1391 /* else we assign registers to it */
1392 _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
1393 _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, sym->key);
1395 for (j = 0; j < sym->nRegs; j++) {
1396 sym->regs[j] = NULL;
1397 if (sym->regType == REG_PTR)
1398 sym->regs[j] = getRegPtr (ic, ebbs[i], sym);
1399 else if (sym->regType == REG_BIT)
1400 sym->regs[j] = getRegBit (sym);
1403 if (ic->op == CAST && IS_SYMOP (IC_RIGHT (ic)))
1405 symbol * right = OP_SYMBOL (IC_RIGHT (ic));
1407 if (right->regs[j] && (right->regType != REG_BIT))
1408 sym->regs[j] = allocThisReg (right->regs[j]);
1411 sym->regs[j] = getRegGpr (ic, ebbs[i], sym);
1414 /* if the allocation failed which means
1415 this was spilt then break */
1419 for (i=0; i < sym->nRegs ; i++ )
1420 sym->regs[i] = NULL;
1425 if (!POINTER_SET(ic) && !POINTER_GET(ic)) {
1426 /* if it shares registers with operands make sure
1427 that they are in the same position */
1428 if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)) &&
1429 OP_SYMBOL (IC_LEFT (ic))->nRegs) {
1430 positionRegs (OP_SYMBOL (IC_RESULT (ic)),
1431 OP_SYMBOL (IC_LEFT (ic)));
1433 /* do the same for the right operand */
1434 if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)) &&
1435 OP_SYMBOL (IC_RIGHT (ic))->nRegs) {
1436 positionRegs (OP_SYMBOL (IC_RESULT (ic)),
1437 OP_SYMBOL (IC_RIGHT (ic)));
1450 /* Check for and fix any problems with uninitialized operands */
1451 for (i = 0; i < count; i++)
1455 if (ebbs[i]->noPath &&
1456 (ebbs[i]->entryLabel != entryLabel &&
1457 ebbs[i]->entryLabel != returnLabel))
1460 for (ic = ebbs[i]->sch; ic; ic = ic->next)
1467 verifyRegsAssigned (IC_COND (ic), ic);
1471 if (ic->op == JUMPTABLE)
1473 verifyRegsAssigned (IC_JTCOND (ic), ic);
1477 verifyRegsAssigned (IC_RESULT (ic), ic);
1478 verifyRegsAssigned (IC_LEFT (ic), ic);
1479 verifyRegsAssigned (IC_RIGHT (ic), ic);
1484 /*-----------------------------------------------------------------*/
1485 /* fillGaps - Try to fill in the Gaps left by Pass1 */
1486 /*-----------------------------------------------------------------*/
1487 static void fillGaps()
1494 if (getenv("DISABLE_FILL_GAPS")) return;
1496 /* look for liveranges that were spilt by the allocator */
1497 for (sym = hTabFirstItem(liveRanges,&key) ; sym ;
1498 sym = hTabNextItem(liveRanges,&key)) {
1503 if (!sym->spillA || !sym->clashes || sym->remat) continue ;
1505 /* find the liveRanges this one clashes with, that are
1506 still assigned to registers & mark the registers as used*/
1507 for ( i = 0 ; i < sym->clashes->size ; i ++) {
1511 if (bitVectBitValue(sym->clashes,i) == 0 || /* those that clash with this */
1512 bitVectBitValue(_G.totRegAssigned,i) == 0) /* and are still assigned to registers */
1515 clr = hTabItemWithKey(liveRanges,i);
1518 /* mark these registers as used */
1519 for (k = 0 ; k < clr->nRegs ; k++ )
1520 useReg(clr->regs[k]);
1523 if (willCauseSpill(sym->nRegs,sym->regType)) {
1524 /* NOPE :( clear all registers & and continue */
1530 for (i = 0 ; i < sym->defs->size ; i++ )
1532 if (bitVectBitValue(sym->defs,i))
1534 if (!(ic = hTabItemWithKey(iCodehTab,i)))
1541 D(printf("Attempting fillGaps on %s: [",sym->name));
1542 /* THERE IS HOPE !!!! */
1543 for (i=0; i < sym->nRegs ; i++ ) {
1544 if (sym->regType == REG_PTR)
1545 sym->regs[i] = getRegPtrNoSpil ();
1546 else if (sym->regType == REG_BIT)
1547 sym->regs[i] = getRegBitNoSpil ();
1550 sym->regs[i] = NULL;
1551 if (ic && ic->op == CAST && IS_SYMOP (IC_RIGHT (ic)))
1553 symbol * right = OP_SYMBOL (IC_RIGHT (ic));
1556 sym->regs[i] = allocThisReg (right->regs[i]);
1559 sym->regs[i] = getRegGprNoSpil ();
1561 D(printf("%s ", sym->regs[i]->name));
1565 /* For all its definitions check if the registers
1566 allocated needs positioning NOTE: we can position
1567 only ONCE if more than One positioning required
1569 We may need to perform the checks twice; once to
1570 position the registers as needed, the second to
1571 verify any register repositioning is still
1575 for (pass=0; pass<2; pass++) {
1576 D(printf(" checking definitions\n"));
1577 for (i = 0 ; i < sym->defs->size ; i++ ) {
1578 if (bitVectBitValue(sym->defs,i)) {
1579 if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ;
1580 D(printf(" ic->seq = %d\n", ic->seq));
1581 if (SKIP_IC(ic)) continue;
1582 assert(isSymbolEqual(sym,OP_SYMBOL(IC_RESULT(ic)))); /* just making sure */
1583 /* if left is assigned to registers */
1584 if (IS_SYMOP(IC_LEFT(ic)))
1586 D(printf(" left = "));
1587 D(printOperand(IC_LEFT(ic),NULL));
1589 if (IS_SYMOP(IC_LEFT(ic)) &&
1590 bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_LEFT(ic))->key)) {
1591 pdone += (positionRegs(sym,OP_SYMBOL(IC_LEFT(ic)))>0);
1593 if (IS_SYMOP(IC_RIGHT(ic)))
1595 D(printf(" right = "));
1596 D(printOperand(IC_RIGHT(ic),NULL));
1598 if (IS_SYMOP(IC_RIGHT(ic)) &&
1599 bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RIGHT(ic))->key)) {
1600 pdone += (positionRegs(sym,OP_SYMBOL(IC_RIGHT(ic)))>0);
1602 D(printf(" pdone = %d\n", pdone));
1603 if (pdone > 1) break;
1606 D(printf(" checking uses\n"));
1607 for (i = 0 ; i < sym->uses->size ; i++ ) {
1608 if (bitVectBitValue(sym->uses,i)) {
1610 if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ;
1611 D(printf(" ic->seq = %d\n", ic->seq));
1612 if (SKIP_IC(ic)) continue;
1613 if (POINTER_SET(ic) || POINTER_GET(ic)) continue ;
1615 /* if result is assigned to registers */
1616 if (IS_SYMOP(IC_RESULT(ic)))
1618 D(printf(" result = "));
1619 D(printOperand(IC_RESULT(ic),NULL));
1621 if (IS_SYMOP(IC_RESULT(ic)) &&
1622 bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RESULT(ic))->key)) {
1623 pdone += (positionRegs(sym,OP_SYMBOL(IC_RESULT(ic)))>0);
1625 D(printf(" pdone = %d\n", pdone));
1626 if (pdone > 1) break;
1629 if (pdone == 0) break; /* second pass only if regs repositioned */
1630 if (pdone > 1) break;
1632 D(printf(" sym->regs = ["));
1633 for (i=0; i < sym->nRegs ; i++ )
1634 D(printf("%s ", sym->regs[i]->name));
1636 /* had to position more than once GIVE UP */
1638 /* UNDO all the changes we made to try this */
1640 for (i=0; i < sym->nRegs ; i++ ) {
1641 sym->regs[i] = NULL;
1644 D(printf ("Fill Gap gave up due to positioning for %s in function %s\n",sym->name, currFunc ? currFunc->name : "UNKNOWN"));
1647 D(printf ("FILLED GAP for %s in function %s\n",sym->name, currFunc ? currFunc->name : "UNKNOWN"));
1649 _G.totRegAssigned = bitVectSetBit(_G.totRegAssigned,sym->key);
1650 sym->isspilt = sym->spillA = 0 ;
1651 sym->usl.spillLoc->allocreq--;
1656 /*-----------------------------------------------------------------*/
1657 /* findAllBitregs :- returns bit vector of all bit registers */
1658 /*-----------------------------------------------------------------*/
1660 findAllBitregs (void)
1662 bitVect *rmask = newBitVect (mcs51_nRegs);
1665 for (j = 0; j < mcs51_nRegs; j++)
1667 if (regs8051[j].type == REG_BIT)
1668 rmask = bitVectSetBit (rmask, regs8051[j].rIdx);
1674 /*-----------------------------------------------------------------*/
1675 /* mcs51_allBitregs :- returns bit vector of all bit registers */
1676 /*-----------------------------------------------------------------*/
1678 mcs51_allBitregs (void)
1680 return _G.allBitregs;
1683 /*-----------------------------------------------------------------*/
1684 /* rUmaskForOp :- returns register mask for an operand */
1685 /*-----------------------------------------------------------------*/
1687 mcs51_rUmaskForOp (operand * op)
1693 /* only temporaries are assigned registers */
1697 sym = OP_SYMBOL (op);
1699 /* if spilt or no registers assigned to it
1701 if (sym->isspilt || !sym->nRegs)
1704 rumask = newBitVect (mcs51_nRegs);
1706 for (j = 0; j < sym->nRegs; j++)
1708 if (sym->regs[j]) /* EEP - debug */
1709 rumask = bitVectSetBit (rumask, sym->regs[j]->rIdx);
1715 /*-----------------------------------------------------------------*/
1716 /* regsUsedIniCode :- returns bit vector of registers used in iCode */
1717 /*-----------------------------------------------------------------*/
1719 regsUsedIniCode (iCode * ic)
1721 bitVect *rmask = newBitVect (mcs51_nRegs);
1723 /* do the special cases first */
1726 rmask = bitVectUnion (rmask,
1727 mcs51_rUmaskForOp (IC_COND (ic)));
1731 /* for the jumptable */
1732 if (ic->op == JUMPTABLE)
1734 rmask = bitVectUnion (rmask,
1735 mcs51_rUmaskForOp (IC_JTCOND (ic)));
1740 /* of all other cases */
1742 rmask = bitVectUnion (rmask,
1743 mcs51_rUmaskForOp (IC_LEFT (ic)));
1747 rmask = bitVectUnion (rmask,
1748 mcs51_rUmaskForOp (IC_RIGHT (ic)));
1751 rmask = bitVectUnion (rmask,
1752 mcs51_rUmaskForOp (IC_RESULT (ic)));
1758 /*-----------------------------------------------------------------*/
1759 /* createRegMask - for each instruction will determine the regsUsed */
1760 /*-----------------------------------------------------------------*/
1762 createRegMask (eBBlock ** ebbs, int count)
1766 /* for all blocks */
1767 for (i = 0; i < count; i++)
1771 if (ebbs[i]->noPath &&
1772 (ebbs[i]->entryLabel != entryLabel &&
1773 ebbs[i]->entryLabel != returnLabel))
1776 /* for all instructions */
1777 for (ic = ebbs[i]->sch; ic; ic = ic->next)
1782 if (SKIP_IC2 (ic) || !ic->rlive)
1785 /* first mark the registers used in this
1787 ic->rUsed = regsUsedIniCode (ic);
1788 _G.funcrUsed = bitVectUnion (_G.funcrUsed, ic->rUsed);
1790 /* now create the register mask for those
1791 registers that are in use : this is a
1792 super set of ic->rUsed */
1793 ic->rMask = newBitVect (mcs51_nRegs + 1);
1795 /* for all live Ranges alive at this point */
1796 for (j = 1; j < ic->rlive->size; j++)
1801 /* if not alive then continue */
1802 if (!bitVectBitValue (ic->rlive, j))
1805 /* find the live range we are interested in */
1806 if (!(sym = hTabItemWithKey (liveRanges, j)))
1808 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
1809 "createRegMask cannot find live range");
1810 fprintf(stderr, "\tmissing live range: key=%d\n", j);
1814 /* if no register assigned to it */
1815 if (!sym->nRegs || sym->isspilt)
1818 /* for all the registers allocated to it */
1819 for (k = 0; k < sym->nRegs; k++)
1822 bitVectSetBit (ic->rMask, sym->regs[k]->rIdx);
1828 /*-----------------------------------------------------------------*/
1829 /* rematStr - returns the rematerialized string for a remat var */
1830 /*-----------------------------------------------------------------*/
1832 rematStr (symbol * sym)
1835 iCode *ic = sym->rematiCode;
1842 /* if plus or minus print the right hand side */
1843 if (ic->op == '+' || ic->op == '-')
1845 SNPRINTF (s, sizeof(buffer) - strlen(buffer),
1846 "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)),
1849 ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
1853 /* cast then continue */
1854 if (IS_CAST_ICODE(ic)) {
1855 ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
1858 /* we reached the end */
1859 SNPRINTF (s, sizeof(buffer) - strlen(buffer),
1860 "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
1867 /*-----------------------------------------------------------------*/
1868 /* regTypeNum - computes the type & number of registers required */
1869 /*-----------------------------------------------------------------*/
1871 regTypeNum (eBBlock *ebbs)
1877 /* for each live range do */
1878 for (sym = hTabFirstItem (liveRanges, &k); sym;
1879 sym = hTabNextItem (liveRanges, &k))
1882 /* if used zero times then no registers needed */
1883 if ((sym->liveTo - sym->liveFrom) == 0)
1887 /* if the live range is a temporary */
1891 /* if the type is marked as a conditional */
1892 if (sym->regType == REG_CND)
1895 /* if used in return only then we don't
1897 if (sym->ruonly || sym->accuse)
1899 if (IS_AGGREGATE (sym->type) || sym->isptr)
1900 sym->type = aggrToPtr (sym->type, FALSE);
1904 /* if the symbol has only one definition &
1905 that definition is a get_pointer */
1906 if (bitVectnBitsOn (sym->defs) == 1 &&
1907 (ic = hTabItemWithKey (iCodehTab,
1908 bitVectFirstBit (sym->defs))) &&
1910 !IS_BITVAR (sym->etype) &&
1911 (aggrToPtrDclType (operandType (IC_LEFT (ic)), FALSE) == POINTER))
1914 if (ptrPseudoSymSafe (sym, ic))
1916 ptrPseudoSymConvert (sym, ic, rematStr (OP_SYMBOL (IC_LEFT (ic))));
1920 /* if in data space or idata space then try to
1921 allocate pointer register */
1925 /* if not then we require registers */
1926 sym->nRegs = ((IS_AGGREGATE (sym->type) || sym->isptr) ?
1927 getSize (sym->type = aggrToPtr (sym->type, FALSE)) :
1928 getSize (sym->type));
1932 fprintf (stderr, "allocated more than 4 or 0 registers for type ");
1933 printTypeChain (sym->type, stderr);
1934 fprintf (stderr, "\n");
1937 /* determine the type of register required */
1938 if (sym->nRegs == 1 && IS_PTR (sym->type) && sym->uptr)
1939 sym->regType = REG_PTR;
1940 else if (IS_BIT(sym->type))
1941 sym->regType = REG_BIT;
1943 sym->regType = REG_GPR;
1946 /* for the first run we don't provide */
1947 /* registers for true symbols we will */
1948 /* see how things go */
1954 /*-----------------------------------------------------------------*/
1955 /* freeAllRegs - mark all registers as free */
1956 /*-----------------------------------------------------------------*/
1962 for (i = 0; i < mcs51_nRegs; i++)
1963 regs8051[i].isFree = 1;
1966 /*-----------------------------------------------------------------*/
1967 /* deallocStackSpil - this will set the stack pointer back */
1968 /*-----------------------------------------------------------------*/
1970 DEFSETFUNC (deallocStackSpil)
1978 /*-----------------------------------------------------------------*/
1979 /* farSpacePackable - returns the packable icode for far variables */
1980 /*-----------------------------------------------------------------*/
1982 farSpacePackable (iCode * ic)
1986 /* go thru till we find a definition for the
1987 symbol on the right */
1988 for (dic = ic->prev; dic; dic = dic->prev)
1990 /* if the definition is a call then no */
1991 if ((dic->op == CALL || dic->op == PCALL) &&
1992 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
1997 /* if shift by unknown amount then not */
1998 if ((dic->op == LEFT_OP || dic->op == RIGHT_OP) &&
1999 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
2002 /* if pointer get and size > 1 */
2003 if (POINTER_GET (dic) &&
2004 getSize (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)) > 1)
2007 if (POINTER_SET (dic) &&
2008 getSize (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)) > 1)
2013 if (IC_COND (dic) &&
2014 IS_TRUE_SYMOP (IC_COND (dic)) &&
2015 isOperandInFarSpace (IC_COND (dic)))
2018 else if (dic->op == JUMPTABLE)
2020 if (IC_JTCOND (dic) &&
2021 IS_TRUE_SYMOP (IC_JTCOND (dic)) &&
2022 isOperandInFarSpace (IC_JTCOND (dic)))
2027 /* if any tree is a true symbol in far space */
2028 if (IC_RESULT (dic) &&
2029 IS_TRUE_SYMOP (IC_RESULT (dic)) &&
2030 isOperandInFarSpace (IC_RESULT (dic)))
2033 if (IC_RIGHT (dic) &&
2034 IS_TRUE_SYMOP (IC_RIGHT (dic)) &&
2035 isOperandInFarSpace (IC_RIGHT (dic)) &&
2036 !isOperandEqual (IC_RIGHT (dic), IC_RESULT (ic)))
2039 if (IC_LEFT (dic) &&
2040 IS_TRUE_SYMOP (IC_LEFT (dic)) &&
2041 isOperandInFarSpace (IC_LEFT (dic)) &&
2042 !isOperandEqual (IC_LEFT (dic), IC_RESULT (ic)))
2046 if (isOperandEqual (IC_RIGHT (ic), IC_RESULT (dic)))
2048 if ((dic->op == LEFT_OP ||
2049 dic->op == RIGHT_OP ||
2051 IS_OP_LITERAL (IC_RIGHT (dic)))
2061 /*-----------------------------------------------------------------*/
2062 /* packRegsForAssign - register reduction for assignment */
2063 /*-----------------------------------------------------------------*/
2065 packRegsForAssign (iCode * ic, eBBlock * ebp)
2069 if (!IS_ITEMP (IC_RIGHT (ic)) ||
2070 OP_SYMBOL (IC_RIGHT (ic))->isind ||
2071 OP_LIVETO (IC_RIGHT (ic)) > ic->seq)
2076 /* if the true symbol is defined in far space or on stack
2077 then we should not since this will increase register pressure */
2078 if (isOperandInFarSpace(IC_RESULT(ic)) && !farSpacePackable(ic)) {
2082 /* find the definition of iTempNN scanning backwards if we find a
2083 a use of the true symbol in before we find the definition then
2085 for (dic = ic->prev; dic; dic = dic->prev)
2087 int crossedCall = 0;
2089 /* We can pack across a function call only if it's a local */
2090 /* variable or our parameter. Never pack global variables */
2091 /* or parameters to a function we call. */
2092 if ((dic->op == CALL || dic->op == PCALL))
2094 if (!OP_SYMBOL (IC_RESULT (ic))->ismyparm
2095 && !OP_SYMBOL (IC_RESULT (ic))->islocal)
2106 if (IS_SYMOP (IC_COND (dic)) &&
2107 (IC_COND (dic)->key == IC_RESULT (ic)->key ||
2108 IC_COND (dic)->key == IC_RIGHT (ic)->key))
2116 if (IS_TRUE_SYMOP (IC_RESULT (dic)) &&
2117 IS_OP_VOLATILE (IC_RESULT (dic)))
2123 if (IS_SYMOP (IC_RESULT (dic)) &&
2124 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
2126 if (POINTER_SET (dic))
2132 if (IS_SYMOP (IC_RIGHT (dic)) &&
2133 (IC_RIGHT (dic)->key == IC_RESULT (ic)->key ||
2134 IC_RIGHT (dic)->key == IC_RIGHT (ic)->key))
2140 if (IS_SYMOP (IC_LEFT (dic)) &&
2141 (IC_LEFT (dic)->key == IC_RESULT (ic)->key ||
2142 IC_LEFT (dic)->key == IC_RIGHT (ic)->key))
2148 if (IS_SYMOP (IC_RESULT (dic)) &&
2149 IC_RESULT (dic)->key == IC_RESULT (ic)->key)
2165 return 0; /* did not find */
2167 /* if assignment then check that right is not a bit */
2168 if (ASSIGNMENT (ic) && !POINTER_SET (ic))
2170 sym_link *etype = operandType (IC_RESULT (dic));
2171 if (IS_BITFIELD (etype))
2173 /* if result is a bit too then it's ok */
2174 etype = operandType (IC_RESULT (ic));
2175 if (!IS_BITFIELD (etype))
2182 /* if assignment then check that right is not a bit */
2183 if (ASSIGNMENT (dic) && !POINTER_SET (dic))
2185 sym_link *etype = operandType (IC_RIGHT (dic));
2186 if (IS_BITFIELD (etype))
2188 /* if result is a bit too then it's ok */
2189 etype = operandType (IC_RESULT (dic));
2190 if (!IS_BITFIELD (etype))
2195 /* if the result is on stack or iaccess then it must be
2196 the same atleast one of the operands */
2197 if (OP_SYMBOL (IC_RESULT (ic))->onStack ||
2198 OP_SYMBOL (IC_RESULT (ic))->iaccess)
2201 /* the operation has only one symbol
2202 operator then we can pack */
2203 if ((IC_LEFT (dic) && !IS_SYMOP (IC_LEFT (dic))) ||
2204 (IC_RIGHT (dic) && !IS_SYMOP (IC_RIGHT (dic))))
2207 if (!((IC_LEFT (dic) &&
2208 IC_RESULT (ic)->key == IC_LEFT (dic)->key) ||
2210 IC_RESULT (ic)->key == IC_RIGHT (dic)->key)))
2214 /* found the definition */
2215 /* replace the result with the result of */
2216 /* this assignment and remove this assignment */
2217 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
2218 ReplaceOpWithCheaperOp(&IC_RESULT (dic), IC_RESULT (ic));
2220 if (IS_ITEMP (IC_RESULT (dic)) && OP_SYMBOL (IC_RESULT (dic))->liveFrom > dic->seq)
2222 OP_SYMBOL (IC_RESULT (dic))->liveFrom = dic->seq;
2224 // TODO: and the otherway around?
2226 /* delete from liverange table also
2227 delete from all the points inbetween and the new
2229 for (sic = dic; sic != ic; sic = sic->next)
2231 bitVectUnSetBit (sic->rlive, IC_RESULT (ic)->key);
2232 if (IS_ITEMP (IC_RESULT (dic)))
2233 bitVectSetBit (sic->rlive, IC_RESULT (dic)->key);
2236 remiCodeFromeBBlock (ebp, ic);
2237 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
2238 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
2239 OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
2243 /*------------------------------------------------------------------*/
2244 /* findAssignToSym : scanning backwards looks for first assig found */
2245 /*------------------------------------------------------------------*/
2247 findAssignToSym (operand * op, iCode * ic)
2251 /* This routine is used to find sequences like
2253 ...; (intervening ops don't use iTempAA or modify FOO)
2254 blah = blah + iTempAA;
2256 and eliminate the use of iTempAA, freeing up its register for
2260 for (dic = ic->prev; dic; dic = dic->prev)
2263 /* if definition by assignment */
2264 if (dic->op == '=' &&
2265 !POINTER_SET (dic) &&
2266 IC_RESULT (dic)->key == op->key
2267 /* && IS_TRUE_SYMOP(IC_RIGHT(dic)) */
2269 break; /* found where this temp was defined */
2271 /* if we find an usage then we cannot delete it */
2275 if (IC_COND (dic) && IC_COND (dic)->key == op->key)
2278 else if (dic->op == JUMPTABLE)
2280 if (IC_JTCOND (dic) && IC_JTCOND (dic)->key == op->key)
2285 if (IC_LEFT (dic) && IC_LEFT (dic)->key == op->key)
2288 if (IC_RIGHT (dic) && IC_RIGHT (dic)->key == op->key)
2291 if (POINTER_SET (dic) && IC_RESULT (dic)->key == op->key)
2297 return NULL; /* didn't find any assignment to op */
2299 /* we are interested only if defined in far space */
2300 /* or in stack space in case of + & - */
2302 /* if assigned to a non-symbol then don't repack regs */
2303 if (!IS_SYMOP (IC_RIGHT (dic)))
2306 /* if the symbol is volatile then we should not */
2307 if (isOperandVolatile (IC_RIGHT (dic), TRUE))
2309 /* XXX TODO --- should we be passing FALSE to isOperandVolatile()?
2310 What does it mean for an iTemp to be volatile, anyway? Passing
2311 TRUE is more cautious but may prevent possible optimizations */
2313 /* if the symbol is in far space then we should not */
2314 if (isOperandInFarSpace (IC_RIGHT (dic)))
2317 /* for + & - operations make sure that
2318 if it is on the stack it is the same
2319 as one of the three operands */
2320 if ((ic->op == '+' || ic->op == '-') &&
2321 OP_SYMBOL (IC_RIGHT (dic))->onStack)
2324 if (IC_RESULT (ic)->key != IC_RIGHT (dic)->key &&
2325 IC_LEFT (ic)->key != IC_RIGHT (dic)->key &&
2326 IC_RIGHT (ic)->key != IC_RIGHT (dic)->key)
2330 /* now make sure that the right side of dic
2331 is not defined between ic & dic */
2334 iCode *sic = dic->next;
2336 for (; sic != ic; sic = sic->next)
2337 if (IC_RESULT (sic) &&
2338 IC_RESULT (sic)->key == IC_RIGHT (dic)->key)
2345 /*-----------------------------------------------------------------*/
2346 /* reassignAliasedSym - used by packRegsForSupport to replace */
2347 /* redundant iTemp with equivalent symbol */
2348 /*-----------------------------------------------------------------*/
2350 reassignAliasedSym (eBBlock *ebp, iCode *assignment, iCode *use, operand *op)
2353 unsigned oldSymKey, newSymKey;
2355 oldSymKey = op->key;
2356 newSymKey = IC_RIGHT(assignment)->key;
2358 /* only track live ranges of compiler-generated temporaries */
2359 if (!IS_ITEMP(IC_RIGHT(assignment)))
2362 /* update the live-value bitmaps */
2363 for (ic = assignment; ic != use; ic = ic->next) {
2364 bitVectUnSetBit (ic->rlive, oldSymKey);
2366 ic->rlive = bitVectSetBit (ic->rlive, newSymKey);
2369 /* update the sym of the used operand */
2370 OP_SYMBOL(op) = OP_SYMBOL(IC_RIGHT(assignment));
2371 op->key = OP_SYMBOL(op)->key;
2372 OP_SYMBOL(op)->accuse = 0;
2374 /* update the sym's liverange */
2375 if ( OP_LIVETO(op) < ic->seq )
2376 setToRange(op, ic->seq, FALSE);
2378 /* remove the assignment iCode now that its result is unused */
2379 remiCodeFromeBBlock (ebp, assignment);
2380 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(assignment))->defs, assignment->key);
2381 hTabDeleteItem (&iCodehTab, assignment->key, assignment, DELETE_ITEM, NULL);
2385 /*-----------------------------------------------------------------*/
2386 /* packRegsForSupport :- reduce some registers for support calls */
2387 /*-----------------------------------------------------------------*/
2389 packRegsForSupport (iCode * ic, eBBlock * ebp)
2393 /* for the left & right operand :- look to see if the
2394 left was assigned a true symbol in far space in that
2395 case replace them */
2397 if (IS_ITEMP (IC_LEFT (ic)) &&
2398 OP_SYMBOL (IC_LEFT (ic))->liveTo <= ic->seq)
2400 dic = findAssignToSym (IC_LEFT (ic), ic);
2404 /* found it we need to remove it from the block */
2405 reassignAliasedSym (ebp, dic, ic, IC_LEFT(ic));
2410 /* do the same for the right operand */
2411 if (IS_ITEMP (IC_RIGHT (ic)) &&
2412 OP_SYMBOL (IC_RIGHT (ic))->liveTo <= ic->seq)
2414 iCode *dic = findAssignToSym (IC_RIGHT (ic), ic);
2418 /* if this is a subtraction & the result
2419 is a true symbol in far space then don't pack */
2420 if (ic->op == '-' && IS_TRUE_SYMOP (IC_RESULT (dic)))
2422 sym_link *etype = getSpec (operandType (IC_RESULT (dic)));
2423 if (IN_FARSPACE (SPEC_OCLS (etype)))
2426 /* found it we need to remove it from the
2428 reassignAliasedSym (ebp, dic, ic, IC_RIGHT(ic));
2437 #define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
2440 /*-----------------------------------------------------------------*/
2441 /* packRegsForOneuse : - will reduce some registers for single Use */
2442 /*-----------------------------------------------------------------*/
2444 packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
2448 /* if returning a literal then do nothing */
2452 /* if rematerializable or already return use then do nothing */
2453 if (OP_SYMBOL(op)->remat || OP_SYMBOL(op)->ruonly)
2456 /* only upto 2 bytes since we cannot predict
2457 the usage of b, & acc */
2458 if (getSize (operandType (op)) > (fReturnSizeMCS51 - 2))
2461 if (ic->op != RETURN &&
2463 !POINTER_SET (ic) &&
2467 if (ic->op == SEND && ic->argreg != 1) return NULL;
2469 /* this routine will mark the a symbol as used in one
2470 instruction use only && if the defintion is local
2471 (ie. within the basic block) && has only one definition &&
2472 that definition is either a return value from a
2473 function or does not contain any variables in
2475 if (bitVectnBitsOn (OP_USES (op)) > 1)
2478 /* if it has only one defintion */
2479 if (bitVectnBitsOn (OP_DEFS (op)) > 1)
2480 return NULL; /* has more than one definition */
2482 /* get that definition */
2484 hTabItemWithKey (iCodehTab,
2485 bitVectFirstBit (OP_DEFS (op)))))
2488 /* if that only usage is a cast */
2489 if (dic->op == CAST) {
2490 /* to a bigger type */
2491 if (getSize(OP_SYM_TYPE(IC_RESULT(dic))) >
2492 getSize(OP_SYM_TYPE(IC_RIGHT(dic)))) {
2493 /* than we can not, since we cannot predict the usage of b & acc */
2498 /* found the definition now check if it is local */
2499 if (dic->seq < ebp->fSeq ||
2500 dic->seq > ebp->lSeq)
2501 return NULL; /* non-local */
2503 /* now check if it is the return from
2505 if (dic->op == CALL || dic->op == PCALL)
2507 if (ic->op != SEND && ic->op != RETURN &&
2508 !POINTER_SET(ic) && !POINTER_GET(ic))
2510 OP_SYMBOL (op)->ruonly = 1;
2516 /* otherwise check that the definition does
2517 not contain any symbols in far space */
2518 if (isOperandInFarSpace (IC_LEFT (dic)) ||
2519 isOperandInFarSpace (IC_RIGHT (dic)) ||
2520 IS_OP_RUONLY (IC_LEFT (ic)) ||
2521 IS_OP_RUONLY (IC_RIGHT (ic)))
2526 /* if pointer set then make sure the pointer
2528 if (POINTER_SET (dic) &&
2529 !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)))
2532 if (POINTER_GET (dic) &&
2533 !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)))
2537 /* Make sure no overlapping liverange is already assigned to DPTR */
2538 if (OP_SYMBOL(op)->clashes)
2543 for (i = 0 ; i < OP_SYMBOL(op)->clashes->size ; i++ )
2545 if (bitVectBitValue(OP_SYMBOL(op)->clashes,i))
2547 sym = hTabItemWithKey(liveRanges,i);
2556 /* also make sure the intervenening instructions
2557 don't have any thing in far space */
2558 for (dic = dic->next; dic && dic != ic && sic != ic; dic = dic->next)
2561 /* if there is an intervening function call then no */
2562 if (dic->op == CALL || dic->op == PCALL)
2564 /* if pointer set then make sure the pointer
2566 if (POINTER_SET (dic) &&
2567 !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)))
2570 if (POINTER_GET (dic) &&
2571 !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)))
2574 /* if address of & the result is remat the okay */
2575 if (dic->op == ADDRESS_OF &&
2576 OP_SYMBOL (IC_RESULT (dic))->remat)
2579 /* if operand has size of three or more & this
2580 operation is a '*','/' or '%' then 'b' may
2582 if ((dic->op == '%' || dic->op == '/' || dic->op == '*') &&
2583 getSize (operandType (op)) >= 3)
2586 /* if left or right or result is in far space */
2587 if (isOperandInFarSpace (IC_LEFT (dic)) ||
2588 isOperandInFarSpace (IC_RIGHT (dic)) ||
2589 isOperandInFarSpace (IC_RESULT (dic)) ||
2590 IS_OP_RUONLY (IC_LEFT (dic)) ||
2591 IS_OP_RUONLY (IC_RIGHT (dic)) ||
2592 IS_OP_RUONLY (IC_RESULT (dic)))
2596 /* if left or right or result is on stack */
2597 if (isOperandOnStack(IC_LEFT(dic)) ||
2598 isOperandOnStack(IC_RIGHT(dic)) ||
2599 isOperandOnStack(IC_RESULT(dic))) {
2604 OP_SYMBOL (op)->ruonly = 1;
2608 /*-----------------------------------------------------------------*/
2609 /* isBitwiseOptimizable - requirements of JEAN LOUIS VERN */
2610 /*-----------------------------------------------------------------*/
2612 isBitwiseOptimizable (iCode * ic)
2614 sym_link *ltype = getSpec (operandType (IC_LEFT (ic)));
2615 sym_link *rtype = getSpec (operandType (IC_RIGHT (ic)));
2617 /* bitwise operations are considered optimizable
2618 under the following conditions (Jean-Louis VERN)
2630 if (IS_LITERAL(rtype) ||
2631 (IS_BITVAR (ltype) && IN_BITSPACE (SPEC_OCLS (ltype))))
2637 /*-----------------------------------------------------------------*/
2638 /* isCommutativeOp - tests whether this op cares what order its */
2639 /* operands are in */
2640 /*-----------------------------------------------------------------*/
2641 bool isCommutativeOp(unsigned int op)
2643 if (op == '+' || op == '*' || op == EQ_OP ||
2644 op == '^' || op == '|' || op == BITWISEAND)
2650 /*-----------------------------------------------------------------*/
2651 /* operandUsesAcc - determines whether the code generated for this */
2652 /* operand will have to use the accumulator */
2653 /*-----------------------------------------------------------------*/
2654 bool operandUsesAcc(operand *op)
2660 symbol *sym = OP_SYMBOL(op);
2664 return TRUE; /* duh! */
2666 if (IN_STACK(sym->etype) || sym->onStack ||
2667 (SPIL_LOC(op) && SPIL_LOC(op)->onStack))
2668 return TRUE; /* acc is used to calc stack offset */
2673 sym = SPIL_LOC(op); /* if spilled, look at spill location */
2675 return FALSE; /* more checks? */
2679 symspace = SPEC_OCLS(sym->etype);
2681 if (sym->iaccess && symspace->paged)
2682 return TRUE; /* must fetch paged indirect sym via accumulator */
2684 if (IN_BITSPACE(symspace))
2685 return TRUE; /* fetching bit vars uses the accumulator */
2687 if (IN_FARSPACE(symspace) || IN_CODESPACE(symspace))
2688 return TRUE; /* fetched via accumulator and dptr */
2694 /*-----------------------------------------------------------------*/
2695 /* packRegsForAccUse - pack registers for acc use */
2696 /*-----------------------------------------------------------------*/
2698 packRegsForAccUse (iCode * ic)
2702 /* if this is an aggregate, e.g. a one byte char array */
2703 if (IS_AGGREGATE(operandType(IC_RESULT(ic)))) {
2707 /* if we are calling a reentrant function that has stack parameters */
2708 if (ic->op == CALL &&
2709 IFFUNC_ISREENT(operandType(IC_LEFT(ic))) &&
2710 FUNC_HASSTACKPARM(operandType(IC_LEFT(ic))))
2713 if (ic->op == PCALL &&
2714 IFFUNC_ISREENT(operandType(IC_LEFT(ic))->next) &&
2715 FUNC_HASSTACKPARM(operandType(IC_LEFT(ic))->next))
2718 /* if + or - then it has to be one byte result */
2719 if ((ic->op == '+' || ic->op == '-')
2720 && getSize (operandType (IC_RESULT (ic))) > 1)
2723 /* if shift operation make sure right side is not a literal */
2724 if (ic->op == RIGHT_OP &&
2725 (isOperandLiteral (IC_RIGHT (ic)) ||
2726 getSize (operandType (IC_RESULT (ic))) > 1))
2729 if (ic->op == LEFT_OP &&
2730 (isOperandLiteral (IC_RIGHT (ic)) ||
2731 getSize (operandType (IC_RESULT (ic))) > 1))
2734 if (IS_BITWISE_OP (ic) &&
2735 getSize (operandType (IC_RESULT (ic))) > 1)
2739 /* has only one definition */
2740 if (bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) > 1)
2743 /* has only one use */
2744 if (bitVectnBitsOn (OP_USES (IC_RESULT (ic))) > 1)
2747 /* and the usage immediately follows this iCode */
2748 if (!(uic = hTabItemWithKey (iCodehTab,
2749 bitVectFirstBit (OP_USES (IC_RESULT (ic))))))
2752 if (ic->next != uic)
2755 /* if it is a conditional branch then we definitely can */
2759 if (uic->op == JUMPTABLE)
2762 if (POINTER_SET (uic) &&
2763 getSize (aggrToPtr (operandType (IC_RESULT (uic)), FALSE)) > 1)
2766 /* if the usage is not is an assignment
2767 or an arithmetic / bitwise / shift operation then not */
2768 if (uic->op != '=' &&
2769 !IS_ARITHMETIC_OP (uic) &&
2770 !IS_BITWISE_OP (uic) &&
2771 uic->op != LEFT_OP &&
2772 uic->op != RIGHT_OP)
2775 /* if used in ^ operation then make sure right is not a
2776 literal (WIML: Why is this?) */
2777 if (uic->op == '^' && isOperandLiteral (IC_RIGHT (uic)))
2780 /* if shift operation make sure right side is not a literal */
2781 /* WIML: Why is this? */
2782 if (uic->op == RIGHT_OP &&
2783 (isOperandLiteral (IC_RIGHT (uic)) ||
2784 getSize (operandType (IC_RESULT (uic))) > 1))
2786 if (uic->op == LEFT_OP &&
2787 (isOperandLiteral (IC_RIGHT (uic)) ||
2788 getSize (operandType (IC_RESULT (uic))) > 1))
2791 /* make sure that the result of this icode is not on the
2792 stack, since acc is used to compute stack offset */
2794 if (IS_TRUE_SYMOP (IC_RESULT (uic)) &&
2795 OP_SYMBOL (IC_RESULT (uic))->onStack)
2798 if (isOperandOnStack(IC_RESULT(uic)))
2802 /* if the usage has only one operand then we can */
2803 if (IC_LEFT (uic) == NULL ||
2804 IC_RIGHT (uic) == NULL)
2807 /* if the other operand uses the accumulator then we cannot */
2808 if ( (IC_LEFT(uic)->key == IC_RESULT(ic)->key &&
2809 operandUsesAcc(IC_RIGHT(uic))) ||
2810 (IC_RIGHT(uic)->key == IC_RESULT(ic)->key &&
2811 operandUsesAcc(IC_LEFT(uic))) )
2814 /* make sure this is on the left side if not commutative */
2815 /* except for '-', which has been written to be able to
2816 handle reversed operands */
2817 if (!(isCommutativeOp(ic->op) || ic->op == '-') &&
2818 IC_LEFT (uic)->key != IC_RESULT (ic)->key)
2822 // this is too dangerous and need further restrictions
2825 /* if one of them is a literal then we can */
2826 if ((IC_LEFT (uic) && IS_OP_LITERAL (IC_LEFT (uic))) ||
2827 (IC_RIGHT (uic) && IS_OP_LITERAL (IC_RIGHT (uic))))
2829 OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
2835 OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
2839 /*-----------------------------------------------------------------*/
2840 /* packForPush - heuristics to reduce iCode for pushing */
2841 /*-----------------------------------------------------------------*/
2843 packForPush (iCode * ic, eBBlock ** ebpp, int blockno)
2847 struct eBBlock * ebp=ebpp[blockno];
2849 if (ic->op != IPUSH || !IS_ITEMP (IC_LEFT (ic)))
2852 /* must have only definition & one usage */
2853 if (bitVectnBitsOn (OP_DEFS (IC_LEFT (ic))) != 1 ||
2854 bitVectnBitsOn (OP_USES (IC_LEFT (ic))) != 1)
2857 /* find the definition */
2858 if (!(dic = hTabItemWithKey (iCodehTab,
2859 bitVectFirstBit (OP_DEFS (IC_LEFT (ic))))))
2862 if (dic->op != '=' || POINTER_SET (dic))
2865 if (dic->seq < ebp->fSeq) { // Evelyn did this
2867 for (i=0; i<blockno; i++) {
2868 if (dic->seq >= ebpp[i]->fSeq && dic->seq <= ebpp[i]->lSeq) {
2873 wassert (i!=blockno); // no way to recover from here
2876 if (IS_SYMOP(IC_RIGHT(dic))) {
2877 /* make sure the right side does not have any definitions
2879 dbv = OP_DEFS(IC_RIGHT(dic));
2880 for (lic = ic; lic && lic != dic ; lic = lic->prev) {
2881 if (bitVectBitValue(dbv,lic->key))
2884 /* make sure they have the same type */
2885 if (IS_SPEC(operandType(IC_LEFT(ic))))
2887 sym_link *itype=operandType(IC_LEFT(ic));
2888 sym_link *ditype=operandType(IC_RIGHT(dic));
2890 if (SPEC_USIGN(itype)!=SPEC_USIGN(ditype) ||
2891 SPEC_LONG(itype)!=SPEC_LONG(ditype))
2894 /* extend the live range of replaced operand if needed */
2895 if (OP_SYMBOL(IC_RIGHT(dic))->liveTo < ic->seq) {
2896 OP_SYMBOL(IC_RIGHT(dic))->liveTo = ic->seq;
2898 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
2901 /* we now we know that it has one & only one def & use
2902 and the that the definition is an assignment */
2903 ReplaceOpWithCheaperOp(&IC_LEFT (ic), IC_RIGHT (dic));
2904 remiCodeFromeBBlock (ebp, dic);
2905 hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
2908 /*-----------------------------------------------------------------*/
2909 /* packRegisters - does some transformations to reduce register */
2911 /*-----------------------------------------------------------------*/
2913 packRegisters (eBBlock ** ebpp, int blockno)
2917 eBBlock *ebp=ebpp[blockno];
2923 /* look for assignments of the form */
2924 /* iTempNN = TRueSym (someoperation) SomeOperand */
2926 /* TrueSym := iTempNN:1 */
2927 for (ic = ebp->sch; ic; ic = ic->next)
2929 /* find assignment of the form TrueSym := iTempNN:1 */
2930 if (ic->op == '=' && !POINTER_SET (ic))
2931 change += packRegsForAssign (ic, ebp);
2938 for (ic = ebp->sch; ic; ic = ic->next)
2940 /* Fix for bug #979599: */
2943 /* Look for two subsequent iCodes with */
2945 /* _c = iTemp & op; */
2946 /* and replace them by */
2949 if ((ic->op == BITWISEAND || ic->op == '|' || ic->op == '^') &&
2951 ic->prev->op == '=' &&
2952 IS_ITEMP (IC_LEFT (ic)) &&
2953 IC_LEFT (ic) == IC_RESULT (ic->prev) &&
2954 isOperandEqual (IC_RESULT(ic), IC_RIGHT(ic->prev)))
2956 iCode* ic_prev = ic->prev;
2957 symbol* prev_result_sym = OP_SYMBOL (IC_RESULT (ic_prev));
2959 ReplaceOpWithCheaperOp (&IC_LEFT (ic), IC_RESULT (ic));
2960 if (IC_RESULT (ic_prev) != IC_RIGHT (ic))
2962 bitVectUnSetBit (OP_USES (IC_RESULT (ic_prev)), ic->key);
2963 if (/*IS_ITEMP (IC_RESULT (ic_prev)) && */
2964 prev_result_sym->liveTo == ic->seq)
2966 prev_result_sym->liveTo = ic_prev->seq;
2969 bitVectSetBit (OP_USES (IC_RESULT (ic)), ic->key);
2971 bitVectSetBit (ic->rlive, IC_RESULT (ic)->key);
2973 if (bitVectIsZero (OP_USES (IC_RESULT (ic_prev))))
2975 bitVectUnSetBit (ic->rlive, IC_RESULT (ic)->key);
2976 bitVectUnSetBit (OP_DEFS (IC_RESULT (ic_prev)), ic_prev->key);
2977 remiCodeFromeBBlock (ebp, ic_prev);
2978 hTabDeleteItem (&iCodehTab, ic_prev->key, ic_prev, DELETE_ITEM, NULL);
2982 /* if this is an itemp & result of an address of a true sym
2983 then mark this as rematerialisable */
2984 if (ic->op == ADDRESS_OF &&
2985 IS_ITEMP (IC_RESULT (ic)) &&
2986 IS_TRUE_SYMOP (IC_LEFT (ic)) &&
2987 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
2988 !OP_SYMBOL (IC_LEFT (ic))->onStack)
2990 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
2991 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
2992 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
2995 /* if straight assignment then carry remat flag if
2996 this is the only definition */
2997 if (ic->op == '=' &&
2998 !POINTER_SET (ic) &&
2999 IS_SYMOP (IC_RIGHT (ic)) &&
3000 OP_SYMBOL (IC_RIGHT (ic))->remat &&
3001 !IS_CAST_ICODE(OP_SYMBOL (IC_RIGHT (ic))->rematiCode) &&
3002 bitVectnBitsOn (OP_SYMBOL (IC_RESULT (ic))->defs) <= 1)
3004 OP_SYMBOL (IC_RESULT (ic))->remat =
3005 OP_SYMBOL (IC_RIGHT (ic))->remat;
3006 OP_SYMBOL (IC_RESULT (ic))->rematiCode =
3007 OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
3010 /* if cast to a generic pointer & the pointer being
3011 cast is remat, then we can remat this cast as well */
3012 if (ic->op == CAST &&
3013 IS_SYMOP(IC_RIGHT(ic)) &&
3014 OP_SYMBOL(IC_RIGHT(ic))->remat &&
3015 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1)
3017 sym_link *to_type = operandType(IC_LEFT(ic));
3018 sym_link *from_type = operandType(IC_RIGHT(ic));
3019 if (IS_GENPTR(to_type) && IS_PTR(from_type))
3021 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
3022 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
3023 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
3027 /* if this is a +/- operation with a rematerizable
3028 then mark this as rematerializable as well */
3029 if ((ic->op == '+' || ic->op == '-') &&
3030 (IS_SYMOP (IC_LEFT (ic)) &&
3031 IS_ITEMP (IC_RESULT (ic)) &&
3032 IS_OP_LITERAL (IC_RIGHT (ic))) &&
3033 OP_SYMBOL (IC_LEFT (ic))->remat &&
3034 (!IS_SYMOP (IC_RIGHT (ic)) || !IS_CAST_ICODE(OP_SYMBOL (IC_RIGHT (ic))->rematiCode)) &&
3035 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1)
3037 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
3038 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
3039 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
3042 /* mark the pointer usages */
3043 if (POINTER_SET (ic))
3044 OP_SYMBOL (IC_RESULT (ic))->uptr = 1;
3046 if (POINTER_GET (ic) &&
3047 IS_SYMOP(IC_LEFT (ic)))
3048 OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
3052 /* if we are using a symbol on the stack
3053 then we should say mcs51_ptrRegReq */
3054 if (options.useXstack && ic->parmPush
3055 && (ic->op == IPUSH || ic->op == IPOP))
3057 if (ic->op == IFX && IS_SYMOP (IC_COND (ic)))
3058 mcs51_ptrRegReq += ((OP_SYMBOL (IC_COND (ic))->onStack ||
3059 OP_SYMBOL (IC_COND (ic))->iaccess ||
3060 SPEC_OCLS(OP_SYMBOL (IC_COND (ic))->etype) == idata) ? 1 : 0);
3061 else if (ic->op == JUMPTABLE && IS_SYMOP (IC_JTCOND (ic)))
3062 mcs51_ptrRegReq += ((OP_SYMBOL (IC_JTCOND (ic))->onStack ||
3063 OP_SYMBOL (IC_JTCOND (ic))->iaccess ||
3064 SPEC_OCLS(OP_SYMBOL (IC_JTCOND (ic))->etype) == idata) ? 1 : 0);
3067 if (IS_SYMOP (IC_LEFT (ic)))
3068 mcs51_ptrRegReq += ((OP_SYMBOL (IC_LEFT (ic))->onStack ||
3069 OP_SYMBOL (IC_LEFT (ic))->iaccess ||
3070 SPEC_OCLS(OP_SYMBOL (IC_LEFT (ic))->etype) == idata) ? 1 : 0);
3071 if (IS_SYMOP (IC_RIGHT (ic)))
3072 mcs51_ptrRegReq += ((OP_SYMBOL (IC_RIGHT (ic))->onStack ||
3073 OP_SYMBOL (IC_RIGHT (ic))->iaccess ||
3074 SPEC_OCLS(OP_SYMBOL (IC_RIGHT (ic))->etype) == idata) ? 1 : 0);
3075 if (IS_SYMOP (IC_RESULT (ic)))
3076 mcs51_ptrRegReq += ((OP_SYMBOL (IC_RESULT (ic))->onStack ||
3077 OP_SYMBOL (IC_RESULT (ic))->iaccess ||
3078 SPEC_OCLS(OP_SYMBOL (IC_RESULT (ic))->etype) == idata) ? 1 : 0);
3079 if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic))
3080 && getSize (OP_SYMBOL (IC_LEFT (ic))->type) <= (unsigned int) PTRSIZE)
3082 if (POINTER_SET (ic) && IS_SYMOP (IC_RESULT (ic))
3083 && getSize (OP_SYMBOL (IC_RESULT (ic))->type) <= (unsigned int) PTRSIZE)
3088 /* if the condition of an if instruction
3089 is defined in the previous instruction and
3090 this is the only usage then
3091 mark the itemp as a conditional */
3092 if ((IS_CONDITIONAL (ic) ||
3093 (IS_BITWISE_OP(ic) && isBitwiseOptimizable (ic))) &&
3094 ic->next && ic->next->op == IFX &&
3095 bitVectnBitsOn (OP_USES(IC_RESULT(ic)))==1 &&
3096 isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
3097 OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
3099 OP_SYMBOL (IC_RESULT (ic))->regType = REG_CND;
3103 /* if the condition of an if instruction
3104 is defined in the previous GET_POINTER instruction and
3105 this is the only usage then
3106 mark the itemp as accumulator use */
3107 if ((POINTER_GET (ic) && getSize (operandType (IC_RESULT (ic))) <=1) &&
3108 ic->next && ic->next->op == IFX &&
3109 bitVectnBitsOn (OP_USES(IC_RESULT(ic)))==1 &&
3110 isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
3111 OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
3113 OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
3117 /* reduce for support function calls */
3118 if (ic->supportRtn || ic->op == '+' || ic->op == '-')
3119 packRegsForSupport (ic, ebp);
3121 /* some cases the redundant moves can
3122 can be eliminated for return statements */
3123 if ((ic->op == RETURN || (ic->op == SEND && ic->argreg == 1)) &&
3124 !isOperandInFarSpace (IC_LEFT (ic)) &&
3125 options.model == MODEL_SMALL) {
3126 packRegsForOneuse (ic, IC_LEFT (ic), ebp);
3129 /* if pointer set & left has a size more than
3130 one and right is not in far space */
3131 if (POINTER_SET (ic) &&
3132 !isOperandInFarSpace (IC_RIGHT (ic)) &&
3133 !OP_SYMBOL (IC_RESULT (ic))->remat &&
3134 !IS_OP_RUONLY (IC_RIGHT (ic)) &&
3135 getSize (aggrToPtr (operandType (IC_RESULT (ic)), FALSE)) > 1)
3136 packRegsForOneuse (ic, IC_RESULT (ic), ebp);
3138 /* if pointer get */
3139 if (POINTER_GET (ic) &&
3140 IS_SYMOP (IC_LEFT (ic)) &&
3141 !isOperandInFarSpace (IC_RESULT (ic)) &&
3142 !OP_SYMBOL (IC_LEFT (ic))->remat &&
3143 !IS_OP_RUONLY (IC_RESULT (ic)) &&
3144 getSize (aggrToPtr (operandType (IC_LEFT (ic)), FALSE)) > 1)
3145 packRegsForOneuse (ic, IC_LEFT (ic), ebp);
3148 /* if this is a cast for intergral promotion then
3149 check if it's the only use of the definition of the
3150 operand being casted/ if yes then replace
3151 the result of that arithmetic operation with
3152 this result and get rid of the cast */
3155 sym_link *fromType = operandType (IC_RIGHT (ic));
3156 sym_link *toType = operandType (IC_LEFT (ic));
3158 if (IS_INTEGRAL (fromType) && IS_INTEGRAL (toType) &&
3159 getSize (fromType) != getSize (toType) &&
3160 SPEC_USIGN (fromType) == SPEC_USIGN (toType))
3163 iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
3166 if (IS_ARITHMETIC_OP (dic))
3168 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
3169 ReplaceOpWithCheaperOp(&IC_RESULT (dic), IC_RESULT (ic));
3170 remiCodeFromeBBlock (ebp, ic);
3171 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
3172 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
3173 OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
3177 OP_SYMBOL (IC_RIGHT (ic))->ruonly = 0;
3183 /* if the type from and type to are the same
3184 then if this is the only use then packit */
3185 if (compareType (operandType (IC_RIGHT (ic)),
3186 operandType (IC_LEFT (ic))) == 1)
3188 iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
3191 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
3192 ReplaceOpWithCheaperOp(&IC_RESULT (dic), IC_RESULT (ic));
3193 remiCodeFromeBBlock (ebp, ic);
3194 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
3195 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
3196 OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
3204 iTempNN := (some variable in farspace) V1
3209 if (ic->op == IPUSH)
3211 packForPush (ic, ebpp, blockno);
3215 /* pack registers for accumulator use, when the
3216 result of an arithmetic or bit wise operation
3217 has only one use, that use is immediately following
3218 the defintion and the using iCode has only one
3219 operand or has two operands but one is literal &
3220 the result of that operation is not on stack then
3221 we can leave the result of this operation in acc:b
3223 if ((IS_ARITHMETIC_OP (ic)
3224 || IS_CONDITIONAL(ic)
3225 || IS_BITWISE_OP (ic)
3226 || ic->op == LEFT_OP || ic->op == RIGHT_OP || ic->op == CALL
3227 || (ic->op == ADDRESS_OF && isOperandOnStack (IC_LEFT (ic)))
3229 IS_ITEMP (IC_RESULT (ic)) &&
3230 getSize (operandType (IC_RESULT (ic))) <= 2)
3232 packRegsForAccUse (ic);
3236 /*-----------------------------------------------------------------*/
3237 /* assignRegisters - assigns registers to each live range as need */
3238 /*-----------------------------------------------------------------*/
3240 mcs51_assignRegisters (ebbIndex * ebbi)
3242 eBBlock ** ebbs = ebbi->bbOrder;
3243 int count = ebbi->count;
3247 setToNull ((void *) &_G.funcrUsed);
3248 setToNull ((void *) &_G.regAssigned);
3249 setToNull ((void *) &_G.totRegAssigned);
3250 mcs51_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
3251 if ((currFunc && IFFUNC_ISREENT (currFunc->type)) || options.stackAuto)
3259 _G.allBitregs = findAllBitregs ();
3262 /* change assignments this will remove some
3263 live ranges reducing some register pressure */
3265 for (i = 0; i < count; i++)
3266 packRegisters (ebbs, i);
3268 /* liveranges probably changed by register packing
3269 so we compute them again */
3270 recomputeLiveRanges (ebbs, count);
3272 if (options.dump_pack)
3273 dumpEbbsToFileExt (DUMP_PACK, ebbi);
3275 /* first determine for each live range the number of
3276 registers & the type of registers required for each */
3279 /* and serially allocate registers */
3280 serialRegAssign (ebbs, count);
3283 //setToNull ((void *) &_G.regAssigned);
3284 //setToNull ((void *) &_G.totRegAssigned);
3287 /* if stack was extended then tell the user */
3290 /* werror(W_TOOMANY_SPILS,"stack", */
3291 /* _G.stackExtend,currFunc->name,""); */
3297 /* werror(W_TOOMANY_SPILS,"data space", */
3298 /* _G.dataExtend,currFunc->name,""); */
3302 /* after that create the register mask
3303 for each of the instruction */
3304 createRegMask (ebbs, count);
3306 /* redo that offsets for stacked automatic variables */
3308 redoStackOffsets ();
3311 /* make sure r0 & r1 are flagged as used if they might be used */
3313 if (currFunc && mcs51_ptrRegReq)
3315 currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, R0_IDX);
3316 currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, R1_IDX);
3319 if (options.dump_rassgn)
3321 dumpEbbsToFileExt (DUMP_RASSGN, ebbi);
3322 dumpLiveRanges (DUMP_LRANGE, liveRanges);
3325 /* do the overlaysegment stuff SDCCmem.c */
3326 doOverlays (ebbs, count);
3328 /* now get back the chain */
3329 ic = iCodeLabelOptimize (iCodeFromeBBlock (ebbs, count));
3333 /* free up any _G.stackSpil locations allocated */
3334 applyToSet (_G.stackSpil, deallocStackSpil);
3336 setToNull ((void *) &_G.stackSpil);
3337 setToNull ((void *) &_G.spiltSet);
3338 /* mark all registers as free */