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);
348 return *
LHS.first < *
RHS.first;
356 auto LastI =
std::unique(Symbols.begin(), Symbols.end());
357 Symbols.erase(LastI, Symbols.end());
364 if (Symbols.size() < 2)
367 for (UnderlyingVector::size_type
I = 1;
I != Symbols.size(); ++
I)
368 if (Symbols[
I].first == Symbols[
I - 1].first)
420 std::shared_ptr<SymbolDependenceMap> Symbols);
427 std::shared_ptr<SymbolStringPool> SSP;
428 std::shared_ptr<SymbolDependenceMap> Symbols;
445 std::shared_ptr<SymbolStringPool> SSP;
462 std::shared_ptr<SymbolStringPool> SSP;
484 std::shared_ptr<SymbolStringPool> SSP;
507 std::shared_ptr<SymbolStringPool> SSP;
646 : JD(RT->getJITDylib()), RT(
std::
move(RT)),
648 assert(!this->SymbolFlags.
empty() &&
"Materializing nothing?");
654 SymbolStringPtr InitSymbol;
678 "If set, InitSymbol should appear in InitialSymbolFlags map");
704 materialize(std::unique_ptr<MaterializationResponsibility> R) = 0;
718 virtual void anchor();
738 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override;
755 inline std::unique_ptr<AbsoluteSymbolsMaterializationUnit>
757 return std::make_unique<AbsoluteSymbolsMaterializationUnit>(
780 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override;
801 inline std::unique_ptr<ReExportsMaterializationUnit>
803 return std::make_unique<ReExportsMaterializationUnit>(
810 inline std::unique_ptr<ReExportsMaterializationUnit>
814 return std::make_unique<ReExportsMaterializationUnit>(
815 &SourceJD, SourceJDLookupFlags,
std::move(Aliases));
858 bool isComplete()
const {
return OutstandingSymbolsCount == 0; }
864 SymbolState getRequiredState() {
return RequiredState; }
866 void addQueryDependence(
JITDylib &JD, SymbolStringPtr
Name);
868 void removeQueryDependence(
JITDylib &JD,
const SymbolStringPtr &
Name);
870 void dropSymbol(
const SymbolStringPtr &
Name);
872 void handleFailed(
Error Err);
879 size_t OutstandingSymbolsCount;
901 LookupState(std::unique_ptr<InProgressLookupState> IPLS);
906 std::unique_ptr<InProgressLookupState> IPLS;
1006 template <
typename GeneratorT>
1007 GeneratorT &
addGenerator(std::unique_ptr<GeneratorT> DefGenerator);
1040 bool LinkAgainstThisJITDylibFirst =
true);
1071 template <
typename Func>
1073 -> decltype(
F(std::declval<const JITDylibSearchOrder &>()));
1085 template <
typename MaterializationUnitType>
1086 Error define(std::unique_ptr<MaterializationUnitType> &&MU,
1099 template <
typename MaterializationUnitType>
1100 Error define(std::unique_ptr<MaterializationUnitType> &MU,
1151 using AsynchronousSymbolQuerySet =
1152 std::set<std::shared_ptr<AsynchronousSymbolQuery>>;
1154 using AsynchronousSymbolQueryList =
1155 std::vector<std::shared_ptr<AsynchronousSymbolQuery>>;
1157 struct UnmaterializedInfo {
1158 UnmaterializedInfo(std::unique_ptr<MaterializationUnit> MU,
1160 : MU(
std::
move(MU)), RT(RT) {}
1162 std::unique_ptr<MaterializationUnit> MU;
1163 ResourceTracker *RT;
1166 using UnmaterializedInfosMap =
1167 DenseMap<SymbolStringPtr, std::shared_ptr<UnmaterializedInfo>>;
1169 using UnmaterializedInfosList =
1170 std::vector<std::shared_ptr<UnmaterializedInfo>>;
1172 struct MaterializingInfo {
1176 void addQuery(std::shared_ptr<AsynchronousSymbolQuery> Q);
1178 AsynchronousSymbolQueryList takeQueriesMeeting(
SymbolState RequiredState);
1179 AsynchronousSymbolQueryList takeAllPendingQueries() {
1182 bool hasQueriesPending()
const {
return !PendingQueries.empty(); }
1183 const AsynchronousSymbolQueryList &pendingQueries()
const {
1184 return PendingQueries;
1187 AsynchronousSymbolQueryList PendingQueries;
1190 using MaterializingInfosMap = DenseMap<SymbolStringPtr, MaterializingInfo>;
1192 class SymbolTableEntry {
1194 SymbolTableEntry() =
default;
1195 SymbolTableEntry(JITSymbolFlags Flags)
1197 MaterializerAttached(
false), PendingRemoval(
false) {}
1200 JITSymbolFlags
getFlags()
const {
return Flags; }
1203 bool hasMaterializerAttached()
const {
return MaterializerAttached; }
1204 bool isPendingRemoval()
const {
return PendingRemoval; }
1207 void setFlags(JITSymbolFlags Flags) { this->Flags = Flags; }
1209 assert(
static_cast<uint8_t
>(State) < (1 << 6) &&
1210 "State does not fit in bitfield");
1211 this->State =
static_cast<uint8_t
>(State);
1214 void setMaterializerAttached(
bool MaterializerAttached) {
1215 this->MaterializerAttached = MaterializerAttached;
1218 void setPendingRemoval(
bool PendingRemoval) {
1219 this->PendingRemoval = PendingRemoval;
1222 JITEvaluatedSymbol getSymbol()
const {
1223 return JITEvaluatedSymbol(
Addr, Flags);
1228 JITSymbolFlags Flags;
1230 uint8_t MaterializerAttached : 1;
1231 uint8_t PendingRemoval : 1;
1234 using SymbolTable = DenseMap<SymbolStringPtr, SymbolTableEntry>;
1238 std::pair<AsynchronousSymbolQuerySet, std::shared_ptr<SymbolDependenceMap>>
1239 removeTracker(ResourceTracker &RT);
1241 void transferTracker(ResourceTracker &DstRT, ResourceTracker &SrcRT);
1243 Error defineImpl(MaterializationUnit &MU);
1245 void installMaterializationUnit(std::unique_ptr<MaterializationUnit> MU,
1246 ResourceTracker &RT);
1251 void transferEmittedNodeDependencies(MaterializingInfo &DependantMI,
1252 const SymbolStringPtr &DependantName,
1253 MaterializingInfo &EmittedMI);
1258 std::unique_ptr<MaterializationUnit> MU);
1260 Expected<std::unique_ptr<MaterializationResponsibility>>
1262 SymbolStringPtr InitSymbol);
1266 void addDependencies(
const SymbolStringPtr &Name,
1275 using FailedSymbolsWorklist =
1276 std::vector<std::pair<JITDylib *, SymbolStringPtr>>;
1278 static std::pair<AsynchronousSymbolQuerySet,
1279 std::shared_ptr<SymbolDependenceMap>>
1280 failSymbols(FailedSymbolsWorklist);
1283 enum { Open, Closing, Closed } State = Open;
1284 std::mutex GeneratorsMutex;
1285 SymbolTable Symbols;
1286 UnmaterializedInfosMap UnmaterializedInfos;
1287 MaterializingInfosMap MaterializingInfos;
1288 std::vector<std::shared_ptr<DefinitionGenerator>> DefGenerators;
1293 DenseMap<ResourceTracker *, SymbolNameVector> TrackerSymbols;
1294 DenseMap<ResourceTracker *, DenseSet<MaterializationResponsibility *>>
1347 std::unique_ptr<MaterializationResponsibility> MR)
1350 void run()
override;
1353 std::unique_ptr<MaterializationUnit> MU;
1354 std::unique_ptr<MaterializationResponsibility> MR;
1380 const char *ArgData,
size_t ArgSize)>;
1405 return EPC->getSymbolStringPool();
1420 std::lock_guard<std::recursive_mutex>
Lock(SessionMutex);
1471 this->ReportError =
std::move(ReportError);
1482 this->DispatchTask =
std::move(DispatchTask);
1558 assert(
T &&
"T must be non-null");
1572 template <
typename... ArgTs>
1574 EPC->callWrapperAsync(std::forward<ArgTs>(
Args)...);
1585 return EPC->callWrapper(WrapperFnAddr, ArgBuffer);
1590 template <
typename SPSSignature,
typename SendResultT,
typename... ArgTs>
1592 const ArgTs &...
Args) {
1593 EPC->callSPSWrapperAsync<SPSSignature, SendResultT, ArgTs...>(
1594 WrapperFnAddr, std::forward<SendResultT>(SendResult),
Args...);
1602 template <
typename SPSSignature,
typename... WrapperCallArgTs>
1604 WrapperCallArgTs &&...WrapperCallArgs) {
1605 return EPC->callSPSWrapper<SPSSignature, WrapperCallArgTs...>(
1606 WrapperFnAddr, std::forward<WrapperCallArgTs>(WrapperCallArgs)...);
1616 template <
typename SPSSignature,
typename HandlerT>
1618 return [
H = std::forward<HandlerT>(
H)](
1620 const char *ArgData,
size_t ArgSize)
mutable {
1633 template <
typename SPSSignature,
typename ClassT,
typename... MethodArgTs>
1636 return wrapAsyncWithSPS<SPSSignature>(
1637 [Instance, Method](MethodArgTs &&...MethodArgs) {
1638 (Instance->*Method)(std::forward<MethodArgTs>(MethodArgs)...);
1666 static void logErrorsToStdErr(
Error Err) {
1670 static void runOnCurrentThread(std::unique_ptr<Task>
T) {
T->run(); }
1672 void dispatchOutstandingMUs();
1674 static std::unique_ptr<MaterializationResponsibility>
1677 SymbolStringPtr InitSymbol) {
1678 auto &JD = RT.getJITDylib();
1679 std::unique_ptr<MaterializationResponsibility> MR(
1682 JD.TrackerMRs[&RT].insert(MR.get());
1696 SymbolLookupSet &Candidates,
1697 SymbolLookupSet *NonCandidates);
1702 void OL_applyQueryPhase1(std::unique_ptr<InProgressLookupState> IPLS,
1709 void OL_completeLookup(std::unique_ptr<InProgressLookupState> IPLS,
1710 std::shared_ptr<AsynchronousSymbolQuery> Q,
1715 void OL_completeLookupFlags(
1716 std::unique_ptr<InProgressLookupState> IPLS,
1717 unique_function<
void(Expected<SymbolFlagsMap>)> OnComplete);
1720 void OL_destroyMaterializationResponsibility(
1730 std::unique_ptr<MaterializationUnit> MU);
1731 Expected<std::unique_ptr<MaterializationResponsibility>>
1734 const SymbolStringPtr &
Name,
1740 void dumpDispatchInfo(Task &
T);
1743 mutable std::recursive_mutex SessionMutex;
1744 bool SessionOpen =
true;
1745 std::unique_ptr<ExecutorProcessControl> EPC;
1746 std::unique_ptr<Platform>
P;
1750 std::vector<ResourceManager *> ResourceManagers;
1752 std::vector<JITDylibSP> JDs;
1756 mutable std::recursive_mutex OutstandingMUsMutex;
1757 std::vector<std::pair<std::unique_ptr<MaterializationUnit>,
1758 std::unique_ptr<MaterializationResponsibility>>>
1761 mutable std::mutex JITDispatchHandlersMutex;
1762 DenseMap<JITTargetAddress, std::shared_ptr<JITDispatchHandlerFunction>>
1763 JITDispatchHandlers;
1766 inline ExecutionSession &
1771 template <
typename Func>
1774 if (RT->isDefunct())
1775 return make_error<ResourceTrackerDefunct>(RT);
1776 F(RT->getKeyUnsafe());
1781 template <
typename GeneratorT>
1783 auto &
G = *DefGenerator;
1785 assert(State == Open &&
"Cannot add generator to closed JITDylib");
1786 DefGenerators.push_back(
std::move(DefGenerator));
1791 template <
typename Func>
1793 -> decltype(
F(std::declval<const JITDylibSearchOrder &>())) {
1794 assert(State == Open &&
"Cannot use link order of closed JITDylib");
1795 return ES.runSessionLocked([&]() {
return F(LinkOrder); });
1798 template <
typename MaterializationUnitType>
1801 assert(MU &&
"Can not define with a null MU");
1803 if (MU->getSymbols().empty()) {
1806 dbgs() <<
"Warning: Discarding empty MU " << MU->getName() <<
" for "
1812 dbgs() <<
"Defining MU " << MU->getName() <<
" for " <<
getName()
1815 dbgs() <<
"default)";
1817 dbgs() << RT.get() <<
")\n";
1819 dbgs() <<
"0x0, default will be used)\n";
1823 assert(State == Open &&
"JD is defunct");
1825 if (
auto Err = defineImpl(*MU))
1832 if (
auto Err =
P->notifyAdding(*RT, *MU))
1836 installMaterializationUnit(
std::move(MU), *RT);
1841 template <
typename MaterializationUnitType>
1844 assert(MU &&
"Can not define with a null MU");
1846 if (MU->getSymbols().empty()) {
1849 dbgs() <<
"Warning: Discarding empty MU " << MU->getName() <<
getName()
1855 dbgs() <<
"Defining MU " << MU->getName() <<
" for " <<
getName()
1858 dbgs() <<
"default)";
1860 dbgs() << RT.get() <<
")\n";
1862 dbgs() <<
"0x0, default will be used)\n";
1866 assert(State == Open &&
"JD is defunct");
1868 if (
auto Err = defineImpl(*MU))
1875 if (
auto Err =
P->notifyAdding(*RT, *MU))
1879 installMaterializationUnit(
std::move(MU), *RT);
1939 std::unique_ptr<MaterializationUnit> MU) {
1961 #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.
Function object to check whether the first component of a std::pair compares less than the first comp...
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.