2016-09-23 21:59:15 +00:00
|
|
|
#include "mcg.h"
|
|
|
|
|
2016-09-26 20:48:58 +00:00
|
|
|
static ARRAYOF(struct basicblock) used;
|
2016-09-23 21:59:15 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2016-09-26 20:48:58 +00:00
|
|
|
if (!array_contains(&used, bb))
|
2016-09-23 21:59:15 +00:00
|
|
|
{
|
2016-09-26 20:48:58 +00:00
|
|
|
array_append(&used, bb);
|
2016-09-23 21:59:15 +00:00
|
|
|
|
2016-09-26 20:48:58 +00:00
|
|
|
for (i=0; i<bb->irs.count; i++)
|
|
|
|
ir_walk(bb->irs.item[i], walk_blocks_cb, NULL);
|
2016-09-23 21:59:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-15 21:19:44 +00:00
|
|
|
void pass_remove_dead_blocks(void)
|
2016-09-23 21:59:15 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
2016-09-26 20:48:58 +00:00
|
|
|
used.count = 0;
|
2016-10-15 21:19:44 +00:00
|
|
|
walk_blocks(current_proc->blocks.item[0]);
|
2016-09-23 21:59:15 +00:00
|
|
|
|
2016-10-15 21:19:44 +00:00
|
|
|
current_proc->blocks.count = 0;
|
2016-09-26 20:48:58 +00:00
|
|
|
for (i=0; i<used.count; i++)
|
2016-10-15 21:19:44 +00:00
|
|
|
array_append(¤t_proc->blocks, used.item[i]);
|
2016-09-23 21:59:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set sw=4 ts=4 expandtab : */
|
|
|
|
|