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