]> git.gag.com Git - fw/sdcc/blobdiff - src/SDCClrange.c
Applied liferange patch from Klaus Flittner <klaus_flittner@gmx.de>
[fw/sdcc] / src / SDCClrange.c
index a85c5ff19b64fa6c5eb532e1058650473e4c6375..b34565bcd5fa3618b0fead1894ea29b73558b2f1 100644 (file)
@@ -124,10 +124,14 @@ isLastUse (operand * op, eBBlock * ebp, iCode * ic,
   if (usedInRemaining (op, ic))
     return 0;
 
-  /* if not then check any of the successor blocks use it */
-  for (i = 0; i < count; ebbs[i++]->visited = 0);
-  if (applyToSet (ebp->succList, isOpAlive, op, ebp, ic))
-    return 0;
+  /* if not then check any of the following blocks use it */
+  for (i = 0; i < count; i++)
+    {
+      if (ebbs[i]->fSeq <= ebp->fSeq)
+       continue;
+      if (usedInRemaining (op, ebbs[i]->sch))
+       return 0;
+    }
 
   /* this is the last use */
   return 1;
@@ -307,23 +311,33 @@ operandLUse (operand * op, eBBlock ** ebbs,
 
       /* if this is a SEND then the toRange should be extended
         to the call */
-      if (ic->op == SEND) {
+      if (ic->op == SEND)
+        {
          iCode *lic ;
-         for (lic = ic->next ; lic ; lic = lic->next) {
-             if (lic->op == CALL || lic->op == PCALL) break;
-         }
+         for (lic = ic->next ; lic ; lic = lic->next)
+           {
+             if (lic->op == CALL || lic->op == PCALL)
+               break;
+           }
          /* 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 
+         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);
+      if (ebp->partOfLoop)
+        {
+         region *aloop;
+
+         aloop = setFirstItem (ebp->partOfLoop);
+         for (; aloop; aloop = setNextItem (ebp->partOfLoop))
+           {
+             if (hasIncomingDefs (aloop, op))
+               torange = findLoopEndSeq (aloop);
+           }
        }
-      
+
       op = operandFromOperand (op);
       setToRange (op, torange, FALSE);
     }
@@ -702,8 +716,8 @@ void
 computeLiveRanges (eBBlock ** ebbs, int count)
 {
   int i = 0;
-  /* sequence the code the live ranges are computed 
-     in terms of this sequence additionally the   
+  /* sequence the code the live ranges are computed
+     in terms of this sequence additionally the
      routine will also create a hashtable of instructions */
   iCodeSeq = 0;
   setToNull ((void **) &iCodehTab);
@@ -712,6 +726,9 @@ computeLiveRanges (eBBlock ** ebbs, int count)
   iCodeSeqhTab = newHashTable (iCodeKey);
   sequenceiCode (ebbs, count);
 
+  /* add blocks between loop blocks as part of that loop */
+  addLoopBlocks (ebbs, count);
+
   /* call routine to mark the from & to live ranges for
      variables used */
   setToNull ((void **) &liveRanges);