X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fmcs51%2Fralloc.c;h=6be33c026df4f02c1dad728f02452fe7420cb9c2;hb=44eff090172fe33c4fa48eb88ed3f1bb2d10be28;hp=aab641b6e4a9a859722e2353574b0858cca2da0b;hpb=ab0c0d4209a086795b25e9d9a47213d0bb89708d;p=fw%2Fsdcc diff --git a/src/mcs51/ralloc.c b/src/mcs51/ralloc.c index aab641b6..6be33c02 100644 --- a/src/mcs51/ralloc.c +++ b/src/mcs51/ralloc.c @@ -571,7 +571,6 @@ spillThis (symbol * sym) if (!(sym->remat || sym->usl.spillLoc)) createStackSpil (sym); - /* mark it has spilt & put it in the spilt set */ sym->isspilt = sym->spillA = 1; _G.spiltSet = bitVectSetBit (_G.spiltSet, sym->key); @@ -1563,6 +1562,30 @@ regTypeNum (eBBlock *ebbs) continue; } +#ifdef RANGEHUNT + /* if this symbol has only one usage and that is an assignment + to a ruonly, we don't need registers */ + // if this symbol has only one def + if (bitVectnBitsOn (sym->defs)==1) { + printf ("sym: %s has only one usage", sym->name); + // find that usage + if ((ic = hTabItemWithKey (iCodehTab, bitVectFirstBit (sym->defs)))) { + if (ic->op==CALL) { + printf (" for a call "); + // if this is only assigned to a ruonly + if ((ic = hTabItemWithKey (iCodehTab, bitVectFirstBit (sym->defs)))) { + if (ic->op=='=') { + if (OP_SYMBOL(IC_RESULT(ic))->ruonly) { + printf("regTypeNum: %s assigned to %s\n", \ + sym->name, OP_SYMBOL(IC_RESULT(ic))->name); + } + } + } + } + } + } +#endif + /* if the symbol has only one definition & that definition is a get_pointer */ if (bitVectnBitsOn (sym->defs) == 1 && @@ -1575,7 +1598,8 @@ regTypeNum (eBBlock *ebbs) /* and that pointer is remat in data space */ - if (OP_SYMBOL (IC_LEFT (ic))->remat && + if (IS_SYMOP (IC_LEFT (ic)) && + OP_SYMBOL (IC_LEFT (ic))->remat && !IS_CAST_ICODE(OP_SYMBOL (IC_LEFT (ic))->rematiCode) && DCL_TYPE (aggrToPtr (operandType(IC_LEFT(ic)), FALSE)) == POINTER) { @@ -1593,7 +1617,7 @@ regTypeNum (eBBlock *ebbs) /* now this really is an assignment to itself, make it so; it will be optimized out later */ ic->op='='; - IC_RIGHT(ic)=IC_RESULT(ic); + ReplaceOpWithCheaperOp(&IC_RIGHT(ic), IC_RESULT(ic)); IC_LEFT(ic)=NULL; #endif continue; @@ -1630,7 +1654,7 @@ regTypeNum (eBBlock *ebbs) /* registers for true symbols we will */ /* see how things go */ sym->nRegs = 0; - } + } } @@ -1731,16 +1755,15 @@ static int packRegsForAssign (iCode * ic, eBBlock * ebp) { iCode *dic, *sic; - //sym_link *etype = operandType (IC_RIGHT (ic)); if (!IS_ITEMP (IC_RIGHT (ic)) || OP_SYMBOL (IC_RIGHT (ic))->isind || - OP_LIVETO (IC_RIGHT (ic)) > ic->seq - /* why? || IS_BITFIELD (etype) */ ) + OP_LIVETO (IC_RIGHT (ic)) > ic->seq) { return 0; } + /* if the true symbol is defined in far space or on stack then we should not since this will increase register pressure */ if (isOperandInFarSpace(IC_RESULT(ic)) && !farSpacePackable(ic)) { @@ -1810,7 +1833,12 @@ packRegsForAssign (iCode * ic, eBBlock * ebp) { sym_link *etype = operandType (IC_RIGHT (dic)); if (IS_BITFIELD (etype)) - return 0; + { + /* if result is a bit too then it's ok */ + etype = operandType (IC_RESULT (dic)); + if (!IS_BITFIELD (etype)) + return 0; + } } /* if the result is on stack or iaccess then it must be the same atleast one of the operands */ @@ -1835,12 +1863,14 @@ pack: /* replace the result with the result of */ /* this assignment and remove this assignment */ bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key); - IC_RESULT (dic) = IC_RESULT (ic); + ReplaceOpWithCheaperOp(&IC_RESULT (dic), IC_RESULT (ic)); if (IS_ITEMP (IC_RESULT (dic)) && OP_SYMBOL (IC_RESULT (dic))->liveFrom > dic->seq) { OP_SYMBOL (IC_RESULT (dic))->liveFrom = dic->seq; } + // TODO: and the otherway around? + /* delete from liverange table also delete from all the points inbetween and the new one */ @@ -1854,9 +1884,8 @@ pack: 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; - } /*------------------------------------------------------------------*/ @@ -1978,7 +2007,7 @@ reassignAliasedSym (eBBlock *ebp, iCode *assignment, iCode *use, operand *op) /* update the sym's liverange */ if ( OP_LIVETO(op) < ic->seq ) - setToRange(op, ic->seq, FALSE); + setToRange(op, ic->seq, FALSE, OP_SYMBOL(op)->level); /* remove the assignment iCode now that its result is unused */ remiCodeFromeBBlock (ebp, assignment); @@ -2190,7 +2219,6 @@ packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp) OP_SYMBOL (op)->ruonly = 1; return sic; - } /*-----------------------------------------------------------------*/ @@ -2226,7 +2254,7 @@ isBitwiseOptimizable (iCode * ic) /* isCommutativeOp - tests whether this op cares what order its */ /* operands are in */ /*-----------------------------------------------------------------*/ -bool isCommutativeOp(char op) +bool isCommutativeOp(unsigned int op) { if (op == '+' || op == '*' || op == EQ_OP || op == '^' || op == '|' || op == BITWISEAND) @@ -2428,10 +2456,11 @@ accuse: /* packForPush - hueristics to reduce iCode for pushing */ /*-----------------------------------------------------------------*/ static void -packForPush (iCode * ic, eBBlock * ebp) +packForPush (iCode * ic, eBBlock ** ebpp, int blockno) { iCode *dic, *lic; bitVect *dbv; + struct eBBlock * ebp=ebpp[blockno]; if (ic->op != IPUSH || !IS_ITEMP (IC_LEFT (ic))) return; @@ -2449,32 +2478,46 @@ packForPush (iCode * ic, eBBlock * ebp) if (dic->op != '=' || POINTER_SET (dic)) return; - /* make sure the right side does not have any definitions - inbetween */ - dbv = OP_DEFS(IC_RIGHT(dic)); - for (lic = ic; lic && lic != dic ; lic = lic->prev) { - if (bitVectBitValue(dbv,lic->key)) - return ; + if (dic->seq < ebp->fSeq) { // Evelyn did this + int i; + for (i=0; iseq >= ebpp[i]->fSeq && dic->seq <= ebpp[i]->lSeq) { + ebp=ebpp[i]; + break; + } + } + wassert (i!=blockno); // no way to recover from here } - /* make sure they have the same type */ - { - sym_link *itype=operandType(IC_LEFT(ic)); - sym_link *ditype=operandType(IC_RIGHT(dic)); - if (SPEC_USIGN(itype)!=SPEC_USIGN(ditype) || - SPEC_LONG(itype)!=SPEC_LONG(ditype)) - return; - } - /* extend the live range of replaced operand if needed */ - if (OP_SYMBOL(IC_RIGHT(dic))->liveTo < ic->seq) { - OP_SYMBOL(IC_RIGHT(dic))->liveTo = ic->seq; - } + if (IS_SYMOP(IC_RIGHT(dic))) { + /* make sure the right side does not have any definitions + inbetween */ + dbv = OP_DEFS(IC_RIGHT(dic)); + for (lic = ic; lic && lic != dic ; lic = lic->prev) { + if (bitVectBitValue(dbv,lic->key)) + return ; + } + /* make sure they have the same type */ + if (IS_SPEC(operandType(IC_LEFT(ic)))) + { + sym_link *itype=operandType(IC_LEFT(ic)); + sym_link *ditype=operandType(IC_RIGHT(dic)); + + if (SPEC_USIGN(itype)!=SPEC_USIGN(ditype) || + SPEC_LONG(itype)!=SPEC_LONG(ditype)) + return; + } + /* extend the live range of replaced operand if needed */ + if (OP_SYMBOL(IC_RIGHT(dic))->liveTo < ic->seq) { + OP_SYMBOL(IC_RIGHT(dic))->liveTo = ic->seq; + } + bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key); + } + /* we now we know that it has one & only one def & use and the that the definition is an assignment */ - IC_LEFT (ic) = IC_RIGHT (dic); - + ReplaceOpWithCheaperOp(&IC_LEFT (ic), IC_RIGHT (dic)); remiCodeFromeBBlock (ebp, dic); - bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key); hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL); } @@ -2483,10 +2526,11 @@ packForPush (iCode * ic, eBBlock * ebp) /* pressure */ /*-----------------------------------------------------------------*/ static void -packRegisters (eBBlock * ebp) +packRegisters (eBBlock ** ebpp, int blockno) { iCode *ic; int change = 0; + eBBlock *ebp=ebpp[blockno]; while (1) { @@ -2574,7 +2618,8 @@ packRegisters (eBBlock * ebp) if (POINTER_SET (ic)) OP_SYMBOL (IC_RESULT (ic))->uptr = 1; - if (POINTER_GET (ic)) + if (POINTER_GET (ic) && + IS_SYMOP(IC_LEFT (ic))) OP_SYMBOL (IC_LEFT (ic))->uptr = 1; if (!SKIP_IC2 (ic)) @@ -2625,12 +2670,7 @@ packRegisters (eBBlock * ebp) if ((ic->op == RETURN || (ic->op == SEND && ic->argreg == 1)) && !isOperandInFarSpace (IC_LEFT (ic)) && options.model == MODEL_SMALL) { - if (0 && options.stackAuto) { - /* we should check here if acc will be clobbered for stack - offset calculations */ - } else { - packRegsForOneuse (ic, IC_LEFT (ic), ebp); - } + packRegsForOneuse (ic, IC_LEFT (ic), ebp); } /* if pointer set & left has a size more than @@ -2640,16 +2680,15 @@ packRegisters (eBBlock * ebp) !OP_SYMBOL (IC_RESULT (ic))->remat && !IS_OP_RUONLY (IC_RIGHT (ic)) && getSize (aggrToPtr (operandType (IC_RESULT (ic)), FALSE)) > 1) - packRegsForOneuse (ic, IC_RESULT (ic), ebp); /* if pointer get */ if (POINTER_GET (ic) && + IS_SYMOP (IC_LEFT (ic)) && !isOperandInFarSpace (IC_RESULT (ic)) && !OP_SYMBOL (IC_LEFT (ic))->remat && !IS_OP_RUONLY (IC_RESULT (ic)) && getSize (aggrToPtr (operandType (IC_LEFT (ic)), FALSE)) > 1) - packRegsForOneuse (ic, IC_LEFT (ic), ebp); @@ -2674,11 +2713,11 @@ packRegisters (eBBlock * ebp) if (IS_ARITHMETIC_OP (dic)) { bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key); - IC_RESULT (dic) = IC_RESULT (ic); + ReplaceOpWithCheaperOp(&IC_RESULT (dic), IC_RESULT (ic)); 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 @@ -2697,11 +2736,11 @@ packRegisters (eBBlock * ebp) if (dic) { bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key); - IC_RESULT (dic) = IC_RESULT (ic); + ReplaceOpWithCheaperOp(&IC_RESULT (dic), IC_RESULT (ic)); 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; } } @@ -2716,7 +2755,7 @@ packRegisters (eBBlock * ebp) */ if (ic->op == IPUSH) { - packForPush (ic, ebp); + packForPush (ic, ebpp, blockno); } @@ -2758,7 +2797,7 @@ mcs51_assignRegisters (eBBlock ** ebbs, int count) /* change assignments this will remove some live ranges reducing some register pressure */ for (i = 0; i < count; i++) - packRegisters (ebbs[i]); + packRegisters (ebbs, i); if (options.dump_pack) dumpEbbsToFileExt (DUMP_PACK, ebbs, count);