ref: 0c574aa0d1cf26d51211668522db935da52a5ebe
parent: 1692dfdd9688c970e0b5fb1def9758b229bc1402
author: Ori Bernstein <[email protected]>
date: Tue Jul 31 07:36:58 EDT 2012
Move towards registerizing stuff.
--- a/6/asm.h
+++ b/6/asm.h
@@ -109,6 +109,7 @@
Node *ret; /* we store the return into here */
Htab *locs; /* decl id => int stkoff */
+ Htab *reglocs; /* decl id => Loc *reg */
Htab *globls; /* decl id => char *globlname */
/* increased when we spill */
--- a/6/isel.c
+++ b/6/isel.c
@@ -94,7 +94,9 @@
rip = locphysreg(Rrip);
l = locmeml(htget(s->globls, n), rip, NULL, mode(n));
} else {
- die("%s (id=%ld) not found", namestr(n->expr.args[0]), n->expr.did);
+ if (!hthas(s->reglocs, n))
+ htput(s->reglocs, n, locreg(mode(n)));
+ return htget(s->reglocs, n);
}
break;
case Olit:
@@ -870,6 +872,7 @@
size_t i, j;
char buf[128];
+ is.reglocs = mkht(dclhash, dcleq);
is.locs = fn->locs;
is.globls = globls;
is.ret = fn->ret;
--- a/6/simp.c
+++ b/6/simp.c
@@ -151,30 +151,6 @@
return n;
}
-static size_t did(Node *n)
-{
- if (n->type == Ndecl) {
- return n->decl.did;
- } else if (n->type == Nexpr) {
- assert(exprop(n) == Ovar);
- return n->expr.did;
- }
- dump(n, stderr);
- die("Can't get did");
- return 0;
-}
-
-static ulong dclhash(void *dcl)
-{
- /* large-prime hash. meh. */
- return did(dcl) * 366787;
-}
-
-static int dcleq(void *a, void *b)
-{
- return did(a) == did(b);
-}
-
static void append(Simp *s, Node *n)
{
lappend(&s->stmts, &s->nstmts, n);
@@ -325,7 +301,8 @@
assert(e->type == Nexpr);
t = gentemp(simp, e, e->expr.type, &dcl);
- declarelocal(simp, dcl);
+ if (stacknode(e))
+ declarelocal(simp, dcl);
return t;
}
@@ -1094,11 +1071,13 @@
static void declarelocal(Simp *s, Node *n)
{
assert(n->type == Ndecl);
- s->stksz += size(n);
- s->stksz = align(s->stksz, min(size(n), Ptrsz));
- if (debug)
- printf("declare %s:%s(%zd) at %zd\n", declname(n), tystr(decltype(n)), n->decl.did, s->stksz);
- htput(s->locs, n, (void*)s->stksz);
+ if (stacknode(n)) {
+ s->stksz += size(n);
+ s->stksz = align(s->stksz, min(size(n), Ptrsz));
+ if (debug)
+ printf("declare %s:%s(%zd) at %zd\n", declname(n), tystr(decltype(n)), n->decl.did, s->stksz);
+ htput(s->locs, n, (void*)s->stksz);
+ }
}
static void declarearg(Simp *s, Node *n)
--- a/parse/node.c
+++ b/parse/node.c
@@ -335,3 +335,28 @@
assert(name->type == Nname);
return name->name.name;
}
+
+static size_t did(Node *n)
+{
+ if (n->type == Ndecl) {
+ return n->decl.did;
+ } else if (n->type == Nexpr) {
+ assert(exprop(n) == Ovar);
+ return n->expr.did;
+ }
+ dump(n, stderr);
+ die("Can't get did");
+ return 0;
+}
+
+ulong dclhash(void *dcl)
+{
+ /* large-prime hash. meh. */
+ return did(dcl) * 366787;
+}
+
+int dcleq(void *a, void *b)
+{
+ return did(a) == did(b);
+}
+
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -393,6 +393,8 @@
void addstmt(Node *file, Node *stmt);
void setns(Node *n, char *ns);
void updatens(Stab *st, char *ns);
+ulong dclhash(void *dcl);
+int dcleq(void *a, void *b);
Op exprop(Node *n);
/* specialize generics */