LLVM 17.0.0git
|
An ExecutionSession represents a running JIT program. More...
#include "llvm/ExecutionEngine/Orc/Core.h"
Public Types | |
using | ErrorReporter = std::function< void(Error)> |
For reporting errors. | |
using | SendResultFunction = unique_function< void(shared::WrapperFunctionResult)> |
Send a result to the remote. | |
using | DispatchTaskFunction = unique_function< void(std::unique_ptr< Task > T)> |
For dispatching ORC tasks (typically materialization tasks). | |
using | JITDispatchHandlerFunction = unique_function< void(SendResultFunction SendResult, const char *ArgData, size_t ArgSize)> |
An asynchronous wrapper-function callable from the executor via jit-dispatch. | |
using | JITDispatchHandlerAssociationMap = DenseMap< SymbolStringPtr, JITDispatchHandlerFunction > |
A map associating tag names with asynchronous wrapper function implementations in the JIT. | |
Public Member Functions | |
ExecutionSession (std::unique_ptr< ExecutorProcessControl > EPC) | |
Construct an ExecutionSession with the given ExecutorProcessControl object. | |
~ExecutionSession () | |
Destroy an ExecutionSession. | |
Error | endSession () |
End the session. | |
ExecutorProcessControl & | getExecutorProcessControl () |
Get the ExecutorProcessControl object associated with this ExecutionSession. | |
const Triple & | getTargetTriple () const |
Return the triple for the executor. | |
std::shared_ptr< SymbolStringPool > | getSymbolStringPool () |
Get the SymbolStringPool for this instance. | |
SymbolStringPtr | intern (StringRef SymName) |
Add a symbol name to the SymbolStringPool and return a pointer to it. | |
void | setPlatform (std::unique_ptr< Platform > P) |
Set the Platform for this ExecutionSession. | |
Platform * | getPlatform () |
Get the Platform for this session. | |
template<typename Func > | |
decltype(auto) | runSessionLocked (Func &&F) |
Run the given lambda with the session mutex locked. | |
void | registerResourceManager (ResourceManager &RM) |
Register the given ResourceManager with this ExecutionSession. | |
void | deregisterResourceManager (ResourceManager &RM) |
Deregister the given ResourceManager with this ExecutionSession. | |
JITDylib * | getJITDylibByName (StringRef Name) |
Return a pointer to the "name" JITDylib. | |
JITDylib & | createBareJITDylib (std::string Name) |
Add a new bare JITDylib to this ExecutionSession. | |
Expected< JITDylib & > | createJITDylib (std::string Name) |
Add a new JITDylib to this ExecutionSession. | |
Error | removeJITDylib (JITDylib &JD) |
Closes the given JITDylib. | |
ExecutionSession & | setErrorReporter (ErrorReporter ReportError) |
Set the error reporter function. | |
void | reportError (Error Err) |
Report a error for this execution session. | |
ExecutionSession & | setDispatchTask (DispatchTaskFunction DispatchTask) |
Set the task dispatch function. | |
void | lookupFlags (LookupKind K, JITDylibSearchOrder SearchOrder, SymbolLookupSet Symbols, unique_function< void(Expected< SymbolFlagsMap >)> OnComplete) |
Search the given JITDylibs to find the flags associated with each of the given symbols. | |
Expected< SymbolFlagsMap > | lookupFlags (LookupKind K, JITDylibSearchOrder SearchOrder, SymbolLookupSet Symbols) |
Blocking version of lookupFlags. | |
void | lookup (LookupKind K, const JITDylibSearchOrder &SearchOrder, SymbolLookupSet Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete, RegisterDependenciesFunction RegisterDependencies) |
Search the given JITDylibs for the given symbols. | |
Expected< SymbolMap > | lookup (const JITDylibSearchOrder &SearchOrder, SymbolLookupSet Symbols, LookupKind K=LookupKind::Static, SymbolState RequiredState=SymbolState::Ready, RegisterDependenciesFunction RegisterDependencies=NoDependenciesToRegister) |
Blocking version of lookup above. | |
Expected< ExecutorSymbolDef > | lookup (const JITDylibSearchOrder &SearchOrder, SymbolStringPtr Symbol, SymbolState RequiredState=SymbolState::Ready) |
Convenience version of blocking lookup. | |
Expected< ExecutorSymbolDef > | lookup (ArrayRef< JITDylib * > SearchOrder, SymbolStringPtr Symbol, SymbolState RequiredState=SymbolState::Ready) |
Convenience version of blocking lookup. | |
Expected< ExecutorSymbolDef > | lookup (ArrayRef< JITDylib * > SearchOrder, StringRef Symbol, SymbolState RequiredState=SymbolState::Ready) |
Convenience version of blocking lookup. | |
void | dispatchTask (std::unique_ptr< Task > T) |
Materialize the given unit. | |
template<typename... ArgTs> | |
void | callWrapperAsync (ArgTs &&... Args) |
Run a wrapper function in the executor. | |
shared::WrapperFunctionResult | callWrapper (ExecutorAddr WrapperFnAddr, ArrayRef< char > ArgBuffer) |
Run a wrapper function in the executor. | |
template<typename SPSSignature , typename SendResultT , typename... ArgTs> | |
void | callSPSWrapperAsync (ExecutorAddr WrapperFnAddr, SendResultT &&SendResult, const ArgTs &...Args) |
Run a wrapper function using SPS to serialize the arguments and deserialize the results. | |
template<typename SPSSignature , typename... WrapperCallArgTs> | |
Error | callSPSWrapper (ExecutorAddr WrapperFnAddr, WrapperCallArgTs &&...WrapperCallArgs) |
Run a wrapper function using SPS to serialize the arguments and deserialize the results. | |
Error | registerJITDispatchHandlers (JITDylib &JD, JITDispatchHandlerAssociationMap WFs) |
For each tag symbol name, associate the corresponding AsyncHandlerWrapperFunction with the address of that symbol. | |
void | runJITDispatchHandler (SendResultFunction SendResult, ExecutorAddr HandlerFnTagAddr, ArrayRef< char > ArgBuffer) |
Run a registered jit-side wrapper function. | |
void | dump (raw_ostream &OS) |
Dump the state of all the JITDylibs in this session. | |
Static Public Member Functions | |
template<typename SPSSignature , typename HandlerT > | |
static JITDispatchHandlerFunction | wrapAsyncWithSPS (HandlerT &&H) |
Wrap a handler that takes concrete argument types (and a sender for a concrete return type) to produce an AsyncHandlerWrapperFunction. | |
template<typename SPSSignature , typename ClassT , typename... MethodArgTs> | |
static JITDispatchHandlerFunction | wrapAsyncWithSPS (ClassT *Instance, void(ClassT::*Method)(MethodArgTs...)) |
Wrap a class method that takes concrete argument types (and a sender for a concrete return type) to produce an AsyncHandlerWrapperFunction. | |
Friends | |
class | InProgressLookupFlagsState |
class | InProgressFullLookupState |
class | JITDylib |
class | LookupState |
class | MaterializationResponsibility |
class | ResourceTracker |
An ExecutionSession represents a running JIT program.
using llvm::orc::ExecutionSession::DispatchTaskFunction = unique_function<void(std::unique_ptr<Task> T)> |
using llvm::orc::ExecutionSession::ErrorReporter = std::function<void(Error)> |
using llvm::orc::ExecutionSession::JITDispatchHandlerFunction = unique_function<void( SendResultFunction SendResult, const char *ArgData, size_t ArgSize)> |
llvm::orc::ExecutionSession::ExecutionSession | ( | std::unique_ptr< ExecutorProcessControl > | EPC | ) |
Construct an ExecutionSession with the given ExecutorProcessControl object.
llvm::orc::ExecutionSession::~ExecutionSession | ( | ) |
Destroy an ExecutionSession.
Verifies that endSession was called prior to destruction.
Definition at line 1909 of file Core.cpp.
References assert().
|
inline |
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
If SPSSignature is a non-void function signature then the second argument (the first in the Args list) should be a reference to a return value.
Definition at line 1612 of file Core.h.
Referenced by llvm::orc::EPCEHFrameRegistrar::deregisterEHFrames(), llvm::orc::EPCDebugObjectRegistrar::registerDebugObject(), and llvm::orc::EPCEHFrameRegistrar::registerEHFrames().
|
inline |
|
inline |
Run a wrapper function in the executor.
The wrapper function should be callable as:
{.cpp}
|
inline |
JITDylib & llvm::orc::ExecutionSession::createBareJITDylib | ( | std::string | Name | ) |
Add a new bare JITDylib to this ExecutionSession.
The JITDylib Name is required to be unique. Clients should verify that names are not being re-used (E.g. by calling getJITDylibByName) if names are based on user input.
This call does not install any library code or symbols into the newly created JITDylib. The client is responsible for all configuration.
Definition at line 1960 of file Core.cpp.
References assert(), getJITDylibByName(), JITDylib, Name, and runSessionLocked().
Referenced by llvm::orc::COFFPlatform::Create(), createJITDylib(), and llvm::orc::ExecutorNativePlatform::operator()().
Add a new JITDylib to this ExecutionSession.
The JITDylib Name is required to be unique. Clients should verify that names are not being re-used (e.g. by calling getJITDylibByName) if names are based on user input.
If a Platform is attached then Platform::setupJITDylib will be called to install standard platform symbols (e.g. standard library interposes). If no Platform is attached this call is equivalent to createBareJITDylib.
Definition at line 1968 of file Core.cpp.
References createBareJITDylib(), and Name.
void llvm::orc::ExecutionSession::deregisterResourceManager | ( | ResourceManager & | RM | ) |
Deregister the given ResourceManager with this ExecutionSession.
Manager must have been previously registered.
Definition at line 1938 of file Core.cpp.
References assert(), llvm::find(), I, and runSessionLocked().
|
inline |
Materialize the given unit.
Definition at line 1566 of file Core.h.
References assert(), and DEBUG_WITH_TYPE.
void llvm::orc::ExecutionSession::dump | ( | raw_ostream & | OS | ) |
Dump the state of all the JITDylibs in this session.
Definition at line 2257 of file Core.cpp.
References OS, and runSessionLocked().
Error llvm::orc::ExecutionSession::endSession | ( | ) |
End the session.
Closes all JITDylibs and disconnects from the executor. Clients must call this method before destroying the session.
Definition at line 1915 of file Core.cpp.
References llvm::dbgs(), llvm::joinErrors(), LLVM_DEBUG, llvm::reverse(), runSessionLocked(), and llvm::Error::success().
|
inline |
Get the ExecutorProcessControl object associated with this ExecutionSession.
Definition at line 1407 of file Core.h.
Referenced by llvm::orc::EPCIndirectionUtils::Create(), llvm::orc::ELFNixPlatform::Create(), llvm::orc::MachOPlatform::Create(), llvm::orc::COFFPlatform::Create(), llvm::orc::EPCEHFrameRegistrar::Create(), llvm::orc::createJITLoaderGDBRegistrar(), llvm::orc::COFFVCRuntimeBootstrapper::initializeStaticVCRuntime(), and llvm::orc::EPCDynamicLibrarySearchGenerator::Load().
Return a pointer to the "name" JITDylib.
Ownership of JITDylib remains within Execution Session
Definition at line 1951 of file Core.cpp.
References Name, and runSessionLocked().
Referenced by createBareJITDylib().
|
inline |
Get the Platform for this session.
Will return null if no Platform has been set for this ExecutionSession.
Definition at line 1425 of file Core.h.
References P.
Referenced by llvm::orc::JITDylib::define().
|
inline |
Get the SymbolStringPool for this instance.
Definition at line 1413 of file Core.h.
Referenced by llvm::orc::JITDylib::remove().
Return the triple for the executor.
Definition at line 1410 of file Core.h.
Referenced by llvm::orc::ELFNixPlatform::Create(), llvm::orc::MachOPlatform::Create(), and llvm::orc::COFFPlatform::Create().
|
inline |
Add a symbol name to the SymbolStringPool and return a pointer to it.
Definition at line 1418 of file Core.h.
Referenced by llvm::orc::addAliases(), llvm::orc::addInitSymbol(), llvm::orc::GDBJITDebugInfoRegistrationPlugin::Create(), llvm::orc::ELFNixPlatform::Create(), llvm::orc::MachOPlatform::Create(), llvm::orc::COFFPlatform::Create(), llvm::orc::getCOFFObjectFileSymbolInfo(), llvm::orc::JITCompileCallbackManager::getCompileCallback(), llvm::orc::getELFObjectFileSymbolInfo(), llvm::orc::getGenericObjectFileSymbolInfo(), llvm::orc::getMachOObjectFileSymbolInfo(), llvm::orc::COFFVCRuntimeBootstrapper::initializeStaticVCRuntime(), llvm::orc::IRMaterializationUnit::IRMaterializationUnit(), lookup(), llvm::orc::MangleAndInterner::operator()(), and llvm::orc::DLLImportDefinitionGenerator::tryToGenerate().
Expected< ExecutorSymbolDef > llvm::orc::ExecutionSession::lookup | ( | ArrayRef< JITDylib * > | SearchOrder, |
StringRef | Symbol, | ||
SymbolState | RequiredState = SymbolState::Ready |
||
) |
Expected< ExecutorSymbolDef > llvm::orc::ExecutionSession::lookup | ( | ArrayRef< JITDylib * > | SearchOrder, |
SymbolStringPtr | Symbol, | ||
SymbolState | RequiredState = SymbolState::Ready |
||
) |
Convenience version of blocking lookup.
Searches each of the JITDylibs in the search order in turn for the given symbol. The search will not find non-exported symbols.
Definition at line 2194 of file Core.cpp.
References lookup(), llvm::orc::makeJITDylibSearchOrder(), and Name.
Expected< SymbolMap > llvm::orc::ExecutionSession::lookup | ( | const JITDylibSearchOrder & | SearchOrder, |
SymbolLookupSet | Symbols, | ||
LookupKind | K = LookupKind::Static , |
||
SymbolState | RequiredState = SymbolState::Ready , |
||
RegisterDependenciesFunction | RegisterDependencies = NoDependenciesToRegister |
||
) |
Blocking version of lookup above.
Returns the resolved symbol map. If WaitUntilReady is true (the default), will not return until all requested symbols are ready (or an error occurs). If WaitUntilReady is false, will return as soon as all requested symbols are resolved, or an error occurs. If WaitUntilReady is false and an error occurs after resolution, the function will return a success value, but the error will be reported via reportErrors.
Definition at line 2126 of file Core.cpp.
References _, lookup(), llvm::orc::Result, and llvm::Error::success().
Expected< ExecutorSymbolDef > llvm::orc::ExecutionSession::lookup | ( | const JITDylibSearchOrder & | SearchOrder, |
SymbolStringPtr | Symbol, | ||
SymbolState | RequiredState = SymbolState::Ready |
||
) |
Convenience version of blocking lookup.
Searches each of the JITDylibs in the search order in turn for the given symbol.
Definition at line 2180 of file Core.cpp.
References assert(), lookup(), Name, Names, llvm::orc::NoDependenciesToRegister, and llvm::orc::Static.
void llvm::orc::ExecutionSession::lookup | ( | LookupKind | K, |
const JITDylibSearchOrder & | SearchOrder, | ||
SymbolLookupSet | Symbols, | ||
SymbolState | RequiredState, | ||
SymbolsResolvedCallback | NotifyComplete, | ||
RegisterDependenciesFunction | RegisterDependencies | ||
) |
Search the given JITDylibs for the given symbols.
SearchOrder lists the JITDylibs to search. For each dylib, the associated boolean indicates whether the search should match against non-exported (hidden visibility) symbols in that dylib (true means match against non-exported symbols, false means do not match).
The NotifyComplete callback will be called once all requested symbols reach the required state.
If all symbols are found, the RegisterDependencies function will be called while the session lock is held. This gives clients a chance to register dependencies for on the queried symbols for any symbols they are materializing (if a MaterializationResponsibility instance is present, this can be implemented by calling MaterializationResponsibility::addDependencies). If there are no dependenant symbols for this query (e.g. it is being made by a top level client to get an address to call) then the value NoDependenciesToRegister can be used.
Definition at line 2096 of file Core.cpp.
References llvm::dbgs(), LLVM_DEBUG, runSessionLocked(), and llvm::Error::success().
Referenced by llvm::orc::GDBJITDebugInfoRegistrationPlugin::Create(), llvm::orc::JITCompileCallbackManager::executeCompileCallback(), lookup(), llvm::orc::lookupAndRecordAddrs(), llvm::orc::Platform::lookupInitSymbols(), llvm::orc::Platform::lookupInitSymbolsAsync(), registerJITDispatchHandlers(), llvm::orc::Speculator::registerSymbols(), llvm::orc::LazyCallThroughManager::resolveTrampolineLandingAddress(), llvm::orc::COFFPlatform::setupJITDylib(), llvm::orc::MachOPlatform::setupJITDylib(), and llvm::orc::DLLImportDefinitionGenerator::tryToGenerate().
Expected< SymbolFlagsMap > llvm::orc::ExecutionSession::lookupFlags | ( | LookupKind | K, |
JITDylibSearchOrder | SearchOrder, | ||
SymbolLookupSet | Symbols | ||
) |
Blocking version of lookupFlags.
Definition at line 2081 of file Core.cpp.
References llvm::orc::Result, and llvm::Error::success().
void llvm::orc::ExecutionSession::lookupFlags | ( | LookupKind | K, |
JITDylibSearchOrder | SearchOrder, | ||
SymbolLookupSet | Symbols, | ||
unique_function< void(Expected< SymbolFlagsMap >)> | OnComplete | ||
) |
Search the given JITDylibs to find the flags associated with each of the given symbols.
Definition at line 2070 of file Core.cpp.
References llvm::Error::success().
Referenced by llvm::orc::buildSimpleReexportsAliasMap(), and llvm::orc::ReexportsGenerator::tryToGenerate().
Error llvm::orc::ExecutionSession::registerJITDispatchHandlers | ( | JITDylib & | JD, |
JITDispatchHandlerAssociationMap | WFs | ||
) |
For each tag symbol name, associate the corresponding AsyncHandlerWrapperFunction with the address of that symbol.
The handler becomes callable from the executor using the ORC runtime __orc_rt_jit_dispatch function and the given tag.
Tag symbols will be looked up in JD using LookupKind::Static, JITDylibLookupFlags::MatchAllSymbols (hidden tags will be found), and LookupFlags::WeaklyReferencedSymbol. Missing tag definitions will not cause an error, the handler will simply be dropped.
Definition at line 2205 of file Core.cpp.
References assert(), llvm::dbgs(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::formatv(), llvm::orc::SymbolLookupSet::fromMapKeys(), I, llvm::inconvertibleErrorCode(), LLVM_DEBUG, lookup(), llvm::orc::MatchAllSymbols, llvm::Error::success(), and llvm::orc::WeaklyReferencedSymbol.
void llvm::orc::ExecutionSession::registerResourceManager | ( | ResourceManager & | RM | ) |
Register the given ResourceManager with this ExecutionSession.
Managers will be notified of events in reverse order of registration.
Definition at line 1934 of file Core.cpp.
References runSessionLocked().
Referenced by llvm::orc::ObjectLinkingLayer::ObjectLinkingLayer(), and llvm::orc::RTDyldObjectLinkingLayer::RTDyldObjectLinkingLayer().
Closes the given JITDylib.
This method clears all resources held for the JITDylib, puts it in the closed state, and clears all references held by the ExecutionSession and other JITDylibs. No further code can be added to the JITDylib, and the object will be freed once any remaining JITDylibSPs to it are destroyed.
This method does not run static destructors.
This method can only be called once for each JITDylib.
Definition at line 1976 of file Core.cpp.
References assert(), llvm::orc::JITDylib::clear(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::empty(), llvm::find(), I, llvm::joinErrors(), and runSessionLocked().
|
inline |
Report a error for this execution session.
Unhandled errors can be sent here to log them.
Definition at line 1487 of file Core.h.
Referenced by llvm::orc::SimpleRemoteEPC::callWrapperAsync(), llvm::orc::CompileOnDemandLayer::emit(), llvm::orc::IRCompileLayer::emit(), llvm::orc::IRTransformLayer::emit(), llvm::orc::JITCompileCallbackManager::executeCompileCallback(), llvm::orc::Speculator::registerSymbols(), llvm::orc::LazyCallThroughManager::reportCallThroughError(), and llvm::orc::DebugObject::~DebugObject().
void llvm::orc::ExecutionSession::runJITDispatchHandler | ( | SendResultFunction | SendResult, |
ExecutorAddr | HandlerFnTagAddr, | ||
ArrayRef< char > | ArgBuffer | ||
) |
Run a registered jit-side wrapper function.
This should be called by the ExecutorProcessControl instance in response to incoming jit-dispatch requests from the executor.
Definition at line 2236 of file Core.cpp.
References llvm::orc::shared::WrapperFunctionResult::createOutOfBandError(), llvm::ArrayRef< T >::data(), F, llvm::formatv(), I, and llvm::ArrayRef< T >::size().
|
inline |
Run the given lambda with the session mutex locked.
Definition at line 1428 of file Core.h.
References F.
Referenced by llvm::orc::JITDylib::addGenerator(), llvm::orc::JITDylib::addToLinkOrder(), llvm::orc::JITDylib::clear(), createBareJITDylib(), llvm::orc::JITDylib::createResourceTracker(), llvm::orc::JITDylib::define(), deregisterResourceManager(), llvm::orc::JITDylib::dump(), dump(), endSession(), llvm::orc::JITDylib::getDefaultResourceTracker(), getJITDylibByName(), lookup(), llvm::orc::EHFrameRegistrationPlugin::notifyRemovingResources(), registerResourceManager(), llvm::orc::JITDylib::remove(), llvm::orc::JITDylib::removeFromLinkOrder(), llvm::orc::JITDylib::removeGenerator(), removeJITDylib(), llvm::orc::JITDylib::replaceInLinkOrder(), llvm::orc::JITDylib::setLinkOrder(), and llvm::orc::ResourceTracker::withResourceKeyDo().
|
inline |
|
inline |
|
inline |
Set the Platform for this ExecutionSession.
Definition at line 1421 of file Core.h.
References P.
Referenced by llvm::orc::ExecutorNativePlatform::operator()().
|
inlinestatic |
Wrap a class method that takes concrete argument types (and a sender for a concrete return type) to produce an AsyncHandlerWrapperFunction.
Uses SPS to unpack teh arguments and pack the result.
This function is intended to support easy construction of AsyncHandlerWrapperFunctions that can be associated with a tag (using registerJITDispatchHandler) and called from the executor.
|
inlinestatic |
Wrap a handler that takes concrete argument types (and a sender for a concrete return type) to produce an AsyncHandlerWrapperFunction.
Uses SPS to unpack the arguments and pack the result.
This function is intended to support easy construction of AsyncHandlerWrapperFunctions that can be associated with a tag (using registerJITDispatchHandler) and called from the executor.
Definition at line 1626 of file Core.h.
References H.
|
friend |
|
friend |
|
friend |
Definition at line 1367 of file Core.h.
Referenced by createBareJITDylib().
|
friend |
|
friend |
|
friend |