Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.27
 
1.28
 
MAIN:ragge:20050629071241
 
optim2.c
_>5252 static struct interpass ipole;
 5353 struct interpass *storesave;
 5454 
<>55 -static struct rsv {
 56 -        struct rsv *next;
 57 -        int fpoff;
 58 -        TWORD type;
 59 -        int use;
 60 -} *rsv;
 61 -
6255 int bblocks_build(struct labelinfo *labinfo, struct bblockinfo *bbinfo);
 6356 void cfg_build(struct labelinfo *labinfo);
 6457 void cfg_dfs(struct basicblock *bb, unsigned int parent,
     
 !
7467 
 7568 static struct basicblock bblocks;
 7669 
<>77 -static void
 78 -addcand(TWORD type, int off, int avoid)
 79 -{
 80 -        struct rsv *w = rsv;
 81 -
 82 -        while (w != NULL) {
 83 -                if (w->type == type && w->fpoff == off) {
 84 -                        if (avoid)
 85 -                                w->use = -1;
 86 -                        else if (w->use > 0)
 87 -                                w->use++;
 88 -                        return;
 89 -                }
 90 -                w = w->next;
 91 -        }
 92 -        w = tmpalloc(sizeof(*w));
 93 -        w->type = type;
 94 -        w->fpoff = off;
 95 -        w->use = avoid ? -1 : 1;
 96 -        w->next = rsv;
 97 -        rsv = w;
 98 -}
 99 -
 100 -/*
 101 - * walk through the tree and count the number of (possible)
 102 - * temporary nodes.
 103 - */
 104 -static void
 105 -cntuse(NODE *p)
 106 -{
 107 -        NODE *l = p->n_left;
 108 -        NODE *r = p->n_right;
 109 -
 110 -        if (p->n_op == UMUL && l->n_op == REG && l->n_rval == FPREG) {
 111 -                /* found a candidate for register */
 112 -                addcand(p->n_type, 0, ISVOL(p->n_qual << TSHIFT));
 113 -        } else if (p->n_op == UMUL && l->n_op == PLUS &&
 114 -            l->n_right->n_op == ICON &&
 115 -             (l->n_left->n_op == REG && l->n_left->n_rval == FPREG)) {
 116 -                /* The same as above */
 117 -                addcand(p->n_type, l->n_right->n_lval,
 118 -                    ISVOL(p->n_qual << TSHIFT));
 119 -        } else if (p->n_op == PLUS && l->n_op == REG && l->n_rval == FPREG &&
 120 -            p->n_right->n_op == ICON) {
 121 -                /* Address taken of temporary, avoid register */
 122 -                addcand(DECREF(p->n_type), r->n_lval, 1);
 123 -        } else {
 124 -                if (optype(p->n_op) == BITYPE)
 125 -                        cntuse(r);
 126 -                if (optype(p->n_op) != LTYPE)
 127 -                        cntuse(l);
 128 -        }
 129 -}
 130 -
 131 -/*
 132 - * Insert a node into the register stack.
 133 - */
 134 -static void
 135 -insert(struct rsv *w, struct rsv **saved, int maxregs)
 136 -{
 137 -        int i, j, size;
 138 -
 139 -        size = szty(w->type);
 140 -
 141 -        /* Find reg move position */
 142 -        for (i = 0; i < maxregs; i++) {
 143 -                if (saved[i] == NULL)
 144 -                        continue;
 145 -                if (saved[i]->use > w->use)
 146 -                        break;
 147 -        }
 148 -        /* Move down other regs */
 149 -        for (j = size; j < i; j++)
 150 -                saved[j-size] = saved[j];
 151 -
 152 -        /* Insert new reg pointer */
 153 -        if (i-size >= 0) {
 154 -                saved[i-size] = w;
 155 -                for (j = i-size+1; j < i; j++)
 156 -                        saved[j] = NULL;
 157 -        }
 158 -}
 159 -
 160 -/* Help routine to rconvert() */
 161 -static int
 162 -matches(TWORD type, int off, struct rsv **rsv, int maxregs)
 163 -{
 164 -        int i;
 165 -
 166 -        for (i = 0; i < maxregs; i++)
 167 -                if (rsv[i] && rsv[i]->type == type && rsv[i]->fpoff == off)
 168 -                        return i;
 169 -        return -1;
 170 -}
 171 -
 172 -/* Help routine to rconvert() */
 173 -static void
 174 -modify(NODE *p, int reg)
 175 -{
 176 -        tfree(p->n_left);
 177 -        p->n_op = REG;
 178 -        p->n_rval = p->n_rall = reg + MINRVAR;
 179 -        p->n_lval = 0;
 180 -}
 181 -
 182 -/*
 183 - * walk through the tree and convert nodes to registers
 184 - */
 185 -static void
 186 -rconvert(NODE *p, struct rsv **rsv, int maxregs)
 187 -{
 188 -        NODE *l = p->n_left;
 189 -        NODE *r = p->n_right;
 190 -        int i;
 191 -
 192 -        if (p->n_op == UMUL && l->n_op == REG && l->n_rval == FPREG) {
 193 -                /* found a candidate for register */
 194 -                if ((i = matches(p->n_type, 0, rsv, maxregs)) >= 0)
 195 -                        modify(p, i);
 196 -        } else if (p->n_op == UMUL && l->n_op == PLUS &&
 197 -            l->n_right->n_op == ICON &&
 198 -             (l->n_left->n_op == REG && l->n_left->n_rval == FPREG)) {
 199 -                /* The same as above */
 200 -                if ((i = matches(p->n_type,
 201 -                    l->n_right->n_lval, rsv, maxregs)) >= 0)
 202 -                        modify(p, i);
 203 -#if 0
 204 -        } else if (p->n_op == PLUS && l->n_op == REG && l->n_rval == FPREG &&
 205 -            p->n_right->n_op == ICON) {
 206 -                /* Address taken of temporary, avoid register */
 207 -                addcand(DECREF(p->n_type), r->n_lval, 1);
 208 -#endif
 209 -        } else {
 210 -                if (optype(p->n_op) == BITYPE)
 211 -                        rconvert(r, rsv, maxregs);
 212 -                if (optype(p->n_op) != LTYPE)
 213 -                        rconvert(l, rsv, maxregs);
 214 -        }
 215 -}
 216 -
 217 -/*
 218 - * Assign non-temporary registers to variables.
 219 - * Cannot do it if:
 220 - * - address is taken of the temporary
 221 - * - variable is declared "volatile".
 222 - */
 223 -int asgregs(void);
 224 -int
 225 -asgregs(void)
 226 -{
 227 -        struct interpass *ip;
 228 -        struct rsv *w, **saved;
 229 -        int i, maxregs = MAXRVAR - MINRVAR + 1;
 230 -
 231 -        if (maxregs == 0)
 232 -                return MAXRVAR; /* No register usage */
 233 -        rsv = NULL;
 234 -
 235 -        /* Loop over the function to do a usage count */
 236 -        DLIST_FOREACH(ip, &ipole, qelem) {
 237 -                if (ip->type != IP_NODE)
 238 -                        continue;
 239 -                cntuse(ip->ip_node);
 240 -        }
 241 -        /* Check which nodes that shall be converted to registers */
 242 -        saved = tmpalloc(sizeof(struct rsv *) * maxregs);
 243 -        memset(saved, 0, sizeof(struct rsv *) * maxregs);
 244 -        w = rsv;
 245 -        for (w = rsv; w; w = w->next) {
 246 -                if (w->use < 0)
 247 -                        continue; /* Not allowed to be in register */
 248 -
 249 -                /* XXX check here if type is allowed to be in register */
 250 -
 251 -                insert(w, saved, maxregs);
 252 -        }
 253 -
 254 -        /* Convert found nodes to registers */
 255 -        DLIST_FOREACH(ip, &ipole, qelem) {
 256 -                if (ip->type != IP_NODE)
 257 -                        continue;
 258 -                rconvert(ip->ip_node, saved, maxregs);
 259 -        }
 260 -        for (i = 0; i < maxregs; i++)
 261 -                if (saved[i] != NULL)
 262 -                        break;
 263 -        return MINRVAR+i-1;
 264 -}
 265 -
26670 void
 26771 saveip(struct interpass *ip)
 26872 {
     
 !
28993         epp = (struct interpass_prolog *)ip;
 29094         saving = -1;
 29195 
<>292 -ipp = (struct interpass_prolog *)DLIST_NEXT(&ipole, qelem);
 293 -printf("inlab %d utlab %d\n", ipp->ip_lblnum, epp->ip_lblnum);
29496         if (xdeljumps)
 29597                 deljumps();     /* Delete redundant jumps and dead code */
<> 98+
29699         if (xssaflag) {
 297100                 DLIST_INIT(&bblocks, bbelem);
 298101                 if (bblocks_build(&labinfo, &bbinfo)) {
     
 !
309112                 }
 310113  
 311114         }
<>312 -#if 0
 313 -        regs = asgregs();       /* Assign non-temporary registers */
 314 -#endif
315115 
 316116 #ifdef PCC_DEBUG
 317117         if (epp->ipp_regs != MAXRVAR)
     
 !
396196                         geninsn(ip->ip_node, FOREFF);
 397197                         nsucomp(ip->ip_node);
 398198                 }
<>399 -        } while (ngenregs(DLIST_NEXT(&ipole, qelem),
 400 -            DLIST_PREV(&ipole, qelem)));
  199+        } while (ngenregs(&ipole));
