Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.58
 
1.59
 
MAIN:pantzer:20081122201350
 
optim2.c
_>6262 ancestorwithlowestsemi(struct basicblock *bblock, struct bblockinfo *bbinfo);
 6363 void link(struct basicblock *parent, struct basicblock *child);
 6464 void computeDF(struct basicblock *bblock, struct bblockinfo *bbinfo);
<> 65+void printDF(struct p2env *p2e, struct bblockinfo *bbinfo);
6566 void findTemps(struct interpass *ip);
 6667 void placePhiFunctions(struct p2env *, struct bblockinfo *bbinfo);
<> 68+void renamevar(struct p2env *p2e,struct basicblock *bblock, struct bblockinfo *bbinfo);
  69+void removephi(struct p2env *p2e, struct labelinfo *,struct bblockinfo *bbinfo);
6770 void remunreach(struct p2env *);
 6871 
 6972 void
     
 !
98101                 dominators(p2e, &bbinfo);
 99102                 BDEBUG(("Calling computeDF\n"));
 100103                 computeDF(DLIST_NEXT(&p2e->bblocks, bbelem), &bbinfo);
<> 104+
  105+                if (b2debug) {
  106+                        printDF(p2e,&bbinfo);
  107+                }
  108+
  109+                BDEBUG(("Calling placePhiFunctions\n"));
  110+
  111+                placePhiFunctions(p2e, &bbinfo);
  112+
  113+                BDEBUG(("Calling renamevar\n"));
  114+
  115+                renamevar(p2e,DLIST_NEXT(&p2e->bblocks, bbelem), &bbinfo);
  116+
  117+                BDEBUG(("Calling removephi\n"));
  118+
  119+                removephi(p2e,&labinfo,&bbinfo);
  120+
101121                 BDEBUG(("Calling remunreach\n"));
 102122                 remunreach(p2e);
<>103 -#if 0
 104 -                dfg = dfg_build(cfg);
 105 -                ssa = ssa_build(cfg, dfg);
  123+                
  124+                /*
  125+                 Recalculate basic blocks and cfg that was destroyed
  126+                 by removephi
  127+                 */
  128+
  129+                DLIST_INIT(&p2e->bblocks, bbelem);
  130+                bblocks_build(p2e, &labinfo, &bbinfo);
  131+                BDEBUG(("Calling cfg_build\n"));
  132+                cfg_build(p2e, &labinfo);
  133+
  134+#ifdef PCC_DEBUG
  135+                if (b2debug) {
  136+                        printf("new tree\n");
  137+                        printip(ipole);
  138+                }
106139 #endif
 107140         }
 108141 
     
 !
408441                         bb->dfchildren = NULL;
 409442                         bb->Aorig = NULL;
 410443                         bb->Aphi = NULL;
<> 444+                        SLIST_INIT(&bb->phi);
411445                         bb->bbnum = count;
 412446                         DLIST_INSERT_BEFORE(&p2e->bblocks, bb, bbelem);
 413447                         count++;
     
 !
671705                 computeDF(bbinfo->arr[h], bbinfo);
 672706                 for (i = 1; i < bbinfo->size; i++) {
 673707                         if (TESTBIT(bbinfo->arr[h]->df, i) &&
<>674 -                            (bbinfo->arr[h] == bblock ||
 675 -                             (bblock->idom != bbinfo->arr[h]->dfnum)))
  708+                            (bbinfo->arr[i] == bblock ||
  709+                             (bblock->dfnum != bbinfo->arr[i]->idom)))
676710                             BITSET(bblock->df, i);
 677711                 }
 678712         }
 679713 }
 680714 
<> 715+void printDF(struct p2env *p2e, struct bblockinfo *bbinfo)
  716+{
  717+        struct basicblock *bb;
  718+        int i;
  719+
  720+        printf("Dominance frontiers:\n");
  721+   
  722+        DLIST_FOREACH(bb, &p2e->bblocks, bbelem) {
  723+                printf("bb %d : ", bb->dfnum);
  724+        
  725+                for (i=1; i < bbinfo->size;i++) {
  726+                        if (TESTBIT(bb->df,i)) {
  727+                                printf("%d ",i);
  728+                        }
  729+                }
  730+           
  731+                printf("\n");
  732+        }
  733+   
  734+}
  735+
  736+
  737+
