Skip to content

Commit

Permalink
Handle empty LLVMModule in GetFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
kumasento committed Mar 25, 2020
1 parent 3aabbd9 commit a6dcbe8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/target/llvm/llvm_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class LLVMModuleNode final : public runtime::ModuleNode {
PackedFunc GetFunction(
const std::string& name,
const ObjectPtr<Object>& sptr_to_self) final {
std::cout << name << std::endl;
if (name == "__tvm_is_system_module") {
bool flag =
(mptr_->getFunction("__tvm_module_startup") != nullptr);
Expand All @@ -71,6 +72,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);
Expand Down Expand Up @@ -318,6 +323,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**>(
Expand All @@ -329,15 +338,15 @@ 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);
} else {
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);
Expand Down

0 comments on commit a6dcbe8

Please sign in to comment.