Go to the documentation of this file.
13 #ifndef LLVM_EXECUTIONENGINE_ORC_CORE_H
14 #define LLVM_EXECUTIONENGINE_ORC_CORE_H
37 class AsynchronousSymbolQuery;
38 class ExecutionSession;
39 class MaterializationUnit;
40 class MaterializationResponsibility;
42 class ResourceTracker;
43 class InProgressLookupState;
69 return *
reinterpret_cast<JITDylib *
>(JDAndFlag.load() &
70 ~static_cast<uintptr_t>(1));
81 bool isDefunct()
const {
return JDAndFlag.load() & 0x1; }
93 std::atomic_uintptr_t JDAndFlag;
154 std::vector<std::pair<JITDylib *, JITDylibLookupFlags>>;
162 O.reserve(JDs.
size());
164 O.push_back(std::make_pair(JD, Flags));
177 using value_type = std::pair<SymbolStringPtr, SymbolLookupFlags>;
192 std::initializer_list<SymbolStringPtr> Names,
194 Symbols.reserve(Names.size());
195 for (
auto &
Name : Names)
204 Symbols.reserve(Names.
size());
205 for (
const auto &
Name : Names)
216 Symbols.reserve(Names.
size());
217 for (
const auto &
Name : Names)
222 template <
typename KeyT>
227 Result.Symbols.reserve(
M.size());
228 for (
const auto &KV :
M)
229 Result.add(KV.first, Flags);
244 Symbols.reserve(Symbols.size() +
Other.size());
245 for (
auto &KV :
Other)
250 bool empty()
const {
return Symbols.empty(); }
251 UnderlyingVector::size_type
size()
const {
return Symbols.size(); }
269 template <
typename PredFn>
void remove_if(PredFn &&Pred) {
270 UnderlyingVector::size_type
I = 0;
271 while (
I != Symbols.size()) {
272 const auto &
Name = Symbols[
I].first;
273 auto Flags = Symbols[
I].second;
274 if (Pred(
Name, Flags))
286 template <
typename BodyFn>
288 std::is_same<decltype(Body(std::declval<const SymbolStringPtr &>(),
289 std::declval<SymbolLookupFlags>())),
291 UnderlyingVector::size_type
I = 0;
292 while (
I != Symbols.size()) {
293 const auto &
Name = Symbols[
I].first;
294 auto Flags = Symbols[
I].second;
295 if (Body(
Name, Flags))
308 template <
typename BodyFn>
310 std::is_same<decltype(Body(std::declval<const SymbolStringPtr &>(),
311 std::declval<SymbolLookupFlags>())),
314 UnderlyingVector::size_type
I = 0;
315 while (
I != Symbols.size()) {
316 const auto &
Name = Symbols[
I].first;
317 auto Flags = Symbols[
I].second;
318 auto Remove = Body(
Name, Flags);
320 return Remove.takeError();
333 Names.reserve(Symbols.size());
334 for (
auto &KV : Symbols)
335 Names.push_back(KV.first);
344 return LHS.first <
RHS.first;
352 return *
LHS.first < *
RHS.first;
360 auto LastI =
std::unique(Symbols.begin(), Symbols.end());
361 Symbols.erase(LastI, Symbols.end());
368 if (Symbols.size() < 2)
371 for (UnderlyingVector::size_type
I = 1;
I != Symbols.size(); ++
I)
372 if (Symbols[
I].first == Symbols[
I - 1].first)
424 std::shared_ptr<SymbolDependenceMap> Symbols);
431 std::shared_ptr<SymbolStringPool> SSP;
432 std::shared_ptr<SymbolDependenceMap> Symbols;
449 std::shared_ptr<SymbolStringPool> SSP;
466 std::shared_ptr<SymbolStringPool> SSP;
488 std::shared_ptr<SymbolStringPool> SSP;
511 std::shared_ptr<SymbolStringPool> SSP;
650 : JD(RT->getJITDylib()), RT(
std::
move(RT)),
652 assert(!this->SymbolFlags.
empty() &&
"Materializing nothing?");
658 SymbolStringPtr InitSymbol;
682 "If set, InitSymbol should appear in InitialSymbolFlags map");
708 materialize(std::unique_ptr<MaterializationResponsibility> R) = 0;
722 virtual void anchor();
742 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override;
759 inline std::unique_ptr<AbsoluteSymbolsMaterializationUnit>
761 return std::make_unique<AbsoluteSymbolsMaterializationUnit>(
784 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override;
805 inline std::unique_ptr<ReExportsMaterializationUnit>
807 return std::make_unique<ReExportsMaterializationUnit>(
814 inline std::unique_ptr<ReExportsMaterializationUnit>
818 return std::make_unique<ReExportsMaterializationUnit>(
819 &SourceJD, SourceJDLookupFlags,
std::move(Aliases));
862 bool isComplete()
const {
return OutstandingSymbolsCount == 0; }
868 SymbolState getRequiredState() {
return RequiredState; }
870 void addQueryDependence(
JITDylib &JD, SymbolStringPtr
Name);
872 void removeQueryDependence(
JITDylib &JD,
const SymbolStringPtr &
Name);
874 void dropSymbol(
const SymbolStringPtr &
Name);
876 void handleFailed(
Error Err);
883 size_t OutstandingSymbolsCount;
905 LookupState(std::unique_ptr<InProgressLookupState> IPLS);
910 std::unique_ptr<InProgressLookupState> IPLS;
1010 template <
typename GeneratorT>
1011 GeneratorT &
addGenerator(std::unique_ptr<GeneratorT> DefGenerator);
1044 bool LinkAgainstThisJITDylibFirst =
true);
1075 template <
typename Func>
1077 -> decltype(
F(std::declval<const JITDylibSearchOrder &>()));
1089 template <
typename MaterializationUnitType>
1090 Error define(std::unique_ptr<MaterializationUnitType> &&MU,
1103 template <
typename MaterializationUnitType>
1104 Error define(std::unique_ptr<MaterializationUnitType> &MU,
1155 using AsynchronousSymbolQuerySet =
1156 std::set<std::shared_ptr<AsynchronousSymbolQuery>>;
1158 using AsynchronousSymbolQueryList =
1159 std::vector<std::shared_ptr<AsynchronousSymbolQuery>>;
1161 struct UnmaterializedInfo {
1162 UnmaterializedInfo(std::unique_ptr<MaterializationUnit> MU,
1164 : MU(
std::
move(MU)), RT(RT) {}
1166 std::unique_ptr<MaterializationUnit> MU;
1167 ResourceTracker *RT;
1170 using UnmaterializedInfosMap =
1171 DenseMap<SymbolStringPtr, std::shared_ptr<UnmaterializedInfo>>;
1173 using UnmaterializedInfosList =
1174 std::vector<std::shared_ptr<UnmaterializedInfo>>;
1176 struct MaterializingInfo {
1180 void addQuery(std::shared_ptr<AsynchronousSymbolQuery> Q);
1182 AsynchronousSymbolQueryList takeQueriesMeeting(
SymbolState RequiredState);
1183 AsynchronousSymbolQueryList takeAllPendingQueries() {
1186 bool hasQueriesPending()
const {
return !PendingQueries.empty(); }
1187 const AsynchronousSymbolQueryList &pendingQueries()
const {
1188 return PendingQueries;
1191 AsynchronousSymbolQueryList PendingQueries;
1194 using MaterializingInfosMap = DenseMap<SymbolStringPtr, MaterializingInfo>;
1196 class SymbolTableEntry {
1198 SymbolTableEntry() =
default;
1199 SymbolTableEntry(JITSymbolFlags Flags)
1201 MaterializerAttached(
false), PendingRemoval(
false) {}
1204 JITSymbolFlags
getFlags()
const {
return Flags; }
1207 bool hasMaterializerAttached()
const {
return MaterializerAttached; }
1208 bool isPendingRemoval()
const {
return PendingRemoval; }
1211 void setFlags(JITSymbolFlags Flags) { this->Flags = Flags; }
1213 assert(
static_cast<uint8_t
>(State) < (1 << 6) &&
1214 "State does not fit in bitfield");
1215 this->State =
static_cast<uint8_t
>(State);
1218 void setMaterializerAttached(
bool MaterializerAttached) {
1219 this->MaterializerAttached = MaterializerAttached;
1222 void setPendingRemoval(
bool PendingRemoval) {
1223 this->PendingRemoval = PendingRemoval;
1226 JITEvaluatedSymbol getSymbol()
const {
1227 return JITEvaluatedSymbol(
Addr, Flags);
1232 JITSymbolFlags Flags;
1234 uint8_t MaterializerAttached : 1;
1235 uint8_t PendingRemoval : 1;
1238 using SymbolTable = DenseMap<SymbolStringPtr, SymbolTableEntry>;
1242 std::pair<AsynchronousSymbolQuerySet, std::shared_ptr<SymbolDependenceMap>>
1243 removeTracker(ResourceTracker &RT);
1245 void transferTracker(ResourceTracker &DstRT, ResourceTracker &SrcRT);
1247 Error defineImpl(MaterializationUnit &MU);
1249 void installMaterializationUnit(std::unique_ptr<MaterializationUnit> MU,
1250 ResourceTracker &RT);
1255 void transferEmittedNodeDependencies(MaterializingInfo &DependantMI,
1256 const SymbolStringPtr &DependantName,
1257 MaterializingInfo &EmittedMI);
1262 std::unique_ptr<MaterializationUnit> MU);
1264 Expected<std::unique_ptr<MaterializationResponsibility>>
1266 SymbolStringPtr InitSymbol);
1270 void addDependencies(
const SymbolStringPtr &Name,
1279 using FailedSymbolsWorklist =
1280 std::vector<std::pair<JITDylib *, SymbolStringPtr>>;
1282 static std::pair<AsynchronousSymbolQuerySet,
1283 std::shared_ptr<SymbolDependenceMap>>
1284 failSymbols(FailedSymbolsWorklist);
1287 enum { Open, Closing, Closed } State = Open;
1288 std::mutex GeneratorsMutex;
1289 SymbolTable Symbols;
1290 UnmaterializedInfosMap UnmaterializedInfos;
1291 MaterializingInfosMap MaterializingInfos;
1292 std::vector<std::shared_ptr<DefinitionGenerator>> DefGenerators;
1297 DenseMap<ResourceTracker *, SymbolNameVector> TrackerSymbols;
1298 DenseMap<ResourceTracker *, DenseSet<MaterializationResponsibility *>>
1351 std::unique_ptr<MaterializationResponsibility> MR)
1354 void run()
override;
1357 std::unique_ptr<MaterializationUnit> MU;
1358 std::unique_ptr<MaterializationResponsibility> MR;
1384 const char *ArgData,
size_t ArgSize)>;
1409 return EPC->getSymbolStringPool();
1424 std::lock_guard<std::recursive_mutex>
Lock(SessionMutex);
1475 this->ReportError =
std::move(ReportError);
1486 this->DispatchTask =
std::move(DispatchTask);
1562 assert(
T &&
"T must be non-null");
1576 template <
typename... ArgTs>
1578 EPC->callWrapperAsync(std::forward<ArgTs>(
Args)...);
1589 return EPC->callWrapper(WrapperFnAddr, ArgBuffer);
1594 template <
typename SPSSignature,
typename SendResultT,
typename... ArgTs>
1596 const ArgTs &...
Args) {
1597 EPC->callSPSWrapperAsync<SPSSignature, SendResultT, ArgTs...>(
1598 WrapperFnAddr, std::forward<SendResultT>(SendResult),
Args...);
1606 template <
typename SPSSignature,
typename... WrapperCallArgTs>
1608 WrapperCallArgTs &&...WrapperCallArgs) {
1609 return EPC->callSPSWrapper<SPSSignature, WrapperCallArgTs...>(
1610 WrapperFnAddr, std::forward<WrapperCallArgTs>(WrapperCallArgs)...);
1620 template <
typename SPSSignature,
typename HandlerT>
1622 return [
H = std::forward<HandlerT>(
H)](
1624 const char *ArgData,
size_t ArgSize)
mutable {
1637 template <
typename SPSSignature,
typename ClassT,
typename... MethodArgTs>
1640 return wrapAsyncWithSPS<SPSSignature>(
1641 [Instance, Method](MethodArgTs &&...MethodArgs) {
1642 (Instance->*Method)(std::forward<MethodArgTs>(MethodArgs)...);
1670 static void logErrorsToStdErr(
Error Err) {
1674 static void runOnCurrentThread(std::unique_ptr<Task>
T) {
T->run(); }
1676 void dispatchOutstandingMUs();
1678 static std::unique_ptr<MaterializationResponsibility>
1681 SymbolStringPtr InitSymbol) {
1682 auto &JD = RT.getJITDylib();
1683 std::unique_ptr<MaterializationResponsibility> MR(
1686 JD.TrackerMRs[&RT].insert(MR.get());
1700 SymbolLookupSet &Candidates,
1701 SymbolLookupSet *NonCandidates);
1706 void OL_applyQueryPhase1(std::unique_ptr<InProgressLookupState> IPLS,
1713 void OL_completeLookup(std::unique_ptr<InProgressLookupState> IPLS,
1714 std::shared_ptr<AsynchronousSymbolQuery> Q,
1719 void OL_completeLookupFlags(
1720 std::unique_ptr<InProgressLookupState> IPLS,
1721 unique_function<
void(Expected<SymbolFlagsMap>)> OnComplete);
1724 void OL_destroyMaterializationResponsibility(
1734 std::unique_ptr<MaterializationUnit> MU);
1735 Expected<std::unique_ptr<MaterializationResponsibility>>
1738 const SymbolStringPtr &
Name,
1744 void dumpDispatchInfo(Task &
T);
1747 mutable std::recursive_mutex SessionMutex;
1748 bool SessionOpen =
true;
1749 std::unique_ptr<ExecutorProcessControl> EPC;
1750 std::unique_ptr<Platform>
P;
1754 std::vector<ResourceManager *> ResourceManagers;
1756 std::vector<JITDylibSP> JDs;
1760 mutable std::recursive_mutex OutstandingMUsMutex;
1761 std::vector<std::pair<std::unique_ptr<MaterializationUnit>,
1762 std::unique_ptr<MaterializationResponsibility>>>
1765 mutable std::mutex JITDispatchHandlersMutex;
1766 DenseMap<JITTargetAddress, std::shared_ptr<JITDispatchHandlerFunction>>
1767 JITDispatchHandlers;
1770 inline ExecutionSession &
1775 template <
typename Func>
1778 if (RT->isDefunct())
1779 return make_error<ResourceTrackerDefunct>(RT);
1780 F(RT->getKeyUnsafe());
1785 template <
typename GeneratorT>
1787 auto &
G = *DefGenerator;
1789 assert(State == Open &&
"Cannot add generator to closed JITDylib");
1790 DefGenerators.push_back(
std::move(DefGenerator));
1795 template <
typename Func>
1797 -> decltype(
F(std::declval<const JITDylibSearchOrder &>())) {
1798 assert(State == Open &&
"Cannot use link order of closed JITDylib");
1799 return ES.runSessionLocked([&]() {
return F(LinkOrder); });
1802 template <
typename MaterializationUnitType>
1805 assert(MU &&
"Can not define with a null MU");
1807 if (MU->getSymbols().empty()) {
1810 dbgs() <<
"Warning: Discarding empty MU " << MU->getName() <<
" for "
1816 dbgs() <<
"Defining MU " << MU->getName() <<
" for " <<
getName()
1819 dbgs() <<
"default)";
1821 dbgs() << RT.get() <<
")\n";
1823 dbgs() <<
"0x0, default will be used)\n";
1827 assert(State == Open &&
"JD is defunct");
1829 if (
auto Err = defineImpl(*MU))
1836 if (
auto Err =
P->notifyAdding(*RT, *MU))
1840 installMaterializationUnit(
std::move(MU), *RT);
1845 template <
typename MaterializationUnitType>
1848 assert(MU &&
"Can not define with a null MU");
1850 if (MU->getSymbols().empty()) {
1853 dbgs() <<
"Warning: Discarding empty MU " << MU->getName() <<
getName()
1859 dbgs() <<
"Defining MU " << MU->getName() <<
" for " <<
getName()
1862 dbgs() <<
"default)";
1864 dbgs() << RT.get() <<
")\n";
1866 dbgs() <<
"0x0, default will be used)\n";
1870 assert(State == Open &&
"JD is defunct");
1872 if (
auto Err = defineImpl(*MU))
1879 if (
auto Err =
P->notifyAdding(*RT, *MU))
1883 installMaterializationUnit(
std::move(MU), *RT);
1943 std::unique_ptr<MaterializationUnit> MU) {
1965 #endif // LLVM_EXECUTIONENGINE_ORC_CORE_H
Represents an address in the executor process.
Error replace(std::unique_ptr< MaterializationUnit > MU)
Transfers responsibility to the given MaterializationUnit for all symbols defined by that Materializa...
static SymbolLookupSet fromMapKeys(const DenseMap< SymbolStringPtr, KeyT > &M, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Construct a SymbolLookupSet from DenseMap keys.
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
MaterializationTask(std::unique_ptr< MaterializationUnit > MU, std::unique_ptr< MaterializationResponsibility > MR)
auto withLinkOrderDo(Func &&F) -> decltype(F(std::declval< const JITDylibSearchOrder & >()))
Do something with the link order (run under the session lock).
This is an optimization pass for GlobalISel generic memory operations.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Represents a JIT'd dynamic library.
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.
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
void remove_if(PredFn &&Pred)
Removes all elements matching the given predicate, which must be callable as bool(const SymbolStringP...
void notifySymbolMetRequiredState(const SymbolStringPtr &Name, JITEvaluatedSymbol Sym)
Notify the query that a requested symbol has reached the required state.
std::vector< value_type > UnderlyingVector
@ Materializing
Added to the symbol table, never queried.
void setLinkOrder(JITDylibSearchOrder NewSearchOrder, bool LinkAgainstThisJITDylibFirst=true)
Set the link order to be used when fixing up definitions in JITDylib.
void callSPSWrapperAsync(ExecutorAddr WrapperFnAddr, SendResultT &&SendResult, const ArgTs &...Args)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
virtual ~DefinitionGenerator()
void reportError(Error Err)
Report a error for this execution session.
void callWrapperAsync(ArgTs &&... Args)
Run a wrapper function in the executor.
unique_function< void(std::unique_ptr< Task > T)> DispatchTaskFunction
For dispatching ORC tasks (typically materialization tasks).
virtual void materialize(std::unique_ptr< MaterializationResponsibility > R)=0
Implementations of this method should materialize all symbols in the materialzation unit,...
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
void addToLinkOrder(JITDylib &JD, JITDylibLookupFlags JDLookupFlags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Add the given JITDylib to the link order for definitions in this JITDylib.
JITDylib * getJITDylibByName(StringRef Name)
Return a pointer to the "name" JITDylib.
LookupState & operator=(LookupState &&)
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
void dump(raw_ostream &OS)
Dump current JITDylib state to OS.
ResourceTrackerSP getDefaultResourceTracker()
Get the default resource tracker for this JITDylib.
friend class ExecutionSession
A MaterializationUnit implementation for pre-existing absolute symbols.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
SymbolAliasMapEntry(SymbolStringPtr Aliasee, JITSymbolFlags AliasFlags)
const std::string & getName() const
Get the name for this JITLinkDylib.
Error notifyResolved(const SymbolMap &Symbols)
Notifies the target JITDylib that the given symbols have been resolved.
void doDiscard(const JITDylib &JD, const SymbolStringPtr &Name)
Called by JITDylibs to notify MaterializationUnits that the given symbol has been overridden.
Error removeJITDylib(JITDylib &JD)
Closes the given JITDylib.
A set of symbols to look up, each associated with a SymbolLookupFlags value.
const SymbolNameSet & getSymbols() const
Pointer to a pooled string representing a symbol name.
StringRef getName() const override
Return the name of this materialization unit.
void defineNonExistent(ArrayRef< SymbolStringPtr > Symbols)
Define the given symbols as non-existent, removing it from the symbol table and notifying any pending...
virtual ~ResourceManager()
static ErrorSuccess success()
Create a success value.
Error clear()
Calls remove on all trackers currently associated with this JITDylib.
friend class ResourceTracker
UnexpectedSymbolDefinitions(std::shared_ptr< SymbolStringPool > SSP, std::string ModuleName, SymbolNameVector Symbols)
A materialization unit for symbol aliases.
bool erase(const KeyT &Val)
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.
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
ExecutorProcessControl supports interaction with a JIT target process.
API to remove / transfer ownership of JIT resources.
const_iterator end() const
Error defineMaterializing(SymbolFlagsMap SymbolFlags)
Attempt to claim responsibility for new definitions.
void registerResourceManager(ResourceManager &RM)
Register the given ResourceManager with this ExecutionSession.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
SymbolStringPtr InitSymbol
SymbolsCouldNotBeRemoved(std::shared_ptr< SymbolStringPool > SSP, SymbolNameSet Symbols)
const SymbolDependenceMap & getSymbols() const
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Tagged union holding either a T or a Error.
void continueLookup(Error Err)
Continue the lookup.
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
Errors of this type should be returned if a module contains definitions for symbols that are not clai...
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
LookupKind
Describes the kind of lookup being performed.
Flags for symbols in the JIT.
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
void runJITDispatchHandler(SendResultFunction SendResult, JITTargetAddress HandlerFnTagAddr, ArrayRef< char > ArgBuffer)
Run a registered jit-side wrapper function.
void dispatchTask(std::unique_ptr< Task > T)
Materialize the given unit.
void sortByName()
Sort the lookup set lexicographically.
const std::string & getModuleName() const
Represents a symbol that has been evaluated to an address already.
ResourceTrackerSP createResourceTracker()
Create a resource tracker for this JITDylib.
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 ...
virtual StringRef getName() const =0
Return the name of this materialization unit.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
std::function< void(const SymbolDependenceMap &)> RegisterDependenciesFunction
Callback to register the dependencies for a given query.
void replaceInLinkOrder(JITDylib &OldJD, JITDylib &NewJD, JITDylibLookupFlags JDLookupFlags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Replace OldJD with NewJD in the link order if OldJD is present.
JITDylib(const JITDylib &)=delete
unique_function< void(shared::WrapperFunctionResult)> SendResultFunction
Send a result to the remote.
JITDylib & getJITDylib() const
Return the JITDylib targeted by this tracker.
void dump(raw_ostream &OS)
Dump the state of all the JITDylibs in this session.
Error registerJITDispatchHandlers(JITDylib &JD, JITDispatchHandlerAssociationMap WFs)
For each tag symbol name, associate the corresponding AsyncHandlerWrapperFunction with the address of...
SymbolLookupSet(SymbolStringPtr Name, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
SymbolState
Represents the state that a symbol has reached during materialization.
#define DEBUG_WITH_TYPE(TYPE, X)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
SymbolLookupSet(std::initializer_list< SymbolStringPtr > Names, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Construct a SymbolLookupSet from an initializer list of SymbolStringPtrs.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
SymbolLookupFlags
Lookup flags that apply to each symbol in a lookup.
const SymbolFlagsMap & getSymbols() const
Returns the symbol flags map for this responsibility instance.
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.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
const std::string & getModuleName() const
bool containsDuplicates()
Returns true if this set contains any duplicates.
Used to notify clients when symbols can not be found during a lookup.
void remove(iterator I)
Removes the element pointed to by the given iterator.
SymbolLookupSet(ArrayRef< SymbolStringPtr > Names, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Construct a SymbolLookupSet from a vector of symbols with the given Flags used for each value.
RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
friend class JITSymbolResolverAdapter
Error notifyEmitted()
Notifies the target JITDylib (and any pending queries on that JITDylib) that all symbols covered by t...
DenseMap< SymbolStringPtr, JITEvaluatedSymbol > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
void addDependenciesForAll(const SymbolDependenceMap &Dependencies)
Add dependencies that apply to all symbols covered by this instance.
SymbolLookupSet(const SymbolNameSet &Names, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Construct a SymbolLookupSet from a SymbolNameSet with the given Flags used for each value.
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
A thread-safe version of RefCountedBase.
GeneratorT & addGenerator(std::unique_ptr< GeneratorT > DefGenerator)
Adds a definition generator to this JITDylib and returns a referenece to it.
A symbol query that returns results via a callback when results are ready.
decltype(auto) runSessionLocked(Func &&F)
Run the given lambda with the session mutex locked.
This class implements an extremely fast bulk output stream that can only output to a stream.
SymbolLookupSet & add(SymbolStringPtr Name, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Add an element to the set.
StringRef getName() const override
Return the name of this materialization unit.
MaterializationResponsibility & operator=(MaterializationResponsibility &&)=delete
Inheritance utility for extensible RTTI.
void setPlatform(std::unique_ptr< Platform > P)
Set the Platform for this ExecutionSession.
SymbolsNotFound(std::shared_ptr< SymbolStringPool > SSP, SymbolNameSet Symbols)
void remove(UnderlyingVector::size_type I)
Removes the Ith element of the vector, replacing it with the last element.
SymbolNameSet getRequestedSymbols() const
Returns the names of any symbols covered by this MaterializationResponsibility object that have queri...
const SymbolNameVector & getSymbols() const
JITDylib & createBareJITDylib(std::string Name)
Add a new bare JITDylib to this ExecutionSession.
Error endSession()
End the session.
UnderlyingVector::size_type size() const
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization pseudo-symbol, if any.
Error withResourceKeyDo(Func &&F) const
Returns the ResourceTracker for this instance.
void printDescription(raw_ostream &OS) override
shared::WrapperFunctionResult callWrapper(ExecutorAddr WrapperFnAddr, ArrayRef< char > ArgBuffer)
Run a wrapper function in the executor.
C++ wrapper function result: Same as CWrapperFunctionResult but auto-releases memory.
DenseMap< SymbolStringPtr, JITDispatchHandlerFunction > JITDispatchHandlerAssociationMap
A map associating tag names with asynchronous wrapper function implementations in the JIT.
Errors of this type should be returned if a module fails to include definitions that are claimed by t...
friend class MaterializationResponsibility
Expected< std::vector< JITDylibSP > > getDFSLinkOrder()
Return this JITDylib and its transitive dependencies in DFS order based on linkage relationships.
~ExecutionSession()
Destroy an ExecutionSession.
JITDylib & getTargetJITDylib() const
Returns the target JITDylib that these symbols are being materialized into.
std::pair< SymbolStringPtr, SymbolLookupFlags > value_type
ExecutionSession & setDispatchTask(DispatchTaskFunction DispatchTask)
Set the task dispatch function.
MissingSymbolDefinitions(std::shared_ptr< SymbolStringPool > SSP, std::string ModuleName, SymbolNameVector Symbols)
SymbolLookupSet & append(SymbolLookupSet Other)
Quickly append one lookup set to another.
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization symbol for this MaterializationUnit (if any).
Expected< std::vector< JITDylibSP > > getReverseDFSLinkOrder()
Rteurn this JITDylib and its transitive dependencies in reverse DFS order based on linkage relationsh...
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.
bool isDefunct() const
Return true if this tracker has become defunct.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
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...
const SymbolFlagsMap & getSymbols() const
Return the set of symbols that this source provides.
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 addDependencies(const SymbolStringPtr &Name, const SymbolDependenceMap &Dependencies)
@ NeverSearched
No symbol should be in this state.
uint8_t IntrusiveRefCntPtr< ResourceTracker > ResourceTrackerSP
unique_function< void(SendResultFunction SendResult, const char *ArgData, size_t ArgSize)> JITDispatchHandlerFunction
An asynchronous wrapper-function callable from the executor via jit-dispatch.
ReexportsGenerator(JITDylib &SourceJD, JITDylibLookupFlags SourceJDLookupFlags, SymbolPredicate Allow=SymbolPredicate())
Create a reexports generator.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
AbsoluteSymbolsMaterializationUnit(SymbolMap Symbols)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
ResourceKey getKeyUnsafe() const
Returns the key associated with this tracker.
friend class AsynchronousSymbolQuery
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
ExecutionSession(std::unique_ptr< ExecutorProcessControl > EPC)
Construct an ExecutionSession with the given ExecutorProcessControl object.
MaterializationUnit(Interface I)
SymbolAliasMapEntry()=default
Error callSPSWrapper(ExecutorAddr WrapperFnAddr, WrapperCallArgTs &&...WrapperCallArgs)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
Error remove(const SymbolNameSet &Names)
Tries to remove the given symbols.
const_iterator begin() const
print Print MemDeps of function
Interface(SymbolFlagsMap InitalSymbolFlags, SymbolStringPtr InitSymbol)
std::vector< std::pair< JITDylib *, JITDylibLookupFlags > > JITDylibSearchOrder
A list of (JITDylib*, JITDylibLookupFlags) pairs to be used as a search order during symbol lookup.
virtual Error handleRemoveResources(ResourceKey K)=0
Definition generators can be attached to JITDylibs to generate new definitions for otherwise unresolv...
ExecutorProcessControl & getExecutorProcessControl()
Get the ExecutorProcessControl object associated with this ExecutionSession.
Base class for user error types.
virtual ~MaterializationUnit()=default
JITDylib & operator=(const JITDylib &)=delete
ExecutionSession & getExecutionSession() const
Returns the ExecutionSession for this instance.
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...
void deregisterResourceManager(ResourceManager &RM)
Deregister the given ResourceManager with this ExecutionSession.
virtual void handleTransferResources(ResourceKey DstK, ResourceKey SrcK)=0
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
SymbolLookupSet()=default
~MaterializationResponsibility()
Destruct a MaterializationResponsibility instance.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
friend class MaterializationResponsibility
std::function< bool(SymbolStringPtr)> SymbolPredicate
StringRef - Represent a constant reference to a string, i.e.
Analysis the ScalarEvolution expression for r is this
@ Ready
Emitted to memory, but waiting on transitive dependencies.
MaterializationResponsibility(MaterializationResponsibility &&)=delete
Wraps state for a lookup-in-progress.
UnderlyingVector::iterator iterator
SymbolNameVector getSymbolNames() const
Construct a SymbolNameVector from this instance by dropping the Flags values.
void sortByAddress()
Sort the lookup set by pointer value.
Expected< JITDylib & > createJITDylib(std::string Name)
Add a new JITDylib to this ExecutionSession.
DenseMap< JITDylib *, SymbolNameSet > SymbolDependenceMap
A map from JITDylibs to sets of symbols.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
DenseMap< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap
A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
LLVM_NODISCARD bool empty() const
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
AsynchronousSymbolQuery(const SymbolLookupSet &Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete)
Create a query for the given symbols.
Listens for ResourceTracker operations.
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
Get the SymbolStringPool for this instance.
void failMaterialization()
Notify all not-yet-emitted covered by this MaterializationResponsibility instance that an error has o...
ReexportsGenerator can be used with JITDylib::addGenerator to automatically re-export a subset of the...
Platform * getPlatform()
Get the Platform for this session.
std::function< void(Error)> ErrorReporter
For reporting errors.
UnderlyingVector::const_iterator const_iterator
void removeFromLinkOrder(JITDylib &JD)
Remove the given JITDylib from the link order for this JITDylib if it is present.
static uint32_t getFlags(const Symbol *Sym)
Lightweight error class with error context and mandatory checking.
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
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.
void removeDuplicates()
Remove any duplicate elements.
An ExecutionSession represents a running JIT program.
@ MatchExportedSymbolsOnly
Used to notify a JITDylib that the given set of symbols failed to materialize.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
void sort(IteratorTy Start, IteratorTy End)
std::unique_ptr< ReExportsMaterializationUnit > symbolAliases(SymbolAliasMap Aliases)
Create a ReExportsMaterializationUnit with the given aliases.
auto unique(Range &&R, Predicate P)
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
uint64_t JITTargetAddress
Represents an address in the target process's address space.
const SymbolNameVector & getSymbols() const
ResourceTrackerDefunct(ResourceTrackerSP RT)
Expected< std::unique_ptr< MaterializationResponsibility > > delegate(const SymbolNameSet &Symbols)
Delegates responsibility for the given symbols to the returned materialization responsibility.
Error define(std::unique_ptr< MaterializationUnitType > &&MU, ResourceTrackerSP RT=nullptr)
Define all symbols provided by the materialization unit to be part of this JITDylib.
JITSymbolFlags AliasFlags
void lookup(LookupKind K, const JITDylibSearchOrder &SearchOrder, SymbolLookupSet Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete, RegisterDependenciesFunction RegisterDependencies)
Search the given JITDylibs for the given symbols.
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
size_t size() const
size - Get the array size.
const SymbolNameVector & getSymbols() const
SymbolFlagsMap SymbolFlags
@ Emitted
Assigned address, still materializing.
DenseSet< SymbolStringPtr > SymbolNameSet
A set of symbol names (represented by SymbolStringPtrs for.
JITDylibLookupFlags
Lookup flags that apply to each dylib in the search order for a lookup.
@ Resolved
Queried, materialization begun.
static JITDispatchHandlerFunction wrapAsyncWithSPS(HandlerT &&H)
Wrap a handler that takes concrete argument types (and a sender for a concrete return type) to produc...
ReExportsMaterializationUnit(JITDylib *SourceJD, JITDylibLookupFlags SourceJDLookupFlags, SymbolAliasMap Aliases)
SourceJD is allowed to be nullptr, in which case the source JITDylib is taken to be whatever JITDylib...
FailedToMaterialize(std::shared_ptr< SymbolStringPool > SSP, std::shared_ptr< SymbolDependenceMap > Symbols)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
SymbolFlagsMap SymbolFlags
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
unique_function< void(Expected< SymbolMap >)> SymbolsResolvedCallback
Callback to notify client that symbols have been resolved.
std::vector< SymbolStringPtr > SymbolNameVector
A vector of symbol names.
ExecutionSession & setErrorReporter(ErrorReporter ReportError)
Set the error reporter function.
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
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...
Optional< std::vector< StOtherPiece > > Other
bool isComplete() const
Returns true if all symbols covered by this query have been resolved.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
SymbolStringPtr InitSymbol
void removeGenerator(DefinitionGenerator &G)
Remove a definition generator from this JITDylib.