LRH commit, only to sync with other developers
[fw/sdcc] / src / SDCCBBlock.c
index 15470f19ac039f8081e05f7f3fd48a4e418ee25b..dac9d8ec5ce3019245d2327fb0c88818da07628b 100644 (file)
@@ -24,7 +24,6 @@
 -------------------------------------------------------------------------*/
 
 #include "common.h"
-#include "newalloc.h"
 
 int eBBNum = 0;
 set *graphEdges = NULL;                /* list of edges in this flow graph */
@@ -65,7 +64,7 @@ neweBBlock ()
 {
   eBBlock *ebb;
 
-  ebb = Safe_calloc (1, sizeof (eBBlock));
+  ebb = Safe_alloc (sizeof (eBBlock));
   return ebb;
 }
 
@@ -77,7 +76,7 @@ newEdge (eBBlock * from, eBBlock * to)
 {
   edge *ep;
 
-  ep = Safe_calloc (1, sizeof (edge));
+  ep = Safe_alloc (sizeof (edge));
 
   ep->from = from;
   ep->to = to;
@@ -103,8 +102,8 @@ FILE *appendDumpFile (int id) {
 
   if (!dumpFilesPtr->filePtr) {
     // not used before, create it
-    strcpy (scratchFileName, srcFileName);
-    strcat (scratchFileName, dumpFilesPtr->ext);
+    strncpyz (scratchFileName, dstFileName, PATH_MAX);
+    strncatz (scratchFileName, dumpFilesPtr->ext, PATH_MAX);
     if (!(dumpFilesPtr->filePtr = fopen (scratchFileName, "w"))) {
       werror (E_FILE_OPEN_ERR, scratchFileName);
       exit (1);
@@ -142,7 +141,9 @@ dumpLiveRanges (int id, hTab * liveRanges)
   } else {
     file = stdout;
   }
-
+  
+  if (currFunc) 
+      fprintf(file,"------------- Func %s -------------\n",currFunc->name);
   for (sym = hTabFirstItem (liveRanges, &k); sym;
        sym = hTabNextItem (liveRanges, &k))
     {
@@ -161,32 +162,8 @@ dumpLiveRanges (int id, hTab * liveRanges)
        {
          fprintf (file, "}{ sir@ %s", sym->usl.spillLoc->rname);
        }
-      fprintf (file, "}");
-
-      /* if assigned to registers */
-      if (sym->nRegs)
-       {
-         if (sym->isspilt)
-           {
-             if (!sym->remat)
-               if (sym->usl.spillLoc)
-                 fprintf (file, "[%s]", (sym->usl.spillLoc->rname[0] ?
-                                         sym->usl.spillLoc->rname :
-                                         sym->usl.spillLoc->name));
-               else
-                 fprintf (file, "[err]");
-             else
-               fprintf (file, "[remat]");
-           }
-         else
-           {
-             int i;
-             fprintf (file, "[");
-             for (i = 0; i < sym->nRegs; i++)
-               fprintf (file, "%s ", port->getRegName (sym->regs[i]));
-             fprintf (file, "]");
-           }
-       }
+      fprintf (file, "} clashes with ");
+      bitVectDebugOn(sym->clashes,file);
       fprintf (file, "\n");
     }
 
@@ -211,9 +188,11 @@ dumpEbbsToFileExt (int id, eBBlock ** ebbs, int count)
   for (i = 0; i < count; i++)
     {
       fprintf (of, "\n----------------------------------------------------------------\n");
-      fprintf (of, "Basic Block %s : loop Depth = %d noPath = %d , lastinLoop = %d\n",
+      fprintf (of, "Basic Block %s : loop Depth(lSeq) = %d(%d) noPath = %d , lastinLoop = %d\n",
               ebbs[i]->entryLabel->name,
               ebbs[i]->depth,
+              (0 /* for now */ &
+               ebbs[i]->depth) ? findLoopEndSeq(ebbs[i]->partOfLoop) : 0,
               ebbs[i]->noPath,
               ebbs[i]->isLastInLoop);
       fprintf (of, "\ndefines bitVector :");
@@ -222,6 +201,10 @@ dumpEbbsToFileExt (int id, eBBlock ** ebbs, int count)
       bitVectDebugOn (ebbs[i]->ldefs, of);
       fprintf (of, "\npointers Set bitvector :");
       bitVectDebugOn (ebbs[i]->ptrsSet, of);
+      if (ebbs[i]->isLastInLoop) {
+             fprintf (of, "\nInductions Set bitvector :");
+             bitVectDebugOn (ebbs[i]->linds, of);
+      }
       fprintf (of, "\n----------------------------------------------------------------\n");
       printiCChain (ebbs[i]->sch, of);
     }
@@ -245,7 +228,7 @@ iCode2eBBlock (iCode * ic)
     ebb->entryLabel = ic->argLabel.label;
   else
     {
-      sprintf (buffer, "_eBBlock%d", eBBNum++);
+      SNPRINTF (buffer, sizeof(buffer), "_eBBlock%d", eBBNum++);
       ebb->entryLabel = newSymbol (buffer, 1);
       ebb->entryLabel->key = labelKey++;
     }
@@ -278,7 +261,7 @@ iCode2eBBlock (iCode * ic)
        {
          ebb->hasFcall = 1;
          if (currFunc)
-           currFunc->hasFcall = 1;
+           FUNC_HASFCALL(currFunc->type) = 1;
        }
 
       /* if the next one is a label */
@@ -438,6 +421,7 @@ addiCodeToeBBlock (eBBlock * ebp, iCode * ic, iCode * ip)
 void 
 remiCodeFromeBBlock (eBBlock * ebb, iCode * ic)
 {
+  wassert (ic->seq>=ebb->fSeq && ic->seq<=ebb->lSeq);
   if (ic->prev)
     ic->prev->next = ic->next;
   else
@@ -462,7 +446,7 @@ iCodeBreakDown (iCode * ic, int *count)
 
   /* allocate for the first entry */
 
-  ebbs = Safe_calloc (1, sizeof (eBBlock **));
+  ebbs = Safe_alloc (sizeof (eBBlock **));
 
   while (loop)
     {
@@ -581,7 +565,7 @@ replaceSymBySym (set * sset, operand * src, operand * dest)
            {
              bitVectUnSetBit (OP_USES (IC_COND (ic)), ic->key);
              IC_COND (ic) = operandFromOperand (dest);
-             OP_USES (dest) = bitVectSetBit (OP_USES (dest), ic->key);
+             OP_USES_SET ((dest), bitVectSetBit (OP_USES (dest), ic->key));
              continue;
            }
 
@@ -590,7 +574,7 @@ replaceSymBySym (set * sset, operand * src, operand * dest)
              bitVectUnSetBit (OP_USES (IC_RIGHT (ic)), ic->key);
              IC_RIGHT (ic) = operandFromOperand (dest);
              IC_RIGHT (ic)->isaddr = 0;
-             OP_USES (dest) = bitVectSetBit (OP_USES (dest), ic->key);
+             OP_USES_SET ((dest), bitVectSetBit (OP_USES (dest), ic->key));
            }
 
          if (isOperandEqual (IC_LEFT (ic), src))
@@ -606,7 +590,7 @@ replaceSymBySym (set * sset, operand * src, operand * dest)
                  IC_LEFT (ic) = operandFromOperand (dest);
                  IC_LEFT (ic)->isaddr = 0;
                }
-             OP_USES (dest) = bitVectSetBit (OP_USES (dest), ic->key);
+             OP_USES_SET ((dest), bitVectSetBit (OP_USES (dest), ic->key));
            }
 
          /* special case for pointer sets */
@@ -616,7 +600,7 @@ replaceSymBySym (set * sset, operand * src, operand * dest)
              bitVectUnSetBit (OP_USES (IC_RESULT (ic)), ic->key);
              IC_RESULT (ic) = operandFromOperand (dest);
              IC_RESULT (ic)->isaddr = 1;
-             OP_USES (dest) = bitVectSetBit (OP_USES (dest), ic->key);
+             OP_USES_SET ((dest), bitVectSetBit (OP_USES (dest), ic->key));
            }
        }
     }