Oops
[fw/sdcc] / src / mcs51 / ralloc.c
index 8ecb55b395dfe6ac39580dbaa781a79f84650fd4..a97776bea7b6b80c9b5534bd6feb75f8a27d5215 100644 (file)
@@ -1,9 +1,3 @@
-//#define LIVERANGEHUNT
-#ifdef LIVERANGEHUNT
-  #define LRH(x) x
-#else
-  #define LRH(x)
-#endif
 /*------------------------------------------------------------------------
 
   SDCCralloc.c - source file for register allocation. (8051) specific
@@ -577,7 +571,6 @@ spillThis (symbol * sym)
   if (!(sym->remat || sym->usl.spillLoc))
     createStackSpil (sym);
 
-  LRH(printf("spillThis: %s\n", sym->name));
   /* mark it has spilt & put it in the spilt set */
   sym->isspilt = sym->spillA = 1;
   _G.spiltSet = bitVectSetBit (_G.spiltSet, sym->key);
@@ -725,7 +718,6 @@ spilSomething (iCode * ic, eBBlock * ebp, symbol * forSym)
 
   /* get something we can spil */
   ssym = selectSpil (ic, ebp, forSym);
-  LRH(printf("spilSomething: spilled %s for %s\n", ssym->name, forSym->name));
 
   /* mark it as spilt */
   ssym->isspilt = ssym->spillA = 1;
@@ -1115,6 +1107,18 @@ serialRegAssign (eBBlock ** ebbs, int count)
 
        /* of all instructions do */
        for (ic = ebbs[i]->sch; ic; ic = ic->next) {
+#if 1
+           int reg;
+
+           // update the registers in use at the start of this icode
+           for (reg=0; reg<mcs51_nRegs; reg++) {
+             if (regs8051[reg].isFree) {
+               ic->riu &= ~(1<<regs8051[reg].offset);
+             } else {
+               ic->riu |= (1<<regs8051[reg].offset);
+             }
+           }
+#endif
 
            /* if this is an ipop that means some live
               range will have to be assigned again */
@@ -1570,30 +1574,6 @@ regTypeNum (eBBlock *ebbs)
              continue;
            }
 
-#ifdef RANGEHUNT
-         /* if this symbol has only one usage and that is an assignment
-            to a ruonly, we don't need registers */
-         // if this symbol has only one def
-         if (bitVectnBitsOn (sym->defs)==1) {
-           printf ("sym: %s has only one usage", sym->name);
-           // find that usage
-           if ((ic = hTabItemWithKey (iCodehTab, bitVectFirstBit (sym->defs)))) {
-             if (ic->op==CALL) {
-               printf (" for a call ");
-               // if this is only assigned to a ruonly
-               if ((ic = hTabItemWithKey (iCodehTab, bitVectFirstBit (sym->defs)))) {
-                 if (ic->op=='=') {
-                   if (OP_SYMBOL(IC_RESULT(ic))->ruonly) {
-                     printf("regTypeNum: %s assigned to %s\n", \
-                            sym->name, OP_SYMBOL(IC_RESULT(ic))->name); 
-                   }
-                 }
-               }
-             }
-           }
-         }
-#endif
-
          /* if the symbol has only one definition &
             that definition is a get_pointer */
          if (bitVectnBitsOn (sym->defs) == 1 &&
@@ -1783,12 +1763,19 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
      we cannot */
   for (dic = ic->prev; dic; dic = dic->prev)
     {
+
+#if 0 /* jwk: This collides with 1.43 but I really see no need for
+        this anymore. It fixes bug #716790 and substantially improves 
+        redundant register usage around function calls.
+      */
+
       /* if there is a function call then don't pack it */
       if ((dic->op == CALL || dic->op == PCALL))
        {
          dic = NULL;
          break;
        }
+#endif
 
       if (SKIP_IC2 (dic))
        continue;
@@ -1841,7 +1828,12 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
     {
       sym_link *etype = operandType (IC_RIGHT (dic));
       if (IS_BITFIELD (etype))
-       return 0;
+        {
+          /* if result is a bit too then it's ok */
+         etype = operandType (IC_RESULT (dic));
+          if (!IS_BITFIELD (etype))
+           return 0;
+       }
     }
   /* if the result is on stack or iaccess then it must be
      the same atleast one of the operands */
@@ -1872,7 +1864,7 @@ pack:
     {
       OP_SYMBOL (IC_RESULT (dic))->liveFrom = dic->seq;
     }
-  // jwk: and the otherway around?
+  // TODO: and the otherway around?
 
   /* delete from liverange table also 
      delete from all the points inbetween and the new
@@ -1934,7 +1926,6 @@ findAssignToSym (operand * op, iCode * ic)
   if (!dic)
     return NULL;   /* didn't find any assignment to op */
 
-  LRH(printf ("findAssignToSym: %s\n", OP_SYMBOL(IC_RESULT(dic))->name));
   /* we are interested only if defined in far space */
   /* or in stack space in case of + & - */
   
@@ -2122,7 +2113,6 @@ packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
                         bitVectFirstBit (OP_DEFS (op)))))
     return NULL;
 
-  LRH(printf ("packRegsForOneUse: %s\n", OP_SYMBOL(op)->name));
   /* if that only usage is a cast */
   if (dic->op == CAST) {
     /* to a bigger type */
@@ -2594,7 +2584,8 @@ packRegisters (eBBlock ** ebpp, int blockno)
         cast is remat, then we can remat this cast as well */
       if (ic->op == CAST && 
          IS_SYMOP(IC_RIGHT(ic)) &&
-         OP_SYMBOL(IC_RIGHT(ic))->remat ) {
+         OP_SYMBOL(IC_RIGHT(ic))->remat &&
+         bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1) {
              sym_link *to_type = operandType(IC_LEFT(ic));
              sym_link *from_type = operandType(IC_RIGHT(ic));
              if (IS_GENPTR(to_type) && IS_PTR(from_type)) {                  
@@ -2795,6 +2786,7 @@ mcs51_assignRegisters (eBBlock ** ebbs, int count)
   int i;
 
   setToNull ((void *) &_G.funcrUsed);
+  setToNull ((void *) &_G.regAssigned);
   setToNull ((void *) &_G.totRegAssigned);
   mcs51_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
   mcs51_nRegs = 8;
@@ -2815,6 +2807,8 @@ mcs51_assignRegisters (eBBlock ** ebbs, int count)
   serialRegAssign (ebbs, count);
 
   freeAllRegs ();
+  //setToNull ((void *) &_G.regAssigned);
+  //setToNull ((void *) &_G.totRegAssigned);
   fillGaps();
 
   /* if stack was extended then tell the user */
@@ -2837,7 +2831,9 @@ mcs51_assignRegisters (eBBlock ** ebbs, int count)
   createRegMask (ebbs, count);
 
   /* redo that offsets for stacked automatic variables */
-  redoStackOffsets ();
+  if (currFunc) {
+    redoStackOffsets ();
+  }
 
   if (options.dump_rassgn)
     {