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 */
64 {REG_GPR, R2_IDX, REG_GPR, "r2", "ar2", "0", 2, 1},
65 {REG_GPR, R3_IDX, REG_GPR, "r3", "ar3", "0", 3, 1},
66 {REG_GPR, R4_IDX, REG_GPR, "r4", "ar4", "0", 4, 1},
67 {REG_GPR, R5_IDX, REG_GPR, "r5", "ar5", "0", 5, 1},
68 {REG_GPR, R6_IDX, REG_GPR, "r6", "ar6", "0", 6, 1},
69 {REG_GPR, R7_IDX, REG_GPR, "r7", "ar7", "0", 7, 1},
70 {REG_PTR, R0_IDX, REG_PTR, "r0", "ar0", "0", 0, 1},
71 {REG_PTR, R1_IDX, REG_PTR, "r1", "ar1", "0", 1, 1},
72 {REG_BIT, B0_IDX, REG_BIT, "b0", "b0", "bits", 0, 1},
73 {REG_BIT, B1_IDX, REG_BIT, "b1", "b1", "bits", 1, 1},
74 {REG_BIT, B2_IDX, REG_BIT, "b2", "b2", "bits", 2, 1},
75 {REG_BIT, B3_IDX, REG_BIT, "b3", "b3", "bits", 3, 1},
76 {REG_BIT, B4_IDX, REG_BIT, "b4", "b4", "bits", 4, 1},
77 {REG_BIT, B5_IDX, REG_BIT, "b5", "b5", "bits", 5, 1},
78 {REG_BIT, B6_IDX, REG_BIT, "b6", "b6", "bits", 6, 1},
79 {REG_BIT, B7_IDX, REG_BIT, "b7", "b7", "bits", 7, 1},
80 {REG_GPR, X8_IDX, REG_GPR, "x8", "x8", "xreg", 0, 1},
81 {REG_GPR, X9_IDX, REG_GPR, "x9", "x9", "xreg", 1, 1},
82 {REG_GPR, X10_IDX, REG_GPR, "x10", "x10", "xreg", 2, 1},
83 {REG_GPR, X11_IDX, REG_GPR, "x11", "x11", "xreg", 3, 1},
84 {REG_GPR, X12_IDX, REG_GPR, "x12", "x12", "xreg", 4, 1},
85 {REG_CND, CND_IDX, REG_CND, "C", "psw", "0xd0", 0, 1},
86 {0, DPL_IDX, 0, "dpl", "dpl", "0x82", 0, 0},
87 {0, DPH_IDX, 0, "dph", "dph", "0x83", 0, 0},
88 {0, B_IDX, 0, "b", "b", "0xf0", 0, 0},
89 {0, A_IDX, 0, "a", "acc", "0xe0", 0, 0},
92 static void spillThis (symbol *);
93 static void freeAllRegs ();
95 /*-----------------------------------------------------------------*/
96 /* allocReg - allocates register of given type */
97 /*-----------------------------------------------------------------*/
103 for (i = 0; i < mcs51_nRegs; i++)
105 /* if type is given as 0 then any
106 free register will do */
107 if (!type && regs8051[i].isFree)
109 regs8051[i].isFree = 0;
111 currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, i);
114 /* other wise look for specific type
116 if (regs8051[i].isFree && regs8051[i].type == type)
118 regs8051[i].isFree = 0;
120 currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, i);
127 /*-----------------------------------------------------------------*/
128 /* allocThisReg - allocates a particular register (if free) */
129 /*-----------------------------------------------------------------*/
131 allocThisReg (regs * reg)
138 currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, reg->rIdx);
144 /*-----------------------------------------------------------------*/
145 /* mcs51_regWithIdx - returns pointer to register with index number*/
146 /*-----------------------------------------------------------------*/
148 mcs51_regWithIdx (int idx)
152 for (i = 0; i < sizeof(regs8051)/sizeof(regs); i++)
153 if (regs8051[i].rIdx == idx)
156 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
157 "regWithIdx not found");
161 /*-----------------------------------------------------------------*/
162 /* freeReg - frees a register */
163 /*-----------------------------------------------------------------*/
169 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
170 "freeReg - Freeing NULL register");
178 /*-----------------------------------------------------------------*/
179 /* nFreeRegs - returns number of free registers */
180 /*-----------------------------------------------------------------*/
187 for (i = 0; i < mcs51_nRegs; i++)
188 if (regs8051[i].isFree && regs8051[i].type == type)
193 /*-----------------------------------------------------------------*/
194 /* nfreeRegsType - free registers with type */
195 /*-----------------------------------------------------------------*/
197 nfreeRegsType (int type)
202 if ((nfr = nFreeRegs (type)) == 0)
203 return nFreeRegs (REG_GPR);
206 return nFreeRegs (type);
209 /*-----------------------------------------------------------------*/
210 /* useReg - marks a register as used */
211 /*-----------------------------------------------------------------*/
218 /*-----------------------------------------------------------------*/
219 /* computeSpillable - given a point find the spillable live ranges */
220 /*-----------------------------------------------------------------*/
222 computeSpillable (iCode * ic)
226 /* spillable live ranges are those that are live at this
227 point . the following categories need to be subtracted
229 a) - those that are already spilt
230 b) - if being used by this one
231 c) - defined by this one */
233 spillable = bitVectCopy (ic->rlive);
235 bitVectCplAnd (spillable, _G.spiltSet); /* those already spilt */
237 bitVectCplAnd (spillable, ic->uses); /* used in this one */
238 bitVectUnSetBit (spillable, ic->defKey);
239 spillable = bitVectIntersect (spillable, _G.regAssigned);
243 /*-----------------------------------------------------------------*/
244 /* bitType - will return 1 if the symbol has type REG_BIT */
245 /*-----------------------------------------------------------------*/
247 bitType (symbol * sym, eBBlock * ebp, iCode * ic)
249 return (sym->regType == REG_BIT ? 1 : 0);
252 /*-----------------------------------------------------------------*/
253 /* noSpilLoc - return true if a variable has no spil location */
254 /*-----------------------------------------------------------------*/
256 noSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
258 return (sym->usl.spillLoc ? 0 : 1);
261 /*-----------------------------------------------------------------*/
262 /* hasSpilLoc - will return 1 if the symbol has spil location */
263 /*-----------------------------------------------------------------*/
265 hasSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
267 return (sym->usl.spillLoc ? 1 : 0);
270 /*-----------------------------------------------------------------*/
271 /* directSpilLoc - will return 1 if the spillocation is in direct */
272 /*-----------------------------------------------------------------*/
274 directSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
276 if (sym->usl.spillLoc &&
277 (IN_DIRSPACE (SPEC_OCLS (sym->usl.spillLoc->etype))))
283 /*-----------------------------------------------------------------*/
284 /* hasSpilLocnoUptr - will return 1 if the symbol has spil location */
285 /* but is not used as a pointer */
286 /*-----------------------------------------------------------------*/
288 hasSpilLocnoUptr (symbol * sym, eBBlock * ebp, iCode * ic)
290 return ((sym->usl.spillLoc && !sym->uptr) ? 1 : 0);
293 /*-----------------------------------------------------------------*/
294 /* rematable - will return 1 if the remat flag is set */
295 /*-----------------------------------------------------------------*/
297 rematable (symbol * sym, eBBlock * ebp, iCode * ic)
302 /*-----------------------------------------------------------------*/
303 /* notUsedInRemaining - not used or defined in remain of the block */
304 /*-----------------------------------------------------------------*/
306 notUsedInRemaining (symbol * sym, eBBlock * ebp, iCode * ic)
308 return ((usedInRemaining (operandFromSymbol (sym), ic) ? 0 : 1) &&
309 allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq));
312 /*-----------------------------------------------------------------*/
313 /* allLRs - return true for all */
314 /*-----------------------------------------------------------------*/
316 allLRs (symbol * sym, eBBlock * ebp, iCode * ic)
321 /*-----------------------------------------------------------------*/
322 /* liveRangesWith - applies function to a given set of live range */
323 /*-----------------------------------------------------------------*/
325 liveRangesWith (bitVect * lrs, int (func) (symbol *, eBBlock *, iCode *),
326 eBBlock * ebp, iCode * ic)
331 if (!lrs || !lrs->size)
334 for (i = 1; i < lrs->size; i++)
337 if (!bitVectBitValue (lrs, i))
340 /* if we don't find it in the live range
341 hash table we are in serious trouble */
342 if (!(sym = hTabItemWithKey (liveRanges, i)))
344 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
345 "liveRangesWith could not find liveRange");
349 if (func (sym, ebp, ic) && bitVectBitValue (_G.regAssigned, sym->key))
350 addSetHead (&rset, sym);
357 /*-----------------------------------------------------------------*/
358 /* leastUsedLR - given a set determines which is the least used */
359 /*-----------------------------------------------------------------*/
361 leastUsedLR (set * sset)
363 symbol *sym = NULL, *lsym = NULL;
365 sym = lsym = setFirstItem (sset);
370 for (; lsym; lsym = setNextItem (sset))
372 /* if usage is the same then prefer
373 to spill the smaller of the two */
374 if (lsym->used == sym->used)
375 if (getSize (lsym->type) < getSize (sym->type))
379 if (lsym->used < sym->used)
383 setToNull ((void *) &sset);
388 /*-----------------------------------------------------------------*/
389 /* noOverLap - will iterate through the list looking for over lap */
390 /*-----------------------------------------------------------------*/
392 noOverLap (set * itmpStack, symbol * fsym)
396 for (sym = setFirstItem (itmpStack); sym;
397 sym = setNextItem (itmpStack))
399 if (bitVectBitValue(sym->clashes,fsym->key)) return 0;
404 /*-----------------------------------------------------------------*/
405 /* isFree - will return 1 if the a free spil location is found */
406 /*-----------------------------------------------------------------*/
411 V_ARG (symbol **, sloc);
412 V_ARG (symbol *, fsym);
414 /* if already found */
418 /* if it is free && and the itmp assigned to
419 this does not have any overlapping live ranges
420 with the one currently being assigned and
421 the size can be accomodated */
423 noOverLap (sym->usl.itmpStack, fsym) &&
424 getSize (sym->type) >= getSize (fsym->type))
433 /*-----------------------------------------------------------------*/
434 /* spillLRWithPtrReg :- will spil those live ranges which use PTR */
435 /*-----------------------------------------------------------------*/
437 spillLRWithPtrReg (symbol * forSym)
443 if (!_G.regAssigned || bitVectIsZero (_G.regAssigned))
446 r0 = mcs51_regWithIdx (R0_IDX);
447 r1 = mcs51_regWithIdx (R1_IDX);
449 /* for all live ranges */
450 for (lrsym = hTabFirstItem (liveRanges, &k); lrsym;
451 lrsym = hTabNextItem (liveRanges, &k))
455 /* if no registers assigned to it or spilt */
456 /* if it does not overlap this then
457 no need to spill it */
459 if (lrsym->isspilt || !lrsym->nRegs ||
460 (lrsym->liveTo < forSym->liveFrom))
463 /* go thru the registers : if it is either
464 r0 or r1 then spill it */
465 for (j = 0; j < lrsym->nRegs; j++)
466 if (lrsym->regs[j] == r0 ||
467 lrsym->regs[j] == r1)
475 /*-----------------------------------------------------------------*/
476 /* createStackSpil - create a location on the stack to spil */
477 /*-----------------------------------------------------------------*/
479 createStackSpil (symbol * sym)
482 int useXstack, model;
486 /* first go try and find a free one that is already
487 existing on the stack */
488 if (applyToSet (_G.stackSpil, isFree, &sloc, sym))
490 /* found a free one : just update & return */
491 sym->usl.spillLoc = sloc;
494 addSetHead (&sloc->usl.itmpStack, sym);
498 /* could not then have to create one , this is the hard part
499 we need to allocate this on the stack : this is really a
500 hack!! but cannot think of anything better at this time */
502 if (SNPRINTF (slocBuffer, sizeof(slocBuffer),
503 "sloc%d", _G.slocNum++) >= sizeof (slocBuffer))
505 fprintf (stderr, "***Internal error: slocBuffer overflowed: %s:%d\n",
510 sloc = newiTemp (slocBuffer);
512 /* set the type to the spilling symbol */
513 sloc->type = copyLinkChain (sym->type);
514 sloc->etype = getSpec (sloc->type);
515 if (!IS_BIT (sloc->etype))
517 SPEC_SCLS (sloc->etype) = S_DATA;
519 else if (SPEC_SCLS (sloc->etype) == S_SBIT)
521 SPEC_SCLS (sloc->etype) = S_BIT;
523 SPEC_EXTR (sloc->etype) = 0;
524 SPEC_STAT (sloc->etype) = 0;
525 SPEC_VOLATILE(sloc->etype) = 0;
526 SPEC_ABSA(sloc->etype) = 0;
528 /* we don't allow it to be allocated
529 onto the external stack since : so we
530 temporarily turn it off ; we also
531 turn off memory model to prevent
532 the spil from going to the external storage
535 useXstack = options.useXstack;
536 model = options.model;
537 /* noOverlay = options.noOverlay; */
538 /* options.noOverlay = 1; */
539 options.model = options.useXstack = 0;
543 options.useXstack = useXstack;
544 options.model = model;
545 /* options.noOverlay = noOverlay; */
546 sloc->isref = 1; /* to prevent compiler warning */
548 /* if it is on the stack then update the stack */
549 if (IN_STACK (sloc->etype))
551 currFunc->stack += getSize (sloc->type);
552 _G.stackExtend += getSize (sloc->type);
555 _G.dataExtend += getSize (sloc->type);
557 /* add it to the _G.stackSpil set */
558 addSetHead (&_G.stackSpil, sloc);
559 sym->usl.spillLoc = sloc;
562 /* add it to the set of itempStack set
563 of the spill location */
564 addSetHead (&sloc->usl.itmpStack, sym);
568 /*-----------------------------------------------------------------*/
569 /* isSpiltOnStack - returns true if the spil location is on stack */
570 /* or otherwise needs a pointer register */
571 /*-----------------------------------------------------------------*/
573 isSpiltOnStack (symbol * sym)
583 /* if (sym->_G.stackSpil) */
586 if (!sym->usl.spillLoc)
589 if (sym->usl.spillLoc->onStack || sym->usl.spillLoc->iaccess)
592 etype = getSpec (sym->usl.spillLoc->type);
593 if (IN_STACK (etype))
599 /*-----------------------------------------------------------------*/
600 /* spillThis - spils a specific operand */
601 /*-----------------------------------------------------------------*/
603 spillThis (symbol * sym)
606 /* if this is rematerializable or has a spillLocation
607 we are okay, else we need to create a spillLocation
609 if (!(sym->remat || sym->usl.spillLoc))
610 createStackSpil (sym);
612 /* mark it has spilt & put it in the spilt set */
613 sym->isspilt = sym->spillA = 1;
614 _G.spiltSet = bitVectSetBit (_G.spiltSet, sym->key);
616 bitVectUnSetBit (_G.regAssigned, sym->key);
617 bitVectUnSetBit (_G.totRegAssigned, sym->key);
619 for (i = 0; i < sym->nRegs; i++)
623 freeReg (sym->regs[i]);
628 /* if spilt on stack then free up r0 & r1
629 if they could have been assigned to some
631 if (!mcs51_ptrRegReq && isSpiltOnStack (sym))
633 spillLRWithPtrReg (sym);
637 if (sym->usl.spillLoc && !sym->remat)
638 sym->usl.spillLoc->allocreq++;
642 /*-----------------------------------------------------------------*/
643 /* selectSpil - select a iTemp to spil : rather a simple procedure */
644 /*-----------------------------------------------------------------*/
646 selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
648 bitVect *lrcs = NULL;
652 /* get the spillable live ranges */
653 lrcs = computeSpillable (ic);
655 /* remove incompatible registers */
656 if ((forSym->regType == REG_PTR) || (forSym->regType == REG_GPR))
658 selectS = liveRangesWith (lrcs, bitType, ebp, ic);
660 for (sym = setFirstItem (selectS); sym; sym = setNextItem (selectS))
662 bitVectUnSetBit (lrcs, sym->key);
666 /* get all live ranges that are rematerializable */
667 if ((selectS = liveRangesWith (lrcs, rematable, ebp, ic)))
669 /* return the least used of these */
670 return leastUsedLR (selectS);
673 /* get live ranges with spillLocations in direct space */
674 if ((selectS = liveRangesWith (lrcs, directSpilLoc, ebp, ic)))
676 sym = leastUsedLR (selectS);
677 strncpyz (sym->rname,
678 sym->usl.spillLoc->rname[0] ?
679 sym->usl.spillLoc->rname : sym->usl.spillLoc->name,
682 /* mark it as allocation required */
683 sym->usl.spillLoc->allocreq++;
687 /* if the symbol is local to the block then */
688 if (forSym->liveTo < ebp->lSeq)
690 /* check if there are any live ranges allocated
691 to registers that are not used in this block */
692 if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInBlock, ebp, ic)))
694 sym = leastUsedLR (selectS);
695 /* if this is not rematerializable */
704 /* check if there are any live ranges that are
705 not used in the remainder of the block */
707 !isiCodeInFunctionCall (ic) &&
708 (selectS = liveRangesWith (lrcs, notUsedInRemaining, ebp, ic)))
710 sym = leastUsedLR (selectS);
723 /* find live ranges with spillocation && not used as pointers */
724 if ((selectS = liveRangesWith (lrcs, hasSpilLocnoUptr, ebp, ic)))
726 sym = leastUsedLR (selectS);
727 /* mark this as allocation required */
728 sym->usl.spillLoc->allocreq++;
732 /* find live ranges with spillocation */
733 if ((selectS = liveRangesWith (lrcs, hasSpilLoc, ebp, ic)))
735 sym = leastUsedLR (selectS);
736 sym->usl.spillLoc->allocreq++;
740 /* couldn't find then we need to create a spil
741 location on the stack, for which one?
742 the least used ofcourse */
743 if ((selectS = liveRangesWith (lrcs, noSpilLoc, ebp, ic)))
745 /* return a created spil location */
746 sym = createStackSpil (leastUsedLR (selectS));
747 sym->usl.spillLoc->allocreq++;
751 /* this is an extreme situation we will spill
752 this one : happens very rarely but it does happen */
757 /*-----------------------------------------------------------------*/
758 /* spilSomething - spil some variable & mark registers as free */
759 /*-----------------------------------------------------------------*/
761 spilSomething (iCode * ic, eBBlock * ebp, symbol * forSym)
766 /* get something we can spil */
767 ssym = selectSpil (ic, ebp, forSym);
769 /* mark it as spilt */
770 ssym->isspilt = ssym->spillA = 1;
771 _G.spiltSet = bitVectSetBit (_G.spiltSet, ssym->key);
773 /* mark it as not register assigned &
774 take it away from the set */
775 bitVectUnSetBit (_G.regAssigned, ssym->key);
776 bitVectUnSetBit (_G.totRegAssigned, ssym->key);
778 /* mark the registers as free */
779 for (i = 0; i < ssym->nRegs; i++)
781 freeReg (ssym->regs[i]);
783 /* if spilt on stack then free up r0 & r1
784 if they could have been assigned to as gprs */
785 if (!mcs51_ptrRegReq && isSpiltOnStack (ssym))
787 spillLRWithPtrReg (ssym);
791 /* if this was a block level spil then insert push & pop
792 at the start & end of block respectively */
795 iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
796 /* add push to the start of the block */
797 addiCodeToeBBlock (ebp, nic, (ebp->sch->op == LABEL ?
798 ebp->sch->next : ebp->sch));
799 nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
800 /* add pop to the end of the block */
801 addiCodeToeBBlock (ebp, nic, NULL);
804 /* if spilt because not used in the remainder of the
805 block then add a push before this instruction and
806 a pop at the end of the block */
807 if (ssym->remainSpil)
809 iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
810 /* add push just before this instruction */
811 addiCodeToeBBlock (ebp, nic, ic);
813 nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
814 /* add pop to the end of the block */
815 addiCodeToeBBlock (ebp, nic, NULL);
824 /*-----------------------------------------------------------------*/
825 /* getRegPtr - will try for PTR if not a GPR type if not spil */
826 /*-----------------------------------------------------------------*/
828 getRegPtr (iCode * ic, eBBlock * ebp, symbol * sym)
834 /* try for a ptr type */
835 if ((reg = allocReg (REG_PTR)))
838 /* try for gpr type */
839 if ((reg = allocReg (REG_GPR)))
842 /* we have to spil */
843 if (!spilSomething (ic, ebp, sym))
846 /* make sure partially assigned registers aren't reused */
847 for (j=0; j<=sym->nRegs; j++)
849 sym->regs[j]->isFree = 0;
851 /* this looks like an infinite loop but
852 in really selectSpil will abort */
856 /*-----------------------------------------------------------------*/
857 /* getRegGpr - will try for GPR if not spil */
858 /*-----------------------------------------------------------------*/
860 getRegGpr (iCode * ic, eBBlock * ebp, symbol * sym)
866 /* try for gpr type */
867 if ((reg = allocReg (REG_GPR)))
870 if (!mcs51_ptrRegReq)
871 if ((reg = allocReg (REG_PTR)))
874 /* we have to spil */
875 if (!spilSomething (ic, ebp, sym))
878 /* make sure partially assigned registers aren't reused */
879 for (j=0; j<=sym->nRegs; j++)
881 sym->regs[j]->isFree = 0;
883 /* this looks like an infinite loop but
884 in really selectSpil will abort */
888 /*-----------------------------------------------------------------*/
889 /* getRegBit - will try for Bit if not spill this */
890 /*-----------------------------------------------------------------*/
891 static regs *getRegBit (symbol * sym)
895 /* try for a bit type */
896 if ((reg = allocReg (REG_BIT)))
903 /*-----------------------------------------------------------------*/
904 /* getRegPtrNoSpil - get it cannot be spilt */
905 /*-----------------------------------------------------------------*/
906 static regs *getRegPtrNoSpil()
910 /* try for a ptr type */
911 if ((reg = allocReg (REG_PTR)))
914 /* try for gpr type */
915 if ((reg = allocReg (REG_GPR)))
920 /* just to make the compiler happy */
924 /*-----------------------------------------------------------------*/
925 /* getRegGprNoSpil - get it cannot be spilt */
926 /*-----------------------------------------------------------------*/
927 static regs *getRegGprNoSpil()
930 if ((reg = allocReg (REG_GPR)))
933 if (!mcs51_ptrRegReq)
934 if ((reg = allocReg (REG_PTR)))
939 /* just to make the compiler happy */
943 /*-----------------------------------------------------------------*/
944 /* getRegBitNoSpil - get it cannot be spilt */
945 /*-----------------------------------------------------------------*/
946 static regs *getRegBitNoSpil()
950 /* try for a ptr type */
951 if ((reg = allocReg (REG_BIT)))
954 /* try for gpr type */
955 if ((reg = allocReg (REG_GPR)))
960 /* just to make the compiler happy */
964 /*-----------------------------------------------------------------*/
965 /* symHasReg - symbol has a given register */
966 /*-----------------------------------------------------------------*/
968 symHasReg (symbol * sym, regs * reg)
972 for (i = 0; i < sym->nRegs; i++)
973 if (sym->regs[i] == reg)
979 /*-----------------------------------------------------------------*/
980 /* updateRegUsage - update the registers in use at the start of */
982 /*-----------------------------------------------------------------*/
984 updateRegUsage (iCode * ic)
988 for (reg=0; reg<mcs51_nRegs; reg++)
990 if (regs8051[reg].isFree)
992 ic->riu &= ~(1<<regs8051[reg].offset);
996 ic->riu |= (1<<regs8051[reg].offset);
997 BitBankUsed |= (reg >= 8);
1002 /*-----------------------------------------------------------------*/
1003 /* deassignLRs - check the live to and if they have registers & are */
1004 /* not spilt then free up the registers */
1005 /*-----------------------------------------------------------------*/
1007 deassignLRs (iCode * ic, eBBlock * ebp)
1013 for (sym = hTabFirstItem (liveRanges, &k); sym;
1014 sym = hTabNextItem (liveRanges, &k))
1016 symbol *psym = NULL;
1017 /* if it does not end here */
1018 if (sym->liveTo > ic->seq)
1021 /* if it was spilt on stack then we can
1022 mark the stack spil location as free */
1027 sym->usl.spillLoc->isFree = 1;
1033 if (!bitVectBitValue (_G.regAssigned, sym->key))
1036 /* special case check if this is an IFX &
1037 the privious one was a pop and the
1038 previous one was not spilt then keep track
1040 if (ic->op == IFX && ic->prev &&
1041 ic->prev->op == IPOP &&
1042 !ic->prev->parmPush &&
1043 !OP_SYMBOL (IC_LEFT (ic->prev))->isspilt)
1044 psym = OP_SYMBOL (IC_LEFT (ic->prev));
1050 bitVectUnSetBit (_G.regAssigned, sym->key);
1052 /* if the result of this one needs registers
1053 and does not have it then assign it right
1055 if (IC_RESULT (ic) &&
1056 !(SKIP_IC2 (ic) || /* not a special icode */
1057 ic->op == JUMPTABLE ||
1062 POINTER_SET (ic)) &&
1063 (result = OP_SYMBOL (IC_RESULT (ic))) && /* has a result */
1064 result->liveTo > ic->seq && /* and will live beyond this */
1065 result->liveTo <= ebp->lSeq && /* does not go beyond this block */
1066 result->liveFrom == ic->seq && /* does not start before here */
1067 result->regType == sym->regType && /* same register types */
1068 result->nRegs && /* which needs registers */
1069 !result->isspilt && /* and does not already have them */
1071 !bitVectBitValue (_G.regAssigned, result->key) &&
1072 /* the number of free regs + number of regs in this LR
1073 can accomodate the what result Needs */
1074 ((nfreeRegsType (result->regType) +
1075 sym->nRegs) >= result->nRegs)
1078 for (i = 0; i < result->nRegs; i++)
1080 result->regs[i] = sym->regs[i];
1082 result->regs[i] = getRegGpr (ic, ebp, result);
1084 _G.regAssigned = bitVectSetBit (_G.regAssigned, result->key);
1085 _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, result->key);
1089 /* free the remaining */
1090 for (; i < sym->nRegs; i++)
1094 if (!symHasReg (psym, sym->regs[i]))
1095 freeReg (sym->regs[i]);
1098 freeReg (sym->regs[i]);
1105 /*-----------------------------------------------------------------*/
1106 /* reassignLR - reassign this to registers */
1107 /*-----------------------------------------------------------------*/
1109 reassignLR (operand * op)
1111 symbol *sym = OP_SYMBOL (op);
1114 /* not spilt any more */
1115 sym->isspilt = sym->spillA = sym->blockSpil = sym->remainSpil = 0;
1116 bitVectUnSetBit (_G.spiltSet, sym->key);
1118 _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
1119 _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, sym->key);
1123 for (i = 0; i < sym->nRegs; i++)
1124 sym->regs[i]->isFree = 0;
1127 /*-----------------------------------------------------------------*/
1128 /* willCauseSpill - determines if allocating will cause a spill */
1129 /*-----------------------------------------------------------------*/
1131 willCauseSpill (int nr, int rt)
1133 /* first check if there are any available registers
1134 of the type required */
1137 /* special case for pointer type
1138 if pointer type not avlb then
1139 check for type gpr */
1140 if (nFreeRegs (rt) >= nr)
1142 if (nFreeRegs (REG_GPR) >= nr)
1145 else if (rt == REG_BIT)
1147 if (nFreeRegs (rt) >= nr)
1152 if (mcs51_ptrRegReq)
1154 if (nFreeRegs (rt) >= nr)
1159 if (nFreeRegs (REG_PTR) +
1160 nFreeRegs (REG_GPR) >= nr)
1165 /* it will cause a spil */
1169 /*-----------------------------------------------------------------*/
1170 /* positionRegs - the allocator can allocate same registers to res- */
1171 /* ult and operand, if this happens make sure they are in the same */
1172 /* position as the operand otherwise chaos results */
1173 /*-----------------------------------------------------------------*/
1175 positionRegs (symbol * result, symbol * opsym)
1177 int count = min (result->nRegs, opsym->nRegs);
1178 int i, j = 0, shared = 0;
1181 /* if the result has been spilt then cannot share */
1186 /* first make sure that they actually share */
1187 for (i = 0; i < count; i++)
1189 for (j = 0; j < count; j++)
1191 if (result->regs[i] == opsym->regs[j] && i != j)
1201 regs *tmp = result->regs[i];
1202 result->regs[i] = result->regs[j];
1203 result->regs[j] = tmp;
1210 /*------------------------------------------------------------------*/
1211 /* verifyRegsAssigned - make sure an iTemp is properly initialized; */
1212 /* it should either have registers or have beed spilled. Otherwise, */
1213 /* there was an uninitialized variable, so just spill this to get */
1214 /* the operand in a valid state. */
1215 /*------------------------------------------------------------------*/
1217 verifyRegsAssigned (operand *op, iCode * ic)
1222 if (!IS_ITEMP (op)) return;
1224 sym = OP_SYMBOL (op);
1225 if (sym->isspilt) return;
1226 if (!sym->nRegs) return;
1227 if (sym->regs[0]) return;
1229 werrorfl (ic->filename, ic->lineno, W_LOCAL_NOINIT,
1230 sym->prereqv ? sym->prereqv->name : sym->name);
1235 /*-----------------------------------------------------------------*/
1236 /* serialRegAssign - serially allocate registers to the variables */
1237 /*-----------------------------------------------------------------*/
1239 serialRegAssign (eBBlock ** ebbs, int count)
1243 /* for all blocks */
1244 for (i = 0; i < count; i++)
1248 if (ebbs[i]->noPath &&
1249 (ebbs[i]->entryLabel != entryLabel &&
1250 ebbs[i]->entryLabel != returnLabel))
1253 /* for all instructions do */
1254 for (ic = ebbs[i]->sch; ic; ic = ic->next)
1258 /* if this is an ipop that means some live
1259 range will have to be assigned again */
1261 reassignLR (IC_LEFT (ic));
1263 /* if result is present && is a true symbol */
1264 if (IC_RESULT (ic) && ic->op != IFX &&
1265 IS_TRUE_SYMOP (IC_RESULT (ic)))
1267 OP_SYMBOL (IC_RESULT (ic))->allocreq++;
1270 /* take away registers from live
1271 ranges that end at this instruction */
1272 deassignLRs (ic, ebbs[i]);
1274 /* some don't need registers */
1275 if (SKIP_IC2 (ic) ||
1276 ic->op == JUMPTABLE ||
1280 (IC_RESULT (ic) && POINTER_SET (ic)))
1285 /* now we need to allocate registers
1286 only for the result */
1289 symbol *sym = OP_SYMBOL (IC_RESULT (ic));
1295 /* Make sure any spill location is definitely allocated */
1296 if (sym->isspilt && !sym->remat && sym->usl.spillLoc &&
1297 !sym->usl.spillLoc->allocreq)
1299 sym->usl.spillLoc->allocreq++;
1302 /* if it does not need or is spilt
1303 or is already assigned to registers
1304 or will not live beyond this instructions */
1307 bitVectBitValue (_G.regAssigned, sym->key) ||
1308 sym->liveTo <= ic->seq)
1313 /* do not try to spil bit registers as it won't work */
1314 if (sym->regType != REG_BIT)
1316 /* if some liverange has been spilt at the block level
1317 and this one live beyond this block then spil this
1319 if (_G.blockSpil && sym->liveTo > ebbs[i]->lSeq)
1325 willCS = willCauseSpill (sym->nRegs, sym->regType);
1326 /* if this is a bit variable then don't use precious registers
1327 along with expensive bit-to-char conversions but just spill
1329 if (willCS && SPEC_NOUN(sym->etype) == V_BIT)
1335 /* if trying to allocate this will cause
1336 a spill and there is nothing to spill
1337 or this one is rematerializable then
1339 spillable = computeSpillable (ic);
1340 if (sym->remat || (willCS && bitVectIsZero (spillable)))
1346 /* If the live range preceeds the point of definition
1347 then ideally we must take into account registers that
1348 have been allocated after sym->liveFrom but freed
1349 before ic->seq. This is complicated, so spill this
1350 symbol instead and let fillGaps handle the allocation. */
1351 if (sym->liveFrom < ic->seq)
1357 /* if it has a spillocation & is used less than
1358 all other live ranges then spill this */
1361 if (sym->usl.spillLoc)
1363 symbol *leastUsed = leastUsedLR (liveRangesWith (spillable,
1364 allLRs, ebbs[i], ic));
1365 if (leastUsed && leastUsed->used > sym->used)
1373 /* if none of the liveRanges have a spillLocation then better
1374 to spill this one than anything else already assigned to registers */
1375 if (liveRangesWith(spillable,noSpilLoc,ebbs[i],ic))
1377 /* if this is local to this block then we might find a block spil */
1378 if (!(sym->liveFrom >= ebbs[i]->fSeq && sym->liveTo <= ebbs[i]->lSeq))
1387 /* if we need ptr regs for the right side
1389 if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic))
1390 && getSize (OP_SYMBOL (IC_LEFT (ic))->type) <= (unsigned int) PTRSIZE)
1395 if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic))
1396 && SPEC_OCLS(OP_SYMBOL (IC_LEFT (ic))->etype) == idata)
1401 if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic))
1402 && SPEC_OCLS(OP_SYMBOL (IC_RIGHT (ic))->etype) == idata)
1408 /* else we assign registers to it */
1409 _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
1410 _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, sym->key);
1412 for (j = 0; j < sym->nRegs; j++)
1414 sym->regs[j] = NULL;
1415 if (sym->regType == REG_PTR)
1416 sym->regs[j] = getRegPtr (ic, ebbs[i], sym);
1417 else if (sym->regType == REG_BIT)
1418 sym->regs[j] = getRegBit (sym);
1421 if (ic->op == CAST && IS_SYMOP (IC_RIGHT (ic)))
1423 symbol * right = OP_SYMBOL (IC_RIGHT (ic));
1425 if (right->regs[j] && (right->regType != REG_BIT))
1426 sym->regs[j] = allocThisReg (right->regs[j]);
1429 sym->regs[j] = getRegGpr (ic, ebbs[i], sym);
1432 /* if the allocation failed which means
1433 this was spilt then break */
1437 for (i=0; i < sym->nRegs ; i++ )
1438 sym->regs[i] = NULL;
1443 if (!POINTER_SET(ic) && !POINTER_GET(ic))
1445 /* if it shares registers with operands make sure
1446 that they are in the same position */
1447 if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)) &&
1448 OP_SYMBOL (IC_LEFT (ic))->nRegs)
1450 positionRegs (OP_SYMBOL (IC_RESULT (ic)),
1451 OP_SYMBOL (IC_LEFT (ic)));
1453 /* do the same for the right operand */
1454 if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)) &&
1455 OP_SYMBOL (IC_RIGHT (ic))->nRegs)
1457 positionRegs (OP_SYMBOL (IC_RESULT (ic)),
1458 OP_SYMBOL (IC_RIGHT (ic)));
1471 /* Check for and fix any problems with uninitialized operands */
1472 for (i = 0; i < count; i++)
1476 if (ebbs[i]->noPath &&
1477 (ebbs[i]->entryLabel != entryLabel &&
1478 ebbs[i]->entryLabel != returnLabel))
1483 for (ic = ebbs[i]->sch; ic; ic = ic->next)
1490 verifyRegsAssigned (IC_COND (ic), ic);
1494 if (ic->op == JUMPTABLE)
1496 verifyRegsAssigned (IC_JTCOND (ic), ic);
1500 verifyRegsAssigned (IC_RESULT (ic), ic);
1501 verifyRegsAssigned (IC_LEFT (ic), ic);
1502 verifyRegsAssigned (IC_RIGHT (ic), ic);
1507 /*-----------------------------------------------------------------*/
1508 /* fillGaps - Try to fill in the Gaps left by Pass1 */
1509 /*-----------------------------------------------------------------*/
1510 static void fillGaps()
1517 if (getenv("DISABLE_FILL_GAPS"))
1520 /* look for liveranges that were spilt by the allocator */
1521 for (sym = hTabFirstItem(liveRanges, &key) ; sym ;
1522 sym = hTabNextItem(liveRanges, &key))
1527 if (!sym->spillA || !sym->clashes || sym->remat)
1530 /* if spilt in direct space the original rname is lost */
1531 if (sym->usl.spillLoc && (IN_DIRSPACE (SPEC_OCLS (sym->usl.spillLoc->etype))))
1534 /* find the liveRanges this one clashes with, that are
1535 still assigned to registers & mark the registers as used*/
1536 for ( i = 0 ; i < sym->clashes->size ; i ++)
1541 if (bitVectBitValue(sym->clashes,i) == 0 || /* those that clash with this */
1542 bitVectBitValue(_G.totRegAssigned,i) == 0) /* and are still assigned to registers */
1545 clr = hTabItemWithKey(liveRanges, i);
1548 /* mark these registers as used */
1549 for (k = 0 ; k < clr->nRegs ; k++ )
1550 useReg(clr->regs[k]);
1553 if (willCauseSpill(sym->nRegs, sym->regType))
1555 /* NOPE :( clear all registers & and continue */
1561 for (i = 0 ; i < sym->defs->size ; i++ )
1563 if (bitVectBitValue(sym->defs, i))
1565 if (!(ic = hTabItemWithKey(iCodehTab, i)))
1572 D(printf("Attempting fillGaps on %s: [", sym->name));
1573 /* THERE IS HOPE !!!! */
1574 for (i=0; i < sym->nRegs ; i++ )
1576 if (sym->regType == REG_PTR)
1577 sym->regs[i] = getRegPtrNoSpil ();
1578 else if (sym->regType == REG_BIT)
1579 sym->regs[i] = getRegBitNoSpil ();
1582 sym->regs[i] = NULL;
1583 if (ic && ic->op == CAST && IS_SYMOP (IC_RIGHT (ic)))
1585 symbol * right = OP_SYMBOL (IC_RIGHT (ic));
1588 sym->regs[i] = allocThisReg (right->regs[i]);
1591 sym->regs[i] = getRegGprNoSpil ();
1593 D(printf("%s ", sym->regs[i]->name));
1597 /* For all its definitions check if the registers
1598 allocated needs positioning NOTE: we can position
1599 only ONCE if more than One positioning required
1601 We may need to perform the checks twice; once to
1602 position the registers as needed, the second to
1603 verify any register repositioning is still
1607 for (pass=0; pass<2; pass++)
1609 D(printf(" checking definitions\n"));
1610 for (i = 0 ; i < sym->defs->size ; i++ )
1612 if (bitVectBitValue(sym->defs,i))
1614 if (!(ic = hTabItemWithKey(iCodehTab,i)))
1616 D(printf(" ic->seq = %d\n", ic->seq));
1619 assert(isSymbolEqual(sym,OP_SYMBOL(IC_RESULT(ic)))); /* just making sure */
1620 /* if left is assigned to registers */
1621 if (IS_SYMOP(IC_LEFT(ic)))
1623 D(printf(" left = "));
1624 D(printOperand(IC_LEFT(ic),NULL));
1626 if (IS_SYMOP(IC_LEFT(ic)) &&
1627 bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_LEFT(ic))->key))
1629 pdone += (positionRegs(sym,OP_SYMBOL(IC_LEFT(ic)))>0);
1631 if (IS_SYMOP(IC_RIGHT(ic)))
1633 D(printf(" right = "));
1634 D(printOperand(IC_RIGHT(ic),NULL));
1636 if (IS_SYMOP(IC_RIGHT(ic)) &&
1637 bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RIGHT(ic))->key))
1639 pdone += (positionRegs(sym,OP_SYMBOL(IC_RIGHT(ic)))>0);
1641 D(printf(" pdone = %d\n", pdone));
1646 D(printf(" checking uses\n"));
1647 for (i = 0 ; i < sym->uses->size ; i++ )
1649 if (bitVectBitValue(sym->uses,i))
1652 if (!(ic = hTabItemWithKey(iCodehTab, i)))
1654 D(printf(" ic->seq = %d\n", ic->seq));
1657 if (POINTER_SET(ic) || POINTER_GET(ic))
1660 /* if result is assigned to registers */
1661 if (IS_SYMOP (IC_RESULT (ic)))
1663 D(printf(" result = "));
1664 D(printOperand(IC_RESULT (ic), NULL));
1666 if (IS_SYMOP (IC_RESULT (ic)) &&
1667 bitVectBitValue(_G.totRegAssigned, OP_SYMBOL (IC_RESULT (ic))->key))
1669 pdone += (positionRegs(sym, OP_SYMBOL (IC_RESULT (ic)))>0);
1671 D(printf(" pdone = %d\n", pdone));
1677 break; /* second pass only if regs repositioned */
1681 D(printf(" sym->regs = ["));
1682 for (i=0; i < sym->nRegs ; i++ )
1683 D(printf("%s ", sym->regs[i]->name));
1685 /* had to position more than once GIVE UP */
1688 /* UNDO all the changes we made to try this */
1690 for (i=0; i < sym->nRegs ; i++ )
1692 sym->regs[i] = NULL;
1695 D(printf ("Fill Gap gave up due to positioning for %s in function %s\n",sym->name, currFunc ? currFunc->name : "UNKNOWN"));
1698 D(printf ("FILLED GAP for %s in function %s\n",sym->name, currFunc ? currFunc->name : "UNKNOWN"));
1700 _G.totRegAssigned = bitVectSetBit(_G.totRegAssigned,sym->key);
1701 sym->isspilt = sym->spillA = 0 ;
1702 sym->usl.spillLoc->allocreq--;
1707 /*-----------------------------------------------------------------*/
1708 /* findAllBitregs :- returns bit vector of all bit registers */
1709 /*-----------------------------------------------------------------*/
1711 findAllBitregs (void)
1713 bitVect *rmask = newBitVect (mcs51_nRegs);
1716 for (j = 0; j < mcs51_nRegs; j++)
1718 if (regs8051[j].type == REG_BIT)
1719 rmask = bitVectSetBit (rmask, regs8051[j].rIdx);
1725 /*-----------------------------------------------------------------*/
1726 /* mcs51_allBitregs :- returns bit vector of all bit registers */
1727 /*-----------------------------------------------------------------*/
1729 mcs51_allBitregs (void)
1731 return _G.allBitregs;
1734 /*-----------------------------------------------------------------*/
1735 /* rUmaskForOp :- returns register mask for an operand */
1736 /*-----------------------------------------------------------------*/
1738 mcs51_rUmaskForOp (operand * op)
1744 /* only temporaries are assigned registers */
1748 sym = OP_SYMBOL (op);
1750 /* if spilt or no registers assigned to it
1752 if (sym->isspilt || !sym->nRegs)
1755 rumask = newBitVect (mcs51_nRegs);
1757 for (j = 0; j < sym->nRegs; j++)
1759 if (sym->regs[j]) /* EEP - debug */
1760 rumask = bitVectSetBit (rumask, sym->regs[j]->rIdx);
1766 /*-----------------------------------------------------------------*/
1767 /* regsUsedIniCode :- returns bit vector of registers used in iCode */
1768 /*-----------------------------------------------------------------*/
1770 regsUsedIniCode (iCode * ic)
1772 bitVect *rmask = newBitVect (mcs51_nRegs);
1774 /* do the special cases first */
1777 rmask = bitVectUnion (rmask, mcs51_rUmaskForOp (IC_COND (ic)));
1781 /* for the jumptable */
1782 if (ic->op == JUMPTABLE)
1784 rmask = bitVectUnion (rmask, mcs51_rUmaskForOp (IC_JTCOND (ic)));
1788 /* of all other cases */
1790 rmask = bitVectUnion (rmask, mcs51_rUmaskForOp (IC_LEFT (ic)));
1793 rmask = bitVectUnion (rmask, mcs51_rUmaskForOp (IC_RIGHT (ic)));
1796 rmask = bitVectUnion (rmask, mcs51_rUmaskForOp (IC_RESULT (ic)));
1802 /*-----------------------------------------------------------------*/
1803 /* createRegMask - for each instruction will determine the regsUsed */
1804 /*-----------------------------------------------------------------*/
1806 createRegMask (eBBlock ** ebbs, int count)
1810 /* for all blocks */
1811 for (i = 0; i < count; i++)
1815 if (ebbs[i]->noPath &&
1816 (ebbs[i]->entryLabel != entryLabel &&
1817 ebbs[i]->entryLabel != returnLabel))
1820 /* for all instructions */
1821 for (ic = ebbs[i]->sch; ic; ic = ic->next)
1825 if (SKIP_IC2 (ic) || !ic->rlive)
1828 /* first mark the registers used in this
1830 ic->rUsed = regsUsedIniCode (ic);
1831 _G.funcrUsed = bitVectUnion (_G.funcrUsed, ic->rUsed);
1833 /* now create the register mask for those
1834 registers that are in use : this is a
1835 super set of ic->rUsed */
1836 ic->rMask = newBitVect (mcs51_nRegs + 1);
1838 /* for all live Ranges alive at this point */
1839 for (j = 1; j < ic->rlive->size; j++)
1844 /* if not alive then continue */
1845 if (!bitVectBitValue (ic->rlive, j))
1848 /* find the live range we are interested in */
1849 if (!(sym = hTabItemWithKey (liveRanges, j)))
1851 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
1852 "createRegMask cannot find live range");
1853 fprintf(stderr, "\tmissing live range: key=%d\n", j);
1857 /* if no register assigned to it */
1858 if (!sym->nRegs || sym->isspilt)
1861 /* for all the registers allocated to it */
1862 for (k = 0; k < sym->nRegs; k++)
1864 ic->rMask = bitVectSetBit (ic->rMask, sym->regs[k]->rIdx);
1870 /*-----------------------------------------------------------------*/
1871 /* rematStr - returns the rematerialized string for a remat var */
1872 /*-----------------------------------------------------------------*/
1874 rematStr (symbol * sym)
1876 iCode *ic = sym->rematiCode;
1881 /* if plus adjust offset to right hand side */
1884 offset += (int) operandLitValue (IC_RIGHT (ic));
1885 ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
1889 /* if minus adjust offset to right hand side */
1892 offset -= (int) operandLitValue (IC_RIGHT (ic));
1893 ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
1897 /* cast then continue */
1898 if (IS_CAST_ICODE(ic))
1900 ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
1903 /* we reached the end */
1909 SNPRINTF (buffer, sizeof(buffer),
1911 OP_SYMBOL (IC_LEFT (ic))->rname,
1912 offset >= 0 ? '+' : '-',
1913 abs (offset) & 0xffff);
1917 strncpyz (buffer, OP_SYMBOL (IC_LEFT (ic))->rname, sizeof(buffer));
1922 /*-----------------------------------------------------------------*/
1923 /* regTypeNum - computes the type & number of registers required */
1924 /*-----------------------------------------------------------------*/
1926 regTypeNum (eBBlock *ebbs)
1932 /* for each live range do */
1933 for (sym = hTabFirstItem (liveRanges, &k); sym;
1934 sym = hTabNextItem (liveRanges, &k))
1936 /* if used zero times then no registers needed */
1937 if ((sym->liveTo - sym->liveFrom) == 0)
1940 /* if the live range is a temporary */
1943 /* if the type is marked as a conditional */
1944 if (sym->regType == REG_CND)
1947 /* if used in return only then we don't
1949 if (sym->ruonly || sym->accuse)
1951 if (IS_AGGREGATE (sym->type) || sym->isptr)
1952 sym->type = aggrToPtr (sym->type, FALSE);
1953 else if (IS_BIT(sym->type))
1954 sym->regType = REG_CND;
1958 /* if the symbol has only one definition &
1959 that definition is a get_pointer */
1960 if (bitVectnBitsOn (sym->defs) == 1 &&
1961 (ic = hTabItemWithKey (iCodehTab, bitVectFirstBit (sym->defs))) &&
1963 !IS_BITVAR (sym->etype) &&
1964 (aggrToPtrDclType (operandType (IC_LEFT (ic)), FALSE) == POINTER))
1966 if (ptrPseudoSymSafe (sym, ic))
1968 ptrPseudoSymConvert (sym, ic, rematStr (OP_SYMBOL (IC_LEFT (ic))));
1972 /* if in data space or idata space then try to
1973 allocate pointer register */
1976 /* if not then we require registers */
1977 sym->nRegs = ((IS_AGGREGATE (sym->type) || sym->isptr) ?
1978 getSize (sym->type = aggrToPtr (sym->type, FALSE)) :
1979 getSize (sym->type));
1983 fprintf (stderr, "allocated more than 4 or 0 registers for type ");
1984 printTypeChain (sym->type, stderr);
1985 fprintf (stderr, "\n");
1988 /* determine the type of register required */
1989 if (sym->nRegs == 1 && IS_PTR (sym->type) && sym->uptr)
1990 sym->regType = REG_PTR;
1991 else if (IS_BIT(sym->type))
1992 sym->regType = REG_BIT;
1994 sym->regType = REG_GPR;
1997 /* for the first run we don't provide */
1998 /* registers for true symbols we will */
1999 /* see how things go */
2004 /*-----------------------------------------------------------------*/
2005 /* freeAllRegs - mark all registers as free */
2006 /*-----------------------------------------------------------------*/
2012 for (i = 0; i < mcs51_nRegs; i++)
2013 regs8051[i].isFree = 1;
2016 /*-----------------------------------------------------------------*/
2017 /* deallocStackSpil - this will set the stack pointer back */
2018 /*-----------------------------------------------------------------*/
2020 DEFSETFUNC (deallocStackSpil)
2028 /*-----------------------------------------------------------------*/
2029 /* farSpacePackable - returns the packable icode for far variables */
2030 /*-----------------------------------------------------------------*/
2032 farSpacePackable (iCode * ic)
2036 /* go thru till we find a definition for the
2037 symbol on the right */
2038 for (dic = ic->prev; dic; dic = dic->prev)
2040 /* if the definition is a call then no */
2041 if ((dic->op == CALL || dic->op == PCALL) &&
2042 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
2047 /* if shift by unknown amount then not */
2048 if ((dic->op == LEFT_OP || dic->op == RIGHT_OP) &&
2049 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
2052 /* if pointer get and size > 1 */
2053 if (POINTER_GET (dic) &&
2054 getSize (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)) > 1)
2057 if (POINTER_SET (dic) &&
2058 getSize (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)) > 1)
2063 if (IC_COND (dic) &&
2064 IS_TRUE_SYMOP (IC_COND (dic)) &&
2065 isOperandInFarSpace (IC_COND (dic)))
2068 else if (dic->op == JUMPTABLE)
2070 if (IC_JTCOND (dic) &&
2071 IS_TRUE_SYMOP (IC_JTCOND (dic)) &&
2072 isOperandInFarSpace (IC_JTCOND (dic)))
2077 /* if any tree is a true symbol in far space */
2078 if (IC_RESULT (dic) &&
2079 IS_TRUE_SYMOP (IC_RESULT (dic)) &&
2080 isOperandInFarSpace (IC_RESULT (dic)))
2083 if (IC_RIGHT (dic) &&
2084 IS_TRUE_SYMOP (IC_RIGHT (dic)) &&
2085 isOperandInFarSpace (IC_RIGHT (dic)) &&
2086 !isOperandEqual (IC_RIGHT (dic), IC_RESULT (ic)))
2089 if (IC_LEFT (dic) &&
2090 IS_TRUE_SYMOP (IC_LEFT (dic)) &&
2091 isOperandInFarSpace (IC_LEFT (dic)) &&
2092 !isOperandEqual (IC_LEFT (dic), IC_RESULT (ic)))
2096 if (isOperandEqual (IC_RIGHT (ic), IC_RESULT (dic)))
2098 if ((dic->op == LEFT_OP ||
2099 dic->op == RIGHT_OP ||
2101 IS_OP_LITERAL (IC_RIGHT (dic)))
2111 /*-----------------------------------------------------------------*/
2112 /* packRegsForAssign - register reduction for assignment */
2113 /*-----------------------------------------------------------------*/
2115 packRegsForAssign (iCode * ic, eBBlock * ebp)
2119 if (!IS_ITEMP (IC_RIGHT (ic)) ||
2120 OP_SYMBOL (IC_RIGHT (ic))->isind ||
2121 OP_LIVETO (IC_RIGHT (ic)) > ic->seq)
2126 /* if the true symbol is defined in far space or on stack
2127 then we should not since this will increase register pressure */
2128 if (isOperandInFarSpace(IC_RESULT(ic)) && !farSpacePackable(ic))
2133 /* find the definition of iTempNN scanning backwards if we find a
2134 a use of the true symbol in before we find the definition then
2136 for (dic = ic->prev; dic; dic = dic->prev)
2138 int crossedCall = 0;
2140 /* We can pack across a function call only if it's a local */
2141 /* variable or our parameter. Never pack global variables */
2142 /* or parameters to a function we call. */
2143 if ((dic->op == CALL || dic->op == PCALL))
2145 if (!OP_SYMBOL (IC_RESULT (ic))->ismyparm
2146 && !OP_SYMBOL (IC_RESULT (ic))->islocal)
2152 /* Don't move an assignment out of a critical block */
2153 if (dic->op == CRITICAL)
2164 if (IS_SYMOP (IC_COND (dic)) &&
2165 (IC_COND (dic)->key == IC_RESULT (ic)->key ||
2166 IC_COND (dic)->key == IC_RIGHT (ic)->key))
2174 if (IS_TRUE_SYMOP (IC_RESULT (dic)) &&
2175 IS_OP_VOLATILE (IC_RESULT (dic)))
2181 if (IS_SYMOP (IC_RESULT (dic)) &&
2182 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
2184 if (POINTER_SET (dic))
2190 if (IS_SYMOP (IC_RIGHT (dic)) &&
2191 (IC_RIGHT (dic)->key == IC_RESULT (ic)->key ||
2192 IC_RIGHT (dic)->key == IC_RIGHT (ic)->key))
2198 if (IS_SYMOP (IC_LEFT (dic)) &&
2199 (IC_LEFT (dic)->key == IC_RESULT (ic)->key ||
2200 IC_LEFT (dic)->key == IC_RIGHT (ic)->key))
2206 if (IS_SYMOP (IC_RESULT (dic)) &&
2207 IC_RESULT (dic)->key == IC_RESULT (ic)->key)
2222 return 0; /* did not find */
2224 /* if assignment then check that right is not a bit */
2225 if (ASSIGNMENT (ic) && !POINTER_SET (ic))
2227 sym_link *etype = operandType (IC_RESULT (dic));
2228 if (IS_BITFIELD (etype))
2230 /* if result is a bit too then it's ok */
2231 etype = operandType (IC_RESULT (ic));
2232 if (!IS_BITFIELD (etype))
2239 /* if the result is on stack or iaccess then it must be
2240 the same atleast one of the operands */
2241 if (OP_SYMBOL (IC_RESULT (ic))->onStack ||
2242 OP_SYMBOL (IC_RESULT (ic))->iaccess)
2244 /* the operation has only one symbol
2245 operator then we can pack */
2246 if ((IC_LEFT (dic) && !IS_SYMOP (IC_LEFT (dic))) ||
2247 (IC_RIGHT (dic) && !IS_SYMOP (IC_RIGHT (dic))))
2250 if (!((IC_LEFT (dic) &&
2251 IC_RESULT (ic)->key == IC_LEFT (dic)->key) ||
2253 IC_RESULT (ic)->key == IC_RIGHT (dic)->key)))
2257 /* found the definition */
2258 /* replace the result with the result of */
2259 /* this assignment and remove this assignment */
2260 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
2261 ReplaceOpWithCheaperOp(&IC_RESULT (dic), IC_RESULT (ic));
2263 if (IS_ITEMP (IC_RESULT (dic)) && OP_SYMBOL (IC_RESULT (dic))->liveFrom > dic->seq)
2265 OP_SYMBOL (IC_RESULT (dic))->liveFrom = dic->seq;
2267 // TODO: and the otherway around?
2269 /* delete from liverange table also
2270 delete from all the points inbetween and the new
2272 for (sic = dic; sic != ic; sic = sic->next)
2274 bitVectUnSetBit (sic->rlive, IC_RESULT (ic)->key);
2275 if (IS_ITEMP (IC_RESULT (dic)))
2276 bitVectSetBit (sic->rlive, IC_RESULT (dic)->key);
2279 remiCodeFromeBBlock (ebp, ic);
2280 bitVectUnSetBit(OP_DEFS (IC_RESULT (ic)), ic->key);
2281 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
2282 OP_DEFS(IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
2286 /*------------------------------------------------------------------*/
2287 /* findAssignToSym : scanning backwards looks for first assig found */
2288 /*------------------------------------------------------------------*/
2290 findAssignToSym (operand * op, iCode * ic)
2294 /* This routine is used to find sequences like
2296 ...; (intervening ops don't use iTempAA or modify FOO)
2297 blah = blah + iTempAA;
2299 and eliminate the use of iTempAA, freeing up its register for
2303 for (dic = ic->prev; dic; dic = dic->prev)
2305 /* if definition by assignment */
2306 if (dic->op == '=' &&
2307 !POINTER_SET (dic) &&
2308 IC_RESULT (dic)->key == op->key
2309 /* && IS_TRUE_SYMOP(IC_RIGHT(dic)) */
2311 break; /* found where this temp was defined */
2313 /* if we find an usage then we cannot delete it */
2317 if (IC_COND (dic) && IC_COND (dic)->key == op->key)
2320 else if (dic->op == JUMPTABLE)
2322 if (IC_JTCOND (dic) && IC_JTCOND (dic)->key == op->key)
2327 if (IC_LEFT (dic) && IC_LEFT (dic)->key == op->key)
2330 if (IC_RIGHT (dic) && IC_RIGHT (dic)->key == op->key)
2333 if (POINTER_SET (dic) && IC_RESULT (dic)->key == op->key)
2339 return NULL; /* didn't find any assignment to op */
2341 /* we are interested only if defined in far space */
2342 /* or in stack space in case of + & - */
2344 /* if assigned to a non-symbol then don't repack regs */
2345 if (!IS_SYMOP (IC_RIGHT (dic)))
2348 /* if the symbol is volatile then we should not */
2349 if (isOperandVolatile (IC_RIGHT (dic), TRUE))
2351 /* XXX TODO --- should we be passing FALSE to isOperandVolatile()?
2352 What does it mean for an iTemp to be volatile, anyway? Passing
2353 TRUE is more cautious but may prevent possible optimizations */
2355 /* if the symbol is in far space then we should not */
2356 if (isOperandInFarSpace (IC_RIGHT (dic)))
2359 /* for + & - operations make sure that
2360 if it is on the stack it is the same
2361 as one of the three operands */
2362 if ((ic->op == '+' || ic->op == '-') &&
2363 OP_SYMBOL (IC_RIGHT (dic))->onStack)
2365 if (IC_RESULT (ic)->key != IC_RIGHT (dic)->key &&
2366 IC_LEFT (ic)->key != IC_RIGHT (dic)->key &&
2367 IC_RIGHT (ic)->key != IC_RIGHT (dic)->key)
2371 /* now make sure that the right side of dic
2372 is not defined between ic & dic */
2375 iCode *sic = dic->next;
2377 for (; sic != ic; sic = sic->next)
2378 if (IC_RESULT (sic) &&
2379 IC_RESULT (sic)->key == IC_RIGHT (dic)->key)
2386 /*-----------------------------------------------------------------*/
2387 /* reassignAliasedSym - used by packRegsForSupport to replace */
2388 /* redundant iTemp with equivalent symbol */
2389 /*-----------------------------------------------------------------*/
2391 reassignAliasedSym (eBBlock *ebp, iCode *assignment, iCode *use, operand *op)
2394 unsigned oldSymKey, newSymKey;
2396 oldSymKey = op->key;
2397 newSymKey = IC_RIGHT(assignment)->key;
2399 /* only track live ranges of compiler-generated temporaries */
2400 if (!IS_ITEMP(IC_RIGHT(assignment)))
2403 /* update the live-value bitmaps */
2404 for (ic = assignment; ic != use; ic = ic->next) {
2405 bitVectUnSetBit (ic->rlive, oldSymKey);
2407 ic->rlive = bitVectSetBit (ic->rlive, newSymKey);
2410 /* update the sym of the used operand */
2411 OP_SYMBOL(op) = OP_SYMBOL(IC_RIGHT(assignment));
2412 op->key = OP_SYMBOL(op)->key;
2413 OP_SYMBOL(op)->accuse = 0;
2415 /* update the sym's liverange */
2416 if ( OP_LIVETO(op) < ic->seq )
2417 setToRange(op, ic->seq, FALSE);
2419 /* remove the assignment iCode now that its result is unused */
2420 remiCodeFromeBBlock (ebp, assignment);
2421 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(assignment))->defs, assignment->key);
2422 hTabDeleteItem (&iCodehTab, assignment->key, assignment, DELETE_ITEM, NULL);
2426 /*-----------------------------------------------------------------*/
2427 /* packRegsForSupport :- reduce some registers for support calls */
2428 /*-----------------------------------------------------------------*/
2430 packRegsForSupport (iCode * ic, eBBlock * ebp)
2434 /* for the left & right operand :- look to see if the
2435 left was assigned a true symbol in far space in that
2436 case replace them */
2438 if (IS_ITEMP (IC_LEFT (ic)) &&
2439 OP_SYMBOL (IC_LEFT (ic))->liveTo <= ic->seq)
2441 dic = findAssignToSym (IC_LEFT (ic), ic);
2445 /* found it we need to remove it from the block */
2446 reassignAliasedSym (ebp, dic, ic, IC_LEFT(ic));
2451 /* do the same for the right operand */
2452 if (IS_ITEMP (IC_RIGHT (ic)) &&
2453 OP_SYMBOL (IC_RIGHT (ic))->liveTo <= ic->seq)
2455 iCode *dic = findAssignToSym (IC_RIGHT (ic), ic);
2459 /* if this is a subtraction & the result
2460 is a true symbol in far space then don't pack */
2461 if (ic->op == '-' && IS_TRUE_SYMOP (IC_RESULT (dic)))
2463 sym_link *etype = getSpec (operandType (IC_RESULT (dic)));
2464 if (IN_FARSPACE (SPEC_OCLS (etype)))
2467 /* found it we need to remove it from the
2469 reassignAliasedSym (ebp, dic, ic, IC_RIGHT(ic));
2479 /*-----------------------------------------------------------------*/
2480 /* packRegsForOneuse : - will reduce some registers for single Use */
2481 /*-----------------------------------------------------------------*/
2483 packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
2487 /* if returning a literal then do nothing */
2491 /* if rematerializable or already return use then do nothing */
2492 if (OP_SYMBOL(op)->remat || OP_SYMBOL(op)->ruonly)
2495 /* only upto 2 bytes since we cannot predict
2496 the usage of b, & acc */
2497 if (getSize (operandType (op)) > (fReturnSizeMCS51 - 2))
2500 if (ic->op != RETURN &&
2502 !POINTER_SET (ic) &&
2506 if (ic->op == SEND && ic->argreg != 1) return NULL;
2508 /* this routine will mark the symbol as used in one
2509 instruction use only && if the definition is local
2510 (ie. within the basic block) && has only one definition &&
2511 that definition is either a return value from a
2512 function or does not contain any variables in
2514 if (bitVectnBitsOn (OP_USES (op)) > 1)
2517 /* if it has only one definition */
2518 if (bitVectnBitsOn (OP_DEFS (op)) > 1)
2519 return NULL; /* has more than one definition */
2521 /* get that definition */
2522 if (!(dic = hTabItemWithKey (iCodehTab, bitVectFirstBit (OP_DEFS (op)))))
2525 /* if that only usage is a cast */
2526 if (dic->op == CAST)
2528 /* to a bigger type */
2529 if (getSize(OP_SYM_TYPE(IC_RESULT(dic))) >
2530 getSize(OP_SYM_TYPE(IC_RIGHT(dic))))
2532 /* then we can not, since we cannot predict the usage of b & acc */
2537 /* found the definition now check if it is local */
2538 if (dic->seq < ebp->fSeq ||
2539 dic->seq > ebp->lSeq)
2540 return NULL; /* non-local */
2542 /* now check if it is the return from
2544 if (dic->op == CALL || dic->op == PCALL)
2546 if (ic->op != SEND && ic->op != RETURN &&
2547 !POINTER_SET(ic) && !POINTER_GET(ic))
2549 OP_SYMBOL (op)->ruonly = 1;
2555 /* otherwise check that the definition does
2556 not contain any symbols in far space */
2557 if (isOperandInFarSpace (IC_LEFT (dic)) ||
2558 isOperandInFarSpace (IC_RIGHT (dic)) ||
2559 IS_OP_RUONLY (IC_LEFT (ic)) ||
2560 IS_OP_RUONLY (IC_RIGHT (ic)))
2565 /* if pointer set then make sure the pointer
2567 if (POINTER_SET (dic) &&
2568 !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)))
2571 if (POINTER_GET (dic) &&
2572 !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)))
2576 /* Make sure no overlapping liverange is already assigned to DPTR */
2577 if (OP_SYMBOL(op)->clashes)
2582 for (i = 0 ; i < OP_SYMBOL(op)->clashes->size ; i++ )
2584 if (bitVectBitValue(OP_SYMBOL(op)->clashes,i))
2586 sym = hTabItemWithKey(liveRanges,i);
2595 /* also make sure the intervening instructions
2596 don't have anything in far space */
2597 for (dic = dic->next; dic && dic != ic && sic != ic; dic = dic->next)
2599 /* if there is an intervening function call then no */
2600 if (dic->op == CALL || dic->op == PCALL)
2602 /* if pointer set then make sure the pointer
2604 if (POINTER_SET (dic) &&
2605 !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)))
2608 if (POINTER_GET (dic) &&
2609 !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)))
2612 /* if address of & the result is remat the okay */
2613 if (dic->op == ADDRESS_OF &&
2614 OP_SYMBOL (IC_RESULT (dic))->remat)
2617 /* if operand has size of three or more & this
2618 operation is a '*','/' or '%' then 'b' may
2620 if ((dic->op == '%' || dic->op == '/' || dic->op == '*') &&
2621 getSize (operandType (op)) >= 3)
2624 /* if left or right or result is in far space */
2625 if (isOperandInFarSpace (IC_LEFT (dic)) ||
2626 isOperandInFarSpace (IC_RIGHT (dic)) ||
2627 isOperandInFarSpace (IC_RESULT (dic)) ||
2628 IS_OP_RUONLY (IC_LEFT (dic)) ||
2629 IS_OP_RUONLY (IC_RIGHT (dic)) ||
2630 IS_OP_RUONLY (IC_RESULT (dic)))
2634 /* if left or right or result is on stack */
2635 if (isOperandOnStack(IC_LEFT(dic)) ||
2636 isOperandOnStack(IC_RIGHT(dic)) ||
2637 isOperandOnStack(IC_RESULT(dic)))
2643 OP_SYMBOL (op)->ruonly = 1;
2647 /*-----------------------------------------------------------------*/
2648 /* isBitwiseOptimizable - requirements of JEAN LOUIS VERN */
2649 /*-----------------------------------------------------------------*/
2651 isBitwiseOptimizable (iCode * ic)
2653 sym_link *ltype = getSpec (operandType (IC_LEFT (ic)));
2654 sym_link *rtype = getSpec (operandType (IC_RIGHT (ic)));
2656 /* bitwise operations are considered optimizable
2657 under the following conditions (Jean-Louis VERN)
2669 if (IS_LITERAL(rtype) ||
2670 (IS_BITVAR (ltype) && IN_BITSPACE (SPEC_OCLS (ltype))))
2676 /*-----------------------------------------------------------------*/
2677 /* isCommutativeOp - tests whether this op cares what order its */
2678 /* operands are in */
2679 /*-----------------------------------------------------------------*/
2680 bool isCommutativeOp(unsigned int op)
2682 if (op == '+' || op == '*' || op == EQ_OP ||
2683 op == '^' || op == '|' || op == BITWISEAND)
2689 /*-----------------------------------------------------------------*/
2690 /* operandUsesAcc - determines whether the code generated for this */
2691 /* operand will have to use the accumulator */
2692 /*-----------------------------------------------------------------*/
2693 bool operandUsesAcc(operand *op, bool allowBitspace)
2699 symbol *sym = OP_SYMBOL(op);
2703 return TRUE; /* duh! */
2705 if (IN_STACK(sym->etype) || sym->onStack ||
2706 (SPIL_LOC(op) && SPIL_LOC(op)->onStack))
2707 return TRUE; /* acc is used to calc stack offset */
2712 sym = SPIL_LOC(op); /* if spilled, look at spill location */
2714 return FALSE; /* more checks? */
2718 symspace = SPEC_OCLS(sym->etype);
2720 if (sym->iaccess && symspace->paged)
2721 return TRUE; /* must fetch paged indirect sym via accumulator */
2723 if (!allowBitspace && IN_BITSPACE(symspace))
2724 return TRUE; /* fetching bit vars uses the accumulator */
2726 if (IN_FARSPACE(symspace) || IN_CODESPACE(symspace))
2727 return TRUE; /* fetched via accumulator and dptr */
2733 /*-----------------------------------------------------------------*/
2734 /* packRegsForAccUse - pack registers for acc use */
2735 /*-----------------------------------------------------------------*/
2737 packRegsForAccUse (iCode * ic)
2741 /* if this is an aggregate, e.g. a one byte char array */
2742 if (IS_AGGREGATE(operandType(IC_RESULT(ic))))
2745 /* if we are calling a reentrant function that has stack parameters */
2746 if (ic->op == CALL &&
2747 IFFUNC_ISREENT(operandType(IC_LEFT(ic))) &&
2748 FUNC_HASSTACKPARM(operandType(IC_LEFT(ic))))
2751 if (ic->op == PCALL &&
2752 IFFUNC_ISREENT(operandType(IC_LEFT(ic))->next) &&
2753 FUNC_HASSTACKPARM(operandType(IC_LEFT(ic))->next))
2756 /* if + or - then it has to be one byte result */
2757 if ((ic->op == '+' || ic->op == '-')
2758 && getSize (operandType (IC_RESULT (ic))) > 1)
2761 /* if shift operation make sure right side is not a literal */
2762 if (ic->op == RIGHT_OP &&
2763 (isOperandLiteral (IC_RIGHT (ic)) ||
2764 getSize (operandType (IC_RESULT (ic))) > 1))
2767 if (ic->op == LEFT_OP &&
2768 (isOperandLiteral (IC_RIGHT (ic)) ||
2769 getSize (operandType (IC_RESULT (ic))) > 1))
2772 if (IS_BITWISE_OP (ic) &&
2773 getSize (operandType (IC_RESULT (ic))) > 1)
2776 /* has only one definition */
2777 if (bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) > 1)
2780 /* has only one use */
2781 if (bitVectnBitsOn (OP_USES (IC_RESULT (ic))) > 1)
2784 /* and the usage immediately follows this iCode */
2785 if (!(uic = hTabItemWithKey (iCodehTab,
2786 bitVectFirstBit (OP_USES (IC_RESULT (ic))))))
2789 if (ic->next != uic)
2792 /* if it is a conditional branch then we definitely can */
2796 if (uic->op == JUMPTABLE)
2799 if (POINTER_SET (uic) &&
2800 getSize (aggrToPtr (operandType (IC_RESULT (uic)), FALSE)) > 1)
2803 /* if the usage is not an assignment
2804 or an arithmetic / bitwise / shift operation then not */
2805 if (uic->op != '=' &&
2806 !IS_ARITHMETIC_OP (uic) &&
2807 !IS_BITWISE_OP (uic) &&
2808 uic->op != LEFT_OP &&
2809 uic->op != RIGHT_OP)
2812 /* if used in ^ operation then make sure right is not a
2813 literal (WIML: Why is this?) */
2814 if (uic->op == '^' && isOperandLiteral (IC_RIGHT (uic)))
2817 /* if shift operation make sure right side is not a literal */
2818 /* WIML: Why is this? */
2819 if (uic->op == RIGHT_OP &&
2820 (isOperandLiteral (IC_RIGHT (uic)) ||
2821 getSize (operandType (IC_RESULT (uic))) > 1))
2823 if (uic->op == LEFT_OP &&
2824 (isOperandLiteral (IC_RIGHT (uic)) ||
2825 getSize (operandType (IC_RESULT (uic))) > 1))
2828 /* make sure that the result of this icode is not on the
2829 stack, since acc is used to compute stack offset */
2831 if (IS_TRUE_SYMOP (IC_RESULT (uic)) &&
2832 OP_SYMBOL (IC_RESULT (uic))->onStack)
2835 if (isOperandOnStack(IC_RESULT(uic)))
2839 /* if the usage has only one operand then we can */
2840 if (IC_LEFT (uic) == NULL ||
2841 IC_RIGHT (uic) == NULL)
2844 /* if the other operand uses the accumulator then we cannot */
2845 if ( (IC_LEFT (uic)->key == IC_RESULT (ic)->key &&
2846 operandUsesAcc (IC_RIGHT (uic), IS_BIT (operandType (IC_LEFT (uic))))) ||
2847 (IC_RIGHT(uic)->key == IC_RESULT(ic)->key &&
2848 operandUsesAcc (IC_LEFT (uic), IS_BIT (operandType (IC_RIGHT (uic))))) )
2851 /* make sure this is on the left side if not commutative */
2852 /* except for '-', which has been written to be able to
2853 handle reversed operands */
2854 if (!(isCommutativeOp(ic->op) || ic->op == '-') &&
2855 IC_LEFT (uic)->key != IC_RESULT (ic)->key)
2859 // this is too dangerous and need further restrictions
2862 /* if one of them is a literal then we can */
2863 if ((IC_LEFT (uic) && IS_OP_LITERAL (IC_LEFT (uic))) ||
2864 (IC_RIGHT (uic) && IS_OP_LITERAL (IC_RIGHT (uic))))
2866 OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
2872 OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
2876 /*-----------------------------------------------------------------*/
2877 /* packForPush - heuristics to reduce iCode for pushing */
2878 /*-----------------------------------------------------------------*/
2880 packForPush (iCode * ic, eBBlock ** ebpp, int blockno)
2884 struct eBBlock * ebp=ebpp[blockno];
2886 if (ic->op != IPUSH || !IS_ITEMP (IC_LEFT (ic)))
2889 /* must have only definition & one usage */
2890 if (bitVectnBitsOn (OP_DEFS (IC_LEFT (ic))) != 1 ||
2891 bitVectnBitsOn (OP_USES (IC_LEFT (ic))) != 1)
2894 /* find the definition */
2895 if (!(dic = hTabItemWithKey (iCodehTab,
2896 bitVectFirstBit (OP_DEFS (IC_LEFT (ic))))))
2899 if (dic->op != '=' || POINTER_SET (dic))
2902 if (dic->seq < ebp->fSeq) // Evelyn did this
2905 for (i=0; i<blockno; i++)
2907 if (dic->seq >= ebpp[i]->fSeq && dic->seq <= ebpp[i]->lSeq)
2913 wassert (i!=blockno); // no way to recover from here
2916 if (IS_SYMOP(IC_RIGHT(dic)))
2918 /* make sure the right side does not have any definitions
2920 dbv = OP_DEFS(IC_RIGHT(dic));
2921 for (lic = ic; lic && lic != dic ; lic = lic->prev)
2923 if (bitVectBitValue(dbv,lic->key))
2926 /* make sure they have the same type */
2927 if (IS_SPEC(operandType(IC_LEFT(ic))))
2929 sym_link *itype=operandType(IC_LEFT(ic));
2930 sym_link *ditype=operandType(IC_RIGHT(dic));
2932 if (SPEC_USIGN(itype)!=SPEC_USIGN(ditype) ||
2933 SPEC_LONG(itype)!=SPEC_LONG(ditype))
2936 /* extend the live range of replaced operand if needed */
2937 if (OP_SYMBOL(IC_RIGHT(dic))->liveTo < ic->seq)
2939 OP_SYMBOL(IC_RIGHT(dic))->liveTo = ic->seq;
2941 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
2944 /* we now we know that it has one & only one def & use
2945 and the that the definition is an assignment */
2946 ReplaceOpWithCheaperOp(&IC_LEFT (ic), IC_RIGHT (dic));
2947 remiCodeFromeBBlock (ebp, dic);
2948 hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
2951 /*-----------------------------------------------------------------*/
2952 /* packRegisters - does some transformations to reduce register */
2954 /*-----------------------------------------------------------------*/
2956 packRegisters (eBBlock ** ebpp, int blockno)
2960 eBBlock *ebp=ebpp[blockno];
2966 /* look for assignments of the form */
2967 /* iTempNN = TrueSym (someoperation) SomeOperand */
2969 /* TrueSym := iTempNN:1 */
2970 for (ic = ebp->sch; ic; ic = ic->next)
2972 /* find assignment of the form TrueSym := iTempNN:1 */
2973 if (ic->op == '=' && !POINTER_SET (ic))
2974 change += packRegsForAssign (ic, ebp);
2979 for (ic = ebp->sch; ic; ic = ic->next)
2981 /* Fix for bug #979599: */
2984 /* Look for two subsequent iCodes with */
2986 /* _c = iTemp & op; */
2987 /* and replace them by */
2990 if ((ic->op == BITWISEAND || ic->op == '|' || ic->op == '^') &&
2992 ic->prev->op == '=' &&
2993 IS_ITEMP (IC_LEFT (ic)) &&
2994 IC_LEFT (ic) == IC_RESULT (ic->prev) &&
2995 isOperandEqual (IC_RESULT(ic), IC_RIGHT(ic->prev)))
2997 iCode* ic_prev = ic->prev;
2998 symbol* prev_result_sym = OP_SYMBOL (IC_RESULT (ic_prev));
3000 ReplaceOpWithCheaperOp (&IC_LEFT (ic), IC_RESULT (ic));
3001 if (IC_RESULT (ic_prev) != IC_RIGHT (ic))
3003 bitVectUnSetBit (OP_USES (IC_RESULT (ic_prev)), ic->key);
3004 if (/*IS_ITEMP (IC_RESULT (ic_prev)) && */
3005 prev_result_sym->liveTo == ic->seq)
3007 prev_result_sym->liveTo = ic_prev->seq;
3010 bitVectSetBit (OP_USES (IC_RESULT (ic)), ic->key);
3012 bitVectSetBit (ic->rlive, IC_RESULT (ic)->key);
3014 if (bitVectIsZero (OP_USES (IC_RESULT (ic_prev))))
3016 bitVectUnSetBit (ic->rlive, IC_RESULT (ic)->key);
3017 bitVectUnSetBit (OP_DEFS (IC_RESULT (ic_prev)), ic_prev->key);
3018 remiCodeFromeBBlock (ebp, ic_prev);
3019 hTabDeleteItem (&iCodehTab, ic_prev->key, ic_prev, DELETE_ITEM, NULL);
3023 /* if this is an itemp & result of an address of a true sym
3024 then mark this as rematerialisable */
3025 if (ic->op == ADDRESS_OF &&
3026 IS_ITEMP (IC_RESULT (ic)) &&
3027 IS_TRUE_SYMOP (IC_LEFT (ic)) &&
3028 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
3029 !OP_SYMBOL (IC_LEFT (ic))->onStack)
3031 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
3032 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
3033 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
3036 /* if straight assignment then carry remat flag if
3037 this is the only definition */
3038 if (ic->op == '=' &&
3039 !POINTER_SET (ic) &&
3040 IS_SYMOP (IC_RIGHT (ic)) &&
3041 OP_SYMBOL (IC_RIGHT (ic))->remat &&
3042 !IS_CAST_ICODE(OP_SYMBOL (IC_RIGHT (ic))->rematiCode) &&
3043 !isOperandGlobal(IC_RESULT(ic)) && /* due to bug 1618050 */
3044 bitVectnBitsOn (OP_SYMBOL (IC_RESULT (ic))->defs) <= 1)
3046 OP_SYMBOL (IC_RESULT (ic))->remat =
3047 OP_SYMBOL (IC_RIGHT (ic))->remat;
3048 OP_SYMBOL (IC_RESULT (ic))->rematiCode =
3049 OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
3052 /* if cast to a generic pointer & the pointer being
3053 cast is remat, then we can remat this cast as well */
3054 if (ic->op == CAST &&
3055 IS_SYMOP(IC_RIGHT(ic)) &&
3056 OP_SYMBOL(IC_RIGHT(ic))->remat &&
3057 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1)
3059 sym_link *to_type = operandType(IC_LEFT(ic));
3060 sym_link *from_type = operandType(IC_RIGHT(ic));
3061 if (IS_GENPTR(to_type) && IS_PTR(from_type))
3063 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
3064 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
3065 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
3069 /* if this is a +/- operation with a rematerizable
3070 then mark this as rematerializable as well */
3071 if ((ic->op == '+' || ic->op == '-') &&
3072 (IS_SYMOP (IC_LEFT (ic)) &&
3073 IS_ITEMP (IC_RESULT (ic)) &&
3074 IS_OP_LITERAL (IC_RIGHT (ic))) &&
3075 OP_SYMBOL (IC_LEFT (ic))->remat &&
3076 (!IS_SYMOP (IC_RIGHT (ic)) || !IS_CAST_ICODE(OP_SYMBOL (IC_RIGHT (ic))->rematiCode)) &&
3077 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1)
3079 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
3080 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
3081 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
3084 /* mark the pointer usages */
3085 if (POINTER_SET (ic) && IS_SYMOP (IC_RESULT (ic)))
3086 OP_SYMBOL (IC_RESULT (ic))->uptr = 1;
3088 if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic)))
3089 OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
3093 /* if we are using a symbol on the stack
3094 then we should say mcs51_ptrRegReq */
3095 if (options.useXstack && ic->parmPush
3096 && (ic->op == IPUSH || ic->op == IPOP))
3098 if (ic->op == IFX && IS_SYMOP (IC_COND (ic)))
3099 mcs51_ptrRegReq += ((OP_SYMBOL (IC_COND (ic))->onStack ||
3100 OP_SYMBOL (IC_COND (ic))->iaccess ||
3101 SPEC_OCLS(OP_SYMBOL (IC_COND (ic))->etype) == idata) ? 1 : 0);
3102 else if (ic->op == JUMPTABLE && IS_SYMOP (IC_JTCOND (ic)))
3103 mcs51_ptrRegReq += ((OP_SYMBOL (IC_JTCOND (ic))->onStack ||
3104 OP_SYMBOL (IC_JTCOND (ic))->iaccess ||
3105 SPEC_OCLS(OP_SYMBOL (IC_JTCOND (ic))->etype) == idata) ? 1 : 0);
3108 if (IS_SYMOP (IC_LEFT (ic)))
3109 mcs51_ptrRegReq += ((OP_SYMBOL (IC_LEFT (ic))->onStack ||
3110 OP_SYMBOL (IC_LEFT (ic))->iaccess ||
3111 SPEC_OCLS(OP_SYMBOL (IC_LEFT (ic))->etype) == idata) ? 1 : 0);
3112 if (IS_SYMOP (IC_RIGHT (ic)))
3113 mcs51_ptrRegReq += ((OP_SYMBOL (IC_RIGHT (ic))->onStack ||
3114 OP_SYMBOL (IC_RIGHT (ic))->iaccess ||
3115 SPEC_OCLS(OP_SYMBOL (IC_RIGHT (ic))->etype) == idata) ? 1 : 0);
3116 if (IS_SYMOP (IC_RESULT (ic)))
3117 mcs51_ptrRegReq += ((OP_SYMBOL (IC_RESULT (ic))->onStack ||
3118 OP_SYMBOL (IC_RESULT (ic))->iaccess ||
3119 SPEC_OCLS(OP_SYMBOL (IC_RESULT (ic))->etype) == idata) ? 1 : 0);
3120 if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic))
3121 && getSize (OP_SYMBOL (IC_LEFT (ic))->type) <= (unsigned int) PTRSIZE)
3123 if (POINTER_SET (ic) && IS_SYMOP (IC_RESULT (ic))
3124 && getSize (OP_SYMBOL (IC_RESULT (ic))->type) <= (unsigned int) PTRSIZE)
3129 /* if the condition of an if instruction
3130 is defined in the previous instruction and
3131 this is the only usage then
3132 mark the itemp as a conditional */
3133 if ((IS_CONDITIONAL (ic) ||
3134 (IS_BITWISE_OP(ic) && isBitwiseOptimizable (ic))) &&
3135 ic->next && ic->next->op == IFX &&
3136 bitVectnBitsOn (OP_USES(IC_RESULT(ic)))==1 &&
3137 isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
3138 OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
3140 OP_SYMBOL (IC_RESULT (ic))->regType = REG_CND;
3144 /* if the condition of an if instruction
3145 is defined in the previous GET_POINTER instruction and
3146 this is the only usage then
3147 mark the itemp as accumulator use */
3148 if ((POINTER_GET (ic) && getSize (operandType (IC_RESULT (ic))) <=1) &&
3149 ic->next && ic->next->op == IFX &&
3150 bitVectnBitsOn (OP_USES(IC_RESULT(ic)))==1 &&
3151 isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
3152 OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
3154 OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
3158 /* reduce for support function calls */
3159 if (ic->supportRtn || ic->op == '+' || ic->op == '-')
3160 packRegsForSupport (ic, ebp);
3162 /* some cases the redundant moves can
3163 can be eliminated for return statements */
3164 if ((ic->op == RETURN || (ic->op == SEND && ic->argreg == 1)) &&
3165 !isOperandInFarSpace (IC_LEFT (ic)) &&
3166 options.model == MODEL_SMALL) {
3167 packRegsForOneuse (ic, IC_LEFT (ic), ebp);
3170 /* if pointer set & left has a size more than
3171 one and right is not in far space */
3172 if (POINTER_SET (ic) &&
3173 IS_SYMOP (IC_RESULT (ic)) &&
3174 !isOperandInFarSpace (IC_RIGHT (ic)) &&
3175 !OP_SYMBOL (IC_RESULT (ic))->remat &&
3176 !IS_OP_RUONLY (IC_RIGHT (ic)) &&
3177 getSize (aggrToPtr (operandType (IC_RESULT (ic)), FALSE)) > 1)
3178 packRegsForOneuse (ic, IC_RESULT (ic), ebp);
3180 /* if pointer get */
3181 if (POINTER_GET (ic) &&
3182 IS_SYMOP (IC_LEFT (ic)) &&
3183 !isOperandInFarSpace (IC_RESULT (ic)) &&
3184 !OP_SYMBOL (IC_LEFT (ic))->remat &&
3185 !IS_OP_RUONLY (IC_RESULT (ic)) &&
3186 getSize (aggrToPtr (operandType (IC_LEFT (ic)), FALSE)) > 1)
3187 packRegsForOneuse (ic, IC_LEFT (ic), ebp);
3189 /* if this is a cast for intergral promotion then
3190 check if it's the only use of the definition of the
3191 operand being casted/ if yes then replace
3192 the result of that arithmetic operation with
3193 this result and get rid of the cast */
3196 sym_link *fromType = operandType (IC_RIGHT (ic));
3197 sym_link *toType = operandType (IC_LEFT (ic));
3199 if (IS_INTEGRAL (fromType) && IS_INTEGRAL (toType) &&
3200 getSize (fromType) != getSize (toType) &&
3201 SPEC_USIGN (fromType) == SPEC_USIGN (toType))
3204 iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
3207 if (IS_ARITHMETIC_OP (dic))
3209 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
3210 ReplaceOpWithCheaperOp(&IC_RESULT (dic), IC_RESULT (ic));
3211 remiCodeFromeBBlock (ebp, ic);
3212 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
3213 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
3214 OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
3218 OP_SYMBOL (IC_RIGHT (ic))->ruonly = 0;
3223 /* if the type from and type to are the same
3224 then if this is the only use then packit */
3225 if (compareType (operandType (IC_RIGHT (ic)),
3226 operandType (IC_LEFT (ic))) == 1)
3228 iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
3231 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
3232 ReplaceOpWithCheaperOp(&IC_RESULT (dic), IC_RESULT (ic));
3233 remiCodeFromeBBlock (ebp, ic);
3234 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
3235 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
3236 OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
3244 iTempNN := (some variable in farspace) V1
3249 if (ic->op == IPUSH)
3251 packForPush (ic, ebpp, blockno);
3254 /* pack registers for accumulator use, when the
3255 result of an arithmetic or bit wise operation
3256 has only one use, that use is immediately following
3257 the definition and the using iCode has only one
3258 operand or has two operands but one is literal &
3259 the result of that operation is not on stack then
3260 we can leave the result of this operation in acc:b
3262 if ((IS_ARITHMETIC_OP (ic)
3263 || IS_CONDITIONAL(ic)
3264 || IS_BITWISE_OP (ic)
3265 || ic->op == LEFT_OP || ic->op == RIGHT_OP || ic->op == CALL
3266 || (ic->op == ADDRESS_OF && isOperandOnStack (IC_LEFT (ic)))
3268 IS_ITEMP (IC_RESULT (ic)) &&
3269 getSize (operandType (IC_RESULT (ic))) <= 2)
3271 packRegsForAccUse (ic);
3276 /*-----------------------------------------------------------------*/
3277 /* assignRegisters - assigns registers to each live range as need */
3278 /*-----------------------------------------------------------------*/
3280 mcs51_assignRegisters (ebbIndex * ebbi)
3282 eBBlock ** ebbs = ebbi->bbOrder;
3283 int count = ebbi->count;
3287 setToNull ((void *) &_G.funcrUsed);
3288 setToNull ((void *) &_G.regAssigned);
3289 setToNull ((void *) &_G.totRegAssigned);
3290 mcs51_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
3291 if ((currFunc && IFFUNC_ISREENT (currFunc->type)) || options.stackAuto)
3299 _G.allBitregs = findAllBitregs ();
3301 /* change assignments this will remove some
3302 live ranges reducing some register pressure */
3304 for (i = 0; i < count; i++)
3305 packRegisters (ebbs, i);
3307 /* liveranges probably changed by register packing
3308 so we compute them again */
3309 recomputeLiveRanges (ebbs, count);
3311 if (options.dump_pack)
3312 dumpEbbsToFileExt (DUMP_PACK, ebbi);
3314 /* first determine for each live range the number of
3315 registers & the type of registers required for each */
3318 /* and serially allocate registers */
3319 serialRegAssign (ebbs, count);
3322 //setToNull ((void *) &_G.regAssigned);
3323 //setToNull ((void *) &_G.totRegAssigned);
3326 /* if stack was extended then tell the user */
3329 /* werror(W_TOOMANY_SPILS,"stack", */
3330 /* _G.stackExtend,currFunc->name,""); */
3336 /* werror(W_TOOMANY_SPILS,"data space", */
3337 /* _G.dataExtend,currFunc->name,""); */
3341 /* after that create the register mask
3342 for each of the instruction */
3343 createRegMask (ebbs, count);
3345 /* redo that offsets for stacked automatic variables */
3347 redoStackOffsets ();
3350 /* make sure r0 & r1 are flagged as used if they might be used */
3352 if (currFunc && mcs51_ptrRegReq)
3354 currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, R0_IDX);
3355 currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, R1_IDX);
3358 if (options.dump_rassgn)
3360 dumpEbbsToFileExt (DUMP_RASSGN, ebbi);
3361 dumpLiveRanges (DUMP_LRANGE, liveRanges);
3364 /* do the overlaysegment stuff SDCCmem.c */
3365 doOverlays (ebbs, count);
3367 /* now get back the chain */
3368 ic = iCodeLabelOptimize (iCodeFromeBBlock (ebbs, count));
3372 /* free up any _G.stackSpil locations allocated */
3373 applyToSet (_G.stackSpil, deallocStackSpil);
3375 setToNull ((void *) &_G.stackSpil);
3376 setToNull ((void *) &_G.spiltSet);
3377 /* mark all registers as free */