You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by wr...@apache.org on 2022/08/14 03:13:36 UTC

[tvm] 01/01: fix thread pool alloca

This is an automated email from the ASF dual-hosted git repository.

wrongtest pushed a commit to branch fix_thread_pool_alloca
in repository https://gitbox.apache.org/repos/asf/tvm.git

commit b4c2c08fda7682f3b2b34efade8441554cfbf457
Author: wrongtest <wr...@gmail.com>
AuthorDate: Sun Aug 14 11:13:15 2022 +0800

    fix thread pool alloca
---
 src/target/llvm/codegen_cpu.cc | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/target/llvm/codegen_cpu.cc b/src/target/llvm/codegen_cpu.cc
index c4aed1a237..a95622f5e4 100644
--- a/src/target/llvm/codegen_cpu.cc
+++ b/src/target/llvm/codegen_cpu.cc
@@ -642,7 +642,16 @@ CodeGenLLVM::TypedPointer CodeGenCPU::PackClosureData(const Array<Var>& vfields,
   }
   llvm::StructType* ctype = struct_name.size() ? llvm::StructType::create(fields, struct_name)
                                                : llvm::StructType::create(fields);
-  llvm::Value* cvalue = builder_->CreateAlloca(ctype, ConstInt32(1));
+  // create ctype alloca at function entry
+  llvm::BasicBlock* cur_pt = builder_->GetInsertBlock();
+  llvm::BasicBlock* entry_block = &function_->getEntryBlock();
+  if (entry_block->getFirstInsertionPt() == entry_block->end()) {
+    builder_->SetInsertPoint(entry_block);
+  } else {
+    builder_->SetInsertPoint(&(*entry_block->getFirstInsertionPt()));
+  }
+  llvm::Value* cvalue = builder_->CreateAlloca(ctype, ConstInt32(1));  // alloca at function begin
+  builder_->SetInsertPoint(cur_pt);
   llvm::Value* zero = ConstInt32(0);
   for (size_t i = 0; i < vfields.size(); ++i) {
     builder_->CreateStore(var_map_.at(vfields[i].get()),