shithub: scc

Download patch

ref: 2c2a9652ce246e092bcb3e3801d7ab434724fd45
parent: ce03e9ba4b39cc668444a5678a6686d70669f111
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon May 9 06:30:15 EDT 2016

[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).

--- 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
 
--- /dev/null
+++ b/cc2/arch/amd64-sysv/optm.c
@@ -1,0 +1,9 @@
+
+#include "arch.h"
+#include "../../cc2.h"
+
+Node *
+optm(Node *np)
+{
+	return np;
+}
--- /dev/null
+++ b/cc2/arch/i386-sysv/optm.c
@@ -1,0 +1,9 @@
+
+#include "arch.h"
+#include "../../cc2.h"
+
+Node *
+optm(Node *np)
+{
+	return np;
+}
--- /dev/null
+++ b/cc2/arch/qbe/optm.c
@@ -1,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;
+}
--- /dev/null
+++ b/cc2/arch/z80/optm.c
@@ -1,0 +1,9 @@
+
+#include "arch.h"
+#include "../../cc2.h"
+
+Node *
+optm(Node *np)
+{
+	return np;
+}
--- a/cc2/optm.c
+++ /dev/null
@@ -1,45 +1,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;
-}