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 /*-----------------------------------------------------------------*/
47 bitVect *totRegAssigned; /* final set of LRs that got into registers */
50 bitVect *funcrUsed; /* registers used in a function */
56 /* Shared with gen.c */
57 int ds390_ptrRegReq; /* one byte pointer register required */
63 {REG_GPR, R2_IDX, REG_GPR, "r2", "ar2", "0", 2, 1, 1},
64 {REG_GPR, R3_IDX, REG_GPR, "r3", "ar3", "0", 3, 1, 1},
65 {REG_GPR, R4_IDX, REG_GPR, "r4", "ar4", "0", 4, 1, 1},
66 {REG_GPR, R5_IDX, REG_GPR, "r5", "ar5", "0", 5, 1, 1},
67 {REG_GPR, R6_IDX, REG_GPR, "r6", "ar6", "0", 6, 1, 1},
68 {REG_GPR, R7_IDX, REG_GPR, "r7", "ar7", "0", 7, 1, 1},
69 {REG_PTR, R0_IDX, REG_PTR, "r0", "ar0", "0", 0, 1, 1},
70 {REG_PTR, R1_IDX, REG_PTR, "r1", "ar1", "0", 1, 1, 1},
71 {REG_GPR, DPL_IDX, REG_GPR, "dpl", "dpl", "dpl", 0, 0, 0},
72 {REG_GPR, DPH_IDX, REG_GPR, "dph", "dph", "dph", 0, 0, 0},
73 {REG_GPR, DPX_IDX, REG_GPR, "dpx", "dpx", "dpx", 0, 0, 0},
74 {REG_GPR, B_IDX, REG_GPR, "b", "b", "b", 0, 0, 0},
75 {REG_GPR, X8_IDX, REG_GPR, "x8", "x8", "xreg", 0, 0, 0},
76 {REG_GPR, X9_IDX, REG_GPR, "x9", "x9", "xreg", 1, 0, 0},
77 {REG_GPR, X10_IDX, REG_GPR, "x10", "x10", "xreg", 2, 0, 0},
78 {REG_GPR, X11_IDX, REG_GPR, "x11", "x11", "xreg", 3, 0, 0},
79 {REG_GPR, X12_IDX, REG_GPR, "x12", "x12", "xreg", 4, 0, 0},
80 {REG_CND, CND_IDX, REG_GPR, "C", "psw", "xreg", 0, 0, 0},
81 {0, DPL1_IDX, 0, "dpl1", "dpl1", "dpl1", 0, 0, 0},
82 {0, DPH1_IDX, 0, "dph1", "dph1", "dph1", 0, 0, 0},
83 {0, DPX1_IDX, 0, "dpx1", "dpx1", "dpx1", 0, 0, 0},
84 {0, DPS_IDX, 0, "dps", "dps", "dps", 0, 0, 0},
85 {0, A_IDX, 0, "a", "acc", "acc", 0, 0, 0},
86 {0, AP_IDX, 0, "ap", "ap", "ap", 0, 0, 0},
89 static void spillThis (symbol *);
90 static void freeAllRegs ();
91 static iCode * packRegsDPTRuse (operand *);
92 static int packRegsDPTRnuse (operand *,int);
94 /*-----------------------------------------------------------------*/
95 /* allocReg - allocates register of given type */
96 /*-----------------------------------------------------------------*/
102 for (i = 0; i < ds390_nRegs; i++)
105 /* if type is given as 0 then any
106 free register will do */
110 regs390[i].isFree = 0;
113 bitVectSetBit (currFunc->regsUsed, i);
116 /* other wise look for specific type
118 if (regs390[i].isFree &&
119 regs390[i].type == type)
121 regs390[i].isFree = 0;
124 bitVectSetBit (currFunc->regsUsed, i);
131 /*-----------------------------------------------------------------*/
132 /* ds390_regWithIdx - returns pointer to register wit index number */
133 /*-----------------------------------------------------------------*/
135 ds390_regWithIdx (int idx)
139 for (i = 0; i < sizeof(regs390)/sizeof(regs); i++)
140 if (regs390[i].rIdx == idx)
143 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
144 "regWithIdx not found");
148 /*-----------------------------------------------------------------*/
149 /* freeReg - frees a register */
150 /*-----------------------------------------------------------------*/
157 /*-----------------------------------------------------------------*/
158 /* useReg - marks a register as used */
159 /*-----------------------------------------------------------------*/
167 /*-----------------------------------------------------------------*/
168 /* nFreeRegs - returns number of free registers */
169 /*-----------------------------------------------------------------*/
176 for (i = 0; i < ds390_nRegs; i++)
177 if (regs390[i].isFree && regs390[i].type == type)
182 /*-----------------------------------------------------------------*/
183 /* nfreeRegsType - free registers with type */
184 /*-----------------------------------------------------------------*/
186 nfreeRegsType (int type)
191 if ((nfr = nFreeRegs (type)) == 0)
192 return nFreeRegs (REG_GPR);
195 return nFreeRegs (type);
200 /*-----------------------------------------------------------------*/
201 /* isOperandInReg - returns true if operand is currently in regs */
202 /*-----------------------------------------------------------------*/
203 static int isOperandInReg(operand *op)
205 if (!IS_SYMOP(op)) return 0;
206 if (OP_SYMBOL(op)->ruonly) return 1;
207 if (OP_SYMBOL(op)->accuse) return 1;
208 if (OP_SYMBOL(op)->dptr) return 1;
209 return bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(op)->key);
212 /*-----------------------------------------------------------------*/
213 /* computeSpillable - given a point find the spillable live ranges */
214 /*-----------------------------------------------------------------*/
216 computeSpillable (iCode * ic)
220 /* spillable live ranges are those that are live at this
221 point . the following categories need to be subtracted
223 a) - those that are already spilt
224 b) - if being used by this one
225 c) - defined by this one */
227 spillable = bitVectCopy (ic->rlive);
229 bitVectCplAnd (spillable, _G.spiltSet); /* those already spilt */
231 bitVectCplAnd (spillable, ic->uses); /* used in this one */
232 bitVectUnSetBit (spillable, ic->defKey);
233 spillable = bitVectIntersect (spillable, _G.regAssigned);
238 /*-----------------------------------------------------------------*/
239 /* noSpilLoc - return true if a variable has no spil location */
240 /*-----------------------------------------------------------------*/
242 noSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
244 return (sym->usl.spillLoc ? 0 : 1);
247 /*-----------------------------------------------------------------*/
248 /* hasSpilLoc - will return 1 if the symbol has spil location */
249 /*-----------------------------------------------------------------*/
251 hasSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
253 return (sym->usl.spillLoc ? 1 : 0);
256 /*-----------------------------------------------------------------*/
257 /* directSpilLoc - will return 1 if the splilocation is in direct */
258 /*-----------------------------------------------------------------*/
260 directSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
262 if (sym->usl.spillLoc &&
263 (IN_DIRSPACE (SPEC_OCLS (sym->usl.spillLoc->etype))))
269 /*-----------------------------------------------------------------*/
270 /* hasSpilLocnoUptr - will return 1 if the symbol has spil location */
271 /* but is not used as a pointer */
272 /*-----------------------------------------------------------------*/
274 hasSpilLocnoUptr (symbol * sym, eBBlock * ebp, iCode * ic)
276 return ((sym->usl.spillLoc && !sym->uptr) ? 1 : 0);
279 /*-----------------------------------------------------------------*/
280 /* rematable - will return 1 if the remat flag is set */
281 /*-----------------------------------------------------------------*/
283 rematable (symbol * sym, eBBlock * ebp, iCode * ic)
288 /*-----------------------------------------------------------------*/
289 /* notUsedInRemaining - not used or defined in remain of the block */
290 /*-----------------------------------------------------------------*/
292 notUsedInRemaining (symbol * sym, eBBlock * ebp, iCode * ic)
294 return ((usedInRemaining (operandFromSymbol (sym), ic) ? 0 : 1) &&
295 allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq));
298 /*-----------------------------------------------------------------*/
299 /* allLRs - return true for all */
300 /*-----------------------------------------------------------------*/
302 allLRs (symbol * sym, eBBlock * ebp, iCode * ic)
307 /*-----------------------------------------------------------------*/
308 /* liveRangesWith - applies function to a given set of live range */
309 /*-----------------------------------------------------------------*/
311 liveRangesWith (bitVect * lrs, int (func) (symbol *, eBBlock *, iCode *),
312 eBBlock * ebp, iCode * ic)
317 if (!lrs || !lrs->size)
320 for (i = 1; i < lrs->size; i++)
323 if (!bitVectBitValue (lrs, i))
326 /* if we don't find it in the live range
327 hash table we are in serious trouble */
328 if (!(sym = hTabItemWithKey (liveRanges, i)))
330 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
331 "liveRangesWith could not find liveRange");
335 if (func (sym, ebp, ic) && bitVectBitValue (_G.regAssigned, sym->key))
336 addSetHead (&rset, sym);
343 /*-----------------------------------------------------------------*/
344 /* leastUsedLR - given a set determines which is the least used */
345 /*-----------------------------------------------------------------*/
347 leastUsedLR (set * sset)
349 symbol *sym = NULL, *lsym = NULL;
351 sym = lsym = setFirstItem (sset);
356 for (; lsym; lsym = setNextItem (sset))
359 /* if usage is the same then prefer
360 the spill the smaller of the two */
361 if (lsym->used == sym->used)
362 if (getSize (lsym->type) < getSize (sym->type))
366 if (lsym->used < sym->used)
371 setToNull ((void *) &sset);
376 /*-----------------------------------------------------------------*/
377 /* noOverLap - will iterate through the list looking for over lap */
378 /*-----------------------------------------------------------------*/
380 noOverLap (set * itmpStack, symbol * fsym)
384 for (sym = setFirstItem (itmpStack); sym;
385 sym = setNextItem (itmpStack))
387 if (bitVectBitValue(sym->clashes,fsym->key)) return 0;
392 /*-----------------------------------------------------------------*/
393 /* isFree - will return 1 if the a free spil location is found */
394 /*-----------------------------------------------------------------*/
399 V_ARG (symbol **, sloc);
400 V_ARG (symbol *, fsym);
402 /* if already found */
406 /* if it is free && and the itmp assigned to
407 this does not have any overlapping live ranges
408 with the one currently being assigned and
409 the size can be accomodated */
411 noOverLap (sym->usl.itmpStack, fsym) &&
412 getSize (sym->type) >= getSize (fsym->type))
421 /*-----------------------------------------------------------------*/
422 /* spillLRWithPtrReg :- will spil those live ranges which use PTR */
423 /*-----------------------------------------------------------------*/
425 spillLRWithPtrReg (symbol * forSym)
431 if (!_G.regAssigned ||
432 bitVectIsZero (_G.regAssigned))
435 r0 = ds390_regWithIdx (R0_IDX);
436 r1 = ds390_regWithIdx (R1_IDX);
438 /* for all live ranges */
439 for (lrsym = hTabFirstItem (liveRanges, &k); lrsym;
440 lrsym = hTabNextItem (liveRanges, &k))
444 /* if no registers assigned to it or
446 /* if it does not overlap with this then
447 not need to spill it */
449 if (lrsym->isspilt || !lrsym->nRegs ||
450 (lrsym->liveTo < forSym->liveFrom))
453 /* go thru the registers : if it is either
454 r0 or r1 then spil it */
455 for (j = 0; j < lrsym->nRegs; j++)
456 if (lrsym->regs[j] == r0 ||
457 lrsym->regs[j] == r1)
466 /*-----------------------------------------------------------------*/
467 /* createStackSpil - create a location on the stack to spil */
468 /*-----------------------------------------------------------------*/
470 createStackSpil (symbol * sym)
473 int useXstack, model, noOverlay;
477 /* first go try and find a free one that is already
478 existing on the stack */
479 if (applyToSet (_G.stackSpil, isFree, &sloc, sym))
481 /* found a free one : just update & return */
482 sym->usl.spillLoc = sloc;
485 addSetHead (&sloc->usl.itmpStack, sym);
489 /* could not then have to create one , this is the hard part
490 we need to allocate this on the stack : this is really a
491 hack!! but cannot think of anything better at this time */
493 if (SNPRINTF (slocBuffer, sizeof(slocBuffer),
494 "sloc%d", _G.slocNum++) >= sizeof (slocBuffer))
496 fprintf (stderr, "***Internal error: slocBuffer overflowed: %s:%d\n",
501 sloc = newiTemp (slocBuffer);
503 /* set the type to the spilling symbol */
504 sloc->type = copyLinkChain (sym->type);
505 sloc->etype = getSpec (sloc->type);
506 if (options.model == MODEL_SMALL) {
507 SPEC_SCLS (sloc->etype) = S_DATA;
509 SPEC_SCLS (sloc->etype) = S_XDATA;
511 SPEC_EXTR (sloc->etype) = 0;
512 SPEC_STAT (sloc->etype) = 0;
513 SPEC_VOLATILE(sloc->etype) = 0;
514 SPEC_ABSA(sloc->etype) = 0;
516 /* we don't allow it to be allocated`
517 onto the external stack since : so we
518 temporarily turn it off ; we also
519 turn off memory model to prevent
520 the spil from going to the external storage
521 and turn off overlaying
524 useXstack = options.useXstack;
525 model = options.model;
526 noOverlay = options.noOverlay;
527 options.noOverlay = 1;
529 /* options.model = options.useXstack = 0; */
533 options.useXstack = useXstack;
534 options.model = model;
535 options.noOverlay = noOverlay;
536 sloc->isref = 1; /* to prevent compiler warning */
538 /* if it is on the stack then update the stack */
539 if (IN_STACK (sloc->etype))
541 currFunc->stack += getSize (sloc->type);
542 _G.stackExtend += getSize (sloc->type);
545 _G.dataExtend += getSize (sloc->type);
547 /* add it to the _G.stackSpil set */
548 addSetHead (&_G.stackSpil, sloc);
549 sym->usl.spillLoc = sloc;
552 /* add it to the set of itempStack set
553 of the spill location */
554 addSetHead (&sloc->usl.itmpStack, sym);
558 /*-----------------------------------------------------------------*/
559 /* isSpiltOnStack - returns true if the spil location is on stack */
560 /*-----------------------------------------------------------------*/
562 isSpiltOnStack (symbol * sym)
572 /* if (sym->_G.stackSpil) */
575 if (!sym->usl.spillLoc)
578 etype = getSpec (sym->usl.spillLoc->type);
579 if (IN_STACK (etype))
585 /*-----------------------------------------------------------------*/
586 /* spillThis - spils a specific operand */
587 /*-----------------------------------------------------------------*/
589 spillThis (symbol * sym)
592 /* if this is rematerializable or has a spillLocation
593 we are okay, else we need to create a spillLocation
595 if (!(sym->remat || sym->usl.spillLoc))
596 createStackSpil (sym);
599 /* mark it has spilt & put it in the spilt set */
600 sym->isspilt = sym->spillA = 1;
601 _G.spiltSet = bitVectSetBit (_G.spiltSet, sym->key);
603 bitVectUnSetBit (_G.regAssigned, sym->key);
604 bitVectUnSetBit (_G.totRegAssigned, sym->key);
606 for (i = 0; i < sym->nRegs; i++)
610 freeReg (sym->regs[i]);
614 /* if spilt on stack then free up r0 & r1
615 if they could have been assigned to some
617 if (!ds390_ptrRegReq && isSpiltOnStack (sym) && !options.stack10bit)
620 spillLRWithPtrReg (sym);
623 if (sym->usl.spillLoc && !sym->remat)
624 sym->usl.spillLoc->allocreq++;
628 /*-----------------------------------------------------------------*/
629 /* selectSpil - select a iTemp to spil : rather a simple procedure */
630 /*-----------------------------------------------------------------*/
632 selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
634 bitVect *lrcs = NULL;
638 /* get the spillable live ranges */
639 lrcs = computeSpillable (ic);
641 /* get all live ranges that are rematerizable */
642 if ((selectS = liveRangesWith (lrcs, rematable, ebp, ic)))
645 /* return the least used of these */
646 return leastUsedLR (selectS);
649 /* get live ranges with spillLocations in direct space */
650 if ((selectS = liveRangesWith (lrcs, directSpilLoc, ebp, ic)))
652 sym = leastUsedLR (selectS);
653 strncpyz (sym->rname,
654 sym->usl.spillLoc->rname[0] ?
655 sym->usl.spillLoc->rname : sym->usl.spillLoc->name,
658 /* mark it as allocation required */
659 sym->usl.spillLoc->allocreq++;
663 /* if the symbol is local to the block then */
664 if (forSym->liveTo < ebp->lSeq)
667 /* check if there are any live ranges allocated
668 to registers that are not used in this block */
669 if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInBlock, ebp, ic)))
671 sym = leastUsedLR (selectS);
672 /* if this is not rematerializable */
681 /* check if there are any live ranges that not
682 used in the remainder of the block */
683 if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInRemaining, ebp, ic)))
685 sym = leastUsedLR (selectS);
698 /* find live ranges with spillocation && not used as pointers */
699 if ((selectS = liveRangesWith (lrcs, hasSpilLocnoUptr, ebp, ic)))
702 sym = leastUsedLR (selectS);
703 /* mark this as allocation required */
704 sym->usl.spillLoc->allocreq++;
708 /* find live ranges with spillocation */
709 if ((selectS = liveRangesWith (lrcs, hasSpilLoc, ebp, ic)))
712 sym = leastUsedLR (selectS);
713 sym->usl.spillLoc->allocreq++;
717 /* couldn't find then we need to create a spil
718 location on the stack , for which one? the least
720 if ((selectS = liveRangesWith (lrcs, noSpilLoc, ebp, ic)))
723 /* return a created spil location */
724 sym = createStackSpil (leastUsedLR (selectS));
725 sym->usl.spillLoc->allocreq++;
729 /* this is an extreme situation we will spill
730 this one : happens very rarely but it does happen */
736 /*-----------------------------------------------------------------*/
737 /* spilSomething - spil some variable & mark registers as free */
738 /*-----------------------------------------------------------------*/
740 spilSomething (iCode * ic, eBBlock * ebp, symbol * forSym)
745 /* get something we can spil */
746 ssym = selectSpil (ic, ebp, forSym);
748 /* mark it as spilt */
749 ssym->isspilt = ssym->spillA = 1;
750 _G.spiltSet = bitVectSetBit (_G.spiltSet, ssym->key);
752 /* mark it as not register assigned &
753 take it away from the set */
754 bitVectUnSetBit (_G.regAssigned, ssym->key);
755 bitVectUnSetBit (_G.totRegAssigned, ssym->key);
757 /* mark the registers as free */
758 for (i = 0; i < ssym->nRegs; i++)
760 freeReg (ssym->regs[i]);
762 /* if spilt on stack then free up r0 & r1
763 if they could have been assigned to as gprs */
764 if (!ds390_ptrRegReq && isSpiltOnStack (ssym) && !options.stack10bit)
767 spillLRWithPtrReg (ssym);
770 /* if this was a block level spil then insert push & pop
771 at the start & end of block respectively */
774 iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
775 /* add push to the start of the block */
776 addiCodeToeBBlock (ebp, nic, (ebp->sch->op == LABEL ?
777 ebp->sch->next : ebp->sch));
778 nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
779 /* add pop to the end of the block */
780 addiCodeToeBBlock (ebp, nic, NULL);
783 /* if spilt because not used in the remainder of the
784 block then add a push before this instruction and
785 a pop at the end of the block */
786 if (ssym->remainSpil)
789 iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
790 /* add push just before this instruction */
791 addiCodeToeBBlock (ebp, nic, ic);
793 nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
794 /* add pop to the end of the block */
795 addiCodeToeBBlock (ebp, nic, NULL);
804 /*-----------------------------------------------------------------*/
805 /* getRegPtr - will try for PTR if not a GPR type if not spil */
806 /*-----------------------------------------------------------------*/
808 getRegPtr (iCode * ic, eBBlock * ebp, symbol * sym)
814 /* try for a ptr type */
815 if ((reg = allocReg (REG_PTR)))
818 /* try for gpr type */
819 if ((reg = allocReg (REG_GPR)))
822 /* we have to spil */
823 if (!spilSomething (ic, ebp, sym))
826 /* make sure partially assigned registers aren't reused */
827 for (j=0; j<=sym->nRegs; j++)
829 sym->regs[j]->isFree = 0;
831 /* this looks like an infinite loop but
832 in really selectSpil will abort */
836 /*-----------------------------------------------------------------*/
837 /* getRegGpr - will try for GPR if not spil */
838 /*-----------------------------------------------------------------*/
840 getRegGpr (iCode * ic, eBBlock * ebp, symbol * sym)
846 /* try for gpr type */
847 if ((reg = allocReg (REG_GPR)))
850 if (!ds390_ptrRegReq)
851 if ((reg = allocReg (REG_PTR)))
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 /* getRegPtrNoSpil - get it cannot split */
870 /*-----------------------------------------------------------------*/
871 static regs *getRegPtrNoSpil()
875 /* try for a ptr type */
876 if ((reg = allocReg (REG_PTR)))
879 /* try for gpr type */
880 if ((reg = allocReg (REG_GPR)))
885 /* just to make the compiler happy */
889 /*-----------------------------------------------------------------*/
890 /* getRegGprNoSpil - get it cannot split */
891 /*-----------------------------------------------------------------*/
892 static regs *getRegGprNoSpil()
896 if ((reg = allocReg (REG_GPR)))
899 if (!ds390_ptrRegReq)
900 if ((reg = allocReg (REG_PTR)))
905 /* just to make the compiler happy */
909 /*-----------------------------------------------------------------*/
910 /* symHasReg - symbol has a given register */
911 /*-----------------------------------------------------------------*/
913 symHasReg (symbol * sym, regs * reg)
917 for (i = 0; i < sym->nRegs; i++)
918 if (sym->regs[i] == reg)
924 /*-----------------------------------------------------------------*/
925 /* deassignLRs - check the live to and if they have registers & are */
926 /* not spilt then free up the registers */
927 /*-----------------------------------------------------------------*/
929 deassignLRs (iCode * ic, eBBlock * ebp)
935 for (sym = hTabFirstItem (liveRanges, &k); sym;
936 sym = hTabNextItem (liveRanges, &k))
940 /* if it does not end here */
941 if (sym->liveTo > ic->seq)
944 /* if it was spilt on stack then we can
945 mark the stack spil location as free */
950 sym->usl.spillLoc->isFree = 1;
956 if (!bitVectBitValue (_G.regAssigned, sym->key))
959 /* special case check if this is an IFX &
960 the privious one was a pop and the
961 previous one was not spilt then keep track
963 if (ic->op == IFX && ic->prev &&
964 ic->prev->op == IPOP &&
965 !ic->prev->parmPush &&
966 !OP_SYMBOL (IC_LEFT (ic->prev))->isspilt)
967 psym = OP_SYMBOL (IC_LEFT (ic->prev));
973 bitVectUnSetBit (_G.regAssigned, sym->key);
975 /* if the result of this one needs registers
976 and does not have it then assign it right
978 if (IC_RESULT (ic) &&
979 !(SKIP_IC2 (ic) || /* not a special icode */
980 ic->op == JUMPTABLE ||
986 (result = OP_SYMBOL (IC_RESULT (ic))) && /* has a result */
987 result->liveTo > ic->seq && /* and will live beyond this */
988 result->liveTo <= ebp->lSeq && /* does not go beyond this block */
989 result->regType == sym->regType && /* same register types */
990 result->nRegs && /* which needs registers */
991 !result->isspilt && /* and does not already have them */
993 !bitVectBitValue (_G.regAssigned, result->key) &&
994 /* the number of free regs + number of regs in this LR
995 can accomodate the what result Needs */
996 ((nfreeRegsType (result->regType) +
997 sym->nRegs) >= result->nRegs)
1001 for (i = 0; i < result->nRegs; i++)
1003 result->regs[i] = sym->regs[i];
1005 result->regs[i] = getRegGpr (ic, ebp, result);
1007 _G.regAssigned = bitVectSetBit (_G.regAssigned, result->key);
1008 _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, result->key);
1012 /* free the remaining */
1013 for (; i < sym->nRegs; i++)
1017 if (!symHasReg (psym, sym->regs[i]))
1018 freeReg (sym->regs[i]);
1021 freeReg (sym->regs[i]);
1028 /*-----------------------------------------------------------------*/
1029 /* reassignLR - reassign this to registers */
1030 /*-----------------------------------------------------------------*/
1032 reassignLR (operand * op)
1034 symbol *sym = OP_SYMBOL (op);
1037 /* not spilt any more */
1038 sym->isspilt = sym->spillA = sym->blockSpil = sym->remainSpil = 0;
1039 bitVectUnSetBit (_G.spiltSet, sym->key);
1041 _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
1042 _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, sym->key);
1046 for (i = 0; i < sym->nRegs; i++)
1047 sym->regs[i]->isFree = 0;
1050 /*-----------------------------------------------------------------*/
1051 /* willCauseSpill - determines if allocating will cause a spill */
1052 /*-----------------------------------------------------------------*/
1054 willCauseSpill (int nr, int rt)
1056 /* first check if there are any avlb registers
1057 of te type required */
1060 /* special case for pointer type
1061 if pointer type not avlb then
1062 check for type gpr */
1063 if (nFreeRegs (rt) >= nr)
1065 if (nFreeRegs (REG_GPR) >= nr)
1070 if (ds390_ptrRegReq)
1072 if (nFreeRegs (rt) >= nr)
1077 if (nFreeRegs (REG_PTR) +
1078 nFreeRegs (REG_GPR) >= nr)
1083 /* it will cause a spil */
1087 /*-----------------------------------------------------------------*/
1088 /* positionRegs - the allocator can allocate same registers to res- */
1089 /* ult and operand, if this happens make sure they are in the same */
1090 /* position as the operand otherwise chaos results */
1091 /*-----------------------------------------------------------------*/
1093 positionRegs (symbol * result, symbol * opsym)
1095 int count = min (result->nRegs, opsym->nRegs);
1096 int i, j = 0, shared = 0;
1099 /* if the result has been spilt then cannot share */
1104 /* first make sure that they actually share */
1105 for (i = 0; i < count; i++)
1107 for (j = 0; j < count; j++)
1109 if (result->regs[i] == opsym->regs[j] && i != j)
1119 regs *tmp = result->regs[i];
1120 result->regs[i] = result->regs[j];
1121 result->regs[j] = tmp;
1128 /*-----------------------------------------------------------------*/
1129 /* unusedLRS - returns a bitVector of liveranges not used in 'ebp' */
1130 /*-----------------------------------------------------------------*/
1131 bitVect *unusedLRs (eBBlock *ebp)
1133 bitVect *ret = NULL;
1137 if (!ebp) return NULL;
1138 for (sym = hTabFirstItem(liveRanges,&key); sym ;
1139 sym = hTabNextItem(liveRanges,&key)) {
1141 if (notUsedInBlock(sym,ebp,NULL)) {
1142 ret = bitVectSetBit(ret,sym->key);
1149 /*-----------------------------------------------------------------*/
1150 /* deassignUnsedLRs - if this baisc block ends in a return then */
1151 /* deassign symbols not used in this block */
1152 /*-----------------------------------------------------------------*/
1153 bitVect *deassignUnsedLRs(eBBlock *ebp)
1155 bitVect *unused = NULL;
1158 switch (returnAtEnd(ebp)) {
1159 case 2: /* successor block ends in a return */
1160 unused = unusedLRs((eBBlock *) setFirstItem(ebp->succList));
1162 case 1: /* this block ends in a return */
1163 unused = bitVectIntersect(unused,unusedLRs(ebp));
1168 for (i = 0 ; i < unused->size ; i++ ) {
1171 if (bitVectBitValue(unused,i)) {
1173 /* if assigned to registers */
1174 if (bitVectBitValue(_G.regAssigned,i)) {
1178 sym = hTabItemWithKey(liveRanges,i);
1179 /* remove it from regassigned & mark the
1181 bitVectUnSetBit(_G.regAssigned,i);
1182 for (j = 0 ; j < sym->nRegs; j++)
1183 freeReg(sym->regs[j]);
1185 /* not assigned to registers : remove from set*/
1186 bitVectUnSetBit(unused,i);
1194 /*-----------------------------------------------------------------*/
1195 /* reassignUnusedLRs - put registers to unused Live ranges */
1196 /*-----------------------------------------------------------------*/
1197 void reassignUnusedLRs (bitVect *unused)
1200 if (!unused) return ;
1202 for (i = 0 ; i < unused->size ; i++ ) {
1203 /* if unused : means it was assigned to registers before */
1204 if (bitVectBitValue(unused,i)) {
1208 /* put it back into reg set*/
1209 bitVectSetBit(_G.regAssigned,i) ;
1211 sym = hTabItemWithKey(liveRanges,i);
1212 /* makr registers busy */
1213 for (j = 0 ; j < sym->nRegs; j++)
1214 sym->regs[j]->isFree = 0;
1219 /*------------------------------------------------------------------*/
1220 /* verifyRegsAssigned - make sure an iTemp is properly initialized; */
1221 /* it should either have registers or have beed spilled. Otherwise, */
1222 /* there was an uninitialized variable, so just spill this to get */
1223 /* the operand in a valid state. */
1224 /*------------------------------------------------------------------*/
1226 verifyRegsAssigned (operand *op, iCode * ic)
1231 if (!IS_ITEMP (op)) return;
1233 sym = OP_SYMBOL (op);
1234 if (sym->isspilt) return;
1235 if (!sym->nRegs) return;
1236 if (sym->regs[0]) return;
1238 werrorfl (ic->filename, ic->lineno, W_LOCAL_NOINIT,
1239 sym->prereqv ? sym->prereqv->name : sym->name);
1244 /*-----------------------------------------------------------------*/
1245 /* serialRegAssign - serially allocate registers to the variables */
1246 /*-----------------------------------------------------------------*/
1248 serialRegAssign (eBBlock ** ebbs, int count)
1252 /* for all blocks */
1253 for (i = 0; i < count; i++)
1257 bitVect *unusedLRs = NULL;
1259 if (ebbs[i]->noPath &&
1260 (ebbs[i]->entryLabel != entryLabel &&
1261 ebbs[i]->entryLabel != returnLabel))
1264 unusedLRs = deassignUnsedLRs(ebbs[i]);
1266 /* of all instructions do */
1267 for (ic = ebbs[i]->sch; ic; ic = ic->next)
1270 /* if this is an ipop that means some live
1271 range will have to be assigned again */
1273 reassignLR (IC_LEFT (ic));
1275 /* if result is present && is a true symbol */
1276 if (IC_RESULT (ic) && ic->op != IFX &&
1277 IS_TRUE_SYMOP (IC_RESULT (ic)))
1278 OP_SYMBOL (IC_RESULT (ic))->allocreq++;
1280 /* take away registers from live
1281 ranges that end at this instruction */
1282 deassignLRs (ic, ebbs[i]);
1284 /* some don't need registers */
1285 if (SKIP_IC2 (ic) ||
1286 ic->op == JUMPTABLE ||
1290 (IC_RESULT (ic) && POINTER_SET (ic)))
1293 /* now we need to allocate registers
1294 only for the result */
1297 symbol *sym = OP_SYMBOL (IC_RESULT (ic));
1303 /* if it does not need or is spilt
1304 or is already assigned to registers
1305 or will not live beyond this instructions */
1308 bitVectBitValue (_G.regAssigned, sym->key) ||
1309 sym->liveTo <= ic->seq)
1312 /* if some liverange has been spilt at the block level
1313 and this one live beyond this block then spil this
1315 if (_G.blockSpil && sym->liveTo > ebbs[i]->lSeq)
1320 /* if trying to allocate this will cause
1321 a spill and there is nothing to spill
1322 or this one is rematerializable then
1324 willCS = willCauseSpill (sym->nRegs, sym->regType);
1325 spillable = computeSpillable (ic);
1327 (willCS && bitVectIsZero (spillable)))
1335 /* If the live range preceeds the point of definition
1336 then ideally we must take into account registers that
1337 have been allocated after sym->liveFrom but freed
1338 before ic->seq. This is complicated, so spill this
1339 symbol instead and let fillGaps handle the allocation. */
1340 if (sym->liveFrom < ic->seq)
1346 /* if it has a spillocation & is used less than
1347 all other live ranges then spill this */
1349 if (sym->usl.spillLoc) {
1350 symbol *leastUsed = leastUsedLR (liveRangesWith (spillable,
1351 allLRs, ebbs[i], ic));
1352 if (leastUsed && leastUsed->used > sym->used) {
1357 /* if none of the liveRanges have a spillLocation then better
1358 to spill this one than anything else already assigned to registers */
1359 if (liveRangesWith(spillable,noSpilLoc,ebbs[i],ic)) {
1360 /* if this is local to this block then we might find a block spil */
1361 if (!(sym->liveFrom >= ebbs[i]->fSeq && sym->liveTo <= ebbs[i]->lSeq)) {
1369 /* if we need ptr regs for the right side
1371 if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic))
1372 && getSize (OP_SYMBOL (IC_LEFT (ic))->type)
1373 <= (unsigned) PTRSIZE)
1378 /* else we assign registers to it */
1379 _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
1380 _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, sym->key);
1382 for (j = 0; j < sym->nRegs; j++)
1384 if (sym->regType == REG_PTR)
1385 sym->regs[j] = getRegPtr (ic, ebbs[i], sym);
1387 sym->regs[j] = getRegGpr (ic, ebbs[i], sym);
1389 /* if the allocation falied which means
1390 this was spilt then break */
1395 /* if it shares registers with operands make sure
1396 that they are in the same position */
1397 if (!POINTER_SET(ic) && !POINTER_GET(ic))
1399 if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)) &&
1400 OP_SYMBOL (IC_LEFT (ic))->nRegs)
1402 positionRegs (OP_SYMBOL (IC_RESULT (ic)),
1403 OP_SYMBOL (IC_LEFT (ic)));
1405 /* do the same for the right operand */
1406 if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)) &&
1407 OP_SYMBOL (IC_RIGHT (ic))->nRegs)
1409 positionRegs (OP_SYMBOL (IC_RESULT (ic)),
1410 OP_SYMBOL (IC_RIGHT (ic)));
1422 reassignUnusedLRs(unusedLRs);
1425 /* Check for and fix any problems with uninitialized operands */
1426 for (i = 0; i < count; i++)
1430 if (ebbs[i]->noPath &&
1431 (ebbs[i]->entryLabel != entryLabel &&
1432 ebbs[i]->entryLabel != returnLabel))
1435 for (ic = ebbs[i]->sch; ic; ic = ic->next)
1442 verifyRegsAssigned (IC_COND (ic), ic);
1446 if (ic->op == JUMPTABLE)
1448 verifyRegsAssigned (IC_JTCOND (ic), ic);
1452 verifyRegsAssigned (IC_RESULT (ic), ic);
1453 verifyRegsAssigned (IC_LEFT (ic), ic);
1454 verifyRegsAssigned (IC_RIGHT (ic), ic);
1460 /*-----------------------------------------------------------------*/
1461 /* fillGaps - Try to fill in the Gaps left by Pass1 */
1462 /*-----------------------------------------------------------------*/
1463 static void fillGaps()
1467 int loop = 0, change;
1470 if (getenv("DISABLE_FILL_GAPS")) return;
1472 /* First try to do DPTRuse once more since now we know what got into
1475 while (loop++ < 10) {
1478 for (sym = hTabFirstItem(liveRanges,&key) ; sym ;
1479 sym = hTabNextItem(liveRanges,&key)) {
1480 int size = getSize(sym->type);
1482 if (sym->liveFrom == sym->liveTo) continue;
1484 if (sym->uptr && sym->dptr==0 && !sym->ruonly &&
1485 size < 4 && size > 1) {
1487 if (packRegsDPTRuse(operandFromSymbol(sym))) {
1489 /* if this was ssigned to registers then */
1490 if (bitVectBitValue(_G.totRegAssigned,sym->key)) {
1491 /* take it out of the register assigned set */
1492 bitVectUnSetBit(_G.totRegAssigned,sym->key);
1493 } else if (sym->usl.spillLoc) {
1494 sym->usl.spillLoc->allocreq--;
1495 sym->usl.spillLoc = NULL;
1499 sym->isspilt = sym->spillA = 0;
1503 /* try assigning other dptrs */
1504 if (sym->dptr == 0 && packRegsDPTRnuse(operandFromSymbol(sym),1) && !getenv("DPTRnDISABLE")) {
1505 /* if this was ssigned to registers then */
1506 if (bitVectBitValue(_G.totRegAssigned,sym->key)) {
1507 /* take it out of the register assigned set */
1508 bitVectUnSetBit(_G.totRegAssigned,sym->key);
1509 } else if (sym->usl.spillLoc) {
1510 sym->usl.spillLoc->allocreq--;
1511 sym->usl.spillLoc = NULL;
1514 sym->isspilt = sym->spillA = 0;
1519 /* look for livernages that was spilt by the allocator */
1520 for (sym = hTabFirstItem(liveRanges,&key) ; sym ;
1521 sym = hTabNextItem(liveRanges,&key)) {
1526 if (!sym->spillA || !sym->clashes || sym->remat) continue ;
1527 if (!sym->uses || !sym->defs) continue ;
1528 /* find the liveRanges this one clashes with, that are
1529 still assigned to registers & mark the registers as used*/
1530 for ( i = 0 ; i < sym->clashes->size ; i ++) {
1534 if (bitVectBitValue(sym->clashes,i) == 0 || /* those that clash with this */
1535 bitVectBitValue(_G.totRegAssigned,i) == 0) /* and are still assigned to registers */
1538 clr = hTabItemWithKey(liveRanges,i);
1541 /* mark these registers as used */
1542 for (k = 0 ; k < clr->nRegs ; k++ )
1543 useReg(clr->regs[k]);
1546 if (willCauseSpill(sym->nRegs,sym->regType)) {
1547 /* NOPE :( clear all registers & and continue */
1552 /* THERE IS HOPE !!!! */
1553 for (i=0; i < sym->nRegs ; i++ ) {
1554 if (sym->regType == REG_PTR)
1555 sym->regs[i] = getRegPtrNoSpil ();
1557 sym->regs[i] = getRegGprNoSpil ();
1560 /* For all its definitions check if the registers
1561 allocated needs positioning NOTE: we can position
1562 only ONCE if more than One positioning required
1564 We may need to perform the checks twice; once to
1565 position the registers as needed, the second to
1566 verify any register repositioning is still
1570 for (pass=0; pass<2; pass++) {
1571 for (i = 0 ; i < sym->defs->size ; i++ ) {
1572 if (bitVectBitValue(sym->defs,i)) {
1574 if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ;
1575 if (SKIP_IC(ic)) continue;
1576 assert(isSymbolEqual(sym,OP_SYMBOL(IC_RESULT(ic)))); /* just making sure */
1577 /* if left is assigned to registers */
1578 if (IS_SYMOP(IC_LEFT(ic)) &&
1579 bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_LEFT(ic))->key)) {
1580 pdone += (positionRegs(sym,OP_SYMBOL(IC_LEFT(ic)))>0);
1582 if (IS_SYMOP(IC_RIGHT(ic)) &&
1583 bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RIGHT(ic))->key)) {
1584 pdone += (positionRegs(sym,OP_SYMBOL(IC_RIGHT(ic)))>0);
1586 if (pdone > 1) break;
1589 for (i = 0 ; i < sym->uses->size ; i++ ) {
1590 if (bitVectBitValue(sym->uses,i)) {
1592 if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ;
1593 if (SKIP_IC(ic)) continue;
1594 if (POINTER_SET(ic) || POINTER_GET(ic)) continue ;
1596 /* if result is assigned to registers */
1597 if (IS_SYMOP(IC_RESULT(ic)) &&
1598 bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RESULT(ic))->key)) {
1599 pdone += (positionRegs(sym,OP_SYMBOL(IC_RESULT(ic)))>0);
1601 if (pdone > 1) break;
1604 if (pdone == 0) break; /* second pass only if regs repositioned */
1605 if (pdone > 1) break;
1607 /* had to position more than once GIVE UP */
1609 /* UNDO all the changes we made to try this */
1611 for (i=0; i < sym->nRegs ; i++ ) {
1612 sym->regs[i] = NULL;
1615 D (fprintf (stderr, "Fill Gap gave up due to positioning for "
1616 "%s in function %s\n",
1617 sym->name, currFunc ? currFunc->name : "UNKNOWN"));
1620 D (fprintf (stderr, "FILLED GAP for %s in function %s\n",
1621 sym->name, currFunc ? currFunc->name : "UNKNOWN"));
1622 _G.totRegAssigned = bitVectSetBit(_G.totRegAssigned,sym->key);
1623 sym->isspilt = sym->spillA = 0 ;
1624 sym->usl.spillLoc->allocreq--;
1625 sym->usl.spillLoc = NULL;
1633 /*-----------------------------------------------------------------*/
1634 /* rUmaskForOp :- returns register mask for an operand */
1635 /*-----------------------------------------------------------------*/
1637 ds390_rUmaskForOp (operand * op)
1643 /* only temporaries are assigned registers */
1647 sym = OP_SYMBOL (op);
1649 /* if spilt or no registers assigned to it
1651 if (sym->isspilt || !sym->nRegs)
1654 rumask = newBitVect (ds390_nRegs);
1656 for (j = 0; j < sym->nRegs; j++)
1658 rumask = bitVectSetBit (rumask,
1659 sym->regs[j]->rIdx);
1665 /*-----------------------------------------------------------------*/
1666 /* regsUsedIniCode :- returns bit vector of registers used in iCode */
1667 /*-----------------------------------------------------------------*/
1669 regsUsedIniCode (iCode * ic)
1671 bitVect *rmask = newBitVect (ds390_nRegs);
1673 /* do the special cases first */
1676 rmask = bitVectUnion (rmask,
1677 ds390_rUmaskForOp (IC_COND (ic)));
1681 /* for the jumptable */
1682 if (ic->op == JUMPTABLE)
1684 rmask = bitVectUnion (rmask,
1685 ds390_rUmaskForOp (IC_JTCOND (ic)));
1690 /* of all other cases */
1692 rmask = bitVectUnion (rmask,
1693 ds390_rUmaskForOp (IC_LEFT (ic)));
1697 rmask = bitVectUnion (rmask,
1698 ds390_rUmaskForOp (IC_RIGHT (ic)));
1701 rmask = bitVectUnion (rmask,
1702 ds390_rUmaskForOp (IC_RESULT (ic)));
1708 /*-----------------------------------------------------------------*/
1709 /* createRegMask - for each instruction will determine the regsUsed */
1710 /*-----------------------------------------------------------------*/
1712 createRegMask (eBBlock ** ebbs, int count)
1716 /* for all blocks */
1717 for (i = 0; i < count; i++)
1721 if (ebbs[i]->noPath &&
1722 (ebbs[i]->entryLabel != entryLabel &&
1723 ebbs[i]->entryLabel != returnLabel))
1726 /* for all instructions */
1727 for (ic = ebbs[i]->sch; ic; ic = ic->next)
1732 if (SKIP_IC2 (ic) || !ic->rlive)
1735 /* first mark the registers used in this
1737 ic->rUsed = regsUsedIniCode (ic);
1738 _G.funcrUsed = bitVectUnion (_G.funcrUsed, ic->rUsed);
1740 /* now create the register mask for those
1741 registers that are in use : this is a
1742 super set of ic->rUsed */
1743 ic->rMask = newBitVect (ds390_nRegs + 1);
1745 /* for all live Ranges alive at this point */
1746 for (j = 1; j < ic->rlive->size; j++)
1751 /* if not alive then continue */
1752 if (!bitVectBitValue (ic->rlive, j))
1755 /* find the live range we are interested in */
1756 if (!(sym = hTabItemWithKey (liveRanges, j)))
1758 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
1759 "createRegMask cannot find live range");
1763 /* special case for ruonly */
1764 if (sym->ruonly && sym->liveFrom != sym->liveTo) {
1765 int size = getSize(sym->type);
1767 for (k = 0 ; k < size; k++ )
1768 ic->rMask = bitVectSetBit (ic->rMask, j++);
1772 /* if no register assigned to it */
1773 if (!sym->nRegs || sym->isspilt)
1776 /* for all the registers allocated to it */
1777 for (k = 0; k < sym->nRegs; k++)
1780 bitVectSetBit (ic->rMask, sym->regs[k]->rIdx);
1786 /*-----------------------------------------------------------------*/
1787 /* rematStr - returns the rematerialized string for a remat var */
1788 /*-----------------------------------------------------------------*/
1790 rematStr (symbol * sym)
1793 iCode *ic = sym->rematiCode;
1800 /* if plus or minus print the right hand side */
1801 if (ic->op == '+' || ic->op == '-')
1803 SNPRINTF (s, sizeof(buffer) - strlen(buffer),
1804 "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)),
1807 ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
1810 /* cast then continue */
1811 if (IS_CAST_ICODE(ic)) {
1812 ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
1815 /* we reached the end */
1816 SNPRINTF (s, sizeof(buffer) - strlen(buffer),
1817 "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
1824 /*-----------------------------------------------------------------*/
1825 /* regTypeNum - computes the type & number of registers required */
1826 /*-----------------------------------------------------------------*/
1834 /* for each live range do */
1835 for (sym = hTabFirstItem (liveRanges, &k); sym;
1836 sym = hTabNextItem (liveRanges, &k))
1839 /* if used zero times then no registers needed */
1840 if ((sym->liveTo - sym->liveFrom) == 0)
1844 /* if the live range is a temporary */
1848 /* if the type is marked as a conditional */
1849 if (sym->regType == REG_CND)
1852 /* if used in return only then we don't
1854 if (sym->ruonly || sym->accuse)
1856 if (IS_AGGREGATE (sym->type) || sym->isptr)
1857 sym->type = aggrToPtr (sym->type, FALSE);
1861 /* if the symbol has only one definition &
1862 that definition is a get_pointer */
1863 if (bitVectnBitsOn (sym->defs) == 1 &&
1864 (ic = hTabItemWithKey (iCodehTab,
1865 bitVectFirstBit (sym->defs))) &&
1867 !IS_BITVAR (sym->etype) &&
1868 (aggrToPtrDclType (operandType (IC_LEFT (ic)), FALSE) == POINTER))
1871 if (ptrPseudoSymSafe (sym, ic))
1873 ptrPseudoSymConvert (sym, ic, rematStr (OP_SYMBOL (IC_LEFT (ic))));
1877 /* if in data space or idata space then try to
1878 allocate pointer register */
1882 /* if not then we require registers */
1883 sym->nRegs = ((IS_AGGREGATE (sym->type) || sym->isptr) ?
1884 getSize (sym->type = aggrToPtr (sym->type, FALSE)) :
1885 getSize (sym->type));
1889 fprintf (stderr, "allocated more than 4 or 0 registers for type ");
1890 printTypeChain (sym->type, stderr);
1891 fprintf (stderr, "\n");
1894 /* determine the type of register required */
1895 if (sym->nRegs == 1 &&
1896 IS_PTR (sym->type) &&
1898 sym->regType = REG_PTR;
1900 sym->regType = REG_GPR;
1904 /* for the first run we don't provide */
1905 /* registers for true symbols we will */
1906 /* see how things go */
1912 /*-----------------------------------------------------------------*/
1913 /* freeAllRegs - mark all registers as free */
1914 /*-----------------------------------------------------------------*/
1920 for (i = 0; i < ds390_nRegs; i++)
1921 regs390[i].isFree = 1;
1924 /*-----------------------------------------------------------------*/
1925 /* deallocStackSpil - this will set the stack pointer back */
1926 /*-----------------------------------------------------------------*/
1928 DEFSETFUNC (deallocStackSpil)
1936 /*-----------------------------------------------------------------*/
1937 /* farSpacePackable - returns the packable icode for far variables */
1938 /*-----------------------------------------------------------------*/
1940 farSpacePackable (iCode * ic)
1944 /* go thru till we find a definition for the
1945 symbol on the right */
1946 for (dic = ic->prev; dic; dic = dic->prev)
1949 /* if the definition is a call then no */
1950 if ((dic->op == CALL || dic->op == PCALL) &&
1951 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
1956 /* if shift by unknown amount then not */
1957 if ((dic->op == LEFT_OP || dic->op == RIGHT_OP) &&
1958 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
1961 /* if pointer get and size > 1 */
1962 if (POINTER_GET (dic) &&
1963 getSize (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)) > 1)
1966 if (POINTER_SET (dic) &&
1967 getSize (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)) > 1)
1970 /* if any three is a true symbol in far space */
1971 if (IC_RESULT (dic) &&
1972 IS_TRUE_SYMOP (IC_RESULT (dic)) &&
1973 isOperandInFarSpace (IC_RESULT (dic)))
1976 if (IC_RIGHT (dic) &&
1977 IS_TRUE_SYMOP (IC_RIGHT (dic)) &&
1978 isOperandInFarSpace (IC_RIGHT (dic)) &&
1979 !isOperandEqual (IC_RIGHT (dic), IC_RESULT (ic)))
1982 if (IC_LEFT (dic) &&
1983 IS_TRUE_SYMOP (IC_LEFT (dic)) &&
1984 isOperandInFarSpace (IC_LEFT (dic)) &&
1985 !isOperandEqual (IC_LEFT (dic), IC_RESULT (ic)))
1988 if (isOperandEqual (IC_RIGHT (ic), IC_RESULT (dic)))
1990 if ((dic->op == LEFT_OP ||
1991 dic->op == RIGHT_OP ||
1993 IS_OP_LITERAL (IC_RIGHT (dic)))
2003 /*-----------------------------------------------------------------*/
2004 /* packRegsForAssign - register reduction for assignment */
2005 /*-----------------------------------------------------------------*/
2007 packRegsForAssign (iCode * ic, eBBlock * ebp)
2011 if (!IS_ITEMP (IC_RIGHT (ic)) ||
2012 OP_SYMBOL (IC_RIGHT (ic))->isind ||
2013 OP_LIVETO (IC_RIGHT (ic)) > ic->seq)
2018 /* if the true symbol is defined in far space or on stack
2019 then we should not since this will increase register pressure */
2021 if (isOperandInFarSpace (IC_RESULT (ic)))
2023 if ((dic = farSpacePackable (ic)))
2029 if (isOperandInFarSpace(IC_RESULT(ic)) && !farSpacePackable(ic)) {
2034 /* find the definition of iTempNN scanning backwards if we find a
2035 a use of the true symbol in before we find the definition then
2037 for (dic = ic->prev; dic; dic = dic->prev)
2039 /* if there is a function call then don't pack it */
2040 if ((dic->op == CALL || dic->op == PCALL))
2049 if (IS_TRUE_SYMOP (IC_RESULT (dic)) &&
2050 IS_OP_VOLATILE (IC_RESULT (dic)))
2056 if (IS_SYMOP (IC_RESULT (dic)) &&
2057 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
2059 if (POINTER_SET (dic))
2065 if (IS_SYMOP (IC_RIGHT (dic)) &&
2066 (IC_RIGHT (dic)->key == IC_RESULT (ic)->key ||
2067 IC_RIGHT (dic)->key == IC_RIGHT (ic)->key))
2073 if (IS_SYMOP (IC_LEFT (dic)) &&
2074 (IC_LEFT (dic)->key == IC_RESULT (ic)->key ||
2075 IC_LEFT (dic)->key == IC_RIGHT (ic)->key))
2081 if (POINTER_SET (dic) &&
2082 IC_RESULT (dic)->key == IC_RESULT (ic)->key)
2090 return 0; /* did not find */
2092 /* if the result is on stack or iaccess then it must be
2093 the same atleast one of the operands */
2094 if (OP_SYMBOL (IC_RESULT (ic))->onStack ||
2095 OP_SYMBOL (IC_RESULT (ic))->iaccess)
2098 /* the operation has only one symbol
2099 operator then we can pack */
2100 if ((IC_LEFT (dic) && !IS_SYMOP (IC_LEFT (dic))) ||
2101 (IC_RIGHT (dic) && !IS_SYMOP (IC_RIGHT (dic))))
2104 if (!((IC_LEFT (dic) &&
2105 IC_RESULT (ic)->key == IC_LEFT (dic)->key) ||
2107 IC_RESULT (ic)->key == IC_RIGHT (dic)->key)))
2111 /* found the definition */
2112 /* replace the result with the result of */
2113 /* this assignment and remove this assignment */
2114 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
2116 IC_RESULT (dic) = IC_RESULT (ic);
2118 if (IS_ITEMP (IC_RESULT (dic)) && OP_SYMBOL (IC_RESULT (dic))->liveFrom > dic->seq)
2120 OP_SYMBOL (IC_RESULT (dic))->liveFrom = dic->seq;
2122 /* delete from liverange table also
2123 delete from all the points inbetween and the new
2125 for (sic = dic; sic != ic; sic = sic->next)
2127 bitVectUnSetBit (sic->rlive, IC_RESULT (ic)->key);
2128 if (IS_ITEMP (IC_RESULT (dic)))
2129 bitVectSetBit (sic->rlive, IC_RESULT (dic)->key);
2132 remiCodeFromeBBlock (ebp, ic);
2133 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
2134 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
2135 OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
2140 /*-----------------------------------------------------------------*/
2141 /* findAssignToSym : scanning backwards looks for first assig found */
2142 /*-----------------------------------------------------------------*/
2144 findAssignToSym (operand * op, iCode * ic)
2148 for (dic = ic->prev; dic; dic = dic->prev)
2151 /* if definition by assignment */
2152 if (dic->op == '=' &&
2153 !POINTER_SET (dic) &&
2154 IC_RESULT (dic)->key == op->key
2155 /* && IS_TRUE_SYMOP(IC_RIGHT(dic)) */
2159 /* we are interested only if defined in far space */
2160 /* or in stack space in case of + & - */
2162 /* if assigned to a non-symbol then return
2164 if (!IS_SYMOP (IC_RIGHT (dic)))
2167 /* if the symbol is in far space then
2169 if (isOperandInFarSpace (IC_RIGHT (dic)))
2172 /* for + & - operations make sure that
2173 if it is on the stack it is the same
2174 as one of the three operands */
2175 if ((ic->op == '+' || ic->op == '-') &&
2176 OP_SYMBOL (IC_RIGHT (dic))->onStack)
2179 if (IC_RESULT (ic)->key != IC_RIGHT (dic)->key &&
2180 IC_LEFT (ic)->key != IC_RIGHT (dic)->key &&
2181 IC_RIGHT (ic)->key != IC_RIGHT (dic)->key)
2189 /* if we find an usage then we cannot delete it */
2190 if (IC_LEFT (dic) && IC_LEFT (dic)->key == op->key)
2193 if (IC_RIGHT (dic) && IC_RIGHT (dic)->key == op->key)
2196 if (POINTER_SET (dic) && IC_RESULT (dic)->key == op->key)
2200 /* now make sure that the right side of dic
2201 is not defined between ic & dic */
2204 iCode *sic = dic->next;
2206 for (; sic != ic; sic = sic->next)
2207 if (IC_RESULT (sic) &&
2208 IC_RESULT (sic)->key == IC_RIGHT (dic)->key)
2217 /*-----------------------------------------------------------------*/
2218 /* packRegsForSupport :- reduce some registers for support calls */
2219 /*-----------------------------------------------------------------*/
2221 packRegsForSupport (iCode * ic, eBBlock * ebp)
2225 /* for the left & right operand :- look to see if the
2226 left was assigned a true symbol in far space in that
2227 case replace them */
2228 if (IS_ITEMP (IC_LEFT (ic)) &&
2229 OP_SYMBOL (IC_LEFT (ic))->liveTo <= ic->seq)
2231 iCode *dic = findAssignToSym (IC_LEFT (ic), ic);
2237 /* found it we need to remove it from the
2239 for (sic = dic; sic != ic; sic = sic->next) {
2240 bitVectUnSetBit (sic->rlive, IC_LEFT (ic)->key);
2241 sic->rlive = bitVectSetBit (sic->rlive, IC_RIGHT (dic)->key);
2244 wassert(IS_SYMOP(IC_LEFT (ic)));
2245 wassert(IS_SYMOP(IC_RIGHT (dic)));
2246 IC_LEFT (ic)->operand.symOperand =
2247 IC_RIGHT (dic)->operand.symOperand;
2248 OP_SYMBOL(IC_LEFT(ic))->liveTo = ic->seq;
2249 IC_LEFT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
2250 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
2251 remiCodeFromeBBlock (ebp, dic);
2252 hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
2256 /* do the same for the right operand */
2259 IS_ITEMP (IC_RIGHT (ic)) &&
2260 OP_SYMBOL (IC_RIGHT (ic))->liveTo <= ic->seq)
2262 iCode *dic = findAssignToSym (IC_RIGHT (ic), ic);
2268 /* if this is a subtraction & the result
2269 is a true symbol in far space then don't pack */
2270 if (ic->op == '-' && IS_TRUE_SYMOP (IC_RESULT (dic)))
2272 sym_link *etype = getSpec (operandType (IC_RESULT (dic)));
2273 if (IN_FARSPACE (SPEC_OCLS (etype)))
2276 /* found it we need to remove it from the
2278 for (sic = dic; sic != ic; sic = sic->next) {
2279 bitVectUnSetBit (sic->rlive, IC_RIGHT (ic)->key);
2280 sic->rlive = bitVectSetBit (sic->rlive, IC_RIGHT (dic)->key);
2283 wassert(IS_SYMOP(IC_RIGHT (ic)));
2284 wassert(IS_SYMOP(IC_RIGHT (dic)));
2285 IC_RIGHT (ic)->operand.symOperand =
2286 IC_RIGHT (dic)->operand.symOperand;
2287 IC_RIGHT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
2288 OP_SYMBOL(IC_RIGHT(ic))->liveTo = ic->seq;
2289 remiCodeFromeBBlock (ebp, dic);
2290 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
2291 hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
2298 #define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
2301 /*-----------------------------------------------------------------*/
2302 /* packRegsDPTRnuse - color live ranges that can go into extra DPTRS */
2303 /*-----------------------------------------------------------------*/
2304 static int packRegsDPTRnuse( operand *op , int dptr)
2309 if (!IS_SYMOP(op) || !IS_ITEMP(op)) return 0;
2310 if (OP_SYMBOL(op)->remat || OP_SYMBOL(op)->ruonly || OP_SYMBOL(op)->dptr)
2313 /* first check if any overlapping liverange has already been
2314 assigned to this DPTR */
2315 if (OP_SYMBOL(op)->clashes) {
2316 for (i = 0 ; i < OP_SYMBOL(op)->clashes->size ; i++ ) {
2318 if (bitVectBitValue(OP_SYMBOL(op)->clashes,i)) {
2319 sym = hTabItemWithKey(liveRanges,i);
2320 if (sym->dptr == dptr) return 0;
2325 /* future for more dptrs */
2327 OP_SYMBOL(op)->dptr = dptr;
2331 /* DPTR1 is special since it is also used as a scratch by the backend .
2332 so we walk thru the entire live range of this operand and make sure
2333 DPTR1 will not be used by the backed . The logic here is to find out if
2334 more than one operand in an icode is in far space then we give up : we
2335 don't keep it live across functions for now
2338 ic = hTabFirstItemWK(iCodeSeqhTab,OP_SYMBOL(op)->liveFrom);
2339 for (; ic && ic->seq <= OP_SYMBOL(op)->liveTo;
2340 ic = hTabNextItem(iCodeSeqhTab,&key)) {
2343 if (ic->op == CALL || ic->op == PCALL) return 0;
2345 /* single operand icode are ok */
2346 if (ic->op == IFX || ic->op == IPUSH)
2349 if (ic->op == SEND ) {
2350 if (ic->argreg != 1 ) return 0;
2353 /* two special cases first */
2354 if (POINTER_GET(ic) && !isOperandEqual(IC_LEFT(ic),op) && /* pointer get */
2355 !OP_SYMBOL(IC_LEFT(ic))->ruonly && /* with result in far space */
2356 (isOperandInFarSpace(IC_RESULT(ic)) &&
2357 !isOperandInReg(IC_RESULT(ic)))) {
2361 if (POINTER_SET(ic) && !isOperandEqual(IC_RESULT(ic),op) && /* pointer set */
2362 !OP_SYMBOL(IC_RESULT(ic))->ruonly && /* with right in far space */
2363 (isOperandInFarSpace(IC_RIGHT(ic)) &&
2364 !isOperandInReg(IC_RIGHT(ic)))) {
2368 if (IC_RESULT(ic) && IS_SYMOP(IC_RESULT(ic)) && /* if symbol operand */
2369 !isOperandEqual(IC_RESULT(ic),op) && /* not the same as this */
2370 ((isOperandInFarSpace(IC_RESULT(ic)) || /* in farspace or */
2371 OP_SYMBOL(IC_RESULT(ic))->onStack) && /* on the stack */
2372 !isOperandInReg(IC_RESULT(ic)))) { /* and not in register */
2376 if (IC_LEFT(ic) && IS_SYMOP(IC_LEFT(ic)) && /* if symbol operand */
2377 !isOperandEqual(IC_LEFT(ic),op) && /* not the same as this */
2378 ((isOperandInFarSpace(IC_LEFT(ic)) || /* in farspace or */
2379 OP_SYMBOL(IC_LEFT(ic))->onStack) && /* on the stack */
2380 !isOperandInReg(IC_LEFT(ic)))) { /* and not in register */
2383 /* same for right */
2384 if (IC_RIGHT(ic) && IS_SYMOP(IC_RIGHT(ic)) && /* if symbol operand */
2385 !isOperandEqual(IC_RIGHT(ic),op) && /* not the same as this */
2386 ((isOperandInFarSpace(IC_RIGHT(ic)) || /* in farspace or */
2387 OP_SYMBOL(IC_RIGHT(ic))->onStack) && /* on the stack */
2388 !isOperandInReg(IC_RIGHT(ic)))) { /* and not in register */
2392 // Check that no other ops in this range have been assigned to dptr1.
2393 // I don't understand why this is not caught by the first check, above.
2394 // But it isn't always, see bug 769624.
2395 if (IC_RESULT(ic) && IS_SYMOP(IC_RESULT(ic)) &&
2396 (OP_SYMBOL(IC_RESULT(ic))->dptr == 1))
2398 //fprintf(stderr, "dptr1 already in use in live range #1\n");
2402 if (IC_LEFT(ic) && IS_SYMOP(IC_LEFT(ic)) &&
2403 (OP_SYMBOL(IC_LEFT(ic))->dptr == 1))
2405 //fprintf(stderr, "dptr1 already in use in live range # 2\n");
2409 if (IC_RIGHT(ic) && IS_SYMOP(IC_RIGHT(ic)) &&
2410 (OP_SYMBOL(IC_RIGHT(ic))->dptr == 1))
2412 //fprintf(stderr, "dptr1 already in use in live range # 3\n");
2416 if (nfs && IC_RESULT(ic) && IS_SYMOP(IC_RESULT(ic)) &&
2417 OP_SYMBOL(IC_RESULT(ic))->ruonly) return 0;
2419 if (nfs > 1) return 0;
2421 OP_SYMBOL(op)->dptr = dptr;
2425 /*-----------------------------------------------------------------*/
2426 /* packRegsDPTRuse : - will reduce some registers for single Use */
2427 /*-----------------------------------------------------------------*/
2429 packRegsDPTRuse (operand * op)
2431 /* go thru entire liveRange of this variable & check for
2432 other possible usage of DPTR , if we don't find it the
2433 assign this to DPTR (ruonly)
2438 sym_link *type, *etype;
2440 if (!IS_SYMOP(op) || !IS_ITEMP(op)) return NULL;
2441 if (OP_SYMBOL(op)->remat || OP_SYMBOL(op)->ruonly) return NULL;
2443 /* first check if any overlapping liverange has already been
2445 if (OP_SYMBOL(op)->clashes) {
2446 for (i = 0 ; i < OP_SYMBOL(op)->clashes->size ; i++ ) {
2447 if (bitVectBitValue(OP_SYMBOL(op)->clashes,i)) {
2448 sym = hTabItemWithKey(liveRanges,i);
2449 if (sym->ruonly) return NULL ;
2454 /* no then go thru this guys live range */
2455 dic = ic = hTabFirstItemWK(iCodeSeqhTab,OP_SYMBOL(op)->liveFrom);
2456 for (; ic && ic->seq <= OP_SYMBOL(op)->liveTo;
2457 ic = hTabNextItem(iCodeSeqhTab,&key)) {
2459 if (SKIP_IC3(ic)) continue;
2461 /* if PCALL cannot be sure give up */
2462 if (ic->op == PCALL) return NULL;
2464 /* if SEND & not the first parameter then giveup */
2465 if (ic->op == SEND && ic->argreg != 1 &&
2466 ((isOperandInFarSpace(IC_LEFT(ic)) && !isOperandInReg(IC_LEFT(ic))) ||
2467 isOperandEqual(op,IC_LEFT(ic)))) return NULL;
2469 /* if CALL then make sure it is VOID || return value not used
2470 or the return value is assigned to this one */
2471 if (ic->op == CALL) {
2472 if (OP_SYMBOL(IC_RESULT(ic))->liveTo ==
2473 OP_SYMBOL(IC_RESULT(ic))->liveFrom) continue ;
2474 etype = getSpec(type = operandType(IC_RESULT(ic)));
2475 if (getSize(type) == 0 || isOperandEqual(op,IC_RESULT(ic)))
2480 /* special case of add with a [remat] */
2481 if (ic->op == '+' &&
2482 OP_SYMBOL(IC_LEFT(ic))->remat &&
2483 (isOperandInFarSpace(IC_RIGHT(ic)) &&
2484 !isOperandInReg(IC_RIGHT(ic)))) return NULL ;
2488 if (POINTER_GET(ic) && !isOperandEqual(IC_LEFT(ic),op) &&
2489 getSize(operandType(IC_LEFT(ic))) > 1 ) return NULL ;
2492 if (POINTER_SET(ic) && !isOperandEqual(IC_RESULT(ic),op) &&
2493 getSize(operandType(IC_RESULT(ic))) > 1 ) return NULL;
2495 /* conditionals can destroy 'b' - make sure B wont
2496 be used in this one*/
2497 if ((IS_CONDITIONAL(ic) || ic->op == '*' || ic->op == '/' ||
2498 ic->op == LEFT_OP || ic->op == RIGHT_OP ) &&
2499 getSize(operandType(op)) > 3) return NULL;
2501 /* if this is a cast to a bigger type */
2503 if (!IS_PTR(OP_SYM_TYPE(IC_RESULT(ic))) &&
2504 getSize(OP_SYM_TYPE(IC_RESULT(ic))) >
2505 getSize(OP_SYM_TYPE(IC_RIGHT(ic)))) {
2511 if (IC_RESULT(ic) && IS_SYMOP(IC_RESULT(ic)) &&
2512 !isOperandEqual(IC_RESULT(ic),op) &&
2513 ( ( ( isOperandInFarSpace(IC_RESULT(ic)) || OP_SYMBOL(IC_RESULT(ic))->onStack) &&
2514 !isOperandInReg(IC_RESULT(ic))) ||
2515 OP_SYMBOL(IC_RESULT(ic))->ruonly)) return NULL;
2517 if (IC_RIGHT(ic) && IS_SYMOP(IC_RIGHT(ic)) &&
2518 !isOperandEqual(IC_RIGHT(ic),op) &&
2519 (OP_SYMBOL(IC_RIGHT(ic))->liveTo >= ic->seq ||
2520 IS_TRUE_SYMOP(IC_RIGHT(ic)) ||
2521 OP_SYMBOL(IC_RIGHT(ic))->ruonly) &&
2522 ( ( isOperandInFarSpace(IC_RIGHT(ic)) || OP_SYMBOL(IC_RIGHT(ic))->onStack) &&
2523 !isOperandInReg(IC_RIGHT(ic))) ) return NULL;
2525 if (IC_LEFT(ic) && IS_SYMOP(IC_LEFT(ic)) &&
2526 !isOperandEqual(IC_LEFT(ic),op) &&
2527 (OP_SYMBOL(IC_LEFT(ic))->liveTo >= ic->seq ||
2528 IS_TRUE_SYMOP(IC_LEFT(ic)) ||
2529 OP_SYMBOL(IC_LEFT(ic))->ruonly) &&
2530 ( ( isOperandInFarSpace(IC_LEFT(ic)) || OP_SYMBOL(IC_LEFT(ic))->onStack) &&
2531 !isOperandInReg(IC_LEFT(ic))) ) return NULL;
2533 if (IC_LEFT(ic) && IC_RIGHT(ic) &&
2534 IS_ITEMP(IC_LEFT(ic)) && IS_ITEMP(IC_RIGHT(ic)) &&
2535 (isOperandInFarSpace(IC_LEFT(ic)) && !isOperandInReg(IC_LEFT(ic))) &&
2536 (isOperandInFarSpace(IC_RIGHT(ic)) && !isOperandInReg(IC_RIGHT(ic))))
2539 OP_SYMBOL(op)->ruonly = 1;
2540 if (OP_SYMBOL(op)->usl.spillLoc) {
2541 if (OP_SYMBOL(op)->spillA)
2542 OP_SYMBOL(op)->usl.spillLoc->allocreq--;
2543 OP_SYMBOL(op)->usl.spillLoc = NULL;
2548 /*-----------------------------------------------------------------*/
2549 /* isBitwiseOptimizable - requirements of JEAN LOUIS VERN */
2550 /*-----------------------------------------------------------------*/
2552 isBitwiseOptimizable (iCode * ic)
2554 sym_link *ltype = getSpec (operandType (IC_LEFT (ic)));
2555 sym_link *rtype = getSpec (operandType (IC_RIGHT (ic)));
2557 /* bitwise operations are considered optimizable
2558 under the following conditions (Jean-Louis VERN)
2570 if ( IS_LITERAL (rtype) ||
2571 (IS_BITVAR (ltype) && IN_BITSPACE (SPEC_OCLS (ltype))))
2577 /*-----------------------------------------------------------------*/
2578 /* packRegsForAccUse - pack registers for acc use */
2579 /*-----------------------------------------------------------------*/
2581 packRegsForAccUse (iCode * ic)
2585 /* if this is an aggregate, e.g. a one byte char array */
2586 if (IS_AGGREGATE(operandType(IC_RESULT(ic)))) {
2590 /* if we are calling a reentrant function that has stack parameters */
2591 if (ic->op == CALL &&
2592 IFFUNC_ISREENT(operandType(IC_LEFT(ic))) &&
2593 FUNC_HASSTACKPARM(operandType(IC_LEFT(ic))))
2596 if (ic->op == PCALL &&
2597 IFFUNC_ISREENT(operandType(IC_LEFT(ic))->next) &&
2598 FUNC_HASSTACKPARM(operandType(IC_LEFT(ic))->next))
2601 /* if + or - then it has to be one byte result */
2602 if ((ic->op == '+' || ic->op == '-')
2603 && getSize (operandType (IC_RESULT (ic))) > 1)
2606 /* if shift operation make sure right side is not a literal */
2607 if (ic->op == RIGHT_OP &&
2608 (isOperandLiteral (IC_RIGHT (ic)) ||
2609 getSize (operandType (IC_RESULT (ic))) > 1))
2612 if (ic->op == LEFT_OP &&
2613 (isOperandLiteral (IC_RIGHT (ic)) ||
2614 getSize (operandType (IC_RESULT (ic))) > 1))
2617 if (IS_BITWISE_OP (ic) &&
2618 getSize (operandType (IC_RESULT (ic))) > 1)
2622 /* has only one definition */
2623 if (bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) > 1)
2626 /* has only one use */
2627 if (bitVectnBitsOn (OP_USES (IC_RESULT (ic))) > 1)
2630 /* and the usage immediately follows this iCode */
2631 if (!(uic = hTabItemWithKey (iCodehTab,
2632 bitVectFirstBit (OP_USES (IC_RESULT (ic))))))
2635 if (ic->next != uic)
2638 /* if it is a conditional branch then we definitely can */
2642 if (uic->op == JUMPTABLE)
2645 /* if the usage is not is an assignment
2646 or an arithmetic / bitwise / shift operation then not */
2647 if (POINTER_SET (uic) &&
2648 getSize (aggrToPtr (operandType (IC_RESULT (uic)), FALSE)) > 1)
2651 if (uic->op != '=' &&
2652 !IS_ARITHMETIC_OP (uic) &&
2653 !IS_BITWISE_OP (uic) &&
2654 uic->op != LEFT_OP &&
2655 uic->op != RIGHT_OP)
2658 /* if used in ^ operation then make sure right is not a
2660 if (uic->op == '^' && isOperandLiteral (IC_RIGHT (uic)))
2663 /* if shift operation make sure right side is not a literal */
2664 if (uic->op == RIGHT_OP &&
2665 (isOperandLiteral (IC_RIGHT (uic)) ||
2666 getSize (operandType (IC_RESULT (uic))) > 1))
2669 if (uic->op == LEFT_OP &&
2670 (isOperandLiteral (IC_RIGHT (uic)) ||
2671 getSize (operandType (IC_RESULT (uic))) > 1))
2674 /* make sure that the result of this icode is not on the
2675 stack, since acc is used to compute stack offset */
2676 if (isOperandOnStack(IC_RESULT(uic)))
2679 /* if either one of them in far space then we cannot */
2680 if ((IS_TRUE_SYMOP (IC_LEFT (uic)) &&
2681 isOperandInFarSpace (IC_LEFT (uic))) ||
2682 (IS_TRUE_SYMOP (IC_RIGHT (uic)) &&
2683 isOperandInFarSpace (IC_RIGHT (uic))))
2686 /* if the usage has only one operand then we can */
2687 if (IC_LEFT (uic) == NULL ||
2688 IC_RIGHT (uic) == NULL)
2691 /* make sure this is on the left side if not
2692 a '+' since '+' is commutative */
2693 if (ic->op != '+' &&
2694 IC_LEFT (uic)->key != IC_RESULT (ic)->key)
2697 /* if the other one is not on stack then we can */
2698 if (IC_LEFT (uic)->key == IC_RESULT (ic)->key &&
2699 (IS_ITEMP (IC_RIGHT (uic)) ||
2700 (IS_TRUE_SYMOP (IC_RIGHT (uic)) &&
2701 !OP_SYMBOL (IC_RIGHT (uic))->onStack)))
2704 if (IC_RIGHT (uic)->key == IC_RESULT (ic)->key &&
2705 (IS_ITEMP (IC_LEFT (uic)) ||
2706 (IS_TRUE_SYMOP (IC_LEFT (uic)) &&
2707 !OP_SYMBOL (IC_LEFT (uic))->onStack)))
2713 OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
2718 /*-----------------------------------------------------------------*/
2719 /* packForPush - hueristics to reduce iCode for pushing */
2720 /*-----------------------------------------------------------------*/
2722 packForPush (iCode * ic, eBBlock * ebp)
2727 if ((ic->op != IPUSH && ic->op != SEND) || !IS_ITEMP (IC_LEFT (ic)))
2730 /* must have only definition & one usage */
2731 if (bitVectnBitsOn (OP_DEFS (IC_LEFT (ic))) != 1 ||
2732 bitVectnBitsOn (OP_USES (IC_LEFT (ic))) != 1)
2735 /* find the definition */
2736 if (!(dic = hTabItemWithKey (iCodehTab,
2737 bitVectFirstBit (OP_DEFS (IC_LEFT (ic))))))
2740 if (dic->op != '=' || POINTER_SET (dic))
2743 if (dic->eBBlockNum != ic->eBBlockNum) return ;
2745 /* make sure the right side does not have any definitions
2747 dbv = OP_DEFS(IC_RIGHT(dic));
2748 for (lic = ic; lic && lic != dic ; lic = lic->prev) {
2749 if (bitVectBitValue(dbv,lic->key)) return ;
2751 /* make sure they have the same type */
2752 if (IS_SPEC(operandType(IC_LEFT(ic))))
2754 sym_link *itype=operandType(IC_LEFT(ic));
2755 sym_link *ditype=operandType(IC_RIGHT(dic));
2757 if (SPEC_USIGN(itype)!=SPEC_USIGN(ditype) ||
2758 SPEC_LONG(itype)!=SPEC_LONG(ditype))
2761 /* extend the live range of replaced operand if needed */
2762 if (OP_SYMBOL(IC_RIGHT(dic))->liveTo < OP_SYMBOL(IC_LEFT(ic))->liveTo) {
2763 OP_SYMBOL(IC_RIGHT(dic))->liveTo = OP_SYMBOL(IC_LEFT(ic))->liveTo;
2764 OP_SYMBOL(IC_RIGHT(dic))->clashes =
2765 bitVectUnion(OP_SYMBOL(IC_RIGHT(dic))->clashes,
2766 OP_SYMBOL(IC_LEFT(ic))->clashes);
2768 for (lic = ic; lic && lic != dic; lic = lic->prev)
2770 bitVectUnSetBit (lic->rlive, IC_LEFT (ic)->key);
2771 if (IS_ITEMP (IC_RIGHT (dic)))
2772 bitVectSetBit (lic->rlive, IC_RIGHT (dic)->key);
2774 /* we now we know that it has one & only one def & use
2775 and the that the definition is an assignment */
2776 IC_LEFT (ic) = IC_RIGHT (dic);
2778 remiCodeFromeBBlock (ebp, dic);
2779 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
2780 hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
2783 /*-----------------------------------------------------------------*/
2784 /* packRegisters - does some transformations to reduce register */
2786 /*-----------------------------------------------------------------*/
2788 packRegisters (eBBlock * ebp)
2798 /* look for assignments of the form */
2799 /* iTempNN = TRueSym (someoperation) SomeOperand */
2801 /* TrueSym := iTempNN:1 */
2802 for (ic = ebp->sch; ic; ic = ic->next)
2806 /* find assignment of the form TrueSym := iTempNN:1 */
2807 if (ic->op == '=' && !POINTER_SET (ic))
2808 change += packRegsForAssign (ic, ebp);
2815 for (ic = ebp->sch; ic; ic = ic->next)
2818 /* if this is an itemp & result of a address of a true sym
2819 then mark this as rematerialisable */
2820 if (ic->op == ADDRESS_OF &&
2821 IS_ITEMP (IC_RESULT (ic)) &&
2822 IS_TRUE_SYMOP (IC_LEFT (ic)) &&
2823 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
2824 !OP_SYMBOL (IC_LEFT (ic))->onStack)
2827 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
2828 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
2829 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
2833 /* if this is an itemp & used as a pointer
2834 & assigned to a literal then remat */
2835 if (IS_ASSIGN_ICODE(ic) &&
2836 IS_ITEMP(IC_RESULT(ic)) &&
2837 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
2838 isOperandLiteral(IC_RIGHT(ic)))
2840 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
2841 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
2842 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
2845 /* if straight assignment then carry remat flag if
2846 this is the only definition */
2847 if (ic->op == '=' &&
2848 !POINTER_SET (ic) &&
2849 IS_SYMOP (IC_RIGHT (ic)) &&
2850 OP_SYMBOL (IC_RIGHT (ic))->remat &&
2851 !IS_CAST_ICODE(OP_SYMBOL (IC_RIGHT (ic))->rematiCode) &&
2852 bitVectnBitsOn (OP_SYMBOL (IC_RESULT (ic))->defs) <= 1)
2855 OP_SYMBOL (IC_RESULT (ic))->remat =
2856 OP_SYMBOL (IC_RIGHT (ic))->remat;
2857 OP_SYMBOL (IC_RESULT (ic))->rematiCode =
2858 OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
2861 /* if cast to a generic pointer & the pointer being
2862 cast is remat, then we can remat this cast as well */
2863 if (ic->op == CAST &&
2864 IS_SYMOP(IC_RIGHT(ic)) &&
2865 !OP_SYMBOL(IC_RESULT(ic))->isreqv &&
2866 OP_SYMBOL(IC_RIGHT(ic))->remat ) {
2867 sym_link *to_type = operandType(IC_LEFT(ic));
2868 sym_link *from_type = operandType(IC_RIGHT(ic));
2869 if (IS_GENPTR(to_type) && IS_PTR(from_type)) {
2870 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
2871 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
2872 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
2876 /* if this is a +/- operation with a rematerizable
2877 then mark this as rematerializable as well */
2878 if ((ic->op == '+' || ic->op == '-') &&
2879 (IS_SYMOP (IC_LEFT (ic)) &&
2880 IS_ITEMP (IC_RESULT (ic)) &&
2881 OP_SYMBOL (IC_LEFT (ic))->remat &&
2882 (!IS_SYMOP (IC_RIGHT (ic)) || !IS_CAST_ICODE(OP_SYMBOL (IC_RIGHT (ic))->rematiCode)) &&
2883 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
2884 IS_OP_LITERAL (IC_RIGHT (ic))))
2887 //int i = operandLitValue(IC_RIGHT(ic));
2888 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
2889 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
2890 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
2893 /* mark the pointer usages */
2894 if (POINTER_SET (ic) && IS_SYMOP (IC_RESULT (ic)))
2895 OP_SYMBOL (IC_RESULT (ic))->uptr = 1;
2897 if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic)))
2898 OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
2900 if (ic->op == RETURN && IS_SYMOP (IC_LEFT(ic)))
2901 OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
2903 if (ic->op == RECEIVE && ic->argreg == 1 &&
2904 IS_SYMOP (IC_RESULT (ic)) &&
2905 getSize (operandType(IC_RESULT(ic))) <= 3)
2906 OP_SYMBOL (IC_RESULT(ic))->uptr = 1;
2908 if (ic->op == SEND && ic->argreg == 1 &&
2909 IS_SYMOP(IC_LEFT(ic)) &&
2910 getSize (aggrToPtr(operandType(IC_LEFT(ic)),FALSE)) <= 3)
2911 OP_SYMBOL (IC_LEFT(ic))->uptr = 1;
2915 /* if we are using a symbol on the stack
2916 then we should say ds390_ptrRegReq */
2917 if (options.useXstack && ic->parmPush
2918 && (ic->op == IPUSH || ic->op == IPOP))
2920 if (ic->op == IFX && IS_SYMOP (IC_COND (ic)))
2921 ds390_ptrRegReq += ((OP_SYMBOL (IC_COND (ic))->onStack ? !options.stack10bit : 0) +
2922 OP_SYMBOL (IC_COND (ic))->iaccess +
2923 (SPEC_OCLS(OP_SYMBOL (IC_COND (ic))->etype) == idata));
2924 else if (ic->op == JUMPTABLE && IS_SYMOP (IC_JTCOND (ic)))
2925 ds390_ptrRegReq += ((OP_SYMBOL (IC_JTCOND (ic))->onStack ? !options.stack10bit : 0) +
2926 OP_SYMBOL (IC_JTCOND (ic))->iaccess +
2927 (SPEC_OCLS(OP_SYMBOL (IC_JTCOND (ic))->etype) == idata));
2930 if (IS_SYMOP (IC_LEFT (ic)))
2931 ds390_ptrRegReq += ((OP_SYMBOL (IC_LEFT (ic))->onStack ? !options.stack10bit : 0) +
2932 OP_SYMBOL (IC_LEFT (ic))->iaccess +
2933 (SPEC_OCLS(OP_SYMBOL (IC_LEFT (ic))->etype) == idata));
2934 if (IS_SYMOP (IC_RIGHT (ic)))
2935 ds390_ptrRegReq += ((OP_SYMBOL (IC_RIGHT (ic))->onStack ? !options.stack10bit : 0) +
2936 OP_SYMBOL (IC_RIGHT (ic))->iaccess +
2937 (SPEC_OCLS(OP_SYMBOL (IC_RIGHT (ic))->etype) == idata));
2938 if (IS_SYMOP (IC_RESULT (ic)))
2939 ds390_ptrRegReq += ((OP_SYMBOL (IC_RESULT (ic))->onStack ? !options.stack10bit : 0) +
2940 OP_SYMBOL (IC_RESULT (ic))->iaccess +
2941 (SPEC_OCLS(OP_SYMBOL (IC_RESULT (ic))->etype) == idata));
2945 /* if the condition of an if instruction
2946 is defined in the previous instruction and
2947 this is the only usage then
2948 mark the itemp as a conditional */
2949 if ((IS_CONDITIONAL (ic) ||
2950 (IS_BITWISE_OP(ic) && isBitwiseOptimizable (ic))) &&
2951 ic->next && ic->next->op == IFX &&
2952 bitVectnBitsOn (OP_USES(IC_RESULT(ic)))==1 &&
2953 isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
2954 OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
2956 OP_SYMBOL (IC_RESULT (ic))->regType = REG_CND;
2960 /* reduce for support function calls */
2961 if (ic->supportRtn || ic->op == '+' || ic->op == '-')
2962 packRegsForSupport (ic, ebp);
2964 /* some cases the redundant moves can
2965 can be eliminated for return statements . Can be elminated for the first SEND */
2966 if ((ic->op == RETURN ||
2967 ((ic->op == SEND || ic->op == RECEIVE)&& ic->argreg == 1)) &&
2968 !isOperandInFarSpace (IC_LEFT (ic)) &&
2971 packRegsDPTRuse (IC_LEFT (ic));
2974 if (ic->op == CALL) {
2975 sym_link *ftype = operandType(IC_LEFT(ic));
2976 if (getSize(operandType(IC_RESULT(ic))) <= 4 &&
2977 !IFFUNC_ISBUILTIN(ftype)) {
2978 packRegsDPTRuse (IC_RESULT (ic));
2982 /* if pointer set & left has a size more than
2983 one and right is not in far space */
2984 if (POINTER_SET (ic) &&
2985 !isOperandInFarSpace (IC_RIGHT (ic)) &&
2986 IS_SYMOP (IC_RESULT (ic)) &&
2987 !OP_SYMBOL (IC_RESULT (ic))->remat &&
2988 !IS_OP_RUONLY (IC_RIGHT (ic)) &&
2989 getSize (aggrToPtr (operandType (IC_RESULT (ic)), FALSE)) > 1) {
2991 packRegsDPTRuse (IC_RESULT (ic));
2994 /* if pointer get */
2995 if (POINTER_GET (ic) &&
2996 !isOperandInFarSpace (IC_RESULT (ic)) &&
2997 IS_SYMOP (IC_LEFT (ic)) &&
2998 !OP_SYMBOL (IC_LEFT (ic))->remat &&
2999 !IS_OP_RUONLY (IC_RESULT (ic)) &&
3000 getSize (aggrToPtr (operandType (IC_LEFT (ic)), FALSE)) > 1) {
3002 packRegsDPTRuse (IC_LEFT (ic));
3005 /* if this is cast for intergral promotion then
3006 check if only use of the definition of the
3007 operand being casted/ if yes then replace
3008 the result of that arithmetic operation with
3009 this result and get rid of the cast */
3012 sym_link *fromType = operandType (IC_RIGHT (ic));
3013 sym_link *toType = operandType (IC_LEFT (ic));
3015 if (IS_INTEGRAL (fromType) && IS_INTEGRAL (toType) &&
3016 getSize (fromType) != getSize (toType) &&
3017 SPEC_USIGN (fromType) == SPEC_USIGN (toType))
3020 iCode *dic = packRegsDPTRuse (IC_RIGHT (ic));
3023 if (IS_ARITHMETIC_OP (dic))
3025 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
3026 IC_RESULT (dic) = IC_RESULT (ic);
3027 remiCodeFromeBBlock (ebp, ic);
3028 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
3029 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
3030 OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
3034 OP_SYMBOL (IC_RIGHT (ic))->ruonly = 0;
3040 /* if the type from and type to are the same
3041 then if this is the only use then packit */
3042 if (compareType (operandType (IC_RIGHT (ic)),
3043 operandType (IC_LEFT (ic))) == 1)
3045 iCode *dic = packRegsDPTRuse (IC_RIGHT (ic));
3048 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
3049 IC_RESULT (dic) = IC_RESULT (ic);
3050 remiCodeFromeBBlock (ebp, ic);
3051 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
3052 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
3053 OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
3061 iTempNN := (some variable in farspace) V1
3066 if (ic->op == IPUSH || ic->op == SEND)
3068 packForPush (ic, ebp);
3072 /* pack registers for accumulator use, when the
3073 result of an arithmetic or bit wise operation
3074 has only one use, that use is immediately following
3075 the defintion and the using iCode has only one
3076 operand or has two operands but one is literal &
3077 the result of that operation is not on stack then
3078 we can leave the result of this operation in acc:b
3080 if ((IS_ARITHMETIC_OP (ic)
3081 || IS_CONDITIONAL(ic)
3082 || IS_BITWISE_OP (ic)
3083 || ic->op == LEFT_OP || ic->op == RIGHT_OP
3084 || (ic->op == ADDRESS_OF && isOperandOnStack (IC_LEFT (ic)))
3086 IS_ITEMP (IC_RESULT (ic)) &&
3087 getSize (operandType (IC_RESULT (ic))) <= 2)
3089 packRegsForAccUse (ic);
3094 /*-----------------------------------------------------------------*/
3095 /* assignRegisters - assigns registers to each live range as need */
3096 /*-----------------------------------------------------------------*/
3098 ds390_assignRegisters (eBBlock ** ebbs, int count)
3103 setToNull ((void *) &_G.funcrUsed);
3104 setToNull ((void *) &_G.regAssigned);
3105 setToNull ((void *) &_G.totRegAssigned);
3106 setToNull ((void *) &_G.funcrUsed);
3107 ds390_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
3109 if (options.model != MODEL_FLAT24) options.stack10bit = 0;
3110 /* change assignments this will remove some
3111 live ranges reducing some register pressure */
3112 for (i = 0; i < count; i++)
3113 packRegisters (ebbs[i]);
3115 /* liveranges probably changed by register packing
3116 so we compute them again */
3117 recomputeLiveRanges (ebbs, count);
3119 if (options.dump_pack)
3120 dumpEbbsToFileExt (DUMP_PACK, ebbs, count);
3122 /* first determine for each live range the number of
3123 registers & the type of registers required for each */
3126 /* and serially allocate registers */
3127 serialRegAssign (ebbs, count);
3134 /* if stack was extended then tell the user */
3137 /* werror(W_TOOMANY_SPILS,"stack", */
3138 /* _G.stackExtend,currFunc->name,""); */
3144 /* werror(W_TOOMANY_SPILS,"data space", */
3145 /* _G.dataExtend,currFunc->name,""); */
3149 /* after that create the register mask
3150 for each of the instruction */
3151 createRegMask (ebbs, count);
3153 /* redo that offsets for stacked automatic variables */
3155 redoStackOffsets ();
3157 /* make sure r0 & r1 are flagged as used if they might be used */
3159 if (currFunc && ds390_ptrRegReq)
3161 currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, R0_IDX);
3162 currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, R1_IDX);
3165 if (options.dump_rassgn) {
3166 dumpEbbsToFileExt (DUMP_RASSGN, ebbs, count);
3167 dumpLiveRanges (DUMP_LRANGE, liveRanges);
3170 /* do the overlaysegment stuff SDCCmem.c */
3171 doOverlays (ebbs, count);
3173 /* now get back the chain */
3174 ic = iCodeLabelOptimize (iCodeFromeBBlock (ebbs, count));
3179 /* free up any _G.stackSpil locations allocated */
3180 applyToSet (_G.stackSpil, deallocStackSpil);
3182 setToNull ((void *) &_G.stackSpil);
3183 setToNull ((void *) &_G.spiltSet);
3184 /* mark all registers as free */