Functions "allDefsOutOfRange" & "notUsedinBlock" moved to SDCClrange.c
[fw/sdcc] / src / pic / ralloc.c
index d4c62894012ffdfeeed72cf4f33057dca88a0971..d5ab8566417d142f99a87858425c822a38a73eb0 100644 (file)
@@ -134,7 +134,12 @@ regs regspic14[] =
   {REG_STK, PO_GPR_TEMP, 0x46, "r0x46", "r0x46", 0x46, 1, 0},
   {REG_STK, PO_GPR_TEMP, 0x47, "r0x47", "r0x47", 0x47, 1, 0},
 
-  {REG_PTR, PO_FSR, 4, "FSR", "FSR", 4, 1, 0},
+  {REG_SFR, PO_GPR_REGISTER, IDX_KZ,    "KZ",  "KZ",   IDX_KZ,   1, 0}, /* Known zero */
+
+
+  {REG_STK, PO_FSR,      IDX_FSR,  "FSR",  "FSR",  IDX_FSR,  1, 0},
+  {REG_STK, PO_INDF,     IDX_INDF, "INDF", "INDF", IDX_INDF, 1, 0},
+
 
 };
 
@@ -531,6 +536,29 @@ pic14_regWithIdx (int idx)
   exit (1);
 }
 
+/*-----------------------------------------------------------------*/
+/* pic14_regWithIdx - returns pointer to register wit index number       */
+/*-----------------------------------------------------------------*/
+regs *
+pic14_allocWithIdx (int idx)
+{
+  int i;
+
+  debugLog ("%s - allocating with index = 0x%x\n", __FUNCTION__,idx);
+
+  for (i = 0; i < pic14_nRegs; i++)
+    if (regspic14[i].rIdx == idx){
+      debugLog ("%s - alloc fount index = 0x%x\n", __FUNCTION__,idx);
+      regspic14[i].wasUsed = 1;
+      regspic14[i].isFree = 0;
+      return &regspic14[i];
+    }
+  //return &regspic14[0];
+  fprintf(stderr,"%s %d - requested register: 0x%x\n",__FUNCTION__,__LINE__,idx);
+  werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+         "regWithIdx not found");
+  exit (1);
+}
 /*-----------------------------------------------------------------*/
 /*-----------------------------------------------------------------*/
 regs *
@@ -591,34 +619,6 @@ nfreeRegsType (int type)
   return nFreeRegs (type);
 }
 
-
-/*-----------------------------------------------------------------*/
-/* allDefsOutOfRange - all definitions are out of a range          */
-/*-----------------------------------------------------------------*/
-static bool
-allDefsOutOfRange (bitVect * defs, int fseq, int toseq)
-{
-  int i;
-
-  debugLog ("%s\n", __FUNCTION__);
-  if (!defs)
-    return TRUE;
-
-  for (i = 0; i < defs->size; i++)
-    {
-      iCode *ic;
-
-      if (bitVectBitValue (defs, i) &&
-         (ic = hTabItemWithKey (iCodehTab, i)) &&
-         (ic->seq >= fseq && ic->seq <= toseq))
-
-       return FALSE;
-
-    }
-
-  return TRUE;
-}
-
 /*-----------------------------------------------------------------*/
 /* computeSpillable - given a point find the spillable live ranges */
 /*-----------------------------------------------------------------*/
@@ -701,18 +701,6 @@ rematable (symbol * sym, eBBlock * ebp, iCode * ic)
   return sym->remat;
 }
 
-/*-----------------------------------------------------------------*/
-/* notUsedInBlock - not used in this block                         */
-/*-----------------------------------------------------------------*/
-static int
-notUsedInBlock (symbol * sym, eBBlock * ebp, iCode * ic)
-{
-  debugLog ("%s\n", __FUNCTION__);
-  return (!bitVectBitsInCommon (sym->defs, ebp->usesDefs) &&
-         allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq));
-/*     return (!bitVectBitsInCommon(sym->defs,ebp->usesDefs)); */
-}
-
 /*-----------------------------------------------------------------*/
 /* notUsedInRemaining - not used or defined in remain of the block */
 /*-----------------------------------------------------------------*/
