From: Lang Hames Date: Fri, 19 Mar 2021 21:54:07 +0000 (-0700) Subject: [JITLink] Don't issue lookups for empty symbol sets. X-Git-Tag: llvmorg-14-init~11846 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=602e19ed79b8a15500bf7a683cbaa1ca24c9536d;p=platform%2Fupstream%2Fllvm.git [JITLink] Don't issue lookups for empty symbol sets. Issuing a lookup for an empty symbol set is legal, but can actually result in unrelated work being done if there was a work queue left over from the previous lookup. We can avoid doing this unrelated work (reducing stack depth and interleaving of debugging output) by not issuing these no-op lookups in the first place. --- diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp index 2e5b7cb..63f862b 100644 --- a/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp @@ -66,14 +66,27 @@ void JITLinkerBase::linkPhase1(std::unique_ptr Self) { return Ctx->notifyFailed(std::move(Err)); // Notify client that the defined symbols have been assigned addresses. - LLVM_DEBUG( - { dbgs() << "Resolving symbols defined in " << G->getName() << "\n"; }); + LLVM_DEBUG(dbgs() << "Resolving symbols defined in " << G->getName() << "\n"); if (auto Err = Ctx->notifyResolved(*G)) return Ctx->notifyFailed(std::move(Err)); auto ExternalSymbols = getExternalSymbolNames(); + // If there are no external symbols then proceed immediately with phase 2. + if (ExternalSymbols.empty()) { + LLVM_DEBUG({ + dbgs() << "No external symbols for " << G->getName() + << ". Proceeding immediately with link phase 2.\n"; + }); + // FIXME: Once callee expressions are defined to be sequenced before + // argument expressions (c++17) we can simplify this. See below. + auto &TmpSelf = *Self; + TmpSelf.linkPhase2(std::move(Self), AsyncLookupResult(), std::move(Layout)); + return; + } + + // Otherwise look up the externals. LLVM_DEBUG({ dbgs() << "Issuing lookup for external symbols for " << G->getName() << " (may trigger materialization/linking of other graphs)...\n";