Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.1
 
1.2
 
MAIN:ragge:20040513193347
 
optim2.c
_>100100 }
 101101 
 102102 /*
<> 103+ * Insert a node into the register stack.
  104+ */
  105+static void
  106+insert(struct rsv *w, struct rsv **saved, int maxregs)
  107+{
  108+        int i, j, size;
  109+
  110+        size = szty(w->type);
  111+
  112+        /* Find reg move position */
  113+        for (i = 0; i < maxregs; i++) {
  114+                if (saved[i] == NULL)
  115+                        continue;
  116+                if (saved[i]->use > w->use)
  117+                        break;
  118+        }
  119+        /* Move down other regs */
  120+        for (j = size; j < i; j++)
  121+                saved[j-size] = saved[j];
  122+
  123+        /* Insert new reg pointer */
  124+        if (i-size >= 0) {
  125+                saved[i-size] = w;
  126+                for (j = i-size+1; j < i; j++)
  127+                        saved[j] = NULL;
  128+        }
  129+}
  130+
  131+/* Help routine to rconvert() */
  132+static int
  133+matches(TWORD type, int off, struct rsv **rsv, int maxregs)
  134+{
  135+        int i;
  136+
  137+        for (i = 0; i < maxregs; i++)
  138+                if (rsv[i] && rsv[i]->type == type && rsv[i]->fpoff == off)
  139+                        return i;
  140+        return -1;
  141+}
  142+
  143+/* Help routine to rconvert() */
  144+static void
  145+modify(NODE *p, int reg)
  146+{
  147+        tfree(p->n_left);
  148+        p->n_op = REG;
  149+        p->n_rval = p->n_rall = reg + MINRVAR;
  150+        p->n_lval = 0;
  151+}
  152+
  153+/*
  154+ * walk through the tree and convert nodes to registers
  155+ */
  156+static void
  157+rconvert(NODE *p, struct rsv **rsv, int maxregs)
  158+{
  159+        NODE *l = p->n_left;
  160+        NODE *r = p->n_right;
  161+        int i;
  162+
  163+        if (p->n_op == UMUL && l->n_op == REG && l->n_rval == FPREG) {
  164+                /* found a candidate for register */
  165+                if ((i = matches(p->n_type, 0, rsv, maxregs)) >= 0)
  166+                        modify(p, i);
  167+        } else if (p->n_op == UMUL && l->n_op == PLUS &&
  168+            l->n_right->n_op == ICON &&
  169+             (l->n_left->n_op == REG && l->n_left->n_rval == FPREG)) {
  170+                /* The same as above */
  171+                if ((i = matches(p->n_type,
  172+                    l->n_right->n_lval, rsv, maxregs)) >= 0)
  173+                        modify(p, i);
  174+#if 0
  175+        } else if (p->n_op == PLUS && l->n_op == REG && l->n_rval == FPREG &&
  176+            p->n_right->n_op == ICON) {
  177+                /* Address taken of temporary, avoid register */
  178+                addcand(DECREF(p->n_type), r->n_lval, 1);
  179+#endif
  180+        } else {
  181+                if (optype(p->n_op) == BITYPE)
  182+                        rconvert(r, rsv, maxregs);
  183+                if (optype(p->n_op) != LTYPE)
  184+                        rconvert(l, rsv, maxregs);
  185+        }
  186+}
  187+
  188+/*
103189  * Assign non-temporary registers to variables.
 104190  * Cannot do it if:
 105191  * - address is taken of the temporary
 106192  * - variable is declared "volatile".
 107193  */
<>108 -static void
  194+static int
109195 asgregs(void)
 110196 {
 111197         struct interpass *ip;
<>112 -        struct rsv *w;
 113 -        
  198+        struct rsv *w, **saved;
  199+        int i, maxregs = MAXRVAR - MINRVAR + 1;
114200 
<> 201+        if (maxregs == 0)
  202+                return MAXRVAR; /* No register usage */
115203         rsv = NULL;
 116204 
 117205         /* Loop over the function to do a usage count */
     
 !
120208                         continue;
 121209                 cntuse(ip->ip_node);
 122210         }
<>123 -
124211         /* Check which nodes that shall be converted to registers */
<> 212+        saved = tmpalloc(sizeof(struct rsv *) * maxregs);
  213+        memset(saved, 0, sizeof(struct rsv *) * maxregs);
125214         w = rsv;
 126215         for (w = rsv; w; w = w->next) {
 127216                 if (w->use < 0)
<>128 -                        continue;
 129 -                printf("type %x off %d use %d\n", w->type, w->fpoff, w->use);
  217+                        continue; /* Not allowed to be in register */
  218+
  219+                /* XXX check here if type is allowed to be in register */
  220+
  221+                insert(w, saved, maxregs);
130222         }
 131223 
 132224         /* Convert found nodes to registers */
<> 225+        SIMPLEQ_FOREACH(ip, &ipole, sqelem) {
  226+                if (ip->type != IP_NODE)
  227+                        continue;
  228+                rconvert(ip->ip_node, saved, maxregs);
  229+        }
  230+        for (i = 0; i < maxregs; i++)
  231+                if (saved[i] != NULL)
  232+                        break;
  233+        return MINRVAR+i-1;
133234 }
 134235 
 135236 void
 136237 saveip(struct interpass *ip)
 137238 {
 138239         struct interpass *prol;
<> 240+        int regs;
139241 
 140242         SIMPLEQ_INSERT_TAIL(&ipole, ip, sqelem);
 141243 
     
 !
144246         saving = -1;
 145247 
 146248         deljumps();     /* Delete redundant jumps and dead code */
<>147 -        asgregs();      /* Assign non-temporary registers */
  249+        regs = asgregs();       /* Assign non-temporary registers */
148250 
<> 251+#ifdef PCC_DEBUG
  252+        if (ip->ip_regs != MAXRVAR)
  253+                comperr("register error");
  254+#endif
  255+
149256         prol = SIMPLEQ_FIRST(&ipole);
 150257         prol->ip_auto = ip->ip_auto;
<>151 -        prol->ip_regs = ip->ip_regs;
  258+        prol->ip_regs = ip->ip_regs = regs;
<_152259 
 153260 #ifdef MYOPTIM
 154261         myoptim(prol);
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-10-31 16:04 +0100