commit 2c4ff80a5962f0f37abada47d2b3af2a5e58834f
parent e839d44a1d0bf83eccfbac6e9c333569ec7be0d0
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Mon, 9 May 2016 10:30:15 +0200
[cc2] Move optm to target code
All the independent optimizations are done in cc1, so there is no much room
for target independent optimizations in cc2. At this moment these target
independent optimizations were done mainly because qbe needs them, but
we there are some changes that qbe needs that are not going to be
useful for other targets (and in some cases even they are going to be
worse).
Diffstat:
6 files changed, 75 insertions(+), 47 deletions(-)
diff --git a/cc2/Makefile b/cc2/Makefile
@@ -2,8 +2,9 @@
include ../config.mk
-OBJS = main.o parser.o optm.o peep.o symbol.o node.o code.o\
- arch/$(ARCH)/code.o arch/$(ARCH)/cgen.o arch/$(ARCH)/types.o
+OBJS = main.o parser.o peep.o symbol.o node.o code.o\
+ arch/$(ARCH)/code.o arch/$(ARCH)/cgen.o \
+ arch/$(ARCH)/types.o arch/$(ARCH)/optm.o
all: cc2
diff --git a/cc2/arch/amd64-sysv/optm.c b/cc2/arch/amd64-sysv/optm.c
@@ -0,0 +1,9 @@
+
+#include "arch.h"
+#include "../../cc2.h"
+
+Node *
+optm(Node *np)
+{
+ return np;
+}
diff --git a/cc2/arch/i386-sysv/optm.c b/cc2/arch/i386-sysv/optm.c
@@ -0,0 +1,9 @@
+
+#include "arch.h"
+#include "../../cc2.h"
+
+Node *
+optm(Node *np)
+{
+ return np;
+}
diff --git a/cc2/arch/qbe/optm.c b/cc2/arch/qbe/optm.c
@@ -0,0 +1,45 @@
+
+#include <stddef.h>
+
+#include "arch.h"
+#include "../../cc2.h"
+
+Node *
+optm(Node *np)
+{
+ Node *p, *dst, *next = np->next;
+ Symbol *sym, *osym;
+
+ switch (np->op) {
+ case ONOP:
+ if (next && next->op == ONOP) {
+ sym = np->u.sym;
+ osym = next->u.sym;
+ osym->id = sym->id;
+ osym->numid = sym->id;
+ osym->u.stmt = sym->u.stmt;
+ return NULL;
+ }
+ break;
+ case OJMP:
+ case OBRANCH:
+ for (;;) {
+ dst = np->u.sym->u.stmt;
+ if (dst->op != OJMP)
+ break;
+ np->u.sym = dst->u.sym;
+ }
+ for (p = np->next; p; p = p->next) {
+ if (p == dst)
+ return NULL;
+ if (p->op == ONOP ||
+ p->op == OBLOOP ||
+ p->op == OELOOP) {
+ continue;
+ }
+ break;
+ }
+ break;
+ }
+ return np;
+}
diff --git a/cc2/arch/z80/optm.c b/cc2/arch/z80/optm.c
@@ -0,0 +1,9 @@
+
+#include "arch.h"
+#include "../../cc2.h"
+
+Node *
+optm(Node *np)
+{
+ return np;
+}
diff --git a/cc2/optm.c b/cc2/optm.c
@@ -1,45 +0,0 @@
-
-#include <stddef.h>
-
-#include "arch.h"
-#include "cc2.h"
-
-Node *
-optm(Node *np)
-{
- Node *p, *dst, *next = np->next;
- Symbol *sym, *osym;
-
- switch (np->op) {
- case ONOP:
- if (next && next->op == ONOP) {
- sym = np->u.sym;
- osym = next->u.sym;
- osym->id = sym->id;
- osym->numid = sym->id;
- osym->u.stmt = sym->u.stmt;
- return NULL;
- }
- break;
- case OJMP:
- case OBRANCH:
- for (;;) {
- dst = np->u.sym->u.stmt;
- if (dst->op != OJMP)
- break;
- np->u.sym = dst->u.sym;
- }
- for (p = np->next; p; p = p->next) {
- if (p == dst)
- return NULL;
- if (p->op == ONOP ||
- p->op == OBLOOP ||
- p->op == OELOOP) {
- continue;
- }
- break;
- }
- break;
- }
- return np;
-}