13#ifndef LLVM_EXECUTIONENGINE_ORC_CORE_H
14#define LLVM_EXECUTIONENGINE_ORC_CORE_H
37class AsynchronousSymbolQuery;
38class ExecutionSession;
39class MaterializationUnit;
40class MaterializationResponsibility;
43class InProgressLookupState;
69 return *
reinterpret_cast<JITDylib *
>(JDAndFlag.load() &
70 ~static_cast<uintptr_t>(1));
85 bool isDefunct()
const {
return JDAndFlag.load() & 0x1; }
97 std::atomic_uintptr_t JDAndFlag;
159 std::vector<std::pair<JITDylib *, JITDylibLookupFlags>>;
167 O.reserve(JDs.
size());
169 O.push_back(std::make_pair(JD,
Flags));
182 using value_type = std::pair<SymbolStringPtr, SymbolLookupFlags>;
197 std::initializer_list<SymbolStringPtr>
Names,
199 Symbols.reserve(
Names.size());
209 Symbols.reserve(
Names.size());
221 Symbols.reserve(
Names.size());
227 template <
typename KeyT>
232 Result.Symbols.reserve(M.size());
233 for (
const auto &KV : M)
243 Symbols.push_back(std::make_pair(std::move(
Name),
Flags));
249 Symbols.reserve(Symbols.size() +
Other.size());
250 for (
auto &KV :
Other)
251 Symbols.push_back(std::move(KV));
255 bool empty()
const {
return Symbols.empty(); }
256 UnderlyingVector::size_type
size()
const {
return Symbols.size(); }
274 template <
typename PredFn>
void remove_if(PredFn &&Pred) {
275 UnderlyingVector::size_type
I = 0;
276 while (
I != Symbols.size()) {
277 const auto &
Name = Symbols[
I].first;
278 auto Flags = Symbols[
I].second;
291 template <
typename BodyFn>
293 std::is_same<decltype(Body(std::declval<const SymbolStringPtr &>(),
294 std::declval<SymbolLookupFlags>())),
296 UnderlyingVector::size_type
I = 0;
297 while (
I != Symbols.size()) {
298 const auto &
Name = Symbols[
I].first;
299 auto Flags = Symbols[
I].second;
313 template <
typename BodyFn>
315 std::is_same<decltype(Body(std::declval<const SymbolStringPtr &>(),
316 std::declval<SymbolLookupFlags>())),
319 UnderlyingVector::size_type
I = 0;
320 while (
I != Symbols.size()) {
321 const auto &
Name = Symbols[
I].first;
322 auto Flags = Symbols[
I].second;
325 return Remove.takeError();
338 Names.reserve(Symbols.size());
339 for (
const auto &KV : Symbols)
340 Names.push_back(KV.first);
353 return *
LHS.first < *
RHS.first;
361 auto LastI = std::unique(Symbols.begin(), Symbols.end());
362 Symbols.erase(LastI, Symbols.end());
369 if (Symbols.size() < 2)
372 for (UnderlyingVector::size_type
I = 1;
I != Symbols.size(); ++
I)
373 if (Symbols[
I].first == Symbols[
I - 1].first)
425 std::shared_ptr<SymbolDependenceMap> Symbols);
432 std::shared_ptr<SymbolStringPool> SSP;
433 std::shared_ptr<SymbolDependenceMap> Symbols;
450 std::shared_ptr<SymbolStringPool> SSP;
467 std::shared_ptr<SymbolStringPool> SSP;
489 std::shared_ptr<SymbolStringPool> SSP;
512 std::shared_ptr<SymbolStringPool> SSP;
541 return RT->withResourceKeyDo(std::forward<Func>(
F));
654 : JD(RT->getJITDylib()), RT(
std::
move(RT)),
655 SymbolFlags(
std::
move(SymbolFlags)), InitSymbol(
std::
move(InitSymbol)) {
656 assert(!this->SymbolFlags.
empty() &&
"Materializing nothing?");
686 "If set, InitSymbol should appear in InitialSymbolFlags map");
712 materialize(std::unique_ptr<MaterializationResponsibility> R) = 0;
720 dbgs() <<
"In " <<
getName() <<
": discarding init symbol \""
725 discard(JD, std::move(
Name));
733 virtual void anchor();
753 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override;
770inline std::unique_ptr<AbsoluteSymbolsMaterializationUnit>
772 return std::make_unique<AbsoluteSymbolsMaterializationUnit>(
795 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override;
816inline std::unique_ptr<ReExportsMaterializationUnit>
818 return std::make_unique<ReExportsMaterializationUnit>(
825inline std::unique_ptr<ReExportsMaterializationUnit>
829 return std::make_unique<ReExportsMaterializationUnit>(
830 &SourceJD, SourceJDLookupFlags, std::move(Aliases));
873 bool isComplete()
const {
return OutstandingSymbolsCount == 0; }
879 SymbolState getRequiredState() {
return RequiredState; }
881 void addQueryDependence(
JITDylib &JD, SymbolStringPtr
Name);
883 void removeQueryDependence(
JITDylib &JD,
const SymbolStringPtr &
Name);
885 void dropSymbol(
const SymbolStringPtr &
Name);
887 void handleFailed(
Error Err);
894 size_t OutstandingSymbolsCount;
916 LookupState(std::unique_ptr<InProgressLookupState> IPLS);
921 std::unique_ptr<InProgressLookupState> IPLS;
1021 template <
typename GeneratorT>
1022 GeneratorT &
addGenerator(std::unique_ptr<GeneratorT> DefGenerator);
1055 bool LinkAgainstThisJITDylibFirst =
true);
1086 template <
typename Func>
1088 ->
decltype(
F(std::declval<const JITDylibSearchOrder &>()));
1100 template <
typename MaterializationUnitType>
1101 Error define(std::unique_ptr<MaterializationUnitType> &&MU,
1114 template <
typename MaterializationUnitType>
1115 Error define(std::unique_ptr<MaterializationUnitType> &MU,
1166 using AsynchronousSymbolQuerySet =
1167 std::set<std::shared_ptr<AsynchronousSymbolQuery>>;
1169 using AsynchronousSymbolQueryList =
1170 std::vector<std::shared_ptr<AsynchronousSymbolQuery>>;
1172 struct UnmaterializedInfo {
1173 UnmaterializedInfo(std::unique_ptr<MaterializationUnit> MU,
1175 : MU(
std::
move(MU)), RT(RT) {}
1177 std::unique_ptr<MaterializationUnit> MU;
1178 ResourceTracker *RT;
1181 using UnmaterializedInfosMap =
1182 DenseMap<SymbolStringPtr, std::shared_ptr<UnmaterializedInfo>>;
1184 using UnmaterializedInfosList =
1185 std::vector<std::shared_ptr<UnmaterializedInfo>>;
1187 struct MaterializingInfo {
1191 void addQuery(std::shared_ptr<AsynchronousSymbolQuery> Q);
1193 AsynchronousSymbolQueryList takeQueriesMeeting(
SymbolState RequiredState);
1194 AsynchronousSymbolQueryList takeAllPendingQueries() {
1195 return std::move(PendingQueries);
1197 bool hasQueriesPending()
const {
return !PendingQueries.empty(); }
1198 const AsynchronousSymbolQueryList &pendingQueries()
const {
1199 return PendingQueries;
1202 AsynchronousSymbolQueryList PendingQueries;
1205 using MaterializingInfosMap = DenseMap<SymbolStringPtr, MaterializingInfo>;
1207 class SymbolTableEntry {
1209 SymbolTableEntry() =
default;
1210 SymbolTableEntry(JITSymbolFlags Flags)
1212 MaterializerAttached(
false), PendingRemoval(
false) {}
1214 ExecutorAddr getAddress()
const {
return Addr; }
1218 bool hasMaterializerAttached()
const {
return MaterializerAttached; }
1219 bool isPendingRemoval()
const {
return PendingRemoval; }
1221 void setAddress(ExecutorAddr Addr) { this->Addr =
Addr; }
1222 void setFlags(JITSymbolFlags Flags) { this->Flags =
Flags; }
1224 assert(
static_cast<uint8_t
>(State) < (1 << 6) &&
1225 "State does not fit in bitfield");
1226 this->State =
static_cast<uint8_t
>(State);
1229 void setMaterializerAttached(
bool MaterializerAttached) {
1230 this->MaterializerAttached = MaterializerAttached;
1233 void setPendingRemoval(
bool PendingRemoval) {
1234 this->PendingRemoval = PendingRemoval;
1237 JITEvaluatedSymbol getSymbol()
const {
1238 return JITEvaluatedSymbol(
Addr.getValue(), Flags);
1243 JITSymbolFlags
Flags;
1245 uint8_t MaterializerAttached : 1;
1246 uint8_t PendingRemoval : 1;
1249 using SymbolTable = DenseMap<SymbolStringPtr, SymbolTableEntry>;
1253 std::pair<AsynchronousSymbolQuerySet, std::shared_ptr<SymbolDependenceMap>>
1254 removeTracker(ResourceTracker &RT);
1256 void transferTracker(ResourceTracker &DstRT, ResourceTracker &SrcRT);
1258 Error defineImpl(MaterializationUnit &MU);
1260 void installMaterializationUnit(std::unique_ptr<MaterializationUnit> MU,
1261 ResourceTracker &RT);
1266 void transferEmittedNodeDependencies(MaterializingInfo &DependantMI,
1267 const SymbolStringPtr &DependantName,
1268 MaterializingInfo &EmittedMI);
1270 Expected<SymbolFlagsMap> defineMaterializing(
SymbolFlagsMap SymbolFlags);
1273 std::unique_ptr<MaterializationUnit> MU);
1275 Expected<std::unique_ptr<MaterializationResponsibility>>
1277 SymbolStringPtr InitSymbol);
1281 void addDependencies(
const SymbolStringPtr &Name,
1290 using FailedSymbolsWorklist =
1291 std::vector<std::pair<JITDylib *, SymbolStringPtr>>;
1293 static std::pair<AsynchronousSymbolQuerySet,
1294 std::shared_ptr<SymbolDependenceMap>>
1295 failSymbols(FailedSymbolsWorklist);
1298 enum { Open, Closing, Closed } State = Open;
1299 std::mutex GeneratorsMutex;
1300 SymbolTable Symbols;
1301 UnmaterializedInfosMap UnmaterializedInfos;
1302 MaterializingInfosMap MaterializingInfos;
1303 std::vector<std::shared_ptr<DefinitionGenerator>> DefGenerators;
1308 DenseMap<ResourceTracker *, SymbolNameVector> TrackerSymbols;
1309 DenseMap<ResourceTracker *, DenseSet<MaterializationResponsibility *>>
1362 std::unique_ptr<MaterializationResponsibility> MR)
1365 void run()
override;
1368 std::unique_ptr<MaterializationUnit> MU;
1369 std::unique_ptr<MaterializationResponsibility> MR;
1395 const char *ArgData,
size_t ArgSize)>;
1423 return EPC->getSymbolStringPool();
1438 std::lock_guard<std::recursive_mutex> Lock(SessionMutex);
1489 this->ReportError = std::move(ReportError);
1500 this->DispatchTask = std::move(DispatchTask);
1576 assert(
T &&
"T must be non-null");
1578 DispatchTask(std::move(
T));
1590 template <
typename... ArgTs>
1592 EPC->callWrapperAsync(std::forward<ArgTs>(Args)...);
1603 return EPC->callWrapper(WrapperFnAddr, ArgBuffer);
1608 template <
typename SPSSignature,
typename SendResultT,
typename... ArgTs>
1610 const ArgTs &...Args) {
1611 EPC->callSPSWrapperAsync<SPSSignature, SendResultT, ArgTs...>(
1612 WrapperFnAddr, std::forward<SendResultT>(SendResult), Args...);
1620 template <
typename SPSSignature,
typename... WrapperCallArgTs>
1622 WrapperCallArgTs &&...WrapperCallArgs) {
1623 return EPC->callSPSWrapper<SPSSignature, WrapperCallArgTs...>(
1624 WrapperFnAddr, std::forward<WrapperCallArgTs>(WrapperCallArgs)...);
1634 template <
typename SPSSignature,
typename HandlerT>
1636 return [
H = std::forward<HandlerT>(
H)](
1638 const char *ArgData,
size_t ArgSize)
mutable {
1640 std::move(SendResult));
1651 template <
typename SPSSignature,
typename ClassT,
typename... MethodArgTs>
1654 return wrapAsyncWithSPS<SPSSignature>(
1655 [Instance, Method](MethodArgTs &&...MethodArgs) {
1656 (Instance->*Method)(std::forward<MethodArgTs>(MethodArgs)...);
1684 static void logErrorsToStdErr(
Error Err) {
1688 static void runOnCurrentThread(std::unique_ptr<Task>
T) {
T->run(); }
1690 void dispatchOutstandingMUs();
1692 static std::unique_ptr<MaterializationResponsibility>
1695 SymbolStringPtr InitSymbol) {
1696 auto &JD = RT.getJITDylib();
1697 std::unique_ptr<MaterializationResponsibility> MR(
1699 std::move(InitSymbol)));
1700 JD.TrackerMRs[&RT].insert(MR.get());
1714 SymbolLookupSet &Candidates,
1715 SymbolLookupSet *NonCandidates);
1720 void OL_applyQueryPhase1(std::unique_ptr<InProgressLookupState> IPLS,
1727 void OL_completeLookup(std::unique_ptr<InProgressLookupState> IPLS,
1728 std::shared_ptr<AsynchronousSymbolQuery> Q,
1733 void OL_completeLookupFlags(
1734 std::unique_ptr<InProgressLookupState> IPLS,
1735 unique_function<
void(Expected<SymbolFlagsMap>)> OnComplete);
1738 void OL_destroyMaterializationResponsibility(
1748 std::unique_ptr<MaterializationUnit> MU);
1749 Expected<std::unique_ptr<MaterializationResponsibility>>
1752 const SymbolStringPtr &
Name,
1758 void dumpDispatchInfo(Task &
T);
1761 mutable std::recursive_mutex SessionMutex;
1762 bool SessionOpen =
true;
1763 std::unique_ptr<ExecutorProcessControl> EPC;
1764 std::unique_ptr<Platform>
P;
1768 std::vector<ResourceManager *> ResourceManagers;
1770 std::vector<JITDylibSP> JDs;
1774 mutable std::recursive_mutex OutstandingMUsMutex;
1775 std::vector<std::pair<std::unique_ptr<MaterializationUnit>,
1776 std::unique_ptr<MaterializationResponsibility>>>
1779 mutable std::mutex JITDispatchHandlersMutex;
1780 DenseMap<JITTargetAddress, std::shared_ptr<JITDispatchHandlerFunction>>
1781 JITDispatchHandlers;
1787 return make_error<ResourceTrackerDefunct>(
this);
1798template <
typename GeneratorT>
1800 auto &
G = *DefGenerator;
1802 assert(State == Open &&
"Cannot add generator to closed JITDylib");
1803 DefGenerators.push_back(std::move(DefGenerator));
1808template <
typename Func>
1810 ->
decltype(
F(std::declval<const JITDylibSearchOrder &>())) {
1811 assert(State == Open &&
"Cannot use link order of closed JITDylib");
1812 return ES.runSessionLocked([&]() {
return F(LinkOrder); });
1815template <
typename MaterializationUnitType>
1818 assert(MU &&
"Can not define with a null MU");
1820 if (MU->getSymbols().empty()) {
1823 dbgs() <<
"Warning: Discarding empty MU " << MU->getName() <<
" for "
1829 dbgs() <<
"Defining MU " << MU->getName() <<
" for " <<
getName()
1832 dbgs() <<
"default)";
1836 dbgs() <<
"0x0, default will be used)\n";
1840 assert(State == Open &&
"JD is defunct");
1842 if (
auto Err = defineImpl(*MU))
1849 if (
auto Err =
P->notifyAdding(*RT, *MU))
1853 installMaterializationUnit(std::move(MU), *RT);
1858template <
typename MaterializationUnitType>
1861 assert(MU &&
"Can not define with a null MU");
1863 if (MU->getSymbols().empty()) {
1866 dbgs() <<
"Warning: Discarding empty MU " << MU->getName() <<
getName()
1872 dbgs() <<
"Defining MU " << MU->getName() <<
" for " <<
getName()
1875 dbgs() <<
"default)";
1879 dbgs() <<
"0x0, default will be used)\n";
1883 assert(State == Open &&
"JD is defunct");
1885 if (
auto Err = defineImpl(*MU))
1892 if (
auto Err =
P->notifyAdding(*RT, *MU))
1896 installMaterializationUnit(std::move(MU), *RT);
1948 std::move(SymbolFlags));
1956 std::unique_ptr<MaterializationUnit> MU) {
Given that RA is a live value
#define DEBUG_WITH_TYPE(TYPE, X)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
This file defines the DenseSet and SmallDenseSet classes.
This file defines the RefCountedBase, ThreadSafeRefCountedBase, and IntrusiveRefCntPtr classes.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool erase(const KeyT &Val)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
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.
Represents a symbol that has been evaluated to an address already.
Flags for symbols in the JIT.
Inheritance utility for extensible RTTI.
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.
const std::string & getName() const
Get the name for this JITLinkDylib.
A MaterializationUnit implementation for pre-existing absolute symbols.
StringRef getName() const override
Return the name of this materialization unit.
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.
friend class JITSymbolResolverAdapter
void notifySymbolMetRequiredState(const SymbolStringPtr &Name, JITEvaluatedSymbol Sym)
Notify the query that a requested symbol has reached the required state.
Definition generators can be attached to JITDylibs to generate new definitions for otherwise unresolv...
virtual ~DefinitionGenerator()
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.
Error endSession()
End the session.
void runJITDispatchHandler(SendResultFunction SendResult, JITTargetAddress HandlerFnTagAddr, ArrayRef< char > ArgBuffer)
Run a registered jit-side wrapper function.
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 setPlatform(std::unique_ptr< Platform > P)
Set the Platform for this ExecutionSession.
const Triple & getTargetTriple() const
Return the triple for the executor.
std::function< void(Error)> ErrorReporter
For reporting errors.
ExecutionSession & setDispatchTask(DispatchTaskFunction DispatchTask)
Set the task dispatch function.
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.
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.
JITDylib * getJITDylibByName(StringRef Name)
Return a pointer to the "name" JITDylib.
void callWrapperAsync(ArgTs &&... Args)
Run a wrapper function in the executor.
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...
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.
void lookup(LookupKind K, const JITDylibSearchOrder &SearchOrder, SymbolLookupSet Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete, RegisterDependenciesFunction RegisterDependencies)
Search the given JITDylibs for the given symbols.
Error registerJITDispatchHandlers(JITDylib &JD, JITDispatchHandlerAssociationMap WFs)
For each tag symbol name, associate the corresponding AsyncHandlerWrapperFunction with the address of...
friend class MaterializationResponsibility
void registerResourceManager(ResourceManager &RM)
Register the given ResourceManager with this ExecutionSession.
~ExecutionSession()
Destroy an ExecutionSession.
unique_function< void(SendResultFunction SendResult, const char *ArgData, size_t ArgSize)> JITDispatchHandlerFunction
An asynchronous wrapper-function callable from the executor via jit-dispatch.
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.
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.
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(std::unique_ptr< Task > T)> DispatchTaskFunction
For dispatching ORC tasks (typically materialization tasks).
Error removeJITDylib(JITDylib &JD)
Closes the given JITDylib.
Represents an address in the executor process.
ExecutorProcessControl supports interaction with a JIT target process.
Used to notify a JITDylib that the given set of symbols failed to materialize.
const SymbolDependenceMap & getSymbols() const
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Represents a JIT'd dynamic library.
Error remove(const SymbolNameSet &Names)
Tries to remove the given symbols.
Error clear()
Calls remove on all trackers currently associated with this JITDylib.
JITDylib & operator=(JITDylib &&)=delete
void dump(raw_ostream &OS)
Dump current JITDylib state to OS.
friend class AsynchronousSymbolQuery
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.
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
void removeFromLinkOrder(JITDylib &JD)
Remove the given JITDylib from the link order for this JITDylib if it is present.
void setLinkOrder(JITDylibSearchOrder NewSearchOrder, bool LinkAgainstThisJITDylibFirst=true)
Set the link order to be used when fixing up definitions in JITDylib.
void addToLinkOrder(JITDylib &JD, JITDylibLookupFlags JDLookupFlags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Add the given JITDylib to the link order for definitions in this JITDylib.
Expected< std::vector< JITDylibSP > > getReverseDFSLinkOrder()
Rteurn this JITDylib and its transitive dependencies in reverse DFS order based on linkage relationsh...
friend class ExecutionSession
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
void removeGenerator(DefinitionGenerator &G)
Remove a definition generator from this JITDylib.
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.
void continueLookup(Error Err)
Continue the lookup.
LookupState & operator=(LookupState &&)
LookupState(LookupState &&)
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.
Error notifyEmitted()
Notifies the target JITDylib (and any pending queries on that JITDylib) that all symbols covered by t...
void addDependenciesForAll(const SymbolDependenceMap &Dependencies)
Add dependencies that apply to all symbols covered by this instance.
~MaterializationResponsibility()
Destruct a MaterializationResponsibility instance.
void addDependencies(const SymbolStringPtr &Name, const SymbolDependenceMap &Dependencies)
void defineNonExistent(ArrayRef< SymbolStringPtr > Symbols)
Define the given symbols as non-existent, removing it from the symbol table and notifying any pending...
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 SymbolStringPtr & getInitializerSymbol() const
Returns the initialization pseudo-symbol, if any.
MaterializationResponsibility(MaterializationResponsibility &&)=delete
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.
void printDescription(raw_ostream &OS) override
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,...
MaterializationUnit(Interface I)
virtual StringRef getName() const =0
Return the name of this materialization unit.
SymbolStringPtr InitSymbol
SymbolFlagsMap SymbolFlags
const SymbolFlagsMap & getSymbols() const
Return the set of symbols that this source provides.
virtual void materialize(std::unique_ptr< MaterializationResponsibility > R)=0
Implementations of this method should materialize all symbols in the materialzation unit,...
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization symbol for this MaterializationUnit (if any).
void doDiscard(const JITDylib &JD, const SymbolStringPtr &Name)
Called by JITDylibs to notify MaterializationUnits that the given symbol has been overridden.
virtual ~MaterializationUnit()=default
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()
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
MissingSymbolDefinitions(std::shared_ptr< SymbolStringPool > SSP, std::string ModuleName, SymbolNameVector Symbols)
const std::string & getModuleName() const
A materialization unit for symbol aliases.
StringRef getName() const override
Return the name of this materialization unit.
ReexportsGenerator can be used with JITDylib::addGenerator to automatically re-export a subset of the...
std::function< bool(SymbolStringPtr)> SymbolPredicate
Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD, JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &LookupSet) override
DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.
Listens for ResourceTracker operations.
virtual Error handleRemoveResources(JITDylib &JD, ResourceKey K)=0
virtual ~ResourceManager()
virtual void handleTransferResources(JITDylib &JD, ResourceKey DstK, ResourceKey SrcK)=0
void log(raw_ostream &OS) const override
Print an error message to an output stream.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
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.
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
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.
Error remove()
Remove all resources associated with this key.
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.
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.
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.
static SymbolLookupSet fromMapKeys(const DenseMap< SymbolStringPtr, KeyT > &M, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Construct a SymbolLookupSet from DenseMap keys.
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.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
const SymbolNameSet & getSymbols() const
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
Used to notify clients when symbols can not be found during a lookup.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
const SymbolNameVector & getSymbols() const
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
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::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
const std::string & getModuleName() const
const SymbolNameVector & getSymbols() const
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.
Expected< TBDFlags > getFlags(const Object *File)
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.
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
IntrusiveRefCntPtr< ResourceTracker > ResourceTrackerSP
DenseMap< SymbolStringPtr, JITEvaluatedSymbol > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
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...
JITDylibLookupFlags
Lookup flags that apply to each dylib in the search order for a lookup.
@ MatchExportedSymbolsOnly
DenseMap< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap
A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
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.
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.
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 ...
This is an optimization pass for GlobalISel generic memory operations.
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
uint64_t JITTargetAddress
Represents an address in the target process's address space.
void sort(IteratorTy Start, IteratorTy End)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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.
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::...
SymbolFlagsMap SymbolFlags
SymbolStringPtr InitSymbol
Interface(SymbolFlagsMap InitalSymbolFlags, SymbolStringPtr InitSymbol)
SymbolAliasMapEntry()=default
JITSymbolFlags AliasFlags
SymbolAliasMapEntry(SymbolStringPtr Aliasee, JITSymbolFlags AliasFlags)