cleaned up the mess I left behind
[fw/sdcc] / src / SDCCloop.c
index d65d40c78af651e8c12e2766201d18d09120bba6..55021f34798aa1a0d80e920e8a9a29bd86e22f6a 100644 (file)
@@ -282,6 +282,7 @@ DEFSETFUNC (createLoop)
     }
 
   aloop->entry = ep->to;
+
   /* set max & min dfNum for loopRegion */
   for ( block = setFirstItem(aloop->regBlocks); block; 
        block = setNextItem(aloop->regBlocks)) {
@@ -292,10 +293,22 @@ DEFSETFUNC (createLoop)
   /* 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) {
-             loopInsert(&aloop->regBlocks,ebbs[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;
@@ -462,7 +475,7 @@ loopInvariants (region * theLoop, eBBlock ** ebbs, int count)
          int lin, rin;
          cseDef *ivar;
 
-         /* jwk: TODO this is only needed if the call is between
+         /* 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 */
@@ -884,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)
@@ -1101,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;
        }
     }
@@ -1184,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 */