* src/pic/ralloc.c (debugLogRegType): Removed some old types to get it to compile.
[fw/sdcc] / src / pic / ralloc.c
index 244947d8b753d0c490b273c898a6a65008c35659..8fcff68bbdd20e44f17e8a02ff3ca7148cd12aa9 100644 (file)
 
 #include "common.h"
 #include "ralloc.h"
+#include "pcode.h"
 #include "gen.h"
 
-#if defined(_MSC_VER)
-#define __FUNCTION__ __FILE__
-#endif
-
 /*-----------------------------------------------------------------*/
 /* At this point we start getting processor specific although      */
 /* some routines are non-processor specific & can be reused when   */
@@ -64,27 +61,27 @@ int pic14_ptrRegReq;                /* one byte pointer register required */
 regs regspic14[] =
 {
 
-  {REG_GPR, 0x0C, "r0x0C", "r0x0C", 0x0C, 1, 0},
-  {REG_GPR, 0x0D, "r0x0D", "r0x0C", 0x0D, 1, 0},
-  {REG_GPR, 0x0E, "r0x0E", "r0x0C", 0x0E, 1, 0},
-  {REG_GPR, 0x0F, "r0x0F", "r0x0C", 0x0F, 1, 0},
-  {REG_GPR, 0x10, "r0x10", "r0x10", 0x10, 1, 0},
-  {REG_GPR, 0x11, "r0x11", "r0x11", 0x11, 1, 0},
-  {REG_GPR, 0x12, "r0x12", "r0x12", 0x12, 1, 0},
-  {REG_GPR, 0x13, "r0x13", "r0x13", 0x13, 1, 0},
-  {REG_GPR, 0x14, "r0x14", "r0x14", 0x14, 1, 0},
-  {REG_GPR, 0x15, "r0x15", "r0x15", 0x15, 1, 0},
-  {REG_GPR, 0x16, "r0x16", "r0x16", 0x16, 1, 0},
-  {REG_GPR, 0x17, "r0x17", "r0x17", 0x17, 1, 0},
-  {REG_GPR, 0x18, "r0x18", "r0x18", 0x18, 1, 0},
-  {REG_GPR, 0x19, "r0x19", "r0x19", 0x19, 1, 0},
-  {REG_GPR, 0x1A, "r0x1A", "r0x1A", 0x1A, 1, 0},
-  {REG_GPR, 0x1B, "r0x1B", "r0x1B", 0x1B, 1, 0},
-  {REG_GPR, 0x1C, "r0x1C", "r0x1C", 0x1C, 1, 0},
-  {REG_GPR, 0x1D, "r0x1D", "r0x1D", 0x1D, 1, 0},
-  {REG_GPR, 0x1E, "r0x1E", "r0x1E", 0x1E, 1, 0},
-  {REG_GPR, 0x1F, "r0x1F", "r0x1F", 0x1F, 1, 0},
-  {REG_PTR, 4, "FSR", "FSR", 4, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x0C, "r0x0C", "r0x0C", 0x0C, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x0D, "r0x0D", "r0x0C", 0x0D, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x0E, "r0x0E", "r0x0C", 0x0E, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x0F, "r0x0F", "r0x0C", 0x0F, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x10, "r0x10", "r0x10", 0x10, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x11, "r0x11", "r0x11", 0x11, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x12, "r0x12", "r0x12", 0x12, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x13, "r0x13", "r0x13", 0x13, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x14, "r0x14", "r0x14", 0x14, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x15, "r0x15", "r0x15", 0x15, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x16, "r0x16", "r0x16", 0x16, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x17, "r0x17", "r0x17", 0x17, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x18, "r0x18", "r0x18", 0x18, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x19, "r0x19", "r0x19", 0x19, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x1A, "r0x1A", "r0x1A", 0x1A, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x1B, "r0x1B", "r0x1B", 0x1B, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x1C, "r0x1C", "r0x1C", 0x1C, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x1D, "r0x1D", "r0x1D", 0x1D, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x1E, "r0x1E", "r0x1E", 0x1E, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x1F, "r0x1F", "r0x1F", 0x1F, 1, 0},
+  {REG_PTR, PO_FSR, 4, "FSR", "FSR", 4, 1, 0},
 
 };
 
@@ -105,7 +102,7 @@ debugLog (char *fmt,...)
   //char *bufferP=buffer;
   va_list ap;
 
-  if (!debug)
+  if (!debug || !srcFileName)
     return;
 
 
@@ -319,20 +316,6 @@ decodeOp (unsigned int op)
       return "RANGE";
     case FAR:
       return "FAR";
-    case _XDATA:
-      return "_XDATA";
-    case _CODE:
-      return "_CODE";
-    case _GENERIC:
-      return "_GENERIC";
-    case _NEAR:
-      return "_NEAR";
-    case _PDATA:
-      return "_PDATA";
-    case _IDATA:
-      return "_IDATA";
-    case _EEPROM:
-      return "_EEPROM";
     case CASE:
       return "CASE";
     case DEFAULT:
@@ -493,6 +476,19 @@ pic14_regWithIdx (int idx)
   exit (1);
 }
 
