* src/mcs51/gen.c (genCpl): quick fix for bug #974835
[fw/sdcc] / src / SDCCloop.c
index e68eabf916a3431d769df30bead5152b621140f0..52cc19affc7c0ef5a1e9c124a9ae442710bd6f04 100644 (file)
@@ -46,7 +46,7 @@ newInduction (operand * sym, unsigned int op,
   ip->op = op;
   ip->cval = constVal;
   ip->ic = ic;
-  updateSpillLocation(ic,1);
+//updateSpillLocation(ic,1);
   return ip;
 }
 
@@ -131,7 +131,7 @@ intersectLoopSucc (set * lexits, eBBlock ** ebbs)
 
   if (!exit)
     return NULL;
-
+  
   succVect = bitVectCopy (exit->succVect);
 
   for (exit = setNextItem (lexits); exit;
@@ -235,19 +235,10 @@ DEFSETFUNC (addToExitsMarkDepth)
   if (ebp->depth<depth)
     ebp->depth = depth;
 
-  if (getenv ("SDCC_LRKLAUS"))
-    {
-      /* put the loop region info in the block */
-      if (!isinSet (ebp->KpartOfLoop, lr))
-        addSetHead (&ebp->KpartOfLoop, lr);
-    }
-  else
-    {
-      /* NOTE: here we will update only the inner most loop
-         that it is a part of */
-      if (!ebp->partOfLoop)
-        ebp->partOfLoop = lr;
-    }
+  /* NOTE: here we will update only the inner most loop
+     that it is a part of */
+  if (!ebp->partOfLoop)
+    ebp->partOfLoop = lr;
 
   /* if any of the successors go out of the loop then */
   /* we add this one to the exits */
@@ -388,7 +379,22 @@ DEFSETFUNC (pointerAssigned)
   eBBlock *ebp = item;
   V_ARG (operand *, op);
 
-  return ebp->hasFcall || bitVectBitValue (ebp->ptrsSet, op->key);
+  if (ebp->hasFcall)
+    return 1;
+
+  if (bitVectBitValue (ebp->ptrsSet, op->key))
+    return 1;
+
+  /* Unfortunately, one of the other pointer set operations  */
+  /* may be using an alias of this operand, and the above    */
+  /* test would miss it. To be thorough, some aliasing       */
+  /* analysis should be done here. In the meantime, be       */
+  /* conservative and assume any other pointer set operation */
+  /* is dangerous                                            */
+  if (!bitVectIsZero (ebp->ptrsSet))
+    return 1;
+  
+  return 0;
 }
 
 /*-----------------------------------------------------------------*/
@@ -473,6 +479,13 @@ loopInvariants (region * theLoop, eBBlock ** ebbs, int count)
 
          if (SKIP_IC (ic) || POINTER_SET (ic) || ic->op == IFX)
            continue;
+         
+         /* iTemp assignment from a literal may be invariant, but it
+            will needlessly increase register pressure if the
+            iCode(s) that use this iTemp are not also invariant */
+         if (ic->op=='=' && IS_ITEMP (IC_RESULT (ic))
+             && IS_OP_LITERAL (IC_RIGHT (ic)))
+           continue;
 
          /* if result is volatile then skip */
          if (IC_RESULT (ic) &&
@@ -516,7 +529,8 @@ loopInvariants (region * theLoop, eBBlock ** ebbs, int count)
              applyToSet (theLoop->regBlocks, hasNonPtrUse, IC_LEFT (ic)))
            continue;
 
-         /* if both the left & right are invariants : then check that */
+
+          /* if both the left & right are invariants : then check that */
          /* this definition exists in the out definition of all the  */
          /* blocks, this will ensure that this is not assigned any   */
          /* other value in the loop , and not used in this block     */
@@ -527,7 +541,7 @@ loopInvariants (region * theLoop, eBBlock ** ebbs, int count)
              eBBlock *sBlock;
              set *lSet = setFromSet (theLoop->regBlocks);
 
