* src/mcs51/ralloc.c (deassignLR),
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 5 Aug 2004 08:29:15 +0000 (08:29 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 5 Aug 2004 08:29:15 +0000 (08:29 +0000)
* src/ds390/ralloc.c (deassignLR),
* src/hc08/ralloc.c (deassignLR),
* src/z80/ralloc.c (deassignLR),
* src/pic/ralloc.c (deassignLR),
* src/pic16/ralloc.c (deassignLR),
* src/avr/ralloc.c (deassignLR),
* src/SDCClrange.c (findRecursiveSucc, findRecursivePred, findPrevUse,
rlivePoint): fixed another part of bug #971834

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3422 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCClrange.c
src/avr/ralloc.c
src/ds390/ralloc.c
src/hc08/ralloc.c
src/mcs51/ralloc.c
src/pic/ralloc.c
src/pic16/ralloc.c
src/z80/ralloc.c

index 55fd9c8defd06b3fc09022f691c1476328ed01b0..8c6b6f4ee0bb1b39c16faf2cbd13aaee367b7f82 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2004-08-05 Erik Petrich <epetrich AT ivorytower.norman.ok.us>
+
+       * src/mcs51/ralloc.c (deassignLR),
+       * src/ds390/ralloc.c (deassignLR),
+       * src/hc08/ralloc.c (deassignLR),
+       * src/z80/ralloc.c (deassignLR),
+       * src/pic/ralloc.c (deassignLR),
+       * src/pic16/ralloc.c (deassignLR),
+       * src/avr/ralloc.c (deassignLR),
+       * src/SDCClrange.c (findRecursiveSucc, findRecursivePred, findPrevUse,
+       rlivePoint): fixed another part of bug #971834
+
 2004-08-04 Erik Petrich <epetrich AT ivorytower.norman.ok.us>
 
        * src/z80/main.c: enabled "critical" keyword
index 0c6fbc78f449a1c62917ba91020f205a4a73a958..31a678b2d86f8ee48ff0487dc112bb835fe357b5 100644 (file)
@@ -321,8 +321,88 @@ void unvisitBlocks (eBBlock ** ebbs, int count)
     ebbs[i]->visited = 0;
 }
 
+/*------------------------------------------------------------------*/
+/* findRecursiveSucc - build a bit vector of recursive successors   */
+/*------------------------------------------------------------------*/
+DEFSETFUNC (findRecursiveSucc)
+{
+  eBBlock *ebp = item;
+  V_ARG (bitVect *, succVect);
+  
+  if (ebp->visited)
+    return 0;
+  
+  ebp->visited = 1;
+  bitVectSetBit (succVect, ebp->bbnum);
+  applyToSet (ebp->succList, findRecursiveSucc, succVect);
+  return 0;
+}
+
+
+/*------------------------------------------------------------------*/
+/* findRecursivePred - build a bit vector of recursive predecessors */
+/*------------------------------------------------------------------*/
+DEFSETFUNC (findRecursivePred)
+{
+  eBBlock *ebp = item;
+  V_ARG (bitVect *, predVect);
+  
+  if (ebp->visited)
+    return 0;
+  
+  ebp->visited = 1;
+  bitVectSetBit (predVect, ebp->bbnum);
+  applyToSet (ebp->predList, findRecursivePred, predVect);
+  return 0;
+}
+
+
+/*------------------------------------------------------------------*/
+/* findPrevUse - handle degenerate case of a symbol used prior to   */
+/*               findNextUse() marking any definition.              */
+/*------------------------------------------------------------------*/
+void
+findPrevUse (eBBlock *ebp, iCode *ic, operand *op, eBBlock **ebbs, int count)
+{
+  int i;
+  bitVect * succVect;
+  bitVect * predVect;
+  
+  /* If liveness is already known, then a previous call to findNextUse() */
+  /* has already taken care of everything. */
+  if (ic && bitVectBitValue(ic->rlive, op->key))
+    return;
+  
+  if (op->isaddr)
+    OP_SYMBOL (op)->isptr = 1;
+
+  OP_SYMBOL (op)->key = op->key;
+  
+  /* Otherwise, it appears that this symbol was used prior to definition.     */
+  /* Just fix the live range; we'll deal with a diagnostic message elsewhere. */
+  /* If the symbol use was in a loop, we need to extend the live range to the */
+  /* outermost loop. */
+  unvisitBlocks (ebbs, count);
+  succVect = newBitVect (count);
+  applyToSet (ebp->succList, findRecursiveSucc, succVect);
+  unvisitBlocks (ebbs, count);
+  predVect = newBitVect (count);
+  applyToSet (ebp->predList, findRecursivePred, predVect);
+  
+  /* Blocks that are both recursively predecessors and successors are in */
+  /* a loop with the current iCode. Mark the operand as alive in them.   */
+  for (i = 0; i < count; i++)
+    {
+      if (bitVectBitValue(succVect, i) && bitVectBitValue(predVect, i))
+        markAlive (ebbs[i]->sch, ebbs[i]->ech, op->key);
+    }
+  
+  freeBitVect (succVect);
+  freeBitVect (predVect);
+}
+
 /*-----------------------------------------------------------------*/
