Yet another reg alloc bug uncovered by ds390
[fw/sdcc] / src / mcs51 / ralloc.c
index 368f58fa7ae72682b7ca981b9a5f0cecc514cf0d..2a3726c340fe7a6fd705f54add137b535b9f6c08 100644 (file)
@@ -479,20 +479,19 @@ static symbol *createStackSpil (symbol *sym)
        temporarily turn it off ; we also
        turn off memory model to prevent
        the spil from going to the external storage
-       and turn off overlaying 
     */
     
     useXstack = options.useXstack;
     model = options.model;
-    noOverlay = options.noOverlay;
-    options.noOverlay = 1;
+/*     noOverlay = options.noOverlay; */
+/*     options.noOverlay = 1; */
     options.model = options.useXstack = 0;
 
     allocLocal(sloc);
 
     options.useXstack = useXstack;
     options.model     = model;
-    options.noOverlay = noOverlay;
+/*     options.noOverlay = noOverlay; */
     sloc->isref = 1; /* to prevent compiler warning */
     
     /* if it is on the stack then update the stack */
@@ -628,11 +627,13 @@ static symbol *selectSpil (iCode *ic, eBBlock *ebp, symbol *forSym)
           used in the remainder of the block */
        if (!_G.blockSpil && (selectS = liveRangesWith(lrcs,notUsedInRemaining,ebp,ic))) {
            sym = leastUsedLR (selectS);
-           if (!sym->remat) {
-               sym->remainSpil = 1;
-               _G.blockSpil++;
+           if (sym != forSym) {
+               if (!sym->remat) {
+                   sym->remainSpil = 1;
+                   _G.blockSpil++;
+               }
+               return sym;
            }
-           return sym;
        }
     }   
 
@@ -869,7 +870,7 @@ static void deassignLRs (iCode *ic, eBBlock *ebp)
                  sym->nRegs) >= result->nRegs)
                ) {
                
-               for (i = 0 ; i < max(sym->nRegs,result->nRegs) ; i++)
+               for (i = 0 ; i < result->nRegs ; i++)
                    if (i < sym->nRegs )
                        result->regs[i] = sym->regs[i] ;
                    else
@@ -1794,7 +1795,7 @@ static iCode *packRegsForOneuse (iCode *ic, operand *op , eBBlock *ebp)
 
     /* also make sure the intervenening instructions
        don't have any thing in far space */
-    for (dic = dic->next ; dic && dic != ic ; dic = dic->next) {
+    for (dic = dic->next ; dic && dic != ic && sic != ic; dic = dic->next) {
                
        /* if there is an intervening function call then no */
        if (dic->op == CALL || dic->op == PCALL)
@@ -2156,7 +2157,7 @@ static void packRegisters (eBBlock *ebp)
           can be eliminated for return statements */
        if ((ic->op == RETURN || ic->op == SEND) &&
            !isOperandInFarSpace(IC_LEFT(ic))    &&
-           !options.model)
+           options.model == MODEL_SMALL)
            packRegsForOneuse (ic,IC_LEFT(ic),ebp);     
 
        /* if pointer set & left has a size more than
@@ -2306,8 +2307,13 @@ void mcs51_assignRegisters (eBBlock **ebbs, int count)
     /* redo that offsets for stacked automatic variables */
     redoStackOffsets ();
 
-    if (options.dump_rassgn)
+    if (options.dump_rassgn) {
        dumpEbbsToFileExt(".dumprassgn",ebbs,count);
+       dumpLiveRanges(".lrange",liveRanges);
+    }
+
+    /* do the overlaysegment stuff SDCCmem.c */
+    doOverlays(ebbs,count);
 
     /* now get back the chain */
     ic = iCodeLabelOptimize(iCodeFromeBBlock (ebbs,count));