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 JITLinkMemoryManager &MemMgr)
417 : LinkGraphLayer(ES), MemMgr(MemMgr) {
418 ES.registerResourceManager(*this);
419}
420
422 ExecutionSession &ES, std::unique_ptr<JITLinkMemoryManager> MemMgr)
423 : LinkGraphLayer(ES), MemMgr(*MemMgr), MemMgrOwnership(std::move(MemMgr)) {
424 ES.registerResourceManager(*this);
425}
426
428 assert(Allocs.empty() &&
429 "Layer destroyed with resources still attached "
430 "(ExecutionSession::endSession() must be called prior to "
431 "destruction)");
433}
434
436 std::unique_ptr<MaterializationResponsibility> R,
437 std::unique_ptr<LinkGraph> G) {
438 assert(R && "R must not be null");
439 assert(G && "G must not be null");
440 auto Ctx = std::make_unique<JITLinkCtx>(*this, std::move(R), nullptr);
441 Ctx->notifyMaterializing(*G);
442 link(std::move(G), std::move(Ctx));
443}
444
446 std::unique_ptr<MaterializationResponsibility> R,
447 std::unique_ptr<LinkGraph> G, std::unique_ptr<MemoryBuffer> ObjBuf) {
448 assert(R && "R must not be null");
449 assert(G && "G must not be null");
450 assert(ObjBuf && "Object must not be null");
451 auto Ctx =
452 std::make_unique<JITLinkCtx>(*this, std::move(R), std::move(ObjBuf));
453 Ctx->notifyMaterializing(*G);
454 link(std::move(G), std::move(Ctx));
455}
456
458LinkGraphLinkingLayer::calculateDepGroups(LinkGraph &G) {
459
460 // Step 1.
461 // Build initial map entries and symbol def lists.
462 BlockDepInfoMap BlockDepInfos;
463 for (auto *Sym : G.defined_symbols())
464 if (Sym->getScope() != Scope::Local)
465 BlockDepInfos[&Sym->getBlock()].SymbolDefs.push_back(Sym);
466
467 // Step 2.
468 // Complete the BlockDepInfos "graph" by adding symbol and block dependencies
469 // for each block.
470 {
471 SmallVector<Block *> Worklist;
472 Worklist.reserve(BlockDepInfos.size());
473
474 // Build worklist, link each BlockDepInfo "node" back to the BlockInfos map
475 // "graph" for our GraphTraits specialization above. This will allow us to
476 // walk the SCCs of the anonymous-block-dependence graph.
477 for (auto &[B, BDInfo] : BlockDepInfos) {
478 BDInfo.Graph = &BlockDepInfos;
479 Worklist.push_back(B);
480 }
481
482 // Calculate the relevant symbol and block dependencies for each block:
483 // 1. Absolute symbols are ignored.
484 // 2. External symbols are included in a block's symbol dep set.
485 // 3. Blocks that do not define any symbols are included in the anonymous
486 // block dependence sets.
487 // 4. For blocks that do define symbols we add only the first defined
488 // symbol to the symbol dep set (since all symbols for the block will
489 // have the same dependencies).
490 while (!Worklist.empty()) {
491 auto *B = Worklist.pop_back_val();
492 BlockDepInfo *BDInfo = nullptr; // Populated lazily.
493
494 for (auto &E : B->edges()) {
495 if (E.getTarget().isAbsolute()) // skip: absolutes are assumed ready
496 continue;
497
498 if (!BDInfo) // Populate -- we'll need it below.
499 BDInfo = &BlockDepInfos[B];
500
501 if (E.getTarget().isExternal()) { // include and continue
502 BDInfo->SymbolDeps.insert(&E.getTarget());
503 continue;
504 }
505
506 // Target must be defined.
507 auto *TgtB = &E.getTarget().getBlock();
508 auto I = BlockDepInfos.find(TgtB);
509
510 if (I != BlockDepInfos.end()) {
511 // TgtB is in BlockInfos. Record a symbol dependence (if it defines
512 // any symbols) or anonymous block dependence.
513 auto &TgtBInfo = I->second;
514 if (!TgtBInfo.SymbolDefs.empty())
515 BDInfo->SymbolDeps.insert(TgtBInfo.SymbolDefs.front());
516 else
517 BDInfo->AnonBlockDeps.insert(TgtB);
518 } else {
519 // TgtB not in BlockInfos. It must be anonymous. We need to:
520 // 1. Record the dependence.
521 // 2. Add BlockInfos and Worklist entries for TgtB.
522 // 3. Reset BInfo, since step (2) may have invalidated the pointer.
523 BDInfo->AnonBlockDeps.insert(TgtB);
524 Worklist.push_back(TgtB);
525 BlockDepInfos[TgtB].Graph = &BlockDepInfos;
526 BDInfo = nullptr;
527 continue;
528 }
529 }
530 }
531 }
532
533 // Step 3.
534 // Convert block deps to SCC deps.
536 for (auto &[B, BDInfo] : BlockDepInfos) {
537 for (auto &SCC : make_range(scc_begin(&BDInfo), scc_end(&BDInfo))) {
538
539 auto &SCCRootInfo = *SCC.front();
540
541 // Continue if already visited. The loop over the SCC elements below
542 // deletes the SCCs below as it goes, so this early continue just saves
543 // us looking at a bunch of empty sets below that.
544 if (SCCRootInfo.SCCRoot)
545 continue;
546 SCCRootInfo.SCCRoot = &SCCRootInfo;
547
548 // Collect all symbol defs, deps, and anonymous block deps, and remove
549 // the links to already visited SCCs.
550 auto SCCSymbolDefs = std::move(SCCRootInfo.SymbolDefs);
551 auto SCCSymbolDeps = std::move(SCCRootInfo.SymbolDeps);
552 auto SCCAnonBlockDeps = std::move(SCCRootInfo.AnonBlockDeps);
553 for (auto *SCCBInfo : make_range(std::next(SCC.begin()), SCC.end())) {
554 SCCBInfo->SCCRoot = &SCCRootInfo;
555 SCCSymbolDefs.append(SCCBInfo->SymbolDefs);
556 SCCBInfo->SymbolDefs.clear();
557 SCCSymbolDeps.insert(SCCBInfo->SymbolDeps.begin(),
558 SCCBInfo->SymbolDeps.end());
559 SCCBInfo->SymbolDeps.clear();
560 SCCAnonBlockDeps.insert(SCCBInfo->AnonBlockDeps.begin(),
561 SCCBInfo->AnonBlockDeps.end());
562 SCCBInfo->AnonBlockDeps.clear();
563 }
564
565 // Identify DepGroups emitted for previously visited SCCs that this
566 // SCC depends on.
567 DenseSet<size_t> SrcDepGroups;
568 for (auto *DepB : SCCAnonBlockDeps) {
569 assert(BlockDepInfos.count(DepB) && "Unrecognized block");
570 auto &DepBRootInfo = *BlockDepInfos[DepB].SCCRoot;
571 if (DepBRootInfo.DepGroupIndex)
572 SrcDepGroups.insert(*DepBRootInfo.DepGroupIndex);
573 }
574
575 // If this SCC doesn't depend on any existing dep groups then check
576 // whether it has direct symbol deps of its own.
577 if (SrcDepGroups.empty()) {
578
579 // If this SCC has its own symbol deps then add a dep-group and
580 // continue.
581 if (!SCCSymbolDeps.empty()) {
582 SCCRootInfo.DepGroupIndex = DGs.size();
583 DGs.push_back({});
584 DGs.back().Defs = std::move(SCCSymbolDefs);
585 DGs.back().Deps = std::move(SCCSymbolDeps);
586 }
587 // Otherwise just continue.
588 continue;
589 }
590
591 // Special case: If we only depend on one dep group and this SCC
592 // doesn't have any symbol deps of its own then just merge this SCC's
593 // defs into the existing dep group and continue.
594 if (SrcDepGroups.size() == 1 && SCCSymbolDeps.empty()) {
595 SCCRootInfo.DepGroupIndex = *SrcDepGroups.begin();
596 DGs[*SCCRootInfo.DepGroupIndex].Defs.append(SCCSymbolDefs);
597 continue;
598 }
599
600 // General case: This SCC depends on multiple dep groups, and/or has
601 // its own symbol deps. Build a new dep group for it.
602 SCCRootInfo.DepGroupIndex = DGs.size();
603 DGs.push_back({});
604 auto &DG = DGs.back();
605 DG.Defs = std::move(SCCSymbolDefs);
606 for (auto &DGIndex : SrcDepGroups)
607 DG.Deps.insert(DGs[DGIndex].Deps.begin(), DGs[DGIndex].Deps.end());
608 DG.Deps.insert(SCCSymbolDeps.begin(), SCCSymbolDeps.end());
609 }
610 }
611
612 // Remove self-reference from each dep group, and filter out any dep groups
613 // whose resulting deps or defs are empty.
614 for (size_t I = 0; I != DGs.size();) {
615 auto &DG = DGs[I];
616
617 // Remove self-deps.
618 for (auto &Def : DG.Defs)
619 DG.Deps.erase(Def);
620
621 // Remove groups with empty defs or deps.
622 if (DG.Defs.empty() || DG.Deps.empty()) {
623 std::swap(DG, DGs.back());
624 DGs.pop_back();
625 } else
626 ++I;
627 }
628
629 return DGs;
630}
631
632Error LinkGraphLinkingLayer::recordFinalizedAlloc(
633 MaterializationResponsibility &MR, FinalizedAlloc FA) {
634 auto Err = MR.withResourceKeyDo(
635 [&](ResourceKey K) { Allocs[K].push_back(std::move(FA)); });
636
637 if (Err)
638 Err = joinErrors(std::move(Err), MemMgr.deallocate(std::move(FA)));
639
640 return Err;
641}
642
643Error LinkGraphLinkingLayer::handleRemoveResources(JITDylib &JD,
644 ResourceKey K) {
645
646 {
647 Error Err = Error::success();
648 for (auto &P : Plugins)
649 Err = joinErrors(std::move(Err), P->notifyRemovingResources(JD, K));
650 if (Err)
651 return Err;
652 }
653
654 std::vector<FinalizedAlloc> AllocsToRemove;
656 auto I = Allocs.find(K);
657 if (I != Allocs.end()) {
658 std::swap(AllocsToRemove, I->second);
659 Allocs.erase(I);
660 }
661 });
662
663 if (AllocsToRemove.empty())
664 return Error::success();
665
666 return MemMgr.deallocate(std::move(AllocsToRemove));
667}
668
669void LinkGraphLinkingLayer::handleTransferResources(JITDylib &JD,
670 ResourceKey DstKey,
671 ResourceKey SrcKey) {
672 if (Allocs.contains(SrcKey)) {
673 // DstKey may not be in the DenseMap yet, so the following line may resize
674 // the container and invalidate iterators and value references.
675 auto &DstAllocs = Allocs[DstKey];
676 auto &SrcAllocs = Allocs[SrcKey];
677 DstAllocs.reserve(DstAllocs.size() + SrcAllocs.size());
678 for (auto &Alloc : SrcAllocs)
679 DstAllocs.push_back(std::move(Alloc));
680
681 Allocs.erase(SrcKey);
682 }
683
684 for (auto &P : Plugins)
685 P->notifyTransferringResources(JD, DstKey, SrcKey);
686}
687
688} // End namespace orc.
689} // 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, jitlink::JITLinkMemoryManager &MemMgr)
Construct a LinkGraphLinkingLayer.
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:1916
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)