Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20050218164859

Diff

Diff from 1.11 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/pcc/pcc/mip/optim2.c

Annotated File View

ragge
1.11
1 /*      $Id: optim2.c,v 1.11 2005/02/18 16:48:59 ragge Exp $    */
ragge
1.1
2 /*
3  * Copyright (c) 2004 Anders Magnusson (ragge@ludd.luth.se).
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 #include "pass2.h"
30
ragge
1.3
31 #include <string.h>
pj
1.4
32 #include <stdlib.h>
33 #include <machine/limits.h>
34
35 #ifndef MIN
36 #define MIN(a,b) (((a)<(b))?(a):(b))
37 #endif
38
39 #ifndef MAX
40 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
41 #endif
ragge
1.3
42
ragge
1.1
43 extern int saving;
pj
1.8
44 static int dfsnum;
ragge
1.1
45
46 void saveip(struct interpass *ip);
47 void deljumps(void);
48 void deltemp(NODE *p);
49 void optdump(struct interpass *ip);
50
ragge
1.11
51 static struct interpass ipole;
ragge
1.1
52
53 static struct rsv {
54         struct rsv *next;
55         int fpoff;
56         TWORD type;
57         int use;
58 } *rsv;
59
pj
1.8
60 int bblocks_build(struct labelinfo *labinfostruct bblockinfo *bbinfo);
pj
1.4
61 void cfg_build(struct labelinfo *labinfo);
pj
1.8
62 void cfg_dfs(struct basicblock *bbunsigned int parent
63              struct bblockinfo *bbinfo);
64 void dominators(struct bblockinfo *bbinfo);
pj
1.9
65 struct basicblock *
66 ancestorwithlowestsemi(struct basicblock *bblockstruct bblockinfo *bbinfo);
67 void link(struct basicblock *parentstruct basicblock *child);
68 void computeDF(struct basicblock *bblockstruct bblockinfo *bbinfo);
pj
1.4
69
70
ragge
1.11
71 static struct basicblock bblocks;
pj
1.4
72
ragge
1.1
73 static void
74 addcand(TWORD typeint offint avoid)
75 {
76         struct rsv *w = rsv;
77
78         while (w != NULL) {
79                 if (w->type == type && w->fpoff == off) {
80                         if (avoid)
81                                 w->use = -1;
82                         else if (w->use > 0)
83                                 w->use++;
84                         return;
85                 }
86                 w = w->next;
87         }
88         w = tmpalloc(sizeof(*w));
89         w->type = type;
90         w->fpoff = off;
91         w->use = avoid ? -1 : 1;
92         w->next = rsv;
93         rsv = w;
94 }
95
96 /*
97  * walk through the tree and count the number of (possible)
98  * temporary nodes.
99  */
100 static void
101 cntuse(NODE *p)
102 {
103         NODE *l = p->n_left;
104         NODE *r = p->n_right;
105
106         if (p->n_op == UMUL && l->n_op == REG && l->n_rval == FPREG) {
107                 /* found a candidate for register */
108                 addcand(p->n_type0ISVOL(p->n_qual << TSHIFT));
109         } else if (p->n_op == UMUL && l->n_op == PLUS &&
110             l->n_right->n_op == ICON && 
111              (l->n_left->n_op == REG && l->n_left->n_rval == FPREG)) {
112                 /* The same as above */
113                 addcand(p->n_typel->n_right->n_lval,
114                     ISVOL(p->n_qual << TSHIFT));
115         } else if (p->n_op == PLUS && l->n_op == REG && l->n_rval == FPREG &&
116             p->n_right->n_op == ICON) {
117                 /* Address taken of temporary, avoid register */
118                 addcand(DECREF(p->n_type), r->n_lval1);
119         } else {
120                 if (optype(p->n_op) == BITYPE)
121                         cntuse(r);
122                 if (optype(p->n_op) != LTYPE)
123                         cntuse(l);
124         }
125 }
126
127 /*
ragge
1.2
128  * Insert a node into the register stack.
129  */
130 static void
131 insert(struct rsv *wstruct rsv **savedint maxregs)
132 {
133         int ijsize;
134
135         size = szty(w->type);
136
137         /* Find reg move position */
138         for (i = 0i < maxregsi++) {
139                 if (saved[i] == NULL)
140                         continue;
141                 if (saved[i]->use > w->use)
142                         break;
143         }
144         /* Move down other regs */
145         for (j = sizej < ij++)
146                 saved[j-size] = saved[j];
147
148         /* Insert new reg pointer */
149         if (i-size >= 0) {
150                 saved[i-size] = w;
151                 for (j = i-size+1j < ij++)
152                         saved[j] = NULL;
153         }
154 }
155
156 /* Help routine to rconvert() */
157 static int
158 matches(TWORD typeint offstruct rsv **rsvint maxregs)
159 {
160         int i;
161
162         for (i = 0i < maxregsi++)
163                 if (rsv[i] && rsv[i]->type == type && rsv[i]->fpoff == off)
164                         return i;
165         return -1;
166 }
167
168 /* Help routine to rconvert() */
169 static void
170 modify(NODE *pint reg)
171 {
172         tfree(p->n_left);
173         p->n_op = REG;
174         p->n_rval = p->n_rall = reg + MINRVAR;
175         p->n_lval = 0;
176 }
177
178 /*
179  * walk through the tree and convert nodes to registers
180  */
181 static void
182 rconvert(NODE *pstruct rsv **rsvint maxregs)
183 {
184         NODE *l = p->n_left;
185         NODE *r = p->n_right;
186         int i;
187
188         if (p->n_op == UMUL && l->n_op == REG && l->n_rval == FPREG) {
189                 /* found a candidate for register */
190                 if ((i = matches(p->n_type0rsvmaxregs)) >= 0)
191                         modify(pi);
192         } else if (p->n_op == UMUL && l->n_op == PLUS &&
193             l->n_right->n_op == ICON && 
194              (l->n_left->n_op == REG && l->n_left->n_rval == FPREG)) {
195                 /* The same as above */
196                 if ((i = matches(p->n_type,
197                     l->n_right->n_lvalrsvmaxregs)) >= 0)
198                         modify(pi);
199 #if 0
200         } else if (p->n_op == PLUS && l->n_op == REG && l->n_rval == FPREG &&
201             p->n_right->n_op == ICON) {
202                 /* Address taken of temporary, avoid register */
203                 addcand(DECREF(p->n_type), r->n_lval1);
204 #endif
205         } else {
206                 if (optype(p->n_op) == BITYPE)
207                         rconvert(rrsvmaxregs);
208                 if (optype(p->n_op) != LTYPE)
209                         rconvert(lrsvmaxregs);
210         }
211 }
212
213 /*
ragge
1.1
214  * Assign non-temporary registers to variables.
215  * Cannot do it if:
216  * - address is taken of the temporary
217  * - variable is declared "volatile".
218  */
pj
1.4
219 int asgregs(void);
220 int
ragge
1.1
221 asgregs(void)
222 {
223         struct interpass *ip;
ragge
1.2
224         struct rsv *w, **saved;
225         int imaxregs = MAXRVAR - MINRVAR + 1;
ragge
1.1
226
ragge
1.2
227         if (maxregs == 0)
228                 return MAXRVAR/* No register usage */
ragge
1.1
229         rsv = NULL;
230
231         /* Loop over the function to do a usage count */
ragge
1.11
232         DLIST_FOREACH(ip, &ipoleqelem) {
ragge
1.1
233                 if (ip->type != IP_NODE)
234                         continue;
235                 cntuse(ip->ip_node);
236         }
237         /* Check which nodes that shall be converted to registers */
ragge
1.2
238         saved = tmpalloc(sizeof(struct rsv *) * maxregs);
239         memset(saved0sizeof(struct rsv *) * maxregs);
ragge
1.1
240         w = rsv;
241         for (w = rsvww = w->next) {
242                 if (w->use < 0)
ragge
1.2
243                         continue/* Not allowed to be in register */
244
245                 /* XXX check here if type is allowed to be in register */
246
247                 insert(wsavedmaxregs);
ragge
1.1
248         }
249
250         /* Convert found nodes to registers */
ragge
1.11
251         DLIST_FOREACH(ip, &ipoleqelem) {
ragge
1.2
252                 if (ip->type != IP_NODE)
253                         continue;
254                 rconvert(ip->ip_nodesavedmaxregs);
255         }
256         for (i = 0i < maxregsi++)
257                 if (saved[i] != NULL)
258                         break;
259         return MINRVAR+i-1;
ragge
1.1
260 }
261
262 void
263 saveip(struct interpass *ip)
264 {
ragge
1.5
265         struct interpass_prolog *ipp, *epp;
266
pj
1.4
267 #if 0
ragge
1.2
268         int regs;
pj
1.4
269 #endif
270         struct labelinfo labinfo;
pj
1.8
271         struct bblockinfo bbinfo;
ragge
1.1
272
ragge
1.11
273         if (ip->type == IP_PROLOG)
274                 DLIST_INIT(&ipoleqelem);
275
276         DLIST_INSERT_BEFORE(&ipoleipqelem);
ragge
1.1
277
278         if (ip->type != IP_EPILOG)
279                 return;
ragge
1.5
280         epp = (struct interpass_prolog *)ip;
ragge
1.1
281         saving = -1;
282
pj
1.4
283         //              deljumps();     /* Delete redundant jumps and dead code */
284         if (xssaflag) {
ragge
1.11
285                 DLIST_INIT(&bblocksbbelem);
pj
1.8
286                 if (bblocks_build(&labinfo, &bbinfo)) {
pj
1.4
287                         cfg_build(&labinfo);
pj
1.8
288                         dominators(&bbinfo);
ragge
1.11
289                         computeDF(DLIST_NEXT(&bblocksbbelem), &bbinfo);
pj
1.4
290 #if 0
pj
1.6
291                         if (xssaflag) {
292                                 dfg = dfg_build(cfg);
293                                 ssa = ssa_build(cfgdfg);
294                         }
pj
1.4
295 #endif
296                 }
297  
298         }
299 #if 0
ragge
1.2
300         regs = asgregs();       /* Assign non-temporary registers */
pj
1.4
301 #endif
ragge
1.2
302
303 #ifdef PCC_DEBUG
ragge
1.5
304         if (epp->ipp_regs != MAXRVAR)
ragge
1.2
305                 comperr("register error");
306 #endif
ragge
1.1
307
ragge
1.11
308         ipp = (struct interpass_prolog *)DLIST_NEXT(&ipoleqelem);
ragge
1.5
309         ipp->ipp_autos = epp->ipp_autos;
310         ipp->ipp_regs = epp->ipp_regs// = regs;
ragge
1.1
311
312 #ifdef MYOPTIM
pj
1.6
313         myoptim((struct interpass *)ipp);
ragge
1.1
314 #endif
315
ragge
1.11
316         DLIST_FOREACH(ip, &ipoleqelem) {
ragge
1.1
317                 pass2_compile(ip);
318         }
ragge
1.11
319         DLIST_INIT(&ipoleqelem);
ragge
1.1
320 }
321
322 void
323 deljumps()
324 {
325         struct interpass *ip, *n;
326         int gotone;
327
328 again:  gotone = 0;
329
ragge
1.11
330         DLIST_FOREACH(ip, &ipoleqelem) {
ragge
1.1
331                 if (ip->type == IP_EPILOG)
332                         return;
333                 if (ip->type != IP_NODE)
334                         continue;
ragge
1.11
335                 n = DLIST_NEXT(ipqelem);
ragge
1.1
336                 /* Check for nodes without side effects */
337                 if (ip->ip_node->n_op != GOTO)
338                         continue;
339                 switch (n->type) {
340                 case IP_NODE:
341                         tfree(n->ip_node);
ragge
1.11
342                         DLIST_REMOVE(nqelem);
ragge
1.1
343                         break;
344                 case IP_DEFLAB:
345                         if (ip->ip_node->n_left->n_lval != n->ip_lbl)
346                                 continue;
347                         tfree(ip->ip_node);
348                         *ip = *n;
349                         break;
350                 default:
351                         continue;
352                 }
353                 gotone = 1;
354         }
355         if (gotone)
356                 goto again;
357 }
358
359 void
360 optdump(struct interpass *ip)
361 {
362         static char *nm[] = { "node""prolog""newblk""epilog""locctr",
363                 "deflab""defnam""asm" };
364         printf("type %s\n"nm[ip->type-1]);
365         switch (ip->type) {
366         case IP_NODE:
367                 fwalk(ip->ip_nodee2print0);
368                 break;
369         case IP_DEFLAB:
370                 printf("label " LABFMT "\n"ip->ip_lbl);
371                 break;
372         case IP_ASM:
373                 printf(": %s\n"ip->ip_asm);
374                 break;
375         }
376 }
pj
1.4
377
378 /*
379  * Build the basic blocks, algorithm 9.1, pp 529 in Compilers.
380  *
381  * Also fills the labelinfo struct with information about which bblocks
382  * that contain which label.
383  */
384
385 int
pj
1.8
386 bblocks_build(struct labelinfo *labinfostruct bblockinfo *bbinfo)
pj
1.4
387 {
388         struct interpass *ip;
389         struct basicblock *bb = NULL;
390         int leader = 1;
391         unsigned int low = UINT_MAXhigh = 0;
pj
1.8
392         int count = 0;
pj
1.4
393         int i;
394
395         /* 
396          * First statement is a leader.
397          * Any statement that is target of a jump is a leader.
398          * Any statement that immediately follows a jump is a leader.
399          */
400
ragge
1.11
401         DLIST_FOREACH(ip, &ipoleqelem) {
pj
1.4
402                 /* Garbage, skip it */
ragge
1.11
403                 if (ip->type == IP_NEWBLK)
pj
1.4
404                         continue;
405
406                 if (leader) {
407                         bb = tmpalloc(sizeof(struct basicblock));
408                         bb->first = bb->last = ip;
ragge
1.11
409                         SLIST_INIT(&bb->children);
410                         SLIST_INIT(&bb->parents);
pj
1.8
411                         bb->dfnum = 0;
412                         bb->dfparent = 0;
413                         bb->semi = 0;
414                         bb->ancestor = 0;
415                         bb->idom = 0;
416                         bb->samedom = 0;
417                         bb->bucket = NULL;
418                         bb->df = NULL;
pj
1.10
419                         bb->dfchildren = NULL;
ragge
1.11
420                         DLIST_INSERT_BEFORE(&bblocksbbbbelem);
pj
1.4
421                         leader = 0;
pj
1.8
422                         count++;
pj
1.4
423                 } 
424                 
425                 /* Prologue and epilogue in their own bblock */
426                 if ((ip->type == IP_PROLOG) || (ip->type == IP_EPILOG)) {
427                         bb->last = ip;
428                         if (ip->type == IP_EPILOG)
ragge
1.5
429                                 high = MAX(ip->ip_lblhigh);
pj
1.4
430                         leader = 1;
431                         continue;
432                 }
433                 
434                 /* Keep track of highest and lowest label number */
435                 if (ip->type == IP_DEFLAB) {
436                         low = MIN(ip->ip_lbllow);
437                         high = MAX(ip->ip_lblhigh);
438                 }
439
440                 /* Make sure each label is in a unique bblock */
441                 if (((ip->type == IP_DEFLAB) || (ip->type == IP_DEFNAM)) && 
442                     bb->first != ip) {
443                         bb = tmpalloc(sizeof(struct basicblock));
444                         bb->first = bb->last = ip;
ragge
1.11
445                         SLIST_INIT(&bb->children);
446                         SLIST_INIT(&bb->parents);
pj
1.8
447                         bb->dfnum = 0;
448                         bb->dfparent = 0;
449                         bb->semi = 0;
450                         bb->ancestor = 0;
451                         bb->idom = 0;
452                         bb->samedom = 0;
453                         bb->bucket = NULL;
454                         bb->df = NULL;
pj
1.10
455                         bb->dfchildren = NULL;
ragge
1.11
456                         DLIST_INSERT_BEFORE(&bblocksbbbbelem);
pj
1.8
457                         count++;
pj
1.4
458                         continue;
459                 }
460
461                 if (ip->type == IP_ASM)
462                         return 0;
463
464                 if (ip->type == IP_NODE) {
465                         switch(ip->ip_node->n_op) {
466                         case CBRANCH:
467                         case GOTO:
468                         case RETURN:
469                                 /* Jumps, last in bblock. */
470                                 leader = 1;
471                                 break;
472
473                         case NAME:
474                         case ICON:
475                         case FCON:
476                         case REG:
477                         case OREG:
478                         case MOVE:
479                         case PLUS:
480                         case MINUS:
481                         case DIV:
482                         case MOD:
483                         case MUL:
484                         case AND:
485                         case OR:
486                         case ER:
487                         case LS:
488                         case COMPL:
489                         case INCR:
490                         case DECR:
491                         case UMUL:
492                         case UMINUS:
493                         case EQ:
494                         case NE:
495                         case LE:
496                         case GE:
497                         case GT:
498                         case ULE:
499                         case ULT:
500                         case UGE:
501                         case UGT:
502                         case ASSIGN:
503                         case FORCE:
504                         case FUNARG:
pj
1.7
505                         case CALL:
506                         case UCALL:
507                         case FORTCALL:
508                         case UFORTCALL:
509                         case STCALL:
510                         case USTCALL:
pj
1.4
511                                 /* Not jumps, continue with bblock. */
512                                 break;
513
514                         default:
515                                 comperr("optim2:bblocks_build() %d",ip->ip_node->n_op ); 
516                                 break;
517                         }
518                 }
519
520                 bb->last = ip;
521         }
522 #ifdef PCC_DEBUG
pj
1.8
523         printf("Basic blocks in func: %d\n"count);
pj
1.10
524         printf("Label range in func: %d\n"high - low + 1);
pj
1.4
525 #endif
526
527         labinfo->low = low;
528         labinfo->size = high - low + 1;
529         labinfo->arr = tmpalloc(labinfo->size * sizeof(struct basicblock *));
pj
1.8
530         for (i = 0i <= labinfo->sizei++) {
pj
1.4
531                 labinfo->arr[i] = NULL;
532         }
pj
1.8
533         
534         bbinfo->size = count + 1;
535         bbinfo->arr = tmpalloc(bbinfo->size * sizeof(struct basicblock *));
536         for (i = 0i <= bbinfo->sizei++) {
537                 bbinfo->arr[i] = NULL;
538         }
pj
1.4
539
540         /* Build the label table */
ragge
1.11
541         DLIST_FOREACH(bb, &bblocksbbelem) {
pj
1.4
542                 if (bb->first->type == IP_DEFLAB) {
543                         labinfo->arr[bb->first->ip_lbl - low] = bb;
544                 }
545                 if (bb->first->type == IP_EPILOG) {
ragge
1.5
546                         labinfo->arr[bb->first->ip_lbl - low] = bb;
pj
1.4
547                 }
548         }
549
550         return 1;
551 }
552
553 /*
554  * Build the control flow graph.
555  */
556
557 void
558 cfg_build(struct labelinfo *labinfo)
559 {
560         /* Child and parent nodes */
561         struct cfgnode *cnode
562         struct cfgnode *pnode;
563         struct basicblock *bb;
564         
ragge
1.11
565         DLIST_FOREACH(bb, &bblocksbbelem) {
pj
1.4
566
567                 if (bb->first->type == IP_EPILOG) {
568                         break;
569                 }
570
571                 cnode = tmpalloc(sizeof(struct cfgnode));
572                 pnode = tmpalloc(sizeof(struct cfgnode));
573                 pnode->bblock = bb;
574
575                 if ((bb->last->type == IP_NODE) && 
576                     (bb->last->ip_node->n_op == GOTO)) {
577                         if (bb->last->ip_node->n_left->n_lval - labinfo->low > 
578                             labinfo->size) {
579                                 comperr("Label out of range: %d, base %d"
580                                         bb->last->ip_node->n_left->n_lval
581                                         labinfo->low);
582                         }
583                         cnode->bblock = labinfo->arr[bb->last->ip_node->n_left->n_lval - labinfo->low];
ragge
1.11
584                         SLIST_INSERT_LAST(&cnode->bblock->parentspnodecfgelem);
585                         SLIST_INSERT_LAST(&bb->childrencnodecfgelem);
pj
1.4
586                         continue;
587                 }
588                 if ((bb->last->type == IP_NODE) && 
589                     (bb->last->ip_node->n_op == CBRANCH)) {
590                         if (bb->last->ip_node->n_right->n_lval - labinfo->low > 
591                             labinfo->size
592                                 comperr("Label out of range: %d"
593                                         bb->last->ip_node->n_left->n_lval);
594                         
595                         cnode->bblock = labinfo->arr[bb->last->ip_node->n_right->n_lval - labinfo->low];
ragge
1.11
596                         SLIST_INSERT_LAST(&cnode->bblock->parentspnodecfgelem);
597                         SLIST_INSERT_LAST(&bb->childrencnodecfgelem);
pj
1.4
598                         cnode = tmpalloc(sizeof(struct cfgnode));
599                         pnode = tmpalloc(sizeof(struct cfgnode));
600                         pnode->bblock = bb;
601                 }
602
ragge
1.11
603                 cnode->bblock = DLIST_NEXT(bbbbelem);
604                 SLIST_INSERT_LAST(&cnode->bblock->parentspnodecfgelem);
605                 SLIST_INSERT_LAST(&bb->childrencnodecfgelem);
pj
1.4
606         }
607 }
pj
1.6
608
pj
1.8
609 void
610 cfg_dfs(struct basicblock *bbunsigned int parentstruct bblockinfo *bbinfo)
611 {
612         struct cfgnode *cnode;
613         
614         if (bb->dfnum != 0)
615                 return;
616
617         bb->dfnum = ++dfsnum;
618         bb->dfparent = parent;
619         bbinfo->arr[bb->dfnum] = bb;
ragge
1.11
620         SLIST_FOREACH(cnode, &bb->childrencfgelem) {
pj
1.8
621                 cfg_dfs(cnode->bblockbb->dfnumbbinfo);
622         }
623 }
624
ragge
1.11
625 static bittype *
626 setalloc(int nelem)
627 {
628         bittype *b;
629         int sz = (nelem+NUMBITS-1)/NUMBITS;
630
631         b = tmpalloc(sz * sizeof(bittype));
632         memset(b0sz * sizeof(bittype));
633         return b;
634 }
635
pj
1.8
636 /*
637  * Algorithm 19.9, pp 414 from Appel.
638  */
639
640 void
641 dominators(struct bblockinfo *bbinfo)
642 {
643         struct cfgnode *cnode;
644         struct basicblock *bb, *y, *v;
645         struct basicblock *s, *sprime, *p;
pj
1.10
646         int hi;
pj
1.8
647
ragge
1.11
648         DLIST_FOREACH(bb, &bblocksbbelem) {
649                 bb->bucket = setalloc(bbinfo->size);
650                 bb->df = setalloc(bbinfo->size);
651                 bb->dfchildren = setalloc(bbinfo->size);
pj
1.8
652         }
653
654         dfsnum = 0;
ragge
1.11
655         cfg_dfs(DLIST_NEXT(&bblocksbbelem), 0bbinfo);
pj
1.8
656
pj
1.10
657         for(h = bbinfo->size - 1h > 1h--) {
658                 bb = bbinfo->arr[h];
pj
1.8
659                 p = s = bbinfo->arr[bb->dfparent];
ragge
1.11
660                 SLIST_FOREACH(cnode, &bb->parentscfgelem) {
pj
1.8
661                         if (cnode->bblock->dfnum <= bb->dfnum
662                                 sprime = cnode->bblock;
pj
1.10
663                         else 
664                                 sprime = bbinfo->arr[ancestorwithlowestsemi
665                                               (cnode->bblockbbinfo)->semi];
pj
1.8
666                         if (sprime->dfnum < s->dfnum)
667                                 s = sprime;
668                 }
669                 bb->semi = s->dfnum;
pj
1.10
670                 BITSET(s->bucketbb->dfnum);
pj
1.8
671                 link(pbb);
672                 for (i = 1i < bbinfo->sizei++) {
pj
1.10
673                         if(TESTBIT(p->bucketi)) {
pj
1.8
674                                 v = bbinfo->arr[i];
pj
1.10
675                                 y = ancestorwithlowestsemi(vbbinfo);
676                                 if (y->semi == v->semi
pj
1.8
677                                         v->idom = p->dfnum;
678                                 else
679                                         v->samedom = y->dfnum;
680                         }
681                 }
682                 memset(p->bucket0, (bbinfo->size + 7)/8);
683         }
pj
1.10
684 #if 0
685         printf("Num\tSemi\tAncest\tidom\n");
pj
1.8
686         CIRCLEQ_FOREACH(bb, &bblocksbbelem) {
pj
1.10
687                 printf("%d\t%d\t%d\t%d\n"bb->dfnumbb->semibb->ancestorbb->idom);
688         }
689 #endif
690         for(h = 2h < bbinfo->sizeh++) {
691                 bb = bbinfo->arr[h];
692                 if (bb->samedom != 0) {
pj
1.8
693                         bb->idom = bbinfo->arr[bb->samedom]->idom;
pj
1.10
694                 }
695         }
ragge
1.11
696         DLIST_FOREACH(bb, &bblocksbbelem) {
pj
1.10
697                 if (bb->idom != 0 && bb->idom != bb->dfnum) {
698 #if 0
699
700                         printf("Setting child %d of %d\n"bb->dfnumbbinfo->arr[bb->idom]->dfnum);
701 #endif
702
703                         BITSET(bbinfo->arr[bb->idom]->dfchildrenbb->dfnum);
704                 }
pj
1.8
705         }
706 }
707
708
709 struct basicblock *
710 ancestorwithlowestsemi(struct basicblock *bblockstruct bblockinfo *bbinfo)
711 {
712         struct basicblock *u = bblock;
713         struct basicblock *v = bblock;
714
715         while (v->ancestor != 0) {
716                 if (bbinfo->arr[v->semi]->dfnum < 
pj
1.10
717                     bbinfo->arr[u->semi]->dfnum
pj
1.8
718                         u = v;
719                 v = bbinfo->arr[v->ancestor];
720         }
721         return u;
722 }
723
724 void
725 link(struct basicblock *parentstruct basicblock *child)
726 {
727         child->ancestor = parent->dfnum;
728 }
729
730 void
731 computeDF(struct basicblock *bblockstruct bblockinfo *bbinfo)
732 {
733         struct cfgnode *cnode;
pj
1.10
734         int hi;
pj
1.8
735         
ragge
1.11
736         SLIST_FOREACH(cnode, &bblock->childrencfgelem) {
pj
1.8
737                 if (cnode->bblock->idom != bblock->dfnum)
738                         BITSET(bblock->dfcnode->bblock->dfnum);
739         }
pj
1.10
740         for (h = 1h < bbinfo->sizeh++) {
741                 if (!TESTBIT(bblock->dfchildrenh))
742                         continue;
743                 computeDF(bbinfo->arr[h], bbinfo);
pj
1.8
744                 for (i = 1i < bbinfo->sizei++) {
pj
1.10
745                         if (TESTBIT(bbinfo->arr[h]->dfi) && 
746                             (bbinfo->arr[h] == bblock ||
747                              (bblock->idom != bbinfo->arr[h]->dfnum))) 
pj
1.8
748                             BITSET(bblock->dfi);
749                 }
750         }
751 }
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-07-10 20:18 +0200