qbe

Internal scc patchset buffer for QBE
Log | Files | Refs | README | LICENSE

commit 1e0f18e9086b825d6fc941bf37306ae2823f0341
parent 081360df6a06979852de977a4d4e56f3c4481a81
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date:   Sat,  9 Apr 2016 14:21:56 -0400

add a proper block deletion routine

Diffstat:
Mall.h | 1+
Mfold.c | 2+-
Mssa.c | 2+-
Mutil.c | 24++++++++++++++++++++++++
4 files changed, 27 insertions(+), 2 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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)