-//#define LIVERANGEHUNT
-#ifdef LIVERANGEHUNT
- #define LRH(x) x
-#else
- #define LRH(x)
-#endif
/*-------------------------------------------------------------------------
SDCCloop.c - source file for loop detection & optimizations
ip->op = op;
ip->cval = constVal;
ip->ic = ic;
- updateSpillLocation(ic,1);
+//updateSpillLocation(ic,1);
return ip;
}
if (!exit)
return NULL;
-
+
succVect = bitVectCopy (exit->succVect);
for (exit = setNextItem (lexits); exit;
{
if (!isinSet (*regionSet, block))
{
- LRH(printf ("loopInsert: %s\n", block->entryLabel->name));
addSetHead (regionSet, block);
STACK_PUSH (regionStack, block);
}
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->depth<depth)
ebp->depth = 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)
{
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))
{
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) ebbs[i]->partOfLoop = aloop;
- }
- LRH(printf("****** %d %d %d %x %s\n", ebbs[i]->dfnum, dfMin, dfMax, ebbs[i]->partOfLoop, ebbs[i]->entryLabel->name));
- }
/* now add it to the set */
addSetHead (allRegion, aloop);
V_ARG (int, count);
addSetHead (&ebp->inExprs, cdp);
- cseBBlock (ebp, 0, ebbs, count);
+ cseBBlock (ebp, optimize.global_cse, ebbs, count);
return 0;
}
in this block */
bitVect *defs = bitVectIntersect (ebp->ldefs, OP_DEFS (sym));
assigns += bitVectnBitsOn (defs);
- setToNull ((void **) &defs);
+ setToNull ((void *) &defs);
}
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 */
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) &&
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 */
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)
{
/* 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 */
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)
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; j<count; j++)
+ if (ebbs[j]->bbnum == i)
+ {
+ eblock = ebbs[j];
+ break;
+ }
+ assert(eblock);
/* if the successor does not belong to the loop
and will be executed after the loop : then
iCode *newic = newiCode ('=', NULL,
operandFromOperand (IC_RIGHT (ic)));
IC_RESULT (newic) = operandFromOperand (IC_RESULT (ic));
- OP_DEFS_SET ((IC_RESULT (newic)),
- bitVectSetBit (OP_DEFS (IC_RESULT (newic)), newic->key));
- OP_USES_SET ((IC_RIGHT (newic)),
- bitVectSetBit (OP_USES (IC_RIGHT (newic)), newic->key));
+ OP_DEFS(IC_RESULT (newic))=
+ bitVectSetBit (OP_DEFS (IC_RESULT (newic)), newic->key);
+ OP_USES(IC_RIGHT (newic))=
+ bitVectSetBit (OP_USES (IC_RIGHT (newic)), newic->key);
/* and add it */
if (eblock->sch && eblock->sch->op == LABEL)
addiCodeToeBBlock (eblock, newic, eblock->sch->next);
lastBlock->linds = bitVectUnion(lastBlock->linds,indVect);
}
- setToNull ((void **) &indVars);
+ setToNull ((void *) &indVars);
return change;
}
if (lp->entry == theLoop->entry)
{
theLoop->regBlocks = unionSets (theLoop->regBlocks,
- lp->regBlocks, THROW_BOTH);
+ lp->regBlocks, THROW_DEST);
lp->merged = 1;
}
}
int maxDepth = 0;
region *lp;
- LRH(printf ("createLoopRegions: %x\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 */