LLVM  14.0.0git
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
llvm::orc::ExecutionSession Class Reference

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. More...
 
using DispatchTaskFunction = unique_function< void(std::unique_ptr< Task > T)>
 For dispatching ORC tasks (typically materialization tasks). More...
 
using JITDispatchHandlerFunction = unique_function< void(ExecutorProcessControl::SendResultFunction SendResult, const char *ArgData, size_t ArgSize)>
 An asynchronous wrapper-function callable from the executor via jit-dispatch. More...
 
using JITDispatchHandlerAssociationMap = DenseMap< SymbolStringPtr, JITDispatchHandlerFunction >
 A map associating tag names with asynchronous wrapper function implementations in the JIT. More...
 

Public Member Functions

 ExecutionSession (std::unique_ptr< ExecutorProcessControl > EPC)
 Construct an ExecutionSession with the given ExecutorProcessControl object. More...
 
Error endSession ()
 End the session. Closes all JITDylibs. More...
 
ExecutorProcessControlgetExecutorProcessControl ()
 Get the ExecutorProcessControl object associated with this ExecutionSession. More...
 
SymbolStringPtr intern (StringRef SymName)
 Add a symbol name to the SymbolStringPool and return a pointer to it. More...
 
void setPlatform (std::unique_ptr< Platform > P)
 Set the Platform for this ExecutionSession. More...
 
PlatformgetPlatform ()
 Get the Platform for this session. More...
 
template<typename Func >
decltype(auto) runSessionLocked (Func &&F)
 Run the given lambda with the session mutex locked. More...
 
void registerResourceManager (ResourceManager &RM)
 Register the given ResourceManager with this ExecutionSession. More...
 
void deregisterResourceManager (ResourceManager &RM)
 Deregister the given ResourceManager with this ExecutionSession. More...
 
JITDylibgetJITDylibByName (StringRef Name)
 Return a pointer to the "name" JITDylib. More...
 
JITDylibcreateBareJITDylib (std::string Name)
 Add a new bare JITDylib to this ExecutionSession. More...
 
Expected< JITDylib & > createJITDylib (std::string Name)
 Add a new JITDylib to this ExecutionSession. More...
 
ExecutionSessionsetErrorReporter (ErrorReporter ReportError)
 Set the error reporter function. More...
 
void reportError (Error Err)
 Report a error for this execution session. More...
 
ExecutionSessionsetDispatchTask (DispatchTaskFunction DispatchTask)
 Set the task dispatch function. More...
 
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. More...
 
Expected< SymbolFlagsMaplookupFlags (LookupKind K, JITDylibSearchOrder SearchOrder, SymbolLookupSet Symbols)
 Blocking version of lookupFlags. More...
 
void lookup (LookupKind K, const JITDylibSearchOrder &SearchOrder, SymbolLookupSet Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete, RegisterDependenciesFunction RegisterDependencies)
 Search the given JITDylibs for the given symbols. More...
 
Expected< SymbolMaplookup (const JITDylibSearchOrder &SearchOrder, const SymbolLookupSet &Symbols, LookupKind K=LookupKind::Static, SymbolState RequiredState=SymbolState::Ready, RegisterDependenciesFunction RegisterDependencies=NoDependenciesToRegister)
 Blocking version of lookup above. More...
 
Expected< JITEvaluatedSymbollookup (const JITDylibSearchOrder &SearchOrder, SymbolStringPtr Symbol, SymbolState RequiredState=SymbolState::Ready)
 Convenience version of blocking lookup. More...
 
Expected< JITEvaluatedSymbollookup (ArrayRef< JITDylib * > SearchOrder, SymbolStringPtr Symbol, SymbolState RequiredState=SymbolState::Ready)
 Convenience version of blocking lookup. More...
 
Expected< JITEvaluatedSymbollookup (ArrayRef< JITDylib * > SearchOrder, StringRef Symbol, SymbolState RequiredState=SymbolState::Ready)
 Convenience version of blocking lookup. More...
 
void dispatchTask (std::unique_ptr< Task > T)
 Materialize the given unit. More...
 
void callWrapperAsync (ExecutorProcessControl::SendResultFunction OnComplete, JITTargetAddress WrapperFnAddr, ArrayRef< char > ArgBuffer)
 Run a wrapper function in the executor. More...
 
