Applied patch #2762516
[fw/sdcc] / src / avr / ralloc.c
index 6efc4aedf2f214354b96f5ecd448c6ee42cd1b2e..512edc4fdf7f068101e6c1677cfac87a316ef301 100644 (file)
@@ -549,31 +549,6 @@ nfreeRegsType (int type)
        return nFreeRegs (type);
 }
 
-
-/*-----------------------------------------------------------------*/
-/* allDefsOutOfRange - all definitions are out of a range          */
-/*-----------------------------------------------------------------*/
-static bool
-allDefsOutOfRange (bitVect * defs, int fseq, int toseq)
-{
-       int i;
-
-       if (!defs)
-               return TRUE;
-
-       for (i = 0; i < defs->size; i++) {
-               iCode *ic;
-
-               if (bitVectBitValue (defs, i) &&
-                   (ic = hTabItemWithKey (iCodehTab, i)) &&
-                   (ic->seq >= fseq && ic->seq <= toseq))
-
-                       return FALSE;
-       }
-
-       return TRUE;
-}
-
 /*-----------------------------------------------------------------*/
 /* computeSpillable - given a point find the spillable live ranges */
 /*-----------------------------------------------------------------*/
@@ -635,16 +610,6 @@ rematable (symbol * sym, eBBlock * ebp, iCode * ic)
        return sym->remat;
 }
 
-/*-----------------------------------------------------------------*/
-/* notUsedInBlock - not used in this block                         */
-/*-----------------------------------------------------------------*/
-static int
-notUsedInBlock (symbol * sym, eBBlock * ebp, iCode * ic)
-{
-       return (!bitVectBitsInCommon (sym->defs, ebp->usesDefs) &&
-               allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq));
-}
-
 /*-----------------------------------------------------------------*/
 /* notUsedInRemaining - not used or defined in remain of the block */
 /*-----------------------------------------------------------------*/
@@ -727,7 +692,7 @@ leastUsedLR (set * sset)
 
        }
 
-       setToNull ((void **) &sset);
+       setToNull ((void *) &sset);
        sym->blockSpil = 0;
        return sym;
 }
@@ -936,7 +901,8 @@ selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
                /* check if there are any live ranges that not
                   used in the remainder of the block */
                if (!_G.blockSpil &&
-                   (selectS =
+                   !isiCodeInFunctionCall (ic) &&
+                    (selectS =
                     liveRangesWith (lrcs, notUsedInRemaining, ebp, ic))) {
                        sym = leastUsedLR (selectS);
                        if (sym != forSym) {
@@ -1198,6 +1164,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 */
@@ -1398,6 +1365,12 @@ serialRegAssign (eBBlock ** ebbs, int count)
                                int willCS;
                                int j=0;
 
+                               /* Make sure any spill location is definately allocated */
+                               if (sym->isspilt && !sym->remat && sym->usl.spillLoc &&
+                                   !sym->usl.spillLoc->allocreq) {
+                                       sym->usl.spillLoc->allocreq++;
+                               }
+
                                /* if it does not need or is spilt 
                                   or is already assigned to registers
                                   or will not live beyond this instructions */
@@ -1428,6 +1401,17 @@ 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) {
@@ -1845,8 +1829,6 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
 
 }
 
-#define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
-
 
 /*-----------------------------------------------------------------*/
 /* packRegsForOneuse : - will reduce some registers for single Use */
@@ -2252,8 +2234,10 @@ setDefaultRegs (eBBlock ** ebbs, int count)
 /* assignRegisters - assigns registers to each live range as need  */
 /*-----------------------------------------------------------------*/
 void
-avr_assignRegisters (eBBlock ** ebbs, int count)
+avr_assignRegisters (ebbIndex * ebbi)
 {
+       eBBlock ** ebbs = ebbi->bbOrder;
+       int count = ebbi->count;
        iCode *ic;
        int i;
 
@@ -2265,8 +2249,12 @@ avr_assignRegisters (eBBlock ** ebbs, int count)
        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);
+               dumpEbbsToFileExt (DUMP_PACK, ebbi);
 
        /* first determine for each live range the number of 
           registers & the type of registers required for each */
@@ -2299,7 +2287,7 @@ avr_assignRegisters (eBBlock ** ebbs, int count)
        redoStackOffsets ();
 
        if (options.dump_rassgn)
-               dumpEbbsToFileExt (DUMP_RASSGN, ebbs, count);
+               dumpEbbsToFileExt (DUMP_RASSGN, ebbi);
 
        /* now get back the chain */
        ic = iCodeLabelOptimize (iCodeFromeBBlock (ebbs, count));
@@ -2311,8 +2299,8 @@ avr_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 */
 
        return;