mirror of https://github.com/inolen/redream.git
assert branch is last instruction in ir block
This commit is contained in:
parent
45695ce3e0
commit
427e5d64f7
|
@ -4,19 +4,29 @@
|
|||
|
||||
void cfa_run(struct cfa *cfa, struct ir *ir) {
|
||||
list_for_each_entry(block, &ir->blocks, struct ir_block, it) {
|
||||
struct ir_instr *last_instr =
|
||||
list_last_entry(&block->instrs, struct ir_instr, it);
|
||||
|
||||
list_for_each_entry(instr, &block->instrs, struct ir_instr, it) {
|
||||
/* add edges between blocks for easy traversing */
|
||||
if (instr->op == OP_BRANCH) {
|
||||
if (instr->arg[0]->type == VALUE_BLOCK) {
|
||||
ir_add_edge(ir, block, instr->arg[0]->blk);
|
||||
}
|
||||
} else if (instr->op == OP_BRANCH_COND) {
|
||||
if (instr->arg[0]->type == VALUE_BLOCK) {
|
||||
ir_add_edge(ir, block, instr->arg[0]->blk);
|
||||
}
|
||||
if (instr->arg[1]->type == VALUE_BLOCK) {
|
||||
ir_add_edge(ir, block, instr->arg[1]->blk);
|
||||
}
|
||||
if (instr == last_instr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CHECK(instr->op != OP_BRANCH && instr->op != OP_BRANCH_COND,
|
||||
"only the last instruction in the block can branch");
|
||||
}
|
||||
|
||||
/* add edges between blocks for easy traversing */
|
||||
if (last_instr->op == OP_BRANCH) {
|
||||
if (last_instr->arg[0]->type == VALUE_BLOCK) {
|
||||
ir_add_edge(ir, block, last_instr->arg[0]->blk);
|
||||
}
|
||||
} else if (last_instr->op == OP_BRANCH_COND) {
|
||||
if (last_instr->arg[0]->type == VALUE_BLOCK) {
|
||||
ir_add_edge(ir, block, last_instr->arg[0]->blk);
|
||||
}
|
||||
if (last_instr->arg[1]->type == VALUE_BLOCK) {
|
||||
ir_add_edge(ir, block, last_instr->arg[1]->blk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue