diff options
author | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2016-04-09 14:21:56 -0400 |
---|---|---|
committer | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2016-04-09 14:21:56 -0400 |
commit | 1e0f18e9086b825d6fc941bf37306ae2823f0341 (patch) | |
tree | 71b5ebe09b04fa44465fd98a559a6a3541acd8c9 | |
parent | 081360df6a06979852de977a4d4e56f3c4481a81 (diff) | |
download | roux-1e0f18e9086b825d6fc941bf37306ae2823f0341.tar.gz |
add a proper block deletion routine
-rw-r--r-- | all.h | 1 | ||||
-rw-r--r-- | fold.c | 2 | ||||
-rw-r--r-- | ssa.c | 2 | ||||
-rw-r--r-- | util.c | 24 |
4 files changed, 27 insertions, 2 deletions
diff --git a/all.h b/all.h index 0629e1c..c9b52b0 100644 --- a/all.h +++ b/all.h @@ -481,6 +481,7 @@ void *emalloc(size_t); void *alloc(size_t); void freeall(void); Blk *blknew(void); +void blkdel(Blk *); void emit(int, int, Ref, Ref, Ref); void emiti(Ins); void idup(Ins **, Ins *, ulong); diff --git a/fold.c b/fold.c index c8466e4..e9d9228 100644 --- a/fold.c +++ b/fold.c @@ -254,7 +254,7 @@ fold(Fn *fn) d = 1; if (debug['F']) fprintf(stderr, "%s ", b->name); - // blkdel(pb); + blkdel(b); *pb = b->link; continue; } diff --git a/ssa.c b/ssa.c index 201f22c..77c6258 100644 --- a/ssa.c +++ b/ssa.c @@ -161,8 +161,8 @@ fillrpo(Fn *f) for (p=&f->start; *p;) { b = *p; if (b->id == -1) { + blkdel(b); *p = b->link; - /* todo, free block */ } else { b->id -= n; f->rpo[b->id] = b; diff --git a/util.c b/util.c index 51d7e58..15f9dea 100644 --- a/util.c +++ b/util.c @@ -98,6 +98,30 @@ blknew() } void +blkdel(Blk *b) +{ + Blk *s, **ps; + Phi *p; + uint a; + + for (ps=(Blk*[]){b->s1, b->s2, 0}; (s=*ps); ps++) { + for (p=s->phi; p; p=p->link) { + for (a=0; p->blk[a]!=b; a++) + assert(a+1<p->narg); + p->narg--; + memcpy(&p->blk[a], &p->blk[a+1], p->narg-a); + memcpy(&p->arg[a], &p->arg[a+1], p->narg-a); + } + if (s->npred != 0) { + for (a=0; s->pred[a]!=b; a++) + assert(a+1<s->npred); + s->npred--; + memcpy(&s->pred[a], &s->pred[a+1], s->npred-a); + } + } +} + +void emit(int op, int k, Ref to, Ref arg0, Ref arg1) { if (curi == insb) |