Skip to content

Commit

Permalink
WIP: attempt to fix spill code
Browse files Browse the repository at this point in the history
The results of targeting inserted reloads were being silently discarded,
which resulted in kervinck#76. These changes stop discarding these results and
label/reduce any resulting copies.
  • Loading branch information
pgavlin committed May 21, 2019
1 parent fc66452 commit b74c8e7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
11 changes: 11 additions & 0 deletions Utils/lcc/lburg/lburg.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,17 @@ static void emitstring(Rule rules) {
print(",%1/* %R */\n", r);
}
print("};\n");
print("static char *%Pactionnames[] = {\n");
print("/* 0 */%10,\n");
for (r = rules; r; r = r->link) {
print("/* %d */%1", r->ern);
if (r->action->code == 0)
print("0");
else
print("\"%s\"", r->action->code);
print(",%1/* %R */\n", r);
}
print("};\n");
print("static char *%Ptemplates[] = {\n");
print("/* 0 */%10,\n");
for (r = rules; r; r = r->link) {
Expand Down
1 change: 1 addition & 0 deletions Utils/lcc/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ typedef struct {
void (*_kids)(Node, int, Node*);
char **_string;
Action *_actions;
char **_actionnames;
char **_templates;
char *_isinstruction;
char **_ntname;
Expand Down
19 changes: 11 additions & 8 deletions Utils/lcc/src/gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ static void dumprule(int rulenum) {

char *str = IR->x._templates[rulenum];
if (str == 0)
str = "(action)\n";
str = IR->x._actionnames[rulenum];

fprint(stderr, "%s / %s", IR->x._string[rulenum], str);
if (!IR->x._isinstruction[rulenum])
if (!IR->x._isinstruction[rulenum] || IR->x._templates[rulenum] == 0)
fprint(stderr, "\n");
}
unsigned emitasm(Node p, int nt) {
Expand All @@ -357,7 +357,7 @@ unsigned emitasm(Node p, int nt) {
if (rulenum == 0) {
debug(fprint(stderr, " (no rule)\n"));
} else if (fmt == 0) {
debug(fprint(stderr, " (action)\n"));
debug(fprint(stderr, " %s\n", IR->x._actionnames[rulenum]));
} else {
debug(fprint(stderr, " %s\n", fmt));
}
Expand Down Expand Up @@ -775,7 +775,7 @@ static void genspill(Symbol r, Node last, Symbol tmp) {
Symbol s;
unsigned ty;

debug(fprint(stderr, "(spilling %s to local %s)\n", r->x.name, tmp->x.name));
debug(fprint(stderr, "(spilling %s to local %s after %x)\n", r->x.name, tmp->x.name, last));
debug(fprint(stderr, "(genspill: "));
debug(dumptree(last));
debug(fprint(stderr, ")\n"));
Expand Down Expand Up @@ -803,7 +803,7 @@ static void genreload(Node p, Symbol tmp, int i) {
Node q;
int ty;

debug(fprint(stderr, "(replacing %x with a reload from %s)\n", p->x.kids[i], tmp->x.name));
debug(fprint(stderr, "(replacing %x with a reload from %s before %x)\n", p->x.kids[i], tmp->x.name, p));
debug(fprint(stderr, "(genreload: "));
debug(dumptree(p->x.kids[i]));
debug(fprint(stderr, ")\n"));
Expand All @@ -817,7 +817,7 @@ static void genreload(Node p, Symbol tmp, int i) {
linearize(p->x.kids[i], p);
}
static int reprune(Node *pp, int k, int n, Node p) {
struct node x, *q = *pp;
struct node *q = *pp;

if (q == NULL || k > n)
return k;
Expand All @@ -827,8 +827,11 @@ static int reprune(Node *pp, int k, int n, Node p) {
if (k == n) {
debug(fprint(stderr, "(reprune changes %x from %x to %x)\n", pp, *pp, p->x.kids[n]));
*pp = p->x.kids[n];
x = *p;
(IR->x.target)(&x);
(IR->x.target)(p);

(*IR->x._label)(p->kids[n]);
debug(dumpcover(p->kids[n], 1, 0));
reduce(p->kids[n], 1);
}
return k + 1;
}
Expand Down
14 changes: 13 additions & 1 deletion Utils/lcc/src/gt1.md
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,20 @@ static void inst_spill(Node p) {
// inst_spill is essentially the same as inst_stloc, but covers an entire spill tree to avoid reentry in the
// spiller when spilling vAC.
Node vregp = p->kids[1]->kids[0]->kids[0];
assert(getregnum(vregp) == 0);

// If we are spilling vAC, we're all set. Otherwise we've got some extra work to do to avoid clobbering vAC.
int regnum = vregp->syms[0]->x.regnode->number;
if (regnum != 0) {
print("asm.stw('ht')\n");
print("asm.ldw('r%d')\n", regnum);
}

setreg(p->kids[1], wregs[0]);
inst_stloc(p);

if (regnum != 0) {
print("asm.ldw('ht')\n");
}
}

static void inst_blkcopy(Node p) {
Expand Down Expand Up @@ -1428,6 +1439,7 @@ Interface gt1IR = {
_kids,
_string,
_actions,
_actionnames,
_templates,
_isinstruction,
_ntname,
Expand Down

0 comments on commit b74c8e7

Please sign in to comment.