Each pass now lives in its own source file; much cleaner.
This commit is contained in:
parent
9077baa850
commit
f8bbf9e87d
5 changed files with 89 additions and 74 deletions
|
@ -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)
|
void compile(struct procedure* proc)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
print_blocks('1', proc);
|
print_blocks('1', proc);
|
||||||
|
|
||||||
remove_dead_blocks(proc);
|
pass_remove_dead_blocks(proc);
|
||||||
|
pass_convert_stack_ops(proc);
|
||||||
for (i=0; i<proc->blocks_count; i++)
|
pass_splice_adjacent_blocks(proc);
|
||||||
sse_convert_block_parameters(proc->blocks[i]);
|
|
||||||
|
|
||||||
splice_adjacent_blocks(proc);
|
|
||||||
|
|
||||||
print_blocks('2', proc);
|
print_blocks('2', proc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,9 @@ extern void tb_fileend(void);
|
||||||
extern void tb_procedure(struct procedure* proc);
|
extern void tb_procedure(struct procedure* proc);
|
||||||
extern void tb_regvar(arith offset, int size, int type, int priority);
|
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);
|
extern void compile(struct procedure* proc);
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ static struct ir* get_first_pop(struct basicblock* bb)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sse_convert_block_parameters(struct basicblock* bb)
|
static void convert_block(struct basicblock* bb)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
struct ir* ir;
|
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 : */
|
/* vim: set sw=4 ts=4 expandtab : */
|
27
mach/proto/mcg/pass_deadblocks.c
Normal file
27
mach/proto/mcg/pass_deadblocks.c
Normal file
|
@ -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 : */
|
||||||
|
|
47
mach/proto/mcg/pass_spliceadjacentblocks.c
Normal file
47
mach/proto/mcg/pass_spliceadjacentblocks.c
Normal file
|
@ -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 : */
|
||||||
|
|
Loading…
Reference in a new issue