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 --- llvm/lib/ExecutionEngine/Orc/Legacy.cpp | 40 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'llvm/lib/ExecutionEngine/Orc/Legacy.cpp') diff --git a/llvm/lib/ExecutionEngine/Orc/Legacy.cpp b/llvm/lib/ExecutionEngine/Orc/Legacy.cpp index 925729e0eee..f61376a909d 100644 --- a/llvm/lib/ExecutionEngine/Orc/Legacy.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Legacy.cpp @@ -18,34 +18,34 @@ JITSymbolResolverAdapter::JITSymbolResolverAdapter( ExecutionSession &ES, SymbolResolver &R, MaterializationResponsibility *MR) : ES(ES), R(R), MR(MR) {} -Expected -JITSymbolResolverAdapter::lookup(const LookupSet &Symbols) { +void JITSymbolResolverAdapter::lookup(const LookupSet &Symbols, + OnResolvedFunction OnResolved) { SymbolNameSet InternedSymbols; for (auto &S : Symbols) InternedSymbols.insert(ES.getSymbolStringPool().intern(S)); - auto LookupFn = [&, this](std::shared_ptr Q, - SymbolNameSet Unresolved) { - return R.lookup(std::move(Q), std::move(Unresolved)); - }; + auto OnResolvedWithUnwrap = [OnResolved](Expected InternedResult) { + if (!InternedResult) { + OnResolved(InternedResult.takeError()); + return; + } - auto RegisterDependencies = [&](const SymbolDependenceMap &Deps) { - if (MR) - MR->addDependenciesForAll(Deps); + LookupResult Result; + for (auto &KV : *InternedResult) + Result[*KV.first] = std::move(KV.second); + OnResolved(Result); }; - auto InternedResult = - ES.legacyLookup(std::move(LookupFn), std::move(InternedSymbols), - false, RegisterDependencies); - - if (!InternedResult) - return InternedResult.takeError(); + auto Q = std::make_shared( + InternedSymbols, OnResolvedWithUnwrap, + [this](Error Err) { ES.reportError(std::move(Err)); }); - JITSymbolResolver::LookupResult Result; - for (auto &KV : *InternedResult) - Result[*KV.first] = KV.second; - - return Result; + auto Unresolved = R.lookup(Q, InternedSymbols); + if (Unresolved.empty()) { + if (MR) + MR->addDependenciesForAll(Q->QueryRegistrations); + } else + ES.legacyFailQuery(*Q, make_error(std::move(Unresolved))); } Expected -- cgit v1.2.3