From 784fecfe71912a618d89cc77ea825b86df184f54 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Thu, 14 Jun 2018 15:32:58 +0000 Subject: [ORC] Add a WaitUntilReady argument to blockingLookup. If WaitUntilReady is set to true then blockingLookup will return once all requested symbols are ready. If WaitUntilReady is set to false then blockingLookup will return as soon as all requested symbols have been resolved. In the latter case, if any error occurs in finalizing the symbols it will be reported to the ExecutionSession, rather than returned by blockingLookup. llvm-svn: 334722 --- llvm/lib/ExecutionEngine/Orc/Core.cpp | 64 +++++++++++++++++++++------------ llvm/lib/ExecutionEngine/Orc/Legacy.cpp | 4 +-- 2 files changed, 44 insertions(+), 24 deletions(-) (limited to 'llvm/lib/ExecutionEngine') diff --git a/llvm/lib/ExecutionEngine/Orc/Core.cpp b/llvm/lib/ExecutionEngine/Orc/Core.cpp index 5ae65ab2f66..74cb3834b79 100644 --- a/llvm/lib/ExecutionEngine/Orc/Core.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Core.cpp @@ -937,7 +937,7 @@ VSO &ExecutionSession::createVSO(std::string Name) { Expected blockingLookup(ExecutionSessionBase &ES, AsynchronousLookupFunction AsyncLookup, - SymbolNameSet Names, + SymbolNameSet Names, bool WaitUntilReady, MaterializationResponsibility *MR) { #if LLVM_ENABLE_THREADS @@ -963,14 +963,23 @@ Expected blockingLookup(ExecutionSessionBase &ES, } }; - auto OnReady = [&](Error Err) { - if (Err) { - ErrorAsOutParameter _(&ReadyError); - std::lock_guard Lock(ErrMutex); - ReadyError = std::move(Err); - } - PromisedReady.set_value(); - }; + std::function OnReady; + if (WaitUntilReady) { + OnReady = [&](Error Err) { + if (Err) { + ErrorAsOutParameter _(&ReadyError); + std::lock_guard Lock(ErrMutex); + ReadyError = std::move(Err); + } + PromisedReady.set_value(); + }; + } else { + OnReady = [&](Error Err) { + if (Err) + ES.reportError(std::move(Err)); + }; + } + #else SymbolMap Result; Error ResolutionError = Error::success(); @@ -986,11 +995,19 @@ Expected blockingLookup(ExecutionSessionBase &ES, ResolutionError = R.takeError(); }; - auto OnReady = [&](Error Err) { - ErrorAsOutParameter _(&ReadyError); - if (Err) - ReadyError = std::move(Err); - }; + std::function OnReady; + if (WaitUntilReady) { + OnReady = [&](Error Err) { + ErrorAsOutParameter _(&ReadyError); + if (Err) + ReadyError = std::move(Err); + }; + } else { + OnReady = [&](Error Err) { + if (Err) + ES.reportError(std::move(Err)); + }; + } #endif auto Query = std::make_shared( @@ -1017,14 +1034,17 @@ Expected blockingLookup(ExecutionSessionBase &ES, } } - auto ReadyFuture = PromisedReady.get_future(); - ReadyFuture.get(); + if (WaitUntilReady) { + auto ReadyFuture = PromisedReady.get_future(); + ReadyFuture.get(); - { - std::lock_guard Lock(ErrMutex); - if (ReadyError) - return std::move(ReadyError); - } + { + std::lock_guard Lock(ErrMutex); + if (ReadyError) + return std::move(ReadyError); + } + } else + cantFail(std::move(ReadyError)); return std::move(Result); @@ -1060,7 +1080,7 @@ Expected lookup(const VSO::VSOList &VSOs, SymbolNameSet Names) { return Unresolved; }; - return blockingLookup(ES, std::move(LookupFn), Names); + return blockingLookup(ES, std::move(LookupFn), Names, true); } /// Look up a symbol by searching a list of VSOs. diff --git a/llvm/lib/ExecutionEngine/Orc/Legacy.cpp b/llvm/lib/ExecutionEngine/Orc/Legacy.cpp index 3fd53a00a79..795ddd582d8 100644 --- a/llvm/lib/ExecutionEngine/Orc/Legacy.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Legacy.cpp @@ -27,8 +27,8 @@ JITSymbolResolverAdapter::lookup(const LookupSet &Symbols) { return R.lookup(std::move(Q), std::move(Unresolved)); }; - auto InternedResult = - blockingLookup(ES, std::move(LookupFn), std::move(InternedSymbols), MR); + auto InternedResult = blockingLookup(ES, std::move(LookupFn), + std::move(InternedSymbols), false, MR); if (!InternedResult) return InternedResult.takeError(); -- cgit v1.2.3