aboutsummaryrefslogtreecommitdiff
path: root/simpl.c
diff options
context:
space:
mode:
authorQuentin Carbonneaux <[email protected]>2017-02-24 15:52:56 -0500
committerQuentin Carbonneaux <[email protected]>2017-02-24 15:52:56 -0500
commitdf61decee5095479f4760f36027a445d8d792373 (patch)
tree57518bc097906385a8c9d143a47194052606c07a /simpl.c
parenta35dc8c495467306ca149d642b2d2983922d7a9d (diff)
start a new simplification pass
Diffstat (limited to 'simpl.c')
-rw-r--r--simpl.c46
1 files changed, 46 insertions, 0 deletions
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;
+ }
+}