/* if this block is not reachable */
if (ebb->noPath)
- return change;
+ return 0;
/* set of common subexpressions */
cseSet = setFromSet (ebb->inExprs);
if (SKIP_IC (ic))
continue;
- /* do some algebraic optimizations if possible */
- algebraicOpts (ic);
- while (constFold (ic, cseSet));
+ if (!computeOnly) {
+ /* do some algebraic optimizations if possible */
+ algebraicOpts (ic);
+ while (constFold (ic, cseSet));
+ }
/* small klugde */
if (POINTER_GET (ic) && !IS_PTR (operandType (IC_LEFT (ic))))
/* if this is a condition statment then */
/* check if the condition can be replaced */
- if (ic->op == IFX)
+ if (!computeOnly && ic->op == IFX)
{
ifxOptimize (ic, cseSet, computeOnly,
ebb, &change,
/* if the assignment & result is a temp */
/* see if we can replace it */
- if (ic->op == '=')
+ if (!computeOnly && ic->op == '=')
{
/* update the spill location for this */
while (constFold (ic, cseSet));
}
- /* if after all this it becomes a assignment to self
+ /* if after all this it becomes an assignment to self
then delete it and continue */
if (ASSIGNMENT_TO_SELF (ic))
{
/* cseAllBlocks - will sequentially go thru & do cse for all blocks */
/*-----------------------------------------------------------------*/
int
-cseAllBlocks (eBBlock ** ebbs, int count)
+cseAllBlocks (eBBlock ** ebbs, int count, int computeOnly)
{
int i;
int change = 0;
/* if optimization turned off */
for (i = 0; i < count; i++)
- change += cseBBlock (ebbs[i], FALSE, ebbs, count);
+ change += cseBBlock (ebbs[i], computeOnly, ebbs, count);
return change;
}
DEFSETFUNC (ifOperandsHave);
DEFSETFUNC (findCheaperOp);
int cseBBlock (eBBlock *, int, eBBlock **, int);
-int cseAllBlocks (eBBlock **, int);
+int cseAllBlocks (eBBlock **, int, int computeOnly);
void ifxOptimize (iCode *, set *, int, eBBlock *, int *, eBBlock **, int);
void unsetDefsAndUses (iCode *);
void updateSpillLocation (iCode * ic,int);
/* kill this one if required */
if (kill)
{
+ printf ("kill ic %d\n", ic->key);
change = 1;
gchange++;
/* eliminate this */
dumpEbbsToFileExt (DUMP_RAW1, ebbs, count);
/* do common subexpression elimination for each block */
- change = cseAllBlocks (ebbs, saveCount);
+ change = cseAllBlocks (ebbs, saveCount, FALSE);
/* dumpraw if asked for */
if (options.dump_raw)
/* global common subexpression elimination */
if (optimize.global_cse)
{
- change += cseAllBlocks (ebbs, saveCount);
+ change += cseAllBlocks (ebbs, saveCount, TRUE);
if (options.dump_gcse)
dumpEbbsToFileExt (DUMP_GCSE, ebbs, saveCount);
}
+ else
+ {
+ // compute the dataflow only
+ assert(cseAllBlocks (ebbs, saveCount, FALSE)==0);
+ }
/* kill dead code */
kchange = killDeadCode (ebbs, saveCount);
if (lchange || kchange)
{
computeDataFlow (ebbs, saveCount);
- change += cseAllBlocks (ebbs, saveCount);
+ change += cseAllBlocks (ebbs, saveCount, TRUE);
if (options.dump_loop)
dumpEbbsToFileExt (DUMP_LOOPG, ebbs, count);