Fixing CFG to remove unreachable blocks and properly maintain dominators.

This commit is contained in:
Ben Vanik
2015-06-07 15:14:14 -07:00
parent 10e8d0bd9b
commit 889f29c18a
4 changed files with 116 additions and 5 deletions

View File

@@ -31,9 +31,21 @@ ControlFlowSimplificationPass::ControlFlowSimplificationPass()
ControlFlowSimplificationPass::~ControlFlowSimplificationPass() {}
bool ControlFlowSimplificationPass::Run(HIRBuilder* builder) {
// Walk forwards and kill any unreachable blocks.
// Do this before merging.
auto block = builder->first_block();
while (block) {
auto next_block = block->next;
if (!block->incoming_edge_head && block->prev) {
// Block is in the interior and has no incoming edges - kill it.
builder->RemoveBlock(block);
}
block = next_block;
}
// Walk backwards and merge blocks if possible.
bool merged_any = false;
auto block = builder->last_block();
block = builder->last_block();
while (block) {
auto prev_block = block->prev;
const uint32_t expected = Edge::DOMINATES | Edge::UNCONDITIONAL;