Skip to content

Commit

Permalink
[LLVM/CPU] Terminate basic block after "ret" instruction (apache#6036)
Browse files Browse the repository at this point in the history
* [LLVM/CPU] Terminate basic block after "ret" instruction

"Ret" is a terminator in LLVM IR and there should be no instructions
in the basic block following it. When generating a "ret", end the
current block and start a new one.
  • Loading branch information
Krzysztof Parzyszek authored and trevor-m committed Jul 14, 2020
1 parent fde001c commit 6e9861d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/target/llvm/codegen_cpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,9 @@ llvm::Value* CodeGenCPU::CreateIntrinsic(const CallNode* op) {
return CreateStaticHandle();
} else if (op->op.same_as(builtin::tvm_throw_last_error())) {
builder_->CreateRet(ConstInt32(-1));
auto next_block = std::next(builder_->GetInsertBlock()->getIterator());
llvm::BasicBlock* new_bb = llvm::BasicBlock::Create(*ctx_, "cont", function_, &*next_block);
builder_->SetInsertPoint(new_bb);
return ConstInt32(-1);
} else if (op->op.same_as(builtin::tvm_struct_get())) {
CHECK_EQ(op->args.size(), 3U);
Expand Down

0 comments on commit 6e9861d

Please sign in to comment.