ack/mach/proto/mcg/pass_removedeadblocks.c
2016-09-26 22:48:58 +02:00

41 lines
785 B
C

#include "mcg.h"
static ARRAYOF(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 (!array_contains(&used, bb))
{
array_append(&used, bb);
for (i=0; i<bb->irs.count; i++)
ir_walk(bb->irs.item[i], walk_blocks_cb, NULL);
}
}
void pass_remove_dead_blocks(struct procedure* proc)
{
int i, j;
used.count = 0;
walk_blocks(proc->blocks.item[0]);
proc->blocks.count = 0;
for (i=0; i<used.count; i++)
array_append(&proc->blocks, used.item[i]);
}
/* vim: set sw=4 ts=4 expandtab : */