-             /* if this block does not dominate all exists */
+             /* if this block does not dominate all exits */
              /* make sure this defintion is not used anywhere else */
              if (!domsAllExits)
                {
@@ -576,7 +590,9 @@ loopInvariants (region * theLoop, eBBlock ** ebbs, int count)
              /* now we know it is a true invariant */
              /* remove it from the insts chain & put */
              /* in the invariant set                */
-             OP_SYMBOL (IC_RESULT (ic))->isinvariant = 1;
+             
+              OP_SYMBOL (IC_RESULT (ic))->isinvariant = 1;
+              SPIL_LOC (IC_RESULT (ic)) = NULL;
              remiCodeFromeBBlock (lBlock, ic);
 
              /* maintain the data flow */
@@ -826,7 +842,6 @@ basicInduction (region * loopReg, eBBlock ** ebbs, int count)
          if (nexits == 1)
            {
              eBBlock *exit = setFirstItem (loopReg->exits);
-
              /* if it is the same block then there is no
                 need to move it about */
              if (exit != lBlock)
@@ -864,7 +879,18 @@ basicInduction (region * loopReg, eBBlock ** ebbs, int count)
                      if (bitVectBitValue (loopSuccs, i))
                        {
 
-                         eBBlock *eblock = ebbs[i];
+                         eBBlock *eblock = NULL;
+                         int j;
+                         
+                         /* Need to search for bbnum == i since ebbs is  */
+                         /* sorted by dfnum; a direct index won't do.  */
+                         for (j=0; j<count; j++)
+                           if (ebbs[j]->bbnum == i)
+                             {
+                               eblock = ebbs[j];
+                               break;
+                             }
+                         assert(eblock);
 
                          /* if the successor does not belong to the loop
                             and will be executed after the loop : then
@@ -1224,57 +1250,3 @@ loopOptimizations (hTab * orderedLoops, eBBlock ** ebbs, int count)
 
   return change;
 }
-
-/*-----------------------------------------------------------------*/
-/* addLoopBlocks - will add all blocks inside a loop to this loop  */
-/* this should fix most of the liverange problems                  */
-/*-----------------------------------------------------------------*/
-void
-addLoopBlocks (eBBlock ** ebbs, int count)
-{
-  region *aloop;
-  struct eBBlock *block;
-  int seqMin, seqMax;
-  int i, j;
-
-  for (i = 0; i < count; i++)
-    {
-      if (!ebbs[i]->KpartOfLoop)
-        continue;
-
-      /* for all loops this block belongs to */
-      /* add inner block not already marked as part of this loop */
-      aloop = setFirstItem (ebbs[i]->KpartOfLoop);
-      for (; aloop; aloop = setNextItem (ebbs[i]->KpartOfLoop))
-        {
-
-          if (aloop->visited)
-            continue;
-
-          aloop->visited = 1;
-
-          /* set max & min Seq for loopRegion */
-          block = setFirstItem (aloop->regBlocks);
-          seqMax = block->lSeq;
-          seqMin = block->fSeq;
-          for (; block; block = setNextItem (aloop->regBlocks))
-           {
-              if (block->lSeq > seqMax)
-                seqMax = block->lSeq;
-              if (block->fSeq < seqMin)
-                seqMin = block->fSeq;
-            }
-
-          /* add all blocks between seqMin, seqMax to loop */
-          for (j = 0; j < count; j++)
-           {
-              if (ebbs[j]->fSeq > seqMin && ebbs[j]->lSeq < seqMax &&
-                  !isinSet (aloop->regBlocks, ebbs[j]))
-               {
-                  if (!isinSet (ebbs[j]->KpartOfLoop, aloop))
-                   addSetHead (&ebbs[j]->KpartOfLoop, aloop);
-               }
-           }
-       }
-    }
-}