ref: d7527440ec5bdcf8ae6a5bfe4787c5fcdc9a4d08
parent: 6a5373b289e74fb66819266a4b2fcfab5de23913
author: Ori Bernstein <[email protected]>
date: Wed Jun 13 20:56:48 EDT 2012
Fix use/def calculations. We called uses() instead of defs() and forgot to initalize j
--- a/8/asm.h
+++ b/8/asm.h
@@ -134,8 +134,9 @@
void regalloc(Isel *s);
size_t uses(Insn *i, long *uses);
size_t defs(Insn *i, long *defs);
-extern const char *regnames[];
-extern const Mode regmodes[];
+extern char *regnames[];
+extern Mode regmodes[];
+extern Loc **loctab;
/* useful functions */
--- a/8/insns.def
+++ b/8/insns.def
@@ -19,10 +19,10 @@
/* Note, the mov instruction is specified in an overly general manner. */
Insn(Inone, "BAD_INSN", Use(), Def())
-Insn(Imov, "\tmov%t %x,%x\n", Use(.l={1,2}), Def(.l={2}))
-Insn(Imovz, "\tmovz%1t%2t %x,%x\n", Use(.l={1,2}), Def(.l={2}))
-Insn(Imovs, "\tmovs%1t%2t %x,%x\n", Use(.l={1,2}), Def(.l={2}))
-Insn(Ilea, "\tlea%t %x,%x\n", Use(.l={1,2}), Def(.l={2}))
+Insn(Imov, "\tmov%t %x,%x\n", Use(.l={1}), Def(.l={2}))
+Insn(Imovz, "\tmovz%1t%2t %x,%x\n", Use(.l={1}), Def(.l={2}))
+Insn(Imovs, "\tmovs%1t%2t %x,%x\n", Use(.l={1}), Def(.l={2}))
+Insn(Ilea, "\tlea%t %x,%x\n", Use(.l={1}), Def(.l={2}))
Insn(Iadd, "\tadd%t %r,%x\n", Use(.l={1,2}), Def(.l={2}))
Insn(Isub, "\tsub%t %r,%x\n", Use(.l={1,2}), Def(.l={2}))
--- a/8/ra.c
+++ b/8/ra.c
@@ -67,7 +67,7 @@
for (i = 0; i < insn->nargs; i++) {
m = insn->args[i];
if (m->type != Locmem && m->type != Locmeml)
- break;
+ continue;
u[j++] = m->mem.base->reg.id;
if (m->mem.idx)
u[j++] = m->mem.idx->reg.id;
@@ -80,6 +80,7 @@
size_t i, j;
int k;
+ j = 0;
/* Add all the registers dsed and defined. Ddplicates
* in this list are fine, since they're being added to
* a set anyways */
@@ -101,7 +102,7 @@
return j;
}
-void bbliveness(Asmbb *bb)
+void usedef(Asmbb *bb)
{
/* up to 2 registers per memloc, so
* 2*Maxarg is the maximum number of
@@ -114,7 +115,7 @@
bb->def = bsclear(bb->def);
for (i = 0; i < bb->ni; i++) {
nu = uses(bb->il[i], u);
- nd = uses(bb->il[i], d);
+ nd = defs(bb->il[i], d);
for (j = 0; j < nu; j++)
if (!bshas(bb->def, u[j]))
bsput(bb->use, u[j]);
@@ -134,12 +135,12 @@
bb = s->bb;
nbb = s->nbb;
for (i = 0; i < nbb; i++) {
- bbliveness(s->bb[i]);
+ usedef(s->bb[i]);
bb[i]->livein = bsclear(bb[i]->livein);
bb[i]->liveout = bsclear(bb[i]->liveout);
}
- changed = 1;
+ changed = 0;
while (changed) {
changed = 0;
for (i = 0; i < nbb; i--) {
@@ -201,6 +202,47 @@
}
fprintf(fd, "\n");
+ fprintf(fd, "Use: ");
+ sep = "";
+ for (i = 0; i < bsmax(bb->use); i++) {
+ if (bshas(bb->use, i)) {
+ fprintf(fd, "%s", sep);
+ locprint(fd, loctab[i]);
+ sep = ",";
+ }
+ }
+ fprintf(fd, "\n");
+ fprintf(fd, "Def: ");
+ sep = "";
+ for (i = 0; i < bsmax(bb->def); i++) {
+ if (bshas(bb->def, i)) {
+ fprintf(fd, "%s", sep);
+ locprint(fd, loctab[i]);
+ sep = ",";
+ }
+ }
+ fprintf(fd, "\n");
+
+ fprintf(fd, "Livein: ");
+ sep = "";
+ for (i = 0; i < bsmax(bb->livein); i++) {
+ if (bshas(bb->livein, i)) {
+ fprintf(fd, "%s", sep);
+ locprint(fd, loctab[i]);
+ sep = ",";
+ }
+ }
+ fprintf(fd, "\n");
+ fprintf(fd, "Liveout: ");
+ sep = "";
+ for (i = 0; i < bsmax(bb->liveout); i++) {
+ if (bshas(bb->liveout, i)) {
+ fprintf(fd, "%s", sep);
+ locprint(fd, loctab[i]);
+ sep = ",";
+ }
+ }
+ fprintf(fd, "\n");
for (i = 0; i < bb->ni; i++)
iprintf(fd, bb->il[i]);
}
--- a/8/regalloc.c
+++ b/8/regalloc.c
@@ -14,13 +14,13 @@
#include "opt.h"
#include "asm.h"
-const Mode regmodes[] = {
+Mode regmodes[] = {
#define Reg(r, name, mode) mode,
#include "regs.def"
#undef Reg
};
-const char *regnames[] = {
+char *regnames[] = {
#define Reg(r, name, mode) name,
#include "regs.def"
#undef Reg
@@ -70,6 +70,7 @@
return locstrlbl(lbl->lbl.name);
}
+Loc **loctab = NULL;
Loc *locreg(Mode m)
{
Loc *l;
@@ -79,6 +80,8 @@
l->type = Locreg;
l->mode = m;
l->reg.id = nextid++;
+ loctab = xrealloc(loctab, nextid * sizeof(Loc*));
+ loctab[l->reg.id] = l;
return l;
}