401200 }
 402201 
 403202         DLIST_FOREACH(ip, &ipole, qelem) {
     
 !
414213 deljumps()
 415214 {
 416215         struct interpass_prolog *ipp, *epp;
<>417 -        struct interpass *ip, *n;
  216+        struct interpass *ip, *n, *ip2;
418217         int gotone,low, high;
<>419 -        int *lblary, sz;
  218+        int *lblary, sz, o, i;
420219 
 421220         ipp = (struct interpass_prolog *)DLIST_NEXT(&ipole, qelem);
 422221         epp = (struct interpass_prolog *)DLIST_PREV(&ipole, qelem);
     
 !
427226 #ifdef notyet
 428227         mark = tmpmark(); /* temporary used memory */
 429228 #endif
<>430 -#define FOUND   1
 431 -#define REFD    2
  229+
432230         sz = (high-low) * sizeof(int);
 433231         lblary = tmpalloc(sz);
<>434 -        memset(lblary, 0, sz);
435232 
 436233 again:  gotone = 0;
<> 234+        memset(lblary, 0, sz);
437235 
<>438 -printip(&ipole);
 439 -
 440 -        /* delete all labels with a following label */
  236+        /* refcount and coalesce  all labels */
441237         DLIST_FOREACH(ip, &ipole, qelem) {
 442238                 if (ip->type == IP_DEFLAB) {
 443239                         n = DLIST_NEXT(ip, qelem);
<>444 -                        while (n->type == IP_DEFLAB) {
 445 -                                lblary[n->ip_lbl-low] = -ip->ip_lbl;
 446 -                                DLIST_REMOVE(n, qelem);
 447 -                                n = DLIST_NEXT(ip, qelem);
 448 -                        }
 449 -                        if (n->type == IP_STKOFF) {
 450 -                                n = DLIST_NEXT(n, qelem);
 451 -                                while (n->type == IP_DEFLAB) {
  240+                        while (n->type == IP_DEFLAB || n->type == IP_STKOFF) {
  241+                                if (n->type == IP_DEFLAB &&
  242+                                    lblary[n->ip_lbl-low] >= 0)
452243                                         lblary[n->ip_lbl-low] = -ip->ip_lbl;
<>453 -                                        DLIST_REMOVE(n, qelem);
 454 -                                        n = DLIST_NEXT(n, qelem);
 455 -                                }
  244+                                n = DLIST_NEXT(n, qelem);
456245                         }
 457246                 }
<> 247+                if (ip->type != IP_NODE)
  248+                        continue;
  249+                o = ip->ip_node->n_op;
  250+                if (o == GOTO)
  251+                        i = ip->ip_node->n_left->n_lval;
  252+                else if (o == CBRANCH)
  253+                        i = ip->ip_node->n_right->n_lval;
  254+                else
  255+                        continue;
  256+                lblary[i-low] |= 1;
458257         }
 459258 
<>460 -        if (gotone)
 461 -                goto again;
 462 -
 463 -printf("2\n");
 464 -printip(&ipole);
 465 -
 466 -#if 0
 467 - && ip->type != IP_STKOFF)
 468 -                        continue;
 469 -
 470 -                n = DLIST_NEXT(ip, qelem);
 471 -                while (n->type == IP_DEFLAB || n->type == IP_STKOFF) {
 472 -                        
 473 -
 474 -
 475 -
 476 -
 477 -
 478 -
  259+        /* delete coalesced/unused labels and rename gotos */
479260         DLIST_FOREACH(ip, &ipole, qelem) {
<>480 -                if (ip->type == IP_DEFLAB) {
 481 -                        lblary[ip->ip_lbl-low] |= FOUND;
 482 -printf("IP_DEFLAB: %d\n", ip->ip_lbl);
 483 -                        ip2 = DLIST_NEXT(ip, qelem);
 484 -printf("ip2 %d\n", ip2->type);
 485 -                        while (ip2->type == IP_DEFLAB ||
 486 -                            ip2->type == IP_STKOFF) {
 487 -                                if (ip2->type == IP_DEFLAB) {
 488 -                                        lblary[ip2->ip_lbl-low] = -ip->ip_lbl;
 489 -printf("coal %d\n", ip2->ip_lbl);
 490 -                                        DLIST_REMOVE(ip2, qelem);
 491 -                                        gotone = 1;
 492 -                                } else
 493 -                                        ip = ip2;
 494 -                                ip2 = DLIST_NEXT(ip, qelem);
  261+                n = DLIST_NEXT(ip, qelem);
  262+                if (n->type == IP_DEFLAB) {
  263+                        if (lblary[n->ip_lbl-low] <= 0) {
  264+                                DLIST_REMOVE(n, qelem);
  265+                                gotone = 1;
495266                         }
<>496 -                        ip = DLIST_PREV(ip, qelem);
497267                         continue;
 498268                 }
<>499 -                n = DLIST_NEXT(ip, qelem);
500269                 if (n->type != IP_NODE)
 501270                         continue;
 502271                 o = n->ip_node->n_op;
     
 !
511280                                 n->ip_node->n_left->n_lval = -lblary[i-low];
 512281                         else
 513282                                 n->ip_node->n_right->n_lval = -lblary[i-low];
<>514 -                        gotone = 1;
515283                 }
<>516 -                ip2 = DLIST_NEXT(n, qelem);
 517 -                if (ip2->type == IP_DEFLAB && ip2->ip_lbl == i) {
 518 -                        tfree(n->ip_node);
 519 -                        DLIST_REMOVE(n, qelem);
 520 -                        gotone = 1;
 521 -                }
522284         }
<>523 -        if (gotone)
 524 -                goto again;
525285 
<>526 -#endif
 527 -
 528 -#ifdef notyet
 529 -        tmpfree(mark);
 530 -#endif
 531 -
 532 -#if 0
  286+        /* Delete gotos to the next statement */
533287         DLIST_FOREACH(ip, &ipole, qelem) {
<>534 -                if (ip->type == IP_DEFLAB) {
 535 -                        lblary[ip->ip_lbl-low] |= FOUND;
 536 -                        ip2 = DLIST_NEXT(ip, qelem);
 537 -                        while (ip2->type == IP_DEFLAB) {
 538 -                                lblary[ip2->ip_lbl-low] = -ip->ip_lbl;
 539 -                                DLIST_REMOVE(ip2, qelem);
 540 -                                ip2 = DLIST_NEXT(ip, qelem);
 541 -                        }
 542 -                }
 543 -                if (ip->type != IP_NODE)
  288+                n = DLIST_NEXT(ip, qelem);
  289+                if (n->type != IP_NODE)
544290                         continue;
<> 291+                o = n->ip_node->n_op;
545292                 if (o == GOTO)
<>546 -                        i = ip->ip_node->n_left->n_lval;
  293+                        i = n->ip_node->n_left->n_lval;
547294                 else if (o == CBRANCH)
<>548 -                        i = ip->ip_node->n_right->n_lval;
  295+                        i = n->ip_node->n_right->n_lval;
549296                 else
 550297                         continue;
<>551 -                if (lblary[i-low] < 0) {
 552 -                        /* coalesced */
 553 -                        
 554 -                lblary[i-low] |= REFD;
 555 -        }
 556 -
 557 -
 558 -
 559 -
 560 -again:  gotone = 0;
 561 -
 562 -
 563 -
 564 -
 565 -
 566 -
 567 -
 568 -        DLIST_FOREACH(ip, &ipole, qelem) {
 569 -                if (ip->type == IP_EPILOG)
 570 -                        return;
 571 -                if (ip->type != IP_NODE)
  298+                ip2 = DLIST_NEXT(n, qelem);
  299+                if (ip2->type != IP_DEFLAB)
572300                         continue;
<>573 -                n = DLIST_NEXT(ip, qelem);
 574 -                /* Check for nodes without side effects */
 575 -                if (ip->ip_node->n_op != GOTO)
 576 -                        continue;
 577 -                switch (n->type) {
 578 -                case IP_NODE:
  301+                if (ip2->ip_lbl == i) {
579302                         tfree(n->ip_node);
 580303                         DLIST_REMOVE(n, qelem);
<>581 -                        break;
 582 -                case IP_DEFLAB:
 583 -                        if (ip->ip_node->n_left->n_lval != n->ip_lbl)
 584 -                                continue;
 585 -                        tfree(ip->ip_node);
 586 -                        *ip = *n;
 587 -                        break;
 588 -                default:
 589 -                        continue;
  304+                        gotone = 1;
590305                 }
<>591 -                gotone = 1;
592306         }
<> 307+
593308         if (gotone)
 594309                 goto again;
<> 310+
  311+#ifdef notyet
  312+        tmpfree(mark);
<_595313 #endif
 596314 }
 597315 
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-22 16:16 +0200