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 else if (SPEC_SCLS (sloc->etype) == S_SBIT)
532 SPEC_SCLS (sloc->etype) = S_BIT;
534 SPEC_EXTR (sloc->etype) = 0;
535 SPEC_STAT (sloc->etype) = 0;
536 SPEC_VOLATILE(sloc->etype) = 0;
537 SPEC_ABSA(sloc->etype) = 0;
539 /* we don't allow it to be allocated
540 onto the external stack since : so we
541 temporarily turn it off ; we also
542 turn off memory model to prevent
543 the spil from going to the external storage
546 useXstack = options.useXstack;
547 model = options.model;
548 /* noOverlay = options.noOverlay; */
549 /* options.noOverlay = 1; */
550 options.model = options.useXstack = 0;
554 options.useXstack = useXstack;
555 options.model = model;
556 /* options.noOverlay = noOverlay; */
557 sloc->isref = 1; /* to prevent compiler warning */
559 /* if it is on the stack then update the stack */
560 if (IN_STACK (sloc->etype))
562 currFunc->stack += getSize (sloc->type);
563 _G.stackExtend += getSize (sloc->type);
566 _G.dataExtend += getSize (sloc->type);
568 /* add it to the _G.stackSpil set */
569 addSetHead (&_G.stackSpil, sloc);
570 sym->usl.spillLoc = sloc;
573 /* add it to the set of itempStack set
574 of the spill location */
575 addSetHead (&sloc->usl.itmpStack, sym);
579 /*-----------------------------------------------------------------*/
580 /* isSpiltOnStack - returns true if the spil location is on stack */
581 /* or otherwise needs a pointer register */
582 /*-----------------------------------------------------------------*/
584 isSpiltOnStack (symbol * sym)
594 /* if (sym->_G.stackSpil) */
597 if (!sym->usl.spillLoc)
600 if (sym->usl.spillLoc->onStack || sym->usl.spillLoc->iaccess)
603 etype = getSpec (sym->usl.spillLoc->type);
604 if (IN_STACK (etype))
610 /*-----------------------------------------------------------------*/
611 /* spillThis - spils a specific operand */
612 /*-----------------------------------------------------------------*/
614 spillThis (symbol * sym)
617 /* if this is rematerializable or has a spillLocation
618 we are okay, else we need to create a spillLocation
620 if (!(sym->remat || sym->usl.spillLoc))
621 createStackSpil (sym);
623 /* mark it has spilt & put it in the spilt set */
624 sym->isspilt = sym->spillA = 1;
625 _G.spiltSet = bitVectSetBit (_G.spiltSet, sym->key);
627 bitVectUnSetBit (_G.regAssigned, sym->key);
628 bitVectUnSetBit (_G.totRegAssigned, sym->key);
630 for (i = 0; i < sym->nRegs; i++)
634 freeReg (sym->regs[i]);
638 /* if spilt on stack then free up r0 & r1
639 if they could have been assigned to some
641 if (!mcs51_ptrRegReq && isSpiltOnStack (sym))
644 spillLRWithPtrReg (sym);
647 if (sym->usl.spillLoc && !sym->remat)
648 sym->usl.spillLoc->allocreq++;
652 /*-----------------------------------------------------------------*/
653 /* selectSpil - select a iTemp to spil : rather a simple procedure */
654 /*-----------------------------------------------------------------*/
656 selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
658 bitVect *lrcs = NULL;
662 /* get the spillable live ranges */
663 lrcs = computeSpillable (ic);
665 /* remove incompatible registers */
666 if ((forSym->regType == REG_PTR) || (forSym->regType == REG_GPR))
668 selectS = liveRangesWith (lrcs, bitType, ebp, ic);
670 for (sym = setFirstItem (selectS); sym; sym = setNextItem (selectS))
672 bitVectUnSetBit (lrcs, sym->key);
676 /* get all live ranges that are rematerializable */
677 if ((selectS = liveRangesWith (lrcs, rematable, ebp, ic)))
679 /* return the least used of these */
680 return leastUsedLR (selectS);
683 /* get live ranges with spillLocations in direct space */
684 if ((selectS = liveRangesWith (lrcs, directSpilLoc, ebp, ic)))
686 sym = leastUsedLR (selectS);
687 strncpyz (sym->rname,
688 sym->usl.spillLoc->rname[0] ?
689 sym->usl.spillLoc->rname : sym->usl.spillLoc->name,
692 /* mark it as allocation required */
693 sym->usl.spillLoc->allocreq++;
697 /* if the symbol is local to the block then */
698 if (forSym->liveTo < ebp->lSeq)
700 /* check if there are any live ranges allocated
701 to registers that are not used in this block */
702 if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInBlock, ebp, ic)))
704 sym = leastUsedLR (selectS);
705 /* if this is not rematerializable */
714 /* check if there are any live ranges that not
715 used in the remainder of the block */
717 !isiCodeInFunctionCall (ic) &&
718 (selectS = liveRangesWith (lrcs, notUsedInRemaining, ebp, ic)))
720 sym = leastUsedLR (selectS);
733 /* find live ranges with spillocation && not used as pointers */
734 if ((selectS = liveRangesWith (lrcs, hasSpilLocnoUptr, ebp, ic)))
736 sym = leastUsedLR (selectS);
737 /* mark this as allocation required */
738 sym->usl.spillLoc->allocreq++;
742 /* find live ranges with spillocation */
743 if ((selectS = liveRangesWith (lrcs, hasSpilLoc, ebp, ic)))
745 sym = leastUsedLR (selectS);
746 sym->usl.spillLoc->allocreq++;
750 /* couldn't find then we need to create a spil
751 location on the stack , for which one? the least
753 if ((selectS = liveRangesWith (lrcs, noSpilLoc, ebp, ic)))
755 /* return a created spil location */
756 sym = createStackSpil (leastUsedLR (selectS));
757 sym->usl.spillLoc->allocreq++;
761 /* this is an extreme situation we will spill
762 this one : happens very rarely but it does happen */
768 /*-----------------------------------------------------------------*/
769 /* spilSomething - spil some variable & mark registers as free */
770 /*-----------------------------------------------------------------*/
772 spilSomething (iCode * ic, eBBlock * ebp, symbol * forSym)
777 /* get something we can spil */
778 ssym = selectSpil (ic, ebp, forSym);
780 /* mark it as spilt */
781 ssym->isspilt = ssym->spillA = 1;
782 _G.spiltSet = bitVectSetBit (_G.spiltSet, ssym->key);
784 /* mark it as not register assigned &
785 take it away from the set */
786 bitVectUnSetBit (_G.regAssigned, ssym->key);
787 bitVectUnSetBit (_G.totRegAssigned, ssym->key);
789 /* mark the registers as free */
790 for (i = 0; i < ssym->nRegs; i++)
792 freeReg (ssym->regs[i]);
794 /* if spilt on stack then free up r0 & r1
795 if they could have been assigned to as gprs */
796 if (!mcs51_ptrRegReq && isSpiltOnStack (ssym))
799 spillLRWithPtrReg (ssym);
802 /* if this was a block level spil then insert push & pop
803 at the start & end of block respectively */
806 iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
807 /* add push to the start of the block */
808 addiCodeToeBBlock (ebp, nic, (ebp->sch->op == LABEL ?
809 ebp->sch->next : ebp->sch));
810 nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
811 /* add pop to the end of the block */
812 addiCodeToeBBlock (ebp, nic, NULL);
815 /* if spilt because not used in the remainder of the
816 block then add a push before this instruction and
817 a pop at the end of the block */
818 if (ssym->remainSpil)
821 iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
822 /* add push just before this instruction */
823 addiCodeToeBBlock (ebp, nic, ic);
825 nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
826 /* add pop to the end of the block */
827 addiCodeToeBBlock (ebp, nic, NULL);
836 /*-----------------------------------------------------------------*/
837 /* getRegPtr - will try for PTR if not a GPR type if not spil */
838 /*-----------------------------------------------------------------*/
840 getRegPtr (iCode * ic, eBBlock * ebp, symbol * sym)
846 /* try for a ptr type */
847 if ((reg = allocReg (REG_PTR)))
850 /* try for gpr type */
851 if ((reg = allocReg (REG_GPR)))
854 /* we have to spil */
855 if (!spilSomething (ic, ebp, sym))
858 /* make sure partially assigned registers aren't reused */
859 for (j=0; j<=sym->nRegs; j++)
861 sym->regs[j]->isFree = 0;
863 /* this looks like an infinite loop but
864 in really selectSpil will abort */
868 /*-----------------------------------------------------------------*/
869 /* getRegGpr - will try for GPR if not spil */
870 /*-----------------------------------------------------------------*/
872 getRegGpr (iCode * ic, eBBlock * ebp, symbol * sym)
878 /* try for gpr type */
879 if ((reg = allocReg (REG_GPR)))
882 if (!mcs51_ptrRegReq)
883 if ((reg = allocReg (REG_PTR)))
886 /* we have to spil */
887 if (!spilSomething (ic, ebp, sym))
890 /* make sure partially assigned registers aren't reused */
891 for (j=0; j<=sym->nRegs; j++)
893 sym->regs[j]->isFree = 0;
895 /* this looks like an infinite loop but
896 in really selectSpil will abort */
900 /*-----------------------------------------------------------------*/
901 /* getRegBit - will try for Bit if not spill this */
902 /*-----------------------------------------------------------------*/
903 static regs *getRegBit (symbol * sym)
907 /* try for a bit type */
908 if ((reg = allocReg (REG_BIT)))
915 /*-----------------------------------------------------------------*/
916 /* getRegPtrNoSpil - get it cannot be spilt */
917 /*-----------------------------------------------------------------*/
918 static regs *getRegPtrNoSpil()
922 /* try for a ptr type */
923 if ((reg = allocReg (REG_PTR)))
926 /* try for gpr type */
927 if ((reg = allocReg (REG_GPR)))
932 /* just to make the compiler happy */
936 /*-----------------------------------------------------------------*/
937 /* getRegGprNoSpil - get it cannot be spilt */
938 /*-----------------------------------------------------------------*/
939 static regs *getRegGprNoSpil()
943 if ((reg = allocReg (REG_GPR)))
946 if (!mcs51_ptrRegReq)
947 if ((reg = allocReg (REG_PTR)))
952 /* just to make the compiler happy */
956 /*-----------------------------------------------------------------*/
957 /* getRegBitNoSpil - get it cannot be spilt */
958 /*-----------------------------------------------------------------*/
959 static regs *getRegBitNoSpil()
963 /* try for a ptr type */
964 if ((reg = allocReg (REG_BIT)))
967 /* try for gpr type */
968 if ((reg = allocReg (REG_GPR)))
973 /* just to make the compiler happy */
977 /*-----------------------------------------------------------------*/
978 /* symHasReg - symbol has a given register */
979 /*-----------------------------------------------------------------*/
981 symHasReg (symbol * sym, regs * reg)
985 for (i = 0; i < sym->nRegs; i++)
986 if (sym->regs[i] == reg)
992 /*-----------------------------------------------------------------*/
993 /* updateRegUsage - update the registers in use at the start of */
995 /*-----------------------------------------------------------------*/
997 updateRegUsage (iCode * ic)
1001 for (reg=0; reg<mcs51_nRegs; reg++)
1003 if (regs8051[reg].isFree)
1005 ic->riu &= ~(1<<regs8051[reg].offset);
1009 ic->riu |= (1<<regs8051[reg].offset);
1010 BitBankUsed |= (reg >= 8);
1015 /*-----------------------------------------------------------------*/
1016 /* deassignLRs - check the live to and if they have registers & are */
1017 /* not spilt then free up the registers */
1018 /*-----------------------------------------------------------------*/
1020 deassignLRs (iCode * ic, eBBlock * ebp)
1026 for (sym = hTabFirstItem (liveRanges, &k); sym;
1027 sym = hTabNextItem (liveRanges, &k))
1030 symbol *psym = NULL;
1031 /* if it does not end here */
1032 if (sym->liveTo > ic->seq)
1035 /* if it was spilt on stack then we can
1036 mark the stack spil location as free */
1041 sym->usl.spillLoc->isFree = 1;
1047 if (!bitVectBitValue (_G.regAssigned, sym->key))
1050 /* special case check if this is an IFX &
1051 the privious one was a pop and the
1052 previous one was not spilt then keep track
1054 if (ic->op == IFX && ic->prev &&
1055 ic->prev->op == IPOP &&
1056 !ic->prev->parmPush &&
1057 !OP_SYMBOL (IC_LEFT (ic->prev))->isspilt)
1058 psym = OP_SYMBOL (IC_LEFT (ic->prev));
1064 bitVectUnSetBit (_G.regAssigned, sym->key);
1066 /* if the result of this one needs registers
1067 and does not have it then assign it right
1069 if (IC_RESULT (ic) &&
1070 !(SKIP_IC2 (ic) || /* not a special icode */
1071 ic->op == JUMPTABLE ||
1076 POINTER_SET (ic)) &&
1077 (result = OP_SYMBOL (IC_RESULT (ic))) && /* has a result */
1078 result->liveTo > ic->seq && /* and will live beyond this */
1079 result->liveTo <= ebp->lSeq && /* does not go beyond this block */
1080 result->liveFrom == ic->seq && /* does not start before here */
1081 result->regType == sym->regType && /* same register types */
1082 result->nRegs && /* which needs registers */
1083 !result->isspilt && /* and does not already have them */
1085 !bitVectBitValue (_G.regAssigned, result->key) &&
1086 /* the number of free regs + number of regs in this LR
1087 can accomodate the what result Needs */
1088 ((nfreeRegsType (result->regType) +
1089 sym->nRegs) >= result->nRegs)
1093 for (i = 0; i < result->nRegs; i++)
1095 result->regs[i] = sym->regs[i];
1097 result->regs[i] = getRegGpr (ic, ebp, result);
1099 _G.regAssigned = bitVectSetBit (_G.regAssigned, result->key);
1100 _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, result->key);
1104 /* free the remaining */
1105 for (; i < sym->nRegs; i++)
1109 if (!symHasReg (psym, sym->regs[i]))
1110 freeReg (sym->regs[i]);
1113 freeReg (sym->regs[i]);
1120 /*-----------------------------------------------------------------*/
1121 /* reassignLR - reassign this to registers */
1122 /*-----------------------------------------------------------------*/
1124 reassignLR (operand * op)
1126 symbol *sym = OP_SYMBOL (op);
1129 /* not spilt any more */
1130 sym->isspilt = sym->spillA = sym->blockSpil = sym->remainSpil = 0;
1131 bitVectUnSetBit (_G.spiltSet, sym->key);
1133 _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
1134 _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, sym->key);
1138 for (i = 0; i < sym->nRegs; i++)
1139 sym->regs[i]->isFree = 0;
1142 /*-----------------------------------------------------------------*/
1143 /* willCauseSpill - determines if allocating will cause a spill */
1144 /*-----------------------------------------------------------------*/
1146 willCauseSpill (int nr, int rt)
1148 /* first check if there are any available registers
1149 of the type required */
1152 /* special case for pointer type
1153 if pointer type not avlb then
1154 check for type gpr */
1155 if (nFreeRegs (rt) >= nr)
1157 if (nFreeRegs (REG_GPR) >= nr)
1160 else if (rt == REG_BIT)
1162 if (nFreeRegs (rt) >= nr)
1167 if (mcs51_ptrRegReq)
1169 if (nFreeRegs (rt) >= nr)
1174 if (nFreeRegs (REG_PTR) +
1175 nFreeRegs (REG_GPR) >= nr)
1180 /* it will cause a spil */
1184 /*-----------------------------------------------------------------*/
1185 /* positionRegs - the allocator can allocate same registers to res- */
1186 /* ult and operand, if this happens make sure they are in the same */
1187 /* position as the operand otherwise chaos results */
1188 /*-----------------------------------------------------------------*/
1190 positionRegs (symbol * result, symbol * opsym)
1192 int count = min (result->nRegs, opsym->nRegs);
1193 int i, j = 0, shared = 0;
1196 /* if the result has been spilt then cannot share */
1201 /* first make sure that they actually share */
1202 for (i = 0; i < count; i++)
1204 for (j = 0; j < count; j++)
1206 if (result->regs[i] == opsym->regs[j] && i != j)
1216 regs *tmp = result->regs[i];
1217 result->regs[i] = result->regs[j];
1218 result->regs[j] = tmp;
1225 /*------------------------------------------------------------------*/
1226 /* verifyRegsAssigned - make sure an iTemp is properly initialized; */
1227 /* it should either have registers or have beed spilled. Otherwise, */
1228 /* there was an uninitialized variable, so just spill this to get */
1229 /* the operand in a valid state. */
1230 /*------------------------------------------------------------------*/
1232 verifyRegsAssigned (operand *op, iCode * ic)
1237 if (!IS_ITEMP (op)) return;
1239 sym = OP_SYMBOL (op);
1240 if (sym->isspilt) return;
1241 if (!sym->nRegs) return;
1242 if (sym->regs[0]) return;
1244 werrorfl (ic->filename, ic->lineno, W_LOCAL_NOINIT,
1245 sym->prereqv ? sym->prereqv->name : sym->name);
1250 /*-----------------------------------------------------------------*/
1251 /* serialRegAssign - serially allocate registers to the variables */
1252 /*-----------------------------------------------------------------*/
1254 serialRegAssign (eBBlock ** ebbs, int count)
1258 /* for all blocks */
1259 for (i = 0; i < count; i++)
1264 if (ebbs[i]->noPath &&
1265 (ebbs[i]->entryLabel != entryLabel &&
1266 ebbs[i]->entryLabel != returnLabel))
1269 /* for all instructions do */
1270 for (ic = ebbs[i]->sch; ic; ic = ic->next)
1274 /* if this is an ipop that means some live
1275 range will have to be assigned again */
1277 reassignLR (IC_LEFT (ic));
1279 /* if result is present && is a true symbol */
1280 if (IC_RESULT (ic) && ic->op != IFX &&
1281 IS_TRUE_SYMOP (IC_RESULT (ic)))
1282 OP_SYMBOL (IC_RESULT (ic))->allocreq++;
1284 /* take away registers from live
1285 ranges that end at this instruction */
1286 deassignLRs (ic, ebbs[i]);
1288 /* some don't need registers */
1289 if (SKIP_IC2 (ic) ||
1290 ic->op == JUMPTABLE ||
1294 (IC_RESULT (ic) && POINTER_SET (ic)))
1297 /* now we need to allocate registers
1298 only for the result */
1299 if (IC_RESULT (ic)) {
1300 symbol *sym = OP_SYMBOL (IC_RESULT (ic));
1306 /* Make sure any spill location is definitely allocated */
1307 if (sym->isspilt && !sym->remat && sym->usl.spillLoc &&
1308 !sym->usl.spillLoc->allocreq)
1310 sym->usl.spillLoc->allocreq++;
1313 /* if it does not need or is spilt
1314 or is already assigned to registers
1315 or will not live beyond this instructions */
1318 bitVectBitValue (_G.regAssigned, sym->key) ||
1319 sym->liveTo <= ic->seq)
1322 /* if some liverange has been spilt at the block level
1323 and this one live beyond this block then spil this
1325 if (_G.blockSpil && sym->liveTo > ebbs[i]->lSeq) {
1330 willCS = willCauseSpill (sym->nRegs, sym->regType);
1331 /* if this is a bit variable then don't use precious registers
1332 along with expensive bit-to-char conversions but just spill
1334 if (willCS && SPEC_NOUN(sym->etype) == V_BIT) {
1339 /* if trying to allocate this will cause
1340 a spill and there is nothing to spill
1341 or this one is rematerializable then
1343 spillable = computeSpillable (ic);
1344 if (sym->remat || (willCS && bitVectIsZero (spillable))) {
1349 /* If the live range preceeds the point of definition
1350 then ideally we must take into account registers that
1351 have been allocated after sym->liveFrom but freed
1352 before ic->seq. This is complicated, so spill this
1353 symbol instead and let fillGaps handle the allocation. */
1354 if (sym->liveFrom < ic->seq) {
1359 /* if it has a spillocation & is used less than
1360 all other live ranges then spill this */
1362 if (sym->usl.spillLoc) {
1363 symbol *leastUsed = leastUsedLR (liveRangesWith (spillable,
1364 allLRs, ebbs[i], ic));
1365 if (leastUsed && leastUsed->used > sym->used) {
1370 /* if none of the liveRanges have a spillLocation then better
1371 to spill this one than anything else already assigned to registers */
1372 if (liveRangesWith(spillable,noSpilLoc,ebbs[i],ic)) {
1373 /* if this is local to this block then we might find a block spil */
1374 if (!(sym->liveFrom >= ebbs[i]->fSeq && sym->liveTo <= ebbs[i]->lSeq)) {
1381 /* if we need ptr regs for the right side
1383 if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic))
1384 && getSize (OP_SYMBOL (IC_LEFT (ic))->type) <= (unsigned int) PTRSIZE) {
1388 if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic))
1389 && SPEC_OCLS(OP_SYMBOL (IC_LEFT (ic))->etype) == idata) {
1393 if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic))
1394 && SPEC_OCLS(OP_SYMBOL (IC_RIGHT (ic))->etype) == idata) {
1399 /* else we assign registers to it */
1400 _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
1401 _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, sym->key);
1403 for (j = 0; j < sym->nRegs; j++) {
1404 sym->regs[j] = NULL;
1405 if (sym->regType == REG_PTR)
1406 sym->regs[j] = getRegPtr (ic, ebbs[i], sym);
1407 else if (sym->regType == REG_BIT)
1408 sym->regs[j] = getRegBit (sym);
1411 if (ic->op == CAST && IS_SYMOP (IC_RIGHT (ic)))
1413 symbol * right = OP_SYMBOL (IC_RIGHT (ic));
1415 if (right->regs[j] && (right->regType != REG_BIT))
1416 sym->regs[j] = allocThisReg (right->regs[j]);
1419 sym->regs[j] = getRegGpr (ic, ebbs[i], sym);
1422 /* if the allocation failed which means
1423 this was spilt then break */
1427 for (i=0; i < sym->nRegs ; i++ )
1428 sym->regs[i] = NULL;
1433 if (!POINTER_SET(ic) && !POINTER_GET(ic)) {
1434 /* if it shares registers with operands make sure
1435 that they are in the same position */
1436 if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)) &&
1437 OP_SYMBOL (IC_LEFT (ic))->nRegs) {
1438 positionRegs (OP_SYMBOL (IC_RESULT (ic)),
1439 OP_SYMBOL (IC_LEFT (ic)));
1441 /* do the same for the right operand */
1442 if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)) &&
1443 OP_SYMBOL (IC_RIGHT (ic))->nRegs) {
1444 positionRegs (OP_SYMBOL (IC_RESULT (ic)),
1445 OP_SYMBOL (IC_RIGHT (ic)));
1458 /* Check for and fix any problems with uninitialized operands */
1459 for (i = 0; i < count; i++)
1463 if (ebbs[i]->noPath &&
1464 (ebbs[i]->entryLabel != entryLabel &&
1465 ebbs[i]->entryLabel != returnLabel))
1468 for (ic = ebbs[i]->sch; ic; ic = ic->next)
1475 verifyRegsAssigned (IC_COND (ic), ic);
1479 if (ic->op == JUMPTABLE)
1481 verifyRegsAssigned (IC_JTCOND (ic), ic);
1485 verifyRegsAssigned (IC_RESULT (ic), ic);
1486 verifyRegsAssigned (IC_LEFT (ic), ic);
1487 verifyRegsAssigned (IC_RIGHT (ic), ic);
1492 /*-----------------------------------------------------------------*/
1493 /* fillGaps - Try to fill in the Gaps left by Pass1 */
1494 /*-----------------------------------------------------------------*/
1495 static void fillGaps()
1502 if (getenv("DISABLE_FILL_GAPS")) return;
1504 /* look for liveranges that were spilt by the allocator */
1505 for (sym = hTabFirstItem(liveRanges,&key) ; sym ;
1506 sym = hTabNextItem(liveRanges,&key)) {
1511 if (!sym->spillA || !sym->clashes || sym->remat) continue ;
1513 /* find the liveRanges this one clashes with, that are
1514 still assigned to registers & mark the registers as used*/
1515 for ( i = 0 ; i < sym->clashes->size ; i ++) {
1519 if (bitVectBitValue(sym->clashes,i) == 0 || /* those that clash with this */
1520 bitVectBitValue(_G.totRegAssigned,i) == 0) /* and are still assigned to registers */
1523 clr = hTabItemWithKey(liveRanges,i);
1526 /* mark these registers as used */
1527 for (k = 0 ; k < clr->nRegs ; k++ )
1528 useReg(clr->regs[k]);
1531 if (willCauseSpill(sym->nRegs,sym->regType)) {
1532 /* NOPE :( clear all registers & and continue */
1538 for (i = 0 ; i < sym->defs->size ; i++ )
1540 if (bitVectBitValue(sym->defs,i))
1542 if (!(ic = hTabItemWithKey(iCodehTab,i)))
1549 D(printf("Attempting fillGaps on %s: [",sym->name));
1550 /* THERE IS HOPE !!!! */
1551 for (i=0; i < sym->nRegs ; i++ ) {
1552 if (sym->regType == REG_PTR)
1553 sym->regs[i] = getRegPtrNoSpil ();
1554 else if (sym->regType == REG_BIT)
1555 sym->regs[i] = getRegBitNoSpil ();
1558 sym->regs[i] = NULL;
1559 if (ic && ic->op == CAST && IS_SYMOP (IC_RIGHT (ic)))
1561 symbol * right = OP_SYMBOL (IC_RIGHT (ic));
1564 sym->regs[i] = allocThisReg (right->regs[i]);
1567 sym->regs[i] = getRegGprNoSpil ();
1569 D(printf("%s ", sym->regs[i]->name));
1573 /* For all its definitions check if the registers
1574 allocated needs positioning NOTE: we can position
1575 only ONCE if more than One positioning required
1577 We may need to perform the checks twice; once to
1578 position the registers as needed, the second to
1579 verify any register repositioning is still
1583 for (pass=0; pass<2; pass++) {
1584 D(printf(" checking definitions\n"));
1585 for (i = 0 ; i < sym->defs->size ; i++ ) {
1586 if (bitVectBitValue(sym->defs,i)) {
1587 if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ;
1588 D(printf(" ic->seq = %d\n", ic->seq));
1589 if (SKIP_IC(ic)) continue;
1590 assert(isSymbolEqual(sym,OP_SYMBOL(IC_RESULT(ic)))); /* just making sure */
1591 /* if left is assigned to registers */
1592 if (IS_SYMOP(IC_LEFT(ic)))
1594 D(printf(" left = "));
1595 D(printOperand(IC_LEFT(ic),NULL));
1597 if (IS_SYMOP(IC_LEFT(ic)) &&
1598 bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_LEFT(ic))->key)) {
1599 pdone += (positionRegs(sym,OP_SYMBOL(IC_LEFT(ic)))>0);
1601 if (IS_SYMOP(IC_RIGHT(ic)))
1603 D(printf(" right = "));
1604 D(printOperand(IC_RIGHT(ic),NULL));
1606 if (IS_SYMOP(IC_RIGHT(ic)) &&
1607 bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RIGHT(ic))->key)) {
1608 pdone += (positionRegs(sym,OP_SYMBOL(IC_RIGHT(ic)))>0);
1610 D(printf(" pdone = %d\n", pdone));
1611 if (pdone > 1) break;
1614 D(printf(" checking uses\n"));
1615 for (i = 0 ; i < sym->uses->size ; i++ ) {
1616 if (bitVectBitValue(sym->uses,i)) {
1618 if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ;
1619 D(printf(" ic->seq = %d\n", ic->seq));
1620 if (SKIP_IC(ic)) continue;
1621 if (POINTER_SET(ic) || POINTER_GET(ic)) continue ;
1623 /* if result is assigned to registers */
1624 if (IS_SYMOP(IC_RESULT(ic)))
1626 D(printf(" result = "));
1627 D(printOperand(IC_RESULT(ic),NULL));
1629 if (IS_SYMOP(IC_RESULT(ic)) &&
1630 bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RESULT(ic))->key)) {
1631 pdone += (positionRegs(sym,OP_SYMBOL(IC_RESULT(ic)))>0);
1633 D(printf(" pdone = %d\n", pdone));
1634 if (pdone > 1) break;
1637 if (pdone == 0) break; /* second pass only if regs repositioned */
1638 if (pdone > 1) break;
1640 D(printf(" sym->regs = ["));
1641 for (i=0; i < sym->nRegs ; i++ )
1642 D(printf("%s ", sym->regs[i]->name));
1644 /* had to position more than once GIVE UP */
1646 /* UNDO all the changes we made to try this */
1648 for (i=0; i < sym->nRegs ; i++ ) {
1649 sym->regs[i] = NULL;
1652 D(printf ("Fill Gap gave up due to positioning for %s in function %s\n",sym->name, currFunc ? currFunc->name : "UNKNOWN"));
1655 D(printf ("FILLED GAP for %s in function %s\n",sym->name, currFunc ? currFunc->name : "UNKNOWN"));
1657 _G.totRegAssigned = bitVectSetBit(_G.totRegAssigned,sym->key);
1658 sym->isspilt = sym->spillA = 0 ;
1659 sym->usl.spillLoc->allocreq--;
1664 /*-----------------------------------------------------------------*/
1665 /* findAllBitregs :- returns bit vector of all bit registers */
1666 /*-----------------------------------------------------------------*/
1668 findAllBitregs (void)
1670 bitVect *rmask = newBitVect (mcs51_nRegs);
1673 for (j = 0; j < mcs51_nRegs; j++)
1675 if (regs8051[j].type == REG_BIT)
1676 rmask = bitVectSetBit (rmask, regs8051[j].rIdx);
1682 /*-----------------------------------------------------------------*/
1683 /* mcs51_allBitregs :- returns bit vector of all bit registers */
1684 /*-----------------------------------------------------------------*/
1686 mcs51_allBitregs (void)
1688 return _G.allBitregs;
1691 /*-----------------------------------------------------------------*/
1692 /* rUmaskForOp :- returns register mask for an operand */
1693 /*-----------------------------------------------------------------*/
1695 mcs51_rUmaskForOp (operand * op)
1701 /* only temporaries are assigned registers */
1705 sym = OP_SYMBOL (op);
1707 /* if spilt or no registers assigned to it
1709 if (sym->isspilt || !sym->nRegs)
1712 rumask = newBitVect (mcs51_nRegs);
1714 for (j = 0; j < sym->nRegs; j++)
1716 if (sym->regs[j]) /* EEP - debug */
1717 rumask = bitVectSetBit (rumask, sym->regs[j]->rIdx);
1723 /*-----------------------------------------------------------------*/
1724 /* regsUsedIniCode :- returns bit vector of registers used in iCode */
1725 /*-----------------------------------------------------------------*/
1727 regsUsedIniCode (iCode * ic)
1729 bitVect *rmask = newBitVect (mcs51_nRegs);
1731 /* do the special cases first */
1734 rmask = bitVectUnion (rmask,
1735 mcs51_rUmaskForOp (IC_COND (ic)));
1739 /* for the jumptable */
1740 if (ic->op == JUMPTABLE)
1742 rmask = bitVectUnion (rmask,
1743 mcs51_rUmaskForOp (IC_JTCOND (ic)));
1748 /* of all other cases */
1750 rmask = bitVectUnion (rmask,
1751 mcs51_rUmaskForOp (IC_LEFT (ic)));
1755 rmask = bitVectUnion (rmask,
1756 mcs51_rUmaskForOp (IC_RIGHT (ic)));
1759 rmask = bitVectUnion (rmask,
1760 mcs51_rUmaskForOp (IC_RESULT (ic)));
1766 /*-----------------------------------------------------------------*/
1767 /* createRegMask - for each instruction will determine the regsUsed */
1768 /*-----------------------------------------------------------------*/
1770 createRegMask (eBBlock ** ebbs, int count)
1774 /* for all blocks */
1775 for (i = 0; i < count; i++)
1779 if (ebbs[i]->noPath &&
1780 (ebbs[i]->entryLabel != entryLabel &&
1781 ebbs[i]->entryLabel != returnLabel))
1784 /* for all instructions */
1785 for (ic = ebbs[i]->sch; ic; ic = ic->next)
1790 if (SKIP_IC2 (ic) || !ic->rlive)
1793 /* first mark the registers used in this
1795 ic->rUsed = regsUsedIniCode (ic);
1796 _G.funcrUsed = bitVectUnion (_G.funcrUsed, ic->rUsed);
1798 /* now create the register mask for those
1799 registers that are in use : this is a
1800 super set of ic->rUsed */
1801 ic->rMask = newBitVect (mcs51_nRegs + 1);
1803 /* for all live Ranges alive at this point */
1804 for (j = 1; j < ic->rlive->size; j++)
1809 /* if not alive then continue */
1810 if (!bitVectBitValue (ic->rlive, j))
1813 /* find the live range we are interested in */
1814 if (!(sym = hTabItemWithKey (liveRanges, j)))
1816 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
1817 "createRegMask cannot find live range");
1818 fprintf(stderr, "\tmissing live range: key=%d\n", j);
1822 /* if no register assigned to it */
1823 if (!sym->nRegs || sym->isspilt)
1826 /* for all the registers allocated to it */
1827 for (k = 0; k < sym->nRegs; k++)
1830 bitVectSetBit (ic->rMask, sym->regs[k]->rIdx);
1836 /*-----------------------------------------------------------------*/
1837 /* rematStr - returns the rematerialized string for a remat var */
1838 /*-----------------------------------------------------------------*/
1840 rematStr (symbol * sym)
1842 iCode *ic = sym->rematiCode;
1847 /* if plus adjust offset to right hand side */
1850 offset += (int) operandLitValue (IC_RIGHT (ic));
1851 ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
1855 /* if minus adjust offset to right hand side */
1858 offset -= (int) operandLitValue (IC_RIGHT (ic));
1859 ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
1863 /* cast then continue */
1864 if (IS_CAST_ICODE(ic)) {
1865 ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
1868 /* we reached the end */
1874 SNPRINTF (buffer, sizeof(buffer),
1876 OP_SYMBOL (IC_LEFT (ic))->rname,
1877 offset >= 0 ? '+' : '-',
1878 abs (offset) & 0xffff);
1882 strncpyz (buffer, OP_SYMBOL (IC_LEFT (ic))->rname, sizeof(buffer));
1887 /*-----------------------------------------------------------------*/
1888 /* regTypeNum - computes the type & number of registers required */
1889 /*-----------------------------------------------------------------*/
1891 regTypeNum (eBBlock *ebbs)
1897 /* for each live range do */
1898 for (sym = hTabFirstItem (liveRanges, &k); sym;
1899 sym = hTabNextItem (liveRanges, &k))
1902 /* if used zero times then no registers needed */
1903 if ((sym->liveTo - sym->liveFrom) == 0)
1907 /* if the live range is a temporary */
1911 /* if the type is marked as a conditional */
1912 if (sym->regType == REG_CND)
1915 /* if used in return only then we don't
1917 if (sym->ruonly || sym->accuse)
1919 if (IS_AGGREGATE (sym->type) || sym->isptr)
1920 sym->type = aggrToPtr (sym->type, FALSE);
1921 else if (IS_BIT(sym->type))
1922 sym->regType = REG_CND;
1926 /* if the symbol has only one definition &
1927 that definition is a get_pointer */
1928 if (bitVectnBitsOn (sym->defs) == 1 &&
1929 (ic = hTabItemWithKey (iCodehTab,
1930 bitVectFirstBit (sym->defs))) &&
1932 !IS_BITVAR (sym->etype) &&
1933 (aggrToPtrDclType (operandType (IC_LEFT (ic)), FALSE) == POINTER))
1936 if (ptrPseudoSymSafe (sym, ic))
1938 ptrPseudoSymConvert (sym, ic, rematStr (OP_SYMBOL (IC_LEFT (ic))));
1942 /* if in data space or idata space then try to
1943 allocate pointer register */
1947 /* if not then we require registers */
1948 sym->nRegs = ((IS_AGGREGATE (sym->type) || sym->isptr) ?
1949 getSize (sym->type = aggrToPtr (sym->type, FALSE)) :
1950 getSize (sym->type));
1954 fprintf (stderr, "allocated more than 4 or 0 registers for type ");
1955 printTypeChain (sym->type, stderr);
1956 fprintf (stderr, "\n");
1959 /* determine the type of register required */
1960 if (sym->nRegs == 1 && IS_PTR (sym->type) && sym->uptr)
1961 sym->regType = REG_PTR;
1962 else if (IS_BIT(sym->type))
1963 sym->regType = REG_BIT;
1965 sym->regType = REG_GPR;
1968 /* for the first run we don't provide */
1969 /* registers for true symbols we will */
1970 /* see how things go */
1976 /*-----------------------------------------------------------------*/
1977 /* freeAllRegs - mark all registers as free */
1978 /*-----------------------------------------------------------------*/
1984 for (i = 0; i < mcs51_nRegs; i++)
1985 regs8051[i].isFree = 1;
1988 /*-----------------------------------------------------------------*/
1989 /* deallocStackSpil - this will set the stack pointer back */
1990 /*-----------------------------------------------------------------*/
1992 DEFSETFUNC (deallocStackSpil)
2000 /*-----------------------------------------------------------------*/
2001 /* farSpacePackable - returns the packable icode for far variables */
2002 /*-----------------------------------------------------------------*/
2004 farSpacePackable (iCode * ic)
2008 /* go thru till we find a definition for the
2009 symbol on the right */
2010 for (dic = ic->prev; dic; dic = dic->prev)
2012 /* if the definition is a call then no */
2013 if ((dic->op == CALL || dic->op == PCALL) &&
2014 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
2019 /* if shift by unknown amount then not */
2020 if ((dic->op == LEFT_OP || dic->op == RIGHT_OP) &&
2021 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
2024 /* if pointer get and size > 1 */
2025 if (POINTER_GET (dic) &&
2026 getSize (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)) > 1)
2029 if (POINTER_SET (dic) &&
2030 getSize (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)) > 1)
2035 if (IC_COND (dic) &&
2036 IS_TRUE_SYMOP (IC_COND (dic)) &&
2037 isOperandInFarSpace (IC_COND (dic)))
2040 else if (dic->op == JUMPTABLE)
2042 if (IC_JTCOND (dic) &&
2043 IS_TRUE_SYMOP (IC_JTCOND (dic)) &&
2044 isOperandInFarSpace (IC_JTCOND (dic)))
2049 /* if any tree is a true symbol in far space */
2050 if (IC_RESULT (dic) &&
2051 IS_TRUE_SYMOP (IC_RESULT (dic)) &&
2052 isOperandInFarSpace (IC_RESULT (dic)))
2055 if (IC_RIGHT (dic) &&
2056 IS_TRUE_SYMOP (IC_RIGHT (dic)) &&
2057 isOperandInFarSpace (IC_RIGHT (dic)) &&
2058 !isOperandEqual (IC_RIGHT (dic), IC_RESULT (ic)))
2061 if (IC_LEFT (dic) &&
2062 IS_TRUE_SYMOP (IC_LEFT (dic)) &&
2063 isOperandInFarSpace (IC_LEFT (dic)) &&
2064 !isOperandEqual (IC_LEFT (dic), IC_RESULT (ic)))
2068 if (isOperandEqual (IC_RIGHT (ic), IC_RESULT (dic)))
2070 if ((dic->op == LEFT_OP ||
2071 dic->op == RIGHT_OP ||
2073 IS_OP_LITERAL (IC_RIGHT (dic)))
2083 /*-----------------------------------------------------------------*/
2084 /* packRegsForAssign - register reduction for assignment */
2085 /*-----------------------------------------------------------------*/
2087 packRegsForAssign (iCode * ic, eBBlock * ebp)
2091 if (!IS_ITEMP (IC_RIGHT (ic)) ||
2092 OP_SYMBOL (IC_RIGHT (ic))->isind ||
2093 OP_LIVETO (IC_RIGHT (ic)) > ic->seq)
2098 /* if the true symbol is defined in far space or on stack
2099 then we should not since this will increase register pressure */
2100 if (isOperandInFarSpace(IC_RESULT(ic)) && !farSpacePackable(ic)) {
2104 /* find the definition of iTempNN scanning backwards if we find a
2105 a use of the true symbol in before we find the definition then
2107 for (dic = ic->prev; dic; dic = dic->prev)
2109 int crossedCall = 0;
2111 /* We can pack across a function call only if it's a local */
2112 /* variable or our parameter. Never pack global variables */
2113 /* or parameters to a function we call. */
2114 if ((dic->op == CALL || dic->op == PCALL))
2116 if (!OP_SYMBOL (IC_RESULT (ic))->ismyparm
2117 && !OP_SYMBOL (IC_RESULT (ic))->islocal)
2123 /* Don't move an assignment out of a critical block */
2124 if (dic->op == CRITICAL)
2135 if (IS_SYMOP (IC_COND (dic)) &&
2136 (IC_COND (dic)->key == IC_RESULT (ic)->key ||
2137 IC_COND (dic)->key == IC_RIGHT (ic)->key))
2145 if (IS_TRUE_SYMOP (IC_RESULT (dic)) &&
2146 IS_OP_VOLATILE (IC_RESULT (dic)))
2152 if (IS_SYMOP (IC_RESULT (dic)) &&
2153 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
2155 if (POINTER_SET (dic))
2161 if (IS_SYMOP (IC_RIGHT (dic)) &&
2162 (IC_RIGHT (dic)->key == IC_RESULT (ic)->key ||
2163 IC_RIGHT (dic)->key == IC_RIGHT (ic)->key))
2169 if (IS_SYMOP (IC_LEFT (dic)) &&
2170 (IC_LEFT (dic)->key == IC_RESULT (ic)->key ||
2171 IC_LEFT (dic)->key == IC_RIGHT (ic)->key))
2177 if (IS_SYMOP (IC_RESULT (dic)) &&
2178 IC_RESULT (dic)->key == IC_RESULT (ic)->key)
2194 return 0; /* did not find */
2196 /* if assignment then check that right is not a bit */
2197 if (ASSIGNMENT (ic) && !POINTER_SET (ic))
2199 sym_link *etype = operandType (IC_RESULT (dic));
2200 if (IS_BITFIELD (etype))
2202 /* if result is a bit too then it's ok */
2203 etype = operandType (IC_RESULT (ic));
2204 if (!IS_BITFIELD (etype))
2211 /* if the result is on stack or iaccess then it must be
2212 the same atleast one of the operands */
2213 if (OP_SYMBOL (IC_RESULT (ic))->onStack ||
2214 OP_SYMBOL (IC_RESULT (ic))->iaccess)
2217 /* the operation has only one symbol
2218 operator then we can pack */
2219 if ((IC_LEFT (dic) && !IS_SYMOP (IC_LEFT (dic))) ||
2220 (IC_RIGHT (dic) && !IS_SYMOP (IC_RIGHT (dic))))
2223 if (!((IC_LEFT (dic) &&
2224 IC_RESULT (ic)->key == IC_LEFT (dic)->key) ||
2226 IC_RESULT (ic)->key == IC_RIGHT (dic)->key)))
2230 /* found the definition */
2231 /* replace the result with the result of */
2232 /* this assignment and remove this assignment */
2233 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
2234 ReplaceOpWithCheaperOp(&IC_RESULT (dic), IC_RESULT (ic));
2236 if (IS_ITEMP (IC_RESULT (dic)) && OP_SYMBOL (IC_RESULT (dic))->liveFrom > dic->seq)
2238 OP_SYMBOL (IC_RESULT (dic))->liveFrom = dic->seq;
2240 // TODO: and the otherway around?
2242 /* delete from liverange table also
2243 delete from all the points inbetween and the new
2245 for (sic = dic; sic != ic; sic = sic->next)
2247 bitVectUnSetBit (sic->rlive, IC_RESULT (ic)->key);
2248 if (IS_ITEMP (IC_RESULT (dic)))
2249 bitVectSetBit (sic->rlive, IC_RESULT (dic)->key);
2252 remiCodeFromeBBlock (ebp, ic);
2253 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
2254 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
2255 OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
2259 /*------------------------------------------------------------------*/
2260 /* findAssignToSym : scanning backwards looks for first assig found */
2261 /*------------------------------------------------------------------*/
2263 findAssignToSym (operand * op, iCode * ic)
2267 /* This routine is used to find sequences like
2269 ...; (intervening ops don't use iTempAA or modify FOO)
2270 blah = blah + iTempAA;
2272 and eliminate the use of iTempAA, freeing up its register for
2276 for (dic = ic->prev; dic; dic = dic->prev)
2279 /* if definition by assignment */
2280 if (dic->op == '=' &&
2281 !POINTER_SET (dic) &&
2282 IC_RESULT (dic)->key == op->key
2283 /* && IS_TRUE_SYMOP(IC_RIGHT(dic)) */
2285 break; /* found where this temp was defined */
2287 /* if we find an usage then we cannot delete it */
2291 if (IC_COND (dic) && IC_COND (dic)->key == op->key)
2294 else if (dic->op == JUMPTABLE)
2296 if (IC_JTCOND (dic) && IC_JTCOND (dic)->key == op->key)
2301 if (IC_LEFT (dic) && IC_LEFT (dic)->key == op->key)
2304 if (IC_RIGHT (dic) && IC_RIGHT (dic)->key == op->key)
2307 if (POINTER_SET (dic) && IC_RESULT (dic)->key == op->key)
2313 return NULL; /* didn't find any assignment to op */
2315 /* we are interested only if defined in far space */
2316 /* or in stack space in case of + & - */
2318 /* if assigned to a non-symbol then don't repack regs */
2319 if (!IS_SYMOP (IC_RIGHT (dic)))
2322 /* if the symbol is volatile then we should not */
2323 if (isOperandVolatile (IC_RIGHT (dic), TRUE))
2325 /* XXX TODO --- should we be passing FALSE to isOperandVolatile()?
2326 What does it mean for an iTemp to be volatile, anyway? Passing
2327 TRUE is more cautious but may prevent possible optimizations */
2329 /* if the symbol is in far space then we should not */
2330 if (isOperandInFarSpace (IC_RIGHT (dic)))
2333 /* for + & - operations make sure that
2334 if it is on the stack it is the same
2335 as one of the three operands */
2336 if ((ic->op == '+' || ic->op == '-') &&
2337 OP_SYMBOL (IC_RIGHT (dic))->onStack)
2340 if (IC_RESULT (ic)->key != IC_RIGHT (dic)->key &&
2341 IC_LEFT (ic)->key != IC_RIGHT (dic)->key &&
2342 IC_RIGHT (ic)->key != IC_RIGHT (dic)->key)
2346 /* now make sure that the right side of dic
2347 is not defined between ic & dic */
2350 iCode *sic = dic->next;
2352 for (; sic != ic; sic = sic->next)
2353 if (IC_RESULT (sic) &&
2354 IC_RESULT (sic)->key == IC_RIGHT (dic)->key)
2361 /*-----------------------------------------------------------------*/
2362 /* reassignAliasedSym - used by packRegsForSupport to replace */
2363 /* redundant iTemp with equivalent symbol */
2364 /*-----------------------------------------------------------------*/
2366 reassignAliasedSym (eBBlock *ebp, iCode *assignment, iCode *use, operand *op)
2369 unsigned oldSymKey, newSymKey;
2371 oldSymKey = op->key;
2372 newSymKey = IC_RIGHT(assignment)->key;
2374 /* only track live ranges of compiler-generated temporaries */
2375 if (!IS_ITEMP(IC_RIGHT(assignment)))
2378 /* update the live-value bitmaps */
2379 for (ic = assignment; ic != use; ic = ic->next) {
2380 bitVectUnSetBit (ic->rlive, oldSymKey);
2382 ic->rlive = bitVectSetBit (ic->rlive, newSymKey);
2385 /* update the sym of the used operand */
2386 OP_SYMBOL(op) = OP_SYMBOL(IC_RIGHT(assignment));
2387 op->key = OP_SYMBOL(op)->key;
2388 OP_SYMBOL(op)->accuse = 0;
2390 /* update the sym's liverange */
2391 if ( OP_LIVETO(op) < ic->seq )
2392 setToRange(op, ic->seq, FALSE);
2394 /* remove the assignment iCode now that its result is unused */
2395 remiCodeFromeBBlock (ebp, assignment);
2396 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(assignment))->defs, assignment->key);
2397 hTabDeleteItem (&iCodehTab, assignment->key, assignment, DELETE_ITEM, NULL);
2401 /*-----------------------------------------------------------------*/
2402 /* packRegsForSupport :- reduce some registers for support calls */
2403 /*-----------------------------------------------------------------*/
2405 packRegsForSupport (iCode * ic, eBBlock * ebp)
2409 /* for the left & right operand :- look to see if the
2410 left was assigned a true symbol in far space in that
2411 case replace them */
2413 if (IS_ITEMP (IC_LEFT (ic)) &&
2414 OP_SYMBOL (IC_LEFT (ic))->liveTo <= ic->seq)
2416 dic = findAssignToSym (IC_LEFT (ic), ic);
2420 /* found it we need to remove it from the block */
2421 reassignAliasedSym (ebp, dic, ic, IC_LEFT(ic));
2426 /* do the same for the right operand */
2427 if (IS_ITEMP (IC_RIGHT (ic)) &&
2428 OP_SYMBOL (IC_RIGHT (ic))->liveTo <= ic->seq)
2430 iCode *dic = findAssignToSym (IC_RIGHT (ic), ic);
2434 /* if this is a subtraction & the result
2435 is a true symbol in far space then don't pack */
2436 if (ic->op == '-' && IS_TRUE_SYMOP (IC_RESULT (dic)))
2438 sym_link *etype = getSpec (operandType (IC_RESULT (dic)));
2439 if (IN_FARSPACE (SPEC_OCLS (etype)))
2442 /* found it we need to remove it from the
2444 reassignAliasedSym (ebp, dic, ic, IC_RIGHT(ic));
2454 /*-----------------------------------------------------------------*/
2455 /* packRegsForOneuse : - will reduce some registers for single Use */
2456 /*-----------------------------------------------------------------*/
2458 packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
2462 /* if returning a literal then do nothing */
2466 /* if rematerializable or already return use then do nothing */
2467 if (OP_SYMBOL(op)->remat || OP_SYMBOL(op)->ruonly)
2470 /* only upto 2 bytes since we cannot predict
2471 the usage of b, & acc */
2472 if (getSize (operandType (op)) > (fReturnSizeMCS51 - 2))
2475 if (ic->op != RETURN &&
2477 !POINTER_SET (ic) &&
2481 if (ic->op == SEND && ic->argreg != 1) return NULL;
2483 /* this routine will mark the symbol as used in one
2484 instruction use only && if the definition is local
2485 (ie. within the basic block) && has only one definition &&
2486 that definition is either a return value from a
2487 function or does not contain any variables in
2489 if (bitVectnBitsOn (OP_USES (op)) > 1)
2492 /* if it has only one definition */
2493 if (bitVectnBitsOn (OP_DEFS (op)) > 1)
2494 return NULL; /* has more than one definition */
2496 /* get that definition */
2498 hTabItemWithKey (iCodehTab,
2499 bitVectFirstBit (OP_DEFS (op)))))
2502 /* if that only usage is a cast */
2503 if (dic->op == CAST) {
2504 /* to a bigger type */
2505 if (getSize(OP_SYM_TYPE(IC_RESULT(dic))) >
2506 getSize(OP_SYM_TYPE(IC_RIGHT(dic)))) {
2507 /* than we can not, since we cannot predict the usage of b & acc */
2512 /* found the definition now check if it is local */
2513 if (dic->seq < ebp->fSeq ||
2514 dic->seq > ebp->lSeq)
2515 return NULL; /* non-local */
2517 /* now check if it is the return from
2519 if (dic->op == CALL || dic->op == PCALL)
2521 if (ic->op != SEND && ic->op != RETURN &&
2522 !POINTER_SET(ic) && !POINTER_GET(ic))
2524 OP_SYMBOL (op)->ruonly = 1;
2530 /* otherwise check that the definition does
2531 not contain any symbols in far space */
2532 if (isOperandInFarSpace (IC_LEFT (dic)) ||
2533 isOperandInFarSpace (IC_RIGHT (dic)) ||
2534 IS_OP_RUONLY (IC_LEFT (ic)) ||
2535 IS_OP_RUONLY (IC_RIGHT (ic)))
2540 /* if pointer set then make sure the pointer
2542 if (POINTER_SET (dic) &&
2543 !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)))
2546 if (POINTER_GET (dic) &&
2547 !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)))
2551 /* Make sure no overlapping liverange is already assigned to DPTR */
2552 if (OP_SYMBOL(op)->clashes)
2557 for (i = 0 ; i < OP_SYMBOL(op)->clashes->size ; i++ )
2559 if (bitVectBitValue(OP_SYMBOL(op)->clashes,i))
2561 sym = hTabItemWithKey(liveRanges,i);
2570 /* also make sure the intervening instructions
2571 don't have anything in far space */
2572 for (dic = dic->next; dic && dic != ic && sic != ic; dic = dic->next)
2574 /* if there is an intervening function call then no */
2575 if (dic->op == CALL || dic->op == PCALL)
2577 /* if pointer set then make sure the pointer
2579 if (POINTER_SET (dic) &&
2580 !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)))
2583 if (POINTER_GET (dic) &&
2584 !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)))
2587 /* if address of & the result is remat the okay */
2588 if (dic->op == ADDRESS_OF &&
2589 OP_SYMBOL (IC_RESULT (dic))->remat)
2592 /* if operand has size of three or more & this
2593 operation is a '*','/' or '%' then 'b' may
2595 if ((dic->op == '%' || dic->op == '/' || dic->op == '*') &&
2596 getSize (operandType (op)) >= 3)
2599 /* if left or right or result is in far space */
2600 if (isOperandInFarSpace (IC_LEFT (dic)) ||
2601 isOperandInFarSpace (IC_RIGHT (dic)) ||
2602 isOperandInFarSpace (IC_RESULT (dic)) ||
2603 IS_OP_RUONLY (IC_LEFT (dic)) ||
2604 IS_OP_RUONLY (IC_RIGHT (dic)) ||
2605 IS_OP_RUONLY (IC_RESULT (dic)))
2609 /* if left or right or result is on stack */
2610 if (isOperandOnStack(IC_LEFT(dic)) ||
2611 isOperandOnStack(IC_RIGHT(dic)) ||
2612 isOperandOnStack(IC_RESULT(dic))) {
2617 OP_SYMBOL (op)->ruonly = 1;
2621 /*-----------------------------------------------------------------*/
2622 /* isBitwiseOptimizable - requirements of JEAN LOUIS VERN */
2623 /*-----------------------------------------------------------------*/
2625 isBitwiseOptimizable (iCode * ic)
2627 sym_link *ltype = getSpec (operandType (IC_LEFT (ic)));
2628 sym_link *rtype = getSpec (operandType (IC_RIGHT (ic)));
2630 /* bitwise operations are considered optimizable
2631 under the following conditions (Jean-Louis VERN)
2643 if (IS_LITERAL(rtype) ||
2644 (IS_BITVAR (ltype) && IN_BITSPACE (SPEC_OCLS (ltype))))
2650 /*-----------------------------------------------------------------*/
2651 /* isCommutativeOp - tests whether this op cares what order its */
2652 /* operands are in */
2653 /*-----------------------------------------------------------------*/
2654 bool isCommutativeOp(unsigned int op)
2656 if (op == '+' || op == '*' || op == EQ_OP ||
2657 op == '^' || op == '|' || op == BITWISEAND)
2663 /*-----------------------------------------------------------------*/
2664 /* operandUsesAcc - determines whether the code generated for this */
2665 /* operand will have to use the accumulator */
2666 /*-----------------------------------------------------------------*/
2667 bool operandUsesAcc(operand *op, bool allowBitspace)
2673 symbol *sym = OP_SYMBOL(op);
2677 return TRUE; /* duh! */
2679 if (IN_STACK(sym->etype) || sym->onStack ||
2680 (SPIL_LOC(op) && SPIL_LOC(op)->onStack))
2681 return TRUE; /* acc is used to calc stack offset */
2686 sym = SPIL_LOC(op); /* if spilled, look at spill location */
2688 return FALSE; /* more checks? */
2692 symspace = SPEC_OCLS(sym->etype);
2694 if (sym->iaccess && symspace->paged)
2695 return TRUE; /* must fetch paged indirect sym via accumulator */
2697 if (!allowBitspace && IN_BITSPACE(symspace))
2698 return TRUE; /* fetching bit vars uses the accumulator */
2700 if (IN_FARSPACE(symspace) || IN_CODESPACE(symspace))
2701 return TRUE; /* fetched via accumulator and dptr */
2707 /*-----------------------------------------------------------------*/
2708 /* packRegsForAccUse - pack registers for acc use */
2709 /*-----------------------------------------------------------------*/
2711 packRegsForAccUse (iCode * ic)
2715 /* if this is an aggregate, e.g. a one byte char array */
2716 if (IS_AGGREGATE(operandType(IC_RESULT(ic)))) {
2720 /* if we are calling a reentrant function that has stack parameters */
2721 if (ic->op == CALL &&
2722 IFFUNC_ISREENT(operandType(IC_LEFT(ic))) &&
2723 FUNC_HASSTACKPARM(operandType(IC_LEFT(ic))))
2726 if (ic->op == PCALL &&
2727 IFFUNC_ISREENT(operandType(IC_LEFT(ic))->next) &&
2728 FUNC_HASSTACKPARM(operandType(IC_LEFT(ic))->next))
2731 /* if + or - then it has to be one byte result */
2732 if ((ic->op == '+' || ic->op == '-')
2733 && getSize (operandType (IC_RESULT (ic))) > 1)
2736 /* if shift operation make sure right side is not a literal */
2737 if (ic->op == RIGHT_OP &&
2738 (isOperandLiteral (IC_RIGHT (ic)) ||
2739 getSize (operandType (IC_RESULT (ic))) > 1))
2742 if (ic->op == LEFT_OP &&
2743 (isOperandLiteral (IC_RIGHT (ic)) ||
2744 getSize (operandType (IC_RESULT (ic))) > 1))
2747 if (IS_BITWISE_OP (ic) &&
2748 getSize (operandType (IC_RESULT (ic))) > 1)
2751 /* has only one definition */
2752 if (bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) > 1)
2755 /* has only one use */
2756 if (bitVectnBitsOn (OP_USES (IC_RESULT (ic))) > 1)
2759 /* and the usage immediately follows this iCode */
2760 if (!(uic = hTabItemWithKey (iCodehTab,
2761 bitVectFirstBit (OP_USES (IC_RESULT (ic))))))
2764 if (ic->next != uic)
2767 /* if it is a conditional branch then we definitely can */
2771 if (uic->op == JUMPTABLE)
2774 if (POINTER_SET (uic) &&
2775 getSize (aggrToPtr (operandType (IC_RESULT (uic)), FALSE)) > 1)
2778 /* if the usage is not an assignment
2779 or an arithmetic / bitwise / shift operation then not */
2780 if (uic->op != '=' &&
2781 !IS_ARITHMETIC_OP (uic) &&
2782 !IS_BITWISE_OP (uic) &&
2783 uic->op != LEFT_OP &&
2784 uic->op != RIGHT_OP)
2787 /* if used in ^ operation then make sure right is not a
2788 literal (WIML: Why is this?) */
2789 if (uic->op == '^' && isOperandLiteral (IC_RIGHT (uic)))
2792 /* if shift operation make sure right side is not a literal */
2793 /* WIML: Why is this? */
2794 if (uic->op == RIGHT_OP &&
2795 (isOperandLiteral (IC_RIGHT (uic)) ||
2796 getSize (operandType (IC_RESULT (uic))) > 1))
2798 if (uic->op == LEFT_OP &&
2799 (isOperandLiteral (IC_RIGHT (uic)) ||
2800 getSize (operandType (IC_RESULT (uic))) > 1))
2803 /* make sure that the result of this icode is not on the
2804 stack, since acc is used to compute stack offset */
2806 if (IS_TRUE_SYMOP (IC_RESULT (uic)) &&
2807 OP_SYMBOL (IC_RESULT (uic))->onStack)
2810 if (isOperandOnStack(IC_RESULT(uic)))
2814 /* if the usage has only one operand then we can */
2815 if (IC_LEFT (uic) == NULL ||
2816 IC_RIGHT (uic) == NULL)
2819 /* if the other operand uses the accumulator then we cannot */
2820 if ( (IC_LEFT (uic)->key == IC_RESULT (ic)->key &&
2821 operandUsesAcc (IC_RIGHT (uic), IS_BIT (operandType (IC_LEFT (uic))))) ||
2822 (IC_RIGHT(uic)->key == IC_RESULT(ic)->key &&
2823 operandUsesAcc (IC_LEFT (uic), IS_BIT (operandType (IC_RIGHT (uic))))) )
2826 /* make sure this is on the left side if not commutative */
2827 /* except for '-', which has been written to be able to
2828 handle reversed operands */
2829 if (!(isCommutativeOp(ic->op) || ic->op == '-') &&
2830 IC_LEFT (uic)->key != IC_RESULT (ic)->key)
2834 // this is too dangerous and need further restrictions
2837 /* if one of them is a literal then we can */
2838 if ((IC_LEFT (uic) && IS_OP_LITERAL (IC_LEFT (uic))) ||
2839 (IC_RIGHT (uic) && IS_OP_LITERAL (IC_RIGHT (uic))))
2841 OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
2847 OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
2851 /*-----------------------------------------------------------------*/
2852 /* packForPush - heuristics to reduce iCode for pushing */
2853 /*-----------------------------------------------------------------*/
2855 packForPush (iCode * ic, eBBlock ** ebpp, int blockno)
2859 struct eBBlock * ebp=ebpp[blockno];
2861 if (ic->op != IPUSH || !IS_ITEMP (IC_LEFT (ic)))
2864 /* must have only definition & one usage */
2865 if (bitVectnBitsOn (OP_DEFS (IC_LEFT (ic))) != 1 ||
2866 bitVectnBitsOn (OP_USES (IC_LEFT (ic))) != 1)
2869 /* find the definition */
2870 if (!(dic = hTabItemWithKey (iCodehTab,
2871 bitVectFirstBit (OP_DEFS (IC_LEFT (ic))))))
2874 if (dic->op != '=' || POINTER_SET (dic))
2877 if (dic->seq < ebp->fSeq) { // Evelyn did this
2879 for (i=0; i<blockno; i++) {
2880 if (dic->seq >= ebpp[i]->fSeq && dic->seq <= ebpp[i]->lSeq) {
2885 wassert (i!=blockno); // no way to recover from here
2888 if (IS_SYMOP(IC_RIGHT(dic))) {
2889 /* make sure the right side does not have any definitions
2891 dbv = OP_DEFS(IC_RIGHT(dic));
2892 for (lic = ic; lic && lic != dic ; lic = lic->prev) {
2893 if (bitVectBitValue(dbv,lic->key))
2896 /* make sure they have the same type */
2897 if (IS_SPEC(operandType(IC_LEFT(ic))))
2899 sym_link *itype=operandType(IC_LEFT(ic));
2900 sym_link *ditype=operandType(IC_RIGHT(dic));
2902 if (SPEC_USIGN(itype)!=SPEC_USIGN(ditype) ||
2903 SPEC_LONG(itype)!=SPEC_LONG(ditype))
2906 /* extend the live range of replaced operand if needed */
2907 if (OP_SYMBOL(IC_RIGHT(dic))->liveTo < ic->seq) {
2908 OP_SYMBOL(IC_RIGHT(dic))->liveTo = ic->seq;
2910 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
2913 /* we now we know that it has one & only one def & use
2914 and the that the definition is an assignment */
2915 ReplaceOpWithCheaperOp(&IC_LEFT (ic), IC_RIGHT (dic));
2916 remiCodeFromeBBlock (ebp, dic);
2917 hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
2920 /*-----------------------------------------------------------------*/
2921 /* packRegisters - does some transformations to reduce register */
2923 /*-----------------------------------------------------------------*/
2925 packRegisters (eBBlock ** ebpp, int blockno)
2929 eBBlock *ebp=ebpp[blockno];
2935 /* look for assignments of the form */
2936 /* iTempNN = TRueSym (someoperation) SomeOperand */
2938 /* TrueSym := iTempNN:1 */
2939 for (ic = ebp->sch; ic; ic = ic->next)
2941 /* find assignment of the form TrueSym := iTempNN:1 */
2942 if (ic->op == '=' && !POINTER_SET (ic))
2943 change += packRegsForAssign (ic, ebp);
2950 for (ic = ebp->sch; ic; ic = ic->next)
2952 /* Fix for bug #979599: */
2955 /* Look for two subsequent iCodes with */
2957 /* _c = iTemp & op; */
2958 /* and replace them by */
2961 if ((ic->op == BITWISEAND || ic->op == '|' || ic->op == '^') &&
2963 ic->prev->op == '=' &&
2964 IS_ITEMP (IC_LEFT (ic)) &&
2965 IC_LEFT (ic) == IC_RESULT (ic->prev) &&
2966 isOperandEqual (IC_RESULT(ic), IC_RIGHT(ic->prev)))
2968 iCode* ic_prev = ic->prev;
2969 symbol* prev_result_sym = OP_SYMBOL (IC_RESULT (ic_prev));
2971 ReplaceOpWithCheaperOp (&IC_LEFT (ic), IC_RESULT (ic));
2972 if (IC_RESULT (ic_prev) != IC_RIGHT (ic))
2974 bitVectUnSetBit (OP_USES (IC_RESULT (ic_prev)), ic->key);
2975 if (/*IS_ITEMP (IC_RESULT (ic_prev)) && */
2976 prev_result_sym->liveTo == ic->seq)
2978 prev_result_sym->liveTo = ic_prev->seq;
2981 bitVectSetBit (OP_USES (IC_RESULT (ic)), ic->key);
2983 bitVectSetBit (ic->rlive, IC_RESULT (ic)->key);
2985 if (bitVectIsZero (OP_USES (IC_RESULT (ic_prev))))
2987 bitVectUnSetBit (ic->rlive, IC_RESULT (ic)->key);
2988 bitVectUnSetBit (OP_DEFS (IC_RESULT (ic_prev)), ic_prev->key);
2989 remiCodeFromeBBlock (ebp, ic_prev);
2990 hTabDeleteItem (&iCodehTab, ic_prev->key, ic_prev, DELETE_ITEM, NULL);
2994 /* if this is an itemp & result of an address of a true sym
2995 then mark this as rematerialisable */
2996 if (ic->op == ADDRESS_OF &&
2997 IS_ITEMP (IC_RESULT (ic)) &&
2998 IS_TRUE_SYMOP (IC_LEFT (ic)) &&
2999 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
3000 !OP_SYMBOL (IC_LEFT (ic))->onStack)
3002 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
3003 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
3004 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
3007 /* if straight assignment then carry remat flag if
3008 this is the only definition */
3009 if (ic->op == '=' &&
3010 !POINTER_SET (ic) &&
3011 IS_SYMOP (IC_RIGHT (ic)) &&
3012 OP_SYMBOL (IC_RIGHT (ic))->remat &&
3013 !IS_CAST_ICODE(OP_SYMBOL (IC_RIGHT (ic))->rematiCode) &&
3014 bitVectnBitsOn (OP_SYMBOL (IC_RESULT (ic))->defs) <= 1)
3016 OP_SYMBOL (IC_RESULT (ic))->remat =
3017 OP_SYMBOL (IC_RIGHT (ic))->remat;
3018 OP_SYMBOL (IC_RESULT (ic))->rematiCode =
3019 OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
3022 /* if cast to a generic pointer & the pointer being
3023 cast is remat, then we can remat this cast as well */
3024 if (ic->op == CAST &&
3025 IS_SYMOP(IC_RIGHT(ic)) &&
3026 OP_SYMBOL(IC_RIGHT(ic))->remat &&
3027 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1)
3029 sym_link *to_type = operandType(IC_LEFT(ic));
3030 sym_link *from_type = operandType(IC_RIGHT(ic));
3031 if (IS_GENPTR(to_type) && IS_PTR(from_type))
3033 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
3034 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
3035 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
3039 /* if this is a +/- operation with a rematerizable
3040 then mark this as rematerializable as well */
3041 if ((ic->op == '+' || ic->op == '-') &&
3042 (IS_SYMOP (IC_LEFT (ic)) &&
3043 IS_ITEMP (IC_RESULT (ic)) &&
3044 IS_OP_LITERAL (IC_RIGHT (ic))) &&
3045 OP_SYMBOL (IC_LEFT (ic))->remat &&
3046 (!IS_SYMOP (IC_RIGHT (ic)) || !IS_CAST_ICODE(OP_SYMBOL (IC_RIGHT (ic))->rematiCode)) &&
3047 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1)
3049 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
3050 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
3051 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
3054 /* mark the pointer usages */
3055 if (POINTER_SET (ic) && IS_SYMOP (IC_RESULT (ic)))
3056 OP_SYMBOL (IC_RESULT (ic))->uptr = 1;
3058 if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic)))
3059 OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
3063 /* if we are using a symbol on the stack
3064 then we should say mcs51_ptrRegReq */
3065 if (options.useXstack && ic->parmPush
3066 && (ic->op == IPUSH || ic->op == IPOP))
3068 if (ic->op == IFX && IS_SYMOP (IC_COND (ic)))
3069 mcs51_ptrRegReq += ((OP_SYMBOL (IC_COND (ic))->onStack ||
3070 OP_SYMBOL (IC_COND (ic))->iaccess ||
3071 SPEC_OCLS(OP_SYMBOL (IC_COND (ic))->etype) == idata) ? 1 : 0);
3072 else if (ic->op == JUMPTABLE && IS_SYMOP (IC_JTCOND (ic)))
3073 mcs51_ptrRegReq += ((OP_SYMBOL (IC_JTCOND (ic))->onStack ||
3074 OP_SYMBOL (IC_JTCOND (ic))->iaccess ||
3075 SPEC_OCLS(OP_SYMBOL (IC_JTCOND (ic))->etype) == idata) ? 1 : 0);
3078 if (IS_SYMOP (IC_LEFT (ic)))
3079 mcs51_ptrRegReq += ((OP_SYMBOL (IC_LEFT (ic))->onStack ||
3080 OP_SYMBOL (IC_LEFT (ic))->iaccess ||
3081 SPEC_OCLS(OP_SYMBOL (IC_LEFT (ic))->etype) == idata) ? 1 : 0);
3082 if (IS_SYMOP (IC_RIGHT (ic)))
3083 mcs51_ptrRegReq += ((OP_SYMBOL (IC_RIGHT (ic))->onStack ||
3084 OP_SYMBOL (IC_RIGHT (ic))->iaccess ||
3085 SPEC_OCLS(OP_SYMBOL (IC_RIGHT (ic))->etype) == idata) ? 1 : 0);
3086 if (IS_SYMOP (IC_RESULT (ic)))
3087 mcs51_ptrRegReq += ((OP_SYMBOL (IC_RESULT (ic))->onStack ||
3088 OP_SYMBOL (IC_RESULT (ic))->iaccess ||
3089 SPEC_OCLS(OP_SYMBOL (IC_RESULT (ic))->etype) == idata) ? 1 : 0);
3090 if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic))
3091 && getSize (OP_SYMBOL (IC_LEFT (ic))->type) <= (unsigned int) PTRSIZE)
3093 if (POINTER_SET (ic) && IS_SYMOP (IC_RESULT (ic))
3094 && getSize (OP_SYMBOL (IC_RESULT (ic))->type) <= (unsigned int) PTRSIZE)
3099 /* if the condition of an if instruction
3100 is defined in the previous instruction and
3101 this is the only usage then
3102 mark the itemp as a conditional */
3103 if ((IS_CONDITIONAL (ic) ||
3104 (IS_BITWISE_OP(ic) && isBitwiseOptimizable (ic))) &&
3105 ic->next && ic->next->op == IFX &&
3106 bitVectnBitsOn (OP_USES(IC_RESULT(ic)))==1 &&
3107 isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
3108 OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
3110 OP_SYMBOL (IC_RESULT (ic))->regType = REG_CND;
3114 /* if the condition of an if instruction
3115 is defined in the previous GET_POINTER instruction and
3116 this is the only usage then
3117 mark the itemp as accumulator use */
3118 if ((POINTER_GET (ic) && getSize (operandType (IC_RESULT (ic))) <=1) &&
3119 ic->next && ic->next->op == IFX &&
3120 bitVectnBitsOn (OP_USES(IC_RESULT(ic)))==1 &&
3121 isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
3122 OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
3124 OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
3128 /* reduce for support function calls */
3129 if (ic->supportRtn || ic->op == '+' || ic->op == '-')
3130 packRegsForSupport (ic, ebp);
3132 /* some cases the redundant moves can
3133 can be eliminated for return statements */
3134 if ((ic->op == RETURN || (ic->op == SEND && ic->argreg == 1)) &&
3135 !isOperandInFarSpace (IC_LEFT (ic)) &&
3136 options.model == MODEL_SMALL) {
3137 packRegsForOneuse (ic, IC_LEFT (ic), ebp);
3140 /* if pointer set & left has a size more than
3141 one and right is not in far space */
3142 if (POINTER_SET (ic) &&
3143 IS_SYMOP (IC_RESULT (ic)) &&
3144 !isOperandInFarSpace (IC_RIGHT (ic)) &&
3145 !OP_SYMBOL (IC_RESULT (ic))->remat &&
3146 !IS_OP_RUONLY (IC_RIGHT (ic)) &&
3147 getSize (aggrToPtr (operandType (IC_RESULT (ic)), FALSE)) > 1)
3148 packRegsForOneuse (ic, IC_RESULT (ic), ebp);
3150 /* if pointer get */
3151 if (POINTER_GET (ic) &&
3152 IS_SYMOP (IC_LEFT (ic)) &&
3153 !isOperandInFarSpace (IC_RESULT (ic)) &&
3154 !OP_SYMBOL (IC_LEFT (ic))->remat &&
3155 !IS_OP_RUONLY (IC_RESULT (ic)) &&
3156 getSize (aggrToPtr (operandType (IC_LEFT (ic)), FALSE)) > 1)
3157 packRegsForOneuse (ic, IC_LEFT (ic), ebp);
3159 /* if this is a cast for intergral promotion then
3160 check if it's the only use of the definition of the
3161 operand being casted/ if yes then replace
3162 the result of that arithmetic operation with
3163 this result and get rid of the cast */
3166 sym_link *fromType = operandType (IC_RIGHT (ic));
3167 sym_link *toType = operandType (IC_LEFT (ic));
3169 if (IS_INTEGRAL (fromType) && IS_INTEGRAL (toType) &&
3170 getSize (fromType) != getSize (toType) &&
3171 SPEC_USIGN (fromType) == SPEC_USIGN (toType))
3174 iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
3177 if (IS_ARITHMETIC_OP (dic))
3179 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
3180 ReplaceOpWithCheaperOp(&IC_RESULT (dic), IC_RESULT (ic));
3181 remiCodeFromeBBlock (ebp, ic);
3182 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
3183 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
3184 OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
3188 OP_SYMBOL (IC_RIGHT (ic))->ruonly = 0;
3193 /* if the type from and type to are the same
3194 then if this is the only use then packit */
3195 if (compareType (operandType (IC_RIGHT (ic)),
3196 operandType (IC_LEFT (ic))) == 1)
3198 iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
3201 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
3202 ReplaceOpWithCheaperOp(&IC_RESULT (dic), IC_RESULT (ic));
3203 remiCodeFromeBBlock (ebp, ic);
3204 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
3205 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
3206 OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
3214 iTempNN := (some variable in farspace) V1
3219 if (ic->op == IPUSH)
3221 packForPush (ic, ebpp, blockno);
3225 /* pack registers for accumulator use, when the
3226 result of an arithmetic or bit wise operation
3227 has only one use, that use is immediately following
3228 the defintion and the using iCode has only one
3229 operand or has two operands but one is literal &
3230 the result of that operation is not on stack then
3231 we can leave the result of this operation in acc:b
3233 if ((IS_ARITHMETIC_OP (ic)
3234 || IS_CONDITIONAL(ic)
3235 || IS_BITWISE_OP (ic)
3236 || ic->op == LEFT_OP || ic->op == RIGHT_OP || ic->op == CALL
3237 || (ic->op == ADDRESS_OF && isOperandOnStack (IC_LEFT (ic)))
3239 IS_ITEMP (IC_RESULT (ic)) &&
3240 getSize (operandType (IC_RESULT (ic))) <= 2)
3242 packRegsForAccUse (ic);
3246 /*-----------------------------------------------------------------*/
3247 /* assignRegisters - assigns registers to each live range as need */
3248 /*-----------------------------------------------------------------*/
3250 mcs51_assignRegisters (ebbIndex * ebbi)
3252 eBBlock ** ebbs = ebbi->bbOrder;
3253 int count = ebbi->count;
3257 setToNull ((void *) &_G.funcrUsed);
3258 setToNull ((void *) &_G.regAssigned);
3259 setToNull ((void *) &_G.totRegAssigned);
3260 mcs51_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
3261 if ((currFunc && IFFUNC_ISREENT (currFunc->type)) || options.stackAuto)
3269 _G.allBitregs = findAllBitregs ();
3272 /* change assignments this will remove some
3273 live ranges reducing some register pressure */
3275 for (i = 0; i < count; i++)
3276 packRegisters (ebbs, i);
3278 /* liveranges probably changed by register packing
3279 so we compute them again */
3280 recomputeLiveRanges (ebbs, count);
3282 if (options.dump_pack)
3283 dumpEbbsToFileExt (DUMP_PACK, ebbi);
3285 /* first determine for each live range the number of
3286 registers & the type of registers required for each */
3289 /* and serially allocate registers */
3290 serialRegAssign (ebbs, count);
3293 //setToNull ((void *) &_G.regAssigned);
3294 //setToNull ((void *) &_G.totRegAssigned);
3297 /* if stack was extended then tell the user */
3300 /* werror(W_TOOMANY_SPILS,"stack", */
3301 /* _G.stackExtend,currFunc->name,""); */
3307 /* werror(W_TOOMANY_SPILS,"data space", */
3308 /* _G.dataExtend,currFunc->name,""); */
3312 /* after that create the register mask
3313 for each of the instruction */
3314 createRegMask (ebbs, count);
3316 /* redo that offsets for stacked automatic variables */
3318 redoStackOffsets ();
3321 /* make sure r0 & r1 are flagged as used if they might be used */
3323 if (currFunc && mcs51_ptrRegReq)
3325 currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, R0_IDX);
3326 currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, R1_IDX);
3329 if (options.dump_rassgn)
3331 dumpEbbsToFileExt (DUMP_RASSGN, ebbi);
3332 dumpLiveRanges (DUMP_LRANGE, liveRanges);
3335 /* do the overlaysegment stuff SDCCmem.c */
3336 doOverlays (ebbs, count);
3338 /* now get back the chain */
3339 ic = iCodeLabelOptimize (iCodeFromeBBlock (ebbs, count));
3343 /* free up any _G.stackSpil locations allocated */
3344 applyToSet (_G.stackSpil, deallocStackSpil);
3346 setToNull ((void *) &_G.stackSpil);
3347 setToNull ((void *) &_G.spiltSet);
3348 /* mark all registers as free */