commit df61decee5095479f4760f36027a445d8d792373
parent a35dc8c495467306ca149d642b2d2983922d7a9d
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date: Fri, 24 Feb 2017 15:52:56 -0500
start a new simplification pass
Diffstat:
4 files changed, 51 insertions(+), 1 deletion(-)
diff --git 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
@@ -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
@@ -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
@@ -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;
+ }
+}