X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCloop.c;h=52cc19affc7c0ef5a1e9c124a9ae442710bd6f04;hb=d0036c2fdca6bf20f9adb6eeb58bdbd404edda51;hp=34bb23d38653ee6f41cbdf70071f65ec4e0af00a;hpb=5df1b9a579235d42fcec8a8884808334ed99a246;p=fw%2Fsdcc diff --git a/src/SDCCloop.c b/src/SDCCloop.c index 34bb23d3..52cc19af 100644 --- a/src/SDCCloop.c +++ b/src/SDCCloop.c @@ -46,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; } @@ -131,7 +131,7 @@ intersectLoopSucc (set * lexits, eBBlock ** ebbs) if (!exit) return NULL; - + succVect = bitVectCopy (exit->succVect); for (exit = setNextItem (lexits); exit; @@ -231,10 +231,10 @@ 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 */ /* NOTE: here we will update only the inner most loop that it is a part of */ if (!ebp->partOfLoop) @@ -306,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; } @@ -328,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); } @@ -379,7 +379,22 @@ DEFSETFUNC (pointerAssigned) eBBlock *ebp = item; V_ARG (operand *, op); - return ebp->hasFcall || bitVectBitValue (ebp->ptrsSet, op->key); + if (ebp->hasFcall) + return 1; + + if (bitVectBitValue (ebp->ptrsSet, op->key)) + return 1; + + /* Unfortunately, one of the other pointer set operations */ + /* may be using an alias of this operand, and the above */ + /* test would miss it. To be thorough, some aliasing */ + /* analysis should be done here. In the meantime, be */ + /* conservative and assume any other pointer set operation */ + /* is dangerous */ + if (!bitVectIsZero (ebp->ptrsSet)) + return 1; + + return 0; } /*-----------------------------------------------------------------*/ @@ -445,15 +460,32 @@ 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; + /* 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) 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) && @@ -497,7 +529,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 */ @@ -508,7 +541,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) { @@ -557,7 +590,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 */ @@ -798,13 +833,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)); @@ -814,7 +842,6 @@ basicInduction (region * loopReg, eBBlock ** ebbs, int count) if (nexits == 1) { eBBlock *exit = setFirstItem (loopReg->exits); - /* if it is the same block then there is no need to move it about */ if (exit != lBlock) @@ -852,7 +879,18 @@ basicInduction (region * loopReg, eBBlock ** ebbs, int count) if (bitVectBitValue (loopSuccs, i)) { - eBBlock *eblock = ebbs[i]; + eBBlock *eblock = NULL; + int j; + + /* Need to search for bbnum == i since ebbs is */ + /* sorted by dfnum; a direct index won't do. */ + for (j=0; jbbnum == i) + { + eblock = ebbs[j]; + break; + } + assert(eblock); /* if the successor does not belong to the loop and will be executed after the loop : then @@ -864,9 +902,9 @@ basicInduction (region * loopReg, eBBlock ** ebbs, int count) iCode *newic = newiCode ('=', NULL, operandFromOperand (IC_RIGHT (ic))); IC_RESULT (newic) = operandFromOperand (IC_RESULT (ic)); - OP_DEFS (IC_RESULT (newic)) = + OP_DEFS(IC_RESULT (newic))= bitVectSetBit (OP_DEFS (IC_RESULT (newic)), newic->key); - OP_USES (IC_RIGHT (newic)) = + OP_USES(IC_RIGHT (newic))= bitVectSetBit (OP_USES (IC_RIGHT (newic)), newic->key); /* and add it */ if (eblock->sch && eblock->sch->op == LABEL) @@ -1050,10 +1088,10 @@ 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); + setToNull ((void *) &indVars); return change; } @@ -1081,7 +1119,7 @@ DEFSETFUNC (mergeRegions) if (lp->entry == theLoop->entry) { theLoop->regBlocks = unionSets (theLoop->regBlocks, - lp->regBlocks, THROW_BOTH); + lp->regBlocks, THROW_DEST); lp->merged = 1; } } @@ -1164,6 +1202,7 @@ createLoopRegions (eBBlock ** ebbs, int count) applyToSet (allRegion, mergeInnerLoops, allRegion, &maxDepth); maxDepth++; + /* now create all the exits .. also */ /* create an ordered set of loops */ /* i.e. we process loops in the inner to outer order */