* src/SDCCpeeph.c (labelIsReturnOnly): support hc08 rts opcode also
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 31 Aug 2004 07:46:41 +0000 (07:46 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 31 Aug 2004 07:46:41 +0000 (07:46 +0000)
* 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

ChangeLog
src/SDCCpeeph.c
src/hc08/gen.c
src/hc08/peeph.def

index 32bd6227baa587408feeedc0fc8f09133b4b599f..4788d7f586a2f7b014e290afaed0d4d688cda7c5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2004-08-30 Erik Petrich <epetrich AT ivorytower.norman.ok.us>
+
+       * 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 <epetrich AT ivorytower.norman.ok.us>
 
        * device/lib/acosf.c (acosf),
index 670f70792f070fa3214e2a8fa8037de9c61d1f4a..e2e5f454bfc3dd82f4edac9aea065ef8d3388b8d 100644 (file)
@@ -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);
        }
index 01864aea4b5ce0469968de34387b9b1f39a6ad15..3d2101b566e885940e9115f67a9ad499c7083a89 100644 (file)
@@ -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);
index a4c8e75615af7a7eaec507b4d47d330c76c7e1e8..d70a5d1ebc48bd98af4e3bb70341e5e23789d6b1 100644 (file)
@@ -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