Each pass now lives in its own source file; much cleaner.
authorDavid Given <dg@cowlark.com>
Fri, 23 Sep 2016 19:07:16 +0000 (21:07 +0200)
committerDavid Given <dg@cowlark.com>
Fri, 23 Sep 2016 19:07:16 +0000 (21:07 +0200)
mach/proto/mcg/compile.c
mach/proto/mcg/mcg.h
mach/proto/mcg/pass_convertstackops.c [moved from mach/proto/mcg/sse.c with 92% similarity]
mach/proto/mcg/pass_deadblocks.c [new file with mode: 0644]
mach/proto/mcg/pass_spliceadjacentblocks.c [new file with mode: 0644]

index 8d147a6..e9fb86b 100644 (file)
@@ -34,84 +34,15 @@ static void print_blocks(char k, struct procedure* proc)
        }
 }
 
-static void remove_dead_blocks(struct procedure* proc)
-{
-    int i, j;
-
-again:
-    /* Starts at 1 because we don't want to remove the root block! */
-    for (i=1; i<proc->blocks_count; i++)
-    {
-        struct basicblock* bb = proc->blocks[i];
-        
-        if (bb->inblocks_count == 0)
-        {
-            /* Nobody uses this block; disconnect it from its output
-             * blocks. */
-            for (j=0; j<bb->outblocks_count; j++)
-                REMOVE(bb->outblocks[j]->inblocks, bb);
-
-            REMOVE(proc->blocks, bb);
-            goto again;
-        }
-    }
-}
-
-static void splice_adjacent_blocks(struct procedure* proc)
-{
-    int i, j;
-
-again:
-    for (i=0; i<proc->blocks_count; i++)
-    {
-        struct basicblock* bb = proc->blocks[i];
-        if (bb->outblocks_count == 1)
-        {
-            struct basicblock* outbb = bb->outblocks[0];
-            if (outbb->inblocks_count == 1)
-            {
-                struct ir* lastir = bb->irs[bb->irs_count-1];
-
-                if ((lastir->opcode == IR_JUMP)
-                    && (lastir->left->opcode == IR_BLOCK)
-                    && (lastir->left->u.bvalue == outbb))
-                {
-                    /* Remove jump instruction. */
-
-                    bb->irs_count--; 
-
-                    REMOVE(bb->outblocks, outbb);
-                    REMOVE(outbb->inblocks, bb);
-
-                    for (j=0; j<outbb->irs_count; j++)
-                        APPEND(bb->irs, outbb->irs[j]);
-                    for (j=0; j<outbb->outblocks_count; j++)
-                    {
-                        APPENDU(bb->outblocks, outbb->outblocks[j]);
-                        APPENDU(outbb->outblocks[j]->inblocks, bb);
-                        REMOVE(outbb->outblocks[j]->inblocks, outbb);
-                    }
-
-                    REMOVE(proc->blocks, outbb);
-                    goto again;
-                }
-            }
-        }
-    }
-}
-
 void compile(struct procedure* proc)
 {
        int i;
 
        print_blocks('1', proc);
 
-    remove_dead_blocks(proc);
-
-    for (i=0; i<proc->blocks_count; i++)
-        sse_convert_block_parameters(proc->blocks[i]);
-
-    splice_adjacent_blocks(proc);
+    pass_remove_dead_blocks(proc);
+    pass_convert_stack_ops(proc);
+    pass_splice_adjacent_blocks(proc);
 
     print_blocks('2', proc);
 }
index bcc6ff4..1f66ef2 100644 (file)
@@ -114,7 +114,9 @@ extern void tb_fileend(void);
 extern void tb_procedure(struct procedure* proc);
 extern void tb_regvar(arith offset, int size, int type, int priority);
 
-extern void sse_convert_block_parameters(struct basicblock* bb);
+extern void pass_convert_stack_ops(struct procedure* proc);
+extern void pass_remove_dead_blocks(struct procedure* proc);
+extern void pass_splice_adjacent_blocks(struct procedure* proc);
 
 extern void compile(struct procedure* proc);
 
similarity index 92%
rename from mach/proto/mcg/sse.c
rename to mach/proto/mcg/pass_convertstackops.c
index 3c57a3f..6ee90bd 100644 (file)
@@ -37,7 +37,7 @@ static struct ir* get_first_pop(struct basicblock* bb)
     return NULL;
 }
 
-void sse_convert_block_parameters(struct basicblock* bb)
+static void convert_block(struct basicblock* bb)
 {
     int i, j;
     struct ir* ir;
@@ -96,4 +96,12 @@ void sse_convert_block_parameters(struct basicblock* bb)
     }
 }
 
+void pass_convert_stack_ops(struct procedure* proc)
+{
+    int i;
+
+    for (i=0; i<proc->blocks_count; i++)
+        convert_block(proc->blocks[i]);
+}
+
 /* vim: set sw=4 ts=4 expandtab : */
diff --git a/mach/proto/mcg/pass_deadblocks.c b/mach/proto/mcg/pass_deadblocks.c
new file mode 100644 (file)
index 0000000..94c8735
--- /dev/null
@@ -0,0 +1,27 @@
+#include "mcg.h"
+
+void pass_remove_dead_blocks(struct procedure* proc)
+{
+    int i, j;
+
+again:
+    /* Starts at 1 because we don't want to remove the root block! */
+    for (i=1; i<proc->blocks_count; i++)
+    {
+        struct basicblock* bb = proc->blocks[i];
+        
+        if (bb->inblocks_count == 0)
+        {
+            /* Nobody uses this block; disconnect it from its output
+             * blocks. */
+            for (j=0; j<bb->outblocks_count; j++)
+                REMOVE(bb->outblocks[j]->inblocks, bb);
+
+            REMOVE(proc->blocks, bb);
+            goto again;
+        }
+    }
+}
+
+/* vim: set sw=4 ts=4 expandtab : */
+
diff --git a/mach/proto/mcg/pass_spliceadjacentblocks.c b/mach/proto/mcg/pass_spliceadjacentblocks.c
new file mode 100644 (file)
index 0000000..7f6a69b
--- /dev/null
@@ -0,0 +1,47 @@
+#include "mcg.h"
+
+void pass_splice_adjacent_blocks(struct procedure* proc)
+{
+    int i, j;
+
+again:
+    for (i=0; i<proc->blocks_count; i++)
+    {
+        struct basicblock* bb = proc->blocks[i];
+        if (bb->outblocks_count == 1)
+        {
+            struct basicblock* outbb = bb->outblocks[0];
+            if (outbb->inblocks_count == 1)
+            {
+                struct ir* lastir = bb->irs[bb->irs_count-1];
+
+                if ((lastir->opcode == IR_JUMP)
+                    && (lastir->left->opcode == IR_BLOCK)
+                    && (lastir->left->u.bvalue == outbb))
+                {
+                    /* Remove jump instruction. */
+
+                    bb->irs_count--; 
+
+                    REMOVE(bb->outblocks, outbb);
+                    REMOVE(outbb->inblocks, bb);
+
+                    for (j=0; j<outbb->irs_count; j++)
+                        APPEND(bb->irs, outbb->irs[j]);
+                    for (j=0; j<outbb->outblocks_count; j++)
+                    {
+                        APPENDU(bb->outblocks, outbb->outblocks[j]);
+                        APPENDU(outbb->outblocks[j]->inblocks, bb);
+                        REMOVE(outbb->outblocks[j]->inblocks, outbb);
+                    }
+
+                    REMOVE(proc->blocks, outbb);
+                    goto again;
+                }
+            }
+        }
+    }
+}
+
+/* vim: set sw=4 ts=4 expandtab : */
+