Skip to content

Commit 833ebd2

Browse files
committed
DEV: Create temporary for IfExp outside LLVM loop
1 parent da8d25b commit 833ebd2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/libasr/codegen/asr_to_llvm.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
218218
llvm_utils->set_api_sc = set_api_sc.get();
219219
}
220220

221+
llvm::AllocaInst* CreateAlloca(llvm::Type* type,
222+
llvm::Value* size=nullptr, const std::string& Name="") {
223+
llvm::BasicBlock &entry_block = builder->GetInsertBlock()->getParent()->getEntryBlock();
224+
llvm::IRBuilder<> builder0(context);
225+
builder0.SetInsertPoint(&entry_block, entry_block.getFirstInsertionPt());
226+
return builder0.CreateAlloca(type, size, Name);
227+
}
228+
221229
llvm::Value* CreateLoad(llvm::Value *x) {
222230
return LLVM::CreateLoad(*builder, x);
223231
}
@@ -5371,7 +5379,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
53715379
this->visit_expr_wrapper(x.m_test, true);
53725380
llvm::Value *cond = tmp;
53735381
llvm::Type* _type = llvm_utils->get_type_from_ttype_t_util(x.m_type, module.get());
5374-
llvm::Value* ifexp_res = builder->CreateAlloca(_type);
5382+
llvm::Value* ifexp_res = CreateAlloca(_type);
53755383
llvm_utils->create_if_else(cond, [&]() {
53765384
this->visit_expr_wrapper(x.m_body, true);
53775385
builder->CreateStore(tmp, ifexp_res);

0 commit comments

Comments
 (0)