LLVM  13.0.0git
Core.h
Go to the documentation of this file.
1 //===------ Core.h -- Core ORC APIs (Layer, JITDylib, etc.) -----*- 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 core ORC APIs.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_EXECUTIONENGINE_ORC_CORE_H
14 #define LLVM_EXECUTIONENGINE_ORC_CORE_H
15 
16 #include "llvm/ADT/BitmaskEnum.h"
17 #include "llvm/ADT/DenseSet.h"
24 #include "llvm/Support/Debug.h"
26 
27 #include <atomic>
28 #include <memory>
29 #include <vector>
30 
31 namespace llvm {
32 namespace orc {
33 
34 // Forward declare some classes.
35 class AsynchronousSymbolQuery;
36 class ExecutionSession;
37 class MaterializationUnit;
38 class MaterializationResponsibility;
39 class JITDylib;
40 class ResourceTracker;
41 class InProgressLookupState;
42 
43 enum class SymbolState : uint8_t;
44 
45 using ResourceTrackerSP = IntrusiveRefCntPtr<ResourceTracker>;
46 using JITDylibSP = IntrusiveRefCntPtr<JITDylib>;
47 
48 using ResourceKey = uintptr_t;
49 
50 /// API to remove / transfer ownership of JIT resources.
51 class ResourceTracker : public ThreadSafeRefCountedBase<ResourceTracker> {
52 private:
53  friend class ExecutionSession;
54  friend class JITDylib;
56 
57 public:
58  ResourceTracker(const ResourceTracker &) = delete;
59  ResourceTracker &operator=(const ResourceTracker &) = delete;
60  ResourceTracker(ResourceTracker &&) = delete;
61  ResourceTracker &operator=(ResourceTracker &&) = delete;
62 
63  ~ResourceTracker();
64 
65  /// Return the JITDylib targeted by this tracker.
66  JITDylib &getJITDylib() const {
67  return *reinterpret_cast<JITDylib *>(JDAndFlag.load() &
68  ~static_cast<uintptr_t>(1));
69  }
70 
71  /// Remove all resources associated with this key.
72  Error remove();
73 
74  /// Transfer all resources associated with this key to the given
75  /// tracker, which must target the same JITDylib as this one.
76  void transferTo(ResourceTracker &DstRT);
77 
78  /// Return true if this tracker has become defunct.
79  bool isDefunct() const { return JDAndFlag.load() & 0x1; }
80 
81  /// Returns the key associated with this tracker.
82  /// This method should not be used except for debug logging: there is no
83  /// guarantee that the returned value will remain valid.
84  ResourceKey getKeyUnsafe() const { return reinterpret_cast<uintptr_t>(this); }
85 
86 private:
88 
89  void makeDefunct();
90 
91  std::atomic_uintptr_t JDAndFlag;
92 };
93 
94 /// Listens for ResourceTracker operations.
96 public:
97  virtual ~ResourceManager();
99  virtual void handleTransferResources(ResourceKey DstK, ResourceKey SrcK) = 0;
100 };
101 
102 /// A set of symbol names (represented by SymbolStringPtrs for
103 // efficiency).
105 
106 /// A vector of symbol names.
107 using SymbolNameVector = std::vector<SymbolStringPtr>;
108 
109 /// A map from symbol names (as SymbolStringPtrs) to JITSymbols
110 /// (address/flags pairs).
112 
113 /// A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
115 
116 /// A map from JITDylibs to sets of symbols.
118 
119 /// Lookup flags that apply to each dylib in the search order for a lookup.
120 ///
121 /// If MatchHiddenSymbolsOnly is used (the default) for a given dylib, then
122 /// only symbols in that Dylib's interface will be searched. If
123 /// MatchHiddenSymbols is used then symbols with hidden visibility will match
124 /// as well.
126 
127 /// Lookup flags that apply to each symbol in a lookup.
128 ///
129 /// If RequiredSymbol is used (the default) for a given symbol then that symbol
130 /// must be found during the lookup or the lookup will fail returning a
131 /// SymbolNotFound error. If WeaklyReferencedSymbol is used and the given
132 /// symbol is not found then the query will continue, and no result for the
133 /// missing symbol will be present in the result (assuming the rest of the
134 /// lookup succeeds).
136 
137 /// Describes the kind of lookup being performed. The lookup kind is passed to
138 /// symbol generators (if they're invoked) to help them determine what
139 /// definitions to generate.
140 ///
141 /// Static -- Lookup is being performed as-if at static link time (e.g.
142 /// generators representing static archives should pull in new
143 /// definitions).
144 ///
145 /// DLSym -- Lookup is being performed as-if at runtime (e.g. generators
146 /// representing static archives should not pull in new definitions).
147 enum class LookupKind { Static, DLSym };
148 
149 /// A list of (JITDylib*, JITDylibLookupFlags) pairs to be used as a search
150 /// order during symbol lookup.
151 using JITDylibSearchOrder =
152  std::vector<std::pair<JITDylib *, JITDylibLookupFlags>>;
153 
154 /// Convenience function for creating a search order from an ArrayRef of
155 /// JITDylib*, all with the same flags.
160  O.reserve(JDs.size());
161  for (auto *JD : JDs)
162  O.push_back(std::make_pair(JD, Flags));
163  return O;
164 }
165 
166 /// A set of symbols to look up, each associated with a SymbolLookupFlags
167 /// value.
168 ///
169 /// This class is backed by a vector and optimized for fast insertion,
170 /// deletion and iteration. It does not guarantee a stable order between
171 /// operations, and will not automatically detect duplicate elements (they
172 /// can be manually checked by calling the validate method).
174 public:
175  using value_type = std::pair<SymbolStringPtr, SymbolLookupFlags>;
176  using UnderlyingVector = std::vector<value_type>;
177  using iterator = UnderlyingVector::iterator;
178  using const_iterator = UnderlyingVector::const_iterator;
179 
180  SymbolLookupSet() = default;
181 
182  explicit SymbolLookupSet(
185  add(std::move(Name), Flags);
186  }
187 
188  /// Construct a SymbolLookupSet from an initializer list of SymbolStringPtrs.
189  explicit SymbolLookupSet(
190  std::initializer_list<SymbolStringPtr> Names,
192  Symbols.reserve(Names.size());
193  for (auto &Name : Names)
194  add(std::move(Name), Flags);
195  }
196 
197  /// Construct a SymbolLookupSet from a SymbolNameSet with the given
198  /// Flags used for each value.
199  explicit SymbolLookupSet(
200  const SymbolNameSet &Names,
202  Symbols.reserve(Names.size());
203  for (const auto &Name : Names)
204  add(Name, Flags);
205  }
206 
207  /// Construct a SymbolLookupSet from a vector of symbols with the given Flags
208  /// used for each value.
209  /// If the ArrayRef contains duplicates it is up to the client to remove these
210  /// before using this instance for lookup.
211  explicit SymbolLookupSet(
214  Symbols.reserve(Names.size());
215  for (const auto &Name : Names)
216  add(Name, Flags);
217  }
218 
219  /// Add an element to the set. The client is responsible for checking that
220  /// duplicates are not added.
224  Symbols.push_back(std::make_pair(std::move(Name), Flags));
225  return *this;
226  }
227 
228  /// Quickly append one lookup set to another.
230  Symbols.reserve(Symbols.size() + Other.size());
231  for (auto &KV : Other)
232  Symbols.push_back(std::move(KV));
233  return *this;
234  }
235 
236  bool empty() const { return Symbols.empty(); }
237  UnderlyingVector::size_type size() const { return Symbols.size(); }
238  iterator begin() { return Symbols.begin(); }
239  iterator end() { return Symbols.end(); }
240  const_iterator begin() const { return Symbols.begin(); }
241  const_iterator end() const { return Symbols.end(); }
242 
243  /// Removes the Ith element of the vector, replacing it with the last element.
244  void remove(UnderlyingVector::size_type I) {
245  std::swap(Symbols[I], Symbols.back());
246  Symbols.pop_back();
247  }
248 
249  /// Removes the element pointed to by the given iterator. This iterator and
250  /// all subsequent ones (including end()) are invalidated.
251  void remove(iterator I) { remove(I - begin()); }
252 
253  /// Removes all elements matching the given predicate, which must be callable
254  /// as bool(const SymbolStringPtr &, SymbolLookupFlags Flags).
255  template <typename PredFn> void remove_if(PredFn &&Pred) {
256  UnderlyingVector::size_type I = 0;
257  while (I != Symbols.size()) {
258  const auto &Name = Symbols[I].first;
259  auto Flags = Symbols[I].second;
260  if (Pred(Name, Flags))
261  remove(I);
262  else
263  ++I;
264  }
265  }
266 
267  /// Loop over the elements of this SymbolLookupSet, applying the Body function
268  /// to each one. Body must be callable as
269  /// bool(const SymbolStringPtr &, SymbolLookupFlags).
270  /// If Body returns true then the element just passed in is removed from the
271  /// set. If Body returns false then the element is retained.
272  template <typename BodyFn>
273  auto forEachWithRemoval(BodyFn &&Body) -> std::enable_if_t<
274  std::is_same<decltype(Body(std::declval<const SymbolStringPtr &>(),
275  std::declval<SymbolLookupFlags>())),
276  bool>::value> {
277  UnderlyingVector::size_type I = 0;
278  while (I != Symbols.size()) {
279  const auto &Name = Symbols[I].first;
280  auto Flags = Symbols[I].second;
281  if (Body(Name, Flags))
282  remove(I);
283  else
284  ++I;
285  }
286  }
287 
288  /// Loop over the elements of this SymbolLookupSet, applying the Body function
289  /// to each one. Body must be callable as
290  /// Expected<bool>(const SymbolStringPtr &, SymbolLookupFlags).
291  /// If Body returns a failure value, the loop exits immediately. If Body
292  /// returns true then the element just passed in is removed from the set. If
293  /// Body returns false then the element is retained.
294  template <typename BodyFn>
295  auto forEachWithRemoval(BodyFn &&Body) -> std::enable_if_t<
296  std::is_same<decltype(Body(std::declval<const SymbolStringPtr &>(),
297  std::declval<SymbolLookupFlags>())),
298  Expected<bool>>::value,
299  Error> {
300  UnderlyingVector::size_type I = 0;
301  while (I != Symbols.size()) {
302  const auto &Name = Symbols[I].first;
303  auto Flags = Symbols[I].second;
304  auto Remove = Body(Name, Flags);
305  if (!Remove)
306  return Remove.takeError();
307  if (*Remove)
308  remove(I);
309  else
310  ++I;
311  }
312  return Error::success();
313  }
314 
315  /// Construct a SymbolNameVector from this instance by dropping the Flags
316  /// values.
318  SymbolNameVector Names;
319  Names.reserve(Symbols.size());
320  for (auto &KV : Symbols)
321  Names.push_back(KV.first);
322  return Names;
323  }
324 
325  /// Sort the lookup set by pointer value. This sort is fast but sensitive to
326  /// allocation order and so should not be used where a consistent order is
327  /// required.
328  void sortByAddress() {
329  llvm::sort(Symbols, [](const value_type &LHS, const value_type &RHS) {
330  return LHS.first < RHS.first;
331  });
332  }
333 
334  /// Sort the lookup set lexicographically. This sort is slow but the order
335  /// is unaffected by allocation order.
336  void sortByName() {
337  llvm::sort(Symbols, [](const value_type &LHS, const value_type &RHS) {
338  return *LHS.first < *RHS.first;
339  });
340  }
341 
342  /// Remove any duplicate elements. If a SymbolLookupSet is not duplicate-free
343  /// by construction, this method can be used to turn it into a proper set.
345  sortByAddress();
346  auto LastI = std::unique(Symbols.begin(), Symbols.end());
347  Symbols.erase(LastI, Symbols.end());
348  }
349 
350 #ifndef NDEBUG
351  /// Returns true if this set contains any duplicates. This should only be used
352  /// in assertions.
354  if (Symbols.size() < 2)
355  return false;
356  sortByAddress();
357  for (UnderlyingVector::size_type I = 1; I != Symbols.size(); ++I)
358  if (Symbols[I].first == Symbols[I - 1].first)
359  return true;
360  return false;
361  }
362 #endif
363 
364 private:
365  UnderlyingVector Symbols;
366 };
367 
369  SymbolAliasMapEntry() = default;
372 
375 };
376 
377 /// A map of Symbols to (Symbol, Flags) pairs.
379 
380 /// Callback to notify client that symbols have been resolved.
382 
383 /// Callback to register the dependencies for a given query.
386 
387 /// This can be used as the value for a RegisterDependenciesFunction if there
388 /// are no dependants to register with.
390 
391 class ResourceTrackerDefunct : public ErrorInfo<ResourceTrackerDefunct> {
392 public:
393  static char ID;
394 
396  std::error_code convertToErrorCode() const override;
397  void log(raw_ostream &OS) const override;
398 
399 private:
401 };
402 
403 /// Used to notify a JITDylib that the given set of symbols failed to
404 /// materialize.
405 class FailedToMaterialize : public ErrorInfo<FailedToMaterialize> {
406 public:
407  static char ID;
408 
409  FailedToMaterialize(std::shared_ptr<SymbolDependenceMap> Symbols);
410  std::error_code convertToErrorCode() const override;
411  void log(raw_ostream &OS) const override;
412  const SymbolDependenceMap &getSymbols() const { return *Symbols; }
413 
414 private:
415  std::shared_ptr<SymbolDependenceMap> Symbols;
416 };
417 
418 /// Used to notify clients when symbols can not be found during a lookup.
419 class SymbolsNotFound : public ErrorInfo<SymbolsNotFound> {
420 public:
421  static char ID;
422 
425  std::error_code convertToErrorCode() const override;
426  void log(raw_ostream &OS) const override;
427  const SymbolNameVector &getSymbols() const { return Symbols; }
428 
429 private:
430  SymbolNameVector Symbols;
431 };
432 
433 /// Used to notify clients that a set of symbols could not be removed.
434 class SymbolsCouldNotBeRemoved : public ErrorInfo<SymbolsCouldNotBeRemoved> {
435 public:
436  static char ID;
437 
439  std::error_code convertToErrorCode() const override;
440  void log(raw_ostream &OS) const override;
441  const SymbolNameSet &getSymbols() const { return Symbols; }
442 
443 private:
444  SymbolNameSet Symbols;
445 };
446 
447 /// Errors of this type should be returned if a module fails to include
448 /// definitions that are claimed by the module's associated
449 /// MaterializationResponsibility. If this error is returned it is indicative of
450 /// a broken transformation / compiler / object cache.
451 class MissingSymbolDefinitions : public ErrorInfo<MissingSymbolDefinitions> {
452 public:
453  static char ID;
454 
455  MissingSymbolDefinitions(std::string ModuleName, SymbolNameVector Symbols)
456  : ModuleName(std::move(ModuleName)), Symbols(std::move(Symbols)) {}
457  std::error_code convertToErrorCode() const override;
458  void log(raw_ostream &OS) const override;
459  const std::string &getModuleName() const { return ModuleName; }
460  const SymbolNameVector &getSymbols() const { return Symbols; }
461 private:
462  std::string ModuleName;
463  SymbolNameVector Symbols;
464 };
465 
466 /// Errors of this type should be returned if a module contains definitions for
467 /// symbols that are not claimed by the module's associated
468 /// MaterializationResponsibility. If this error is returned it is indicative of
469 /// a broken transformation / compiler / object cache.
470 class UnexpectedSymbolDefinitions : public ErrorInfo<UnexpectedSymbolDefinitions> {
471 public:
472  static char ID;
473 
474  UnexpectedSymbolDefinitions(std::string ModuleName, SymbolNameVector Symbols)
475  : ModuleName(std::move(ModuleName)), Symbols(std::move(Symbols)) {}
476  std::error_code convertToErrorCode() const override;
477  void log(raw_ostream &OS) const override;
478  const std::string &getModuleName() const { return ModuleName; }
479  const SymbolNameVector &getSymbols() const { return Symbols; }
480 private:
481  std::string ModuleName;
482  SymbolNameVector Symbols;
483 };
484 
485 /// Tracks responsibility for materialization, and mediates interactions between
486 /// MaterializationUnits and JDs.
487 ///
488 /// An instance of this class is passed to MaterializationUnits when their
489 /// materialize method is called. It allows MaterializationUnits to resolve and
490 /// emit symbols, or abandon materialization by notifying any unmaterialized
491 /// symbols of an error.
493  friend class ExecutionSession;
494 
495 public:
499 
500  /// Destruct a MaterializationResponsibility instance. In debug mode
501  /// this asserts that all symbols being tracked have been either
502  /// emitted or notified of an error.
504 
505  /// Returns the ResourceTracker for this instance.
506  template <typename Func> Error withResourceKeyDo(Func &&F) const;
507 
508  /// Returns the target JITDylib that these symbols are being materialized
509  /// into.
510  JITDylib &getTargetJITDylib() const { return *JD; }
511 
512  /// Returns the ExecutionSession for this instance.
514 
515  /// Returns the symbol flags map for this responsibility instance.
516  /// Note: The returned flags may have transient flags (Lazy, Materializing)
517  /// set. These should be stripped with JITSymbolFlags::stripTransientFlags
518  /// before using.
519  const SymbolFlagsMap &getSymbols() const { return SymbolFlags; }
520 
521  /// Returns the initialization pseudo-symbol, if any. This symbol will also
522  /// be present in the SymbolFlagsMap for this MaterializationResponsibility
523  /// object.
524  const SymbolStringPtr &getInitializerSymbol() const { return InitSymbol; }
525 
526  /// Returns the names of any symbols covered by this
527  /// MaterializationResponsibility object that have queries pending. This
528  /// information can be used to return responsibility for unrequested symbols
529  /// back to the JITDylib via the delegate method.
531 
532  /// Notifies the target JITDylib that the given symbols have been resolved.
533  /// This will update the given symbols' addresses in the JITDylib, and notify
534  /// any pending queries on the given symbols of their resolution. The given
535  /// symbols must be ones covered by this MaterializationResponsibility
536  /// instance. Individual calls to this method may resolve a subset of the
537  /// symbols, but all symbols must have been resolved prior to calling emit.
538  ///
539  /// This method will return an error if any symbols being resolved have been
540  /// moved to the error state due to the failure of a dependency. If this
541  /// method returns an error then clients should log it and call
542  /// failMaterialize. If no dependencies have been registered for the
543  /// symbols covered by this MaterializationResponsibiility then this method
544  /// is guaranteed to return Error::success() and can be wrapped with cantFail.
545  Error notifyResolved(const SymbolMap &Symbols);
546 
547  /// Notifies the target JITDylib (and any pending queries on that JITDylib)
548  /// that all symbols covered by this MaterializationResponsibility instance
549  /// have been emitted.
550  ///
551  /// This method will return an error if any symbols being resolved have been
552  /// moved to the error state due to the failure of a dependency. If this
553  /// method returns an error then clients should log it and call
554  /// failMaterialize. If no dependencies have been registered for the
555  /// symbols covered by this MaterializationResponsibiility then this method
556  /// is guaranteed to return Error::success() and can be wrapped with cantFail.
558 
559  /// Attempt to claim responsibility for new definitions. This method can be
560  /// used to claim responsibility for symbols that are added to a
561  /// materialization unit during the compilation process (e.g. literal pool
562  /// symbols). Symbol linkage rules are the same as for symbols that are
563  /// defined up front: duplicate strong definitions will result in errors.
564  /// Duplicate weak definitions will be discarded (in which case they will
565  /// not be added to this responsibility instance).
566  ///
567  /// This method can be used by materialization units that want to add
568  /// additional symbols at materialization time (e.g. stubs, compile
569  /// callbacks, metadata).
571 
572  /// Define the given symbols as non-existent, removing it from the symbol
573  /// table and notifying any pending queries. Queries that lookup up the
574  /// symbol using the SymbolLookupFlags::WeaklyReferencedSymbol flag will
575  /// behave as if the symbol had not been matched in the first place. Queries
576  /// that required this symbol will fail with a missing symbol definition
577  /// error.
578  ///
579  /// This method is intended to support cleanup of special symbols like
580  /// initializer symbols: Queries using
581  /// SymbolLookupFlags::WeaklyReferencedSymbol can be used to trigger their
582  /// emission, and this method can be used to remove them from the JITDylib
583  /// once materialization is complete.
585 
586  /// Notify all not-yet-emitted covered by this MaterializationResponsibility
587  /// instance that an error has occurred.
588  /// This will remove all symbols covered by this MaterializationResponsibilty
589  /// from the target JITDylib, and send an error to any queries waiting on
590  /// these symbols.
591  void failMaterialization();
592 
593  /// Transfers responsibility to the given MaterializationUnit for all
594  /// symbols defined by that MaterializationUnit. This allows
595  /// materializers to break up work based on run-time information (e.g.
596  /// by introspecting which symbols have actually been looked up and
597  /// materializing only those).
598  Error replace(std::unique_ptr<MaterializationUnit> MU);
599 
600  /// Delegates responsibility for the given symbols to the returned
601  /// materialization responsibility. Useful for breaking up work between
602  /// threads, or different kinds of materialization processes.
604  delegate(const SymbolNameSet &Symbols);
605 
607  const SymbolDependenceMap &Dependencies);
608 
609  /// Add dependencies that apply to all symbols covered by this instance.
610  void addDependenciesForAll(const SymbolDependenceMap &Dependencies);
611 
612 private:
613  /// Create a MaterializationResponsibility for the given JITDylib and
614  /// initial symbols.
616  SymbolStringPtr InitSymbol)
617  : JD(std::move(JD)), SymbolFlags(std::move(SymbolFlags)),
618  InitSymbol(std::move(InitSymbol)) {
619  assert(this->JD && "Cannot initialize with null JITDylib");
620  assert(!this->SymbolFlags.empty() && "Materializing nothing?");
621  }
622 
623  JITDylibSP JD;
625  SymbolStringPtr InitSymbol;
626 };
627 
628 /// A MaterializationUnit represents a set of symbol definitions that can
629 /// be materialized as a group, or individually discarded (when
630 /// overriding definitions are encountered).
631 ///
632 /// MaterializationUnits are used when providing lazy definitions of symbols to
633 /// JITDylibs. The JITDylib will call materialize when the address of a symbol
634 /// is requested via the lookup method. The JITDylib will call discard if a
635 /// stronger definition is added or already present.
637  friend class ExecutionSession;
638  friend class JITDylib;
639 
640 public:
641  static char ID;
642 
645  : SymbolFlags(std::move(InitalSymbolFlags)),
647  assert((!this->InitSymbol || this->SymbolFlags.count(this->InitSymbol)) &&
648  "If set, InitSymbol should appear in InitialSymbolFlags map");
649  }
650 
651  virtual ~MaterializationUnit() {}
652 
653  /// Return the name of this materialization unit. Useful for debugging
654  /// output.
655  virtual StringRef getName() const = 0;
656 
657  /// Return the set of symbols that this source provides.
658  const SymbolFlagsMap &getSymbols() const { return SymbolFlags; }
659 
660  /// Returns the initialization symbol for this MaterializationUnit (if any).
662 
663  /// Implementations of this method should materialize all symbols
664  /// in the materialzation unit, except for those that have been
665  /// previously discarded.
666  virtual void
667  materialize(std::unique_ptr<MaterializationResponsibility> R) = 0;
668 
669  /// Called by JITDylibs to notify MaterializationUnits that the given symbol
670  /// has been overridden.
671  void doDiscard(const JITDylib &JD, const SymbolStringPtr &Name) {
673  discard(JD, std::move(Name));
674  }
675 
676 protected:
679 
680 private:
681  virtual void anchor();
682 
683  /// Implementations of this method should discard the given symbol
684  /// from the source (e.g. if the source is an LLVM IR Module and the
685  /// symbol is a function, delete the function body or mark it available
686  /// externally).
687  virtual void discard(const JITDylib &JD, const SymbolStringPtr &Name) = 0;
688 };
689 
690 /// A MaterializationUnit implementation for pre-existing absolute symbols.
691 ///
692 /// All symbols will be resolved and marked ready as soon as the unit is
693 /// materialized.
695 public:
697 
698  StringRef getName() const override;
699 
700 private:
701  void materialize(std::unique_ptr<MaterializationResponsibility> R) override;
702  void discard(const JITDylib &JD, const SymbolStringPtr &Name) override;
703  static SymbolFlagsMap extractFlags(const SymbolMap &Symbols);
704 
705  SymbolMap Symbols;
706 };
707 
708 /// Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
709 /// Useful for inserting absolute symbols into a JITDylib. E.g.:
710 /// \code{.cpp}
711 /// JITDylib &JD = ...;
712 /// SymbolStringPtr Foo = ...;
713 /// JITEvaluatedSymbol FooSym = ...;
714 /// if (auto Err = JD.define(absoluteSymbols({{Foo, FooSym}})))
715 /// return Err;
716 /// \endcode
717 ///
718 inline std::unique_ptr<AbsoluteSymbolsMaterializationUnit>
720  return std::make_unique<AbsoluteSymbolsMaterializationUnit>(
721  std::move(Symbols));
722 }
723 
724 /// A materialization unit for symbol aliases. Allows existing symbols to be
725 /// aliased with alternate flags.
727 public:
728  /// SourceJD is allowed to be nullptr, in which case the source JITDylib is
729  /// taken to be whatever JITDylib these definitions are materialized in (and
730  /// MatchNonExported has no effect). This is useful for defining aliases
731  /// within a JITDylib.
732  ///
733  /// Note: Care must be taken that no sets of aliases form a cycle, as such
734  /// a cycle will result in a deadlock when any symbol in the cycle is
735  /// resolved.
737  JITDylibLookupFlags SourceJDLookupFlags,
738  SymbolAliasMap Aliases);
739 
740  StringRef getName() const override;
741 
742 private:
743  void materialize(std::unique_ptr<MaterializationResponsibility> R) override;
744  void discard(const JITDylib &JD, const SymbolStringPtr &Name) override;
745  static SymbolFlagsMap extractFlags(const SymbolAliasMap &Aliases);
746 
747  JITDylib *SourceJD = nullptr;
748  JITDylibLookupFlags SourceJDLookupFlags;
749  SymbolAliasMap Aliases;
750 };
751 
752 /// Create a ReExportsMaterializationUnit with the given aliases.
753 /// Useful for defining symbol aliases.: E.g., given a JITDylib JD containing
754 /// symbols "foo" and "bar", we can define aliases "baz" (for "foo") and "qux"
755 /// (for "bar") with: \code{.cpp}
756 /// SymbolStringPtr Baz = ...;
757 /// SymbolStringPtr Qux = ...;
758 /// if (auto Err = JD.define(symbolAliases({
759 /// {Baz, { Foo, JITSymbolFlags::Exported }},
760 /// {Qux, { Bar, JITSymbolFlags::Weak }}}))
761 /// return Err;
762 /// \endcode
763 inline std::unique_ptr<ReExportsMaterializationUnit>
765  return std::make_unique<ReExportsMaterializationUnit>(
767 }
768 
769 /// Create a materialization unit for re-exporting symbols from another JITDylib
770 /// with alternative names/flags.
771 /// SourceJD will be searched using the given JITDylibLookupFlags.
772 inline std::unique_ptr<ReExportsMaterializationUnit>
773 reexports(JITDylib &SourceJD, SymbolAliasMap Aliases,
774  JITDylibLookupFlags SourceJDLookupFlags =
776  return std::make_unique<ReExportsMaterializationUnit>(
777  &SourceJD, SourceJDLookupFlags, std::move(Aliases));
778 }
779 
780 /// Build a SymbolAliasMap for the common case where you want to re-export
781 /// symbols from another JITDylib with the same linkage/flags.
783 buildSimpleReexportsAAliasMap(JITDylib &SourceJD, const SymbolNameSet &Symbols);
784 
785 /// Represents the state that a symbol has reached during materialization.
786 enum class SymbolState : uint8_t {
787  Invalid, /// No symbol should be in this state.
788  NeverSearched, /// Added to the symbol table, never queried.
789  Materializing, /// Queried, materialization begun.
790  Resolved, /// Assigned address, still materializing.
791  Emitted, /// Emitted to memory, but waiting on transitive dependencies.
792  Ready = 0x3f /// Ready and safe for clients to access.
793 };
794 
795 /// A symbol query that returns results via a callback when results are
796 /// ready.
797 ///
798 /// makes a callback when all symbols are available.
800  friend class ExecutionSession;
802  friend class JITDylib;
805 
806 public:
807  /// Create a query for the given symbols. The NotifyComplete
808  /// callback will be called once all queried symbols reach the given
809  /// minimum state.
811  SymbolState RequiredState,
812  SymbolsResolvedCallback NotifyComplete);
813 
814  /// Notify the query that a requested symbol has reached the required state.
816  JITEvaluatedSymbol Sym);
817 
818  /// Returns true if all symbols covered by this query have been
819  /// resolved.
820  bool isComplete() const { return OutstandingSymbolsCount == 0; }
821 
822 
823 private:
824  void handleComplete(ExecutionSession &ES);
825 
826  SymbolState getRequiredState() { return RequiredState; }
827 
828  void addQueryDependence(JITDylib &JD, SymbolStringPtr Name);
829 
830  void removeQueryDependence(JITDylib &JD, const SymbolStringPtr &Name);
831 
832  void dropSymbol(const SymbolStringPtr &Name);
833 
834  void handleFailed(Error Err);
835 
836  void detach();
837 
838  SymbolsResolvedCallback NotifyComplete;
839  SymbolDependenceMap QueryRegistrations;
840  SymbolMap ResolvedSymbols;
841  size_t OutstandingSymbolsCount;
842  SymbolState RequiredState;
843 };
844 
845 /// Wraps state for a lookup-in-progress.
846 /// DefinitionGenerators can optionally take ownership of a LookupState object
847 /// to suspend a lookup-in-progress while they search for definitions.
848 class LookupState {
849  friend class OrcV2CAPIHelper;
850  friend class ExecutionSession;
851 
852 public:
853  LookupState();
856  ~LookupState();
857 
858  /// Continue the lookup. This can be called by DefinitionGenerators
859  /// to re-start a captured query-application operation.
860  void continueLookup(Error Err);
861 
862 private:
863  LookupState(std::unique_ptr<InProgressLookupState> IPLS);
864 
865  // For C API.
866  void reset(InProgressLookupState *IPLS);
867 
868  std::unique_ptr<InProgressLookupState> IPLS;
869 };
870 
871 /// Definition generators can be attached to JITDylibs to generate new
872 /// definitions for otherwise unresolved symbols during lookup.
874 public:
875  virtual ~DefinitionGenerator();
876 
877  /// DefinitionGenerators should override this method to insert new
878  /// definitions into the parent JITDylib. K specifies the kind of this
879  /// lookup. JD specifies the target JITDylib being searched, and
880  /// JDLookupFlags specifies whether the search should match against
881  /// hidden symbols. Finally, Symbols describes the set of unresolved
882  /// symbols and their associated lookup flags.
884  JITDylibLookupFlags JDLookupFlags,
885  const SymbolLookupSet &LookupSet) = 0;
886 };
887 
888 /// A symbol table that supports asynchoronous symbol queries.
889 ///
890 /// Represents a virtual shared object. Instances can not be copied or moved, so
891 /// their addresses may be used as keys for resource management.
892 /// JITDylib state changes must be made via an ExecutionSession to guarantee
893 /// that they are synchronized with respect to other JITDylib operations.
894 class JITDylib : public ThreadSafeRefCountedBase<JITDylib>,
895  public jitlink::JITLinkDylib {
897  friend class ExecutionSession;
898  friend class Platform;
900 public:
901 
903  std::set<std::shared_ptr<AsynchronousSymbolQuery>>;
904 
905  JITDylib(const JITDylib &) = delete;
906  JITDylib &operator=(const JITDylib &) = delete;
907  JITDylib(JITDylib &&) = delete;
908  JITDylib &operator=(JITDylib &&) = delete;
909 
910  /// Get the name for this JITDylib.
911  const std::string &getName() const { return JITDylibName; }
912 
913  /// Get a reference to the ExecutionSession for this JITDylib.
914  ExecutionSession &getExecutionSession() const { return ES; }
915 
916  /// Calls remove on all trackers currently associated with this JITDylib.
917  /// Does not run static deinits.
918  ///
919  /// Note that removal happens outside the session lock, so new code may be
920  /// added concurrently while the clear is underway, and the newly added
921  /// code will *not* be cleared. Adding new code concurrently with a clear
922  /// is usually a bug and should be avoided.
923  Error clear();
924 
925  /// Get the default resource tracker for this JITDylib.
927 
928  /// Create a resource tracker for this JITDylib.
930 
931  /// Adds a definition generator to this JITDylib and returns a referenece to
932  /// it.
933  ///
934  /// When JITDylibs are searched during lookup, if no existing definition of
935  /// a symbol is found, then any generators that have been added are run (in
936  /// the order that they were added) to potentially generate a definition.
937  template <typename GeneratorT>
938  GeneratorT &addGenerator(std::unique_ptr<GeneratorT> DefGenerator);
939 
940  /// Remove a definition generator from this JITDylib.
941  ///
942  /// The given generator must exist in this JITDylib's generators list (i.e.
943  /// have been added and not yet removed).
945 
946  /// Set the link order to be used when fixing up definitions in JITDylib.
947  /// This will replace the previous link order, and apply to any symbol
948  /// resolutions made for definitions in this JITDylib after the call to
949  /// setLinkOrder (even if the definition itself was added before the
950  /// call).
951  ///
952  /// If LinkAgainstThisJITDylibFirst is true (the default) then this JITDylib
953  /// will add itself to the beginning of the LinkOrder (Clients should not
954  /// put this JITDylib in the list in this case, to avoid redundant lookups).
955  ///
956  /// If LinkAgainstThisJITDylibFirst is false then the link order will be used
957  /// as-is. The primary motivation for this feature is to support deliberate
958  /// shadowing of symbols in this JITDylib by a facade JITDylib. For example,
959  /// the facade may resolve function names to stubs, and the stubs may compile
960  /// lazily by looking up symbols in this dylib. Adding the facade dylib
961  /// as the first in the link order (instead of this dylib) ensures that
962  /// definitions within this dylib resolve to the lazy-compiling stubs,
963  /// rather than immediately materializing the definitions in this dylib.
964  void setLinkOrder(JITDylibSearchOrder NewSearchOrder,
965  bool LinkAgainstThisJITDylibFirst = true);
966 
967  /// Add the given JITDylib to the link order for definitions in this
968  /// JITDylib.
969  void addToLinkOrder(JITDylib &JD,
970  JITDylibLookupFlags JDLookupFlags =
972 
973  /// Replace OldJD with NewJD in the link order if OldJD is present.
974  /// Otherwise this operation is a no-op.
975  void replaceInLinkOrder(JITDylib &OldJD, JITDylib &NewJD,
976  JITDylibLookupFlags JDLookupFlags =
978 
979  /// Remove the given JITDylib from the link order for this JITDylib if it is
980  /// present. Otherwise this operation is a no-op.
981  void removeFromLinkOrder(JITDylib &JD);
982 
983  /// Do something with the link order (run under the session lock).
984  template <typename Func>
985  auto withLinkOrderDo(Func &&F)
986  -> decltype(F(std::declval<const JITDylibSearchOrder &>()));
987 
988  /// Define all symbols provided by the materialization unit to be part of this
989  /// JITDylib.
990  ///
991  /// If RT is not specified then the default resource tracker will be used.
992  ///
993  /// This overload always takes ownership of the MaterializationUnit. If any
994  /// errors occur, the MaterializationUnit consumed.
995  template <typename MaterializationUnitType>
996  Error define(std::unique_ptr<MaterializationUnitType> &&MU,
997  ResourceTrackerSP RT = nullptr);
998 
999  /// Define all symbols provided by the materialization unit to be part of this
1000  /// JITDylib.
1001  ///
1002  /// This overload only takes ownership of the MaterializationUnit no error is
1003  /// generated. If an error occurs, ownership remains with the caller. This
1004  /// may allow the caller to modify the MaterializationUnit to correct the
1005  /// issue, then re-call define.
1006  template <typename MaterializationUnitType>
1007  Error define(std::unique_ptr<MaterializationUnitType> &MU,
1008  ResourceTrackerSP RT = nullptr);
1009 
1010  /// Tries to remove the given symbols.
1011  ///
1012  /// If any symbols are not defined in this JITDylib this method will return
1013  /// a SymbolsNotFound error covering the missing symbols.
1014  ///
1015  /// If all symbols are found but some symbols are in the process of being
1016  /// materialized this method will return a SymbolsCouldNotBeRemoved error.
1017  ///
1018  /// On success, all symbols are removed. On failure, the JITDylib state is
1019  /// left unmodified (no symbols are removed).
1020  Error remove(const SymbolNameSet &Names);
1021 
1022  /// Dump current JITDylib state to OS.
1023  void dump(raw_ostream &OS);
1024 
1025  /// Returns the given JITDylibs and all of their transitive dependencies in
1026  /// DFS order (based on linkage relationships). Each JITDylib will appear
1027  /// only once.
1028  static std::vector<JITDylibSP> getDFSLinkOrder(ArrayRef<JITDylibSP> JDs);
1029 
1030  /// Returns the given JITDylibs and all of their transitive dependensies in
1031  /// reverse DFS order (based on linkage relationships). Each JITDylib will
1032  /// appear only once.
1033  static std::vector<JITDylibSP>
1035 
1036  /// Return this JITDylib and its transitive dependencies in DFS order
1037  /// based on linkage relationships.
1038  std::vector<JITDylibSP> getDFSLinkOrder();
1039 
1040  /// Rteurn this JITDylib and its transitive dependencies in reverse DFS order
1041  /// based on linkage relationships.
1042  std::vector<JITDylibSP> getReverseDFSLinkOrder();
1043 
1044 private:
1045  using AsynchronousSymbolQueryList =
1046  std::vector<std::shared_ptr<AsynchronousSymbolQuery>>;
1047 
1048  struct UnmaterializedInfo {
1049  UnmaterializedInfo(std::unique_ptr<MaterializationUnit> MU,
1050  ResourceTracker *RT)
1051  : MU(std::move(MU)), RT(RT) {}
1052 
1053  std::unique_ptr<MaterializationUnit> MU;
1054  ResourceTracker *RT;
1055  };
1056 
1057  using UnmaterializedInfosMap =
1058  DenseMap<SymbolStringPtr, std::shared_ptr<UnmaterializedInfo>>;
1059 
1060  using UnmaterializedInfosList =
1061  std::vector<std::shared_ptr<UnmaterializedInfo>>;
1062 
1063  struct MaterializingInfo {
1064  SymbolDependenceMap Dependants;
1065  SymbolDependenceMap UnemittedDependencies;
1066 
1067  void addQuery(std::shared_ptr<AsynchronousSymbolQuery> Q);
1068  void removeQuery(const AsynchronousSymbolQuery &Q);
1069  AsynchronousSymbolQueryList takeQueriesMeeting(SymbolState RequiredState);
1070  AsynchronousSymbolQueryList takeAllPendingQueries() {
1071  return std::move(PendingQueries);
1072  }
1073  bool hasQueriesPending() const { return !PendingQueries.empty(); }
1074  const AsynchronousSymbolQueryList &pendingQueries() const {
1075  return PendingQueries;
1076  }
1077  private:
1078  AsynchronousSymbolQueryList PendingQueries;
1079  };
1080 
1081  using MaterializingInfosMap = DenseMap<SymbolStringPtr, MaterializingInfo>;
1082 
1083  class SymbolTableEntry {
1084  public:
1085  SymbolTableEntry() = default;
1086  SymbolTableEntry(JITSymbolFlags Flags)
1087  : Flags(Flags), State(static_cast<uint8_t>(SymbolState::NeverSearched)),
1088  MaterializerAttached(false), PendingRemoval(false) {}
1089 
1090  JITTargetAddress getAddress() const { return Addr; }
1091  JITSymbolFlags getFlags() const { return Flags; }
1092  SymbolState getState() const { return static_cast<SymbolState>(State); }
1093 
1094  bool hasMaterializerAttached() const { return MaterializerAttached; }
1095  bool isPendingRemoval() const { return PendingRemoval; }
1096 
1097  void setAddress(JITTargetAddress Addr) { this->Addr = Addr; }
1098  void setFlags(JITSymbolFlags Flags) { this->Flags = Flags; }
1099  void setState(SymbolState State) {
1100  assert(static_cast<uint8_t>(State) < (1 << 6) &&
1101  "State does not fit in bitfield");
1102  this->State = static_cast<uint8_t>(State);
1103  }
1104 
1105  void setMaterializerAttached(bool MaterializerAttached) {
1106  this->MaterializerAttached = MaterializerAttached;
1107  }
1108 
1109  void setPendingRemoval(bool PendingRemoval) {
1110  this->PendingRemoval = PendingRemoval;
1111  }
1112 
1113  JITEvaluatedSymbol getSymbol() const {
1114  return JITEvaluatedSymbol(Addr, Flags);
1115  }
1116 
1117  private:
1118  JITTargetAddress Addr = 0;
1119  JITSymbolFlags Flags;
1120  uint8_t State : 6;
1121  uint8_t MaterializerAttached : 1;
1122  uint8_t PendingRemoval : 1;
1123  };
1124 
1125  using SymbolTable = DenseMap<SymbolStringPtr, SymbolTableEntry>;
1126 
1127  JITDylib(ExecutionSession &ES, std::string Name);
1128 
1130  std::pair<AsynchronousSymbolQuerySet, std::shared_ptr<SymbolDependenceMap>>
1131  removeTracker(ResourceTracker &RT);
1132 
1133  void transferTracker(ResourceTracker &DstRT, ResourceTracker &SrcRT);
1134 
1135  Error defineImpl(MaterializationUnit &MU);
1136 
1137  void installMaterializationUnit(std::unique_ptr<MaterializationUnit> MU,
1138  ResourceTracker &RT);
1139 
1140  void detachQueryHelper(AsynchronousSymbolQuery &Q,
1141  const SymbolNameSet &QuerySymbols);
1142 
1143  void transferEmittedNodeDependencies(MaterializingInfo &DependantMI,
1144  const SymbolStringPtr &DependantName,
1145  MaterializingInfo &EmittedMI);
1146 
1147  Expected<SymbolFlagsMap> defineMaterializing(SymbolFlagsMap SymbolFlags);
1148 
1149  Error replace(MaterializationResponsibility &FromMR,
1150  std::unique_ptr<MaterializationUnit> MU);
1151 
1152  Expected<std::unique_ptr<MaterializationResponsibility>>
1154  SymbolStringPtr InitSymbol);
1155 
1156  SymbolNameSet getRequestedSymbols(const SymbolFlagsMap &SymbolFlags) const;
1157 
1158  void addDependencies(const SymbolStringPtr &Name,
1159  const SymbolDependenceMap &Dependants);
1160 
1161  Error resolve(MaterializationResponsibility &MR, const SymbolMap &Resolved);
1162 
1163  Error emit(MaterializationResponsibility &MR, const SymbolFlagsMap &Emitted);
1164 
1165  void unlinkMaterializationResponsibility(MaterializationResponsibility &MR);
1166 
1167  using FailedSymbolsWorklist =
1168  std::vector<std::pair<JITDylib *, SymbolStringPtr>>;
1169 
1170  static std::pair<AsynchronousSymbolQuerySet,
1171  std::shared_ptr<SymbolDependenceMap>>
1172  failSymbols(FailedSymbolsWorklist);
1173 
1174  ExecutionSession &ES;
1175  std::string JITDylibName;
1176  std::mutex GeneratorsMutex;
1177  bool Open = true;
1178  SymbolTable Symbols;
1179  UnmaterializedInfosMap UnmaterializedInfos;
1180  MaterializingInfosMap MaterializingInfos;
1181  std::vector<std::shared_ptr<DefinitionGenerator>> DefGenerators;
1182  JITDylibSearchOrder LinkOrder;
1183  ResourceTrackerSP DefaultTracker;
1184 
1185  // Map trackers to sets of symbols tracked.
1186  DenseMap<ResourceTracker *, SymbolNameVector> TrackerSymbols;
1187  DenseMap<MaterializationResponsibility *, ResourceTracker *> MRTrackers;
1188 };
1189 
1190 /// Platforms set up standard symbols and mediate interactions between dynamic
1191 /// initializers (e.g. C++ static constructors) and ExecutionSession state.
1192 /// Note that Platforms do not automatically run initializers: clients are still
1193 /// responsible for doing this.
1194 class Platform {
1195 public:
1196  virtual ~Platform();
1197 
1198  /// This method will be called outside the session lock each time a JITDylib
1199  /// is created (unless it is created with EmptyJITDylib set) to allow the
1200  /// Platform to install any JITDylib specific standard symbols (e.g
1201  /// __dso_handle).
1202  virtual Error setupJITDylib(JITDylib &JD) = 0;
1203 
1204  /// This method will be called under the ExecutionSession lock each time a
1205  /// MaterializationUnit is added to a JITDylib.
1206  virtual Error notifyAdding(ResourceTracker &RT,
1207  const MaterializationUnit &MU) = 0;
1208 
1209  /// This method will be called under the ExecutionSession lock when a
1210  /// ResourceTracker is removed.
1211  virtual Error notifyRemoving(ResourceTracker &RT) = 0;
1212 
1213  /// A utility function for looking up initializer symbols. Performs a blocking
1214  /// lookup for the given symbols in each of the given JITDylibs.
1217  const DenseMap<JITDylib *, SymbolLookupSet> &InitSyms);
1218 };
1219 
1220 /// Represents an abstract task for ORC to run.
1221 class Task : public RTTIExtends<Task, RTTIRoot> {
1222 public:
1223  static char ID;
1224 
1225  /// Description of the task to be performed. Used for logging.
1226  virtual void printDescription(raw_ostream &OS) = 0;
1227 
1228  /// Run the task.
1229  virtual void run() = 0;
1230 
1231 private:
1232  void anchor() override;
1233 };
1234 
1235 /// A materialization task.
1236 class MaterializationTask : public RTTIExtends<MaterializationTask, Task> {
1237 public:
1238  static char ID;
1239 
1240  MaterializationTask(std::unique_ptr<MaterializationUnit> MU,
1241  std::unique_ptr<MaterializationResponsibility> MR)
1242  : MU(std::move(MU)), MR(std::move(MR)) {}
1243  void printDescription(raw_ostream &OS) override;
1244  void run() override;
1245 
1246 private:
1247  std::unique_ptr<MaterializationUnit> MU;
1248  std::unique_ptr<MaterializationResponsibility> MR;
1249 };
1250 
1251 /// An ExecutionSession represents a running JIT program.
1255  friend class JITDylib;
1256  friend class LookupState;
1258  friend class ResourceTracker;
1259 
1260 public:
1261  /// For reporting errors.
1263 
1264  /// For dispatching ORC tasks (typically materialization tasks).
1265  using DispatchTaskFunction = unique_function<void(std::unique_ptr<Task> T)>;
1266 
1267  /// Construct an ExecutionSession.
1268  ///
1269  /// SymbolStringPools may be shared between ExecutionSessions.
1270  ExecutionSession(std::shared_ptr<SymbolStringPool> SSP = nullptr);
1271 
1272  /// End the session. Closes all JITDylibs.
1273  Error endSession();
1274 
1275  /// Add a symbol name to the SymbolStringPool and return a pointer to it.
1276  SymbolStringPtr intern(StringRef SymName) { return SSP->intern(SymName); }
1277 
1278  /// Returns a shared_ptr to the SymbolStringPool for this ExecutionSession.
1279  std::shared_ptr<SymbolStringPool> getSymbolStringPool() const { return SSP; }
1280 
1281  /// Set the Platform for this ExecutionSession.
1282  void setPlatform(std::unique_ptr<Platform> P) { this->P = std::move(P); }
1283 
1284  /// Get the Platform for this session.
1285  /// Will return null if no Platform has been set for this ExecutionSession.
1286  Platform *getPlatform() { return P.get(); }
1287 
1288  /// Run the given lambda with the session mutex locked.
1289  template <typename Func> decltype(auto) runSessionLocked(Func &&F) {
1290  std::lock_guard<std::recursive_mutex> Lock(SessionMutex);
1291  return F();
1292  }
1293 
1294  /// Register the given ResourceManager with this ExecutionSession.
1295  /// Managers will be notified of events in reverse order of registration.
1297 
1298  /// Deregister the given ResourceManager with this ExecutionSession.
1299  /// Manager must have been previously registered.
1301 
1302  /// Return a pointer to the "name" JITDylib.
1303  /// Ownership of JITDylib remains within Execution Session
1305 
1306  /// Add a new bare JITDylib to this ExecutionSession.
1307  ///
1308  /// The JITDylib Name is required to be unique. Clients should verify that
1309  /// names are not being re-used (E.g. by calling getJITDylibByName) if names
1310  /// are based on user input.
1311  ///
1312  /// This call does not install any library code or symbols into the newly
1313  /// created JITDylib. The client is responsible for all configuration.
1314  JITDylib &createBareJITDylib(std::string Name);
1315 
1316  /// Add a new JITDylib to this ExecutionSession.
1317  ///
1318  /// The JITDylib Name is required to be unique. Clients should verify that
1319  /// names are not being re-used (e.g. by calling getJITDylibByName) if names
1320  /// are based on user input.
1321  ///
1322  /// If a Platform is attached then Platform::setupJITDylib will be called to
1323  /// install standard platform symbols (e.g. standard library interposes).
1324  /// If no Platform is attached this call is equivalent to createBareJITDylib.
1326 
1327  /// Set the error reporter function.
1329  this->ReportError = std::move(ReportError);
1330  return *this;
1331  }
1332 
1333  /// Report a error for this execution session.
1334  ///
1335  /// Unhandled errors can be sent here to log them.
1336  void reportError(Error Err) { ReportError(std::move(Err)); }
1337 
1338  /// Set the task dispatch function.
1340  this->DispatchTask = std::move(DispatchTask);
1341  return *this;
1342  }
1343 
1344  /// Search the given JITDylibs to find the flags associated with each of the
1345  /// given symbols.
1346  void lookupFlags(LookupKind K, JITDylibSearchOrder SearchOrder,
1347  SymbolLookupSet Symbols,
1348  unique_function<void(Expected<SymbolFlagsMap>)> OnComplete);
1349 
1350  /// Blocking version of lookupFlags.
1352  JITDylibSearchOrder SearchOrder,
1353  SymbolLookupSet Symbols);
1354 
1355  /// Search the given JITDylibs for the given symbols.
1356  ///
1357  /// SearchOrder lists the JITDylibs to search. For each dylib, the associated
1358  /// boolean indicates whether the search should match against non-exported
1359  /// (hidden visibility) symbols in that dylib (true means match against
1360  /// non-exported symbols, false means do not match).
1361  ///
1362  /// The NotifyComplete callback will be called once all requested symbols
1363  /// reach the required state.
1364  ///
1365  /// If all symbols are found, the RegisterDependencies function will be called
1366  /// while the session lock is held. This gives clients a chance to register
1367  /// dependencies for on the queried symbols for any symbols they are
1368  /// materializing (if a MaterializationResponsibility instance is present,
1369  /// this can be implemented by calling
1370  /// MaterializationResponsibility::addDependencies). If there are no
1371  /// dependenant symbols for this query (e.g. it is being made by a top level
1372  /// client to get an address to call) then the value NoDependenciesToRegister
1373  /// can be used.
1374  void lookup(LookupKind K, const JITDylibSearchOrder &SearchOrder,
1375  SymbolLookupSet Symbols, SymbolState RequiredState,
1376  SymbolsResolvedCallback NotifyComplete,
1377  RegisterDependenciesFunction RegisterDependencies);
1378 
1379  /// Blocking version of lookup above. Returns the resolved symbol map.
1380  /// If WaitUntilReady is true (the default), will not return until all
1381  /// requested symbols are ready (or an error occurs). If WaitUntilReady is
1382  /// false, will return as soon as all requested symbols are resolved,
1383  /// or an error occurs. If WaitUntilReady is false and an error occurs
1384  /// after resolution, the function will return a success value, but the
1385  /// error will be reported via reportErrors.
1386  Expected<SymbolMap> lookup(const JITDylibSearchOrder &SearchOrder,
1387  const SymbolLookupSet &Symbols,
1389  SymbolState RequiredState = SymbolState::Ready,
1390  RegisterDependenciesFunction RegisterDependencies =
1392 
1393  /// Convenience version of blocking lookup.
1394  /// Searches each of the JITDylibs in the search order in turn for the given
1395  /// symbol.
1397  lookup(const JITDylibSearchOrder &SearchOrder, SymbolStringPtr Symbol,
1398  SymbolState RequiredState = SymbolState::Ready);
1399 
1400  /// Convenience version of blocking lookup.
1401  /// Searches each of the JITDylibs in the search order in turn for the given
1402  /// symbol. The search will not find non-exported symbols.
1405  SymbolState RequiredState = SymbolState::Ready);
1406 
1407  /// Convenience version of blocking lookup.
1408  /// Searches each of the JITDylibs in the search order in turn for the given
1409  /// symbol. The search will not find non-exported symbols.
1412  SymbolState RequiredState = SymbolState::Ready);
1413 
1414  /// Materialize the given unit.
1415  void dispatchTask(std::unique_ptr<Task> T) {
1416  assert(T && "T must be non-null");
1417  DEBUG_WITH_TYPE("orc", dumpDispatchInfo(*T));
1418  DispatchTask(std::move(T));
1419  }
1420 
1421  /// Dump the state of all the JITDylibs in this session.
1422  void dump(raw_ostream &OS);
1423 
1424 private:
1425  static void logErrorsToStdErr(Error Err) {
1426  logAllUnhandledErrors(std::move(Err), errs(), "JIT session error: ");
1427  }
1428 
1429  static void runOnCurrentThread(std::unique_ptr<Task> T) { T->run(); }
1430 
1431  void dispatchOutstandingMUs();
1432 
1433  static std::unique_ptr<MaterializationResponsibility>
1434  createMaterializationResponsibility(ResourceTracker &RT,
1435  SymbolFlagsMap Symbols,
1436  SymbolStringPtr InitSymbol) {
1437  auto &JD = RT.getJITDylib();
1438  std::unique_ptr<MaterializationResponsibility> MR(
1439  new MaterializationResponsibility(&JD, std::move(Symbols),
1440  std::move(InitSymbol)));
1441  JD.MRTrackers[MR.get()] = &RT;
1442  return MR;
1443  }
1444 
1445  Error removeResourceTracker(ResourceTracker &RT);
1446  void transferResourceTracker(ResourceTracker &DstRT, ResourceTracker &SrcRT);
1447  void destroyResourceTracker(ResourceTracker &RT);
1448 
1449  // State machine functions for query application..
1450 
1451  /// IL_updateCandidatesFor is called to remove already-defined symbols that
1452  /// match a given query from the set of candidate symbols to generate
1453  /// definitions for (no need to generate a definition if one already exists).
1454  Error IL_updateCandidatesFor(JITDylib &JD, JITDylibLookupFlags JDLookupFlags,
1455  SymbolLookupSet &Candidates,
1456  SymbolLookupSet *NonCandidates);
1457 
1458  /// OL_applyQueryPhase1 is an optionally re-startable loop for triggering
1459  /// definition generation. It is called when a lookup is performed, and again
1460  /// each time that LookupState::continueLookup is called.
1461  void OL_applyQueryPhase1(std::unique_ptr<InProgressLookupState> IPLS,
1462  Error Err);
1463 
1464  /// OL_completeLookup is run once phase 1 successfully completes for a lookup
1465  /// call. It attempts to attach the symbol to all symbol table entries and
1466  /// collect all MaterializationUnits to dispatch. If this method fails then
1467  /// all MaterializationUnits will be left un-materialized.
1468  void OL_completeLookup(std::unique_ptr<InProgressLookupState> IPLS,
1469  std::shared_ptr<AsynchronousSymbolQuery> Q,
1470  RegisterDependenciesFunction RegisterDependencies);
1471 
1472  /// OL_completeLookupFlags is run once phase 1 successfully completes for a
1473  /// lookupFlags call.
1474  void OL_completeLookupFlags(
1475  std::unique_ptr<InProgressLookupState> IPLS,
1476  unique_function<void(Expected<SymbolFlagsMap>)> OnComplete);
1477 
1478  // State machine functions for MaterializationResponsibility.
1479  void OL_destroyMaterializationResponsibility(
1481  SymbolNameSet OL_getRequestedSymbols(const MaterializationResponsibility &MR);
1482  Error OL_notifyResolved(MaterializationResponsibility &MR,
1483  const SymbolMap &Symbols);
1484  Error OL_notifyEmitted(MaterializationResponsibility &MR);
1485  Error OL_defineMaterializing(MaterializationResponsibility &MR,
1487  void OL_notifyFailed(MaterializationResponsibility &MR);
1488  Error OL_replace(MaterializationResponsibility &MR,
1489  std::unique_ptr<MaterializationUnit> MU);
1490  Expected<std::unique_ptr<MaterializationResponsibility>>
1491  OL_delegate(MaterializationResponsibility &MR, const SymbolNameSet &Symbols);
1492  void OL_addDependencies(MaterializationResponsibility &MR,
1493  const SymbolStringPtr &Name,
1494  const SymbolDependenceMap &Dependencies);
1495  void OL_addDependenciesForAll(MaterializationResponsibility &MR,
1496  const SymbolDependenceMap &Dependencies);
1497 
1498 #ifndef NDEBUG
1499  void dumpDispatchInfo(Task &T);
1500 #endif // NDEBUG
1501 
1502  mutable std::recursive_mutex SessionMutex;
1503  bool SessionOpen = true;
1504  std::shared_ptr<SymbolStringPool> SSP;
1505  std::unique_ptr<Platform> P;
1506  ErrorReporter ReportError = logErrorsToStdErr;
1507  DispatchTaskFunction DispatchTask = runOnCurrentThread;
1508 
1509  std::vector<ResourceManager *> ResourceManagers;
1510 
1511  std::vector<JITDylibSP> JDs;
1512 
1513  // FIXME: Remove this (and runOutstandingMUs) once the linking layer works
1514  // with callbacks from asynchronous queries.
1515  mutable std::recursive_mutex OutstandingMUsMutex;
1516  std::vector<std::pair<std::unique_ptr<MaterializationUnit>,
1517  std::unique_ptr<MaterializationResponsibility>>>
1518  OutstandingMUs;
1519 };
1520 
1522  return JD->getExecutionSession();
1523 }
1524 
1525 template <typename Func>
1527  return JD->getExecutionSession().runSessionLocked([&]() -> Error {
1528  auto I = JD->MRTrackers.find(this);
1529  assert(I != JD->MRTrackers.end() && "No tracker for this MR");
1530  if (I->second->isDefunct())
1531  return make_error<ResourceTrackerDefunct>(I->second);
1532  F(I->second->getKeyUnsafe());
1533  return Error::success();
1534  });
1535 }
1536 
1537 template <typename GeneratorT>
1538 GeneratorT &JITDylib::addGenerator(std::unique_ptr<GeneratorT> DefGenerator) {
1539  auto &G = *DefGenerator;
1540  std::lock_guard<std::mutex> Lock(GeneratorsMutex);
1541  DefGenerators.push_back(std::move(DefGenerator));
1542  return G;
1543 }
1544 
1545 template <typename Func>
1547  -> decltype(F(std::declval<const JITDylibSearchOrder &>())) {
1548  return ES.runSessionLocked([&]() { return F(LinkOrder); });
1549 }
1550 
1551 template <typename MaterializationUnitType>
1552 Error JITDylib::define(std::unique_ptr<MaterializationUnitType> &&MU,
1553  ResourceTrackerSP RT) {
1554  assert(MU && "Can not define with a null MU");
1555 
1556  if (MU->getSymbols().empty()) {
1557  // Empty MUs are allowable but pathological, so issue a warning.
1558  DEBUG_WITH_TYPE("orc", {
1559  dbgs() << "Warning: Discarding empty MU " << MU->getName() << " for "
1560  << getName() << "\n";
1561  });
1562  return Error::success();
1563  } else
1564  DEBUG_WITH_TYPE("orc", {
1565  dbgs() << "Defining MU " << MU->getName() << " for " << getName()
1566  << " (tracker: ";
1567  if (RT == getDefaultResourceTracker())
1568  dbgs() << "default)";
1569  else if (RT)
1570  dbgs() << RT.get() << ")\n";
1571  else
1572  dbgs() << "0x0, default will be used)\n";
1573  });
1574 
1575  return ES.runSessionLocked([&, this]() -> Error {
1576  if (auto Err = defineImpl(*MU))
1577  return Err;
1578 
1579  if (!RT)
1581 
1582  if (auto *P = ES.getPlatform()) {
1583  if (auto Err = P->notifyAdding(*RT, *MU))
1584  return Err;
1585  }
1586 
1587  installMaterializationUnit(std::move(MU), *RT);
1588  return Error::success();
1589  });
1590 }
1591 
1592 template <typename MaterializationUnitType>
1593 Error JITDylib::define(std::unique_ptr<MaterializationUnitType> &MU,
1594  ResourceTrackerSP RT) {
1595  assert(MU && "Can not define with a null MU");
1596 
1597  if (MU->getSymbols().empty()) {
1598  // Empty MUs are allowable but pathological, so issue a warning.
1599  DEBUG_WITH_TYPE("orc", {
1600  dbgs() << "Warning: Discarding empty MU " << MU->getName() << getName()
1601  << "\n";
1602  });
1603  return Error::success();
1604  } else
1605  DEBUG_WITH_TYPE("orc", {
1606  dbgs() << "Defining MU " << MU->getName() << " for " << getName()
1607  << " (tracker: ";
1608  if (RT == getDefaultResourceTracker())
1609  dbgs() << "default)";
1610  else if (RT)
1611  dbgs() << RT.get() << ")\n";
1612  else
1613  dbgs() << "0x0, default will be used)\n";
1614  });
1615 
1616  return ES.runSessionLocked([&, this]() -> Error {
1617  if (auto Err = defineImpl(*MU))
1618  return Err;
1619 
1620  if (!RT)
1622 
1623  if (auto *P = ES.getPlatform()) {
1624  if (auto Err = P->notifyAdding(*RT, *MU))
1625  return Err;
1626  }
1627 
1628  installMaterializationUnit(std::move(MU), *RT);
1629  return Error::success();
1630  });
1631 }
1632 
1633 /// ReexportsGenerator can be used with JITDylib::addGenerator to automatically
1634 /// re-export a subset of the source JITDylib's symbols in the target.
1636 public:
1638 
1639  /// Create a reexports generator. If an Allow predicate is passed, only
1640  /// symbols for which the predicate returns true will be reexported. If no
1641  /// Allow predicate is passed, all symbols will be exported.
1642  ReexportsGenerator(JITDylib &SourceJD,
1643  JITDylibLookupFlags SourceJDLookupFlags,
1644  SymbolPredicate Allow = SymbolPredicate());
1645 
1647  JITDylibLookupFlags JDLookupFlags,
1648  const SymbolLookupSet &LookupSet) override;
1649 
1650 private:
1651  JITDylib &SourceJD;
1652  JITDylibLookupFlags SourceJDLookupFlags;
1653  SymbolPredicate Allow;
1654 };
1655 
1656 // --------------- IMPLEMENTATION --------------
1657 // Implementations for inline functions/methods.
1658 // ---------------------------------------------
1659 
1661  JD->getExecutionSession().OL_destroyMaterializationResponsibility(*this);
1662 }
1663 
1665  return JD->getExecutionSession().OL_getRequestedSymbols(*this);
1666 }
1667 
1669  const SymbolMap &Symbols) {
1670  return JD->getExecutionSession().OL_notifyResolved(*this, Symbols);
1671 }
1672 
1674  return JD->getExecutionSession().OL_notifyEmitted(*this);
1675 }
1676 
1679  return JD->getExecutionSession().OL_defineMaterializing(
1680  *this, std::move(SymbolFlags));
1681 }
1682 
1684  JD->getExecutionSession().OL_notifyFailed(*this);
1685 }
1686 
1688  std::unique_ptr<MaterializationUnit> MU) {
1689  return JD->getExecutionSession().OL_replace(*this, std::move(MU));
1690 }
1691 
1694  return JD->getExecutionSession().OL_delegate(*this, Symbols);
1695 }
1696 
1698  const SymbolStringPtr &Name, const SymbolDependenceMap &Dependencies) {
1699  JD->getExecutionSession().OL_addDependencies(*this, Name, Dependencies);
1700 }
1701 
1703  const SymbolDependenceMap &Dependencies) {
1704  JD->getExecutionSession().OL_addDependenciesForAll(*this, Dependencies);
1705 }
1706 
1707 } // End namespace orc
1708 } // End namespace llvm
1709 
1710 #endif // LLVM_EXECUTIONENGINE_ORC_CORE_H
llvm::orc::ResourceKey
uintptr_t ResourceKey
Definition: Core.h:48
llvm::orc::MaterializationResponsibility::replace
Error replace(std::unique_ptr< MaterializationUnit > MU)
Transfers responsibility to the given MaterializationUnit for all symbols defined by that Materializa...
Definition: Core.h:1687
llvm::orc::MaterializationTask
A materialization task.
Definition: Core.h:1236
llvm::orc::MaterializationResponsibility
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Definition: Core.h:492
llvm::orc::MaterializationTask::MaterializationTask
MaterializationTask(std::unique_ptr< MaterializationUnit > MU, std::unique_ptr< MaterializationResponsibility > MR)
Definition: Core.h:1240
llvm::orc::JITDylib::withLinkOrderDo
auto withLinkOrderDo(Func &&F) -> decltype(F(std::declval< const JITDylibSearchOrder & >()))
Do something with the link order (run under the session lock).
Definition: Core.h:1546
llvm::orc::Task::ID
static char ID
Definition: Core.h:1223
llvm
Definition: AllocatorList.h:23
llvm::orc::SymbolsNotFound::log
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: Core.cpp:108
llvm::orc::JITDylib
A symbol table that supports asynchoronous symbol queries.
Definition: Core.h:894
llvm::orc::ReexportsGenerator::tryToGenerate
Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD, JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &LookupSet) override
DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.
Definition: Core.cpp:569
llvm::orc::MaterializationUnit::MaterializationUnit
MaterializationUnit(SymbolFlagsMap InitalSymbolFlags, SymbolStringPtr InitSymbol)
Definition: Core.h:643
JITSymbol.h
llvm::lltok::Error
@ Error
Definition: LLToken.h:21
FunctionExtras.h
llvm::orc::SymbolLookupSet::remove_if
void remove_if(PredFn &&Pred)
Removes all elements matching the given predicate, which must be callable as bool(const SymbolStringP...
Definition: Core.h:255
llvm::orc::AsynchronousSymbolQuery::notifySymbolMetRequiredState
void notifySymbolMetRequiredState(const SymbolStringPtr &Name, JITEvaluatedSymbol Sym)
Notify the query that a requested symbol has reached the required state.
Definition: Core.cpp:157
llvm::orc::SymbolLookupSet::UnderlyingVector
std::vector< value_type > UnderlyingVector
Definition: Core.h:176
llvm::orc::SymbolState::Materializing
@ Materializing
Added to the symbol table, never queried.
llvm::orc::JITDylib::setLinkOrder
void setLinkOrder(JITDylibSearchOrder NewSearchOrder, bool LinkAgainstThisJITDylibFirst=true)
Set the link order to be used when fixing up definitions in JITDylib.
Definition: Core.cpp:1264
llvm::orc::DefinitionGenerator::~DefinitionGenerator
virtual ~DefinitionGenerator()
Definition: Core.cpp:610
llvm::orc::ExecutionSession::reportError
void reportError(Error Err)
Report a error for this execution session.
Definition: Core.h:1336
llvm::orc::InProgressLookupState
Definition: Core.cpp:484
llvm::unique_function< void(Expected< SymbolMap >)>
llvm::orc::ExecutionSession::DispatchTaskFunction
unique_function< void(std::unique_ptr< Task > T)> DispatchTaskFunction
For dispatching ORC tasks (typically materialization tasks).
Definition: Core.h:1265
llvm::orc::MaterializationUnit::materialize
virtual void materialize(std::unique_ptr< MaterializationResponsibility > R)=0
Implementations of this method should materialize all symbols in the materialzation unit,...
llvm::orc::SymbolsCouldNotBeRemoved::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: Core.cpp:117
llvm::orc::ResourceTrackerDefunct
Definition: Core.h:391
llvm::orc::JITDylib::addToLinkOrder
void addToLinkOrder(JITDylib &JD, JITDylibLookupFlags JDLookupFlags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Add the given JITDylib to the link order for definitions in this JITDylib.
Definition: Core.cpp:1278
llvm::orc::ExecutionSession::getJITDylibByName
JITDylib * getJITDylibByName(StringRef Name)
Return a pointer to the "name" JITDylib.
Definition: Core.cpp:1798
llvm::orc::LookupState::operator=
LookupState & operator=(LookupState &&)
llvm::orc::ResourceTrackerDefunct::ID
static char ID
Definition: Core.h:393
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::orc::JITDylib::dump
void dump(raw_ostream &OS)
Dump current JITDylib state to OS.
Definition: Core.cpp:1360
llvm::orc::JITDylib::getDefaultResourceTracker
ResourceTrackerSP getDefaultResourceTracker()
Get the default resource tracker for this JITDylib.
Definition: Core.cpp:626
llvm::orc::JITDylib::ExecutionSession
friend class ExecutionSession
Definition: Core.h:897
llvm::orc::AbsoluteSymbolsMaterializationUnit
A MaterializationUnit implementation for pre-existing absolute symbols.
Definition: Core.h:694
llvm::orc::ResourceTrackerDefunct::log
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: Core.cpp:75
llvm::orc::SymbolAliasMapEntry::SymbolAliasMapEntry
SymbolAliasMapEntry(SymbolStringPtr Aliasee, JITSymbolFlags AliasFlags)
Definition: Core.h:370
llvm::orc::MaterializationResponsibility::notifyResolved
Error notifyResolved(const SymbolMap &Symbols)
Notifies the target JITDylib that the given symbols have been resolved.
Definition: Core.h:1668
llvm::orc::MaterializationUnit::doDiscard
void doDiscard(const JITDylib &JD, const SymbolStringPtr &Name)
Called by JITDylibs to notify MaterializationUnits that the given symbol has been overridden.
Definition: Core.h:671
llvm::orc::SymbolLookupSet
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Definition: Core.h:173
llvm::orc::Platform::~Platform
virtual ~Platform()
Definition: Core.cpp:1702
llvm::orc::LookupKind::Static
@ Static
llvm::orc::SymbolsCouldNotBeRemoved::getSymbols
const SymbolNameSet & getSymbols() const
Definition: Core.h:441
llvm::orc::SymbolStringPtr
Pointer to a pooled string representing a symbol name.
Definition: SymbolStringPool.h:50
llvm::orc::ReExportsMaterializationUnit::getName
StringRef getName() const override
Return the name of this materialization unit.
Definition: Core.cpp:277
llvm::orc::MaterializationResponsibility::defineNonExistent
void defineNonExistent(ArrayRef< SymbolStringPtr > Symbols)
Define the given symbols as non-existent, removing it from the symbol table and notifying any pending...
llvm::orc::ResourceManager::~ResourceManager
virtual ~ResourceManager()
Definition: Core.cpp:66
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:332
llvm::orc::JITDylib::clear
Error clear()
Calls remove on all trackers currently associated with this JITDylib.
Definition: Core.cpp:612
llvm::orc::ExecutionSession::ResourceTracker
friend class ResourceTracker
Definition: Core.h:1258
llvm::orc::ReExportsMaterializationUnit
A materialization unit for symbol aliases.
Definition: Core.h:726
llvm::DenseMapBase::erase
bool erase(const KeyT &Val)
Definition: DenseMap.h:302
llvm::orc::SymbolsCouldNotBeRemoved
Used to notify clients that a set of symbols could not be removed.
Definition: Core.h:434
llvm::orc::FailedToMaterialize::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: Core.cpp:85
llvm::orc::LookupState::~LookupState
~LookupState()
llvm::orc::SymbolState::Invalid
@ Invalid
llvm::orc::ResourceTracker
API to remove / transfer ownership of JIT resources.
Definition: Core.h:51
llvm::orc::SymbolLookupSet::end
const_iterator end() const
Definition: Core.h:241
llvm::orc::MaterializationResponsibility::defineMaterializing
Error defineMaterializing(SymbolFlagsMap SymbolFlags)
Attempt to claim responsibility for new definitions.
Definition: Core.h:1677
llvm::orc::ExecutionSession::registerResourceManager
void registerResourceManager(ResourceManager &RM)
Register the given ResourceManager with this ExecutionSession.
Definition: Core.cpp:1781
llvm::orc::MaterializationTask::run
void run() override
Definition: Core.cpp:1760
llvm::DenseMapBase::count
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:145
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::orc::UnexpectedSymbolDefinitions::UnexpectedSymbolDefinitions
UnexpectedSymbolDefinitions(std::string ModuleName, SymbolNameVector Symbols)
Definition: Core.h:474
llvm::orc::FailedToMaterialize::getSymbols
const SymbolDependenceMap & getSymbols() const
Definition: Core.h:412
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:892
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::orc::LookupState::continueLookup
void continueLookup(Error Err)
Continue the lookup.
Definition: Core.cpp:604
llvm::orc::UnexpectedSymbolDefinitions
Errors of this type should be returned if a module contains definitions for symbols that are not clai...
Definition: Core.h:470
llvm::orc::SymbolsNotFound::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: Core.cpp:104
IntrusiveRefCntPtr.h
llvm::orc::LookupKind
LookupKind
Describes the kind of lookup being performed.
Definition: Core.h:147
ExtensibleRTTI.h
llvm::JITSymbolFlags
Flags for symbols in the JIT.
Definition: JITSymbol.h:74
llvm::MachO::SymbolFlags
SymbolFlags
Symbol flags.
Definition: Symbol.h:25
llvm::orc::MaterializationUnit
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
Definition: Core.h:636
llvm::orc::ExecutionSession::dispatchTask
void dispatchTask(std::unique_ptr< Task > T)
Materialize the given unit.
Definition: Core.h:1415
llvm::orc::ExecutionSession::JITDylib
friend class JITDylib
Definition: Core.h:1255
llvm::orc::SymbolLookupSet::sortByName
void sortByName()
Sort the lookup set lexicographically.
Definition: Core.h:336
llvm::orc::MissingSymbolDefinitions::getModuleName
const std::string & getModuleName() const
Definition: Core.h:459
llvm::JITEvaluatedSymbol
Represents a symbol that has been evaluated to an address already.
Definition: JITSymbol.h:229
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::RISCVFenceField::R
@ R
Definition: RISCVBaseInfo.h:180
llvm::orc::JITDylib::createResourceTracker
ResourceTrackerSP createResourceTracker()
Create a resource tracker for this JITDylib.
Definition: Core.cpp:634
llvm::orc::FailedToMaterialize::ID
static char ID
Definition: Core.h:407
llvm::orc::MaterializationUnit::getName
virtual StringRef getName() const =0
Return the name of this materialization unit.
llvm::orc::Platform::notifyRemoving
virtual Error notifyRemoving(ResourceTracker &RT)=0
This method will be called under the ExecutionSession lock when a ResourceTracker is removed.
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
llvm::Lock
static sys::Mutex Lock
Definition: NVPTXUtilities.cpp:39
llvm::orc::RegisterDependenciesFunction
std::function< void(const SymbolDependenceMap &)> RegisterDependenciesFunction
Callback to register the dependencies for a given query.
Definition: Core.h:385
llvm::orc::JITDylib::replaceInLinkOrder
void replaceInLinkOrder(JITDylib &OldJD, JITDylib &NewJD, JITDylibLookupFlags JDLookupFlags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Replace OldJD with NewJD in the link order if OldJD is present.
Definition: Core.cpp:1282
llvm::orc::JITDylib::JITDylib
JITDylib(const JITDylib &)=delete
llvm::orc::ResourceTracker::getJITDylib
JITDylib & getJITDylib() const
Return the JITDylib targeted by this tracker.
Definition: Core.h:66
llvm::orc::ExecutionSession::dump
void dump(raw_ostream &OS)
Dump the state of all the JITDylibs in this session.
Definition: Core.cpp:2008
llvm::orc::SymbolLookupSet::SymbolLookupSet
SymbolLookupSet(SymbolStringPtr Name, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Definition: Core.h:182
llvm::orc::Task::printDescription
virtual void printDescription(raw_ostream &OS)=0
Description of the task to be performed. Used for logging.
llvm::orc::SymbolState
SymbolState
Represents the state that a symbol has reached during materialization.
Definition: Core.h:786
SymbolStringPool.h
DEBUG_WITH_TYPE
#define DEBUG_WITH_TYPE(TYPE, X)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
Definition: Debug.h:64
llvm::orc::SymbolLookupSet::SymbolLookupSet
SymbolLookupSet(std::initializer_list< SymbolStringPtr > Names, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Construct a SymbolLookupSet from an initializer list of SymbolStringPtrs.
Definition: Core.h:189
llvm::orc::MissingSymbolDefinitions::log
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: Core.cpp:129
llvm::orc::SymbolLookupFlags
SymbolLookupFlags
Lookup flags that apply to each symbol in a lookup.
Definition: Core.h:135
llvm::orc::MaterializationResponsibility::getSymbols
const SymbolFlagsMap & getSymbols() const
Returns the symbol flags map for this responsibility instance.
Definition: Core.h:519
llvm::orc::SymbolLookupSet::forEachWithRemoval
auto forEachWithRemoval(BodyFn &&Body) -> std::enable_if_t< std::is_same< decltype(Body(std::declval< const SymbolStringPtr & >(), std::declval< SymbolLookupFlags >())), bool >::value >
Loop over the elements of this SymbolLookupSet, applying the Body function to each one.
Definition: Core.h:273
llvm::orc::UnexpectedSymbolDefinitions::log
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: Core.cpp:138
llvm::orc::UnexpectedSymbolDefinitions::getModuleName
const std::string & getModuleName() const
Definition: Core.h:478
llvm::orc::Platform::setupJITDylib
virtual Error setupJITDylib(JITDylib &JD)=0
This method will be called outside the session lock each time a JITDylib is created (unless it is cre...
llvm::orc::SymbolLookupSet::end
iterator end()
Definition: Core.h:239
llvm::orc::Platform::lookupInitSymbols
static Expected< DenseMap< JITDylib *, SymbolMap > > lookupInitSymbols(ExecutionSession &ES, const DenseMap< JITDylib *, SymbolLookupSet > &InitSyms)
A utility function for looking up initializer symbols.
Definition: Core.cpp:1704
llvm::orc::SymbolLookupSet::containsDuplicates
bool containsDuplicates()
Returns true if this set contains any duplicates.
Definition: Core.h:353
llvm::orc::SymbolsNotFound
Used to notify clients when symbols can not be found during a lookup.
Definition: Core.h:419
llvm::orc::Platform::notifyAdding
virtual Error notifyAdding(ResourceTracker &RT, const MaterializationUnit &MU)=0
This method will be called under the ExecutionSession lock each time a MaterializationUnit is added t...
llvm::orc::UnexpectedSymbolDefinitions::ID
static char ID
Definition: Core.h:472
llvm::orc::SymbolLookupSet::remove
void remove(iterator I)
Removes the element pointed to by the given iterator.
Definition: Core.h:251
llvm::orc::SymbolLookupSet::SymbolLookupSet
SymbolLookupSet(ArrayRef< SymbolStringPtr > Names, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Construct a SymbolLookupSet from a vector of symbols with the given Flags used for each value.
Definition: Core.h:211
llvm::orc::NoDependenciesToRegister
RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
Definition: Core.cpp:35
llvm::orc::AsynchronousSymbolQuery::JITSymbolResolverAdapter
friend class JITSymbolResolverAdapter
Definition: Core.h:803
llvm::orc::MaterializationResponsibility::notifyEmitted
Error notifyEmitted()
Notifies the target JITDylib (and any pending queries on that JITDylib) that all symbols covered by t...
Definition: Core.h:1673
DenseSet.h
false
Definition: StackSlotColoring.cpp:142
llvm::orc::SymbolMap
DenseMap< SymbolStringPtr, JITEvaluatedSymbol > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
Definition: Core.h:111
llvm::orc::MaterializationResponsibility::addDependenciesForAll
void addDependenciesForAll(const SymbolDependenceMap &Dependencies)
Add dependencies that apply to all symbols covered by this instance.
Definition: Core.h:1702
llvm::orc::SymbolLookupSet::SymbolLookupSet
SymbolLookupSet(const SymbolNameSet &Names, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Construct a SymbolLookupSet from a SymbolNameSet with the given Flags used for each value.
Definition: Core.h:199
llvm::orc::ExecutionSession::intern
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
Definition: Core.h:1276
llvm::detail::DenseSetImpl::size
size_type size() const
Definition: DenseSet.h:81
llvm::ThreadSafeRefCountedBase
A thread-safe version of RefCountedBase.
Definition: IntrusiveRefCntPtr.h:101
llvm::orc::MaterializationUnit::~MaterializationUnit
virtual ~MaterializationUnit()
Definition: Core.h:651
llvm::orc::JITDylib::addGenerator
GeneratorT & addGenerator(std::unique_ptr< GeneratorT > DefGenerator)
Adds a definition generator to this JITDylib and returns a referenece to it.
Definition: Core.h:1538
llvm::orc::AsynchronousSymbolQuery
A symbol query that returns results via a callback when results are ready.
Definition: Core.h:799
llvm::orc::ExecutionSession::runSessionLocked
decltype(auto) runSessionLocked(Func &&F)
Run the given lambda with the session mutex locked.
Definition: Core.h:1289
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
llvm::orc::LookupKind::DLSym
@ DLSym
llvm::orc::SymbolLookupSet::add
SymbolLookupSet & add(SymbolStringPtr Name, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Add an element to the set.
Definition: Core.h:222
llvm::orc::AbsoluteSymbolsMaterializationUnit::getName
StringRef getName() const override
Return the name of this materialization unit.
Definition: Core.cpp:246
llvm::orc::MaterializationResponsibility::operator=
MaterializationResponsibility & operator=(MaterializationResponsibility &&)=delete
llvm::orc::FailedToMaterialize::FailedToMaterialize
FailedToMaterialize(std::shared_ptr< SymbolDependenceMap > Symbols)
Definition: Core.cpp:79
llvm::orc::SymbolsNotFound::ID
static char ID
Definition: Core.h:421
llvm::RTTIExtends
Inheritance utility for extensible RTTI.
Definition: ExtensibleRTTI.h:66
llvm::orc::ExecutionSession::setPlatform
void setPlatform(std::unique_ptr< Platform > P)
Set the Platform for this ExecutionSession.
Definition: Core.h:1282
llvm::orc::Task::run
virtual void run()=0
Run the task.
llvm::orc::SymbolLookupFlags::WeaklyReferencedSymbol
@ WeaklyReferencedSymbol
llvm::orc::SymbolLookupSet::remove
void remove(UnderlyingVector::size_type I)
Removes the Ith element of the vector, replacing it with the last element.
Definition: Core.h:244
llvm::orc::MaterializationResponsibility::getRequestedSymbols
SymbolNameSet getRequestedSymbols() const
Returns the names of any symbols covered by this MaterializationResponsibility object that have queri...
Definition: Core.h:1664
llvm::orc::UnexpectedSymbolDefinitions::getSymbols
const SymbolNameVector & getSymbols() const
Definition: Core.h:479
llvm::orc::ExecutionSession::createBareJITDylib
JITDylib & createBareJITDylib(std::string Name)
Add a new bare JITDylib to this ExecutionSession.
Definition: Core.cpp:1807
llvm::orc::ExecutionSession::endSession
Error endSession()
End the session. Closes all JITDylibs.
Definition: Core.cpp:1765
llvm::orc::SymbolLookupSet::size
UnderlyingVector::size_type size() const
Definition: Core.h:237
llvm::orc::MaterializationResponsibility::getInitializerSymbol
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization pseudo-symbol, if any.
Definition: Core.h:524
llvm::orc::MaterializationResponsibility::withResourceKeyDo
Error withResourceKeyDo(Func &&F) const
Returns the ResourceTracker for this instance.
Definition: Core.h:1526
llvm::orc::ExecutionSession::ExecutionSession
ExecutionSession(std::shared_ptr< SymbolStringPool > SSP=nullptr)
Construct an ExecutionSession.
Definition: Core.cpp:1762
llvm::orc::MaterializationTask::printDescription
void printDescription(raw_ostream &OS) override
Definition: Core.cpp:1755
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
llvm::DenseSet< SymbolStringPtr >
llvm::orc::InProgressLookupFlagsState
Definition: Core.cpp:509
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:179
llvm::orc::MissingSymbolDefinitions
Errors of this type should be returned if a module fails to include definitions that are claimed by t...
Definition: Core.h:451
llvm::orc::JITDylib::MaterializationResponsibility
friend class MaterializationResponsibility
Definition: Core.h:899
llvm::orc::MaterializationResponsibility::getTargetJITDylib
JITDylib & getTargetJITDylib() const
Returns the target JITDylib that these symbols are being materialized into.
Definition: Core.h:510
llvm::orc::SymbolLookupSet::value_type
std::pair< SymbolStringPtr, SymbolLookupFlags > value_type
Definition: Core.h:175
llvm::orc::ExecutionSession::setDispatchTask
ExecutionSession & setDispatchTask(DispatchTaskFunction DispatchTask)
Set the task dispatch function.
Definition: Core.h:1339
llvm::orc::SymbolLookupSet::append
SymbolLookupSet & append(SymbolLookupSet Other)
Quickly append one lookup set to another.
Definition: Core.h:229
llvm::orc::MaterializationUnit::getInitializerSymbol
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization symbol for this MaterializationUnit (if any).
Definition: Core.h:661
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:80
llvm::orc::ExecutionSession::lookupFlags
void lookupFlags(LookupKind K, JITDylibSearchOrder SearchOrder, SymbolLookupSet Symbols, unique_function< void(Expected< SymbolFlagsMap >)> OnComplete)
Search the given JITDylibs to find the flags associated with each of the given symbols.
Definition: Core.cpp:1873
llvm::orc::ResourceTracker::isDefunct
bool isDefunct() const
Return true if this tracker has become defunct.
Definition: Core.h:79
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< SymbolStringPtr, JITEvaluatedSymbol >
llvm::orc::MissingSymbolDefinitions::MissingSymbolDefinitions
MissingSymbolDefinitions(std::string ModuleName, SymbolNameVector Symbols)
Definition: Core.h:455
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::orc::JITDylib::AsynchronousSymbolQuerySet
std::set< std::shared_ptr< AsynchronousSymbolQuery > > AsynchronousSymbolQuerySet
Definition: Core.h:903
llvm::orc::MaterializationUnit::getSymbols
const SymbolFlagsMap & getSymbols() const
Return the set of symbols that this source provides.
Definition: Core.h:658
llvm::orc::SymbolLookupSet::forEachWithRemoval
auto forEachWithRemoval(BodyFn &&Body) -> std::enable_if_t< std::is_same< decltype(Body(std::declval< const SymbolStringPtr & >(), std::declval< SymbolLookupFlags >())), Expected< bool >>::value, Error >
Loop over the elements of this SymbolLookupSet, applying the Body function to each one.
Definition: Core.h:295
llvm::orc::MaterializationResponsibility::addDependencies
void addDependencies(const SymbolStringPtr &Name, const SymbolDependenceMap &Dependencies)
Definition: Core.h:1697
llvm::orc::SymbolState::NeverSearched
@ NeverSearched
No symbol should be in this state.
llvm::orc::ResourceTrackerSP
uint8_t IntrusiveRefCntPtr< ResourceTracker > ResourceTrackerSP
Definition: Core.h:45
llvm::orc::ReexportsGenerator::ReexportsGenerator
ReexportsGenerator(JITDylib &SourceJD, JITDylibLookupFlags SourceJDLookupFlags, SymbolPredicate Allow=SymbolPredicate())
Create a reexports generator.
Definition: Core.cpp:563
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::orc::AbsoluteSymbolsMaterializationUnit::AbsoluteSymbolsMaterializationUnit
AbsoluteSymbolsMaterializationUnit(SymbolMap Symbols)
Definition: Core.cpp:241
OrcV1Deprecation.h
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:1540
llvm::orc::ResourceTracker::getKeyUnsafe
ResourceKey getKeyUnsafe() const
Returns the key associated with this tracker.
Definition: Core.h:84
llvm::orc::JITDylib::AsynchronousSymbolQuery
friend class AsynchronousSymbolQuery
Definition: Core.h:896
std::swap
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:840
llvm::orc::JITDylibSP
IntrusiveRefCntPtr< JITDylib > JITDylibSP
Definition: Core.h:46
llvm::orc::SymbolAliasMapEntry::SymbolAliasMapEntry
SymbolAliasMapEntry()=default
llvm::orc::JITDylib::remove
Error remove(const SymbolNameSet &Names)
Tries to remove the given symbols.
Definition: Core.cpp:1304
llvm::orc::SymbolLookupSet::begin
const_iterator begin() const
Definition: Core.h:240
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::orc::SymbolLookupSet::empty
bool empty() const
Definition: Core.h:236
llvm::orc::JITDylibSearchOrder
std::vector< std::pair< JITDylib *, JITDylibLookupFlags > > JITDylibSearchOrder
A list of (JITDylib*, JITDylibLookupFlags) pairs to be used as a search order during symbol lookup.
Definition: Core.h:152
llvm::orc::ResourceManager::handleRemoveResources
virtual Error handleRemoveResources(ResourceKey K)=0
llvm::orc::JITDylib::getReverseDFSLinkOrder
std::vector< JITDylibSP > getReverseDFSLinkOrder()
Rteurn this JITDylib and its transitive dependencies in reverse DFS order based on linkage relationsh...
Definition: Core.cpp:1869
llvm::orc::DefinitionGenerator
Definition generators can be attached to JITDylibs to generate new definitions for otherwise unresolv...
Definition: Core.h:873
llvm::ErrorInfo
Base class for user error types.
Definition: Error.h:350
llvm::orc::JITDylib::operator=
JITDylib & operator=(const JITDylib &)=delete
llvm::orc::SymbolAliasMapEntry::Aliasee
SymbolStringPtr Aliasee
Definition: Core.h:373
llvm::orc::reexports
std::unique_ptr< ReExportsMaterializationUnit > reexports(JITDylib &SourceJD, SymbolAliasMap Aliases, JITDylibLookupFlags SourceJDLookupFlags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Create a materialization unit for re-exporting symbols from another JITDylib with alternative names/f...
Definition: Core.h:773
llvm::orc::ExecutionSession::deregisterResourceManager
void deregisterResourceManager(ResourceManager &RM)
Deregister the given ResourceManager with this ExecutionSession.
Definition: Core.cpp:1785
llvm::orc::ResourceManager::handleTransferResources
virtual void handleTransferResources(ResourceKey DstK, ResourceKey SrcK)=0
llvm::sys::fs::remove
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
llvm::AArch64::RM
@ RM
Definition: AArch64ISelLowering.h:471
llvm::orc::SymbolLookupSet::SymbolLookupSet
SymbolLookupSet()=default
llvm::orc::MaterializationResponsibility::~MaterializationResponsibility
~MaterializationResponsibility()
Destruct a MaterializationResponsibility instance.
Definition: Core.h:1660
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::orc::ExecutionSession::MaterializationResponsibility
friend class MaterializationResponsibility
Definition: Core.h:1257
llvm::orc::ReexportsGenerator::SymbolPredicate
std::function< bool(SymbolStringPtr)> SymbolPredicate
Definition: Core.h:1637
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
this
Analysis the ScalarEvolution expression for r is this
Definition: README.txt:8
llvm::orc::Platform
Platforms set up standard symbols and mediate interactions between dynamic initializers (e....
Definition: Core.h:1194
llvm::orc::SymbolState::Ready
@ Ready
Emitted to memory, but waiting on transitive dependencies.
BitmaskEnum.h
llvm::orc::SymbolLookupSet::begin
iterator begin()
Definition: Core.h:238
llvm::orc::MaterializationResponsibility::MaterializationResponsibility
MaterializationResponsibility(MaterializationResponsibility &&)=delete
llvm::orc::LookupState
Wraps state for a lookup-in-progress.
Definition: Core.h:848
llvm::orc::JITDylib::getDFSLinkOrder
std::vector< JITDylibSP > getDFSLinkOrder()
Return this JITDylib and its transitive dependencies in DFS order based on linkage relationships.
Definition: Core.cpp:1865
llvm::orc::SymbolLookupSet::iterator
UnderlyingVector::iterator iterator
Definition: Core.h:177
llvm::orc::MaterializationUnit::ID
static char ID
Definition: Core.h:641
llvm::orc::SymbolLookupSet::getSymbolNames
SymbolNameVector getSymbolNames() const
Construct a SymbolNameVector from this instance by dropping the Flags values.
Definition: Core.h:317
llvm::orc::SymbolLookupSet::sortByAddress
void sortByAddress()
Sort the lookup set by pointer value.
Definition: Core.h:328
llvm::orc::SymbolAliasMapEntry
Definition: Core.h:368
llvm::orc::InProgressFullLookupState
Definition: Core.cpp:533
llvm::orc::ExecutionSession::createJITDylib
Expected< JITDylib & > createJITDylib(std::string Name)
Add a new JITDylib to this ExecutionSession.
Definition: Core.cpp:1815
llvm::orc::SymbolDependenceMap
DenseMap< JITDylib *, SymbolNameSet > SymbolDependenceMap
A map from JITDylibs to sets of symbols.
Definition: Core.h:117
llvm::orc::ResourceTrackerDefunct::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: Core.cpp:71
llvm::orc::SymbolFlagsMap
DenseMap< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap
A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
Definition: Core.h:114
llvm::DenseMapBase::empty
LLVM_NODISCARD bool empty() const
Definition: DenseMap.h:97
llvm::logAllUnhandledErrors
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
Definition: Error.cpp:61
llvm::orc::AsynchronousSymbolQuery::AsynchronousSymbolQuery
AsynchronousSymbolQuery(const SymbolLookupSet &Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete)
Create a query for the given symbols.
Definition: Core.cpp:143
llvm::orc::ResourceManager
Listens for ResourceTracker operations.
Definition: Core.h:95
llvm::orc::MaterializationResponsibility::failMaterialization
void failMaterialization()
Notify all not-yet-emitted covered by this MaterializationResponsibility instance that an error has o...
Definition: Core.h:1683
llvm::orc::ReexportsGenerator
ReexportsGenerator can be used with JITDylib::addGenerator to automatically re-export a subset of the...
Definition: Core.h:1635
llvm::orc::ExecutionSession::getPlatform
Platform * getPlatform()
Get the Platform for this session.
Definition: Core.h:1286
llvm::orc::ExecutionSession::ErrorReporter
std::function< void(Error)> ErrorReporter
For reporting errors.
Definition: Core.h:1262
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
std
Definition: BitVector.h:838
llvm::orc::MaterializationResponsibility::getExecutionSession
ExecutionSession & getExecutionSession()
Returns the ExecutionSession for this instance.
Definition: Core.h:1521
llvm::orc::SymbolLookupSet::const_iterator
UnderlyingVector::const_iterator const_iterator
Definition: Core.h:178
llvm::orc::JITDylib::removeFromLinkOrder
void removeFromLinkOrder(JITDylib &JD)
Remove the given JITDylib from the link order for this JITDylib if it is present.
Definition: Core.cpp:1293
llvm::orc::SymbolsNotFound::SymbolsNotFound
SymbolsNotFound(SymbolNameSet Symbols)
Definition: Core.cpp:93
getFlags
static uint32_t getFlags(const Symbol *Sym)
Definition: TapiFile.cpp:28
llvm::orc::OrcV2CAPIHelper
Definition: OrcV2CBindings.cpp:27
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::orc::Task
Represents an abstract task for ORC to run.
Definition: Core.h:1221
llvm::orc::DefinitionGenerator::tryToGenerate
virtual Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD, JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &LookupSet)=0
DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.
llvm::orc::SymbolLookupSet::removeDuplicates
void removeDuplicates()
Remove any duplicate elements.
Definition: Core.h:344
llvm::orc::ExecutionSession::getSymbolStringPool
std::shared_ptr< SymbolStringPool > getSymbolStringPool() const
Returns a shared_ptr to the SymbolStringPool for this ExecutionSession.
Definition: Core.h:1279
llvm::orc::ExecutionSession
An ExecutionSession represents a running JIT program.
Definition: Core.h:1252
llvm::orc::JITDylibLookupFlags::MatchExportedSymbolsOnly
@ MatchExportedSymbolsOnly
llvm::AArch64CC::LS
@ LS
Definition: AArch64BaseInfo.h:245
llvm::orc::FailedToMaterialize
Used to notify a JITDylib that the given set of symbols failed to materialize.
Definition: Core.h:405
llvm::orc::MissingSymbolDefinitions::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: Core.cpp:125
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1423
llvm::orc::symbolAliases
std::unique_ptr< ReExportsMaterializationUnit > symbolAliases(SymbolAliasMap Aliases)
Create a ReExportsMaterializationUnit with the given aliases.
Definition: Core.h:764
llvm::orc::absoluteSymbols
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
Definition: Core.h:719
llvm::orc::FailedToMaterialize::log
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: Core.cpp:89
llvm::JITTargetAddress
uint64_t JITTargetAddress
Represents an address in the target process's address space.
Definition: JITSymbol.h:42
llvm::orc::SymbolsNotFound::getSymbols
const SymbolNameVector & getSymbols() const
Definition: Core.h:427
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:79
llvm::orc::ResourceTrackerDefunct::ResourceTrackerDefunct
ResourceTrackerDefunct(ResourceTrackerSP RT)
Definition: Core.cpp:68
llvm::orc::JITDylib::getName
const std::string & getName() const
Get the name for this JITDylib.
Definition: Core.h:911
llvm::orc::MaterializationResponsibility::delegate
Expected< std::unique_ptr< MaterializationResponsibility > > delegate(const SymbolNameSet &Symbols)
Delegates responsibility for the given symbols to the returned materialization responsibility.
Definition: Core.h:1693
JITLinkDylib.h
llvm::orc::JITDylib::define
Error define(std::unique_ptr< MaterializationUnitType > &&MU, ResourceTrackerSP RT=nullptr)
Define all symbols provided by the materialization unit to be part of this JITDylib.
Definition: Core.h:1552
llvm::orc::SymbolAliasMapEntry::AliasFlags
JITSymbolFlags AliasFlags
Definition: Core.h:374
llvm::orc::ExecutionSession::lookup
void lookup(LookupKind K, const JITDylibSearchOrder &SearchOrder, SymbolLookupSet Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete, RegisterDependenciesFunction RegisterDependencies)
Search the given JITDylibs for the given symbols.
Definition: Core.cpp:1899
llvm::orc::AsynchronousSymbolQuery::JITDylib
friend class JITDylib
Definition: Core.h:802
llvm::orc::JITDylib::getExecutionSession
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
Definition: Core.h:914
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:163
llvm::orc::MissingSymbolDefinitions::getSymbols
const SymbolNameVector & getSymbols() const
Definition: Core.h:460
llvm::orc::MissingSymbolDefinitions::ID
static char ID
Definition: Core.h:453
llvm::orc::SymbolState::Emitted
@ Emitted
Assigned address, still materializing.
llvm::orc::SymbolNameSet
DenseSet< SymbolStringPtr > SymbolNameSet
A set of symbol names (represented by SymbolStringPtrs for.
Definition: Core.h:104
llvm::orc::JITDylibLookupFlags
JITDylibLookupFlags
Lookup flags that apply to each dylib in the search order for a lookup.
Definition: Core.h:125
llvm::orc::SymbolState::Resolved
@ Resolved
Queried, materialization begun.
llvm::orc::MaterializationTask::ID
static char ID
Definition: Core.h:1238
llvm::orc::ReExportsMaterializationUnit::ReExportsMaterializationUnit
ReExportsMaterializationUnit(JITDylib *SourceJD, JITDylibLookupFlags SourceJDLookupFlags, SymbolAliasMap Aliases)
SourceJD is allowed to be nullptr, in which case the source JITDylib is taken to be whatever JITDylib...
Definition: Core.cpp:271
llvm::orc::MaterializationUnit::SymbolFlags
SymbolFlagsMap SymbolFlags
Definition: Core.h:677
llvm::orc::UnexpectedSymbolDefinitions::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: Core.cpp:134
llvm::orc::LookupState::LookupState
LookupState()
llvm::orc::JITDylibLookupFlags::MatchAllSymbols
@ MatchAllSymbols
llvm::orc::SymbolLookupFlags::RequiredSymbol
@ RequiredSymbol
llvm::orc::SymbolsResolvedCallback
unique_function< void(Expected< SymbolMap >)> SymbolsResolvedCallback
Callback to notify client that symbols have been resolved.
Definition: Core.h:381
llvm::orc::SymbolsCouldNotBeRemoved::SymbolsCouldNotBeRemoved
SymbolsCouldNotBeRemoved(SymbolNameSet Symbols)
Definition: Core.cpp:112
llvm::orc::SymbolNameVector
std::vector< SymbolStringPtr > SymbolNameVector
A vector of symbol names.
Definition: Core.h:107
Debug.h
llvm::orc::ExecutionSession::setErrorReporter
ExecutionSession & setErrorReporter(ErrorReporter ReportError)
Set the error reporter function.
Definition: Core.h:1328
llvm::IntrusiveRefCntPtr
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
Definition: IntrusiveRefCntPtr.h:163
llvm::orc::makeJITDylibSearchOrder
JITDylibSearchOrder makeJITDylibSearchOrder(ArrayRef< JITDylib * > JDs, JITDylibLookupFlags Flags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Convenience function for creating a search order from an ArrayRef of JITDylib*, all with the same fla...
Definition: Core.h:156
llvm::orc::buildSimpleReexportsAAliasMap
Expected< SymbolAliasMap > buildSimpleReexportsAAliasMap(JITDylib &SourceJD, const SymbolNameSet &Symbols)
Build a SymbolAliasMap for the common case where you want to re-export symbols from another JITDylib ...
llvm::orc::SymbolsCouldNotBeRemoved::ID
static char ID
Definition: Core.h:436
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1168
llvm::orc::AsynchronousSymbolQuery::isComplete
bool isComplete() const
Returns true if all symbols covered by this query have been resolved.
Definition: Core.h:820
llvm::orc::SymbolsCouldNotBeRemoved::log
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: Core.cpp:121
llvm::orc::MaterializationUnit::InitSymbol
SymbolStringPtr InitSymbol
Definition: Core.h:678
llvm::orc::JITDylib::removeGenerator
void removeGenerator(DefinitionGenerator &G)
Remove a definition generator from this JITDylib.
Definition: Core.cpp:641