Added peephole to replace LJMP to RET with just a RET instruction
authorpjs <pjs@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 6 Apr 2003 18:32:47 +0000 (18:32 +0000)
committerpjs <pjs@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 6 Apr 2003 18:32:47 +0000 (18:32 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2488 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCCpeeph.c
src/mcs51/peeph.def

index 75c8008b6c50cce70d5e75d411a072f0cb598c2d..636e61b4a3fbb79666f93486a7627adae9e2c7cf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-04-06    Paul Stoffregen <paul@pjrc.com>
+
+       * src/SDCCpeeph.c: added labelIsReturnOnly test
+       * src/mcs51/peeph.def: Peephole 244: replace ljmp to ret with ret
+
 2003-04-05    <johan@balder>
 
        * src/SDCCcse.c (cseAllBlocks): fixed bug #460088
index 13eadb79d23212d7561e2bb5eb1ed29473bec786..d7aa888da8af1f8a37562994fec1ce698d3fb0b2 100644 (file)
@@ -275,6 +275,44 @@ FBYNAME (labelInRange)
   return TRUE;
 }
 
+/*-----------------------------------------------------------------*/
+/* labelIsReturnOnly - Check if label %5 is followed by RET        */
+/*-----------------------------------------------------------------*/
+FBYNAME (labelIsReturnOnly)
+{
+  /* assumes that %5 pattern variable has the label name */
+  const char *label, *p;
+  const lineNode *pl;
+  int len;
+
+  label = hTabItemWithKey (vars, 5);
+  if (!label) return FALSE;
+  len = strlen(label);
+
+  for(pl = currPl; pl; pl = pl->next) {
+       if (pl->line && !pl->isDebug &&
+         pl->line[strlen(pl->line)-1] == ':') {
+               if (strncmp(pl->line, label, len) == 0) break; /* Found Label */
+               if (strlen(pl->line) != 7 || !isdigit(*(pl->line)) ||
+                 !isdigit(*(pl->line+1)) || !isdigit(*(pl->line+2)) ||
+                 !isdigit(*(pl->line+3)) || !isdigit(*(pl->line+4)) ||
+                 *(pl->line+5) != '$') {
+                       return FALSE; /* non-local label encountered */
+               }
+       }
+  }
+  if (!pl) return FALSE; /* did not find the label */
+  pl = pl->next;
+  if (!pl || !pl->line || pl->isDebug) return FALSE; /* next line not valid */
+  p = pl->line;
+  for (p = pl->line; *p && isspace(*p); p++)
+         ;
+  if (strcmp(p, "ret") == 0) return TRUE;
+  return FALSE;
+}
+
+
+
 /*-----------------------------------------------------------------*/
 /* operandsNotSame - check if %1 & %2 are the same                 */
 /*-----------------------------------------------------------------*/
@@ -607,6 +645,9 @@ callFuncByName (char *fname,
     {
       "portIsDS390", portIsDS390
     },
+    {
+      "labelIsReturnOnly", labelIsReturnOnly
+    },
     {
       "24bitModeAndPortDS390", flat24bitModeAndPortDS390
     }
index a7c433e7ca463e944541df799d945c1408083807..7e404ed06443fdf0543631686d924420b1230fc6 100644 (file)
@@ -219,6 +219,15 @@ replace {
 %2:
 } if labelInRange
 
+
+replace {
+        ljmp    %5
+} by {
+       ;       Peephole 244    replaced ljmp to ret with ret
+       ret
+} if labelIsReturnOnly
+
+
 replace {
         ljmp    %5
 %1: