-//#define LIVERANGEHUNT
-#ifdef LIVERANGEHUNT
- #define LRH(x) x
-#else
- #define LRH(x)
-#endif
/*-------------------------------------------------------------------------
SDCCcse.c - source file for Common Subexpressions and other utility
{
iCode *lic;
- LRH(printf ("replaceAllSymBySym: from %s to %s\n", OP_SYMBOL(from)->name, OP_SYMBOL(to)->name));
for (lic = ic; lic; lic = lic->next)
{
int siaddr;
continue;
}
- if (IC_RESULT (lic) && IC_RESULT (lic)->key == from->key)
+ if (IS_SYMOP(to) &&
+ IC_RESULT (lic) && IC_RESULT (lic)->key == from->key)
{
/* maintain du chains */
if (POINTER_SET (lic))
if (IS_SPEC(operandType (cop)) && IS_SPEC(operandType (*opp)) &&
SPEC_NOUN(operandType(cop)) != SPEC_NOUN(operandType(*opp)))
{
- //fprintf(stderr,
- // "findCheaperOp: "
- // "was about to replace %s with %s, Kev says no.\n",
- // nounName(operandType(cop)),
- // nounName(operandType(*opp)));
- *opp = NULL;
- return 0;
+ // special case: we can make an unsigned char literal
+ // into an int literal with no cost.
+ if (isOperandLiteral(*opp)
+ && SPEC_NOUN(operandType(*opp)) == V_CHAR
+ && SPEC_NOUN(operandType(cop)) == V_INT)
+ {
+ *opp = operandFromOperand (*opp);
+ SPEC_NOUN(operandType(*opp)) = V_INT;
+ }
+ else
+ {
+ // No clue...
+ *opp = NULL;
+ return 0;
+ }
+
}
- LRH(printf ("findCheaperOp: %s < %s\n",\
- IS_SYMOP((*opp)) ? OP_SYMBOL((*opp))->name : "!SYM",\
- OP_SYMBOL(cop)->name));
return 1;
}
if (isiCodeEqual (ic, cdp->diCode) &&
isOperandEqual (cdp->sym, IC_RESULT (cdp->diCode)))
{
- LRH(printf ("findPrevIc same: %d %d\n", ic->key, cdp->diCode->key));
- *icp = cdp->diCode;
+ *icp = cdp->diCode;
return 1;
}
isOperandEqual (IC_LEFT (ic), IC_RIGHT (cdp->diCode)) &&
isOperandEqual (IC_RIGHT (ic), IC_LEFT (cdp->diCode)))
{
- LRH(printf ("findPrevIc inter: %d %d\n", ic->key, cdp->diCode->key));
*icp = cdp->diCode;
return 1;
}
/* 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))))
aggrToPtr (operandType (IC_RESULT (ic)), FALSE));
}
- /* if this is a condition statment then */
+ /* if this is a condition statement then */
/* check if the condition can be replaced */
if (ic->op == IFX)
{
/* 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 */
}
/* if left or right changed then do algebraic */
- if (change)
+ if (!computeOnly && change)
{
algebraicOpts (ic);
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;
}