[llvm] r334537 - [ORC] Refactor blocking lookup logic into the blockingLookup function, and
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 12 13:43:18 PDT 2018
Author: lhames
Date: Tue Jun 12 13:43:17 2018
New Revision: 334537
URL: http://llvm.org/viewvc/llvm-project?rev=334537&view=rev
Log:
[ORC] Refactor blocking lookup logic into the blockingLookup function, and
implement existing blocking lookups (the lookup function) and
JITSymbolResolverAdapter on top of that.
Modified:
llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h
llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp
llvm/trunk/lib/ExecutionEngine/Orc/Legacy.cpp
llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h
llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h?rev=334537&r1=334536&r2=334537&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h Tue Jun 12 13:43:17 2018
@@ -614,6 +614,15 @@ private:
std::vector<std::unique_ptr<VSO>> VSOs;
};
+using AsynchronousLookupFunction = std::function<SymbolNameSet(
+ std::shared_ptr<AsynchronousSymbolQuery> Q, SymbolNameSet Names)>;
+
+/// Perform a blocking lookup on the given symbols.
+Expected<SymbolMap> blockingLookup(ExecutionSessionBase &ES,
+ AsynchronousLookupFunction AsyncLookup,
+ SymbolNameSet Names,
+ MaterializationResponsibility *MR = nullptr);
+
/// Look up the given names in the given VSOs.
/// VSOs will be searched in order and no VSO pointer may be null.
/// All symbols must be found within the given VSOs or an error
Modified: llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp?rev=334537&r1=334536&r2=334537&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp Tue Jun 12 13:43:17 2018
@@ -898,7 +898,10 @@ VSO &ExecutionSession::createVSO(std::st
});
}
-Expected<SymbolMap> lookup(const VSO::VSOList &VSOs, SymbolNameSet Names) {
+Expected<SymbolMap> blockingLookup(ExecutionSessionBase &ES,
+ AsynchronousLookupFunction AsyncLookup,
+ SymbolNameSet Names,
+ MaterializationResponsibility *MR) {
#if LLVM_ENABLE_THREADS
// In the threaded case we use promises to return the results.
@@ -909,9 +912,11 @@ Expected<SymbolMap> lookup(const VSO::VS
Error ReadyError = Error::success();
auto OnResolve =
[&](Expected<AsynchronousSymbolQuery::ResolutionResult> Result) {
- if (Result)
+ if (Result) {
+ if (MR)
+ MR->addDependencies(Result->Dependencies);
PromisedResult.set_value(std::move(Result->Symbols));
- else {
+ } else {
{
ErrorAsOutParameter _(&ResolutionError);
std::lock_guard<std::mutex> Lock(ErrMutex);
@@ -920,6 +925,7 @@ Expected<SymbolMap> lookup(const VSO::VS
PromisedResult.set_value(SymbolMap());
}
};
+
auto OnReady = [&](Error Err) {
if (Err) {
ErrorAsOutParameter _(&ReadyError);
@@ -935,11 +941,14 @@ Expected<SymbolMap> lookup(const VSO::VS
auto OnResolve = [&](Expected<AsynchronousSymbolQuery::ResolutionResult> R) {
ErrorAsOutParameter _(&ResolutionError);
- if (R)
+ if (R) {
+ if (MR)
+ MR->addDependencies(Result->Dependencies);
Result = std::move(R->Symbols);
- else
+ } else
ResolutionError = R.takeError();
};
+
auto OnReady = [&](Error Err) {
ErrorAsOutParameter _(&ReadyError);
if (Err)
@@ -949,22 +958,14 @@ Expected<SymbolMap> lookup(const VSO::VS
auto Query = std::make_shared<AsynchronousSymbolQuery>(
Names, std::move(OnResolve), std::move(OnReady));
- SymbolNameSet UnresolvedSymbols(std::move(Names));
- for (auto *V : VSOs) {
- assert(V && "VSO pointers in VSOs list should be non-null");
- if (UnresolvedSymbols.empty())
- break;
- UnresolvedSymbols = V->lookup(Query, UnresolvedSymbols);
- }
+ SymbolNameSet UnresolvedSymbols = AsyncLookup(Query, std::move(Names));
- if (!UnresolvedSymbols.empty()) {
- // If there are unresolved symbols then the query will never return.
- // Fail it with ES.failQuery.
- auto &ES = (*VSOs.begin())->getExecutionSession();
+ // If there are unresolved symbols then the query will never return.
+ // Fail it with ES.failQuery.
+ if (!UnresolvedSymbols.empty())
ES.failQuery(*Query,
make_error<SymbolsNotFound>(std::move(UnresolvedSymbols)));
- }
#if LLVM_ENABLE_THREADS
auto ResultFuture = PromisedResult.get_future();
@@ -1004,6 +1005,27 @@ Expected<SymbolMap> lookup(const VSO::VS
#endif
}
+Expected<SymbolMap> lookup(const VSO::VSOList &VSOs, SymbolNameSet Names) {
+
+ if (VSOs.empty())
+ return SymbolMap();
+
+ auto &ES = (*VSOs.begin())->getExecutionSession();
+
+ auto LookupFn = [&](std::shared_ptr<AsynchronousSymbolQuery> Q,
+ SymbolNameSet Unresolved) {
+ for (auto *V : VSOs) {
+ assert(V && "VSOs entries must not be null");
+ if (Unresolved.empty())
+ break;
+ Unresolved = V->lookup(Q, std::move(Unresolved));
+ }
+ return Unresolved;
+ };
+
+ return blockingLookup(ES, std::move(LookupFn), Names);
+}
+
/// Look up a symbol by searching a list of VSOs.
Expected<JITEvaluatedSymbol> lookup(const VSO::VSOList &VSOs,
SymbolStringPtr Name) {
Modified: llvm/trunk/lib/ExecutionEngine/Orc/Legacy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/Legacy.cpp?rev=334537&r1=334536&r2=334537&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/Legacy.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/Legacy.cpp Tue Jun 12 13:43:17 2018
@@ -18,54 +18,24 @@ JITSymbolResolverAdapter::JITSymbolResol
Expected<JITSymbolResolverAdapter::LookupResult>
JITSymbolResolverAdapter::lookup(const LookupSet &Symbols) {
- Error Err = Error::success();
- JITSymbolResolver::LookupResult Result;
-
SymbolNameSet InternedSymbols;
for (auto &S : Symbols)
InternedSymbols.insert(ES.getSymbolStringPool().intern(S));
- auto OnResolve =
- [&, this](Expected<AsynchronousSymbolQuery::ResolutionResult> RR) {
- if (RR) {
- // If this lookup was attached to a MaterializationResponsibility then
- // record the dependencies.
- if (MR)
- MR->addDependencies(RR->Dependencies);
-
- for (auto &KV : RR->Symbols) {
- ResolvedStrings.insert(KV.first);
- Result[*KV.first] = KV.second;
- }
- } else
- Err = joinErrors(std::move(Err), RR.takeError());
- };
-
- auto OnReady = [this](Error Err) { ES.reportError(std::move(Err)); };
-
- auto Query = std::make_shared<AsynchronousSymbolQuery>(InternedSymbols,
- OnResolve, OnReady);
-
- auto UnresolvedSymbols = R.lookup(Query, InternedSymbols);
-
- if (!UnresolvedSymbols.empty()) {
- std::string ErrorMsg = "Unresolved symbols: ";
-
- ErrorMsg += **UnresolvedSymbols.begin();
- for (auto I = std::next(UnresolvedSymbols.begin()),
- E = UnresolvedSymbols.end();
- I != E; ++I) {
- ErrorMsg += ", ";
- ErrorMsg += **I;
- }
-
- Err =
- joinErrors(std::move(Err),
- make_error<StringError>(ErrorMsg, inconvertibleErrorCode()));
- }
+ auto LookupFn = [&, this](std::shared_ptr<AsynchronousSymbolQuery> Q,
+ SymbolNameSet Unresolved) {
+ return R.lookup(std::move(Q), std::move(Unresolved));
+ };
+
+ auto InternedResult =
+ blockingLookup(ES, std::move(LookupFn), std::move(InternedSymbols), MR);
- if (Err)
- return std::move(Err);
+ if (!InternedResult)
+ return InternedResult.takeError();
+
+ JITSymbolResolver::LookupResult Result;
+ for (auto &KV : *InternedResult)
+ Result[*KV.first] = KV.second;
return Result;
}
Modified: llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h?rev=334537&r1=334536&r2=334537&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h Tue Jun 12 13:43:17 2018
@@ -153,9 +153,10 @@ private:
for (auto &S : Symbols) {
if (auto Sym = findSymbol(*S)) {
- if (auto Addr = Sym.getAddress())
+ if (auto Addr = Sym.getAddress()) {
Query->resolve(S, JITEvaluatedSymbol(*Addr, Sym.getFlags()));
- else {
+ Query->notifySymbolReady();
+ } else {
Stack.ES.failQuery(*Query, Addr.takeError());
return orc::SymbolNameSet();
}
@@ -169,6 +170,9 @@ private:
if (Query->isFullyResolved())
Query->handleFullyResolved();
+ if (Query->isFullyReady())
+ Query->handleFullyReady();
+
return UnresolvedSymbols;
}
Modified: llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h?rev=334537&r1=334536&r2=334537&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h Tue Jun 12 13:43:17 2018
@@ -177,6 +177,7 @@ class OrcMCJITReplacement : public Execu
if (auto Sym = M.findMangledSymbol(*S)) {
if (auto Addr = Sym.getAddress()) {
Query->resolve(S, JITEvaluatedSymbol(*Addr, Sym.getFlags()));
+ Query->notifySymbolReady();
NewSymbolsResolved = true;
} else {
M.ES.failQuery(*Query, Addr.takeError());
@@ -189,6 +190,7 @@ class OrcMCJITReplacement : public Execu
if (auto Sym2 = M.ClientResolver->findSymbol(*S)) {
if (auto Addr = Sym2.getAddress()) {
Query->resolve(S, JITEvaluatedSymbol(*Addr, Sym2.getFlags()));
+ Query->notifySymbolReady();
NewSymbolsResolved = true;
} else {
M.ES.failQuery(*Query, Addr.takeError());
@@ -205,6 +207,9 @@ class OrcMCJITReplacement : public Execu
if (NewSymbolsResolved && Query->isFullyResolved())
Query->handleFullyResolved();
+ if (NewSymbolsResolved && Query->isFullyReady())
+ Query->handleFullyReady();
+
return UnresolvedSymbols;
}
More information about the llvm-commits
mailing list