From: epetrich Date: Sun, 21 Sep 2003 18:11:44 +0000 (+0000) Subject: * src/mcs51/ralloc.c (fillGaps), X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=97ed744af842972e55fa4f5e6470b72bfd30976b;p=fw%2Fsdcc * src/mcs51/ralloc.c (fillGaps), * src/ds390/ralloc.c (fillGaps): fixed bug #810093 (yet another register positioning bug) git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2904 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 53508ac5..11f99d9d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-09-21 Erik Petrich + + * src/mcs51/ralloc.c (fillGaps), + * src/ds390/ralloc.c (fillGaps): fixed bug #810093 (yet another + register positioning bug) + 2003-09-21 Bernhard Held * device/lib/_fsdiv.c: replaced (1<<31) by (1ul<<31) diff --git a/src/ds390/ralloc.c b/src/ds390/ralloc.c index 3f04aa23..5da9df45 100644 --- a/src/ds390/ralloc.c +++ b/src/ds390/ralloc.c @@ -1377,6 +1377,7 @@ static void fillGaps() symbol *sym =NULL; int key =0; int loop = 0, change; + int pass; if (getenv("DISABLE_FILL_GAPS")) return; @@ -1468,44 +1469,53 @@ static void fillGaps() sym->regs[i] = getRegGprNoSpil (); } - /* for all its definitions & uses check if the registers + /* For all its definitions check if the registers allocated needs positioning NOTE: we can position only ONCE if more than One positioning required - then give up */ + then give up. + We may need to perform the checks twice; once to + position the registers as needed, the second to + verify any register repositioning is still + compatible. + */ sym->isspilt = 0; - for (i = 0 ; i < sym->defs->size ; i++ ) { - if (bitVectBitValue(sym->defs,i)) { - iCode *ic; - if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ; - if (SKIP_IC(ic)) continue; - assert(isSymbolEqual(sym,OP_SYMBOL(IC_RESULT(ic)))); /* just making sure */ - /* if left is assigned to registers */ - if (IS_SYMOP(IC_LEFT(ic)) && - bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_LEFT(ic))->key)) { - pdone += (positionRegs(sym,OP_SYMBOL(IC_LEFT(ic)))>0); + for (pass=0; pass<2; pass++) { + for (i = 0 ; i < sym->defs->size ; i++ ) { + if (bitVectBitValue(sym->defs,i)) { + iCode *ic; + if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ; + if (SKIP_IC(ic)) continue; + assert(isSymbolEqual(sym,OP_SYMBOL(IC_RESULT(ic)))); /* just making sure */ + /* if left is assigned to registers */ + if (IS_SYMOP(IC_LEFT(ic)) && + bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_LEFT(ic))->key)) { + pdone += (positionRegs(sym,OP_SYMBOL(IC_LEFT(ic)))>0); + } + if (IS_SYMOP(IC_RIGHT(ic)) && + bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RIGHT(ic))->key)) { + pdone += (positionRegs(sym,OP_SYMBOL(IC_RIGHT(ic)))>0); + } + if (pdone > 1) break; } - if (IS_SYMOP(IC_RIGHT(ic)) && - bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RIGHT(ic))->key)) { - pdone += (positionRegs(sym,OP_SYMBOL(IC_RIGHT(ic)))>0); + } + for (i = 0 ; i < sym->uses->size ; i++ ) { + if (bitVectBitValue(sym->uses,i)) { + iCode *ic; + if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ; + if (SKIP_IC(ic)) continue; + if (POINTER_SET(ic) || POINTER_GET(ic)) continue ; + + /* if result is assigned to registers */ + if (IS_SYMOP(IC_RESULT(ic)) && + bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RESULT(ic))->key)) { + pdone += (positionRegs(sym,OP_SYMBOL(IC_RESULT(ic)))>0); + } + if (pdone > 1) break; } - if (pdone > 1) break; - } - } - for (i = 0 ; i < sym->uses->size ; i++ ) { - if (bitVectBitValue(sym->uses,i)) { - iCode *ic; - if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ; - if (SKIP_IC(ic)) continue; - if (POINTER_SET(ic) || POINTER_GET(ic)) continue ; - - /* if result is assigned to registers */ - if (IS_SYMOP(IC_RESULT(ic)) && - bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RESULT(ic))->key)) { - pdone += (positionRegs(sym,OP_SYMBOL(IC_RESULT(ic)))>0); - } - if (pdone > 1) break; - } - } + } + if (pdone == 0) break; /* second pass only if regs repositioned */ + if (pdone > 1) break; + } /* had to position more than once GIVE UP */ if (pdone > 1) { /* UNDO all the changes we made to try this */ diff --git a/src/mcs51/ralloc.c b/src/mcs51/ralloc.c index da326da8..c71bdf8e 100644 --- a/src/mcs51/ralloc.c +++ b/src/mcs51/ralloc.c @@ -1257,7 +1257,8 @@ serialRegAssign (eBBlock ** ebbs, int count) static void fillGaps() { symbol *sym =NULL; - int key =0; + int key =0; + int pass; if (getenv("DISABLE_FILL_GAPS")) return; @@ -1294,52 +1295,89 @@ static void fillGaps() continue ; } + D(printf("Atemping fillGaps on %s: [",sym->name)); /* THERE IS HOPE !!!! */ for (i=0; i < sym->nRegs ; i++ ) { if (sym->regType == REG_PTR) sym->regs[i] = getRegPtrNoSpil (); else sym->regs[i] = getRegGprNoSpil (); + D(printf("%s ", sym->regs[i]->name)); } + D(printf("]\n")); - /* for all its definitions check if the registers + /* For all its definitions check if the registers allocated needs positioning NOTE: we can position only ONCE if more than One positioning required - then give up */ + then give up. + We may need to perform the checks twice; once to + position the registers as needed, the second to + verify any register repositioning is still + compatible. + */ sym->isspilt = 0; - for (i = 0 ; i < sym->defs->size ; i++ ) { - if (bitVectBitValue(sym->defs,i)) { - iCode *ic; - if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ; - if (SKIP_IC(ic)) continue; - assert(isSymbolEqual(sym,OP_SYMBOL(IC_RESULT(ic)))); /* just making sure */ - /* if left is assigned to registers */ - if (IS_SYMOP(IC_LEFT(ic)) && - bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_LEFT(ic))->key)) { - pdone += (positionRegs(sym,OP_SYMBOL(IC_LEFT(ic)))>0); - } - if (IS_SYMOP(IC_RIGHT(ic)) && - bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RIGHT(ic))->key)) { - pdone += (positionRegs(sym,OP_SYMBOL(IC_RIGHT(ic)))>0); + for (pass=0; pass<2; pass++) { + D(printf(" checking definitions\n")); + for (i = 0 ; i < sym->defs->size ; i++ ) { + if (bitVectBitValue(sym->defs,i)) { + iCode *ic; + if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ; + D(printf(" ic->seq = %d\n", ic->seq)); + if (SKIP_IC(ic)) continue; + assert(isSymbolEqual(sym,OP_SYMBOL(IC_RESULT(ic)))); /* just making sure */ + /* if left is assigned to registers */ + if (IS_SYMOP(IC_LEFT(ic))) + { + D(printf(" left = ")); + D(printOperand(IC_LEFT(ic),NULL)); + } + if (IS_SYMOP(IC_LEFT(ic)) && + bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_LEFT(ic))->key)) { + pdone += (positionRegs(sym,OP_SYMBOL(IC_LEFT(ic)))>0); + } + if (IS_SYMOP(IC_RIGHT(ic))) + { + D(printf(" right = ")); + D(printOperand(IC_RIGHT(ic),NULL)); + } + if (IS_SYMOP(IC_RIGHT(ic)) && + bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RIGHT(ic))->key)) { + pdone += (positionRegs(sym,OP_SYMBOL(IC_RIGHT(ic)))>0); + } + D(printf(" pdone = %d\n", pdone)); + if (pdone > 1) break; } - if (pdone > 1) break; } - } - for (i = 0 ; i < sym->uses->size ; i++ ) { - if (bitVectBitValue(sym->uses,i)) { - iCode *ic; - if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ; - if (SKIP_IC(ic)) continue; - if (POINTER_SET(ic) || POINTER_GET(ic)) continue ; - - /* if result is assigned to registers */ - if (IS_SYMOP(IC_RESULT(ic)) && - bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RESULT(ic))->key)) { - pdone += (positionRegs(sym,OP_SYMBOL(IC_RESULT(ic)))>0); + D(printf(" checking uses\n")); + for (i = 0 ; i < sym->uses->size ; i++ ) { + if (bitVectBitValue(sym->uses,i)) { + iCode *ic; + if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ; + D(printf(" ic->seq = %d\n", ic->seq)); + if (SKIP_IC(ic)) continue; + if (POINTER_SET(ic) || POINTER_GET(ic)) continue ; + + /* if result is assigned to registers */ + if (IS_SYMOP(IC_RESULT(ic))) + { + D(printf(" result = ")); + D(printOperand(IC_RESULT(ic),NULL)); + } + if (IS_SYMOP(IC_RESULT(ic)) && + bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RESULT(ic))->key)) { + pdone += (positionRegs(sym,OP_SYMBOL(IC_RESULT(ic)))>0); + } + D(printf(" pdone = %d\n", pdone)); + if (pdone > 1) break; } - if (pdone > 1) break; } - } + if (pdone == 0) break; /* second pass only if regs repositioned */ + if (pdone > 1) break; + } + D(printf(" sym->regs = [")); + for (i=0; i < sym->nRegs ; i++ ) + D(printf("%s ", sym->regs[i]->name)); + D(printf("]\n")); /* had to position more than once GIVE UP */ if (pdone > 1) { /* UNDO all the changes we made to try this */