From dc5d0d9036733b5b3d5f59f3bf09b1c7afa57c29 Mon Sep 17 00:00:00 2001 From: epetrich Date: Fri, 22 Aug 2003 19:27:52 +0000 Subject: [PATCH] Peephole optimizer speed up git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2843 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 6 ++++++ src/SDCCpeeph.c | 44 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4d2e1ade..e107a4f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-08-22 Erik Petrich + + A few small changes that speed up the peephole optimizer. + + * src/SDCCpeeph.c + 2003-08-22 Erik Petrich Try to make the peephole optimizer smarter by maintaining diff --git a/src/SDCCpeeph.c b/src/SDCCpeeph.c index 04ace3fa..921642b1 100644 --- a/src/SDCCpeeph.c +++ b/src/SDCCpeeph.c @@ -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; -- 2.39.5