Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.37
 
1.38
 
MAIN:ragge:20050905170716
 
optim2.c
_>4444 static int dfsnum;
 4545 
 4646 void saveip(struct interpass *ip);
<>47 -void deljumps(void);
  47+void deljumps(struct interpass *);
4848 void deltemp(NODE *p);
 4949 void optdump(struct interpass *ip);
 5050 void printip(struct interpass *pole);
 5151 
 5252 static struct varinfo defsites;
<> 53+#ifdef OLDSTYLE
5354 static struct interpass ipole;
<> 55+#endif
5456 struct interpass *storesave;
 5557 static struct interpass_prolog *ipp, *epp; /* prolog/epilog */
 5658 
<>57 -void bblocks_build(struct labelinfo *labinfo, struct bblockinfo *bbinfo);
  59+void bblocks_build(struct interpass *, struct labelinfo *, struct bblockinfo *);
5860 void cfg_build(struct labelinfo *labinfo);
 5961 void cfg_dfs(struct basicblock *bb, unsigned int parent,
 6062              struct bblockinfo *bbinfo);
     
 !
7072 struct basicblock bblocks;
 7173 int nbblocks;
 7274 
<> 75+struct addrof {
  76+        struct addrof *next;
  77+        int tempnum;
  78+        int oregoff;
  79+} *otlink;
  80+
  81+static int
  82+getoff(int num)
  83+{
  84+        struct addrof *w;
  85+
  86+        for (w = otlink; w; w = w->next)
  87+                if (w->tempnum == num)
  88+                        return w->oregoff;
  89+        return 0;
  90+}
  91+
  92+/*
  93+ * Search for ADDROF elements and, if found, record them.
  94+ */
  95+static void
  96+findaddrof(NODE *p)
  97+{
  98+        struct addrof *w;
  99+
  100+        if (p->n_op != ADDROF)
  101+                return;
  102+        if (getoff(p->n_left->n_lval))
  103+                return;
  104+        w = tmpalloc(sizeof(struct addrof));
  105+        w->tempnum = p->n_left->n_lval;
  106+        w->oregoff = BITOOR(freetemp(szty(p->n_left->n_type)));
  107+        w->next = otlink;
  108+        otlink = w;
  109+}
  110+
  111+/*
  112+ * Convert address-taken temps to OREGs.
  113+ */
  114+static void
  115+cvtaddrof(NODE *p)
  116+{
  117+        NODE *l;
  118+        int n;
  119+
  120+        if (p->n_op != ADDROF && p->n_op != TEMP)
  121+                return;
  122+        if (p->n_op == TEMP) {
  123+                n = getoff(p->n_lval);
  124+                if (n == 0)
  125+                        return;
  126+                p->n_op = OREG;
  127+                p->n_lval = n;
  128+                p->n_rval = FPREG;
  129+        } else {
  130+                l = p->n_left;
  131+                p->n_type = l->n_type;
  132+                p->n_right = mklnode(ICON, l->n_lval, 0, l->n_type);
  133+                p->n_op = PLUS;
  134+                l->n_op = REG;
  135+                l->n_lval = 0;
  136+                l->n_rval = FPREG;
  137+                
  138+        }
  139+}
  140+
  141+#ifdef OLDSTYLE
73142 void
 74143 saveip(struct interpass *ip)
 75144 {
     
 !
100169                 printip(&ipole);
 101170         }
 102171 
<> 172+        /*
  173+         * Convert ADDROF TEMP to OREGs.
  174+         */
  175+                otlink = NULL;
  176+                DLIST_FOREACH(ip, &ipole, qelem) {
  177+                        if (ip->type != IP_NODE)
  178+                                continue;
  179+                        walkf(ip->ip_node, findaddrof);
  180+                }
  181+                if (otlink) {
  182+                        DLIST_FOREACH(ip, &ipole, qelem) {
  183+                                if (ip->type != IP_NODE)
  184+                                        continue;
  185+                                walkf(ip->ip_node, cvtaddrof);
  186+                        }
  187+                }
  188+        }
  189+                
103190         if (xdeljumps)
 104191                 deljumps();     /* Delete redundant jumps and dead code */
 105192 
     
 !
212299         }
 213300         DLIST_INIT(&ipole, qelem);
 214301 }
