This should fix some, if not all, of the live range problems
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 25 Mar 2003 20:28:36 +0000 (20:28 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 25 Mar 2003 20:28:36 +0000 (20:28 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2416 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCBBlock.c
src/SDCCloop.c
src/SDCClrange.c
src/SDCClrange.h
src/mcs51/ralloc.c

index dfa15ce269fef7bce0f310eff85c2bda68111fe4..5b12ef0a3d2ca098da06828b09b464ed94fcb1f9 100644 (file)
@@ -188,9 +188,9 @@ dumpEbbsToFileExt (int id, eBBlock ** ebbs, int count)
   for (i = 0; i < count; i++)
     {
       fprintf (of, "\n----------------------------------------------------------------\n");
-      fprintf (of, "Basic Block %s (df:%d bb:%d): loop Depth = %d noPath = %d lastinLoop = %d\n",
+      fprintf (of, "Basic Block %s (df:%d bb:%d lvl:%d): loop Depth = %d noPath = %d lastinLoop = %d\n",
               ebbs[i]->entryLabel->name,
-              ebbs[i]->dfnum, ebbs[i]->bbnum,
+              ebbs[i]->dfnum, ebbs[i]->bbnum, ebbs[i]->entryLabel->level,
               ebbs[i]->depth,
               ebbs[i]->noPath,
               ebbs[i]->isLastInLoop);
index 55021f34798aa1a0d80e920e8a9a29bd86e22f6a..f43e48373dcb31f3d42fb12b71aae3101e9177f4 100644 (file)
@@ -259,11 +259,8 @@ DEFSETFUNC (createLoop)
 {
   edge *ep = item;
   V_ARG (set **, allRegion);
-  V_ARG (eBBlock **,ebbs);
-  V_ARG (int,count);
   region *aloop = newRegion ();
   eBBlock *block;
-  int dfMin = count ,dfMax =0, i;
 
   /* make sure regionStack is empty */
   while (!STACK_EMPTY (regionStack))
@@ -283,32 +280,6 @@ DEFSETFUNC (createLoop)
 
   aloop->entry = ep->to;
 
-  /* set max & min dfNum for loopRegion */
-  for ( block = setFirstItem(aloop->regBlocks); block; 
-       block = setNextItem(aloop->regBlocks)) {
-      if (block->dfnum > dfMax) dfMax = block->dfnum;
-      if (block->dfnum < dfMin) dfMin = block->dfnum;
-  }
-
-  /* all blocks that have dfnumbers between dfMin & dfMax are also
-     part of loop */
-  for (i = 0 ; i < count ; i++) {
-    if (ebbs[i]->dfnum > dfMin && 
-          ebbs[i]->dfnum < dfMax &&
-         !isinSet(aloop->regBlocks,ebbs[i])) {
-         if (!ebbs[i]->partOfLoop) {
-           ebbs[i]->partOfLoop = aloop;
-         }
-      }
-  }
-
-  /* and if this is a conditional block, the other side of the IFX 
-     (if any, that could have a greater dfnum) is too */
-  {
-    // just a burp, but I'm getting close :)
-  }
-  
-
   /* now add it to the set */
   addSetHead (allRegion, aloop);
   return 0;
@@ -1183,7 +1154,7 @@ createLoopRegions (eBBlock ** ebbs, int count)
 
   /* for each of these back edges get the blocks that */
   /* constitute the loops                             */
-  applyToSet (bEdges, createLoop, &allRegion, ebbs,count);
+  applyToSet (bEdges, createLoop, &allRegion);
 
   /* now we will create regions from these loops               */
   /* loops with the same entry points are considered to be the */
index 33dddbad685b58a07415ef32de55c4a457d7ce7a..9675329467c89ab75194df9af2798ec2a1d62689 100644 (file)
@@ -175,12 +175,17 @@ setFromRange (operand * op, int from)
 /* setToRange - set the range to for an operand                    */
 /*-----------------------------------------------------------------*/
 void 
-setToRange (operand * op, int to, bool check)
+setToRange (operand * op, int to, bool check, int fromLevel)
 {
   /* only for compiler defined temps */
   if (!IS_ITEMP (op))
     return;
 
+  if (fromLevel > OP_SYMBOL(op)->level) {
+    // this is from an inner block and thus has no authority
+    return;
+  }
+
   OP_SYMBOL (op)->key = op->key;
   hTabAddItemIfNotP (&liveRanges, op->key, OP_SYMBOL (op));
 
@@ -315,17 +320,9 @@ operandLUse (operand * op, eBBlock ** ebbs,
          /* found it : mark */
          if (lic) torange = lic->prev->seq;
       }
-      /* if this is the last use then if this block belongs 
-         to a  loop &  some definition  comes into the loop 
-         then extend the live range to  the end of the loop */
-      if (ebp->partOfLoop 
-         && hasIncomingDefs (ebp->partOfLoop, op))
-       {
-         torange = findLoopEndSeq (ebp->partOfLoop);
-       }
-      
+
       op = operandFromOperand (op);
-      setToRange (op, torange, FALSE);
+      setToRange (op, torange, FALSE, ebp->entryLabel->level);
     }
   ic->uses = bitVectSetBit (ic->uses, op->key);
 
@@ -427,10 +424,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);
@@ -439,7 +436,8 @@ markLiveRanges (eBBlock * ebp, eBBlock ** ebbs, int count)
             and take it away from the defs for the block */
          if (bitVectIsZero (OP_SYMBOL (IC_RESULT (ic))->uses))
            {
-             setToRange (IC_RESULT (ic), ic->seq, FALSE);
+             setToRange (IC_RESULT (ic), ic->seq, FALSE, 
+                         ebp->entryLabel->level);
              bitVectUnSetBit (ebp->defSet, ic->key);
            }
        }
@@ -511,7 +509,8 @@ markLiveRanges (eBBlock * ebp, eBBlock ** ebbs, int count)
                  defUsedAfterLoop (IC_RESULT (dic), ebp->lSeq))
                continue;
 
-             setToRange (IC_RESULT (dic), (ebp->lSeq), FALSE);
+             setToRange (IC_RESULT (dic), (ebp->lSeq), FALSE, 
+                         ebp->entryLabel->level);
            }
        }
     }
