From 833ebd28c25d97aa72c007d7e4090c75d728885a Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Thu, 2 Nov 2023 15:01:40 +0530 Subject: [PATCH] DEV: Create temporary for IfExp outside LLVM loop --- src/libasr/codegen/asr_to_llvm.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index ae4bac53ab..48cccf4acf 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -218,6 +218,14 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm_utils->set_api_sc = set_api_sc.get(); } + llvm::AllocaInst* CreateAlloca(llvm::Type* type, + llvm::Value* size=nullptr, const std::string& Name="") { + llvm::BasicBlock &entry_block = builder->GetInsertBlock()->getParent()->getEntryBlock(); + llvm::IRBuilder<> builder0(context); + builder0.SetInsertPoint(&entry_block, entry_block.getFirstInsertionPt()); + return builder0.CreateAlloca(type, size, Name); + } + llvm::Value* CreateLoad(llvm::Value *x) { return LLVM::CreateLoad(*builder, x); } @@ -5371,7 +5379,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor this->visit_expr_wrapper(x.m_test, true); llvm::Value *cond = tmp; llvm::Type* _type = llvm_utils->get_type_from_ttype_t_util(x.m_type, module.get()); - llvm::Value* ifexp_res = builder->CreateAlloca(_type); + llvm::Value* ifexp_res = CreateAlloca(_type); llvm_utils->create_if_else(cond, [&]() { this->visit_expr_wrapper(x.m_body, true); builder->CreateStore(tmp, ifexp_res);