From 5ed336666f65eab6494a18ba76b20defc841747c Mon Sep 17 00:00:00 2001 From: MaartenBrock Date: Fri, 13 Jul 2007 12:21:56 +0000 Subject: [PATCH] * src/SDCCcse.c (replaceAllSymBySym): renamed siaddr to isaddr, (cseBBlock): remember aggr2ptr has been used * src/SDCCicode.c (operandSize): added function to handle aggr2ptr, (geniCodeAssign): fixed bug 868103 * src/SDCCicode.h: made operand.aggr2ptr 2 bits wide, added operandSize prototype * src/mcs51/gen.c (aopOp): use operandSize to fix bug 868103, (genDataPointerSet): use size of result, (gencjne): added parameter useCarry for optimization, (genCmpEq): use carry if appropriate, (genXor): check if operand already in carry * support/regression/tests/bug-868103.c: enabled test git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4882 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 15 +++++++++++ src/SDCCcse.c | 35 +++++++++++------------- src/SDCCicode.c | 24 +++++++++++++++-- src/SDCCicode.h | 4 ++- src/mcs51/gen.c | 39 +++++++++++++++++++-------- support/regression/tests/bug-868103.c | 9 ++----- 6 files changed, 86 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index 35478722..a053bc9f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2007-07-13 Maarten Brock + + * src/SDCCcse.c (replaceAllSymBySym): renamed siaddr to isaddr, + (cseBBlock): remember aggr2ptr has been used + * src/SDCCicode.c (operandSize): added function to handle aggr2ptr, + (geniCodeAssign): fixed bug 868103 + * src/SDCCicode.h: made operand.aggr2ptr 2 bits wide, + added operandSize prototype + * src/mcs51/gen.c (aopOp): use operandSize to fix bug 868103, + (genDataPointerSet): use size of result, + (gencjne): added parameter useCarry for optimization, + (genCmpEq): use carry if appropriate, + (genXor): check if operand already in carry + * support/regression/tests/bug-868103.c: enabled test + 2007-07-12 Raphael Neider * src/pic16/gen.c (genNearPointerSet): fixed handling of literals diff --git a/src/SDCCcse.c b/src/SDCCcse.c index 7d86488d..d33632ab 100644 --- a/src/SDCCcse.c +++ b/src/SDCCcse.c @@ -188,7 +188,7 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) #endif for (lic = ic; lic; lic = lic->next) { - int siaddr; + int isaddr; /* do the special cases first */ if (lic->op == IFX) @@ -199,9 +199,9 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) bitVectUnSetBit (OP_USES (from), lic->key); OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key); - siaddr = IC_COND (lic)->isaddr; + isaddr = IC_COND (lic)->isaddr; IC_COND (lic) = operandFromOperand (to); - IC_COND (lic)->isaddr = siaddr; + IC_COND (lic)->isaddr = isaddr; } continue; @@ -215,9 +215,9 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) bitVectUnSetBit (OP_USES (from), lic->key); OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key); - siaddr = IC_COND (lic)->isaddr; + isaddr = IC_COND (lic)->isaddr; IC_JTCOND (lic) = operandFromOperand (to); - IC_JTCOND (lic)->isaddr = siaddr; + IC_JTCOND (lic)->isaddr = isaddr; } continue; @@ -246,9 +246,9 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) bitVectUnSetBit (OP_DEFS (from), lic->key); OP_DEFS(to)=bitVectSetBit (OP_DEFS (to), lic->key); } - siaddr = IC_RESULT (lic)->isaddr; + isaddr = IC_RESULT (lic)->isaddr; IC_RESULT (lic) = operandFromOperand (to); - IC_RESULT (lic)->isaddr = siaddr; + IC_RESULT (lic)->isaddr = isaddr; } if (IS_SYMOP (to) && @@ -256,9 +256,9 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) { bitVectUnSetBit (OP_USES (from), lic->key); OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key); - siaddr = IC_RIGHT (lic)->isaddr; + isaddr = IC_RIGHT (lic)->isaddr; IC_RIGHT (lic) = operandFromOperand (to); - IC_RIGHT (lic)->isaddr = siaddr; + IC_RIGHT (lic)->isaddr = isaddr; } if (IS_SYMOP (to) && @@ -266,9 +266,9 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) { bitVectUnSetBit (OP_USES (from), lic->key); OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key); - siaddr = IC_LEFT (lic)->isaddr; + isaddr = IC_LEFT (lic)->isaddr; IC_LEFT (lic) = operandFromOperand (to); - IC_LEFT (lic)->isaddr = siaddr; + IC_LEFT (lic)->isaddr = isaddr; } } } @@ -1980,11 +1980,11 @@ cseBBlock (eBBlock * ebb, int computeOnly, IC_LEFT (ic)->aggr2ptr = 0; fixUpTypes (ic); } - else if (IC_LEFT (ic)->aggr2ptr) + else if (IC_LEFT (ic)->aggr2ptr == 1) {/* band aid for kludge */ setOperandType (IC_LEFT (ic), aggrToPtr (operandType (IC_LEFT (ic)), TRUE)); - IC_LEFT (ic)->aggr2ptr = 0; + IC_LEFT (ic)->aggr2ptr++; fixUpTypes (ic); } } @@ -1997,11 +1997,11 @@ cseBBlock (eBBlock * ebb, int computeOnly, aggrToPtr (operandType (IC_RESULT (ic)), FALSE)); IC_RESULT (ic)->aggr2ptr = 0; } - else if (IC_RESULT (ic)->aggr2ptr) + else if (IC_RESULT (ic)->aggr2ptr == 1) {/* band aid for kludge */ setOperandType (IC_RESULT (ic), aggrToPtr (operandType (IC_RESULT (ic)), TRUE)); - IC_RESULT (ic)->aggr2ptr = 0; + IC_RESULT (ic)->aggr2ptr++; } } @@ -2090,7 +2090,7 @@ cseBBlock (eBBlock * ebb, int computeOnly, } } - /*right operand */ + /* right operand */ if (IS_SYMOP (IC_RIGHT (ic)) && !computeOnly) { @@ -2202,7 +2202,6 @@ cseBBlock (eBBlock * ebb, int computeOnly, deleteItemIf (&cseSet, ifOperandsHave, IC_RESULT (ic)); /* delete any previous definitions */ ebb->defSet = bitVectCplAnd (ebb->defSet, OP_DEFS (IC_RESULT (ic))); - } /* add the left & right to the defUse set */ @@ -2211,7 +2210,6 @@ cseBBlock (eBBlock * ebb, int computeOnly, OP_USES(IC_LEFT (ic))= bitVectSetBit (OP_USES (IC_LEFT (ic)), ic->key); setUsesDefs (IC_LEFT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs); - } if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic))) @@ -2219,7 +2217,6 @@ cseBBlock (eBBlock * ebb, int computeOnly, OP_USES(IC_RIGHT (ic))= bitVectSetBit (OP_USES (IC_RIGHT (ic)), ic->key); setUsesDefs (IC_RIGHT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs); - } /* for the result it is special case, put the result */ diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 2c0b61ea..24def78e 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -819,6 +819,24 @@ operandType (operand * op) } } +/*-----------------------------------------------------------------*/ +/* operandSize - returns size of an operand in bytes */ +/*-----------------------------------------------------------------*/ +unsigned int +operandSize (operand * op) +{ + sym_link *type; + + /* if nothing return 0 */ + if (!op) + return 0; + + type = operandType (op); + if (op->aggr2ptr == 2) + type = type->next; + return getSize (type); +} + /*-----------------------------------------------------------------*/ /* isParamterToCall - will return 1 if op is a parameter to args */ /*-----------------------------------------------------------------*/ @@ -3204,7 +3222,9 @@ geniCodeAssign (operand * left, operand * right, int nosupdate, int strictLval) if (left->isaddr && IS_PTR (ltype) && IS_ITEMP (left) && compareType (ltype, rtype) <= 0) { - if (compareType (ltype->next, rtype) < 0) + if (left->aggr2ptr) + right = geniCodeCast (ltype, right, TRUE); + else if (compareType (ltype->next, rtype) < 0) right = geniCodeCast (ltype->next, right, TRUE); } else if (compareType (ltype, rtype) < 0) @@ -4291,7 +4311,7 @@ ast2iCode (ast * tree,int lvl) tree->opval.op); */ { - operand *leftOp, *rightOp; + operand *leftOp, *rightOp; leftOp = geniCodeRValue (left , FALSE); rightOp = geniCodeRValue (right, FALSE); diff --git a/src/SDCCicode.h b/src/SDCCicode.h index a05c67c4..30e730a8 100644 --- a/src/SDCCicode.h +++ b/src/SDCCicode.h @@ -75,7 +75,8 @@ typedef struct operand { OPTYPE type; /* type of operand */ unsigned int isaddr:1; /* is an address */ - unsigned int aggr2ptr:1; /* must change aggregate to pointer to aggregate */ + unsigned int aggr2ptr:2; /* 1: must change aggregate to pointer to aggregate */ + /* 2: aggregate has been changed to pointer to aggregate */ unsigned int isvolatile:1; /* is a volatile operand */ unsigned int isGlobal:1; /* is a global operand */ unsigned int isPtr:1; /* is assigned a pointer */ @@ -322,6 +323,7 @@ symbol *newiTempLabel (char *); symbol *newiTempLoopHeaderLabel (bool); iCode *newiCode (int, operand *, operand *); sym_link *operandType (operand *); +unsigned int operandSize (operand *); operand *operandFromValue (value *); operand *operandFromSymbol (symbol *); operand *operandFromLink (sym_link *); diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index dbff5f9a..dd0eb5a8 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -969,7 +969,7 @@ aopOp (operand * op, iCode * ic, bool result) if (sym->remat) { sym->aop = op->aop = aop = aopForRemat (sym); - aop->size = getSize (sym->type); + aop->size = operandSize (op); return; } @@ -6116,7 +6116,7 @@ gencjneshort (operand * left, operand * right, symbol * lbl) /* gencjne - compare and jump if not equal */ /*-----------------------------------------------------------------*/ static void -gencjne (operand * left, operand * right, symbol * lbl) +gencjne (operand * left, operand * right, symbol * lbl, bool useCarry) { symbol *tlbl = newiTempLabel (NULL); @@ -6124,10 +6124,16 @@ gencjne (operand * left, operand * right, symbol * lbl) gencjneshort (left, right, lbl); - emitcode ("mov", "a,%s", one); + if (useCarry) + SETC; + else + MOVA (one); emitcode ("sjmp", "%05d$", tlbl->key + 100); emitLabel (lbl); - emitcode ("clr", "a"); + if (useCarry) + CLRC; + else + MOVA (zero); emitLabel (tlbl); } @@ -6288,12 +6294,13 @@ genCmpEq (iCode * ic, iCode * ifx) } else { - gencjne (left, right, newiTempLabel (NULL)); if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result)) { - aopPut (result, "a", 0); + gencjne (left, right, newiTempLabel (NULL), TRUE); + aopPut (result, "c", 0); goto release; } + gencjne (left, right, newiTempLabel (NULL), FALSE); if (ifx) { genIfxJump (ifx, "a", left, right, result); @@ -7448,7 +7455,16 @@ genXor (iCode * ic, iCode * ifx) if (AOP_TYPE (right) == AOP_CRY) { // c = bit ^ bit; - emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir); + if (IS_SYMOP (left) && OP_SYMBOL (left) && OP_SYMBOL (left)->accuse) + {// left already is in the carry + operand *tmp = right; + right = left; + left = tmp; + } + else + { + emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir); + } } else { @@ -10519,7 +10535,7 @@ genDataPointerSet (operand * right, l = aopGet (result, 0, FALSE, TRUE); l++; //remove # - size = AOP_SIZE (right); + size = AOP_SIZE (result); while (size--) { if (offset) @@ -10530,8 +10546,8 @@ genDataPointerSet (operand * right, aopGet (right, offset++, FALSE, FALSE)); } - freeAsmop (result, NULL, ic, TRUE); freeAsmop (right, NULL, ic, TRUE); + freeAsmop (result, NULL, ic, TRUE); } /*-----------------------------------------------------------------*/ @@ -10660,9 +10676,10 @@ genNearPointerSet (operand * right, } /* done */ - if (pi) pi->generated = 1; - freeAsmop (result, NULL, ic, TRUE); + if (pi) + pi->generated = 1; freeAsmop (right, NULL, ic, TRUE); + freeAsmop (result, NULL, ic, TRUE); } /*-----------------------------------------------------------------*/ diff --git a/support/regression/tests/bug-868103.c b/support/regression/tests/bug-868103.c index ed2c04e7..6180aa81 100644 --- a/support/regression/tests/bug-868103.c +++ b/support/regression/tests/bug-868103.c @@ -14,12 +14,6 @@ #include -#if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80) -# define near -# define far -# define code -#endif - typedef struct { STORAGE1 char * bar[2]; } foo; @@ -27,7 +21,8 @@ typedef struct { STORAGE1 char c = 'x'; STORAGE2 foo f; -void bug868103(void) +void +testBug868103(void) { f.bar[1] = &c; ASSERT(f.bar[1] == &c); -- 2.39.5