* src/pic/ralloc.c (deassignLR): allthough pic port is buggy already,
[fw/sdcc] / src / ds390 / ralloc.c
1 /*------------------------------------------------------------------------
2
3   SDCCralloc.c - source file for register allocation. (DS80C390) specific
4
5                 Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1998)
6
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
10    later version.
11
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.
16
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.
20
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 -------------------------------------------------------------------------*/
25
26 #include "common.h"
27 #include "ralloc.h"
28 #include "gen.h"
29
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 /*-----------------------------------------------------------------*/
38
39 #define D(x)
40
41 /* Global data */
42 static struct
43   {
44     bitVect *spiltSet;
45     set *stackSpil;
46     bitVect *regAssigned;
47     bitVect *totRegAssigned;    /* final set of LRs that got into registers */
48     short blockSpil;
49     int slocNum;
50     bitVect *funcrUsed;         /* registers used in a function */
51     int stackExtend;
52     int dataExtend;
53   }
54 _G;
55
56 /* Shared with gen.c */
57 int ds390_ptrRegReq;            /* one byte pointer register required */
58
59 /* 8051 registers */
60 regs regs390[] =
61 {
62
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},
87 };
88 int ds390_nRegs = 13;
89 static void spillThis (symbol *);
90 static void freeAllRegs ();
91 static iCode * packRegsDPTRuse (operand *);
92 static int packRegsDPTRnuse (operand *,unsigned);
93
94 /*-----------------------------------------------------------------*/
95 /* allocReg - allocates register of given type                     */
96 /*-----------------------------------------------------------------*/
97 static regs *
98 allocReg (short type)
99 {
100   int i;
101
102   for (i = 0; i < ds390_nRegs; i++)
103     {
104
105       /* if type is given as 0 then any
106          free register will do */
107       if (!type &&
108           regs390[i].isFree)
109         {
110           regs390[i].isFree = 0;
111           if (currFunc)
112             currFunc->regsUsed =
113               bitVectSetBit (currFunc->regsUsed, i);
114           return &regs390[i];
115         }
116       /* other wise look for specific type
117          of register */
118       if (regs390[i].isFree &&
119           regs390[i].type == type)
120         {
121           regs390[i].isFree = 0;
122           if (currFunc)
123             currFunc->regsUsed =
124               bitVectSetBit (currFunc->regsUsed, i);
125           return &regs390[i];
126         }
127     }
128   return NULL;
129 }
130
131 /*-----------------------------------------------------------------*/
132 /* ds390_regWithIdx - returns pointer to register with index number*/
133 /*-----------------------------------------------------------------*/
134 regs *
135 ds390_regWithIdx (int idx)
136 {
137   int i;
138
139   for (i = 0; i < sizeof(regs390)/sizeof(regs); i++)
140     if (regs390[i].rIdx == idx)
141       return &regs390[i];
142
143   werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
144           "regWithIdx not found");
145   exit (1);
146 }
147
148 /*-----------------------------------------------------------------*/
149 /* freeReg - frees a register                                      */
150 /*-----------------------------------------------------------------*/
151 static void
152 freeReg (regs * reg)
153 {
154   if (!reg)
155     {
156       werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
157               "freeReg - Freeing NULL register");
158       exit (1);
159     }
160
161   reg->isFree = 1;
162 }
163
164 /*-----------------------------------------------------------------*/
165 /* useReg - marks a register  as used                              */
166 /*-----------------------------------------------------------------*/
167 static void
168 useReg (regs * reg)
169 {
170   reg->isFree = 0;
171 }
172
173
174 /*-----------------------------------------------------------------*/
175 /* nFreeRegs - returns number of free registers                    */
176 /*-----------------------------------------------------------------*/
177 static int
178 nFreeRegs (int type)
179 {
180   int i;
181   int nfr = 0;
182
183   for (i = 0; i < ds390_nRegs; i++)
184     if (regs390[i].isFree && regs390[i].type == type)
185       nfr++;
186   return nfr;
187 }
188
189 /*-----------------------------------------------------------------*/
190 /* nfreeRegsType - free registers with type                         */
191 /*-----------------------------------------------------------------*/
192 static int
193 nfreeRegsType (int type)
194 {
195   int nfr;
196   if (type == REG_PTR)
197     {
198       if ((nfr = nFreeRegs (type)) == 0)
199         return nFreeRegs (REG_GPR);
200     }
201
202   return nFreeRegs (type);
203 }
204
205
206
207 /*-----------------------------------------------------------------*/
208 /* isOperandInReg - returns true if operand is currently in regs   */
209 /*-----------------------------------------------------------------*/
210 static int isOperandInReg(operand *op)
211 {
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);
217 }
218
219 /*-----------------------------------------------------------------*/
220 /* computeSpillable - given a point find the spillable live ranges */
221 /*-----------------------------------------------------------------*/
222 static bitVect *
223 computeSpillable (iCode * ic)
224 {
225   bitVect *spillable;
226
227   /* spillable live ranges are those that are live at this
228      point . the following categories need to be subtracted
229      from this set.
230      a) - those that are already spilt
231      b) - if being used by this one
232      c) - defined by this one */
233
234   spillable = bitVectCopy (ic->rlive);
235   spillable =
236     bitVectCplAnd (spillable, _G.spiltSet);     /* those already spilt */
237   spillable =
238     bitVectCplAnd (spillable, ic->uses);        /* used in this one */
239   bitVectUnSetBit (spillable, ic->defKey);
240   spillable = bitVectIntersect (spillable, _G.regAssigned);
241   return spillable;
242
243 }
244
245 /*-----------------------------------------------------------------*/
246 /* noSpilLoc - return true if a variable has no spil location      */
247 /*-----------------------------------------------------------------*/
248 static int
249 noSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
250 {
251   return (sym->usl.spillLoc ? 0 : 1);
252 }
253
254 /*-----------------------------------------------------------------*/
255 /* hasSpilLoc - will return 1 if the symbol has spil location      */
256 /*-----------------------------------------------------------------*/
257 static int
258 hasSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
259 {
260   return (sym->usl.spillLoc ? 1 : 0);
261 }
262
263 /*-----------------------------------------------------------------*/
264 /* directSpilLoc - will return 1 if the splilocation is in direct  */
265 /*-----------------------------------------------------------------*/
266 static int
267 directSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
268 {
269   if (sym->usl.spillLoc &&
270       (IN_DIRSPACE (SPEC_OCLS (sym->usl.spillLoc->etype))))
271     return 1;
272   else
273     return 0;
274 }
275
276 /*-----------------------------------------------------------------*/
277 /* hasSpilLocnoUptr - will return 1 if the symbol has spil location */
278 /*                    but is not used as a pointer                 */
279 /*-----------------------------------------------------------------*/
280 static int
281 hasSpilLocnoUptr (symbol * sym, eBBlock * ebp, iCode * ic)
282 {
283   return ((sym->usl.spillLoc && !sym->uptr) ? 1 : 0);
284 }
285
286 /*-----------------------------------------------------------------*/
287 /* rematable - will return 1 if the remat flag is set              */
288 /*-----------------------------------------------------------------*/
289 static int
290 rematable (symbol * sym, eBBlock * ebp, iCode * ic)
291 {
292   return sym->remat;
293 }
294
295 /*-----------------------------------------------------------------*/
296 /* notUsedInRemaining - not used or defined in remain of the block */
297 /*-----------------------------------------------------------------*/
298 static int
299 notUsedInRemaining (symbol * sym, eBBlock * ebp, iCode * ic)
300 {
301   return ((usedInRemaining (operandFromSymbol (sym), ic) ? 0 : 1) &&
302           allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq));
303 }
304
305 /*-----------------------------------------------------------------*/
306 /* allLRs - return true for all                                    */
307 /*-----------------------------------------------------------------*/
308 static int
309 allLRs (symbol * sym, eBBlock * ebp, iCode * ic)
310 {
311   return 1;
312 }
313
314 /*-----------------------------------------------------------------*/
315 /* liveRangesWith - applies function to a given set of live range  */
316 /*-----------------------------------------------------------------*/
317 static set *
318 liveRangesWith (bitVect * lrs, int (func) (symbol *, eBBlock *, iCode *),
319                 eBBlock * ebp, iCode * ic)
320 {
321   set *rset = NULL;
322   int i;
323
324   if (!lrs || !lrs->size)
325     return NULL;
326
327   for (i = 1; i < lrs->size; i++)
328     {
329       symbol *sym;
330       if (!bitVectBitValue (lrs, i))
331         continue;
332
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)))
336         {
337           werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
338                   "liveRangesWith could not find liveRange");
339           exit (1);
340         }
341
342       if (func (sym, ebp, ic) && bitVectBitValue (_G.regAssigned, sym->key))
343         addSetHead (&rset, sym);
344     }
345
346   return rset;
347 }
348
349
350 /*-----------------------------------------------------------------*/
351 /* leastUsedLR - given a set determines which is the least used    */
352 /*-----------------------------------------------------------------*/
353 static symbol *
354 leastUsedLR (set * sset)
355 {
356   symbol *sym = NULL, *lsym = NULL;
357
358   sym = lsym = setFirstItem (sset);
359
360   if (!lsym)
361     return NULL;
362
363   for (; lsym; lsym = setNextItem (sset))
364     {
365
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))
370           sym = lsym;
371
372       /* if less usage */
373       if (lsym->used < sym->used)
374         sym = lsym;
375
376     }
377
378   setToNull ((void *) &sset);
379   sym->blockSpil = 0;
380   return sym;
381 }
382
383 /*-----------------------------------------------------------------*/
384 /* noOverLap - will iterate through the list looking for over lap  */
385 /*-----------------------------------------------------------------*/
386 static int
387 noOverLap (set * itmpStack, symbol * fsym)
388 {
389   symbol *sym;
390
391   for (sym = setFirstItem (itmpStack); sym;
392        sym = setNextItem (itmpStack))
393     {
394         if (bitVectBitValue(sym->clashes,fsym->key)) return 0;
395     }
396   return 1;
397 }
398
399 /*-----------------------------------------------------------------*/
400 /* isFree - will return 1 if the a free spil location is found     */
401 /*-----------------------------------------------------------------*/
402 static
403 DEFSETFUNC (isFree)
404 {
405   symbol *sym = item;
406   V_ARG (symbol **, sloc);
407   V_ARG (symbol *, fsym);
408
409   /* if already found */
410   if (*sloc)
411     return 0;
412
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  */
417   if (sym->isFree &&
418       noOverLap (sym->usl.itmpStack, fsym) &&
419       getSize (sym->type) >= getSize (fsym->type))
420     {
421       *sloc = sym;
422       return 1;
423     }
424
425   return 0;
426 }
427
428 /*-----------------------------------------------------------------*/
429 /* spillLRWithPtrReg :- will spil those live ranges which use PTR  */
430 /*-----------------------------------------------------------------*/
431 static void
432 spillLRWithPtrReg (symbol * forSym)
433 {
434   symbol *lrsym;
435   regs *r0, *r1;
436   int k;
437
438   if (!_G.regAssigned ||
439       bitVectIsZero (_G.regAssigned))
440     return;
441
442   r0 = ds390_regWithIdx (R0_IDX);
443   r1 = ds390_regWithIdx (R1_IDX);
444
445   /* for all live ranges */
446   for (lrsym = hTabFirstItem (liveRanges, &k); lrsym;
447        lrsym = hTabNextItem (liveRanges, &k))
448     {
449       int j;
450
451       /* if no registers assigned to it or spilt */
452       /* if it does not overlap this then
453          no need to spill it */
454
455       if (lrsym->isspilt || !lrsym->nRegs ||
456           (lrsym->liveTo < forSym->liveFrom))
457         continue;
458
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)
464           {
465             spillThis (lrsym);
466             break;
467           }
468     }
469
470 }
471
472 /*-----------------------------------------------------------------*/
473 /* createStackSpil - create a location on the stack to spil        */
474 /*-----------------------------------------------------------------*/
475 static symbol *
476 createStackSpil (symbol * sym)
477 {
478   symbol *sloc = NULL;
479   int useXstack, model, noOverlay;
480
481   char slocBuffer[30];
482
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))
486     {
487       /* found a free one : just update & return */
488       sym->usl.spillLoc = sloc;
489       sym->stackSpil = 1;
490       sloc->isFree = 0;
491       addSetHead (&sloc->usl.itmpStack, sym);
492       return sym;
493     }
494
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 */
498
499   if (SNPRINTF (slocBuffer, sizeof(slocBuffer),
500                 "sloc%d", _G.slocNum++) >= sizeof (slocBuffer))
501     {
502       fprintf (stderr, "***Internal error: slocBuffer overflowed: %s:%d\n",
503                __FILE__, __LINE__);
504       exit (1);
505     }
506
507   sloc = newiTemp (slocBuffer);
508
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;
514   } else {
515     SPEC_SCLS (sloc->etype) = S_XDATA;
516   }
517   SPEC_EXTR (sloc->etype) = 0;
518   SPEC_STAT (sloc->etype) = 0;
519   SPEC_VOLATILE(sloc->etype) = 0;
520   SPEC_ABSA(sloc->etype) = 0;
521
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
528    */
529
530   useXstack = options.useXstack;
531   model = options.model;
532   noOverlay = options.noOverlay;
533   options.noOverlay = 1;
534
535   /* options.model = options.useXstack = 0; */
536
537   allocLocal (sloc);
538
539   options.useXstack = useXstack;
540   options.model = model;
541   options.noOverlay = noOverlay;
542   sloc->isref = 1;              /* to prevent compiler warning */
543
544   /* if it is on the stack then update the stack */
545   if (IN_STACK (sloc->etype))
546     {
547       currFunc->stack += getSize (sloc->type);
548       _G.stackExtend += getSize (sloc->type);
549     }
550   else
551     _G.dataExtend += getSize (sloc->type);
552
553   /* add it to the _G.stackSpil set */
554   addSetHead (&_G.stackSpil, sloc);
555   sym->usl.spillLoc = sloc;
556   sym->stackSpil = 1;
557
558   /* add it to the set of itempStack set
559      of the spill location */
560   addSetHead (&sloc->usl.itmpStack, sym);
561   return sym;
562 }
563
564 /*-----------------------------------------------------------------*/
565 /* isSpiltOnStack - returns true if the spil location is on stack  */
566 /*-----------------------------------------------------------------*/
567 static bool
568 isSpiltOnStack (symbol * sym)
569 {
570   sym_link *etype;
571
572   if (!sym)
573     return FALSE;
574
575   if (!sym->isspilt)
576     return FALSE;
577
578 /*     if (sym->_G.stackSpil) */
579 /*      return TRUE; */
580
581   if (!sym->usl.spillLoc)
582     return FALSE;
583
584   etype = getSpec (sym->usl.spillLoc->type);
585   if (IN_STACK (etype))
586     return TRUE;
587
588   return FALSE;
589 }
590
591 /*-----------------------------------------------------------------*/
592 /* spillThis - spils a specific operand                            */
593 /*-----------------------------------------------------------------*/
594 static void
595 spillThis (symbol * sym)
596 {
597   int i;
598   /* if this is rematerializable or has a spillLocation
599      we are okay, else we need to create a spillLocation
600      for it */
601   if (!(sym->remat || sym->usl.spillLoc))
602     createStackSpil (sym);
603
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);
607
608   bitVectUnSetBit (_G.regAssigned, sym->key);
609   bitVectUnSetBit (_G.totRegAssigned, sym->key);
610
611   for (i = 0; i < sym->nRegs; i++)
612
613     if (sym->regs[i])
614       {
615         freeReg (sym->regs[i]);
616         sym->regs[i] = NULL;
617       }
618
619   /* if spilt on stack then free up r0 & r1
620      if they could have been assigned to some
621      LIVE ranges */
622   if (!ds390_ptrRegReq && isSpiltOnStack (sym) && !options.stack10bit)
623     {
624       ds390_ptrRegReq ++;
625       spillLRWithPtrReg (sym);
626     }
627
628   if (sym->usl.spillLoc && !sym->remat)
629     sym->usl.spillLoc->allocreq++;
630   return;
631 }
632
633 /*-----------------------------------------------------------------*/
634 /* selectSpil - select a iTemp to spil : rather a simple procedure */
635 /*-----------------------------------------------------------------*/
636 static symbol *
637 selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
638 {
639   bitVect *lrcs = NULL;
640   set *selectS;
641   symbol *sym;
642
643   /* get the spillable live ranges */
644   lrcs = computeSpillable (ic);
645
646   /* get all live ranges that are rematerizable */
647   if ((selectS = liveRangesWith (lrcs, rematable, ebp, ic)))
648     {
649
650       /* return the least used of these */
651       return leastUsedLR (selectS);
652     }
653
654   /* get live ranges with spillLocations in direct space */
655   if ((selectS = liveRangesWith (lrcs, directSpilLoc, ebp, ic)))
656     {
657       sym = leastUsedLR (selectS);
658       strncpyz (sym->rname,
659                 sym->usl.spillLoc->rname[0] ?
660                    sym->usl.spillLoc->rname : sym->usl.spillLoc->name,
661                 sizeof(sym->rname));
662       sym->spildir = 1;
663       /* mark it as allocation required */
664       sym->usl.spillLoc->allocreq++;
665       return sym;
666     }
667
668   /* if the symbol is local to the block then */
669   if (forSym->liveTo < ebp->lSeq)
670     {
671
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)))
675         {
676           sym = leastUsedLR (selectS);
677           /* if this is not rematerializable */
678           if (!sym->remat)
679             {
680               _G.blockSpil++;
681               sym->blockSpil = 1;
682             }
683           return sym;
684         }
685
686       /* check if there are any live ranges that not
687          used in the remainder of the block */
688       if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInRemaining, ebp, ic)))
689         {
690           sym = leastUsedLR (selectS);
691           if (sym != forSym)
692             {
693               if (!sym->remat)
694                 {
695                   sym->remainSpil = 1;
696                   _G.blockSpil++;
697                 }
698               return sym;
699             }
700         }
701     }
702
703   /* find live ranges with spillocation && not used as pointers */
704   if ((selectS = liveRangesWith (lrcs, hasSpilLocnoUptr, ebp, ic)))
705     {
706
707       sym = leastUsedLR (selectS);
708       /* mark this as allocation required */
709       sym->usl.spillLoc->allocreq++;
710       return sym;
711     }
712
713   /* find live ranges with spillocation */
714   if ((selectS = liveRangesWith (lrcs, hasSpilLoc, ebp, ic)))
715     {
716
717       sym = leastUsedLR (selectS);
718       sym->usl.spillLoc->allocreq++;
719       return sym;
720     }
721
722   /* couldn't find then we need to create a spil
723      location on the stack , for which one? the least
724      used ofcourse */
725   if ((selectS = liveRangesWith (lrcs, noSpilLoc, ebp, ic)))
726     {
727
728       /* return a created spil location */
729       sym = createStackSpil (leastUsedLR (selectS));
730       sym->usl.spillLoc->allocreq++;
731       return sym;
732     }
733
734   /* this is an extreme situation we will spill
735      this one : happens very rarely but it does happen */
736   spillThis (forSym);
737   return forSym;
738
739 }
740
741 /*-----------------------------------------------------------------*/
742 /* spilSomething - spil some variable & mark registers as free     */
743 /*-----------------------------------------------------------------*/
744 static bool
745 spilSomething (iCode * ic, eBBlock * ebp, symbol * forSym)
746 {
747   symbol *ssym;
748   int i;
749
750   /* get something we can spil */
751   ssym = selectSpil (ic, ebp, forSym);
752
753   /* mark it as spilt */
754   ssym->isspilt = ssym->spillA = 1;
755   _G.spiltSet = bitVectSetBit (_G.spiltSet, ssym->key);
756
757   /* mark it as not register assigned &
758      take it away from the set */
759   bitVectUnSetBit (_G.regAssigned, ssym->key);
760   bitVectUnSetBit (_G.totRegAssigned, ssym->key);
761
762   /* mark the registers as free */
763   for (i = 0; i < ssym->nRegs; i++)
764     if (ssym->regs[i])
765       freeReg (ssym->regs[i]);
766
767   /* if spilt on stack then free up r0 & r1
768      if they could have been assigned to as gprs */
769   if (!ds390_ptrRegReq && isSpiltOnStack (ssym) && !options.stack10bit)
770     {
771             ds390_ptrRegReq++;
772       spillLRWithPtrReg (ssym);
773     }
774
775   /* if this was a block level spil then insert push & pop
776      at the start & end of block respectively */
777   if (ssym->blockSpil)
778     {
779       iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
780       /* add push to the start of the block */
781       addiCodeToeBBlock (ebp, nic, (ebp->sch->op == LABEL ?
782                                     ebp->sch->next : ebp->sch));
783       nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
784       /* add pop to the end of the block */
785       addiCodeToeBBlock (ebp, nic, NULL);
786     }
787
788   /* if spilt because not used in the remainder of the
789      block then add a push before this instruction and
790      a pop at the end of the block */
791   if (ssym->remainSpil)
792     {
793
794       iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
795       /* add push just before this instruction */
796       addiCodeToeBBlock (ebp, nic, ic);
797
798       nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
799       /* add pop to the end of the block */
800       addiCodeToeBBlock (ebp, nic, NULL);
801     }
802
803   if (ssym == forSym)
804     return FALSE;
805   else
806     return TRUE;
807 }
808
809 /*-----------------------------------------------------------------*/
810 /* getRegPtr - will try for PTR if not a GPR type if not spil      */
811 /*-----------------------------------------------------------------*/
812 static regs *
813 getRegPtr (iCode * ic, eBBlock * ebp, symbol * sym)
814 {
815   regs *reg;
816   int j;
817
818 tryAgain:
819   /* try for a ptr type */
820   if ((reg = allocReg (REG_PTR)))
821     return reg;
822
823   /* try for gpr type */
824   if ((reg = allocReg (REG_GPR)))
825     return reg;
826
827   /* we have to spil */
828   if (!spilSomething (ic, ebp, sym))
829     return NULL;
830
831   /* make sure partially assigned registers aren't reused */
832   for (j=0; j<=sym->nRegs; j++)
833     if (sym->regs[j])
834       sym->regs[j]->isFree = 0;
835
836   /* this looks like an infinite loop but
837      in really selectSpil will abort  */
838   goto tryAgain;
839 }
840
841 /*-----------------------------------------------------------------*/
842 /* getRegGpr - will try for GPR if not spil                        */
843 /*-----------------------------------------------------------------*/
844 static regs *
845 getRegGpr (iCode * ic, eBBlock * ebp, symbol * sym)
846 {
847   regs *reg;
848   int j;
849
850 tryAgain:
851   /* try for gpr type */
852   if ((reg = allocReg (REG_GPR)))
853     return reg;
854
855   if (!ds390_ptrRegReq)
856     if ((reg = allocReg (REG_PTR)))
857       return reg;
858
859   /* we have to spil */
860   if (!spilSomething (ic, ebp, sym))
861     return NULL;
862
863   /* make sure partially assigned registers aren't reused */
864   for (j=0; j<=sym->nRegs; j++)
865     if (sym->regs[j])
866       sym->regs[j]->isFree = 0;
867
868   /* this looks like an infinite loop but
869      in really selectSpil will abort  */
870   goto tryAgain;
871 }
872
873 /*-----------------------------------------------------------------*/
874 /* getRegPtrNoSpil - get it cannot split                           */
875 /*-----------------------------------------------------------------*/
876 static regs *getRegPtrNoSpil()
877 {
878   regs *reg;
879
880   /* try for a ptr type */
881   if ((reg = allocReg (REG_PTR)))
882     return reg;
883
884   /* try for gpr type */
885   if ((reg = allocReg (REG_GPR)))
886     return reg;
887
888   assert(0);
889
890   /* just to make the compiler happy */
891   return 0;
892 }
893
894 /*-----------------------------------------------------------------*/
895 /* getRegGprNoSpil - get it cannot split                           */
896 /*-----------------------------------------------------------------*/
897 static regs *getRegGprNoSpil()
898 {
899
900   regs *reg;
901   if ((reg = allocReg (REG_GPR)))
902     return reg;
903
904   if (!ds390_ptrRegReq)
905     if ((reg = allocReg (REG_PTR)))
906       return reg;
907
908   assert(0);
909
910   /* just to make the compiler happy */
911   return 0;
912 }
913
914 /*-----------------------------------------------------------------*/
915 /* symHasReg - symbol has a given register                         */
916 /*-----------------------------------------------------------------*/
917 static bool
918 symHasReg (symbol * sym, regs * reg)
919 {
920   int i;
921
922   for (i = 0; i < sym->nRegs; i++)
923     if (sym->regs[i] == reg)
924       return TRUE;
925
926   return FALSE;
927 }
928
929 /*-----------------------------------------------------------------*/
930 /* deassignLRs - check the live to and if they have registers & are */
931 /*               not spilt then free up the registers              */
932 /*-----------------------------------------------------------------*/
933 static void
934 deassignLRs (iCode * ic, eBBlock * ebp)
935 {
936   symbol *sym;
937   int k;
938   symbol *result;
939
940   for (sym = hTabFirstItem (liveRanges, &k); sym;
941        sym = hTabNextItem (liveRanges, &k))
942     {
943
944       symbol *psym = NULL;
945       /* if it does not end here */
946       if (sym->liveTo > ic->seq)
947         continue;
948
949       /* if it was spilt on stack then we can
950          mark the stack spil location as free */
951       if (sym->isspilt)
952         {
953           if (sym->stackSpil)
954             {
955               sym->usl.spillLoc->isFree = 1;
956               sym->stackSpil = 0;
957             }
958           continue;
959         }
960
961       if (!bitVectBitValue (_G.regAssigned, sym->key))
962         continue;
963
964       /* special case check if this is an IFX &
965          the privious one was a pop and the
966          previous one was not spilt then keep track
967          of the symbol */
968       if (ic->op == IFX && ic->prev &&
969           ic->prev->op == IPOP &&
970           !ic->prev->parmPush &&
971           !OP_SYMBOL (IC_LEFT (ic->prev))->isspilt)
972         psym = OP_SYMBOL (IC_LEFT (ic->prev));
973
974       if (sym->nRegs)
975         {
976           int i = 0;
977
978           bitVectUnSetBit (_G.regAssigned, sym->key);
979
980           /* if the result of this one needs registers
981              and does not have it then assign it right
982              away */
983           if (IC_RESULT (ic) &&
984               !(SKIP_IC2 (ic) ||        /* not a special icode */
985                 ic->op == JUMPTABLE ||
986                 ic->op == IFX ||
987                 ic->op == IPUSH ||
988                 ic->op == IPOP ||
989                 ic->op == RETURN ||
990                 POINTER_SET (ic)) &&
991               (result = OP_SYMBOL (IC_RESULT (ic))) &&  /* has a result */
992               result->liveTo > ic->seq &&       /* and will live beyond this */
993               result->liveTo <= ebp->lSeq &&    /* does not go beyond this block */
994               result->liveFrom == ic->seq &&    /* does not start before here */
995               result->regType == sym->regType &&        /* same register types */
996               result->nRegs &&  /* which needs registers */
997               !result->isspilt &&       /* and does not already have them */
998               !result->remat &&
999               !bitVectBitValue (_G.regAssigned, result->key) &&
1000           /* the number of free regs + number of regs in this LR
1001              can accomodate the what result Needs */
1002               ((nfreeRegsType (result->regType) +
1003                 sym->nRegs) >= result->nRegs)
1004             )
1005             {
1006
1007               for (i = 0; i < result->nRegs; i++)
1008                 if (i < sym->nRegs)
1009                   result->regs[i] = sym->regs[i];
1010                 else
1011                   result->regs[i] = getRegGpr (ic, ebp, result);
1012
1013               _G.regAssigned = bitVectSetBit (_G.regAssigned, result->key);
1014               _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, result->key);
1015
1016             }
1017
1018           /* free the remaining */
1019           for (; i < sym->nRegs; i++)
1020             {
1021               if (psym)
1022                 {
1023                   if (!symHasReg (psym, sym->regs[i]))
1024                     freeReg (sym->regs[i]);
1025                 }
1026               else
1027                 freeReg (sym->regs[i]);
1028             }
1029         }
1030     }
1031 }
1032
1033
1034 /*-----------------------------------------------------------------*/
1035 /* reassignLR - reassign this to registers                         */
1036 /*-----------------------------------------------------------------*/
1037 static void
1038 reassignLR (operand * op)
1039 {
1040   symbol *sym = OP_SYMBOL (op);
1041   int i;
1042
1043   /* not spilt any more */
1044   sym->isspilt = sym->spillA = sym->blockSpil = sym->remainSpil = 0;
1045   bitVectUnSetBit (_G.spiltSet, sym->key);
1046
1047   _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
1048   _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, sym->key);
1049
1050   _G.blockSpil--;
1051
1052   for (i = 0; i < sym->nRegs; i++)
1053     sym->regs[i]->isFree = 0;
1054 }
1055
1056 /*-----------------------------------------------------------------*/
1057 /* willCauseSpill - determines if allocating will cause a spill    */
1058 /*-----------------------------------------------------------------*/
1059 static int
1060 willCauseSpill (int nr, int rt)
1061 {
1062   /* first check if there are any avlb registers
1063      of te type required */
1064   if (rt == REG_PTR)
1065     {
1066       /* special case for pointer type
1067          if pointer type not avlb then
1068          check for type gpr */
1069       if (nFreeRegs (rt) >= nr)
1070         return 0;
1071       if (nFreeRegs (REG_GPR) >= nr)
1072         return 0;
1073     }
1074   else
1075     {
1076       if (ds390_ptrRegReq)
1077         {
1078           if (nFreeRegs (rt) >= nr)
1079             return 0;
1080         }
1081       else
1082         {
1083           if (nFreeRegs (REG_PTR) +
1084               nFreeRegs (REG_GPR) >= nr)
1085             return 0;
1086         }
1087     }
1088
1089   /* it will cause a spil */
1090   return 1;
1091 }
1092
1093 /*-----------------------------------------------------------------*/
1094 /* positionRegs - the allocator can allocate same registers to res- */
1095 /* ult and operand, if this happens make sure they are in the same */
1096 /* position as the operand otherwise chaos results                 */
1097 /*-----------------------------------------------------------------*/
1098 static int
1099 positionRegs (symbol * result, symbol * opsym)
1100 {
1101   int count = min (result->nRegs, opsym->nRegs);
1102   int i, j = 0, shared = 0;
1103   int change = 0;
1104
1105   /* if the result has been spilt then cannot share */
1106   if (opsym->isspilt)
1107     return 0;
1108 again:
1109   shared = 0;
1110   /* first make sure that they actually share */
1111   for (i = 0; i < count; i++)
1112     {
1113       for (j = 0; j < count; j++)
1114         {
1115           if (result->regs[i] == opsym->regs[j] && i != j)
1116             {
1117               shared = 1;
1118               goto xchgPositions;
1119             }
1120         }
1121     }
1122 xchgPositions:
1123   if (shared)
1124     {
1125       regs *tmp = result->regs[i];
1126       result->regs[i] = result->regs[j];
1127       result->regs[j] = tmp;
1128       change ++;
1129       goto again;
1130     }
1131   return change;
1132 }
1133
1134 /*-----------------------------------------------------------------*/
1135 /* unusedLRS - returns a bitVector of liveranges not used in 'ebp' */
1136 /*-----------------------------------------------------------------*/
1137 bitVect *unusedLRs (eBBlock *ebp)
1138 {
1139     bitVect *ret = NULL;
1140     symbol *sym;
1141     int key;
1142
1143     if (!ebp) return NULL;
1144     for (sym = hTabFirstItem(liveRanges,&key); sym ;
1145          sym = hTabNextItem(liveRanges,&key)) {
1146
1147         if (notUsedInBlock(sym,ebp,NULL)) {
1148             ret = bitVectSetBit(ret,sym->key);
1149         }
1150     }
1151
1152     return ret;
1153 }
1154
1155 /*-----------------------------------------------------------------*/
1156 /* deassignUnsedLRs - if this baisc block ends in a return then    */
1157 /*                    deassign symbols not used in this block      */
1158 /*-----------------------------------------------------------------*/
1159 bitVect *deassignUnsedLRs(eBBlock *ebp)
1160 {
1161     bitVect *unused = NULL;
1162     int i;
1163
1164     switch (returnAtEnd(ebp)) {
1165     case 2: /* successor block ends in a return */
1166         unused = unusedLRs((eBBlock *) setFirstItem(ebp->succList));
1167         /* fall thru */
1168     case 1: /* this block ends in a return */
1169         unused = bitVectIntersect(unused,unusedLRs(ebp));
1170         break;
1171     }
1172
1173     if (unused) {
1174         for (i = 0 ; i < unused->size ; i++ ) {
1175
1176             /* if unused  */
1177             if (bitVectBitValue(unused,i)) {
1178
1179                 /* if assigned to registers */
1180                 if (bitVectBitValue(_G.regAssigned,i)) {
1181                     symbol *sym;
1182                     int j;
1183
1184                     sym = hTabItemWithKey(liveRanges,i);
1185                     /* remove it from regassigned & mark the
1186                        register free */
1187                     bitVectUnSetBit(_G.regAssigned,i);
1188                     for (j = 0 ; j < sym->nRegs; j++)
1189                         freeReg(sym->regs[j]);
1190                 } else {
1191                     /* not assigned to registers : remove from set*/
1192                     bitVectUnSetBit(unused,i);
1193                 }
1194             }
1195         }
1196     }
1197     return unused;
1198 }
1199
1200 /*-----------------------------------------------------------------*/
1201 /* reassignUnusedLRs - put registers to unused Live ranges         */
1202 /*-----------------------------------------------------------------*/
1203 void reassignUnusedLRs (bitVect *unused)
1204 {
1205     int i;
1206     if (!unused) return ;
1207
1208     for (i = 0 ; i < unused->size ; i++ ) {
1209         /* if unused : means it was assigned to registers before */
1210         if (bitVectBitValue(unused,i)) {
1211             symbol *sym;
1212             int j;
1213
1214             /* put it back into reg set*/
1215             bitVectSetBit(_G.regAssigned,i) ;
1216
1217             sym = hTabItemWithKey(liveRanges,i);
1218             /* makr registers busy */
1219             for (j = 0 ; j < sym->nRegs; j++)
1220                 sym->regs[j]->isFree = 0;
1221         }
1222     }
1223 }
1224
1225 /*------------------------------------------------------------------*/
1226 /* verifyRegsAssigned - make sure an iTemp is properly initialized; */
1227 /* it should either have registers or have beed spilled. Otherwise, */
1228 /* there was an uninitialized variable, so just spill this to get   */
1229 /* the operand in a valid state.                                    */
1230 /*------------------------------------------------------------------*/
1231 static void
1232 verifyRegsAssigned (operand *op, iCode * ic)
1233 {
1234   symbol * sym;
1235
1236   if (!op) return;
1237   if (!IS_ITEMP (op)) return;
1238
1239   sym = OP_SYMBOL (op);
1240   if (sym->isspilt) return;
1241   if (!sym->nRegs) return;
1242   if (sym->regs[0]) return;
1243
1244   werrorfl (ic->filename, ic->lineno, W_LOCAL_NOINIT,
1245             sym->prereqv ? sym->prereqv->name : sym->name);
1246   spillThis (sym);
1247 }
1248
1249
1250 /*-----------------------------------------------------------------*/
1251 /* serialRegAssign - serially allocate registers to the variables  */
1252 /*-----------------------------------------------------------------*/
1253 static void
1254 serialRegAssign (eBBlock ** ebbs, int count)
1255 {
1256   int i;
1257
1258   /* for all blocks */
1259   for (i = 0; i < count; i++)
1260       { /* ebbs */
1261
1262       iCode *ic;
1263       bitVect *unusedLRs = NULL;
1264
1265       if (ebbs[i]->noPath &&
1266           (ebbs[i]->entryLabel != entryLabel &&
1267            ebbs[i]->entryLabel != returnLabel))
1268         continue;
1269
1270       unusedLRs = deassignUnsedLRs(ebbs[i]);
1271
1272       /* of all instructions do */
1273       for (ic = ebbs[i]->sch; ic; ic = ic->next)
1274         {
1275
1276           /* if this is an ipop that means some live
1277              range will have to be assigned again */
1278           if (ic->op == IPOP)
1279             reassignLR (IC_LEFT (ic));
1280
1281           /* if result is present && is a true symbol */
1282           if (IC_RESULT (ic) && ic->op != IFX &&
1283               IS_TRUE_SYMOP (IC_RESULT (ic)))
1284             OP_SYMBOL (IC_RESULT (ic))->allocreq++;
1285
1286           /* take away registers from live
1287              ranges that end at this instruction */
1288           deassignLRs (ic, ebbs[i]);
1289
1290           /* some don't need registers */
1291           if (SKIP_IC2 (ic) ||
1292               ic->op == JUMPTABLE ||
1293               ic->op == IFX ||
1294               ic->op == IPUSH ||
1295               ic->op == IPOP ||
1296               (IC_RESULT (ic) && POINTER_SET (ic)))
1297             continue;
1298
1299           /* now we need to allocate registers
1300              only for the result */
1301           if (IC_RESULT (ic))
1302             {
1303               symbol *sym = OP_SYMBOL (IC_RESULT (ic));
1304               bitVect *spillable;
1305               int willCS;
1306               int j;
1307               int ptrRegSet = 0;
1308
1309               /* if it does not need or is spilt
1310                  or is already assigned to registers
1311                  or will not live beyond this instructions */
1312               if (!sym->nRegs ||
1313                   sym->isspilt ||
1314                   bitVectBitValue (_G.regAssigned, sym->key) ||
1315                   sym->liveTo <= ic->seq)
1316                 continue;
1317
1318               /* if some liverange has been spilt at the block level
1319                  and this one live beyond this block then spil this
1320                  to be safe */
1321               if (_G.blockSpil && sym->liveTo > ebbs[i]->lSeq)
1322                 {
1323                   spillThis (sym);
1324                   continue;
1325                 }
1326               /* if trying to allocate this will cause
1327                  a spill and there is nothing to spill
1328                  or this one is rematerializable then
1329                  spill this one */
1330               willCS = willCauseSpill (sym->nRegs, sym->regType);
1331               spillable = computeSpillable (ic);
1332               if (sym->remat ||
1333                   (willCS && bitVectIsZero (spillable)))
1334                 {
1335
1336                   spillThis (sym);
1337                   continue;
1338
1339                 }
1340
1341               /* If the live range preceeds the point of definition
1342                  then ideally we must take into account registers that
1343                  have been allocated after sym->liveFrom but freed
1344                  before ic->seq. This is complicated, so spill this
1345                  symbol instead and let fillGaps handle the allocation. */
1346               if (sym->liveFrom < ic->seq)
1347                 {
1348                     spillThis (sym);
1349                     continue;
1350                 }
1351
1352               /* if it has a spillocation & is used less than
1353                  all other live ranges then spill this */
1354                 if (willCS) {
1355                     if (sym->usl.spillLoc) {
1356                         symbol *leastUsed = leastUsedLR (liveRangesWith (spillable,
1357                                                                          allLRs, ebbs[i], ic));
1358                         if (leastUsed && leastUsed->used > sym->used) {
1359                             spillThis (sym);
1360                             continue;
1361                         }
1362                     } else {
1363                         /* if none of the liveRanges have a spillLocation then better
1364                            to spill this one than anything else already assigned to registers */
1365                         if (liveRangesWith(spillable,noSpilLoc,ebbs[i],ic)) {
1366                             /* if this is local to this block then we might find a block spil */
1367                             if (!(sym->liveFrom >= ebbs[i]->fSeq && sym->liveTo <= ebbs[i]->lSeq)) {
1368                                 spillThis (sym);
1369                                 continue;
1370                             }
1371                         }
1372                     }
1373                 }
1374
1375               /* if we need ptr regs for the right side
1376                  then mark it */
1377               if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic))
1378                   && getSize (OP_SYMBOL (IC_LEFT (ic))->type)
1379                   <= (unsigned) PTRSIZE)
1380                 {
1381                   ds390_ptrRegReq++;
1382                   ptrRegSet = 1;
1383                 }
1384               /* else we assign registers to it */
1385               _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
1386               _G.totRegAssigned = bitVectSetBit (_G.totRegAssigned, sym->key);
1387
1388               for (j = 0; j < sym->nRegs; j++)
1389                 {
1390                   if (sym->regType == REG_PTR)
1391                     sym->regs[j] = getRegPtr (ic, ebbs[i], sym);
1392                   else
1393                     sym->regs[j] = getRegGpr (ic, ebbs[i], sym);
1394
1395                   /* if the allocation falied which means
1396                      this was spilt then break */
1397                   if (!sym->regs[j])
1398                     break;
1399                 }
1400
1401               /* if it shares registers with operands make sure
1402                  that they are in the same position */
1403               if (!POINTER_SET(ic) && !POINTER_GET(ic))
1404                 {
1405                   if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)) &&
1406                       OP_SYMBOL (IC_LEFT (ic))->nRegs)
1407                     {
1408                       positionRegs (OP_SYMBOL (IC_RESULT (ic)),
1409                                     OP_SYMBOL (IC_LEFT (ic)));
1410                     }
1411                   /* do the same for the right operand */
1412                   if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)) &&
1413                       OP_SYMBOL (IC_RIGHT (ic))->nRegs)
1414                     {
1415                       positionRegs (OP_SYMBOL (IC_RESULT (ic)),
1416                                     OP_SYMBOL (IC_RIGHT (ic)));
1417                     }
1418                 }
1419
1420               if (ptrRegSet)
1421                 {
1422                   ds390_ptrRegReq--;
1423                   ptrRegSet = 0;
1424                 }
1425
1426             }
1427         }
1428       reassignUnusedLRs(unusedLRs);
1429     }
1430
1431     /* Check for and fix any problems with uninitialized operands */
1432     for (i = 0; i < count; i++)
1433       {
1434         iCode *ic;
1435
1436         if (ebbs[i]->noPath &&
1437             (ebbs[i]->entryLabel != entryLabel &&
1438              ebbs[i]->entryLabel != returnLabel))
1439             continue;
1440
1441         for (ic = ebbs[i]->sch; ic; ic = ic->next)
1442           {
1443             if (SKIP_IC2 (ic))
1444               continue;
1445
1446             if (ic->op == IFX)
1447               {
1448                 verifyRegsAssigned (IC_COND (ic), ic);
1449                 continue;
1450               }
1451
1452             if (ic->op == JUMPTABLE)
1453               {
1454                 verifyRegsAssigned (IC_JTCOND (ic), ic);
1455                 continue;
1456               }
1457
1458             verifyRegsAssigned (IC_RESULT (ic), ic);
1459             verifyRegsAssigned (IC_LEFT (ic), ic);
1460             verifyRegsAssigned (IC_RIGHT (ic), ic);
1461           }
1462       }
1463 }
1464
1465 /*-----------------------------------------------------------------*/
1466 /* fillGaps - Try to fill in the Gaps left by Pass1                */
1467 /*-----------------------------------------------------------------*/
1468 static void fillGaps()
1469 {
1470     symbol *sym =NULL;
1471     int key =0;
1472     int loop = 0, change;
1473     int pass;
1474
1475     if (getenv("DISABLE_FILL_GAPS")) return;
1476
1477     /* First try to do DPTRuse once more since now we know what got into
1478        registers */
1479
1480     while (loop++ < 10) {
1481         change = 0;
1482
1483         for (sym = hTabFirstItem(liveRanges,&key) ; sym ;
1484              sym = hTabNextItem(liveRanges,&key)) {
1485             int size = getSize(sym->type);
1486
1487             if (sym->liveFrom == sym->liveTo) continue;
1488
1489             if (sym->uptr && sym->dptr==0 && !sym->ruonly &&
1490                 size < 4 && size > 1) {
1491
1492                 if (packRegsDPTRuse(operandFromSymbol(sym))) {
1493
1494                     /* if this was assigned to registers then */
1495                     if (bitVectBitValue(_G.totRegAssigned,sym->key)) {
1496                         /* take it out of the register assigned set */
1497                         bitVectUnSetBit(_G.totRegAssigned,sym->key);
1498                     } else if (sym->usl.spillLoc) {
1499                         sym->usl.spillLoc->allocreq--;
1500                         sym->usl.spillLoc = NULL;
1501                     }
1502
1503                     sym->nRegs = 0;
1504                     sym->isspilt = sym->spillA = 0;
1505                     continue ;
1506                 }
1507
1508                 /* try assigning other dptrs */
1509                 if (sym->dptr == 0 && packRegsDPTRnuse(operandFromSymbol(sym),1) && !getenv("DPTRnDISABLE")) {
1510                     /* if this was ssigned to registers then */
1511                     if (bitVectBitValue(_G.totRegAssigned,sym->key)) {
1512                         /* take it out of the register assigned set */
1513                         bitVectUnSetBit(_G.totRegAssigned,sym->key);
1514                     } else if (sym->usl.spillLoc) {
1515                         sym->usl.spillLoc->allocreq--;
1516                         sym->usl.spillLoc = NULL;
1517                     }
1518                     sym->nRegs = 0;
1519                     sym->isspilt = sym->spillA = 0;
1520                 }
1521             }
1522         }
1523
1524         /* look for livernages that was spilt by the allocator */
1525         for (sym = hTabFirstItem(liveRanges,&key) ; sym ;
1526              sym = hTabNextItem(liveRanges,&key)) {
1527
1528             int i;
1529             int pdone = 0;
1530
1531             if (!sym->spillA || !sym->clashes || sym->remat) continue ;
1532             if (!sym->uses || !sym->defs) continue ;
1533             /* find the liveRanges this one clashes with, that are
1534                still assigned to registers & mark the registers as used*/
1535             for ( i = 0 ; i < sym->clashes->size ; i ++) {
1536                 int k;
1537                 symbol *clr;
1538
1539                 if (bitVectBitValue(sym->clashes,i) == 0 ||    /* those that clash with this */
1540                     bitVectBitValue(_G.totRegAssigned,i) == 0) /* and are still assigned to registers */
1541                     continue ;
1542
1543                 clr = hTabItemWithKey(liveRanges,i);
1544                 assert(clr);
1545
1546                 /* mark these registers as used */
1547                 for (k = 0 ; k < clr->nRegs ; k++ )
1548                     useReg(clr->regs[k]);
1549             }
1550
1551             if (willCauseSpill(sym->nRegs,sym->regType)) {
1552                 /* NOPE :( clear all registers & and continue */
1553                 freeAllRegs();
1554                 continue ;
1555             }
1556
1557             /* THERE IS HOPE !!!! */
1558             for (i=0; i < sym->nRegs ; i++ ) {
1559                 if (sym->regType == REG_PTR)
1560                     sym->regs[i] = getRegPtrNoSpil ();
1561                 else
1562                     sym->regs[i] = getRegGprNoSpil ();
1563             }
1564
1565             /* For all its definitions check if the registers
1566                allocated needs positioning NOTE: we can position
1567                only ONCE if more than One positioning required
1568                then give up.
1569                We may need to perform the checks twice; once to
1570                position the registers as needed, the second to
1571                verify any register repositioning is still
1572                compatible.
1573               */
1574             sym->isspilt = 0;
1575             for (pass=0; pass<2; pass++) {
1576                 for (i = 0 ; i < sym->defs->size ; i++ ) {
1577                     if (bitVectBitValue(sym->defs,i)) {
1578                         iCode *ic;
1579                         if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ;
1580                         if (SKIP_IC(ic)) continue;
1581                         assert(isSymbolEqual(sym,OP_SYMBOL(IC_RESULT(ic)))); /* just making sure */
1582                         /* if left is assigned to registers */
1583                         if (IS_SYMOP(IC_LEFT(ic)) &&
1584                           bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_LEFT(ic))->key)) {
1585                             pdone += (positionRegs(sym,OP_SYMBOL(IC_LEFT(ic)))>0);
1586                         }
1587                         if (IS_SYMOP(IC_RIGHT(ic)) &&
1588                           bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RIGHT(ic))->key)) {
1589                             pdone += (positionRegs(sym,OP_SYMBOL(IC_RIGHT(ic)))>0);
1590                         }
1591                         if (pdone > 1) break;
1592                     }
1593                 }
1594                 for (i = 0 ; i < sym->uses->size ; i++ ) {
1595                     if (bitVectBitValue(sym->uses,i)) {
1596                         iCode *ic;
1597                         if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ;
1598                         if (SKIP_IC(ic)) continue;
1599                         if (POINTER_SET(ic) || POINTER_GET(ic)) continue ;
1600
1601                         /* if result is assigned to registers */
1602                         if (IS_SYMOP(IC_RESULT(ic)) &&
1603                           bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RESULT(ic))->key)) {
1604                             pdone += (positionRegs(sym,OP_SYMBOL(IC_RESULT(ic)))>0);
1605                         }
1606                         if (pdone > 1) break;
1607                     }
1608                 }
1609                 if (pdone == 0) break; /* second pass only if regs repositioned */
1610                 if (pdone > 1) break;
1611             }
1612             /* had to position more than once GIVE UP */
1613             if (pdone > 1) {
1614                 /* UNDO all the changes we made to try this */
1615                 sym->isspilt = 1;
1616                 for (i=0; i < sym->nRegs ; i++ ) {
1617                     sym->regs[i] = NULL;
1618                 }
1619                 freeAllRegs();
1620                 D (fprintf (stderr, "Fill Gap gave up due to positioning for "
1621                             "%s in function %s\n",
1622                             sym->name, currFunc ? currFunc->name : "UNKNOWN"));
1623                 continue ;
1624             }
1625             D (fprintf (stderr, "FILLED GAP for %s in function %s\n",
1626                         sym->name, currFunc ? currFunc->name : "UNKNOWN"));
1627             _G.totRegAssigned = bitVectSetBit(_G.totRegAssigned,sym->key);
1628             sym->isspilt = sym->spillA = 0 ;
1629             sym->usl.spillLoc->allocreq--;
1630             sym->usl.spillLoc = NULL;
1631             freeAllRegs();
1632             change ++;
1633         }
1634         if (!change) break;
1635     }
1636 }
1637
1638 /*-----------------------------------------------------------------*/
1639 /* rUmaskForOp :- returns register mask for an operand             */
1640 /*-----------------------------------------------------------------*/
1641 bitVect *
1642 ds390_rUmaskForOp (operand * op)
1643 {
1644   bitVect *rumask;
1645   symbol *sym;
1646   int j;
1647
1648   /* only temporaries are assigned registers */
1649   if (!IS_ITEMP (op))
1650     return NULL;
1651
1652   sym = OP_SYMBOL (op);
1653
1654   /* if spilt or no registers assigned to it
1655      then nothing */
1656   if (sym->isspilt || !sym->nRegs)
1657     return NULL;
1658
1659   rumask = newBitVect (ds390_nRegs);
1660
1661   for (j = 0; j < sym->nRegs; j++)
1662     {
1663       rumask = bitVectSetBit (rumask,
1664                               sym->regs[j]->rIdx);
1665     }
1666
1667   return rumask;
1668 }
1669
1670 /*-----------------------------------------------------------------*/
1671 /* regsUsedIniCode :- returns bit vector of registers used in iCode */
1672 /*-----------------------------------------------------------------*/
1673 static bitVect *
1674 regsUsedIniCode (iCode * ic)
1675 {
1676   bitVect *rmask = newBitVect (ds390_nRegs);
1677
1678   /* do the special cases first */
1679   if (ic->op == IFX)
1680     {
1681       rmask = bitVectUnion (rmask,
1682                             ds390_rUmaskForOp (IC_COND (ic)));
1683       goto ret;
1684     }
1685
1686   /* for the jumptable */
1687   if (ic->op == JUMPTABLE)
1688     {
1689       rmask = bitVectUnion (rmask,
1690                             ds390_rUmaskForOp (IC_JTCOND (ic)));
1691
1692       goto ret;
1693     }
1694
1695   /* of all other cases */
1696   if (IC_LEFT (ic))
1697     rmask = bitVectUnion (rmask,
1698                           ds390_rUmaskForOp (IC_LEFT (ic)));
1699
1700
1701   if (IC_RIGHT (ic))
1702     rmask = bitVectUnion (rmask,
1703                           ds390_rUmaskForOp (IC_RIGHT (ic)));
1704
1705   if (IC_RESULT (ic))
1706     rmask = bitVectUnion (rmask,
1707                           ds390_rUmaskForOp (IC_RESULT (ic)));
1708
1709 ret:
1710   return rmask;
1711 }
1712
1713 /*-----------------------------------------------------------------*/
1714 /* createRegMask - for each instruction will determine the regsUsed */
1715 /*-----------------------------------------------------------------*/
1716 static void
1717 createRegMask (eBBlock ** ebbs, int count)
1718 {
1719   int i;
1720
1721   /* for all blocks */
1722   for (i = 0; i < count; i++)
1723     {
1724       iCode *ic;
1725
1726       if (ebbs[i]->noPath &&
1727           (ebbs[i]->entryLabel != entryLabel &&
1728            ebbs[i]->entryLabel != returnLabel))
1729         continue;
1730
1731       /* for all instructions */
1732       for (ic = ebbs[i]->sch; ic; ic = ic->next)
1733         {
1734
1735           int j;
1736
1737           if (SKIP_IC2 (ic) || !ic->rlive)
1738             continue;
1739
1740           /* first mark the registers used in this
1741              instruction */
1742           ic->rUsed = regsUsedIniCode (ic);
1743           _G.funcrUsed = bitVectUnion (_G.funcrUsed, ic->rUsed);
1744
1745           /* now create the register mask for those
1746              registers that are in use : this is a
1747              super set of ic->rUsed */
1748           ic->rMask = newBitVect (ds390_nRegs + 1);
1749
1750           /* for all live Ranges alive at this point */
1751           for (j = 1; j < ic->rlive->size; j++)
1752             {
1753               symbol *sym;
1754               int k;
1755
1756               /* if not alive then continue */
1757               if (!bitVectBitValue (ic->rlive, j))
1758                 continue;
1759
1760               /* find the live range we are interested in */
1761               if (!(sym = hTabItemWithKey (liveRanges, j)))
1762                 {
1763                   werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
1764                           "createRegMask cannot find live range");
1765                   fprintf(stderr, "\tmissing live range: key=%d\n", j);
1766                   exit (0);
1767                 }
1768 #if 0
1769               /* special case for ruonly */
1770               if (sym->ruonly && sym->liveFrom != sym->liveTo) {
1771                   int size = getSize(sym->type);
1772                   int j = DPL_IDX;
1773                   for (k = 0 ; k < size; k++ )
1774                       ic->rMask = bitVectSetBit (ic->rMask, j++);
1775                   continue ;
1776               }
1777 #endif
1778               /* if no register assigned to it */
1779               if (!sym->nRegs || sym->isspilt)
1780                 continue;
1781
1782               /* for all the registers allocated to it */
1783               for (k = 0; k < sym->nRegs; k++)
1784                 if (sym->regs[k])
1785                   ic->rMask =
1786                     bitVectSetBit (ic->rMask, sym->regs[k]->rIdx);
1787             }
1788         }
1789     }
1790 }
1791
1792 /*-----------------------------------------------------------------*/
1793 /* rematStr - returns the rematerialized string for a remat var    */
1794 /*-----------------------------------------------------------------*/
1795 static char *
1796 rematStr (symbol * sym)
1797 {
1798   char *s = buffer;
1799   iCode *ic = sym->rematiCode;
1800
1801   *s = 0;
1802
1803   while (1)
1804     {
1805
1806       /* if plus or minus print the right hand side */
1807       if (ic->op == '+' || ic->op == '-')
1808         {
1809           SNPRINTF (s, sizeof(buffer) - strlen(buffer),
1810                     "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)),
1811                     ic->op);
1812           s += strlen (s);
1813           ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
1814           continue;
1815         }
1816
1817       /* cast then continue */
1818       if (IS_CAST_ICODE(ic)) {
1819           ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
1820           continue;
1821       }
1822       /* we reached the end */
1823       SNPRINTF (s, sizeof(buffer) - strlen(buffer),
1824                 "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
1825       break;
1826     }
1827
1828   return buffer;
1829 }
1830
1831 /*-----------------------------------------------------------------*/
1832 /* regTypeNum - computes the type & number of registers required   */
1833 /*-----------------------------------------------------------------*/
1834 static void
1835 regTypeNum ()
1836 {
1837   symbol *sym;
1838   int k;
1839   iCode *ic;
1840
1841   /* for each live range do */
1842   for (sym = hTabFirstItem (liveRanges, &k); sym;
1843        sym = hTabNextItem (liveRanges, &k))
1844     {
1845
1846       /* if used zero times then no registers needed */
1847       if ((sym->liveTo - sym->liveFrom) == 0)
1848         continue;
1849
1850
1851       /* if the live range is a temporary */
1852       if (sym->isitmp)
1853         {
1854
1855           /* if the type is marked as a conditional */
1856           if (sym->regType == REG_CND)
1857             continue;
1858
1859           /* if used in return only then we don't
1860              need registers */
1861           if (sym->ruonly || sym->accuse)
1862             {
1863               if (IS_AGGREGATE (sym->type) || sym->isptr)
1864                 sym->type = aggrToPtr (sym->type, FALSE);
1865               continue;
1866             }
1867
1868           /* if the symbol has only one definition &
1869              that definition is a get_pointer */
1870           if (bitVectnBitsOn (sym->defs) == 1 &&
1871               (ic = hTabItemWithKey (iCodehTab,
1872                                      bitVectFirstBit (sym->defs))) &&
1873               POINTER_GET (ic) &&
1874               !IS_BITVAR (sym->etype) &&
1875               (aggrToPtrDclType (operandType (IC_LEFT (ic)), FALSE) == POINTER))
1876             {
1877
1878               if (ptrPseudoSymSafe (sym, ic))
1879                 {
1880                   ptrPseudoSymConvert (sym, ic, rematStr (OP_SYMBOL (IC_LEFT (ic))));
1881                   continue;
1882                 }
1883
1884               /* if in data space or idata space then try to
1885                  allocate pointer register */
1886
1887             }
1888
1889           /* if not then we require registers */
1890           sym->nRegs = ((IS_AGGREGATE (sym->type) || sym->isptr) ?
1891                         getSize (sym->type = aggrToPtr (sym->type, FALSE)) :
1892                         getSize (sym->type));
1893
1894           if (sym->nRegs > 4)
1895             {
1896               fprintf (stderr, "allocated more than 4 or 0 registers for type ");
1897               printTypeChain (sym->type, stderr);
1898               fprintf (stderr, "\n");
1899             }
1900
1901           /* determine the type of register required */
1902           if (sym->nRegs == 1 &&
1903               IS_PTR (sym->type) &&
1904               sym->uptr)
1905             sym->regType = REG_PTR;
1906           else
1907             sym->regType = REG_GPR;
1908
1909         }
1910       else
1911         /* for the first run we don't provide */
1912         /* registers for true symbols we will */
1913         /* see how things go                  */
1914         sym->nRegs = 0;
1915     }
1916
1917 }
1918
1919 /*-----------------------------------------------------------------*/
1920 /* freeAllRegs - mark all registers as free                        */
1921 /*-----------------------------------------------------------------*/
1922 static void
1923 freeAllRegs ()
1924 {
1925   int i;
1926
1927   for (i = 0; i < ds390_nRegs; i++)
1928     regs390[i].isFree = 1;
1929 }
1930
1931 /*-----------------------------------------------------------------*/
1932 /* deallocStackSpil - this will set the stack pointer back         */
1933 /*-----------------------------------------------------------------*/
1934 static
1935 DEFSETFUNC (deallocStackSpil)
1936 {
1937   symbol *sym = item;
1938
1939   deallocLocal (sym);
1940   return 0;
1941 }
1942
1943 /*-----------------------------------------------------------------*/
1944 /* farSpacePackable - returns the packable icode for far variables */
1945 /*-----------------------------------------------------------------*/
1946 static iCode *
1947 farSpacePackable (iCode * ic)
1948 {
1949   iCode *dic;
1950
1951   /* go thru till we find a definition for the
1952      symbol on the right */
1953   for (dic = ic->prev; dic; dic = dic->prev)
1954     {
1955       /* if the definition is a call then no */
1956       if ((dic->op == CALL || dic->op == PCALL) &&
1957           IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
1958         {
1959           return NULL;
1960         }
1961
1962       /* if shift by unknown amount then not */
1963       if ((dic->op == LEFT_OP || dic->op == RIGHT_OP) &&
1964           IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
1965         return NULL;
1966
1967       /* if pointer get and size > 1 */
1968       if (POINTER_GET (dic) &&
1969           getSize (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)) > 1)
1970         return NULL;
1971
1972       if (POINTER_SET (dic) &&
1973           getSize (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)) > 1)
1974         return NULL;
1975
1976       /* if any tree is a true symbol in far space */
1977       if (IC_RESULT (dic) &&
1978           IS_TRUE_SYMOP (IC_RESULT (dic)) &&
1979           isOperandInFarSpace (IC_RESULT (dic)))
1980         return NULL;
1981
1982       if (IC_RIGHT (dic) &&
1983           IS_TRUE_SYMOP (IC_RIGHT (dic)) &&
1984           isOperandInFarSpace (IC_RIGHT (dic)) &&
1985           !isOperandEqual (IC_RIGHT (dic), IC_RESULT (ic)))
1986         return NULL;
1987
1988       if (IC_LEFT (dic) &&
1989           IS_TRUE_SYMOP (IC_LEFT (dic)) &&
1990           isOperandInFarSpace (IC_LEFT (dic)) &&
1991           !isOperandEqual (IC_LEFT (dic), IC_RESULT (ic)))
1992         return NULL;
1993
1994       if (isOperandEqual (IC_RIGHT (ic), IC_RESULT (dic)))
1995         {
1996           if ((dic->op == LEFT_OP ||
1997                dic->op == RIGHT_OP ||
1998                dic->op == '-') &&
1999               IS_OP_LITERAL (IC_RIGHT (dic)))
2000             return NULL;
2001           else
2002             return dic;
2003         }
2004     }
2005
2006   return NULL;
2007 }
2008
2009 /*-----------------------------------------------------------------*/
2010 /* packRegsForAssign - register reduction for assignment           */
2011 /*-----------------------------------------------------------------*/
2012 static int
2013 packRegsForAssign (iCode * ic, eBBlock * ebp)
2014 {
2015   iCode *dic, *sic;
2016
2017   if (!IS_ITEMP (IC_RIGHT (ic)) ||
2018       OP_SYMBOL (IC_RIGHT (ic))->isind ||
2019       OP_LIVETO (IC_RIGHT (ic)) > ic->seq)
2020     {
2021       return 0;
2022     }
2023
2024   /* if the true symbol is defined in far space or on stack
2025      then we should not since this will increase register pressure */
2026 #if 0
2027   if (isOperandInFarSpace (IC_RESULT (ic)))
2028     {
2029       if ((dic = farSpacePackable (ic)))
2030         goto pack;
2031       else
2032         return 0;
2033     }
2034 #else
2035   if (isOperandInFarSpace(IC_RESULT(ic)) && !farSpacePackable(ic)) {
2036     return 0;
2037   }
2038 #endif
2039
2040   /* find the definition of iTempNN scanning backwards if we find a
2041      a use of the true symbol in before we find the definition then
2042      we cannot */
2043   for (dic = ic->prev; dic; dic = dic->prev)
2044     {
2045       /* if there is a function call then don't pack it */
2046       if ((dic->op == CALL || dic->op == PCALL))
2047         {
2048           dic = NULL;
2049           break;
2050         }
2051
2052       if (SKIP_IC2 (dic))
2053         continue;
2054
2055       if (IS_TRUE_SYMOP (IC_RESULT (dic)) &&
2056           IS_OP_VOLATILE (IC_RESULT (dic)))
2057         {
2058           dic = NULL;
2059           break;
2060         }
2061
2062       if (IS_SYMOP (IC_RESULT (dic)) &&
2063           IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
2064         {
2065           if (POINTER_SET (dic))
2066             dic = NULL;
2067
2068           break;
2069         }
2070
2071       if (IS_SYMOP (IC_RIGHT (dic)) &&
2072           (IC_RIGHT (dic)->key == IC_RESULT (ic)->key ||
2073            IC_RIGHT (dic)->key == IC_RIGHT (ic)->key))
2074         {
2075           dic = NULL;
2076           break;
2077         }
2078
2079       if (IS_SYMOP (IC_LEFT (dic)) &&
2080           (IC_LEFT (dic)->key == IC_RESULT (ic)->key ||
2081            IC_LEFT (dic)->key == IC_RIGHT (ic)->key))
2082         {
2083           dic = NULL;
2084           break;
2085         }
2086
2087       if (POINTER_SET (dic) &&
2088           IC_RESULT (dic)->key == IC_RESULT (ic)->key)
2089         {
2090           dic = NULL;
2091           break;
2092         }
2093     }
2094
2095   if (!dic)
2096     return 0;                   /* did not find */
2097
2098   /* if the result is on stack or iaccess then it must be
2099      the same atleast one of the operands */
2100   if (OP_SYMBOL (IC_RESULT (ic))->onStack ||
2101       OP_SYMBOL (IC_RESULT (ic))->iaccess)
2102     {
2103
2104       /* the operation has only one symbol
2105          operator then we can pack */
2106       if ((IC_LEFT (dic) && !IS_SYMOP (IC_LEFT (dic))) ||
2107           (IC_RIGHT (dic) && !IS_SYMOP (IC_RIGHT (dic))))
2108         goto pack;
2109
2110       if (!((IC_LEFT (dic) &&
2111              IC_RESULT (ic)->key == IC_LEFT (dic)->key) ||
2112             (IC_RIGHT (dic) &&
2113              IC_RESULT (ic)->key == IC_RIGHT (dic)->key)))
2114         return 0;
2115     }
2116 pack:
2117   /* found the definition */
2118   /* replace the result with the result of */
2119   /* this assignment and remove this assignment */
2120   bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
2121
2122   IC_RESULT (dic) = IC_RESULT (ic);
2123
2124   if (IS_ITEMP (IC_RESULT (dic)) && OP_SYMBOL (IC_RESULT (dic))->liveFrom > dic->seq)
2125     {
2126       OP_SYMBOL (IC_RESULT (dic))->liveFrom = dic->seq;
2127     }
2128   /* delete from liverange table also
2129      delete from all the points inbetween and the new
2130      one */
2131   for (sic = dic; sic != ic; sic = sic->next)
2132     {
2133       bitVectUnSetBit (sic->rlive, IC_RESULT (ic)->key);
2134       if (IS_ITEMP (IC_RESULT (dic)))
2135         bitVectSetBit (sic->rlive, IC_RESULT (dic)->key);
2136     }
2137
2138   remiCodeFromeBBlock (ebp, ic);
2139   bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
2140   hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
2141   OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
2142   return 1;
2143 }
2144
2145 /*------------------------------------------------------------------*/
2146 /* findAssignToSym : scanning backwards looks for first assig found */
2147 /*------------------------------------------------------------------*/
2148 static iCode *
2149 findAssignToSym (operand * op, iCode * ic)
2150 {
2151   iCode *dic;
2152
2153   /* This routine is used to find sequences like
2154      iTempAA = FOO;
2155      ...;  (intervening ops don't use iTempAA or modify FOO)
2156      blah = blah + iTempAA;
2157
2158      and eliminate the use of iTempAA, freeing up its register for
2159      other uses.
2160   */
2161
2162   for (dic = ic->prev; dic; dic = dic->prev)
2163     {
2164
2165       /* if definition by assignment */
2166       if (dic->op == '=' &&
2167           !POINTER_SET (dic) &&
2168           IC_RESULT (dic)->key == op->key
2169 /*          &&  IS_TRUE_SYMOP(IC_RIGHT(dic)) */
2170         )
2171         {
2172
2173           /* we are interested only if defined in far space */
2174           /* or in stack space in case of + & - */
2175
2176           /* if assigned to a non-symbol then return
2177              FALSE */
2178           if (!IS_SYMOP (IC_RIGHT (dic)))
2179             return NULL;
2180
2181           /* if the symbol is in far space then
2182              we should not */
2183           if (isOperandInFarSpace (IC_RIGHT (dic)))
2184             return NULL;
2185
2186           /* for + & - operations make sure that
2187              if it is on the stack it is the same
2188              as one of the three operands */
2189           if ((ic->op == '+' || ic->op == '-') &&
2190               OP_SYMBOL (IC_RIGHT (dic))->onStack)
2191             {
2192
2193               if (IC_RESULT (ic)->key != IC_RIGHT (dic)->key &&
2194                   IC_LEFT (ic)->key != IC_RIGHT (dic)->key &&
2195                   IC_RIGHT (ic)->key != IC_RIGHT (dic)->key)
2196                 return NULL;
2197             }
2198
2199           break;
2200
2201         }
2202
2203       /* if we find an usage then we cannot delete it */
2204       if (IC_LEFT (dic) && IC_LEFT (dic)->key == op->key)
2205         return NULL;
2206
2207       if (IC_RIGHT (dic) && IC_RIGHT (dic)->key == op->key)
2208         return NULL;
2209
2210       if (POINTER_SET (dic) && IC_RESULT (dic)->key == op->key)
2211         return NULL;
2212     }
2213
2214   /* now make sure that the right side of dic
2215      is not defined between ic & dic */
2216   if (dic)
2217     {
2218       iCode *sic = dic->next;
2219
2220       for (; sic != ic; sic = sic->next)
2221         if (IC_RESULT (sic) &&
2222             IC_RESULT (sic)->key == IC_RIGHT (dic)->key)
2223           return NULL;
2224     }
2225
2226   return dic;
2227
2228
2229 }
2230
2231 /*-----------------------------------------------------------------*/
2232 /* packRegsForSupport :- reduce some registers for support calls   */
2233 /*-----------------------------------------------------------------*/
2234 static int
2235 packRegsForSupport (iCode * ic, eBBlock * ebp)
2236 {
2237   int change = 0;
2238
2239   /* for the left & right operand :- look to see if the
2240      left was assigned a true symbol in far space in that
2241      case replace them */
2242   if (IS_ITEMP (IC_LEFT (ic)) &&
2243       OP_SYMBOL (IC_LEFT (ic))->liveTo <= ic->seq)
2244     {
2245       iCode *dic = findAssignToSym (IC_LEFT (ic), ic);
2246       iCode *sic;
2247
2248       if (!dic)
2249         goto right;
2250
2251       /* found it we need to remove it from the
2252          block */
2253       for (sic = dic; sic != ic; sic = sic->next) {
2254         bitVectUnSetBit (sic->rlive, IC_LEFT (ic)->key);
2255         sic->rlive = bitVectSetBit (sic->rlive, IC_RIGHT (dic)->key);
2256       }
2257
2258       wassert(IS_SYMOP(IC_LEFT (ic)));
2259       wassert(IS_SYMOP(IC_RIGHT (dic)));
2260       IC_LEFT (ic)->operand.symOperand =
2261         IC_RIGHT (dic)->operand.symOperand;
2262       OP_SYMBOL(IC_LEFT(ic))->liveTo = ic->seq;
2263       IC_LEFT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
2264       bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
2265       remiCodeFromeBBlock (ebp, dic);
2266       hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
2267       change++;
2268     }
2269
2270   /* do the same for the right operand */
2271 right:
2272   if (!change &&
2273       IS_ITEMP (IC_RIGHT (ic)) &&
2274       OP_SYMBOL (IC_RIGHT (ic))->liveTo <= ic->seq)
2275     {
2276       iCode *dic = findAssignToSym (IC_RIGHT (ic), ic);
2277       iCode *sic;
2278
2279       if (!dic)
2280         return change;
2281
2282       /* if this is a subtraction & the result
2283          is a true symbol in far space then don't pack */
2284       if (ic->op == '-' && IS_TRUE_SYMOP (IC_RESULT (dic)))
2285         {
2286           sym_link *etype = getSpec (operandType (IC_RESULT (dic)));
2287           if (IN_FARSPACE (SPEC_OCLS (etype)))
2288             return change;
2289         }
2290       /* found it we need to remove it from the
2291          block */
2292       for (sic = dic; sic != ic; sic = sic->next) {
2293         bitVectUnSetBit (sic->rlive, IC_RIGHT (ic)->key);
2294         sic->rlive = bitVectSetBit (sic->rlive, IC_RIGHT (dic)->key);
2295       }
2296
2297       wassert(IS_SYMOP(IC_RIGHT (ic)));
2298       wassert(IS_SYMOP(IC_RIGHT (dic)));
2299       IC_RIGHT (ic)->operand.symOperand =
2300         IC_RIGHT (dic)->operand.symOperand;
2301       IC_RIGHT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
2302       OP_SYMBOL(IC_RIGHT(ic))->liveTo = ic->seq;
2303       remiCodeFromeBBlock (ebp, dic);
2304       bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
2305       hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
2306       change++;
2307     }
2308
2309   return change;
2310 }
2311
2312 #define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
2313
2314
2315 /*-----------------------------------------------------------------*/
2316 /* packRegsDPTRnuse - color live ranges that can go into extra DPTRS */
2317 /*-----------------------------------------------------------------*/
2318 static int packRegsDPTRnuse( operand *op , unsigned dptr)
2319 {
2320     int i,key;
2321     iCode *ic;
2322
2323     if (!IS_SYMOP(op) || !IS_ITEMP(op)) return 0;
2324     if (OP_SYMBOL(op)->remat || OP_SYMBOL(op)->ruonly || OP_SYMBOL(op)->dptr)
2325         return 0;
2326
2327     /* first check if any overlapping liverange has already been
2328        assigned to this DPTR */
2329     if (OP_SYMBOL(op)->clashes) {
2330         for (i = 0 ; i < OP_SYMBOL(op)->clashes->size ; i++ ) {
2331             symbol *sym;
2332             if (bitVectBitValue(OP_SYMBOL(op)->clashes,i)) {
2333                 sym = hTabItemWithKey(liveRanges,i);
2334                 if (sym->dptr == dptr) return 0;
2335             }
2336         }
2337     }
2338
2339     /* future for more dptrs */
2340     if (dptr > 1) {
2341         OP_SYMBOL(op)->dptr = dptr;
2342         return 1;
2343     }
2344
2345     /* DPTR1 is special since it is also used as a scratch by the backend .
2346        so we walk thru the entire live range of this operand and make sure
2347        DPTR1 will not be used by the backed . The logic here is to find out if
2348        more than one operand in an icode is in far space then we give up : we
2349        don't keep it live across functions for now
2350     */
2351
2352     ic = hTabFirstItemWK(iCodeSeqhTab,OP_SYMBOL(op)->liveFrom);
2353     for (; ic && ic->seq <= OP_SYMBOL(op)->liveTo;
2354          ic = hTabNextItem(iCodeSeqhTab,&key)) {
2355         int nfs =0;
2356
2357         if (ic->op == CALL || ic->op == PCALL) return 0;
2358
2359         /* single operand icode are ok */
2360         if (ic->op == IFX || ic->op == IPUSH)
2361             continue ;
2362
2363         if (ic->op == SEND ) {
2364             if (ic->argreg != 1 ) return 0;
2365             else continue ;
2366         }
2367         /* two special cases first */
2368         if (POINTER_GET(ic) && !isOperandEqual(IC_LEFT(ic),op)  && /* pointer get */
2369             !OP_SYMBOL(IC_LEFT(ic))->ruonly                     && /* with result in far space */
2370             (isOperandInFarSpace(IC_RESULT(ic)) &&
2371              !isOperandInReg(IC_RESULT(ic)))) {
2372             return 0;
2373         }
2374
2375         if (POINTER_SET(ic) && !isOperandEqual(IC_RESULT(ic),op)        && /* pointer set */
2376             !OP_SYMBOL(IC_RESULT(ic))->ruonly                           && /* with right in far space */
2377             (isOperandInFarSpace(IC_RIGHT(ic)) &&
2378              !isOperandInReg(IC_RIGHT(ic)))) {
2379             return 0;
2380         }
2381
2382         if (IC_RESULT(ic) && IS_SYMOP(IC_RESULT(ic))    && /* if symbol operand */
2383             !isOperandEqual(IC_RESULT(ic),op)           && /* not the same as this */
2384             ((isOperandInFarSpace(IC_RESULT(ic)) ||        /* in farspace or */
2385               OP_SYMBOL(IC_RESULT(ic))->onStack)        && /* on the stack   */
2386              !isOperandInReg(IC_RESULT(ic)))) {            /* and not in register */
2387             nfs++;
2388         }
2389         /* same for left */
2390         if (IC_LEFT(ic) && IS_SYMOP(IC_LEFT(ic))        && /* if symbol operand */
2391             !isOperandEqual(IC_LEFT(ic),op)             && /* not the same as this */
2392             ((isOperandInFarSpace(IC_LEFT(ic)) ||          /* in farspace or */
2393               OP_SYMBOL(IC_LEFT(ic))->onStack)          && /* on the stack   */
2394              !isOperandInReg(IC_LEFT(ic)))) {              /* and not in register */
2395             nfs++;
2396         }
2397         /* same for right */
2398         if (IC_RIGHT(ic) && IS_SYMOP(IC_RIGHT(ic))      && /* if symbol operand */
2399             !isOperandEqual(IC_RIGHT(ic),op)            && /* not the same as this */
2400             ((isOperandInFarSpace(IC_RIGHT(ic)) ||         /* in farspace or */
2401               OP_SYMBOL(IC_RIGHT(ic))->onStack)         && /* on the stack   */
2402              !isOperandInReg(IC_RIGHT(ic)))) {             /* and not in register */
2403             nfs++;
2404         }
2405
2406         // Check that no other ops in this range have been assigned to dptr1.
2407         // I don't understand why this is not caught by the first check, above.
2408         // But it isn't always, see bug 769624.
2409         if (IC_RESULT(ic) && IS_SYMOP(IC_RESULT(ic)) &&
2410             (OP_SYMBOL(IC_RESULT(ic))->dptr == 1))
2411         {
2412             //fprintf(stderr, "dptr1 already in use in live range #1\n");
2413             return 0;
2414         }
2415
2416         if (IC_LEFT(ic) && IS_SYMOP(IC_LEFT(ic)) &&
2417             (OP_SYMBOL(IC_LEFT(ic))->dptr == 1))
2418         {
2419             //fprintf(stderr, "dptr1 already in use in live range # 2\n");
2420             return 0;
2421         }
2422
2423         if (IC_RIGHT(ic) && IS_SYMOP(IC_RIGHT(ic)) &&
2424             (OP_SYMBOL(IC_RIGHT(ic))->dptr == 1))
2425         {
2426             //fprintf(stderr, "dptr1 already in use in live range # 3\n");
2427             return 0;
2428         }
2429
2430         if (nfs && IC_RESULT(ic) && IS_SYMOP(IC_RESULT(ic)) &&
2431             OP_SYMBOL(IC_RESULT(ic))->ruonly) return 0;
2432
2433         if (nfs > 1) return 0;
2434     }
2435     OP_SYMBOL(op)->dptr = dptr;
2436     return 1;
2437 }
2438
2439 /*-----------------------------------------------------------------*/
2440 /* packRegsDPTRuse : - will reduce some registers for single Use */
2441 /*-----------------------------------------------------------------*/
2442 static iCode *
2443 packRegsDPTRuse (operand * op)
2444 {
2445     /* go thru entire liveRange of this variable & check for
2446        other possible usage of DPTR , if we don't find it the
2447        assign this to DPTR (ruonly)
2448     */
2449     int i, key;
2450     symbol *sym;
2451     iCode *ic, *dic;
2452     sym_link *type, *etype;
2453
2454     if (!IS_SYMOP(op) || !IS_ITEMP(op)) return NULL;
2455     if (OP_SYMBOL(op)->remat || OP_SYMBOL(op)->ruonly) return NULL;
2456
2457     /* first check if any overlapping liverange has already been
2458        assigned to DPTR */
2459     if (OP_SYMBOL(op)->clashes) {
2460         for (i = 0 ; i < OP_SYMBOL(op)->clashes->size ; i++ ) {
2461             if (bitVectBitValue(OP_SYMBOL(op)->clashes,i)) {
2462                 sym = hTabItemWithKey(liveRanges,i);
2463                 if (sym->ruonly) return NULL ;
2464             }
2465         }
2466     }
2467
2468     /* no then go thru this guys live range */
2469     dic = ic = hTabFirstItemWK(iCodeSeqhTab,OP_SYMBOL(op)->liveFrom);
2470     for (; ic && ic->seq <= OP_SYMBOL(op)->liveTo;
2471          ic = hTabNextItem(iCodeSeqhTab,&key)) {
2472
2473         if (SKIP_IC3(ic)) continue;
2474
2475         /* if PCALL cannot be sure give up */
2476         if (ic->op == PCALL) return NULL;
2477
2478         /* if SEND & not the first parameter then giveup */
2479         if (ic->op == SEND && ic->argreg != 1 &&
2480             ((isOperandInFarSpace(IC_LEFT(ic))  && !isOperandInReg(IC_LEFT(ic))) ||
2481              isOperandEqual(op,IC_LEFT(ic)))) return NULL;
2482
2483         /* if CALL then make sure it is VOID || return value not used
2484            or the return value is assigned to this one */
2485         if (ic->op == CALL) {
2486             if (OP_SYMBOL(IC_RESULT(ic))->liveTo ==
2487                 OP_SYMBOL(IC_RESULT(ic))->liveFrom) continue ;
2488             etype = getSpec(type = operandType(IC_RESULT(ic)));
2489             if (getSize(type) == 0 || isOperandEqual(op,IC_RESULT(ic)))
2490                 continue ;
2491             return NULL ;
2492         }
2493
2494         /* special case of add with a [remat] */
2495         if (ic->op == '+' &&
2496             OP_SYMBOL(IC_LEFT(ic))->remat &&
2497             (isOperandInFarSpace(IC_RIGHT(ic)) &&
2498              !isOperandInReg(IC_RIGHT(ic)))) return NULL ;
2499
2500         /* special cases  */
2501         /* pointerGet */
2502         if (POINTER_GET(ic) && !isOperandEqual(IC_LEFT(ic),op) &&
2503             getSize(operandType(IC_LEFT(ic))) > 1 ) return NULL ;
2504
2505         /* pointerSet */
2506         if (POINTER_SET(ic) && !isOperandEqual(IC_RESULT(ic),op) &&
2507             getSize(operandType(IC_RESULT(ic))) > 1 ) return NULL;
2508
2509         /* conditionals can destroy 'b' - make sure B wont
2510            be used in this one*/
2511         if ((IS_CONDITIONAL(ic) || ic->op == '*' || ic->op == '/'  ||
2512              ic->op == LEFT_OP || ic->op == RIGHT_OP ) &&
2513             getSize(operandType(op)) > 3) return NULL;
2514
2515         /* if this is a cast to a bigger type */
2516         if (ic->op==CAST) {
2517           if (!IS_PTR(OP_SYM_TYPE(IC_RESULT(ic))) &&
2518               getSize(OP_SYM_TYPE(IC_RESULT(ic))) >
2519               getSize(OP_SYM_TYPE(IC_RIGHT(ic)))) {
2520             return 0;
2521           }
2522         }
2523
2524         /* general case */
2525         if (IC_RESULT(ic) && IS_SYMOP(IC_RESULT(ic)) &&
2526             !isOperandEqual(IC_RESULT(ic),op) &&
2527             ( ( ( isOperandInFarSpace(IC_RESULT(ic)) || OP_SYMBOL(IC_RESULT(ic))->onStack) &&
2528                 !isOperandInReg(IC_RESULT(ic))) ||
2529              OP_SYMBOL(IC_RESULT(ic))->ruonly)) return NULL;
2530
2531         if (IC_RIGHT(ic) && IS_SYMOP(IC_RIGHT(ic)) &&
2532             !isOperandEqual(IC_RIGHT(ic),op) &&
2533             (OP_SYMBOL(IC_RIGHT(ic))->liveTo >= ic->seq ||
2534              IS_TRUE_SYMOP(IC_RIGHT(ic))               ||
2535              OP_SYMBOL(IC_RIGHT(ic))->ruonly) &&
2536             ( ( isOperandInFarSpace(IC_RIGHT(ic)) || OP_SYMBOL(IC_RIGHT(ic))->onStack) &&
2537                 !isOperandInReg(IC_RIGHT(ic))) ) return NULL;
2538
2539         if (IC_LEFT(ic) && IS_SYMOP(IC_LEFT(ic)) &&
2540             !isOperandEqual(IC_LEFT(ic),op) &&
2541             (OP_SYMBOL(IC_LEFT(ic))->liveTo >= ic->seq ||
2542              IS_TRUE_SYMOP(IC_LEFT(ic))               ||
2543              OP_SYMBOL(IC_LEFT(ic))->ruonly) &&
2544             ( ( isOperandInFarSpace(IC_LEFT(ic)) || OP_SYMBOL(IC_LEFT(ic))->onStack) &&
2545                 !isOperandInReg(IC_LEFT(ic))) ) return NULL;
2546
2547         if (IC_LEFT(ic) && IC_RIGHT(ic) &&
2548             IS_ITEMP(IC_LEFT(ic)) && IS_ITEMP(IC_RIGHT(ic)) &&
2549             (isOperandInFarSpace(IC_LEFT(ic)) && !isOperandInReg(IC_LEFT(ic))) &&
2550             (isOperandInFarSpace(IC_RIGHT(ic)) && !isOperandInReg(IC_RIGHT(ic))))
2551             return NULL;
2552     }
2553     OP_SYMBOL(op)->ruonly = 1;
2554     if (OP_SYMBOL(op)->usl.spillLoc) {
2555         if (OP_SYMBOL(op)->spillA)
2556             OP_SYMBOL(op)->usl.spillLoc->allocreq--;
2557         OP_SYMBOL(op)->usl.spillLoc = NULL;
2558     }
2559     return dic;
2560 }
2561
2562 /*-----------------------------------------------------------------*/
2563 /* isBitwiseOptimizable - requirements of JEAN LOUIS VERN          */
2564 /*-----------------------------------------------------------------*/
2565 static bool
2566 isBitwiseOptimizable (iCode * ic)
2567 {
2568   sym_link *ltype = getSpec (operandType (IC_LEFT (ic)));
2569   sym_link *rtype = getSpec (operandType (IC_RIGHT (ic)));
2570
2571   /* bitwise operations are considered optimizable
2572      under the following conditions (Jean-Louis VERN)
2573
2574      x & lit
2575      bit & bit
2576      bit & x
2577      bit ^ bit
2578      bit ^ x
2579      x   ^ lit
2580      x   | lit
2581      bit | bit
2582      bit | x
2583    */
2584   if (IS_LITERAL (rtype) ||
2585       (IS_BITVAR (ltype) && IN_BITSPACE (SPEC_OCLS (ltype))))
2586     return TRUE;
2587   else
2588     return FALSE;
2589 }
2590
2591 /*-----------------------------------------------------------------*/
2592 /* packRegsForAccUse - pack registers for acc use                  */
2593 /*-----------------------------------------------------------------*/
2594 static void
2595 packRegsForAccUse (iCode * ic)
2596 {
2597   iCode *uic;
2598
2599   /* if this is an aggregate, e.g. a one byte char array */
2600   if (IS_AGGREGATE(operandType(IC_RESULT(ic)))) {
2601     return;
2602   }
2603
2604   /* if we are calling a reentrant function that has stack parameters */
2605   if (ic->op == CALL &&
2606        IFFUNC_ISREENT(operandType(IC_LEFT(ic))) &&
2607        FUNC_HASSTACKPARM(operandType(IC_LEFT(ic))))
2608       return;
2609
2610   if (ic->op == PCALL &&
2611        IFFUNC_ISREENT(operandType(IC_LEFT(ic))->next) &&
2612        FUNC_HASSTACKPARM(operandType(IC_LEFT(ic))->next))
2613       return;
2614
2615   /* if + or - then it has to be one byte result */
2616   if ((ic->op == '+' || ic->op == '-')
2617       && getSize (operandType (IC_RESULT (ic))) > 1)
2618     return;
2619
2620   /* if shift operation make sure right side is not a literal */
2621   if (ic->op == RIGHT_OP &&
2622       (isOperandLiteral (IC_RIGHT (ic)) ||
2623        getSize (operandType (IC_RESULT (ic))) > 1))
2624     return;
2625
2626   if (ic->op == LEFT_OP &&
2627       (isOperandLiteral (IC_RIGHT (ic)) ||
2628        getSize (operandType (IC_RESULT (ic))) > 1))
2629     return;
2630
2631   if (IS_BITWISE_OP (ic) &&
2632       getSize (operandType (IC_RESULT (ic))) > 1)
2633     return;
2634
2635
2636   /* has only one definition */
2637   if (bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) > 1)
2638     return;
2639
2640   /* has only one use */
2641   if (bitVectnBitsOn (OP_USES (IC_RESULT (ic))) > 1)
2642     return;
2643
2644   /* and the usage immediately follows this iCode */
2645   if (!(uic = hTabItemWithKey (iCodehTab,
2646                                bitVectFirstBit (OP_USES (IC_RESULT (ic))))))
2647     return;
2648
2649   if (ic->next != uic)
2650     return;
2651
2652   /* if it is a conditional branch then we definitely can */
2653   if (uic->op == IFX)
2654     goto accuse;
2655
2656   if (uic->op == JUMPTABLE)
2657     return;
2658
2659   /* if the usage is not is an assignment
2660      or an arithmetic / bitwise / shift operation then not */
2661   if (POINTER_SET (uic) &&
2662       getSize (aggrToPtr (operandType (IC_RESULT (uic)), FALSE)) > 1)
2663     return;
2664
2665   if (uic->op != '=' &&
2666       !IS_ARITHMETIC_OP (uic) &&
2667       !IS_BITWISE_OP (uic) &&
2668       uic->op != LEFT_OP &&
2669       uic->op != RIGHT_OP)
2670     return;
2671
2672   /* if used in ^ operation then make sure right is not a
2673      literl */
2674   if (uic->op == '^' && isOperandLiteral (IC_RIGHT (uic)))
2675     return;
2676
2677   /* if shift operation make sure right side is not a literal */
2678   if (uic->op == RIGHT_OP &&
2679       (isOperandLiteral (IC_RIGHT (uic)) ||
2680        getSize (operandType (IC_RESULT (uic))) > 1))
2681     return;
2682
2683   if (uic->op == LEFT_OP &&
2684       (isOperandLiteral (IC_RIGHT (uic)) ||
2685        getSize (operandType (IC_RESULT (uic))) > 1))
2686     return;
2687
2688   /* make sure that the result of this icode is not on the
2689      stack, since acc is used to compute stack offset */
2690   if (isOperandOnStack(IC_RESULT(uic)))
2691     return;
2692
2693   /* if either one of them in far space then we cannot */
2694   if ((IS_TRUE_SYMOP (IC_LEFT (uic)) &&
2695        isOperandInFarSpace (IC_LEFT (uic))) ||
2696       (IS_TRUE_SYMOP (IC_RIGHT (uic)) &&
2697        isOperandInFarSpace (IC_RIGHT (uic))))
2698     return;
2699
2700   /* if the usage has only one operand then we can */
2701   if (IC_LEFT (uic) == NULL ||
2702       IC_RIGHT (uic) == NULL)
2703     goto accuse;
2704
2705   /* make sure this is on the left side if not
2706      a '+' since '+' is commutative */
2707   if (ic->op != '+' &&
2708       IC_LEFT (uic)->key != IC_RESULT (ic)->key)
2709     return;
2710
2711   /* if the other one is not on stack then we can */
2712   if (IC_LEFT (uic)->key == IC_RESULT (ic)->key &&
2713       (IS_ITEMP (IC_RIGHT (uic)) ||
2714        (IS_TRUE_SYMOP (IC_RIGHT (uic)) &&
2715         !OP_SYMBOL (IC_RIGHT (uic))->onStack)))
2716     goto accuse;
2717
2718   if (IC_RIGHT (uic)->key == IC_RESULT (ic)->key &&
2719       (IS_ITEMP (IC_LEFT (uic)) ||
2720        (IS_TRUE_SYMOP (IC_LEFT (uic)) &&
2721         !OP_SYMBOL (IC_LEFT (uic))->onStack)))
2722     goto accuse;
2723
2724   return;
2725
2726 accuse:
2727   OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
2728
2729 }
2730
2731 /*-----------------------------------------------------------------*/
2732 /* packForPush - hueristics to reduce iCode for pushing            */
2733 /*-----------------------------------------------------------------*/
2734 static void
2735 packForPush (iCode * ic, eBBlock * ebp)
2736 {
2737   iCode *dic, *lic;
2738   bitVect *dbv;
2739
2740   if ((ic->op != IPUSH && ic->op != SEND) || !IS_ITEMP (IC_LEFT (ic)))
2741     return;
2742
2743   /* must have only definition & one usage */
2744   if (bitVectnBitsOn (OP_DEFS (IC_LEFT (ic))) != 1 ||
2745       bitVectnBitsOn (OP_USES (IC_LEFT (ic))) != 1)
2746     return;
2747
2748   /* find the definition */
2749   if (!(dic = hTabItemWithKey (iCodehTab,
2750                                bitVectFirstBit (OP_DEFS (IC_LEFT (ic))))))
2751     return;
2752
2753   if (dic->op != '=' || POINTER_SET (dic))
2754     return;
2755
2756   if (dic->eBBlockNum != ic->eBBlockNum) return ;
2757
2758   /* make sure the right side does not have any definitions
2759      inbetween */
2760   dbv = OP_DEFS(IC_RIGHT(dic));
2761   for (lic = ic; lic && lic != dic ; lic = lic->prev) {
2762           if (bitVectBitValue(dbv,lic->key)) return ;
2763   }
2764   /* make sure they have the same type */
2765   if (IS_SPEC(operandType(IC_LEFT(ic))))
2766   {
2767     sym_link *itype=operandType(IC_LEFT(ic));
2768     sym_link *ditype=operandType(IC_RIGHT(dic));
2769
2770     if (SPEC_USIGN(itype)!=SPEC_USIGN(ditype) ||
2771         SPEC_LONG(itype)!=SPEC_LONG(ditype))
2772       return;
2773   }
2774   /* extend the live range of replaced operand if needed */
2775   if (OP_SYMBOL(IC_RIGHT(dic))->liveTo < OP_SYMBOL(IC_LEFT(ic))->liveTo) {
2776           OP_SYMBOL(IC_RIGHT(dic))->liveTo = OP_SYMBOL(IC_LEFT(ic))->liveTo;
2777           OP_SYMBOL(IC_RIGHT(dic))->clashes =
2778               bitVectUnion(OP_SYMBOL(IC_RIGHT(dic))->clashes,
2779                            OP_SYMBOL(IC_LEFT(ic))->clashes);
2780   }
2781   for (lic = ic; lic && lic != dic; lic = lic->prev)
2782     {
2783       bitVectUnSetBit (lic->rlive, IC_LEFT (ic)->key);
2784       if (IS_ITEMP (IC_RIGHT (dic)))
2785         bitVectSetBit (lic->rlive, IC_RIGHT (dic)->key);
2786     }
2787   /* we now we know that it has one & only one def & use
2788      and the that the definition is an assignment */
2789   IC_LEFT (ic) = IC_RIGHT (dic);
2790
2791   remiCodeFromeBBlock (ebp, dic);
2792   bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
2793   hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
2794 }
2795
2796 /*-----------------------------------------------------------------*/
2797 /* packRegisters - does some transformations to reduce register    */
2798 /*                   pressure                                      */
2799 /*-----------------------------------------------------------------*/
2800 static void
2801 packRegisters (eBBlock * ebp)
2802 {
2803   iCode *ic;
2804   int change = 0;
2805
2806   while (1)
2807     {
2808
2809       change = 0;
2810
2811       /* look for assignments of the form */
2812       /* iTempNN = TRueSym (someoperation) SomeOperand */
2813       /*       ....                       */
2814       /* TrueSym := iTempNN:1             */
2815       for (ic = ebp->sch; ic; ic = ic->next)
2816         {
2817           /* find assignment of the form TrueSym := iTempNN:1 */
2818           if (ic->op == '=' && !POINTER_SET (ic))
2819             change += packRegsForAssign (ic, ebp);
2820         }
2821
2822       if (!change)
2823         break;
2824     }
2825
2826   for (ic = ebp->sch; ic; ic = ic->next)
2827     {
2828       /* if this is an itemp & result of an address of a true sym
2829          then mark this as rematerialisable   */
2830       if (ic->op == ADDRESS_OF &&
2831           IS_ITEMP (IC_RESULT (ic)) &&
2832           IS_TRUE_SYMOP (IC_LEFT (ic)) &&
2833           bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
2834           !OP_SYMBOL (IC_LEFT (ic))->onStack)
2835         {
2836
2837           OP_SYMBOL (IC_RESULT (ic))->remat = 1;
2838           OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
2839           OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
2840
2841         }
2842
2843         /* if this is an itemp & used as a pointer
2844            & assigned to a literal then remat */
2845         if (IS_ASSIGN_ICODE(ic) &&
2846             IS_ITEMP(IC_RESULT(ic)) &&
2847             bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
2848             isOperandLiteral(IC_RIGHT(ic)))
2849         {
2850           OP_SYMBOL (IC_RESULT (ic))->remat = 1;
2851           OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
2852           OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
2853         }
2854
2855       /* if straight assignment then carry remat flag if
2856          this is the only definition */
2857       if (ic->op == '=' &&
2858           !POINTER_SET (ic) &&
2859           IS_SYMOP (IC_RIGHT (ic)) &&
2860           OP_SYMBOL (IC_RIGHT (ic))->remat &&
2861           !IS_CAST_ICODE(OP_SYMBOL (IC_RIGHT (ic))->rematiCode) &&
2862           bitVectnBitsOn (OP_SYMBOL (IC_RESULT (ic))->defs) <= 1)
2863         {
2864
2865           OP_SYMBOL (IC_RESULT (ic))->remat =
2866             OP_SYMBOL (IC_RIGHT (ic))->remat;
2867           OP_SYMBOL (IC_RESULT (ic))->rematiCode =
2868             OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
2869         }
2870
2871       /* if cast to a generic pointer & the pointer being
2872          cast is remat, then we can remat this cast as well */
2873       if (ic->op == CAST &&
2874           IS_SYMOP(IC_RIGHT(ic)) &&
2875           !OP_SYMBOL(IC_RESULT(ic))->isreqv &&
2876           OP_SYMBOL(IC_RIGHT(ic))->remat ) {
2877               sym_link *to_type = operandType(IC_LEFT(ic));
2878               sym_link *from_type = operandType(IC_RIGHT(ic));
2879               if (IS_GENPTR(to_type) && IS_PTR(from_type)) {
2880                       OP_SYMBOL (IC_RESULT (ic))->remat = 1;
2881                       OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
2882                       OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
2883               }
2884       }
2885
2886       /* if this is a +/- operation with a rematerizable
2887          then mark this as rematerializable as well */
2888       if ((ic->op == '+' || ic->op == '-') &&
2889           (IS_SYMOP (IC_LEFT (ic)) &&
2890            IS_ITEMP (IC_RESULT (ic)) &&
2891            OP_SYMBOL (IC_LEFT (ic))->remat &&
2892            (!IS_SYMOP (IC_RIGHT (ic)) || !IS_CAST_ICODE(OP_SYMBOL (IC_RIGHT (ic))->rematiCode)) &&
2893            bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
2894            IS_OP_LITERAL (IC_RIGHT (ic))))
2895         {
2896
2897           //int i = operandLitValue(IC_RIGHT(ic));
2898           OP_SYMBOL (IC_RESULT (ic))->remat = 1;
2899           OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
2900           OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
2901         }
2902
2903       /* mark the pointer usages */
2904       if (POINTER_SET (ic) && IS_SYMOP (IC_RESULT (ic)))
2905         OP_SYMBOL (IC_RESULT (ic))->uptr = 1;
2906
2907       if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic)))
2908         OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
2909
2910       if (ic->op == RETURN && IS_SYMOP (IC_LEFT(ic)))
2911           OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
2912
2913       if (ic->op == RECEIVE && ic->argreg == 1 &&
2914           IS_SYMOP (IC_RESULT (ic)) &&
2915           getSize (operandType(IC_RESULT(ic))) <= 3)
2916           OP_SYMBOL (IC_RESULT(ic))->uptr = 1;
2917
2918       if (ic->op == SEND && ic->argreg == 1 &&
2919           IS_SYMOP(IC_LEFT(ic)) &&
2920           getSize (aggrToPtr(operandType(IC_LEFT(ic)),FALSE)) <= 3)
2921           OP_SYMBOL (IC_LEFT(ic))->uptr = 1;
2922
2923       if (!SKIP_IC2 (ic))
2924         {
2925           /* if we are using a symbol on the stack
2926              then we should say ds390_ptrRegReq */
2927           if (options.useXstack && ic->parmPush
2928               && (ic->op == IPUSH || ic->op == IPOP))
2929             ds390_ptrRegReq++;
2930           if (ic->op == IFX && IS_SYMOP (IC_COND (ic)))
2931                   ds390_ptrRegReq += ((OP_SYMBOL (IC_COND (ic))->onStack ? !options.stack10bit : 0) +
2932                                       OP_SYMBOL (IC_COND (ic))->iaccess +
2933                                       (SPEC_OCLS(OP_SYMBOL (IC_COND (ic))->etype) == idata));
2934           else if (ic->op == JUMPTABLE && IS_SYMOP (IC_JTCOND (ic)))
2935                   ds390_ptrRegReq += ((OP_SYMBOL (IC_JTCOND (ic))->onStack ? !options.stack10bit : 0) +
2936                                       OP_SYMBOL (IC_JTCOND (ic))->iaccess +
2937                                       (SPEC_OCLS(OP_SYMBOL (IC_JTCOND (ic))->etype) == idata));
2938           else
2939             {
2940               if (IS_SYMOP (IC_LEFT (ic)))
2941                       ds390_ptrRegReq += ((OP_SYMBOL (IC_LEFT (ic))->onStack ? !options.stack10bit : 0) +
2942                                           OP_SYMBOL (IC_LEFT (ic))->iaccess +
2943                                           (SPEC_OCLS(OP_SYMBOL (IC_LEFT (ic))->etype) == idata));
2944               if (IS_SYMOP (IC_RIGHT (ic)))
2945                       ds390_ptrRegReq += ((OP_SYMBOL (IC_RIGHT (ic))->onStack ? !options.stack10bit : 0) +
2946                                           OP_SYMBOL (IC_RIGHT (ic))->iaccess +
2947                                           (SPEC_OCLS(OP_SYMBOL (IC_RIGHT (ic))->etype) == idata));
2948               if (IS_SYMOP (IC_RESULT (ic)))
2949                       ds390_ptrRegReq += ((OP_SYMBOL (IC_RESULT (ic))->onStack ? !options.stack10bit : 0) +
2950                                           OP_SYMBOL (IC_RESULT (ic))->iaccess +
2951                                           (SPEC_OCLS(OP_SYMBOL (IC_RESULT (ic))->etype) == idata));
2952             }
2953         }
2954
2955       /* if the condition of an if instruction
2956          is defined in the previous instruction and
2957          this is the only usage then
2958          mark the itemp as a conditional */
2959       if ((IS_CONDITIONAL (ic) ||
2960            (IS_BITWISE_OP(ic) && isBitwiseOptimizable (ic))) &&
2961           ic->next && ic->next->op == IFX &&
2962           bitVectnBitsOn (OP_USES(IC_RESULT(ic)))==1 &&
2963           isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
2964           OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
2965         {
2966           OP_SYMBOL (IC_RESULT (ic))->regType = REG_CND;
2967           continue;
2968         }
2969 #if 1
2970       /* reduce for support function calls */
2971       if (ic->supportRtn || ic->op == '+' || ic->op == '-')
2972         packRegsForSupport (ic, ebp);
2973 #endif
2974       /* some cases the redundant moves can
2975          can be eliminated for return statements . Can be elminated for the first SEND */
2976       if ((ic->op == RETURN ||
2977            ((ic->op == SEND || ic->op == RECEIVE)&& ic->argreg == 1)) &&
2978           !isOperandInFarSpace (IC_LEFT (ic)) &&
2979           !options.model) {
2980
2981           packRegsDPTRuse (IC_LEFT (ic));
2982       }
2983
2984       if (ic->op == CALL) {
2985           sym_link *ftype = operandType(IC_LEFT(ic));
2986           if (getSize(operandType(IC_RESULT(ic))) <= 4 &&
2987               !IFFUNC_ISBUILTIN(ftype)) {
2988               packRegsDPTRuse (IC_RESULT (ic));
2989           }
2990       }
2991
2992       /* if pointer set & left has a size more than
2993          one and right is not in far space */
2994       if (POINTER_SET (ic) &&
2995           !isOperandInFarSpace (IC_RIGHT (ic)) &&
2996           IS_SYMOP (IC_RESULT (ic)) &&
2997           !OP_SYMBOL (IC_RESULT (ic))->remat &&
2998           !IS_OP_RUONLY (IC_RIGHT (ic)) &&
2999           getSize (aggrToPtr (operandType (IC_RESULT (ic)), FALSE)) > 1) {
3000
3001           packRegsDPTRuse (IC_RESULT (ic));
3002       }
3003
3004       /* if pointer get */
3005       if (POINTER_GET (ic) &&
3006           !isOperandInFarSpace (IC_RESULT (ic)) &&
3007           IS_SYMOP (IC_LEFT (ic)) &&
3008           !OP_SYMBOL (IC_LEFT (ic))->remat &&
3009           !IS_OP_RUONLY (IC_RESULT (ic)) &&
3010           getSize (aggrToPtr (operandType (IC_LEFT (ic)), FALSE)) > 1) {
3011
3012           packRegsDPTRuse (IC_LEFT (ic));
3013       }
3014
3015       /* if this is cast for intergral promotion then
3016          check if only use of  the definition of the
3017          operand being casted/ if yes then replace
3018          the result of that arithmetic operation with
3019          this result and get rid of the cast */
3020       if (ic->op == CAST)
3021         {
3022           sym_link *fromType = operandType (IC_RIGHT (ic));
3023           sym_link *toType = operandType (IC_LEFT (ic));
3024
3025           if (IS_INTEGRAL (fromType) && IS_INTEGRAL (toType) &&
3026               getSize (fromType) != getSize (toType) &&
3027               SPEC_USIGN (fromType) == SPEC_USIGN (toType))
3028             {
3029
3030               iCode *dic = packRegsDPTRuse (IC_RIGHT (ic));
3031               if (dic)
3032                 {
3033                   if (IS_ARITHMETIC_OP (dic))
3034                     {
3035                       bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
3036                       IC_RESULT (dic) = IC_RESULT (ic);
3037                       remiCodeFromeBBlock (ebp, ic);
3038                       bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
3039                       hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
3040                       OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
3041                       ic = ic->prev;
3042                     }
3043                   else
3044                     OP_SYMBOL (IC_RIGHT (ic))->ruonly = 0;
3045                 }
3046             }
3047           else
3048             {
3049
3050               /* if the type from and type to are the same
3051                  then if this is the only use then packit */
3052               if (compareType (operandType (IC_RIGHT (ic)),
3053                              operandType (IC_LEFT (ic))) == 1)
3054                 {
3055                   iCode *dic = packRegsDPTRuse (IC_RIGHT (ic));
3056                   if (dic)
3057                     {
3058                       bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
3059                       IC_RESULT (dic) = IC_RESULT (ic);
3060                       remiCodeFromeBBlock (ebp, ic);
3061                       bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
3062                       hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
3063                       OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
3064                       ic = ic->prev;
3065                     }
3066                 }
3067             }
3068         }
3069
3070       /* pack for PUSH
3071          iTempNN := (some variable in farspace) V1
3072          push iTempNN ;
3073          -------------
3074          push V1
3075        */
3076       if (ic->op == IPUSH || ic->op == SEND)
3077         {
3078           packForPush (ic, ebp);
3079         }
3080
3081
3082       /* pack registers for accumulator use, when the
3083          result of an arithmetic or bit wise operation
3084          has only one use, that use is immediately following
3085          the defintion and the using iCode has only one
3086          operand or has two operands but one is literal &
3087          the result of that operation is not on stack then
3088          we can leave the result of this operation in acc:b
3089          combination */
3090       if ((IS_ARITHMETIC_OP (ic)
3091            || IS_CONDITIONAL(ic)
3092            || IS_BITWISE_OP (ic)
3093            || ic->op == LEFT_OP || ic->op == RIGHT_OP
3094            || (ic->op == ADDRESS_OF && isOperandOnStack (IC_LEFT (ic)))
3095           ) &&
3096           IS_ITEMP (IC_RESULT (ic)) &&
3097           getSize (operandType (IC_RESULT (ic))) <= 2)
3098
3099         packRegsForAccUse (ic);
3100
3101     }
3102 }
3103
3104 /*-----------------------------------------------------------------*/
3105 /* assignRegisters - assigns registers to each live range as need  */
3106 /*-----------------------------------------------------------------*/
3107 void
3108 ds390_assignRegisters (eBBlock ** ebbs, int count)
3109 {
3110   iCode *ic;
3111   int i;
3112
3113   setToNull ((void *) &_G.funcrUsed);
3114   setToNull ((void *) &_G.regAssigned);
3115   setToNull ((void *) &_G.totRegAssigned);
3116   setToNull ((void *) &_G.funcrUsed);
3117   ds390_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
3118   ds390_nRegs = 12;
3119   if (options.model != MODEL_FLAT24) options.stack10bit = 0;
3120   /* change assignments this will remove some
3121      live ranges reducing some register pressure */
3122   for (i = 0; i < count; i++)
3123     packRegisters (ebbs[i]);
3124
3125   /* liveranges probably changed by register packing
3126      so we compute them again */
3127   recomputeLiveRanges (ebbs, count);
3128
3129   if (options.dump_pack)
3130     dumpEbbsToFileExt (DUMP_PACK, ebbs, count);
3131
3132   /* first determine for each live range the number of
3133      registers & the type of registers required for each */
3134   regTypeNum ();
3135
3136   /* and serially allocate registers */
3137   serialRegAssign (ebbs, count);
3138
3139   ds390_nRegs = 8;
3140   freeAllRegs ();
3141   fillGaps();
3142   ds390_nRegs = 12;
3143
3144   /* if stack was extended then tell the user */
3145   if (_G.stackExtend)
3146     {
3147 /*      werror(W_TOOMANY_SPILS,"stack", */
3148 /*             _G.stackExtend,currFunc->name,""); */
3149       _G.stackExtend = 0;
3150     }
3151
3152   if (_G.dataExtend)
3153     {
3154 /*      werror(W_TOOMANY_SPILS,"data space", */
3155 /*             _G.dataExtend,currFunc->name,""); */
3156       _G.dataExtend = 0;
3157     }
3158
3159   /* after that create the register mask
3160      for each of the instruction */
3161   createRegMask (ebbs, count);
3162
3163   /* redo that offsets for stacked automatic variables */
3164   if (currFunc)
3165     redoStackOffsets ();
3166
3167   /* make sure r0 & r1 are flagged as used if they might be used */
3168   /* as pointers */
3169   if (currFunc && ds390_ptrRegReq)
3170     {
3171       currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, R0_IDX);
3172       currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, R1_IDX);
3173     }
3174
3175   if (options.dump_rassgn) {
3176     dumpEbbsToFileExt (DUMP_RASSGN, ebbs, count);
3177     dumpLiveRanges (DUMP_LRANGE, liveRanges);
3178   }
3179
3180   /* do the overlaysegment stuff SDCCmem.c */
3181   doOverlays (ebbs, count);
3182
3183   /* now get back the chain */
3184   ic = iCodeLabelOptimize (iCodeFromeBBlock (ebbs, count));
3185
3186   gen390Code (ic);
3187
3188   /* free up any _G.stackSpil locations allocated */
3189   applyToSet (_G.stackSpil, deallocStackSpil);
3190   _G.slocNum = 0;
3191   setToNull ((void *) &_G.stackSpil);
3192   setToNull ((void *) &_G.spiltSet);
3193   /* mark all registers as free */
3194   ds390_nRegs = 8;
3195   freeAllRegs ();
3196
3197   return;
3198 }