lrh
[fw/sdcc] / src / SDCClrange.c
index 376d3caae4b7677bfc1878b375f746c8efe76777..a85c5ff19b64fa6c5eb532e1058650473e4c6375 100644 (file)
@@ -280,7 +280,9 @@ useDefLoopCheck (operand * op, iCode * ic)
                  OP_SYMBOL (op)->name,
                  ic->filename, ic->lineno);
        }
+#if 0 // this will create a segfault: bug #498971
       OP_SYMBOL (op)->isspilt = 1;
+#endif
     }
 }
 
@@ -342,7 +344,7 @@ operandLUse (operand * op, eBBlock ** ebbs,
          !IS_STATIC (etype))
        {
 
-         if (bitVectIsZero (op->usesDefs))
+         if (bitVectIsZero (op->usesDefs) && OP_SYMBOL(op)->ival==NULL)
            {
              OP_SYMBOL (op)->isspilt = 1;
 
@@ -425,10 +427,10 @@ markLiveRanges (eBBlock * ebp, eBBlock ** ebbs, int count)
   bitVect *defsUsed = NULL;
   bitVect *defsNotUsed = NULL;
   int i;
+
   /* for all the instructions */
   for (ic = ebp->sch; ic; ic = ic->next)
     {
-
       if (ic->op == CALL || ic->op == PCALL)
        {
          setFromRange (IC_RESULT (ic), ic->seq);
@@ -539,7 +541,6 @@ markLiveRanges (eBBlock * ebp, eBBlock ** ebbs, int count)
          if (bitVectBitValue (defsNotUsed, i) &&
              (dic = hTabItemWithKey (iCodehTab, i)))
            {
-
              setToRange (IC_RESULT (dic), (ebp->fSeq - 1), TRUE);
            }
        }
@@ -656,6 +657,44 @@ static void computeClash ()
     }
 }
 
+/*-----------------------------------------------------------------*/
+/* allDefsOutOfRange - all definitions are out of a range          */
+/*-----------------------------------------------------------------*/
+bool
+allDefsOutOfRange (bitVect * defs, int fseq, int toseq)
+{
+  int i;
+
+  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;
+}
+
+/*-----------------------------------------------------------------*/
+/* notUsedInBlock - not used in this block                         */
+/*-----------------------------------------------------------------*/
+int
+notUsedInBlock (symbol * sym, eBBlock * ebp, iCode *ic)
+{
+  return (!bitVectBitsInCommon (sym->defs, ebp->usesDefs) &&
+         allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq) &&
+         allDefsOutOfRange (sym->uses, ebp->fSeq, ebp->lSeq));
+}
+
+
 /*-----------------------------------------------------------------*/
 /* computeLiveRanges - computes the live ranges for variables      */
 /*-----------------------------------------------------------------*/
@@ -685,3 +724,4 @@ computeLiveRanges (eBBlock ** ebbs, int count)
   /* compute which overlaps with what */
   computeClash();
 }
+