diff options
author | Lang Hames <lhames@gmail.com> | 2018-09-25 04:43:38 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2018-09-25 04:43:38 +0000 |
commit | 0e5b60326e306cba3f4434692e5d37ffee8a2ae9 (patch) | |
tree | f3861542b7857a06845397b7708d143f16f494e7 /llvm/lib/ExecutionEngine/Orc/Legacy.cpp | |
parent | 3c3e1c62650abb8692b43ba96b0f252418bc5057 (diff) | |
download | bcm5719-llvm-0e5b60326e306cba3f4434692e5d37ffee8a2ae9.tar.gz bcm5719-llvm-0e5b60326e306cba3f4434692e5d37ffee8a2ae9.zip |
[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
Diffstat (limited to 'llvm/lib/ExecutionEngine/Orc/Legacy.cpp')
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/Legacy.cpp | 40 |
1 files changed, 20 insertions, 20 deletions
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::LookupResult> -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<AsynchronousSymbolQuery> Q, - SymbolNameSet Unresolved) { - return R.lookup(std::move(Q), std::move(Unresolved)); - }; + auto OnResolvedWithUnwrap = [OnResolved](Expected<SymbolMap> 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<AsynchronousSymbolQuery>( + 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<SymbolsNotFound>(std::move(Unresolved))); } Expected<JITSymbolResolverAdapter::LookupSet> |