LLVM  16.0.0git
JITLink.h
Go to the documentation of this file.
1 //===------------ JITLink.h - JIT linker functionality ----------*- C++ -*-===//
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 //
9 // Contains generic JIT-linker types.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_EXECUTIONENGINE_JITLINK_JITLINK_H
14 #define LLVM_EXECUTIONENGINE_JITLINK_JITLINK_H
15 
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/DenseSet.h"
18 #include "llvm/ADT/Optional.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/ADT/Triple.h"
24 #include "llvm/Support/Allocator.h"
27 #include "llvm/Support/Endian.h"
28 #include "llvm/Support/Error.h"
32 
33 #include <map>
34 #include <string>
35 #include <system_error>
36 
37 namespace llvm {
38 namespace jitlink {
39 
40 class LinkGraph;
41 class Symbol;
42 class Section;
43 
44 /// Base class for errors originating in JIT linker, e.g. missing relocation
45 /// support.
46 class JITLinkError : public ErrorInfo<JITLinkError> {
47 public:
48  static char ID;
49 
50  JITLinkError(Twine ErrMsg) : ErrMsg(ErrMsg.str()) {}
51 
52  void log(raw_ostream &OS) const override;
53  const std::string &getErrorMessage() const { return ErrMsg; }
54  std::error_code convertToErrorCode() const override;
55 
56 private:
57  std::string ErrMsg;
58 };
59 
60 /// Represents fixups and constraints in the LinkGraph.
61 class Edge {
62 public:
63  using Kind = uint8_t;
64 
66  Invalid, // Invalid edge value.
67  FirstKeepAlive, // Keeps target alive. Offset/addend zero.
68  KeepAlive = FirstKeepAlive, // Tag first edge kind that preserves liveness.
69  FirstRelocation // First architecture specific relocation.
70  };
71 
72  using OffsetT = uint32_t;
73  using AddendT = int64_t;
74 
75  Edge(Kind K, OffsetT Offset, Symbol &Target, AddendT Addend)
76  : Target(&Target), Offset(Offset), Addend(Addend), K(K) {}
77 
78  OffsetT getOffset() const { return Offset; }
79  void setOffset(OffsetT Offset) { this->Offset = Offset; }
80  Kind getKind() const { return K; }
81  void setKind(Kind K) { this->K = K; }
82  bool isRelocation() const { return K >= FirstRelocation; }
83  Kind getRelocation() const {
84  assert(isRelocation() && "Not a relocation edge");
85  return K - FirstRelocation;
86  }
87  bool isKeepAlive() const { return K >= FirstKeepAlive; }
88  Symbol &getTarget() const { return *Target; }
89  void setTarget(Symbol &Target) { this->Target = &Target; }
90  AddendT getAddend() const { return Addend; }
91  void setAddend(AddendT Addend) { this->Addend = Addend; }
92 
93 private:
94  Symbol *Target = nullptr;
95  OffsetT Offset = 0;
96  AddendT Addend = 0;
97  Kind K = 0;
98 };
99 
100 /// Returns the string name of the given generic edge kind, or "unknown"
101 /// otherwise. Useful for debugging.
102 const char *getGenericEdgeKindName(Edge::Kind K);
103 
104 /// Base class for Addressable entities (externals, absolutes, blocks).
105 class Addressable {
106  friend class LinkGraph;
107 
108 protected:
109  Addressable(orc::ExecutorAddr Address, bool IsDefined)
110  : Address(Address), IsDefined(IsDefined), IsAbsolute(false) {}
111 
113  : Address(Address), IsDefined(false), IsAbsolute(true) {
114  assert(!(IsDefined && IsAbsolute) &&
115  "Block cannot be both defined and absolute");
116  }
117 
118 public:
119  Addressable(const Addressable &) = delete;
120  Addressable &operator=(const Addressable &) = default;
121  Addressable(Addressable &&) = delete;
122  Addressable &operator=(Addressable &&) = default;
123 
124  orc::ExecutorAddr getAddress() const { return Address; }
125  void setAddress(orc::ExecutorAddr Address) { this->Address = Address; }
126 
127  /// Returns true if this is a defined addressable, in which case you
128  /// can downcast this to a Block.
129  bool isDefined() const { return static_cast<bool>(IsDefined); }
130  bool isAbsolute() const { return static_cast<bool>(IsAbsolute); }
131 
132 private:
133  void setAbsolute(bool IsAbsolute) {
134  assert(!IsDefined && "Cannot change the Absolute flag on a defined block");
135  this->IsAbsolute = IsAbsolute;
136  }
137 
138  orc::ExecutorAddr Address;
139  uint64_t IsDefined : 1;
140  uint64_t IsAbsolute : 1;
141 
142 protected:
143  // bitfields for Block, allocated here to improve packing.
147 };
148 
149 using SectionOrdinal = unsigned;
150 
151 /// An Addressable with content and edges.
152 class Block : public Addressable {
153  friend class LinkGraph;
154 
155 private:
156  /// Create a zero-fill defined addressable.
158  uint64_t Alignment, uint64_t AlignmentOffset)
159  : Addressable(Address, true), Parent(&Parent), Size(Size) {
160  assert(isPowerOf2_64(Alignment) && "Alignment must be power of 2");
161  assert(AlignmentOffset < Alignment &&
162  "Alignment offset cannot exceed alignment");
163  assert(AlignmentOffset <= MaxAlignmentOffset &&
164  "Alignment offset exceeds maximum");
165  ContentMutable = false;
166  P2Align = Alignment ? countTrailingZeros(Alignment) : 0;
167  this->AlignmentOffset = AlignmentOffset;
168  }
169 
170  /// Create a defined addressable for the given content.
171  /// The Content is assumed to be non-writable, and will be copied when
172  /// mutations are required.
174  uint64_t Alignment, uint64_t AlignmentOffset)
175  : Addressable(Address, true), Parent(&Parent), Data(Content.data()),
176  Size(Content.size()) {
177  assert(isPowerOf2_64(Alignment) && "Alignment must be power of 2");
178  assert(AlignmentOffset < Alignment &&
179  "Alignment offset cannot exceed alignment");
180  assert(AlignmentOffset <= MaxAlignmentOffset &&
181  "Alignment offset exceeds maximum");
182  ContentMutable = false;
183  P2Align = Alignment ? countTrailingZeros(Alignment) : 0;
184  this->AlignmentOffset = AlignmentOffset;
185  }
186 
187  /// Create a defined addressable for the given content.
188  /// The content is assumed to be writable, and the caller is responsible
189  /// for ensuring that it lives for the duration of the Block's lifetime.
190  /// The standard way to achieve this is to allocate it on the Graph's
191  /// allocator.
192  Block(Section &Parent, MutableArrayRef<char> Content,
194  : Addressable(Address, true), Parent(&Parent), Data(Content.data()),
195  Size(Content.size()) {
196  assert(isPowerOf2_64(Alignment) && "Alignment must be power of 2");
197  assert(AlignmentOffset < Alignment &&
198  "Alignment offset cannot exceed alignment");
199  assert(AlignmentOffset <= MaxAlignmentOffset &&
200  "Alignment offset exceeds maximum");
201  ContentMutable = true;
202  P2Align = Alignment ? countTrailingZeros(Alignment) : 0;
203  this->AlignmentOffset = AlignmentOffset;
204  }
205 
206 public:
207  using EdgeVector = std::vector<Edge>;
208  using edge_iterator = EdgeVector::iterator;
209  using const_edge_iterator = EdgeVector::const_iterator;
210 
211  Block(const Block &) = delete;
212  Block &operator=(const Block &) = delete;
213  Block(Block &&) = delete;
214  Block &operator=(Block &&) = delete;
215 
216  /// Return the parent section for this block.
217  Section &getSection() const { return *Parent; }
218 
219  /// Returns true if this is a zero-fill block.
220  ///
221  /// If true, getSize is callable but getContent is not (the content is
222  /// defined to be a sequence of zero bytes of length Size).
223  bool isZeroFill() const { return !Data; }
224 
225  /// Returns the size of this defined addressable.
226  size_t getSize() const { return Size; }
227 
228  /// Returns the address range of this defined addressable.
231  }
232 
233  /// Get the content for this block. Block must not be a zero-fill block.
235  assert(Data && "Block does not contain content");
236  return ArrayRef<char>(Data, Size);
237  }
238 
239  /// Set the content for this block.
240  /// Caller is responsible for ensuring the underlying bytes are not
241  /// deallocated while pointed to by this block.
243  assert(Content.data() && "Setting null content");
244  Data = Content.data();
245  Size = Content.size();
246  ContentMutable = false;
247  }
248 
249  /// Get mutable content for this block.
250  ///
251  /// If this Block's content is not already mutable this will trigger a copy
252  /// of the existing immutable content to a new, mutable buffer allocated using
253  /// LinkGraph::allocateContent.
255 
256  /// Get mutable content for this block.
257  ///
258  /// This block's content must already be mutable. It is a programmatic error
259  /// to call this on a block with immutable content -- consider using
260  /// getMutableContent instead.
262  assert(Data && "Block does not contain content");
263  assert(ContentMutable && "Content is not mutable");
264  return MutableArrayRef<char>(const_cast<char *>(Data), Size);
265  }
266 
267  /// Set mutable content for this block.
268  ///
269  /// The caller is responsible for ensuring that the memory pointed to by
270  /// MutableContent is not deallocated while pointed to by this block.
272  assert(MutableContent.data() && "Setting null content");
273  Data = MutableContent.data();
274  Size = MutableContent.size();
275  ContentMutable = true;
276  }
277 
278  /// Returns true if this block's content is mutable.
279  ///
280  /// This is primarily useful for asserting that a block is already in a
281  /// mutable state prior to modifying the content. E.g. when applying
282  /// fixups we expect the block to already be mutable as it should have been
283  /// copied to working memory.
284  bool isContentMutable() const { return ContentMutable; }
285 
286  /// Get the alignment for this content.
287  uint64_t getAlignment() const { return 1ull << P2Align; }
288 
289  /// Set the alignment for this content.
290  void setAlignment(uint64_t Alignment) {
291  assert(isPowerOf2_64(Alignment) && "Alignment must be a power of two");
292  P2Align = Alignment ? countTrailingZeros(Alignment) : 0;
293  }
294 
295  /// Get the alignment offset for this content.
297 
298  /// Set the alignment offset for this content.
300  assert(AlignmentOffset < (1ull << P2Align) &&
301  "Alignment offset can't exceed alignment");
302  this->AlignmentOffset = AlignmentOffset;
303  }
304 
305  /// Add an edge to this block.
307  Edge::AddendT Addend) {
308  assert((K == Edge::KeepAlive || !isZeroFill()) &&
309  "Adding edge to zero-fill block?");
310  Edges.push_back(Edge(K, Offset, Target, Addend));
311  }
312 
313  /// Add an edge by copying an existing one. This is typically used when
314  /// moving edges between blocks.
315  void addEdge(const Edge &E) { Edges.push_back(E); }
316 
317  /// Return the list of edges attached to this content.
319  return make_range(Edges.begin(), Edges.end());
320  }
321 
322  /// Returns the list of edges attached to this content.
324  return make_range(Edges.begin(), Edges.end());
325  }
326 
327  /// Return the size of the edges list.
328  size_t edges_size() const { return Edges.size(); }
329 
330  /// Returns true if the list of edges is empty.
331  bool edges_empty() const { return Edges.empty(); }
332 
333  /// Remove the edge pointed to by the given iterator.
334  /// Returns an iterator to the new next element.
335  edge_iterator removeEdge(edge_iterator I) { return Edges.erase(I); }
336 
337  /// Returns the address of the fixup for the given edge, which is equal to
338  /// this block's address plus the edge's offset.
340  return getAddress() + E.getOffset();
341  }
342 
343 private:
344  static constexpr uint64_t MaxAlignmentOffset = (1ULL << 56) - 1;
345 
346  void setSection(Section &Parent) { this->Parent = &Parent; }
347 
348  Section *Parent;
349  const char *Data = nullptr;
350  size_t Size = 0;
351  std::vector<Edge> Edges;
352 };
353 
354 // Align an address to conform with block alignment requirements.
356  uint64_t Delta = (B.getAlignmentOffset() - Addr) % B.getAlignment();
357  return Addr + Delta;
358 }
359 
360 // Align a orc::ExecutorAddr to conform with block alignment requirements.
362  return orc::ExecutorAddr(alignToBlock(Addr.getValue(), B));
363 }
364 
365 /// Describes symbol linkage. This can be used to make resolve definition
366 /// clashes.
367 enum class Linkage : uint8_t {
368  Strong,
369  Weak,
370 };
371 
372 /// For errors and debugging output.
373 const char *getLinkageName(Linkage L);
374 
375 /// Defines the scope in which this symbol should be visible:
376 /// Default -- Visible in the public interface of the linkage unit.
377 /// Hidden -- Visible within the linkage unit, but not exported from it.
378 /// Local -- Visible only within the LinkGraph.
379 enum class Scope : uint8_t {
380  Default,
381  Hidden,
382  Local
383 };
384 
385 /// For debugging output.
386 const char *getScopeName(Scope S);
387 
388 raw_ostream &operator<<(raw_ostream &OS, const Block &B);
389 
390 /// Symbol representation.
391 ///
392 /// Symbols represent locations within Addressable objects.
393 /// They can be either Named or Anonymous.
394 /// Anonymous symbols have neither linkage nor visibility, and must point at
395 /// ContentBlocks.
396 /// Named symbols may be in one of four states:
397 /// - Null: Default initialized. Assignable, but otherwise unusable.
398 /// - Defined: Has both linkage and visibility and points to a ContentBlock
399 /// - Common: Has both linkage and visibility, points to a null Addressable.
400 /// - External: Has neither linkage nor visibility, points to an external
401 /// Addressable.
402 ///
403 class Symbol {
404  friend class LinkGraph;
405 
406 private:
408  orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsLive,
409  bool IsCallable)
410  : Name(Name), Base(&Base), Offset(Offset), WeakRef(0), Size(Size) {
411  assert(Offset <= MaxOffset && "Offset out of range");
412  setLinkage(L);
413  setScope(S);
414  setLive(IsLive);
415  setCallable(IsCallable);
416  }
417 
418  static Symbol &constructExternal(BumpPtrAllocator &Allocator,
421  bool WeaklyReferenced) {
422  assert(!Base.isDefined() &&
423  "Cannot create external symbol from defined block");
424  assert(!Name.empty() && "External symbol name cannot be empty");
425  auto *Sym = Allocator.Allocate<Symbol>();
426  new (Sym) Symbol(Base, 0, Name, Size, L, Scope::Default, false, false);
427  Sym->setWeaklyReferenced(WeaklyReferenced);
428  return *Sym;
429  }
430 
431  static Symbol &constructAbsolute(BumpPtrAllocator &Allocator,
432  Addressable &Base, StringRef Name,
434  Scope S, bool IsLive) {
435  assert(!Base.isDefined() &&
436  "Cannot create absolute symbol from a defined block");
437  auto *Sym = Allocator.Allocate<Symbol>();
438  new (Sym) Symbol(Base, 0, Name, Size, L, S, IsLive, false);
439  return *Sym;
440  }
441 
442  static Symbol &constructAnonDef(BumpPtrAllocator &Allocator, Block &Base,
444  orc::ExecutorAddrDiff Size, bool IsCallable,
445  bool IsLive) {
446  assert((Offset + Size) <= Base.getSize() &&
447  "Symbol extends past end of block");
448  auto *Sym = Allocator.Allocate<Symbol>();
449  new (Sym) Symbol(Base, Offset, StringRef(), Size, Linkage::Strong,
450  Scope::Local, IsLive, IsCallable);
451  return *Sym;
452  }
453 
454  static Symbol &constructNamedDef(BumpPtrAllocator &Allocator, Block &Base,
455  orc::ExecutorAddrDiff Offset, StringRef Name,
457  Scope S, bool IsLive, bool IsCallable) {
458  assert((Offset + Size) <= Base.getSize() &&
459  "Symbol extends past end of block");
460  assert(!Name.empty() && "Name cannot be empty");
461  auto *Sym = Allocator.Allocate<Symbol>();
462  new (Sym) Symbol(Base, Offset, Name, Size, L, S, IsLive, IsCallable);
463  return *Sym;
464  }
465 
466 public:
467  /// Create a null Symbol. This allows Symbols to be default initialized for
468  /// use in containers (e.g. as map values). Null symbols are only useful for
469  /// assigning to.
470  Symbol() = default;
471 
472  // Symbols are not movable or copyable.
473  Symbol(const Symbol &) = delete;
474  Symbol &operator=(const Symbol &) = delete;
475  Symbol(Symbol &&) = delete;
476  Symbol &operator=(Symbol &&) = delete;
477 
478  /// Returns true if this symbol has a name.
479  bool hasName() const { return !Name.empty(); }
480 
481  /// Returns the name of this symbol (empty if the symbol is anonymous).
482  StringRef getName() const {
483  assert((!Name.empty() || getScope() == Scope::Local) &&
484  "Anonymous symbol has non-local scope");
485  return Name;
486  }
487 
488  /// Rename this symbol. The client is responsible for updating scope and
489  /// linkage if this name-change requires it.
490  void setName(StringRef Name) { this->Name = Name; }
491 
492  /// Returns true if this Symbol has content (potentially) defined within this
493  /// object file (i.e. is anything but an external or absolute symbol).
494  bool isDefined() const {
495  assert(Base && "Attempt to access null symbol");
496  return Base->isDefined();
497  }
498 
499  /// Returns true if this symbol is live (i.e. should be treated as a root for
500  /// dead stripping).
501  bool isLive() const {
502  assert(Base && "Attempting to access null symbol");
503  return IsLive;
504  }
505 
506  /// Set this symbol's live bit.
507  void setLive(bool IsLive) { this->IsLive = IsLive; }
508 
509  /// Returns true is this symbol is callable.
510  bool isCallable() const { return IsCallable; }
511 
512  /// Set this symbol's callable bit.
513  void setCallable(bool IsCallable) { this->IsCallable = IsCallable; }
514 
515  /// Returns true if the underlying addressable is an unresolved external.
516  bool isExternal() const {
517  assert(Base && "Attempt to access null symbol");
518  return !Base->isDefined() && !Base->isAbsolute();
519  }
520 
521  /// Returns true if the underlying addressable is an absolute symbol.
522  bool isAbsolute() const {
523  assert(Base && "Attempt to access null symbol");
524  return Base->isAbsolute();
525  }
526 
527  /// Return the addressable that this symbol points to.
529  assert(Base && "Cannot get underlying addressable for null symbol");
530  return *Base;
531  }
532 
533  /// Return the addressable that this symbol points to.
534  const Addressable &getAddressable() const {
535  assert(Base && "Cannot get underlying addressable for null symbol");
536  return *Base;
537  }
538 
539  /// Return the Block for this Symbol (Symbol must be defined).
541  assert(Base && "Cannot get block for null symbol");
542  assert(Base->isDefined() && "Not a defined symbol");
543  return static_cast<Block &>(*Base);
544  }
545 
546  /// Return the Block for this Symbol (Symbol must be defined).
547  const Block &getBlock() const {
548  assert(Base && "Cannot get block for null symbol");
549  assert(Base->isDefined() && "Not a defined symbol");
550  return static_cast<const Block &>(*Base);
551  }
552 
553  /// Returns the offset for this symbol within the underlying addressable.
555 
556  /// Returns the address of this symbol.
557  orc::ExecutorAddr getAddress() const { return Base->getAddress() + Offset; }
558 
559  /// Returns the size of this symbol.
560  orc::ExecutorAddrDiff getSize() const { return Size; }
561 
562  /// Set the size of this symbol.
564  assert(Base && "Cannot set size for null Symbol");
565  assert((Size == 0 || Base->isDefined()) &&
566  "Non-zero size can only be set for defined symbols");
567  assert((Offset + Size <= static_cast<const Block &>(*Base).getSize()) &&
568  "Symbol size cannot extend past the end of its containing block");
569  this->Size = Size;
570  }
571 
572  /// Returns the address range of this symbol.
575  }
576 
577  /// Returns true if this symbol is backed by a zero-fill block.
578  /// This method may only be called on defined symbols.
579  bool isSymbolZeroFill() const { return getBlock().isZeroFill(); }
580 
581  /// Returns the content in the underlying block covered by this symbol.
582  /// This method may only be called on defined non-zero-fill symbols.
584  return getBlock().getContent().slice(Offset, Size);
585  }
586 
587  /// Get the linkage for this Symbol.
588  Linkage getLinkage() const { return static_cast<Linkage>(L); }
589 
590  /// Set the linkage for this Symbol.
591  void setLinkage(Linkage L) {
592  assert((L == Linkage::Strong || (!Base->isAbsolute() && !Name.empty())) &&
593  "Linkage can only be applied to defined named symbols");
594  this->L = static_cast<uint8_t>(L);
595  }
596 
597  /// Get the visibility for this Symbol.
598  Scope getScope() const { return static_cast<Scope>(S); }
599 
600  /// Set the visibility for this Symbol.
601  void setScope(Scope S) {
602  assert((!Name.empty() || S == Scope::Local) &&
603  "Can not set anonymous symbol to non-local scope");
604  assert((S != Scope::Local || Base->isDefined() || Base->isAbsolute()) &&
605  "Invalid visibility for symbol type");
606  this->S = static_cast<uint8_t>(S);
607  }
608 
609  /// Returns true if this is a weakly referenced external symbol.
610  /// This method may only be called on external symbols.
611  bool isWeaklyReferenced() const {
612  assert(isExternal() && "isWeaklyReferenced called on non-external");
613  return WeakRef;
614  }
615 
616  /// Set the WeaklyReferenced value for this symbol.
617  /// This method may only be called on external symbols.
618  void setWeaklyReferenced(bool WeakRef) {
619  assert(isExternal() && "setWeaklyReferenced called on non-external");
620  this->WeakRef = WeakRef;
621  }
622 
623 private:
624  void makeExternal(Addressable &A) {
625  assert(!A.isDefined() && !A.isAbsolute() &&
626  "Attempting to make external with defined or absolute block");
627  Base = &A;
628  Offset = 0;
630  IsLive = 0;
631  // note: Size, Linkage and IsCallable fields left unchanged.
632  }
633 
634  void makeAbsolute(Addressable &A) {
635  assert(!A.isDefined() && A.isAbsolute() &&
636  "Attempting to make absolute with defined or external block");
637  Base = &A;
638  Offset = 0;
639  }
640 
641  void setBlock(Block &B) { Base = &B; }
642 
643  void setOffset(orc::ExecutorAddrDiff NewOffset) {
644  assert(NewOffset <= MaxOffset && "Offset out of range");
645  Offset = NewOffset;
646  }
647 
648  static constexpr uint64_t MaxOffset = (1ULL << 59) - 1;
649 
650  // FIXME: A char* or SymbolStringPtr may pack better.
651  StringRef Name;
652  Addressable *Base = nullptr;
653  uint64_t Offset : 58;
654  uint64_t L : 1;
655  uint64_t S : 2;
656  uint64_t IsLive : 1;
657  uint64_t IsCallable : 1;
658  uint64_t WeakRef : 1;
659  size_t Size = 0;
660 };
661 
662 raw_ostream &operator<<(raw_ostream &OS, const Symbol &A);
663 
664 void printEdge(raw_ostream &OS, const Block &B, const Edge &E,
665  StringRef EdgeKindName);
666 
667 /// Represents an object file section.
668 class Section {
669  friend class LinkGraph;
670 
671 private:
673  : Name(Name), Prot(Prot), SecOrdinal(SecOrdinal) {}
674 
675  using SymbolSet = DenseSet<Symbol *>;
676  using BlockSet = DenseSet<Block *>;
677 
678 public:
681 
684 
685  ~Section();
686 
687  // Sections are not movable or copyable.
688  Section(const Section &) = delete;
689  Section &operator=(const Section &) = delete;
690  Section(Section &&) = delete;
691  Section &operator=(Section &&) = delete;
692 
693  /// Returns the name of this section.
694  StringRef getName() const { return Name; }
695 
696  /// Returns the protection flags for this section.
697  orc::MemProt getMemProt() const { return Prot; }
698 
699  /// Set the protection flags for this section.
700  void setMemProt(orc::MemProt Prot) { this->Prot = Prot; }
701 
702  /// Get the deallocation policy for this section.
704 
705  /// Set the deallocation policy for this section.
706  void setMemDeallocPolicy(orc::MemDeallocPolicy MDP) { this->MDP = MDP; }
707 
708  /// Returns the ordinal for this section.
709  SectionOrdinal getOrdinal() const { return SecOrdinal; }
710 
711  /// Returns an iterator over the blocks defined in this section.
713  return make_range(Blocks.begin(), Blocks.end());
714  }
715 
716  /// Returns an iterator over the blocks defined in this section.
718  return make_range(Blocks.begin(), Blocks.end());
719  }
720 
721  /// Returns the number of blocks in this section.
722  BlockSet::size_type blocks_size() const { return Blocks.size(); }
723 
724  /// Returns an iterator over the symbols defined in this section.
726  return make_range(Symbols.begin(), Symbols.end());
727  }
728 
729  /// Returns an iterator over the symbols defined in this section.
731  return make_range(Symbols.begin(), Symbols.end());
732  }
733 
734  /// Return the number of symbols in this section.
735  SymbolSet::size_type symbols_size() const { return Symbols.size(); }
736 
737 private:
738  void addSymbol(Symbol &Sym) {
739  assert(!Symbols.count(&Sym) && "Symbol is already in this section");
740  Symbols.insert(&Sym);
741  }
742 
743  void removeSymbol(Symbol &Sym) {
744  assert(Symbols.count(&Sym) && "symbol is not in this section");
745  Symbols.erase(&Sym);
746  }
747 
748  void addBlock(Block &B) {
749  assert(!Blocks.count(&B) && "Block is already in this section");
750  Blocks.insert(&B);
751  }
752 
753  void removeBlock(Block &B) {
754  assert(Blocks.count(&B) && "Block is not in this section");
755  Blocks.erase(&B);
756  }
757 
758  void transferContentTo(Section &DstSection) {
759  if (&DstSection == this)
760  return;
761  for (auto *S : Symbols)
762  DstSection.addSymbol(*S);
763  for (auto *B : Blocks)
764  DstSection.addBlock(*B);
765  Symbols.clear();
766  Blocks.clear();
767  }
768 
769  StringRef Name;
770  orc::MemProt Prot;
772  SectionOrdinal SecOrdinal = 0;
773  BlockSet Blocks;
774  SymbolSet Symbols;
775 };
776 
777 /// Represents a section address range via a pair of Block pointers
778 /// to the first and last Blocks in the section.
780 public:
781  SectionRange() = default;
782  SectionRange(const Section &Sec) {
783  if (Sec.blocks().empty())
784  return;
785  First = Last = *Sec.blocks().begin();
786  for (auto *B : Sec.blocks()) {
787  if (B->getAddress() < First->getAddress())
788  First = B;
789  if (B->getAddress() > Last->getAddress())
790  Last = B;
791  }
792  }
793  Block *getFirstBlock() const {
794  assert((!Last || First) && "First can not be null if end is non-null");
795  return First;
796  }
797  Block *getLastBlock() const {
798  assert((First || !Last) && "Last can not be null if start is non-null");
799  return Last;
800  }
801  bool empty() const {
802  assert((First || !Last) && "Last can not be null if start is non-null");
803  return !First;
804  }
806  return First ? First->getAddress() : orc::ExecutorAddr();
807  }
809  return Last ? Last->getAddress() + Last->getSize() : orc::ExecutorAddr();
810  }
811  orc::ExecutorAddrDiff getSize() const { return getEnd() - getStart(); }
812 
815  }
816 
817 private:
818  Block *First = nullptr;
819  Block *Last = nullptr;
820 };
821 
822 class LinkGraph {
823 private:
824  using SectionList = std::vector<std::unique_ptr<Section>>;
826  using BlockSet = DenseSet<Block *>;
827 
828  template <typename... ArgTs>
829  Addressable &createAddressable(ArgTs &&... Args) {
830  Addressable *A =
831  reinterpret_cast<Addressable *>(Allocator.Allocate<Addressable>());
832  new (A) Addressable(std::forward<ArgTs>(Args)...);
833  return *A;
834  }
835 
836  void destroyAddressable(Addressable &A) {
837  A.~Addressable();
838  Allocator.Deallocate(&A);
839  }
840 
841  template <typename... ArgTs> Block &createBlock(ArgTs &&... Args) {
842  Block *B = reinterpret_cast<Block *>(Allocator.Allocate<Block>());
843  new (B) Block(std::forward<ArgTs>(Args)...);
844  B->getSection().addBlock(*B);
845  return *B;
846  }
847 
848  void destroyBlock(Block &B) {
849  B.~Block();
850  Allocator.Deallocate(&B);
851  }
852 
853  void destroySymbol(Symbol &S) {
854  S.~Symbol();
855  Allocator.Deallocate(&S);
856  }
857 
858  static iterator_range<Section::block_iterator> getSectionBlocks(Section &S) {
859  return S.blocks();
860  }
861 
863  getSectionConstBlocks(Section &S) {
864  return S.blocks();
865  }
866 
868  getSectionSymbols(Section &S) {
869  return S.symbols();
870  }
871 
873  getSectionConstSymbols(Section &S) {
874  return S.symbols();
875  }
876 
877 public:
879 
882 
883  template <typename OuterItrT, typename InnerItrT, typename T,
884  iterator_range<InnerItrT> getInnerRange(
885  typename OuterItrT::reference)>
887  : public iterator_facade_base<
888  nested_collection_iterator<OuterItrT, InnerItrT, T, getInnerRange>,
889  std::forward_iterator_tag, T> {
890  public:
891  nested_collection_iterator() = default;
892 
893  nested_collection_iterator(OuterItrT OuterI, OuterItrT OuterE)
894  : OuterI(OuterI), OuterE(OuterE),
895  InnerI(getInnerBegin(OuterI, OuterE)) {
896  moveToNonEmptyInnerOrEnd();
897  }
898 
900  return (OuterI == RHS.OuterI) && (InnerI == RHS.InnerI);
901  }
902 
903  T operator*() const {
904  assert(InnerI != getInnerRange(*OuterI).end() && "Dereferencing end?");
905  return *InnerI;
906  }
907 
909  ++InnerI;
910  moveToNonEmptyInnerOrEnd();
911  return *this;
912  }
913 
914  private:
915  static InnerItrT getInnerBegin(OuterItrT OuterI, OuterItrT OuterE) {
916  return OuterI != OuterE ? getInnerRange(*OuterI).begin() : InnerItrT();
917  }
918 
919  void moveToNonEmptyInnerOrEnd() {
920  while (OuterI != OuterE && InnerI == getInnerRange(*OuterI).end()) {
921  ++OuterI;
922  InnerI = getInnerBegin(OuterI, OuterE);
923  }
924  }
925 
926  OuterItrT OuterI, OuterE;
927  InnerItrT InnerI;
928  };
929 
931  nested_collection_iterator<const_section_iterator,
933  getSectionSymbols>;
934 
938  getSectionConstSymbols>;
939 
942  Block *, getSectionBlocks>;
943 
944  using const_block_iterator =
947  getSectionConstBlocks>;
948 
949  using GetEdgeKindNameFunction = const char *(*)(Edge::Kind);
950 
951  LinkGraph(std::string Name, const Triple &TT, unsigned PointerSize,
952  support::endianness Endianness,
953  GetEdgeKindNameFunction GetEdgeKindName)
954  : Name(std::move(Name)), TT(TT), PointerSize(PointerSize),
955  Endianness(Endianness), GetEdgeKindName(std::move(GetEdgeKindName)) {}
956 
957  LinkGraph(const LinkGraph &) = delete;
958  LinkGraph &operator=(const LinkGraph &) = delete;
959  LinkGraph(LinkGraph &&) = delete;
960  LinkGraph &operator=(LinkGraph &&) = delete;
961 
962  /// Returns the name of this graph (usually the name of the original
963  /// underlying MemoryBuffer).
964  const std::string &getName() const { return Name; }
965 
966  /// Returns the target triple for this Graph.
967  const Triple &getTargetTriple() const { return TT; }
968 
969  /// Returns the pointer size for use in this graph.
970  unsigned getPointerSize() const { return PointerSize; }
971 
972  /// Returns the endianness of content in this graph.
973  support::endianness getEndianness() const { return Endianness; }
974 
975  const char *getEdgeKindName(Edge::Kind K) const { return GetEdgeKindName(K); }
976 
977  /// Allocate a mutable buffer of the given size using the LinkGraph's
978  /// allocator.
980  return {Allocator.Allocate<char>(Size), Size};
981  }
982 
983  /// Allocate a copy of the given string using the LinkGraph's allocator.
984  /// This can be useful when renaming symbols or adding new content to the
985  /// graph.
987  auto *AllocatedBuffer = Allocator.Allocate<char>(Source.size());
988  llvm::copy(Source, AllocatedBuffer);
989  return MutableArrayRef<char>(AllocatedBuffer, Source.size());
990  }
991 
992  /// Allocate a copy of the given string using the LinkGraph's allocator.
993  /// This can be useful when renaming symbols or adding new content to the
994  /// graph.
995  ///
996  /// Note: This Twine-based overload requires an extra string copy and an
997  /// extra heap allocation for large strings. The ArrayRef<char> overload
998  /// should be preferred where possible.
1000  SmallString<256> TmpBuffer;
1001  auto SourceStr = Source.toStringRef(TmpBuffer);
1002  auto *AllocatedBuffer = Allocator.Allocate<char>(SourceStr.size());
1003  llvm::copy(SourceStr, AllocatedBuffer);
1004  return MutableArrayRef<char>(AllocatedBuffer, SourceStr.size());
1005  }
1006 
1007  /// Create a section with the given name, protection flags, and alignment.
1009  assert(llvm::none_of(Sections,
1010  [&](std::unique_ptr<Section> &Sec) {
1011  return Sec->getName() == Name;
1012  }) &&
1013  "Duplicate section name");
1014  std::unique_ptr<Section> Sec(new Section(Name, Prot, Sections.size()));
1015  Sections.push_back(std::move(Sec));
1016  return *Sections.back();
1017  }
1018 
1019  /// Create a content block.
1021  orc::ExecutorAddr Address, uint64_t Alignment,
1022  uint64_t AlignmentOffset) {
1023  return createBlock(Parent, Content, Address, Alignment, AlignmentOffset);
1024  }
1025 
1026  /// Create a content block with initially mutable data.
1028  MutableArrayRef<char> MutableContent,
1029  orc::ExecutorAddr Address,
1030  uint64_t Alignment,
1031  uint64_t AlignmentOffset) {
1032  return createBlock(Parent, MutableContent, Address, Alignment,
1033  AlignmentOffset);
1034  }
1035 
1036  /// Create a content block with initially mutable data of the given size.
1037  /// Content will be allocated via the LinkGraph's allocateBuffer method.
1038  /// By default the memory will be zero-initialized. Passing false for
1039  /// ZeroInitialize will prevent this.
1040  Block &createMutableContentBlock(Section &Parent, size_t ContentSize,
1041  orc::ExecutorAddr Address,
1042  uint64_t Alignment, uint64_t AlignmentOffset,
1043  bool ZeroInitialize = true) {
1044  auto Content = allocateContent(ContentSize);
1045  if (ZeroInitialize)
1046  memset(Content.data(), 0, Content.size());
1047  return createBlock(Parent, Content, Address, Alignment, AlignmentOffset);
1048  }
1049 
1050  /// Create a zero-fill block.
1052  orc::ExecutorAddr Address, uint64_t Alignment,
1053  uint64_t AlignmentOffset) {
1054  return createBlock(Parent, Size, Address, Alignment, AlignmentOffset);
1055  }
1056 
1057  /// Returns a BinaryStreamReader for the given block.
1060  reinterpret_cast<const uint8_t *>(B.getContent().data()), B.getSize());
1061  return BinaryStreamReader(C, getEndianness());
1062  }
1063 
1064  /// Returns a BinaryStreamWriter for the given block.
1065  /// This will call getMutableContent to obtain mutable content for the block.
1068  reinterpret_cast<uint8_t *>(B.getMutableContent(*this).data()),
1069  B.getSize());
1070  return BinaryStreamWriter(C, getEndianness());
1071  }
1072 
1073  /// Cache type for the splitBlock function.
1075 
1076  /// Splits block B at the given index which must be greater than zero.
1077  /// If SplitIndex == B.getSize() then this function is a no-op and returns B.
1078  /// If SplitIndex < B.getSize() then this function returns a new block
1079  /// covering the range [ 0, SplitIndex ), and B is modified to cover the range
1080  /// [ SplitIndex, B.size() ).
1081  ///
1082  /// The optional Cache parameter can be used to speed up repeated calls to
1083  /// splitBlock for a single block. If the value is None the cache will be
1084  /// treated as uninitialized and splitBlock will populate it. Otherwise it
1085  /// is assumed to contain the list of Symbols pointing at B, sorted in
1086  /// descending order of offset.
1087  ///
1088  /// Notes:
1089  ///
1090  /// 1. splitBlock must be used with care. Splitting a block may cause
1091  /// incoming edges to become invalid if the edge target subexpression
1092  /// points outside the bounds of the newly split target block (E.g. an
1093  /// edge 'S + 10 : Pointer64' where S points to a newly split block
1094  /// whose size is less than 10). No attempt is made to detect invalidation
1095  /// of incoming edges, as in general this requires context that the
1096  /// LinkGraph does not have. Clients are responsible for ensuring that
1097  /// splitBlock is not used in a way that invalidates edges.
1098  ///
1099  /// 2. The newly introduced block will have a new ordinal which will be
1100  /// higher than any other ordinals in the section. Clients are responsible
1101  /// for re-assigning block ordinals to restore a compatible order if
1102  /// needed.
1103  ///
1104  /// 3. The cache is not automatically updated if new symbols are introduced
1105  /// between calls to splitBlock. Any newly introduced symbols may be
1106  /// added to the cache manually (descending offset order must be
1107  /// preserved), or the cache can be set to None and rebuilt by
1108  /// splitBlock on the next call.
1109  Block &splitBlock(Block &B, size_t SplitIndex,
1110  SplitBlockCache *Cache = nullptr);
1111 
1112  /// Add an external symbol.
1113  /// Some formats (e.g. ELF) allow Symbols to have sizes. For Symbols whose
1114  /// size is not known, you should substitute '0'.
1115  /// The IsWeaklyReferenced argument determines whether the symbol must be
1116  /// present during lookup: Externals that are strongly referenced must be
1117  /// found or an error will be emitted. Externals that are weakly referenced
1118  /// are permitted to be undefined, in which case they are assigned an address
1119  /// of 0.
1121  bool IsWeaklyReferenced) {
1122  assert(llvm::count_if(ExternalSymbols,
1123  [&](const Symbol *Sym) {
1124  return Sym->getName() == Name;
1125  }) == 0 &&
1126  "Duplicate external symbol");
1127  auto &Sym = Symbol::constructExternal(
1128  Allocator, createAddressable(orc::ExecutorAddr(), false), Name, Size,
1129  Linkage::Strong, IsWeaklyReferenced);
1130  ExternalSymbols.insert(&Sym);
1131  return Sym;
1132  }
1133 
1134  /// Add an absolute symbol.
1137  bool IsLive) {
1138  assert((S == Scope::Local || llvm::count_if(AbsoluteSymbols,
1139  [&](const Symbol *Sym) {
1140  return Sym->getName() == Name;
1141  }) == 0) &&
1142  "Duplicate absolute symbol");
1143  auto &Sym = Symbol::constructAbsolute(Allocator, createAddressable(Address),
1144  Name, Size, L, S, IsLive);
1145  AbsoluteSymbols.insert(&Sym);
1146  return Sym;
1147  }
1148 
1149  /// Add an anonymous symbol.
1151  orc::ExecutorAddrDiff Size, bool IsCallable,
1152  bool IsLive) {
1153  auto &Sym = Symbol::constructAnonDef(Allocator, Content, Offset, Size,
1154  IsCallable, IsLive);
1155  Content.getSection().addSymbol(Sym);
1156  return Sym;
1157  }
1158 
1159  /// Add a named symbol.
1161  StringRef Name, orc::ExecutorAddrDiff Size,
1162  Linkage L, Scope S, bool IsCallable, bool IsLive) {
1164  [&](const Symbol *Sym) {
1165  return Sym->getName() == Name;
1166  }) == 0) &&
1167  "Duplicate defined symbol");
1168  auto &Sym = Symbol::constructNamedDef(Allocator, Content, Offset, Name,
1169  Size, L, S, IsLive, IsCallable);
1170  Content.getSection().addSymbol(Sym);
1171  return Sym;
1172  }
1173 
1175  return make_range(section_iterator(Sections.begin()),
1176  section_iterator(Sections.end()));
1177  }
1178 
1179  SectionList::size_type sections_size() const { return Sections.size(); }
1180 
1181  /// Returns the section with the given name if it exists, otherwise returns
1182  /// null.
1184  for (auto &S : sections())
1185  if (S.getName() == Name)
1186  return &S;
1187  return nullptr;
1188  }
1189 
1191  return make_range(block_iterator(Sections.begin(), Sections.end()),
1192  block_iterator(Sections.end(), Sections.end()));
1193  }
1194 
1196  return make_range(const_block_iterator(Sections.begin(), Sections.end()),
1197  const_block_iterator(Sections.end(), Sections.end()));
1198  }
1199 
1201  return make_range(ExternalSymbols.begin(), ExternalSymbols.end());
1202  }
1203 
1205  return make_range(AbsoluteSymbols.begin(), AbsoluteSymbols.end());
1206  }
1207 
1209  return make_range(defined_symbol_iterator(Sections.begin(), Sections.end()),
1210  defined_symbol_iterator(Sections.end(), Sections.end()));
1211  }
1212 
1214  return make_range(
1215  const_defined_symbol_iterator(Sections.begin(), Sections.end()),
1216  const_defined_symbol_iterator(Sections.end(), Sections.end()));
1217  }
1218 
1219  /// Make the given symbol external (must not already be external).
1220  ///
1221  /// Symbol size, linkage and callability will be left unchanged. Symbol scope
1222  /// will be set to Default, and offset will be reset to 0.
1223  void makeExternal(Symbol &Sym) {
1224  assert(!Sym.isExternal() && "Symbol is already external");
1225  if (Sym.isAbsolute()) {
1226  assert(AbsoluteSymbols.count(&Sym) &&
1227  "Sym is not in the absolute symbols set");
1228  assert(Sym.getOffset() == 0 && "Absolute not at offset 0");
1229  AbsoluteSymbols.erase(&Sym);
1230  auto &A = Sym.getAddressable();
1231  A.setAbsolute(false);
1232  A.setAddress(orc::ExecutorAddr());
1233  } else {
1234  assert(Sym.isDefined() && "Sym is not a defined symbol");
1235  Section &Sec = Sym.getBlock().getSection();
1236  Sec.removeSymbol(Sym);
1237  Sym.makeExternal(createAddressable(orc::ExecutorAddr(), false));
1238  }
1239  ExternalSymbols.insert(&Sym);
1240  }
1241 
1242  /// Make the given symbol an absolute with the given address (must not already
1243  /// be absolute).
1244  ///
1245  /// The symbol's size, linkage, and callability, and liveness will be left
1246  /// unchanged, and its offset will be reset to 0.
1247  ///
1248  /// If the symbol was external then its scope will be set to local, otherwise
1249  /// it will be left unchanged.
1250  void makeAbsolute(Symbol &Sym, orc::ExecutorAddr Address) {
1251  assert(!Sym.isAbsolute() && "Symbol is already absolute");
1252  if (Sym.isExternal()) {
1253  assert(ExternalSymbols.count(&Sym) &&
1254  "Sym is not in the absolute symbols set");
1255  assert(Sym.getOffset() == 0 && "External is not at offset 0");
1256  ExternalSymbols.erase(&Sym);
1257  auto &A = Sym.getAddressable();
1258  A.setAbsolute(true);
1259  A.setAddress(Address);
1260  Sym.setScope(Scope::Local);
1261  } else {
1262  assert(Sym.isDefined() && "Sym is not a defined symbol");
1263  Section &Sec = Sym.getBlock().getSection();
1264  Sec.removeSymbol(Sym);
1265  Sym.makeAbsolute(createAddressable(Address));
1266  }
1267  AbsoluteSymbols.insert(&Sym);
1268  }
1269 
1270  /// Turn an absolute or external symbol into a defined one by attaching it to
1271  /// a block. Symbol must not already be defined.
1274  bool IsLive) {
1275  assert(!Sym.isDefined() && "Sym is already a defined symbol");
1276  if (Sym.isAbsolute()) {
1277  assert(AbsoluteSymbols.count(&Sym) &&
1278  "Symbol is not in the absolutes set");
1279  AbsoluteSymbols.erase(&Sym);
1280  } else {
1281  assert(ExternalSymbols.count(&Sym) &&
1282  "Symbol is not in the externals set");
1283  ExternalSymbols.erase(&Sym);
1284  }
1285  Addressable &OldBase = *Sym.Base;
1286  Sym.setBlock(Content);
1287  Sym.setOffset(Offset);
1288  Sym.setSize(Size);
1289  Sym.setLinkage(L);
1290  Sym.setScope(S);
1291  Sym.setLive(IsLive);
1292  Content.getSection().addSymbol(Sym);
1293  destroyAddressable(OldBase);
1294  }
1295 
1296  /// Transfer a defined symbol from one block to another.
1297  ///
1298  /// The symbol's offset within DestBlock is set to NewOffset.
1299  ///
1300  /// If ExplicitNewSize is given as None then the size of the symbol will be
1301  /// checked and auto-truncated to at most the size of the remainder (from the
1302  /// given offset) of the size of the new block.
1303  ///
1304  /// All other symbol attributes are unchanged.
1305  void transferDefinedSymbol(Symbol &Sym, Block &DestBlock,
1306  orc::ExecutorAddrDiff NewOffset,
1307  Optional<orc::ExecutorAddrDiff> ExplicitNewSize) {
1308  auto &OldSection = Sym.getBlock().getSection();
1309  Sym.setBlock(DestBlock);
1310  Sym.setOffset(NewOffset);
1311  if (ExplicitNewSize)
1312  Sym.setSize(*ExplicitNewSize);
1313  else {
1314  auto RemainingBlockSize = DestBlock.getSize() - NewOffset;
1315  if (Sym.getSize() > RemainingBlockSize)
1316  Sym.setSize(RemainingBlockSize);
1317  }
1318  if (&DestBlock.getSection() != &OldSection) {
1319  OldSection.removeSymbol(Sym);
1320  DestBlock.getSection().addSymbol(Sym);
1321  }
1322  }
1323 
1324  /// Transfers the given Block and all Symbols pointing to it to the given
1325  /// Section.
1326  ///
1327  /// No attempt is made to check compatibility of the source and destination
1328  /// sections. Blocks may be moved between sections with incompatible
1329  /// permissions (e.g. from data to text). The client is responsible for
1330  /// ensuring that this is safe.
1331  void transferBlock(Block &B, Section &NewSection) {
1332  auto &OldSection = B.getSection();
1333  if (&OldSection == &NewSection)
1334  return;
1335  SmallVector<Symbol *> AttachedSymbols;
1336  for (auto *S : OldSection.symbols())
1337  if (&S->getBlock() == &B)
1338  AttachedSymbols.push_back(S);
1339  for (auto *S : AttachedSymbols) {
1340  OldSection.removeSymbol(*S);
1341  NewSection.addSymbol(*S);
1342  }
1343  OldSection.removeBlock(B);
1344  NewSection.addBlock(B);
1345  }
1346 
1347  /// Move all blocks and symbols from the source section to the destination
1348  /// section.
1349  ///
1350  /// If PreserveSrcSection is true (or SrcSection and DstSection are the same)
1351  /// then SrcSection is preserved, otherwise it is removed (the default).
1352  void mergeSections(Section &DstSection, Section &SrcSection,
1353  bool PreserveSrcSection = false) {
1354  if (&DstSection == &SrcSection)
1355  return;
1356  for (auto *B : SrcSection.blocks())
1357  B->setSection(DstSection);
1358  SrcSection.transferContentTo(DstSection);
1359  if (!PreserveSrcSection)
1360  removeSection(SrcSection);
1361  }
1362 
1363  /// Removes an external symbol. Also removes the underlying Addressable.
1365  assert(!Sym.isDefined() && !Sym.isAbsolute() &&
1366  "Sym is not an external symbol");
1367  assert(ExternalSymbols.count(&Sym) && "Symbol is not in the externals set");
1368  ExternalSymbols.erase(&Sym);
1369  Addressable &Base = *Sym.Base;
1370  assert(llvm::none_of(ExternalSymbols,
1371  [&](Symbol *AS) { return AS->Base == &Base; }) &&
1372  "Base addressable still in use");
1373  destroySymbol(Sym);
1374  destroyAddressable(Base);
1375  }
1376 
1377  /// Remove an absolute symbol. Also removes the underlying Addressable.
1379  assert(!Sym.isDefined() && Sym.isAbsolute() &&
1380  "Sym is not an absolute symbol");
1381  assert(AbsoluteSymbols.count(&Sym) &&
1382  "Symbol is not in the absolute symbols set");
1383  AbsoluteSymbols.erase(&Sym);
1384  Addressable &Base = *Sym.Base;
1385  assert(llvm::none_of(ExternalSymbols,
1386  [&](Symbol *AS) { return AS->Base == &Base; }) &&
1387  "Base addressable still in use");
1388  destroySymbol(Sym);
1389  destroyAddressable(Base);
1390  }
1391 
1392  /// Removes defined symbols. Does not remove the underlying block.
1394  assert(Sym.isDefined() && "Sym is not a defined symbol");
1395  Sym.getBlock().getSection().removeSymbol(Sym);
1396  destroySymbol(Sym);
1397  }
1398 
1399  /// Remove a block. The block reference is defunct after calling this
1400  /// function and should no longer be used.
1402  assert(llvm::none_of(B.getSection().symbols(),
1403  [&](const Symbol *Sym) {
1404  return &Sym->getBlock() == &B;
1405  }) &&
1406  "Block still has symbols attached");
1407  B.getSection().removeBlock(B);
1408  destroyBlock(B);
1409  }
1410 
1411  /// Remove a section. The section reference is defunct after calling this
1412  /// function and should no longer be used.
1413  void removeSection(Section &Sec) {
1414  auto I = llvm::find_if(Sections, [&Sec](const std::unique_ptr<Section> &S) {
1415  return S.get() == &Sec;
1416  });
1417  assert(I != Sections.end() && "Section does not appear in this graph");
1418  Sections.erase(I);
1419  }
1420 
1421  /// Accessor for the AllocActions object for this graph. This can be used to
1422  /// register allocation action calls prior to finalization.
1423  ///
1424  /// Accessing this object after finalization will result in undefined
1425  /// behavior.
1427 
1428  /// Dump the graph.
1429  void dump(raw_ostream &OS);
1430 
1431 private:
1432  // Put the BumpPtrAllocator first so that we don't free any of the underlying
1433  // memory until the Symbol/Addressable destructors have been run.
1435 
1436  std::string Name;
1437  Triple TT;
1438  unsigned PointerSize;
1439  support::endianness Endianness;
1440  GetEdgeKindNameFunction GetEdgeKindName = nullptr;
1441  SectionList Sections;
1442  ExternalSymbolSet ExternalSymbols;
1443  ExternalSymbolSet AbsoluteSymbols;
1445 };
1446 
1448  if (!ContentMutable)
1449  setMutableContent(G.allocateContent({Data, Size}));
1450  return MutableArrayRef<char>(const_cast<char *>(Data), Size);
1451 }
1452 
1453 /// Enables easy lookup of blocks by addresses.
1455 public:
1456  using AddrToBlockMap = std::map<orc::ExecutorAddr, Block *>;
1457  using const_iterator = AddrToBlockMap::const_iterator;
1458 
1459  /// A block predicate that always adds all blocks.
1460  static bool includeAllBlocks(const Block &B) { return true; }
1461 
1462  /// A block predicate that always includes blocks with non-null addresses.
1463  static bool includeNonNull(const Block &B) { return !!B.getAddress(); }
1464 
1465  BlockAddressMap() = default;
1466 
1467  /// Add a block to the map. Returns an error if the block overlaps with any
1468  /// existing block.
1469  template <typename PredFn = decltype(includeAllBlocks)>
1471  if (!Pred(B))
1472  return Error::success();
1473 
1474  auto I = AddrToBlock.upper_bound(B.getAddress());
1475 
1476  // If we're not at the end of the map, check for overlap with the next
1477  // element.
1478  if (I != AddrToBlock.end()) {
1479  if (B.getAddress() + B.getSize() > I->second->getAddress())
1480  return overlapError(B, *I->second);
1481  }
1482 
1483  // If we're not at the start of the map, check for overlap with the previous
1484  // element.
1485  if (I != AddrToBlock.begin()) {
1486  auto &PrevBlock = *std::prev(I)->second;
1487  if (PrevBlock.getAddress() + PrevBlock.getSize() > B.getAddress())
1488  return overlapError(B, PrevBlock);
1489  }
1490 
1491  AddrToBlock.insert(I, std::make_pair(B.getAddress(), &B));
1492  return Error::success();
1493  }
1494 
1495  /// Add a block to the map without checking for overlap with existing blocks.
1496  /// The client is responsible for ensuring that the block added does not
1497  /// overlap with any existing block.
1498  void addBlockWithoutChecking(Block &B) { AddrToBlock[B.getAddress()] = &B; }
1499 
1500  /// Add a range of blocks to the map. Returns an error if any block in the
1501  /// range overlaps with any other block in the range, or with any existing
1502  /// block in the map.
1503  template <typename BlockPtrRange,
1504  typename PredFn = decltype(includeAllBlocks)>
1505  Error addBlocks(BlockPtrRange &&Blocks, PredFn Pred = includeAllBlocks) {
1506  for (auto *B : Blocks)
1507  if (auto Err = addBlock(*B, Pred))
1508  return Err;
1509  return Error::success();
1510  }
1511 
1512  /// Add a range of blocks to the map without checking for overlap with
1513  /// existing blocks. The client is responsible for ensuring that the block
1514  /// added does not overlap with any existing block.
1515  template <typename BlockPtrRange>
1516  void addBlocksWithoutChecking(BlockPtrRange &&Blocks) {
1517  for (auto *B : Blocks)
1519  }
1520 
1521  /// Iterates over (Address, Block*) pairs in ascending order of address.
1522  const_iterator begin() const { return AddrToBlock.begin(); }
1523  const_iterator end() const { return AddrToBlock.end(); }
1524 
1525  /// Returns the block starting at the given address, or nullptr if no such
1526  /// block exists.
1528  auto I = AddrToBlock.find(Addr);
1529  if (I == AddrToBlock.end())
1530  return nullptr;
1531  return I->second;
1532  }
1533 
1534  /// Returns the block covering the given address, or nullptr if no such block
1535  /// exists.
1537  auto I = AddrToBlock.upper_bound(Addr);
1538  if (I == AddrToBlock.begin())
1539  return nullptr;
1540  auto *B = std::prev(I)->second;
1541  if (Addr < B->getAddress() + B->getSize())
1542  return B;
1543  return nullptr;
1544  }
1545 
1546 private:
1547  Error overlapError(Block &NewBlock, Block &ExistingBlock) {
1548  auto NewBlockEnd = NewBlock.getAddress() + NewBlock.getSize();
1549  auto ExistingBlockEnd =
1550  ExistingBlock.getAddress() + ExistingBlock.getSize();
1551  return make_error<JITLinkError>(
1552  "Block at " +
1553  formatv("{0:x16} -- {1:x16}", NewBlock.getAddress().getValue(),
1554  NewBlockEnd.getValue()) +
1555  " overlaps " +
1556  formatv("{0:x16} -- {1:x16}", ExistingBlock.getAddress().getValue(),
1557  ExistingBlockEnd.getValue()));
1558  }
1559 
1560  AddrToBlockMap AddrToBlock;
1561 };
1562 
1563 /// A map of addresses to Symbols.
1565 public:
1567 
1568  /// Add a symbol to the SymbolAddressMap.
1569  void addSymbol(Symbol &Sym) {
1570  AddrToSymbols[Sym.getAddress()].push_back(&Sym);
1571  }
1572 
1573  /// Add all symbols in a given range to the SymbolAddressMap.
1574  template <typename SymbolPtrCollection>
1575  void addSymbols(SymbolPtrCollection &&Symbols) {
1576  for (auto *Sym : Symbols)
1577  addSymbol(*Sym);
1578  }
1579 
1580  /// Returns the list of symbols that start at the given address, or nullptr if
1581  /// no such symbols exist.
1583  auto I = AddrToSymbols.find(Addr);
1584  if (I == AddrToSymbols.end())
1585  return nullptr;
1586  return &I->second;
1587  }
1588 
1589 private:
1590  std::map<orc::ExecutorAddr, SymbolVector> AddrToSymbols;
1591 };
1592 
1593 /// A function for mutating LinkGraphs.
1595 
1596 /// A list of LinkGraph passes.
1597 using LinkGraphPassList = std::vector<LinkGraphPassFunction>;
1598 
1599 /// An LinkGraph pass configuration, consisting of a list of pre-prune,
1600 /// post-prune, and post-fixup passes.
1602 
1603  /// Pre-prune passes.
1604  ///
1605  /// These passes are called on the graph after it is built, and before any
1606  /// symbols have been pruned. Graph nodes still have their original vmaddrs.
1607  ///
1608  /// Notable use cases: Marking symbols live or should-discard.
1610 
1611  /// Post-prune passes.
1612  ///
1613  /// These passes are called on the graph after dead stripping, but before
1614  /// memory is allocated or nodes assigned their final addresses.
1615  ///
1616  /// Notable use cases: Building GOT, stub, and TLV symbols.
1618 
1619  /// Post-allocation passes.
1620  ///
1621  /// These passes are called on the graph after memory has been allocated and
1622  /// defined nodes have been assigned their final addresses, but before the
1623  /// context has been notified of these addresses. At this point externals
1624  /// have not been resolved, and symbol content has not yet been copied into
1625  /// working memory.
1626  ///
1627  /// Notable use cases: Setting up data structures associated with addresses
1628  /// of defined symbols (e.g. a mapping of __dso_handle to JITDylib* for the
1629  /// JIT runtime) -- using a PostAllocationPass for this ensures that the
1630  /// data structures are in-place before any query for resolved symbols
1631  /// can complete.
1633 
1634  /// Pre-fixup passes.
1635  ///
1636  /// These passes are called on the graph after memory has been allocated,
1637  /// content copied into working memory, and all nodes (including externals)
1638  /// have been assigned their final addresses, but before any fixups have been
1639  /// applied.
1640  ///
1641  /// Notable use cases: Late link-time optimizations like GOT and stub
1642  /// elimination.
1644 
1645  /// Post-fixup passes.
1646  ///
1647  /// These passes are called on the graph after block contents has been copied
1648  /// to working memory, and fixups applied. Blocks have been updated to point
1649  /// to their fixed up content.
1650  ///
1651  /// Notable use cases: Testing and validation.
1653 };
1654 
1655 /// Flags for symbol lookup.
1656 ///
1657 /// FIXME: These basically duplicate orc::SymbolLookupFlags -- We should merge
1658 /// the two types once we have an OrcSupport library.
1660 
1662 
1663 /// A map of symbol names to resolved addresses.
1665 
1666 /// A function object to call with a resolved symbol map (See AsyncLookupResult)
1667 /// or an error if resolution failed.
1669 public:
1670  virtual ~JITLinkAsyncLookupContinuation() = default;
1671  virtual void run(Expected<AsyncLookupResult> LR) = 0;
1672 
1673 private:
1674  virtual void anchor();
1675 };
1676 
1677 /// Create a lookup continuation from a function object.
1678 template <typename Continuation>
1679 std::unique_ptr<JITLinkAsyncLookupContinuation>
1680 createLookupContinuation(Continuation Cont) {
1681 
1682  class Impl final : public JITLinkAsyncLookupContinuation {
1683  public:
1684  Impl(Continuation C) : C(std::move(C)) {}
1685  void run(Expected<AsyncLookupResult> LR) override { C(std::move(LR)); }
1686 
1687  private:
1688  Continuation C;
1689  };
1690 
1691  return std::make_unique<Impl>(std::move(Cont));
1692 }
1693 
1694 /// Holds context for a single jitLink invocation.
1696 public:
1698 
1699  /// Create a JITLinkContext.
1700  JITLinkContext(const JITLinkDylib *JD) : JD(JD) {}
1701 
1702  /// Destroy a JITLinkContext.
1703  virtual ~JITLinkContext();
1704 
1705  /// Return the JITLinkDylib that this link is targeting, if any.
1706  const JITLinkDylib *getJITLinkDylib() const { return JD; }
1707 
1708  /// Return the MemoryManager to be used for this link.
1709  virtual JITLinkMemoryManager &getMemoryManager() = 0;
1710 
1711  /// Notify this context that linking failed.
1712  /// Called by JITLink if linking cannot be completed.
1713  virtual void notifyFailed(Error Err) = 0;
1714 
1715  /// Called by JITLink to resolve external symbols. This method is passed a
1716  /// lookup continutation which it must call with a result to continue the
1717  /// linking process.
1718  virtual void lookup(const LookupMap &Symbols,
1719  std::unique_ptr<JITLinkAsyncLookupContinuation> LC) = 0;
1720 
1721  /// Called by JITLink once all defined symbols in the graph have been assigned
1722  /// their final memory locations in the target process. At this point the
1723  /// LinkGraph can be inspected to build a symbol table, however the block
1724  /// content will not generally have been copied to the target location yet.
1725  ///
1726  /// If the client detects an error in the LinkGraph state (e.g. unexpected or
1727  /// missing symbols) they may return an error here. The error will be
1728  /// propagated to notifyFailed and the linker will bail out.
1729  virtual Error notifyResolved(LinkGraph &G) = 0;
1730 
1731  /// Called by JITLink to notify the context that the object has been
1732  /// finalized (i.e. emitted to memory and memory permissions set). If all of
1733  /// this objects dependencies have also been finalized then the code is ready
1734  /// to run.
1735  virtual void notifyFinalized(JITLinkMemoryManager::FinalizedAlloc Alloc) = 0;
1736 
1737  /// Called by JITLink prior to linking to determine whether default passes for
1738  /// the target should be added. The default implementation returns true.
1739  /// If subclasses override this method to return false for any target then
1740  /// they are required to fully configure the pass pipeline for that target.
1741  virtual bool shouldAddDefaultTargetPasses(const Triple &TT) const;
1742 
1743  /// Returns the mark-live pass to be used for this link. If no pass is
1744  /// returned (the default) then the target-specific linker implementation will
1745  /// choose a conservative default (usually marking all symbols live).
1746  /// This function is only called if shouldAddDefaultTargetPasses returns true,
1747  /// otherwise the JITContext is responsible for adding a mark-live pass in
1748  /// modifyPassConfig.
1749  virtual LinkGraphPassFunction getMarkLivePass(const Triple &TT) const;
1750 
1751  /// Called by JITLink to modify the pass pipeline prior to linking.
1752  /// The default version performs no modification.
1753  virtual Error modifyPassConfig(LinkGraph &G, PassConfiguration &Config);
1754 
1755 private:
1756  const JITLinkDylib *JD = nullptr;
1757 };
1758 
1759 /// Marks all symbols in a graph live. This can be used as a default,
1760 /// conservative mark-live implementation.
1761 Error markAllSymbolsLive(LinkGraph &G);
1762 
1763 /// Create an out of range error for the given edge in the given block.
1764 Error makeTargetOutOfRangeError(const LinkGraph &G, const Block &B,
1765  const Edge &E);
1766 
1768  const Edge &E);
1769 
1770 /// Base case for edge-visitors where the visitor-list is empty.
1771 inline void visitEdge(LinkGraph &G, Block *B, Edge &E) {}
1772 
1773 /// Applies the first visitor in the list to the given edge. If the visitor's
1774 /// visitEdge method returns true then we return immediately, otherwise we
1775 /// apply the next visitor.
1776 template <typename VisitorT, typename... VisitorTs>
1777 void visitEdge(LinkGraph &G, Block *B, Edge &E, VisitorT &&V,
1778  VisitorTs &&...Vs) {
1779  if (!V.visitEdge(G, B, E))
1780  visitEdge(G, B, E, std::forward<VisitorTs>(Vs)...);
1781 }
1782 
1783 /// For each edge in the given graph, apply a list of visitors to the edge,
1784 /// stopping when the first visitor's visitEdge method returns true.
1785 ///
1786 /// Only visits edges that were in the graph at call time: if any visitor
1787 /// adds new edges those will not be visited. Visitors are not allowed to
1788 /// remove edges (though they can change their kind, target, and addend).
1789 template <typename... VisitorTs>
1790 void visitExistingEdges(LinkGraph &G, VisitorTs &&...Vs) {
1791  // We may add new blocks during this process, but we don't want to iterate
1792  // over them, so build a worklist.
1793  std::vector<Block *> Worklist(G.blocks().begin(), G.blocks().end());
1794 
1795  for (auto *B : Worklist)
1796  for (auto &E : B->edges())
1797  visitEdge(G, B, E, std::forward<VisitorTs>(Vs)...);
1798 }
1799 
1800 /// Create a LinkGraph from the given object buffer.
1801 ///
1802 /// Note: The graph does not take ownership of the underlying buffer, nor copy
1803 /// its contents. The caller is responsible for ensuring that the object buffer
1804 /// outlives the graph.
1807 
1808 /// Link the given graph.
1809 void link(std::unique_ptr<LinkGraph> G, std::unique_ptr<JITLinkContext> Ctx);
1810 
1811 } // end namespace jitlink
1812 } // end namespace llvm
1813 
1814 #endif // LLVM_EXECUTIONENGINE_JITLINK_JITLINK_H
llvm::orc::ExecutorAddr
Represents an address in the executor process.
Definition: ExecutorAddress.h:31
MemoryBuffer.h
BinaryStreamReader.h
MathExtras.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
JITSymbol.h
llvm::none_of
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1748
llvm::make_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition: iterator_range.h:53
Optional.h
MemoryFlags.h
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:149
llvm::BinaryStreamWriter
Provides write only access to a subclass of WritableBinaryStream.
Definition: BinaryStreamWriter.h:30
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1199
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
Allocator.h
Content
T Content
Definition: ELFObjHandler.cpp:89
Error.h
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::orc::ExecutorAddr::getValue
uint64_t getValue() const
Definition: ExecutorAddress.h:105
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1793
DenseMap.h
llvm::copy
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:1836
llvm::Optional
Definition: APInt.h:33
llvm::BumpPtrAllocator
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition: Allocator.h:375
T
#define T
Definition: Mips16ISelLowering.cpp:341
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:80
makeAbsolute
static void makeAbsolute(SmallVectorImpl< char > &Path)
Make Path absolute.
Definition: FileCollector.cpp:91
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
STLExtras.h
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::detail::DenseSetImpl::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
llvm::detail::DenseSetImpl::count
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition: DenseSet.h:97
llvm::count_if
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
Definition: STLExtras.h:1902
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:82
llvm::detail::DenseSetImpl::end
iterator end()
Definition: DenseSet.h:174
llvm::formatv
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
Definition: FormatVariadic.h:251
llvm::MutableArrayRef< char >
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
DenseSet.h
false
Definition: StackSlotColoring.cpp:141
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::detail::DenseSetImpl::size
size_type size() const
Definition: DenseSet.h:81
llvm::orc::ExecutorAddrDiff
uint64_t ExecutorAddrDiff
Definition: ExecutorAddress.h:28
llvm::orc::MemDeallocPolicy::Standard
@ Standard
Standard memory should be deallocated when the deallocate method is called for the finalized allocati...
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::orc::ExecutorAddrRange
Represents an address range in the exceutor process.
Definition: ExecutorAddress.h:191
llvm::detail::DenseSetImpl< Block *, DenseMap< Block *, detail::DenseSetEmpty, DenseMapInfo< Block * >, detail::DenseSetPair< Block * > >, DenseMapInfo< Block * > >::size_type
unsigned size_type
Definition: DenseSet.h:65
FormatVariadic.h
llvm::ArrayRef::slice
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Definition: ArrayRef.h:194
llvm::SmallString< 256 >
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:29
llvm::dxil::PointerTypeAnalysis::run
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
Definition: PointerTypeAnalysis.cpp:189
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:200
llvm::DenseSet< Symbol * >
llvm::orc::MemProt
MemProt
Describes Read/Write/Exec permissions for memory.
Definition: MemoryFlags.h:27
uint64_t
llvm::detail::DenseSetImpl< Symbol *, DenseMap< Symbol *, detail::DenseSetEmpty, DenseMapInfo< Symbol * >, detail::DenseSetPair< Symbol * > >, DenseMapInfo< Symbol * > >::const_iterator
ConstIterator const_iterator
Definition: DenseSet.h:171
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:79
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:63
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::DenseMap
Definition: DenseMap.h:714
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::iterator_facade_base
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition: iterator.h:80
llvm::detail::DenseSetImpl::begin
iterator begin()
Definition: DenseSet.h:173
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
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:1861
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::ErrorInfo
Base class for user error types.
Definition: Error.h:347
Triple.h
llvm::size
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1715
llvm::Sched::Source
@ Source
Definition: TargetLowering.h:99
llvm::ArrayRef< char >
llvm::countTrailingZeros
unsigned countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition: MathExtras.h:152
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::orc::shared::AllocActions
std::vector< AllocActionCallPair > AllocActions
A vector of allocation actions to be run for this allocation.
Definition: AllocationActions.h:44
A
* A
Definition: README_ALTIVEC.txt:89
uint32_t
JITLinkMemoryManager.h
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::MutableArrayRef::data
T * data() const
Definition: ArrayRef.h:353
llvm::find_if
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1761
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
std
Definition: BitVector.h:851
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:83
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:143
N
#define N
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
addSymbol
static void addSymbol(Object &Obj, const NewSymbolInfo &SymInfo, uint8_t DefaultVisibility)
Definition: ELFObjcopy.cpp:531
llvm::support::endianness
endianness
Definition: Endian.h:27
llvm::detail::DenseSetImpl::erase
bool erase(const ValueT &V)
Definition: DenseSet.h:101
llvm::orc::MemDeallocPolicy
MemDeallocPolicy
Describes a memory deallocation policy for memory to be allocated by a JITLinkMemoryManager.
Definition: MemoryFlags.h:75
BinaryStreamWriter.h
llvm::pointee_iterator
An iterator type that allows iterating over the pointees via some other iterator.
Definition: iterator.h:320
InlinePriorityMode::Size
@ Size
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:394
Endian.h
llvm::isPowerOf2_64
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition: MathExtras.h:463
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::detail::DenseSetImpl< Symbol *, DenseMap< Symbol *, detail::DenseSetEmpty, DenseMapInfo< Symbol * >, detail::DenseSetPair< Symbol * > >, DenseMapInfo< Symbol * > >::iterator
Iterator iterator
Definition: DenseSet.h:170
llvm::sampleprof::Base
@ Base
Definition: Discriminator.h:58