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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pass_remove_dead_blocks(struct procedure* proc)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
2016-09-26 20:48:58 +00:00
|
|
|
used.count = 0;
|
|
|
|
walk_blocks(proc->blocks.item[0]);
|
2016-09-23 21:59:15 +00:00
|
|
|
|
2016-09-26 20:48:58 +00:00
|
|
|
proc->blocks.count = 0;
|
|
|
|
for (i=0; i<used.count; i++)
|
|
|
|
array_append(&proc->blocks, used.item[i]);
|
2016-09-23 21:59:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set sw=4 ts=4 expandtab : */
|
|
|
|
|