* src/hc08/main.c (_hc08_genAssemblerPreamble): fixed bug #875487. Also
[fw/sdcc] / src / hc08 / ralloc.c
index cbd8b8282f5afb2bb6205c584adeb1d8187b2aa6..f413f7653370a6fb3b5f81689fc4e0d99d1cfa54 100644 (file)
@@ -434,7 +434,7 @@ leastUsedLR (set * sset)
 
     }
 
-  setToNull ((void **) &sset);
+  setToNull ((void *) &sset);
   sym->blockSpil = 0;
   return sym;
 }
@@ -1606,6 +1606,7 @@ rematStr (symbol * sym)
          ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
          continue;
        }
+
 /*      
       if (ic->op == '+')
         {
@@ -1626,7 +1627,10 @@ rematStr (symbol * sym)
          continue;
       }
       /* we reached the end */
-      sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
+      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;
     }
 
@@ -1768,6 +1772,7 @@ DEFSETFUNC (deallocStackSpil)
   return 0;
 }
 
+#if 0
 /*-----------------------------------------------------------------*/
 /* farSpacePackable - returns the packable icode for far variables */
 /*-----------------------------------------------------------------*/
@@ -1835,6 +1840,44 @@ farSpacePackable (iCode * ic)
 
   return NULL;
 }
+#endif
+
+#if 0
+static void
+packRegsForLiteral (iCode * ic)
+{
+  int k;
+  iCode *uic;
+  
+  if (ic->op != '=')
+    return;
+  if (POINTER_SET (ic))
+    return;
+  if (!IS_LITERAL (getSpec (operandType (IC_RIGHT (ic)))))
+    return;
+  if (bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) > 1)
+    return;
+
+  for (k=0; k< OP_USES (IC_RESULT (ic))->size; k++)
+    if (bitVectBitValue (OP_USES (IC_RESULT (ic)), k))
+      {
+        uic = hTabItemWithKey (iCodehTab, k);
+        if (!uic) continue;
+        
+        if (uic->op != IFX && uic->op != JUMPTABLE)
+         {
+           if (IC_LEFT (uic) && IC_LEFT (uic)->key == IC_RESULT (ic)->key)
+             ReplaceOpWithCheaperOp(&IC_LEFT(uic), IC_RIGHT(ic));
+           if (IC_RIGHT (uic) && IC_RIGHT (uic)->key == IC_RESULT (ic)->key)
+             ReplaceOpWithCheaperOp(&IC_RIGHT(uic), IC_RIGHT(ic));
+           if (IC_RESULT (uic) && IC_RESULT (uic)->key == IC_RESULT (ic)->key)
+             ReplaceOpWithCheaperOp(&IC_RESULT(uic), IC_RIGHT(ic));
+         }
+      }
+
+}
+#endif
+
 
 /*-----------------------------------------------------------------*/
 /* packRegsForAssign - register reduction for assignment           */
@@ -1985,6 +2028,7 @@ pack:
   return 1;
 }
 
+
 /*------------------------------------------------------------------*/
 /* findAssignToSym : scanning backwards looks for first assig found */
 /*------------------------------------------------------------------*/
@@ -2122,6 +2166,7 @@ static int
 packRegsForSupport (iCode * ic, eBBlock * ebp)
 {
   iCode *dic;
+  int changes = 0;
   
   /* for the left & right operand :- look to see if the
      left was assigned a true symbol in far space in that
@@ -2136,7 +2181,7 @@ packRegsForSupport (iCode * ic, eBBlock * ebp)
        {
          /* found it we need to remove it from the block */
          reassignAliasedSym (ebp, dic, ic, IC_LEFT(ic));
-         return 1;
+         changes++;
        }
     }
 
@@ -2148,30 +2193,19 @@ packRegsForSupport (iCode * ic, eBBlock * ebp)
 
       if (dic)
        {
-         /* if this is a subtraction & the result
-            is a true symbol in far space then don't pack */
-#if 0
-         if (ic->op == '-' && IS_TRUE_SYMOP (IC_RESULT (dic)))
-           {
-             sym_link *etype = getSpec (operandType (IC_RESULT (dic)));
-             if (IN_FARSPACE (SPEC_OCLS (etype)))
-               return 0;
-           }
-#endif
-         /* found it we need to remove it from the
-            block */
+         /* found it we need to remove it from the block */
          reassignAliasedSym (ebp, dic, ic, IC_RIGHT(ic));
-         
-         return 1;
+         changes++;
        }
     }
 
-  return 0;
+  return changes;
 }
 
 #define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
 
 
