X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCcse.c;h=00cda0b8521905d298220c27e98f27810eaa43c9;hb=cea246282ef02e72548408c02833d6efe2ea0786;hp=dad1084b2a25550b689f30beedf4a78d3996ef15;hpb=958a651d053c089412d87ab75101812383d03f19;p=fw%2Fsdcc diff --git a/src/SDCCcse.c b/src/SDCCcse.c index dad1084b..00cda0b8 100644 --- a/src/SDCCcse.c +++ b/src/SDCCcse.c @@ -67,6 +67,8 @@ int pcseDef (void *item, va_list ap) cseDef *cdp = item; iCodeTable *icTab ; + (void)ap; + if (!cdp->sym) fprintf(stdout,"**null op**"); printOperand(cdp->sym,stdout); @@ -276,11 +278,14 @@ DEFSETFUNC(findPointerSet) cseDef *cdp = item; V_ARG(operand *,op); V_ARG(operand **,opp); + V_ARG(operand *,rop); if (POINTER_SET(cdp->diCode) && IC_RESULT(cdp->diCode)->key == op->key && !isOperandVolatile(IC_RESULT(cdp->diCode),TRUE) && - !isOperandVolatile(IC_RIGHT(cdp->diCode),TRUE)) { + !isOperandVolatile(IC_RIGHT(cdp->diCode),TRUE) && + getSize(operandType(IC_RIGHT(cdp->diCode))) == + getSize(operandType(rop))) { *opp = IC_RIGHT(cdp->diCode); return 1; } @@ -430,9 +435,10 @@ DEFSETFUNC(ifPointerGet) { cseDef *cdp = item; V_ARG(operand *,op); + iCode *dic = cdp->diCode; + operand *left = IC_LEFT(cdp->diCode); - if (POINTER_GET(cdp->diCode) && - IC_LEFT(cdp->diCode)->key == op->key) + if (POINTER_GET(dic) && left->key == op->key) return 1; return 0; @@ -761,6 +767,7 @@ void updateSpillLocation ( iCode *ic) if (ASSIGN_ITEMP_TO_ITEMP(ic) && !SPIL_LOC(IC_RIGHT(ic)) && + !bitVectBitsInCommon(OP_DEFS(IC_RIGHT(ic)),OP_USES(IC_RESULT(ic))) && OP_SYMBOL(IC_RESULT(ic))->isreqv) { setype = getSpec(operandType(IC_RESULT(ic))); @@ -795,6 +802,36 @@ void setUsesDefs (operand *op, bitVect *bdefs, *oud = bitVectUnion(*oud,adefs); } +/*-----------------------------------------------------------------*/ +/* unsetDefsAndUses - clear this operation for the operands */ +/*-----------------------------------------------------------------*/ +void unsetDefsAndUses ( iCode *ic ) +{ + if ( ic->op == JUMPTABLE) + return ; + + /* take away this definition from the def chain of the */ + /* result & take away from use set of the operands */ + if (ic->op != IFX) { + /* turn off def set */ + if (IS_SYMOP(IC_RESULT(ic))) { + if ( !POINTER_SET(ic)) + bitVectUnSetBit(OP_DEFS(IC_RESULT(ic)),ic->key); + else + bitVectUnSetBit(OP_USES(IC_RESULT(ic)),ic->key); + } + /* turn off the useSet for the operands */ + if (IS_SYMOP(IC_LEFT(ic))) + bitVectUnSetBit (OP_USES(IC_LEFT(ic)),ic->key); + + if (IS_SYMOP(IC_RIGHT(ic))) + bitVectUnSetBit (OP_USES(IC_RIGHT(ic)),ic->key); + } + else /* must be ifx turn off the use */ + if (IS_SYMOP(IC_COND(ic))) + bitVectUnSetBit (OP_USES(IC_COND(ic)),ic->key); +} + /*-----------------------------------------------------------------*/ /* ifxOptimize - changes ifx conditions if it can */ /*-----------------------------------------------------------------*/ @@ -819,7 +856,7 @@ void ifxOptimize (iCode *ic, set *cseSet, /* if the conditional is a literal then */ if (IS_OP_LITERAL(IC_COND(ic))) { - if ( operandLitValue(IC_COND(ic)) && IC_TRUE(ic)) { + if ( (operandLitValue(IC_COND(ic)) != 0.0) && IC_TRUE(ic)) { /* change to a goto */ ic->op = GOTO ; @@ -869,36 +906,6 @@ void ifxOptimize (iCode *ic, set *cseSet, return ; } -/*-----------------------------------------------------------------*/ -/* unsetDefsAndUses - clear this operation for the operands */ -/*-----------------------------------------------------------------*/ -void unsetDefsAndUses ( iCode *ic ) -{ - if ( ic->op == JUMPTABLE) - return ; - - /* take away this definition from the def chain of the */ - /* result & take away from use set of the operands */ - if (ic->op != IFX) { - /* turn off def set */ - if (IS_SYMOP(IC_RESULT(ic))) { - if ( !POINTER_SET(ic)) - bitVectUnSetBit(OP_DEFS(IC_RESULT(ic)),ic->key); - else - bitVectUnSetBit(OP_USES(IC_RESULT(ic)),ic->key); - } - /* turn off the useSet for the operands */ - if (IS_SYMOP(IC_LEFT(ic))) - bitVectUnSetBit (OP_USES(IC_LEFT(ic)),ic->key); - - if (IS_SYMOP(IC_RIGHT(ic))) - bitVectUnSetBit (OP_USES(IC_RIGHT(ic)),ic->key); - } - else /* must be ifx turn off the use */ - if (IS_SYMOP(IC_COND(ic))) - bitVectUnSetBit (OP_USES(IC_COND(ic)),ic->key); -} - /*-----------------------------------------------------------------*/ /* diCodeForSym - finds the definiting instruction for a symbol */ /*-----------------------------------------------------------------*/ @@ -984,14 +991,14 @@ int constFold (iCode *ic, set *cseSet) /* will delete from cseSet all get pointers computed from this */ /* pointer. A simple ifOperandsHave is not good enough here */ /*-----------------------------------------------------------------*/ -static void deleteGetPointers (set **cseSet,operand *op,eBBlock *ebb) +static void deleteGetPointers (set **cseSet, set **pss, operand *op,eBBlock *ebb) { set *compItems = NULL; cseDef *cdp ; operand *cop; /* easy return */ - if (!*cseSet) + if (!*cseSet && !*pss) return ; /* first find all items computed from this operand . @@ -1018,12 +1025,15 @@ static void deleteGetPointers (set **cseSet,operand *op,eBBlock *ebb) /* now delete all pointer gets with this op */ deleteItemIf(cseSet,ifPointerGet,op); + deleteItemIf(pss,ifPointerSet,op); + /* set the bit vector used by dataFlow computation later */ ebb->ptrsSet = bitVectSetBit(ebb->ptrsSet,op->key); /* now for the computed items */ for (cop = setFirstItem(compItems); cop ; cop = setNextItem(compItems)) { ebb->ptrsSet = bitVectSetBit(ebb->ptrsSet,cop->key); deleteItemIf(cseSet,ifPointerGet,cop); + deleteItemIf(pss,ifPointerSet,cop); } } @@ -1132,11 +1142,18 @@ int cseBBlock ( eBBlock *ebb, int computeOnly, setUsesDefs(IC_LEFT(ic),ebb->defSet, ebb->outDefs,&ebb->usesDefs); } + + /* if we a sending a pointer as a parameter then kill all cse since the pointed to item might be changed in the function being called */ - if (IS_PTR(operandType(IC_LEFT(ic)))) { - deleteGetPointers(&cseSet,IC_LEFT(ic),ebb); + if ((ic->op == IPUSH || ic->op == SEND) && + IS_PTR(operandType(IC_LEFT(ic)))) { + deleteGetPointers(&cseSet,&ptrSetSet,IC_LEFT(ic),ebb); + ebb->ptrsSet = bitVectSetBit(ebb->ptrsSet,IC_LEFT(ic)->key); + for (i = 0 ; i < count ;ebbs[i++]->visited = 0); + applyToSet(ebb->succList,delGetPointerSucc, + IC_LEFT(ic),ebb->dfnum); } continue; } @@ -1157,6 +1174,16 @@ int cseBBlock ( eBBlock *ebb, int computeOnly, algebraicOpts (ic); while (constFold(ic,cseSet)); + /* small klugde */ + if (POINTER_GET(ic) && !IS_PTR(operandType(IC_LEFT(ic)))) { + setOperandType(IC_LEFT(ic), + aggrToPtr(operandType(IC_LEFT(ic)),FALSE)); + } + if (POINTER_SET(ic) && !IS_PTR(operandType(IC_RESULT(ic)))) { + setOperandType(IC_RESULT(ic), + aggrToPtr(operandType(IC_RESULT(ic)),FALSE)); + } + /* if this is a condition statment then */ /* check if the condition can be replaced */ if (ic->op == IFX ) { @@ -1202,7 +1229,8 @@ int cseBBlock ( eBBlock *ebb, int computeOnly, for the same pointer visible if yes then change this into an assignment */ pdop = NULL; - if (applyToSetFTrue(cseSet,findPointerSet,IC_LEFT(ic),&pdop)){ + if (applyToSetFTrue(cseSet,findPointerSet,IC_LEFT(ic),&pdop,IC_RESULT(ic)) && + !bitVectBitValue(ebb->ptrsSet,pdop->key)){ ic->op = '='; IC_LEFT(ic) = NULL; IC_RIGHT(ic) = pdop; @@ -1316,7 +1344,10 @@ int cseBBlock ( eBBlock *ebb, int computeOnly, if (ASSIGNMENT(ic) && OTHERS_PARM(OP_SYMBOL(IC_RESULT(ic))) && IS_PTR(operandType(IC_RESULT(ic)))) { - deleteGetPointers(&cseSet,IC_RIGHT(ic),ebb); + deleteGetPointers(&cseSet,&ptrSetSet,IC_RIGHT(ic),ebb); + for (i = 0 ; i < count ;ebbs[i++]->visited = 0); + applyToSet(ebb->succList,delGetPointerSucc,IC_RIGHT(ic),ebb->dfnum); + ebb->ptrsSet = bitVectSetBit(ebb->ptrsSet,IC_RIGHT(ic)->key); } /* if this is a pointerget then see if we can replace @@ -1325,7 +1356,7 @@ int cseBBlock ( eBBlock *ebb, int computeOnly, !(IS_BITFIELD(OP_SYMBOL(IC_RESULT(ic))->etype) || isOperandVolatile(IC_LEFT(ic),TRUE))) { pdop = NULL; - applyToSet(ptrSetSet,findPointerSet,IC_LEFT(ic),&pdop); + applyToSet(ptrSetSet,findPointerSet,IC_LEFT(ic),&pdop,IC_RESULT(ic)); /* if we find it then locally replace all references to the result with what we assigned */ if (pdop) {