summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--all.h1
-rw-r--r--fold.c2
-rw-r--r--ssa.c2
-rw-r--r--util.c24
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)