commit 93601b6d0234875cf97e57b7e56fdd5a1803eac0
parent 033dce6e17ea10997498e8fa189f6d079a6105b9
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date: Mon, 3 Aug 2015 10:18:21 -0400
patch isel to use symbol types
Diffstat:
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/lisc/isel.c b/lisc/isel.c
@@ -24,6 +24,20 @@ emit(short op, Ref to, Ref arg0, Ref arg1)
*--curi = (Ins){op, to, {arg0, arg1}};
}
+static int
+newsym(int type, Fn *fn)
+{
+ int s;
+
+ s = fn->nsym++;
+ fn->sym = realloc(fn->sym, fn->nsym * sizeof(Sym));
+ if (!fn->sym)
+ diag("isel: out of memory");
+ fn->sym[s] = (Sym){.type = type};
+ sprintf(fn->sym[s].name, "isel%d", s);
+ return s;
+}
+
static void
sel(Ins *i, Fn *fn)
{
@@ -45,7 +59,7 @@ sel(Ins *i, Fn *fn)
/* immediates not allowed for
* divisions in x86
*/
- t = fn->ntmp++;
+ t = newsym(fn->sym[i->to.val].type, fn);
r0 = SYM(t);
} else
r0 = i->arg[1];
@@ -72,10 +86,8 @@ isel(Fn *fn)
{
Blk *b;
Ins *i;
- int t0, t;
uint nins;
- t0 = fn->ntmp;
for (b=fn->start; b; b=b->link) {
curi = &insb[NIns];
for (i=&b->ins[b->nins]; i!=b->ins;) {
@@ -87,13 +99,4 @@ isel(Fn *fn)
memcpy(b->ins, curi, nins * sizeof b->ins[0]);
b->nins = nins;
}
- if (fn->ntmp == t0)
- return;
- fn->sym = realloc(fn->sym, fn->ntmp * sizeof(Sym));
- if (!fn->sym)
- diag("isel: out of memory");
- for (t=t0; t<fn->ntmp; t++) {
- fn->sym[t].type = STmp;
- sprintf(fn->sym[t].name, "isel%d", t-t0);
- }
}