From f8bbf9e87d37dbfac29705679381446c08d7dce1 Mon Sep 17 00:00:00 2001 From: David Given Date: Fri, 23 Sep 2016 21:07:16 +0200 Subject: [PATCH] Each pass now lives in its own source file; much cleaner. --- mach/proto/mcg/compile.c | 75 +------------------ mach/proto/mcg/mcg.h | 4 +- .../mcg/{sse.c => pass_convertstackops.c} | 10 ++- mach/proto/mcg/pass_deadblocks.c | 27 +++++++ mach/proto/mcg/pass_spliceadjacentblocks.c | 47 ++++++++++++ 5 files changed, 89 insertions(+), 74 deletions(-) rename mach/proto/mcg/{sse.c => pass_convertstackops.c} (92%) create mode 100644 mach/proto/mcg/pass_deadblocks.c create mode 100644 mach/proto/mcg/pass_spliceadjacentblocks.c diff --git a/mach/proto/mcg/compile.c b/mach/proto/mcg/compile.c index 8d147a61a..e9fb86be2 100644 --- a/mach/proto/mcg/compile.c +++ b/mach/proto/mcg/compile.c @@ -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; iblocks_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; joutblocks_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; iblocks_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; jirs_count; j++) - APPEND(bb->irs, outbb->irs[j]); - for (j=0; joutblocks_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; iblocks_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); } diff --git a/mach/proto/mcg/mcg.h b/mach/proto/mcg/mcg.h index bcc6ff4b6..1f66ef249 100644 --- a/mach/proto/mcg/mcg.h +++ b/mach/proto/mcg/mcg.h @@ -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); diff --git a/mach/proto/mcg/sse.c b/mach/proto/mcg/pass_convertstackops.c similarity index 92% rename from mach/proto/mcg/sse.c rename to mach/proto/mcg/pass_convertstackops.c index 3c57a3f8b..6ee90bda9 100644 --- a/mach/proto/mcg/sse.c +++ b/mach/proto/mcg/pass_convertstackops.c @@ -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; iblocks_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 index 000000000..94c8735cc --- /dev/null +++ b/mach/proto/mcg/pass_deadblocks.c @@ -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; iblocks_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; joutblocks_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 index 000000000..7f6a69b98 --- /dev/null +++ b/mach/proto/mcg/pass_spliceadjacentblocks.c @@ -0,0 +1,47 @@ +#include "mcg.h" + +void pass_splice_adjacent_blocks(struct procedure* proc) +{ + int i, j; + +again: + for (i=0; iblocks_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; jirs_count; j++) + APPEND(bb->irs, outbb->irs[j]); + for (j=0; joutblocks_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 : */ + -- 2.34.1