Clean up lb_end_procedure_body logic

This commit is contained in:
gingerBill
2021-03-02 00:43:25 +00:00
parent 6faf024ab4
commit 2a1bec9fbb
2 changed files with 4 additions and 23 deletions
+1 -1
View File
@@ -403,7 +403,7 @@ namespace lbAbi386 {
// TODO(bill): LLVM is probably bugged here and doesn't correctly generate the right code
// So even though it is "technically" wrong, no cast might be the best option
LLVMTypeRef cast_type = nullptr;
if (!is_return) {
if (true || !is_return) {
cast_type = LLVMVectorType(LLVMInt64TypeInContext(c), 2);
}
return lb_arg_type_direct(type, cast_type, nullptr, nullptr);
+3 -22
View File
@@ -2575,37 +2575,18 @@ void lb_end_procedure_body(lbProcedure *p) {
}
}
LLVMBasicBlockRef block = nullptr;
LLVMBasicBlockRef first_block = LLVMGetFirstBasicBlock(p->value);
// Remove dead blocks with no code
for (block = first_block;
block != nullptr;
/**/) {
LLVMBasicBlockRef next_block = LLVMGetNextBasicBlock(block);
LLVMValueRef instr = LLVMGetLastInstruction(block);
if (instr == nullptr) {
LLVMDeleteBasicBlock(block);
}
block = next_block;
}
LLVMBasicBlockRef block = nullptr;
// Make sure every block terminates, and if not, make it unreachable
for (block = first_block;
block != nullptr;
block = LLVMGetNextBasicBlock(block)) {
for (block = first_block; block != nullptr; block = LLVMGetNextBasicBlock(block)) {
LLVMValueRef instr = LLVMGetLastInstruction(block);
if (!lb_is_instr_terminating(instr)) {
// NOTE(bill): This is a sanity check
LLVMBasicBlockRef prev_block = block;
if (instr == nullptr) {
LLVMPositionBuilderAtEnd(p->builder, block);
LLVMBuildUnreachable(p->builder);
LLVMPositionBuilderAtEnd(p->builder, prev_block);
}
}
p->curr_block = nullptr;
p->module->state_flags = 0;
}