diff options
author | Lang Hames <lhames@gmail.com> | 2021-07-27 13:50:19 +1000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2021-07-27 16:53:49 +1000 |
commit | 2487db1f286222e2501c2fa8e8244eda13f6afc3 (patch) | |
tree | 17b28297505513f4d91342724f471c49eaf89f2b /llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp | |
parent | 70b75f62fc617f1fa7e4859571a99137297146c6 (diff) | |
download | llvm-2487db1f286222e2501c2fa8e8244eda13f6afc3.zip llvm-2487db1f286222e2501c2fa8e8244eda13f6afc3.tar.gz llvm-2487db1f286222e2501c2fa8e8244eda13f6afc3.tar.bz2 |
[ORC] Require ExecutorProcessControl when constructing an ExecutionSession.
Wrapper function call and dispatch handler helpers are moved to
ExecutionSession, and existing EPC-based tools are re-written to take an
ExecutionSession argument instead.
Requiring an ExecutorProcessControl instance simplifies existing EPC based
utilities (which only need to take an ES now), and should encourage more
utilities to use the EPC interface. It also simplifies process termination,
since the session can automatically call ExecutorProcessControl::disconnect
(previously this had to be done manually, and carefully ordered with the
rest of JIT tear-down to work correctly).
Diffstat (limited to 'llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp')
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp | 78 |
1 files changed, 15 insertions, 63 deletions
diff --git a/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp b/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp index 9442eab..7d86d12 100644 --- a/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp @@ -23,60 +23,6 @@ ExecutorProcessControl::MemoryAccess::~MemoryAccess() {} ExecutorProcessControl::~ExecutorProcessControl() {} -Error ExecutorProcessControl::associateJITSideWrapperFunctions( - JITDylib &JD, WrapperFunctionAssociationMap WFs) { - - // Look up tag addresses. - auto &ES = JD.getExecutionSession(); - auto TagAddrs = - ES.lookup({{&JD, JITDylibLookupFlags::MatchAllSymbols}}, - SymbolLookupSet::fromMapKeys( - WFs, SymbolLookupFlags::WeaklyReferencedSymbol)); - if (!TagAddrs) - return TagAddrs.takeError(); - - // Associate tag addresses with implementations. - std::lock_guard<std::mutex> Lock(TagToFuncMapMutex); - for (auto &KV : *TagAddrs) { - auto TagAddr = KV.second.getAddress(); - if (TagToFunc.count(TagAddr)) - return make_error<StringError>("Tag " + formatv("{0:x16}", TagAddr) + - " (for " + *KV.first + - ") already registered", - inconvertibleErrorCode()); - auto I = WFs.find(KV.first); - assert(I != WFs.end() && I->second && - "AsyncWrapperFunction implementation missing"); - TagToFunc[KV.second.getAddress()] = - std::make_shared<AsyncWrapperFunction>(std::move(I->second)); - LLVM_DEBUG({ - dbgs() << "Associated function tag \"" << *KV.first << "\" (" - << formatv("{0:x}", KV.second.getAddress()) << ") with handler\n"; - }); - } - return Error::success(); -} - -void ExecutorProcessControl::runJITSideWrapperFunction( - SendResultFunction SendResult, JITTargetAddress TagAddr, - ArrayRef<char> ArgBuffer) { - - std::shared_ptr<AsyncWrapperFunction> F; - { - std::lock_guard<std::mutex> Lock(TagToFuncMapMutex); - auto I = TagToFunc.find(TagAddr); - if (I != TagToFunc.end()) - F = I->second; - } - - if (F) - (*F)(std::move(SendResult), ArgBuffer.data(), ArgBuffer.size()); - else - SendResult(shared::WrapperFunctionResult::createOutOfBandError( - ("No function registered for tag " + formatv("{0:x16}", TagAddr)) - .str())); -} - SelfExecutorProcessControl::SelfExecutorProcessControl( std::shared_ptr<SymbolStringPool> SSP, Triple TargetTriple, unsigned PageSize, std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr) @@ -100,6 +46,10 @@ Expected<std::unique_ptr<SelfExecutorProcessControl>> SelfExecutorProcessControl::Create( std::shared_ptr<SymbolStringPool> SSP, std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr) { + + if (!SSP) + SSP = std::make_shared<SymbolStringPool>(); + auto PageSize = sys::Process::getPageSize(); if (!PageSize) return PageSize.takeError(); @@ -159,9 +109,9 @@ SelfExecutorProcessControl::runAsMain(JITTargetAddress MainFnAddr, return orc::runAsMain(jitTargetAddressToFunction<MainTy>(MainFnAddr), Args); } -void SelfExecutorProcessControl::runWrapperAsync(SendResultFunction SendResult, - JITTargetAddress WrapperFnAddr, - ArrayRef<char> ArgBuffer) { +void SelfExecutorProcessControl::callWrapperAsync( + SendResultFunction SendResult, JITTargetAddress WrapperFnAddr, + ArrayRef<char> ArgBuffer) { using WrapperFnTy = shared::detail::CWrapperFunctionResult (*)(const char *Data, size_t Size); auto *WrapperFn = jitTargetAddressToFunction<WrapperFnTy>(WrapperFnAddr); @@ -217,12 +167,14 @@ SelfExecutorProcessControl::jitDispatchViaWrapperFunctionManager( std::promise<shared::WrapperFunctionResult> ResultP; auto ResultF = ResultP.get_future(); - static_cast<SelfExecutorProcessControl *>(Ctx)->runJITSideWrapperFunction( - [ResultP = - std::move(ResultP)](shared::WrapperFunctionResult Result) mutable { - ResultP.set_value(std::move(Result)); - }, - pointerToJITTargetAddress(FnTag), {Data, Size}); + static_cast<SelfExecutorProcessControl *>(Ctx) + ->getExecutionSession() + .runJITDispatchHandler( + [ResultP = std::move(ResultP)]( + shared::WrapperFunctionResult Result) mutable { + ResultP.set_value(std::move(Result)); + }, + pointerToJITTargetAddress(FnTag), {Data, Size}); return ResultF.get().release(); } |