commit fea73f0b34c2e192b38362e6468870a1c1ce312a
parent ecf29f6e95d44f013c47a2d907eea21b2bb5d934
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 26 Dec 2024 22:19:00 +0100
cc2: Add information about basic blocks
Nodes can be grouped into basic blocks composed of a set
of consecutive statements without branches or jumps that
are executed sequentially from the entry point to the
exit point.
Diffstat:
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/src/cmd/scc-cc/cc2/cc2.h b/src/cmd/scc-cc/cc2/cc2.h
@@ -2,6 +2,7 @@
enum iflags {
BBENTRY = 1, /* basic block entry */
+ BBEXIT = 2, /* basic block exit */
};
enum tflags {
@@ -152,6 +153,7 @@ typedef struct type Type;
typedef struct symbol Symbol;
typedef struct addr Addr;
typedef struct inst Inst;
+typedef struct block Block;
struct type {
unsigned long size;
@@ -193,10 +195,19 @@ struct node {
long off;
} u;
Symbol *label;
+ Block *bb;
Node *left, *right;
Node *next, *prev;
};
+struct block {
+ int id;
+ int printed, visited;
+ Node *entryp, *exitp;
+ Block *true, *false;
+ Block *next;
+};
+
struct addr {
char kind;
union {
diff --git a/src/cmd/scc-cc/cc2/node.c b/src/cmd/scc-cc/cc2/node.c
@@ -43,6 +43,16 @@ prnode(Node *np)
void
prtree(Node *np)
{
+ Block *bb;
+
+ bb = np->bb;
+
+ if (np->flags & BBENTRY)
+ putc('>', stderr);
+ fprintf(stderr, "(%d)", bb ? bb->id : 0);
+ if (np->flags & BBEXIT)
+ putc('>', stderr);
+
prnode(np);
putc('\n', stderr);
}
@@ -55,7 +65,7 @@ prforest(char *msg)
if (!curfun)
return;
- fprintf(stderr, "%s {\n", msg);
+ fprintf(stderr, "tree %s {\n", msg);
for (np = curfun->u.stmt; np; np = np->next)
prtree(np);
fputs("}\n", stderr);