From 3deeed761a1da5128e841a85bf4773a8a48e15b4 Mon Sep 17 00:00:00 2001 From: MaartenBrock Date: Mon, 29 Oct 2007 14:05:31 +0000 Subject: [PATCH] * src/ds390/peeph.def: replaced 24bitModeAndPortDS390 by 24bitMode, portIsDS390 * src/mcs51/gen.c (genOr): optimized for RFE 1750727 * src/SDCCpeeph.c (flat24bitModeAndPortDS390): removed (notVolatileVariable): also check sloc names, (callFuncByName): moved ftab[] out of function and sorted it by use git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4948 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 9 ++ src/SDCCpeeph.c | 239 ++++++++++++++++++++------------------------ src/ds390/peeph.def | 4 +- src/mcs51/gen.c | 24 ++--- 4 files changed, 132 insertions(+), 144 deletions(-) diff --git a/ChangeLog b/ChangeLog index c03c9c86..e8d02344 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-10-29 Maarten Brock + + * src/ds390/peeph.def: replaced 24bitModeAndPortDS390 by + 24bitMode, portIsDS390 + * src/mcs51/gen.c (genOr): optimized for RFE 1750727 + * src/SDCCpeeph.c (flat24bitModeAndPortDS390): removed + (notVolatileVariable): also check sloc names, + (callFuncByName): moved ftab[] out of function and sorted it by use + 2007-10-28 Maarten Brock * device/include/stdarg.h: fixed bug in va_start macro for --xstack diff --git a/src/SDCCpeeph.c b/src/SDCCpeeph.c index afb6de55..0359d894 100644 --- a/src/SDCCpeeph.c +++ b/src/SDCCpeeph.c @@ -98,16 +98,6 @@ pcDistance (lineNode * cpos, char *lbl, bool back) return 0; } -/*-----------------------------------------------------------------*/ -/* flat24bitModeAndPortDS390 - */ -/*-----------------------------------------------------------------*/ -FBYNAME (flat24bitModeAndPortDS390) -{ - return (((strcmp(port->target,"ds390") == 0) || - (strcmp(port->target,"ds400") == 0)) && - (options.model == MODEL_FLAT24)); -} - /*-----------------------------------------------------------------*/ /* portIsDS390 - return true if port is DS390 */ /*-----------------------------------------------------------------*/ @@ -141,8 +131,6 @@ FBYNAME (useAcallAjmp) return (options.acall_ajmp && (strcmp(port->target,"mcs51") == 0)); } - - /*-----------------------------------------------------------------*/ /* labelInRange - will check to see if label %5 is within range */ /*-----------------------------------------------------------------*/ @@ -182,7 +170,6 @@ FBYNAME (labelInRange) return TRUE; } - /*-----------------------------------------------------------------*/ /* labelJTInRange - will check to see if label %5 and up are */ /* within range. */ @@ -226,7 +213,6 @@ FBYNAME (labelJTInRange) return TRUE; } - /*-----------------------------------------------------------------*/ /* labelIsReturnOnly - Check if label %5 is followed by RET */ /*-----------------------------------------------------------------*/ @@ -281,7 +267,6 @@ FBYNAME (labelIsReturnOnly) return FALSE; } - /*-----------------------------------------------------------------*/ /* labelIsUncondJump - Check if label %5 is followed by an */ /* unconditional jump and put the destination of that jump in %6 */ @@ -365,7 +350,6 @@ FBYNAME (labelIsUncondJump) return TRUE; } - /*-----------------------------------------------------------------*/ /* okToRemoveSLOC - Check if label %1 is a SLOC and not other */ /* usage of it in the code depends on a value from this section */ @@ -411,7 +395,7 @@ FBYNAME (deadMove) if (port->peep.deadMove) return port->peep.deadMove (reg, currPl, head); - fprintf (stderr, "Function deadMove not initialized in port structure\n"); + fprintf (stderr, "Function deadMove not initialized in port structure\n"); return FALSE; } @@ -525,7 +509,6 @@ FBYNAME (operandsNotSame6) return TRUE; } - /*-----------------------------------------------------------------*/ /* operandsNotSame7- check if any pair of %1,%2,%3,.. are the same */ /*-----------------------------------------------------------------*/ @@ -696,7 +679,6 @@ FBYNAME (labelRefCount) return rc; } - /* labelRefCountChange: * takes two parameters: a variable (bound to a label name) * and a signed int for changing the reference count. @@ -773,7 +755,6 @@ FBYNAME (labelRefCountChange) return rc; } - /* Within the context of the lines currPl through endPl, determine ** if the variable var contains a symbol that is volatile. Returns ** TRUE only if it is certain that this was not volatile (the symbol @@ -838,22 +819,42 @@ notVolatileVariable(char *var, lineNode *currPl, lineNode *endPl) { case IFX: op = IC_COND (cl->ic); - if (IS_SYMOP (op) && !strcmp(OP_SYMBOL (op)->rname,symname) ) - return !op->isvolatile; + if (IS_SYMOP (op) && + ( !strcmp(OP_SYMBOL (op)->rname, symname) || + (OP_SYMBOL (op)->isspilt && !strcmp(SPIL_LOC (op)->rname, symname)) )) + { + return !op->isvolatile; + } case JUMPTABLE: op = IC_JTCOND (cl->ic); - if (IS_SYMOP (op) && !strcmp(OP_SYMBOL (op)->rname,symname) ) - return !op->isvolatile; + if (IS_SYMOP (op) && + ( !strcmp(OP_SYMBOL (op)->rname, symname) || + (OP_SYMBOL (op)->isspilt && !strcmp(SPIL_LOC (op)->rname, symname)) )) + { + return !op->isvolatile; + } default: op = IC_LEFT (cl->ic); - if (IS_SYMOP (op) && !strcmp(OP_SYMBOL (op)->rname,symname) ) - return !op->isvolatile; + if (IS_SYMOP (op) && + ( !strcmp(OP_SYMBOL (op)->rname, symname) || + (OP_SYMBOL (op)->isspilt && !strcmp(SPIL_LOC (op)->rname, symname)) )) + { + return !op->isvolatile; + } op = IC_RIGHT (cl->ic); - if (IS_SYMOP (op) && !strcmp(OP_SYMBOL (op)->rname,symname) ) - return !op->isvolatile; + if (IS_SYMOP (op) && + ( !strcmp(OP_SYMBOL (op)->rname, symname) || + (OP_SYMBOL (op)->isspilt && !strcmp(SPIL_LOC (op)->rname, symname)) )) + { + return !op->isvolatile; + } op = IC_RESULT (cl->ic); - if (IS_SYMOP (op) && !strcmp(OP_SYMBOL (op)->rname,symname) ) - return !op->isvolatile; + if (IS_SYMOP (op) && + ( !strcmp(OP_SYMBOL (op)->rname, symname) || + (OP_SYMBOL (op)->isspilt && !strcmp(SPIL_LOC (op)->rname, symname)) )) + { + return !op->isvolatile; + } } } } @@ -952,7 +953,6 @@ FBYNAME (notVolatile) return TRUE; - error: fprintf (stderr, "*** internal error: notVolatile peephole restriction" @@ -960,7 +960,6 @@ error: return FALSE; } - /*------------------------------------------------------------------*/ /* setFromConditionArgs - parse a peephole condition's arguments */ /* to produce a set of strings, one per argument. Variables %x will */ @@ -1041,7 +1040,6 @@ operandBaseName (const char *op) return op; } - /*-------------------------------------------------------------------*/ /* operandsNotRelated - returns true if the condition's operands are */ /* not related (taking into account register name aliases). N-way */ @@ -1082,7 +1080,6 @@ FBYNAME (operandsNotRelated) return TRUE; } - /*-------------------------------------------------------------------*/ /* operandsLiteral - returns true of the condition's operands are */ /* literals. */ @@ -1115,7 +1112,80 @@ FBYNAME (operandsLiteral) return TRUE; } - +static const struct ftab +{ + char *fname; + int (*func) (hTab *, lineNode *, lineNode *, lineNode *, char *); +} +ftab[] = // sorted on the number of times used +{ // in the peephole rules on 2007-10-29 + { + "labelRefCount", labelRefCount //105 + }, + { + "notVolatile", notVolatile //85 + }, + { + "labelRefCountChange", labelRefCountChange //74 + }, + { + "labelInRange", labelInRange //37 + }, + { + "labelJTInRange", labelJTInRange //13 + }, + { + "operandsNotRelated", operandsNotRelated //9 + }, + { + "24bitMode", flat24bitMode //9 + }, + { + "operandsNotSame", operandsNotSame //8 + }, + { + "operandsNotSame3", operandsNotSame3 + }, + { + "operandsNotSame4", operandsNotSame4 + }, + { + "operandsNotSame5", operandsNotSame5 + }, + { + "operandsNotSame6", operandsNotSame6 + }, + { + "operandsNotSame7", operandsNotSame7 + }, + { + "operandsNotSame8", operandsNotSame8 + }, + { + "xramMovcOption", xramMovcOption + }, + { + "portIsDS390", portIsDS390 + }, + { + "labelIsReturnOnly", labelIsReturnOnly + }, + { + "labelIsUncondJump", labelIsUncondJump + }, + { + "okToRemoveSLOC", okToRemoveSLOC + }, + { + "deadMove", deadMove + }, + { + "operandsLiteral", operandsLiteral + }, + { + "useAcallAjmp", useAcallAjmp + } +}; /*-----------------------------------------------------------------*/ /* callFuncByName - calls a function as defined in the table */ /*-----------------------------------------------------------------*/ @@ -1126,95 +1196,6 @@ callFuncByName (char *fname, lineNode * endPl, lineNode * head) { - struct ftab - { - char *fname; - int (*func) (hTab *, lineNode *, lineNode *, lineNode *, char *); - } - ftab[] = - { - { - "labelInRange", labelInRange - } - , - { - "labelJTInRange", labelJTInRange - } - , - { - "operandsNotSame", operandsNotSame - } - , - { - "operandsNotSame3", operandsNotSame3 - } - , - { - "operandsNotSame4", operandsNotSame4 - } - , - { - "operandsNotSame5", operandsNotSame5 - } - , - { - "operandsNotSame6", operandsNotSame6 - } - , - { - "operandsNotSame7", operandsNotSame7 - } - , - { - "operandsNotSame8", operandsNotSame8 - } - , - { - "24bitMode", flat24bitMode - } - , - { - "xramMovcOption", xramMovcOption - } - , - { - "labelRefCount", labelRefCount - } - , - { - "portIsDS390", portIsDS390 - }, - { - "labelIsReturnOnly", labelIsReturnOnly - }, - { - "labelIsUncondJump", labelIsUncondJump - }, - { - "okToRemoveSLOC", okToRemoveSLOC - }, - { - "deadMove", deadMove - }, - { - "24bitModeAndPortDS390", flat24bitModeAndPortDS390 - }, - { - "notVolatile", notVolatile - }, - { - "operandsNotRelated", operandsNotRelated - }, - { - "operandsLiteral", operandsLiteral - }, - { - "labelRefCountChange", labelRefCountChange - }, - { - "useAcallAjmp", useAcallAjmp - } - }; int i; char *cmdCopy, *funcName, *funcArgs, *cmdTerm; char c; @@ -1571,18 +1552,18 @@ top: newPeepRule (match, replace, lines, restart); } else - { + { if (*bp && strncmp (bp, "replace", 7)) { /* not the start of a new peeprule, so "if" should be here */ - + char strbuff[1000]; char *cp; - + /* go to the start of the line following "{" of the "by" token */ while (*rp && (*rp == '\n')) rp++; - + /* copy text of rule starting with line after "by {" */ cp = strbuff; while (*rp && (rp < bp) && ((cp - strbuff) < sizeof(strbuff))) @@ -1597,7 +1578,7 @@ top: return; } newPeepRule (match, replace, NULL, restart); - } + } goto top; } diff --git a/src/ds390/peeph.def b/src/ds390/peeph.def index 06a0249d..831605e8 100644 --- a/src/ds390/peeph.def +++ b/src/ds390/peeph.def @@ -1082,7 +1082,7 @@ replace { } by { ; Peephole 182a used 24 bit load of dptr mov dptr,#0x%3%2%1 -} if 24bitModeAndPortDS390 +} if 24bitMode, portIsDS390 // saves 2 bytes, ?? cycles. replace { @@ -1092,7 +1092,7 @@ replace { } by { ; Peephole 182b used 24 bit load of dptr mov dptr,#((%3 << 16) + (%2 << 8) + %1) -} if 24bitModeAndPortDS390 +} if 24bitMode, portIsDS390 // saving 3 byte, 2 cycles, return(float_constant) profits here replace { diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index f4016b75..e4c6e5f8 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -4171,7 +4171,7 @@ genPlusIncr (iCode * ic) D(emitcode (";","genPlusIncr")); /* if increment >=16 bits in register or direct space */ - if (( AOP_TYPE(IC_LEFT(ic)) == AOP_REG || + if (( AOP_TYPE(IC_LEFT(ic)) == AOP_REG || AOP_TYPE(IC_LEFT(ic)) == AOP_DIR || (IS_AOP_PREG (IC_LEFT(ic)) && !AOP_NEEDSACC (IC_LEFT(ic))) ) && sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) && @@ -4640,7 +4640,7 @@ genMinusDec (iCode * ic) D (emitcode (";", "genMinusDec")); /* if decrement >=16 bits in register or direct space */ - if (( AOP_TYPE(IC_LEFT(ic)) == AOP_REG || + if (( AOP_TYPE(IC_LEFT(ic)) == AOP_REG || AOP_TYPE(IC_LEFT(ic)) == AOP_DIR || (IS_AOP_PREG (IC_LEFT(ic)) && !AOP_NEEDSACC (IC_LEFT(ic))) ) && sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) && @@ -6638,7 +6638,7 @@ genAnd (iCode * ic, iCode * ifx) { emitcode ("anl", "c,%s", AOP (right)->aopu.aop_dir); } - else + else { emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir); emitcode ("anl", "c,%s", AOP (left)->aopu.aop_dir); @@ -7067,7 +7067,7 @@ genOr (iCode * ic, iCode * ifx) { emitcode ("orl", "c,%s", AOP (right)->aopu.aop_dir); } - else + else { emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir); emitcode ("orl", "c,%s", AOP (left)->aopu.aop_dir); @@ -7076,22 +7076,20 @@ genOr (iCode * ic, iCode * ifx) else { // c = bit | val; - symbol *tlbl = newiTempLabel (NULL); - if (!((AOP_TYPE (result) == AOP_CRY) && ifx)) - emitcode ("setb", "c"); - emitcode ("jb", "%s,%05d$", - AOP (left)->aopu.aop_dir, tlbl->key + 100); - toBoolean (right); - emitcode ("jnz", "%05d$", tlbl->key + 100); if ((AOP_TYPE (result) == AOP_CRY) && ifx) { + symbol *tlbl = newiTempLabel (NULL); + emitcode ("jb", "%s,%05d$", + AOP (left)->aopu.aop_dir, tlbl->key + 100); + toBoolean (right); + emitcode ("jnz", "%05d$", tlbl->key + 100); jmpTrueOrFalse (ifx, tlbl, left, right, result); goto release; } else { - CLRC; - emitLabel (tlbl); + toCarry (right); + emitcode ("orl", "c,%s", AOP (left)->aopu.aop_dir); } } } -- 2.30.2