diff options
author | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-11-13 13:12:22 -0500 |
---|---|---|
committer | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-11-13 13:12:22 -0500 |
commit | 291c39565fb3b4e688dce2bfedbdd781ed71e87d (patch) | |
tree | 92ec7f068607a2ce34cec5d857c9302708b2047f | |
parent | 681fc07defc8902d5b3d827bac50eedc748f8664 (diff) | |
download | roux-291c39565fb3b4e688dce2bfedbdd781ed71e87d.tar.gz |
store the use locations for temporaries
-rw-r--r-- | lisc/lisc.h | 16 | ||||
-rw-r--r-- | lisc/ssa.c | 45 |
2 files changed, 54 insertions, 7 deletions
diff --git a/lisc/lisc.h b/lisc/lisc.h index 5748587..3643e48 100644 --- a/lisc/lisc.h +++ b/lisc/lisc.h @@ -14,6 +14,7 @@ typedef struct OpDesc OpDesc; typedef struct Ins Ins; typedef struct Phi Phi; typedef struct Blk Blk; +typedef struct Use Use; typedef struct Tmp Tmp; typedef struct Con Con; typedef struct Addr Mem; @@ -247,8 +248,23 @@ struct Blk { char name[NString]; }; +struct Use { + enum { + UXXX, + UPhi, + UIns, + UJmp, + } type; + int bid; + union { + int ins; + Ref phi; + } u; +}; + struct Tmp { char name[NString]; + Use *use; uint ndef, nuse; uint cost; short slot; diff --git a/lisc/ssa.c b/lisc/ssa.c index d628f15..2d4a373 100644 --- a/lisc/ssa.c +++ b/lisc/ssa.c @@ -1,4 +1,32 @@ #include "lisc.h" +#include <stdarg.h> + +static void +adduse(Tmp *tmp, int ty, Blk *b, ...) +{ + Use *u; + int n; + va_list ap; + + va_start(ap, b); + n = tmp->nuse; + vgrow(tmp->use, ++tmp->nuse); + u = &tmp->use[n]; + u->bid = b->id; + switch (ty) { + default: + diag("ssa: adduse defaulted"); + case UPhi: + u->u.phi = va_arg(ap, Ref); + break; + case UIns: + u->u.ins = va_arg(ap, Ins *) - b->ins; + break; + case UJmp: + break; + } + va_end(ap); +} /* fill usage and phi information */ @@ -8,7 +36,7 @@ filluse(Fn *fn) Blk *b; Phi *p; Ins *i; - int t; + int m, t; uint a; Tmp *tmp; @@ -18,6 +46,8 @@ filluse(Fn *fn) tmp[t].ndef = 0; tmp[t].nuse = 0; tmp[t].phi = 0; + if (tmp[t].use == 0) + tmp[t].use = vnew(0, sizeof(Use)); } for (b=fn->start; b; b=b->link) { for (p=b->phi; p; p=p->link) { @@ -27,7 +57,7 @@ filluse(Fn *fn) for (a=0; a<p->narg; a++) if (rtype(p->arg[a]) == RTmp) { t = p->arg[a].val; - tmp[t].nuse++; + adduse(&tmp[t], UPhi, b, p->to); if (!tmp[t].phi) tmp[t].phi = p->to.val; } @@ -37,13 +67,14 @@ filluse(Fn *fn) assert(rtype(i->to) == RTmp); tmp[i->to.val].ndef++; } - if (rtype(i->arg[0]) == RTmp) - tmp[i->arg[0].val].nuse++; - if (rtype(i->arg[1]) == RTmp) - tmp[i->arg[1].val].nuse++; + for (m=0; m<2; m++) + if (rtype(i->arg[m]) == RTmp) { + t = i->arg[m].val; + adduse(&tmp[t], UIns, b, i); + } } if (rtype(b->jmp.arg) == RTmp) - tmp[b->jmp.arg.val].nuse++; + adduse(&tmp[b->jmp.arg.val], UJmp, b); } } |