Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.76
 
1.77
 
MAIN:ragge:20100521160828
 
optim2.c
_>7272 void renamevar(struct p2env *p2e,struct basicblock *bblock);
 7373 void removephi(struct p2env *p2e);
 7474 void remunreach(struct p2env *);
<> 75+static void liveanal(struct p2env *p2e);
7576 
 7677 /* create "proper" basic blocks, add labels where needed (so bblocks have labels) */
 7778 /* run before bb generate */
     
 !
132133 #endif
 133134         }
 134135         if (xssaflag) {
<> 136+                BDEBUG(("Calling liveanal\n"));
  137+                liveanal(p2e);
135138                 BDEBUG(("Calling dominators\n"));
 136139                 dominators(p2e);
 137140                 BDEBUG(("Calling computeDF\n"));
     
 !
11431146                                             printf("Phi in %d(%d) (%p) for %d\n",
 11441147                                             y->dfnum,y->bbnum,y,i+defsites.low);
 11451148 
<> 1149+                                        /* If no live in, no phi node needed */
  1150+                                        if (!TESTBIT(y->in,
  1151+                                            (i+defsites.low-p2e->ipp->ip_tmpnum+MAXREGS))) {
  1152+                                        if (b2debug)
  1153+                                        printf("tmp %d bb %d unused, no phi\n",
  1154+                                            i+defsites.low, y->bbnum);
  1155+                                                /* No live in */
  1156+                                                BITSET(p2e->bbinfo.arr[j]->Aphi, i);
  1157+                                                continue;
  1158+                                        }
  1159+
11461160                                         phi = tmpcalloc(sizeof(struct phiinfo));
 11471161                            
 11481162                                         phi->tmpregno=i+defsites.low;
     
 !
11641178                                         pv->next = defsites.arr[i];
 11651179                                         defsites.arr[i] = pv;
 11661180                                 }
<>1167 -                                        
 1168 -
11691181                         }
 11701182                 }
 11711183         }
     
 !
19361948 }
 19371949 #endif
 19381950 
