Use an instruction instead of a special-case boolean instruction.

This commit is contained in:
2020-09-17 18:33:52 -07:00
parent fb5a8a5a73
commit 8a44109f93
3 changed files with 17 additions and 50 deletions

View File

@@ -100,7 +100,7 @@ void instruction_jump::print(int indent, std::ostream& to) const {
void instruction_jump::gen_llvm(llvm_context& ctx, Function* f) const {
auto top_node = ctx.create_peek(f, ctx.create_size(0));
auto tag = ctx.unwrap_data_tag(top_node);
auto tag = get_case_value(ctx, top_node);
auto safety_block = ctx.create_basic_block("safety", f);
auto switch_op = ctx.get_builder().CreateSwitch(tag, safety_block, tag_mappings.size());
std::vector<BasicBlock*> blocks;
@@ -122,43 +122,12 @@ void instruction_jump::gen_llvm(llvm_context& ctx, Function* f) const {
ctx.get_builder().SetInsertPoint(safety_block);
}
void instruction_if::print(int indent, std::ostream& to) const {
print_indent(indent, to);
to << "If(" << std::endl;
for(auto& instruction : on_true) {
instruction->print(indent + 2, to);
}
to << std::endl;
for(auto& instruction : on_false) {
instruction->print(indent + 2, to);
}
print_indent(indent, to);
to << ")" << std::endl;
Value* instruction_jump::get_case_value(llvm_context& ctx, Value* v) const {
return ctx.unwrap_data_tag(v);
}
void instruction_if::gen_llvm(llvm_context& ctx, llvm::Function* f) const {
auto top_node = ctx.create_peek(f, ctx.create_size(0));
auto num = ctx.unwrap_num(top_node);
auto nonzero_block = ctx.create_basic_block("nonzero", f);
auto zero_block = ctx.create_basic_block("zero", f);
auto resume_block = ctx.create_basic_block("resume", f);
auto switch_op = ctx.get_builder().CreateSwitch(num, nonzero_block, 2);
switch_op->addCase(ctx.create_i32(0), zero_block);
ctx.get_builder().SetInsertPoint(nonzero_block);
for(auto& instruction : on_true) {
instruction->gen_llvm(ctx, f);
}
ctx.get_builder().CreateBr(resume_block);
ctx.get_builder().SetInsertPoint(zero_block);
for(auto& instruction : on_false) {
instruction->gen_llvm(ctx, f);
}
ctx.get_builder().CreateBr(resume_block);
ctx.get_builder().SetInsertPoint(resume_block);
Value* instruction_ijump::get_case_value(llvm_context& ctx, Value* v) const {
return ctx.unwrap_num(v);
}
void instruction_slide::print(int indent, std::ostream& to) const {