commit a9b2d0338ba49f582b3dceb7bd60556c52832611
parent 476e54c5d5c2834171b38b7b7a831df3ee7cc3b2
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date: Tue, 14 Jul 2015 06:46:48 -0400
change phi nodes representation
Diffstat:
3 files changed, 52 insertions(+), 56 deletions(-)
diff --git a/lisc/Makefile b/lisc/Makefile
@@ -1,5 +1,5 @@
BIN = lisc
-OBJ = parse.o ssa.o
+OBJ = parse.o # ssa.o
CFLAGS = -Wall -Wextra -std=c99 -g
diff --git a/lisc/lisc.h b/lisc/lisc.h
@@ -6,22 +6,14 @@ typedef unsigned int uint;
typedef unsigned short ushort;
typedef unsigned char uchar;
-/* How do I deal with stack slots (alloc, set, get) ?
- * It seems that computing the address of the slot
- * and then dereferencing is a bad idea, it uses
- * one register while I could use the machine
- * addressing capabilities.
- */
-
enum {
- R = 0, /* invalid reference */
- NRegs = 32,
- Tmp0 = NRegs+1,
+ R = 0, /* invalid reference */
+ NReg = 32,
+ Tmp0 = NReg+1,
NString = 32,
- NPreds = 15,
- NBlks = 128,
- NInss = 256,
- NPhis = 32,
+ NPred = 15,
+ NBlk = 128,
+ NIns = 256,
};
typedef struct Ins Ins;
@@ -71,16 +63,16 @@ struct Ins {
struct Phi {
Ref to;
- Ref args[NPreds];
- int na;
+ Ref arg[NPred];
+ Blk *blk[NPred];
+ uint narg;
+ Phi *link;
};
struct Blk {
- Phi *ps;
- Ins *is;
- uint np;
- uint ni;
- int id;
+ Phi *phi;
+ Ins *ins;
+ uint nins;
struct {
short type;
Ref arg;
@@ -89,9 +81,10 @@ struct Blk {
Blk *s2;
Blk *link;
- Blk **preds;
- int npreds;
+ Blk **pred;
+ uint npred;
char name[NString];
+ int id;
};
struct Sym {
@@ -102,7 +95,7 @@ struct Sym {
} type;
char name[NString];
Blk *blk;
- int pos; /* negative for phis */
+ int pos;
};
struct Fn {
diff --git a/lisc/parse.c b/lisc/parse.c
@@ -6,7 +6,7 @@
#include "lisc.h"
enum {
- NSyms = 256,
+ NSym = 256,
};
typedef enum {
@@ -44,14 +44,14 @@ typedef enum {
static FILE *inf;
static Token thead;
-static Sym sym[NSyms];
+static Sym sym[NSym];
static Ref ntmp;
-static Phi phi[NPhis], *curp;
-static Ins ins[NInss], *curi;
+static Ins ins[NIns], *curi;
+static Phi **plink;
static struct {
char name[NString];
Blk *blk;
-} bmap[NBlks+1];
+} bmap[NBlk+1];
static Blk *curb;
static Blk **blink;
static int nblk;
@@ -217,7 +217,7 @@ varref(char *v)
if (sym[t].type == STmp)
if (strcmp(v, sym[t].name) == 0)
return SYM(t);
- if (t >= NSyms)
+ if (t >= NSym)
err("too many symbols");
sym[t].type = STmp;
strcpy(sym[t].name, v);
@@ -248,10 +248,10 @@ findblk(char *name)
int i;
assert(name[0]);
- for (i=0; i<NBlks; i++)
+ for (i=0; i<NBlk; i++)
if (!bmap[i].blk || strcmp(bmap[i].name, name) == 0)
break;
- if (i == NBlks)
+ if (i == NBlk)
err("too many blocks");
if (!bmap[i].blk) {
assert(bmap[i].name[0] == 0);
@@ -288,13 +288,15 @@ expect(Token t)
static PState
parseline(PState ps)
{
- Ref args[NPreds] = {0};
+ Ref arg[NPred] = {0};
+ Blk *blk[NPred];
+ Phi *phi;
Ref r;
Token t;
Blk *b;
int op, i, j;
- assert(args[0] == R);
+ assert(arg[0] == R);
do
t = next();
while (t == TNL);
@@ -310,12 +312,10 @@ parseline(PState ps)
case TLbl:
b = findblk(tokval.str);
if (curb) {
- curb->np = curp - phi;
- curb->ni = curi - ins;
- curb->ps = alloc(curb->np * sizeof(Phi));
- curb->is = alloc(curb->ni * sizeof(Ins));
- memcpy(curb->ps, curp, curb->np * sizeof(Phi));
- memcpy(curb->is, curi, curb->ni * sizeof(Ins));
+ curb->nins = curi - ins;
+ curb->ins = alloc(curb->nins * sizeof(Ins));
+ memcpy(curb->ins, ins, curb->nins * sizeof(Ins));
+ plink = &curb->phi;
if (curb->jmp.type == JXXX) {
curb->jmp.type = JJmp;
curb->s1 = b;
@@ -388,10 +388,14 @@ parseline(PState ps)
i = 0;
if (peek() != TNL)
for (;;) {
- if (i == NPreds)
+ if (i == NPred)
err("too many arguments");
- args[i] = parseref();
- if (args[i] == R)
+ if (op == -1) {
+ expect(TLbl);
+ blk[i] = findblk(tokval.str);
+ }
+ arg[i] = parseref();
+ if (arg[i] == R)
err("invalid instruction argument");
i++;
t = peek();
@@ -405,20 +409,20 @@ parseline(PState ps)
if (j >= 0 && i != j)
err("invalid arity");
if (op != -1) {
- if (curi - ins >= NInss)
+ if (curi - ins >= NIns)
err("too many instructions in block");
curi->to = r;
- curi->l = args[0];
- curi->r = args[1];
+ curi->l = arg[0];
+ curi->r = arg[1];
curi++;
return PIns;
} else {
- if (curp - phi >= NPhis)
- err("too many phis in block");
- curp->to = r;
- memcpy(curp->args, args, i * sizeof(Ref));
- curp->na = i;
- curp++;
+ phi = alloc(sizeof *phi);
+ phi->to = r;
+ memcpy(phi->arg, arg, i * sizeof arg[0]);
+ memcpy(phi->blk, blk, i * sizeof blk[0]);
+ phi->narg = i;
+ plink = &phi->link;
return PPhi;
}
}
@@ -431,17 +435,16 @@ parsefn(FILE *f)
Fn *fn;
inf = f;
- for (i=0; i<NBlks; i++) {
+ for (i=0; i<NBlk; i++) {
bmap[i].name[0] = 0;
bmap[i].blk = 0;
}
- for (i=Tmp0; i<NSyms; i++) {
+ for (i=Tmp0; i<NSym; i++) {
sym[i].type = SUndef;
sym[i].name[0] = 0;
sym[i].blk = 0;
}
ntmp = Tmp0;
- curp = phi;
curi = ins;
curb = 0;
lnum = 1;