ref: 9e9929a75c4fdc24b941b0bdc371b54847752b88
parent: 0c581bc0c0bac79db689a457723af4a7e373467a
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Jun 16 07:41:22 EDT 2016
[cc2] Add basic support for basic blocks Basic blocks are going to be useful in the code generation of the majority of the targets, and in the case of qbe it can help with the label problem.
--- a/cc2/arch/amd64-sysv/code.c
+++ b/cc2/arch/amd64-sysv/code.c
@@ -201,3 +201,8 @@
endinit(void)
{
}
+
+void
+getbblocks(void)
+{
+}
--- a/cc2/arch/i386-sysv/code.c
+++ b/cc2/arch/i386-sysv/code.c
@@ -200,3 +200,8 @@
endinit(void)
{
}
+
+void
+getbblocks(void)
+{
+}
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -466,3 +466,34 @@
{
puts("}");
}
+
+void
+getbblocks(void)
+{
+ Inst *i;
+
+ if (!prog)
+ return;
+
+ prog->flags |= BBENTRY;
+ for (pc = prog; pc; pc = pc->next) {
+ switch (pc->op) {
+ case ASBRANCH:
+ i = pc->from2.u.sym->u.inst;
+ i->flags |= BBENTRY;
+ case ASJMP:
+ i = pc->from1.u.sym->u.inst;
+ i->flags |= BBENTRY;
+ case ASRET:
+ case ASCALLB:
+ case ASCALLH:
+ case ASCALLW:
+ case ASCALLS:
+ case ASCALLL:
+ case ASCALLD:
+ case ASCALL:
+ pc->flags |= BBENTRY;
+ break;
+ }
+ }
+}
--- a/cc2/arch/z80/code.c
+++ b/cc2/arch/z80/code.c
@@ -219,3 +219,8 @@
endinit(void)
{
}
+
+void
+getbblocks(void)
+{
+}
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -1,4 +1,9 @@
/* See LICENSE file for copyright and license details. */
+
+enum iflags {
+ BBENTRY = 1,
+};
+
enum tflags {
SIGNF = 1,
INTF = 2,
@@ -179,9 +184,10 @@
struct inst {
unsigned char op;
+ unsigned char flags;
Symbol *label;
- Addr from1, from2, to;
Inst *next, *prev;
+ Addr from1, from2, to;
};
/* main.c */
@@ -205,7 +211,7 @@
extern void writeout(void), endinit(void), newfun(void);
extern void code(int op, Node *to, Node *from1, Node *from2);
extern void defvar(Symbol *), defpar(Symbol *), defglobal(Symbol *);
-extern void setlabel(Symbol *sym);
+extern void setlabel(Symbol *sym), getbblocks(void);
extern Node *label2node(Symbol *sym);
extern Symbol *newlabel(void);
--- a/cc2/code.c
+++ b/cc2/code.c
@@ -22,6 +22,7 @@
}
new->prev = pc;
+ new->flags = 0;
new->to.kind = new->from2.kind = new->from1.kind = SNONE;
pc = new;
}
--- a/cc2/main.c
+++ b/cc2/main.c
@@ -48,6 +48,7 @@
apply(optm_dep);
apply(sethi);
apply(cgen);
+ getbblocks(); /* TODO: run apply over asm ins too */
peephole();
writeout();
}
--
⑨