xa 51, work in progress
[fw/sdcc] / src / xa51 / ralloc.c
index 66cdeb4fed0ae56e001aafdaa083c1959f9bddb7..037e79830a8d88a10e18fd8d78ebcececbf1167a 100755 (executable)
@@ -203,7 +203,7 @@ static bool allocReg (short size, short type, symbol *sym,
 
   switch (size) 
     {
-      // TODO: gaps should be filled for dwords too
+      // TODO: gaps could be filled for dwords too
     case 1:
       // let's see if we can fill a gap
       for (i=0; i<xa51_nRegs; i++) {
@@ -524,29 +524,29 @@ noOverLap (set * itmpStack, symbol * fsym)
 /*-----------------------------------------------------------------*/
 /* isFree - will return 1 if the a free spil location is found     */
 /*-----------------------------------------------------------------*/
-static
-DEFSETFUNC (isFree)
-{
+static DEFSETFUNC (isFree) {
   symbol *sym = item;
   V_ARG (symbol **, sloc);
   V_ARG (symbol *, fsym);
-
+  
   /* if already found */
   if (*sloc)
     return 0;
-
+  
   /* if it is free && and the itmp assigned to
      this does not have any overlapping live ranges
      with the one currently being assigned and
      the size can be accomodated  */
   if (sym->isFree &&
       noOverLap (sym->usl.itmpStack, fsym) &&
-      getSize (sym->type) >= getSize (fsym->type))
-    {
-      *sloc = sym;
-      return 1;
-    }
-
+      /* TODO: this is a waste but causes to many problems 
+        getSize (sym->type) >= getSize (fsym->type)) {
+      */
+      getSize (sym->type) == getSize (fsym->type)) {
+    *sloc = sym;
+    return 1;
+  }
+  
   return 0;
 }
 
@@ -557,8 +557,6 @@ static symbol *
 createStackSpil (symbol * sym)
 {
   symbol *sloc = NULL;
-  int useXstack, model;
-
   char slocBuffer[30];
 
   D(fprintf (stderr, "  createStackSpil: %s\n", sym->name));
@@ -575,17 +573,7 @@ createStackSpil (symbol * sym)
       return sym;
     }
 
-  /* could not then have to create one , this is the hard part
-     we need to allocate this on the stack : this is really a
-     hack!! but cannot think of anything better at this time */
-
-  if (sprintf (slocBuffer, "sloc%d", _G.slocNum++) >= sizeof (slocBuffer))
-    {
-      fprintf (stderr, "***Internal error: slocBuffer overflowed: %s:%d\n",
-              __FILE__, __LINE__);
-      exit (1);
-    }
-
+  sprintf (slocBuffer, "sloc%d", _G.slocNum++);
   sloc = newiTemp (slocBuffer);
 
   /* set the type to the spilling symbol */
@@ -597,34 +585,12 @@ createStackSpil (symbol * sym)
   SPEC_VOLATILE(sloc->etype) = 0;
   SPEC_ABSA(sloc->etype) = 0;
 
-  /* we don't allow it to be allocated`
-     onto the external stack since : so we
-     temporarily turn it off ; we also
-     turn off memory model to prevent
-     the spil from going to the external storage
-   */
-
-  useXstack = options.useXstack;
-  model = options.model;
-/*     noOverlay = options.noOverlay; */
-/*     options.noOverlay = 1; */
-  options.model = options.useXstack = 0;
-
   allocLocal (sloc);
 
-  options.useXstack = useXstack;
-  options.model = model;
-/*     options.noOverlay = noOverlay; */
   sloc->isref = 1;             /* to prevent compiler warning */
 
-  /* if it is on the stack then update the stack */
-  if (IN_STACK (sloc->etype))
-    {
-      currFunc->stack += getSize (sloc->type);
-      _G.stackExtend += getSize (sloc->type);
-    }
-  else
-    _G.dataExtend += getSize (sloc->type);
+  currFunc->stack += getSize (sloc->type);
+  _G.stackExtend += getSize (sloc->type);
 
   /* add it to the _G.stackSpil set */
   addSetHead (&_G.stackSpil, sloc);
@@ -1014,8 +980,9 @@ serialRegAssign (eBBlock ** ebbs, int count)
 
            /* if result is present && is a true symbol */
            if (IC_RESULT (ic) && ic->op != IFX &&
-               IS_TRUE_SYMOP (IC_RESULT (ic)))
-               OP_SYMBOL (IC_RESULT (ic))->allocreq++;
+               IS_TRUE_SYMOP (IC_RESULT (ic))) {
+             OP_SYMBOL (IC_RESULT (ic))->allocreq++;
+           }
 
            /* take away registers from live
               ranges that end at this instruction */
@@ -1030,6 +997,39 @@ serialRegAssign (eBBlock ** ebbs, int count)
                (IC_RESULT (ic) && POINTER_SET (ic)))
                continue;
 
+#if 0
+           /* xa51 has advance compare instructions */
+           if (ic->op == '<' || ic->op == '>' || 
+               ic->op == LE_OP || ic->op == GE_OP ||
+               ic->op == NE_OP || ic->op == EQ_OP) {
+             /* if this result is only used for an ifx, we don't
+                need registers nor the ifx */
+             int used=bitVectnBitsOn(OP_SYMBOL(IC_RESULT(ic))->uses);
+             iCode *nic;
+             if (used!=1) {
+               fprintf (stderr, "unexpected \"used\" for cmp:%d\n", ic->op);
+               exit (1);
+             }
+             // find the ifx
+             for (nic=ic->next; nic; nic=nic->next) {
+               if (nic->op == IFX) {
+                 break;
+               }
+             }
+             if (!nic) {
+               // we are in big trouble
+               fprintf (stderr, "No ifx found for %d\n",
+                        ic->op);
+               exit (1);
+             }
+             // remove the ifx
+             nic->prev->next=nic->next;
+             if (nic->next) {
+               nic->next->prev=nic->prev;
+             }
+           }
+#endif
+
            /* now we need to allocate registers
               only for the result */
            if (IC_RESULT (ic)) {
@@ -1067,24 +1067,24 @@ serialRegAssign (eBBlock ** ebbs, int count)
                /* if it has a spillocation & is used less than
                   all other live ranges then spill this */
                if (willCS) {
-                   if (sym->usl.spillLoc) {
-                       symbol *leastUsed = leastUsedLR (liveRangesWith (spillable,
-                                                                        allLRs, ebbs[i], ic));
-                       if (leastUsed && leastUsed->used > sym->used) {
-                           spillThis (sym);
-                           continue;
-                       }
-                   } else {
-                       /* if none of the liveRanges have a spillLocation then better
-                          to spill this one than anything else already assigned to registers */
-                       if (liveRangesWith(spillable,noSpilLoc,ebbs[i],ic)) {
-                           /* if this is local to this block then we might find a block spil */
-                           if (!(sym->liveFrom >= ebbs[i]->fSeq && sym->liveTo <= ebbs[i]->lSeq)) {
-                               spillThis (sym);
-                               continue;
-                           }
-                       }
+                 if (sym->usl.spillLoc) {
+                   symbol *leastUsed = leastUsedLR (liveRangesWith (spillable,
+                                                                    allLRs, ebbs[i], ic));
+                   if (leastUsed && leastUsed->used > sym->used) {
+                     spillThis (sym);
+                     continue;
                    }
+                 } else {
+                   /* if none of the liveRanges have a spillLocation then better
+                      to spill this one than anything else already assigned to registers */
+                   if (liveRangesWith(spillable,noSpilLoc,ebbs[i],ic)) {
+                     /* if this is local to this block then we might find a block spil */
+                     if (!(sym->liveFrom >= ebbs[i]->fSeq && sym->liveTo <= ebbs[i]->lSeq)) {
+                       spillThis (sym);
+                       continue;
+                     }
+                   }
+                 }
                }
 
                /* else we assign registers to it */
@@ -1329,10 +1329,7 @@ regTypeNum (eBBlock *ebbs)
 #endif
 
          /* if the symbol has only one definition &
-            that definition is a get_pointer and the
-            pointer we are getting is rematerializable and
-            in "data" space */
-
+            that definition is a get_pointer */
          if (bitVectnBitsOn (sym->defs) == 1 &&
              (ic = hTabItemWithKey (iCodehTab,
                                     bitVectFirstBit (sym->defs))) &&
@@ -1340,12 +1337,10 @@ regTypeNum (eBBlock *ebbs)
              !sym->noSpilLoc &&
              !IS_BITVAR (sym->etype))
            {
-
-
-             /* if remat in data space */
+             /* and that pointer is remat in data space */
              if (OP_SYMBOL (IC_LEFT (ic))->remat &&
                  !IS_CAST_ICODE(OP_SYMBOL (IC_LEFT (ic))->rematiCode) &&
-                 DCL_TYPE (aggrToPtr (sym->type, FALSE)) == POINTER)
+                 DCL_TYPE (aggrToPtr (operandType(IC_LEFT(ic)), FALSE)) == POINTER)
                {
                  /* create a psuedo symbol & force a spil */
                  symbol *psym = newSymbol (rematStr (OP_SYMBOL (IC_LEFT (ic))), 1);
@@ -1888,6 +1883,8 @@ static void packRegisters (eBBlock * ebp) {
   iCode *ic;
   int change = 0;
   
+  return; // that's it for now
+
   while (1) {
     change = 0;
     
@@ -1899,7 +1896,6 @@ static void packRegisters (eBBlock * ebp) {
     if (!change)
       break;
   }
-  return; // that's it for now
 
   for (ic = ebp->sch; ic; ic = ic->next)
     {