X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fxa51%2Fralloc.c;h=ac0d124b5685e071839b972532f723ae18037250;hb=90bdb43b342189fcb94a398855d43f3f47f96738;hp=3a704d93d1d955e7b0940c17e57f00f0a079a7fb;hpb=1f40e564d92322da50a9917d95112bcecd6b31bb;p=fw%2Fsdcc diff --git a/src/xa51/ralloc.c b/src/xa51/ralloc.c index 3a704d93..ac0d124b 100755 --- a/src/xa51/ralloc.c +++ b/src/xa51/ralloc.c @@ -127,7 +127,7 @@ regs *xa51_regWithMask (unsigned long mask) { /* checkRegsMask - check the consistancy of the regMask redundancy */ /*-----------------------------------------------------------------*/ -void checkRegMask(char *f) { // for debugging purposes only +void checkRegMask(const char *f) { // for debugging purposes only int i; unsigned long regMask=0; @@ -199,8 +199,8 @@ static void freeReg (regs * reg, bool silent) { /* allocReg - allocates register of given size (byte, word, dword) */ /* and type (ptr, gpr, cnd) */ /*-----------------------------------------------------------------*/ -static bool allocReg (short size, short type, symbol *sym, - short offset, bool silent) { +static bool allocReg (unsigned int size, int type, symbol *sym, + int offset, bool silent) { int i; checkRegMask(__FUNCTION__); @@ -329,27 +329,6 @@ static void freeAllRegs (void) { } } -/*-----------------------------------------------------------------*/ -/* 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 */ /*-----------------------------------------------------------------*/ @@ -411,17 +390,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)); - /* return (!bitVectBitsInCommon(sym->defs,ebp->usesDefs)); */ -} - /*-----------------------------------------------------------------*/ /* notUsedInRemaining - not used or defined in remain of the block */ /*-----------------------------------------------------------------*/ @@ -505,7 +473,7 @@ leastUsedLR (set * sset) } - setToNull ((void **) &sset); + setToNull ((void *) &sset); sym->blockSpil = 0; return sym; } @@ -687,7 +655,9 @@ 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 = liveRangesWith (lrcs, notUsedInRemaining, ebp, ic))) + if (!_G.blockSpil && + !isiCodeInFunctionCall (ic) && + (selectS = liveRangesWith (lrcs, notUsedInRemaining, ebp, ic))) { sym = leastUsedLR (selectS); if (sym != forSym) @@ -1015,7 +985,13 @@ serialRegAssign (eBBlock ** ebbs, int count) bitVect *spillable; int willCS; - /* if it does not need or is spilt + /* 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 */ if (!sym->nRegs || @@ -1042,6 +1018,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) { @@ -1469,7 +1455,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; } @@ -2026,7 +2012,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 @@ -2049,7 +2035,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; } } @@ -2073,8 +2059,10 @@ static void packRegisters (eBBlock * ebp) { /* assignRegisters - assigns registers to each live range as need */ /*-----------------------------------------------------------------*/ void -xa51_assignRegisters (eBBlock ** ebbs, int count) +xa51_assignRegisters (ebbIndex * ebbi) { + eBBlock ** ebbs = ebbi->bbOrder; + int count = ebbi->count; iCode *ic; int i; @@ -2086,9 +2074,13 @@ 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); + dumpEbbsToFileExt (DUMP_PACK, ebbi); /* first determine for each live range the number of registers & the type of registers required for each */ @@ -2116,7 +2108,7 @@ xa51_assignRegisters (eBBlock ** ebbs, int count) if (options.dump_rassgn) { - dumpEbbsToFileExt (DUMP_RASSGN, ebbs, count); + dumpEbbsToFileExt (DUMP_RASSGN, ebbi); dumpLiveRanges (DUMP_LRANGE, liveRanges); } @@ -2131,8 +2123,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 ();