1 /*------------------------------------------------------------------------
3 SDCCralloc.c - source file for register allocation. (DS80C390) 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 *,unsigned);
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 with 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 /*-----------------------------------------------------------------*/
156 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
157 "freeReg - Freeing NULL register");
164 /*-----------------------------------------------------------------*/
165 /* useReg - marks a register as used */
166 /*-----------------------------------------------------------------*/
174 /*-----------------------------------------------------------------*/
175 /* nFreeRegs - returns number of free registers */
176 /*-----------------------------------------------------------------*/
183 for (i = 0; i < ds390_nRegs; i++)
184 if (regs390[i].isFree && regs390[i].type == type)
189 /*-----------------------------------------------------------------*/
190 /* nfreeRegsType - free registers with type */
191 /*-----------------------------------------------------------------*/
193 nfreeRegsType (int type)
198 if ((nfr = nFreeRegs (type)) == 0)
199 return nFreeRegs (REG_GPR);
202 return nFreeRegs (type);
207 /*-----------------------------------------------------------------*/
208 /* isOperandInReg - returns true if operand is currently in regs */
209 /*-----------------------------------------------------------------*/
210 static int isOperandInReg(operand *op)
212 if (!IS_SYMOP(op)) return 0;
213 if (OP_SYMBOL(op)->ruonly) return 1;
214 if (OP_SYMBOL(op)->accuse) return 1;
215 if (OP_SYMBOL(op)->dptr) return 1;
216 return bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(op)->key);
219 /*-----------------------------------------------------------------*/
220 /* computeSpillable - given a point find the spillable live ranges */
221 /*-----------------------------------------------------------------*/
223 computeSpillable (iCode * ic)
227 /* spillable live ranges are those that are live at this
228 point . the following categories need to be subtracted
230 a) - those that are already spilt
231 b) - if being used by this one
232 c) - defined by this one */
234 spillable = bitVectCopy (ic->rlive);
236 bitVectCplAnd (spillable, _G.spiltSet); /* those already spilt */
238 bitVectCplAnd (spillable, ic->uses); /* used in this one */
239 bitVectUnSetBit (spillable, ic->defKey);
240 spillable = bitVectIntersect (spillable, _G.regAssigned);
245 /*-----------------------------------------------------------------*/
246 /* noSpilLoc - return true if a variable has no spil location */
247 /*-----------------------------------------------------------------*/
249 noSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
251 return (sym->usl.spillLoc ? 0 : 1);
254 /*-----------------------------------------------------------------*/
255 /* hasSpilLoc - will return 1 if the symbol has spil location */
256 /*-----------------------------------------------------------------*/
258 hasSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
260 return (sym->usl.spillLoc ? 1 : 0);
263 /*-----------------------------------------------------------------*/
264 /* directSpilLoc - will return 1 if the splilocation is in direct */
265 /*-----------------------------------------------------------------*/
267 directSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
269 if (sym->usl.spillLoc &&
270 (IN_DIRSPACE (SPEC_OCLS (sym->usl.spillLoc->etype))))
276 /*-----------------------------------------------------------------*/
277 /* hasSpilLocnoUptr - will return 1 if the symbol has spil location */
278 /* but is not used as a pointer */
279 /*-----------------------------------------------------------------*/
281 hasSpilLocnoUptr (symbol * sym, eBBlock * ebp, iCode * ic)
283 return ((sym->usl.spillLoc && !sym->uptr) ? 1 : 0);
286 /*-----------------------------------------------------------------*/
287 /* rematable - will return 1 if the remat flag is set */
288 /*-----------------------------------------------------------------*/
290 rematable (symbol * sym, eBBlock * ebp, iCode * ic)
295 /*-----------------------------------------------------------------*/
296 /* notUsedInRemaining - not used or defined in remain of the block */
297 /*-----------------------------------------------------------------*/
299 notUsedInRemaining (symbol * sym, eBBlock * ebp, iCode * ic)
301 return ((usedInRemaining (operandFromSymbol (sym), ic) ? 0 : 1) &&
302 allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq));
305 /*-----------------------------------------------------------------*/
306 /* allLRs - return true for all */
307 /*-----------------------------------------------------------------*/
309 allLRs (symbol * sym, eBBlock * ebp, iCode * ic)
314 /*-----------------------------------------------------------------*/
315 /* liveRangesWith - applies function to a given set of live range */
316 /*-----------------------------------------------------------------*/
318 liveRangesWith (bitVect * lrs, int (func) (symbol *, eBBlock *, iCode *),
319 eBBlock * ebp, iCode * ic)
324 if (!lrs || !lrs->size)
327 for (i = 1; i < lrs->size; i++)
330 if (!bitVectBitValue (lrs, i))
333 /* if we don't find it in the live range
334 hash table we are in serious trouble */
335 if (!(sym = hTabItemWithKey (liveRanges, i)))
337 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
338 "liveRangesWith could not find liveRange");
342 if (func (sym, ebp, ic) && bitVectBitValue (_G.regAssigned, sym->key))
343 addSetHead (&rset, sym);
350 /*-----------------------------------------------------------------*/
351 /* leastUsedLR - given a set determines which is the least used */
352 /*-----------------------------------------------------------------*/
354 leastUsedLR (set * sset)
356 symbol *sym = NULL, *lsym = NULL;
358 sym = lsym = setFirstItem (sset);
363 for (; lsym; lsym = setNextItem (sset))
366 /* if usage is the same then prefer
367 the spill the smaller of the two */
368 if (lsym->used == sym->used)
369 if (getSize (lsym->type) < getSize (sym->type))
373 if (lsym->used < sym->used)
378 setToNull ((void *) &sset);
383 /*-----------------------------------------------------------------*/
384 /* noOverLap - will iterate through the list looking for over lap */
385 /*-----------------------------------------------------------------*/
387 noOverLap (set * itmpStack, symbol * fsym)
391 for (sym = setFirstItem (itmpStack); sym;
392 sym = setNextItem (itmpStack))
394 if (bitVectBitValue(sym->clashes,fsym->key)) return 0;
399 /*-----------------------------------------------------------------*/
400 /* isFree - will return 1 if the a free spil location is found */
401 /*-----------------------------------------------------------------*/
406 V_ARG (symbol **, sloc);
407 V_ARG (symbol *, fsym);
409 /* if already found */
413 /* if it is free && and the itmp assigned to
414 this does not have any overlapping live ranges
415 with the one currently being assigned and
416 the size can be accomodated */
418 noOverLap (sym->usl.itmpStack, fsym) &&
419 getSize (sym->type) >= getSize (fsym->type))
428 /*-----------------------------------------------------------------*/
429 /* spillLRWithPtrReg :- will spil those live ranges which use PTR */
430 /*-----------------------------------------------------------------*/
432 spillLRWithPtrReg (symbol * forSym)
438 if (!_G.regAssigned ||
439 bitVectIsZero (_G.regAssigned))
442 r0 = ds390_regWithIdx (R0_IDX);
443 r1 = ds390_regWithIdx (R1_IDX);
445 /* for all live ranges */
446 for (lrsym = hTabFirstItem (liveRanges, &k); lrsym;
447 lrsym = hTabNextItem (liveRanges, &k))
451 /* if no registers assigned to it or spilt */
452 /* if it does not overlap this then
453 no need to spill it */
455 if (lrsym->isspilt || !lrsym->nRegs ||
456 (lrsym->liveTo < forSym->liveFrom))
459 /* go thru the registers : if it is either
460 r0 or r1 then spill it */
461 for (j = 0; j < lrsym->nRegs; j++)
462 if (lrsym->regs[j] == r0 ||
463 lrsym->regs[j] == r1)
472 /*-----------------------------------------------------------------*/
473 /* createStackSpil - create a location on the stack to spil */
474 /*-----------------------------------------------------------------*/
476 createStackSpil (symbol * sym)
479 int useXstack, model, noOverlay;
483 /* first go try and find a free one that is already
484 existing on the stack */
485 if (applyToSet (_G.stackSpil, isFree, &sloc, sym))
487 /* found a free one : just update & return */
488 sym->usl.spillLoc = sloc;
491 addSetHead (&sloc->usl.itmpStack, sym);
495 /* could not then have to create one , this is the hard part
496 we need to allocate this on the stack : this is really a
497 hack!! but cannot think of anything better at this time */
499 if (SNPRINTF (slocBuffer, sizeof(slocBuffer),
500 "sloc%d", _G.slocNum++) >= sizeof (slocBuffer))
502 fprintf (stderr, "***Internal error: slocBuffer overflowed: %s:%d\n",
507 sloc = newiTemp (slocBuffer);
509 /* set the type to the spilling symbol */
510 sloc->type = copyLinkChain (sym->type);
511 sloc->etype = getSpec (sloc->type);
512 if (options.model == MODEL_SMALL) {
513 SPEC_SCLS (sloc->etype) = S_DATA;
515 SPEC_SCLS (sloc->etype) = S_XDATA;
517 SPEC_EXTR (sloc->etype) = 0;
518 SPEC_STAT (sloc->etype) = 0;
519 SPEC_VOLATILE(sloc->etype) = 0;
520 SPEC_ABSA(sloc->etype) = 0;
522 /* we don't allow it to be allocated`
523 onto the external stack since : so we
524 temporarily turn it off ; we also
525 turn off memory model to prevent
526 the spil from going to the external storage
527 and turn off overlaying
530 useXstack = options.useXstack;
531 model = options.model;
532 noOverlay = options.noOverlay;
533 options.noOverlay = 1;
535 /* options.model = options.useXstack = 0; */
539 options.useXstack = useXstack;
540 options.model = model;
541 options.noOverlay = noOverlay;
542 sloc->isref = 1; /* to prevent compiler warning */
544 /* if it is on the stack then update the stack */
545 if (IN_STACK (sloc->etype))
547 currFunc->stack += getSize (sloc->type);
548 _G.stackExtend += getSize (sloc->type);
551 _G.dataExtend += getSize (sloc->type);
553 /* add it to the _G.stackSpil set */
554 addSetHead (&_G.stackSpil, sloc);
555 sym->usl.spillLoc = sloc;
558 /* add it to the set of itempStack set
559 of the spill location */
560 addSetHead (&sloc->usl.itmpStack, sym);
564 /*-----------------------------------------------------------------*/
565 /* isSpiltOnStack - returns true if the spil location is on stack */
566 /*-----------------------------------------------------------------*/
568 isSpiltOnStack (symbol * sym)
578 /* if (sym->_G.stackSpil) */
581 if (!sym->usl.spillLoc)
584 etype = getSpec (sym->usl.spillLoc->type);
585 if (IN_STACK (etype))
591 /*-----------------------------------------------------------------*/
592 /* spillThis - spils a specific operand */
593 /*-----------------------------------------------------------------*/
595 spillThis (symbol * sym)
598 /* if this is rematerializable or has a spillLocation
599 we are okay, else we need to create a spillLocation
601 if (!(sym->remat || sym->usl.spillLoc))
602 createStackSpil (sym);
604 /* mark it has spilt & put it in the spilt set */
605 sym->isspilt = sym->spillA = 1;
606 _G.spiltSet = bitVectSetBit (_G.spiltSet, sym->key);
608 bitVectUnSetBit (_G.regAssigned, sym->key);
609 bitVectUnSetBit (_G.totRegAssigned, sym->key);
611 for (i = 0; i < sym->nRegs; i++)
615 freeReg (sym->regs[i]);
619 /* if spilt on stack then free up r0 & r1
620 if they could have been assigned to some
622 if (!ds390_ptrRegReq && isSpiltOnStack (sym) && !options.stack10bit)
625 spillLRWithPtrReg (sym);
628 if (sym->usl.spillLoc && !sym->remat)
629 sym->usl.spillLoc->allocreq++;
633 /*-----------------------------------------------------------------*/
634 /* selectSpil - select a iTemp to spil : rather a simple procedure */
635 /*-----------------------------------------------------------------*/
637 selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
639 bitVect *lrcs = NULL;
643 /* get the spillable live ranges */
644 lrcs = computeSpillable (ic);
646 /* get all live ranges that are rematerizable */
647 if ((selectS = liveRangesWith (lrcs, rematable, ebp, ic)))
650 /* return the least used of these */
651 return leastUsedLR (selectS);
654 /* get live ranges with spillLocations in direct space */
655 if ((selectS = liveRangesWith (lrcs, directSpilLoc, ebp, ic)))
657 sym = leastUsedLR (selectS);
658 strncpyz (sym->rname,
659 sym->usl.spillLoc->rname[0] ?
660 sym->usl.spillLoc->rname : sym->usl.spillLoc->name,
663 /* mark it as allocation required */
664 sym->usl.spillLoc->allocreq++;
668 /* if the symbol is local to the block then */
669 if (forSym->liveTo < ebp->lSeq)
672 /* check if there are any live ranges allocated
673 to registers that are not used in this block */
674 if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInBlock, ebp, ic)))
676 sym = leastUsedLR (selectS);
677 /* if this is not rematerializable */
686 /* check if there are any live ranges that not
687 used in the remainder of the block */
689 !isiCodeInFunctionCall (ic) &&
690 (selectS = liveRangesWith (lrcs, notUsedInRemaining, ebp, ic)))
692 sym = leastUsedLR (selectS);
705 /* find live ranges with spillocation && not used as pointers */
706 if ((selectS = liveRangesWith (lrcs, hasSpilLocnoUptr, ebp, ic)))
709 sym = leastUsedLR (selectS);
710 /* mark this as allocation required */
711 sym->usl.spillLoc->allocreq++;
715 /* find live ranges with spillocation */
716 if ((selectS = liveRangesWith (lrcs, hasSpilLoc, ebp, ic)))
719 sym = leastUsedLR (selectS);
720 sym->usl.spillLoc->allocreq++;
724 /* couldn't find then we need to create a spil
725 location on the stack , for which one? the least
727 if ((selectS = liveRangesWith (lrcs, noSpilLoc, ebp, ic)))
730 /* return a created spil location */
731 sym = createStackSpil (leastUsedLR (selectS));
732 sym->usl.spillLoc->allocreq++;
736 /* this is an extreme situation we will spill
737 this one : happens very rarely but it does happen */
743 /*-----------------------------------------------------------------*/
744 /* spilSomething - spil some variable & mark registers as free */
745 /*-----------------------------------------------------------------*/
747 spilSomething (iCode * ic, eBBlock * ebp, symbol * forSym)
752 /* get something we can spil */
753 ssym = selectSpil (ic, ebp, forSym);
755 /* mark it as spilt */
756 ssym->isspilt = ssym->spillA = 1;
757 _G.spiltSet = bitVectSetBit (_G.spiltSet, ssym->key);
759 /* mark it as not register assigned &
760 take it away from the set */
761 bitVectUnSetBit (_G.regAssigned, ssym->key);
762 bitVectUnSetBit (_G.totRegAssigned, ssym->key);
764 /* mark the registers as free */
765 for (i = 0; i < ssym->nRegs; i++)
767 freeReg (ssym->regs[i]);
769 /* if spilt on stack then free up r0 & r1
770 if they could have been assigned to as gprs */
771 if (!ds390_ptrRegReq && isSpiltOnStack (ssym) && !options.stack10bit)
774 spillLRWithPtrReg (ssym);
777 /* if this was a block level spil then insert push & pop
778 at the start & end of block respectively */
781 iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
782 /* add push to the start of the block */
783 addiCodeToeBBlock (ebp, nic, (ebp->sch->op == LABEL ?
784 ebp->sch->next : ebp->sch));
785 nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
786 /* add pop to the end of the block */
787 addiCodeToeBBlock (ebp, nic, NULL);
790 /* if spilt because not used in the remainder of the
791 block then add a push before this instruction and
792 a pop at the end of the block */
793 if (ssym->remainSpil)
796 iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
797 /* add push just before this instruction */
798 addiCodeToeBBlock (ebp, nic, ic);
800 nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
801 /* add pop to the end of the block */
802 addiCodeToeBBlock (ebp, nic, NULL);
811 /*-----------------------------------------------------------------*/
812 /* getRegPtr - will try for PTR if not a GPR type if not spil */
813 /*-----------------------------------------------------------------*/
815 getRegPtr (iCode * ic, eBBlock * ebp, symbol * sym)
821 /* try for a ptr type */
822 if ((reg = allocReg (REG_PTR)))
825 /* try for gpr type */
826 if ((reg = allocReg (REG_GPR)))
829 /* we have to spil */
830 if (!spilSomething (ic, ebp, sym))
833 /* make sure partially assigned registers aren't reused */
834 for (j=0; j<=sym->nRegs; j++)
836 sym->regs[j]->isFree = 0;
838 /* this looks like an infinite loop but
839 in really selectSpil will abort */
843 /*-----------------------------------------------------------------*/
844 /* getRegGpr - will try for GPR if not spil */
845 /*-----------------------------------------------------------------*/
847 getRegGpr (iCode * ic, eBBlock * ebp, symbol * sym)
853 /* try for gpr type */
854 if ((reg = allocReg (REG_GPR)))
857 if (!ds390_ptrRegReq)
858 if ((reg = allocReg (REG_PTR)))
861 /* we have to spil */
862 if (!spilSomething (ic, ebp, sym))
865 /* make sure partially assigned registers aren't reused */
866 for (j=0; j<=sym->nRegs; j++)
868 sym->regs[j]->isFree = 0;
870 /* this looks like an infinite loop but
871 in really selectSpil will abort */
875 /*-----------------------------------------------------------------*/
876 /* getRegPtrNoSpil - get it cannot split */
877 /*-----------------------------------------------------------------*/
878 static regs *getRegPtrNoSpil()
882 /* try for a ptr type */
883 if ((reg = allocReg (REG_PTR)))
886 /* try for gpr type */
887 if ((reg = allocReg (REG_GPR)))
892 /* just to make the compiler happy */
896 /*-----------------------------------------------------------------*/
897 /* getRegGprNoSpil - get it cannot split */
898 /*-----------------------------------------------------------------*/
899 static regs *getRegGprNoSpil()
903 if ((reg = allocReg (REG_GPR)))
906 if (!ds390_ptrRegReq)
907 if ((reg = allocReg (REG_PTR)))
912 /* just to make the compiler happy */
916 /*-----------------------------------------------------------------*/
917 /* symHasReg - symbol has a given register */
918 /*-----------------------------------------------------------------*/
920 symHasReg (symbol * sym, regs * reg)
924 for (i = 0; i < sym->nRegs; i++)
925 if (sym->regs[i] == reg)
931 /*-----------------------------------------------------------------*/
932 /* deassignLRs - check the live to and if they have registers & are */
933 /* not spilt then free up the registers */
934 /*-----------------------------------------------------------------*/
936 deassignLRs (iCode * ic, eBBlock * ebp)
942 for (sym = hTabFirstItem (liveRanges, &k); sym;
943 sym = hTabNextItem (liveRanges, &k))
947 /* if it does not end here */
948 if (sym->liveTo > ic->seq)
951 /* if it was spilt on stack then we can
952 mark the stack spil location as free */
957 sym->usl.spillLoc->isFree = 1;
963 if (!bitVectBitValue (_G.regAssigned, sym->key))
966 /* special case check if this is an IFX &
967 the privious one was a pop and the
968 previous one was not spilt then keep track
970 if (ic->op == IFX && ic->prev &&
971 ic->prev->op == IPOP &&
972 !ic->prev->parmPush &&
973 !OP_SYMBOL (IC_LEFT (ic->prev))->isspilt)
974 psym = OP_SYMBOL (IC_LEFT (ic->prev));
980 bitVectUnSetBit (_G.regAssigned, sym->key);
982 /* if the result of this one needs registers
983 and does not have it then assign it right
985 if (IC_RESULT (ic) &&
986 !(SKIP_IC2 (ic) || /* not a special icode */
987 ic->op == JUMPTABLE ||
993 (result = OP_SYMBOL (IC_RESULT (ic))) && /* has a result */
994 result->liveTo > ic->seq && /* and will live beyond this */
995 result->liveTo <= ebp->lSeq && /* does not go beyond this block */
996 result->liveFrom == ic->seq && /* does not start before here */
997 result->regType == sym->regType && /* same register types */
998 result->nRegs && /* which needs registers */
999 !result->isspilt && /* and does not already have them */
1001 !bitVectBitValue (_G.regAssigned, result->key) &&
1002 /* the number of free regs + number of regs in this LR
1003 can accomodate the what result Needs */
1004 ((nfreeRegsType (result->regType) +
1005 sym->nRegs) >= result->nRegs)
1009 for (i = 0; i < result->nRegs; i++)
1011 result->regs[i] = sym->regs[i];
1013 result->regs[i] = getRegGpr (ic, ebp, result);
1015 _G.regAssigned = bitVectSetBit (_G.regAssigned, result->key);
1016 _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, result->key);
1020 /* free the remaining */
1021 for (; i < sym->nRegs; i++)
1025 if (!symHasReg (psym, sym->regs[i]))
1026 freeReg (sym->regs[i]);
1029 freeReg (sym->regs[i]);
1036 /*-----------------------------------------------------------------*/
1037 /* reassignLR - reassign this to registers */
1038 /*-----------------------------------------------------------------*/
1040 reassignLR (operand * op)
1042 symbol *sym = OP_SYMBOL (op);
1045 /* not spilt any more */
1046 sym->isspilt = sym->spillA = sym->blockSpil = sym->remainSpil = 0;
1047 bitVectUnSetBit (_G.spiltSet, sym->key);
1049 _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
1050 _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, sym->key);
1054 for (i = 0; i < sym->nRegs; i++)
1055 sym->regs[i]->isFree = 0;
1058 /*-----------------------------------------------------------------*/
1059 /* willCauseSpill - determines if allocating will cause a spill */
1060 /*-----------------------------------------------------------------*/
1062 willCauseSpill (int nr, int rt)
1064 /* first check if there are any avlb registers
1065 of te type required */
1068 /* special case for pointer type
1069 if pointer type not avlb then
1070 check for type gpr */
1071 if (nFreeRegs (rt) >= nr)
1073 if (nFreeRegs (REG_GPR) >= nr)
1078 if (ds390_ptrRegReq)
1080 if (nFreeRegs (rt) >= nr)
1085 if (nFreeRegs (REG_PTR) +
1086 nFreeRegs (REG_GPR) >= nr)
1091 /* it will cause a spil */
1095 /*-----------------------------------------------------------------*/
1096 /* positionRegs - the allocator can allocate same registers to res- */
1097 /* ult and operand, if this happens make sure they are in the same */
1098 /* position as the operand otherwise chaos results */
1099 /*-----------------------------------------------------------------*/
1101 positionRegs (symbol * result, symbol * opsym)
1103 int count = min (result->nRegs, opsym->nRegs);
1104 int i, j = 0, shared = 0;
1107 /* if the result has been spilt then cannot share */
1112 /* first make sure that they actually share */
1113 for (i = 0; i < count; i++)
1115 for (j = 0; j < count; j++)
1117 if (result->regs[i] == opsym->regs[j] && i != j)
1127 regs *tmp = result->regs[i];
1128 result->regs[i] = result->regs[j];
1129 result->regs[j] = tmp;
1136 /*-----------------------------------------------------------------*/
1137 /* unusedLRS - returns a bitVector of liveranges not used in 'ebp' */
1138 /*-----------------------------------------------------------------*/
1139 bitVect *unusedLRs (eBBlock *ebp)
1141 bitVect *ret = NULL;
1145 if (!ebp) return NULL;
1146 for (sym = hTabFirstItem(liveRanges,&key); sym ;
1147 sym = hTabNextItem(liveRanges,&key)) {
1149 if (notUsedInBlock(sym,ebp,NULL)) {
1150 ret = bitVectSetBit(ret,sym->key);
1157 /*-----------------------------------------------------------------*/
1158 /* deassignUnsedLRs - if this baisc block ends in a return then */
1159 /* deassign symbols not used in this block */
1160 /*-----------------------------------------------------------------*/
1161 bitVect *deassignUnsedLRs(eBBlock *ebp)
1163 bitVect *unused = NULL;
1166 switch (returnAtEnd(ebp)) {
1167 case 2: /* successor block ends in a return */
1168 unused = unusedLRs((eBBlock *) setFirstItem(ebp->succList));
1170 case 1: /* this block ends in a return */
1171 unused = bitVectIntersect(unused,unusedLRs(ebp));
1176 for (i = 0 ; i < unused->size ; i++ ) {
1179 if (bitVectBitValue(unused,i)) {
1181 /* if assigned to registers */
1182 if (bitVectBitValue(_G.regAssigned,i)) {
1186 sym = hTabItemWithKey(liveRanges,i);
1187 /* remove it from regassigned & mark the
1189 bitVectUnSetBit(_G.regAssigned,i);
1190 for (j = 0 ; j < sym->nRegs; j++)
1191 freeReg(sym->regs[j]);
1193 /* not assigned to registers : remove from set*/
1194 bitVectUnSetBit(unused,i);
1202 /*-----------------------------------------------------------------*/
1203 /* reassignUnusedLRs - put registers to unused Live ranges */
1204 /*-----------------------------------------------------------------*/
1205 void reassignUnusedLRs (bitVect *unused)
1208 if (!unused) return ;
1210 for (i = 0 ; i < unused->size ; i++ ) {
1211 /* if unused : means it was assigned to registers before */
1212 if (bitVectBitValue(unused,i)) {
1216 /* put it back into reg set*/
1217 bitVectSetBit(_G.regAssigned,i) ;
1219 sym = hTabItemWithKey(liveRanges,i);
1220 /* makr registers busy */
1221 for (j = 0 ; j < sym->nRegs; j++)
1222 sym->regs[j]->isFree = 0;
1227 /*------------------------------------------------------------------*/
1228 /* verifyRegsAssigned - make sure an iTemp is properly initialized; */
1229 /* it should either have registers or have beed spilled. Otherwise, */
1230 /* there was an uninitialized variable, so just spill this to get */
1231 /* the operand in a valid state. */
1232 /*------------------------------------------------------------------*/
1234 verifyRegsAssigned (operand *op, iCode * ic)
1239 if (!IS_ITEMP (op)) return;
1241 sym = OP_SYMBOL (op);
1242 if (sym->isspilt) return;
1243 if (!sym->nRegs) return;
1244 if (sym->regs[0]) return;
1246 werrorfl (ic->filename, ic->lineno, W_LOCAL_NOINIT,
1247 sym->prereqv ? sym->prereqv->name : sym->name);
1252 /*-----------------------------------------------------------------*/
1253 /* serialRegAssign - serially allocate registers to the variables */
1254 /*-----------------------------------------------------------------*/
1256 serialRegAssign (eBBlock ** ebbs, int count)
1260 /* for all blocks */
1261 for (i = 0; i < count; i++)
1265 bitVect *unusedLRs = NULL;
1267 if (ebbs[i]->noPath &&
1268 (ebbs[i]->entryLabel != entryLabel &&
1269 ebbs[i]->entryLabel != returnLabel))
1272 unusedLRs = deassignUnsedLRs(ebbs[i]);
1274 /* of all instructions do */
1275 for (ic = ebbs[i]->sch; ic; ic = ic->next)
1278 /* if this is an ipop that means some live
1279 range will have to be assigned again */
1281 reassignLR (IC_LEFT (ic));
1283 /* if result is present && is a true symbol */
1284 if (IC_RESULT (ic) && ic->op != IFX &&
1285 IS_TRUE_SYMOP (IC_RESULT (ic)))
1286 OP_SYMBOL (IC_RESULT (ic))->allocreq++;
1288 /* take away registers from live
1289 ranges that end at this instruction */
1290 deassignLRs (ic, ebbs[i]);
1292 /* some don't need registers */
1293 if (SKIP_IC2 (ic) ||
1294 ic->op == JUMPTABLE ||
1298 (IC_RESULT (ic) && POINTER_SET (ic)))
1301 /* now we need to allocate registers
1302 only for the result */
1305 symbol *sym = OP_SYMBOL (IC_RESULT (ic));
1311 /* if it does not need or is spilt
1312 or is already assigned to registers
1313 or will not live beyond this instructions */
1316 bitVectBitValue (_G.regAssigned, sym->key) ||
1317 sym->liveTo <= ic->seq)
1320 /* if some liverange has been spilt at the block level
1321 and this one live beyond this block then spil this
1323 if (_G.blockSpil && sym->liveTo > ebbs[i]->lSeq)
1328 /* if trying to allocate this will cause
1329 a spill and there is nothing to spill
1330 or this one is rematerializable then
1332 willCS = willCauseSpill (sym->nRegs, sym->regType);
1333 spillable = computeSpillable (ic);
1335 (willCS && bitVectIsZero (spillable)))
1343 /* If the live range preceeds the point of definition
1344 then ideally we must take into account registers that
1345 have been allocated after sym->liveFrom but freed
1346 before ic->seq. This is complicated, so spill this
1347 symbol instead and let fillGaps handle the allocation. */
1348 if (sym->liveFrom < ic->seq)
1354 /* if it has a spillocation & is used less than
1355 all other live ranges then spill this */
1357 if (sym->usl.spillLoc) {
1358 symbol *leastUsed = leastUsedLR (liveRangesWith (spillable,
1359 allLRs, ebbs[i], ic));
1360 if (leastUsed && leastUsed->used > sym->used) {
1365 /* if none of the liveRanges have a spillLocation then better
1366 to spill this one than anything else already assigned to registers */
1367 if (liveRangesWith(spillable,noSpilLoc,ebbs[i],ic)) {
1368 /* if this is local to this block then we might find a block spil */
1369 if (!(sym->liveFrom >= ebbs[i]->fSeq && sym->liveTo <= ebbs[i]->lSeq)) {
1377 /* if we need ptr regs for the right side
1379 if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic))
1380 && getSize (OP_SYMBOL (IC_LEFT (ic))->type)
1381 <= (unsigned) PTRSIZE)
1386 /* else we assign registers to it */
1387 _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
1388 _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, sym->key);
1390 for (j = 0; j < sym->nRegs; j++)
1392 if (sym->regType == REG_PTR)
1393 sym->regs[j] = getRegPtr (ic, ebbs[i], sym);
1395 sym->regs[j] = getRegGpr (ic, ebbs[i], sym);
1397 /* if the allocation falied which means
1398 this was spilt then break */
1403 /* if it shares registers with operands make sure
1404 that they are in the same position */
1405 if (!POINTER_SET(ic) && !POINTER_GET(ic))
1407 if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)) &&
1408 OP_SYMBOL (IC_LEFT (ic))->nRegs)
1410 positionRegs (OP_SYMBOL (IC_RESULT (ic)),
1411 OP_SYMBOL (IC_LEFT (ic)));
1413 /* do the same for the right operand */
1414 if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)) &&
1415 OP_SYMBOL (IC_RIGHT (ic))->nRegs)
1417 positionRegs (OP_SYMBOL (IC_RESULT (ic)),
1418 OP_SYMBOL (IC_RIGHT (ic)));
1430 reassignUnusedLRs(unusedLRs);
1433 /* Check for and fix any problems with uninitialized operands */
1434 for (i = 0; i < count; i++)
1438 if (ebbs[i]->noPath &&
1439 (ebbs[i]->entryLabel != entryLabel &&
1440 ebbs[i]->entryLabel != returnLabel))
1443 for (ic = ebbs[i]->sch; ic; ic = ic->next)
1450 verifyRegsAssigned (IC_COND (ic), ic);
1454 if (ic->op == JUMPTABLE)
1456 verifyRegsAssigned (IC_JTCOND (ic), ic);
1460 verifyRegsAssigned (IC_RESULT (ic), ic);
1461 verifyRegsAssigned (IC_LEFT (ic), ic);
1462 verifyRegsAssigned (IC_RIGHT (ic), ic);
1467 /*-----------------------------------------------------------------*/
1468 /* fillGaps - Try to fill in the Gaps left by Pass1 */
1469 /*-----------------------------------------------------------------*/
1470 static void fillGaps()
1474 int loop = 0, change;
1477 if (getenv("DISABLE_FILL_GAPS")) return;
1479 /* First try to do DPTRuse once more since now we know what got into
1482 while (loop++ < 10) {
1485 for (sym = hTabFirstItem(liveRanges,&key) ; sym ;
1486 sym = hTabNextItem(liveRanges,&key)) {
1487 int size = getSize(sym->type);
1489 if (sym->liveFrom == sym->liveTo) continue;
1491 if (sym->uptr && sym->dptr==0 && !sym->ruonly &&
1492 size < 4 && size > 1) {
1494 if (packRegsDPTRuse(operandFromSymbol(sym))) {
1496 /* if this was assigned to registers then */
1497 if (bitVectBitValue(_G.totRegAssigned,sym->key)) {
1498 /* take it out of the register assigned set */
1499 bitVectUnSetBit(_G.totRegAssigned,sym->key);
1500 } else if (sym->usl.spillLoc) {
1501 sym->usl.spillLoc->allocreq--;
1502 sym->usl.spillLoc = NULL;
1506 sym->isspilt = sym->spillA = 0;
1510 /* try assigning other dptrs */
1511 if (sym->dptr == 0 && packRegsDPTRnuse(operandFromSymbol(sym),1) && !getenv("DPTRnDISABLE")) {
1512 /* if this was ssigned to registers then */
1513 if (bitVectBitValue(_G.totRegAssigned,sym->key)) {
1514 /* take it out of the register assigned set */
1515 bitVectUnSetBit(_G.totRegAssigned,sym->key);
1516 } else if (sym->usl.spillLoc) {
1517 sym->usl.spillLoc->allocreq--;
1518 sym->usl.spillLoc = NULL;
1521 sym->isspilt = sym->spillA = 0;
1526 /* look for livernages that was spilt by the allocator */
1527 for (sym = hTabFirstItem(liveRanges,&key) ; sym ;
1528 sym = hTabNextItem(liveRanges,&key)) {
1533 if (!sym->spillA || !sym->clashes || sym->remat) continue ;
1534 if (!sym->uses || !sym->defs) continue ;
1535 /* find the liveRanges this one clashes with, that are
1536 still assigned to registers & mark the registers as used*/
1537 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)) {
1554 /* NOPE :( clear all registers & and continue */
1559 /* THERE IS HOPE !!!! */
1560 for (i=0; i < sym->nRegs ; i++ ) {
1561 if (sym->regType == REG_PTR)
1562 sym->regs[i] = getRegPtrNoSpil ();
1564 sym->regs[i] = getRegGprNoSpil ();
1567 /* For all its definitions check if the registers
1568 allocated needs positioning NOTE: we can position
1569 only ONCE if more than One positioning required
1571 We may need to perform the checks twice; once to
1572 position the registers as needed, the second to
1573 verify any register repositioning is still
1577 for (pass=0; pass<2; pass++) {
1578 for (i = 0 ; i < sym->defs->size ; i++ ) {
1579 if (bitVectBitValue(sym->defs,i)) {
1581 if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ;
1582 if (SKIP_IC(ic)) continue;
1583 assert(isSymbolEqual(sym,OP_SYMBOL(IC_RESULT(ic)))); /* just making sure */
1584 /* if left is assigned to registers */
1585 if (IS_SYMOP(IC_LEFT(ic)) &&
1586 bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_LEFT(ic))->key)) {
1587 pdone += (positionRegs(sym,OP_SYMBOL(IC_LEFT(ic)))>0);
1589 if (IS_SYMOP(IC_RIGHT(ic)) &&
1590 bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RIGHT(ic))->key)) {
1591 pdone += (positionRegs(sym,OP_SYMBOL(IC_RIGHT(ic)))>0);
1593 if (pdone > 1) break;
1596 for (i = 0 ; i < sym->uses->size ; i++ ) {
1597 if (bitVectBitValue(sym->uses,i)) {
1599 if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ;
1600 if (SKIP_IC(ic)) continue;
1601 if (POINTER_SET(ic) || POINTER_GET(ic)) continue ;
1603 /* if result is assigned to registers */
1604 if (IS_SYMOP(IC_RESULT(ic)) &&
1605 bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RESULT(ic))->key)) {
1606 pdone += (positionRegs(sym,OP_SYMBOL(IC_RESULT(ic)))>0);
1608 if (pdone > 1) break;
1611 if (pdone == 0) break; /* second pass only if regs repositioned */
1612 if (pdone > 1) break;
1614 /* had to position more than once GIVE UP */
1616 /* UNDO all the changes we made to try this */
1618 for (i=0; i < sym->nRegs ; i++ ) {
1619 sym->regs[i] = NULL;
1622 D (fprintf (stderr, "Fill Gap gave up due to positioning for "
1623 "%s in function %s\n",
1624 sym->name, currFunc ? currFunc->name : "UNKNOWN"));
1627 D (fprintf (stderr, "FILLED GAP for %s in function %s\n",
1628 sym->name, currFunc ? currFunc->name : "UNKNOWN"));
1629 _G.totRegAssigned = bitVectSetBit(_G.totRegAssigned,sym->key);
1630 sym->isspilt = sym->spillA = 0 ;
1631 sym->usl.spillLoc->allocreq--;
1632 sym->usl.spillLoc = NULL;
1640 /*-----------------------------------------------------------------*/
1641 /* rUmaskForOp :- returns register mask for an operand */
1642 /*-----------------------------------------------------------------*/
1644 ds390_rUmaskForOp (operand * op)
1650 /* only temporaries are assigned registers */
1654 sym = OP_SYMBOL (op);
1656 /* if spilt or no registers assigned to it
1658 if (sym->isspilt || !sym->nRegs)
1661 rumask = newBitVect (ds390_nRegs);
1663 for (j = 0; j < sym->nRegs; j++)
1665 rumask = bitVectSetBit (rumask,
1666 sym->regs[j]->rIdx);
1672 /*-----------------------------------------------------------------*/
1673 /* regsUsedIniCode :- returns bit vector of registers used in iCode */
1674 /*-----------------------------------------------------------------*/
1676 regsUsedIniCode (iCode * ic)
1678 bitVect *rmask = newBitVect (ds390_nRegs);
1680 /* do the special cases first */
1683 rmask = bitVectUnion (rmask,
1684 ds390_rUmaskForOp (IC_COND (ic)));
1688 /* for the jumptable */
1689 if (ic->op == JUMPTABLE)
1691 rmask = bitVectUnion (rmask,
1692 ds390_rUmaskForOp (IC_JTCOND (ic)));
1697 /* of all other cases */
1699 rmask = bitVectUnion (rmask,
1700 ds390_rUmaskForOp (IC_LEFT (ic)));
1704 rmask = bitVectUnion (rmask,
1705 ds390_rUmaskForOp (IC_RIGHT (ic)));
1708 rmask = bitVectUnion (rmask,
1709 ds390_rUmaskForOp (IC_RESULT (ic)));
1715 /*-----------------------------------------------------------------*/
1716 /* createRegMask - for each instruction will determine the regsUsed */
1717 /*-----------------------------------------------------------------*/
1719 createRegMask (eBBlock ** ebbs, int count)
1723 /* for all blocks */
1724 for (i = 0; i < count; i++)
1728 if (ebbs[i]->noPath &&
1729 (ebbs[i]->entryLabel != entryLabel &&
1730 ebbs[i]->entryLabel != returnLabel))
1733 /* for all instructions */
1734 for (ic = ebbs[i]->sch; ic; ic = ic->next)
1739 if (SKIP_IC2 (ic) || !ic->rlive)
1742 /* first mark the registers used in this
1744 ic->rUsed = regsUsedIniCode (ic);
1745 _G.funcrUsed = bitVectUnion (_G.funcrUsed, ic->rUsed);
1747 /* now create the register mask for those
1748 registers that are in use : this is a
1749 super set of ic->rUsed */
1750 ic->rMask = newBitVect (ds390_nRegs + 1);
1752 /* for all live Ranges alive at this point */
1753 for (j = 1; j < ic->rlive->size; j++)
1758 /* if not alive then continue */
1759 if (!bitVectBitValue (ic->rlive, j))
1762 /* find the live range we are interested in */
1763 if (!(sym = hTabItemWithKey (liveRanges, j)))
1765 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
1766 "createRegMask cannot find live range");
1767 fprintf(stderr, "\tmissing live range: key=%d\n", j);
1771 /* special case for ruonly */
1772 if (sym->ruonly && sym->liveFrom != sym->liveTo) {
1773 int size = getSize(sym->type);
1775 for (k = 0 ; k < size; k++ )
1776 ic->rMask = bitVectSetBit (ic->rMask, j++);
1780 /* if no register assigned to it */
1781 if (!sym->nRegs || sym->isspilt)
1784 /* for all the registers allocated to it */
1785 for (k = 0; k < sym->nRegs; k++)
1788 bitVectSetBit (ic->rMask, sym->regs[k]->rIdx);
1794 /*-----------------------------------------------------------------*/
1795 /* rematStr - returns the rematerialized string for a remat var */
1796 /*-----------------------------------------------------------------*/
1798 rematStr (symbol * sym)
1801 iCode *ic = sym->rematiCode;
1808 /* if plus or minus print the right hand side */
1809 if (ic->op == '+' || ic->op == '-')
1811 SNPRINTF (s, sizeof(buffer) - strlen(buffer),
1812 "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)),
1815 ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
1819 /* cast then continue */
1820 if (IS_CAST_ICODE(ic)) {
1821 ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
1824 /* we reached the end */
1825 SNPRINTF (s, sizeof(buffer) - strlen(buffer),
1826 "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
1833 /*-----------------------------------------------------------------*/
1834 /* regTypeNum - computes the type & number of registers required */
1835 /*-----------------------------------------------------------------*/
1843 /* for each live range do */
1844 for (sym = hTabFirstItem (liveRanges, &k); sym;
1845 sym = hTabNextItem (liveRanges, &k))
1848 /* if used zero times then no registers needed */
1849 if ((sym->liveTo - sym->liveFrom) == 0)
1853 /* if the live range is a temporary */
1857 /* if the type is marked as a conditional */
1858 if (sym->regType == REG_CND)
1861 /* if used in return only then we don't
1863 if (sym->ruonly || sym->accuse)
1865 if (IS_AGGREGATE (sym->type) || sym->isptr)
1866 sym->type = aggrToPtr (sym->type, FALSE);
1870 /* if the symbol has only one definition &
1871 that definition is a get_pointer */
1872 if (bitVectnBitsOn (sym->defs) == 1 &&
1873 (ic = hTabItemWithKey (iCodehTab,
1874 bitVectFirstBit (sym->defs))) &&
1876 !IS_BITVAR (sym->etype) &&
1877 (aggrToPtrDclType (operandType (IC_LEFT (ic)), FALSE) == POINTER))
1880 if (ptrPseudoSymSafe (sym, ic))
1882 ptrPseudoSymConvert (sym, ic, rematStr (OP_SYMBOL (IC_LEFT (ic))));
1886 /* if in data space or idata space then try to
1887 allocate pointer register */
1891 /* if not then we require registers */
1892 sym->nRegs = ((IS_AGGREGATE (sym->type) || sym->isptr) ?
1893 getSize (sym->type = aggrToPtr (sym->type, FALSE)) :
1894 getSize (sym->type));
1898 fprintf (stderr, "allocated more than 4 or 0 registers for type ");
1899 printTypeChain (sym->type, stderr);
1900 fprintf (stderr, "\n");
1903 /* determine the type of register required */
1904 if (sym->nRegs == 1 &&
1905 IS_PTR (sym->type) &&
1907 sym->regType = REG_PTR;
1909 sym->regType = REG_GPR;
1913 /* for the first run we don't provide */
1914 /* registers for true symbols we will */
1915 /* see how things go */
1921 /*-----------------------------------------------------------------*/
1922 /* freeAllRegs - mark all registers as free */
1923 /*-----------------------------------------------------------------*/
1929 for (i = 0; i < ds390_nRegs; i++)
1930 regs390[i].isFree = 1;
1933 /*-----------------------------------------------------------------*/
1934 /* deallocStackSpil - this will set the stack pointer back */
1935 /*-----------------------------------------------------------------*/
1937 DEFSETFUNC (deallocStackSpil)
1945 /*-----------------------------------------------------------------*/
1946 /* farSpacePackable - returns the packable icode for far variables */
1947 /*-----------------------------------------------------------------*/
1949 farSpacePackable (iCode * ic)
1953 /* go thru till we find a definition for the
1954 symbol on the right */
1955 for (dic = ic->prev; dic; dic = dic->prev)
1957 /* if the definition is a call then no */
1958 if ((dic->op == CALL || dic->op == PCALL) &&
1959 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
1964 /* if shift by unknown amount then not */
1965 if ((dic->op == LEFT_OP || dic->op == RIGHT_OP) &&
1966 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
1969 /* if pointer get and size > 1 */
1970 if (POINTER_GET (dic) &&
1971 getSize (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)) > 1)
1974 if (POINTER_SET (dic) &&
1975 getSize (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)) > 1)
1978 /* if any tree is a true symbol in far space */
1979 if (IC_RESULT (dic) &&
1980 IS_TRUE_SYMOP (IC_RESULT (dic)) &&
1981 isOperandInFarSpace (IC_RESULT (dic)))
1984 if (IC_RIGHT (dic) &&
1985 IS_TRUE_SYMOP (IC_RIGHT (dic)) &&
1986 isOperandInFarSpace (IC_RIGHT (dic)) &&
1987 !isOperandEqual (IC_RIGHT (dic), IC_RESULT (ic)))
1990 if (IC_LEFT (dic) &&
1991 IS_TRUE_SYMOP (IC_LEFT (dic)) &&
1992 isOperandInFarSpace (IC_LEFT (dic)) &&
1993 !isOperandEqual (IC_LEFT (dic), IC_RESULT (ic)))
1996 if (isOperandEqual (IC_RIGHT (ic), IC_RESULT (dic)))
1998 if ((dic->op == LEFT_OP ||
1999 dic->op == RIGHT_OP ||
2001 IS_OP_LITERAL (IC_RIGHT (dic)))
2011 /*-----------------------------------------------------------------*/
2012 /* packRegsForAssign - register reduction for assignment */
2013 /*-----------------------------------------------------------------*/
2015 packRegsForAssign (iCode * ic, eBBlock * ebp)
2019 if (!IS_ITEMP (IC_RIGHT (ic)) ||
2020 OP_SYMBOL (IC_RIGHT (ic))->isind ||
2021 OP_LIVETO (IC_RIGHT (ic)) > ic->seq)
2026 /* if the true symbol is defined in far space or on stack
2027 then we should not since this will increase register pressure */
2029 if (isOperandInFarSpace (IC_RESULT (ic)))
2031 if ((dic = farSpacePackable (ic)))
2037 if (isOperandInFarSpace(IC_RESULT(ic)) && !farSpacePackable(ic)) {
2042 /* find the definition of iTempNN scanning backwards if we find a
2043 a use of the true symbol in before we find the definition then
2045 for (dic = ic->prev; dic; dic = dic->prev)
2047 /* if there is a function call then don't pack it */
2048 if ((dic->op == CALL || dic->op == PCALL))
2057 if (IS_TRUE_SYMOP (IC_RESULT (dic)) &&
2058 IS_OP_VOLATILE (IC_RESULT (dic)))
2064 if (IS_SYMOP (IC_RESULT (dic)) &&
2065 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
2067 if (POINTER_SET (dic))
2073 if (IS_SYMOP (IC_RIGHT (dic)) &&
2074 (IC_RIGHT (dic)->key == IC_RESULT (ic)->key ||
2075 IC_RIGHT (dic)->key == IC_RIGHT (ic)->key))
2081 if (IS_SYMOP (IC_LEFT (dic)) &&
2082 (IC_LEFT (dic)->key == IC_RESULT (ic)->key ||
2083 IC_LEFT (dic)->key == IC_RIGHT (ic)->key))
2089 if (POINTER_SET (dic) &&
2090 IC_RESULT (dic)->key == IC_RESULT (ic)->key)
2098 return 0; /* did not find */
2100 /* if the result is on stack or iaccess then it must be
2101 the same atleast one of the operands */
2102 if (OP_SYMBOL (IC_RESULT (ic))->onStack ||
2103 OP_SYMBOL (IC_RESULT (ic))->iaccess)
2106 /* the operation has only one symbol
2107 operator then we can pack */
2108 if ((IC_LEFT (dic) && !IS_SYMOP (IC_LEFT (dic))) ||
2109 (IC_RIGHT (dic) && !IS_SYMOP (IC_RIGHT (dic))))
2112 if (!((IC_LEFT (dic) &&
2113 IC_RESULT (ic)->key == IC_LEFT (dic)->key) ||
2115 IC_RESULT (ic)->key == IC_RIGHT (dic)->key)))
2119 /* found the definition */
2120 /* replace the result with the result of */
2121 /* this assignment and remove this assignment */
2122 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
2124 IC_RESULT (dic) = IC_RESULT (ic);
2126 if (IS_ITEMP (IC_RESULT (dic)) && OP_SYMBOL (IC_RESULT (dic))->liveFrom > dic->seq)
2128 OP_SYMBOL (IC_RESULT (dic))->liveFrom = dic->seq;
2130 /* delete from liverange table also
2131 delete from all the points inbetween and the new
2133 for (sic = dic; sic != ic; sic = sic->next)
2135 bitVectUnSetBit (sic->rlive, IC_RESULT (ic)->key);
2136 if (IS_ITEMP (IC_RESULT (dic)))
2137 bitVectSetBit (sic->rlive, IC_RESULT (dic)->key);
2140 remiCodeFromeBBlock (ebp, ic);
2141 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
2142 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
2143 OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
2147 /*------------------------------------------------------------------*/
2148 /* findAssignToSym : scanning backwards looks for first assig found */
2149 /*------------------------------------------------------------------*/
2151 findAssignToSym (operand * op, iCode * ic)
2155 /* This routine is used to find sequences like
2157 ...; (intervening ops don't use iTempAA or modify FOO)
2158 blah = blah + iTempAA;
2160 and eliminate the use of iTempAA, freeing up its register for
2164 for (dic = ic->prev; dic; dic = dic->prev)
2167 /* if definition by assignment */
2168 if (dic->op == '=' &&
2169 !POINTER_SET (dic) &&
2170 IC_RESULT (dic)->key == op->key
2171 /* && IS_TRUE_SYMOP(IC_RIGHT(dic)) */
2175 /* we are interested only if defined in far space */
2176 /* or in stack space in case of + & - */
2178 /* if assigned to a non-symbol then return
2180 if (!IS_SYMOP (IC_RIGHT (dic)))
2183 /* if the symbol is in far space then
2185 if (isOperandInFarSpace (IC_RIGHT (dic)))
2188 /* for + & - operations make sure that
2189 if it is on the stack it is the same
2190 as one of the three operands */
2191 if ((ic->op == '+' || ic->op == '-') &&
2192 OP_SYMBOL (IC_RIGHT (dic))->onStack)
2195 if (IC_RESULT (ic)->key != IC_RIGHT (dic)->key &&
2196 IC_LEFT (ic)->key != IC_RIGHT (dic)->key &&
2197 IC_RIGHT (ic)->key != IC_RIGHT (dic)->key)
2205 /* if we find an usage then we cannot delete it */
2206 if (IC_LEFT (dic) && IC_LEFT (dic)->key == op->key)
2209 if (IC_RIGHT (dic) && IC_RIGHT (dic)->key == op->key)
2212 if (POINTER_SET (dic) && IC_RESULT (dic)->key == op->key)
2216 /* now make sure that the right side of dic
2217 is not defined between ic & dic */
2220 iCode *sic = dic->next;
2222 for (; sic != ic; sic = sic->next)
2223 if (IC_RESULT (sic) &&
2224 IC_RESULT (sic)->key == IC_RIGHT (dic)->key)
2233 /*-----------------------------------------------------------------*/
2234 /* packRegsForSupport :- reduce some registers for support calls */
2235 /*-----------------------------------------------------------------*/
2237 packRegsForSupport (iCode * ic, eBBlock * ebp)
2241 /* for the left & right operand :- look to see if the
2242 left was assigned a true symbol in far space in that
2243 case replace them */
2244 if (IS_ITEMP (IC_LEFT (ic)) &&
2245 OP_SYMBOL (IC_LEFT (ic))->liveTo <= ic->seq)
2247 iCode *dic = findAssignToSym (IC_LEFT (ic), ic);
2253 /* found it we need to remove it from the
2255 for (sic = dic; sic != ic; sic = sic->next) {
2256 bitVectUnSetBit (sic->rlive, IC_LEFT (ic)->key);
2257 sic->rlive = bitVectSetBit (sic->rlive, IC_RIGHT (dic)->key);
2260 wassert(IS_SYMOP(IC_LEFT (ic)));
2261 wassert(IS_SYMOP(IC_RIGHT (dic)));
2262 IC_LEFT (ic)->operand.symOperand =
2263 IC_RIGHT (dic)->operand.symOperand;
2264 OP_SYMBOL(IC_LEFT(ic))->liveTo = ic->seq;
2265 IC_LEFT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
2266 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
2267 remiCodeFromeBBlock (ebp, dic);
2268 hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
2272 /* do the same for the right operand */
2275 IS_ITEMP (IC_RIGHT (ic)) &&
2276 OP_SYMBOL (IC_RIGHT (ic))->liveTo <= ic->seq)
2278 iCode *dic = findAssignToSym (IC_RIGHT (ic), ic);
2284 /* if this is a subtraction & the result
2285 is a true symbol in far space then don't pack */
2286 if (ic->op == '-' && IS_TRUE_SYMOP (IC_RESULT (dic)))
2288 sym_link *etype = getSpec (operandType (IC_RESULT (dic)));
2289 if (IN_FARSPACE (SPEC_OCLS (etype)))
2292 /* found it we need to remove it from the
2294 for (sic = dic; sic != ic; sic = sic->next) {
2295 bitVectUnSetBit (sic->rlive, IC_RIGHT (ic)->key);
2296 sic->rlive = bitVectSetBit (sic->rlive, IC_RIGHT (dic)->key);
2299 wassert(IS_SYMOP(IC_RIGHT (ic)));
2300 wassert(IS_SYMOP(IC_RIGHT (dic)));
2301 IC_RIGHT (ic)->operand.symOperand =
2302 IC_RIGHT (dic)->operand.symOperand;
2303 IC_RIGHT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
2304 OP_SYMBOL(IC_RIGHT(ic))->liveTo = ic->seq;
2305 remiCodeFromeBBlock (ebp, dic);
2306 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
2307 hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
2314 #define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
2317 /*-----------------------------------------------------------------*/
2318 /* packRegsDPTRnuse - color live ranges that can go into extra DPTRS */
2319 /*-----------------------------------------------------------------*/
2320 static int packRegsDPTRnuse( operand *op , unsigned dptr)
2325 if (!IS_SYMOP(op) || !IS_ITEMP(op)) return 0;
2326 if (OP_SYMBOL(op)->remat || OP_SYMBOL(op)->ruonly || OP_SYMBOL(op)->dptr)
2329 /* first check if any overlapping liverange has already been
2330 assigned to this DPTR */
2331 if (OP_SYMBOL(op)->clashes) {
2332 for (i = 0 ; i < OP_SYMBOL(op)->clashes->size ; i++ ) {
2334 if (bitVectBitValue(OP_SYMBOL(op)->clashes,i)) {
2335 sym = hTabItemWithKey(liveRanges,i);
2336 if (sym->dptr == dptr) return 0;
2341 /* future for more dptrs */
2343 OP_SYMBOL(op)->dptr = dptr;
2347 /* DPTR1 is special since it is also used as a scratch by the backend .
2348 so we walk thru the entire live range of this operand and make sure
2349 DPTR1 will not be used by the backed . The logic here is to find out if
2350 more than one operand in an icode is in far space then we give up : we
2351 don't keep it live across functions for now
2354 ic = hTabFirstItemWK(iCodeSeqhTab,OP_SYMBOL(op)->liveFrom);
2355 for (; ic && ic->seq <= OP_SYMBOL(op)->liveTo;
2356 ic = hTabNextItem(iCodeSeqhTab,&key)) {
2359 if (ic->op == CALL || ic->op == PCALL) return 0;
2361 /* single operand icode are ok */
2362 if (ic->op == IFX || ic->op == IPUSH)
2365 if (ic->op == SEND ) {
2366 if (ic->argreg != 1 ) return 0;
2369 /* two special cases first */
2370 if (POINTER_GET(ic) && !isOperandEqual(IC_LEFT(ic),op) && /* pointer get */
2371 !OP_SYMBOL(IC_LEFT(ic))->ruonly && /* with result in far space */
2372 (isOperandInFarSpace(IC_RESULT(ic)) &&
2373 !isOperandInReg(IC_RESULT(ic)))) {
2377 if (POINTER_SET(ic) && !isOperandEqual(IC_RESULT(ic),op) && /* pointer set */
2378 !OP_SYMBOL(IC_RESULT(ic))->ruonly && /* with right in far space */
2379 (isOperandInFarSpace(IC_RIGHT(ic)) &&
2380 !isOperandInReg(IC_RIGHT(ic)))) {
2384 if (IC_RESULT(ic) && IS_SYMOP(IC_RESULT(ic)) && /* if symbol operand */
2385 !isOperandEqual(IC_RESULT(ic),op) && /* not the same as this */
2386 ((isOperandInFarSpace(IC_RESULT(ic)) || /* in farspace or */
2387 OP_SYMBOL(IC_RESULT(ic))->onStack) && /* on the stack */
2388 !isOperandInReg(IC_RESULT(ic)))) { /* and not in register */
2392 if (IC_LEFT(ic) && IS_SYMOP(IC_LEFT(ic)) && /* if symbol operand */
2393 !isOperandEqual(IC_LEFT(ic),op) && /* not the same as this */
2394 ((isOperandInFarSpace(IC_LEFT(ic)) || /* in farspace or */
2395 OP_SYMBOL(IC_LEFT(ic))->onStack) && /* on the stack */
2396 !isOperandInReg(IC_LEFT(ic)))) { /* and not in register */
2399 /* same for right */
2400 if (IC_RIGHT(ic) && IS_SYMOP(IC_RIGHT(ic)) && /* if symbol operand */
2401 !isOperandEqual(IC_RIGHT(ic),op) && /* not the same as this */
2402 ((isOperandInFarSpace(IC_RIGHT(ic)) || /* in farspace or */
2403 OP_SYMBOL(IC_RIGHT(ic))->onStack) && /* on the stack */
2404 !isOperandInReg(IC_RIGHT(ic)))) { /* and not in register */
2408 // Check that no other ops in this range have been assigned to dptr1.
2409 // I don't understand why this is not caught by the first check, above.
2410 // But it isn't always, see bug 769624.
2411 if (IC_RESULT(ic) && IS_SYMOP(IC_RESULT(ic)) &&
2412 (OP_SYMBOL(IC_RESULT(ic))->dptr == 1))
2414 //fprintf(stderr, "dptr1 already in use in live range #1\n");
2418 if (IC_LEFT(ic) && IS_SYMOP(IC_LEFT(ic)) &&
2419 (OP_SYMBOL(IC_LEFT(ic))->dptr == 1))
2421 //fprintf(stderr, "dptr1 already in use in live range # 2\n");
2425 if (IC_RIGHT(ic) && IS_SYMOP(IC_RIGHT(ic)) &&
2426 (OP_SYMBOL(IC_RIGHT(ic))->dptr == 1))
2428 //fprintf(stderr, "dptr1 already in use in live range # 3\n");
2432 if (nfs && IC_RESULT(ic) && IS_SYMOP(IC_RESULT(ic)) &&
2433 OP_SYMBOL(IC_RESULT(ic))->ruonly) return 0;
2435 if (nfs > 1) return 0;
2437 OP_SYMBOL(op)->dptr = dptr;
2441 /*-----------------------------------------------------------------*/
2442 /* packRegsDPTRuse : - will reduce some registers for single Use */
2443 /*-----------------------------------------------------------------*/
2445 packRegsDPTRuse (operand * op)
2447 /* go thru entire liveRange of this variable & check for
2448 other possible usage of DPTR , if we don't find it the
2449 assign this to DPTR (ruonly)
2454 sym_link *type, *etype;
2456 if (!IS_SYMOP(op) || !IS_ITEMP(op)) return NULL;
2457 if (OP_SYMBOL(op)->remat || OP_SYMBOL(op)->ruonly) return NULL;
2459 /* first check if any overlapping liverange has already been
2461 if (OP_SYMBOL(op)->clashes) {
2462 for (i = 0 ; i < OP_SYMBOL(op)->clashes->size ; i++ ) {
2463 if (bitVectBitValue(OP_SYMBOL(op)->clashes,i)) {
2464 sym = hTabItemWithKey(liveRanges,i);
2465 if (sym->ruonly) return NULL ;
2470 /* no then go thru this guys live range */
2471 dic = ic = hTabFirstItemWK(iCodeSeqhTab,OP_SYMBOL(op)->liveFrom);
2472 for (; ic && ic->seq <= OP_SYMBOL(op)->liveTo;
2473 ic = hTabNextItem(iCodeSeqhTab,&key)) {
2475 if (SKIP_IC3(ic)) continue;
2477 /* if PCALL cannot be sure give up */
2478 if (ic->op == PCALL) return NULL;
2480 /* if SEND & not the first parameter then giveup */
2481 if (ic->op == SEND && ic->argreg != 1 &&
2482 ((isOperandInFarSpace(IC_LEFT(ic)) && !isOperandInReg(IC_LEFT(ic))) ||
2483 isOperandEqual(op,IC_LEFT(ic)))) return NULL;
2485 /* if CALL then make sure it is VOID || return value not used
2486 or the return value is assigned to this one */
2487 if (ic->op == CALL) {
2488 if (OP_SYMBOL(IC_RESULT(ic))->liveTo ==
2489 OP_SYMBOL(IC_RESULT(ic))->liveFrom) continue ;
2490 etype = getSpec(type = operandType(IC_RESULT(ic)));
2491 if (getSize(type) == 0 || isOperandEqual(op,IC_RESULT(ic)))
2496 /* special case of add with a [remat] */
2497 if (ic->op == '+' &&
2498 OP_SYMBOL(IC_LEFT(ic))->remat &&
2499 (isOperandInFarSpace(IC_RIGHT(ic)) &&
2500 !isOperandInReg(IC_RIGHT(ic)))) return NULL ;
2504 if (POINTER_GET(ic) && !isOperandEqual(IC_LEFT(ic),op) &&
2505 getSize(operandType(IC_LEFT(ic))) > 1 ) return NULL ;
2508 if (POINTER_SET(ic) && !isOperandEqual(IC_RESULT(ic),op) &&
2509 getSize(operandType(IC_RESULT(ic))) > 1 ) return NULL;
2511 /* conditionals can destroy 'b' - make sure B wont
2512 be used in this one*/
2513 if ((IS_CONDITIONAL(ic) || ic->op == '*' || ic->op == '/' ||
2514 ic->op == LEFT_OP || ic->op == RIGHT_OP ) &&
2515 getSize(operandType(op)) > 3) return NULL;
2517 /* if this is a cast to a bigger type */
2519 if (!IS_PTR(OP_SYM_TYPE(IC_RESULT(ic))) &&
2520 getSize(OP_SYM_TYPE(IC_RESULT(ic))) >
2521 getSize(OP_SYM_TYPE(IC_RIGHT(ic)))) {
2527 if (IC_RESULT(ic) && IS_SYMOP(IC_RESULT(ic)) &&
2528 !isOperandEqual(IC_RESULT(ic),op) &&
2529 ( ( ( isOperandInFarSpace(IC_RESULT(ic)) || OP_SYMBOL(IC_RESULT(ic))->onStack) &&
2530 !isOperandInReg(IC_RESULT(ic))) ||
2531 OP_SYMBOL(IC_RESULT(ic))->ruonly)) return NULL;
2533 if (IC_RIGHT(ic) && IS_SYMOP(IC_RIGHT(ic)) &&
2534 !isOperandEqual(IC_RIGHT(ic),op) &&
2535 (OP_SYMBOL(IC_RIGHT(ic))->liveTo >= ic->seq ||
2536 IS_TRUE_SYMOP(IC_RIGHT(ic)) ||
2537 OP_SYMBOL(IC_RIGHT(ic))->ruonly) &&
2538 ( ( isOperandInFarSpace(IC_RIGHT(ic)) || OP_SYMBOL(IC_RIGHT(ic))->onStack) &&
2539 !isOperandInReg(IC_RIGHT(ic))) ) return NULL;
2541 if (IC_LEFT(ic) && IS_SYMOP(IC_LEFT(ic)) &&
2542 !isOperandEqual(IC_LEFT(ic),op) &&
2543 (OP_SYMBOL(IC_LEFT(ic))->liveTo >= ic->seq ||
2544 IS_TRUE_SYMOP(IC_LEFT(ic)) ||
2545 OP_SYMBOL(IC_LEFT(ic))->ruonly) &&
2546 ( ( isOperandInFarSpace(IC_LEFT(ic)) || OP_SYMBOL(IC_LEFT(ic))->onStack) &&
2547 !isOperandInReg(IC_LEFT(ic))) ) return NULL;
2549 if (IC_LEFT(ic) && IC_RIGHT(ic) &&
2550 IS_ITEMP(IC_LEFT(ic)) && IS_ITEMP(IC_RIGHT(ic)) &&
2551 (isOperandInFarSpace(IC_LEFT(ic)) && !isOperandInReg(IC_LEFT(ic))) &&
2552 (isOperandInFarSpace(IC_RIGHT(ic)) && !isOperandInReg(IC_RIGHT(ic))))
2555 OP_SYMBOL(op)->ruonly = 1;
2556 if (OP_SYMBOL(op)->usl.spillLoc) {
2557 if (OP_SYMBOL(op)->spillA)
2558 OP_SYMBOL(op)->usl.spillLoc->allocreq--;
2559 OP_SYMBOL(op)->usl.spillLoc = NULL;
2564 /*-----------------------------------------------------------------*/
2565 /* isBitwiseOptimizable - requirements of JEAN LOUIS VERN */
2566 /*-----------------------------------------------------------------*/
2568 isBitwiseOptimizable (iCode * ic)
2570 sym_link *ltype = getSpec (operandType (IC_LEFT (ic)));
2571 sym_link *rtype = getSpec (operandType (IC_RIGHT (ic)));
2573 /* bitwise operations are considered optimizable
2574 under the following conditions (Jean-Louis VERN)
2586 if (IS_LITERAL (rtype) ||
2587 (IS_BITVAR (ltype) && IN_BITSPACE (SPEC_OCLS (ltype))))
2593 /*-----------------------------------------------------------------*/
2594 /* packRegsForAccUse - pack registers for acc use */
2595 /*-----------------------------------------------------------------*/
2597 packRegsForAccUse (iCode * ic)
2601 /* if this is an aggregate, e.g. a one byte char array */
2602 if (IS_AGGREGATE(operandType(IC_RESULT(ic)))) {
2606 /* if we are calling a reentrant function that has stack parameters */
2607 if (ic->op == CALL &&
2608 IFFUNC_ISREENT(operandType(IC_LEFT(ic))) &&
2609 FUNC_HASSTACKPARM(operandType(IC_LEFT(ic))))
2612 if (ic->op == PCALL &&
2613 IFFUNC_ISREENT(operandType(IC_LEFT(ic))->next) &&
2614 FUNC_HASSTACKPARM(operandType(IC_LEFT(ic))->next))
2617 /* if + or - then it has to be one byte result */
2618 if ((ic->op == '+' || ic->op == '-')
2619 && getSize (operandType (IC_RESULT (ic))) > 1)
2622 /* if shift operation make sure right side is not a literal */
2623 if (ic->op == RIGHT_OP &&
2624 (isOperandLiteral (IC_RIGHT (ic)) ||
2625 getSize (operandType (IC_RESULT (ic))) > 1))
2628 if (ic->op == LEFT_OP &&
2629 (isOperandLiteral (IC_RIGHT (ic)) ||
2630 getSize (operandType (IC_RESULT (ic))) > 1))
2633 if (IS_BITWISE_OP (ic) &&
2634 getSize (operandType (IC_RESULT (ic))) > 1)
2638 /* has only one definition */
2639 if (bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) > 1)
2642 /* has only one use */
2643 if (bitVectnBitsOn (OP_USES (IC_RESULT (ic))) > 1)
2646 /* and the usage immediately follows this iCode */
2647 if (!(uic = hTabItemWithKey (iCodehTab,
2648 bitVectFirstBit (OP_USES (IC_RESULT (ic))))))
2651 if (ic->next != uic)
2654 /* if it is a conditional branch then we definitely can */
2658 if (uic->op == JUMPTABLE)
2661 /* if the usage is not is an assignment
2662 or an arithmetic / bitwise / shift operation then not */
2663 if (POINTER_SET (uic) &&
2664 getSize (aggrToPtr (operandType (IC_RESULT (uic)), FALSE)) > 1)
2667 if (uic->op != '=' &&
2668 !IS_ARITHMETIC_OP (uic) &&
2669 !IS_BITWISE_OP (uic) &&
2670 uic->op != LEFT_OP &&
2671 uic->op != RIGHT_OP)
2674 /* if used in ^ operation then make sure right is not a
2676 if (uic->op == '^' && isOperandLiteral (IC_RIGHT (uic)))
2679 /* if shift operation make sure right side is not a literal */
2680 if (uic->op == RIGHT_OP &&
2681 (isOperandLiteral (IC_RIGHT (uic)) ||
2682 getSize (operandType (IC_RESULT (uic))) > 1))
2685 if (uic->op == LEFT_OP &&
2686 (isOperandLiteral (IC_RIGHT (uic)) ||
2687 getSize (operandType (IC_RESULT (uic))) > 1))
2690 /* make sure that the result of this icode is not on the
2691 stack, since acc is used to compute stack offset */
2692 if (isOperandOnStack(IC_RESULT(uic)))
2695 /* if either one of them in far space then we cannot */
2696 if ((IS_TRUE_SYMOP (IC_LEFT (uic)) &&
2697 isOperandInFarSpace (IC_LEFT (uic))) ||
2698 (IS_TRUE_SYMOP (IC_RIGHT (uic)) &&
2699 isOperandInFarSpace (IC_RIGHT (uic))))
2702 /* if the usage has only one operand then we can */
2703 if (IC_LEFT (uic) == NULL ||
2704 IC_RIGHT (uic) == NULL)
2707 /* make sure this is on the left side if not
2708 a '+' since '+' is commutative */
2709 if (ic->op != '+' &&
2710 IC_LEFT (uic)->key != IC_RESULT (ic)->key)
2713 /* if the other one is not on stack then we can */
2714 if (IC_LEFT (uic)->key == IC_RESULT (ic)->key &&
2715 (IS_ITEMP (IC_RIGHT (uic)) ||
2716 (IS_TRUE_SYMOP (IC_RIGHT (uic)) &&
2717 !OP_SYMBOL (IC_RIGHT (uic))->onStack)))
2720 if (IC_RIGHT (uic)->key == IC_RESULT (ic)->key &&
2721 (IS_ITEMP (IC_LEFT (uic)) ||
2722 (IS_TRUE_SYMOP (IC_LEFT (uic)) &&
2723 !OP_SYMBOL (IC_LEFT (uic))->onStack)))
2729 OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
2733 /*-----------------------------------------------------------------*/
2734 /* packForPush - hueristics to reduce iCode for pushing */
2735 /*-----------------------------------------------------------------*/
2737 packForPush (iCode * ic, eBBlock * ebp)
2742 if ((ic->op != IPUSH && ic->op != SEND) || !IS_ITEMP (IC_LEFT (ic)))
2745 /* must have only definition & one usage */
2746 if (bitVectnBitsOn (OP_DEFS (IC_LEFT (ic))) != 1 ||
2747 bitVectnBitsOn (OP_USES (IC_LEFT (ic))) != 1)
2750 /* find the definition */
2751 if (!(dic = hTabItemWithKey (iCodehTab,
2752 bitVectFirstBit (OP_DEFS (IC_LEFT (ic))))))
2755 if (dic->op != '=' || POINTER_SET (dic))
2758 if (dic->eBBlockNum != ic->eBBlockNum) return ;
2760 /* make sure the right side does not have any definitions
2762 dbv = OP_DEFS(IC_RIGHT(dic));
2763 for (lic = ic; lic && lic != dic ; lic = lic->prev) {
2764 if (bitVectBitValue(dbv,lic->key)) return ;
2766 /* make sure they have the same type */
2767 if (IS_SPEC(operandType(IC_LEFT(ic))))
2769 sym_link *itype=operandType(IC_LEFT(ic));
2770 sym_link *ditype=operandType(IC_RIGHT(dic));
2772 if (SPEC_USIGN(itype)!=SPEC_USIGN(ditype) ||
2773 SPEC_LONG(itype)!=SPEC_LONG(ditype))
2776 /* extend the live range of replaced operand if needed */
2777 if (OP_SYMBOL(IC_RIGHT(dic))->liveTo < OP_SYMBOL(IC_LEFT(ic))->liveTo) {
2778 OP_SYMBOL(IC_RIGHT(dic))->liveTo = OP_SYMBOL(IC_LEFT(ic))->liveTo;
2779 OP_SYMBOL(IC_RIGHT(dic))->clashes =
2780 bitVectUnion(OP_SYMBOL(IC_RIGHT(dic))->clashes,
2781 OP_SYMBOL(IC_LEFT(ic))->clashes);
2783 for (lic = ic; lic && lic != dic; lic = lic->prev)
2785 bitVectUnSetBit (lic->rlive, IC_LEFT (ic)->key);
2786 if (IS_ITEMP (IC_RIGHT (dic)))
2787 bitVectSetBit (lic->rlive, IC_RIGHT (dic)->key);
2789 /* we now we know that it has one & only one def & use
2790 and the that the definition is an assignment */
2791 IC_LEFT (ic) = IC_RIGHT (dic);
2793 remiCodeFromeBBlock (ebp, dic);
2794 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
2795 hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
2798 /*-----------------------------------------------------------------*/
2799 /* packRegisters - does some transformations to reduce register */
2801 /*-----------------------------------------------------------------*/
2803 packRegisters (eBBlock * ebp)
2813 /* look for assignments of the form */
2814 /* iTempNN = TRueSym (someoperation) SomeOperand */
2816 /* TrueSym := iTempNN:1 */
2817 for (ic = ebp->sch; ic; ic = ic->next)
2819 /* find assignment of the form TrueSym := iTempNN:1 */
2820 if (ic->op == '=' && !POINTER_SET (ic))
2821 change += packRegsForAssign (ic, ebp);
2828 for (ic = ebp->sch; ic; ic = ic->next)
2830 /* if this is an itemp & result of an address of a true sym
2831 then mark this as rematerialisable */
2832 if (ic->op == ADDRESS_OF &&
2833 IS_ITEMP (IC_RESULT (ic)) &&
2834 IS_TRUE_SYMOP (IC_LEFT (ic)) &&
2835 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
2836 !OP_SYMBOL (IC_LEFT (ic))->onStack)
2839 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
2840 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
2841 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
2845 /* if this is an itemp & used as a pointer
2846 & assigned to a literal then remat */
2847 if (IS_ASSIGN_ICODE(ic) &&
2848 IS_ITEMP(IC_RESULT(ic)) &&
2849 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
2850 isOperandLiteral(IC_RIGHT(ic)))
2852 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
2853 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
2854 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
2857 /* if straight assignment then carry remat flag if
2858 this is the only definition */
2859 if (ic->op == '=' &&
2860 !POINTER_SET (ic) &&
2861 IS_SYMOP (IC_RIGHT (ic)) &&
2862 OP_SYMBOL (IC_RIGHT (ic))->remat &&
2863 !IS_CAST_ICODE(OP_SYMBOL (IC_RIGHT (ic))->rematiCode) &&
2864 bitVectnBitsOn (OP_SYMBOL (IC_RESULT (ic))->defs) <= 1)
2867 OP_SYMBOL (IC_RESULT (ic))->remat =
2868 OP_SYMBOL (IC_RIGHT (ic))->remat;
2869 OP_SYMBOL (IC_RESULT (ic))->rematiCode =
2870 OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
2873 /* if cast to a generic pointer & the pointer being
2874 cast is remat, then we can remat this cast as well */
2875 if (ic->op == CAST &&
2876 IS_SYMOP(IC_RIGHT(ic)) &&
2877 !OP_SYMBOL(IC_RESULT(ic))->isreqv &&
2878 OP_SYMBOL(IC_RIGHT(ic))->remat ) {
2879 sym_link *to_type = operandType(IC_LEFT(ic));
2880 sym_link *from_type = operandType(IC_RIGHT(ic));
2881 if (IS_GENPTR(to_type) && IS_PTR(from_type)) {
2882 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
2883 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
2884 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
2888 /* if this is a +/- operation with a rematerizable
2889 then mark this as rematerializable as well */
2890 if ((ic->op == '+' || ic->op == '-') &&
2891 (IS_SYMOP (IC_LEFT (ic)) &&
2892 IS_ITEMP (IC_RESULT (ic)) &&
2893 OP_SYMBOL (IC_LEFT (ic))->remat &&
2894 (!IS_SYMOP (IC_RIGHT (ic)) || !IS_CAST_ICODE(OP_SYMBOL (IC_RIGHT (ic))->rematiCode)) &&
2895 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
2896 IS_OP_LITERAL (IC_RIGHT (ic))))
2899 //int i = operandLitValue(IC_RIGHT(ic));
2900 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
2901 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
2902 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
2905 /* mark the pointer usages */
2906 if (POINTER_SET (ic) && IS_SYMOP (IC_RESULT (ic)))
2907 OP_SYMBOL (IC_RESULT (ic))->uptr = 1;
2909 if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic)))
2910 OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
2912 if (ic->op == RETURN && IS_SYMOP (IC_LEFT(ic)))
2913 OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
2915 if (ic->op == RECEIVE && ic->argreg == 1 &&
2916 IS_SYMOP (IC_RESULT (ic)) &&
2917 getSize (operandType(IC_RESULT(ic))) <= 3)
2918 OP_SYMBOL (IC_RESULT(ic))->uptr = 1;
2920 if (ic->op == SEND && ic->argreg == 1 &&
2921 IS_SYMOP(IC_LEFT(ic)) &&
2922 getSize (aggrToPtr(operandType(IC_LEFT(ic)),FALSE)) <= 3)
2923 OP_SYMBOL (IC_LEFT(ic))->uptr = 1;
2927 /* if we are using a symbol on the stack
2928 then we should say ds390_ptrRegReq */
2929 if (options.useXstack && ic->parmPush
2930 && (ic->op == IPUSH || ic->op == IPOP))
2932 if (ic->op == IFX && IS_SYMOP (IC_COND (ic)))
2933 ds390_ptrRegReq += ((OP_SYMBOL (IC_COND (ic))->onStack ? !options.stack10bit : 0) +
2934 OP_SYMBOL (IC_COND (ic))->iaccess +
2935 (SPEC_OCLS(OP_SYMBOL (IC_COND (ic))->etype) == idata));
2936 else if (ic->op == JUMPTABLE && IS_SYMOP (IC_JTCOND (ic)))
2937 ds390_ptrRegReq += ((OP_SYMBOL (IC_JTCOND (ic))->onStack ? !options.stack10bit : 0) +
2938 OP_SYMBOL (IC_JTCOND (ic))->iaccess +
2939 (SPEC_OCLS(OP_SYMBOL (IC_JTCOND (ic))->etype) == idata));
2942 if (IS_SYMOP (IC_LEFT (ic)))
2943 ds390_ptrRegReq += ((OP_SYMBOL (IC_LEFT (ic))->onStack ? !options.stack10bit : 0) +
2944 OP_SYMBOL (IC_LEFT (ic))->iaccess +
2945 (SPEC_OCLS(OP_SYMBOL (IC_LEFT (ic))->etype) == idata));
2946 if (IS_SYMOP (IC_RIGHT (ic)))
2947 ds390_ptrRegReq += ((OP_SYMBOL (IC_RIGHT (ic))->onStack ? !options.stack10bit : 0) +
2948 OP_SYMBOL (IC_RIGHT (ic))->iaccess +
2949 (SPEC_OCLS(OP_SYMBOL (IC_RIGHT (ic))->etype) == idata));
2950 if (IS_SYMOP (IC_RESULT (ic)))
2951 ds390_ptrRegReq += ((OP_SYMBOL (IC_RESULT (ic))->onStack ? !options.stack10bit : 0) +
2952 OP_SYMBOL (IC_RESULT (ic))->iaccess +
2953 (SPEC_OCLS(OP_SYMBOL (IC_RESULT (ic))->etype) == idata));
2957 /* if the condition of an if instruction
2958 is defined in the previous instruction and
2959 this is the only usage then
2960 mark the itemp as a conditional */
2961 if ((IS_CONDITIONAL (ic) ||
2962 (IS_BITWISE_OP(ic) && isBitwiseOptimizable (ic))) &&
2963 ic->next && ic->next->op == IFX &&
2964 bitVectnBitsOn (OP_USES(IC_RESULT(ic)))==1 &&
2965 isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
2966 OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
2968 OP_SYMBOL (IC_RESULT (ic))->regType = REG_CND;
2972 /* reduce for support function calls */
2973 if (ic->supportRtn || ic->op == '+' || ic->op == '-')
2974 packRegsForSupport (ic, ebp);
2976 /* some cases the redundant moves can
2977 can be eliminated for return statements . Can be elminated for the first SEND */
2978 if ((ic->op == RETURN ||
2979 ((ic->op == SEND || ic->op == RECEIVE)&& ic->argreg == 1)) &&
2980 !isOperandInFarSpace (IC_LEFT (ic)) &&
2983 packRegsDPTRuse (IC_LEFT (ic));
2986 if (ic->op == CALL) {
2987 sym_link *ftype = operandType(IC_LEFT(ic));
2988 if (getSize(operandType(IC_RESULT(ic))) <= 4 &&
2989 !IFFUNC_ISBUILTIN(ftype)) {
2990 packRegsDPTRuse (IC_RESULT (ic));
2994 /* if pointer set & left has a size more than
2995 one and right is not in far space */
2996 if (POINTER_SET (ic) &&
2997 !isOperandInFarSpace (IC_RIGHT (ic)) &&
2998 IS_SYMOP (IC_RESULT (ic)) &&
2999 !OP_SYMBOL (IC_RESULT (ic))->remat &&
3000 !IS_OP_RUONLY (IC_RIGHT (ic)) &&
3001 getSize (aggrToPtr (operandType (IC_RESULT (ic)), FALSE)) > 1) {
3003 packRegsDPTRuse (IC_RESULT (ic));
3006 /* if pointer get */
3007 if (POINTER_GET (ic) &&
3008 !isOperandInFarSpace (IC_RESULT (ic)) &&
3009 IS_SYMOP (IC_LEFT (ic)) &&
3010 !OP_SYMBOL (IC_LEFT (ic))->remat &&
3011 !IS_OP_RUONLY (IC_RESULT (ic)) &&
3012 getSize (aggrToPtr (operandType (IC_LEFT (ic)), FALSE)) > 1) {
3014 packRegsDPTRuse (IC_LEFT (ic));
3017 /* if this is cast for intergral promotion then
3018 check if only use of the definition of the
3019 operand being casted/ if yes then replace
3020 the result of that arithmetic operation with
3021 this result and get rid of the cast */
3024 sym_link *fromType = operandType (IC_RIGHT (ic));
3025 sym_link *toType = operandType (IC_LEFT (ic));
3027 if (IS_INTEGRAL (fromType) && IS_INTEGRAL (toType) &&
3028 getSize (fromType) != getSize (toType) &&
3029 SPEC_USIGN (fromType) == SPEC_USIGN (toType))
3032 iCode *dic = packRegsDPTRuse (IC_RIGHT (ic));
3035 if (IS_ARITHMETIC_OP (dic))
3037 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
3038 IC_RESULT (dic) = IC_RESULT (ic);
3039 remiCodeFromeBBlock (ebp, ic);
3040 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
3041 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
3042 OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
3046 OP_SYMBOL (IC_RIGHT (ic))->ruonly = 0;
3052 /* if the type from and type to are the same
3053 then if this is the only use then packit */
3054 if (compareType (operandType (IC_RIGHT (ic)),
3055 operandType (IC_LEFT (ic))) == 1)
3057 iCode *dic = packRegsDPTRuse (IC_RIGHT (ic));
3060 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
3061 IC_RESULT (dic) = IC_RESULT (ic);
3062 remiCodeFromeBBlock (ebp, ic);
3063 bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
3064 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
3065 OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
3073 iTempNN := (some variable in farspace) V1
3078 if (ic->op == IPUSH || ic->op == SEND)
3080 packForPush (ic, ebp);
3084 /* pack registers for accumulator use, when the
3085 result of an arithmetic or bit wise operation
3086 has only one use, that use is immediately following
3087 the defintion and the using iCode has only one
3088 operand or has two operands but one is literal &
3089 the result of that operation is not on stack then
3090 we can leave the result of this operation in acc:b
3092 if ((IS_ARITHMETIC_OP (ic)
3093 || IS_CONDITIONAL(ic)
3094 || IS_BITWISE_OP (ic)
3095 || ic->op == LEFT_OP || ic->op == RIGHT_OP
3096 || (ic->op == ADDRESS_OF && isOperandOnStack (IC_LEFT (ic)))
3098 IS_ITEMP (IC_RESULT (ic)) &&
3099 getSize (operandType (IC_RESULT (ic))) <= 2)
3101 packRegsForAccUse (ic);
3106 /*-----------------------------------------------------------------*/
3107 /* assignRegisters - assigns registers to each live range as need */
3108 /*-----------------------------------------------------------------*/
3110 ds390_assignRegisters (eBBlock ** ebbs, int count)
3115 setToNull ((void *) &_G.funcrUsed);
3116 setToNull ((void *) &_G.regAssigned);
3117 setToNull ((void *) &_G.totRegAssigned);
3118 setToNull ((void *) &_G.funcrUsed);
3119 ds390_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
3121 if (options.model != MODEL_FLAT24) options.stack10bit = 0;
3122 /* change assignments this will remove some
3123 live ranges reducing some register pressure */
3124 for (i = 0; i < count; i++)
3125 packRegisters (ebbs[i]);
3127 /* liveranges probably changed by register packing
3128 so we compute them again */
3129 recomputeLiveRanges (ebbs, count);
3131 if (options.dump_pack)
3132 dumpEbbsToFileExt (DUMP_PACK, ebbs, count);
3134 /* first determine for each live range the number of
3135 registers & the type of registers required for each */
3138 /* and serially allocate registers */
3139 serialRegAssign (ebbs, count);
3146 /* if stack was extended then tell the user */
3149 /* werror(W_TOOMANY_SPILS,"stack", */
3150 /* _G.stackExtend,currFunc->name,""); */
3156 /* werror(W_TOOMANY_SPILS,"data space", */
3157 /* _G.dataExtend,currFunc->name,""); */
3161 /* after that create the register mask
3162 for each of the instruction */
3163 createRegMask (ebbs, count);
3165 /* redo that offsets for stacked automatic variables */
3167 redoStackOffsets ();
3169 /* make sure r0 & r1 are flagged as used if they might be used */
3171 if (currFunc && ds390_ptrRegReq)
3173 currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, R0_IDX);
3174 currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, R1_IDX);
3177 if (options.dump_rassgn) {
3178 dumpEbbsToFileExt (DUMP_RASSGN, ebbs, count);
3179 dumpLiveRanges (DUMP_LRANGE, liveRanges);
3182 /* do the overlaysegment stuff SDCCmem.c */
3183 doOverlays (ebbs, count);
3185 /* now get back the chain */
3186 ic = iCodeLabelOptimize (iCodeFromeBBlock (ebbs, count));
3190 /* free up any _G.stackSpil locations allocated */
3191 applyToSet (_G.stackSpil, deallocStackSpil);
3193 setToNull ((void *) &_G.stackSpil);
3194 setToNull ((void *) &_G.spiltSet);
3195 /* mark all registers as free */