@@ -2000,8 +1988,10 @@ pic14_deallocateAllRegs ()
 
   debugLog ("%s\n", __FUNCTION__);
   for (i = 0; i < pic14_nRegs; i++) {
-    regspic14[i].isFree = 1;
-    regspic14[i].wasUsed = 0;
+    if(regspic14[i].pc_type == PO_GPR_TEMP) {
+      regspic14[i].isFree = 1;
+      regspic14[i].wasUsed = 0;
+    }
   }
 }
 
@@ -2143,7 +2133,7 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
       if (IS_TRUE_SYMOP (IC_RESULT (dic)) &&
          IS_OP_VOLATILE (IC_RESULT (dic)))
        {
-         debugLog ("  %d - \n", __LINE__);
+         debugLog ("  %d - dic is VOLATILE \n", __LINE__);
          dic = NULL;
          break;
        }
@@ -2151,7 +2141,9 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
       if (IS_SYMOP (IC_RESULT (dic)) &&
          IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
        {
-         debugLog ("  %d - dic key == ic key -- pointer set=%c\n", __LINE__, ((POINTER_SET (dic)) ? 'Y' : 'N'));
+         /* A previous result was assigned to the same register - we'll our definition */
+         debugLog ("  %d - dic result key == ic right key -- pointer set=%c\n",
+                   __LINE__, ((POINTER_SET (dic)) ? 'Y' : 'N'));
          if (POINTER_SET (dic))
            dic = NULL;
 
@@ -2162,7 +2154,7 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
          (IC_RIGHT (dic)->key == IC_RESULT (ic)->key ||
           IC_RIGHT (dic)->key == IC_RIGHT (ic)->key))
        {
-         debugLog ("  %d - \n", __LINE__);
+         debugLog ("  %d - dic right key == ic rightor result key\n", __LINE__);
          dic = NULL;
          break;
        }
@@ -2171,7 +2163,7 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
          (IC_LEFT (dic)->key == IC_RESULT (ic)->key ||
           IC_LEFT (dic)->key == IC_RIGHT (ic)->key))
        {
-         debugLog ("  %d - \n", __LINE__);
+         debugLog ("  %d - dic left key == ic rightor result key\n", __LINE__);
          dic = NULL;
          break;
        }
@@ -2179,7 +2171,8 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
       if (POINTER_SET (dic) &&
          IC_RESULT (dic)->key == IC_RESULT (ic)->key)
        {
-         debugLog ("  %d - \n", __LINE__);
+         debugLog ("  %d - dic result key == ic result key -- pointer set=Y\n",
+                   __LINE__);
          dic = NULL;
          break;
        }
@@ -2208,6 +2201,7 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
     }
 pack:
   debugLog ("  packing. removing %s\n", OP_SYMBOL (IC_RIGHT (ic))->rname);
+  debugLog ("  replacing with %s\n", OP_SYMBOL (IC_RESULT (dic))->rname);
   /* found the definition */
   /* replace the result with the result of */
   /* this assignment and remove this assignment */
@@ -2447,7 +2441,8 @@ packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
      a function call */
   if (dic->op == CALL || dic->op == PCALL)
     {
-      if (ic->op != SEND && ic->op != RETURN)
+      if (ic->op != SEND && ic->op != RETURN &&
+         !POINTER_SET(ic) && !POINTER_GET(ic))
        {
          OP_SYMBOL (op)->ruonly = 1;
          return dic;
@@ -3095,7 +3090,7 @@ pic14_assignRegisters (eBBlock ** ebbs, int count)
   int i;
 
   debugLog ("<><><><><><><><><><><><><><><><><>\nstarting\t%s:%s", __FILE__, __FUNCTION__);
-  debugLog ("ebbs before optimizing:\n");
+  debugLog ("\nebbs before optimizing:\n");
   dumpEbbsToDebug (ebbs, count);
 
   setToNull ((void *) &_G.funcrUsed);