From 0e5b60326e306cba3f4434692e5d37ffee8a2ae9 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Tue, 25 Sep 2018 04:43:38 +0000 Subject: [ORC] Switch to asynchronous resolution in JITSymbolResolver. Asynchronous resolution (where the caller receives a callback once the requested set of symbols are resolved) is a core part of the new concurrent ORC APIs. This change extends the asynchronous resolution model down to RuntimeDyld, which is necessary to prevent deadlocks when compiling/linking on a fixed number of threads: If RuntimeDyld's linking process were a blocking operation, then any complete K-graph in a program will require at least K threads to link in the worst case, as each thread would block waiting for all the others to complete. Using callbacks instead allows the work to be passed between dependent threads until it is complete. For backwards compatibility, all existing RuntimeDyld functions will continue to operate in blocking mode as before. This change will enable the introduction of a new async finalization process in a subsequent patch to enable asynchronous JIT linking. llvm-svn: 342939 --- .../RuntimeDyld/RuntimeDyldChecker.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp') diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp index fa8906869b3..79a1bbb1a77 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp @@ -16,6 +16,7 @@ #include "llvm/MC/MCInst.h" #include "llvm/Support/Path.h" #include +#include #include #include @@ -729,15 +730,29 @@ bool RuntimeDyldCheckerImpl::checkAllRulesInBuffer(StringRef RulePrefix, return DidAllTestsPass && (NumRules != 0); } +Expected RuntimeDyldCheckerImpl::lookup( + const JITSymbolResolver::LookupSet &Symbols) const { + auto ResultP = std::make_shared< + std::promise>>(); + auto ResultF = ResultP->get_future(); + + getRTDyld().Resolver.lookup( + Symbols, [=](Expected Result) { + ResultP->set_value(std::move(Result)); + }); + return ResultF.get(); +} + bool RuntimeDyldCheckerImpl::isSymbolValid(StringRef Symbol) const { if (getRTDyld().getSymbol(Symbol)) return true; - JITSymbolResolver::LookupSet Symbols({Symbol}); - auto Result = getRTDyld().Resolver.lookup(Symbols); + auto Result = lookup({Symbol}); + if (!Result) { logAllUnhandledErrors(Result.takeError(), errs(), "RTDyldChecker: "); return false; } + assert(Result->count(Symbol) && "Missing symbol result"); return true; } @@ -751,8 +766,7 @@ uint64_t RuntimeDyldCheckerImpl::getSymbolRemoteAddr(StringRef Symbol) const { if (auto InternalSymbol = getRTDyld().getSymbol(Symbol)) return InternalSymbol.getAddress(); - JITSymbolResolver::LookupSet Symbols({Symbol}); - auto Result = getRTDyld().Resolver.lookup(Symbols); + auto Result = lookup({Symbol}); if (!Result) { logAllUnhandledErrors(Result.takeError(), errs(), "RTDyldChecker: "); return 0; -- cgit v1.2.3