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 /*-----------------------------------------------------------------*/
45 bitVect *totRegAssigned; /* final set of LRs that got into registers */
48 bitVect *funcrUsed; /* registers used in a function */
54 /* Shared with gen.c */
55 int ds390_ptrRegReq; /* one byte pointer register required */
61 {REG_GPR, R2_IDX, REG_GPR, "r2", "ar2", "0", 2, 1, 1},
62 {REG_GPR, R3_IDX, REG_GPR, "r3", "ar3", "0", 3, 1, 1},
63 {REG_GPR, R4_IDX, REG_GPR, "r4", "ar4", "0", 4, 1, 1},
64 {REG_GPR, R5_IDX, REG_GPR, "r5", "ar5", "0", 5, 1, 1},
65 {REG_GPR, R6_IDX, REG_GPR, "r6", "ar6", "0", 6, 1, 1},
66 {REG_GPR, R7_IDX, REG_GPR, "r7", "ar7", "0", 7, 1, 1},
67 {REG_PTR, R0_IDX, REG_PTR, "r0", "ar0", "0", 0, 1, 1},
68 {REG_PTR, R1_IDX, REG_PTR, "r1", "ar1", "0", 1, 1, 1},
69 {REG_GPR, X8_IDX, REG_GPR, "x8", "x8", "xreg", 0, 0, 0},
70 {REG_GPR, X9_IDX, REG_GPR, "x9", "x9", "xreg", 1, 0, 0},
71 {REG_GPR, X10_IDX, REG_GPR, "x10", "x10", "xreg", 2, 0, 0},
72 {REG_GPR, X11_IDX, REG_GPR, "x11", "x11", "xreg", 3, 0, 0},
73 {REG_GPR, X12_IDX, REG_GPR, "x12", "x12", "xreg", 4, 0, 0},
74 {REG_CND, CND_IDX, REG_GPR, "C", "C", "xreg", 0, 0, 0},
75 {REG_GPR, DPL_IDX, REG_GPR, "dpl", "dpl", "dpl", 0, 0, 0},
76 {REG_GPR, DPH_IDX, REG_GPR, "dph", "dph", "dph", 0, 0, 0},
77 {REG_GPR, DPX_IDX, REG_GPR, "dpx", "dpx", "dpx", 0, 0, 0},
78 {REG_GPR, B_IDX, REG_GPR, "b", "b", "b", 0, 0, 0},
81 static void spillThis (symbol *);
82 static void freeAllRegs ();
84 /*-----------------------------------------------------------------*/
85 /* allocReg - allocates register of given type */
86 /*-----------------------------------------------------------------*/
92 for (i = 0; i < ds390_nRegs; i++)
95 /* if type is given as 0 then any
96 free register will do */
100 regs390[i].isFree = 0;
103 bitVectSetBit (currFunc->regsUsed, i);
106 /* other wise look for specific type
108 if (regs390[i].isFree &&
109 regs390[i].type == type)
111 regs390[i].isFree = 0;
114 bitVectSetBit (currFunc->regsUsed, i);
121 /*-----------------------------------------------------------------*/
122 /* ds390_regWithIdx - returns pointer to register wit index number */
123 /*-----------------------------------------------------------------*/
125 ds390_regWithIdx (int idx)
129 for (i = 0; i < ds390_nRegs; i++)
130 if (regs390[i].rIdx == idx)
133 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
134 "regWithIdx not found");
138 /*-----------------------------------------------------------------*/
139 /* freeReg - frees a register */
140 /*-----------------------------------------------------------------*/
147 /*-----------------------------------------------------------------*/
148 /* useReg - marks a register as used */
149 /*-----------------------------------------------------------------*/
157 /*-----------------------------------------------------------------*/
158 /* nFreeRegs - returns number of free registers */
159 /*-----------------------------------------------------------------*/
166 for (i = 0; i < ds390_nRegs; i++)
167 if (regs390[i].isFree && regs390[i].type == type)
172 /*-----------------------------------------------------------------*/
173 /* nfreeRegsType - free registers with type */
174 /*-----------------------------------------------------------------*/
176 nfreeRegsType (int type)
181 if ((nfr = nFreeRegs (type)) == 0)
182 return nFreeRegs (REG_GPR);
185 return nFreeRegs (type);
189 /*-----------------------------------------------------------------*/
190 /* allDefsOutOfRange - all definitions are out of a range */
191 /*-----------------------------------------------------------------*/
193 allDefsOutOfRange (bitVect * defs, int fseq, int toseq)
200 for (i = 0; i < defs->size; i++)
204 if (bitVectBitValue (defs, i) &&
205 (ic = hTabItemWithKey (iCodehTab, i)) &&
206 (ic->seq >= fseq && ic->seq <= toseq))
215 /*-----------------------------------------------------------------*/
216 /* computeSpillable - given a point find the spillable live ranges */
217 /*-----------------------------------------------------------------*/
219 computeSpillable (iCode * ic)
223 /* spillable live ranges are those that are live at this
224 point . the following categories need to be subtracted
226 a) - those that are already spilt
227 b) - if being used by this one
228 c) - defined by this one */
230 spillable = bitVectCopy (ic->rlive);
232 bitVectCplAnd (spillable, _G.spiltSet); /* those already spilt */
234 bitVectCplAnd (spillable, ic->uses); /* used in this one */
235 bitVectUnSetBit (spillable, ic->defKey);
236 spillable = bitVectIntersect (spillable, _G.regAssigned);
241 /*-----------------------------------------------------------------*/
242 /* noSpilLoc - return true if a variable has no spil location */
243 /*-----------------------------------------------------------------*/
245 noSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
247 return (sym->usl.spillLoc ? 0 : 1);
250 /*-----------------------------------------------------------------*/
251 /* hasSpilLoc - will return 1 if the symbol has spil location */
252 /*-----------------------------------------------------------------*/
254 hasSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
256 return (sym->usl.spillLoc ? 1 : 0);
259 /*-----------------------------------------------------------------*/
260 /* directSpilLoc - will return 1 if the splilocation is in direct */
261 /*-----------------------------------------------------------------*/
263 directSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
265 if (sym->usl.spillLoc &&
266 (IN_DIRSPACE (SPEC_OCLS (sym->usl.spillLoc->etype))))
272 /*-----------------------------------------------------------------*/
273 /* hasSpilLocnoUptr - will return 1 if the symbol has spil location */
274 /* but is not used as a pointer */
275 /*-----------------------------------------------------------------*/
277 hasSpilLocnoUptr (symbol * sym, eBBlock * ebp, iCode * ic)
279 return ((sym->usl.spillLoc && !sym->uptr) ? 1 : 0);
282 /*-----------------------------------------------------------------*/
283 /* rematable - will return 1 if the remat flag is set */
284 /*-----------------------------------------------------------------*/
286 rematable (symbol * sym, eBBlock * ebp, iCode * ic)
291 /*-----------------------------------------------------------------*/
292 /* notUsedInBlock - not used in this block */
293 /*-----------------------------------------------------------------*/
295 notUsedInBlock (symbol * sym, eBBlock * ebp, iCode * ic)
297 return (!bitVectBitsInCommon (sym->defs, ebp->usesDefs) &&
298 allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq));
299 /* return (!bitVectBitsInCommon(sym->defs,ebp->usesDefs)); */
302 /*-----------------------------------------------------------------*/
303 /* notUsedInRemaining - not used or defined in remain of the block */
304 /*-----------------------------------------------------------------*/
306 notUsedInRemaining (symbol * sym, eBBlock * ebp, iCode * ic)
308 return ((usedInRemaining (operandFromSymbol (sym), ic) ? 0 : 1) &&
309 allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq));
312 /*-----------------------------------------------------------------*/
313 /* allLRs - return true for all */
314 /*-----------------------------------------------------------------*/
316 allLRs (symbol * sym, eBBlock * ebp, iCode * ic)
321 /*-----------------------------------------------------------------*/
322 /* liveRangesWith - applies function to a given set of live range */
323 /*-----------------------------------------------------------------*/
325 liveRangesWith (bitVect * lrs, int (func) (symbol *, eBBlock *, iCode *),
326 eBBlock * ebp, iCode * ic)
331 if (!lrs || !lrs->size)
334 for (i = 1; i < lrs->size; i++)
337 if (!bitVectBitValue (lrs, i))
340 /* if we don't find it in the live range
341 hash table we are in serious trouble */
342 if (!(sym = hTabItemWithKey (liveRanges, i)))
344 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
345 "liveRangesWith could not find liveRange");
349 if (func (sym, ebp, ic) && bitVectBitValue (_G.regAssigned, sym->key))
350 addSetHead (&rset, sym);
357 /*-----------------------------------------------------------------*/
358 /* leastUsedLR - given a set determines which is the least used */
359 /*-----------------------------------------------------------------*/
361 leastUsedLR (set * sset)
363 symbol *sym = NULL, *lsym = NULL;
365 sym = lsym = setFirstItem (sset);
370 for (; lsym; lsym = setNextItem (sset))
373 /* if usage is the same then prefer
374 the spill the smaller of the two */
375 if (lsym->used == sym->used)
376 if (getSize (lsym->type) < getSize (sym->type))
380 if (lsym->used < sym->used)
385 setToNull ((void **) &sset);
390 /*-----------------------------------------------------------------*/
391 /* noOverLap - will iterate through the list looking for over lap */
392 /*-----------------------------------------------------------------*/
394 noOverLap (set * itmpStack, symbol * fsym)
398 for (sym = setFirstItem (itmpStack); sym;
399 sym = setNextItem (itmpStack))
401 if (bitVectBitValue(sym->clashes,fsym->key)) return 0;
406 /*-----------------------------------------------------------------*/
407 /* isFree - will return 1 if the a free spil location is found */
408 /*-----------------------------------------------------------------*/
413 V_ARG (symbol **, sloc);
414 V_ARG (symbol *, fsym);
416 /* if already found */
420 /* if it is free && and the itmp assigned to
421 this does not have any overlapping live ranges
422 with the one currently being assigned and
423 the size can be accomodated */
425 noOverLap (sym->usl.itmpStack, fsym) &&
426 getSize (sym->type) >= getSize (fsym->type))
435 /*-----------------------------------------------------------------*/
436 /* spillLRWithPtrReg :- will spil those live ranges which use PTR */
437 /*-----------------------------------------------------------------*/
439 spillLRWithPtrReg (symbol * forSym)
445 if (!_G.regAssigned ||
446 bitVectIsZero (_G.regAssigned))
449 r0 = ds390_regWithIdx (R0_IDX);
450 r1 = ds390_regWithIdx (R1_IDX);
452 /* for all live ranges */
453 for (lrsym = hTabFirstItem (liveRanges, &k); lrsym;
454 lrsym = hTabNextItem (liveRanges, &k))
458 /* if no registers assigned to it or
460 /* if it does not overlap with this then
461 not need to spill it */
463 if (lrsym->isspilt || !lrsym->nRegs ||
464 (lrsym->liveTo < forSym->liveFrom))
467 /* go thru the registers : if it is either
468 r0 or r1 then spil it */
469 for (j = 0; j < lrsym->nRegs; j++)
470 if (lrsym->regs[j] == r0 ||
471 lrsym->regs[j] == r1)
480 /*-----------------------------------------------------------------*/
481 /* createStackSpil - create a location on the stack to spil */
482 /*-----------------------------------------------------------------*/
484 createStackSpil (symbol * sym)
487 int useXstack, model, noOverlay;
491 /* first go try and find a free one that is already
492 existing on the stack */
493 if (applyToSet (_G.stackSpil, isFree, &sloc, sym))
495 /* found a free one : just update & return */
496 sym->usl.spillLoc = sloc;
500 addSetHead (&sloc->usl.itmpStack, sym);
504 /* could not then have to create one , this is the hard part
505 we need to allocate this on the stack : this is really a
506 hack!! but cannot think of anything better at this time */
508 if (sprintf (slocBuffer, "sloc%d", _G.slocNum++) >= sizeof (slocBuffer))
510 fprintf (stderr, "***Internal error: slocBuffer overflowed: %s:%d\n",
515 sloc = newiTemp (slocBuffer);
517 /* set the type to the spilling symbol */
518 sloc->type = copyLinkChain (sym->type);
519 sloc->etype = getSpec (sloc->type);
520 if (options.model == MODEL_SMALL) {
521 SPEC_SCLS (sloc->etype) = S_DATA;
523 SPEC_SCLS (sloc->etype) = S_XDATA;
525 SPEC_EXTR (sloc->etype) = 0;
527 /* we don't allow it to be allocated`
528 onto the external stack since : so we
529 temporarily turn it off ; we also
530 turn off memory model to prevent
531 the spil from going to the external storage
532 and turn off overlaying
535 useXstack = options.useXstack;
536 model = options.model;
537 noOverlay = options.noOverlay;
538 options.noOverlay = 1;
540 /* options.model = options.useXstack = 0; */
544 options.useXstack = useXstack;
545 options.model = model;
546 options.noOverlay = noOverlay;
547 sloc->isref = 1; /* to prevent compiler warning */
549 /* if it is on the stack then update the stack */
550 if (IN_STACK (sloc->etype))
552 currFunc->stack += getSize (sloc->type);
553 _G.stackExtend += getSize (sloc->type);
556 _G.dataExtend += getSize (sloc->type);
558 /* add it to the _G.stackSpil set */
559 addSetHead (&_G.stackSpil, sloc);
560 sym->usl.spillLoc = sloc;
563 /* add it to the set of itempStack set
564 of the spill location */
565 addSetHead (&sloc->usl.itmpStack, sym);
569 /*-----------------------------------------------------------------*/
570 /* isSpiltOnStack - returns true if the spil location is on stack */
571 /*-----------------------------------------------------------------*/
573 isSpiltOnStack (symbol * sym)
583 /* if (sym->_G.stackSpil) */
586 if (!sym->usl.spillLoc)
589 etype = getSpec (sym->usl.spillLoc->type);
590 if (IN_STACK (etype))
596 /*-----------------------------------------------------------------*/
597 /* spillThis - spils a specific operand */
598 /*-----------------------------------------------------------------*/
600 spillThis (symbol * sym)
603 /* if this is rematerializable or has a spillLocation
604 we are okay, else we need to create a spillLocation
606 if (!(sym->remat || sym->usl.spillLoc))
607 createStackSpil (sym);
610 /* mark it has spilt & put it in the spilt set */
611 sym->isspilt = sym->spillA = 1;
612 _G.spiltSet = bitVectSetBit (_G.spiltSet, sym->key);
614 bitVectUnSetBit (_G.regAssigned, sym->key);
615 bitVectUnSetBit (_G.totRegAssigned, sym->key);
617 for (i = 0; i < sym->nRegs; i++)
621 freeReg (sym->regs[i]);
625 /* if spilt on stack then free up r0 & r1
626 if they could have been assigned to some
628 if (!ds390_ptrRegReq && isSpiltOnStack (sym))
630 ds390_ptrRegReq += !options.stack10bit;
631 spillLRWithPtrReg (sym);
634 if (sym->usl.spillLoc && !sym->remat)
635 sym->usl.spillLoc->allocreq++;
639 /*-----------------------------------------------------------------*/
640 /* selectSpil - select a iTemp to spil : rather a simple procedure */
641 /*-----------------------------------------------------------------*/
643 selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
645 bitVect *lrcs = NULL;
649 /* get the spillable live ranges */
650 lrcs = computeSpillable (ic);
652 /* get all live ranges that are rematerizable */
653 if ((selectS = liveRangesWith (lrcs, rematable, ebp, ic)))
656 /* return the least used of these */
657 return leastUsedLR (selectS);
660 /* get live ranges with spillLocations in direct space */
661 if ((selectS = liveRangesWith (lrcs, directSpilLoc, ebp, ic)))
663 sym = leastUsedLR (selectS);
664 strcpy (sym->rname, (sym->usl.spillLoc->rname[0] ?
665 sym->usl.spillLoc->rname :
666 sym->usl.spillLoc->name));
668 /* mark it as allocation required */
669 sym->usl.spillLoc->allocreq++;
673 /* if the symbol is local to the block then */
674 if (forSym->liveTo < ebp->lSeq)
677 /* check if there are any live ranges allocated
678 to registers that are not used in this block */
679 if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInBlock, ebp, ic)))
681 sym = leastUsedLR (selectS);
682 /* if this is not rematerializable */
691 /* check if there are any live ranges that not
692 used in the remainder of the block */
693 if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInRemaining, ebp, ic)))
695 sym = leastUsedLR (selectS);
708 /* find live ranges with spillocation && not used as pointers */
709 if ((selectS = liveRangesWith (lrcs, hasSpilLocnoUptr, ebp, ic)))
712 sym = leastUsedLR (selectS);
713 /* mark this as allocation required */
714 sym->usl.spillLoc->allocreq++;
718 /* find live ranges with spillocation */
719 if ((selectS = liveRangesWith (lrcs, hasSpilLoc, ebp, ic)))
722 sym = leastUsedLR (selectS);
723 sym->usl.spillLoc->allocreq++;
727 /* couldn't find then we need to create a spil
728 location on the stack , for which one? the least
730 if ((selectS = liveRangesWith (lrcs, noSpilLoc, ebp, ic)))
733 /* return a created spil location */
734 sym = createStackSpil (leastUsedLR (selectS));
735 sym->usl.spillLoc->allocreq++;
739 /* this is an extreme situation we will spill
740 this one : happens very rarely but it does happen */
746 /*-----------------------------------------------------------------*/
747 /* spilSomething - spil some variable & mark registers as free */
748 /*-----------------------------------------------------------------*/
750 spilSomething (iCode * ic, eBBlock * ebp, symbol * forSym)
755 /* get something we can spil */
756 ssym = selectSpil (ic, ebp, forSym);
758 /* mark it as spilt */
759 ssym->isspilt = ssym->spillA = 1;
760 _G.spiltSet = bitVectSetBit (_G.spiltSet, ssym->key);
762 /* mark it as not register assigned &
763 take it away from the set */
764 bitVectUnSetBit (_G.regAssigned, ssym->key);
765 bitVectUnSetBit (_G.totRegAssigned, ssym->key);
767 /* mark the registers as free */
768 for (i = 0; i < ssym->nRegs; i++)
770 freeReg (ssym->regs[i]);
772 /* if spilt on stack then free up r0 & r1
773 if they could have been assigned to as gprs */
774 if (!ds390_ptrRegReq && isSpiltOnStack (ssym) && !options.stack10bit)
777 spillLRWithPtrReg (ssym);
780 /* if this was a block level spil then insert push & pop
781 at the start & end of block respectively */
784 iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
785 /* add push to the start of the block */
786 addiCodeToeBBlock (ebp, nic, (ebp->sch->op == LABEL ?
787 ebp->sch->next : ebp->sch));
788 nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
789 /* add pop to the end of the block */
790 addiCodeToeBBlock (ebp, nic, NULL);
793 /* if spilt because not used in the remainder of the
794 block then add a push before this instruction and
795 a pop at the end of the block */
796 if (ssym->remainSpil)
799 iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
800 /* add push just before this instruction */
801 addiCodeToeBBlock (ebp, nic, ic);
803 nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
804 /* add pop to the end of the block */
805 addiCodeToeBBlock (ebp, nic, NULL);
814 /*-----------------------------------------------------------------*/
815 /* getRegPtr - will try for PTR if not a GPR type if not spil */
816 /*-----------------------------------------------------------------*/
818 getRegPtr (iCode * ic, eBBlock * ebp, symbol * sym)
823 /* try for a ptr type */
824 if ((reg = allocReg (REG_PTR)))
827 /* try for gpr type */
828 if ((reg = allocReg (REG_GPR)))
831 /* we have to spil */
832 if (!spilSomething (ic, ebp, sym))
835 /* this looks like an infinite loop but
836 in really selectSpil will abort */
840 /*-----------------------------------------------------------------*/
841 /* getRegGpr - will try for GPR if not spil */
842 /*-----------------------------------------------------------------*/
844 getRegGpr (iCode * ic, eBBlock * ebp, symbol * sym)
849 /* try for gpr type */
850 if ((reg = allocReg (REG_GPR)))
853 if (!ds390_ptrRegReq)
854 if ((reg = allocReg (REG_PTR)))
857 /* we have to spil */
858 if (!spilSomething (ic, ebp, sym))
861 /* this looks like an infinite loop but
862 in really selectSpil will abort */
866 /*-----------------------------------------------------------------*/
867 /* getRegPtrNoSpil - get it cannot split */
868 /*-----------------------------------------------------------------*/
869 static regs *getRegPtrNoSpil()
873 /* try for a ptr type */
874 if ((reg = allocReg (REG_PTR)))
877 /* try for gpr type */
878 if ((reg = allocReg (REG_GPR)))
884 /*-----------------------------------------------------------------*/
885 /* getRegGprNoSpil - get it cannot split */
886 /*-----------------------------------------------------------------*/
887 static regs *getRegGprNoSpil()
891 if ((reg = allocReg (REG_GPR)))
894 if (!ds390_ptrRegReq)
895 if ((reg = allocReg (REG_PTR)))
901 /*-----------------------------------------------------------------*/
902 /* symHasReg - symbol has a given register */
903 /*-----------------------------------------------------------------*/
905 symHasReg (symbol * sym, regs * reg)
909 for (i = 0; i < sym->nRegs; i++)
910 if (sym->regs[i] == reg)
916 /*-----------------------------------------------------------------*/
917 /* deassignLRs - check the live to and if they have registers & are */
918 /* not spilt then free up the registers */
919 /*-----------------------------------------------------------------*/
921 deassignLRs (iCode * ic, eBBlock * ebp)
927 for (sym = hTabFirstItem (liveRanges, &k); sym;
928 sym = hTabNextItem (liveRanges, &k))
932 /* if it does not end here */
933 if (sym->liveTo > ic->seq)
936 /* if it was spilt on stack then we can
937 mark the stack spil location as free */
942 sym->usl.spillLoc->isFree = 1;
948 if (!bitVectBitValue (_G.regAssigned, sym->key))
951 /* special case check if this is an IFX &
952 the privious one was a pop and the
953 previous one was not spilt then keep track
955 if (ic->op == IFX && ic->prev &&
956 ic->prev->op == IPOP &&
957 !ic->prev->parmPush &&
958 !OP_SYMBOL (IC_LEFT (ic->prev))->isspilt)
959 psym = OP_SYMBOL (IC_LEFT (ic->prev));
965 bitVectUnSetBit (_G.regAssigned, sym->key);
967 /* if the result of this one needs registers
968 and does not have it then assign it right
970 if (IC_RESULT (ic) &&
971 !(SKIP_IC2 (ic) || /* not a special icode */
972 ic->op == JUMPTABLE ||
978 (result = OP_SYMBOL (IC_RESULT (ic))) && /* has a result */
979 result->liveTo > ic->seq && /* and will live beyond this */
980 result->liveTo <= ebp->lSeq && /* does not go beyond this block */
981 result->regType == sym->regType && /* same register types */
982 result->nRegs && /* which needs registers */
983 !result->isspilt && /* and does not already have them */
985 !bitVectBitValue (_G.regAssigned, result->key) &&
986 /* the number of free regs + number of regs in this LR
987 can accomodate the what result Needs */
988 ((nfreeRegsType (result->regType) +
989 sym->nRegs) >= result->nRegs)
993 for (i = 0; i < result->nRegs; i++)
995 result->regs[i] = sym->regs[i];
997 result->regs[i] = getRegGpr (ic, ebp, result);
999 _G.regAssigned = bitVectSetBit (_G.regAssigned, result->key);
1000 _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, result->key);
1004 /* free the remaining */
1005 for (; i < sym->nRegs; i++)
1009 if (!symHasReg (psym, sym->regs[i]))
1010 freeReg (sym->regs[i]);
1013 freeReg (sym->regs[i]);
1020 /*-----------------------------------------------------------------*/
1021 /* reassignLR - reassign this to registers */
1022 /*-----------------------------------------------------------------*/
1024 reassignLR (operand * op)
1026 symbol *sym = OP_SYMBOL (op);
1029 /* not spilt any more */
1030 sym->isspilt = sym->spillA = sym->blockSpil = sym->remainSpil = 0;
1031 bitVectUnSetBit (_G.spiltSet, sym->key);
1033 _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
1034 _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, sym->key);
1038 for (i = 0; i < sym->nRegs; i++)
1039 sym->regs[i]->isFree = 0;
1042 /*-----------------------------------------------------------------*/
1043 /* willCauseSpill - determines if allocating will cause a spill */
1044 /*-----------------------------------------------------------------*/
1046 willCauseSpill (int nr, int rt)
1048 /* first check if there are any avlb registers
1049 of te type required */
1052 /* special case for pointer type
1053 if pointer type not avlb then
1054 check for type gpr */
1055 if (nFreeRegs (rt) >= nr)
1057 if (nFreeRegs (REG_GPR) >= nr)
1062 if (ds390_ptrRegReq)
1064 if (nFreeRegs (rt) >= nr)
1069 if (nFreeRegs (REG_PTR) +
1070 nFreeRegs (REG_GPR) >= nr)
1075 /* it will cause a spil */
1079 /*-----------------------------------------------------------------*/
1080 /* positionRegs - the allocator can allocate same registers to res- */
1081 /* ult and operand, if this happens make sure they are in the same */
1082 /* position as the operand otherwise chaos results */
1083 /*-----------------------------------------------------------------*/
1085 positionRegs (symbol * result, symbol * opsym, int lineno)
1087 int count = min (result->nRegs, opsym->nRegs);
1088 int i, j = 0, shared = 0;
1091 /* if the result has been spilt then cannot share */
1096 /* first make sure that they actually share */
1097 for (i = 0; i < count; i++)
1099 for (j = 0; j < count; j++)
1101 if (result->regs[i] == opsym->regs[j] && i != j)
1111 regs *tmp = result->regs[i];
1112 result->regs[i] = result->regs[j];
1113 result->regs[j] = tmp;
1120 /*-----------------------------------------------------------------*/
1121 /* serialRegAssign - serially allocate registers to the variables */
1122 /*-----------------------------------------------------------------*/
1124 serialRegAssign (eBBlock ** ebbs, int count)
1128 /* for all blocks */
1129 for (i = 0; i < count; i++)
1134 if (ebbs[i]->noPath &&
1135 (ebbs[i]->entryLabel != entryLabel &&
1136 ebbs[i]->entryLabel != returnLabel))
1139 /* of all instructions do */
1140 for (ic = ebbs[i]->sch; ic; ic = ic->next)
1143 /* if this is an ipop that means some live
1144 range will have to be assigned again */
1146 reassignLR (IC_LEFT (ic));
1148 /* if result is present && is a true symbol */
1149 if (IC_RESULT (ic) && ic->op != IFX &&
1150 IS_TRUE_SYMOP (IC_RESULT (ic)))
1151 OP_SYMBOL (IC_RESULT (ic))->allocreq++;
1153 /* take away registers from live
1154 ranges that end at this instruction */
1155 deassignLRs (ic, ebbs[i]);
1157 /* some don't need registers */
1158 if (SKIP_IC2 (ic) ||
1159 ic->op == JUMPTABLE ||
1163 (IC_RESULT (ic) && POINTER_SET (ic)))
1166 /* now we need to allocate registers
1167 only for the result */
1170 symbol *sym = OP_SYMBOL (IC_RESULT (ic));
1176 /* if it does not need or is spilt
1177 or is already assigned to registers
1178 or will not live beyond this instructions */
1181 bitVectBitValue (_G.regAssigned, sym->key) ||
1182 sym->liveTo <= ic->seq)
1185 /* if some liverange has been spilt at the block level
1186 and this one live beyond this block then spil this
1188 if (_G.blockSpil && sym->liveTo > ebbs[i]->lSeq)
1193 /* if trying to allocate this will cause
1194 a spill and there is nothing to spill
1195 or this one is rematerializable then
1197 willCS = willCauseSpill (sym->nRegs, sym->regType);
1198 spillable = computeSpillable (ic);
1200 (willCS && bitVectIsZero (spillable)))
1208 /* if it has a spillocation & is used less than
1209 all other live ranges then spill this */
1211 if (sym->usl.spillLoc) {
1212 symbol *leastUsed = leastUsedLR (liveRangesWith (spillable,
1213 allLRs, ebbs[i], ic));
1214 if (leastUsed && leastUsed->used > sym->used) {
1219 /* if none of the liveRanges have a spillLocation then better
1220 to spill this one than anything else already assigned to registers */
1221 if (liveRangesWith(spillable,noSpilLoc,ebbs[i],ic)) {
1228 /* if we need ptr regs for the right side
1230 if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic))
1231 && getSize (OP_SYMBOL (IC_LEFT (ic))->type)
1232 <= (unsigned) PTRSIZE)
1237 /* else we assign registers to it */
1238 _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
1239 _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, sym->key);
1241 for (j = 0; j < sym->nRegs; j++)
1243 if (sym->regType == REG_PTR)
1244 sym->regs[j] = getRegPtr (ic, ebbs[i], sym);
1246 sym->regs[j] = getRegGpr (ic, ebbs[i], sym);
1248 /* if the allocation falied which means
1249 this was spilt then break */
1253 /* if it shares registers with operands make sure
1254 that they are in the same position */
1255 if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)) &&
1256 OP_SYMBOL (IC_LEFT (ic))->nRegs && ic->op != '=')
1257 positionRegs (OP_SYMBOL (IC_RESULT (ic)),
1258 OP_SYMBOL (IC_LEFT (ic)), ic->lineno);
1259 /* do the same for the right operand */
1260 if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)) &&
1261 OP_SYMBOL (IC_RIGHT (ic))->nRegs)
1262 positionRegs (OP_SYMBOL (IC_RESULT (ic)),
1263 OP_SYMBOL (IC_RIGHT (ic)), ic->lineno);
1276 /*-----------------------------------------------------------------*/
1277 /* fillGaps - Try to fill in the Gaps left by Pass1 */
1278 /*-----------------------------------------------------------------*/
1279 static void fillGaps()
1284 return ; /* NOT YET .. MORE TESTING IN PROGRESS */
1285 /* look for livernages that was spilt by the allocator */
1286 for (sym = hTabFirstItem(liveRanges,&key) ; sym ;
1287 sym = hTabNextItem(liveRanges,&key)) {
1291 if (!sym->spillA || !sym->clashes || sym->remat) continue ;
1293 /* find the liveRanges this one clashes with, that are
1294 still assigned to registers & mark the registers as used*/
1295 for ( i = 0 ; i < sym->clashes->size ; i ++) {
1299 if (bitVectBitValue(sym->clashes,i) == 0 || /* those that clash with this */
1300 bitVectBitValue(_G.totRegAssigned,i) == 0) /* and are still assigned to registers */
1303 assert (clr = hTabItemWithKey(liveRanges,i));
1305 /* mark these registers as used */
1306 for (k = 0 ; k < clr->nRegs ; k++ )
1307 useReg(clr->regs[k]);
1310 if (willCauseSpill(sym->nRegs,sym->regType)) {
1311 /* NOPE :( clear all registers & and continue */
1316 /* THERE IS HOPE !!!! */
1317 for (i=0; i < sym->nRegs ; i++ ) {
1318 if (sym->regType == REG_PTR)
1319 sym->regs[i] = getRegPtrNoSpil ();
1321 sym->regs[i] = getRegGprNoSpil ();
1323 printf("FILLED GAP for %s in function %s\n",sym->name, currFunc ? currFunc->name : "UNKNOWN");
1324 _G.totRegAssigned = bitVectSetBit(_G.totRegAssigned,sym->key);
1325 sym->isspilt = sym->spillA = 0 ;
1326 sym->usl.spillLoc->allocreq--;
1331 /*-----------------------------------------------------------------*/
1332 /* rUmaskForOp :- returns register mask for an operand */
1333 /*-----------------------------------------------------------------*/
1335 rUmaskForOp (operand * op)
1341 /* only temporaries are assigned registers */
1345 sym = OP_SYMBOL (op);
1347 /* if spilt or no registers assigned to it
1349 if (sym->isspilt || !sym->nRegs)
1352 rumask = newBitVect (ds390_nRegs);
1354 for (j = 0; j < sym->nRegs; j++)
1356 rumask = bitVectSetBit (rumask,
1357 sym->regs[j]->rIdx);
1363 /*-----------------------------------------------------------------*/
1364 /* regsUsedIniCode :- returns bit vector of registers used in iCode */
1365 /*-----------------------------------------------------------------*/
1367 regsUsedIniCode (iCode * ic)
1369 bitVect *rmask = newBitVect (ds390_nRegs);
1371 /* do the special cases first */
1374 rmask = bitVectUnion (rmask,
1375 rUmaskForOp (IC_COND (ic)));
1379 /* for the jumptable */
1380 if (ic->op == JUMPTABLE)
1382 rmask = bitVectUnion (rmask,
1383 rUmaskForOp (IC_JTCOND (ic)));
1388 /* of all other cases */
1390 rmask = bitVectUnion (rmask,
1391 rUmaskForOp (IC_LEFT (ic)));
1395 rmask = bitVectUnion (rmask,
1396 rUmaskForOp (IC_RIGHT (ic)));
1399 rmask = bitVectUnion (rmask,
1400 rUmaskForOp (IC_RESULT (ic)));
1406 /*-----------------------------------------------------------------*/
1407 /* createRegMask - for each instruction will determine the regsUsed */
1408 /*-----------------------------------------------------------------*/
1410 createRegMask (eBBlock ** ebbs, int count)
1414 /* for all blocks */
1415 for (i = 0; i < count; i++)
1419 if (ebbs[i]->noPath &&
1420 (ebbs[i]->entryLabel != entryLabel &&
1421 ebbs[i]->entryLabel != returnLabel))
1424 /* for all instructions */
1425 for (ic = ebbs[i]->sch; ic; ic = ic->next)
1430 if (SKIP_IC2 (ic) || !ic->rlive)
1433 /* first mark the registers used in this
1435 ic->rUsed = regsUsedIniCode (ic);
1436 _G.funcrUsed = bitVectUnion (_G.funcrUsed, ic->rUsed);
1438 /* now create the register mask for those
1439 registers that are in use : this is a
1440 super set of ic->rUsed */
1441 ic->rMask = newBitVect (ds390_nRegs + 1);
1443 /* for all live Ranges alive at this point */
1444 for (j = 1; j < ic->rlive->size; j++)
1449 /* if not alive then continue */
1450 if (!bitVectBitValue (ic->rlive, j))
1453 /* find the live range we are interested in */
1454 if (!(sym = hTabItemWithKey (liveRanges, j)))
1456 werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
1457 "createRegMask cannot find live range");
1461 /* special case for ruonly */
1463 int size = getSize(sym->type);
1465 for (k = 0 ; k < size; k++ )
1466 ic->rMask = bitVectSetBit (ic->rMask, j++);
1469 /* if no register assigned to it */
1470 if (!sym->nRegs || sym->isspilt)
1473 /* for all the registers allocated to it */
1474 for (k = 0; k < sym->nRegs; k++)
1477 bitVectSetBit (ic->rMask, sym->regs[k]->rIdx);
1483 /*-----------------------------------------------------------------*/
1484 /* rematStr - returns the rematerialized string for a remat var */
1485 /*-----------------------------------------------------------------*/
1487 rematStr (symbol * sym)
1490 iCode *ic = sym->rematiCode;
1495 /* if plus or minus print the right hand side */
1496 if (ic->op == '+' || ic->op == '-')
1498 sprintf (s, "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)),
1501 ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
1504 /* cast then continue */
1505 if (IS_CAST_ICODE(ic)) {
1506 ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
1509 /* we reached the end */
1510 sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
1517 /*-----------------------------------------------------------------*/
1518 /* regTypeNum - computes the type & number of registers required */
1519 /*-----------------------------------------------------------------*/
1527 /* for each live range do */
1528 for (sym = hTabFirstItem (liveRanges, &k); sym;
1529 sym = hTabNextItem (liveRanges, &k))
1532 /* if used zero times then no registers needed */
1533 if ((sym->liveTo - sym->liveFrom) == 0)
1537 /* if the live range is a temporary */
1541 /* if the type is marked as a conditional */
1542 if (sym->regType == REG_CND)
1545 /* if used in return only then we don't
1547 if (sym->ruonly || sym->accuse)
1549 if (IS_AGGREGATE (sym->type) || sym->isptr)
1550 sym->type = aggrToPtr (sym->type, FALSE);
1554 /* if the symbol has only one definition &
1555 that definition is a get_pointer and the
1556 pointer we are getting is rematerializable and
1559 if (bitVectnBitsOn (sym->defs) == 1 &&
1560 (ic = hTabItemWithKey (iCodehTab,
1561 bitVectFirstBit (sym->defs))) &&
1564 !IS_BITVAR (sym->etype))
1568 /* if remat in data space */
1569 if (OP_SYMBOL (IC_LEFT (ic))->remat &&
1570 !IS_CAST_ICODE(OP_SYMBOL (IC_LEFT (ic))->rematiCode) &&
1571 DCL_TYPE (aggrToPtr (sym->type, FALSE)) == POINTER)
1574 /* create a psuedo symbol & force a spil */
1575 symbol *psym = newSymbol (rematStr (OP_SYMBOL (IC_LEFT (ic))), 1);
1576 psym->type = sym->type;
1577 psym->etype = sym->etype;
1578 strcpy (psym->rname, psym->name);
1580 sym->usl.spillLoc = psym;
1584 /* if in data space or idata space then try to
1585 allocate pointer register */
1589 /* if not then we require registers */
1590 sym->nRegs = ((IS_AGGREGATE (sym->type) || sym->isptr) ?
1591 getSize (sym->type = aggrToPtr (sym->type, FALSE)) :
1592 getSize (sym->type));
1596 fprintf (stderr, "allocated more than 4 or 0 registers for type ");
1597 printTypeChain (sym->type, stderr);
1598 fprintf (stderr, "\n");
1601 /* determine the type of register required */
1602 if (sym->nRegs == 1 &&
1603 IS_PTR (sym->type) &&
1605 sym->regType = REG_PTR;
1607 sym->regType = REG_GPR;
1611 /* for the first run we don't provide */
1612 /* registers for true symbols we will */
1613 /* see how things go */
1619 /*-----------------------------------------------------------------*/
1620 /* freeAllRegs - mark all registers as free */
1621 /*-----------------------------------------------------------------*/
1627 for (i = 0; i < ds390_nRegs; i++)
1628 regs390[i].isFree = 1;
1631 /*-----------------------------------------------------------------*/
1632 /* deallocStackSpil - this will set the stack pointer back */
1633 /*-----------------------------------------------------------------*/
1635 DEFSETFUNC (deallocStackSpil)
1643 /*-----------------------------------------------------------------*/
1644 /* farSpacePackable - returns the packable icode for far variables */
1645 /*-----------------------------------------------------------------*/
1647 farSpacePackable (iCode * ic)
1651 /* go thru till we find a definition for the
1652 symbol on the right */
1653 for (dic = ic->prev; dic; dic = dic->prev)
1656 /* if the definition is a call then no */
1657 if ((dic->op == CALL || dic->op == PCALL) &&
1658 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
1663 /* if shift by unknown amount then not */
1664 if ((dic->op == LEFT_OP || dic->op == RIGHT_OP) &&
1665 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
1668 /* if pointer get and size > 1 */
1669 if (POINTER_GET (dic) &&
1670 getSize (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)) > 1)
1673 if (POINTER_SET (dic) &&
1674 getSize (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)) > 1)
1677 /* if any three is a true symbol in far space */
1678 if (IC_RESULT (dic) &&
1679 IS_TRUE_SYMOP (IC_RESULT (dic)) &&
1680 isOperandInFarSpace (IC_RESULT (dic)))
1683 if (IC_RIGHT (dic) &&
1684 IS_TRUE_SYMOP (IC_RIGHT (dic)) &&
1685 isOperandInFarSpace (IC_RIGHT (dic)) &&
1686 !isOperandEqual (IC_RIGHT (dic), IC_RESULT (ic)))
1689 if (IC_LEFT (dic) &&
1690 IS_TRUE_SYMOP (IC_LEFT (dic)) &&
1691 isOperandInFarSpace (IC_LEFT (dic)) &&
1692 !isOperandEqual (IC_LEFT (dic), IC_RESULT (ic)))
1695 if (isOperandEqual (IC_RIGHT (ic), IC_RESULT (dic)))
1697 if ((dic->op == LEFT_OP ||
1698 dic->op == RIGHT_OP ||
1700 IS_OP_LITERAL (IC_RIGHT (dic)))
1710 /*-----------------------------------------------------------------*/
1711 /* packRegsForAssign - register reduction for assignment */
1712 /*-----------------------------------------------------------------*/
1714 packRegsForAssign (iCode * ic, eBBlock * ebp)
1718 if (!IS_ITEMP (IC_RIGHT (ic)) ||
1719 OP_SYMBOL (IC_RIGHT (ic))->isind ||
1720 OP_LIVETO (IC_RIGHT (ic)) > ic->seq)
1725 /* if the true symbol is defined in far space or on stack
1726 then we should not since this will increase register pressure */
1728 if (isOperandInFarSpace (IC_RESULT (ic)))
1730 if ((dic = farSpacePackable (ic)))
1736 if (isOperandInFarSpace(IC_RESULT(ic)) && !farSpacePackable(ic)) {
1741 /* find the definition of iTempNN scanning backwards if we find a
1742 a use of the true symbol in before we find the definition then
1744 for (dic = ic->prev; dic; dic = dic->prev)
1746 /* if there is a function call then don't pack it */
1747 if ((dic->op == CALL || dic->op == PCALL))
1756 if (IS_TRUE_SYMOP (IC_RESULT (dic)) &&
1757 IS_OP_VOLATILE (IC_RESULT (dic)))
1763 if (IS_SYMOP (IC_RESULT (dic)) &&
1764 IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
1766 if (POINTER_SET (dic))
1772 if (IS_SYMOP (IC_RIGHT (dic)) &&
1773 (IC_RIGHT (dic)->key == IC_RESULT (ic)->key ||
1774 IC_RIGHT (dic)->key == IC_RIGHT (ic)->key))
1780 if (IS_SYMOP (IC_LEFT (dic)) &&
1781 (IC_LEFT (dic)->key == IC_RESULT (ic)->key ||
1782 IC_LEFT (dic)->key == IC_RIGHT (ic)->key))
1788 if (POINTER_SET (dic) &&
1789 IC_RESULT (dic)->key == IC_RESULT (ic)->key)
1797 return 0; /* did not find */
1799 /* if the result is on stack or iaccess then it must be
1800 the same atleast one of the operands */
1801 if (OP_SYMBOL (IC_RESULT (ic))->onStack ||
1802 OP_SYMBOL (IC_RESULT (ic))->iaccess)
1805 /* the operation has only one symbol
1806 operator then we can pack */
1807 if ((IC_LEFT (dic) && !IS_SYMOP (IC_LEFT (dic))) ||
1808 (IC_RIGHT (dic) && !IS_SYMOP (IC_RIGHT (dic))))
1811 if (!((IC_LEFT (dic) &&
1812 IC_RESULT (ic)->key == IC_LEFT (dic)->key) ||
1814 IC_RESULT (ic)->key == IC_RIGHT (dic)->key)))
1818 /* found the definition */
1819 /* replace the result with the result of */
1820 /* this assignment and remove this assignment */
1821 IC_RESULT (dic) = IC_RESULT (ic);
1823 if (IS_ITEMP (IC_RESULT (dic)) && OP_SYMBOL (IC_RESULT (dic))->liveFrom > dic->seq)
1825 OP_SYMBOL (IC_RESULT (dic))->liveFrom = dic->seq;
1827 /* delete from liverange table also
1828 delete from all the points inbetween and the new
1830 for (sic = dic; sic != ic; sic = sic->next)
1832 bitVectUnSetBit (sic->rlive, IC_RESULT (ic)->key);
1833 if (IS_ITEMP (IC_RESULT (dic)))
1834 bitVectSetBit (sic->rlive, IC_RESULT (dic)->key);
1837 remiCodeFromeBBlock (ebp, ic);
1838 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
1839 OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
1844 /*-----------------------------------------------------------------*/
1845 /* findAssignToSym : scanning backwards looks for first assig found */
1846 /*-----------------------------------------------------------------*/
1848 findAssignToSym (operand * op, iCode * ic)
1852 for (dic = ic->prev; dic; dic = dic->prev)
1855 /* if definition by assignment */
1856 if (dic->op == '=' &&
1857 !POINTER_SET (dic) &&
1858 IC_RESULT (dic)->key == op->key
1859 /* && IS_TRUE_SYMOP(IC_RIGHT(dic)) */
1863 /* we are interested only if defined in far space */
1864 /* or in stack space in case of + & - */
1866 /* if assigned to a non-symbol then return
1868 if (!IS_SYMOP (IC_RIGHT (dic)))
1871 /* if the symbol is in far space then
1873 if (isOperandInFarSpace (IC_RIGHT (dic)))
1876 /* for + & - operations make sure that
1877 if it is on the stack it is the same
1878 as one of the three operands */
1879 if ((ic->op == '+' || ic->op == '-') &&
1880 OP_SYMBOL (IC_RIGHT (dic))->onStack)
1883 if (IC_RESULT (ic)->key != IC_RIGHT (dic)->key &&
1884 IC_LEFT (ic)->key != IC_RIGHT (dic)->key &&
1885 IC_RIGHT (ic)->key != IC_RIGHT (dic)->key)
1893 /* if we find an usage then we cannot delete it */
1894 if (IC_LEFT (dic) && IC_LEFT (dic)->key == op->key)
1897 if (IC_RIGHT (dic) && IC_RIGHT (dic)->key == op->key)
1900 if (POINTER_SET (dic) && IC_RESULT (dic)->key == op->key)
1904 /* now make sure that the right side of dic
1905 is not defined between ic & dic */
1908 iCode *sic = dic->next;
1910 for (; sic != ic; sic = sic->next)
1911 if (IC_RESULT (sic) &&
1912 IC_RESULT (sic)->key == IC_RIGHT (dic)->key)
1921 /*-----------------------------------------------------------------*/
1922 /* packRegsForSupport :- reduce some registers for support calls */
1923 /*-----------------------------------------------------------------*/
1925 packRegsForSupport (iCode * ic, eBBlock * ebp)
1928 /* for the left & right operand :- look to see if the
1929 left was assigned a true symbol in far space in that
1930 case replace them */
1931 if (IS_ITEMP (IC_LEFT (ic)) &&
1932 OP_SYMBOL (IC_LEFT (ic))->liveTo <= ic->seq)
1934 iCode *dic = findAssignToSym (IC_LEFT (ic), ic);
1940 /* found it we need to remove it from the
1942 for (sic = dic; sic != ic; sic = sic->next)
1943 bitVectUnSetBit (sic->rlive, IC_LEFT (ic)->key);
1945 IC_LEFT (ic)->operand.symOperand =
1946 IC_RIGHT (dic)->operand.symOperand;
1947 IC_LEFT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
1948 remiCodeFromeBBlock (ebp, dic);
1949 hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
1953 /* do the same for the right operand */
1956 IS_ITEMP (IC_RIGHT (ic)) &&
1957 OP_SYMBOL (IC_RIGHT (ic))->liveTo <= ic->seq)
1959 iCode *dic = findAssignToSym (IC_RIGHT (ic), ic);
1965 /* if this is a subtraction & the result
1966 is a true symbol in far space then don't pack */
1967 if (ic->op == '-' && IS_TRUE_SYMOP (IC_RESULT (dic)))
1969 sym_link *etype = getSpec (operandType (IC_RESULT (dic)));
1970 if (IN_FARSPACE (SPEC_OCLS (etype)))
1973 /* found it we need to remove it from the
1975 for (sic = dic; sic != ic; sic = sic->next)
1976 bitVectUnSetBit (sic->rlive, IC_RIGHT (ic)->key);
1978 IC_RIGHT (ic)->operand.symOperand =
1979 IC_RIGHT (dic)->operand.symOperand;
1980 IC_RIGHT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
1982 remiCodeFromeBBlock (ebp, dic);
1983 hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
1990 #define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
1993 /*-----------------------------------------------------------------*/
1994 /* packRegsDPTRuse : - will reduce some registers for single Use */
1995 /*-----------------------------------------------------------------*/
1997 packRegsDPTRuse (iCode * lic, operand * op, eBBlock * ebp)
1999 /* go thru entire liveRange of this variable & check for
2000 other possible usage of DPTR , if we don't find it the
2001 assign this to DPTR (ruonly)
2006 sym_link *type, *etype;
2008 if (!IS_SYMOP(op)) return NULL;
2009 if (OP_SYMBOL(op)->remat || OP_SYMBOL(op)->ruonly) return NULL;
2011 /* first check if any overlapping liverange has already been
2013 if (OP_SYMBOL(op)->clashes) {
2014 for (i = 0 ; i < OP_SYMBOL(op)->clashes->size ; i++ ) {
2015 if (bitVectBitValue(OP_SYMBOL(op)->clashes,i)) {
2016 sym = hTabItemWithKey(liveRanges,i);
2017 if (sym->ruonly) return NULL ;
2022 /* no then go thru this guys live range */
2023 dic = ic = hTabFirstItemWK(iCodeSeqhTab,OP_SYMBOL(op)->liveFrom);
2024 for (; ic && ic->seq <= OP_SYMBOL(op)->liveTo;
2025 ic = hTabNextItem(iCodeSeqhTab,&key)) {
2027 /* if PCALL cannot be sure give up */
2028 if (ic->op == PCALL) return NULL;
2030 /* if CALL then make sure it is VOID || return value not used */
2031 if (ic->op == CALL) {
2032 if (OP_SYMBOL(IC_RESULT(ic))->liveTo ==
2033 OP_SYMBOL(IC_RESULT(ic))->liveFrom) continue ;
2034 etype = getSpec(type = operandType(IC_RESULT(ic)));
2035 if (getSize(type) == 0) continue ;
2039 /* special case of add with a [remat] */
2040 if (ic->op == '+' &&
2041 OP_SYMBOL(IC_LEFT(ic))->remat &&
2042 !isOperandInFarSpace(IC_RIGHT(ic))) continue ;
2046 if (POINTER_GET(ic) && isOperandEqual(IC_RESULT(ic),op) &&
2047 getSize(operandType(IC_LEFT(ic))) > 1) return NULL ;
2049 if (POINTER_SET(ic) && isOperandEqual(IC_RIGHT(ic),op) &&
2050 getSize(operandType(IC_RESULT(ic))) > 1) return NULL;
2053 if (IC_RESULT(ic) && IS_SYMOP(IC_RESULT(ic)) &&
2054 !isOperandEqual(IC_RESULT(ic),op) &&
2055 (isOperandInFarSpace(IC_RESULT(ic)) ||
2056 OP_SYMBOL(IC_RESULT(ic))->ruonly ||
2057 OP_SYMBOL(IC_RESULT(ic))->onStack)) return NULL;
2059 if (IC_RIGHT(ic) && IS_SYMOP(IC_RIGHT(ic)) &&
2060 !isOperandEqual(IC_RIGHT(ic),op) &&
2061 (OP_SYMBOL(IC_RIGHT(ic))->liveTo > ic->seq ||
2062 IS_TRUE_SYMOP(IC_RIGHT(ic)) ||
2063 OP_SYMBOL(IC_RIGHT(ic))->ruonly) &&
2064 (isOperandInFarSpace(IC_RIGHT(ic)) ||
2065 OP_SYMBOL(IC_RIGHT(ic))->onStack)) return NULL;
2067 if (IC_LEFT(ic) && IS_SYMOP(IC_LEFT(ic)) &&
2068 !isOperandEqual(IC_LEFT(ic),op) &&
2069 (OP_SYMBOL(IC_LEFT(ic))->liveTo > ic->seq ||
2070 IS_TRUE_SYMOP(IC_LEFT(ic)) ||
2071 OP_SYMBOL(IC_LEFT(ic))->ruonly) &&
2072 (isOperandInFarSpace(IC_LEFT(ic)) ||
2073 OP_SYMBOL(IC_LEFT(ic))->onStack)) return NULL;
2075 if (IC_LEFT(ic) && IC_RIGHT(ic) &&
2076 IS_ITEMP(IC_LEFT(ic)) && IS_ITEMP(IC_RIGHT(ic)) &&
2077 isOperandInFarSpace(IC_LEFT(ic)) && isOperandInFarSpace(IC_RIGHT(ic)))
2080 OP_SYMBOL(op)->ruonly = 1;
2084 /*-----------------------------------------------------------------*/
2085 /* isBitwiseOptimizable - requirements of JEAN LOUIS VERN */
2086 /*-----------------------------------------------------------------*/
2088 isBitwiseOptimizable (iCode * ic)
2090 sym_link *ltype = getSpec (operandType (IC_LEFT (ic)));
2091 sym_link *rtype = getSpec (operandType (IC_RIGHT (ic)));
2093 /* bitwise operations are considered optimizable
2094 under the following conditions (Jean-Louis VERN)
2106 if ( IS_LITERAL (rtype) ||
2107 (IS_BITVAR (ltype) && IN_BITSPACE (SPEC_OCLS (ltype))))
2113 /*-----------------------------------------------------------------*/
2114 /* packRegsForAccUse - pack registers for acc use */
2115 /*-----------------------------------------------------------------*/
2117 packRegsForAccUse (iCode * ic)
2121 /* if + or - then it has to be one byte result */
2122 if ((ic->op == '+' || ic->op == '-')
2123 && getSize (operandType (IC_RESULT (ic))) > 1)
2126 /* if shift operation make sure right side is not a literal */
2127 if (ic->op == RIGHT_OP &&
2128 (isOperandLiteral (IC_RIGHT (ic)) ||
2129 getSize (operandType (IC_RESULT (ic))) > 1))
2132 if (ic->op == LEFT_OP &&
2133 (isOperandLiteral (IC_RIGHT (ic)) ||
2134 getSize (operandType (IC_RESULT (ic))) > 1))
2137 if (IS_BITWISE_OP (ic) &&
2138 getSize (operandType (IC_RESULT (ic))) > 1)
2142 /* has only one definition */
2143 if (bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) > 1)
2146 /* has only one use */
2147 if (bitVectnBitsOn (OP_USES (IC_RESULT (ic))) > 1)
2150 /* and the usage immediately follows this iCode */
2151 if (!(uic = hTabItemWithKey (iCodehTab,
2152 bitVectFirstBit (OP_USES (IC_RESULT (ic))))))
2155 if (ic->next != uic)
2158 /* if it is a conditional branch then we definitely can */
2162 if (uic->op == JUMPTABLE)
2165 /* if the usage is not is an assignment
2166 or an arithmetic / bitwise / shift operation then not */
2167 if (POINTER_SET (uic) &&
2168 getSize (aggrToPtr (operandType (IC_RESULT (uic)), FALSE)) > 1)
2171 if (uic->op != '=' &&
2172 !IS_ARITHMETIC_OP (uic) &&
2173 !IS_BITWISE_OP (uic) &&
2174 uic->op != LEFT_OP &&
2175 uic->op != RIGHT_OP)
2178 /* if used in ^ operation then make sure right is not a
2180 if (uic->op == '^' && isOperandLiteral (IC_RIGHT (uic)))
2183 /* if shift operation make sure right side is not a literal */
2184 if (uic->op == RIGHT_OP &&
2185 (isOperandLiteral (IC_RIGHT (uic)) ||
2186 getSize (operandType (IC_RESULT (uic))) > 1))
2189 if (uic->op == LEFT_OP &&
2190 (isOperandLiteral (IC_RIGHT (uic)) ||
2191 getSize (operandType (IC_RESULT (uic))) > 1))
2194 /* make sure that the result of this icode is not on the
2195 stack, since acc is used to compute stack offset */
2196 if (IS_TRUE_SYMOP (IC_RESULT (uic)) &&
2197 OP_SYMBOL (IC_RESULT (uic))->onStack)
2200 /* if either one of them in far space then we cannot */
2201 if ((IS_TRUE_SYMOP (IC_LEFT (uic)) &&
2202 isOperandInFarSpace (IC_LEFT (uic))) ||
2203 (IS_TRUE_SYMOP (IC_RIGHT (uic)) &&
2204 isOperandInFarSpace (IC_RIGHT (uic))))
2207 /* if the usage has only one operand then we can */
2208 if (IC_LEFT (uic) == NULL ||
2209 IC_RIGHT (uic) == NULL)
2212 /* make sure this is on the left side if not
2213 a '+' since '+' is commutative */
2214 if (ic->op != '+' &&
2215 IC_LEFT (uic)->key != IC_RESULT (ic)->key)
2219 // this is too dangerous and need further restrictions
2222 /* if one of them is a literal then we can */
2223 if ((IC_LEFT (uic) && IS_OP_LITERAL (IC_LEFT (uic))) ||
2224 (IC_RIGHT (uic) && IS_OP_LITERAL (IC_RIGHT (uic))))
2226 OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
2231 /* if the other one is not on stack then we can */
2232 if (IC_LEFT (uic)->key == IC_RESULT (ic)->key &&
2233 (IS_ITEMP (IC_RIGHT (uic)) ||
2234 (IS_TRUE_SYMOP (IC_RIGHT (uic)) &&
2235 !OP_SYMBOL (IC_RIGHT (uic))->onStack)))
2238 if (IC_RIGHT (uic)->key == IC_RESULT (ic)->key &&
2239 (IS_ITEMP (IC_LEFT (uic)) ||
2240 (IS_TRUE_SYMOP (IC_LEFT (uic)) &&
2241 !OP_SYMBOL (IC_LEFT (uic))->onStack)))
2247 OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
2252 /*-----------------------------------------------------------------*/
2253 /* packForPush - hueristics to reduce iCode for pushing */
2254 /*-----------------------------------------------------------------*/
2256 packForPush (iCode * ic, eBBlock * ebp)
2261 if (ic->op != IPUSH || !IS_ITEMP (IC_LEFT (ic)))
2264 /* must have only definition & one usage */
2265 if (bitVectnBitsOn (OP_DEFS (IC_LEFT (ic))) != 1 ||
2266 bitVectnBitsOn (OP_USES (IC_LEFT (ic))) != 1)
2269 /* find the definition */
2270 if (!(dic = hTabItemWithKey (iCodehTab,
2271 bitVectFirstBit (OP_DEFS (IC_LEFT (ic))))))
2274 if (dic->op != '=' || POINTER_SET (dic))
2277 /* make sure the right side does not have any definitions
2279 dbv = OP_DEFS(IC_RIGHT(dic));
2280 for (lic = ic; lic && lic != dic ; lic = lic->prev) {
2281 if (bitVectBitValue(dbv,lic->key)) return ;
2283 /* make sure they have the same type */
2285 sym_link *itype=operandType(IC_LEFT(ic));
2286 sym_link *ditype=operandType(IC_RIGHT(dic));
2288 if (SPEC_USIGN(itype)!=SPEC_USIGN(ditype) ||
2289 SPEC_LONG(itype)!=SPEC_LONG(ditype))
2292 /* extend the live range of replaced operand if needed */
2293 if (OP_SYMBOL(IC_RIGHT(dic))->liveTo < ic->seq) {
2294 OP_SYMBOL(IC_RIGHT(dic))->liveTo = ic->seq;
2296 /* we now we know that it has one & only one def & use
2297 and the that the definition is an assignment */
2298 IC_LEFT (ic) = IC_RIGHT (dic);
2300 remiCodeFromeBBlock (ebp, dic);
2301 hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
2304 /*-----------------------------------------------------------------*/
2305 /* packRegisters - does some transformations to reduce register */
2307 /*-----------------------------------------------------------------*/
2309 packRegisters (eBBlock * ebp)
2319 /* look for assignments of the form */
2320 /* iTempNN = TRueSym (someoperation) SomeOperand */
2322 /* TrueSym := iTempNN:1 */
2323 for (ic = ebp->sch; ic; ic = ic->next)
2327 /* find assignment of the form TrueSym := iTempNN:1 */
2328 if (ic->op == '=' && !POINTER_SET (ic))
2329 change += packRegsForAssign (ic, ebp);
2336 for (ic = ebp->sch; ic; ic = ic->next)
2339 /* if this is an itemp & result of a address of a true sym
2340 then mark this as rematerialisable */
2341 if (ic->op == ADDRESS_OF &&
2342 IS_ITEMP (IC_RESULT (ic)) &&
2343 IS_TRUE_SYMOP (IC_LEFT (ic)) &&
2344 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
2345 !OP_SYMBOL (IC_LEFT (ic))->onStack)
2348 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
2349 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
2350 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
2354 /* if straight assignment then carry remat flag if
2355 this is the only definition */
2356 if (ic->op == '=' &&
2357 !POINTER_SET (ic) &&
2358 IS_SYMOP (IC_RIGHT (ic)) &&
2359 OP_SYMBOL (IC_RIGHT (ic))->remat &&
2360 !IS_CAST_ICODE(OP_SYMBOL (IC_RIGHT (ic))->rematiCode) &&
2361 bitVectnBitsOn (OP_SYMBOL (IC_RESULT (ic))->defs) <= 1)
2364 OP_SYMBOL (IC_RESULT (ic))->remat =
2365 OP_SYMBOL (IC_RIGHT (ic))->remat;
2366 OP_SYMBOL (IC_RESULT (ic))->rematiCode =
2367 OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
2370 /* if cast to a generic pointer & the pointer being
2371 cast is remat, then we can remat this cast as well */
2372 if (ic->op == CAST &&
2373 IS_SYMOP(IC_RIGHT(ic)) &&
2374 OP_SYMBOL(IC_RIGHT(ic))->remat ) {
2375 sym_link *to_type = operandType(IC_LEFT(ic));
2376 sym_link *from_type = operandType(IC_RIGHT(ic));
2377 if (IS_GENPTR(to_type) && IS_PTR(from_type)) {
2378 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
2379 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
2380 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
2384 /* if this is a +/- operation with a rematerizable
2385 then mark this as rematerializable as well */
2386 if ((ic->op == '+' || ic->op == '-') &&
2387 (IS_SYMOP (IC_LEFT (ic)) &&
2388 IS_ITEMP (IC_RESULT (ic)) &&
2389 OP_SYMBOL (IC_LEFT (ic))->remat &&
2390 (!IS_SYMOP (IC_RIGHT (ic)) || !IS_CAST_ICODE(OP_SYMBOL (IC_RIGHT (ic))->rematiCode)) &&
2391 bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
2392 IS_OP_LITERAL (IC_RIGHT (ic))))
2395 //int i = operandLitValue(IC_RIGHT(ic));
2396 OP_SYMBOL (IC_RESULT (ic))->remat = 1;
2397 OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
2398 OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
2401 /* mark the pointer usages */
2402 if (POINTER_SET (ic))
2403 OP_SYMBOL (IC_RESULT (ic))->uptr = 1;
2405 if (POINTER_GET (ic))
2406 OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
2410 /* if we are using a symbol on the stack
2411 then we should say ds390_ptrRegReq */
2412 if (ic->op == IFX && IS_SYMOP (IC_COND (ic)))
2413 ds390_ptrRegReq += ((OP_SYMBOL (IC_COND (ic))->onStack ? !options.stack10bit : 0) +
2414 OP_SYMBOL (IC_COND (ic))->iaccess);
2415 else if (ic->op == JUMPTABLE && IS_SYMOP (IC_JTCOND (ic)))
2416 ds390_ptrRegReq += ((OP_SYMBOL (IC_JTCOND (ic))->onStack ? !options.stack10bit : 0) +
2417 OP_SYMBOL (IC_JTCOND (ic))->iaccess);
2420 if (IS_SYMOP (IC_LEFT (ic)))
2421 ds390_ptrRegReq += ((OP_SYMBOL (IC_LEFT (ic))->onStack ? !options.stack10bit : 0) +
2422 OP_SYMBOL (IC_LEFT (ic))->iaccess);
2423 if (IS_SYMOP (IC_RIGHT (ic)))
2424 ds390_ptrRegReq += ((OP_SYMBOL (IC_RIGHT (ic))->onStack ? !options.stack10bit : 0) +
2425 OP_SYMBOL (IC_RIGHT (ic))->iaccess);
2426 if (IS_SYMOP (IC_RESULT (ic)))
2427 ds390_ptrRegReq += ((OP_SYMBOL (IC_RESULT (ic))->onStack ? !options.stack10bit : 0) +
2428 OP_SYMBOL (IC_RESULT (ic))->iaccess);
2433 /* if the condition of an if instruction
2434 is defined in the previous instruction then
2435 mark the itemp as a conditional */
2436 if ((IS_CONDITIONAL (ic) ||
2437 (IS_BITWISE_OP(ic) && isBitwiseOptimizable(ic))) &&
2438 ic->next && ic->next->op == IFX &&
2439 isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
2440 OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
2443 OP_SYMBOL (IC_RESULT (ic))->regType = REG_CND;
2447 /* if the condition of an if instruction
2448 is defined in the previous instruction and
2449 this is the only usage then
2450 mark the itemp as a conditional */
2451 if ((IS_CONDITIONAL (ic) ||
2452 (IS_BITWISE_OP(ic) && isBitwiseOptimizable (ic))) &&
2453 ic->next && ic->next->op == IFX &&
2454 bitVectnBitsOn (OP_USES(IC_RESULT(ic)))==1 &&
2455 isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
2456 OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
2458 OP_SYMBOL (IC_RESULT (ic))->regType = REG_CND;
2463 /* reduce for support function calls */
2464 if (ic->supportRtn || ic->op == '+' || ic->op == '-')
2465 packRegsForSupport (ic, ebp);
2467 /* some cases the redundant moves can
2468 can be eliminated for return statements */
2469 if ((ic->op == RETURN || ic->op == SEND) &&
2470 !isOperandInFarSpace (IC_LEFT (ic)) &&
2473 packRegsDPTRuse (ic, IC_LEFT (ic), ebp);
2476 if ((ic->op == CALL && getSize(operandType(IC_RESULT(ic))) <= 4)) {
2477 packRegsDPTRuse (ic, IC_RESULT (ic), ebp);
2480 /* if pointer set & left has a size more than
2481 one and right is not in far space */
2482 if (POINTER_SET (ic) &&
2483 !isOperandInFarSpace (IC_RIGHT (ic)) &&
2484 !OP_SYMBOL (IC_RESULT (ic))->remat &&
2485 !IS_OP_RUONLY (IC_RIGHT (ic)) &&
2486 getSize (aggrToPtr (operandType (IC_RESULT (ic)), FALSE)) > 1) {
2488 packRegsDPTRuse (ic, IC_RESULT (ic), ebp);
2491 /* if pointer get */
2492 if (POINTER_GET (ic) &&
2493 !isOperandInFarSpace (IC_RESULT (ic)) &&
2494 !OP_SYMBOL (IC_LEFT (ic))->remat &&
2495 !IS_OP_RUONLY (IC_RESULT (ic)) &&
2496 getSize (aggrToPtr (operandType (IC_LEFT (ic)), FALSE)) > 1) {
2498 packRegsDPTRuse (ic, IC_LEFT (ic), ebp);
2501 /* if this is cast for intergral promotion then
2502 check if only use of the definition of the
2503 operand being casted/ if yes then replace
2504 the result of that arithmetic operation with
2505 this result and get rid of the cast */
2508 sym_link *fromType = operandType (IC_RIGHT (ic));
2509 sym_link *toType = operandType (IC_LEFT (ic));
2511 if (IS_INTEGRAL (fromType) && IS_INTEGRAL (toType) &&
2512 getSize (fromType) != getSize (toType) &&
2513 SPEC_USIGN (fromType) == SPEC_USIGN (toType))
2516 iCode *dic = packRegsDPTRuse (ic, IC_RIGHT (ic), ebp);
2519 if (IS_ARITHMETIC_OP (dic))
2521 IC_RESULT (dic) = IC_RESULT (ic);
2522 remiCodeFromeBBlock (ebp, ic);
2523 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
2524 OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
2528 OP_SYMBOL (IC_RIGHT (ic))->ruonly = 0;
2534 /* if the type from and type to are the same
2535 then if this is the only use then packit */
2536 if (compareType (operandType (IC_RIGHT (ic)),
2537 operandType (IC_LEFT (ic))) == 1)
2539 iCode *dic = packRegsDPTRuse (ic, IC_RIGHT (ic), ebp);
2542 IC_RESULT (dic) = IC_RESULT (ic);
2543 remiCodeFromeBBlock (ebp, ic);
2544 hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
2545 OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
2553 iTempNN := (some variable in farspace) V1
2558 if (ic->op == IPUSH)
2560 packForPush (ic, ebp);
2564 /* pack registers for accumulator use, when the
2565 result of an arithmetic or bit wise operation
2566 has only one use, that use is immediately following
2567 the defintion and the using iCode has only one
2568 operand or has two operands but one is literal &
2569 the result of that operation is not on stack then
2570 we can leave the result of this operation in acc:b
2572 if ((IS_ARITHMETIC_OP (ic)
2573 || IS_CONDITIONAL(ic)
2574 || IS_BITWISE_OP (ic)
2575 || ic->op == LEFT_OP || ic->op == RIGHT_OP || ic->op == CALL
2576 || (ic->op == ADDRESS_OF && isOperandOnStack (IC_LEFT (ic)))
2578 IS_ITEMP (IC_RESULT (ic)) &&
2579 getSize (operandType (IC_RESULT (ic))) <= 2)
2581 packRegsForAccUse (ic);
2586 /*-----------------------------------------------------------------*/
2587 /* assignRegisters - assigns registers to each live range as need */
2588 /*-----------------------------------------------------------------*/
2590 ds390_assignRegisters (eBBlock ** ebbs, int count)
2595 setToNull ((void *) &_G.funcrUsed);
2596 setToNull ((void *) &_G.regAssigned);
2597 setToNull ((void *) &_G.totRegAssigned);
2598 setToNull ((void *) &_G.funcrUsed);
2599 ds390_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
2601 if (options.model != MODEL_FLAT24) options.stack10bit = 0;
2602 /* change assignments this will remove some
2603 live ranges reducing some register pressure */
2604 for (i = 0; i < count; i++)
2605 packRegisters (ebbs[i]);
2607 if (options.dump_pack)
2608 dumpEbbsToFileExt (DUMP_PACK, ebbs, count);
2610 /* first determine for each live range the number of
2611 registers & the type of registers required for each */
2614 /* and serially allocate registers */
2615 serialRegAssign (ebbs, count);
2622 /* if stack was extended then tell the user */
2625 /* werror(W_TOOMANY_SPILS,"stack", */
2626 /* _G.stackExtend,currFunc->name,""); */
2632 /* werror(W_TOOMANY_SPILS,"data space", */
2633 /* _G.dataExtend,currFunc->name,""); */
2637 /* after that create the register mask
2638 for each of the instruction */
2639 createRegMask (ebbs, count);
2641 /* redo that offsets for stacked automatic variables */
2642 redoStackOffsets ();
2644 if (options.dump_rassgn) {
2645 dumpEbbsToFileExt (DUMP_RASSGN, ebbs, count);
2646 dumpLiveRanges (DUMP_LRANGE, liveRanges);
2649 /* do the overlaysegment stuff SDCCmem.c */
2650 doOverlays (ebbs, count);
2652 /* now get back the chain */
2653 ic = iCodeLabelOptimize (iCodeFromeBBlock (ebbs, count));
2658 /* free up any _G.stackSpil locations allocated */
2659 applyToSet (_G.stackSpil, deallocStackSpil);
2661 setToNull ((void **) &_G.stackSpil);
2662 setToNull ((void **) &_G.spiltSet);
2663 /* mark all registers as free */