681738 static struct basicblock *currbb;
 682739 static struct interpass *currip;
 683740 
     
 !
686743 searchasg(NODE *p, void *arg)
 687744 {
 688745         struct pvarinfo *pv;
<>689 -
  746+        int tempnr;
  747+        struct varstack *stacke;
  748+   
690749         if (p->n_op != ASSIGN)
 691750                 return;
 692751 
 693752         if (p->n_left->n_op != TEMP)
 694753                 return;
 695754 
<> 755+        tempnr=regno(p->n_left)-defsites.low;
  756+   
  757+        BITSET(currbb->Aorig, tempnr);
  758+        
696759         pv = tmpcalloc(sizeof(struct pvarinfo));
<>697 -        pv->next = defsites.arr[p->n_left->n_lval];
  760+        pv->next = defsites.arr[tempnr];
698761         pv->bb = currbb;
<>699 -        pv->top = currip->ip_node;
 700 -        pv->n = p->n_left;
 701 -        BITSET(currbb->Aorig, p->n_left->n_lval);
 702 -
 703 -        defsites.arr[p->n_left->n_lval] = pv;
  762+        pv->n_type = p->n_left->n_type;
  763+        
  764+        defsites.arr[tempnr] = pv;
  765+        
  766+        
  767+        if (SLIST_FIRST(&defsites.stack[tempnr])==NULL) {
  768+                stacke=tmpcalloc(sizeof (struct varstack));
  769+                stacke->tmpregno=regno(p->n_left);
  770+                SLIST_INSERT_FIRST(&defsites.stack[tempnr],stacke,varstackelem);
  771+        }
704772 }
 705773 
 706774 /* Walk the interpass looking for assignment nodes. */
     
 !
