{
eBBlock *ebp = item;
V_ARG (cseDef *, cdp);
- V_ARG (eBBlock **, ebbs);
- V_ARG (int, count);
+ V_ARG (ebbIndex *, ebbi);
addSetHead (&ebp->inExprs, cdp);
- cseBBlock (ebp, optimize.global_cse, ebbs, count);
+ cseBBlock (ebp, optimize.global_cse, ebbi);
return 0;
}
/* loopInvariants - takes loop invariants out of region */
/*-----------------------------------------------------------------*/
int
-loopInvariants (region * theLoop, eBBlock ** ebbs, int count)
+loopInvariants (region * theLoop, ebbIndex * ebbi)
{
+ eBBlock ** ebbs = ebbi->dfOrder;
+ int count = ebbi->count;
eBBlock *lBlock;
set *lInvars = NULL;
for (sBlock = setFirstItem (lSet); sBlock;
sBlock = setNextItem (lSet))
{
+ iCode *ic2;
+ int used;
+ int defDominates;
+
/* if this is the block make sure the definition */
/* reaches the end of the block */
if (sBlock == lBlock)
else if (bitVectBitsInCommon (sBlock->defSet, OP_DEFS (IC_RESULT (ic))))
break;
- if (IC_RESULT(ic))
+ /* Check that this definition is not assigned */
+ /* any other value in this block. Also check */
+ /* that any usage in the block is dominated by */
+ /* by this definition. */
+ defDominates = bitVectBitValue (sBlock->domVect, lBlock->bbnum);
+ used = 0;
+ for (ic2 = sBlock->sch; ic2; ic2 = ic2->next)
{
- iCode *ic2;
- /* check that this definition is not assigned */
- /* any other value in this block */
- for (ic2 = sBlock->sch; ic2; ic2 = ic2->next)
+ if (ic2->op == IFX)
+ {
+ if (isOperandEqual (IC_RESULT (ic), IC_COND (ic2)))
+ used = 1;
+ }
+ else if (ic2->op == JUMPTABLE)
{
+ if (isOperandEqual (IC_RESULT (ic), IC_JTCOND (ic2)))
+ used = 1;
+ }
+ else
+ {
+ if (IC_LEFT (ic2) && isOperandEqual (IC_RESULT (ic), IC_LEFT (ic2)))
+ used = 1;
+ if (IC_RIGHT (ic2) && isOperandEqual (IC_RESULT (ic), IC_RIGHT (ic2)))
+ used = 1;
if ((ic != ic2) && (isOperandEqual(IC_RESULT(ic), IC_RESULT(ic2))))
break;
+ /* If used before this definition, might not be invariant */
+ if ((ic == ic2) && used)
+ break;
}
- if (ic2) /* found another definition */
+ if (used && !defDominates)
break;
}
+ if (ic2) /* found another definition or a usage before the definition */
+ break;
}
if (sBlock)
continue; /* another definition present in the block */
+
- /* now check if it exists in the in of this block */
+ /* now check if it exists in the in of this block */
/* if not then it was killed before this instruction */
if (!bitVectBitValue (lBlock->inDefs, ic->key))
continue;
bitVectUnSetBit (lBlock->defSet, ic->key);
bitVectUnSetBit (lBlock->ldefs, ic->key);
ivar = newCseDef (IC_RESULT (ic), ic);
- applyToSet (theLoop->regBlocks, addDefInExprs, ivar, ebbs, count);
+ applyToSet (theLoop->regBlocks, addDefInExprs, ivar, ebbi);
addSet (&lInvars, ivar);
}
}
/* loopInduction - remove induction variables from a loop */
/*-----------------------------------------------------------------*/
int
-loopInduction (region * loopReg, eBBlock ** ebbs, int count)
+loopInduction (region * loopReg, ebbIndex * ebbi)
{
+ eBBlock ** ebbs = ebbi->dfOrder;
+ int count = ebbi->count;
int change = 0;
eBBlock *lBlock, *owner, *lastBlock = NULL;
set *indVars = NULL;
{
operand *aSym;
long litVal;
- int lr = 0;
/* consider only * & / */
if (ic->op != '*' && ic->op != '/')
/* createLoopRegions - will detect and create a set of natural loops */
/*-----------------------------------------------------------------*/
hTab *
-createLoopRegions (eBBlock ** ebbs, int count)
+createLoopRegions (ebbIndex * ebbi)
{
set *allRegion = NULL; /* set of all loops */
hTab *orderedLoops = NULL;
/* loopOptimizations - identify region & remove invariants & ind */
/*-----------------------------------------------------------------*/
int
-loopOptimizations (hTab * orderedLoops, eBBlock ** ebbs, int count)
+loopOptimizations (hTab * orderedLoops, ebbIndex * ebbi)
{
region *lp;
int change = 0;
{
if (optimize.loopInvariant)
- change += loopInvariants (lp, ebbs, count);
+ change += loopInvariants (lp, ebbi);
if (optimize.loopInduction)
- change += loopInduction (lp, ebbs, count);
+ change += loopInduction (lp, ebbi);
}
return change;