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