From ea1b8716bdb4c19fc4ca7fec3ce8259a506a6df3 Mon Sep 17 00:00:00 2001 From: pjs Date: Mon, 7 Apr 2003 03:08:59 +0000 Subject: [PATCH] Added okToRemoveSLOC conditional test to peephole optimizer (not used yet) git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2490 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 4 ++++ src/SDCCpeeph.c | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index e82a278b..f985e599 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2003-04-06 Paul Stoffregen + + * src/SDCCpeeph.c: added okToRemoveSLOC test + 2003-04-06 Paul Stoffregen * device/lib/printf_fast.c: added leading zero format ("%06d", etc) diff --git a/src/SDCCpeeph.c b/src/SDCCpeeph.c index d7aa888d..e052e3ea 100644 --- a/src/SDCCpeeph.c +++ b/src/SDCCpeeph.c @@ -49,8 +49,8 @@ static void buildLabelRefCountHash (lineNode * head); static bool matchLine (char *, char *, hTab **); -#define FBYNAME(x) int x (hTab *vars, lineNode *currPl, lineNode *head, \ - const char *cmdLine) +#define FBYNAME(x) int x (hTab *vars, lineNode *currPl, lineNode *endPl, \ + lineNode *head, const char *cmdLine) #if !OPT_DISABLE_PIC void peepRules2pCode(peepRule *); @@ -312,6 +312,41 @@ FBYNAME (labelIsReturnOnly) } +/*-----------------------------------------------------------------*/ +/* okToRemoveSLOC - Check if label %1 is a SLOC and not other */ +/* usage of it in the code depends on a value from this section */ +/*-----------------------------------------------------------------*/ +FBYNAME (okToRemoveSLOC) +{ + const lineNode *pl; + const char *sloc, *p; + int dummy1, dummy2, dummy3; + + /* assumes that %1 as the SLOC name */ + sloc = hTabItemWithKey (vars, 1); + if (sloc == NULL) return FALSE; + p = strstr(sloc, "sloc"); + if (p == NULL) return FALSE; + p += 4; + if (sscanf(p, "%d_%d_%d", &dummy1, &dummy2, &dummy3) != 3) return FALSE; + /*TODO: ultra-paranoid: get funtion name from "head" and check that */ + /* the sloc name begins with that. Probably not really necessary */ + + /* Look for any occurance of this SLOC before the peephole match */ + for (pl = currPl->prev; pl; pl = pl->prev) { + if (pl->line && !pl->isDebug && !pl->isComment + && *pl->line != ';' && strstr(pl->line, sloc)) + return FALSE; + } + /* Look for any occurance of this SLOC after the peephole match */ + for (pl = endPl->next; pl; pl = pl->next) { + if (pl->line && !pl->isDebug && !pl->isComment + && *pl->line != ';' && strstr(pl->line, sloc)) + return FALSE; + } + return TRUE; /* safe for a peephole to remove it :) */ +} + /*-----------------------------------------------------------------*/ /* operandsNotSame - check if %1 & %2 are the same */ @@ -589,12 +624,13 @@ int callFuncByName (char *fname, hTab * vars, lineNode * currPl, + lineNode * endPl, lineNode * head) { struct ftab { char *fname; - int (*func) (hTab *, lineNode *, lineNode *, const char *); + int (*func) (hTab *, lineNode *, lineNode *, lineNode *, const char *); } ftab[] = { @@ -648,6 +684,9 @@ callFuncByName (char *fname, { "labelIsReturnOnly", labelIsReturnOnly }, + { + "okToRemoveSLOC", okToRemoveSLOC + }, { "24bitModeAndPortDS390", flat24bitModeAndPortDS390 } @@ -667,7 +706,7 @@ callFuncByName (char *fname, { if (strcmp (ftab[i].fname, funcName) == 0) { - rc = (*ftab[i].func) (vars, currPl, head, + rc = (*ftab[i].func) (vars, currPl, endPl, head, funcArgs); } } @@ -1117,7 +1156,7 @@ matchRule (lineNode * pl, /* if this rule has additional conditions */ if (pr->cond) { - if (callFuncByName (pr->cond, pr->vars, pl, head)) + if (callFuncByName (pr->cond, pr->vars, pl, spl, head)) { *mtail = spl; return TRUE; -- 2.47.2