summaryrefslogtreecommitdiff
path: root/usr.bin/pcc/mip
diff options
context:
space:
mode:
authorAnders Magnusson <ragge@cvs.openbsd.org>2008-01-12 17:17:29 +0000
committerAnders Magnusson <ragge@cvs.openbsd.org>2008-01-12 17:17:29 +0000
commit5435eef5c2fd45c7b516422cd37370bbb1a13f68 (patch)
tree4f9161c463ed8b82811f9a483d4a054008ef17e9 /usr.bin/pcc/mip
parent71275cb1615732fdce1815a3d07d52852082e5ef (diff)
Update from master repo:
> Convert TEMPs to use rval for numbers.
Diffstat (limited to 'usr.bin/pcc/mip')
-rw-r--r--usr.bin/pcc/mip/manifest.h5
-rw-r--r--usr.bin/pcc/mip/match.c10
-rw-r--r--usr.bin/pcc/mip/mkext.c4
-rw-r--r--usr.bin/pcc/mip/optim2.c30
-rw-r--r--usr.bin/pcc/mip/protos.h6
-rw-r--r--usr.bin/pcc/mip/reader.c9
-rw-r--r--usr.bin/pcc/mip/regs.c50
7 files changed, 56 insertions, 58 deletions
diff --git a/usr.bin/pcc/mip/manifest.h b/usr.bin/pcc/mip/manifest.h
index c154c4e4d64..b569f844366 100644
--- a/usr.bin/pcc/mip/manifest.h
+++ b/usr.bin/pcc/mip/manifest.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: manifest.h,v 1.8 2007/12/09 18:37:48 ragge Exp $ */
+/* $OpenBSD: manifest.h,v 1.9 2008/01/12 17:17:28 ragge Exp $ */
/*
* Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
*
@@ -115,6 +115,7 @@
#define UNSIGNABLE(x) (((x)<=ULONGLONG&&(x)>=CHAR) && !ISUNSIGNED(x))
#define ENUNSIGN(x) ((x)|1)
#define DEUNSIGN(x) ((x)&~1)
+#define ISINTEGER(x) (((x) >= CHAR && (x) <= ULONGLONG) || (x) == BOOL)
#define ISPTR(x) (((x)&TMASK)==PTR)
#define ISFTN(x) (((x)&TMASK)==FTN) /* is x a function type? */
#define ISARY(x) (((x)&TMASK)==ARY) /* is x an array type? */
@@ -168,6 +169,8 @@
#define STRNG 3 /* (ro) string segment */
+#define regno(p) ((p)->n_rval) /* register number */
+
/*
*
*/
diff --git a/usr.bin/pcc/mip/match.c b/usr.bin/pcc/mip/match.c
index fe7d0603a77..e03b06ddb28 100644
--- a/usr.bin/pcc/mip/match.c
+++ b/usr.bin/pcc/mip/match.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: match.c,v 1.7 2007/12/22 22:56:31 stefan Exp $ */
+/* $OpenBSD: match.c,v 1.8 2008/01/12 17:17:28 ragge Exp $ */
/*
* Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
* All rights reserved.
@@ -147,6 +147,7 @@ tshape(NODE *p, int shape)
break;
case ICON:
+ case FCON:
if (shape & SCON)
return SRDIR;
break;
@@ -276,8 +277,10 @@ expand(NODE *p, int cookie, char *cp)
case 'F': /* this line deleted if FOREFF is active */
if (cookie & FOREFF) {
- while (*++cp != '\n' && *(cp - 1) != '\0')
- continue;
+ while (*cp && *cp != '\n')
+ cp++;
+ if (*cp == 0)
+ return;
}
continue;
@@ -894,7 +897,6 @@ findleaf(NODE *p, int cookie)
F2DEBUG(("findleaf: ixp %d\n", ixp[i]));
if (!acceptable(q)) /* target-dependent filter */
continue;
-
if ((q->visit & cookie) == 0)
continue; /* wrong registers */
diff --git a/usr.bin/pcc/mip/mkext.c b/usr.bin/pcc/mip/mkext.c
index 2f545e34e36..609aae81cb6 100644
--- a/usr.bin/pcc/mip/mkext.c
+++ b/usr.bin/pcc/mip/mkext.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mkext.c,v 1.6 2007/10/27 13:55:00 ragge Exp $ */
+/* $OpenBSD: mkext.c,v 1.7 2008/01/12 17:17:28 ragge Exp $ */
/*
* Generate defines for the needed hardops.
*/
@@ -305,7 +305,7 @@ mktables()
int opmtemp;
if ((opmtemp=mamask[op->op - OPSIMP])&SPFLG) {
if (i==NAME || i==ICON || i==TEMP ||
- i==OREG || i == REG) {
+ i==OREG || i == REG || i == FCON) {
P((fc, "%td, ", op - table));
curalen++;
}
diff --git a/usr.bin/pcc/mip/optim2.c b/usr.bin/pcc/mip/optim2.c
index 341a7e71602..393cbbd2302 100644
--- a/usr.bin/pcc/mip/optim2.c
+++ b/usr.bin/pcc/mip/optim2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: optim2.c,v 1.6 2007/12/09 18:41:21 ragge Exp $ */
+/* $OpenBSD: optim2.c,v 1.7 2008/01/12 17:17:28 ragge Exp $ */
/*
* Copyright (c) 2004 Anders Magnusson (ragge@ludd.luth.se).
* All rights reserved.
@@ -41,6 +41,8 @@
#define BDEBUG(x) if (b2debug) printf x
+#define mktemp(n, t) mklnode(TEMP, 0, n, t)
+
static int dfsnum;
void saveip(struct interpass *ip);
@@ -106,7 +108,7 @@ setargs(int tval, struct addrof *w)
#endif
if (p->n_right->n_op != OREG)
continue; /* arg in register */
- if (tval != p->n_left->n_lval)
+ if (tval != regno(p->n_left))
continue; /* wrong assign */
w->oregoff = p->n_right->n_lval;
tfree(p);
@@ -123,14 +125,16 @@ static void
findaddrof(NODE *p)
{
struct addrof *w;
+ int tnr;
if (p->n_op != ADDROF)
return;
- if (getoff(p->n_left->n_lval))
+ tnr = regno(p->n_left);
+ if (getoff(tnr))
return;
w = tmpalloc(sizeof(struct addrof));
- w->tempnum = p->n_left->n_lval;
- if (setargs(p->n_left->n_lval, w) == 0)
+ w->tempnum = tnr;
+ if (setargs(tnr, w) == 0)
w->oregoff = BITOOR(freetemp(szty(p->n_left->n_type)));
w->next = otlink;
otlink = w;
@@ -149,12 +153,12 @@ cvtaddrof(NODE *p)
if (p->n_op != ADDROF && p->n_op != TEMP)
return;
if (p->n_op == TEMP) {
- n = getoff(p->n_lval);
+ n = getoff(regno(p));
if (n == 0)
return;
p->n_op = OREG;
p->n_lval = n;
- p->n_rval = FPREG;
+ regno(p) = FPREG;
} else {
l = p->n_left;
l->n_type = p->n_type;
@@ -297,11 +301,13 @@ again: gotone = 0;
/*
* Find unconditional jumps directly following a
- * label.
+ * label. Jumps jumping to themselves are not
+ * taken into account.
*/
if (n->type == IP_NODE && n->ip_node->n_op == GOTO) {
i = n->ip_node->n_left->n_lval;
- jmpary[ip->ip_lbl - low] = i;
+ if (i != ip->ip_lbl)
+ jmpary[ip->ip_lbl - low] = i;
}
while (n->type == IP_DEFLAB) {
@@ -887,12 +893,12 @@ placePhiFunctions(struct bblockinfo *bbinfo)
SLIST_FOREACH(cnode, &n->bb->parents, cfgelem)
k++;
/* Construct phi(...) */
- p = mklnode(TEMP, i, 0, ntype);
+ p = mktemp(i, ntype);
for (l = 0; l < k-1; l++)
p = mkbinode(PHI, p,
- mklnode(TEMP, i, 0, ntype), ntype);
+ mktemp(i, ntype), ntype);
ip = ipnode(mkbinode(ASSIGN,
- mklnode(TEMP, i, 0, ntype), p, ntype));
+ mktemp(i, ntype), p, ntype));
/* Insert phi at top of basic block */
DLIST_INSERT_BEFORE(((struct interpass*)&n->bb->first), ip, qelem);
n->bb->first = ip;
diff --git a/usr.bin/pcc/mip/protos.h b/usr.bin/pcc/mip/protos.h
index a5f8674110a..e266120633e 100644
--- a/usr.bin/pcc/mip/protos.h
+++ b/usr.bin/pcc/mip/protos.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: protos.h,v 1.6 2007/12/22 22:56:31 stefan Exp $ */
+/* $OpenBSD: protos.h,v 1.7 2008/01/12 17:17:28 ragge Exp $ */
struct optab;
struct symtab;
@@ -11,7 +11,6 @@ void reclaim(NODE *p, int, int);
void walkf(NODE *, void (*f)(NODE *));
void tfree(NODE *);
int tshape(NODE *, int);
-void prtdcon(NODE *p);
void tcheck(void);
void mkdope(void);
int tshape(NODE *p, int shape);
@@ -34,10 +33,8 @@ void ftnend(void);
void efcode(void);
void dclargs(void);
void cendarg(void);
-void defalign(int);
int fldal(unsigned int);
int fldexpand(NODE *, int, char **);
-void putbyte(int v);
void ecomp(NODE *p);
void bccode(void);
int upoff(int size, int alignment, int *poff);
@@ -53,7 +50,6 @@ int tlen(NODE *p);
int setbin(NODE *);
void oreg2(NODE *p);
int notoff(TWORD, int, CONSZ, char *);
-void bycode(int, int);
int notlval(NODE *);
void ecode(NODE *p);
int yylex(void);
diff --git a/usr.bin/pcc/mip/reader.c b/usr.bin/pcc/mip/reader.c
index ac731cf44bf..fd6a6339752 100644
--- a/usr.bin/pcc/mip/reader.c
+++ b/usr.bin/pcc/mip/reader.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: reader.c,v 1.12 2007/12/16 19:24:03 ragge Exp $ */
+/* $OpenBSD: reader.c,v 1.13 2008/01/12 17:17:28 ragge Exp $ */
/*
* Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
* All rights reserved.
@@ -436,6 +436,7 @@ again: switch (o = p->n_op) {
case TEMP:
case NAME:
case ICON:
+ case FCON:
case OREG:
rv = findleaf(p, cookie);
break;
@@ -732,7 +733,7 @@ e2print(NODE *p, int down, int *a, int *b)
break;
case TEMP:
- fprintf(prfil, " " CONFMT, p->n_lval);
+ fprintf(prfil, " %d", regno(p));
break;
case ICON:
@@ -848,12 +849,12 @@ deltemp(NODE *p)
if (p->n_op == TEMP) {
/* Check if already existing */
for (w = tmpsave; w; w = w->next)
- if (w->tempno == p->n_lval)
+ if (w->tempno == regno(p))
break;
if (w == NULL) {
/* new on stack */
w = tmpalloc(sizeof(struct tmpsave));
- w->tempno = p->n_lval;
+ w->tempno = regno(p);
w->tempaddr = BITOOR(freetemp(szty(p->n_type)));
w->next = tmpsave;
tmpsave = w;
diff --git a/usr.bin/pcc/mip/regs.c b/usr.bin/pcc/mip/regs.c
index 3e256d3c365..e87069d6a15 100644
--- a/usr.bin/pcc/mip/regs.c
+++ b/usr.bin/pcc/mip/regs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: regs.c,v 1.14 2007/12/16 19:24:03 ragge Exp $ */
+/* $OpenBSD: regs.c,v 1.15 2008/01/12 17:17:28 ragge Exp $ */
/*
* Copyright (c) 2005 Anders Magnusson (ragge@ludd.luth.se).
* All rights reserved.
@@ -158,12 +158,12 @@ static int *nsavregs, *ndontregs;
static REGW *
newblock(NODE *p)
{
- REGW *nb = &nblock[(int)p->n_lval];
+ REGW *nb = &nblock[regno(p)];
if (nb->link.q_forw == 0) {
DLIST_INSERT_AFTER(&initial, nb, link);
- ASGNUM(nb) = p->n_lval;
+ ASGNUM(nb) = regno(p);
RDEBUG(("Adding longtime %d for tmp %d\n",
- nb->nodnum, (int)p->n_lval));
+ nb->nodnum, regno(p)));
}
if (nb->r_class == 0)
nb->r_class = gclass(p->n_type);
@@ -207,7 +207,7 @@ nsucomp(NODE *p)
if (p->n_op == TEMP)
p->n_regw = newblock(p);
else if (p->n_op == REG)
- p->n_regw = &ablock[p->n_rval];
+ p->n_regw = &ablock[regno(p)];
} else
a = nsucomp(p->n_left);
if (o == BITYPE) {
@@ -784,10 +784,8 @@ setlive(NODE *p, int set, REGW *rv)
switch (optype(p->n_op)) {
case LTYPE:
- if (p->n_op == TEMP)
- set ? LIVEADD((int)p->n_lval) : LIVEDEL((int)p->n_lval);
- else if (p->n_op == REG)
- set ? LIVEADD(p->n_rval) : LIVEDEL(p->n_rval);
+ if (p->n_op == REG || p->n_op == TEMP)
+ set ? LIVEADD(regno(p)) : LIVEDEL(regno(p));
break;
case BITYPE:
setlive(p->n_right, set, rv);
@@ -842,9 +840,6 @@ addedge_r(NODE *p, REGW *w)
* Moves to special regs are scheduled after the evaluation of both legs.
*/
-#define ASGLEFT(p) (p->n_op == ASSIGN && p->n_left->n_op == TEMP)
-#define RASGLEFT(p) (p->n_op == ASSIGN && p->n_left->n_op == REG)
-
static void
insnwalk(NODE *p)
{
@@ -860,13 +855,8 @@ insnwalk(NODE *p)
rrv = lrv = NULL;
if (p->n_op == ASSIGN &&
(p->n_left->n_op == TEMP || p->n_left->n_op == REG)) {
- if (p->n_left->n_op == TEMP) {
- i = p->n_left->n_lval;
- lr = nblock;
- } else {
- i = p->n_left->n_rval;
- lr = ablock;
- }
+ lr = p->n_left->n_op == TEMP ? nblock : ablock;
+ i = regno(p->n_left);
LIVEDEL(i); /* remove assigned temp from live set */
addalledges(&lr[i]);
}
@@ -1017,7 +1007,7 @@ insnwalk(NODE *p)
switch (o) {
case TEMP:
case REG:
- i = (o == TEMP ? p->n_lval : p->n_rval);
+ i = regno(p);
rr = (o == TEMP ? &nblock[i] : &ablock[i]);
if (rv != rr) {
addalledges(rr);
@@ -1047,18 +1037,18 @@ unionize(NODE *p, int bb)
if ((o = p->n_op) == TEMP) {
#ifdef notyet
for (i = 0; i < szty(p->n_type); i++) {
- BITSET(gen[bb], ((int)p->n_lval - tempmin+i+MAXREGS));
+ BITSET(gen[bb], (regno(p) - tempmin+i+MAXREGS));
}
#else
i = 0;
- BITSET(gen[bb], ((int)p->n_lval - tempmin+i+MAXREGS));
+ BITSET(gen[bb], (regno(p) - tempmin+i+MAXREGS));
#endif
} else if (o == REG) {
- BITSET(gen[bb], p->n_rval);
+ BITSET(gen[bb], regno(p));
}
if (asgop(o)) {
if (p->n_left->n_op == TEMP) {
- int b = p->n_left->n_lval - tempmin+MAXREGS;
+ int b = regno(p->n_left) - tempmin+MAXREGS;
#ifdef notyet
for (i = 0; i < szty(p->n_type); i++) {
BITCLEAR(gen[bb], (b+i));
@@ -1072,7 +1062,7 @@ unionize(NODE *p, int bb)
unionize(p->n_right, bb);
return;
} else if (p->n_left->n_op == REG) {
- int b = p->n_left->n_rval;
+ int b = regno(p->n_left);
BITCLEAR(gen[bb], b);
BITSET(kill[bb], b);
unionize(p->n_right, bb);
@@ -1763,7 +1753,7 @@ traclass(NODE *p)
if (p->n_op != TEMP)
return;
- nb = &nblock[(int)p->n_lval];
+ nb = &nblock[regno(p)];
if (CLASS(nb) == 0)
CLASS(nb) = gclass(p->n_type);
}
@@ -1792,8 +1782,8 @@ paint(NODE *p)
} else
p->n_reg = -1;
if (p->n_op == TEMP) {
- REGW *nb = &nblock[(int)p->n_lval];
- p->n_rval = COLOR(nb);
+ REGW *nb = &nblock[regno(p)];
+ regno(p) = COLOR(nb);
if (TCLASS(p->n_su) == 0)
SCLASS(p->n_su, CLASS(nb));
p->n_op = REG;
@@ -1880,7 +1870,7 @@ longtemp(NODE *p)
return;
/* XXX - should have a bitmask to find temps to convert */
DLIST_FOREACH(w, spole, link) {
- if (w != &nblock[(int)p->n_lval])
+ if (w != &nblock[regno(p)])
continue;
if (w->r_class == 0) {
w->r_color = BITOOR(freetemp(szty(p->n_type)));
@@ -2018,7 +2008,7 @@ temparg(struct interpass *ipole, REGW *w)
#endif
if (p->n_right->n_op != OREG)
continue; /* arg in register */
- if (w != &nblock[(int)p->n_left->n_lval])
+ if (w != &nblock[regno(p->n_left)])
continue;
w->r_color = p->n_right->n_lval;
tfree(p);