Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.73
 
1.74
 
MAIN:ragge:20100512170121
 
optim2.c
_>5757 static struct varinfo defsites;
 5858 struct interpass *storesave;
 5959 
<>60 -void bblocks_build(struct p2env *, struct labelinfo *, struct bblockinfo *);
 61 -void cfg_build(struct p2env *, struct labelinfo *labinfo);
  60+void bblocks_build(struct p2env *);
  61+void cfg_build(struct p2env *);
6262 void cfg_dfs(struct basicblock *bb, unsigned int parent,
 6363              struct bblockinfo *bbinfo);
<>64 -void dominators(struct p2env *, struct bblockinfo *bbinfo);
  64+void dominators(struct p2env *);
6565 struct basicblock *
 6666 ancestorwithlowestsemi(struct basicblock *bblock, struct bblockinfo *bbinfo);
 6767 void link(struct basicblock *parent, struct basicblock *child);
<>68 -void computeDF(struct basicblock *bblock, struct bblockinfo *bbinfo);
 69 -void printDF(struct p2env *p2e, struct bblockinfo *bbinfo);
  68+void computeDF(struct p2env *, struct basicblock *bblock);
  69+void printDF(struct p2env *p2e);
7070 void findTemps(struct interpass *ip);
<>71 -void placePhiFunctions(struct p2env *, struct bblockinfo *bbinfo);
 72 -void renamevar(struct p2env *p2e,struct basicblock *bblock, struct bblockinfo *bbinfo);
 73 -void removephi(struct p2env *p2e, struct labelinfo *,struct bblockinfo *bbinfo);
  71+void placePhiFunctions(struct p2env *);
  72+void renamevar(struct p2env *p2e,struct basicblock *bblock);
  73+void removephi(struct p2env *p2e);
7474 void remunreach(struct p2env *);
 7575 
 7676 /* create "proper" basic blocks, add labels where needed (so bblocks have labels) */
     
 !
9494 void LiveDead(struct p2env* p2e, int what, unsigned int variable) ;
 9595 
 9696 #ifdef PCC_DEBUG
<>97 -void printflowdiagram(struct p2env *,struct labelinfo *labinfo,struct bblockinfo *bbinfo,char *);
  97+void printflowdiagram(struct p2env *, char *);
