From: sdattalo Date: Wed, 19 Jun 2002 14:26:10 +0000 (+0000) Subject: Operand comparisons were unnecessarily failing in the pCode peep hole optimizer. X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=a11adc08c61607bc23d54c29b090c159e4b9c994;p=fw%2Fsdcc Operand comparisons were unnecessarily failing in the pCode peep hole optimizer. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2025 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/pic/genarith.c b/src/pic/genarith.c index fb6b9498..d6e5d796 100644 --- a/src/pic/genarith.c +++ b/src/pic/genarith.c @@ -961,7 +961,9 @@ void genPlus (iCode *ic) else { PIC_OPCODE poc = POC_ADDFW; - if ((AOP_TYPE(IC_LEFT(ic)) == AOP_PCODE) && AOP(IC_LEFT(ic))->aopu.pcop->type == PO_LITERAL) + if ((AOP_TYPE(IC_LEFT(ic)) == AOP_PCODE) && ( + (AOP(IC_LEFT(ic))->aopu.pcop->type == PO_LITERAL) || + (AOP(IC_LEFT(ic))->aopu.pcop->type == PO_IMMEDIATE))) poc = POC_ADDLW; emitpcode(poc, popGet(AOP(IC_LEFT(ic)),0)); if ( AOP_TYPE(IC_RESULT(ic)) != AOP_ACC) diff --git a/src/pic/pcode.c b/src/pic/pcode.c index bb3ac5ac..dce14196 100644 --- a/src/pic/pcode.c +++ b/src/pic/pcode.c @@ -112,7 +112,7 @@ static void pCodePrintLabel(FILE *of, pCode *pc); static void pCodePrintFunction(FILE *of, pCode *pc); static void pCodeOpPrint(FILE *of, pCodeOp *pcop); static char *get_op_from_instruction( pCodeInstruction *pcc); -char *get_op( pCodeOp *pcop); +char *get_op( pCodeOp *pcop,char *buff,int buf_size); int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd); int pCodePeepMatchRule(pCode *pc); void pBlockStats(FILE *of, pBlock *pb); @@ -1161,6 +1161,7 @@ void SAFE_snprintf(char **str, size_t *size, const char *format, ...) len = strlen(*str); if(len > *size) { fprintf(stderr,"WARNING, it looks like %s has overflowed\n",__FUNCTION__); + fprintf(stderr,"len = %d is > str size %d\n",len,*size); } *str += len; @@ -1189,6 +1190,7 @@ void SAFE_snprintf(char **str, size_t *size, const char *format, ...) len = strlen(buffer); if(len > *size) { fprintf(stderr,"WARNING, it looks like %s has overflowed\n",__FUNCTION__); + fprintf(stderr,"len = %d is > str size %d\n",len,*size); } strcpy(*str, buffer); @@ -2364,13 +2366,17 @@ void pBlockRegs(FILE *of, pBlock *pb) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -char *get_op(pCodeOp *pcop) +char *get_op(pCodeOp *pcop,char *buffer, int size) { regs *r; - static char buffer[50]; + static char b[50]; char *s; - int size; + // int size; + if(!buffer) { + buffer = b; + size = sizeof(b); + } if(pcop) { switch(pcop->type) { @@ -2390,7 +2396,7 @@ char *get_op(pCodeOp *pcop) // return PCOR(pcc->pcop)->r)->name; case PO_IMMEDIATE: s = buffer; - size = sizeof(buffer); + //size = sizeof(buffer); //fprintf(stderr,"PO_IMMEDIATE name = %s offset = %d\n",pcc->pcop->name,PCOI(pcc->pcop)->offset); if(PCOI(pcop)->_const) { @@ -2415,7 +2421,7 @@ char *get_op(pCodeOp *pcop) case PO_DIR: s = buffer; - size = sizeof(buffer); + //size = sizeof(buffer); if( PCOR(pcop)->instance) { SAFE_snprintf(&s,&size,"(%s + %d)", pcop->name, @@ -2442,7 +2448,7 @@ static char *get_op_from_instruction( pCodeInstruction *pcc) { if(pcc ) - return get_op(pcc->pcop); + return get_op(pcc->pcop,NULL,0); return ("ERROR Null: "__FUNCTION__); diff --git a/src/pic/pcodepeep.c b/src/pic/pcodepeep.c index 9083d1b9..2ba9fd1f 100644 --- a/src/pic/pcodepeep.c +++ b/src/pic/pcodepeep.c @@ -44,7 +44,7 @@ int getpCode(char *mnem,int dest); int getpCodePeepCommand(char *cmd); void pBlockMergeLabels(pBlock *pb); char *pCode2str(char *str, int size, pCode *pc); -char *get_op( pCodeOp *pcop); +char *get_op( pCodeOp *pcop,char *buf,int buf_size); extern pCodeInstruction *pic14Mnemonics[]; @@ -1366,6 +1366,8 @@ int pCodeSearchCondition(pCode *pc, unsigned int cond) return 0; if(pc->type == PC_OPCODE) { + //fprintf(stderr," checking conditions of: "); + //pc->print(stderr,pc); if(PCI(pc)->inCond & cond) return 1; if(PCI(pc)->outCond & cond) @@ -1385,24 +1387,29 @@ int pCodeSearchCondition(pCode *pc, unsigned int cond) *-----------------------------------------------------------------*/ int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd) { + char b[50], *n2; if(!pcops || !pcopd) return 0; - /* +/* fprintf(stderr," Comparing operands %s", - get_op( pcops)); + get_op( pcops,NULL,0)); fprintf(stderr," to %s\n", - get_op( pcopd)); - */ + get_op( pcopd,NULL,0)); +*/ if(pcops->type != pcopd->type) { //fprintf(stderr," - fail - diff types\n"); return 0; // different types } - if(!pcops->name || !pcopd->name || strcmp(pcops->name,pcopd->name)) { - //fprintf(stderr," - fail - diff names\n"); + b[0]=0; + get_op(pcops,b,sizeof(b)); + n2 = get_op(pcopd,NULL,0); + + if( !n2 || strcmp(b,n2)) { + //fprintf(stderr," - fail - diff names: %s, len=%d, %s, len=%d\n",b,strlen(b), n2, strlen(n2) ); return 0; // different names } @@ -1417,7 +1424,7 @@ int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd) break; } - //fprintf(stderr," - pass\n"); + // fprintf(stderr," - pass\n"); return 1; } @@ -1915,8 +1922,10 @@ int pCodePeepMatchRule(pCode *pc) pct = pct->next; //debug: //DFPRINTF((stderr," matched\n")); + if(!pcin && pct) { DFPRINTF((stderr," partial match... no more code\n")); + fprintf(stderr," partial match... no more code\n"); matched = 0; } if(!pct) { @@ -1926,6 +1935,9 @@ int pCodePeepMatchRule(pCode *pc) if(matched) { + //pCode *pcr = peepBlock->replace.pb->pcHead; + //if(pcr) pcr->print(stderr,pcr); + /* So far we matched the rule up to the point of the conditions . * In other words, all of the opcodes match. Now we need to see * if the post conditions are satisfied. @@ -1938,6 +1950,8 @@ int pCodePeepMatchRule(pCode *pc) if (pcin && peepBlock->postFalseCond && (pCodeSearchCondition(pcin,peepBlock->postFalseCond) > 0) ) matched = 0; + + if(!matched) fprintf(stderr,"failed on conditions\n"); } if(matched) { @@ -1967,7 +1981,7 @@ int pCodePeepMatchRule(pCode *pc) pcin->prev = pc->prev; -#if 0 + //#if 0 { /* DEBUG */ /* Converted the deleted pCodes into comments */ @@ -1999,7 +2013,7 @@ int pCodePeepMatchRule(pCode *pc) if(pc_cline2) pc_cline2->pc.next = NULL; } -#endif + //#endif if(pcin) pCodeDeleteChain(pc,pcin); diff --git a/src/pic/peeph.def b/src/pic/peeph.def index e48e6d0d..09923399 100644 --- a/src/pic/peeph.def +++ b/src/pic/peeph.def @@ -133,54 +133,6 @@ replace restart { %3: %6 } -//replace restart { -// btfss %1 -// goto %2 -// %3 -//%2: %4 -//} by { -// ;peep 1 - test/jump to test/skip -// btfsc %1 -// %3 -//%2: %4 -//} -// -//replace restart { -// btfsc %1 -// goto %2 -// %3 -//%2: %4 -//} by { -// ;peep 1a - test/jump to test/skip -// btfss %1 -// %3 -//%2: %4 -//} -// -//replace restart { -// btfss %1 -// goto %4 -//%2: %3 -//%4: %5 -//} by { -// ;peep 1b - test/jump to test/skip -// btfsc %1 -//%2: %3 -//%4: %5 -//} -// -//replace restart { -// btfsc %1 -// goto %4 -//%2: %3 -//%4: %5 -//} by { -// ;peep 1c - test/jump to test/skip -// btfss %1 -//%2: %3 -//%4: %5 -//} - //bogus test for pcode //replace restart {