This is an automated email from the ASF dual-hosted git repository. zhaowu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git
The following commit(s) were added to refs/heads/master by this push: new 08b38be Handle empty LLVMModule in GetFunction (#5146) 08b38be is described below commit 08b38be95f4eb4e9c6c1c4d41a5219b9ba689bf1 Author: Ruizhe Zhao <kumase...@users.noreply.github.com> AuthorDate: Thu Mar 26 02:11:29 2020 +0000 Handle empty LLVMModule in GetFunction (#5146) --- src/target/llvm/llvm_module.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/target/llvm/llvm_module.cc b/src/target/llvm/llvm_module.cc index 6cf9f11..3f508a5 100644 --- a/src/target/llvm/llvm_module.cc +++ b/src/target/llvm/llvm_module.cc @@ -71,6 +71,10 @@ class LLVMModuleNode final : public runtime::ModuleNode { }); } if (ee_ == nullptr) LazyInitJIT(); + + // This LLVMModule is empty and no function can be retrieved. + if (entry_func_.empty()) return nullptr; + std::lock_guard<std::mutex> lock(mutex_); const std::string& fname = (name == runtime::symbol::tvm_module_main ? entry_func_ : name); @@ -318,6 +322,10 @@ class LLVMModuleNode final : public runtime::ModuleNode { << "Failed to initialize jit engine for " << mptr_->getTargetTriple(); ee_->runStaticConstructorsDestructors(false); // setup context address. + // we will skip context setup if this LLVMModule is empty. + if (GetGlobalAddr(runtime::symbol::tvm_module_main) == 0) + return; + entry_func_ = reinterpret_cast<const char*>(GetGlobalAddr(runtime::symbol::tvm_module_main)); if (void** ctx_addr = reinterpret_cast<void**>( @@ -329,7 +337,7 @@ class LLVMModuleNode final : public runtime::ModuleNode { }); } // Get global address from execution engine. - uint64_t GetGlobalAddr(const std::string& name) { + uint64_t GetGlobalAddr(const std::string& name) const { // first verifies if GV exists. if (mptr_->getGlobalVariable(name) != nullptr) { return ee_->getGlobalValueAddress(name); @@ -337,7 +345,7 @@ class LLVMModuleNode final : public runtime::ModuleNode { return 0; } } - uint64_t GetFunctionAddr(const std::string& name) { + uint64_t GetFunctionAddr(const std::string& name) const { // first verifies if GV exists. if (mptr_->getFunction(name) != nullptr) { return ee_->getFunctionAddress(name);