From ed70c6e0de82527c2ee28c9c52a5eaf1b8f51650 Mon Sep 17 00:00:00 2001 From: epetrich Date: Fri, 3 Oct 2003 07:08:11 +0000 Subject: [PATCH] * src/z80/gen.h, * src/z80/gen.c (aopOp, aopGet, aopPut, genDummyRead), * src/mcs51/gen.h * src/mcs51/gen.c (aopOp, aopGet, aopPut, genDummyRead), * src/ds390/gen.h * src/ds390/gen.c (aopOp, aopGet, aopPut, genDummyRead), * src/SDCCicode.c (ast2iCode, geniCodeDummyRead): Fixed bug #663539 * src/SDCCopt.c (killDeadCode): Fixed bugs #663539 & #816705 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2918 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 12 ++++++++++- src/SDCCicode.c | 28 ++++++++++++++++++++++++-- src/SDCCopt.c | 8 ++++++-- src/ds390/gen.c | 31 +++++++++++++++++++++-------- src/ds390/gen.h | 3 ++- src/mcs51/gen.c | 34 ++++++++++++++++++++++--------- src/mcs51/gen.h | 3 ++- src/z80/gen.c | 53 +++++++++++++++++++++++++++++++++++++++---------- src/z80/gen.h | 4 +++- 9 files changed, 141 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index cd097e3b..6f865770 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2003-10-03 Erik Petrich + + * src/z80/gen.h, + * src/z80/gen.c (aopOp, aopGet, aopPut, genDummyRead), + * src/mcs51/gen.h + * src/mcs51/gen.c (aopOp, aopGet, aopPut, genDummyRead), + * src/ds390/gen.h + * src/ds390/gen.c (aopOp, aopGet, aopPut, genDummyRead), + * src/SDCCicode.c (ast2iCode, geniCodeDummyRead): Fixed bug #663539 + * src/SDCCopt.c (killDeadCode): Fixed bugs #663539 & #816705 + 2003-10-02 Erik Petrich * src/z80/gen.c (genRet): fixed bug #524753 @@ -8,7 +19,6 @@ * src/z80/gen.c (genZ80code, _vemit2, _emit2): added support for tracking iCodes in the peephole optimizer for z80 - 2003-10-01 Erik Petrich * src/SDCCicode.c (geniCodeJumpTable, geniCodeSwitch): fixed diff --git a/src/SDCCicode.c b/src/SDCCicode.c index a59ed4ef..960a6964 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -2862,6 +2862,24 @@ geniCodeAssign (operand * left, operand * right, int nosupdate) return left; } +/*-----------------------------------------------------------------*/ +/* geniCodeDummyRead - generate code for dummy read */ +/*-----------------------------------------------------------------*/ +static void +geniCodeDummyRead (operand * op) +{ + iCode *ic; + sym_link *type = operandType (op); + + if (!IS_VOLATILE(type)) + return; + + ic = newiCode (DUMMY_READ_VOLATILE, NULL, op); + ADDTOCHAIN (ic); + + ic->nosupdate = 1; +} + /*-----------------------------------------------------------------*/ /* geniCodeSEParms - generate code for side effecting fcalls */ /*-----------------------------------------------------------------*/ @@ -3503,8 +3521,14 @@ ast2iCode (ast * tree,int lvl) (tree->opval.op == NULLOP || tree->opval.op == BLOCK)) { - ast2iCode (tree->left,lvl+1); - ast2iCode (tree->right,lvl+1); + if (tree->left && tree->left->type == EX_VALUE) + geniCodeDummyRead (ast2iCode (tree->left,lvl+1)); + else + ast2iCode (tree->left,lvl+1); + if (tree->right && tree->right->type == EX_VALUE) + geniCodeDummyRead (ast2iCode (tree->right,lvl+1)); + else + ast2iCode (tree->right,lvl+1); return NULL; } diff --git a/src/SDCCopt.c b/src/SDCCopt.c index 34e0e78a..345f8484 100644 --- a/src/SDCCopt.c +++ b/src/SDCCopt.c @@ -679,7 +679,8 @@ killDeadCode (eBBlock ** ebbs, int count) if (SKIP_IC (ic) || ic->op == IFX || - ic->op == RETURN) + ic->op == RETURN || + ic->op == DUMMY_READ_VOLATILE) continue; /* if the result is volatile then continue */ @@ -689,6 +690,9 @@ killDeadCode (eBBlock ** ebbs, int count) /* if the result is a temp & isaddr then skip */ if (IC_RESULT (ic) && POINTER_SET (ic)) continue; + + if (POINTER_GET (ic) && IS_VOLATILE (operandType (IC_LEFT (ic))->next)) + continue; /* if the result is used in the remainder of the */ /* block then skip */ @@ -725,7 +729,7 @@ killDeadCode (eBBlock ** ebbs, int count) continue; kill = 1; - } + } kill: /* kill this one if required */ diff --git a/src/ds390/gen.c b/src/ds390/gen.c index 83ceb8bc..99dba5b4 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -1006,13 +1006,22 @@ aopOp (operand * op, iCode * ic, bool result, bool useDP2) aop->aopu.dptr = sym->dptr; return ; } - /* else spill location */ - if (sym->usl.spillLoc && getSize(sym->type) != getSize(sym->usl.spillLoc->type)) { - /* force a new aop if sizes differ */ - sym->usl.spillLoc->aop = NULL; - } - sym->aop = op->aop = aop = - aopForSym (ic, sym->usl.spillLoc, result, useDP2); + + if (sym->usl.spillLoc) + { + if (getSize(sym->type) != getSize(sym->usl.spillLoc->type)) + { + /* force a new aop if sizes differ */ + sym->usl.spillLoc->aop = NULL; + } + sym->aop = op->aop = aop = + aopForSym (ic, sym->usl.spillLoc, result, useDP2); + aop->size = getSize (sym->type); + return; + } + + /* else must be a dummy iTemp */ + sym->aop = op->aop = aop = newAsmop (AOP_DUMMY); aop->size = getSize (sym->type); return; } @@ -1182,6 +1191,8 @@ aopGet (asmop *aop, /* depending on type */ switch (aop->type) { + case AOP_DUMMY: + return zero; case AOP_R0: case AOP_R1: @@ -1383,6 +1394,10 @@ aopPut (asmop * aop, char *s, int offset) /* depending on where it is ofcourse */ switch (aop->type) { + case AOP_DUMMY: + MOVA (s); /* read s in case it was volatile */ + break; + case AOP_DIR: if (offset) { @@ -12650,7 +12665,7 @@ genDummyRead (iCode * ic) offset = 0; while (size--) { - emitcode ("mov", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE, FALSE)); + MOVA (aopGet (AOP (right), offset, FALSE, FALSE, FALSE)); offset++; } diff --git a/src/ds390/gen.h b/src/ds390/gen.h index 04726f8b..8f33d712 100644 --- a/src/ds390/gen.h +++ b/src/ds390/gen.h @@ -31,7 +31,7 @@ enum AOP_REG, AOP_DIR, AOP_DPTR, AOP_DPTR2, AOP_R0, AOP_R1, AOP_STK, AOP_IMMD, AOP_STR, - AOP_CRY, AOP_ACC, AOP_DPTRn + AOP_CRY, AOP_ACC, AOP_DPTRn, AOP_DUMMY }; /* type asmop : a homogenised type for @@ -54,6 +54,7 @@ typedef struct asmop AOP_STR - array of strings AOP_ACC - result is in the acc:b pair AOP_DPTRn - is in dptr(n) + AOP_DUMMY - read as 0, discard writes */ short coff; /* current offset */ short size; /* total size */ diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 89a30529..fc821211 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -708,13 +708,21 @@ aopOp (operand * op, iCode * ic, bool result) return; } - /* else spill location */ - if (sym->usl.spillLoc && getSize(sym->type) != getSize(sym->usl.spillLoc->type)) { - /* force a new aop if sizes differ */ - sym->usl.spillLoc->aop = NULL; - } - sym->aop = op->aop = aop = - aopForSym (ic, sym->usl.spillLoc, result); + if (sym->usl.spillLoc) + { + if (getSize(sym->type) != getSize(sym->usl.spillLoc->type)) + { + /* force a new aop if sizes differ */ + sym->usl.spillLoc->aop = NULL; + } + sym->aop = op->aop = aop = + aopForSym (ic, sym->usl.spillLoc, result); + aop->size = getSize (sym->type); + return; + } + + /* else must be a dummy iTemp */ + sym->aop = op->aop = aop = newAsmop (AOP_DUMMY); aop->size = getSize (sym->type); return; } @@ -871,6 +879,8 @@ aopGetUsesAcc (asmop *aop, int offset) if (strcmp (aop->aopu.aop_str[offset], "a") == 0) return TRUE; return FALSE; + case AOP_DUMMY: + return FALSE; default: /* Error case --- will have been caught already */ wassert(0); @@ -896,7 +906,9 @@ aopGet (asmop * aop, int offset, bool bit16, bool dname) /* depending on type */ switch (aop->type) { - + case AOP_DUMMY: + return zero; + case AOP_R0: case AOP_R1: /* if we need to increment it */ @@ -1035,6 +1047,10 @@ aopPut (asmop * aop, const char *s, int offset, bool bvolatile) /* depending on where it is ofcourse */ switch (aop->type) { + case AOP_DUMMY: + MOVA (s); /* read s in case it was volatile */ + break; + case AOP_DIR: if (offset) sprintf (d, "(%s + %d)", @@ -8965,7 +8981,7 @@ genDummyRead (iCode * ic) offset = 0; while (size--) { - emitcode ("mov", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE)); + MOVA (aopGet (AOP (right), offset, FALSE, FALSE)); offset++; } diff --git a/src/mcs51/gen.h b/src/mcs51/gen.h index 12cc17d7..ada89d6a 100644 --- a/src/mcs51/gen.h +++ b/src/mcs51/gen.h @@ -31,7 +31,7 @@ enum AOP_REG, AOP_DIR, AOP_DPTR, AOP_R0, AOP_R1, AOP_STK, AOP_IMMD, AOP_STR, - AOP_CRY, AOP_ACC + AOP_CRY, AOP_ACC, AOP_DUMMY }; /* type asmop : a homogenised type for @@ -53,6 +53,7 @@ typedef struct asmop AOP_CRY - carry contains the value of this AOP_STR - array of strings AOP_ACC - result is in the acc:b pair + AOP_DUMMY - read as 0, discard writes */ short coff; /* current offset */ short size; /* total size */ diff --git a/src/z80/gen.c b/src/z80/gen.c index dc7f19c5..26394433 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -262,7 +262,8 @@ static const char *aopNames[] = { "AOP_HLREG", "AOP_SIMPLELIT", "AOP_EXSTK", - "AOP_PAIRPT" + "AOP_PAIRPT", + "AOP_DUMMY" }; static bool @@ -1082,13 +1083,21 @@ aopOp (operand * op, iCode * ic, bool result, bool requires_a) return; } - /* else spill location */ - if (sym->usl.spillLoc && getSize(sym->type) != getSize(sym->usl.spillLoc->type)) { - /* force a new aop if sizes differ */ - sym->usl.spillLoc->aop = NULL; - } - sym->aop = op->aop = aop = - aopForSym (ic, sym->usl.spillLoc, result, requires_a); + if (sym->usl.spillLoc) + { + if (getSize(sym->type) != getSize(sym->usl.spillLoc->type)) + { + /* force a new aop if sizes differ */ + sym->usl.spillLoc->aop = NULL; + } + sym->aop = op->aop = aop = + aopForSym (ic, sym->usl.spillLoc, result, requires_a); + aop->size = getSize (sym->type); + return; + } + + /* else must be a dummy iTemp */ + sym->aop = op->aop = aop = newAsmop (AOP_DUMMY); aop->size = getSize (sym->type); return; } @@ -1584,6 +1593,10 @@ aopGet (asmop * aop, int offset, bool bit16) /* depending on type */ switch (aop->type) { + case AOP_DUMMY: + tsprintf (buffer, sizeof(buffer), "!zero"); + return traceAlloc(&_G.trace.aops, Safe_strdup(buffer)); + case AOP_IMMD: /* PENDING: re-target */ if (bit16) @@ -1770,6 +1783,10 @@ aopPut (asmop * aop, const char *s, int offset) /* depending on where it is ofcourse */ switch (aop->type) { + case AOP_DUMMY: + _moveA (s); /* in case s is volatile */ + break; + case AOP_DIR: /* Direct. Hmmm. */ wassert (IS_GB); @@ -7099,9 +7116,24 @@ genReceive (iCode * ic) static void genDummyRead (iCode * ic) { - emit2 ("; genDummyRead not implemented"); + operand *right; + int size, offset; - ic = ic; + right = IC_RIGHT (ic); + aopOp (right, ic, FALSE, FALSE); + + /* general case */ + size = AOP_SIZE (right); + offset = 0; + + while (size--) + { + _moveA (aopGet (AOP (right), offset, FALSE)); + offset++; + } + +release: + freeAsmop (right, NULL, ic); } enum @@ -7910,6 +7942,7 @@ genZ80Code (iCode * lic) break; case DUMMY_READ_VOLATILE: + emitDebug ("; genDummyRead"); genDummyRead (ic); break; diff --git a/src/z80/gen.h b/src/z80/gen.h index becc53ad..3e666177 100644 --- a/src/z80/gen.h +++ b/src/z80/gen.h @@ -57,7 +57,9 @@ typedef enum /* Is in the extended stack pointer (IY on the Z80) */ AOP_EXSTK, /* Is referenced by a pointer in a register pair. */ - AOP_PAIRPTR + AOP_PAIRPTR, + /* Read as 0, discard writes */ + AOP_DUMMY } AOP_TYPE; -- 2.30.2