Fixing CFG to remove unreachable blocks and properly maintain dominators.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user