X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fpic%2Fralloc.c;h=d12186f789872bce39a75754bf0a1e2a221836fb;hb=0892d3692ded8c67ab4df6b26f603bb8d243e39d;hp=6c67f75c8de2ff5c59f3d0faff04650ca040952f;hpb=08dd337046c6cfa728572976d1a23d3ea5654da6;p=fw%2Fsdcc diff --git a/src/pic/ralloc.c b/src/pic/ralloc.c index 6c67f75c..d12186f7 100644 --- a/src/pic/ralloc.c +++ b/src/pic/ralloc.c @@ -2021,7 +2021,7 @@ deassignLRs (iCode * ic, eBBlock * ebp) if (sym->liveTo > ic->seq) continue; - /* if it was spilt on stack then we can + /* if it was spilt on stack then we can mark the stack spil location as free */ if (sym->isspilt) { @@ -2036,9 +2036,9 @@ deassignLRs (iCode * ic, eBBlock * ebp) if (!bitVectBitValue (_G.regAssigned, sym->key)) continue; - /* special case check if this is an IFX & - the privious one was a pop and the - previous one was not spilt then keep track + /* special case check if this is an IFX & + the privious one was a pop and the + previous one was not spilt then keep track of the symbol */ if (ic->op == IFX && ic->prev && ic->prev->op == IPOP && @@ -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 && @@ -2204,6 +2204,31 @@ xchgPositions: } } +/*------------------------------------------------------------------*/ +/* verifyRegsAssigned - make sure an iTemp is properly initialized; */ +/* it should either have registers or have beed spilled. Otherwise, */ +/* there was an uninitialized variable, so just spill this to get */ +/* the operand in a valid state. */ +/*------------------------------------------------------------------*/ +static void +verifyRegsAssigned (operand *op, iCode * ic) +{ + symbol * sym; + + if (!op) return; + if (!IS_ITEMP (op)) return; + + sym = OP_SYMBOL (op); + if (sym->isspilt) return; + if (!sym->nRegs) return; + if (sym->regs[0]) return; + + werrorfl (ic->filename, ic->lineno, W_LOCAL_NOINIT, + sym->prereqv ? sym->prereqv->name : sym->name); + spillThis (sym); +} + + /*-----------------------------------------------------------------*/ /* serialRegAssign - serially allocate registers to the variables */ /*-----------------------------------------------------------------*/ @@ -2240,7 +2265,7 @@ serialRegAssign (eBBlock ** ebbs, int count) IS_TRUE_SYMOP (IC_RESULT (ic))) OP_SYMBOL (IC_RESULT (ic))->allocreq = 1; - /* take away registers from live + /* take away registers from live ranges that end at this instruction */ deassignLRs (ic, ebbs[i]); @@ -2294,6 +2319,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 */ @@ -2369,9 +2405,43 @@ serialRegAssign (eBBlock ** ebbs, int count) ptrRegSet = 0; } + } } } + + /* Check for and fix any problems with uninitialized operands */ + for (i = 0; i < count; i++) + { + iCode *ic; + + if (ebbs[i]->noPath && + (ebbs[i]->entryLabel != entryLabel && + ebbs[i]->entryLabel != returnLabel)) + continue; + + for (ic = ebbs[i]->sch; ic; ic = ic->next) + { + if (SKIP_IC2 (ic)) + continue; + + if (ic->op == IFX) + { + verifyRegsAssigned (IC_COND (ic), ic); + continue; + } + + if (ic->op == JUMPTABLE) + { + verifyRegsAssigned (IC_JTCOND (ic), ic); + continue; + } + + verifyRegsAssigned (IC_RESULT (ic), ic); + verifyRegsAssigned (IC_LEFT (ic), ic); + verifyRegsAssigned (IC_RIGHT (ic), ic); + } } + } /*-----------------------------------------------------------------*/ @@ -2667,24 +2737,24 @@ regTypeNum () in "data" space */ if (bitVectnBitsOn (sym->defs) == 1 && - (ic = hTabItemWithKey (iCodehTab, - bitVectFirstBit (sym->defs))) && - POINTER_GET (ic) && - !sym->noSpilLoc && - !IS_BITVAR (sym->etype)) { - - - debugLog (" %d - \n", __LINE__); - - /* if remat in data space */ - if (OP_SYMBOL (IC_LEFT (ic))->remat && - DCL_TYPE (aggrToPtr (sym->type, FALSE)) == POINTER) { + (ic = hTabItemWithKey (iCodehTab, + bitVectFirstBit (sym->defs))) && + POINTER_GET (ic) && + !IS_BITVAR (sym->etype) && + (aggrToPtrDclType (operandType (IC_LEFT (ic)), FALSE) == POINTER)) { + + if (ptrPseudoSymSafe (sym, ic)) { + + symbol *psym; + debugLog (" %d - \n", __LINE__); + /* create a psuedo symbol & force a spil */ //X symbol *psym = newSymbol (rematStr (OP_SYMBOL (IC_LEFT (ic))), 1); - symbol *psym = rematStr (OP_SYMBOL (IC_LEFT (ic))); + psym = rematStr (OP_SYMBOL (IC_LEFT (ic))); psym->type = sym->type; psym->etype = sym->etype; + psym->psbase = ptrBaseRematSym (OP_SYMBOL (IC_LEFT (ic))); strcpy (psym->rname, psym->name); sym->isspilt = 1; sym->usl.spillLoc = psym; @@ -4041,7 +4111,7 @@ pic14_assignRegisters (eBBlock ** ebbs, int count) if (options.dump_pack) dumpEbbsToFileExt (DUMP_PACK, ebbs, count); - /* first determine for each live range the number of + /* first determine for each live range the number of registers & the type of registers required for each */ regTypeNum ();