Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:pj:20050206114953

Diff

Diff from 1.9 to:

Annotations

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

Annotated File View

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