17#define DEBUG_TYPE "orc"
23constexpr StringRef ReentryFnName =
"__orc_rt_reenter";
24constexpr StringRef ReentrySectionName =
"__orc_stubs";
51 std::shared_ptr<std::vector<ExecutorSymbolDef>> Addrs) {
52 std::lock_guard<std::mutex> Lock(M);
53 assert(!PendingAddrs.count(&
G) &&
"Duplicate registration");
54 PendingAddrs[&
G] = std::move(Addrs);
58 std::shared_ptr<std::vector<ExecutorSymbolDef>> Addrs;
60 std::lock_guard<std::mutex> Lock(M);
61 auto I = PendingAddrs.find(&
G);
62 if (
I == PendingAddrs.end())
64 Addrs = std::move(
I->second);
65 PendingAddrs.erase(
I);
68 auto *Sec =
G.findSectionByName(ReentrySectionName);
69 assert(Sec &&
"Reentry graph missing reentry section");
70 assert(!Sec->empty() &&
"Reentry graph is empty");
72 for (
auto *Sym : Sec->symbols())
90 const auto &TT = ObjLinkingLayer.getExecutionSession().getTargetTriple();
91 switch (TT.getArch()) {
100 TT.getArchName() +
" not supported",
104 return std::make_unique<JITLinkReentryTrampolines>(ObjLinkingLayer,
105 std::move(EmitTrampoline));
110 : ObjLinkingLayer(ObjLinkingLayer),
111 EmitTrampoline(
std::
move(EmitTrampoline)) {
112 auto TAS = std::make_shared<TrampolineAddrScraperPlugin>();
113 TrampolineAddrScraper = TAS.get();
114 ObjLinkingLayer.addPlugin(std::move(TAS));
118 size_t NumTrampolines,
121 if (NumTrampolines == 0)
122 return OnTrampolinesReady(std::vector<ExecutorSymbolDef>());
125 auto &ES = ObjLinkingLayer.getExecutionSession();
127 auto ReentryGraphSym =
128 ES.intern((
"__orc_reentry_graph_#" +
Twine(++ReentryGraphIdx)).str());
130 auto G = std::make_unique<jitlink::LinkGraph>(
131 (*ReentryGraphSym).str(), ES.getSymbolStringPool(), ES.getTargetTriple(),
135 auto &ReentryFnSym =
G->addExternalSymbol(ReentryFnName, 0,
false);
137 auto &ReentrySection =
140 for (
size_t I = 0;
I != NumTrampolines; ++
I)
141 EmitTrampoline(*
G, ReentrySection, ReentryFnSym).setLive(
true);
143 auto &FirstBlock = **ReentrySection.blocks().begin();
144 G->addDefinedSymbol(FirstBlock, 0, *ReentryGraphSym, FirstBlock.getSize(),
147 auto TrampolineAddrs = std::make_shared<std::vector<ExecutorSymbolDef>>();
148 TrampolineAddrScraper->registerGraph(*
G, TrampolineAddrs);
151 if (
auto Err = ObjLinkingLayer.add(std::move(RT), std::move(
G)))
152 return OnTrampolinesReady(std::move(Err));
160 [OnTrampolinesReady = std::move(OnTrampolinesReady),
164 OnTrampolinesReady(std::move(*TrampolineAddrs));
166 OnTrampolinesReady(
Result.takeError());
178 return JLT.takeError();
183 OnTrampolinesReady)
mutable {
184 JLT->emit(std::move(RT), NumTrampolines, std::move(OnTrampolinesReady));
186 RSMgr, PlatformJD, L);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Flags for symbols in the JIT.
Represent a constant reference to a string, i.e.
Manages the enabling and disabling of subtarget specific features.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Represents a JIT'd dynamic library.
void registerGraph(LinkGraph &G, std::shared_ptr< std::vector< ExecutorSymbolDef > > Addrs)
Error notifyFailed(MaterializationResponsibility &MR) override
Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override
void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey, ResourceKey SrcKey) override
void modifyPassConfig(MaterializationResponsibility &MR, jitlink::LinkGraph &G, jitlink::PassConfiguration &Config) override
Error recordTrampolineAddrs(LinkGraph &G)
unique_function< void( Expected< std::vector< ExecutorSymbolDef > > EntryAddrs)> OnTrampolinesReadyFn
LLVM_ABI JITLinkReentryTrampolines(ObjectLinkingLayer &ObjLinkingLayer, EmitTrampolineFn EmitTrampoline)
LLVM_ABI void emit(ResourceTrackerSP RT, size_t NumTrampolines, OnTrampolinesReadyFn OnTrampolinesReady)
static LLVM_ABI Expected< std::unique_ptr< JITLinkReentryTrampolines > > Create(ObjectLinkingLayer &ObjLinkingLayer)
Create trampolines using the default reentry trampoline function for the session triple.
unique_function< jitlink::Symbol &( jitlink::LinkGraph &G, jitlink::Section &Sec, jitlink::Symbol &ReentrySym)> EmitTrampolineFn
unique_function< void( Expected< std::vector< ExecutorSymbolDef > > EntryAddrs)> OnTrampolinesReadyFn
static Expected< std::unique_ptr< LazyReexportsManager > > Create(EmitTrampolinesFn EmitTrampolines, RedirectableSymbolManager &RSMgr, JITDylib &PlatformJD, Listener *L=nullptr)
Create a LazyReexportsManager that uses the ORC runtime for reentry.
Plugin instances can be added to the ObjectLinkingLayer to receive callbacks when code is loaded or e...
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
An ObjectLayer implementation built on JITLink.
Base class for managing redirectable symbols in which a call gets redirected to another symbol in run...
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Symbol & createAnonymousReentryTrampoline(LinkGraph &G, Section &TrampolineSection, Symbol &ReentrySymbol)
Symbol & createAnonymousReentryTrampoline(LinkGraph &G, Section &TrampolineSection, Symbol &ReentrySymbol)
LLVM_ABI const char * getGenericEdgeKindName(Edge::Kind K)
Returns the string name of the given generic edge kind, or "unknown" otherwise.
IntrusiveRefCntPtr< JITDylib > JITDylibSP
IntrusiveRefCntPtr< ResourceTracker > ResourceTrackerSP
LLVM_ABI Expected< std::unique_ptr< LazyReexportsManager > > createJITLinkLazyReexportsManager(ObjectLinkingLayer &ObjLinkingLayer, RedirectableSymbolManager &RSMgr, JITDylib &PlatformJD, LazyReexportsManager::Listener *L=nullptr)
LLVM_ABI RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
@ Ready
Emitted to memory, but waiting on transitive dependencies.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
An LinkGraph pass configuration, consisting of a list of pre-prune, post-prune, and post-fixup passes...
LinkGraphPassList PreFixupPasses
Pre-fixup passes.