<> 302+#else
  303+void
  304+optimize(struct interpass *ipole)
  305+{
  306+        struct interpass *ip;
  307+        struct labelinfo labinfo;
  308+        struct bblockinfo bbinfo;
215309 
<> 310+        ipp = (struct interpass_prolog *)DLIST_NEXT(ipole, qelem);
  311+        epp = (struct interpass_prolog *)DLIST_PREV(ipole, qelem);
  312+
  313+        if (b2debug) {
  314+                printf("initial links\n");
  315+                printip(ipole);
  316+        }
  317+
  318+        /*
  319+         * Convert ADDROF TEMP to OREGs.
  320+         */
  321+        if (xtemps) {
  322+                otlink = NULL;
  323+                DLIST_FOREACH(ip, ipole, qelem) {
  324+                        if (ip->type != IP_NODE)
  325+                                continue;
  326+                        walkf(ip->ip_node, findaddrof);
  327+                }
  328+                if (otlink) {
  329+                        DLIST_FOREACH(ip, ipole, qelem) {
  330+                                if (ip->type != IP_NODE)
  331+                                        continue;
  332+                                walkf(ip->ip_node, cvtaddrof);
  333+                        }
  334+                }
  335+        }
  336+                
  337+        if (xdeljumps)
  338+                deljumps(ipole); /* Delete redundant jumps and dead code */
  339+
  340+#ifdef PCC_DEBUG
  341+        if (b2debug) {
  342+                printf("links after deljumps\n");
  343+                printip(ipole);
  344+        }
  345+#endif
  346+        if (xssaflag || xtemps) {
  347+                DLIST_INIT(&bblocks, bbelem);
  348+                bblocks_build(ipole, &labinfo, &bbinfo);
  349+                BDEBUG(("Calling cfg_build\n"));
  350+                cfg_build(&labinfo);
  351+        }
  352+        if (xssaflag) {
  353+                BDEBUG(("Calling dominators\n"));
  354+                dominators(&bbinfo);
  355+                BDEBUG(("Calling computeDF\n"));
  356+                computeDF(DLIST_NEXT(&bblocks, bbelem), &bbinfo);
  357+                BDEBUG(("Calling remunreach\n"));
  358+                remunreach();
  359+#if 0
  360+                dfg = dfg_build(cfg);
  361+                ssa = ssa_build(cfg, dfg);
  362+#endif
  363+        }
  364+
  365+#ifdef PCC_DEBUG
  366+        if (epp->ipp_regs != 0)
  367+                comperr("register error");
  368+#endif
  369+
  370+#ifdef MYOPTIM
  371+        myoptim((struct interpass *)ipp);
  372+#endif
  373+}
  374+#endif
  375+
216376 /*
 217377  * Delete unused labels, excess of labels, gotos to gotos.
 218378  * This routine can be made much more efficient.
 219379  */
 220380 void
<>221 -deljumps()
  381+deljumps(struct interpass *ipole)
