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