X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCloop.c;h=238cf250b3915e0e439792f4dc8c3b93d332bfc2;hb=c8a2ee66f80f73936e93c8505984d5b4ed63b84a;hp=0be4da81cb3dcaf2976c81905cb3f69313716e4a;hpb=bbf4fa557b2639260fc2ac97810046501f375fcc;p=fw%2Fsdcc diff --git a/src/SDCCloop.c b/src/SDCCloop.c index 0be4da81..238cf250 100644 --- a/src/SDCCloop.c +++ b/src/SDCCloop.c @@ -39,7 +39,7 @@ newInduction (operand * sym, unsigned int op, { induction *ip; - ip = Safe_calloc (1, sizeof (induction)); + ip = Safe_alloc ( sizeof (induction)); ip->sym = sym; ip->asym = asym; @@ -58,7 +58,7 @@ newRegion () { region *lp; - lp = Safe_calloc (1, sizeof (region)); + lp = Safe_alloc ( sizeof (region)); return lp; } @@ -231,7 +231,8 @@ DEFSETFUNC (addToExitsMarkDepth) V_ARG (region *, lr); /* mark the loop depth of this block */ - if (!ebp->depth) + //if (!ebp->depth) + if (ebp->depthdepth = depth; /* put the loop region info in the block */ @@ -258,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)) @@ -278,6 +282,22 @@ 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; + } + } /* now add it to the set */ addSetHead (allRegion, aloop); @@ -445,11 +465,21 @@ loopInvariants (region * theLoop, eBBlock ** ebbs, int count) int lin, rin; cseDef *ivar; - /* if there are function calls in this block and this - is a pointer get, the function could have changed it - so skip, ISO-C99 according to David A. Long */ - if (fCallsInBlock && POINTER_GET(ic)) { - continue; + /* jwk: 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 */ + if (fCallsInBlock) { + + /* if this is a pointer get */ + if (POINTER_GET(ic)) { + continue; + } + + /* if this is an assignment from a global */ + if (ic->op=='=' && isOperandGlobal(IC_RIGHT(ic))) { + continue; + } } if (SKIP_IC (ic) || POINTER_SET (ic) || ic->op == IFX) @@ -798,13 +828,6 @@ basicInduction (region * loopReg, eBBlock ** ebbs, int count) OP_SYMBOL (IC_RESULT (indIc))->isind = 1; ip = newInduction (IC_RIGHT (ic), dic->op, litValue, indIc, NULL); - if (1) { - fprintf (stderr, "%s:%d: stupid way to avoid bug #467035, but\n" - "this will keep the regressions tests going.\n", - __FILE__, __LINE__); - continue; - } - /* replace the inducted variable by the iTemp */ replaceSymBySym (loopReg->regBlocks, IC_RESULT (ic), IC_RIGHT (ic)); @@ -1050,7 +1073,7 @@ loopInduction (region * loopReg, eBBlock ** ebbs, int count) /* add the induction variable vector to the last block in the loop */ lastBlock->isLastInLoop = 1; - lastBlock->linds = indVect; + lastBlock->linds = bitVectUnion(lastBlock->linds,indVect); } setToNull ((void **) &indVars); @@ -1150,7 +1173,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 */