* device/lib/libsdcc.lib: added module rand
[fw/sdcc] / src / hc08 / ralloc.c
index a4dc8526695e6d8fe730c6b18078e2b05866e6a8..116804335972d319f21ff542f0d2217db85349ef 100644 (file)
@@ -738,7 +738,9 @@ selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
 
       /* check if there are any live ranges that not
          used in the remainder of the block */
-      if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInRemaining, ebp, ic)))
+      if (!_G.blockSpil &&
+          !isiCodeInFunctionCall (ic) &&       
+          (selectS = liveRangesWith (lrcs, notUsedInRemaining, ebp, ic)))
        {
          sym = leastUsedLR (selectS);
          if (sym != forSym)
@@ -1263,7 +1265,13 @@ serialRegAssign (eBBlock ** ebbs, int count)
                int j;
                int ptrRegSet = 0;
 
-               /* if it does not need or is spilt
+               /* Make sure any spill location is definately allocated */
+               if (sym->isspilt && !sym->remat && sym->usl.spillLoc &&
+                   !sym->usl.spillLoc->allocreq) {
+                   sym->usl.spillLoc->allocreq++;
+               }
+
+                /* if it does not need or is spilt
                   or is already assigned to registers
                   or will not live beyond this instructions */
                if (!sym->nRegs ||
@@ -1663,49 +1671,58 @@ createRegMask (eBBlock ** ebbs, int count)
 static char *
 rematStr (symbol * sym)
 {
-  char *s = buffer;
   iCode *ic = sym->rematiCode;
-//  int offset = 0;
+  int offset = 0;
 
   while (1)
     {
-      /* if plus or minus print the right hand side */
-      if (ic->op == '+' || ic->op == '-')
-       {
-         sprintf (s, "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)),
-                  ic->op);
-         s += strlen (s);
-         ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
-         continue;
-       }
-
-/*
+      /* if plus adjust offset to right hand side */
       if (ic->op == '+')
         {
-          offset += operandLitValue (IC_RIGHT (ic));
+          offset += (int) operandLitValue (IC_RIGHT (ic));
          ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
           continue;
         }
+
+      /* if minus adjust offset to right hand side */
       if (ic->op == '-')
         {
-          offset -= operandLitValue (IC_RIGHT (ic));
+          offset -= (int) operandLitValue (IC_RIGHT (ic));
          ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
           continue;
         }
-*/
+
       /* cast then continue */
       if (IS_CAST_ICODE(ic)) {
          ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
          continue;
       }
       /* we reached the end */
-      if (ic->op == ADDRESS_OF)
-        sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
-      else if (ic->op == '=')
-        sprintf (s, "0x%04x", (int) operandLitValue (IC_RIGHT (ic)) );
       break;
     }
 
+  if (ic->op == ADDRESS_OF)
+    {
+      if (offset)
+        {
+          SNPRINTF (buffer, sizeof(buffer),
+                    "(%s %c 0x%04x)",
+                    OP_SYMBOL (IC_LEFT (ic))->rname,
+                    offset >= 0 ? '+' : '-',
+                    abs (offset) & 0xffff);
+        }
+      else
+        {
+          strncpyz (buffer, OP_SYMBOL (IC_LEFT (ic))->rname, sizeof(buffer));
+        }
+    }
+  else if (ic->op == '=')
+    {
+      offset += (int) operandLitValue (IC_RIGHT (ic));
+      SNPRINTF (buffer, sizeof(buffer),
+                "0x%04x",
+                offset & 0xffff);
+    }
   return buffer;
 }
 
@@ -1945,7 +1962,6 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
       return 0;
     }
 
-
   /* if the true symbol is defined in far space or on stack
      then we should not since this will increase register pressure */
 #if 0
@@ -2020,16 +2036,18 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
     return 0;                  /* did not find */
 
   /* if assignment then check that right is not a bit */
-  if (ASSIGNMENT (dic) && !POINTER_SET (dic))
+  if (ASSIGNMENT (ic) && !POINTER_SET (ic))
     {
-      sym_link *etype = operandType (IC_RIGHT (dic));
+      sym_link *etype = operandType (IC_RESULT (dic));
       if (IS_BITFIELD (etype))
         {
           /* if result is a bit too then it's ok */
-         etype = operandType (IC_RESULT (dic));
+          etype = operandType (IC_RESULT (ic));
           if (!IS_BITFIELD (etype))
-           return 0;
-       }
+            {
+              return 0;
+            }
+       }
     }
   /* if the result is on stack or iaccess then it must be
      the same atleast one of the operands */
@@ -3047,8 +3065,10 @@ packRegisters (eBBlock ** ebpp, int blockno)
 /* assignRegisters - assigns registers to each live range as need  */
 /*-----------------------------------------------------------------*/
 void
-hc08_assignRegisters (eBBlock ** ebbs, int count)
+hc08_assignRegisters (ebbIndex * ebbi)
 {
+  eBBlock ** ebbs = ebbi->bbOrder;
+  int count = ebbi->count;
   iCode *ic;
   int i;
 
@@ -3075,7 +3095,7 @@ hc08_assignRegisters (eBBlock ** ebbs, int count)
   recomputeLiveRanges (ebbs, count);
 
   if (options.dump_pack)
-    dumpEbbsToFileExt (DUMP_PACK, ebbs, count);
+    dumpEbbsToFileExt (DUMP_PACK, ebbi);
 
   /* first determine for each live range the number of
      registers & the type of registers required for each */
@@ -3115,7 +3135,7 @@ hc08_assignRegisters (eBBlock ** ebbs, int count)
 
   if (options.dump_rassgn)
     {
-      dumpEbbsToFileExt (DUMP_RASSGN, ebbs, count);
+      dumpEbbsToFileExt (DUMP_RASSGN, ebbi);
       dumpLiveRanges (DUMP_LRANGE, liveRanges);
     }
 
@@ -3130,8 +3150,8 @@ hc08_assignRegisters (eBBlock ** ebbs, int count)
   /* free up any _G.stackSpil locations allocated */
   applyToSet (_G.stackSpil, deallocStackSpil);
   _G.slocNum = 0;
-  setToNull ((void **) &_G.stackSpil);
-  setToNull ((void **) &_G.spiltSet);
+  setToNull ((void *) &_G.stackSpil);
+  setToNull ((void *) &_G.spiltSet);
   /* mark all registers as free */
   freeAllRegs ();