commit 0fc70b67c3a3d5242809249cd0ca56fa09873b52
parent 46f7ea655c0f4f25e851b9197487269529eb5641
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 10 Dec 2024 10:07:47 +0100
cc2: Remove opts from main loop
These functions are better in the target itsels
that knows when optimizations should be applied
or not.
Diffstat:
13 files changed, 52 insertions(+), 102 deletions(-)
diff --git a/src/cmd/scc-cc/cc2/Makefile b/src/cmd/scc-cc/cc2/Makefile
@@ -18,7 +18,6 @@ OBJS =\
code.o\
main.o\
node.o\
- optm.o\
parser.o\
symbol.o\
diff --git a/src/cmd/scc-cc/cc2/amd64-sysv/Makefile b/src/cmd/scc-cc/cc2/amd64-sysv/Makefile
@@ -7,7 +7,6 @@ include $(PROJECTDIR)/scripts/rules.mk
OBJS =\
cgen.o \
code.o \
- optm.o \
peep.o \
types.o \
diff --git a/src/cmd/scc-cc/cc2/amd64-sysv/optm.c b/src/cmd/scc-cc/cc2/amd64-sysv/optm.c
@@ -1,9 +0,0 @@
-#include <scc/scc.h>
-
-#include "../cc2.h"
-
-Node *
-optm_dep(Node *np)
-{
- return np;
-}
diff --git a/src/cmd/scc-cc/cc2/cc2.h b/src/cmd/scc-cc/cc2/cc2.h
@@ -217,9 +217,6 @@ extern void error(unsigned nerror, ...);
/* parse.c */
extern void parse(void);
-/* optm.c */
-extern Node *optm_dep(Node *np), *optm_ind(Node *np);
-
/* cgen.c */
extern Node *sethi(Node *np);
extern void genasm(void);
diff --git a/src/cmd/scc-cc/cc2/i386-sysv/Makefile b/src/cmd/scc-cc/cc2/i386-sysv/Makefile
@@ -7,7 +7,6 @@ include $(PROJECTDIR)/scripts/rules.mk
OBJS =\
cgen.o \
code.o \
- optm.o \
peep.o \
types.o \
diff --git a/src/cmd/scc-cc/cc2/i386-sysv/optm.c b/src/cmd/scc-cc/cc2/i386-sysv/optm.c
@@ -1,9 +0,0 @@
-#include <scc/scc.h>
-
-#include "../cc2.h"
-
-Node *
-optm_dep(Node *np)
-{
- return np;
-}
diff --git a/src/cmd/scc-cc/cc2/main.c b/src/cmd/scc-cc/cc2/main.c
@@ -57,8 +57,6 @@ main(int argc, char *argv[])
while (moreinput()) {
parse();
- apply(optm_ind);
- apply(optm_dep);
apply(sethi);
genasm();
peephole();
diff --git a/src/cmd/scc-cc/cc2/optm.c b/src/cmd/scc-cc/cc2/optm.c
@@ -1,9 +0,0 @@
-#include <scc/scc.h>
-#include "cc2.h"
-
-Node *
-optm_ind(Node *np)
-{
- return np;
-}
-
diff --git a/src/cmd/scc-cc/cc2/qbe/Makefile b/src/cmd/scc-cc/cc2/qbe/Makefile
@@ -7,7 +7,6 @@ include $(PROJECTDIR)/scripts/rules.mk
OBJS =\
cgen.o \
code.o \
- optm.o \
peep.o \
all: builtin.o
diff --git a/src/cmd/scc-cc/cc2/qbe/cgen.c b/src/cmd/scc-cc/cc2/qbe/cgen.c
@@ -787,9 +787,61 @@ cgen(Node *np)
return NULL;
}
+static Node *
+norm(Node *np)
+{
+ int op = np->op;
+ Node *p, *dst, *next = np->next;
+ Symbol *sym, *osym;
+
+ switch (op) {
+ case OEFUN:
+ /*
+ * In QBE we need at the end of a basic block
+ * a jump, so we have to ensure that the last
+ * statement of the function is a ret, a jmp
+ * or a branch. In the same way, QBE does
+ * not accept labels at the end of a function
+ * (ONOP is used for labels) so we have to add
+ * a ret there, and in the case of branches
+ * we need a label for the next statement
+ */
+ op = (np->prev) ? np->prev->op : 0;
+ if (!op || op == ONOP || op == OBRANCH || (op != ORET && op != OJMP))
+ addstmt(node(ORET), KEEPCUR);
+ break;
+ case OBRANCH:
+ if (!next->label) {
+ sym = getsym(TMPSYM);
+ sym->kind = SLABEL;
+ next->label = sym;
+ }
+ case OJMP:
+ 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;
+}
+
void
genasm(void)
{
+ apply(norm);
apply(cgen);
getbblocks();
}
diff --git a/src/cmd/scc-cc/cc2/qbe/optm.c b/src/cmd/scc-cc/cc2/qbe/optm.c
@@ -1,56 +0,0 @@
-#include <stddef.h>
-
-#include <scc/scc.h>
-
-#include "../cc2.h"
-
-Node *
-optm_dep(Node *np)
-{
- int op = np->op;
- Node *p, *dst, *next = np->next;
- Symbol *sym, *osym;
-
- switch (op) {
- case OEFUN:
- /*
- * In QBE we need at the end of a basic block
- * a jump, so we have to ensure that the last
- * statement of the function is a ret, a jmp
- * or a branch. In the same way, QBE does
- * not accept labels at the end of a function
- * (ONOP is used for labels) so we have to add
- * a ret there, and in the case of branches
- * we need a label for the next statement
- */
- op = (np->prev) ? np->prev->op : 0;
- if (!op || op == ONOP || op == OBRANCH || (op != ORET && op != OJMP))
- addstmt(node(ORET), KEEPCUR);
- break;
- case OBRANCH:
- if (!next->label) {
- sym = getsym(TMPSYM);
- sym->kind = SLABEL;
- next->label = sym;
- }
- case OJMP:
- 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/src/cmd/scc-cc/cc2/z80-scc/Makefile b/src/cmd/scc-cc/cc2/z80-scc/Makefile
@@ -7,7 +7,6 @@ include $(PROJECTDIR)/scripts/rules.mk
OBJS =\
cgen.o \
code.o \
- optm.o \
peep.o \
types.o \
diff --git a/src/cmd/scc-cc/cc2/z80-scc/optm.c b/src/cmd/scc-cc/cc2/z80-scc/optm.c
@@ -1,9 +0,0 @@
-#include <scc/scc.h>
-
-#include "../cc2.h"
-
-Node *
-optm_dep(Node *np)
-{
- return np;
-}