[hackers] [scc] [cc2] Add basic support for basic blocks || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Thu, 16 Jun 2016 11:43:33 +0200 (CEST)

commit 5b7040998d5b60b95e827094a4412973fb7db862
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Jun 16 11:41:22 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Thu Jun 16 11:41:22 2016 +0200

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

diff --git a/cc2/arch/amd64-sysv/code.c b/cc2/arch/amd64-sysv/code.c
index d223ecb..1a374d4 100644
--- a/cc2/arch/amd64-sysv/code.c
+++ b/cc2/arch/amd64-sysv/code.c
_AT_@ -201,3 +201,8 @@ void
 endinit(void)
 {
 }
+
+void
+getbblocks(void)
+{
+}
diff --git a/cc2/arch/i386-sysv/code.c b/cc2/arch/i386-sysv/code.c
index c85b341..5238908 100644
--- a/cc2/arch/i386-sysv/code.c
+++ b/cc2/arch/i386-sysv/code.c
_AT_@ -200,3 +200,8 @@ void
 endinit(void)
 {
 }
+
+void
+getbblocks(void)
+{
+}
diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index f675618..805ff0b 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -466,3 +466,34 @@ endinit(void)
 {
         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;
+ }
+ }
+}
diff --git a/cc2/arch/z80/code.c b/cc2/arch/z80/code.c
index 0c4e860..b15f58e 100644
--- a/cc2/arch/z80/code.c
+++ b/cc2/arch/z80/code.c
_AT_@ -219,3 +219,8 @@ void
 endinit(void)
 {
 }
+
+void
+getbblocks(void)
+{
+}
diff --git a/cc2/cc2.h b/cc2/cc2.h
index 00528da..13a7b8d 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
_AT_@ -1,4 +1,9 @@
 /* See LICENSE file for copyright and license details. */
+
+enum iflags {
+ BBENTRY = 1,
+};
+
 enum tflags {
         SIGNF = 1,
         INTF = 2,
_AT_@ -179,9 +184,10 @@ struct addr {
 
 struct inst {
         unsigned char op;
+ unsigned char flags;
         Symbol *label;
- Addr from1, from2, to;
         Inst *next, *prev;
+ Addr from1, from2, to;
 };
 
 /* main.c */
_AT_@ -205,7 +211,7 @@ extern void data(Node *np);
 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);
 
diff --git a/cc2/code.c b/cc2/code.c
index ba7c616..722f288 100644
--- a/cc2/code.c
+++ b/cc2/code.c
_AT_@ -22,6 +22,7 @@ nextpc(void)
         }
 
         new->prev = pc;
+ new->flags = 0;
         new->to.kind = new->from2.kind = new->from1.kind = SNONE;
         pc = new;
 }
diff --git a/cc2/main.c b/cc2/main.c
index 4850815..924f862 100644
--- a/cc2/main.c
+++ b/cc2/main.c
_AT_@ -48,6 +48,7 @@ main(int argc, char *argv[])
                 apply(optm_dep);
                 apply(sethi);
                 apply(cgen);
+ getbblocks(); /* TODO: run apply over asm ins too */
                 peephole();
                 writeout();
         }
Received on Thu Jun 16 2016 - 11:43:33 CEST

This archive was generated by hypermail 2.3.0 : Thu Jun 16 2016 - 11:48:18 CEST