9898 #endif
 9999 
 100100 void
 101101 optimize(struct p2env *p2e)
 102102 {
 103103         struct interpass *ipole = &p2e->ipole;
<>104 -        struct labelinfo labinfo;
 105 -        struct bblockinfo bbinfo;
106104 
 107105         if (b2debug) {
 108106                 printf("initial links\n");
     
 !
126124 #endif
 127125         if (xssaflag || xtemps) {
 128126                 DLIST_INIT(&p2e->bblocks, bbelem);
<>129 -                bblocks_build(p2e, &labinfo, &bbinfo);
  127+                bblocks_build(p2e);
130128                 BDEBUG(("Calling cfg_build\n"));
<>131 -                cfg_build(p2e, &labinfo);
  129+                cfg_build(p2e);
132130         
 133131 #ifdef PCC_DEBUG
<>134 -                printflowdiagram(p2e, &labinfo, &bbinfo,"first");
  132+                printflowdiagram(p2e, "first");
135133 #endif
 136134         }
 137135         if (xssaflag) {
 138136                 BDEBUG(("Calling dominators\n"));
<>139 -                dominators(p2e, &bbinfo);
  137+                dominators(p2e);
140138                 BDEBUG(("Calling computeDF\n"));
<>141 -                computeDF(DLIST_NEXT(&p2e->bblocks, bbelem), &bbinfo);
  139+                computeDF(p2e, DLIST_NEXT(&p2e->bblocks, bbelem));
142140 
 143141                 if (b2debug) {
<>144 -                        printDF(p2e,&bbinfo);
  142+                        printDF(p2e);
145143                 }
 146144 
 147145                 BDEBUG(("Calling placePhiFunctions\n"));
 148146 
<>149 -                placePhiFunctions(p2e, &bbinfo);
  147+                placePhiFunctions(p2e);
150148 
 151149                 BDEBUG(("Calling renamevar\n"));
 152150 
<>153 -                renamevar(p2e,DLIST_NEXT(&p2e->bblocks, bbelem), &bbinfo);
  151+                renamevar(p2e,DLIST_NEXT(&p2e->bblocks, bbelem));
154152 
 155153                 BDEBUG(("Calling removephi\n"));
 156154 
 157155 #ifdef PCC_DEBUG
<>158 -                printflowdiagram(p2e, &labinfo, &bbinfo,"ssa");
  156+                printflowdiagram(p2e, "ssa");
159157 #endif
 160158 
<>161 -                removephi(p2e,&labinfo,&bbinfo);
  159+                removephi(p2e);
162160 
 163161                 BDEBUG(("Calling remunreach\n"));
 164162 /*              remunreach(p2e); */
     
 !
198196                         deljumps(p2e); /* Delete redundant jumps and dead code */
 199197 
 200198                 DLIST_INIT(&p2e->bblocks, bbelem);
<>201 -                bblocks_build(p2e, &labinfo, &bbinfo);
  199+                bblocks_build(p2e);
202200                 BDEBUG(("Calling cfg_build\n"));
<>203 -                cfg_build(p2e, &labinfo);
  201+                cfg_build(p2e);
204202 
 205203 #ifdef PCC_DEBUG
<>206 -                printflowdiagram(p2e, &labinfo, &bbinfo,"no_phi");
  204+                printflowdiagram(p2e, "no_phi");
207205 
 208206                 if (b2debug) {
 209207                         printf("new tree\n");
     
 !
664662  */
 665663 
 666664 void
<>667 -bblocks_build(struct p2env *p2e, struct labelinfo *labinfo,
 668 -    struct bblockinfo *bbinfo)
  665+bblocks_build(struct p2env *p2e)
669666 {
 670667         struct interpass *ipole = &p2e->ipole;
 671668         struct interpass *ip;
     
 !
674671         int count = 0;
 675672         int i;
 676673 
<>677 -        BDEBUG(("bblocks_build (%p, %p)\n", labinfo, bbinfo));
  674+        BDEBUG(("bblocks_build (%p, %p)\n", &p2e->labinfo, &p2e->bbinfo));
678675         low = p2e->ipp->ip_lblnum;
 679676         high = p2e->epp->ip_lblnum;
 680677 
     
 !
724721                 }
 725722         }
 726723 
<>727 -        labinfo->low = low;
 728 -        labinfo->size = high - low + 1;
 729 -        labinfo->arr = tmpalloc(labinfo->size * sizeof(struct basicblock *));
 730 -        for (i = 0; i < labinfo->size; i++) {
 731 -                labinfo->arr[i] = NULL;
  724+        p2e->labinfo.low = low;
  725+        p2e->labinfo.size = high - low + 1;
  726+        p2e->labinfo.arr = tmpalloc(p2e->labinfo.size * sizeof(struct basicblock *));
  727+        for (i = 0; i < p2e->labinfo.size; i++) {
  728+                p2e->labinfo.arr[i] = NULL;
732729         }
 733730         
<>734 -        bbinfo->size = count + 1;
 735 -        bbinfo->arr = tmpalloc(bbinfo->size * sizeof(struct basicblock *));
 736 -        for (i = 0; i < bbinfo->size; i++) {
 737 -                bbinfo->arr[i] = NULL;
  731+        p2e->bbinfo.size = count + 1;
  732+        p2e->bbinfo.arr = tmpalloc(p2e->bbinfo.size * sizeof(struct basicblock *));
  733+        for (i = 0; i < p2e->bbinfo.size; i++) {
  734+                p2e->bbinfo.arr[i] = NULL;
738735         }
 739736 
 740737         /* Build the label table */
 741738         DLIST_FOREACH(bb, &p2e->bblocks, bbelem) {
 742739                 if (bb->first->type == IP_DEFLAB)
<>743 -                        labinfo->arr[bb->first->ip_lbl - low] = bb;
  740+                        p2e->labinfo.arr[bb->first->ip_lbl - low] = bb;
744741         }
 745742 
 746743         if (b2debug) {
 747744                 printf("Label table:\n");
<>748 -                for (i = 0; i < labinfo->size; i++)
 749 -                        if (labinfo->arr[i])
  745+                for (i = 0; i < p2e->labinfo.size; i++)
  746+                        if (p2e->labinfo.arr[i])
750747                                 printf("Label %d bblock %p\n", i+low,
<>751 -                                    labinfo->arr[i]);
  748+                                    p2e->labinfo.arr[i]);
752749         }
 753750 }
 754751 
     
 !
757754  */
 758755 
 759756 void
<>760 -cfg_build(struct p2env *p2e, struct labelinfo *labinfo)
  757+cfg_build(struct p2env *p2e)
761758 {
 762759         /* Child and parent nodes */
 763760         struct cfgnode *cnode;
     
 !
777774                 if ((bb->last->type == IP_NODE) &&
 778775                     (bb->last->ip_node->n_op == GOTO) &&
 779776                     (bb->last->ip_node->n_left->n_op == ICON))  {
<>780 -                        if (bb->last->ip_node->n_left->n_lval - labinfo->low >
 781 -                            labinfo->size) {
  777+                        if (bb->last->ip_node->n_left->n_lval - p2e->labinfo.low >
  778+                            p2e->labinfo.size) {
782779                                 comperr("Label out of range: %d, base %d",
 783780                                         bb->last->ip_node->n_left->n_lval,
<>784 -                                        labinfo->low);
  781+                                        p2e->labinfo.low);
785782                         }
<>786 -                        cnode->bblock = labinfo->arr[bb->last->ip_node->n_left->n_lval - labinfo->low];
  783+                        cnode->bblock = p2e->labinfo.arr[bb->last->ip_node->n_left->n_lval - p2e->labinfo.low];
787784                         SLIST_INSERT_LAST(&cnode->bblock->parents, pnode, cfgelem);
 788785                         SLIST_INSERT_LAST(&bb->children, cnode, cfgelem);
 789786                         continue;
 790787                 }
 791788                 if ((bb->last->type == IP_NODE) &&
 792789                     (bb->last->ip_node->n_op == CBRANCH)) {
<>793 -                        if (bb->last->ip_node->n_right->n_lval - labinfo->low >
 794 -                            labinfo->size)
  790+                        if (bb->last->ip_node->n_right->n_lval - p2e->labinfo.low >
  791+                            p2e->labinfo.size)
795792                                 comperr("Label out of range: %d",
 796793                                         bb->last->ip_node->n_left->n_lval);
 797794 
<>798 -                        cnode->bblock = labinfo->arr[bb->last->ip_node->n_right->n_lval - labinfo->low];
  795+                        cnode->bblock = p2e->labinfo.arr[bb->last->ip_node->n_right->n_lval - p2e->labinfo.low];
799796                         SLIST_INSERT_LAST(&cnode->bblock->parents, pnode, cfgelem);
 800797                         SLIST_INSERT_LAST(&bb->children, cnode, cfgelem);
 801798                         cnode = tmpalloc(sizeof(struct cfgnode));
     
 !
843840  */
 844841 
 845842 void
<>846 -dominators(struct p2env *p2e, struct bblockinfo *bbinfo)
  843+dominators(struct p2env *p2e)
847844 {
 848845         struct cfgnode *cnode;
 849846         struct basicblock *bb, *y, *v;
 850847         struct basicblock *s, *sprime, *p;
 851848         int h, i;
 852849 
 853850         DLIST_FOREACH(bb, &p2e->bblocks, bbelem) {
<>854 -                bb->bucket = setalloc(bbinfo->size);
 855 -                bb->df = setalloc(bbinfo->size);
 856 -                bb->dfchildren = setalloc(bbinfo->size);
  851+                bb->bucket = setalloc(p2e->bbinfo.size);
  852+                bb->df = setalloc(p2e->bbinfo.size);
  853+                bb->dfchildren = setalloc(p2e->bbinfo.size);
857854         }
 858855 
 859856         dfsnum = 0;
<>860 -        cfg_dfs(DLIST_NEXT(&p2e->bblocks, bbelem), 0, bbinfo);
  857+        cfg_dfs(DLIST_NEXT(&p2e->bblocks, bbelem), 0, &p2e->bbinfo);
861858 
 862859         if (b2debug) {
 863860                 struct basicblock *bbb;
     
 !
876873                 }
 877874         }
 878875 
<>879 -        for(h = bbinfo->size - 1; h > 1; h--) {
 880 -                bb = bbinfo->arr[h];
 881 -                p = s = bbinfo->arr[bb->dfparent];
  876+        for(h = p2e->bbinfo.size - 1; h > 1; h--) {
  877+                bb = p2e->bbinfo.arr[h];
  878+                p = s = p2e->bbinfo.arr[bb->dfparent];
882879                 SLIST_FOREACH(cnode, &bb->parents, cfgelem) {
 883880                         if (cnode->bblock->dfnum ==0)
 884881                                 continue; /* Ignore unreachable code */
 885882 
 886883                         if (cnode->bblock->dfnum <= bb->dfnum)
 887884                                 sprime = cnode->bblock;
 888885                         else
<>889 -                                sprime = bbinfo->arr[ancestorwithlowestsemi
 890 -                                              (cnode->bblock, bbinfo)->semi];
  886+                                sprime = p2e->bbinfo.arr[ancestorwithlowestsemi
  887+                                              (cnode->bblock, &p2e->bbinfo)->semi];
891888                         if (sprime->dfnum < s->dfnum)
 892889                                 s = sprime;
 893890                 }
 894891                 bb->semi = s->dfnum;
 895892                 BITSET(s->bucket, bb->dfnum);
 896893                 link(p, bb);
<>897 -                for (i = 1; i < bbinfo->size; i++) {
  894+                for (i = 1; i < p2e->bbinfo.size; i++) {
898895                         if(TESTBIT(p->bucket, i)) {
<>899 -                                v = bbinfo->arr[i];
 900 -                                y = ancestorwithlowestsemi(v, bbinfo);
  896+                                v = p2e->bbinfo.arr[i];
  897+                                y = ancestorwithlowestsemi(v, &p2e->bbinfo);
901898                                 if (y->semi == v->semi)
 902899                                         v->idom = p->dfnum;
 903900                                 else
 904901                                         v->samedom = y->dfnum;
 905902                         }
 906903                 }
<>907 -                memset(p->bucket, 0, (bbinfo->size + 7)/8);
  904+                memset(p->bucket, 0, (p2e->bbinfo.size + 7)/8);
908905         }
 909906 
 910907         if (b2debug) {
     
 !
915912                 }
 916913         }
 917914 
<>918 -        for(h = 2; h < bbinfo->size; h++) {
 919 -                bb = bbinfo->arr[h];
  915+        for(h = 2; h < p2e->bbinfo.size; h++) {
  916+                bb = p2e->bbinfo.arr[h];
920917                 if (bb->samedom != 0) {
<>921 -                        bb->idom = bbinfo->arr[bb->samedom]->idom;
  918+                        bb->idom = p2e->bbinfo.arr[bb->samedom]->idom;
922919                 }
 923920         }
 924921         DLIST_FOREACH(bb, &p2e->bblocks, bbelem) {
 925922                 if (bb->idom != 0 && bb->idom != bb->dfnum) {
 926923                         BDEBUG(("Setting child %d of %d\n",
<>927 -                            bb->dfnum, bbinfo->arr[bb->idom]->dfnum));
 928 -                        BITSET(bbinfo->arr[bb->idom]->dfchildren, bb->dfnum);
  924+                            bb->dfnum, p2e->bbinfo.arr[bb->idom]->dfnum));
  925+                        BITSET(p2e->bbinfo.arr[bb->idom]->dfchildren, bb->dfnum);
929926                 }
 930927         }
 931928 }
     
 !
953950 }
 954951 
 955952 void
<>956 -computeDF(struct basicblock *bblock, struct bblockinfo *bbinfo)
  953+computeDF(struct p2env *p2e, struct basicblock *bblock)
957954 {
 958955         struct cfgnode *cnode;
 959956         int h, i;
     
 !
962959                 if (cnode->bblock->idom != bblock->dfnum)
 963960                         BITSET(bblock->df, cnode->bblock->dfnum);
 964961         }
<>965 -        for (h = 1; h < bbinfo->size; h++) {
  962+        for (h = 1; h < p2e->bbinfo.size; h++) {
966963                 if (!TESTBIT(bblock->dfchildren, h))
 967964                         continue;
<>968 -                computeDF(bbinfo->arr[h], bbinfo);
 969 -                for (i = 1; i < bbinfo->size; i++) {
 970 -                        if (TESTBIT(bbinfo->arr[h]->df, i) &&
 971 -                            (bbinfo->arr[i] == bblock ||
 972 -                             (bblock->dfnum != bbinfo->arr[i]->idom)))
  965+                computeDF(p2e, p2e->bbinfo.arr[h]);
  966+                for (i = 1; i < p2e->bbinfo.size; i++) {
  967+                        if (TESTBIT(p2e->bbinfo.arr[h]->df, i) &&
  968+                            (p2e->bbinfo.arr[i] == bblock ||
  969+                             (bblock->dfnum != p2e->bbinfo.arr[i]->idom)))
973970                             BITSET(bblock->df, i);
 974971                 }
 975972         }
 976973 }
 977974 
<>978 -void printDF(struct p2env *p2e, struct bblockinfo *bbinfo)
  975+void printDF(struct p2env *p2e)
979976 {
 980977         struct basicblock *bb;
 981978         int i;
     
 !
985982         DLIST_FOREACH(bb, &p2e->bblocks, bbelem) {
 986983                 printf("bb %d : ", bb->dfnum);
 987984         
<>988 -                for (i=1; i < bbinfo->size;i++) {
  985+                for (i=1; i < p2e->bbinfo.size;i++) {
989986                         if (TESTBIT(bb->df,i)) {
 990987                                 printf("%d ",i);
 991988                         }
     
 !
10501047  */
 10511048 
 10521049 void
<>1053 -placePhiFunctions(struct p2env *p2e, struct bblockinfo *bbinfo)
  1050+placePhiFunctions(struct p2env *p2e)
10541051 {
 10551052         struct basicblock *bb;
 10561053         struct basicblock *y;
     
 !
10971094                         n = defsites.arr[i];
 10981095                         defsites.arr[i] = n->next;
 10991096                         /* For each y in n->bb->df */
<>1100 -                        for (j = 0; j < bbinfo->size; j++) {
  1097+                        for (j = 0; j < p2e->bbinfo.size; j++) {
11011098                                 if (!TESTBIT(n->bb->df, j))
 11021099                                         continue;
 11031100                                 
<>1104 -                                if (TESTBIT(bbinfo->arr[j]->Aphi, i))
  1101+                                if (TESTBIT(p2e->bbinfo.arr[j]->Aphi, i))
11051102                                         continue;
 11061103 
<>1107 -                                y=bbinfo->arr[j];
  1104+                                y=p2e->bbinfo.arr[j];
11081105                                 ntype = n->n_type;
 11091106                                 k = 0;
 11101107                                 /* Amount of predecessors for y */
     
 !
11371134                                         printf("Phi already in %d for %d\n",y->dfnum,i+defsites.low);
 11381135                                 }
 11391136 
<>1140 -                                BITSET(bbinfo->arr[j]->Aphi, i);
 1141 -                                if (!TESTBIT(bbinfo->arr[j]->Aorig, i)) {
  1137+                                BITSET(p2e->bbinfo.arr[j]->Aphi, i);
  1138+                                if (!TESTBIT(p2e->bbinfo.arr[j]->Aorig, i)) {
11421139                                         pv = tmpalloc(sizeof(struct pvarinfo));
 11431140                                         pv->bb = y;
 11441141                                         pv->n_type=ntype;
     
 !
11991196 
 12001197 
 12011198 void
<>1202 -renamevar(struct p2env *p2e,struct basicblock *bb, struct bblockinfo *bbinfo)
  1199+renamevar(struct p2env *p2e,struct basicblock *bb)
12031200 {
 12041201         struct interpass *ip;
 12051202         int h,j;
     
 !
12571254                 
 12581255         }
 12591256         
<>1260 -        for (h = 1; h < bbinfo->size; h++) {
  1257+        for (h = 1; h < p2e->bbinfo.size; h++) {
12611258                 if (!TESTBIT(bb->dfchildren, h))
 12621259                         continue;
 12631260                 
<>1264 -                renamevar(p2e,bbinfo->arr[h], bbinfo);
  1261+                renamevar(p2e,p2e->bbinfo.arr[h]);
12651262         }
 12661263         
 12671264         SLIST_FOREACH(stacke,&poplist,varstackelem) {
     
 !
12791276 } ;
 12801277 
 12811278 void
<>1282 -removephi(struct p2env *p2e, struct labelinfo *labinfo,struct bblockinfo *bbinfo)
  1279+removephi(struct p2env *p2e)
12831280 {
 12841281         struct basicblock *bb,*bbparent;
 12851282         struct cfgnode *cfgn;
     
 !
13161313                                         BDEBUG((" CBRANCH "));
 13171314                                         label = (int)pip->ip_node->n_right->n_lval;
 13181315                                         
<>1319 -                                        if (bb==labinfo->arr[label - p2e->ipp->ip_lblnum])
  1316+                                        if (bb==p2e->labinfo.arr[label - p2e->ipp->ip_lblnum])
13201317                                                 complex = pred_cond ;
 13211318                                         else
 13221319                                                 complex = pred_falltrough ;
     
 !
15771574         fprintf(flowdiagramfile,"}");
 15781575 }
 15791576 
<>1580 -void printflowdiagram(struct p2env *p2e,struct labelinfo *labinfo,struct bblockinfo *bbinfo,char *type) {
  1577+void
  1578+printflowdiagram(struct p2env *p2e, char *type) {
15811579         struct basicblock *bbb;
 15821580         struct cfgnode *ccnode;
 15831581         struct interpass *ip;
     
 !
16591657                         if (pip->type == IP_NODE && pip->ip_node->n_op == CBRANCH) {
 16601658                                 int label = (int)pip->ip_node->n_right->n_lval;
 16611659                                 
<>1662 -                                if (ccnode->bblock==labinfo->arr[label - p2e->ipp->ip_lblnum])
  1660+                                if (ccnode->bblock==p2e->labinfo.arr[label - p2e->ipp->ip_lblnum])
<_16631661                                         color="red";
 16641662                         }
 16651663                         
FishEye: Open Source License registered to PCC.
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-12-19 04:15 +0100