* src/SDCCicode.c (geniCodePostInc, geniCodePreInc, geniCodePostDec,
[fw/sdcc] / src / xa51 / ralloc.c
index 92ba2bdb504851379ec879c21fa81cd8262bfb82..27c88a44f9127195957d2347e000a319039b8725 100755 (executable)
@@ -473,7 +473,7 @@ leastUsedLR (set * sset)
       
     }
   
-  setToNull ((void **) &sset);
+  setToNull ((void *) &sset);
   sym->blockSpil = 0;
   return sym;
 }
@@ -1010,6 +1010,16 @@ serialRegAssign (eBBlock ** ebbs, int count)
          continue;                   
        }
        
+       /* If the live range preceeds the point of definition 
+          then ideally we must take into account registers that 
+          have been allocated after sym->liveFrom but freed
+          before ic->seq. This is complicated, so spill this
+          symbol instead and let fillGaps handle the allocation. */
+       if (sym->liveFrom < ic->seq) {
+           spillThis (sym);
+           continue;                 
+       }
+       
        /* if it has a spillocation & is used less than
           all other live ranges then spill this */
        if (willCS) {
@@ -1437,7 +1447,7 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
   remiCodeFromeBBlock (ebp, ic);
   bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
   hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
-  OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
+  OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
   return 1;
   
 }
@@ -1994,7 +2004,7 @@ static void packRegisters (eBBlock * ebp) {
                      remiCodeFromeBBlock (ebp, ic);
                      bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
                      hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
-                     OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
+                     OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
                      ic = ic->prev;
                    }
                  else
@@ -2017,7 +2027,7 @@ static void packRegisters (eBBlock * ebp) {
                      remiCodeFromeBBlock (ebp, ic);
                      bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
                      hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
-                     OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
+                     OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
                      ic = ic->prev;
                    }
                }
@@ -2054,7 +2064,11 @@ xa51_assignRegisters (eBBlock ** ebbs, int count)
      live ranges reducing some register pressure */
   for (i = 0; i < count; i++)
     packRegisters (ebbs[i]);
-  
+
+  /* liveranges probably changed by register packing
+     so we compute them again */
+  recomputeLiveRanges (ebbs, count);
+
   if (options.dump_pack)
     dumpEbbsToFileExt (DUMP_PACK, ebbs, count);
   
@@ -2099,8 +2113,8 @@ xa51_assignRegisters (eBBlock ** ebbs, int count)
   /* free up any _G.stackSpil locations allocated */
   applyToSet (_G.stackSpil, deallocStackSpil);
   _G.slocNum = 0;
-  setToNull ((void **) &_G.stackSpil);
-  setToNull ((void **) &_G.spiltSet);
+  setToNull ((void *) &_G.stackSpil);
+  setToNull ((void *) &_G.spiltSet);
   /* mark all registers as free */
   freeAllRegs ();