13#ifndef LLVM_EXECUTIONENGINE_ORC_CORE_H
14#define LLVM_EXECUTIONENGINE_ORC_CORE_H
43class AsynchronousSymbolQuery;
44class ExecutionSession;
45class MaterializationResponsibility;
48class InProgressLookupState;
94 return *
reinterpret_cast<JITDylib *
>(JDAndFlag.load() &
95 ~static_cast<uintptr_t>(1));
110 bool isDefunct()
const {
return JDAndFlag.load() & 0x1; }
122 std::atomic_uintptr_t JDAndFlag;
174 std::vector<std::pair<JITDylib *, JITDylibLookupFlags>>;
182 O.reserve(JDs.
size());
184 O.push_back(std::make_pair(JD, Flags));
197 using value_type = std::pair<SymbolStringPtr, SymbolLookupFlags>;
205 for (
auto &
E : Elems)
206 Symbols.push_back(std::move(
E));
217 std::initializer_list<SymbolStringPtr> Names,
219 Symbols.reserve(Names.size());
220 for (
const auto &
Name : Names)
229 Symbols.reserve(Names.
size());
230 for (
const auto &
Name : Names)
241 Symbols.reserve(Names.
size());
242 for (
const auto &
Name : Names)
247 template <
typename ValT>
252 Result.Symbols.reserve(M.size());
253 for (
const auto &[
Name, Val] : M)
263 Symbols.push_back(std::make_pair(std::move(
Name), Flags));
269 Symbols.reserve(Symbols.size() +
Other.size());
270 for (
auto &KV :
Other)
271 Symbols.push_back(std::move(KV));
275 bool empty()
const {
return Symbols.empty(); }
276 UnderlyingVector::size_type
size()
const {
return Symbols.size(); }
294 template <
typename PredFn>
void remove_if(PredFn &&Pred) {
295 UnderlyingVector::size_type
I = 0;
296 while (
I != Symbols.size()) {
297 const auto &
Name = Symbols[
I].first;
298 auto Flags = Symbols[
I].second;
299 if (Pred(
Name, Flags))
311 template <
typename BodyFn>
313 std::is_same<decltype(Body(std::declval<const SymbolStringPtr &>(),
314 std::declval<SymbolLookupFlags>())),
316 UnderlyingVector::size_type
I = 0;
317 while (
I != Symbols.size()) {
318 const auto &
Name = Symbols[
I].first;
319 auto Flags = Symbols[
I].second;
320 if (Body(
Name, Flags))
333 template <
typename BodyFn>
335 std::is_same<decltype(Body(std::declval<const SymbolStringPtr &>(),
336 std::declval<SymbolLookupFlags>())),
339 UnderlyingVector::size_type
I = 0;
340 while (
I != Symbols.size()) {
341 const auto &
Name = Symbols[
I].first;
342 auto Flags = Symbols[
I].second;
343 auto Remove = Body(
Name, Flags);
345 return Remove.takeError();
358 Names.reserve(Symbols.size());
359 for (
const auto &KV : Symbols)
360 Names.push_back(KV.first);
373 return *
LHS.first < *
RHS.first;
382 Symbols.erase(LastI, Symbols.end());
389 if (Symbols.size() < 2)
392 for (UnderlyingVector::size_type
I = 1;
I != Symbols.size(); ++
I)
393 if (Symbols[
I].first == Symbols[
I - 1].first)
427 :
public ErrorInfo<ResourceTrackerDefunct> {
432 std::error_code convertToErrorCode()
const override;
446 std::shared_ptr<SymbolDependenceMap> Symbols);
448 std::error_code convertToErrorCode()
const override;
453 std::shared_ptr<SymbolStringPool> SSP;
454 std::shared_ptr<SymbolDependenceMap> Symbols;
459 :
public ErrorInfo<UnsatisfiedSymbolDependencies> {
466 std::string Explanation);
467 std::error_code convertToErrorCode()
const override;
471 std::shared_ptr<SymbolStringPool> SSP;
475 std::string Explanation;
486 std::error_code convertToErrorCode()
const override;
492 std::shared_ptr<SymbolStringPool> SSP;
498 :
public ErrorInfo<SymbolsCouldNotBeRemoved> {
504 std::error_code convertToErrorCode()
const override;
510 std::shared_ptr<SymbolStringPool> SSP;
519 :
public ErrorInfo<MissingSymbolDefinitions> {
527 std::error_code convertToErrorCode()
const override;
533 std::shared_ptr<SymbolStringPool> SSP;
543 :
public ErrorInfo<UnexpectedSymbolDefinitions> {
551 std::error_code convertToErrorCode()
const override;
557 std::shared_ptr<SymbolStringPool> SSP;
596 return RT->withResourceKeyDo(std::forward<Func>(
F));
698 : JD(RT->getJITDylib()), RT(
std::
move(RT)),
699 SymbolFlags(
std::
move(SymbolFlags)), InitSymbol(
std::
move(InitSymbol)) {
700 assert(!this->SymbolFlags.
empty() &&
"Materializing nothing?");
706 SymbolStringPtr InitSymbol;
728 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override;
749inline std::unique_ptr<ReExportsMaterializationUnit>
751 return std::make_unique<ReExportsMaterializationUnit>(
758inline std::unique_ptr<ReExportsMaterializationUnit>
762 return std::make_unique<ReExportsMaterializationUnit>(
763 &SourceJD, SourceJDLookupFlags, std::move(Aliases));
806 bool isComplete()
const {
return OutstandingSymbolsCount == 0; }
812 SymbolState getRequiredState() {
return RequiredState; }
814 void addQueryDependence(
JITDylib &JD, SymbolStringPtr
Name);
816 void removeQueryDependence(
JITDylib &JD,
const SymbolStringPtr &
Name);
818 void dropSymbol(
const SymbolStringPtr &
Name);
820 void handleFailed(
Error Err);
827 size_t OutstandingSymbolsCount;
849 LookupState(std::unique_ptr<InProgressLookupState> IPLS);
854 std::unique_ptr<InProgressLookupState> IPLS;
878 std::deque<LookupState> PendingLookups;
961 template <
typename GeneratorT>
962 GeneratorT &
addGenerator(std::unique_ptr<GeneratorT> DefGenerator);
995 bool LinkAgainstThisJITDylibFirst =
true);
1033 template <
typename Func>
1035 ->
decltype(
F(std::declval<const JITDylibSearchOrder &>()));
1047 template <
typename MaterializationUnitType>
1048 Error define(std::unique_ptr<MaterializationUnitType> &&MU,
1061 template <
typename MaterializationUnitType>
1062 Error define(std::unique_ptr<MaterializationUnitType> &MU,
1113 using AsynchronousSymbolQuerySet =
1114 std::set<std::shared_ptr<AsynchronousSymbolQuery>>;
1116 using AsynchronousSymbolQueryList =
1117 std::vector<std::shared_ptr<AsynchronousSymbolQuery>>;
1119 struct UnmaterializedInfo {
1120 UnmaterializedInfo(std::unique_ptr<MaterializationUnit> MU,
1122 : MU(
std::
move(MU)), RT(RT) {}
1124 std::unique_ptr<MaterializationUnit> MU;
1125 ResourceTracker *RT;
1128 using UnmaterializedInfosMap =
1129 DenseMap<SymbolStringPtr, std::shared_ptr<UnmaterializedInfo>>;
1131 using UnmaterializedInfosList =
1132 std::vector<std::shared_ptr<UnmaterializedInfo>>;
1134 struct EmissionDepUnit {
1135 EmissionDepUnit(JITDylib &JD) : JD(&JD) {}
1137 JITDylib *JD =
nullptr;
1138 DenseMap<NonOwningSymbolStringPtr, JITSymbolFlags> Symbols;
1139 DenseMap<JITDylib *, DenseSet<NonOwningSymbolStringPtr>> Dependencies;
1142 struct EmissionDepUnitInfo {
1143 std::shared_ptr<EmissionDepUnit> EDU;
1144 DenseSet<EmissionDepUnit *> IntraEmitUsers;
1145 DenseMap<JITDylib *, DenseSet<NonOwningSymbolStringPtr>> NewDeps;
1154 struct MaterializingInfo {
1155 friend class ExecutionSession;
1157 std::shared_ptr<EmissionDepUnit> DefiningEDU;
1158 DenseSet<EmissionDepUnit *> DependantEDUs;
1160 LLVM_ABI void addQuery(std::shared_ptr<AsynchronousSymbolQuery> Q);
1162 LLVM_ABI AsynchronousSymbolQueryList
1164 AsynchronousSymbolQueryList takeAllPendingQueries() {
1165 return std::move(PendingQueries);
1167 bool hasQueriesPending()
const {
return !PendingQueries.empty(); }
1168 const AsynchronousSymbolQueryList &pendingQueries()
const {
1169 return PendingQueries;
1172 AsynchronousSymbolQueryList PendingQueries;
1175 using MaterializingInfosMap = DenseMap<SymbolStringPtr, MaterializingInfo>;
1177 class SymbolTableEntry {
1179 SymbolTableEntry() =
default;
1180 SymbolTableEntry(JITSymbolFlags Flags)
1182 MaterializerAttached(
false) {}
1184 ExecutorAddr getAddress()
const {
return Addr; }
1188 bool hasMaterializerAttached()
const {
return MaterializerAttached; }
1190 void setAddress(ExecutorAddr Addr) { this->Addr =
Addr; }
1191 void setFlags(JITSymbolFlags Flags) { this->Flags =
Flags; }
1194 "State does not fit in bitfield");
1195 this->State =
static_cast<uint8_t>(State);
1198 void setMaterializerAttached(
bool MaterializerAttached) {
1199 this->MaterializerAttached = MaterializerAttached;
1202 ExecutorSymbolDef getSymbol()
const {
return {
Addr,
Flags}; }
1206 JITSymbolFlags
Flags;
1208 uint8_t MaterializerAttached : 1;
1211 using SymbolTable = DenseMap<SymbolStringPtr, SymbolTableEntry>;
1215 struct RemoveTrackerResult {
1216 AsynchronousSymbolQuerySet QueriesToFail;
1217 std::shared_ptr<SymbolDependenceMap> FailedSymbols;
1218 std::vector<std::unique_ptr<MaterializationUnit>> DefunctMUs;
1221 RemoveTrackerResult IL_removeTracker(ResourceTracker &RT);
1223 void transferTracker(ResourceTracker &DstRT, ResourceTracker &SrcRT);
1228 installMaterializationUnit(std::unique_ptr<MaterializationUnit> MU,
1229 ResourceTracker &RT);
1234 void transferEmittedNodeDependencies(MaterializingInfo &DependantMI,
1235 const SymbolStringPtr &DependantName,
1236 MaterializingInfo &EmittedMI);
1238 Expected<SymbolFlagsMap>
1243 std::unique_ptr<MaterializationUnit> MU);
1245 Expected<std::unique_ptr<MaterializationResponsibility>>
1247 SymbolStringPtr InitSymbol);
1251 void addDependencies(
const SymbolStringPtr &Name,
1260 void shrinkMaterializationInfoMemory();
1263 enum { Open, Closing, Closed } State = Open;
1264 std::mutex GeneratorsMutex;
1265 SymbolTable Symbols;
1266 UnmaterializedInfosMap UnmaterializedInfos;
1267 MaterializingInfosMap MaterializingInfos;
1268 std::vector<std::shared_ptr<DefinitionGenerator>> DefGenerators;
1273 DenseMap<ResourceTracker *, SymbolNameVector> TrackerSymbols;
1274 DenseMap<ResourceTracker *, DenseSet<MaterializationResponsibility *>>
1328 std::unique_ptr<MaterializationResponsibility> MR)
1332 void run()
override;
1335 std::unique_ptr<MaterializationUnit> MU;
1336 std::unique_ptr<MaterializationResponsibility> MR;
1348 void run()
override;
1374 const char *ArgData,
size_t ArgSize)>;
1405 return EPC->getSymbolStringPool();
1420 std::lock_guard<std::recursive_mutex> Lock(SessionMutex);
1483 this->ReportError = std::move(ReportError);
1565 assert(
T &&
"T must be non-null");
1567 EPC->getDispatcher().dispatch(std::move(
T));
1572 return EPC->getBootstrapMap();
1576 template <
typename T,
typename SPSTagT>
1578 return EPC->getBootstrapMapValue<
T, SPSTagT>(Key, Val);
1583 return EPC->getBootstrapSymbolsMap();
1590 ArrayRef<std::pair<ExecutorAddr &, StringRef>> Pairs)
const {
1591 return EPC->getBootstrapSymbols(Pairs);
1605 EPC->callWrapperAsync(WrapperFnAddr, std::move(OnComplete), ArgBuffer);
1610 template <
typename RunPolicyT,
typename FnT>
1613 EPC->callWrapperAsync(std::forward<RunPolicyT>(Runner), WrapperFnAddr,
1614 std::forward<FnT>(OnComplete), ArgBuffer);
1619 template <
typename FnT>
1622 EPC->callWrapperAsync(WrapperFnAddr, std::forward<FnT>(OnComplete),
1634 return EPC->callWrapper(WrapperFnAddr, ArgBuffer);
1639 template <
typename SPSSignature,
typename SendResultT,
typename... ArgTs>
1641 const ArgTs &...Args) {
1642 EPC->callSPSWrapperAsync<SPSSignature, SendResultT, ArgTs...>(
1643 WrapperFnAddr, std::forward<SendResultT>(SendResult), Args...);
1651 template <
typename SPSSignature,
typename... WrapperCallArgTs>
1653 WrapperCallArgTs &&...WrapperCallArgs) {
1654 return EPC->callSPSWrapper<SPSSignature, WrapperCallArgTs...>(
1655 WrapperFnAddr, std::forward<WrapperCallArgTs>(WrapperCallArgs)...);
1665 template <
typename SPSSignature,
typename HandlerT>
1668 const char *ArgData,
1669 size_t ArgSize)
mutable {
1671 ArgData, ArgSize, std::move(SendResult),
H);
1682 template <
typename SPSSignature,
typename ClassT,
typename... MethodArgTs>
1685 return wrapAsyncWithSPS<SPSSignature>(
1686 [
Instance, Method](MethodArgTs &&...MethodArgs) {
1687 (
Instance->*Method)(std::forward<MethodArgTs>(MethodArgs)...);
1714#ifdef EXPENSIVE_CHECKS
1719 static void logErrorsToStdErr(
Error Err) {
1723 void dispatchOutstandingMUs();
1725 static std::unique_ptr<MaterializationResponsibility>
1728 SymbolStringPtr InitSymbol) {
1729 auto &JD = RT.getJITDylib();
1730 std::unique_ptr<MaterializationResponsibility> MR(
1732 std::move(InitSymbol)));
1733 JD.TrackerMRs[&RT].insert(MR.get());
1747 SymbolLookupSet &Candidates,
1748 SymbolLookupSet *NonCandidates);
1751 void OL_resumeLookupAfterGeneration(InProgressLookupState &IPLS);
1756 void OL_applyQueryPhase1(std::unique_ptr<InProgressLookupState> IPLS,
1763 void OL_completeLookup(std::unique_ptr<InProgressLookupState> IPLS,
1764 std::shared_ptr<AsynchronousSymbolQuery> Q,
1769 void OL_completeLookupFlags(
1770 std::unique_ptr<InProgressLookupState> IPLS,
1771 unique_function<
void(Expected<SymbolFlagsMap>)> OnComplete);
1782 DenseMap<JITDylib::EmissionDepUnit *, JITDylib::EmissionDepUnitInfo>;
1784 template <
typename HandleNewDepFn>
1785 void propagateExtraEmitDeps(std::deque<JITDylib::EmissionDepUnit *> Worklist,
1786 EDUInfosMap &EDUInfos,
1787 HandleNewDepFn HandleNewDep);
1789 ArrayRef<SymbolDependenceGroup> EmittedDeps);
1790 void IL_makeEDUReady(std::shared_ptr<JITDylib::EmissionDepUnit> EDU,
1791 JITDylib::AsynchronousSymbolQuerySet &Queries);
1792 void IL_makeEDUEmitted(std::shared_ptr<JITDylib::EmissionDepUnit> EDU,
1793 JITDylib::AsynchronousSymbolQuerySet &Queries);
1794 bool IL_removeEDUDependence(JITDylib::EmissionDepUnit &EDU,
JITDylib &DepJD,
1795 NonOwningSymbolStringPtr DepSym,
1796 EDUInfosMap &EDUInfos);
1798 static Error makeJDClosedError(JITDylib::EmissionDepUnit &EDU,
1800 static Error makeUnsatisfiedDepsError(JITDylib::EmissionDepUnit &EDU,
1803 Expected<JITDylib::AsynchronousSymbolQuerySet>
1806 ArrayRef<SymbolDependenceGroup> EmittedDeps);
1811 std::pair<JITDylib::AsynchronousSymbolQuerySet,
1812 std::shared_ptr<SymbolDependenceMap>>
1816 std::unique_ptr<MaterializationUnit> MU);
1817 LLVM_ABI Expected<std::unique_ptr<MaterializationResponsibility>>
1821 void dumpDispatchInfo(Task &
T);
1824 mutable std::recursive_mutex SessionMutex;
1825 bool SessionOpen =
true;
1826 std::unique_ptr<ExecutorProcessControl> EPC;
1827 std::unique_ptr<Platform>
P;
1830 std::vector<ResourceManager *> ResourceManagers;
1832 std::vector<JITDylibSP> JDs;
1836 mutable std::recursive_mutex OutstandingMUsMutex;
1837 std::vector<std::pair<std::unique_ptr<MaterializationUnit>,
1838 std::unique_ptr<MaterializationResponsibility>>>
1841 mutable std::mutex JITDispatchHandlersMutex;
1842 DenseMap<ExecutorAddr, std::shared_ptr<JITDispatchHandlerFunction>>
1843 JITDispatchHandlers;
1847 return JD->getExecutionSession().lookup({JD.
get()},
Name);
1853 return make_error<ResourceTrackerDefunct>(
this);
1864template <
typename GeneratorT>
1866 auto &
G = *DefGenerator;
1868 assert(State == Open &&
"Cannot add generator to closed JITDylib");
1869 DefGenerators.push_back(std::move(DefGenerator));
1874template <
typename Func>
1876 ->
decltype(
F(std::declval<const JITDylibSearchOrder &>())) {
1877 assert(State == Open &&
"Cannot use link order of closed JITDylib");
1878 return ES.runSessionLocked([&]() {
return F(LinkOrder); });
1881template <
typename MaterializationUnitType>
1884 assert(MU &&
"Can not define with a null MU");
1886 if (MU->getSymbols().empty()) {
1889 dbgs() <<
"Warning: Discarding empty MU " << MU->getName() <<
" for "
1895 dbgs() <<
"Defining MU " << MU->getName() <<
" for " <<
getName()
1898 dbgs() <<
"default)";
1902 dbgs() <<
"0x0, default will be used)\n";
1906 assert(State == Open &&
"JD is defunct");
1908 if (
auto Err = defineImpl(*MU))
1915 if (
auto Err =
P->notifyAdding(*RT, *MU))
1919 installMaterializationUnit(std::move(MU), *RT);
1924template <
typename MaterializationUnitType>
1927 assert(MU &&
"Can not define with a null MU");
1929 if (MU->getSymbols().empty()) {
1932 dbgs() <<
"Warning: Discarding empty MU " << MU->getName() <<
getName()
1938 dbgs() <<
"Defining MU " << MU->getName() <<
" for " <<
getName()
1941 dbgs() <<
"default)";
1945 dbgs() <<
"0x0, default will be used)\n";
1949 assert(State == Open &&
"JD is defunct");
1951 if (
auto Err = defineImpl(*MU))
1958 if (
auto Err =
P->notifyAdding(*RT, *MU))
1962 installMaterializationUnit(std::move(MU), *RT);
2015 std::move(SymbolFlags));
2023 std::unique_ptr<MaterializationUnit> MU) {
aarch64 falkor hwpf fix Falkor HW Prefetch Fix Late Phase
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Given that RA is a live value
This file defines the DenseSet and SmallDenseSet classes.
This file defines the RefCountedBase, ThreadSafeRefCountedBase, and IntrusiveRefCntPtr classes.
static StringRef getName(Value *V)
#define DEBUG_WITH_TYPE(TYPE,...)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
Base class for user error types.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Flags for symbols in the JIT.
Inheritance utility for extensible RTTI.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
A thread-safe version of RefCountedBase.
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
const std::string & getName() const
Get the name for this JITLinkDylib.
A symbol query that returns results via a callback when results are ready.
bool isComplete() const
Returns true if all symbols covered by this query have been resolved.
LLVM_ABI void notifySymbolMetRequiredState(const SymbolStringPtr &Name, ExecutorSymbolDef Sym)
Notify the query that a requested symbol has reached the required state.
friend class JITSymbolResolverAdapter
Definition generators can be attached to JITDylibs to generate new definitions for otherwise unresolv...
virtual Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD, JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &LookupSet)=0
DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.
An ExecutionSession represents a running JIT program.
LLVM_ABI Error endSession()
End the session.
ExecutorProcessControl & getExecutorProcessControl()
Get the ExecutorProcessControl object associated with this ExecutionSession.
unique_function< void(shared::WrapperFunctionResult)> SendResultFunction
Send a result to the remote.
void reportError(Error Err)
Report a error for this execution session.
void callWrapperAsync(ExecutorAddr WrapperFnAddr, ExecutorProcessControl::IncomingWFRHandler OnComplete, ArrayRef< char > ArgBuffer)
Run a wrapper function in the executor.
const StringMap< ExecutorAddr > & getBootstrapSymbolsMap() const
Returns the bootstrap symbol map.
void setPlatform(std::unique_ptr< Platform > P)
Set the Platform for this ExecutionSession.
const Triple & getTargetTriple() const
Return the triple for the executor.
Platform * getPlatform()
Get the Platform for this session.
Error callSPSWrapper(ExecutorAddr WrapperFnAddr, WrapperCallArgTs &&...WrapperCallArgs)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
LLVM_ABI 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.
shared::WrapperFunctionResult callWrapper(ExecutorAddr WrapperFnAddr, ArrayRef< char > ArgBuffer)
Run a wrapper function in the executor.
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
LLVM_ABI JITDylib * getJITDylibByName(StringRef Name)
Return a pointer to the "name" JITDylib.
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 p...
void callWrapperAsync(RunPolicyT &&Runner, ExecutorAddr WrapperFnAddr, FnT &&OnComplete, ArrayRef< char > ArgBuffer)
Run a wrapper function in the executor using the given Runner to dispatch OnComplete when the result ...
LLVM_ABI JITDylib & createBareJITDylib(std::string Name)
Add a new bare JITDylib to this ExecutionSession.
static JITDispatchHandlerFunction wrapAsyncWithSPS(HandlerT &&H)
Wrap a handler that takes concrete argument types (and a sender for a concrete return type) to produc...
void callSPSWrapperAsync(ExecutorAddr WrapperFnAddr, SendResultT &&SendResult, const ArgTs &...Args)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
DenseMap< SymbolStringPtr, JITDispatchHandlerFunction > JITDispatchHandlerAssociationMap
A map associating tag names with asynchronous wrapper function implementations in the JIT.
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
Get the SymbolStringPool for this instance.
Error getBootstrapMapValue(StringRef Key, std::optional< T > &Val) const
Look up and SPS-deserialize a bootstrap map value.
Error getBootstrapSymbols(ArrayRef< std::pair< ExecutorAddr &, StringRef > > Pairs) const
For each (ExecutorAddr&, StringRef) pair, looks up the string in the bootstrap symbols map and writes...
const StringMap< std::vector< char > > & getBootstrapMap() const
Returns the bootstrap map.
LLVM_ABI void lookup(LookupKind K, const JITDylibSearchOrder &SearchOrder, SymbolLookupSet Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete, RegisterDependenciesFunction RegisterDependencies)
Search the given JITDylibs for the given symbols.
LLVM_ABI Error registerJITDispatchHandlers(JITDylib &JD, JITDispatchHandlerAssociationMap WFs)
For each tag symbol name, associate the corresponding AsyncHandlerWrapperFunction with the address of...
friend class MaterializationResponsibility
LLVM_ABI void registerResourceManager(ResourceManager &RM)
Register the given ResourceManager with this ExecutionSession.
LLVM_ABI ~ExecutionSession()
Destroy an ExecutionSession.
LLVM_ABI void runJITDispatchHandler(SendResultFunction SendResult, ExecutorAddr HandlerFnTagAddr, ArrayRef< char > ArgBuffer)
Run a registered jit-side wrapper function.
unique_function< void(SendResultFunction SendResult, const char *ArgData, size_t ArgSize)> JITDispatchHandlerFunction
An asynchronous wrapper-function callable from the executor via jit-dispatch.
LLVM_ABI void deregisterResourceManager(ResourceManager &RM)
Deregister the given ResourceManager with this ExecutionSession.
decltype(auto) runSessionLocked(Func &&F)
Run the given lambda with the session mutex locked.
LLVM_ABI void dump(raw_ostream &OS)
Dump the state of all the JITDylibs in this session.
friend class ResourceTracker
ExecutionSession & setErrorReporter(ErrorReporter ReportError)
Set the error reporter function.
LLVM_ABI Error removeJITDylibs(std::vector< JITDylibSP > JDsToRemove)
Removes the given JITDylibs from the ExecutionSession.
size_t getPageSize() const
LLVM_ABI Expected< JITDylib & > createJITDylib(std::string Name)
Add a new JITDylib to this ExecutionSession.
void dispatchTask(std::unique_ptr< Task > T)
Materialize the given unit.
unique_function< void(Error)> ErrorReporter
For reporting errors.
Error removeJITDylib(JITDylib &JD)
Calls removeJTIDylibs on the gives JITDylib.
void callWrapperAsync(ExecutorAddr WrapperFnAddr, FnT &&OnComplete, ArrayRef< char > ArgBuffer)
Run a wrapper function in the executor.
Represents an address in the executor process.
A handler or incoming WrapperFunctionResults – either return values from callWrapper* calls,...
ExecutorProcessControl supports interaction with a JIT target process.
Represents a defining location for a JIT symbol.
Used to notify a JITDylib that the given set of symbols failed to materialize.
const SymbolDependenceMap & getSymbols() const
Represents a JIT'd dynamic library.
LLVM_ABI Error remove(const SymbolNameSet &Names)
Tries to remove the given symbols.
LLVM_ABI Error clear()
Calls remove on all trackers currently associated with this JITDylib.
JITDylib & operator=(JITDylib &&)=delete
LLVM_ABI void dump(raw_ostream &OS)
Dump current JITDylib state to OS.
friend class AsynchronousSymbolQuery
LLVM_ABI void replaceInLinkOrder(JITDylib &OldJD, JITDylib &NewJD, JITDylibLookupFlags JDLookupFlags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Replace OldJD with NewJD in the link order if OldJD is present.
Error define(std::unique_ptr< MaterializationUnitType > &&MU, ResourceTrackerSP RT=nullptr)
Define all symbols provided by the materialization unit to be part of this JITDylib.
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
LLVM_ABI void addToLinkOrder(const JITDylibSearchOrder &NewLinks)
Append the given JITDylibSearchOrder to the link order for this JITDylib (discarding any elements alr...
LLVM_ABI ResourceTrackerSP createResourceTracker()
Create a resource tracker for this JITDylib.
auto withLinkOrderDo(Func &&F) -> decltype(F(std::declval< const JITDylibSearchOrder & >()))
Do something with the link order (run under the session lock).
friend class MaterializationResponsibility
LLVM_ABI void removeFromLinkOrder(JITDylib &JD)
Remove the given JITDylib from the link order for this JITDylib if it is present.
LLVM_ABI void setLinkOrder(JITDylibSearchOrder NewSearchOrder, bool LinkAgainstThisJITDylibFirst=true)
Set the link order to be used when fixing up definitions in JITDylib.
LLVM_ABI Expected< std::vector< JITDylibSP > > getReverseDFSLinkOrder()
Rteurn this JITDylib and its transitive dependencies in reverse DFS order based on linkage relationsh...
friend class ExecutionSession
LLVM_ABI ResourceTrackerSP getDefaultResourceTracker()
Get the default resource tracker for this JITDylib.
GeneratorT & addGenerator(std::unique_ptr< GeneratorT > DefGenerator)
Adds a definition generator to this JITDylib and returns a referenece to it.
JITDylib(const JITDylib &)=delete
JITDylib & operator=(const JITDylib &)=delete
JITDylib(JITDylib &&)=delete
LLVM_ABI void removeGenerator(DefinitionGenerator &G)
Remove a definition generator from this JITDylib.
LLVM_ABI Expected< std::vector< JITDylibSP > > getDFSLinkOrder()
Return this JITDylib and its transitive dependencies in DFS order based on linkage relationships.
Wraps state for a lookup-in-progress.
LLVM_ABI void continueLookup(Error Err)
Continue the lookup.
LLVM_ABI LookupState & operator=(LookupState &&)
LLVM_ABI LookupState(LookupState &&)
Lookups are usually run on the current thread, but in some cases they may be run as tasks,...
LookupTask(LookupState LS)
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
MaterializationResponsibility & operator=(MaterializationResponsibility &&)=delete
ExecutionSession & getExecutionSession() const
Returns the ExecutionSession for this instance.
Error notifyResolved(const SymbolMap &Symbols)
Notifies the target JITDylib that the given symbols have been resolved.
~MaterializationResponsibility()
Destruct a MaterializationResponsibility instance.
Error replace(std::unique_ptr< MaterializationUnit > MU)
Transfers responsibility to the given MaterializationUnit for all symbols defined by that Materializa...
Error withResourceKeyDo(Func &&F) const
Runs the given callback under the session lock, passing in the associated ResourceKey.
Error defineMaterializing(SymbolFlagsMap SymbolFlags)
Attempt to claim responsibility for new definitions.
SymbolNameSet getRequestedSymbols() const
Returns the names of any symbols covered by this MaterializationResponsibility object that have queri...
Expected< std::unique_ptr< MaterializationResponsibility > > delegate(const SymbolNameSet &Symbols)
Delegates responsibility for the given symbols to the returned materialization responsibility.
const ResourceTrackerSP & getResourceTracker() const
Return the ResourceTracker associated with this instance.
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization pseudo-symbol, if any.
MaterializationResponsibility(MaterializationResponsibility &&)=delete
Error notifyEmitted(ArrayRef< SymbolDependenceGroup > DepGroups)
Notifies the target JITDylib (and any pending queries on that JITDylib) that all symbols covered by t...
void failMaterialization()
Notify all not-yet-emitted covered by this MaterializationResponsibility instance that an error has o...
JITDylib & getTargetJITDylib() const
Returns the target JITDylib that these symbols are being materialized into.
const SymbolFlagsMap & getSymbols() const
Returns the symbol flags map for this responsibility instance.
MaterializationTask(std::unique_ptr< MaterializationUnit > MU, std::unique_ptr< MaterializationResponsibility > MR)
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
Errors of this type should be returned if a module fails to include definitions that are claimed by t...
const SymbolNameVector & getSymbols() const
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
MissingSymbolDefinitions(std::shared_ptr< SymbolStringPool > SSP, std::string ModuleName, SymbolNameVector Symbols)
const std::string & getModuleName() const
A materialization unit for symbol aliases.
ReexportsGenerator can be used with JITDylib::addGenerator to automatically re-export a subset of the...
std::function< bool(SymbolStringPtr)> SymbolPredicate
Listens for ResourceTracker operations.
virtual Error handleRemoveResources(JITDylib &JD, ResourceKey K)=0
This function will be called outside the session lock.
virtual ~ResourceManager()
virtual void handleTransferResources(JITDylib &JD, ResourceKey DstK, ResourceKey SrcK)=0
This function will be called inside the session lock.
API to remove / transfer ownership of JIT resources.
JITDylib & getJITDylib() const
Return the JITDylib targeted by this tracker.
ResourceTracker & operator=(const ResourceTracker &)=delete
ResourceKey getKeyUnsafe() const
Returns the key associated with this tracker.
LLVM_ABI void transferTo(ResourceTracker &DstRT)
Transfer all resources associated with this key to the given tracker, which must target the same JITD...
ResourceTracker & operator=(ResourceTracker &&)=delete
LLVM_ABI ~ResourceTracker()
ResourceTracker(const ResourceTracker &)=delete
bool isDefunct() const
Return true if this tracker has become defunct.
ResourceTracker(ResourceTracker &&)=delete
Error withResourceKeyDo(Func &&F)
Runs the given callback under the session lock, passing in the associated ResourceKey.
LLVM_ABI Error remove()
Remove all resources associated with this key.
A definition of a Symbol within a JITDylib.
Expected< ExecutorSymbolDef > lookup() const
SymbolInstance(JITDylibSP JD, SymbolStringPtr Name)
LLVM_ABI void lookupAsync(LookupAsyncOnCompleteFn OnComplete) const
const JITDylib & getJITDylib() const
const SymbolStringPtr & getName() const
unique_function< void(Expected< ExecutorSymbolDef >)> LookupAsyncOnCompleteFn
A set of symbols to look up, each associated with a SymbolLookupFlags value.
std::pair< SymbolStringPtr, SymbolLookupFlags > value_type
const_iterator begin() const
void removeDuplicates()
Remove any duplicate elements.
UnderlyingVector::const_iterator const_iterator
void sortByAddress()
Sort the lookup set by pointer value.
SymbolLookupSet(std::initializer_list< SymbolStringPtr > Names, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Construct a SymbolLookupSet from an initializer list of SymbolStringPtrs.
UnderlyingVector::size_type size() const
SymbolLookupSet & add(SymbolStringPtr Name, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Add an element to the set.
static SymbolLookupSet fromMapKeys(const DenseMap< SymbolStringPtr, ValT > &M, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Construct a SymbolLookupSet from DenseMap keys.
SymbolLookupSet & append(SymbolLookupSet Other)
Quickly append one lookup set to another.
SymbolLookupSet(ArrayRef< SymbolStringPtr > Names, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Construct a SymbolLookupSet from a vector of symbols with the given Flags used for each value.
SymbolLookupSet(std::initializer_list< value_type > Elems)
void sortByName()
Sort the lookup set lexicographically.
void remove(iterator I)
Removes the element pointed to by the given iterator.
auto forEachWithRemoval(BodyFn &&Body) -> std::enable_if_t< std::is_same< decltype(Body(std::declval< const SymbolStringPtr & >(), std::declval< SymbolLookupFlags >())), bool >::value >
Loop over the elements of this SymbolLookupSet, applying the Body function to each one.
bool containsDuplicates()
Returns true if this set contains any duplicates.
UnderlyingVector::iterator iterator
void remove_if(PredFn &&Pred)
Removes all elements matching the given predicate, which must be callable as bool(const SymbolStringP...
SymbolLookupSet(const SymbolNameSet &Names, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Construct a SymbolLookupSet from a SymbolNameSet with the given Flags used for each value.
SymbolLookupSet(SymbolStringPtr Name, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
SymbolNameVector getSymbolNames() const
Construct a SymbolNameVector from this instance by dropping the Flags values.
const_iterator end() const
SymbolLookupSet()=default
auto forEachWithRemoval(BodyFn &&Body) -> std::enable_if_t< std::is_same< decltype(Body(std::declval< const SymbolStringPtr & >(), std::declval< SymbolLookupFlags >())), Expected< bool > >::value, Error >
Loop over the elements of this SymbolLookupSet, applying the Body function to each one.
void remove(UnderlyingVector::size_type I)
Removes the Ith element of the vector, replacing it with the last element.
std::vector< value_type > UnderlyingVector
Pointer to a pooled string representing a symbol name.
Used to notify clients that a set of symbols could not be removed.
const SymbolNameSet & getSymbols() const
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
Used to notify clients when symbols can not be found during a lookup.
const SymbolNameVector & getSymbols() const
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
Errors of this type should be returned if a module contains definitions for symbols that are not clai...
UnexpectedSymbolDefinitions(std::shared_ptr< SymbolStringPool > SSP, std::string ModuleName, SymbolNameVector Symbols)
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
const std::string & getModuleName() const
const SymbolNameVector & getSymbols() const
Used to report failure due to unsatisfiable symbol dependencies.
C++ wrapper function result: Same as CWrapperFunctionResult but auto-releases memory.
This class implements an extremely fast bulk output stream that can only output to a stream.
unique_function is a type-erasing functor similar to std::function.
JITDylibSearchOrder makeJITDylibSearchOrder(ArrayRef< JITDylib * > JDs, JITDylibLookupFlags Flags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Convenience function for creating a search order from an ArrayRef of JITDylib*, all with the same fla...
std::vector< std::pair< JITDylib *, JITDylibLookupFlags > > JITDylibSearchOrder
A list of (JITDylib*, JITDylibLookupFlags) pairs to be used as a search order during symbol lookup.
std::function< void(const SymbolDependenceMap &)> RegisterDependenciesFunction
Callback to register the dependencies for a given query.
std::unique_ptr< ReExportsMaterializationUnit > symbolAliases(SymbolAliasMap Aliases)
Create a ReExportsMaterializationUnit with the given aliases.
IntrusiveRefCntPtr< ResourceTracker > ResourceTrackerSP
SymbolLookupFlags
Lookup flags that apply to each symbol in a lookup.
std::unique_ptr< ReExportsMaterializationUnit > reexports(JITDylib &SourceJD, SymbolAliasMap Aliases, JITDylibLookupFlags SourceJDLookupFlags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Create a materialization unit for re-exporting symbols from another JITDylib with alternative names/f...
LLVM_ABI Expected< SymbolAliasMap > buildSimpleReexportsAliasMap(JITDylib &SourceJD, const SymbolNameSet &Symbols)
Build a SymbolAliasMap for the common case where you want to re-export symbols from another JITDylib ...
JITDylibLookupFlags
Lookup flags that apply to each dylib in the search order for a lookup.
@ MatchExportedSymbolsOnly
DenseMap< SymbolStringPtr, ExecutorSymbolDef > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
DenseMap< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap
A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
static std::unique_ptr< UnwindInfoManager > Instance
unique_function< void(Expected< SymbolMap >)> SymbolsResolvedCallback
Callback to notify client that symbols have been resolved.
DenseSet< SymbolStringPtr > SymbolNameSet
A set of symbol names (represented by SymbolStringPtrs for.
LookupKind
Describes the kind of lookup being performed.
LLVM_ABI RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
std::vector< SymbolStringPtr > SymbolNameVector
A vector of symbol names.
SymbolState
Represents the state that a symbol has reached during materialization.
@ Materializing
Added to the symbol table, never queried.
@ NeverSearched
No symbol should be in this state.
@ Ready
Emitted to memory, but waiting on transitive dependencies.
@ Emitted
Assigned address, still materializing.
@ Resolved
Queried, materialization begun.
DenseMap< JITDylib *, SymbolNameSet > SymbolDependenceMap
A map from JITDylibs to sets of symbols.
LLVM_ABI ArrayRef< EnumEntry< Flags > > getFlags()
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
auto unique(Range &&R, Predicate P)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Function object to check whether the first component of a container supported by std::get (like std::...
SymbolAliasMapEntry()=default
JITSymbolFlags AliasFlags
SymbolAliasMapEntry(SymbolStringPtr Aliasee, JITSymbolFlags AliasFlags)
A set of symbols and the their dependencies.
SymbolDependenceMap Dependencies