LLVM 20.0.0git
LinkGraphLinkingLayer.cpp
Go to the documentation of this file.
1//===----- LinkGraphLinkingLayer.cpp - JITLink backed ORC ObjectLayer -----===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
15
16#define DEBUG_TYPE "orc"
17
18using namespace llvm;
19using namespace llvm::jitlink;
20using namespace llvm::orc;
21
22namespace {
23
24ExecutorAddr getJITSymbolPtrForSymbol(Symbol &Sym, const Triple &TT) {
25 switch (TT.getArch()) {
26 case Triple::arm:
27 case Triple::armeb:
28 case Triple::thumb:
29 case Triple::thumbeb:
30 if (hasTargetFlags(Sym, aarch32::ThumbSymbol)) {
31 // Set LSB to indicate thumb target
32 assert(Sym.isCallable() && "Only callable symbols can have thumb flag");
33 assert((Sym.getAddress().getValue() & 0x01) == 0 && "LSB is clear");
34 return Sym.getAddress() + 0x01;
35 }
36 return Sym.getAddress();
37 default:
38 return Sym.getAddress();
39 }
40}
41
42} // end anonymous namespace
43
44namespace llvm {
45namespace orc {
46
48public:
50 std::unique_ptr<MaterializationResponsibility> MR,
51 std::unique_ptr<MemoryBuffer> ObjBuffer)
52 : JITLinkContext(&MR->getTargetJITDylib()), Layer(Layer),
53 MR(std::move(MR)), ObjBuffer(std::move(ObjBuffer)) {
54 std::lock_guard<std::mutex> Lock(Layer.LayerMutex);
55 Plugins = Layer.Plugins;
56 }
57
59 // If there is an object buffer return function then use it to
60 // return ownership of the buffer.
61 if (Layer.ReturnObjectBuffer && ObjBuffer)
62 Layer.ReturnObjectBuffer(std::move(ObjBuffer));
63 }
64
65 JITLinkMemoryManager &getMemoryManager() override { return Layer.MemMgr; }
66
68 for (auto &P : Plugins)
69 P->notifyMaterializing(*MR, G, *this,
70 ObjBuffer ? ObjBuffer->getMemBufferRef()
71 : MemoryBufferRef());
72 }
73
74 void notifyFailed(Error Err) override {
75 for (auto &P : Plugins)
76 Err = joinErrors(std::move(Err), P->notifyFailed(*MR));
77 Layer.getExecutionSession().reportError(std::move(Err));
78 MR->failMaterialization();
79 }
80
81 void lookup(const LookupMap &Symbols,
82 std::unique_ptr<JITLinkAsyncLookupContinuation> LC) override {
83
84 JITDylibSearchOrder LinkOrder;
85 MR->getTargetJITDylib().withLinkOrderDo(
86 [&](const JITDylibSearchOrder &LO) { LinkOrder = LO; });
87
88 auto &ES = Layer.getExecutionSession();
89
90 SymbolLookupSet LookupSet;
91 for (auto &KV : Symbols) {
92 orc::SymbolLookupFlags LookupFlags;
93 switch (KV.second) {
96 break;
99 break;
100 }
101 LookupSet.add(KV.first, LookupFlags);
102 }
103
104 // OnResolve -- De-intern the symbols and pass the result to the linker.
105 auto OnResolve = [LookupContinuation =
106 std::move(LC)](Expected<SymbolMap> Result) mutable {
107 if (!Result)
108 LookupContinuation->run(Result.takeError());
109 else {
111 for (auto &KV : *Result)
112 LR[KV.first] = KV.second;
113 LookupContinuation->run(std::move(LR));
114 }
115 };
116
117 ES.lookup(LookupKind::Static, LinkOrder, std::move(LookupSet),
118 SymbolState::Resolved, std::move(OnResolve),
119 [this](const SymbolDependenceMap &Deps) {
120 // Translate LookupDeps map to SymbolSourceJD.
121 for (auto &[DepJD, Deps] : Deps)
122 for (auto &DepSym : Deps)
123 SymbolSourceJDs[NonOwningSymbolStringPtr(DepSym)] = DepJD;
124 });
125 }
126
128
129 SymbolFlagsMap ExtraSymbolsToClaim;
130 bool AutoClaim = Layer.AutoClaimObjectSymbols;
131
132 SymbolMap InternedResult;
133 for (auto *Sym : G.defined_symbols())
134 if (Sym->getScope() < Scope::SideEffectsOnly) {
135 auto Ptr = getJITSymbolPtrForSymbol(*Sym, G.getTargetTriple());
136 auto Flags = getJITSymbolFlagsForSymbol(*Sym);
137 InternedResult[Sym->getName()] = {Ptr, Flags};
138 if (AutoClaim && !MR->getSymbols().count(Sym->getName())) {
139 assert(!ExtraSymbolsToClaim.count(Sym->getName()) &&
140 "Duplicate symbol to claim?");
141 ExtraSymbolsToClaim[Sym->getName()] = Flags;
142 }
143 }
144
145 for (auto *Sym : G.absolute_symbols())
146 if (Sym->getScope() < Scope::SideEffectsOnly) {
147 auto Ptr = getJITSymbolPtrForSymbol(*Sym, G.getTargetTriple());
148 auto Flags = getJITSymbolFlagsForSymbol(*Sym);
149 InternedResult[Sym->getName()] = {Ptr, Flags};
150 if (AutoClaim && !MR->getSymbols().count(Sym->getName())) {
151 assert(!ExtraSymbolsToClaim.count(Sym->getName()) &&
152 "Duplicate symbol to claim?");
153 ExtraSymbolsToClaim[Sym->getName()] = Flags;
154 }
155 }
156
157 if (!ExtraSymbolsToClaim.empty())
158 if (auto Err = MR->defineMaterializing(ExtraSymbolsToClaim))
159 return Err;
160
161 {
162
163 // Check that InternedResult matches up with MR->getSymbols(), overriding
164 // flags if requested.
165 // This guards against faulty transformations / compilers / object caches.
166
167 // First check that there aren't any missing symbols.
168 size_t NumMaterializationSideEffectsOnlySymbols = 0;
169 SymbolNameVector MissingSymbols;
170 for (auto &[Sym, Flags] : MR->getSymbols()) {
171
172 auto I = InternedResult.find(Sym);
173
174 // If this is a materialization-side-effects only symbol then bump
175 // the counter and remove in from the result, otherwise make sure that
176 // it's defined.
177 if (Flags.hasMaterializationSideEffectsOnly())
178 ++NumMaterializationSideEffectsOnlySymbols;
179 else if (I == InternedResult.end())
180 MissingSymbols.push_back(Sym);
181 else if (Layer.OverrideObjectFlags)
182 I->second.setFlags(Flags);
183 }
184
185 // If there were missing symbols then report the error.
186 if (!MissingSymbols.empty())
187 return make_error<MissingSymbolDefinitions>(
188 Layer.getExecutionSession().getSymbolStringPool(), G.getName(),
189 std::move(MissingSymbols));
190
191 // If there are more definitions than expected, add them to the
192 // ExtraSymbols vector.
193 SymbolNameVector ExtraSymbols;
194 if (InternedResult.size() >
195 MR->getSymbols().size() - NumMaterializationSideEffectsOnlySymbols) {
196 for (auto &KV : InternedResult)
197 if (!MR->getSymbols().count(KV.first))
198 ExtraSymbols.push_back(KV.first);
199 }
200
201 // If there were extra definitions then report the error.
202 if (!ExtraSymbols.empty())
203 return make_error<UnexpectedSymbolDefinitions>(
204 Layer.getExecutionSession().getSymbolStringPool(), G.getName(),
205 std::move(ExtraSymbols));
206 }
207
208 if (auto Err = MR->notifyResolved(InternedResult))
209 return Err;
210
211 notifyLoaded();
212 return Error::success();
213 }
214
216 if (auto Err = notifyEmitted(std::move(A))) {
217 Layer.getExecutionSession().reportError(std::move(Err));
218 MR->failMaterialization();
219 return;
220 }
221
222 if (auto Err = MR->notifyEmitted(SymbolDepGroups)) {
223 Layer.getExecutionSession().reportError(std::move(Err));
224 MR->failMaterialization();
225 }
226 }
227
228 LinkGraphPassFunction getMarkLivePass(const Triple &TT) const override {
229 return [this](LinkGraph &G) { return markResponsibilitySymbolsLive(G); };
230 }
231
233 // Add passes to mark duplicate defs as should-discard, and to walk the
234 // link graph to build the symbol dependence graph.
235 Config.PrePrunePasses.push_back([this](LinkGraph &G) {
236 return claimOrExternalizeWeakAndCommonSymbols(G);
237 });
238
239 for (auto &P : Plugins)
240 P->modifyPassConfig(*MR, LG, Config);
241
242 Config.PreFixupPasses.push_back(
243 [this](LinkGraph &G) { return registerDependencies(G); });
244
245 return Error::success();
246 }
247
249 for (auto &P : Plugins)
250 P->notifyLoaded(*MR);
251 }
252
254 Error Err = Error::success();
255 for (auto &P : Plugins)
256 Err = joinErrors(std::move(Err), P->notifyEmitted(*MR));
257
258 if (Err) {
259 if (FA)
260 Err =
261 joinErrors(std::move(Err), Layer.MemMgr.deallocate(std::move(FA)));
262 return Err;
263 }
264
265 if (FA)
266 return Layer.recordFinalizedAlloc(*MR, std::move(FA));
267
268 return Error::success();
269 }
270
271private:
272 Error claimOrExternalizeWeakAndCommonSymbols(LinkGraph &G) {
273 SymbolFlagsMap NewSymbolsToClaim;
274 std::vector<std::pair<SymbolStringPtr, Symbol *>> NameToSym;
275
276 auto ProcessSymbol = [&](Symbol *Sym) {
277 if (Sym->hasName() && Sym->getLinkage() == Linkage::Weak &&
278 Sym->getScope() != Scope::Local) {
279 if (!MR->getSymbols().count(Sym->getName())) {
280 NewSymbolsToClaim[Sym->getName()] =
282 NameToSym.push_back(std::make_pair(Sym->getName(), Sym));
283 }
284 }
285 };
286
287 for (auto *Sym : G.defined_symbols())
288 ProcessSymbol(Sym);
289 for (auto *Sym : G.absolute_symbols())
290 ProcessSymbol(Sym);
291
292 // Attempt to claim all weak defs that we're not already responsible for.
293 // This may fail if the resource tracker has become defunct, but should
294 // always succeed otherwise.
295 if (auto Err = MR->defineMaterializing(std::move(NewSymbolsToClaim)))
296 return Err;
297
298 // Walk the list of symbols that we just tried to claim. Symbols that we're
299 // responsible for are marked live. Symbols that we're not responsible for
300 // are turned into external references.
301 for (auto &KV : NameToSym) {
302 if (MR->getSymbols().count(KV.first))
303 KV.second->setLive(true);
304 else
305 G.makeExternal(*KV.second);
306 }
307
308 return Error::success();
309 }
310
311 Error markResponsibilitySymbolsLive(LinkGraph &G) const {
312 for (auto *Sym : G.defined_symbols())
313 if (Sym->hasName() && MR->getSymbols().count(Sym->getName()))
314 Sym->setLive(true);
315 return Error::success();
316 }
317
318 Error registerDependencies(LinkGraph &G) {
319
320 struct BlockInfo {
321 bool InWorklist = false;
323 DenseSet<Symbol *> SymbolDeps;
324 DenseSet<Block *> AnonEdges, AnonBackEdges;
325 };
326
328
329 // Reserve space so that BlockInfos doesn't need to resize. This is
330 // essential to avoid invalidating pointers to entries below.
331 {
332 size_t NumBlocks = 0;
333 for (auto &Sec : G.sections())
334 NumBlocks += Sec.blocks_size();
335 BlockInfos.reserve(NumBlocks);
336 }
337
338 // Identify non-locally-scoped symbols defined by each block.
339 for (auto *Sym : G.defined_symbols()) {
340 if (Sym->getScope() != Scope::Local)
341 BlockInfos[&Sym->getBlock()].Defs.insert(Sym);
342 }
343
344 // Identify the symbolic and anonymous-block dependencies for each block.
345 for (auto *B : G.blocks()) {
346 auto &BI = BlockInfos[B];
347
348 for (auto &E : B->edges()) {
349
350 // External symbols are trivially depended on.
351 if (E.getTarget().isExternal()) {
352 BI.SymbolDeps.insert(&E.getTarget());
353 continue;
354 }
355
356 // Anonymous symbols aren't depended on at all (they're assumed to be
357 // already available).
358 if (E.getTarget().isAbsolute())
359 continue;
360
361 // If we get here then we depend on a symbol defined by some other
362 // block.
363 auto &TgtBI = BlockInfos[&E.getTarget().getBlock()];
364
365 // If that block has any definitions then use the first one as the
366 // "effective" dependence here (all symbols in TgtBI will become
367 // ready at the same time, and chosing a single symbol to represent
368 // the block keeps the SymbolDepGroup size small).
369 if (!TgtBI.Defs.empty()) {
370 BI.SymbolDeps.insert(*TgtBI.Defs.begin());
371 continue;
372 }
373
374 // Otherwise we've got a dependence on an anonymous block. Record it
375 // here for back-propagating symbol dependencies below.
376 BI.AnonEdges.insert(&E.getTarget().getBlock());
377 TgtBI.AnonBackEdges.insert(B);
378 }
379 }
380
381 // Prune anonymous blocks.
382 {
383 std::vector<Block *> BlocksToRemove;
384 for (auto &[B, BI] : BlockInfos) {
385 // Skip blocks with defs. We only care about anonyous blocks.
386 if (!BI.Defs.empty())
387 continue;
388
389 BlocksToRemove.push_back(B);
390
391 for (auto *FB : BI.AnonEdges)
392 BlockInfos[FB].AnonBackEdges.erase(B);
393
394 for (auto *BB : BI.AnonBackEdges)
395 BlockInfos[BB].AnonEdges.erase(B);
396
397 for (auto *FB : BI.AnonEdges) {
398 auto &FBI = BlockInfos[FB];
399 for (auto *BB : BI.AnonBackEdges)
400 FBI.AnonBackEdges.insert(BB);
401 }
402
403 for (auto *BB : BI.AnonBackEdges) {
404 auto &BBI = BlockInfos[BB];
405 for (auto *SD : BI.SymbolDeps)
406 BBI.SymbolDeps.insert(SD);
407 for (auto *FB : BI.AnonEdges)
408 BBI.AnonEdges.insert(FB);
409 }
410 }
411
412 for (auto *B : BlocksToRemove)
413 BlockInfos.erase(B);
414 }
415
416 // Build the initial dependence propagation worklist.
417 std::deque<Block *> Worklist;
418 for (auto &[B, BI] : BlockInfos) {
419 if (!BI.SymbolDeps.empty() && !BI.AnonBackEdges.empty()) {
420 Worklist.push_back(B);
421 BI.InWorklist = true;
422 }
423 }
424
425 // Propagate symbol deps through the graph.
426 while (!Worklist.empty()) {
427 auto *B = Worklist.front();
428 Worklist.pop_front();
429
430 auto &BI = BlockInfos[B];
431 BI.InWorklist = false;
432
433 for (auto *DB : BI.AnonBackEdges) {
434 auto &DBI = BlockInfos[DB];
435 for (auto *Sym : BI.SymbolDeps) {
436 if (DBI.SymbolDeps.insert(Sym).second && !DBI.InWorklist) {
437 Worklist.push_back(DB);
438 DBI.InWorklist = true;
439 }
440 }
441 }
442 }
443
444 // Transform our local dependence information into a list of
445 // SymbolDependenceGroups (in the SymbolDepGroups member), ready for use in
446 // the upcoming notifyFinalized call.
447 auto &TargetJD = MR->getTargetJITDylib();
448
449 for (auto &[B, BI] : BlockInfos) {
450 if (!BI.Defs.empty()) {
451 SymbolDepGroups.push_back(SymbolDependenceGroup());
452 auto &SDG = SymbolDepGroups.back();
453
454 for (auto *Def : BI.Defs)
455 SDG.Symbols.insert(Def->getName());
456
457 for (auto *Dep : BI.SymbolDeps) {
458 auto DepName = Dep->getName();
459 if (Dep->isDefined())
460 SDG.Dependencies[&TargetJD].insert(std::move(DepName));
461 else {
462 auto SourceJDItr =
463 SymbolSourceJDs.find(NonOwningSymbolStringPtr(DepName));
464 if (SourceJDItr != SymbolSourceJDs.end())
465 SDG.Dependencies[SourceJDItr->second].insert(std::move(DepName));
466 }
467 }
468 }
469 }
470
471 return Error::success();
472 }
473
475 std::vector<std::shared_ptr<LinkGraphLinkingLayer::Plugin>> Plugins;
476 std::unique_ptr<MaterializationResponsibility> MR;
477 std::unique_ptr<MemoryBuffer> ObjBuffer;
479 std::vector<SymbolDependenceGroup> SymbolDepGroups;
480};
481
483
485 : LinkGraphLayer(ES), MemMgr(ES.getExecutorProcessControl().getMemMgr()) {
486 ES.registerResourceManager(*this);
487}
488
490 JITLinkMemoryManager &MemMgr)
491 : LinkGraphLayer(ES), MemMgr(MemMgr) {
492 ES.registerResourceManager(*this);
493}
494
496 ExecutionSession &ES, std::unique_ptr<JITLinkMemoryManager> MemMgr)
497 : LinkGraphLayer(ES), MemMgr(*MemMgr), MemMgrOwnership(std::move(MemMgr)) {
498 ES.registerResourceManager(*this);
499}
500
502 assert(Allocs.empty() && "Layer destroyed with resources still attached");
504}
505
507 std::unique_ptr<MaterializationResponsibility> R,
508 std::unique_ptr<LinkGraph> G) {
509 assert(R && "R must not be null");
510 assert(G && "G must not be null");
511 auto Ctx = std::make_unique<JITLinkCtx>(*this, std::move(R), nullptr);
512 Ctx->notifyMaterializing(*G);
513 link(std::move(G), std::move(Ctx));
514}
515
517 std::unique_ptr<MaterializationResponsibility> R,
518 std::unique_ptr<LinkGraph> G, std::unique_ptr<MemoryBuffer> ObjBuf) {
519 assert(R && "R must not be null");
520 assert(G && "G must not be null");
521 assert(ObjBuf && "Object must not be null");
522 auto Ctx =
523 std::make_unique<JITLinkCtx>(*this, std::move(R), std::move(ObjBuf));
524 Ctx->notifyMaterializing(*G);
525 link(std::move(G), std::move(Ctx));
526}
527
528Error LinkGraphLinkingLayer::recordFinalizedAlloc(
529 MaterializationResponsibility &MR, FinalizedAlloc FA) {
530 auto Err = MR.withResourceKeyDo(
531 [&](ResourceKey K) { Allocs[K].push_back(std::move(FA)); });
532
533 if (Err)
534 Err = joinErrors(std::move(Err), MemMgr.deallocate(std::move(FA)));
535
536 return Err;
537}
538
539Error LinkGraphLinkingLayer::handleRemoveResources(JITDylib &JD,
540 ResourceKey K) {
541
542 {
543 Error Err = Error::success();
544 for (auto &P : Plugins)
545 Err = joinErrors(std::move(Err), P->notifyRemovingResources(JD, K));
546 if (Err)
547 return Err;
548 }
549
550 std::vector<FinalizedAlloc> AllocsToRemove;
552 auto I = Allocs.find(K);
553 if (I != Allocs.end()) {
554 std::swap(AllocsToRemove, I->second);
555 Allocs.erase(I);
556 }
557 });
558
559 if (AllocsToRemove.empty())
560 return Error::success();
561
562 return MemMgr.deallocate(std::move(AllocsToRemove));
563}
564
565void LinkGraphLinkingLayer::handleTransferResources(JITDylib &JD,
566 ResourceKey DstKey,
567 ResourceKey SrcKey) {
568 if (Allocs.contains(SrcKey)) {
569 // DstKey may not be in the DenseMap yet, so the following line may resize
570 // the container and invalidate iterators and value references.
571 auto &DstAllocs = Allocs[DstKey];
572 auto &SrcAllocs = Allocs[SrcKey];
573 DstAllocs.reserve(DstAllocs.size() + SrcAllocs.size());
574 for (auto &Alloc : SrcAllocs)
575 DstAllocs.push_back(std::move(Alloc));
576
577 Allocs.erase(SrcKey);
578 }
579
580 for (auto &P : Plugins)
581 P->notifyTransferringResources(JD, DstKey, SrcKey);
582}
583
585 ExecutionSession &ES, std::unique_ptr<EHFrameRegistrar> Registrar)
586 : ES(ES), Registrar(std::move(Registrar)) {}
587
590 PassConfiguration &PassConfig) {
591
592 PassConfig.PostFixupPasses.push_back(createEHFrameRecorderPass(
593 G.getTargetTriple(), [this, &MR](ExecutorAddr Addr, size_t Size) {
594 if (Addr) {
595 std::lock_guard<std::mutex> Lock(EHFramePluginMutex);
596 assert(!InProcessLinks.count(&MR) &&
597 "Link for MR already being tracked?");
598 InProcessLinks[&MR] = {Addr, Size};
599 }
600 }));
601}
602
605
606 ExecutorAddrRange EmittedRange;
607 {
608 std::lock_guard<std::mutex> Lock(EHFramePluginMutex);
609
610 auto EHFrameRangeItr = InProcessLinks.find(&MR);
611 if (EHFrameRangeItr == InProcessLinks.end())
612 return Error::success();
613
614 EmittedRange = EHFrameRangeItr->second;
615 assert(EmittedRange.Start && "eh-frame addr to register can not be null");
616 InProcessLinks.erase(EHFrameRangeItr);
617 }
618
619 if (auto Err = MR.withResourceKeyDo(
620 [&](ResourceKey K) { EHFrameRanges[K].push_back(EmittedRange); }))
621 return Err;
622
623 return Registrar->registerEHFrames(EmittedRange);
624}
625
628 std::lock_guard<std::mutex> Lock(EHFramePluginMutex);
629 InProcessLinks.erase(&MR);
630 return Error::success();
631}
632
634 ResourceKey K) {
635 std::vector<ExecutorAddrRange> RangesToRemove;
636
637 ES.runSessionLocked([&] {
638 auto I = EHFrameRanges.find(K);
639 if (I != EHFrameRanges.end()) {
640 RangesToRemove = std::move(I->second);
641 EHFrameRanges.erase(I);
642 }
643 });
644
645 Error Err = Error::success();
646 while (!RangesToRemove.empty()) {
647 auto RangeToRemove = RangesToRemove.back();
648 RangesToRemove.pop_back();
649 assert(RangeToRemove.Start && "Untracked eh-frame range must not be null");
650 Err = joinErrors(std::move(Err),
651 Registrar->deregisterEHFrames(RangeToRemove));
652 }
653
654 return Err;
655}
656
658 JITDylib &JD, ResourceKey DstKey, ResourceKey SrcKey) {
659 auto SI = EHFrameRanges.find(SrcKey);
660 if (SI == EHFrameRanges.end())
661 return;
662
663 auto DI = EHFrameRanges.find(DstKey);
664 if (DI != EHFrameRanges.end()) {
665 auto &SrcRanges = SI->second;
666 auto &DstRanges = DI->second;
667 DstRanges.reserve(DstRanges.size() + SrcRanges.size());
668 for (auto &SrcRange : SrcRanges)
669 DstRanges.push_back(std::move(SrcRange));
670 EHFrameRanges.erase(SI);
671 } else {
672 // We need to move SrcKey's ranges over without invalidating the SI
673 // iterator.
674 auto Tmp = std::move(SI->second);
675 EHFrameRanges.erase(SI);
676 EHFrameRanges[DstKey] = std::move(Tmp);
677 }
678}
679
680} // End namespace orc.
681} // End namespace llvm.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
uint64_t Addr
uint64_t Size
RelaxConfig Config
Definition: ELF_riscv.cpp:506
Symbol * Sym
Definition: ELF_riscv.cpp:479
#define I(x, y, z)
Definition: MD5.cpp:58
#define G(x, y, z)
Definition: MD5.cpp:56
#define P(N)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:194
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:156
unsigned size() const
Definition: DenseMap.h:99
bool empty() const
Definition: DenseMap.h:98
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:152
iterator end()
Definition: DenseMap.h:84
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:211
void reserve(size_type NumEntries)
Grow the densemap so that it can contain at least NumEntries items before resizing again.
Definition: DenseMap.h:103
Implements a dense probed hash-table based set.
Definition: DenseSet.h:278
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
Tagged union holding either a T or a Error.
Definition: Error.h:481
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey, ResourceKey SrcKey) override
Error notifyEmitted(MaterializationResponsibility &MR) override
Error notifyFailed(MaterializationResponsibility &MR) override
EHFrameRegistrationPlugin(ExecutionSession &ES, std::unique_ptr< jitlink::EHFrameRegistrar > Registrar)
Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override
void modifyPassConfig(MaterializationResponsibility &MR, jitlink::LinkGraph &G, jitlink::PassConfiguration &PassConfig) override
An ExecutionSession represents a running JIT program.
Definition: Core.h:1339
void reportError(Error Err)
Report a error for this execution session.
Definition: Core.h:1474
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
Get the SymbolStringPool for this instance.
Definition: Core.h:1388
void registerResourceManager(ResourceManager &RM)
Register the given ResourceManager with this ExecutionSession.
Definition: Core.cpp:1624
void deregisterResourceManager(ResourceManager &RM)
Deregister the given ResourceManager with this ExecutionSession.
Definition: Core.cpp:1628
decltype(auto) runSessionLocked(Func &&F)
Run the given lambda with the session mutex locked.
Definition: Core.h:1403
Represents an address in the executor process.
uint64_t getValue() const
Represents a JIT'd dynamic library.
Definition: Core.h:897
ExecutionSession & getExecutionSession()
static JITSymbolFlags getJITSymbolFlagsForSymbol(jitlink::Symbol &Sym)
Get the JITSymbolFlags for the given symbol.
JITLinkCtx(LinkGraphLinkingLayer &Layer, std::unique_ptr< MaterializationResponsibility > MR, std::unique_ptr< MemoryBuffer > ObjBuffer)
void notifyFailed(Error Err) override
Notify this context that linking failed.
void notifyFinalized(JITLinkMemoryManager::FinalizedAlloc A) override
Called by JITLink to notify the context that the object has been finalized (i.e.
JITLinkMemoryManager & getMemoryManager() override
Return the MemoryManager to be used for this link.
Error notifyResolved(LinkGraph &G) override
Called by JITLink once all defined symbols in the graph have been assigned their final memory locatio...
void lookup(const LookupMap &Symbols, std::unique_ptr< JITLinkAsyncLookupContinuation > LC) override
Called by JITLink to resolve external symbols.
LinkGraphPassFunction getMarkLivePass(const Triple &TT) const override
Returns the mark-live pass to be used for this link.
Error modifyPassConfig(LinkGraph &LG, PassConfiguration &Config) override
Called by JITLink to modify the pass pipeline prior to linking.
Error notifyEmitted(jitlink::JITLinkMemoryManager::FinalizedAlloc FA)
LinkGraphLinkingLayer links LinkGraphs into the Executor using JITLink.
void emit(std::unique_ptr< MaterializationResponsibility > R, std::unique_ptr< jitlink::LinkGraph > G) override
Emit a LinkGraph.
std::function< void(std::unique_ptr< MemoryBuffer >)> ReturnObjectBuffer
~LinkGraphLinkingLayer()
Destroy the LinkGraphLinkingLayer.
LinkGraphLinkingLayer(ExecutionSession &ES)
Construct a LinkGraphLinkingLayer using the ExecutorProcessControl instance's memory manager.
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Definition: Core.h:571
Error withResourceKeyDo(Func &&F) const
Runs the given callback under the session lock, passing in the associated ResourceKey.
Definition: Core.h:590
Non-owning SymbolStringPool entry pointer.
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Definition: Core.h:194
SymbolLookupSet & add(SymbolStringPtr Name, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Add an element to the set.
Definition: Core.h:260
unique_function is a type-erasing functor similar to std::function.
std::vector< std::pair< JITDylib *, JITDylibLookupFlags > > JITDylibSearchOrder
A list of (JITDylib*, JITDylibLookupFlags) pairs to be used as a search order during symbol lookup.
Definition: Core.h:173
SymbolLookupFlags
Lookup flags that apply to each symbol in a lookup.
Definition: Core.h:156
std::vector< SymbolStringPtr > SymbolNameVector
A vector of symbol names.
@ Resolved
Queried, materialization begun.
uintptr_t ResourceKey
Definition: Core.h:74
NodeAddr< DefNode * > Def
Definition: RDFGraph.h:384
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition: Error.h:438
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1873
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
Represents an address range in the exceutor process.
A set of symbols and the their dependencies.
Definition: Core.h:559