LLVM: lib/ExecutionEngine/Orc/JITLinkReentryTrampolines.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
10
14
15#include
16
17#define DEBUG_TYPE "orc"
18
19using namespace llvm;
21
22namespace {
23constexpr StringRef ReentryFnName = "__orc_rt_reenter";
24constexpr StringRef ReentrySectionName = "__orc_stubs";
25}
26
28
31public:
38
42
46
49
51 std::shared_ptr<std::vector> Addrs) {
52 std::lock_guardstd::mutex Lock(M);
53 assert(!PendingAddrs.count(&G) && "Duplicate registration");
54 PendingAddrs[&G] = std::move(Addrs);
55 }
56
58 std::shared_ptr<std::vector> Addrs;
59 {
60 std::lock_guardstd::mutex Lock(M);
61 auto I = PendingAddrs.find(&G);
62 if (I == PendingAddrs.end())
64 Addrs = std::move(I->second);
65 PendingAddrs.erase(I);
66 }
67
68 auto *Sec = G.findSectionByName(ReentrySectionName);
69 assert(Sec && "Reentry graph missing reentry section");
70 assert(!Sec->empty() && "Reentry graph is empty");
71
72 for (auto *Sym : Sec->symbols())
73 if (!Sym->hasName())
74 Addrs->push_back({Sym->getAddress(), JITSymbolFlags()});
75
77 }
78
79private:
80 std::mutex M;
82 PendingAddrs;
83};
84
87
89
90 const auto &TT = ObjLinkingLayer.getExecutionSession().getTargetTriple();
91 switch (TT.getArch()) {
94 break;
97 break;
98 default:
100 TT.getArchName() + " not supported",
102 }
103
104 return std::make_unique(ObjLinkingLayer,
105 std::move(EmitTrampoline));
106}
107
110 : ObjLinkingLayer(ObjLinkingLayer),
111 EmitTrampoline(std::move(EmitTrampoline)) {
112 auto TAS = std::make_shared();
113 TrampolineAddrScraper = TAS.get();
114 ObjLinkingLayer.addPlugin(std::move(TAS));
115}
116
118 size_t NumTrampolines,
120
121 if (NumTrampolines == 0)
122 return OnTrampolinesReady(std::vector());
123
125 auto &ES = ObjLinkingLayer.getExecutionSession();
126
127 auto ReentryGraphSym =
128 ES.intern(("__orc_reentry_graph_#" + Twine(++ReentryGraphIdx)).str());
129
130 auto G = std::make_uniquejitlink::LinkGraph(
131 (*ReentryGraphSym).str(), ES.getSymbolStringPool(), ES.getTargetTriple(),
133
134 auto &ReentryFnSym = G->addExternalSymbol(ReentryFnName, 0, false);
135
136 auto &ReentrySection =
138
139 for (size_t I = 0; I != NumTrampolines; ++I)
140 EmitTrampoline(*G, ReentrySection, ReentryFnSym).setLive(true);
141
142 auto &FirstBlock = **ReentrySection.blocks().begin();
143 G->addDefinedSymbol(FirstBlock, 0, *ReentryGraphSym, FirstBlock.getSize(),
145
146 auto TrampolineAddrs = std::make_shared<std::vector>();
147 TrampolineAddrScraper->registerGraph(*G, TrampolineAddrs);
148
149
150 if (auto Err = ObjLinkingLayer.add(std::move(RT), std::move(G)))
151 return OnTrampolinesReady(std::move(Err));
152
153
154 ES.lookup(
159 [OnTrampolinesReady = std::move(OnTrampolinesReady),
160 TrampolineAddrs =
163 OnTrampolinesReady(std::move(*TrampolineAddrs));
164 else
165 OnTrampolinesReady(Result.takeError());
166 },
168}
169
176 if (!JLT)
177 return JLT.takeError();
178
180 [JLT = std::move(*JLT)](ResourceTrackerSP RT, size_t NumTrampolines,
182 OnTrampolinesReady) mutable {
183 JLT->emit(std::move(RT), NumTrampolines, std::move(OnTrampolinesReady));
184 },
185 RSMgr, PlatformJD, L);
186}
187
188}
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.
StringRef - 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.
Definition JITLinkReentryTrampolines.cpp:30
void registerGraph(LinkGraph &G, std::shared_ptr< std::vector< ExecutorSymbolDef > > Addrs)
Definition JITLinkReentryTrampolines.cpp:50
Error notifyFailed(MaterializationResponsibility &MR) override
Definition JITLinkReentryTrampolines.cpp:39
Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override
Definition JITLinkReentryTrampolines.cpp:43
void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey, ResourceKey SrcKey) override
Definition JITLinkReentryTrampolines.cpp:47
void modifyPassConfig(MaterializationResponsibility &MR, jitlink::LinkGraph &G, jitlink::PassConfiguration &Config) override
Definition JITLinkReentryTrampolines.cpp:32
Error recordTrampolineAddrs(LinkGraph &G)
Definition JITLinkReentryTrampolines.cpp:57
unique_function< void( Expected< std::vector< ExecutorSymbolDef > > EntryAddrs)> OnTrampolinesReadyFn
LLVM_ABI JITLinkReentryTrampolines(ObjectLinkingLayer &ObjLinkingLayer, EmitTrampolineFn EmitTrampoline)
Definition JITLinkReentryTrampolines.cpp:108
LLVM_ABI void emit(ResourceTrackerSP RT, size_t NumTrampolines, OnTrampolinesReadyFn OnTrampolinesReady)
Definition JITLinkReentryTrampolines.cpp:117
static LLVM_ABI Expected< std::unique_ptr< JITLinkReentryTrampolines > > Create(ObjectLinkingLayer &ObjLinkingLayer)
Create trampolines using the default reentry trampoline function for the session triple.
Definition JITLinkReentryTrampolines.cpp:86
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)
Definition JITLinkReentryTrampolines.cpp:171
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.