-/* unvisitBlocks - clears visited in all blocks                    */
+/* incUsed - increment a symbol's usage count                      */
 /*-----------------------------------------------------------------*/
 void
 incUsed (iCode *ic, operand *op)
@@ -387,6 +467,7 @@ rlivePoint (eBBlock ** ebbs, int count)
              if (!IS_ITEMP(IC_JTCOND(ic)))
                continue;
 
+             findPrevUse (ebbs[i], ic->prev, IC_JTCOND(ic), ebbs, count);
              unvisitBlocks(ebbs, count);
              ic->rlive = bitVectSetBit (ic->rlive, IC_JTCOND(ic)->key);
              findNextUse (ebbs[i], ic->next, IC_JTCOND(ic));
@@ -401,6 +482,7 @@ rlivePoint (eBBlock ** ebbs, int count)
              if (!IS_ITEMP(IC_COND(ic)))
                continue;
 
+             findPrevUse (ebbs[i], ic->prev, IC_COND(ic), ebbs, count);
              unvisitBlocks (ebbs, count);
              ic->rlive = bitVectSetBit (ic->rlive, IC_COND(ic)->key);
              findNextUse (ebbs[i], ic->next, IC_COND(ic));
@@ -414,6 +496,7 @@ rlivePoint (eBBlock ** ebbs, int count)
              if (IS_ITEMP(IC_LEFT(ic)))
                {
 
+                 findPrevUse (ebbs[i], ic->prev, IC_LEFT(ic), ebbs, count);
                  unvisitBlocks(ebbs, count);
                  ic->rlive = bitVectSetBit (ic->rlive, IC_LEFT(ic)->key);
                  findNextUse (ebbs[i], ic->next, IC_LEFT(ic));
@@ -439,6 +522,7 @@ rlivePoint (eBBlock ** ebbs, int count)
              incUsed (ic, IC_RIGHT(ic));
              if (IS_ITEMP(IC_RIGHT(ic)))
                {
+                 findPrevUse (ebbs[i], ic->prev, IC_RIGHT(ic), ebbs, count);
                  unvisitBlocks(ebbs, count);
                  ic->rlive = bitVectSetBit (ic->rlive, IC_RIGHT(ic)->key);
                  findNextUse (ebbs[i], ic->next, IC_RIGHT(ic));
@@ -450,6 +534,10 @@ rlivePoint (eBBlock ** ebbs, int count)
 
          if (IS_ITEMP(IC_RESULT(ic)))
            {
+             if (POINTER_SET(ic))
+               {
+                 findPrevUse (ebbs[i], ic->prev, IC_RESULT(ic), ebbs, count);
+               }
              unvisitBlocks(ebbs, count);
              ic->rlive = bitVectSetBit (ic->rlive, IC_RESULT(ic)->key);
              findNextUse (ebbs[i], ic->next, IC_RESULT(ic));
index fce0f8024b6719639408598889601acee6eaf825..706ae3cefffb6905e65da6b653189803a4996782 100644 (file)
@@ -1163,6 +1163,7 @@ deassignLRs (iCode * ic, eBBlock * ebp)
                            (result = OP_SYMBOL (IC_RESULT (ic))) &&    /* has a result */
                            result->liveTo > ic->seq && /* and will live beyond this */
                            result->liveTo <= ebp->lSeq &&      /* does not go beyond this block */
+                           result->liveFrom == ic->seq &&    /* does not start before here */
                            result->regType == sym->regType &&  /* same register types */
                            result->nRegs &&    /* which needs registers */
                            !result->isspilt && /* and does not already have them */
index 1bb265e9d067bd5940b25cb962f36ae8649d3f5d..c25c6d46fa424971e15aaa1f168eff14dc860f91 100644 (file)
@@ -991,6 +991,7 @@ deassignLRs (iCode * ic, eBBlock * ebp)
               (result = OP_SYMBOL (IC_RESULT (ic))) &&  /* has a result */
               result->liveTo > ic->seq &&       /* and will live beyond this */
               result->liveTo <= ebp->lSeq &&    /* does not go beyond this block */
+             result->liveFrom == ic->seq &&    /* does not start before here */
               result->regType == sym->regType &&        /* same register types */
               result->nRegs &&  /* which needs registers */
               !result->isspilt &&       /* and does not already have them */
index 25c75138bf9ab286e144dae5ad27ef3e0e5b2d7e..382c2edeac9da19d1e9f5d6da4cae74d5793e868 100644 (file)
@@ -1032,6 +1032,7 @@ deassignLRs (iCode * ic, eBBlock * ebp)
              (result = OP_SYMBOL (IC_RESULT (ic))) &&  /* has a result */
              result->liveTo > ic->seq &&       /* and will live beyond this */
              result->liveTo <= ebp->lSeq &&    /* does not go beyond this block */
+             result->liveFrom == ic->seq &&    /* does not start before here */
              result->regType == sym->regType &&        /* same register types */
              result->nRegs &&  /* which needs registers */
              !result->isspilt &&       /* and does not already have them */
index ffa28c056bd95fc117ada6db7644503977f0b476..ec01a64642e23b935a55a847a41fa9527828b4a5 100644 (file)
@@ -981,6 +981,7 @@ deassignLRs (iCode * ic, eBBlock * ebp)
              (result = OP_SYMBOL (IC_RESULT (ic))) &&  /* has a result */
              result->liveTo > ic->seq &&       /* and will live beyond this */
              result->liveTo <= ebp->lSeq &&    /* does not go beyond this block */
+             result->liveFrom == ic->seq &&    /* does not start before here */
              result->regType == sym->regType &&        /* same register types */
              result->nRegs &&  /* which needs registers */
              !result->isspilt &&       /* and does not already have them */
@@ -1409,7 +1410,7 @@ static void fillGaps()
                bitVectBitValue(_G.totRegAssigned,i) == 0) /* and are still assigned to registers */
                continue ;
 
-               clr = hTabItemWithKey(liveRanges,i);
+           clr = hTabItemWithKey(liveRanges,i);
            assert(clr);
 
            /* mark these registers as used */
index 3be54b56bbf0d5e48f1b3afc8797324543b290b6..d12186f789872bce39a75754bf0a1e2a221836fb 100644 (file)
@@ -2066,7 +2066,7 @@ deassignLRs (iCode * ic, eBBlock * ebp)
                                (result = OP_SYMBOL (IC_RESULT (ic))) &&        /* has a result */
                                result->liveTo > ic->seq &&     /* and will live beyond this */
                                result->liveTo <= ebp->lSeq &&  /* does not go beyond this block */
-                               result->regType == sym->regType &&      /* same register types */
+                               result->liveFrom == ic->seq &&    /* does not start before here */                              result->regType == sym->regType &&      /* same register types */
                                result->nRegs &&        /* which needs registers */
                                !result->isspilt &&     /* and does not already have them */
                                !result->remat &&
index eeb4e787a1c39790fa0515559f2d3391eca43c97..4a026fcc1a7c31b13d80fb89bcc518a78ce0c08f 100644 (file)
@@ -2000,6 +2000,7 @@ deassignLRs (iCode * ic, eBBlock * ebp)
              (result = OP_SYMBOL (IC_RESULT (ic))) &&  /* has a result */
              result->liveTo > ic->seq &&       /* and will live beyond this */
              result->liveTo <= ebp->lSeq &&    /* does not go beyond this block */
+             result->liveFrom == ic->seq &&    /* does not start before here */
              result->regType == sym->regType &&        /* same register types */
              result->nRegs &&  /* which needs registers */
              !result->isspilt &&       /* and does not already have them */
index 53f212194944199e8cfef500ff33ee76d2ab380d..b480b990eac2abb6d6975224ce93800ea826ebc0 100644 (file)
@@ -886,6 +886,7 @@ deassignLRs (iCode * ic, eBBlock * ebp)
              (result = OP_SYMBOL (IC_RESULT (ic))) &&  /* has a result */
              result->liveTo > ic->seq &&       /* and will live beyond this */
              result->liveTo <= ebp->lSeq &&    /* does not go beyond this block */
+             result->liveFrom == ic->seq &&    /* does not start before here */
              result->regType == sym->regType &&        /* same register types */
              result->nRegs &&  /* which needs registers */
              !result->isspilt &&       /* and does not already have them */