@@ -541,8 +540,8 @@ markLiveRanges (eBBlock * ebp, eBBlock ** ebbs, int count)
          if (bitVectBitValue (defsNotUsed, i) &&
              (dic = hTabItemWithKey (iCodehTab, i)))
            {
-
-             setToRange (IC_RESULT (dic), (ebp->fSeq - 1), TRUE);
+             setToRange (IC_RESULT (dic), (ebp->fSeq - 1), TRUE,
+                         ebp->entryLabel->level);
            }
        }
     }
index f1785407ba3a3932a6a7d179e155a8ecdcf61051..6c2441d8e5629b764b3fb4268125bdd70f8ed25f 100644 (file)
@@ -35,6 +35,6 @@ bool allDefsOutOfRange (bitVect *, int, int);
 void computeLiveRanges (eBBlock **, int);
 
 void setFromRange (operand *, int);
-void setToRange (operand *, int, bool);
+void setToRange (operand *, int, bool, int);
 
 #endif
index bf3d162f02809cf0c9259391842376c255433a01..6be33c026df4f02c1dad728f02452fe7420cb9c2 100644 (file)
@@ -2007,7 +2007,7 @@ reassignAliasedSym (eBBlock *ebp, iCode *assignment, iCode *use, operand *op)
 
   /* update the sym's liverange */
   if ( OP_LIVETO(op) < ic->seq )
-    setToRange(op, ic->seq, FALSE);
+    setToRange(op, ic->seq, FALSE, OP_SYMBOL(op)->level);
 
   /* remove the assignment iCode now that its result is unused */
   remiCodeFromeBBlock (ebp, assignment);