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