shared::WrapperFunctionResult callWrapper (JITTargetAddress WrapperFnAddr, ArrayRef< char > ArgBuffer)
 Run a wrapper function in the executor. More...
 
template<typename SPSSignature , typename SendResultT , typename... ArgTs>
void callSPSWrapperAsync (SendResultT &&SendResult, JITTargetAddress WrapperFnAddr, const ArgTs &...Args)
 Run a wrapper function using SPS to serialize the arguments and deserialize the results. More...
 
template<typename SPSSignature , typename... WrapperCallArgTs>
Error callSPSWrapper (JITTargetAddress WrapperFnAddr, WrapperCallArgTs &&...WrapperCallArgs)
 Run a wrapper function using SPS to serialize the arguments and deserialize the results. More...
 
Error registerJITDispatchHandlers (JITDylib &JD, JITDispatchHandlerAssociationMap WFs)
 For each tag symbol name, associate the corresponding AsyncHandlerWrapperFunction with the address of that symbol. More...
 
void runJITDispatchHandler (ExecutorProcessControl::SendResultFunction SendResult, JITTargetAddress HandlerFnTagAddr, ArrayRef< char > ArgBuffer)
 Run a registered jit-side wrapper function. More...
 
void dump (raw_ostream &OS)
 Dump the state of all the JITDylibs in this session. More...
 

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. More...
 
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. More...
 

Friends

class InProgressLookupFlagsState
 
class InProgressFullLookupState
 
class JITDylib
 
class LookupState
 
class MaterializationResponsibility
 
class ResourceTracker
 

Detailed Description

An ExecutionSession represents a running JIT program.

Definition at line 1276 of file Core.h.

Member Typedef Documentation

◆ DispatchTaskFunction

For dispatching ORC tasks (typically materialization tasks).

Definition at line 1289 of file Core.h.

◆ ErrorReporter

For reporting errors.

Definition at line 1286 of file Core.h.

◆ JITDispatchHandlerAssociationMap

A map associating tag names with asynchronous wrapper function implementations in the JIT.

Definition at line 1300 of file Core.h.

◆ JITDispatchHandlerFunction

An asynchronous wrapper-function callable from the executor via jit-dispatch.

Definition at line 1295 of file Core.h.

Constructor & Destructor Documentation

◆ ExecutionSession()

llvm::orc::ExecutionSession::ExecutionSession ( std::unique_ptr< ExecutorProcessControl EPC)

Construct an ExecutionSession with the given ExecutorProcessControl object.

Definition at line 1805 of file Core.cpp.

Member Function Documentation

◆ callSPSWrapper()

template<typename SPSSignature , typename... WrapperCallArgTs>
Error llvm::orc::ExecutionSession::callSPSWrapper ( JITTargetAddress  WrapperFnAddr,
WrapperCallArgTs &&...  WrapperCallArgs 
)
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 1509 of file Core.h.

References call(), and callWrapper().

Referenced by llvm::orc::EPCDebugObjectRegistrar::registerDebugObject().

◆ callSPSWrapperAsync()

template<typename SPSSignature , typename SendResultT , typename... ArgTs>
void llvm::orc::ExecutionSession::callSPSWrapperAsync ( SendResultT &&  SendResult,
JITTargetAddress  WrapperFnAddr,
const ArgTs &...  Args 
)
inline

Run a wrapper function using SPS to serialize the arguments and deserialize the results.

Definition at line 1490 of file Core.h.

References llvm::AMDGPU::HSAMD::Kernel::Key::Args, callWrapperAsync(), and move.

◆ callWrapper()

shared::WrapperFunctionResult llvm::orc::ExecutionSession::callWrapper ( JITTargetAddress  WrapperFnAddr,
ArrayRef< char >  ArgBuffer 
)
inline

Run a wrapper function in the executor.

The wrapper function should be callable as:

CWrapperFunctionResult fn(uint8_t *Data, uint64_t Size);

{.cpp}

Definition at line 1477 of file Core.h.

References callWrapperAsync(), move, llvm::RISCVFenceField::R, and llvm::AArch64::RP.

Referenced by callSPSWrapper().

◆ callWrapperAsync()

