]> git.gag.com Git - fw/sdcc/commitdiff
Peephole optimizer speed up
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 22 Aug 2003 19:27:52 +0000 (19:27 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 22 Aug 2003 19:27:52 +0000 (19:27 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2843 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCCpeeph.c

index 4d2e1adea04a48ec887a5b70fa4e94ca2844ab62..e107a4f8f7613241eeab41a4ada9d35118029d96 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2003-08-22  Erik Petrich <epetrich@ivorytower.norman.ok.us>
+
+       A few small changes that speed up the peephole optimizer.
+
+       * src/SDCCpeeph.c
+
 2003-08-22  Erik Petrich <epetrich@ivorytower.norman.ok.us>
 
        Try to make the peephole optimizer smarter by maintaining
index 04ace3fab89bc0f9912adda2b0d003ee88c2d8e6..921642b1db2becacc19ab061365b8430e111b085 100644 (file)
@@ -74,6 +74,29 @@ mcs51_instruction_size(const char *inst)
        while (*inst && isspace(*inst)) inst++;
 
        #define ISINST(s) (strncmp(inst, (s), sizeof(s)-1) == 0)
+
+       /* Based on the current (2003-08-22) code generation for the
+          small library, the top instruction probability is:
+          
+            57% mov/movx/movc
+             6% push
+             6% pop
+             4% inc
+             4% lcall
+             4% add
+             3% clr
+             2% subb
+       */
+       /* mov, push, & pop are the 69% of the cases. Check them first! */
+       if (ISINST("mov"))
+         {
+           if (*(inst+3)=='x') return 1; /* movx */
+           if (*(inst+3)=='c') return 1; /* movc */
+           goto checkoperands;           /* mov  */
+         }
+       if (ISINST("push")) return 2;
+       if (ISINST("pop")) return 2;
+
        if (ISINST("lcall")) return 3;
        if (ISINST("ret")) return 1;
        if (ISINST("ljmp")) return 3;
@@ -83,10 +106,6 @@ mcs51_instruction_size(const char *inst)
        if (ISINST("rl")) return 1;
        if (ISINST("rr")) return 1;
        if (ISINST("swap")) return 1;
-       if (ISINST("movx")) return 1;
-       if (ISINST("movc")) return 1;
-       if (ISINST("push")) return 2;
-       if (ISINST("pop")) return 2;
        if (ISINST("jc")) return 2;
        if (ISINST("jnc")) return 2;
        if (ISINST("jb")) return 3;
@@ -105,6 +124,7 @@ mcs51_instruction_size(const char *inst)
        if (ISINST("acall")) return 1;
        if (ISINST("ajmp")) return 2;
 
+checkoperands:
        p = inst;
        while (*p && isalnum(*p)) p++;
        for (op = op1, opsize=0; *p && *p != ',' && opsize < sizeof(op1); p++) {
@@ -188,7 +208,7 @@ pcDistance (lineNode * cpos, char *lbl, bool back)
          *pl->line != ';' &&
          pl->line[strlen (pl->line) - 1] != ':' &&
          !pl->isDebug) {
-               if (strcmp(port->target,"mcs51") == 0) {
+               if (TARGET_IS_MCS51) {
                        dist += mcs51_instruction_size(pl->line);
                } else {
                        dist += 3;
@@ -1274,15 +1294,16 @@ matchLine (char *s, char *d, hTab ** vars)
          d++;
          while (isdigit (*d))
            d++;
-       }
 
-      /* they should be an exact match other wise */
-      if (*s && *d)
-       {
          while (isspace (*s))
            s++;
          while (isspace (*d))
            d++;
+       }
+
+      /* they should be an exact match other wise */
+      if (*s && *d)
+       {
          if (*s++ != *d++)
            return FALSE;
        }
@@ -1841,6 +1862,11 @@ peepHole (lineNode ** pls)
               /* if inline assembler then no peep hole */
               if (spl->isInline)
                 continue;
+
+              /* don't waste time starting a match on debug symbol
+              ** or comment */
+              if (spl->isDebug || spl->isComment || *(spl->line)==';')
+                continue;
               
               mtail = NULL;