222382 {
 223383         struct interpass *ip, *n, *ip2;
 224384         int gotone,low, high;
     
 !
238398         memset(lblary, 0, sz);
 239399 
 240400         /* refcount and coalesce all labels */
<>241 -        DLIST_FOREACH(ip, &ipole, qelem) {
  401+        DLIST_FOREACH(ip, ipole, qelem) {
242402                 if (ip->type == IP_DEFLAB) {
 243403                         n = DLIST_NEXT(ip, qelem);
<> 404+#ifdef OLDSTYLE
244405                         while (n->type == IP_DEFLAB || n->type == IP_STKOFF) {
<> 406+#else
  407+                        while (n->type == IP_DEFLAB) {
  408+#endif
245409                                 if (n->type == IP_DEFLAB &&
 246410                                     lblary[n->ip_lbl-low] >= 0)
 247411                                         lblary[n->ip_lbl-low] = -ip->ip_lbl;
     
 !
261425         }
 262426 
 263427         /* delete coalesced/unused labels and rename gotos */
<>264 -        DLIST_FOREACH(ip, &ipole, qelem) {
  428+        DLIST_FOREACH(ip, ipole, qelem) {
265429                 n = DLIST_NEXT(ip, qelem);
 266430                 if (n->type == IP_DEFLAB) {
 267431                         if (lblary[n->ip_lbl-low] <= 0) {
     
 !
288452         }
 289453 
 290454         /* Delete gotos to the next statement */
<>291 -        DLIST_FOREACH(ip, &ipole, qelem) {
  455+        DLIST_FOREACH(ip, ipole, qelem) {
292456                 n = DLIST_NEXT(ip, qelem);
 293457                 if (n->type != IP_NODE)
 294458                         continue;
     
 !
301465                         continue;
 302466 
 303467                 ip2 = n;
<> 468+#ifdef OLDSTYLE
304469                 do {
 305470                         ip2 = DLIST_NEXT(ip2, qelem);
 306471                 } while (ip2->type == IP_STKOFF);
<> 472+#else
  473+                ip2 = DLIST_NEXT(ip2, qelem);
  474+#endif
307475 
 308476                 if (ip2->type != IP_DEFLAB)
 309477                         continue;
     
 !
349517  */
 350518 
 351519 void
<>352 -bblocks_build(struct labelinfo *labinfo, struct bblockinfo *bbinfo)
  520+bblocks_build(struct interpass *ipole, struct labelinfo *labinfo,
  521+    struct bblockinfo *bbinfo)
353522 {
 354523         struct interpass *ip;
 355524         struct basicblock *bb = NULL;
     
 !
366535          * Any statement that is target of a jump is a leader.
 367536          * Any statement that immediately follows a jump is a leader.
 368537          */
<>369 -        DLIST_FOREACH(ip, &ipole, qelem) {
  538+        DLIST_FOREACH(ip, ipole, qelem) {
  539+#ifdef OLDSTYLE
370540                 /* ignore stackoff in beginning or end of bblocks */
 371541                 if (ip->type == IP_STKOFF && bb == NULL)
 372542                         continue;
<> 543+#endif
373544 
 374545                 if (bb == NULL || (ip->type == IP_EPILOG) ||
 375546                     (ip->type == IP_DEFLAB) || (ip->type == IP_DEFNAM)) {
     
 !
826997         static char *foo[] = {
 827998            0, "NODE", "PROLOG", "STKOFF", "EPILOG", "DEFLAB", "DEFNAM", "ASM" };
 828999         struct interpass *ip;
<> 1000+        struct interpass_prolog *ipp, *epp;
8291001 
 8301002         DLIST_FOREACH(ip, pole, qelem) {
<>831 -                if (ip->type > MAXIP)
  1003+                if (ip->type >= MAXIP)
8321004                         printf("IP(%d) (%p): ", ip->type, ip);
 8331005                 else
 8341006                         printf("%s (%p): ", foo[ip->type], ip);
 8351007                 switch (ip->type) {
 8361008                 case IP_NODE: printf("\n");
 8371009                         fwalk(ip->ip_node, e2print, 0); break;
 8381010                 case IP_PROLOG:
<>839 -                        printf("%s\n",
 840 -                            ((struct interpass_prolog *)ip)->ipp_name); break;
  1011+                        ipp = (struct interpass_prolog *)ip;
  1012+                        printf("%s %s regs %x autos %d mintemp %d minlbl %d\n",
  1013+                            ipp->ipp_name, ipp->ipp_vis ? "(local)" : "",
  1014+                            ipp->ipp_regs, ipp->ipp_autos, ipp->ip_tmpnum,
  1015+                            ipp->ip_lblnum);
  1016+                        break;
  1017+#ifdef OLDSTYLE
8411018                 case IP_STKOFF: printf("%d\n", ip->ip_off); break;
<>842 -                case IP_EPILOG: printf("\n"); break;
  1019+#endif
  1020+                case IP_EPILOG:
  1021+                        epp = (struct interpass_prolog *)ip;
  1022+                        printf("%s %s regs %x autos %d mintemp %d minlbl %d\n",
  1023+                            epp->ipp_name, epp->ipp_vis ? "(local)" : "",
  1024+                            epp->ipp_regs, epp->ipp_autos, epp->ip_tmpnum,
  1025+                            epp->ip_lblnum);
  1026+                        break;
8431027                 case IP_DEFLAB: printf(LABFMT "\n", ip->ip_lbl); break;
<> 1028+                case IP_DEFNAM: printf("\n"); break;
  1029+                case IP_ASM: printf("%s\n", ip->ip_asm); break;
  1030+                default:
  1031+                        break;
<_8441032                 }
 8451033         }
 8461034 }
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-10-31 06:33 +0100