X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCloop.c;h=c69101857feab6f466a43fe65344182c4fb8fbba;hb=7a742aa53d932c986e05ab285410366d414e23a4;hp=21d16bacd661e572d10619a1a18f420bde57d648;hpb=a2a330936c98860f9476f33f7d390c95805c60d4;p=fw%2Fsdcc diff --git a/src/SDCCloop.c b/src/SDCCloop.c index 21d16bac..c6910185 100644 --- a/src/SDCCloop.c +++ b/src/SDCCloop.c @@ -1,9 +1,3 @@ -//#define LIVERANGEHUNT -#ifdef LIVERANGEHUNT - #define LRH(x) x -#else - #define LRH(x) -#endif /*------------------------------------------------------------------------- SDCCloop.c - source file for loop detection & optimizations @@ -52,7 +46,7 @@ newInduction (operand * sym, unsigned int op, ip->op = op; ip->cval = constVal; ip->ic = ic; - updateSpillLocation(ic,1); +//updateSpillLocation(ic,1); return ip; } @@ -159,7 +153,6 @@ loopInsert (set ** regionSet, eBBlock * block) { if (!isinSet (*regionSet, block)) { - LRH(printf ("loopInsert: %s\n", block->entryLabel->name)); addSetHead (regionSet, block); STACK_PUSH (regionStack, block); } @@ -236,13 +229,12 @@ DEFSETFUNC (addToExitsMarkDepth) V_ARG (set **, exits); V_ARG (int, depth); V_ARG (region *, lr); - LRH(printf ("addToExitsMarkDepth: %s %d\n", ebp->entryLabel->name, depth)); + /* mark the loop depth of this block */ //if (!ebp->depth) if (ebp->depthdepth = depth; - /* put the loop region info in the block */ /* NOTE: here we will update only the inner most loop that it is a part of */ if (!ebp->partOfLoop) @@ -266,42 +258,16 @@ 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; - LRH(printf("CreateLoop\n")); /* make sure regionStack is empty */ while (!STACK_EMPTY (regionStack)) STACK_POP (regionStack); /* add the entryBlock */ addSet (&aloop->regBlocks, ep->to); -#ifdef LIVERANGEHUNT - // print regBlocks jwk - { - eBBlock *ebp; - region *lp=aloop; - for (ebp=setFirstItem(lp->regBlocks); ebp; ebp=setNextItem(lp->regBlocks)) { - printf ("cl1 %s ", ebp->entryLabel->name); - } - printf (" %d\n", count); - } -#endif loopInsert (&aloop->regBlocks, ep->from); -#ifdef LIVERANGEHUNT - // print regBlocks jwk - { - eBBlock *ebp; - region *lp=aloop; - for (ebp=setFirstItem(lp->regBlocks); ebp; ebp=setNextItem(lp->regBlocks)) { - printf ("cl2 %s ", ebp->entryLabel->name); - } - printf (" %d\n", count); - } -#endif while (!STACK_EMPTY (regionStack)) { @@ -311,61 +277,7 @@ DEFSETFUNC (createLoop) applyToSet (block->predList, insertIntoLoop, &aloop->regBlocks); } -#ifdef LIVERANGEHUNT - // print regBlocks jwk - { - eBBlock *ebp; - region *lp=aloop; - for (ebp=setFirstItem(lp->regBlocks); ebp; ebp=setNextItem(lp->regBlocks)) { - printf ("cl3 %s ", ebp->entryLabel->name); - } - printf (" %d\n", count); - } -#endif - 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) { -#if !defined(LIVERANGEHUNT) - ebbs[i]->partOfLoop = aloop; -#else - loopInsert(&aloop->regBlocks,ebbs[i]); -#endif - } - } - } - -#ifdef LIVERANGEHUNT - printf ("================\n"); - printf (" loop with entry -- > "); - printEntryLabel (aloop->entry, ap); - printf ("\n"); - printf (" loop body --> "); - applyToSet (aloop->regBlocks, printEntryLabel); - printf ("\n"); - printf (" loop exits --> "); - applyToSet (aloop->exits, printEntryLabel); - printf ("\n"); -#endif - - /* 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); @@ -394,7 +306,7 @@ DEFSETFUNC (addDefInExprs) V_ARG (int, count); addSetHead (&ebp->inExprs, cdp); - cseBBlock (ebp, 0, ebbs, count); + cseBBlock (ebp, optimize.global_cse, ebbs, count); return 0; } @@ -416,7 +328,7 @@ assignmentsToSym (set * sset, operand * sym) in this block */ bitVect *defs = bitVectIntersect (ebp->ldefs, OP_DEFS (sym)); assigns += bitVectnBitsOn (defs); - setToNull ((void **) &defs); + setToNull ((void *) &defs); } @@ -452,9 +364,6 @@ isOperandInvariant (operand * op, region * theLoop, set * lInvars) !IS_OP_VOLATILE (op) && assignmentsToSym (theLoop->regBlocks, op) == 0) opin = 1; - LRH(if (opin && IS_SYMOP(op)) { - printf("isOperandInvariant: %s\n", OP_SYMBOL(op)->name); - }); } else opin++; @@ -536,7 +445,7 @@ loopInvariants (region * theLoop, eBBlock ** ebbs, int count) int lin, rin; cseDef *ivar; - /* jwk: TODO this is only needed if the call is between + /* TODO this is only needed if the call is between here and the definition, but I am too lazy to do that now */ /* if there are function calls in this block */ @@ -555,6 +464,13 @@ loopInvariants (region * theLoop, eBBlock ** ebbs, int count) if (SKIP_IC (ic) || POINTER_SET (ic) || ic->op == IFX) continue; + + /* iTemp assignment from a literal may be invariant, but it + will needlessly increase register pressure if the + iCode(s) that use this iTemp are not also invariant */ + if (ic->op=='=' && IS_ITEMP (IC_RESULT (ic)) + && IS_OP_LITERAL (IC_RIGHT (ic))) + continue; /* if result is volatile then skip */ if (IC_RESULT (ic) && @@ -598,7 +514,8 @@ loopInvariants (region * theLoop, eBBlock ** ebbs, int count) applyToSet (theLoop->regBlocks, hasNonPtrUse, IC_LEFT (ic))) continue; - /* if both the left & right are invariants : then check that */ + + /* if both the left & right are invariants : then check that */ /* this definition exists in the out definition of all the */ /* blocks, this will ensure that this is not assigned any */ /* other value in the loop , and not used in this block */ @@ -609,7 +526,7 @@ loopInvariants (region * theLoop, eBBlock ** ebbs, int count) eBBlock *sBlock; set *lSet = setFromSet (theLoop->regBlocks); - /* if this block does not dominate all exists */ + /* if this block does not dominate all exits */ /* make sure this defintion is not used anywhere else */ if (!domsAllExits) { @@ -658,7 +575,9 @@ loopInvariants (region * theLoop, eBBlock ** ebbs, int count) /* now we know it is a true invariant */ /* remove it from the insts chain & put */ /* in the invariant set */ - OP_SYMBOL (IC_RESULT (ic))->isinvariant = 1; + + OP_SYMBOL (IC_RESULT (ic))->isinvariant = 1; + SPIL_LOC (IC_RESULT (ic)) = NULL; remiCodeFromeBBlock (lBlock, ic); /* maintain the data flow */ @@ -1147,7 +1066,7 @@ loopInduction (region * loopReg, eBBlock ** ebbs, int count) lastBlock->linds = bitVectUnion(lastBlock->linds,indVect); } - setToNull ((void **) &indVars); + setToNull ((void *) &indVars); return change; } @@ -1238,26 +1157,13 @@ createLoopRegions (eBBlock ** ebbs, int count) int maxDepth = 0; region *lp; - LRH(printf ("createLoopRegions: %p\n", ebbs)); /* get all the back edges in the graph */ if (!applyToSet (graphEdges, backEdges, &bEdges)) return 0; /* found no loops */ /* for each of these back edges get the blocks that */ /* constitute the loops */ - applyToSet (bEdges, createLoop, &allRegion, ebbs,count); -#ifdef LIVERANGEHUNT - // print regBlocks - { - eBBlock *ebp; - lp=setFirstItem(allRegion); - printf ("createLoopRegions: "); - for (ebp=setFirstItem(lp->regBlocks); ebp; ebp=setNextItem(lp->regBlocks)) { - printf ("%s ", ebp->entryLabel->name); - } - printf (" %d\n", count); - } -#endif + applyToSet (bEdges, createLoop, &allRegion); /* now we will create regions from these loops */ /* loops with the same entry points are considered to be the */