Fixing block split ordering, issue #48.

This commit is contained in:
Ben Vanik 2013-12-27 08:38:59 -08:00
parent 7002a3bd57
commit 402c96f9a6
1 changed files with 14 additions and 4 deletions

View File

@ -296,13 +296,23 @@ void FunctionBuilder::InsertLabel(Label* label, Instr* prev_instr) {
label->block = new_block; label->block = new_block;
label->prev = label->next = NULL; label->prev = label->next = NULL;
new_block->instr_head = prev_instr->next; Instr* prev_next = prev_instr->next;
Instr* old_prev_tail = prev_block->instr_tail;
if (prev_instr->next) {
Instr* prev_last = prev_instr->next->prev;
prev_last->next = NULL;
prev_block->instr_tail = prev_last;
}
new_block->instr_head = prev_next;
if (new_block->instr_head) { if (new_block->instr_head) {
new_block->instr_head->prev = NULL; new_block->instr_head->prev = NULL;
new_block->instr_tail = prev_block->instr_tail; new_block->instr_tail = old_prev_tail;
}
for (auto instr = new_block->instr_head; instr != new_block->instr_tail;
instr = instr->next) {
instr->block = new_block;
} }
prev_instr->next = NULL;
prev_block->instr_tail = prev_instr;
if (current_block_ == prev_block) { if (current_block_ == prev_block) {
current_block_ = new_block; current_block_ = new_block;