LLVM 23.0.0git
LinkGraphLinkingLayer.cpp
Go to the documentation of this file.
1//===------ LinkGraphLinkingLayer.cpp - Link LinkGraphs with JITLink ------===//
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
10
17
18#define DEBUG_TYPE "orc"
19
20using namespace llvm;
21using namespace llvm::jitlink;
22using namespace llvm::orc;
23
24namespace llvm {
25
26struct BlockDepInfo;
27
29
42
43template <> struct GraphTraits<BlockDepInfo *> {
45
47 using impl_iterator = BlockDepInfo::AnonBlockDepSet::iterator;
48
49 public:
50 ChildIteratorType(NodeRef Parent, impl_iterator I)
51 : Parent(Parent), I(std::move(I)) {}
52
53 friend bool operator==(const ChildIteratorType &LHS,
54 const ChildIteratorType &RHS) {
55 return LHS.I == RHS.I;
56 }
57 friend bool operator!=(const ChildIteratorType &LHS,
58 const ChildIteratorType &RHS) {
59 return LHS.I != RHS.I;
60 }
61
63 ++I;
64 return *this;
65 }
67 auto Tmp = *this;
68 ++I;
69 return Tmp;
70 }
72 assert(Parent->Graph && "No pointer to BlockDepInfoMap");
73 return &(*Parent->Graph)[*I];
74 }
75
76 private:
77 NodeRef Parent;
79 };
80
81 static NodeRef getEntryNode(NodeRef N) { return N; }
82
84 return ChildIteratorType(N, N->AnonBlockDeps.begin());
85 }
87 return ChildIteratorType(N, N->AnonBlockDeps.end());
88 }
89};
90
91} // namespace llvm
92
93namespace {
94
95ExecutorAddr getJITSymbolPtrForSymbol(Symbol &Sym, const Triple &TT) {
96 switch (TT.getArch()) {
97 case Triple::arm:
98 case Triple::armeb:
99 case Triple::thumb:
100 case Triple::thumbeb:
102 // Set LSB to indicate thumb target
103 assert(Sym.isCallable() && "Only callable symbols can have thumb flag");
104 assert((Sym.getAddress().getValue() & 0x01) == 0 && "LSB is clear");
105 return Sym.getAddress() + 0x01;
106 }
107 return Sym.getAddress();
108 default:
109 return Sym.getAddress();
110 }
111}
112
113} // end anonymous namespace
114
115namespace llvm {
116namespace orc {
117
119public:
121 std::unique_ptr<MaterializationResponsibility> MR,
122 std::unique_ptr<MemoryBuffer> ObjBuffer)
123 : JITLinkContext(&MR->getTargetJITDylib()), Layer(Layer),
124 MR(std::move(MR)), ObjBuffer(std::move(ObjBuffer)) {
125 std::lock_guard<std::mutex> Lock(Layer.LayerMutex);
126 Plugins = Layer.Plugins;
127 }
128
129 ~JITLinkCtx() override {
130 // If there is an object buffer return function then use it to
131 // return ownership of the buffer.
132 if (Layer.ReturnObjectBuffer && ObjBuffer)
133 Layer.ReturnObjectBuffer(std::move(ObjBuffer));
134 }
135
136 JITLinkMemoryManager &getMemoryManager() override { return Layer.MemMgr; }
137
139 for (auto &P : Plugins)
140 P->notifyMaterializing(*MR, G, *this,
141 ObjBuffer ? ObjBuffer->getMemBufferRef()
142 : MemoryBufferRef());
143 }
144
145 void notifyFailed(Error Err) override {
146 for (auto &P : Plugins)
147 Err = joinErrors(std::move(Err), P->notifyFailed(*MR));
148 Layer.getExecutionSession().reportError(std::move(Err));
149 MR->failMaterialization();
150 }
151
152 void lookup(const LookupMap &Symbols,
153 std::unique_ptr<JITLinkAsyncLookupContinuation> LC) override {
154
155 JITDylibSearchOrder LinkOrder;
156 MR->getTargetJITDylib().withLinkOrderDo(
157 [&](const JITDylibSearchOrder &LO) { LinkOrder = LO; });
158
159 auto &ES = Layer.getExecutionSession();
160
161 SymbolLookupSet LookupSet;
162 for (auto &KV : Symbols) {
163 orc::SymbolLookupFlags LookupFlags;
164 switch (KV.second) {
167 break;
170 break;
171 }
172 LookupSet.add(KV.first, LookupFlags);
173 }
174
175 // OnResolve -- De-intern the symbols and pass the result to the linker.
176 auto OnResolve = [LookupContinuation =
177 std::move(LC)](Expected<SymbolMap> Result) mutable {
178 if (!Result)
179 LookupContinuation->run(Result.takeError());
180 else {
182 LR.insert_range(*Result);
183 LookupContinuation->run(std::move(LR));
184 }
185 };
186
187 ES.lookup(LookupKind::Static, LinkOrder, std::move(LookupSet),
188 SymbolState::Resolved, std::move(OnResolve),
189 [this](const SymbolDependenceMap &Deps) {
190 // Translate LookupDeps map to SymbolSourceJD.
191 for (auto &[DepJD, Deps] : Deps)
192 for (auto &DepSym : Deps)
193 SymbolSourceJDs[NonOwningSymbolStringPtr(DepSym)] = DepJD;
194 });
195 }
196
198
199 SymbolFlagsMap ExtraSymbolsToClaim;
200 bool AutoClaim = Layer.AutoClaimObjectSymbols;
201
202 SymbolMap InternedResult;
203 for (auto *Sym : G.defined_symbols())
204 if (Sym->getScope() < Scope::SideEffectsOnly) {
205 auto Ptr = getJITSymbolPtrForSymbol(*Sym, G.getTargetTriple());
206 auto Flags = getJITSymbolFlagsForSymbol(*Sym);
207 InternedResult[Sym->getName()] = {Ptr, Flags};
208 if (AutoClaim && !MR->getSymbols().count(Sym->getName())) {
209 assert(!ExtraSymbolsToClaim.count(Sym->getName()) &&
210 "Duplicate symbol to claim?");
211 ExtraSymbolsToClaim[Sym->getName()] = Flags;
212 }
213 }
214
215 for (auto *Sym : G.absolute_symbols())
216 if (Sym->getScope() < Scope::SideEffectsOnly) {
217 auto Ptr = getJITSymbolPtrForSymbol(*Sym, G.getTargetTriple());
218 auto Flags = getJITSymbolFlagsForSymbol(*Sym);
219 InternedResult[Sym->getName()] = {Ptr, Flags};
220 if (AutoClaim && !MR->getSymbols().count(Sym->getName())) {
221 assert(!ExtraSymbolsToClaim.count(Sym->getName()) &&
222 "Duplicate symbol to claim?");
223 ExtraSymbolsToClaim[Sym->getName()] = Flags;
224 }
225 }
226
227 if (!ExtraSymbolsToClaim.empty())
228 if (auto Err = MR->defineMaterializing(ExtraSymbolsToClaim))
229 return Err;
230
231 {
232
233 // Check that InternedResult matches up with MR->getSymbols(), overriding
234 // flags if requested.
235 // This guards against faulty transformations / compilers / object caches.
236
237 // First check that there aren't any missing symbols.
238 size_t NumMaterializationSideEffectsOnlySymbols = 0;
239 SymbolNameVector MissingSymbols;
240 for (auto &[Sym, Flags] : MR->getSymbols()) {
241
242 auto I = InternedResult.find(Sym);
243
244 // If this is a materialization-side-effects only symbol then bump
245 // the counter and remove in from the result, otherwise make sure that
246 // it's defined.
247 if (Flags.hasMaterializationSideEffectsOnly())
248 ++NumMaterializationSideEffectsOnlySymbols;
249 else if (I == InternedResult.end())
250 MissingSymbols.push_back(Sym);
251 else if (Layer.OverrideObjectFlags)
252 I->second.setFlags(Flags);
253 }
254
255 // If there were missing symbols then report the error.
256 if (!MissingSymbols.empty())
258 Layer.getExecutionSession().getSymbolStringPool(), G.getName(),
259 std::move(MissingSymbols));
260
261 // If there are more definitions than expected, add them to the
262 // ExtraSymbols vector.
263 SymbolNameVector ExtraSymbols;
264 if (InternedResult.size() >
265 MR->getSymbols().size() - NumMaterializationSideEffectsOnlySymbols) {
266 for (auto &KV : InternedResult)
267 if (!MR->getSymbols().count(KV.first))
268 ExtraSymbols.push_back(KV.first);
269 }
270
271 // If there were extra definitions then report the error.
272 if (!ExtraSymbols.empty())
274 Layer.getExecutionSession().getSymbolStringPool(), G.getName(),
275 std::move(ExtraSymbols));
276 }
277
278 if (auto Err = MR->notifyResolved(InternedResult))
279 return Err;
280
281 return Error::success();
282 }
283
285 if (auto Err = notifyEmitted(std::move(A))) {
286 Layer.getExecutionSession().reportError(std::move(Err));
287 MR->failMaterialization();
288 return;
289 }
290
291 if (auto Err = MR->notifyEmitted(SymbolDepGroups)) {
292 Layer.getExecutionSession().reportError(std::move(Err));
293 MR->failMaterialization();
294 }
295 }
296
297 LinkGraphPassFunction getMarkLivePass(const Triple &TT) const override {
298 return [this](LinkGraph &G) { return markResponsibilitySymbolsLive(G); };
299 }
300
302 // Add passes to mark duplicate defs as should-discard, and to walk the
303 // link graph to build the symbol dependence graph.
304 Config.PrePrunePasses.push_back([this](LinkGraph &G) {
305 return claimOrExternalizeWeakAndCommonSymbols(G);
306 });
307
308 for (auto &P : Plugins)
309 P->modifyPassConfig(*MR, LG, Config);
310
311 Config.PreFixupPasses.push_back(
312 [this](LinkGraph &G) { return registerDependencies(G); });
313
314 return Error::success();
315 }
316
318 Error Err = Error::success();
319 for (auto &P : Plugins)
320 Err = joinErrors(std::move(Err), P->notifyEmitted(*MR));
321
322 if (Err) {
323 if (FA)
324 Err =
325 joinErrors(std::move(Err), Layer.MemMgr.deallocate(std::move(FA)));
326 return Err;
327 }
328
329 if (FA)
330 return Layer.recordFinalizedAlloc(*MR, std::move(FA));
331
332 return Error::success();
333 }
334
335private:
336 Error claimOrExternalizeWeakAndCommonSymbols(LinkGraph &G) {
337 SymbolFlagsMap NewSymbolsToClaim;
338 std::vector<std::pair<SymbolStringPtr, Symbol *>> NameToSym;
339
340 auto ProcessSymbol = [&](Symbol *Sym) {
341 if (Sym->hasName() && Sym->getLinkage() == Linkage::Weak &&
342 Sym->getScope() != Scope::Local) {
343 if (!MR->getSymbols().count(Sym->getName())) {
344 NewSymbolsToClaim[Sym->getName()] =
346 NameToSym.push_back(std::make_pair(Sym->getName(), Sym));
347 }
348 }
349 };
350
351 for (auto *Sym : G.defined_symbols())
352 ProcessSymbol(Sym);
353 for (auto *Sym : G.absolute_symbols())
354 ProcessSymbol(Sym);
355
356 // Attempt to claim all weak defs that we're not already responsible for.
357 // This may fail if the resource tracker has become defunct, but should
358 // always succeed otherwise.
359 if (auto Err = MR->defineMaterializing(std::move(NewSymbolsToClaim)))
360 return Err;
361
362 // Walk the list of symbols that we just tried to claim. Symbols that we're
363 // responsible for are marked live. Symbols that we're not responsible for
364 // are turned into external references.
365 for (auto &KV : NameToSym) {
366 if (MR->getSymbols().count(KV.first))
367 KV.second->setLive(true);
368 else
369 G.makeExternal(*KV.second);
370 }
371
372 return Error::success();
373 }
374
375 Error markResponsibilitySymbolsLive(LinkGraph &G) const {
376 for (auto *Sym : G.defined_symbols())
377 if (Sym->hasName() && MR->getSymbols().count(Sym->getName()))
378 Sym->setLive(true);
379 return Error::success();
380 }
381
382 Error registerDependencies(LinkGraph &G) {
383 auto &TargetJD = MR->getTargetJITDylib();
384 for (auto &[Defs, Deps] : calculateDepGroups(G)) {
385 SymbolDepGroups.push_back(SymbolDependenceGroup());
386 auto &SDG = SymbolDepGroups.back();
387 for (auto *Def : Defs)
388 SDG.Symbols.insert(Def->getName());
389 for (auto *Dep : Deps) {
390 if (Dep->isDefined())
391 SDG.Dependencies[&TargetJD].insert(Dep->getName());
392 else {
393 auto I =
394 SymbolSourceJDs.find(NonOwningSymbolStringPtr(Dep->getName()));
395 if (I != SymbolSourceJDs.end()) {
396 auto &SymJD = *I->second;
397 SDG.Dependencies[&SymJD].insert(Dep->getName());
398 }
399 }
400 }
401 }
402 return Error::success();
403 }
404
406 std::vector<std::shared_ptr<LinkGraphLinkingLayer::Plugin>> Plugins;
407 std::unique_ptr<MaterializationResponsibility> MR;
408 std::unique_ptr<MemoryBuffer> ObjBuffer;
409 DenseMap<NonOwningSymbolStringPtr, JITDylib *> SymbolSourceJDs;
410 std::vector<SymbolDependenceGroup> SymbolDepGroups;
411};
412
414
416 : LinkGraphLayer(ES), MemMgr(ES.getExecutorProcessControl().getMemMgr()) {
417 ES.registerResourceManager(*this);
418}
419
421 JITLinkMemoryManager &MemMgr)
422 : LinkGraphLayer(ES), MemMgr(MemMgr) {
423 ES.registerResourceManager(*this);
424}
425
427 ExecutionSession &ES, std::unique_ptr<JITLinkMemoryManager> MemMgr)
428 : LinkGraphLayer(ES), MemMgr(*MemMgr), MemMgrOwnership(std::move(MemMgr)) {
429 ES.registerResourceManager(*this);
430}
431
433 assert(Allocs.empty() &&
434 "Layer destroyed with resources still attached "
435 "(ExecutionSession::endSession() must be called prior to "
436 "destruction)");
438}
439
441 std::unique_ptr<MaterializationResponsibility> R,
442 std::unique_ptr<LinkGraph> G) {
443 assert(R && "R must not be null");
444 assert(G && "G must not be null");
445 auto Ctx = std::make_unique<JITLinkCtx>(*this, std::move(R), nullptr);
446 Ctx->notifyMaterializing(*G);
447 link(std::move(G), std::move(Ctx));
448}
449
451 std::unique_ptr<MaterializationResponsibility> R,
452 std::unique_ptr<LinkGraph> G, std::unique_ptr<MemoryBuffer> ObjBuf) {
453 assert(R && "R must not be null");
454 assert(G && "G must not be null");
455 assert(ObjBuf && "Object must not be null");
456 auto Ctx =
457 std::make_unique<JITLinkCtx>(*this, std::move(R), std::move(ObjBuf));
458 Ctx->notifyMaterializing(*G);
459 link(std::move(G), std::move(Ctx));
460}
461
463LinkGraphLinkingLayer::calculateDepGroups(LinkGraph &G) {
464
465 // Step 1.
466 // Build initial map entries and symbol def lists.
467 BlockDepInfoMap BlockDepInfos;
468 for (auto *Sym : G.defined_symbols())
469 if (Sym->getScope() != Scope::Local)
470 BlockDepInfos[&Sym->getBlock()].SymbolDefs.push_back(Sym);
471
472 // Step 2.
473 // Complete the BlockDepInfos "graph" by adding symbol and block dependencies
474 // for each block.
475 {
476 SmallVector<Block *> Worklist;
477 Worklist.reserve(BlockDepInfos.size());
478
479 // Build worklist, link each BlockDepInfo "node" back to the BlockInfos map
480 // "graph" for our GraphTraits specialization above. This will allow us to
481 // walk the SCCs of the anonymous-block-dependence graph.
482 for (auto &[B, BDInfo] : BlockDepInfos) {
483 BDInfo.Graph = &BlockDepInfos;
484 Worklist.push_back(B);
485 }
486
487 // Calculate the relevant symbol and block dependencies for each block:
488 // 1. Absolute symbols are ignored.
489 // 2. External symbols are included in a block's symbol dep set.
490 // 3. Blocks that do not define any symbols are included in the anonymous
491 // block dependence sets.
492 // 4. For blocks that do define symbols we add only the first defined
493 // symbol to the symbol dep set (since all symbols for the block will
494 // have the same dependencies).
495 while (!Worklist.empty()) {
496 auto *B = Worklist.pop_back_val();
497 BlockDepInfo *BDInfo = nullptr; // Populated lazily.
498
499 for (auto &E : B->edges()) {
500 if (E.getTarget().isAbsolute()) // skip: absolutes are assumed ready
501 continue;
502
503 if (!BDInfo) // Populate -- we'll need it below.
504 BDInfo = &BlockDepInfos[B];
505
506 if (E.getTarget().isExternal()) { // include and continue
507 BDInfo->SymbolDeps.insert(&E.getTarget());
508 continue;
509 }
510
511 // Target must be defined.
512 auto *TgtB = &E.getTarget().getBlock();
513 auto I = BlockDepInfos.find(TgtB);
514
515 if (I != BlockDepInfos.end()) {
516 // TgtB is in BlockInfos. Record a symbol dependence (if it defines
517 // any symbols) or anonymous block dependence.
518 auto &TgtBInfo = I->second;
519 if (!TgtBInfo.SymbolDefs.empty())
520 BDInfo->SymbolDeps.insert(TgtBInfo.SymbolDefs.front());
521 else
522 BDInfo->AnonBlockDeps.insert(TgtB);
523 } else {
524 // TgtB not in BlockInfos. It must be anonymous. We need to:
525 // 1. Record the dependence.
526 // 2. Add BlockInfos and Worklist entries for TgtB.
527 // 3. Reset BInfo, since step (2) may have invalidated the pointer.
528 BDInfo->AnonBlockDeps.insert(TgtB);
529 Worklist.push_back(TgtB);
530 BlockDepInfos[TgtB].Graph = &BlockDepInfos;
531 BDInfo = nullptr;
532 continue;
533 }
534 }
535 }
536 }
537
538 // Step 3.
539 // Convert block deps to SCC deps.
541 for (auto &[B, BDInfo] : BlockDepInfos) {
542 for (auto &SCC : make_range(scc_begin(&BDInfo), scc_end(&BDInfo))) {
543
544 auto &SCCRootInfo = *SCC.front();
545
546 // Continue if already visited. The loop over the SCC elements below
547 // deletes the SCCs below as it goes, so this early continue just saves
548 // us looking at a bunch of empty sets below that.
549 if (SCCRootInfo.SCCRoot)
550 continue;
551 SCCRootInfo.SCCRoot = &SCCRootInfo;
552
553 // Collect all symbol defs, deps, and anonymous block deps, and remove
554 // the links to already visited SCCs.
555 auto SCCSymbolDefs = std::move(SCCRootInfo.SymbolDefs);
556 auto SCCSymbolDeps = std::move(SCCRootInfo.SymbolDeps);
557 auto SCCAnonBlockDeps = std::move(SCCRootInfo.AnonBlockDeps);
558 for (auto *SCCBInfo : make_range(std::next(SCC.begin()), SCC.end())) {
559 SCCBInfo->SCCRoot = &SCCRootInfo;
560 SCCSymbolDefs.append(SCCBInfo->SymbolDefs);
561 SCCBInfo->SymbolDefs.clear();
562 SCCSymbolDeps.insert(SCCBInfo->SymbolDeps.begin(),
563 SCCBInfo->SymbolDeps.end());
564 SCCBInfo->SymbolDeps.clear();
565 SCCAnonBlockDeps.insert(SCCBInfo->AnonBlockDeps.begin(),
566 SCCBInfo->AnonBlockDeps.end());
567 SCCBInfo->AnonBlockDeps.clear();
568 }
569
570 // Identify DepGroups emitted for previously visited SCCs that this
571 // SCC depends on.
572 DenseSet<size_t> SrcDepGroups;
573 for (auto *DepB : SCCAnonBlockDeps) {
574 assert(BlockDepInfos.count(DepB) && "Unrecognized block");
575 auto &DepBRootInfo = *BlockDepInfos[DepB].SCCRoot;
576 if (DepBRootInfo.DepGroupIndex)
577 SrcDepGroups.insert(*DepBRootInfo.DepGroupIndex);
578 }
579
580 // If this SCC doesn't depend on any existing dep groups then check
581 // whether it has direct symbol deps of its own.
582 if (SrcDepGroups.empty()) {
583
584 // If this SCC has its own symbol deps then add a dep-group and
585 // continue.
586 if (!SCCSymbolDeps.empty()) {
587 SCCRootInfo.DepGroupIndex = DGs.size();
588 DGs.push_back({});
589 DGs.back().Defs = std::move(SCCSymbolDefs);
590 DGs.back().Deps = std::move(SCCSymbolDeps);
591 }
592 // Otherwise just continue.
593 continue;
594 }
595
596 // Special case: If we only depend on one dep group and this SCC
597 // doesn't have any symbol deps of its own then just merge this SCC's
598 // defs into the existing dep group and continue.
599 if (SrcDepGroups.size() == 1 && SCCSymbolDeps.empty()) {
600 SCCRootInfo.DepGroupIndex = *SrcDepGroups.begin();
601 DGs[*SCCRootInfo.DepGroupIndex].Defs.append(SCCSymbolDefs);
602 continue;
603 }
604
605 // General case: This SCC depends on multiple dep groups, and/or has
606 // its own symbol deps. Build a new dep group for it.
607 SCCRootInfo.DepGroupIndex = DGs.size();
608 DGs.push_back({});
609 auto &DG = DGs.back();
610 DG.Defs = std::move(SCCSymbolDefs);
611 for (auto &DGIndex : SrcDepGroups)
612 DG.Deps.insert(DGs[DGIndex].Deps.begin(), DGs[DGIndex].Deps.end());
613 DG.Deps.insert(SCCSymbolDeps.begin(), SCCSymbolDeps.end());
614 }
615 }
616
617 // Remove self-reference from each dep group, and filter out any dep groups
618 // whose resulting deps or defs are empty.
619 for (size_t I = 0; I != DGs.size();) {
620 auto &DG = DGs[I];
621
622 // Remove self-deps.
623 for (auto &Def : DG.Defs)
624 DG.Deps.erase(Def);
625
626 // Remove groups with empty defs or deps.
627 if (DG.Defs.empty() || DG.Deps.empty()) {
628 std::swap(DG, DGs.back());
629 DGs.pop_back();
630 } else
631 ++I;
632 }
633
634 return DGs;
635}
636
637Error LinkGraphLinkingLayer::recordFinalizedAlloc(
638 MaterializationResponsibility &MR, FinalizedAlloc FA) {
639 auto Err = MR.withResourceKeyDo(
640 [&](ResourceKey K) { Allocs[K].push_back(std::move(FA)); });
641
642 if (Err)
643 Err = joinErrors(std::move(Err), MemMgr.deallocate(std::move(FA)));
644
645 return Err;
646}
647
648Error LinkGraphLinkingLayer::handleRemoveResources(JITDylib &JD,
649 ResourceKey K) {
650
651 {
652 Error Err = Error::success();
653 for (auto &P : Plugins)
654 Err = joinErrors(std::move(Err), P->notifyRemovingResources(JD, K));
655 if (Err)
656 return Err;
657 }
658
659 std::vector<FinalizedAlloc> AllocsToRemove;
661 auto I = Allocs.find(K);
662 if (I != Allocs.end()) {
663 std::swap(AllocsToRemove, I->second);
664 Allocs.erase(I);
665 }
666 });
667
668 if (AllocsToRemove.empty())
669 return Error::success();
670
671 return MemMgr.deallocate(std::move(AllocsToRemove));
672}
673
674void LinkGraphLinkingLayer::handleTransferResources(JITDylib &JD,
675 ResourceKey DstKey,
676 ResourceKey SrcKey) {
677 if (Allocs.contains(SrcKey)) {
678 // DstKey may not be in the DenseMap yet, so the following line may resize
679 // the container and invalidate iterators and value references.
680 auto &DstAllocs = Allocs[DstKey];
681 auto &SrcAllocs = Allocs[SrcKey];
682 DstAllocs.reserve(DstAllocs.size() + SrcAllocs.size());
683 for (auto &Alloc : SrcAllocs)
684 DstAllocs.push_back(std::move(Alloc));
685
686 Allocs.erase(SrcKey);
687 }
688
689 for (auto &P : Plugins)
690 P->notifyTransferringResources(JD, DstKey, SrcKey);
691}
692
693} // End namespace orc.
694} // End namespace llvm.
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define I(x, y, z)
Definition MD5.cpp:57
#define G(x, y, z)
Definition MD5.cpp:55
#define P(N)
This builds on the llvm/ADT/GraphTraits.h file to find the strongly connected components (SCCs) of a ...
iterator find(const_arg_type_t< KeyT > Val)
Definition DenseMap.h:178
unsigned size() const
Definition DenseMap.h:110
bool empty() const
Definition DenseMap.h:109
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:174
iterator end()
Definition DenseMap.h:81
void insert_range(Range &&R)
Inserts range of 'std::pair<KeyT, ValueT>' values into the map.
Definition DenseMap.h:294
Implements a dense probed hash-table based set.
Definition DenseSet.h:279
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
friend bool operator!=(const ChildIteratorType &LHS, const ChildIteratorType &RHS)
friend bool operator==(const ChildIteratorType &LHS, const ChildIteratorType &RHS)
void reserve(size_type N)
iterator erase(const_iterator CI)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:202
size_type size() const
Definition DenseSet.h:87
An ExecutionSession represents a running JIT program.
Definition Core.h:1355
LLVM_ABI void registerResourceManager(ResourceManager &RM)
Register the given ResourceManager with this ExecutionSession.
Definition Core.cpp:1626
LLVM_ABI void deregisterResourceManager(ResourceManager &RM)
Deregister the given ResourceManager with this ExecutionSession.
Definition Core.cpp:1630
decltype(auto) runSessionLocked(Func &&F)
Run the given lambda with the session mutex locked.
Definition Core.h:1435
Represents an address in the executor process.
uint64_t getValue() const
Represents a JIT'd dynamic library.
Definition Core.h:919
LinkGraphLayer(ExecutionSession &ES)
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() override
Destroy the LinkGraphLinkingLayer.
void emit(std::unique_ptr< MaterializationResponsibility > R, std::unique_ptr< jitlink::LinkGraph > G) override
Emit a LinkGraph.
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:593
Error withResourceKeyDo(Func &&F) const
Runs the given callback under the session lock, passing in the associated ResourceKey.
Definition Core.h:612
Non-owning SymbolStringPool entry pointer.
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Definition Core.h:199
SymbolLookupSet & add(SymbolStringPtr Name, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Add an element to the set.
Definition Core.h:265
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:177
uintptr_t ResourceKey
Definition Core.h:79
SymbolLookupFlags
Lookup flags that apply to each symbol in a lookup.
Definition Core.h:161
DenseMap< SymbolStringPtr, ExecutorSymbolDef > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
std::vector< SymbolStringPtr > SymbolNameVector
A vector of symbol names.
DenseMap< JITDylib *, SymbolNameSet > SymbolDependenceMap
A map from JITDylibs to sets of symbols.
@ Resolved
Queried, materialization begun.
Definition Core.h:793
DenseMap< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap
A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
NodeAddr< DefNode * > Def
Definition RDFGraph.h:384
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
scc_iterator< T > scc_begin(const T &G)
Construct the begin iterator for a deduced graph type T.
DenseMap< jitlink::Block *, BlockDepInfo > BlockDepInfoMap
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition Error.h:442
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
scc_iterator< T > scc_end(const T &G)
Construct the end iterator for a deduced graph type T.
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:1917
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:872
#define N
SmallVector< jitlink::Symbol * > SymbolDefList
DenseSet< jitlink::Symbol * > SymbolDepSet
std::optional< size_t > DepGroupIndex
DenseSet< jitlink::Block * > AnonBlockDepSet
static ChildIteratorType child_end(NodeRef N)
static ChildIteratorType child_begin(NodeRef N)