void llvm::orc::ExecutionSession::callWrapperAsync ( ExecutorProcessControl::SendResultFunction  OnComplete,
JITTargetAddress  WrapperFnAddr,
ArrayRef< char >  ArgBuffer 
)
inline

Run a wrapper function in the executor.

The wrapper function should be callable as:

CWrapperFunctionResult fn(uint8_t *Data, uint64_t Size);

{.cpp}

The given OnComplete function will be called to return the result.

Definition at line 1465 of file Core.h.

References move.

Referenced by callSPSWrapperAsync(), and callWrapper().

◆ createBareJITDylib()

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 1856 of file Core.cpp.

References assert(), getJITDylibByName(), JITDylib, move, and runSessionLocked().

Referenced by createJITDylib().

◆ createJITDylib()

Expected< JITDylib & > llvm::orc::ExecutionSession::createJITDylib ( std::string  Name)

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 1864 of file Core.cpp.

References createBareJITDylib().

◆ deregisterResourceManager()

void llvm::orc::ExecutionSession::deregisterResourceManager ( ResourceManager RM)

Deregister the given ResourceManager with this ExecutionSession.

Manager must have been previously registered.

Definition at line 1834 of file Core.cpp.

References assert(), llvm::find(), I, llvm::AArch64::RM, and runSessionLocked().

◆ dispatchTask()

void llvm::orc::ExecutionSession::dispatchTask ( std::unique_ptr< Task T)
inline

Materialize the given unit.

Definition at line 1450 of file Core.h.

References assert(), DEBUG_WITH_TYPE, move, and T.

◆ dump()

void llvm::orc::ExecutionSession::dump ( raw_ostream OS)

Dump the state of all the JITDylibs in this session.

Definition at line 2109 of file Core.cpp.

References runSessionLocked().

◆ endSession()

Error llvm::orc::ExecutionSession::endSession ( )

End the session. Closes all JITDylibs.

Definition at line 1811 of file Core.cpp.

References llvm::dbgs(), LLVM_DEBUG, move, and runSessionLocked().

◆ getExecutorProcessControl()

ExecutorProcessControl& llvm::orc::ExecutionSession::getExecutorProcessControl ( )
inline

◆ getJITDylibByName()

JITDylib * llvm::orc::ExecutionSession::getJITDylibByName ( StringRef  Name)

Return a pointer to the "name" JITDylib.

Ownership of JITDylib remains within Execution Session

Definition at line 1847 of file Core.cpp.

References runSessionLocked().

Referenced by createBareJITDylib().

◆ getPlatform()

Platform* llvm::orc::ExecutionSession::getPlatform ( )
inline

Get the Platform for this session.

Will return null if no Platform has been set for this ExecutionSession.

Definition at line 1321 of file Core.h.

References P.

◆ intern()

SymbolStringPtr llvm::orc::ExecutionSession::intern ( StringRef  SymName)
inline

◆ lookup() [1/5]

