more LRH debugging junk
[fw/sdcc] / src / SDCCcflow.c
index 2dc5313511da4c1957ea4329bcaff58817075de8..2da48baa65430991aebd56a1ed34b4d16e0d74a4 100644 (file)
@@ -1,3 +1,9 @@
+//#define LIVERANGEHUNT
+#ifdef LIVERANGEHUNT
+  #define LRH(x) x
+#else
+  #define LRH(x)
+#endif
 /*-------------------------------------------------------------------------
 
   SDCCcflow.c - source file for control flow analysis
@@ -120,7 +126,6 @@ eBBSuccessors (eBBlock ** ebbs, int count)
 
          if (ebbs[i]->ech)
            {
-
              if (ebbs[i]->ech->op != GOTO &&
                  ebbs[i]->ech->op != RETURN &&
                  ebbs[i]->ech->op != JUMPTABLE)
@@ -132,6 +137,18 @@ eBBSuccessors (eBBlock ** ebbs, int count)
 
                  addSuccessor (ebbs[i], ebbs[j]);      /* add it */
                }
+             else
+               {
+                 int j=i;
+                 while (j--) {
+                   if (ebbs[j]->ech && ebbs[j]->ech->op==IFX &&
+                       (isSymbolEqual(IC_TRUE(ebbs[j]->ech), ebbs[i]->entryLabel) ||
+                        isSymbolEqual(IC_FALSE(ebbs[j]->ech), ebbs[i]->entryLabel))) {
+                     LRH(printf ("%s has a conditional exit from %s\n", ebbs[i]->entryLabel->name, ebbs[j]->entryLabel->name));
+                     ebbs[i]->hasConditionalExit=1;
+                   }
+                 }
+               }
            }                   /* no instructions in the block */
          /* could happen for dummy blocks */
          else
@@ -161,7 +178,7 @@ eBBSuccessors (eBBlock ** ebbs, int count)
              switch (ic->op)
                {
                case GOTO:      /* goto has edge to label */
-                 succ = eBBWithEntryLabel (ebbs, ic->argLabel.label, count);
+                 succ = eBBWithEntryLabel (ebbs, ic->label, count);
                  break;
 
                case IFX:       /* conditional jump */
@@ -425,3 +442,35 @@ computeControlFlow (eBBlock ** ebbs, int count, int reSort)
   qsort (ebbs, saveCount, sizeof (eBBlock *), dfNumCompare);
 
 }
+
+/*-----------------------------------------------------------------*/
+/* returnAtEnd - returns 1 if Basic Block has a return at the end  */
+/*               of it                                             */
+/*-----------------------------------------------------------------*/
+int returnAtEnd (eBBlock *ebp)
+{
+    /* case 1.
+       This basic block ends in a return statment 
+    */
+    if (ebp->ech && ebp->ech->op == RETURN) return 1;
+
+    /* case 2.
+       This basic block has only one successor and that
+       successor has only one return statement
+    */
+    if (elementsInSet(ebp->succList) == 1) {
+       eBBlock *succ = setFirstItem(ebp->succList);
+       /* could happen for dummy blocks */
+       if (!succ->sch || !succ->ech) return 0;
+
+       /* first iCode is a return */
+       if (succ->sch->op == RETURN) return 2;
+
+       /* or first iCode is a label & the next &
+          last icode is a return */
+       if (succ->sch->op == LABEL && succ->sch->next == succ->ech &&
+           succ->ech->op == RETURN ) return 2;
+    }
+
+    return 0;
+}