summary refs log tree commit diff
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2017-02-24 15:52:56 -0500
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2017-02-24 15:52:56 -0500
commitdf61decee5095479f4760f36027a445d8d792373 (patch)
tree57518bc097906385a8c9d143a47194052606c07a
parenta35dc8c495467306ca149d642b2d2983922d7a9d (diff)
downloadroux-df61decee5095479f4760f36027a445d8d792373.tar.gz
start a new simplification pass
-rw-r--r--Makefile2
-rw-r--r--all.h3
-rw-r--r--main.c1
-rw-r--r--simpl.c46
4 files changed, 51 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index fc649f8..4040923 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ ABI = sysv
 V = @
 OBJDIR = obj
 
-SRC = main.c util.c parse.c cfg.c mem.c ssa.c alias.c load.c copy.c fold.c live.c $(ABI).c isel.c spill.c rega.c emit.c
+SRC = main.c util.c parse.c cfg.c mem.c ssa.c alias.c load.c simpl.c copy.c fold.c live.c $(ABI).c isel.c spill.c rega.c emit.c
 OBJ = $(SRC:%.c=$(OBJDIR)/%.o)
 
 CFLAGS += -Wall -Wextra -std=c99 -g -pedantic
diff --git a/all.h b/all.h
index 128d16c..f518a36 100644
--- a/all.h
+++ b/all.h
@@ -588,6 +588,9 @@ void fillrpo(Fn *);
 void ssa(Fn *);
 void ssacheck(Fn *);
 
+/* simpl.c */
+void simpl(Fn *);
+
 /* copy.c */
 void copy(Fn *);
 
diff --git a/main.c b/main.c
index fe68ae0..1a8973f 100644
--- a/main.c
+++ b/main.c
@@ -59,6 +59,7 @@ func(Fn *fn)
 	loadopt(fn);
 	filluse(fn);
 	ssacheck(fn);
+	simpl(fn);
 	copy(fn);
 	filluse(fn);
 	fold(fn);
diff --git a/simpl.c b/simpl.c
new file mode 100644
index 0000000..384a8da
--- /dev/null
+++ b/simpl.c
@@ -0,0 +1,46 @@
+#include "all.h"
+
+static void
+elimext(Ins *i, int ext, Fn *fn)
+{
+	Tmp *t;
+	Use *u;
+
+	assert(rtype(i->to) == RTmp);
+	t = &fn->tmp[i->to.val];
+	for (u=t->use; u<&t->use[t->nuse]; u++)
+		if (u->type == UIns
+		&& u->u.ins->op == ext
+		&& (u->u.ins->cls == i->cls || i->cls == Kl)) {
+			u->u.ins->op = Ocopy;
+			elimext(u->u.ins, ext, fn);
+		}
+}
+
+/* requires & preserves uses */
+void
+simpl(Fn *fn)
+{
+	Blk *b;
+	Ins *i;
+	int ext;
+
+	for (b=fn->start; b; b=b->link)
+		for (i=b->ins; i<&b->ins[b->nins]; i++)
+			switch (i->op) {
+			case Oloadsb:
+			case Oloadub:
+			case Oloadsh:
+			case Oloaduh:
+				ext = Oextsb + (i->op - Oloadsb);
+				goto Elimext;
+			case Oextsb:
+			case Oextub:
+			case Oextsh:
+			case Oextuh:
+				ext = i->op;
+			Elimext:
+				elimext(i, ext, fn);
+				break;
+			}
+}