From: johanknol Date: Thu, 27 Mar 2003 10:23:21 +0000 (+0000) Subject: let's try again ;-) X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=633d4639c3ebce5f6b7ef04223e5d7842f841a6b;p=fw%2Fsdcc let's try again ;-) git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2420 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCCloop.c b/src/SDCCloop.c index f43e4837..55021f34 100644 --- a/src/SDCCloop.c +++ b/src/SDCCloop.c @@ -259,8 +259,11 @@ DEFSETFUNC (createLoop) { edge *ep = item; V_ARG (set **, allRegion); + V_ARG (eBBlock **,ebbs); + V_ARG (int,count); region *aloop = newRegion (); eBBlock *block; + int dfMin = count ,dfMax =0, i; /* make sure regionStack is empty */ while (!STACK_EMPTY (regionStack)) @@ -280,6 +283,32 @@ DEFSETFUNC (createLoop) aloop->entry = ep->to; + /* set max & min dfNum for loopRegion */ + for ( block = setFirstItem(aloop->regBlocks); block; + block = setNextItem(aloop->regBlocks)) { + if (block->dfnum > dfMax) dfMax = block->dfnum; + if (block->dfnum < dfMin) dfMin = block->dfnum; + } + + /* all blocks that have dfnumbers between dfMin & dfMax are also + part of loop */ + for (i = 0 ; i < count ; i++) { + if (ebbs[i]->dfnum > dfMin && + ebbs[i]->dfnum < dfMax && + !isinSet(aloop->regBlocks,ebbs[i])) { + if (!ebbs[i]->partOfLoop) { + ebbs[i]->partOfLoop = aloop; + } + } + } + + /* and if this is a conditional block, the other side of the IFX + (if any, that could have a greater dfnum) is too */ + { + // just a burp, but I'm getting close :) + } + + /* now add it to the set */ addSetHead (allRegion, aloop); return 0; @@ -1154,7 +1183,7 @@ createLoopRegions (eBBlock ** ebbs, int count) /* for each of these back edges get the blocks that */ /* constitute the loops */ - applyToSet (bEdges, createLoop, &allRegion); + applyToSet (bEdges, createLoop, &allRegion, ebbs,count); /* now we will create regions from these loops */ /* loops with the same entry points are considered to be the */ diff --git a/src/SDCClrange.c b/src/SDCClrange.c index 96753294..a85c5ff1 100644 --- a/src/SDCClrange.c +++ b/src/SDCClrange.c @@ -175,17 +175,12 @@ setFromRange (operand * op, int from) /* setToRange - set the range to for an operand */ /*-----------------------------------------------------------------*/ void -setToRange (operand * op, int to, bool check, int fromLevel) +setToRange (operand * op, int to, bool check) { /* only for compiler defined temps */ if (!IS_ITEMP (op)) return; - if (fromLevel > OP_SYMBOL(op)->level) { - // this is from an inner block and thus has no authority - return; - } - OP_SYMBOL (op)->key = op->key; hTabAddItemIfNotP (&liveRanges, op->key, OP_SYMBOL (op)); @@ -320,9 +315,17 @@ operandLUse (operand * op, eBBlock ** ebbs, /* found it : mark */ if (lic) torange = lic->prev->seq; } - + /* if this is the last use then if this block belongs + to a loop & some definition comes into the loop + then extend the live range to the end of the loop */ + if (ebp->partOfLoop + && hasIncomingDefs (ebp->partOfLoop, op)) + { + torange = findLoopEndSeq (ebp->partOfLoop); + } + op = operandFromOperand (op); - setToRange (op, torange, FALSE, ebp->entryLabel->level); + setToRange (op, torange, FALSE); } ic->uses = bitVectSetBit (ic->uses, op->key); @@ -436,8 +439,7 @@ markLiveRanges (eBBlock * ebp, eBBlock ** ebbs, int count) and take it away from the defs for the block */ if (bitVectIsZero (OP_SYMBOL (IC_RESULT (ic))->uses)) { - setToRange (IC_RESULT (ic), ic->seq, FALSE, - ebp->entryLabel->level); + setToRange (IC_RESULT (ic), ic->seq, FALSE); bitVectUnSetBit (ebp->defSet, ic->key); } } @@ -509,8 +511,7 @@ markLiveRanges (eBBlock * ebp, eBBlock ** ebbs, int count) defUsedAfterLoop (IC_RESULT (dic), ebp->lSeq)) continue; - setToRange (IC_RESULT (dic), (ebp->lSeq), FALSE, - ebp->entryLabel->level); + setToRange (IC_RESULT (dic), (ebp->lSeq), FALSE); } } } @@ -540,8 +541,7 @@ markLiveRanges (eBBlock * ebp, eBBlock ** ebbs, int count) if (bitVectBitValue (defsNotUsed, i) && (dic = hTabItemWithKey (iCodehTab, i))) { - setToRange (IC_RESULT (dic), (ebp->fSeq - 1), TRUE, - ebp->entryLabel->level); + setToRange (IC_RESULT (dic), (ebp->fSeq - 1), TRUE); } } } diff --git a/src/SDCClrange.h b/src/SDCClrange.h index 6c2441d8..f1785407 100644 --- a/src/SDCClrange.h +++ b/src/SDCClrange.h @@ -35,6 +35,6 @@ bool allDefsOutOfRange (bitVect *, int, int); void computeLiveRanges (eBBlock **, int); void setFromRange (operand *, int); -void setToRange (operand *, int, bool, int); +void setToRange (operand *, int, bool); #endif diff --git a/src/mcs51/ralloc.c b/src/mcs51/ralloc.c index 6be33c02..bf3d162f 100644 --- a/src/mcs51/ralloc.c +++ b/src/mcs51/ralloc.c @@ -2007,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, OP_SYMBOL(op)->level); + setToRange(op, ic->seq, FALSE); /* remove the assignment iCode now that its result is unused */ remiCodeFromeBBlock (ebp, assignment);