kparzysz-quic commented on code in PR #12200:
URL: https://github.com/apache/tvm/pull/12200#discussion_r947138752


##########
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);

Review Comment:
   You can replace all of this with
   ```
     llvm::AllocaInst* cvalue = WithFunctionEntry([&]() {
       return builder_->CreateAlloca(ctype, ConstInt32(1));
     });
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to