From: epetrich Date: Tue, 31 Aug 2004 07:46:41 +0000 (+0000) Subject: * src/SDCCpeeph.c (labelIsReturnOnly): support hc08 rts opcode also X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=d9d71b685333fa132ef705c9932f116d3da7677e;p=fw%2Fsdcc * src/SDCCpeeph.c (labelIsReturnOnly): support hc08 rts opcode also * src/SDCCpeeph.c (buildLabelRefCountHash): assume function entry point labels are referenced at least once (even if a reference is not found) * src/hc08/gen.c (emitcode): set isComment flag for comments * src/hc08/peeph.def: added rules 5a..5f (optimize redundant immediate loads), rules 6a..6b (optimize jumps to return) git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3466 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 32bd6227..4788d7f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-08-30 Erik Petrich + + * src/SDCCpeeph.c (labelIsReturnOnly): support hc08 rts opcode also + * src/SDCCpeeph.c (buildLabelRefCountHash): assume function entry point + labels are referenced at least once (even if a reference is not found) + * src/hc08/gen.c (emitcode): set isComment flag for comments + * src/hc08/peeph.def: added rules 5a..5f (optimize redundant immediate + loads), rules 6a..6b (optimize jumps to return) + 2004-08-30 Erik Petrich * device/lib/acosf.c (acosf), diff --git a/src/SDCCpeeph.c b/src/SDCCpeeph.c index 670f7079..e2e5f454 100644 --- a/src/SDCCpeeph.c +++ b/src/SDCCpeeph.c @@ -187,6 +187,7 @@ FBYNAME (labelIsReturnOnly) const char *label, *p; const lineNode *pl; int len; + char * retInst; label = hTabItemWithKey (vars, 5); if (!label) return FALSE; @@ -212,7 +213,11 @@ FBYNAME (labelIsReturnOnly) p = pl->line; for (p = pl->line; *p && isspace(*p); p++) ; - if (strcmp(p, "ret") == 0) return TRUE; + + retInst = "ret"; + if (TARGET_IS_HC08) + retInst = "rts"; + if (strcmp(p, retInst) == 0) return TRUE; return FALSE; } @@ -1687,6 +1692,12 @@ buildLabelRefCountHash (lineNode * head) memcpy (entry->name, label, labelLen); entry->name[labelLen] = 0; entry->refCount = -1; + + /* Assume function entry points are referenced somewhere, */ + /* even if we can't find a reference (might be from outside */ + /* the function) */ + if (line->ic && (line->ic->op == FUNCTION)) + entry->refCount++; hTabAddItem (&labelHash, hashSymbolName (entry->name), entry); } diff --git a/src/hc08/gen.c b/src/hc08/gen.c index 01864aea..3d2101b5 100644 --- a/src/hc08/gen.c +++ b/src/hc08/gen.c @@ -172,6 +172,7 @@ emitcode (char *inst, char *fmt,...) lineCurr->isInline = _G.inLine; lineCurr->isDebug = _G.debugLine; lineCurr->ic = _G.current_iCode; + lineCurr->isComment = (*lbp==';'); //printf("%s\n", lb); va_end (ap); diff --git a/src/hc08/peeph.def b/src/hc08/peeph.def index a4c8e756..d70a5d1e 100644 --- a/src/hc08/peeph.def +++ b/src/hc08/peeph.def @@ -124,3 +124,107 @@ replace { ; Peephole 4d - eliminated redundant tstx ldx %1,s } + +replace { + clra + sta %1 + clra + sta %2 + clra + sta %3 + clra + sta %4 +} by { + ; Peephole 5a - eliminated redundant clra + clra + sta %1 + sta %2 + sta %3 + sta %4 +} + +replace { + clra + sta %1 + clra + sta %2 + clra + sta %3 +} by { + ; Peephole 5b - eliminated redundant clra + clra + sta %1 + sta %2 + sta %3 +} + +replace { + clra + sta %1 + clra + sta %2 +} by { + ; Peephole 5c - eliminated redundant clra + clra + sta %1 + sta %2 +} + +replace { + lda #%9 + sta %1 + lda #%9 + sta %2 + lda #%9 + sta %3 + lda #%9 + sta %4 +} by { + ; Peephole 5d - eliminated redundant lda + lda #%9 + sta %1 + sta %2 + sta %3 + sta %4 +} + +replace { + lda #%9 + sta %1 + lda #%9 + sta %2 + lda #%9 + sta %3 +} by { + ; Peephole 5e - eliminated redundant lda + lda #%9 + sta %1 + sta %2 + sta %3 +} + +replace { + lda #%9 + sta %1 + lda #%9 + sta %2 +} by { + ; Peephole 5f - eliminated redundant lda + lda #%9 + sta %1 + sta %2 +} + +replace { + jmp %5 +} by { + ; Peephole 6a - replaced jmp to rts with rts + rts +} if labelIsReturnOnly + +replace { + bra %5 +} by { + ; Peephole 6b - replaced jmp to rts with rts + rts +} if labelIsReturnOnly