ack/mach/proto/mcg/pass_removedeadblocks.c
David Given ed67d427c9 Replaced the block splicer with a trivial block eliminator (which rewrites
jumps to blocks which contain only a jump). Don't bother storing the bb graph
in the ir nodes; we can find it on demand by walking the tree instead ---
slower, but much easier to understand and more robust. Added a terrible map
library.
2016-09-23 23:59:15 +02:00

41 lines
748 B
C

#include "mcg.h"
STATICARRAY(struct basicblock, used);
static void walk_blocks(struct basicblock* bb);
static bool walk_blocks_cb(struct ir* ir, void* user)
{
if (ir->opcode == IR_BLOCK)
walk_blocks(ir->u.bvalue);
return false;
}
static void walk_blocks(struct basicblock* bb)
{
int i;
if (!CONTAINS(used, bb))
{
APPENDU(used, bb);
for (i=0; i<bb->irs_count; i++)
ir_walk(bb->irs[i], walk_blocks_cb, NULL);
}
}
void pass_remove_dead_blocks(struct procedure* proc)
{
int i, j;
used_count = 0;
walk_blocks(proc->blocks[0]);
proc->blocks_count = 0;
for (i=0; i<used_count; i++)
APPEND(proc->blocks, used[i]);
}
/* vim: set sw=4 ts=4 expandtab : */