<_ 1951+#define BITALLOC(ptr,all,sz) { \
  1952+        int sz__s = BIT2BYTE(sz); ptr = all(sz__s); memset(ptr, 0, sz__s); }
  1953+#define VALIDREG(p)     (p->n_op == REG && TESTBIT(validregs, regno(p)))
  1954+#define XCHECK(x) if (x < 0 || x >= xbits) printf("x out of range %d\n", x)
  1955+#define RUP(x) (((x)+NUMBITS-1)/NUMBITS)
  1956+#define SETCOPY(t,f,i,n) for (i = 0; i < RUP(n); i++) t[i] = f[i]
  1957+#define SETSET(t,f,i,n) for (i = 0; i < RUP(n); i++) t[i] |= f[i]
  1958+#define SETCLEAR(t,f,i,n) for (i = 0; i < RUP(n); i++) t[i] &= ~f[i]
  1959+#define SETCMP(v,t,f,i,n) for (i = 0; i < RUP(n); i++) \
  1960+        if (t[i] != f[i]) v = 1
  1961+
  1962+static int xxx, xbits;
  1963+/*
  1964+ * Set/clear long term liveness for regs and temps.
  1965+ */
  1966+static void
  1967+unionize(NODE *p, struct basicblock *bb, int suboff)
  1968+{
  1969+        int o, ty;
  1970+
  1971+        if ((o = p->n_op) == TEMP || VALIDREG(p)) {
  1972+                int b = regno(p);
  1973+                if (o == TEMP)
  1974+                        b = b - suboff + MAXREGS;
  1975+XCHECK(b);
  1976+                BITSET(bb->gen, b);
  1977+        }
  1978+        if (asgop(o)) {
  1979+                if (p->n_left->n_op == TEMP || VALIDREG(p)) {
  1980+                        int b = regno(p->n_left);
  1981+                        if (p->n_left->n_op == TEMP)
  1982+                                b = b - suboff + MAXREGS;
  1983+XCHECK(b);
  1984+                        BITCLEAR(bb->gen, b);
  1985+                        BITSET(bb->killed, b);
  1986+                        unionize(p->n_right, bb, suboff);
  1987+                        return;
  1988+                }
  1989+        }
  1990+        ty = optype(o);
  1991+        if (ty != LTYPE)
  1992+                unionize(p->n_left, bb, suboff);
  1993+        if (ty == BITYPE)
  1994+                unionize(p->n_right, bb, suboff);
  1995+}
  1996+
  1997+/*
  1998+ * Found an extended assembler node, so growel out gen/killed nodes.
  1999+ */
  2000+static void
  2001+xasmionize(NODE *p, void *arg)
  2002+{
  2003+        struct basicblock *bb = arg;
  2004+        int cw, b;
  2005+
  2006+        if (p->n_op == ICON && p->n_type == STRTY)
  2007+                return; /* dummy end marker */
  2008+
  2009+        cw = xasmcode(p->n_name);
  2010+        if (XASMVAL(cw) == 'n' || XASMVAL(cw) == 'm')
  2011+                return; /* no flow analysis */
  2012+        p = p->n_left;
  2013+ 
  2014+        if (XASMVAL(cw) == 'g' && p->n_op != TEMP && p->n_op != REG)
  2015+                return; /* no flow analysis */
  2016+
  2017+        b = regno(p);
  2018+#if 0
  2019+        if (XASMVAL(cw) == 'r' && p->n_op == TEMP)
  2020+                addnotspill(b);
  2021+#endif
  2022+#define MKTOFF(r)       ((r) - xxx)
  2023+        if (XASMISOUT(cw)) {
  2024+                if (p->n_op == TEMP) {
  2025+                        BITCLEAR(bb->gen, MKTOFF(b));
  2026+                        BITSET(bb->killed, MKTOFF(b));
  2027+                } else if (p->n_op == REG) {
  2028+                        BITCLEAR(bb->gen, b);
  2029+                        BITSET(bb->killed, b);  
  2030+                } else
  2031+                        uerror("bad xasm node type %d", p->n_op);
  2032+        }
  2033+        if (XASMISINP(cw)) {
  2034+                if (p->n_op == TEMP) {
  2035+                        BITSET(bb->gen, MKTOFF(b));
  2036+                } else if (p->n_op == REG) {
  2037+                        BITSET(bb->gen, b);
  2038+                } else if (optype(p->n_op) != LTYPE) {
  2039+                        if (XASMVAL(cw) == 'r')
  2040+                                uerror("couldn't find available register");
  2041+                        else
  2042+                                uerror("bad xasm node type2");
  2043+                }
  2044+        }
  2045+}
  2046+
  2047+/*
  2048+ * Do variable liveness analysis.  Only analyze the long-lived
  2049+ * variables, and save the live-on-exit temporaries in a bit-field
  2050+ * at the end of each basic block. This bit-field is later used
  2051+ * when doing short-range liveness analysis in Build().
  2052+ */
  2053+void
  2054+liveanal(struct p2env *p2e)
  2055+{
  2056+        struct basicblock *bb;
  2057+        struct interpass *ip;
  2058+        struct cfgnode *cn;
  2059+        bittype *saved;
  2060+        int i, mintemp, again;
  2061+
  2062+        xbits = p2e->epp->ip_tmpnum - p2e->ipp->ip_tmpnum + MAXREGS;
  2063+        mintemp = p2e->ipp->ip_tmpnum;
  2064+
  2065+        /* Just fetch space for the temporaries from heap */
  2066+        DLIST_FOREACH(bb, &p2e->bblocks, bbelem) {
  2067+                BITALLOC(bb->gen,tmpalloc,xbits);
  2068+                BITALLOC(bb->killed,tmpalloc,xbits);
  2069+                BITALLOC(bb->in,tmpalloc,xbits);
  2070+                BITALLOC(bb->out,tmpalloc,xbits);
  2071+        }
  2072+        BITALLOC(saved,tmpalloc,xbits);
  2073+
  2074+        xxx = mintemp;
  2075+        /*
  2076+         * generate the gen-killed sets for all basic blocks.
  2077+         */
  2078+        DLIST_FOREACH(bb, &p2e->bblocks, bbelem) {
  2079+                for (ip = bb->last; ; ip = DLIST_PREV(ip, qelem)) {
  2080+                        /* gen/killed is 'p', this node is 'n' */
  2081+                        if (ip->type == IP_NODE) {
  2082+                                if (ip->ip_node->n_op == XASM)
  2083+                                        flist(ip->ip_node->n_left,
  2084+                                            xasmionize, bb);
  2085+                                else
  2086+                                        unionize(ip->ip_node, bb, mintemp);
  2087+                        }
  2088+                        if (ip == bb->first)
  2089+                                break;
  2090+                }
  2091+                memcpy(bb->in, bb->gen, BIT2BYTE(xbits));
  2092+#ifdef PCC_DEBUG
  2093+#define PRTRG(x) printf("%d ", i < MAXREGS ? i : i + p2e->ipp->ip_tmpnum-MAXREGS)
  2094+                if (b2debug > 1) {
  2095+                        printf("basic block %d\ngen: ", bb->bbnum);
  2096+                        for (i = 0; i < xbits; i++)
  2097+                                if (TESTBIT(bb->gen, i))
  2098+                                        PRTRG(i);
  2099+                        printf("\nkilled: ");
  2100+                        for (i = 0; i < xbits; i++)
  2101+                                if (TESTBIT(bb->killed, i))
  2102+                                        PRTRG(i);
  2103+                        printf("\n");
  2104+                }
  2105+#endif
  2106+        }
  2107+        /* do liveness analysis on basic block level */
  2108+        do {
  2109+                int j;
  2110+
  2111+                again = 0;
  2112+                /* XXX - loop should be in reversed execution-order */
  2113+                DLIST_FOREACH_REVERSE(bb, &p2e->bblocks, bbelem) {
  2114+                        SETCOPY(saved, bb->out, j, xbits);
  2115+                        SLIST_FOREACH(cn, &bb->children, cfgelem) {
  2116+                                SETSET(bb->out, cn->bblock->in, j, xbits);
  2117+                        }
  2118+                        SETCMP(again, saved, bb->out, j, xbits);
  2119+                        SETCOPY(saved, bb->in, j, xbits);
  2120+                        SETCOPY(bb->in, bb->out, j, xbits);
  2121+                        SETCLEAR(bb->in, bb->killed, j, xbits);
  2122+                        SETSET(bb->in, bb->gen, j, xbits);
  2123+                        SETCMP(again, saved, bb->in, j, xbits);
  2124+                }
  2125+        } while (again);
  2126+
  2127+#ifdef PCC_DEBUG
  2128+        DLIST_FOREACH(bb, &p2e->bblocks, bbelem) {
  2129+                if (b2debug) {
  2130+                        printf("all basic block %d\nin: ", bb->bbnum);
  2131+                        for (i = 0; i < xbits; i++)
  2132+                                if (TESTBIT(bb->in, i))
  2133+                                        PRTRG(i);
  2134+                        printf("\nout: ");
  2135+                        for (i = 0; i < xbits; i++)
  2136+                                if (TESTBIT(bb->out, i))
  2137+                                        PRTRG(i);
  2138+                        printf("\n");
  2139+                }
  2140+        }
  2141+#endif
  2142+}
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-23 02:18 +0200