722790 placePhiFunctions(struct p2env *p2e, struct bblockinfo *bbinfo)
 723791 {
 724792         struct basicblock *bb;
<> 793+        struct basicblock *y;
725794         struct interpass *ip;
<>726 -        int maxtmp, i, j, k, l;
  795+        int maxtmp, i, j, k;
727796         struct pvarinfo *n;
 728797         struct cfgnode *cnode;
 729798         TWORD ntype;
<>730 -        NODE *p;
731799         struct pvarinfo *pv;
<> 800+        struct phiinfo *phi;
  801+        int phifound;
732802 
 733803         bb = DLIST_NEXT(&p2e->bblocks, bbelem);
 734804         defsites.low = ((struct interpass_prolog *)bb->first)->ip_tmpnum;
 735805         bb = DLIST_PREV(&p2e->bblocks, bbelem);
 736806         maxtmp = ((struct interpass_prolog *)bb->first)->ip_tmpnum;
 737807         defsites.size = maxtmp - defsites.low + 1;
 738808         defsites.arr = tmpcalloc(defsites.size*sizeof(struct pvarinfo *));
<>739 -
  809+        defsites.stack = tmpcalloc(defsites.size*sizeof(SLIST_HEAD(, varstack)));
  810+        
  811+        for (i=0;i<defsites.size;i++)
  812+                SLIST_INIT(&defsites.stack[i]); 
  813+        
740814         /* Find all defsites */
 741815         DLIST_FOREACH(bb, &p2e->bblocks, bbelem) {
 742816                 currbb = bb;
 743817                 ip = bb->first;
 744818                 bb->Aorig = setalloc(defsites.size);
 745819                 bb->Aphi = setalloc(defsites.size);
 746820                 
<>747 -
748821                 while (ip != bb->last) {
 749822                         findTemps(ip);
 750823                         ip = DLIST_NEXT(ip, qelem);
 751824                 }
 752825                 /* Make sure we get the last statement in the bblock */
 753826                 findTemps(ip);
 754827         }
<> 828+   
755829         /* For each variable */
<>756 -        for (i = defsites.low; i < defsites.size; i++) {
  830+        for (i = 0; i < defsites.size; i++) {
757831                 /* While W not empty */
 758832                 while (defsites.arr[i] != NULL) {
 759833                         /* Remove some node n from W */
     
 !
767841                                 if (TESTBIT(bbinfo->arr[j]->Aphi, i))
 768842                                         continue;
 769843 
<>770 -                                ntype = n->n->n_type;
  844+                                y=bbinfo->arr[j];
  845+                                ntype = n->n_type;
771846                                 k = 0;
 772847                                 /* Amount of predecessors for y */
<>773 -                                SLIST_FOREACH(cnode, &n->bb->parents, cfgelem)
  848+                                SLIST_FOREACH(cnode, &y->parents, cfgelem)
774849                                         k++;
<>775 -                                /* Construct phi(...) */
 776 -                                p = mktemp(i, ntype);
 777 -                                for (l = 0; l < k-1; l++)
 778 -                                        p = mkbinode(PHI, p,
 779 -                                            mktemp(i, ntype), ntype);
 780 -                                ip = ipnode(mkbinode(ASSIGN,
 781 -                                    mktemp(i, ntype), p, ntype));
 782 -                                /* Insert phi at top of basic block */
 783 -                                DLIST_INSERT_BEFORE(((struct interpass*)&n->bb->first), ip, qelem);
 784 -                                n->bb->first = ip;
  850+                                /* Construct phi(...)
  851+                                */
  852+                           
  853+                                phifound=0;
  854+                           
  855+                                SLIST_FOREACH(phi, &y->phi, phielem) {
  856+                                    if (phi->tmpregno==i+defsites.low)
  857+                                        phifound++;
  858+                                }
  859+                           
  860+                                if (phifound==0) {
  861+                                        if (b2debug)
  862+                                            printf("Phi in %d for %d\n",y->dfnum,i+defsites.low);
  863+
  864+                                        phi = tmpcalloc(sizeof(struct phiinfo));
  865+                           
  866+                                        phi->tmpregno=i+defsites.low;
  867+                                        phi->size=k;
  868+                                        phi->n_type=ntype;
  869+                                        phi->intmpregno=tmpalloc(k*sizeof(int));
  870+                           
  871+                                        SLIST_INSERT_LAST(&y->phi,phi,phielem);
  872+                                } else {
  873+                                    if (b2debug)
  874+                                        printf("Phi already in %d for %d\n",y->dfnum,i+defsites.low);
  875+                                }
  876+
785877                                 BITSET(bbinfo->arr[j]->Aphi, i);
 786878                                 if (!TESTBIT(bbinfo->arr[j]->Aorig, i)) {
 787879                                         pv = tmpalloc(sizeof(struct pvarinfo));
<>788 -                                        // XXXpj Ej fullständig information.
 789 -                                        pv->bb = bbinfo->arr[j];
 790 -                                        pv->next = defsites.arr[i]->next;
  880+                                        pv->bb = y;
  881+                                        pv->n_type=ntype;
  882+                                        pv->next = defsites.arr[i];
791883                                         defsites.arr[i] = pv;
 792884                                 }
 793885                                         
     
 !
797889         }
 798890 }
 799891 
<> 892+/* Helper function for renamevar. */
  893+static void
  894+renamevarhelper(struct p2env *p2e,NODE *t,void *poplistarg)
  895+{       
  896+        SLIST_HEAD(, varstack) *poplist=poplistarg;
  897+        int opty;
  898+        int tempnr;
  899+        int newtempnr;
  900+        int x;
  901+        struct varstack *stacke;
  902+        
  903+        if (t->n_op == ASSIGN && t->n_left->n_op == TEMP) {
  904+                renamevarhelper(p2e,t->n_right,poplist);
  905+                                
  906+                tempnr=regno(t->n_left)-defsites.low;
  907+                
  908+                newtempnr=p2e->epp->ip_tmpnum++;
  909+                regno(t->n_left)=newtempnr;
  910+                
  911+                stacke=tmpcalloc(sizeof (struct varstack));
  912+                stacke->tmpregno=newtempnr;
  913+                SLIST_INSERT_FIRST(&defsites.stack[tempnr],stacke,varstackelem);
  914+                
  915+                stacke=tmpcalloc(sizeof (struct varstack));
  916+                stacke->tmpregno=tempnr;
  917+                SLIST_INSERT_FIRST(poplist,stacke,varstackelem);
  918+        } else {
  919+                if (t->n_op == TEMP) {
  920+                        tempnr=regno(t)-defsites.low;
  921+                        
  922+                        x=SLIST_FIRST(&defsites.stack[tempnr])->tmpregno;
  923+                        regno(t)=x;
  924+                }
  925+                
  926+                opty = optype(t->n_op);
  927+                
  928+                if (opty != LTYPE)
  929+                        renamevarhelper(p2e, t->n_left,poplist);
  930+                if (opty == BITYPE)
  931+                        renamevarhelper(p2e, t->n_right,poplist);
  932+        }
  933+}
  934+
  935+
  936+void
  937+renamevar(struct p2env *p2e,struct basicblock *bb, struct bblockinfo *bbinfo)
  938+{
  939+        struct interpass *ip;
  940+        int h,j;
  941+        SLIST_HEAD(, varstack) poplist;
  942+        struct varstack *stacke;
  943+        struct cfgnode *cfgn;
  944+        struct cfgnode *cfgn2;
  945+        int tmpregno,newtmpregno;
  946+        struct phiinfo *phi;
  947+        
  948+        SLIST_INIT(&poplist);
  949+        
  950+        SLIST_FOREACH(phi,&bb->phi,phielem) {
  951+                tmpregno=phi->tmpregno-defsites.low;
  952+                
  953+                newtmpregno=p2e->epp->ip_tmpnum++;
  954+                phi->newtmpregno=newtmpregno;
  955+                
  956+                stacke=tmpcalloc(sizeof (struct varstack));
  957+                stacke->tmpregno=newtmpregno;
  958+                SLIST_INSERT_FIRST(&defsites.stack[tmpregno],stacke,varstackelem);
  959+                
  960+                stacke=tmpcalloc(sizeof (struct varstack));
  961+                stacke->tmpregno=tmpregno;
  962+                SLIST_INSERT_FIRST(&poplist,stacke,varstackelem);               
  963+        }
  964+        
  965+        
  966+        ip=bb->first;
  967+        
  968+        while (1) {             
  969+                if ( ip->type == IP_NODE) {
  970+                        renamevarhelper(p2e,ip->ip_node,&poplist);
  971+                }
  972+                
  973+                if (ip==bb->last)
  974+                        break;
  975+                
  976+                ip = DLIST_NEXT(ip, qelem);
  977+        }
  978+        
  979+        SLIST_FOREACH(cfgn,&bb->children,cfgelem) {
  980+                j=0;
  981+                
  982+                SLIST_FOREACH(cfgn2, &cfgn->bblock->parents, cfgelem) {
  983+                        if (cfgn2->bblock->dfnum==bb->dfnum)
  984+                                break;
  985+                        
  986+                        j++;
  987+                }
  988+
  989+                SLIST_FOREACH(phi,&cfgn->bblock->phi,phielem) {
  990+                        phi->intmpregno[j]=SLIST_FIRST(&defsites.stack[phi->tmpregno-defsites.low])->tmpregno;
  991+                }
  992+                
  993+        }
  994+        
  995+        for (h = 1; h < bbinfo->size; h++) {
  996+                if (!TESTBIT(bb->dfchildren, h))
  997+                        continue;
  998+                
  999+                renamevar(p2e,bbinfo->arr[h], bbinfo);
  1000+        }
  1001+        
  1002+        SLIST_FOREACH(stacke,&poplist,varstackelem) {
  1003+                tmpregno=stacke->tmpregno;
  1004+                
  1005+                defsites.stack[tmpregno].q_forw=defsites.stack[tmpregno].q_forw->varstackelem.q_forw;
  1006+        }
  1007+}
  1008+
  1009+void
  1010+removephi(struct p2env *p2e, struct labelinfo *labinfo,struct bblockinfo *bbinfo)
  1011+{
  1012+        struct basicblock *bb,*bbparent;
  1013+        struct cfgnode *cfgn;
  1014+        struct phiinfo *phi;
  1015+        int i;
  1016+        struct interpass *ip;
  1017+        struct interpass *pip;
  1018+        TWORD n_type;
  1019+        int complex;
  1020+        int label;
  1021+        int newlabel;
  1022+        
  1023+        DLIST_FOREACH(bb, &p2e->bblocks, bbelem) {              
  1024+                SLIST_FOREACH(phi,&bb->phi,phielem) { // Look at only one, notice break at end
  1025+                        i=0;
  1026+                        
  1027+                        SLIST_FOREACH(cfgn, &bb->parents, cfgelem) {
  1028+                                bbparent=cfgn->bblock;
  1029+                                
  1030+                                pip=bbparent->last;
  1031+                                
  1032+                                complex = 0;
  1033+                                
  1034+                                if (pip->type == IP_NODE && pip->ip_node->n_op == GOTO) {
  1035+                                        label=pip->ip_node->n_left->n_lval;
  1036+                                        complex=1;
  1037+                                } else if (pip->type == IP_NODE && pip->ip_node->n_op == CBRANCH) {
  1038+                                        label=pip->ip_node->n_right->n_lval;
  1039+                                        
  1040+                                        if (bb==labinfo->arr[label - p2e->ipp->ip_lblnum])
  1041+                                                complex=2;
  1042+                                }       
  1043+                                                              
  1044+                                                              
  1045+                                if (complex > 0) {
  1046+                                        /*
  1047+                                         This destroys basic block calculations.
  1048+                                         Maybe it shoud not
  1049+                                        */
  1050+                                        ip = ipnode(mkunode(GOTO, mklnode(ICON, label, 0, INT), 0, INT));
  1051+                                        DLIST_INSERT_BEFORE((bb->first), ip, qelem);
  1052+                                        
  1053+                                        newlabel=getlab2();
  1054+                                        
  1055+                                        ip = tmpalloc(sizeof(struct interpass));
  1056+                                        ip->type = IP_DEFLAB;
  1057+                                        // Line number?? ip->lineno;
  1058+                                        ip->ip_lbl = newlabel;
  1059+                                        DLIST_INSERT_BEFORE((bb->first), ip, qelem);
  1060+                                        
  1061+                                        SLIST_FOREACH(phi,&bb->phi,phielem) {
  1062+                                                n_type=phi->n_type;
  1063+                                                ip = ipnode(mkbinode(ASSIGN,
  1064+                                                             mktemp(phi->newtmpregno, n_type),
  1065+                                                             mktemp(phi->intmpregno[i],n_type),
  1066+                                                             n_type));
  1067+                                        
  1068+                                                DLIST_INSERT_BEFORE((bb->first), ip, qelem);
  1069+                                        }
  1070+                                        
  1071+                                        if (complex==1)
  1072+                                                pip->ip_node->n_left->n_lval=newlabel;
  1073+                                        
  1074+                                        if (complex==2)
  1075+                                                pip->ip_node->n_right->n_lval=newlabel;
  1076+                                        
  1077+                                } else {
  1078+                                        /* Construct move */
  1079+                                        SLIST_FOREACH(phi,&bb->phi,phielem) {
  1080+                                                n_type=phi->n_type;
  1081+                                                ip = ipnode(mkbinode(ASSIGN,
  1082+                                                     mktemp(phi->newtmpregno, n_type),
  1083+                                                     mktemp(phi->intmpregno[i],n_type),
  1084+                                                     n_type));
  1085+                                
  1086+                                                /* Insert move at bottom of parent basic block */
  1087+                                                DLIST_INSERT_AFTER((bbparent->last), ip, qelem);
  1088+                                                bbparent->last=ip;
  1089+                                        }
  1090+                                }
  1091+                                i++;
  1092+                        }
  1093+                        break;
  1094+                }
  1095+        }
  1096+}
  1097+
  1098+   
<_8001099 /*
 8011100  * Remove unreachable nodes in the CFG.
 8021101  */
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-09-01 20:41 +0200