LLVM  3.7.0
Metadata.h
Go to the documentation of this file.
1 //===- llvm/IR/Metadata.h - Metadata definitions ----------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// @file
11 /// This file contains the declarations for metadata subclasses.
12 /// They represent the different flavors of metadata that live in LLVM.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_IR_METADATA_H
17 #define LLVM_IR_METADATA_H
18 
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/ilist_node.h"
23 #include "llvm/IR/Constant.h"
25 #include "llvm/IR/Value.h"
27 #include <type_traits>
28 
29 namespace llvm {
30 
31 class LLVMContext;
32 class Module;
33 class ModuleSlotTracker;
34 
35 template<typename ValueSubClass, typename ItemParentClass>
36  class SymbolTableListTraits;
37 
38 enum LLVMConstants : uint32_t {
39  DEBUG_METADATA_VERSION = 3 // Current debug info version number.
40 };
41 
42 /// \brief Root of the metadata hierarchy.
43 ///
44 /// This is a root class for typeless data in the IR.
45 class Metadata {
47 
48  /// \brief RTTI.
49  const unsigned char SubclassID;
50 
51 protected:
52  /// \brief Active type of storage.
54 
55  /// \brief Storage flag for non-uniqued, otherwise unowned, metadata.
56  unsigned Storage : 2;
57  // TODO: expose remaining bits to subclasses.
58 
59  unsigned short SubclassData16;
60  unsigned SubclassData32;
61 
62 public:
63  enum MetadataKind {
90  };
91 
92 protected:
94  : SubclassID(ID), Storage(Storage), SubclassData16(0), SubclassData32(0) {
95  }
96  ~Metadata() = default;
97 
98  /// \brief Default handling of a changed operand, which asserts.
99  ///
100  /// If subclasses pass themselves in as owners to a tracking node reference,
101  /// they must provide an implementation of this method.
102  void handleChangedOperand(void *, Metadata *) {
103  llvm_unreachable("Unimplemented in Metadata subclass");
104  }
105 
106 public:
107  unsigned getMetadataID() const { return SubclassID; }
108 
109  /// \brief User-friendly dump.
110  ///
111  /// If \c M is provided, metadata nodes will be numbered canonically;
112  /// otherwise, pointer addresses are substituted.
113  ///
114  /// Note: this uses an explicit overload instead of default arguments so that
115  /// the nullptr version is easy to call from a debugger.
116  ///
117  /// @{
118  void dump() const;
119  void dump(const Module *M) const;
120  /// @}
121 
122  /// \brief Print.
123  ///
124  /// Prints definition of \c this.
125  ///
126  /// If \c M is provided, metadata nodes will be numbered canonically;
127  /// otherwise, pointer addresses are substituted.
128  /// @{
129  void print(raw_ostream &OS, const Module *M = nullptr) const;
130  void print(raw_ostream &OS, ModuleSlotTracker &MST,
131  const Module *M = nullptr) const;
132  /// @}
133 
134  /// \brief Print as operand.
135  ///
136  /// Prints reference of \c this.
137  ///
138  /// If \c M is provided, metadata nodes will be numbered canonically;
139  /// otherwise, pointer addresses are substituted.
140  /// @{
141  void printAsOperand(raw_ostream &OS, const Module *M = nullptr) const;
143  const Module *M = nullptr) const;
144  /// @}
145 };
146 
147 #define HANDLE_METADATA(CLASS) class CLASS;
148 #include "llvm/IR/Metadata.def"
149 
150 // Provide specializations of isa so that we don't need definitions of
151 // subclasses to see if the metadata is a subclass.
152 #define HANDLE_METADATA_LEAF(CLASS) \
153  template <> struct isa_impl<CLASS, Metadata> { \
154  static inline bool doit(const Metadata &MD) { \
155  return MD.getMetadataID() == Metadata::CLASS##Kind; \
156  } \
157  };
158 #include "llvm/IR/Metadata.def"
159 
160 inline raw_ostream &operator<<(raw_ostream &OS, const Metadata &MD) {
161  MD.print(OS);
162  return OS;
163 }
164 
165 /// \brief Metadata wrapper in the Value hierarchy.
166 ///
167 /// A member of the \a Value hierarchy to represent a reference to metadata.
168 /// This allows, e.g., instrinsics to have metadata as operands.
169 ///
170 /// Notably, this is the only thing in either hierarchy that is allowed to
171 /// reference \a LocalAsMetadata.
172 class MetadataAsValue : public Value {
174  friend class LLVMContextImpl;
175 
176  Metadata *MD;
177 
178  MetadataAsValue(Type *Ty, Metadata *MD);
179  ~MetadataAsValue() override;
180 
181  /// \brief Drop use of metadata (during teardown).
182  void dropUse() { MD = nullptr; }
183 
184 public:
185  static MetadataAsValue *get(LLVMContext &Context, Metadata *MD);
186  static MetadataAsValue *getIfExists(LLVMContext &Context, Metadata *MD);
187  Metadata *getMetadata() const { return MD; }
188 
189  static bool classof(const Value *V) {
190  return V->getValueID() == MetadataAsValueVal;
191  }
192 
193 private:
194  void handleChangedMetadata(Metadata *MD);
195  void track();
196  void untrack();
197 };
198 
199 /// \brief Shared implementation of use-lists for replaceable metadata.
200 ///
201 /// Most metadata cannot be RAUW'ed. This is a shared implementation of
202 /// use-lists and associated API for the two that support it (\a ValueAsMetadata
203 /// and \a TempMDNode).
205  friend class MetadataTracking;
206 
207 public:
209 
210 private:
211  LLVMContext &Context;
212  uint64_t NextIndex;
214 
215 public:
217  : Context(Context), NextIndex(0) {}
219  assert(UseMap.empty() && "Cannot destroy in-use replaceable metadata");
220  }
221 
222  LLVMContext &getContext() const { return Context; }
223 
224  /// \brief Replace all uses of this with MD.
225  ///
226  /// Replace all uses of this with \c MD, which is allowed to be null.
227  void replaceAllUsesWith(Metadata *MD);
228 
229  /// \brief Resolve all uses of this.
230  ///
231  /// Resolve all uses of this, turning off RAUW permanently. If \c
232  /// ResolveUsers, call \a MDNode::resolve() on any users whose last operand
233  /// is resolved.
234  void resolveAllUses(bool ResolveUsers = true);
235 
236 private:
237  void addRef(void *Ref, OwnerTy Owner);
238  void dropRef(void *Ref);
239  void moveRef(void *Ref, void *New, const Metadata &MD);
240 
241  static ReplaceableMetadataImpl *get(Metadata &MD);
242 };
243 
244 /// \brief Value wrapper in the Metadata hierarchy.
245 ///
246 /// This is a custom value handle that allows other metadata to refer to
247 /// classes in the Value hierarchy.
248 ///
249 /// Because of full uniquing support, each value is only wrapped by a single \a
250 /// ValueAsMetadata object, so the lookup maps are far more efficient than
251 /// those using ValueHandleBase.
254  friend class LLVMContextImpl;
255 
256  Value *V;
257 
258  /// \brief Drop users without RAUW (during teardown).
259  void dropUsers() {
260  ReplaceableMetadataImpl::resolveAllUses(/* ResolveUsers */ false);
261  }
262 
263 protected:
264  ValueAsMetadata(unsigned ID, Value *V)
265  : Metadata(ID, Uniqued), ReplaceableMetadataImpl(V->getContext()), V(V) {
266  assert(V && "Expected valid value");
267  }
268  ~ValueAsMetadata() = default;
269 
270 public:
271  static ValueAsMetadata *get(Value *V);
273  return cast<ConstantAsMetadata>(get(C));
274  }
276  return cast<LocalAsMetadata>(get(Local));
277  }
278 
279  static ValueAsMetadata *getIfExists(Value *V);
281  return cast_or_null<ConstantAsMetadata>(getIfExists(C));
282  }
284  return cast_or_null<LocalAsMetadata>(getIfExists(Local));
285  }
286 
287  Value *getValue() const { return V; }
288  Type *getType() const { return V->getType(); }
289  LLVMContext &getContext() const { return V->getContext(); }
290 
291  static void handleDeletion(Value *V);
292  static void handleRAUW(Value *From, Value *To);
293 
294 protected:
295  /// \brief Handle collisions after \a Value::replaceAllUsesWith().
296  ///
297  /// RAUW isn't supported directly for \a ValueAsMetadata, but if the wrapped
298  /// \a Value gets RAUW'ed and the target already exists, this is used to
299  /// merge the two metadata nodes.
302  }
303 
304 public:
305  static bool classof(const Metadata *MD) {
306  return MD->getMetadataID() == LocalAsMetadataKind ||
308  }
309 };
310 
312  friend class ValueAsMetadata;
313 
316 
317 public:
318  static ConstantAsMetadata *get(Constant *C) {
320  }
323  }
324 
325  Constant *getValue() const {
326  return cast<Constant>(ValueAsMetadata::getValue());
327  }
328 
329  static bool classof(const Metadata *MD) {
330  return MD->getMetadataID() == ConstantAsMetadataKind;
331  }
332 };
333 
335  friend class ValueAsMetadata;
336 
339  assert(!isa<Constant>(Local) && "Expected local value");
340  }
341 
342 public:
343  static LocalAsMetadata *get(Value *Local) {
344  return ValueAsMetadata::getLocal(Local);
345  }
347  return ValueAsMetadata::getLocalIfExists(Local);
348  }
349 
350  static bool classof(const Metadata *MD) {
351  return MD->getMetadataID() == LocalAsMetadataKind;
352  }
353 };
354 
355 /// \brief Transitional API for extracting constants from Metadata.
356 ///
357 /// This namespace contains transitional functions for metadata that points to
358 /// \a Constants.
359 ///
360 /// In prehistory -- when metadata was a subclass of \a Value -- \a MDNode
361 /// operands could refer to any \a Value. There's was a lot of code like this:
362 ///
363 /// \code
364 /// MDNode *N = ...;
365 /// auto *CI = dyn_cast<ConstantInt>(N->getOperand(2));
366 /// \endcode
367 ///
368 /// Now that \a Value and \a Metadata are in separate hierarchies, maintaining
369 /// the semantics for \a isa(), \a cast(), \a dyn_cast() (etc.) requires three
370 /// steps: cast in the \a Metadata hierarchy, extraction of the \a Value, and
371 /// cast in the \a Value hierarchy. Besides creating boiler-plate, this
372 /// requires subtle control flow changes.
373 ///
374 /// The end-goal is to create a new type of metadata, called (e.g.) \a MDInt,
375 /// so that metadata can refer to numbers without traversing a bridge to the \a
376 /// Value hierarchy. In this final state, the code above would look like this:
377 ///
378 /// \code
379 /// MDNode *N = ...;
380 /// auto *MI = dyn_cast<MDInt>(N->getOperand(2));
381 /// \endcode
382 ///
383 /// The API in this namespace supports the transition. \a MDInt doesn't exist
384 /// yet, and even once it does, changing each metadata schema to use it is its
385 /// own mini-project. In the meantime this API prevents us from introducing
386 /// complex and bug-prone control flow that will disappear in the end. In
387 /// particular, the above code looks like this:
388 ///
389 /// \code
390 /// MDNode *N = ...;
391 /// auto *CI = mdconst::dyn_extract<ConstantInt>(N->getOperand(2));
392 /// \endcode
393 ///
394 /// The full set of provided functions includes:
395 ///
396 /// mdconst::hasa <=> isa
397 /// mdconst::extract <=> cast
398 /// mdconst::extract_or_null <=> cast_or_null
399 /// mdconst::dyn_extract <=> dyn_cast
400 /// mdconst::dyn_extract_or_null <=> dyn_cast_or_null
401 ///
402 /// The target of the cast must be a subclass of \a Constant.
403 namespace mdconst {
404 
405 namespace detail {
406 template <class T> T &make();
407 template <class T, class Result> struct HasDereference {
408  typedef char Yes[1];
409  typedef char No[2];
410  template <size_t N> struct SFINAE {};
411 
412  template <class U, class V>
413  static Yes &hasDereference(SFINAE<sizeof(static_cast<V>(*make<U>()))> * = 0);
414  template <class U, class V> static No &hasDereference(...);
415 
416  static const bool value =
417  sizeof(hasDereference<T, Result>(nullptr)) == sizeof(Yes);
418 };
419 template <class V, class M> struct IsValidPointer {
420  static const bool value = std::is_base_of<Constant, V>::value &&
422 };
423 template <class V, class M> struct IsValidReference {
424  static const bool value = std::is_base_of<Constant, V>::value &&
425  std::is_convertible<M, const Metadata &>::value;
426 };
427 } // end namespace detail
428 
429 /// \brief Check whether Metadata has a Value.
430 ///
431 /// As an analogue to \a isa(), check whether \c MD has an \a Value inside of
432 /// type \c X.
433 template <class X, class Y>
434 inline typename std::enable_if<detail::IsValidPointer<X, Y>::value, bool>::type
435 hasa(Y &&MD) {
436  assert(MD && "Null pointer sent into hasa");
437  if (auto *V = dyn_cast<ConstantAsMetadata>(MD))
438  return isa<X>(V->getValue());
439  return false;
440 }
441 template <class X, class Y>
442 inline
443  typename std::enable_if<detail::IsValidReference<X, Y &>::value, bool>::type
444  hasa(Y &MD) {
445  return hasa(&MD);
446 }
447 
448 /// \brief Extract a Value from Metadata.
449 ///
450 /// As an analogue to \a cast(), extract the \a Value subclass \c X from \c MD.
451 template <class X, class Y>
452 inline typename std::enable_if<detail::IsValidPointer<X, Y>::value, X *>::type
453 extract(Y &&MD) {
454  return cast<X>(cast<ConstantAsMetadata>(MD)->getValue());
455 }
456 template <class X, class Y>
457 inline
458  typename std::enable_if<detail::IsValidReference<X, Y &>::value, X *>::type
459  extract(Y &MD) {
460  return extract(&MD);
461 }
462 
463 /// \brief Extract a Value from Metadata, allowing null.
464 ///
465 /// As an analogue to \a cast_or_null(), extract the \a Value subclass \c X
466 /// from \c MD, allowing \c MD to be null.
467 template <class X, class Y>
468 inline typename std::enable_if<detail::IsValidPointer<X, Y>::value, X *>::type
470  if (auto *V = cast_or_null<ConstantAsMetadata>(MD))
471  return cast<X>(V->getValue());
472  return nullptr;
473 }
474 
475 /// \brief Extract a Value from Metadata, if any.
476 ///
477 /// As an analogue to \a dyn_cast_or_null(), extract the \a Value subclass \c X
478 /// from \c MD, return null if \c MD doesn't contain a \a Value or if the \a
479 /// Value it does contain is of the wrong subclass.
480 template <class X, class Y>
481 inline typename std::enable_if<detail::IsValidPointer<X, Y>::value, X *>::type
482 dyn_extract(Y &&MD) {
483  if (auto *V = dyn_cast<ConstantAsMetadata>(MD))
484  return dyn_cast<X>(V->getValue());
485  return nullptr;
486 }
487 
488 /// \brief Extract a Value from Metadata, if any, allowing null.
489 ///
490 /// As an analogue to \a dyn_cast_or_null(), extract the \a Value subclass \c X
491 /// from \c MD, return null if \c MD doesn't contain a \a Value or if the \a
492 /// Value it does contain is of the wrong subclass, allowing \c MD to be null.
493 template <class X, class Y>
494 inline typename std::enable_if<detail::IsValidPointer<X, Y>::value, X *>::type
496  if (auto *V = dyn_cast_or_null<ConstantAsMetadata>(MD))
497  return dyn_cast<X>(V->getValue());
498  return nullptr;
499 }
500 
501 } // end namespace mdconst
502 
503 //===----------------------------------------------------------------------===//
504 /// \brief A single uniqued string.
505 ///
506 /// These are used to efficiently contain a byte sequence for metadata.
507 /// MDString is always unnamed.
508 class MDString : public Metadata {
509  friend class StringMapEntry<MDString>;
510 
511  MDString(const MDString &) = delete;
512  MDString &operator=(MDString &&) = delete;
513  MDString &operator=(const MDString &) = delete;
514 
516  MDString() : Metadata(MDStringKind, Uniqued), Entry(nullptr) {}
518 
519 public:
520  static MDString *get(LLVMContext &Context, StringRef Str);
521  static MDString *get(LLVMContext &Context, const char *Str) {
522  return get(Context, Str ? StringRef(Str) : StringRef());
523  }
524 
525  StringRef getString() const;
526 
527  unsigned getLength() const { return (unsigned)getString().size(); }
528 
530 
531  /// \brief Pointer to the first byte of the string.
532  iterator begin() const { return getString().begin(); }
533 
534  /// \brief Pointer to one byte past the end of the string.
535  iterator end() const { return getString().end(); }
536 
537  const unsigned char *bytes_begin() const { return getString().bytes_begin(); }
538  const unsigned char *bytes_end() const { return getString().bytes_end(); }
539 
540  /// \brief Methods for support type inquiry through isa, cast, and dyn_cast.
541  static bool classof(const Metadata *MD) {
542  return MD->getMetadataID() == MDStringKind;
543  }
544 };
545 
546 /// \brief A collection of metadata nodes that might be associated with a
547 /// memory access used by the alias-analysis infrastructure.
548 struct AAMDNodes {
549  explicit AAMDNodes(MDNode *T = nullptr, MDNode *S = nullptr,
550  MDNode *N = nullptr)
551  : TBAA(T), Scope(S), NoAlias(N) {}
552 
553  bool operator==(const AAMDNodes &A) const {
554  return TBAA == A.TBAA && Scope == A.Scope && NoAlias == A.NoAlias;
555  }
556 
557  bool operator!=(const AAMDNodes &A) const { return !(*this == A); }
558 
559  explicit operator bool() const { return TBAA || Scope || NoAlias; }
560 
561  /// \brief The tag for type-based alias analysis.
563 
564  /// \brief The tag for alias scope specification (used with noalias).
566 
567  /// \brief The tag specifying the noalias scope.
569 };
570 
571 // Specialize DenseMapInfo for AAMDNodes.
572 template<>
574  static inline AAMDNodes getEmptyKey() {
576  }
577  static inline AAMDNodes getTombstoneKey() {
579  }
580  static unsigned getHashValue(const AAMDNodes &Val) {
584  }
585  static bool isEqual(const AAMDNodes &LHS, const AAMDNodes &RHS) {
586  return LHS == RHS;
587  }
588 };
589 
590 /// \brief Tracking metadata reference owned by Metadata.
591 ///
592 /// Similar to \a TrackingMDRef, but it's expected to be owned by an instance
593 /// of \a Metadata, which has the option of registering itself for callbacks to
594 /// re-unique itself.
595 ///
596 /// In particular, this is used by \a MDNode.
597 class MDOperand {
598  MDOperand(MDOperand &&) = delete;
599  MDOperand(const MDOperand &) = delete;
600  MDOperand &operator=(MDOperand &&) = delete;
601  MDOperand &operator=(const MDOperand &) = delete;
602 
603  Metadata *MD;
604 
605 public:
606  MDOperand() : MD(nullptr) {}
607  ~MDOperand() { untrack(); }
608 
609  Metadata *get() const { return MD; }
610  operator Metadata *() const { return get(); }
611  Metadata *operator->() const { return get(); }
612  Metadata &operator*() const { return *get(); }
613 
614  void reset() {
615  untrack();
616  MD = nullptr;
617  }
618  void reset(Metadata *MD, Metadata *Owner) {
619  untrack();
620  this->MD = MD;
621  track(Owner);
622  }
623 
624 private:
625  void track(Metadata *Owner) {
626  if (MD) {
627  if (Owner)
628  MetadataTracking::track(this, *MD, *Owner);
629  else
631  }
632  }
633  void untrack() {
634  assert(static_cast<void *>(this) == &MD && "Expected same address");
635  if (MD)
637  }
638 };
639 
640 template <> struct simplify_type<MDOperand> {
642  static SimpleType getSimplifiedValue(MDOperand &MD) { return MD.get(); }
643 };
644 
645 template <> struct simplify_type<const MDOperand> {
647  static SimpleType getSimplifiedValue(const MDOperand &MD) { return MD.get(); }
648 };
649 
650 /// \brief Pointer to the context, with optional RAUW support.
651 ///
652 /// Either a raw (non-null) pointer to the \a LLVMContext, or an owned pointer
653 /// to \a ReplaceableMetadataImpl (which has a reference to \a LLVMContext).
656 
657  ContextAndReplaceableUses() = delete;
662  operator=(const ContextAndReplaceableUses &) = delete;
663 
664 public:
665  ContextAndReplaceableUses(LLVMContext &Context) : Ptr(&Context) {}
667  std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses)
668  : Ptr(ReplaceableUses.release()) {
669  assert(getReplaceableUses() && "Expected non-null replaceable uses");
670  }
672 
673  operator LLVMContext &() { return getContext(); }
674 
675  /// \brief Whether this contains RAUW support.
676  bool hasReplaceableUses() const {
677  return Ptr.is<ReplaceableMetadataImpl *>();
678  }
680  if (hasReplaceableUses())
681  return getReplaceableUses()->getContext();
682  return *Ptr.get<LLVMContext *>();
683  }
685  if (hasReplaceableUses())
686  return Ptr.get<ReplaceableMetadataImpl *>();
687  return nullptr;
688  }
689 
690  /// \brief Assign RAUW support to this.
691  ///
692  /// Make this replaceable, taking ownership of \c ReplaceableUses (which must
693  /// not be null).
694  void
695  makeReplaceable(std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses) {
696  assert(ReplaceableUses && "Expected non-null replaceable uses");
697  assert(&ReplaceableUses->getContext() == &getContext() &&
698  "Expected same context");
699  delete getReplaceableUses();
700  Ptr = ReplaceableUses.release();
701  }
702 
703  /// \brief Drop RAUW support.
704  ///
705  /// Cede ownership of RAUW support, returning it.
706  std::unique_ptr<ReplaceableMetadataImpl> takeReplaceableUses() {
707  assert(hasReplaceableUses() && "Expected to own replaceable uses");
708  std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses(
710  Ptr = &ReplaceableUses->getContext();
711  return ReplaceableUses;
712  }
713 };
714 
716  inline void operator()(MDNode *Node) const;
717 };
718 
719 #define HANDLE_MDNODE_LEAF(CLASS) \
720  typedef std::unique_ptr<CLASS, TempMDNodeDeleter> Temp##CLASS;
721 #define HANDLE_MDNODE_BRANCH(CLASS) HANDLE_MDNODE_LEAF(CLASS)
722 #include "llvm/IR/Metadata.def"
723 
724 /// \brief Metadata node.
725 ///
726 /// Metadata nodes can be uniqued, like constants, or distinct. Temporary
727 /// metadata nodes (with full support for RAUW) can be used to delay uniquing
728 /// until forward references are known. The basic metadata node is an \a
729 /// MDTuple.
730 ///
731 /// There is limited support for RAUW at construction time. At construction
732 /// time, if any operand is a temporary node (or an unresolved uniqued node,
733 /// which indicates a transitive temporary operand), the node itself will be
734 /// unresolved. As soon as all operands become resolved, it will drop RAUW
735 /// support permanently.
736 ///
737 /// If an unresolved node is part of a cycle, \a resolveCycles() needs
738 /// to be called on some member of the cycle once all temporary nodes have been
739 /// replaced.
740 class MDNode : public Metadata {
742  friend class LLVMContextImpl;
743 
744  MDNode(const MDNode &) = delete;
745  void operator=(const MDNode &) = delete;
746  void *operator new(size_t) = delete;
747 
748  unsigned NumOperands;
749  unsigned NumUnresolved;
750 
751 protected:
753 
754  void *operator new(size_t Size, unsigned NumOps);
755  void operator delete(void *Mem);
756 
757  /// \brief Required by std, but never called.
758  void operator delete(void *, unsigned) {
759  llvm_unreachable("Constructor throws?");
760  }
761 
762  /// \brief Required by std, but never called.
763  void operator delete(void *, unsigned, bool) {
764  llvm_unreachable("Constructor throws?");
765  }
766 
769  ~MDNode() = default;
770 
771  void dropAllReferences();
772 
773  MDOperand *mutable_begin() { return mutable_end() - NumOperands; }
774  MDOperand *mutable_end() { return reinterpret_cast<MDOperand *>(this); }
775 
779  }
780 
781 public:
782  static inline MDTuple *get(LLVMContext &Context, ArrayRef<Metadata *> MDs);
783  static inline MDTuple *getIfExists(LLVMContext &Context,
785  static inline MDTuple *getDistinct(LLVMContext &Context,
787  static inline TempMDTuple getTemporary(LLVMContext &Context,
789 
790  /// \brief Create a (temporary) clone of this.
791  TempMDNode clone() const;
792 
793  /// \brief Deallocate a node created by getTemporary.
794  ///
795  /// Calls \c replaceAllUsesWith(nullptr) before deleting, so any remaining
796  /// references will be reset.
797  static void deleteTemporary(MDNode *N);
798 
799  LLVMContext &getContext() const { return Context.getContext(); }
800 
801  /// \brief Replace a specific operand.
802  void replaceOperandWith(unsigned I, Metadata *New);
803 
804  /// \brief Check if node is fully resolved.
805  ///
806  /// If \a isTemporary(), this always returns \c false; if \a isDistinct(),
807  /// this always returns \c true.
808  ///
809  /// If \a isUniqued(), returns \c true if this has already dropped RAUW
810  /// support (because all operands are resolved).
811  ///
812  /// As forward declarations are resolved, their containers should get
813  /// resolved automatically. However, if this (or one of its operands) is
814  /// involved in a cycle, \a resolveCycles() needs to be called explicitly.
815  bool isResolved() const { return !Context.hasReplaceableUses(); }
816 
817  bool isUniqued() const { return Storage == Uniqued; }
818  bool isDistinct() const { return Storage == Distinct; }
819  bool isTemporary() const { return Storage == Temporary; }
820 
821  /// \brief RAUW a temporary.
822  ///
823  /// \pre \a isTemporary() must be \c true.
825  assert(isTemporary() && "Expected temporary node");
826  assert(!isResolved() && "Expected RAUW support");
828  }
829 
830  /// \brief Resolve cycles.
831  ///
832  /// Once all forward declarations have been resolved, force cycles to be
833  /// resolved.
834  ///
835  /// \pre No operands (or operands' operands, etc.) have \a isTemporary().
836  void resolveCycles();
837 
838  /// \brief Replace a temporary node with a permanent one.
839  ///
840  /// Try to create a uniqued version of \c N -- in place, if possible -- and
841  /// return it. If \c N cannot be uniqued, return a distinct node instead.
842  template <class T>
843  static typename std::enable_if<std::is_base_of<MDNode, T>::value, T *>::type
844  replaceWithPermanent(std::unique_ptr<T, TempMDNodeDeleter> N) {
845  return cast<T>(N.release()->replaceWithPermanentImpl());
846  }
847 
848  /// \brief Replace a temporary node with a uniqued one.
849  ///
850  /// Create a uniqued version of \c N -- in place, if possible -- and return
851  /// it. Takes ownership of the temporary node.
852  ///
853  /// \pre N does not self-reference.
854  template <class T>
855  static typename std::enable_if<std::is_base_of<MDNode, T>::value, T *>::type
856  replaceWithUniqued(std::unique_ptr<T, TempMDNodeDeleter> N) {
857  return cast<T>(N.release()->replaceWithUniquedImpl());
858  }
859 
860  /// \brief Replace a temporary node with a distinct one.
861  ///
862  /// Create a distinct version of \c N -- in place, if possible -- and return
863  /// it. Takes ownership of the temporary node.
864  template <class T>
865  static typename std::enable_if<std::is_base_of<MDNode, T>::value, T *>::type
866  replaceWithDistinct(std::unique_ptr<T, TempMDNodeDeleter> N) {
867  return cast<T>(N.release()->replaceWithDistinctImpl());
868  }
869 
870 private:
871  MDNode *replaceWithPermanentImpl();
872  MDNode *replaceWithUniquedImpl();
873  MDNode *replaceWithDistinctImpl();
874 
875 protected:
876  /// \brief Set an operand.
877  ///
878  /// Sets the operand directly, without worrying about uniquing.
879  void setOperand(unsigned I, Metadata *New);
880 
881  void storeDistinctInContext();
882  template <class T, class StoreT>
883  static T *storeImpl(T *N, StorageType Storage, StoreT &Store);
884 
885 private:
886  void handleChangedOperand(void *Ref, Metadata *New);
887 
888  void resolve();
889  void resolveAfterOperandChange(Metadata *Old, Metadata *New);
890  void decrementUnresolvedOperandCount();
891  unsigned countUnresolvedOperands();
892 
893  /// \brief Mutate this to be "uniqued".
894  ///
895  /// Mutate this so that \a isUniqued().
896  /// \pre \a isTemporary().
897  /// \pre already added to uniquing set.
898  void makeUniqued();
899 
900  /// \brief Mutate this to be "distinct".
901  ///
902  /// Mutate this so that \a isDistinct().
903  /// \pre \a isTemporary().
904  void makeDistinct();
905 
906  void deleteAsSubclass();
907  MDNode *uniquify();
908  void eraseFromStore();
909 
910  template <class NodeTy> struct HasCachedHash;
911  template <class NodeTy>
912  static void dispatchRecalculateHash(NodeTy *N, std::true_type) {
913  N->recalculateHash();
914  }
915  template <class NodeTy>
916  static void dispatchRecalculateHash(NodeTy *N, std::false_type) {}
917  template <class NodeTy>
918  static void dispatchResetHash(NodeTy *N, std::true_type) {
919  N->setHash(0);
920  }
921  template <class NodeTy>
922  static void dispatchResetHash(NodeTy *N, std::false_type) {}
923 
924 public:
925  typedef const MDOperand *op_iterator;
927 
929  return const_cast<MDNode *>(this)->mutable_begin();
930  }
931  op_iterator op_end() const {
932  return const_cast<MDNode *>(this)->mutable_end();
933  }
934  op_range operands() const { return op_range(op_begin(), op_end()); }
935 
936  const MDOperand &getOperand(unsigned I) const {
937  assert(I < NumOperands && "Out of range");
938  return op_begin()[I];
939  }
940 
941  /// \brief Return number of MDNode operands.
942  unsigned getNumOperands() const { return NumOperands; }
943 
944  /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
945  static bool classof(const Metadata *MD) {
946  switch (MD->getMetadataID()) {
947  default:
948  return false;
949 #define HANDLE_MDNODE_LEAF(CLASS) \
950  case CLASS##Kind: \
951  return true;
952 #include "llvm/IR/Metadata.def"
953  }
954  }
955 
956  /// \brief Check whether MDNode is a vtable access.
957  bool isTBAAVtableAccess() const;
958 
959  /// \brief Methods for metadata merging.
960  static MDNode *concatenate(MDNode *A, MDNode *B);
961  static MDNode *intersect(MDNode *A, MDNode *B);
962  static MDNode *getMostGenericTBAA(MDNode *A, MDNode *B);
963  static MDNode *getMostGenericFPMath(MDNode *A, MDNode *B);
964  static MDNode *getMostGenericRange(MDNode *A, MDNode *B);
966 };
967 
968 /// \brief Tuple of metadata.
969 ///
970 /// This is the simple \a MDNode arbitrary tuple. Nodes are uniqued by
971 /// default based on their operands.
972 class MDTuple : public MDNode {
973  friend class LLVMContextImpl;
974  friend class MDNode;
975 
978  : MDNode(C, MDTupleKind, Storage, Vals) {
979  setHash(Hash);
980  }
981  ~MDTuple() { dropAllReferences(); }
982 
983  void setHash(unsigned Hash) { SubclassData32 = Hash; }
984  void recalculateHash();
985 
986  static MDTuple *getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
987  StorageType Storage, bool ShouldCreate = true);
988 
989  TempMDTuple cloneImpl() const {
990  return getTemporary(getContext(),
991  SmallVector<Metadata *, 4>(op_begin(), op_end()));
992  }
993 
994 public:
995  /// \brief Get the hash, if any.
996  unsigned getHash() const { return SubclassData32; }
997 
999  return getImpl(Context, MDs, Uniqued);
1000  }
1002  return getImpl(Context, MDs, Uniqued, /* ShouldCreate */ false);
1003  }
1004 
1005  /// \brief Return a distinct node.
1006  ///
1007  /// Return a distinct node -- i.e., a node that is not uniqued.
1009  return getImpl(Context, MDs, Distinct);
1010  }
1011 
1012  /// \brief Return a temporary node.
1013  ///
1014  /// For use in constructing cyclic MDNode structures. A temporary MDNode is
1015  /// not uniqued, may be RAUW'd, and must be manually deleted with
1016  /// deleteTemporary.
1017  static TempMDTuple getTemporary(LLVMContext &Context,
1018  ArrayRef<Metadata *> MDs) {
1019  return TempMDTuple(getImpl(Context, MDs, Temporary));
1020  }
1021 
1022  /// \brief Return a (temporary) clone of this.
1023  TempMDTuple clone() const { return cloneImpl(); }
1024 
1025  static bool classof(const Metadata *MD) {
1026  return MD->getMetadataID() == MDTupleKind;
1027  }
1028 };
1029 
1031  return MDTuple::get(Context, MDs);
1032 }
1034  return MDTuple::getIfExists(Context, MDs);
1035 }
1037  return MDTuple::getDistinct(Context, MDs);
1038 }
1039 TempMDTuple MDNode::getTemporary(LLVMContext &Context,
1040  ArrayRef<Metadata *> MDs) {
1041  return MDTuple::getTemporary(Context, MDs);
1042 }
1043 
1046 }
1047 
1048 /// \brief Typed iterator through MDNode operands.
1049 ///
1050 /// An iterator that transforms an \a MDNode::iterator into an iterator over a
1051 /// particular Metadata subclass.
1052 template <class T>
1054  : std::iterator<std::input_iterator_tag, T *, std::ptrdiff_t, void, T *> {
1055  MDNode::op_iterator I = nullptr;
1056 
1057 public:
1058  TypedMDOperandIterator() = default;
1060  T *operator*() const { return cast_or_null<T>(*I); }
1062  ++I;
1063  return *this;
1064  }
1066  TypedMDOperandIterator Temp(*this);
1067  ++I;
1068  return Temp;
1069  }
1070  bool operator==(const TypedMDOperandIterator &X) const { return I == X.I; }
1071  bool operator!=(const TypedMDOperandIterator &X) const { return I != X.I; }
1072 };
1073 
1074 /// \brief Typed, array-like tuple of metadata.
1075 ///
1076 /// This is a wrapper for \a MDTuple that makes it act like an array holding a
1077 /// particular type of metadata.
1078 template <class T> class MDTupleTypedArrayWrapper {
1079  const MDTuple *N = nullptr;
1080 
1081 public:
1082  MDTupleTypedArrayWrapper() = default;
1083  MDTupleTypedArrayWrapper(const MDTuple *N) : N(N) {}
1084 
1085  template <class U>
1088  typename std::enable_if<std::is_convertible<U *, T *>::value>::type * =
1089  nullptr)
1090  : N(Other.get()) {}
1091 
1092  template <class U>
1095  typename std::enable_if<!std::is_convertible<U *, T *>::value>::type * =
1096  nullptr)
1097  : N(Other.get()) {}
1098 
1099  explicit operator bool() const { return get(); }
1100  explicit operator MDTuple *() const { return get(); }
1101 
1102  MDTuple *get() const { return const_cast<MDTuple *>(N); }
1103  MDTuple *operator->() const { return get(); }
1104  MDTuple &operator*() const { return *get(); }
1105 
1106  // FIXME: Fix callers and remove condition on N.
1107  unsigned size() const { return N ? N->getNumOperands() : 0u; }
1108  T *operator[](unsigned I) const { return cast_or_null<T>(N->getOperand(I)); }
1109 
1110  // FIXME: Fix callers and remove condition on N.
1112  iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); }
1113  iterator end() const { return N ? iterator(N->op_end()) : iterator(); }
1114 };
1115 
1116 #define HANDLE_METADATA(CLASS) \
1117  typedef MDTupleTypedArrayWrapper<CLASS> CLASS##Array;
1118 #include "llvm/IR/Metadata.def"
1119 
1120 //===----------------------------------------------------------------------===//
1121 /// \brief A tuple of MDNodes.
1122 ///
1123 /// Despite its name, a NamedMDNode isn't itself an MDNode. NamedMDNodes belong
1124 /// to modules, have names, and contain lists of MDNodes.
1125 ///
1126 /// TODO: Inherit from Metadata.
1127 class NamedMDNode : public ilist_node<NamedMDNode> {
1129  friend struct ilist_traits<NamedMDNode>;
1130  friend class LLVMContextImpl;
1131  friend class Module;
1132  NamedMDNode(const NamedMDNode &) = delete;
1133 
1134  std::string Name;
1135  Module *Parent;
1136  void *Operands; // SmallVector<TrackingMDRef, 4>
1137 
1138  void setParent(Module *M) { Parent = M; }
1139 
1140  explicit NamedMDNode(const Twine &N);
1141 
1142  template<class T1, class T2>
1143  class op_iterator_impl :
1144  public std::iterator<std::bidirectional_iterator_tag, T2> {
1145  const NamedMDNode *Node;
1146  unsigned Idx;
1147  op_iterator_impl(const NamedMDNode *N, unsigned i) : Node(N), Idx(i) { }
1148 
1149  friend class NamedMDNode;
1150 
1151  public:
1152  op_iterator_impl() : Node(nullptr), Idx(0) { }
1153 
1154  bool operator==(const op_iterator_impl &o) const { return Idx == o.Idx; }
1155  bool operator!=(const op_iterator_impl &o) const { return Idx != o.Idx; }
1156  op_iterator_impl &operator++() {
1157  ++Idx;
1158  return *this;
1159  }
1160  op_iterator_impl operator++(int) {
1161  op_iterator_impl tmp(*this);
1162  operator++();
1163  return tmp;
1164  }
1165  op_iterator_impl &operator--() {
1166  --Idx;
1167  return *this;
1168  }
1169  op_iterator_impl operator--(int) {
1170  op_iterator_impl tmp(*this);
1171  operator--();
1172  return tmp;
1173  }
1174 
1175  T1 operator*() const { return Node->getOperand(Idx); }
1176  };
1177 
1178 public:
1179  /// \brief Drop all references and remove the node from parent module.
1180  void eraseFromParent();
1181 
1182  /// \brief Remove all uses and clear node vector.
1183  void dropAllReferences();
1184 
1185  ~NamedMDNode();
1186 
1187  /// \brief Get the module that holds this named metadata collection.
1188  inline Module *getParent() { return Parent; }
1189  inline const Module *getParent() const { return Parent; }
1190 
1191  MDNode *getOperand(unsigned i) const;
1192  unsigned getNumOperands() const;
1193  void addOperand(MDNode *M);
1194  void setOperand(unsigned I, MDNode *New);
1195  StringRef getName() const;
1196  void print(raw_ostream &ROS) const;
1197  void dump() const;
1198 
1199  // ---------------------------------------------------------------------------
1200  // Operand Iterator interface...
1201  //
1202  typedef op_iterator_impl<MDNode *, MDNode> op_iterator;
1203  op_iterator op_begin() { return op_iterator(this, 0); }
1205 
1206  typedef op_iterator_impl<const MDNode *, MDNode> const_op_iterator;
1207  const_op_iterator op_begin() const { return const_op_iterator(this, 0); }
1209 
1212  }
1215  }
1216 };
1217 
1218 } // end llvm namespace
1219 
1220 #endif
LLVMContext & getContext() const
Definition: Metadata.h:679
StringRef getName() const
Definition: Metadata.cpp:986
static void deleteTemporary(MDNode *N)
Deallocate a node created by getTemporary.
Definition: Metadata.cpp:717
unsigned getLength() const
Definition: Metadata.h:527
Tracking metadata reference owned by Metadata.
Definition: Metadata.h:597
bool hasReplaceableUses() const
Whether this contains RAUW support.
Definition: Metadata.h:676
MDTupleTypedArrayWrapper(const MDTupleTypedArrayWrapper< U > &Other, typename std::enable_if< std::is_convertible< U *, T * >::value >::type *=nullptr)
Definition: Metadata.h:1086
ContextAndReplaceableUses(std::unique_ptr< ReplaceableMetadataImpl > ReplaceableUses)
Definition: Metadata.h:666
MetadataTracking::OwnerTy OwnerTy
Definition: Metadata.h:208
static bool classof(const Metadata *MD)
Definition: Metadata.h:1025
const Module * getParent() const
Definition: Metadata.h:1189
MDNode * Scope
The tag for alias scope specification (used with noalias).
Definition: Metadata.h:565
size_t size() const
size - Get the string size.
Definition: StringRef.h:113
iterator_range< op_iterator > op_range
Definition: Metadata.h:926
MDNode * TBAA
The tag for type-based alias analysis.
Definition: Metadata.h:562
MDTuple * get() const
Definition: Metadata.h:1102
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMap.h:28
void dump() const
Definition: AsmWriter.cpp:3369
TypedMDOperandIterator operator++(int)
Definition: Metadata.h:1065
static std::enable_if< std::is_base_of< MDNode, T >::value, T * >::type replaceWithPermanent(std::unique_ptr< T, TempMDNodeDeleter > N)
Replace a temporary node with a permanent one.
Definition: Metadata.h:844
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:114
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1036
bool operator==(const AAMDNodes &A) const
Definition: Metadata.h:553
MDTuple * operator->() const
Definition: Metadata.h:1103
void replaceOperandWith(unsigned I, Metadata *New)
Replace a specific operand.
Definition: Metadata.cpp:743
static bool classof(const Metadata *MD)
Definition: Metadata.h:329
std::unique_ptr< ReplaceableMetadataImpl > takeReplaceableUses()
Drop RAUW support.
Definition: Metadata.h:706
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:942
static MDTuple * getIfExists(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1001
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
static MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)
Definition: Metadata.cpp:810
void addOperand(MDNode *M)
Definition: Metadata.cpp:971
ContextAndReplaceableUses(LLVMContext &Context)
Definition: Metadata.h:665
void storeDistinctInContext()
Definition: Metadata.cpp:723
const unsigned char * bytes_end() const
Definition: StringRef.h:97
static ConstantAsMetadata * getConstantIfExists(Value *C)
Definition: Metadata.h:280
op_iterator op_begin() const
Definition: Metadata.h:928
MDTupleTypedArrayWrapper(const MDTuple *N)
Definition: Metadata.h:1083
void dropAllReferences()
Definition: Metadata.cpp:577
Shared implementation of use-lists for replaceable metadata.
Definition: Metadata.h:204
Metadata node.
Definition: Metadata.h:740
Manage lifetime of a slot tracker for printing IR.
static T * storeImpl(T *N, StorageType Storage, StoreT &Store)
Definition: MetadataImpl.h:30
Typed, array-like tuple of metadata.
Definition: Metadata.h:1078
void setOperand(unsigned I, Metadata *New)
Set an operand.
Definition: Metadata.cpp:755
bool operator==(const TypedMDOperandIterator &X) const
Definition: Metadata.h:1070
ReplaceableMetadataImpl(LLVMContext &Context)
Definition: Metadata.h:216
void setOperand(unsigned I, MDNode *New)
Definition: Metadata.cpp:973
void print(raw_ostream &ROS) const
Definition: AsmWriter.cpp:3154
op_iterator op_end() const
Definition: Metadata.h:931
Tuple of metadata.
Definition: Metadata.h:972
~ValueAsMetadata()=default
static std::enable_if< std::is_base_of< MDNode, T >::value, T * >::type replaceWithDistinct(std::unique_ptr< T, TempMDNodeDeleter > N)
Replace a temporary node with a distinct one.
Definition: Metadata.h:866
Metadata * get() const
Definition: Metadata.h:609
static AAMDNodes getEmptyKey()
Definition: Metadata.h:574
A tuple of MDNodes.
Definition: Metadata.h:1127
iterator end() const
Pointer to one byte past the end of the string.
Definition: Metadata.h:535
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
T * operator[](unsigned I) const
Definition: Metadata.h:1108
void makeReplaceable(std::unique_ptr< ReplaceableMetadataImpl > ReplaceableUses)
Assign RAUW support to this.
Definition: Metadata.h:695
const unsigned char * bytes_end() const
Definition: Metadata.h:538
static Yes & hasDereference(SFINAE< sizeof(static_cast< V >(*make< U >()))> *=0)
void eraseFromParent()
Drop all references and remove the node from parent module.
Definition: Metadata.cpp:978
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
static bool track(Metadata *&MD)
Track the reference to metadata.
const unsigned char * bytes_begin() const
Definition: Metadata.h:537
unsigned short SubclassData16
Definition: Metadata.h:59
Typed iterator through MDNode operands.
Definition: Metadata.h:1053
MDTuple & operator*() const
Definition: Metadata.h:1104
~MDNode()=default
TypedMDOperandIterator & operator++()
Definition: Metadata.h:1061
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:591
void resolveCycles()
Resolve cycles.
Definition: Metadata.cpp:520
API for tracking metadata references through RAUW and deletion.
MDTupleTypedArrayWrapper(const MDTupleTypedArrayWrapper< U > &Other, typename std::enable_if<!std::is_convertible< U *, T * >::value >::type *=nullptr)
Definition: Metadata.h:1093
bool isTBAAVtableAccess() const
Check whether MDNode is a vtable access.
static bool classof(const Metadata *MD)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Metadata.h:945
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a distinct node.
Definition: Metadata.h:1008
static void handleRAUW(Value *From, Value *To)
Definition: Metadata.cpp:295
void operator()(MDNode *Node) const
Definition: Metadata.h:1044
bool operator!=(const TypedMDOperandIterator &X) const
Definition: Metadata.h:1071
StringRef::iterator iterator
Definition: Metadata.h:529
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:31
static MDNode * intersect(MDNode *A, MDNode *B)
Definition: Metadata.cpp:796
Value wrapper in the Metadata hierarchy.
Definition: Metadata.h:252
void replaceAllUsesWith(Metadata *MD)
RAUW a temporary.
Definition: Metadata.h:824
LLVMContext & getContext() const
Definition: Metadata.h:289
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a temporary node.
Definition: Metadata.h:1017
unsigned SubclassData32
Definition: Metadata.h:60
iterator_range< op_iterator > operands()
Definition: Metadata.h:1210
LLVMConstants
Definition: Metadata.h:38
iterator begin() const
Definition: StringRef.h:90
static bool classof(const Metadata *MD)
Definition: Metadata.h:350
static bool classof(const Value *V)
Definition: Metadata.h:189
static MDNode * getMostGenericRange(MDNode *A, MDNode *B)
Definition: Metadata.cpp:872
AAMDNodes(MDNode *T=nullptr, MDNode *S=nullptr, MDNode *N=nullptr)
Definition: Metadata.h:549
static std::enable_if< std::is_base_of< MDNode, T >::value, T * >::type replaceWithUniqued(std::unique_ptr< T, TempMDNodeDeleter > N)
Replace a temporary node with a uniqued one.
Definition: Metadata.h:856
ValueAsMetadata(unsigned ID, Value *V)
Definition: Metadata.h:264
void resolveAllUses(bool ResolveUsers=true)
Resolve all uses of this.
Definition: Metadata.cpp:209
MDOperand * mutable_end()
Definition: Metadata.h:774
iterator_range< MDOperand * > mutable_op_range
Definition: Metadata.h:776
static ValueAsMetadata * getIfExists(Value *V)
Definition: Metadata.cpp:271
static LocalAsMetadata * getLocal(Value *Local)
Definition: Metadata.h:275
static MetadataAsValue * getIfExists(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:83
bool isTemporary() const
Definition: Metadata.h:819
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:41
bool operator!=(const AAMDNodes &A) const
Definition: Metadata.h:557
const MDOperand * op_iterator
Definition: Metadata.h:925
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:998
This is an important base class in LLVM.
Definition: Constant.h:41
iterator begin() const
Definition: Metadata.h:1112
StorageType
Active type of storage.
Definition: Metadata.h:53
unsigned getMetadataID() const
Definition: Metadata.h:107
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
MDNode * getOperand(unsigned i) const
Definition: Metadata.cpp:965
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:362
static ConstantAsMetadata * getIfExists(Constant *C)
Definition: Metadata.h:321
SI Fold Operands
static SimpleType getSimplifiedValue(MDOperand &MD)
Definition: Metadata.h:642
Metadata wrapper in the Value hierarchy.
Definition: Metadata.h:172
static MDNode * getMostGenericTBAA(MDNode *A, MDNode *B)
TempMDNode clone() const
Create a (temporary) clone of this.
Definition: Metadata.cpp:437
Metadata & operator*() const
Definition: Metadata.h:612
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:519
void handleChangedOperand(void *, Metadata *)
Default handling of a changed operand, which asserts.
Definition: Metadata.h:102
void print(raw_ostream &OS, const Module *M=nullptr) const
Print.
Definition: AsmWriter.cpp:3341
void dump() const
User-friendly dump.
Definition: AsmWriter.cpp:3372
mutable_op_range mutable_operands()
Definition: Metadata.h:777
op_iterator op_end()
Definition: Metadata.h:1204
std::enable_if< detail::IsValidPointer< X, Y >::value, X * >::type extract(Y &&MD)
Extract a Value from Metadata.
Definition: Metadata.h:453
static bool classof(const Metadata *MD)
Methods for support type inquiry through isa, cast, and dyn_cast.
Definition: Metadata.h:541
static bool isEqual(const AAMDNodes &LHS, const AAMDNodes &RHS)
Definition: Metadata.h:585
unsigned getHash() const
Get the hash, if any.
Definition: Metadata.h:996
StringRef getString() const
Definition: Metadata.cpp:375
const char * iterator
Definition: StringRef.h:42
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:936
Metadata * getMetadata() const
Definition: Metadata.h:187
static bool classof(const Metadata *MD)
Definition: Metadata.h:305
BlockMass operator*(const BlockMass &L, const BranchProbability &R)
unsigned Storage
Storage flag for non-uniqued, otherwise unowned, metadata.
Definition: Metadata.h:56
static ConstantAsMetadata * getConstant(Value *C)
Definition: Metadata.h:272
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:222
static LocalAsMetadata * getIfExists(Value *Local)
Definition: Metadata.h:346
~Metadata()=default
void printAsOperand(raw_ostream &OS, const Module *M=nullptr) const
Print as operand.
Definition: AsmWriter.cpp:3331
static MDTuple * getIfExists(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1033
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition: Metadata.h:548
TempMDTuple clone() const
Return a (temporary) clone of this.
Definition: Metadata.h:1023
MDNode * NoAlias
The tag specifying the noalias scope.
Definition: Metadata.h:568
static LocalAsMetadata * getLocalIfExists(Value *Local)
Definition: Metadata.h:283
void reset()
Definition: Metadata.h:614
A range adaptor for a pair of iterators.
static void untrack(Metadata *&MD)
Stop tracking a reference to metadata.
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1039
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:285
std::enable_if< detail::IsValidPointer< X, Y >::value, X * >::type extract_or_null(Y &&MD)
Extract a Value from Metadata, allowing null.
Definition: Metadata.h:469
Type * getType() const
Definition: Metadata.h:288
std::enable_if< detail::IsValidPointer< X, Y >::value, bool >::type hasa(Y &&MD)
Check whether Metadata has a Value.
Definition: Metadata.h:435
const_op_iterator op_begin() const
Definition: Metadata.h:1207
Pointer to the context, with optional RAUW support.
Definition: Metadata.h:654
MDOperand * mutable_begin()
Definition: Metadata.h:773
std::enable_if< detail::IsValidPointer< X, Y >::value, X * >::type dyn_extract_or_null(Y &&MD)
Extract a Value from Metadata, if any, allowing null.
Definition: Metadata.h:495
bool isDistinct() const
Definition: Metadata.h:818
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1030
bool operator!=(uint64_t V1, const APInt &V2)
Definition: APInt.h:1736
static AAMDNodes getTombstoneKey()
Definition: Metadata.h:577
ilist_node - Base class that provides next/prev services for nodes that use ilist_nextprev_traits or ...
Definition: ilist_node.h:43
TypedMDOperandIterator< T > iterator
Definition: Metadata.h:1111
Value * getValue() const
Definition: Metadata.h:287
void replaceAllUsesWith(Metadata *MD)
Handle collisions after Value::replaceAllUsesWith().
Definition: Metadata.h:300
op_iterator_impl< MDNode *, MDNode > op_iterator
Definition: Metadata.h:1202
static SimpleType getSimplifiedValue(const MDOperand &MD)
Definition: Metadata.h:647
static MDNode * concatenate(MDNode *A, MDNode *B)
Methods for metadata merging.
Definition: Metadata.cpp:780
iterator begin() const
Pointer to the first byte of the string.
Definition: Metadata.h:532
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
unsigned size() const
Definition: Metadata.h:1107
Metadata * operator->() const
Definition: Metadata.h:611
op_iterator_impl< const MDNode *, MDNode > const_op_iterator
Definition: Metadata.h:1206
op_range operands() const
Definition: Metadata.h:934
LLVMContext & getContext() const
Definition: Metadata.h:799
void replaceAllUsesWith(Metadata *MD)
Replace all uses of this with MD.
Definition: Metadata.cpp:158
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:1738
Constant * getValue() const
Definition: Metadata.h:325
op_iterator op_begin()
Definition: Metadata.h:1203
iterator_range< const_op_iterator > operands() const
Definition: Metadata.h:1213
bool isUniqued() const
Definition: Metadata.h:817
const unsigned char * bytes_begin() const
Definition: StringRef.h:94
aarch64 promote const
static void handleDeletion(Value *V)
Definition: Metadata.cpp:276
LLVM Value Representation.
Definition: Value.h:69
const_op_iterator op_end() const
Definition: Metadata.h:1208
void reset(Metadata *MD, Metadata *Owner)
Definition: Metadata.h:618
ContextAndReplaceableUses Context
Definition: Metadata.h:752
static unsigned getHashValue(const AAMDNodes &Val)
Definition: Metadata.h:580
Metadata(unsigned ID, StorageType Storage)
Definition: Metadata.h:93
iterator end() const
Definition: StringRef.h:92
unsigned getNumOperands() const
Definition: Metadata.cpp:961
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
std::string Hash(const Unit &U)
Definition: FuzzerUtil.cpp:39
void dropAllReferences()
Remove all uses and clear node vector.
Definition: Metadata.cpp:982
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
A single uniqued string.
Definition: Metadata.h:508
std::enable_if< detail::IsValidPointer< X, Y >::value, X * >::type dyn_extract(Y &&MD)
Extract a Value from Metadata, if any.
Definition: Metadata.h:482
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
ReplaceableMetadataImpl * getReplaceableUses() const
Definition: Metadata.h:684
bool operator==(uint64_t V1, const APInt &V2)
Definition: APInt.h:1734
static MDNode * getMostGenericFPMath(MDNode *A, MDNode *B)
Definition: Metadata.cpp:824
bool isResolved() const
Check if node is fully resolved.
Definition: Metadata.h:815
TypedMDOperandIterator(MDNode::op_iterator I)
Definition: Metadata.h:1059
Root of the metadata hierarchy.
Definition: Metadata.h:45
LLVMContext & getContext() const
Definition: Metadata.h:222
#define T1
Module * getParent()
Get the module that holds this named metadata collection.
Definition: Metadata.h:1188
PointerUnion - This implements a discriminated union of two pointer types, and keeps the discriminato...
Definition: PointerUnion.h:81