areusch commented on a change in pull request #6917:
URL: https://github.com/apache/incubator-tvm/pull/6917#discussion_r528404631



##########
File path: src/target/llvm/codegen_llvm.cc
##########
@@ -184,6 +188,104 @@ void CodeGenLLVM::AddFunctionInternal(const PrimFunc& f, 
bool ret_void) {
   }
 }
 
+void CodeGenLLVM::LinkParameters(const Map<String, LinkedParam> params) {
+  // It would be nice to de-dupe these declarations frm 
src/tir/transforms/make_packed_api.cc,
+  // but they are at a different layer in the compiler...
+  std::vector<llvm::Type*> param_types;
+  // args
+  param_types.push_back(t_void_->getPointerTo(GetGlobalAddressSpace()));
+  // tcodes
+  param_types.push_back(t_int_->getPointerTo(GetGlobalAddressSpace()));
+  // num_args
+  param_types.push_back(t_int_);
+  // ret_args
+  param_types.push_back(t_void_->getPointerTo(GetGlobalAddressSpace()));
+  // ret_tcodes
+  param_types.push_back(t_int_->getPointerTo(GetGlobalAddressSpace()));
+  // resource_handle
+  param_types.push_back(t_void_->getPointerTo(GetGlobalAddressSpace()));
+
+  // TODO(tvm-team):
+  // Update the function type to respect the ret_type field of f.
+  // Once we allow more flexibility in the PrimFunc.
+  llvm::FunctionType* ftype = llvm::FunctionType::get(t_int_, param_types, 
false);
+
+  llvm::Function* function =
+      llvm::Function::Create(ftype, llvm::Function::ExternalLinkage,
+                             ::tvm::runtime::symbol::tvm_lookup_linked_param, 
module_.get());
+  function->setCallingConv(llvm::CallingConv::C);
+  
function->setDLLStorageClass(llvm::GlobalValue::DLLStorageClassTypes::DLLExportStorageClass);
+
+  llvm::BasicBlock* entry = llvm::BasicBlock::Create(*ctx_, "entry", function);
+  builder_->SetInsertPoint(entry);
+  std::vector<llvm::Value*> zero_index_list{llvm::ConstantInt::get(t_int32_, 
0)};
+  std::vector<llvm::Value*> 
zero_array_index_list{llvm::ConstantInt::get(t_int32_, 0),
+                                                  
llvm::ConstantInt::get(t_int32_, 0)};
+  auto args_array = builder_->CreateBitCast(
+#if TVM_LLVM_VERSION >= 50
+      &function->arg_begin()[0],
+#else
+      &(*(function->arg_begin())),
+#endif
+      llvm::ArrayType::get(t_void_->getPointerTo(GetGlobalAddressSpace()), 1));
+  llvm::Value* sid = builder_->CreateBitCast(
+      builder_->CreateLoad(t_void_->getPointerTo(GetGlobalAddressSpace()),
+                           builder_->CreateInBoundsGEP(args_array, 
zero_index_list)),
+      t_int64_);
+
+  llvm::BasicBlock* default_block = llvm::BasicBlock::Create(*ctx_, 
"default_block", function);
+  llvm::SwitchInst* switch_inst = builder_->CreateSwitch(sid, default_block, 
params.size() + 1);
+
+  builder_->SetInsertPoint(default_block);
+  {
+    auto ret_types_array = builder_->CreateBitCast(
+#if TVM_LLVM_VERSION >= 50
+        &function->arg_begin()[4],
+#else
+        &(*(std::next(function->arg_begin(), 4))),
+#endif
+        llvm::ArrayType::get(t_int_, 1)->getPointerTo());
+
+    builder_->CreateStore(llvm::ConstantInt::get(t_int_, kTVMNullptr),
+                          builder_->CreateGEP(ret_types_array, 
zero_array_index_list));

Review comment:
       done




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to