2016-09-23 21:59:15 +00:00
|
|
|
#include "mcg.h"
|
|
|
|
|
|
|
|
static bool rewrite_jumps_cb(struct ir* ir, void* user)
|
|
|
|
{
|
|
|
|
if (ir->opcode == IR_BLOCK)
|
|
|
|
{
|
|
|
|
struct basicblock* bb = ir->u.bvalue;
|
2016-09-23 23:04:00 +00:00
|
|
|
if (!bb->is_fake
|
2016-09-26 20:48:58 +00:00
|
|
|
&& (bb->irs.count > 0)
|
|
|
|
&& (bb->irs.item[0]->opcode == IR_JUMP)
|
|
|
|
&& (bb->irs.item[0]->left->opcode == IR_BLOCK))
|
2016-09-23 21:59:15 +00:00
|
|
|
{
|
2016-09-26 20:48:58 +00:00
|
|
|
ir->u.bvalue = bb->irs.item[0]->left->u.bvalue;
|
2016-09-23 21:59:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rewrite_jumps(struct basicblock* bb)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2016-09-26 20:48:58 +00:00
|
|
|
for (i=0; i<bb->irs.count; i++)
|
2016-09-23 21:59:15 +00:00
|
|
|
{
|
2016-09-26 20:48:58 +00:00
|
|
|
struct ir* ir = bb->irs.item[i];
|
2016-09-23 21:59:15 +00:00
|
|
|
ir_walk(ir, rewrite_jumps_cb, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pass_eliminate_trivial_blocks(struct procedure* proc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2016-09-26 20:48:58 +00:00
|
|
|
for (i=0; i<proc->blocks.count; i++)
|
2016-09-23 21:59:15 +00:00
|
|
|
{
|
2016-09-26 20:48:58 +00:00
|
|
|
struct basicblock* bb = proc->blocks.item[i];
|
2016-09-23 21:59:15 +00:00
|
|
|
rewrite_jumps(bb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set sw=4 ts=4 expandtab : */
|