+#if 0
 /*-----------------------------------------------------------------*/
 /* packRegsForOneuse : - will reduce some registers for single Use */
 /*-----------------------------------------------------------------*/
@@ -2185,8 +2219,7 @@ packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
   if (!IS_SYMOP (op))
     return NULL;
 
-  /* only upto 2 bytes since we cannot predict
-     the usage of b, & acc */
+  /* only up to 2 bytes */
   if (getSize (operandType (op)) > (fReturnSizeHC08 - 2))
     return NULL;
 
@@ -2328,6 +2361,7 @@ packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
   OP_SYMBOL (op)->ruonly = 1;
   return sic;
 }
+#endif
 
 /*-----------------------------------------------------------------*/
 /* isBitwiseOptimizable - requirements of JEAN LOUIS VERN          */
@@ -2499,7 +2533,10 @@ packRegsForAccUse (iCode * ic)
       !IS_BITWISE_OP (uic) &&
       (uic->op != LEFT_OP) &&
       (uic->op != RIGHT_OP) &&
-      (uic->op != GETHBIT))
+      (uic->op != GETHBIT) &&
+      (uic->op != RETURN) &&
+      (uic->op != '~') &&
+      (uic->op != '!'))
     return;
 
 #if 0
@@ -2679,10 +2716,12 @@ packRegisters (eBBlock ** ebpp, int blockno)
 
   for (ic = ebp->sch; ic; ic = ic->next)
     {
+      //packRegsForLiteral (ic);
+      
       /* if this is an itemp & result of an address of a true sym 
          then mark this as rematerialisable   */
       if (ic->op == ADDRESS_OF &&
-         IS_ITEMP (IC_RESULT (ic)) &&
+         IS_ITEMP (IC_RESULT (ic)) && 
          IS_TRUE_SYMOP (IC_LEFT (ic)) &&
          bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
          !OP_SYMBOL (IC_LEFT (ic))->onStack )
@@ -2693,7 +2732,20 @@ packRegisters (eBBlock ** ebpp, int blockno)
          OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
 
        }
+#if 1
+      if (ic->op == '=' &&
+          !POINTER_SET (ic) &&
+         IS_ITEMP (IC_RESULT (ic)) &&
+         IS_VALOP (IC_RIGHT (ic)) &&
+         bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1)
+       {
 
+         OP_SYMBOL (IC_RESULT (ic))->remat = 1;
+         OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
+         OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
+
+       }
+#endif
       /* if straight assignment then carry remat flag if
          this is the only definition */
       if (ic->op == '=' &&
@@ -2790,7 +2842,7 @@ packRegisters (eBBlock ** ebpp, int blockno)
        }
 
       /* reduce for support function calls */
-      if (ic->supportRtn || ic->op == '+' || ic->op == '-')
+      if (ic->supportRtn || (ic->op != IFX && ic->op != JUMPTABLE))
        packRegsForSupport (ic, ebp);
 
       #if 0
@@ -2889,25 +2941,28 @@ packRegisters (eBBlock ** ebpp, int blockno)
        }
 
 
-      #if 0
+      #if 1
       /* pack registers for accumulator use, when the
          result of an arithmetic or bit wise operation
          has only one use, that use is immediately following
          the defintion and the using iCode has only one
          operand or has two operands but one is literal &
          the result of that operation is not on stack then
-         we can leave the result of this operation in acc:b
+         we can leave the result of this operation in x:a
          combination */
       if ((IS_ARITHMETIC_OP (ic)
           || IS_CONDITIONAL(ic)
           || IS_BITWISE_OP (ic)
           || ic->op == '='
+           || ic->op == '!'
+           || ic->op == '~'
           || ic->op == GETHBIT
           || ic->op == LEFT_OP || ic->op == RIGHT_OP || ic->op == CALL
           || (ic->op == ADDRESS_OF && isOperandOnStack (IC_LEFT (ic)))
+           || ic->op == RECEIVE
          ) &&
          IS_ITEMP (IC_RESULT (ic)) &&
-         getSize (operandType (IC_RESULT (ic))) <= 2)
+         getSize (operandType (IC_RESULT (ic))) <= 1)
 
        packRegsForAccUse (ic);
       #endif
@@ -2939,6 +2994,10 @@ hc08_assignRegisters (eBBlock ** ebbs, int count)
   for (i = 0; i < count; i++)
     packRegisters (ebbs, i);
 
+  /* liveranges probably changed by register packing
+     so we compute them again */
+  recomputeLiveRanges (ebbs, count);
+  
   if (options.dump_pack)
     dumpEbbsToFileExt (DUMP_PACK, ebbs, count);