summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <orib@google.com>2013-01-30 14:03:19 -0500
committerOri Bernstein <orib@google.com>2013-01-30 14:03:19 -0500
commit7b0c6c77845e01963e6eabd94bbc91c68eed6bc3 (patch)
tree24bc52e2264d8cf033e8d7cb612d2c878d93a33f
parentb474f4b5e52fdabfec503d8666aefe35bdbdb7f1 (diff)
downloadmc-7b0c6c77845e01963e6eabd94bbc91c68eed6bc3.tar.gz
Work on moving to callee save convention.
This breaks things badly; We have a register allocator bug.
-rw-r--r--6/isel.c8
-rw-r--r--6/ra.c64
2 files changed, 50 insertions, 22 deletions
diff --git a/6/isel.c b/6/isel.c
index aa97bc0..599854d 100644
--- a/6/isel.c
+++ b/6/isel.c
@@ -781,7 +781,7 @@ static void prologue(Isel *s, size_t sz)
Loc *rsp;
Loc *rbp;
Loc *stksz;
- //size_t i;
+ size_t i;
rsp = locphysreg(Rrsp);
rbp = locphysreg(Rrbp);
@@ -790,13 +790,11 @@ static void prologue(Isel *s, size_t sz)
g(s, Ipush, rbp, NULL);
g(s, Imov, rsp, rbp, NULL);
g(s, Isub, stksz, rsp, NULL);
-#if 0
/* save registers */
for (i = 0; i < sizeof(savedregs)/sizeof(savedregs[0]); i++) {
s->calleesave[i] = locreg(ModeQ);
g(s, Imov, locphysreg(savedregs[i]), s->calleesave[i], NULL);
}
-#endif
s->stksz = stksz; /* need to update if we spill */
}
@@ -805,7 +803,7 @@ static void epilogue(Isel *s)
{
Loc *rsp, *rbp;
Loc *ret;
- //size_t i;
+ size_t i;
rsp = locphysreg(Rrsp);
rbp = locphysreg(Rrbp);
@@ -813,12 +811,10 @@ static void epilogue(Isel *s)
ret = loc(s, s->ret);
g(s, Imov, ret, coreg(Rax, ret->mode), NULL);
}
-#if 0
/* restore registers */
for (i = 0; i < Nsaved; i++)
g(s, Imov, s->calleesave[i], locphysreg(savedregs[i]), NULL);
/* leave function */
-#endif
g(s, Imov, rbp, rsp, NULL);
g(s, Ipop, rbp, NULL);
g(s, Iret, NULL);
diff --git a/6/ra.c b/6/ra.c
index 6373b7d..15a6f2a 100644
--- a/6/ra.c
+++ b/6/ra.c
@@ -18,6 +18,7 @@ struct Usemap {
int r[Maxarg + 1]; /* list of registers used implicitly by instruction */
};
+void wlprint(FILE *fd, char *name, Loc **wl, size_t nwl);
static void printedge(FILE *fd, char *msg, size_t a, size_t b);
/* tables of uses/defs by instruction */
@@ -329,6 +330,16 @@ static void setup(Isel *s)
s->degree = zalloc(maxregid * sizeof(int));
s->rmoves = zalloc(maxregid * sizeof(Loc **));
s->nrmoves = zalloc(maxregid * sizeof(size_t));
+
+ /* Initialize the degrees of prepainted registers */
+ bsput(s->prepainted, 0);
+ s->degree[0] = 1<<16;
+ for (i = 0; i < maxregid; i++) {
+ if (locmap[i]->reg.colour) {
+ bsput(s->prepainted, i);
+ s->degree[i] = 1<<16;
+ }
+ }
}
static void build(Isel *s)
@@ -393,7 +404,6 @@ static int adjiter(Isel *s, regid n, regid *m)
goto next;
if (bshas(s->coalesced, r))
goto next;
- assert(r < maxregid);
*m = r;
return 1;
next:
@@ -515,9 +525,12 @@ static void wladd(Isel *s, regid u)
return;
if (s->degree[u] >= K)
return;
- for (i = 0; i < s->nwlfreeze; i++)
- if (s->wlfreeze[i]->reg.id == u)
+ for (i = 0; i < s->nwlfreeze; i++) {
+ if (s->wlfreeze[i]->reg.id == u) {
ldel(&s->wlfreeze, &s->nwlfreeze, i);
+ break;
+ }
+ }
lappend(&s->wlsimp, &s->nwlsimp, locmap[u]);
}
@@ -562,7 +575,7 @@ static int combinable(Isel *s, regid u, regid v)
return 1;
/* if it is, are the adjacent nodes ok to combine with this? */
- for (t = 0; adjiter(s, u, &t); t++)
+ for (t = 0; adjiter(s, v, &t); t++)
if (!ok(s, t, u))
return 0;
return 1;
@@ -617,6 +630,9 @@ static void combine(Isel *s, regid u, regid v)
addedge(s, t, u);
decdegree(s, t);
}
+ printf("Degree ");
+ locprint(stdout, locmap[u], 'x');
+ printf(" = %d\n", s->degree[u]);
if (s->degree[u] >= K && wlhas(s->wlfreeze, s->nwlfreeze, u, &idx)) {
ldel(&s->wlfreeze, &s->nwlfreeze, idx);
lappend(&s->wlspill, &s->nwlspill, locmap[u]);
@@ -718,7 +734,6 @@ static void selspill(Isel *s)
/* FIXME: pick a better heuristic for spilling */
m = NULL;
for (i = 0; i < s->nwlspill; i++) {
- printf("Trying to spill %zd\n", s->wlspill[i]->reg.id);
if (!bshas(s->shouldspill, s->wlspill[i]->reg.id))
continue;
m = s->wlspill[i];
@@ -990,19 +1005,14 @@ static void rewrite(Isel *s)
void regalloc(Isel *s)
{
- size_t i;
int spilled;
+ size_t i;
s->prepainted = mkbs();
s->shouldspill = mkbs();
s->neverspill = mkbs();
-#if 0
for (i = 0; i < Nsaved; i++)
bsput(s->shouldspill, s->calleesave[i]->reg.id);
-#endif
- for (i = 0; i < maxregid; i++)
- if (locmap[i]->reg.colour)
- bsput(s->prepainted, i);
do {
setup(s);
liveness(s);
@@ -1029,6 +1039,21 @@ void regalloc(Isel *s)
bsfree(s->neverspill);
}
+void wlprint(FILE *fd, char *name, Loc **wl, size_t nwl)
+{
+ size_t i;
+ char *sep;
+
+ sep = "";
+ fprintf(fd, "%s = [", name);
+ for (i = 0; i < nwl; i++) {
+ fprintf(fd, "%s", sep);
+ locprint(fd, wl[i], 'x');
+ sep = ",";
+ }
+ fprintf(fd, "]\n");
+}
+
static void setprint(FILE *fd, Bitset *s)
{
char *sep;
@@ -1087,11 +1112,18 @@ void dumpasm(Isel *s, FILE *fd)
char *sep;
Asmbb *bb;
- fprintf(fd, "IGRAPH ----- \n");
- for (i = 0; i < maxregid; i++) {
- for (j = i; j < maxregid; j++) {
- if (gbhasedge(s, i, j))
- printedge(stdout, "", i, j);
+ fprintf(fd, "WORKLISTS -- \n");
+ wlprint(stdout, "spill", s->wlspill, s->nwlspill);
+ wlprint(stdout, "simp", s->wlsimp, s->nwlsimp);
+ wlprint(stdout, "freeze", s->wlfreeze, s->nwlfreeze);
+ /* noisy to dump this all the time; only dump for higher debug levels */
+ if (debugopt['r'] > 2) {
+ fprintf(fd, "IGRAPH ----- \n");
+ for (i = 0; i < maxregid; i++) {
+ for (j = i; j < maxregid; j++) {
+ if (gbhasedge(s, i, j))
+ printedge(stdout, "", i, j);
+ }
}
}
fprintf(fd, "ASM -------- \n");