Expected< JITEvaluatedSymbol > llvm::orc::ExecutionSession::lookup ( ArrayRef< JITDylib * >  SearchOrder,
StringRef  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 2052 of file Core.cpp.

References intern(), and lookup().

◆ lookup() [2/5]

Expected< JITEvaluatedSymbol > 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 2046 of file Core.cpp.

References lookup(), and llvm::orc::makeJITDylibSearchOrder().

◆ lookup() [3/5]

Expected< SymbolMap > llvm::orc::ExecutionSession::lookup ( const JITDylibSearchOrder SearchOrder,
const 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 1978 of file Core.cpp.

References _, lookup(), move, and llvm::Error::success().

◆ lookup() [4/5]

Expected< JITEvaluatedSymbol > 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 2032 of file Core.cpp.

References assert(), lookup(), move, llvm::orc::NoDependenciesToRegister, and llvm::orc::Static.

◆ lookup() [5/5]

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 1948 of file Core.cpp.

References llvm::dbgs(), LLVM_DEBUG, move, runSessionLocked(), and llvm::Error::success().

Referenced by lookup(), llvm::orc::Platform::lookupInitSymbols(), registerJITDispatchHandlers(), and llvm::orc::Speculator::registerSymbols().

◆ lookupFlags() [1/2]

Expected< SymbolFlagsMap > llvm::orc::ExecutionSession::lookupFlags ( LookupKind  K,
JITDylibSearchOrder  SearchOrder,
SymbolLookupSet  Symbols 
)

Blocking version of lookupFlags.

Definition at line 1933 of file Core.cpp.

References move, and llvm::Error::success().

◆ lookupFlags() [2/2]

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 1922 of file Core.cpp.

References move, and llvm::Error::success().

Referenced by llvm::orc::buildSimpleReexportsAliasMap(), and llvm::orc::ReexportsGenerator::tryToGenerate().

◆ registerJITDispatchHandlers()

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 2057 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, llvm::Lock, lookup(), llvm::orc::MatchAllSymbols, move, llvm::Error::success(), and llvm::orc::WeaklyReferencedSymbol.

◆ registerResourceManager()

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 1830 of file Core.cpp.

References llvm::AArch64::RM, and runSessionLocked().

Referenced by llvm::orc::ObjectLinkingLayer::ObjectLinkingLayer(), and llvm::orc::RTDyldObjectLinkingLayer::RTDyldObjectLinkingLayer().

◆ reportError()

void llvm::orc::ExecutionSession::reportError ( Error  Err)
inline

Report a error for this execution session.

Unhandled errors can be sent here to log them.

Definition at line 1371 of file Core.h.

Referenced by llvm::orc::IRTransformLayer::emit(), llvm::orc::IRCompileLayer::emit(), and llvm::orc::Speculator::registerSymbols().

◆ runJITDispatchHandler()

void llvm::orc::ExecutionSession::runJITDispatchHandler ( ExecutorProcessControl::SendResultFunction  SendResult,
JITTargetAddress  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 2088 of file Core.cpp.

References llvm::orc::shared::WrapperFunctionResult::createOutOfBandError(), llvm::ArrayRef< T >::data(), F, llvm::formatv(), I, llvm::Lock, move, and llvm::ArrayRef< T >::size().

◆ runSessionLocked()

template<typename Func >
decltype(auto) llvm::orc::ExecutionSession::runSessionLocked ( Func &&  F)
inline

◆ setDispatchTask()

ExecutionSession& llvm::orc::ExecutionSession::setDispatchTask ( DispatchTaskFunction  DispatchTask)
inline

Set the task dispatch function.

Definition at line 1374 of file Core.h.

References move.

◆ setErrorReporter()

ExecutionSession& llvm::orc::ExecutionSession::setErrorReporter ( ErrorReporter  ReportError)
inline

Set the error reporter function.

Definition at line 1363 of file Core.h.

References move.

◆ setPlatform()

void llvm::orc::ExecutionSession::setPlatform ( std::unique_ptr< Platform P)
inline

Set the Platform for this ExecutionSession.

Definition at line 1317 of file Core.h.

References move, and P.

◆ wrapAsyncWithSPS() [1/2]

template<typename SPSSignature , typename ClassT , typename... MethodArgTs>
static JITDispatchHandlerFunction llvm::orc::ExecutionSession::wrapAsyncWithSPS ( ClassT *  Instance,
void(ClassT::*)(MethodArgTs...)  Method 
)
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.

Definition at line 1544 of file Core.h.

◆ wrapAsyncWithSPS() [2/2]

template<typename SPSSignature , typename HandlerT >
static JITDispatchHandlerFunction llvm::orc::ExecutionSession::wrapAsyncWithSPS ( HandlerT &&  H)
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 1526 of file Core.h.

References H, and move.

Friends And Related Function Documentation

◆ InProgressFullLookupState

friend class InProgressFullLookupState
friend

Definition at line 1278 of file Core.h.

◆ InProgressLookupFlagsState

friend class InProgressLookupFlagsState
friend

Definition at line 1277 of file Core.h.

◆ JITDylib

friend class JITDylib
friend

Definition at line 1279 of file Core.h.

Referenced by createBareJITDylib().

◆ LookupState

friend class LookupState
friend

Definition at line 1280 of file Core.h.

◆ MaterializationResponsibility

friend class MaterializationResponsibility
friend

Definition at line 1281 of file Core.h.

◆ ResourceTracker

friend class ResourceTracker
friend

Definition at line 1282 of file Core.h.


The documentation for this class was generated from the following files:
llvm::Check::Size
@ Size
Definition: FileCheck.h:73