+/*-----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
+regs *
+pic14_findFreeReg(void)
+{
+  int i;
+
+  for (i = 0; i < pic14_nRegs; i++)
+    if (regspic14[i].isFree)
+      return &regspic14[i];
+
+  return NULL;
+}
 /*-----------------------------------------------------------------*/
 /* freeReg - frees a register                                      */
 /*-----------------------------------------------------------------*/
@@ -1544,19 +1540,21 @@ serialRegAssign (eBBlock ** ebbs, int count)
 
              /* if it has a spillocation & is used less than
                 all other live ranges then spill this */
-             if (willCS && sym->usl.spillLoc)
-               {
-
-                 symbol *leastUsed =
-                 leastUsedLR (liveRangesWith (spillable,
-                                              allLRs,
-                                              ebbs[i],
-                                              ic));
-                 if (leastUsed &&
-                     leastUsed->used > sym->used)
-                   {
-                     spillThis (sym);
-                     continue;
+               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)) {
+                           spillThis (sym);
+                           continue;
+                       }
                    }
                }
 
@@ -1566,7 +1564,7 @@ serialRegAssign (eBBlock ** ebbs, int count)
              /* if we need ptr regs for the right side
                 then mark it */
              if (POINTER_GET (ic) && getSize (OP_SYMBOL (IC_LEFT (ic))->type)
-                 <= PTRSIZE)
+                 <= (unsigned) PTRSIZE)
                {
                  pic14_ptrRegReq++;
                  ptrRegSet = 1;
@@ -1801,7 +1799,7 @@ rematStr (symbol * sym)
        }
 
       /* we reached the end */
-      sprintf (s, "%s\n", OP_SYMBOL (IC_LEFT (ic))->rname);
+      sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
       break;
     }
 
@@ -1862,6 +1860,7 @@ regTypeNum ()
              (ic = hTabItemWithKey (iCodehTab,
                                     bitVectFirstBit (sym->defs))) &&
              POINTER_GET (ic) &&
+             !sym->noSpilLoc &&
              !IS_BITVAR (sym->etype))
            {
 
@@ -1923,8 +1922,8 @@ regTypeNum ()
 /*-----------------------------------------------------------------*/
 /* freeAllRegs - mark all registers as free                        */
 /*-----------------------------------------------------------------*/
-static void
-freeAllRegs ()
+void
+pic14_freeAllRegs ()
 {
   int i;
 
@@ -1933,6 +1932,21 @@ freeAllRegs ()
     regspic14[i].isFree = 1;
 }
 
+/*-----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
+void
+pic14_deallocateAllRegs ()
+{
+  int i;
+
+  debugLog ("%s\n", __FUNCTION__);
+  for (i = 0; i < pic14_nRegs; i++) {
+    regspic14[i].isFree = 1;
+    regspic14[i].wasUsed = 0;
+  }
+}
+
+
 /*-----------------------------------------------------------------*/
 /* deallocStackSpil - this will set the stack pointer back         */
 /*-----------------------------------------------------------------*/
@@ -2334,7 +2348,7 @@ packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
 
   /* only upto 2 bytes since we cannot predict
      the usage of b, & acc */
-  if (getSize (operandType (op)) > (fReturnSize - 2) &&
+  if (getSize (operandType (op)) > (fReturnSizePic - 2) &&
       ic->op != RETURN &&
       ic->op != SEND)
     return NULL;
@@ -2619,7 +2633,6 @@ static void
 packForReceive (iCode * ic, eBBlock * ebp)
 {
   iCode *dic;
-  bool can_remove = 1;         // assume that we can remove temporary
 
   debugLog ("%s\n", __FUNCTION__);
   debugAopGet ("  result:", IC_RESULT (ic));
@@ -2898,7 +2911,7 @@ packRegisters (eBBlock * ebp)
 
              /* if the type from and type to are the same
                 then if this is the only use then packit */
-             if (checkType (operandType (IC_RIGHT (ic)),
+             if (compareType (operandType (IC_RIGHT (ic)),
                             operandType (IC_LEFT (ic))) == 1)
                {
                  iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
@@ -3015,7 +3028,7 @@ pic14_assignRegisters (eBBlock ** ebbs, int count)
     packRegisters (ebbs[i]);
 
   if (options.dump_pack)
-    dumpEbbsToFileExt (".dumppack", ebbs, count);
+    dumpEbbsToFileExt (DUMP_PACK, ebbs, count);
 
   /* first determine for each live range the number of 
      registers & the type of registers required for each */
@@ -3047,7 +3060,7 @@ pic14_assignRegisters (eBBlock ** ebbs, int count)
   redoStackOffsets ();
 
   if (options.dump_rassgn)
-    dumpEbbsToFileExt (".dumprassgn", ebbs, count);
+    dumpEbbsToFileExt (DUMP_RASSGN, ebbs, count);
 
   /* now get back the chain */
   ic = iCodeLabelOptimize (iCodeFromeBBlock (ebbs, count));
@@ -3064,7 +3077,7 @@ pic14_assignRegisters (eBBlock ** ebbs, int count)
   setToNull ((void **) &_G.stackSpil);
   setToNull ((void **) &_G.spiltSet);
   /* mark all registers as free */
-  freeAllRegs ();
+  pic14_freeAllRegs ();
 
   debugLog ("leaving\n<><><><><><><><><><><><><><><><><>\n");
   debugLogClose ();