cleaned up the mess I left behind
[fw/sdcc] / src / SDCCloop.c
index 7384fa1364f1c94535369d8b0094bc5d1ec4afee..55021f34798aa1a0d80e920e8a9a29bd86e22f6a 100644 (file)
@@ -259,8 +259,11 @@ 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))
@@ -280,6 +283,32 @@ 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;
@@ -446,11 +475,21 @@ loopInvariants (region * theLoop, eBBlock ** ebbs, int count)
          int lin, rin;
          cseDef *ivar;
 
-         /* if there are function calls in this block and this
-            is a pointer get, the function could have changed it
-            so skip, ISO-C99 according to David A. Long */
-         if (fCallsInBlock && POINTER_GET(ic)) {
-           continue;
+         /* TODO this is only needed if the call is between
+            here and the definition, but I am too lazy to do that now */
+
+         /* if there are function calls in this block */
+         if (fCallsInBlock) {
+
+           /* if this is a pointer get */
+           if (POINTER_GET(ic)) {
+             continue;
+           }
+
+           /* if this is an assignment from a global */
+           if (ic->op=='=' && isOperandGlobal(IC_RIGHT(ic))) {
+             continue;
+           }
          }
 
          if (SKIP_IC (ic) || POINTER_SET (ic) || ic->op == IFX)
@@ -799,13 +838,6 @@ basicInduction (region * loopReg, eBBlock ** ebbs, int count)
          OP_SYMBOL (IC_RESULT (indIc))->isind = 1;
          ip = newInduction (IC_RIGHT (ic), dic->op, litValue, indIc, NULL);
 
-         if (0) {
-           fprintf (stderr, "%s:%d: stupid way to avoid bug #467035, but\n"
-                    "this will keep the regressions tests going.\n",
-                    __FILE__, __LINE__);
-           continue;
-         }
-
          /* replace the inducted variable by the iTemp */
          replaceSymBySym (loopReg->regBlocks, IC_RESULT (ic), IC_RIGHT (ic));
 
@@ -865,9 +897,9 @@ basicInduction (region * loopReg, eBBlock ** ebbs, int count)
                              iCode *newic = newiCode ('=', NULL,
                                        operandFromOperand (IC_RIGHT (ic)));
                              IC_RESULT (newic) = operandFromOperand (IC_RESULT (ic));
-                             OP_DEFS (IC_RESULT (newic)) =
+                             OP_DEFS(IC_RESULT (newic))=
                                bitVectSetBit (OP_DEFS (IC_RESULT (newic)), newic->key);
-                             OP_USES (IC_RIGHT (newic)) =
+                             OP_USES(IC_RIGHT (newic))=
                                bitVectSetBit (OP_USES (IC_RIGHT (newic)), newic->key);
                              /* and add it */
                              if (eblock->sch && eblock->sch->op == LABEL)
@@ -1051,7 +1083,7 @@ loopInduction (region * loopReg, eBBlock ** ebbs, int count)
       /* add the induction variable vector to the last
          block in the loop */
       lastBlock->isLastInLoop = 1;
-      lastBlock->linds = indVect;
+      lastBlock->linds = bitVectUnion(lastBlock->linds,indVect);
     }
 
   setToNull ((void **) &indVars);
@@ -1082,7 +1114,7 @@ DEFSETFUNC (mergeRegions)
       if (lp->entry == theLoop->entry)
        {
          theLoop->regBlocks = unionSets (theLoop->regBlocks,
-                                         lp->regBlocks, THROW_BOTH);
+                                         lp->regBlocks, THROW_DEST);
          lp->merged = 1;
        }
     }
@@ -1151,7 +1183,7 @@ createLoopRegions (eBBlock ** ebbs, int count)
 
   /* for each of these back edges get the blocks that */
   /* constitute the loops                             */
-  applyToSet (bEdges, createLoop, &allRegion);
+  applyToSet (bEdges, createLoop, &allRegion, ebbs,count);
 
   /* now we will create regions from these loops               */
   /* loops with the same entry points are considered to be the */
@@ -1165,6 +1197,7 @@ createLoopRegions (eBBlock ** ebbs, int count)
 
   applyToSet (allRegion, mergeInnerLoops, allRegion, &maxDepth);
   maxDepth++;
+
   /* now create all the exits .. also */
   /* create an ordered set of loops   */
   /* i.e. we process loops in the inner to outer order */