X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCloop.c;h=ef902a31db34666905e4353dd7078146e3d806f9;hb=471d04e308e77523505e67ef7722ab94e7ec385a;hp=453cba1fa728dfe7f359e000042d12ee5ab037f8;hpb=29779804200986ce903b5086441b49265a122dc5;p=fw%2Fsdcc diff --git a/src/SDCCloop.c b/src/SDCCloop.c index 453cba1f..ef902a31 100644 --- a/src/SDCCloop.c +++ b/src/SDCCloop.c @@ -39,14 +39,14 @@ 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; ip->op = op; ip->cval = constVal; ip->ic = ic; - + updateSpillLocation(ic,1); return ip; } @@ -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 */ @@ -408,6 +409,7 @@ loopInvariants (region * theLoop, eBBlock ** ebbs, int count) set *lInvars = NULL; int change = 0; + int fCallsInBlock; /* if the preHeader does not exist then do nothing */ /* or no exits then do nothing ( have to think about this situation */ @@ -429,6 +431,12 @@ loopInvariants (region * theLoop, eBBlock ** ebbs, int count) domsAllExits = (applyToSet (theLoop->exits, dominatedBy, lBlock) == elementsInSet (theLoop->exits)); + /* find out if we have a function call in this block */ + for (ic = lBlock->sch, fCallsInBlock=0; ic; ic = ic->next) { + if (SKIP_IC(ic)) { + fCallsInBlock++; + } + } /* now we go thru the instructions of this block and */ /* collect those instructions with invariant operands */ @@ -438,6 +446,23 @@ loopInvariants (region * theLoop, eBBlock ** ebbs, int count) int lin, rin; cseDef *ivar; + /* 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) continue; @@ -447,27 +472,34 @@ loopInvariants (region * theLoop, eBBlock ** ebbs, int count) IS_OP_PARM (IC_RESULT (ic)))) continue; - lin = rin = 0; + /* if result depends on a volatile then skip */ + if ((IC_LEFT(ic) && isOperandVolatile(IC_LEFT(ic), TRUE)) || + (IC_RIGHT(ic) && isOperandVolatile(IC_RIGHT(ic), TRUE))) + continue; + lin = rin = 0; + /* special case */ /* if address of then it is an invariant */ if (ic->op == ADDRESS_OF && IS_SYMOP (IC_LEFT (ic)) && IS_AGGREGATE (operandType (IC_LEFT (ic)))) lin++; - else + else { /* check if left operand is an invariant */ - if ((lin = isOperandInvariant (IC_LEFT (ic), theLoop, lInvars))) - /* if this is a pointer get then make sure - that the pointer set does not exist in - any of the blocks */ - if (POINTER_GET (ic) && - (applyToSet (theLoop->regBlocks, pointerAssigned, IC_LEFT (ic)))) - lin = 0; - + if ((lin = isOperandInvariant (IC_LEFT (ic), theLoop, lInvars))) + /* if this is a pointer get then make sure + that the pointer set does not exist in + any of the blocks */ + if (POINTER_GET (ic) && + (applyToSet (theLoop->regBlocks, + pointerAssigned, IC_LEFT (ic)))) + lin = 0; + } + /* do the same for right */ rin = isOperandInvariant (IC_RIGHT (ic), theLoop, lInvars); - + /* if this is a POINTER_GET then special case, make sure all usages within the loop are POINTER_GET any other usage would mean that this is not an invariant , since the pointer @@ -737,8 +769,8 @@ basicInduction (region * loopReg, eBBlock ** ebbs, int count) continue; aSym = (IS_OP_LITERAL (IC_RIGHT (dic)) ? - (litValue = operandLitValue (IC_RIGHT (dic)), IC_LEFT (dic)) : - (litValue = operandLitValue (IC_LEFT (dic)), IC_RIGHT (dic))); + (litValue = (unsigned long) operandLitValue (IC_RIGHT (dic)), IC_LEFT (dic)) : + (litValue = (unsigned long) operandLitValue (IC_LEFT (dic)), IC_RIGHT (dic))); if (!isOperandEqual (IC_RESULT (ic), aSym) && !isOperandEqual (IC_RIGHT (ic), aSym)) @@ -916,8 +948,8 @@ loopInduction (region * loopReg, eBBlock ** ebbs, int count) continue; aSym = (IS_SYMOP (IC_LEFT (ic)) ? - (lr = 1, litVal = operandLitValue (IC_RIGHT (ic)), IC_LEFT (ic)) : - (litVal = operandLitValue (IC_LEFT (ic)), IC_RIGHT (ic))); + (lr = 1, litVal = (unsigned long) operandLitValue (IC_RIGHT (ic)), IC_LEFT (ic)) : + (litVal = (unsigned long) operandLitValue (IC_LEFT (ic)), IC_RIGHT (ic))); ip = NULL; /* check if this is an induction variable */ @@ -926,8 +958,8 @@ loopInduction (region * loopReg, eBBlock ** ebbs, int count) /* ask port for size not worth if native instruction exist for multiply & divide */ - if (getSize (operandType (IC_LEFT (ic))) <= port->muldiv.native_below || - getSize (operandType (IC_RIGHT (ic))) <= port->muldiv.native_below) + if (getSize (operandType (IC_LEFT (ic))) <= (unsigned long) port->support.muldiv || + getSize (operandType (IC_RIGHT (ic))) <= (unsigned long) port->support.muldiv) continue; /* if this is a division then the remainder should be zero @@ -1022,7 +1054,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); @@ -1161,7 +1193,6 @@ loopOptimizations (hTab * orderedLoops, eBBlock ** ebbs, int count) int change = 0; int k; - /* if no loop optimizations requested */ if (!optimize.loopInvariant && !optimize.loopInduction)