LLVM  7.0.0svn
DebugInfoMetadata.h
Go to the documentation of this file.
1 //===- llvm/IR/DebugInfoMetadata.h - Debug info metadata --------*- 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 // Declarations for metadata specific to debug info.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_IR_DEBUGINFOMETADATA_H
15 #define LLVM_IR_DEBUGINFOMETADATA_H
16 
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/BitmaskEnum.h"
19 #include "llvm/ADT/None.h"
20 #include "llvm/ADT/Optional.h"
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/StringRef.h"
26 #include "llvm/IR/Metadata.h"
27 #include "llvm/Support/Casting.h"
28 #include <cassert>
29 #include <climits>
30 #include <cstddef>
31 #include <cstdint>
32 #include <iterator>
33 #include <type_traits>
34 #include <vector>
35 
36 // Helper macros for defining get() overrides.
37 #define DEFINE_MDNODE_GET_UNPACK_IMPL(...) __VA_ARGS__
38 #define DEFINE_MDNODE_GET_UNPACK(ARGS) DEFINE_MDNODE_GET_UNPACK_IMPL ARGS
39 #define DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS) \
40  static CLASS *getDistinct(LLVMContext &Context, \
41  DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
42  return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct); \
43  } \
44  static Temp##CLASS getTemporary(LLVMContext &Context, \
45  DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
46  return Temp##CLASS( \
47  getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary)); \
48  }
49 #define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS) \
50  static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
51  return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued); \
52  } \
53  static CLASS *getIfExists(LLVMContext &Context, \
54  DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
55  return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued, \
56  /* ShouldCreate */ false); \
57  } \
58  DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS)
59 
60 namespace llvm {
61 
62 /// Holds a subclass of DINode.
63 ///
64 /// FIXME: This class doesn't currently make much sense. Previously it was a
65 /// union beteen MDString (for ODR-uniqued types) and things like DIType. To
66 /// support CodeView work, it wasn't deleted outright when MDString-based type
67 /// references were deleted; we'll soon need a similar concept for CodeView
68 /// DITypeIndex.
69 template <class T> class TypedDINodeRef {
70  const Metadata *MD = nullptr;
71 
72 public:
73  TypedDINodeRef() = default;
74  TypedDINodeRef(std::nullptr_t) {}
75  TypedDINodeRef(const T *MD) : MD(MD) {}
76 
77  explicit TypedDINodeRef(const Metadata *MD) : MD(MD) {
78  assert((!MD || isa<T>(MD)) && "Expected valid type ref");
79  }
80 
81  template <class U>
83  const TypedDINodeRef<U> &X,
84  typename std::enable_if<std::is_convertible<U *, T *>::value>::type * =
85  nullptr)
86  : MD(X) {}
87 
88  operator Metadata *() const { return const_cast<Metadata *>(MD); }
89 
90  T *resolve() const { return const_cast<T *>(cast_or_null<T>(MD)); }
91 
92  bool operator==(const TypedDINodeRef<T> &X) const { return MD == X.MD; }
93  bool operator!=(const TypedDINodeRef<T> &X) const { return MD != X.MD; }
94 };
95 
99 
101  const MDTuple *N = nullptr;
102 
103 public:
104  DITypeRefArray() = default;
105  DITypeRefArray(const MDTuple *N) : N(N) {}
106 
107  explicit operator bool() const { return get(); }
108  explicit operator MDTuple *() const { return get(); }
109 
110  MDTuple *get() const { return const_cast<MDTuple *>(N); }
111  MDTuple *operator->() const { return get(); }
112  MDTuple &operator*() const { return *get(); }
113 
114  // FIXME: Fix callers and remove condition on N.
115  unsigned size() const { return N ? N->getNumOperands() : 0u; }
116  DITypeRef operator[](unsigned I) const { return DITypeRef(N->getOperand(I)); }
117 
118  class iterator : std::iterator<std::input_iterator_tag, DITypeRef,
119  std::ptrdiff_t, void, DITypeRef> {
120  MDNode::op_iterator I = nullptr;
121 
122  public:
123  iterator() = default;
124  explicit iterator(MDNode::op_iterator I) : I(I) {}
125 
126  DITypeRef operator*() const { return DITypeRef(*I); }
127 
129  ++I;
130  return *this;
131  }
132 
134  iterator Temp(*this);
135  ++I;
136  return Temp;
137  }
138 
139  bool operator==(const iterator &X) const { return I == X.I; }
140  bool operator!=(const iterator &X) const { return I != X.I; }
141  };
142 
143  // FIXME: Fix callers and remove condition on N.
144  iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); }
145  iterator end() const { return N ? iterator(N->op_end()) : iterator(); }
146 };
147 
148 /// Tagged DWARF-like metadata node.
149 ///
150 /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
151 /// defined in llvm/BinaryFormat/Dwarf.h). Called \a DINode because it's
152 /// potentially used for non-DWARF output.
153 class DINode : public MDNode {
154  friend class LLVMContextImpl;
155  friend class MDNode;
156 
157 protected:
158  DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
160  : MDNode(C, ID, Storage, Ops1, Ops2) {
161  assert(Tag < 1u << 16);
162  SubclassData16 = Tag;
163  }
164  ~DINode() = default;
165 
166  template <class Ty> Ty *getOperandAs(unsigned I) const {
167  return cast_or_null<Ty>(getOperand(I));
168  }
169 
170  StringRef getStringOperand(unsigned I) const {
171  if (auto *S = getOperandAs<MDString>(I))
172  return S->getString();
173  return StringRef();
174  }
175 
177  if (S.empty())
178  return nullptr;
179  return MDString::get(Context, S);
180  }
181 
182  /// Allow subclasses to mutate the tag.
183  void setTag(unsigned Tag) { SubclassData16 = Tag; }
184 
185 public:
186  unsigned getTag() const { return SubclassData16; }
187 
188  /// Debug info flags.
189  ///
190  /// The three accessibility flags are mutually exclusive and rolled together
191  /// in the first two bits.
192  enum DIFlags : uint32_t {
193 #define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
194 #define DI_FLAG_LARGEST_NEEDED
195 #include "llvm/IR/DebugInfoFlags.def"
196  FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic,
197  FlagPtrToMemberRep = FlagSingleInheritance | FlagMultipleInheritance |
198  FlagVirtualInheritance,
199  LLVM_MARK_AS_BITMASK_ENUM(FlagLargest)
200  };
201 
202  static DIFlags getFlag(StringRef Flag);
203  static StringRef getFlagString(DIFlags Flag);
204 
205  /// Split up a flags bitfield.
206  ///
207  /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
208  /// any remaining (unrecognized) bits.
209  static DIFlags splitFlags(DIFlags Flags,
210  SmallVectorImpl<DIFlags> &SplitFlags);
211 
212  static bool classof(const Metadata *MD) {
213  switch (MD->getMetadataID()) {
214  default:
215  return false;
216  case GenericDINodeKind:
217  case DISubrangeKind:
218  case DIEnumeratorKind:
219  case DIBasicTypeKind:
220  case DIDerivedTypeKind:
221  case DICompositeTypeKind:
222  case DISubroutineTypeKind:
223  case DIFileKind:
224  case DICompileUnitKind:
225  case DISubprogramKind:
226  case DILexicalBlockKind:
227  case DILexicalBlockFileKind:
228  case DINamespaceKind:
229  case DITemplateTypeParameterKind:
230  case DITemplateValueParameterKind:
231  case DIGlobalVariableKind:
232  case DILocalVariableKind:
233  case DIObjCPropertyKind:
234  case DIImportedEntityKind:
235  case DIModuleKind:
236  return true;
237  }
238  }
239 };
240 
241 template <class T> struct simplify_type<const TypedDINodeRef<T>> {
242  using SimpleType = Metadata *;
243 
245  return MD;
246  }
247 };
248 
249 template <class T>
251  : simplify_type<const TypedDINodeRef<T>> {};
252 
253 /// Generic tagged DWARF-like metadata node.
254 ///
255 /// An un-specialized DWARF-like metadata node. The first operand is a
256 /// (possibly empty) null-separated \a MDString header that contains arbitrary
257 /// fields. The remaining operands are \a dwarf_operands(), and are pointers
258 /// to other metadata.
259 class GenericDINode : public DINode {
260  friend class LLVMContextImpl;
261  friend class MDNode;
262 
263  GenericDINode(LLVMContext &C, StorageType Storage, unsigned Hash,
264  unsigned Tag, ArrayRef<Metadata *> Ops1,
266  : DINode(C, GenericDINodeKind, Storage, Tag, Ops1, Ops2) {
267  setHash(Hash);
268  }
269  ~GenericDINode() { dropAllReferences(); }
270 
271  void setHash(unsigned Hash) { SubclassData32 = Hash; }
272  void recalculateHash();
273 
274  static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
275  StringRef Header, ArrayRef<Metadata *> DwarfOps,
276  StorageType Storage, bool ShouldCreate = true) {
277  return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
278  DwarfOps, Storage, ShouldCreate);
279  }
280 
281  static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
282  MDString *Header, ArrayRef<Metadata *> DwarfOps,
283  StorageType Storage, bool ShouldCreate = true);
284 
285  TempGenericDINode cloneImpl() const {
286  return getTemporary(
287  getContext(), getTag(), getHeader(),
288  SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
289  }
290 
291 public:
292  unsigned getHash() const { return SubclassData32; }
293 
294  DEFINE_MDNODE_GET(GenericDINode, (unsigned Tag, StringRef Header,
295  ArrayRef<Metadata *> DwarfOps),
296  (Tag, Header, DwarfOps))
297  DEFINE_MDNODE_GET(GenericDINode, (unsigned Tag, MDString *Header,
298  ArrayRef<Metadata *> DwarfOps),
299  (Tag, Header, DwarfOps))
300 
301  /// Return a (temporary) clone of this.
302  TempGenericDINode clone() const { return cloneImpl(); }
303 
304  unsigned getTag() const { return SubclassData16; }
305  StringRef getHeader() const { return getStringOperand(0); }
306  MDString *getRawHeader() const { return getOperandAs<MDString>(0); }
307 
308  op_iterator dwarf_op_begin() const { return op_begin() + 1; }
309  op_iterator dwarf_op_end() const { return op_end(); }
311  return op_range(dwarf_op_begin(), dwarf_op_end());
312  }
313 
314  unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
315  const MDOperand &getDwarfOperand(unsigned I) const {
316  return getOperand(I + 1);
317  }
318  void replaceDwarfOperandWith(unsigned I, Metadata *New) {
319  replaceOperandWith(I + 1, New);
320  }
321 
322  static bool classof(const Metadata *MD) {
323  return MD->getMetadataID() == GenericDINodeKind;
324  }
325 };
326 
327 /// Array subrange.
328 ///
329 /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
330 /// type.
331 class DISubrange : public DINode {
332  friend class LLVMContextImpl;
333  friend class MDNode;
334 
335  int64_t Count;
336  int64_t LowerBound;
337 
338  DISubrange(LLVMContext &C, StorageType Storage, int64_t Count,
339  int64_t LowerBound)
340  : DINode(C, DISubrangeKind, Storage, dwarf::DW_TAG_subrange_type, None),
341  Count(Count), LowerBound(LowerBound) {}
342  ~DISubrange() = default;
343 
344  static DISubrange *getImpl(LLVMContext &Context, int64_t Count,
345  int64_t LowerBound, StorageType Storage,
346  bool ShouldCreate = true);
347 
348  TempDISubrange cloneImpl() const {
349  return getTemporary(getContext(), getCount(), getLowerBound());
350  }
351 
352 public:
353  DEFINE_MDNODE_GET(DISubrange, (int64_t Count, int64_t LowerBound = 0),
354  (Count, LowerBound))
355 
356  TempDISubrange clone() const { return cloneImpl(); }
357 
358  int64_t getLowerBound() const { return LowerBound; }
359  int64_t getCount() const { return Count; }
360 
361  static bool classof(const Metadata *MD) {
362  return MD->getMetadataID() == DISubrangeKind;
363  }
364 };
365 
366 /// Enumeration value.
367 ///
368 /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
369 /// longer creates a type cycle.
370 class DIEnumerator : public DINode {
371  friend class LLVMContextImpl;
372  friend class MDNode;
373 
374  int64_t Value;
375 
376  DIEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
378  : DINode(C, DIEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
379  Value(Value) {}
380  ~DIEnumerator() = default;
381 
382  static DIEnumerator *getImpl(LLVMContext &Context, int64_t Value,
383  StringRef Name, StorageType Storage,
384  bool ShouldCreate = true) {
385  return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
386  ShouldCreate);
387  }
388  static DIEnumerator *getImpl(LLVMContext &Context, int64_t Value,
389  MDString *Name, StorageType Storage,
390  bool ShouldCreate = true);
391 
392  TempDIEnumerator cloneImpl() const {
393  return getTemporary(getContext(), getValue(), getName());
394  }
395 
396 public:
397  DEFINE_MDNODE_GET(DIEnumerator, (int64_t Value, StringRef Name),
398  (Value, Name))
399  DEFINE_MDNODE_GET(DIEnumerator, (int64_t Value, MDString *Name),
400  (Value, Name))
401 
402  TempDIEnumerator clone() const { return cloneImpl(); }
403 
404  int64_t getValue() const { return Value; }
405  StringRef getName() const { return getStringOperand(0); }
406 
407  MDString *getRawName() const { return getOperandAs<MDString>(0); }
408 
409  static bool classof(const Metadata *MD) {
410  return MD->getMetadataID() == DIEnumeratorKind;
411  }
412 };
413 
414 /// Base class for scope-like contexts.
415 ///
416 /// Base class for lexical scopes and types (which are also declaration
417 /// contexts).
418 ///
419 /// TODO: Separate the concepts of declaration contexts and lexical scopes.
420 class DIScope : public DINode {
421 protected:
422  DIScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
424  : DINode(C, ID, Storage, Tag, Ops) {}
425  ~DIScope() = default;
426 
427 public:
428  DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
429 
430  inline StringRef getFilename() const;
431  inline StringRef getDirectory() const;
432 
433  StringRef getName() const;
434  DIScopeRef getScope() const;
435 
436  /// Return the raw underlying file.
437  ///
438  /// A \a DIFile is a \a DIScope, but it doesn't point at a separate file (it
439  /// \em is the file). If \c this is an \a DIFile, we need to return \c this.
440  /// Otherwise, return the first operand, which is where all other subclasses
441  /// store their file pointer.
442  Metadata *getRawFile() const {
443  return isa<DIFile>(this) ? const_cast<DIScope *>(this)
444  : static_cast<Metadata *>(getOperand(0));
445  }
446 
447  static bool classof(const Metadata *MD) {
448  switch (MD->getMetadataID()) {
449  default:
450  return false;
451  case DIBasicTypeKind:
452  case DIDerivedTypeKind:
453  case DICompositeTypeKind:
454  case DISubroutineTypeKind:
455  case DIFileKind:
456  case DICompileUnitKind:
457  case DISubprogramKind:
458  case DILexicalBlockKind:
459  case DILexicalBlockFileKind:
460  case DINamespaceKind:
461  case DIModuleKind:
462  return true;
463  }
464  }
465 };
466 
467 /// File.
468 ///
469 /// TODO: Merge with directory/file node (including users).
470 /// TODO: Canonicalize paths on creation.
471 class DIFile : public DIScope {
472  friend class LLVMContextImpl;
473  friend class MDNode;
474 
475 public:
476  // These values must be explictly set, as they end up in the final object
477  // file.
479  CSK_None = 0,
480  CSK_MD5 = 1,
481  CSK_SHA1 = 2,
482  CSK_Last = CSK_SHA1 // Should be last enumeration.
483  };
484 
485 private:
486  ChecksumKind CSKind;
487 
490  : DIScope(C, DIFileKind, Storage, dwarf::DW_TAG_file_type, Ops),
491  CSKind(CSK) {}
492  ~DIFile() = default;
493 
494  static DIFile *getImpl(LLVMContext &Context, StringRef Filename,
495  StringRef Directory, ChecksumKind CSK, StringRef CS,
496  StorageType Storage, bool ShouldCreate = true) {
497  return getImpl(Context, getCanonicalMDString(Context, Filename),
498  getCanonicalMDString(Context, Directory), CSK,
499  getCanonicalMDString(Context, CS), Storage, ShouldCreate);
500  }
501  static DIFile *getImpl(LLVMContext &Context, MDString *Filename,
502  MDString *Directory, ChecksumKind CSK, MDString *CS,
503  StorageType Storage, bool ShouldCreate = true);
504 
505  TempDIFile cloneImpl() const {
506  return getTemporary(getContext(), getFilename(), getDirectory(),
507  getChecksumKind(), getChecksum());
508  }
509 
510 public:
511  DEFINE_MDNODE_GET(DIFile, (StringRef Filename, StringRef Directory,
512  ChecksumKind CSK = CSK_None,
513  StringRef CS = StringRef()),
514  (Filename, Directory, CSK, CS))
515  DEFINE_MDNODE_GET(DIFile, (MDString * Filename, MDString *Directory,
516  ChecksumKind CSK = CSK_None,
517  MDString *CS = nullptr),
518  (Filename, Directory, CSK, CS))
519 
520  TempDIFile clone() const { return cloneImpl(); }
521 
522  StringRef getFilename() const { return getStringOperand(0); }
523  StringRef getDirectory() const { return getStringOperand(1); }
524  StringRef getChecksum() const { return getStringOperand(2); }
525  ChecksumKind getChecksumKind() const { return CSKind; }
526  StringRef getChecksumKindAsString() const;
527 
528  MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
529  MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
530  MDString *getRawChecksum() const { return getOperandAs<MDString>(2); }
531 
532  static ChecksumKind getChecksumKind(StringRef CSKindStr);
533 
534  static bool classof(const Metadata *MD) {
535  return MD->getMetadataID() == DIFileKind;
536  }
537 };
538 
540  if (auto *F = getFile())
541  return F->getFilename();
542  return "";
543 }
544 
546  if (auto *F = getFile())
547  return F->getDirectory();
548  return "";
549 }
550 
551 /// Base class for types.
552 ///
553 /// TODO: Remove the hardcoded name and context, since many types don't use
554 /// them.
555 /// TODO: Split up flags.
556 class DIType : public DIScope {
557  unsigned Line;
558  DIFlags Flags;
559  uint64_t SizeInBits;
560  uint64_t OffsetInBits;
561  uint32_t AlignInBits;
562 
563 protected:
564  DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
565  unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits,
566  uint64_t OffsetInBits, DIFlags Flags, ArrayRef<Metadata *> Ops)
567  : DIScope(C, ID, Storage, Tag, Ops) {
568  init(Line, SizeInBits, AlignInBits, OffsetInBits, Flags);
569  }
570  ~DIType() = default;
571 
572  void init(unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits,
573  uint64_t OffsetInBits, DIFlags Flags) {
574  this->Line = Line;
575  this->Flags = Flags;
576  this->SizeInBits = SizeInBits;
577  this->AlignInBits = AlignInBits;
578  this->OffsetInBits = OffsetInBits;
579  }
580 
581  /// Change fields in place.
582  void mutate(unsigned Tag, unsigned Line, uint64_t SizeInBits,
583  uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags) {
584  assert(isDistinct() && "Only distinct nodes can mutate");
585  setTag(Tag);
586  init(Line, SizeInBits, AlignInBits, OffsetInBits, Flags);
587  }
588 
589 public:
590  TempDIType clone() const {
591  return TempDIType(cast<DIType>(MDNode::clone().release()));
592  }
593 
594  unsigned getLine() const { return Line; }
595  uint64_t getSizeInBits() const { return SizeInBits; }
596  uint32_t getAlignInBits() const { return AlignInBits; }
597  uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
598  uint64_t getOffsetInBits() const { return OffsetInBits; }
599  DIFlags getFlags() const { return Flags; }
600 
601  DIScopeRef getScope() const { return DIScopeRef(getRawScope()); }
602  StringRef getName() const { return getStringOperand(2); }
603 
604 
605  Metadata *getRawScope() const { return getOperand(1); }
606  MDString *getRawName() const { return getOperandAs<MDString>(2); }
607 
608  void setFlags(DIFlags NewFlags) {
609  assert(!isUniqued() && "Cannot set flags on uniqued nodes");
610  Flags = NewFlags;
611  }
612 
613  bool isPrivate() const {
614  return (getFlags() & FlagAccessibility) == FlagPrivate;
615  }
616  bool isProtected() const {
617  return (getFlags() & FlagAccessibility) == FlagProtected;
618  }
619  bool isPublic() const {
620  return (getFlags() & FlagAccessibility) == FlagPublic;
621  }
622  bool isForwardDecl() const { return getFlags() & FlagFwdDecl; }
623  bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; }
624  bool isBlockByrefStruct() const { return getFlags() & FlagBlockByrefStruct; }
625  bool isVirtual() const { return getFlags() & FlagVirtual; }
626  bool isArtificial() const { return getFlags() & FlagArtificial; }
627  bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
628  bool isObjcClassComplete() const {
629  return getFlags() & FlagObjcClassComplete;
630  }
631  bool isVector() const { return getFlags() & FlagVector; }
632  bool isBitField() const { return getFlags() & FlagBitField; }
633  bool isStaticMember() const { return getFlags() & FlagStaticMember; }
634  bool isLValueReference() const { return getFlags() & FlagLValueReference; }
635  bool isRValueReference() const { return getFlags() & FlagRValueReference; }
636  bool isTypePassByValue() const { return getFlags() & FlagTypePassByValue; }
637  bool isTypePassByReference() const {
638  return getFlags() & FlagTypePassByReference;
639  }
640 
641  static bool classof(const Metadata *MD) {
642  switch (MD->getMetadataID()) {
643  default:
644  return false;
645  case DIBasicTypeKind:
646  case DIDerivedTypeKind:
647  case DICompositeTypeKind:
648  case DISubroutineTypeKind:
649  return true;
650  }
651  }
652 };
653 
654 /// Basic type, like 'int' or 'float'.
655 ///
656 /// TODO: Split out DW_TAG_unspecified_type.
657 /// TODO: Drop unused accessors.
658 class DIBasicType : public DIType {
659  friend class LLVMContextImpl;
660  friend class MDNode;
661 
662  unsigned Encoding;
663 
664  DIBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
665  uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
667  : DIType(C, DIBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
668  FlagZero, Ops),
669  Encoding(Encoding) {}
670  ~DIBasicType() = default;
671 
672  static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
673  StringRef Name, uint64_t SizeInBits,
674  uint32_t AlignInBits, unsigned Encoding,
675  StorageType Storage, bool ShouldCreate = true) {
676  return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
677  SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
678  }
679  static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
680  MDString *Name, uint64_t SizeInBits,
681  uint32_t AlignInBits, unsigned Encoding,
682  StorageType Storage, bool ShouldCreate = true);
683 
684  TempDIBasicType cloneImpl() const {
685  return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
686  getAlignInBits(), getEncoding());
687  }
688 
689 public:
690  DEFINE_MDNODE_GET(DIBasicType, (unsigned Tag, StringRef Name),
691  (Tag, Name, 0, 0, 0))
693  (unsigned Tag, StringRef Name, uint64_t SizeInBits,
694  uint32_t AlignInBits, unsigned Encoding),
695  (Tag, Name, SizeInBits, AlignInBits, Encoding))
696  DEFINE_MDNODE_GET(DIBasicType,
697  (unsigned Tag, MDString *Name, uint64_t SizeInBits,
698  uint32_t AlignInBits, unsigned Encoding),
699  (Tag, Name, SizeInBits, AlignInBits, Encoding))
700 
701  TempDIBasicType clone() const { return cloneImpl(); }
702 
703  unsigned getEncoding() const { return Encoding; }
704 
705  static bool classof(const Metadata *MD) {
706  return MD->getMetadataID() == DIBasicTypeKind;
707  }
708 };
709 
710 /// Derived types.
711 ///
712 /// This includes qualified types, pointers, references, friends, typedefs, and
713 /// class members.
714 ///
715 /// TODO: Split out members (inheritance, fields, methods, etc.).
716 class DIDerivedType : public DIType {
717  friend class LLVMContextImpl;
718  friend class MDNode;
719 
720  /// \brief The DWARF address space of the memory pointed to or referenced by a
721  /// pointer or reference type respectively.
722  Optional<unsigned> DWARFAddressSpace;
723 
724  DIDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
725  unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits,
726  uint64_t OffsetInBits, Optional<unsigned> DWARFAddressSpace,
727  DIFlags Flags, ArrayRef<Metadata *> Ops)
728  : DIType(C, DIDerivedTypeKind, Storage, Tag, Line, SizeInBits,
729  AlignInBits, OffsetInBits, Flags, Ops),
730  DWARFAddressSpace(DWARFAddressSpace) {}
731  ~DIDerivedType() = default;
732 
733  static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
734  StringRef Name, DIFile *File, unsigned Line,
736  uint64_t SizeInBits, uint32_t AlignInBits,
737  uint64_t OffsetInBits,
738  Optional<unsigned> DWARFAddressSpace,
739  DIFlags Flags, Metadata *ExtraData,
740  StorageType Storage, bool ShouldCreate = true) {
741  return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
742  Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
743  DWARFAddressSpace, Flags, ExtraData, Storage, ShouldCreate);
744  }
745  static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
746  MDString *Name, Metadata *File, unsigned Line,
747  Metadata *Scope, Metadata *BaseType,
748  uint64_t SizeInBits, uint32_t AlignInBits,
749  uint64_t OffsetInBits,
750  Optional<unsigned> DWARFAddressSpace,
751  DIFlags Flags, Metadata *ExtraData,
752  StorageType Storage, bool ShouldCreate = true);
753 
754  TempDIDerivedType cloneImpl() const {
755  return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
756  getScope(), getBaseType(), getSizeInBits(),
757  getAlignInBits(), getOffsetInBits(),
758  getDWARFAddressSpace(), getFlags(), getExtraData());
759  }
760 
761 public:
763  (unsigned Tag, MDString *Name, Metadata *File,
764  unsigned Line, Metadata *Scope, Metadata *BaseType,
765  uint64_t SizeInBits, uint32_t AlignInBits,
766  uint64_t OffsetInBits,
767  Optional<unsigned> DWARFAddressSpace, DIFlags Flags,
768  Metadata *ExtraData = nullptr),
769  (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
770  AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
771  ExtraData))
773  (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
774  DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits,
775  uint32_t AlignInBits, uint64_t OffsetInBits,
776  Optional<unsigned> DWARFAddressSpace, DIFlags Flags,
777  Metadata *ExtraData = nullptr),
778  (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
779  AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
780  ExtraData))
781 
782  TempDIDerivedType clone() const { return cloneImpl(); }
783 
784  /// Get the base type this is derived from.
785  DITypeRef getBaseType() const { return DITypeRef(getRawBaseType()); }
786  Metadata *getRawBaseType() const { return getOperand(3); }
787 
788  /// \returns The DWARF address space of the memory pointed to or referenced by
789  /// a pointer or reference type respectively.
790  Optional<unsigned> getDWARFAddressSpace() const { return DWARFAddressSpace; }
791 
792  /// Get extra data associated with this derived type.
793  ///
794  /// Class type for pointer-to-members, objective-c property node for ivars,
795  /// or global constant wrapper for static members.
796  ///
797  /// TODO: Separate out types that need this extra operand: pointer-to-member
798  /// types and member fields (static members and ivars).
799  Metadata *getExtraData() const { return getRawExtraData(); }
800  Metadata *getRawExtraData() const { return getOperand(4); }
801 
802  /// Get casted version of extra data.
803  /// @{
804  DITypeRef getClassType() const {
805  assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
806  return DITypeRef(getExtraData());
807  }
808 
809  DIObjCProperty *getObjCProperty() const {
810  return dyn_cast_or_null<DIObjCProperty>(getExtraData());
811  }
812 
813  Constant *getStorageOffsetInBits() const {
814  assert(getTag() == dwarf::DW_TAG_member && isBitField());
815  if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
816  return C->getValue();
817  return nullptr;
818  }
819 
820  Constant *getConstant() const {
821  assert(getTag() == dwarf::DW_TAG_member && isStaticMember());
822  if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
823  return C->getValue();
824  return nullptr;
825  }
826  /// @}
827 
828  static bool classof(const Metadata *MD) {
829  return MD->getMetadataID() == DIDerivedTypeKind;
830  }
831 };
832 
833 /// Composite types.
834 ///
835 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
836 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
837 class DICompositeType : public DIType {
838  friend class LLVMContextImpl;
839  friend class MDNode;
840 
841  unsigned RuntimeLang;
842 
843  DICompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
844  unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
845  uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
847  : DIType(C, DICompositeTypeKind, Storage, Tag, Line, SizeInBits,
848  AlignInBits, OffsetInBits, Flags, Ops),
849  RuntimeLang(RuntimeLang) {}
850  ~DICompositeType() = default;
851 
852  /// Change fields in place.
853  void mutate(unsigned Tag, unsigned Line, unsigned RuntimeLang,
854  uint64_t SizeInBits, uint32_t AlignInBits,
855  uint64_t OffsetInBits, DIFlags Flags) {
856  assert(isDistinct() && "Only distinct nodes can mutate");
857  assert(getRawIdentifier() && "Only ODR-uniqued nodes should mutate");
858  this->RuntimeLang = RuntimeLang;
859  DIType::mutate(Tag, Line, SizeInBits, AlignInBits, OffsetInBits, Flags);
860  }
861 
862  static DICompositeType *
863  getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
864  unsigned Line, DIScopeRef Scope, DITypeRef BaseType,
865  uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
866  DIFlags Flags, DINodeArray Elements, unsigned RuntimeLang,
867  DITypeRef VTableHolder, DITemplateParameterArray TemplateParams,
868  StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
869  return getImpl(
870  Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
871  BaseType, SizeInBits, AlignInBits, OffsetInBits, Flags, Elements.get(),
872  RuntimeLang, VTableHolder, TemplateParams.get(),
873  getCanonicalMDString(Context, Identifier), Storage, ShouldCreate);
874  }
875  static DICompositeType *
876  getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
877  unsigned Line, Metadata *Scope, Metadata *BaseType,
878  uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
879  DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
880  Metadata *VTableHolder, Metadata *TemplateParams,
881  MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
882 
883  TempDICompositeType cloneImpl() const {
884  return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
885  getScope(), getBaseType(), getSizeInBits(),
886  getAlignInBits(), getOffsetInBits(), getFlags(),
887  getElements(), getRuntimeLang(), getVTableHolder(),
888  getTemplateParams(), getIdentifier());
889  }
890 
891 public:
893  (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
894  DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits,
895  uint32_t AlignInBits, uint64_t OffsetInBits,
896  DIFlags Flags, DINodeArray Elements, unsigned RuntimeLang,
897  DITypeRef VTableHolder,
898  DITemplateParameterArray TemplateParams = nullptr,
899  StringRef Identifier = ""),
900  (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
901  AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
902  VTableHolder, TemplateParams, Identifier))
904  (unsigned Tag, MDString *Name, Metadata *File,
905  unsigned Line, Metadata *Scope, Metadata *BaseType,
906  uint64_t SizeInBits, uint32_t AlignInBits,
907  uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements,
908  unsigned RuntimeLang, Metadata *VTableHolder,
909  Metadata *TemplateParams = nullptr,
910  MDString *Identifier = nullptr),
911  (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
912  AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
913  VTableHolder, TemplateParams, Identifier))
914 
915  TempDICompositeType clone() const { return cloneImpl(); }
916 
917  /// Get a DICompositeType with the given ODR identifier.
918  ///
919  /// If \a LLVMContext::isODRUniquingDebugTypes(), gets the mapped
920  /// DICompositeType for the given ODR \c Identifier. If none exists, creates
921  /// a new node.
922  ///
923  /// Else, returns \c nullptr.
924  static DICompositeType *
925  getODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
926  MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
927  Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits,
928  uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements,
929  unsigned RuntimeLang, Metadata *VTableHolder,
930  Metadata *TemplateParams);
931  static DICompositeType *getODRTypeIfExists(LLVMContext &Context,
932  MDString &Identifier);
933 
934  /// Build a DICompositeType with the given ODR identifier.
935  ///
936  /// Looks up the mapped DICompositeType for the given ODR \c Identifier. If
937  /// it doesn't exist, creates a new one. If it does exist and \a
938  /// isForwardDecl(), and the new arguments would be a definition, mutates the
939  /// the type in place. In either case, returns the type.
940  ///
941  /// If not \a LLVMContext::isODRUniquingDebugTypes(), this function returns
942  /// nullptr.
943  static DICompositeType *
944  buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
945  MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
946  Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits,
947  uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements,
948  unsigned RuntimeLang, Metadata *VTableHolder,
949  Metadata *TemplateParams);
950 
951  DITypeRef getBaseType() const { return DITypeRef(getRawBaseType()); }
952  DINodeArray getElements() const {
953  return cast_or_null<MDTuple>(getRawElements());
954  }
955  DITypeRef getVTableHolder() const { return DITypeRef(getRawVTableHolder()); }
956  DITemplateParameterArray getTemplateParams() const {
957  return cast_or_null<MDTuple>(getRawTemplateParams());
958  }
959  StringRef getIdentifier() const { return getStringOperand(7); }
960  unsigned getRuntimeLang() const { return RuntimeLang; }
961 
962  Metadata *getRawBaseType() const { return getOperand(3); }
963  Metadata *getRawElements() const { return getOperand(4); }
964  Metadata *getRawVTableHolder() const { return getOperand(5); }
965  Metadata *getRawTemplateParams() const { return getOperand(6); }
966  MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
967 
968  /// Replace operands.
969  ///
970  /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
971  /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
972  /// of its movement if necessary.
973  /// @{
974  void replaceElements(DINodeArray Elements) {
975 #ifndef NDEBUG
976  for (DINode *Op : getElements())
977  assert(is_contained(Elements->operands(), Op) &&
978  "Lost a member during member list replacement");
979 #endif
980  replaceOperandWith(4, Elements.get());
981  }
982 
983  void replaceVTableHolder(DITypeRef VTableHolder) {
984  replaceOperandWith(5, VTableHolder);
985  }
986 
987  void replaceTemplateParams(DITemplateParameterArray TemplateParams) {
988  replaceOperandWith(6, TemplateParams.get());
989  }
990  /// @}
991 
992  static bool classof(const Metadata *MD) {
993  return MD->getMetadataID() == DICompositeTypeKind;
994  }
995 };
996 
997 /// Type array for a subprogram.
998 ///
999 /// TODO: Fold the array of types in directly as operands.
1000 class DISubroutineType : public DIType {
1001  friend class LLVMContextImpl;
1002  friend class MDNode;
1003 
1004  /// The calling convention used with DW_AT_calling_convention. Actually of
1005  /// type dwarf::CallingConvention.
1006  uint8_t CC;
1007 
1008  DISubroutineType(LLVMContext &C, StorageType Storage, DIFlags Flags,
1009  uint8_t CC, ArrayRef<Metadata *> Ops)
1010  : DIType(C, DISubroutineTypeKind, Storage, dwarf::DW_TAG_subroutine_type,
1011  0, 0, 0, 0, Flags, Ops),
1012  CC(CC) {}
1013  ~DISubroutineType() = default;
1014 
1015  static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
1016  uint8_t CC, DITypeRefArray TypeArray,
1017  StorageType Storage,
1018  bool ShouldCreate = true) {
1019  return getImpl(Context, Flags, CC, TypeArray.get(), Storage, ShouldCreate);
1020  }
1021  static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
1022  uint8_t CC, Metadata *TypeArray,
1023  StorageType Storage,
1024  bool ShouldCreate = true);
1025 
1026  TempDISubroutineType cloneImpl() const {
1027  return getTemporary(getContext(), getFlags(), getCC(), getTypeArray());
1028  }
1029 
1030 public:
1032  (DIFlags Flags, uint8_t CC, DITypeRefArray TypeArray),
1033  (Flags, CC, TypeArray))
1035  (DIFlags Flags, uint8_t CC, Metadata *TypeArray),
1036  (Flags, CC, TypeArray))
1037 
1038  TempDISubroutineType clone() const { return cloneImpl(); }
1039 
1040  uint8_t getCC() const { return CC; }
1041 
1043  return cast_or_null<MDTuple>(getRawTypeArray());
1044  }
1045 
1046  Metadata *getRawTypeArray() const { return getOperand(3); }
1047 
1048  static bool classof(const Metadata *MD) {
1049  return MD->getMetadataID() == DISubroutineTypeKind;
1050  }
1051 };
1052 
1053 /// Compile unit.
1054 class DICompileUnit : public DIScope {
1055  friend class LLVMContextImpl;
1056  friend class MDNode;
1057 
1058 public:
1059  enum DebugEmissionKind : unsigned {
1060  NoDebug = 0,
1063  LastEmissionKind = LineTablesOnly
1064  };
1065 
1066  static Optional<DebugEmissionKind> getEmissionKind(StringRef Str);
1067  static const char *EmissionKindString(DebugEmissionKind EK);
1068 
1069 private:
1070  unsigned SourceLanguage;
1071  bool IsOptimized;
1072  unsigned RuntimeVersion;
1073  unsigned EmissionKind;
1074  uint64_t DWOId;
1075  bool SplitDebugInlining;
1076  bool DebugInfoForProfiling;
1077  bool GnuPubnames;
1078 
1079  DICompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
1080  bool IsOptimized, unsigned RuntimeVersion,
1081  unsigned EmissionKind, uint64_t DWOId, bool SplitDebugInlining,
1082  bool DebugInfoForProfiling, bool GnuPubnames, ArrayRef<Metadata *> Ops)
1083  : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
1084  SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
1085  RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind),
1086  DWOId(DWOId), SplitDebugInlining(SplitDebugInlining),
1087  DebugInfoForProfiling(DebugInfoForProfiling), GnuPubnames(GnuPubnames) {
1088  assert(Storage != Uniqued);
1089  }
1090  ~DICompileUnit() = default;
1091 
1092  static DICompileUnit *
1093  getImpl(LLVMContext &Context, unsigned SourceLanguage, DIFile *File,
1094  StringRef Producer, bool IsOptimized, StringRef Flags,
1095  unsigned RuntimeVersion, StringRef SplitDebugFilename,
1096  unsigned EmissionKind, DICompositeTypeArray EnumTypes,
1097  DIScopeArray RetainedTypes,
1098  DIGlobalVariableExpressionArray GlobalVariables,
1099  DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
1100  uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
1101  bool GnuPubnames, StorageType Storage, bool ShouldCreate = true) {
1102  return getImpl(
1103  Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
1104  IsOptimized, getCanonicalMDString(Context, Flags), RuntimeVersion,
1105  getCanonicalMDString(Context, SplitDebugFilename), EmissionKind,
1106  EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
1107  ImportedEntities.get(), Macros.get(), DWOId, SplitDebugInlining,
1108  DebugInfoForProfiling, GnuPubnames, Storage, ShouldCreate);
1109  }
1110  static DICompileUnit *
1111  getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
1112  MDString *Producer, bool IsOptimized, MDString *Flags,
1113  unsigned RuntimeVersion, MDString *SplitDebugFilename,
1114  unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
1115  Metadata *GlobalVariables, Metadata *ImportedEntities,
1116  Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining,
1117  bool DebugInfoForProfiling, bool GnuPubnames, StorageType Storage,
1118  bool ShouldCreate = true);
1119 
1120  TempDICompileUnit cloneImpl() const {
1121  return getTemporary(getContext(), getSourceLanguage(), getFile(),
1122  getProducer(), isOptimized(), getFlags(),
1123  getRuntimeVersion(), getSplitDebugFilename(),
1124  getEmissionKind(), getEnumTypes(), getRetainedTypes(),
1125  getGlobalVariables(), getImportedEntities(),
1126  getMacros(), DWOId, getSplitDebugInlining(),
1127  getDebugInfoForProfiling(), getGnuPubnames());
1128  }
1129 
1130 public:
1131  static void get() = delete;
1132  static void getIfExists() = delete;
1133 
1135  DICompileUnit,
1136  (unsigned SourceLanguage, DIFile *File, StringRef Producer,
1137  bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
1138  StringRef SplitDebugFilename, DebugEmissionKind EmissionKind,
1139  DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes,
1140  DIGlobalVariableExpressionArray GlobalVariables,
1141  DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
1142  uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
1143  bool GnuPubnames),
1144  (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
1145  SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
1146  GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
1147  DebugInfoForProfiling, GnuPubnames))
1149  DICompileUnit,
1150  (unsigned SourceLanguage, Metadata *File, MDString *Producer,
1151  bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
1152  MDString *SplitDebugFilename, unsigned EmissionKind, Metadata *EnumTypes,
1153  Metadata *RetainedTypes, Metadata *GlobalVariables,
1154  Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId,
1155  bool SplitDebugInlining, bool DebugInfoForProfiling, bool GnuPubnames),
1156  (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
1157  SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
1158  GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
1159  DebugInfoForProfiling, GnuPubnames))
1160 
1161  TempDICompileUnit clone() const { return cloneImpl(); }
1162 
1163  unsigned getSourceLanguage() const { return SourceLanguage; }
1164  bool isOptimized() const { return IsOptimized; }
1165  unsigned getRuntimeVersion() const { return RuntimeVersion; }
1168  }
1169  bool getDebugInfoForProfiling() const { return DebugInfoForProfiling; }
1170  bool getGnuPubnames() const { return GnuPubnames; }
1171  StringRef getProducer() const { return getStringOperand(1); }
1172  StringRef getFlags() const { return getStringOperand(2); }
1173  StringRef getSplitDebugFilename() const { return getStringOperand(3); }
1174  DICompositeTypeArray getEnumTypes() const {
1175  return cast_or_null<MDTuple>(getRawEnumTypes());
1176  }
1177  DIScopeArray getRetainedTypes() const {
1178  return cast_or_null<MDTuple>(getRawRetainedTypes());
1179  }
1180  DIGlobalVariableExpressionArray getGlobalVariables() const {
1181  return cast_or_null<MDTuple>(getRawGlobalVariables());
1182  }
1183  DIImportedEntityArray getImportedEntities() const {
1184  return cast_or_null<MDTuple>(getRawImportedEntities());
1185  }
1186  DIMacroNodeArray getMacros() const {
1187  return cast_or_null<MDTuple>(getRawMacros());
1188  }
1189  uint64_t getDWOId() const { return DWOId; }
1190  void setDWOId(uint64_t DwoId) { DWOId = DwoId; }
1191  bool getSplitDebugInlining() const { return SplitDebugInlining; }
1192  void setSplitDebugInlining(bool SplitDebugInlining) {
1193  this->SplitDebugInlining = SplitDebugInlining;
1194  }
1195 
1196  MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
1197  MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
1199  return getOperandAs<MDString>(3);
1200  }
1201  Metadata *getRawEnumTypes() const { return getOperand(4); }
1202  Metadata *getRawRetainedTypes() const { return getOperand(5); }
1203  Metadata *getRawGlobalVariables() const { return getOperand(6); }
1204  Metadata *getRawImportedEntities() const { return getOperand(7); }
1205  Metadata *getRawMacros() const { return getOperand(8); }
1206 
1207  /// Replace arrays.
1208  ///
1209  /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
1210  /// deleted on a uniquing collision. In practice, uniquing collisions on \a
1211  /// DICompileUnit should be fairly rare.
1212  /// @{
1213  void replaceEnumTypes(DICompositeTypeArray N) {
1214  replaceOperandWith(4, N.get());
1215  }
1216  void replaceRetainedTypes(DITypeArray N) {
1217  replaceOperandWith(5, N.get());
1218  }
1219  void replaceGlobalVariables(DIGlobalVariableExpressionArray N) {
1220  replaceOperandWith(6, N.get());
1221  }
1222  void replaceImportedEntities(DIImportedEntityArray N) {
1223  replaceOperandWith(7, N.get());
1224  }
1225  void replaceMacros(DIMacroNodeArray N) { replaceOperandWith(8, N.get()); }
1226  /// @}
1227 
1228  static bool classof(const Metadata *MD) {
1229  return MD->getMetadataID() == DICompileUnitKind;
1230  }
1231 };
1232 
1233 /// A scope for locals.
1234 ///
1235 /// A legal scope for lexical blocks, local variables, and debug info
1236 /// locations. Subclasses are \a DISubprogram, \a DILexicalBlock, and \a
1237 /// DILexicalBlockFile.
1238 class DILocalScope : public DIScope {
1239 protected:
1240  DILocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1242  : DIScope(C, ID, Storage, Tag, Ops) {}
1243  ~DILocalScope() = default;
1244 
1245 public:
1246  /// Get the subprogram for this scope.
1247  ///
1248  /// Return this if it's an \a DISubprogram; otherwise, look up the scope
1249  /// chain.
1250  DISubprogram *getSubprogram() const;
1251 
1252  /// Get the first non DILexicalBlockFile scope of this scope.
1253  ///
1254  /// Return this if it's not a \a DILexicalBlockFIle; otherwise, look up the
1255  /// scope chain.
1256  DILocalScope *getNonLexicalBlockFileScope() const;
1257 
1258  static bool classof(const Metadata *MD) {
1259  return MD->getMetadataID() == DISubprogramKind ||
1260  MD->getMetadataID() == DILexicalBlockKind ||
1261  MD->getMetadataID() == DILexicalBlockFileKind;
1262  }
1263 };
1264 
1265 /// Debug location.
1266 ///
1267 /// A debug location in source code, used for debug info and otherwise.
1268 class DILocation : public MDNode {
1269  friend class LLVMContextImpl;
1270  friend class MDNode;
1271 
1272  DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
1273  unsigned Column, ArrayRef<Metadata *> MDs);
1274  ~DILocation() { dropAllReferences(); }
1275 
1276  static DILocation *getImpl(LLVMContext &Context, unsigned Line,
1277  unsigned Column, Metadata *Scope,
1278  Metadata *InlinedAt, StorageType Storage,
1279  bool ShouldCreate = true);
1280  static DILocation *getImpl(LLVMContext &Context, unsigned Line,
1281  unsigned Column, DILocalScope *Scope,
1282  DILocation *InlinedAt, StorageType Storage,
1283  bool ShouldCreate = true) {
1284  return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
1285  static_cast<Metadata *>(InlinedAt), Storage, ShouldCreate);
1286  }
1287 
1288  /// With a given unsigned int \p U, use up to 13 bits to represent it.
1289  /// old_bit 1~5 --> new_bit 1~5
1290  /// old_bit 6~12 --> new_bit 7~13
1291  /// new_bit_6 is 0 if higher bits (7~13) are all 0
1292  static unsigned getPrefixEncodingFromUnsigned(unsigned U) {
1293  U &= 0xfff;
1294  return U > 0x1f ? (((U & 0xfe0) << 1) | (U & 0x1f) | 0x20) : U;
1295  }
1296 
1297  /// Reverse transformation as getPrefixEncodingFromUnsigned.
1298  static unsigned getUnsignedFromPrefixEncoding(unsigned U) {
1299  return (U & 0x20) ? (((U >> 1) & 0xfe0) | (U & 0x1f)) : (U & 0x1f);
1300  }
1301 
1302  /// Returns the next component stored in discriminator.
1303  static unsigned getNextComponentInDiscriminator(unsigned D) {
1304  if ((D & 1) == 0)
1305  return D >> ((D & 0x40) ? 14 : 7);
1306  else
1307  return D >> 1;
1308  }
1309 
1310  TempDILocation cloneImpl() const {
1311  // Get the raw scope/inlinedAt since it is possible to invoke this on
1312  // a DILocation containing temporary metadata.
1313  return getTemporary(getContext(), getLine(), getColumn(), getRawScope(),
1314  getRawInlinedAt());
1315  }
1316 
1317 public:
1318  // Disallow replacing operands.
1319  void replaceOperandWith(unsigned I, Metadata *New) = delete;
1320 
1322  (unsigned Line, unsigned Column, Metadata *Scope,
1323  Metadata *InlinedAt = nullptr),
1324  (Line, Column, Scope, InlinedAt))
1326  (unsigned Line, unsigned Column, DILocalScope *Scope,
1327  DILocation *InlinedAt = nullptr),
1328  (Line, Column, Scope, InlinedAt))
1329 
1330  /// Return a (temporary) clone of this.
1331  TempDILocation clone() const { return cloneImpl(); }
1332 
1333  unsigned getLine() const { return SubclassData32; }
1334  unsigned getColumn() const { return SubclassData16; }
1335  DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
1336 
1337  DILocation *getInlinedAt() const {
1338  return cast_or_null<DILocation>(getRawInlinedAt());
1339  }
1340 
1341  DIFile *getFile() const { return getScope()->getFile(); }
1342  StringRef getFilename() const { return getScope()->getFilename(); }
1343  StringRef getDirectory() const { return getScope()->getDirectory(); }
1344 
1345  /// Get the scope where this is inlined.
1346  ///
1347  /// Walk through \a getInlinedAt() and return \a getScope() from the deepest
1348  /// location.
1349  DILocalScope *getInlinedAtScope() const {
1350  if (auto *IA = getInlinedAt())
1351  return IA->getInlinedAtScope();
1352  return getScope();
1353  }
1354 
1355  /// Check whether this can be discriminated from another location.
1356  ///
1357  /// Check \c this can be discriminated from \c RHS in a linetable entry.
1358  /// Scope and inlined-at chains are not recorded in the linetable, so they
1359  /// cannot be used to distinguish basic blocks.
1360  bool canDiscriminate(const DILocation &RHS) const {
1361  return getLine() != RHS.getLine() ||
1362  getColumn() != RHS.getColumn() ||
1363  getDiscriminator() != RHS.getDiscriminator() ||
1364  getFilename() != RHS.getFilename() ||
1365  getDirectory() != RHS.getDirectory();
1366  }
1367 
1368  /// Get the DWARF discriminator.
1369  ///
1370  /// DWARF discriminators distinguish identical file locations between
1371  /// instructions that are on different basic blocks.
1372  ///
1373  /// There are 3 components stored in discriminator, from lower bits:
1374  ///
1375  /// Base discriminator: assigned by AddDiscriminators pass to identify IRs
1376  /// that are defined by the same source line, but
1377  /// different basic blocks.
1378  /// Duplication factor: assigned by optimizations that will scale down
1379  /// the execution frequency of the original IR.
1380  /// Copy Identifier: assigned by optimizations that clones the IR.
1381  /// Each copy of the IR will be assigned an identifier.
1382  ///
1383  /// Encoding:
1384  ///
1385  /// The above 3 components are encoded into a 32bit unsigned integer in
1386  /// order. If the lowest bit is 1, the current component is empty, and the
1387  /// next component will start in the next bit. Otherwise, the the current
1388  /// component is non-empty, and its content starts in the next bit. The
1389  /// length of each components is either 5 bit or 12 bit: if the 7th bit
1390  /// is 0, the bit 2~6 (5 bits) are used to represent the component; if the
1391  /// 7th bit is 1, the bit 2~6 (5 bits) and 8~14 (7 bits) are combined to
1392  /// represent the component.
1393 
1394  inline unsigned getDiscriminator() const;
1395 
1396  /// Returns a new DILocation with updated \p Discriminator.
1397  inline const DILocation *cloneWithDiscriminator(unsigned Discriminator) const;
1398 
1399  /// Returns a new DILocation with updated base discriminator \p BD.
1400  inline const DILocation *setBaseDiscriminator(unsigned BD) const;
1401 
1402  /// Returns the duplication factor stored in the discriminator.
1403  inline unsigned getDuplicationFactor() const;
1404 
1405  /// Returns the copy identifier stored in the discriminator.
1406  inline unsigned getCopyIdentifier() const;
1407 
1408  /// Returns the base discriminator stored in the discriminator.
1409  inline unsigned getBaseDiscriminator() const;
1410 
1411  /// Returns a new DILocation with duplication factor \p DF encoded in the
1412  /// discriminator.
1413  inline const DILocation *cloneWithDuplicationFactor(unsigned DF) const;
1414 
1415  /// When two instructions are combined into a single instruction we also
1416  /// need to combine the original locations into a single location.
1417  ///
1418  /// When the locations are the same we can use either location. When they
1419  /// differ, we need a third location which is distinct from either. If
1420  /// they have the same file/line but have a different discriminator we
1421  /// could create a location with a new discriminator. If they are from
1422  /// different files/lines the location is ambiguous and can't be
1423  /// represented in a single line entry. In this case, no location
1424  /// should be set, unless the merged instruction is a call, which we will
1425  /// set the merged debug location as line 0 of the nearest common scope
1426  /// where 2 locations are inlined from. This only applies to Instruction;
1427  /// for MachineInstruction, as it is post-inline, we will treat the call
1428  /// instruction the same way as other instructions.
1429  ///
1430  /// \p ForInst: The Instruction the merged DILocation is for. If the
1431  /// Instruction is unavailable or non-existent, use nullptr.
1432  static const DILocation *
1433  getMergedLocation(const DILocation *LocA, const DILocation *LocB,
1434  const Instruction *ForInst = nullptr);
1435 
1436  /// Returns the base discriminator for a given encoded discriminator \p D.
1437  static unsigned getBaseDiscriminatorFromDiscriminator(unsigned D) {
1438  if ((D & 1) == 0)
1439  return getUnsignedFromPrefixEncoding(D >> 1);
1440  else
1441  return 0;
1442  }
1443 
1444  /// Returns the duplication factor for a given encoded discriminator \p D.
1445  static unsigned getDuplicationFactorFromDiscriminator(unsigned D) {
1446  D = getNextComponentInDiscriminator(D);
1447  if (D == 0 || (D & 1))
1448  return 1;
1449  else
1450  return getUnsignedFromPrefixEncoding(D >> 1);
1451  }
1452 
1453  /// Returns the copy identifier for a given encoded discriminator \p D.
1454  static unsigned getCopyIdentifierFromDiscriminator(unsigned D) {
1455  return getUnsignedFromPrefixEncoding(getNextComponentInDiscriminator(
1456  getNextComponentInDiscriminator(D)));
1457  }
1458 
1459 
1460  Metadata *getRawScope() const { return getOperand(0); }
1462  if (getNumOperands() == 2)
1463  return getOperand(1);
1464  return nullptr;
1465  }
1466 
1467  static bool classof(const Metadata *MD) {
1468  return MD->getMetadataID() == DILocationKind;
1469  }
1470 };
1471 
1472 /// Subprogram description.
1473 ///
1474 /// TODO: Remove DisplayName. It's always equal to Name.
1475 /// TODO: Split up flags.
1476 class DISubprogram : public DILocalScope {
1477  friend class LLVMContextImpl;
1478  friend class MDNode;
1479 
1480  unsigned Line;
1481  unsigned ScopeLine;
1482  unsigned VirtualIndex;
1483 
1484  /// In the MS ABI, the implicit 'this' parameter is adjusted in the prologue
1485  /// of method overrides from secondary bases by this amount. It may be
1486  /// negative.
1487  int ThisAdjustment;
1488 
1489  // Virtuality can only assume three values, so we can pack
1490  // in 2 bits (none/pure/pure_virtual).
1491  unsigned Virtuality : 2;
1492 
1493  // These are boolean flags so one bit is enough.
1494  // MSVC starts a new container field every time the base
1495  // type changes so we can't use 'bool' to ensure these bits
1496  // are packed.
1497  unsigned IsLocalToUnit : 1;
1498  unsigned IsDefinition : 1;
1499  unsigned IsOptimized : 1;
1500 
1501  unsigned Padding : 3;
1502 
1503  DIFlags Flags;
1504 
1505  DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1506  unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
1507  int ThisAdjustment, DIFlags Flags, bool IsLocalToUnit,
1508  bool IsDefinition, bool IsOptimized, ArrayRef<Metadata *> Ops)
1509  : DILocalScope(C, DISubprogramKind, Storage, dwarf::DW_TAG_subprogram,
1510  Ops),
1511  Line(Line), ScopeLine(ScopeLine), VirtualIndex(VirtualIndex),
1512  ThisAdjustment(ThisAdjustment), Virtuality(Virtuality),
1513  IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition),
1514  IsOptimized(IsOptimized), Flags(Flags) {
1515  static_assert(dwarf::DW_VIRTUALITY_max < 4, "Virtuality out of range");
1516  assert(Virtuality < 4 && "Virtuality out of range");
1517  }
1518  ~DISubprogram() = default;
1519 
1520  static DISubprogram *
1521  getImpl(LLVMContext &Context, DIScopeRef Scope, StringRef Name,
1522  StringRef LinkageName, DIFile *File, unsigned Line,
1523  DISubroutineType *Type, bool IsLocalToUnit, bool IsDefinition,
1524  unsigned ScopeLine, DITypeRef ContainingType, unsigned Virtuality,
1525  unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags,
1526  bool IsOptimized, DICompileUnit *Unit,
1527  DITemplateParameterArray TemplateParams, DISubprogram *Declaration,
1528  DILocalVariableArray Variables, DITypeArray ThrownTypes,
1529  StorageType Storage, bool ShouldCreate = true) {
1530  return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1531  getCanonicalMDString(Context, LinkageName), File, Line, Type,
1532  IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
1533  Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized,
1534  Unit, TemplateParams.get(), Declaration, Variables.get(),
1535  ThrownTypes.get(), Storage, ShouldCreate);
1536  }
1537  static DISubprogram *
1538  getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1539  MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1540  bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1541  Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
1542  int ThisAdjustment, DIFlags Flags, bool IsOptimized, Metadata *Unit,
1543  Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
1544  Metadata *ThrownTypes, StorageType Storage, bool ShouldCreate = true);
1545 
1546  TempDISubprogram cloneImpl() const {
1547  return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1548  getFile(), getLine(), getType(), isLocalToUnit(),
1549  isDefinition(), getScopeLine(), getContainingType(),
1550  getVirtuality(), getVirtualIndex(), getThisAdjustment(),
1551  getFlags(), isOptimized(), getUnit(),
1552  getTemplateParams(), getDeclaration(), getVariables(),
1553  getThrownTypes());
1554  }
1555 
1556 public:
1558  (DIScopeRef Scope, StringRef Name, StringRef LinkageName,
1559  DIFile *File, unsigned Line, DISubroutineType *Type,
1560  bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
1561  DITypeRef ContainingType, unsigned Virtuality,
1562  unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags,
1563  bool IsOptimized, DICompileUnit *Unit,
1564  DITemplateParameterArray TemplateParams = nullptr,
1565  DISubprogram *Declaration = nullptr,
1566  DILocalVariableArray Variables = nullptr,
1567  DITypeArray ThrownTypes = nullptr),
1568  (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1569  IsDefinition, ScopeLine, ContainingType, Virtuality,
1570  VirtualIndex, ThisAdjustment, Flags, IsOptimized, Unit,
1571  TemplateParams, Declaration, Variables, ThrownTypes))
1573  DISubprogram,
1574  (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
1575  unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1576  unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
1577  unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags,
1578  bool IsOptimized, Metadata *Unit, Metadata *TemplateParams = nullptr,
1579  Metadata *Declaration = nullptr, Metadata *Variables = nullptr,
1580  Metadata *ThrownTypes = nullptr),
1581  (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1582  ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment,
1583  Flags, IsOptimized, Unit, TemplateParams, Declaration, Variables,
1584  ThrownTypes))
1585 
1586  TempDISubprogram clone() const { return cloneImpl(); }
1587 
1588 public:
1589  unsigned getLine() const { return Line; }
1590  unsigned getVirtuality() const { return Virtuality; }
1591  unsigned getVirtualIndex() const { return VirtualIndex; }
1592  int getThisAdjustment() const { return ThisAdjustment; }
1593  unsigned getScopeLine() const { return ScopeLine; }
1594  DIFlags getFlags() const { return Flags; }
1595  bool isLocalToUnit() const { return IsLocalToUnit; }
1596  bool isDefinition() const { return IsDefinition; }
1597  bool isOptimized() const { return IsOptimized; }
1598 
1599  bool isArtificial() const { return getFlags() & FlagArtificial; }
1600  bool isPrivate() const {
1601  return (getFlags() & FlagAccessibility) == FlagPrivate;
1602  }
1603  bool isProtected() const {
1604  return (getFlags() & FlagAccessibility) == FlagProtected;
1605  }
1606  bool isPublic() const {
1607  return (getFlags() & FlagAccessibility) == FlagPublic;
1608  }
1609  bool isExplicit() const { return getFlags() & FlagExplicit; }
1610  bool isPrototyped() const { return getFlags() & FlagPrototyped; }
1611  bool isMainSubprogram() const { return getFlags() & FlagMainSubprogram; }
1612 
1613  /// Check if this is reference-qualified.
1614  ///
1615  /// Return true if this subprogram is a C++11 reference-qualified non-static
1616  /// member function (void foo() &).
1617  bool isLValueReference() const { return getFlags() & FlagLValueReference; }
1618 
1619  /// Check if this is rvalue-reference-qualified.
1620  ///
1621  /// Return true if this subprogram is a C++11 rvalue-reference-qualified
1622  /// non-static member function (void foo() &&).
1623  bool isRValueReference() const { return getFlags() & FlagRValueReference; }
1624 
1625  /// Check if this is marked as noreturn.
1626  ///
1627  /// Return true if this subprogram is C++11 noreturn or C11 _Noreturn
1628  bool isNoReturn() const { return getFlags() & FlagNoReturn; }
1629 
1630  DIScopeRef getScope() const { return DIScopeRef(getRawScope()); }
1631 
1632  StringRef getName() const { return getStringOperand(2); }
1633  StringRef getLinkageName() const { return getStringOperand(3); }
1634 
1635  DISubroutineType *getType() const {
1636  return cast_or_null<DISubroutineType>(getRawType());
1637  }
1638  DITypeRef getContainingType() const {
1639  return DITypeRef(getRawContainingType());
1640  }
1641 
1642  DICompileUnit *getUnit() const {
1643  return cast_or_null<DICompileUnit>(getRawUnit());
1644  }
1645  void replaceUnit(DICompileUnit *CU) { replaceOperandWith(5, CU); }
1646  DITemplateParameterArray getTemplateParams() const {
1647  return cast_or_null<MDTuple>(getRawTemplateParams());
1648  }
1649  DISubprogram *getDeclaration() const {
1650  return cast_or_null<DISubprogram>(getRawDeclaration());
1651  }
1652  DILocalVariableArray getVariables() const {
1653  return cast_or_null<MDTuple>(getRawVariables());
1654  }
1655  DITypeArray getThrownTypes() const {
1656  return cast_or_null<MDTuple>(getRawThrownTypes());
1657  }
1658 
1659  Metadata *getRawScope() const { return getOperand(1); }
1660  MDString *getRawName() const { return getOperandAs<MDString>(2); }
1661  MDString *getRawLinkageName() const { return getOperandAs<MDString>(3); }
1662  Metadata *getRawType() const { return getOperand(4); }
1663  Metadata *getRawUnit() const { return getOperand(5); }
1664  Metadata *getRawDeclaration() const { return getOperand(6); }
1665  Metadata *getRawVariables() const { return getOperand(7); }
1666  Metadata *getRawContainingType() const {
1667  return getNumOperands() > 8 ? getOperandAs<Metadata>(8) : nullptr;
1668  }
1669  Metadata *getRawTemplateParams() const {
1670  return getNumOperands() > 9 ? getOperandAs<Metadata>(9) : nullptr;
1671  }
1672  Metadata *getRawThrownTypes() const {
1673  return getNumOperands() > 10 ? getOperandAs<Metadata>(10) : nullptr;
1674  }
1675 
1676  /// Check if this subprogram describes the given function.
1677  ///
1678  /// FIXME: Should this be looking through bitcasts?
1679  bool describes(const Function *F) const;
1680 
1681  static bool classof(const Metadata *MD) {
1682  return MD->getMetadataID() == DISubprogramKind;
1683  }
1684 };
1685 
1687 protected:
1690  : DILocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1691  ~DILexicalBlockBase() = default;
1692 
1693 public:
1694  DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
1695 
1696  Metadata *getRawScope() const { return getOperand(1); }
1697 
1698  static bool classof(const Metadata *MD) {
1699  return MD->getMetadataID() == DILexicalBlockKind ||
1700  MD->getMetadataID() == DILexicalBlockFileKind;
1701  }
1702 };
1703 
1705  friend class LLVMContextImpl;
1706  friend class MDNode;
1707 
1708  unsigned Line;
1709  uint16_t Column;
1710 
1711  DILexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1712  unsigned Column, ArrayRef<Metadata *> Ops)
1713  : DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops), Line(Line),
1714  Column(Column) {
1715  assert(Column < (1u << 16) && "Expected 16-bit column");
1716  }
1717  ~DILexicalBlock() = default;
1718 
1719  static DILexicalBlock *getImpl(LLVMContext &Context, DILocalScope *Scope,
1720  DIFile *File, unsigned Line, unsigned Column,
1721  StorageType Storage,
1722  bool ShouldCreate = true) {
1723  return getImpl(Context, static_cast<Metadata *>(Scope),
1724  static_cast<Metadata *>(File), Line, Column, Storage,
1725  ShouldCreate);
1726  }
1727 
1728  static DILexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1729  Metadata *File, unsigned Line, unsigned Column,
1730  StorageType Storage, bool ShouldCreate = true);
1731 
1732  TempDILexicalBlock cloneImpl() const {
1733  return getTemporary(getContext(), getScope(), getFile(), getLine(),
1734  getColumn());
1735  }
1736 
1737 public:
1739  unsigned Line, unsigned Column),
1740  (Scope, File, Line, Column))
1742  unsigned Line, unsigned Column),
1743  (Scope, File, Line, Column))
1744 
1745  TempDILexicalBlock clone() const { return cloneImpl(); }
1746 
1747  unsigned getLine() const { return Line; }
1748  unsigned getColumn() const { return Column; }
1749 
1750  static bool classof(const Metadata *MD) {
1751  return MD->getMetadataID() == DILexicalBlockKind;
1752  }
1753 };
1754 
1756  friend class LLVMContextImpl;
1757  friend class MDNode;
1758 
1759  unsigned Discriminator;
1760 
1762  unsigned Discriminator, ArrayRef<Metadata *> Ops)
1763  : DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops),
1764  Discriminator(Discriminator) {}
1765  ~DILexicalBlockFile() = default;
1766 
1767  static DILexicalBlockFile *getImpl(LLVMContext &Context, DILocalScope *Scope,
1768  DIFile *File, unsigned Discriminator,
1769  StorageType Storage,
1770  bool ShouldCreate = true) {
1771  return getImpl(Context, static_cast<Metadata *>(Scope),
1772  static_cast<Metadata *>(File), Discriminator, Storage,
1773  ShouldCreate);
1774  }
1775 
1776  static DILexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1777  Metadata *File, unsigned Discriminator,
1778  StorageType Storage,
1779  bool ShouldCreate = true);
1780 
1781  TempDILexicalBlockFile cloneImpl() const {
1782  return getTemporary(getContext(), getScope(), getFile(),
1783  getDiscriminator());
1784  }
1785 
1786 public:
1788  unsigned Discriminator),
1789  (Scope, File, Discriminator))
1791  (Metadata * Scope, Metadata *File, unsigned Discriminator),
1792  (Scope, File, Discriminator))
1793 
1794  TempDILexicalBlockFile clone() const { return cloneImpl(); }
1795 
1796  // TODO: Remove these once they're gone from DILexicalBlockBase.
1797  unsigned getLine() const = delete;
1798  unsigned getColumn() const = delete;
1799 
1800  unsigned getDiscriminator() const { return Discriminator; }
1801 
1802  static bool classof(const Metadata *MD) {
1803  return MD->getMetadataID() == DILexicalBlockFileKind;
1804  }
1805 };
1806 
1807 unsigned DILocation::getDiscriminator() const {
1808  if (auto *F = dyn_cast<DILexicalBlockFile>(getScope()))
1809  return F->getDiscriminator();
1810  return 0;
1811 }
1812 
1813 const DILocation *
1814 DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
1815  DIScope *Scope = getScope();
1816  // Skip all parent DILexicalBlockFile that already have a discriminator
1817  // assigned. We do not want to have nested DILexicalBlockFiles that have
1818  // mutliple discriminators because only the leaf DILexicalBlockFile's
1819  // dominator will be used.
1820  for (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope);
1821  LBF && LBF->getDiscriminator() != 0;
1822  LBF = dyn_cast<DILexicalBlockFile>(Scope))
1823  Scope = LBF->getScope();
1824  DILexicalBlockFile *NewScope =
1825  DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator);
1826  return DILocation::get(getContext(), getLine(), getColumn(), NewScope,
1827  getInlinedAt());
1828 }
1829 
1831  return getBaseDiscriminatorFromDiscriminator(getDiscriminator());
1832 }
1833 
1835  return getDuplicationFactorFromDiscriminator(getDiscriminator());
1836 }
1837 
1839  return getCopyIdentifierFromDiscriminator(getDiscriminator());
1840 }
1841 
1843  if (D == 0)
1844  return this;
1845  else
1846  return cloneWithDiscriminator(getPrefixEncodingFromUnsigned(D) << 1);
1847 }
1848 
1850  DF *= getDuplicationFactor();
1851  if (DF <= 1)
1852  return this;
1853 
1854  unsigned BD = getBaseDiscriminator();
1855  unsigned CI = getCopyIdentifier() << (DF > 0x1f ? 14 : 7);
1856  unsigned D = CI | (getPrefixEncodingFromUnsigned(DF) << 1);
1857 
1858  if (BD == 0)
1859  D = (D << 1) | 1;
1860  else
1861  D = (D << (BD > 0x1f ? 14 : 7)) | (getPrefixEncodingFromUnsigned(BD) << 1);
1862 
1863  return cloneWithDiscriminator(D);
1864 }
1865 
1866 class DINamespace : public DIScope {
1867  friend class LLVMContextImpl;
1868  friend class MDNode;
1869 
1870  unsigned ExportSymbols : 1;
1871 
1872  DINamespace(LLVMContext &Context, StorageType Storage, bool ExportSymbols,
1874  : DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace,
1875  Ops),
1876  ExportSymbols(ExportSymbols) {}
1877  ~DINamespace() = default;
1878 
1879  static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope,
1880  StringRef Name, bool ExportSymbols,
1881  StorageType Storage, bool ShouldCreate = true) {
1882  return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1883  ExportSymbols, Storage, ShouldCreate);
1884  }
1885  static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope,
1886  MDString *Name, bool ExportSymbols,
1887  StorageType Storage, bool ShouldCreate = true);
1888 
1889  TempDINamespace cloneImpl() const {
1890  return getTemporary(getContext(), getScope(), getName(),
1891  getExportSymbols());
1892  }
1893 
1894 public:
1896  (DIScope *Scope, StringRef Name, bool ExportSymbols),
1897  (Scope, Name, ExportSymbols))
1899  (Metadata *Scope, MDString *Name, bool ExportSymbols),
1900  (Scope, Name, ExportSymbols))
1901 
1902  TempDINamespace clone() const { return cloneImpl(); }
1903 
1904  bool getExportSymbols() const { return ExportSymbols; }
1905  DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
1906  StringRef getName() const { return getStringOperand(2); }
1907 
1908  Metadata *getRawScope() const { return getOperand(1); }
1909  MDString *getRawName() const { return getOperandAs<MDString>(2); }
1910 
1911  static bool classof(const Metadata *MD) {
1912  return MD->getMetadataID() == DINamespaceKind;
1913  }
1914 };
1915 
1916 /// A (clang) module that has been imported by the compile unit.
1917 ///
1918 class DIModule : public DIScope {
1919  friend class LLVMContextImpl;
1920  friend class MDNode;
1921 
1922  DIModule(LLVMContext &Context, StorageType Storage, ArrayRef<Metadata *> Ops)
1923  : DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops) {}
1924  ~DIModule() = default;
1925 
1926  static DIModule *getImpl(LLVMContext &Context, DIScope *Scope,
1927  StringRef Name, StringRef ConfigurationMacros,
1928  StringRef IncludePath, StringRef ISysRoot,
1929  StorageType Storage, bool ShouldCreate = true) {
1930  return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1931  getCanonicalMDString(Context, ConfigurationMacros),
1932  getCanonicalMDString(Context, IncludePath),
1933  getCanonicalMDString(Context, ISysRoot),
1934  Storage, ShouldCreate);
1935  }
1936  static DIModule *getImpl(LLVMContext &Context, Metadata *Scope,
1937  MDString *Name, MDString *ConfigurationMacros,
1938  MDString *IncludePath, MDString *ISysRoot,
1939  StorageType Storage, bool ShouldCreate = true);
1940 
1941  TempDIModule cloneImpl() const {
1942  return getTemporary(getContext(), getScope(), getName(),
1943  getConfigurationMacros(), getIncludePath(),
1944  getISysRoot());
1945  }
1946 
1947 public:
1949  StringRef ConfigurationMacros, StringRef IncludePath,
1950  StringRef ISysRoot),
1951  (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot))
1953  (Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
1954  MDString *IncludePath, MDString *ISysRoot),
1955  (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot))
1956 
1957  TempDIModule clone() const { return cloneImpl(); }
1958 
1959  DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
1960  StringRef getName() const { return getStringOperand(1); }
1961  StringRef getConfigurationMacros() const { return getStringOperand(2); }
1962  StringRef getIncludePath() const { return getStringOperand(3); }
1963  StringRef getISysRoot() const { return getStringOperand(4); }
1964 
1965  Metadata *getRawScope() const { return getOperand(0); }
1966  MDString *getRawName() const { return getOperandAs<MDString>(1); }
1967  MDString *getRawConfigurationMacros() const { return getOperandAs<MDString>(2); }
1968  MDString *getRawIncludePath() const { return getOperandAs<MDString>(3); }
1969  MDString *getRawISysRoot() const { return getOperandAs<MDString>(4); }
1970 
1971  static bool classof(const Metadata *MD) {
1972  return MD->getMetadataID() == DIModuleKind;
1973  }
1974 };
1975 
1976 /// Base class for template parameters.
1977 class DITemplateParameter : public DINode {
1978 protected:
1979  DITemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
1980  unsigned Tag, ArrayRef<Metadata *> Ops)
1981  : DINode(Context, ID, Storage, Tag, Ops) {}
1982  ~DITemplateParameter() = default;
1983 
1984 public:
1985  StringRef getName() const { return getStringOperand(0); }
1986  DITypeRef getType() const { return DITypeRef(getRawType()); }
1987 
1988  MDString *getRawName() const { return getOperandAs<MDString>(0); }
1989  Metadata *getRawType() const { return getOperand(1); }
1990 
1991  static bool classof(const Metadata *MD) {
1992  return MD->getMetadataID() == DITemplateTypeParameterKind ||
1993  MD->getMetadataID() == DITemplateValueParameterKind;
1994  }
1995 };
1996 
1998  friend class LLVMContextImpl;
1999  friend class MDNode;
2000 
2003  : DITemplateParameter(Context, DITemplateTypeParameterKind, Storage,
2004  dwarf::DW_TAG_template_type_parameter, Ops) {}
2005  ~DITemplateTypeParameter() = default;
2006 
2007  static DITemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
2008  DITypeRef Type, StorageType Storage,
2009  bool ShouldCreate = true) {
2010  return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
2011  ShouldCreate);
2012  }
2013  static DITemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
2014  Metadata *Type, StorageType Storage,
2015  bool ShouldCreate = true);
2016 
2017  TempDITemplateTypeParameter cloneImpl() const {
2018  return getTemporary(getContext(), getName(), getType());
2019  }
2020 
2021 public:
2023  (Name, Type))
2025  (Name, Type))
2026 
2027  TempDITemplateTypeParameter clone() const { return cloneImpl(); }
2028 
2029  static bool classof(const Metadata *MD) {
2030  return MD->getMetadataID() == DITemplateTypeParameterKind;
2031  }
2032 };
2033 
2035  friend class LLVMContextImpl;
2036  friend class MDNode;
2037 
2039  unsigned Tag, ArrayRef<Metadata *> Ops)
2040  : DITemplateParameter(Context, DITemplateValueParameterKind, Storage, Tag,
2041  Ops) {}
2042  ~DITemplateValueParameter() = default;
2043 
2044  static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
2045  StringRef Name, DITypeRef Type,
2046  Metadata *Value, StorageType Storage,
2047  bool ShouldCreate = true) {
2048  return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
2049  Value, Storage, ShouldCreate);
2050  }
2051  static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
2052  MDString *Name, Metadata *Type,
2053  Metadata *Value, StorageType Storage,
2054  bool ShouldCreate = true);
2055 
2056  TempDITemplateValueParameter cloneImpl() const {
2057  return getTemporary(getContext(), getTag(), getName(), getType(),
2058  getValue());
2059  }
2060 
2061 public:
2063  DITypeRef Type, Metadata *Value),
2064  (Tag, Name, Type, Value))
2066  Metadata *Type, Metadata *Value),
2067  (Tag, Name, Type, Value))
2068 
2069  TempDITemplateValueParameter clone() const { return cloneImpl(); }
2070 
2071  Metadata *getValue() const { return getOperand(2); }
2072 
2073  static bool classof(const Metadata *MD) {
2074  return MD->getMetadataID() == DITemplateValueParameterKind;
2075  }
2076 };
2077 
2078 /// Base class for variables.
2079 class DIVariable : public DINode {
2080  unsigned Line;
2081  uint32_t AlignInBits;
2082 
2083 protected:
2084  DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Line,
2085  ArrayRef<Metadata *> Ops, uint32_t AlignInBits = 0)
2086  : DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line),
2087  AlignInBits(AlignInBits) {}
2088  ~DIVariable() = default;
2089 
2090 public:
2091  unsigned getLine() const { return Line; }
2092  DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2093  StringRef getName() const { return getStringOperand(1); }
2094  DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
2095  DITypeRef getType() const { return DITypeRef(getRawType()); }
2096  uint32_t getAlignInBits() const { return AlignInBits; }
2097  uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
2098  /// Determines the size of the variable's type.
2100 
2102  if (auto *F = getFile())
2103  return F->getFilename();
2104  return "";
2105  }
2106 
2108  if (auto *F = getFile())
2109  return F->getDirectory();
2110  return "";
2111  }
2112 
2113  Metadata *getRawScope() const { return getOperand(0); }
2114  MDString *getRawName() const { return getOperandAs<MDString>(1); }
2115  Metadata *getRawFile() const { return getOperand(2); }
2116  Metadata *getRawType() const { return getOperand(3); }
2117 
2118  static bool classof(const Metadata *MD) {
2119  return MD->getMetadataID() == DILocalVariableKind ||
2120  MD->getMetadataID() == DIGlobalVariableKind;
2121  }
2122 };
2123 
2124 /// DWARF expression.
2125 ///
2126 /// This is (almost) a DWARF expression that modifies the location of a
2127 /// variable, or the location of a single piece of a variable, or (when using
2128 /// DW_OP_stack_value) is the constant variable value.
2129 ///
2130 /// TODO: Co-allocate the expression elements.
2131 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
2132 /// storage types.
2133 class DIExpression : public MDNode {
2134  friend class LLVMContextImpl;
2135  friend class MDNode;
2136 
2137  std::vector<uint64_t> Elements;
2138 
2140  : MDNode(C, DIExpressionKind, Storage, None),
2141  Elements(Elements.begin(), Elements.end()) {}
2142  ~DIExpression() = default;
2143 
2144  static DIExpression *getImpl(LLVMContext &Context,
2145  ArrayRef<uint64_t> Elements, StorageType Storage,
2146  bool ShouldCreate = true);
2147 
2148  TempDIExpression cloneImpl() const {
2149  return getTemporary(getContext(), getElements());
2150  }
2151 
2152 public:
2154 
2155  TempDIExpression clone() const { return cloneImpl(); }
2156 
2157  ArrayRef<uint64_t> getElements() const { return Elements; }
2158 
2159  unsigned getNumElements() const { return Elements.size(); }
2160 
2161  uint64_t getElement(unsigned I) const {
2162  assert(I < Elements.size() && "Index out of range");
2163  return Elements[I];
2164  }
2165 
2166  /// Determine whether this represents a standalone constant value.
2167  bool isConstant() const;
2168 
2170 
2171  element_iterator elements_begin() const { return getElements().begin(); }
2172  element_iterator elements_end() const { return getElements().end(); }
2173 
2174  /// A lightweight wrapper around an expression operand.
2175  ///
2176  /// TODO: Store arguments directly and change \a DIExpression to store a
2177  /// range of these.
2178  class ExprOperand {
2179  const uint64_t *Op = nullptr;
2180 
2181  public:
2182  ExprOperand() = default;
2183  explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
2184 
2185  const uint64_t *get() const { return Op; }
2186 
2187  /// Get the operand code.
2188  uint64_t getOp() const { return *Op; }
2189 
2190  /// Get an argument to the operand.
2191  ///
2192  /// Never returns the operand itself.
2193  uint64_t getArg(unsigned I) const { return Op[I + 1]; }
2194 
2195  unsigned getNumArgs() const { return getSize() - 1; }
2196 
2197  /// Return the size of the operand.
2198  ///
2199  /// Return the number of elements in the operand (1 + args).
2200  unsigned getSize() const;
2201  };
2202 
2203  /// An iterator for expression operands.
2205  : public std::iterator<std::input_iterator_tag, ExprOperand> {
2206  ExprOperand Op;
2207 
2208  public:
2209  expr_op_iterator() = default;
2210  explicit expr_op_iterator(element_iterator I) : Op(I) {}
2211 
2212  element_iterator getBase() const { return Op.get(); }
2213  const ExprOperand &operator*() const { return Op; }
2214  const ExprOperand *operator->() const { return &Op; }
2215 
2217  increment();
2218  return *this;
2219  }
2221  expr_op_iterator T(*this);
2222  increment();
2223  return T;
2224  }
2225 
2226  /// Get the next iterator.
2227  ///
2228  /// \a std::next() doesn't work because this is technically an
2229  /// input_iterator, but it's a perfectly valid operation. This is an
2230  /// accessor to provide the same functionality.
2231  expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
2232 
2233  bool operator==(const expr_op_iterator &X) const {
2234  return getBase() == X.getBase();
2235  }
2236  bool operator!=(const expr_op_iterator &X) const {
2237  return getBase() != X.getBase();
2238  }
2239 
2240  private:
2241  void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
2242  };
2243 
2244  /// Visit the elements via ExprOperand wrappers.
2245  ///
2246  /// These range iterators visit elements through \a ExprOperand wrappers.
2247  /// This is not guaranteed to be a valid range unless \a isValid() gives \c
2248  /// true.
2249  ///
2250  /// \pre \a isValid() gives \c true.
2251  /// @{
2253  return expr_op_iterator(elements_begin());
2254  }
2256  return expr_op_iterator(elements_end());
2257  }
2259  return {expr_op_begin(), expr_op_end()};
2260  }
2261  /// @}
2262 
2263  bool isValid() const;
2264 
2265  static bool classof(const Metadata *MD) {
2266  return MD->getMetadataID() == DIExpressionKind;
2267  }
2268 
2269  /// Return whether the first element a DW_OP_deref.
2270  bool startsWithDeref() const {
2271  return getNumElements() > 0 && getElement(0) == dwarf::DW_OP_deref;
2272  }
2273 
2274  /// Holds the characteristics of one fragment of a larger variable.
2275  struct FragmentInfo {
2276  uint64_t SizeInBits;
2277  uint64_t OffsetInBits;
2278  };
2279 
2280  /// Retrieve the details of this fragment expression.
2281  static Optional<FragmentInfo> getFragmentInfo(expr_op_iterator Start,
2283 
2284  /// Retrieve the details of this fragment expression.
2286  return getFragmentInfo(expr_op_begin(), expr_op_end());
2287  }
2288 
2289  /// Return whether this is a piece of an aggregate variable.
2290  bool isFragment() const { return getFragmentInfo().hasValue(); }
2291 
2292  /// Append \p Ops with operations to apply the \p Offset.
2293  static void appendOffset(SmallVectorImpl<uint64_t> &Ops, int64_t Offset);
2294 
2295  /// If this is a constant offset, extract it. If there is no expression,
2296  /// return true with an offset of zero.
2297  bool extractIfOffset(int64_t &Offset) const;
2298 
2299  /// Constants for DIExpression::prepend.
2300  enum { NoDeref = false, WithDeref = true, WithStackValue = true };
2301 
2302  /// Prepend \p DIExpr with a deref and offset operation and optionally turn it
2303  /// into a stack value.
2304  static DIExpression *prepend(const DIExpression *DIExpr, bool DerefBefore,
2305  int64_t Offset = 0, bool DerefAfter = false,
2306  bool StackValue = false);
2307 
2308  /// Create a DIExpression to describe one part of an aggregate variable that
2309  /// is fragmented across multiple Values. The DW_OP_LLVM_fragment operation
2310  /// will be appended to the elements of \c Expr. If \c Expr already contains
2311  /// a \c DW_OP_LLVM_fragment \c OffsetInBits is interpreted as an offset
2312  /// into the existing fragment.
2313  ///
2314  /// \param OffsetInBits Offset of the piece in bits.
2315  /// \param SizeInBits Size of the piece in bits.
2316  /// \return Creating a fragment expression may fail if \c Expr
2317  /// contains arithmetic operations that would be truncated.
2319  createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits,
2320  unsigned SizeInBits);
2321 };
2322 
2323 /// Global variables.
2324 ///
2325 /// TODO: Remove DisplayName. It's always equal to Name.
2327  friend class LLVMContextImpl;
2328  friend class MDNode;
2329 
2330  bool IsLocalToUnit;
2331  bool IsDefinition;
2332 
2333  DIGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
2334  bool IsLocalToUnit, bool IsDefinition, uint32_t AlignInBits,
2336  : DIVariable(C, DIGlobalVariableKind, Storage, Line, Ops, AlignInBits),
2337  IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
2338  ~DIGlobalVariable() = default;
2339 
2340  static DIGlobalVariable *getImpl(LLVMContext &Context, DIScope *Scope,
2341  StringRef Name, StringRef LinkageName,
2342  DIFile *File, unsigned Line, DITypeRef Type,
2343  bool IsLocalToUnit, bool IsDefinition,
2344  DIDerivedType *StaticDataMemberDeclaration,
2345  uint32_t AlignInBits, StorageType Storage,
2346  bool ShouldCreate = true) {
2347  return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
2348  getCanonicalMDString(Context, LinkageName), File, Line, Type,
2349  IsLocalToUnit, IsDefinition, StaticDataMemberDeclaration,
2350  AlignInBits, Storage, ShouldCreate);
2351  }
2352  static DIGlobalVariable *
2353  getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
2354  MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
2355  bool IsLocalToUnit, bool IsDefinition,
2356  Metadata *StaticDataMemberDeclaration, uint32_t AlignInBits,
2357  StorageType Storage, bool ShouldCreate = true);
2358 
2359  TempDIGlobalVariable cloneImpl() const {
2360  return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
2361  getFile(), getLine(), getType(), isLocalToUnit(),
2362  isDefinition(), getStaticDataMemberDeclaration(),
2363  getAlignInBits());
2364  }
2365 
2366 public:
2368  (DIScope * Scope, StringRef Name, StringRef LinkageName,
2369  DIFile *File, unsigned Line, DITypeRef Type,
2370  bool IsLocalToUnit, bool IsDefinition,
2371  DIDerivedType *StaticDataMemberDeclaration,
2372  uint32_t AlignInBits),
2373  (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
2374  IsDefinition, StaticDataMemberDeclaration, AlignInBits))
2376  (Metadata * Scope, MDString *Name, MDString *LinkageName,
2377  Metadata *File, unsigned Line, Metadata *Type,
2378  bool IsLocalToUnit, bool IsDefinition,
2379  Metadata *StaticDataMemberDeclaration,
2380  uint32_t AlignInBits),
2381  (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
2382  IsDefinition, StaticDataMemberDeclaration, AlignInBits))
2383 
2384  TempDIGlobalVariable clone() const { return cloneImpl(); }
2385 
2386  bool isLocalToUnit() const { return IsLocalToUnit; }
2387  bool isDefinition() const { return IsDefinition; }
2388  StringRef getDisplayName() const { return getStringOperand(4); }
2389  StringRef getLinkageName() const { return getStringOperand(5); }
2391  return cast_or_null<DIDerivedType>(getRawStaticDataMemberDeclaration());
2392  }
2393 
2394  MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
2395  Metadata *getRawStaticDataMemberDeclaration() const { return getOperand(6); }
2396 
2397  static bool classof(const Metadata *MD) {
2398  return MD->getMetadataID() == DIGlobalVariableKind;
2399  }
2400 };
2401 
2402 /// Local variable.
2403 ///
2404 /// TODO: Split up flags.
2405 class DILocalVariable : public DIVariable {
2406  friend class LLVMContextImpl;
2407  friend class MDNode;
2408 
2409  unsigned Arg : 16;
2410  DIFlags Flags;
2411 
2412  DILocalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
2413  unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
2415  : DIVariable(C, DILocalVariableKind, Storage, Line, Ops, AlignInBits),
2416  Arg(Arg), Flags(Flags) {
2417  assert(Arg < (1 << 16) && "DILocalVariable: Arg out of range");
2418  }
2419  ~DILocalVariable() = default;
2420 
2421  static DILocalVariable *getImpl(LLVMContext &Context, DIScope *Scope,
2422  StringRef Name, DIFile *File, unsigned Line,
2423  DITypeRef Type, unsigned Arg, DIFlags Flags,
2424  uint32_t AlignInBits, StorageType Storage,
2425  bool ShouldCreate = true) {
2426  return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
2427  Line, Type, Arg, Flags, AlignInBits, Storage, ShouldCreate);
2428  }
2429  static DILocalVariable *getImpl(LLVMContext &Context, Metadata *Scope,
2430  MDString *Name, Metadata *File, unsigned Line,
2431  Metadata *Type, unsigned Arg, DIFlags Flags,
2432  uint32_t AlignInBits, StorageType Storage,
2433  bool ShouldCreate = true);
2434 
2435  TempDILocalVariable cloneImpl() const {
2436  return getTemporary(getContext(), getScope(), getName(), getFile(),
2437  getLine(), getType(), getArg(), getFlags(),
2438  getAlignInBits());
2439  }
2440 
2441 public:
2443  (DILocalScope * Scope, StringRef Name, DIFile *File,
2444  unsigned Line, DITypeRef Type, unsigned Arg,
2445  DIFlags Flags, uint32_t AlignInBits),
2446  (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits))
2448  (Metadata * Scope, MDString *Name, Metadata *File,
2449  unsigned Line, Metadata *Type, unsigned Arg,
2450  DIFlags Flags, uint32_t AlignInBits),
2451  (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits))
2452 
2453  TempDILocalVariable clone() const { return cloneImpl(); }
2454 
2455  /// Get the local scope for this variable.
2456  ///
2457  /// Variables must be defined in a local scope.
2459  return cast<DILocalScope>(DIVariable::getScope());
2460  }
2461 
2462  bool isParameter() const { return Arg; }
2463  unsigned getArg() const { return Arg; }
2464  DIFlags getFlags() const { return Flags; }
2465 
2466  bool isArtificial() const { return getFlags() & FlagArtificial; }
2467  bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
2468 
2469  /// Check that a location is valid for this variable.
2470  ///
2471  /// Check that \c DL exists, is in the same subprogram, and has the same
2472  /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
2473  /// to a \a DbgInfoIntrinsic.)
2474  bool isValidLocationForIntrinsic(const DILocation *DL) const {
2475  return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
2476  }
2477 
2478  static bool classof(const Metadata *MD) {
2479  return MD->getMetadataID() == DILocalVariableKind;
2480  }
2481 };
2482 
2483 class DIObjCProperty : public DINode {
2484  friend class LLVMContextImpl;
2485  friend class MDNode;
2486 
2487  unsigned Line;
2488  unsigned Attributes;
2489 
2490  DIObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
2491  unsigned Attributes, ArrayRef<Metadata *> Ops)
2492  : DINode(C, DIObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
2493  Ops),
2494  Line(Line), Attributes(Attributes) {}
2495  ~DIObjCProperty() = default;
2496 
2497  static DIObjCProperty *
2498  getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
2499  StringRef GetterName, StringRef SetterName, unsigned Attributes,
2500  DITypeRef Type, StorageType Storage, bool ShouldCreate = true) {
2501  return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
2502  getCanonicalMDString(Context, GetterName),
2503  getCanonicalMDString(Context, SetterName), Attributes, Type,
2504  Storage, ShouldCreate);
2505  }
2506  static DIObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
2507  Metadata *File, unsigned Line,
2508  MDString *GetterName, MDString *SetterName,
2509  unsigned Attributes, Metadata *Type,
2510  StorageType Storage, bool ShouldCreate = true);
2511 
2512  TempDIObjCProperty cloneImpl() const {
2513  return getTemporary(getContext(), getName(), getFile(), getLine(),
2514  getGetterName(), getSetterName(), getAttributes(),
2515  getType());
2516  }
2517 
2518 public:
2520  (StringRef Name, DIFile *File, unsigned Line,
2521  StringRef GetterName, StringRef SetterName,
2522  unsigned Attributes, DITypeRef Type),
2523  (Name, File, Line, GetterName, SetterName, Attributes,
2524  Type))
2526  (MDString * Name, Metadata *File, unsigned Line,
2527  MDString *GetterName, MDString *SetterName,
2528  unsigned Attributes, Metadata *Type),
2529  (Name, File, Line, GetterName, SetterName, Attributes,
2530  Type))
2531 
2532  TempDIObjCProperty clone() const { return cloneImpl(); }
2533 
2534  unsigned getLine() const { return Line; }
2535  unsigned getAttributes() const { return Attributes; }
2536  StringRef getName() const { return getStringOperand(0); }
2537  DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
2538  StringRef getGetterName() const { return getStringOperand(2); }
2539  StringRef getSetterName() const { return getStringOperand(3); }
2540  DITypeRef getType() const { return DITypeRef(getRawType()); }
2541 
2543  if (auto *F = getFile())
2544  return F->getFilename();
2545  return "";
2546  }
2547 
2549  if (auto *F = getFile())
2550  return F->getDirectory();
2551  return "";
2552  }
2553 
2554  MDString *getRawName() const { return getOperandAs<MDString>(0); }
2555  Metadata *getRawFile() const { return getOperand(1); }
2556  MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
2557  MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
2558  Metadata *getRawType() const { return getOperand(4); }
2559 
2560  static bool classof(const Metadata *MD) {
2561  return MD->getMetadataID() == DIObjCPropertyKind;
2562  }
2563 };
2564 
2565 /// An imported module (C++ using directive or similar).
2566 class DIImportedEntity : public DINode {
2567  friend class LLVMContextImpl;
2568  friend class MDNode;
2569 
2570  unsigned Line;
2571 
2572  DIImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
2573  unsigned Line, ArrayRef<Metadata *> Ops)
2574  : DINode(C, DIImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
2575  ~DIImportedEntity() = default;
2576 
2577  static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
2578  DIScope *Scope, DINodeRef Entity,
2579  DIFile *File, unsigned Line, StringRef Name,
2580  StorageType Storage,
2581  bool ShouldCreate = true) {
2582  return getImpl(Context, Tag, Scope, Entity, File, Line,
2583  getCanonicalMDString(Context, Name), Storage, ShouldCreate);
2584  }
2585  static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
2586  Metadata *Scope, Metadata *Entity,
2587  Metadata *File, unsigned Line,
2588  MDString *Name, StorageType Storage,
2589  bool ShouldCreate = true);
2590 
2591  TempDIImportedEntity cloneImpl() const {
2592  return getTemporary(getContext(), getTag(), getScope(), getEntity(),
2593  getFile(), getLine(), getName());
2594  }
2595 
2596 public:
2598  (unsigned Tag, DIScope *Scope, DINodeRef Entity,
2599  DIFile *File, unsigned Line, StringRef Name = ""),
2600  (Tag, Scope, Entity, File, Line, Name))
2602  (unsigned Tag, Metadata *Scope, Metadata *Entity,
2603  Metadata *File, unsigned Line, MDString *Name),
2604  (Tag, Scope, Entity, File, Line, Name))
2605 
2606  TempDIImportedEntity clone() const { return cloneImpl(); }
2607 
2608  unsigned getLine() const { return Line; }
2609  DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2610  DINodeRef getEntity() const { return DINodeRef(getRawEntity()); }
2611  StringRef getName() const { return getStringOperand(2); }
2612  DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
2613 
2614  Metadata *getRawScope() const { return getOperand(0); }
2615  Metadata *getRawEntity() const { return getOperand(1); }
2616  MDString *getRawName() const { return getOperandAs<MDString>(2); }
2617  Metadata *getRawFile() const { return getOperand(3); }
2618 
2619  static bool classof(const Metadata *MD) {
2620  return MD->getMetadataID() == DIImportedEntityKind;
2621  }
2622 };
2623 
2624 /// A pair of DIGlobalVariable and DIExpression.
2626  friend class LLVMContextImpl;
2627  friend class MDNode;
2628 
2631  : MDNode(C, DIGlobalVariableExpressionKind, Storage, Ops) {}
2632  ~DIGlobalVariableExpression() = default;
2633 
2635  getImpl(LLVMContext &Context, Metadata *Variable, Metadata *Expression,
2636  StorageType Storage, bool ShouldCreate = true);
2637 
2638  TempDIGlobalVariableExpression cloneImpl() const {
2639  return getTemporary(getContext(), getVariable(), getExpression());
2640  }
2641 
2642 public:
2644  (Metadata * Variable, Metadata *Expression),
2645  (Variable, Expression))
2646 
2647  TempDIGlobalVariableExpression clone() const { return cloneImpl(); }
2648 
2649  Metadata *getRawVariable() const { return getOperand(0); }
2650 
2652  return cast_or_null<DIGlobalVariable>(getRawVariable());
2653  }
2654 
2655  Metadata *getRawExpression() const { return getOperand(1); }
2656 
2658  return cast<DIExpression>(getRawExpression());
2659  }
2660 
2661  static bool classof(const Metadata *MD) {
2662  return MD->getMetadataID() == DIGlobalVariableExpressionKind;
2663  }
2664 };
2665 
2666 /// Macro Info DWARF-like metadata node.
2667 ///
2668 /// A metadata node with a DWARF macro info (i.e., a constant named
2669 /// \c DW_MACINFO_*, defined in llvm/BinaryFormat/Dwarf.h). Called \a
2670 /// DIMacroNode
2671 /// because it's potentially used for non-DWARF output.
2672 class DIMacroNode : public MDNode {
2673  friend class LLVMContextImpl;
2674  friend class MDNode;
2675 
2676 protected:
2677  DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType,
2679  : MDNode(C, ID, Storage, Ops1, Ops2) {
2680  assert(MIType < 1u << 16);
2681  SubclassData16 = MIType;
2682  }
2683  ~DIMacroNode() = default;
2684 
2685  template <class Ty> Ty *getOperandAs(unsigned I) const {
2686  return cast_or_null<Ty>(getOperand(I));
2687  }
2688 
2689  StringRef getStringOperand(unsigned I) const {
2690  if (auto *S = getOperandAs<MDString>(I))
2691  return S->getString();
2692  return StringRef();
2693  }
2694 
2696  if (S.empty())
2697  return nullptr;
2698  return MDString::get(Context, S);
2699  }
2700 
2701 public:
2702  unsigned getMacinfoType() const { return SubclassData16; }
2703 
2704  static bool classof(const Metadata *MD) {
2705  switch (MD->getMetadataID()) {
2706  default:
2707  return false;
2708  case DIMacroKind:
2709  case DIMacroFileKind:
2710  return true;
2711  }
2712  }
2713 };
2714 
2715 class DIMacro : public DIMacroNode {
2716  friend class LLVMContextImpl;
2717  friend class MDNode;
2718 
2719  unsigned Line;
2720 
2721  DIMacro(LLVMContext &C, StorageType Storage, unsigned MIType, unsigned Line,
2723  : DIMacroNode(C, DIMacroKind, Storage, MIType, Ops), Line(Line) {}
2724  ~DIMacro() = default;
2725 
2726  static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
2727  StringRef Name, StringRef Value, StorageType Storage,
2728  bool ShouldCreate = true) {
2729  return getImpl(Context, MIType, Line, getCanonicalMDString(Context, Name),
2730  getCanonicalMDString(Context, Value), Storage, ShouldCreate);
2731  }
2732  static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
2733  MDString *Name, MDString *Value, StorageType Storage,
2734  bool ShouldCreate = true);
2735 
2736  TempDIMacro cloneImpl() const {
2737  return getTemporary(getContext(), getMacinfoType(), getLine(), getName(),
2738  getValue());
2739  }
2740 
2741 public:
2742  DEFINE_MDNODE_GET(DIMacro, (unsigned MIType, unsigned Line, StringRef Name,
2743  StringRef Value = ""),
2744  (MIType, Line, Name, Value))
2745  DEFINE_MDNODE_GET(DIMacro, (unsigned MIType, unsigned Line, MDString *Name,
2746  MDString *Value),
2747  (MIType, Line, Name, Value))
2748 
2749  TempDIMacro clone() const { return cloneImpl(); }
2750 
2751  unsigned getLine() const { return Line; }
2752 
2753  StringRef getName() const { return getStringOperand(0); }
2754  StringRef getValue() const { return getStringOperand(1); }
2755 
2756  MDString *getRawName() const { return getOperandAs<MDString>(0); }
2757  MDString *getRawValue() const { return getOperandAs<MDString>(1); }
2758 
2759  static bool classof(const Metadata *MD) {
2760  return MD->getMetadataID() == DIMacroKind;
2761  }
2762 };
2763 
2764 class DIMacroFile : public DIMacroNode {
2765  friend class LLVMContextImpl;
2766  friend class MDNode;
2767 
2768  unsigned Line;
2769 
2770  DIMacroFile(LLVMContext &C, StorageType Storage, unsigned MIType,
2771  unsigned Line, ArrayRef<Metadata *> Ops)
2772  : DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops), Line(Line) {}
2773  ~DIMacroFile() = default;
2774 
2775  static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
2776  unsigned Line, DIFile *File,
2777  DIMacroNodeArray Elements, StorageType Storage,
2778  bool ShouldCreate = true) {
2779  return getImpl(Context, MIType, Line, static_cast<Metadata *>(File),
2780  Elements.get(), Storage, ShouldCreate);
2781  }
2782 
2783  static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
2784  unsigned Line, Metadata *File, Metadata *Elements,
2785  StorageType Storage, bool ShouldCreate = true);
2786 
2787  TempDIMacroFile cloneImpl() const {
2788  return getTemporary(getContext(), getMacinfoType(), getLine(), getFile(),
2789  getElements());
2790  }
2791 
2792 public:
2793  DEFINE_MDNODE_GET(DIMacroFile, (unsigned MIType, unsigned Line, DIFile *File,
2794  DIMacroNodeArray Elements),
2795  (MIType, Line, File, Elements))
2796  DEFINE_MDNODE_GET(DIMacroFile, (unsigned MIType, unsigned Line,
2797  Metadata *File, Metadata *Elements),
2798  (MIType, Line, File, Elements))
2799 
2800  TempDIMacroFile clone() const { return cloneImpl(); }
2801 
2802  void replaceElements(DIMacroNodeArray Elements) {
2803 #ifndef NDEBUG
2804  for (DIMacroNode *Op : getElements())
2805  assert(is_contained(Elements->operands(), Op) &&
2806  "Lost a macro node during macro node list replacement");
2807 #endif
2808  replaceOperandWith(1, Elements.get());
2809  }
2810 
2811  unsigned getLine() const { return Line; }
2812  DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
2813 
2814  DIMacroNodeArray getElements() const {
2815  return cast_or_null<MDTuple>(getRawElements());
2816  }
2817 
2818  Metadata *getRawFile() const { return getOperand(0); }
2819  Metadata *getRawElements() const { return getOperand(1); }
2820 
2821  static bool classof(const Metadata *MD) {
2822  return MD->getMetadataID() == DIMacroFileKind;
2823  }
2824 };
2825 
2826 } // end namespace llvm
2827 
2828 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
2829 #undef DEFINE_MDNODE_GET_UNPACK
2830 #undef DEFINE_MDNODE_GET
2831 
2832 #endif // LLVM_IR_DEBUGINFOMETADATA_H
DIFlags getFlags() const
bool operator==(const expr_op_iterator &X) const
bool isObjectPointer() const
StringRef getFilename() const
Metadata * getRawRetainedTypes() const
uint64_t CallInst * C
static bool classof(const Metadata *MD)
MDString * getRawName() const
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:245
Tracking metadata reference owned by Metadata.
Definition: Metadata.h:709
ArrayRef< uint64_t > getElements() const
#define LLVM_MARK_AS_BITMASK_ENUM(LargestValue)
LLVM_MARK_AS_BITMASK_ENUM lets you opt in an individual enum type so you can perform bitwise operatio...
Definition: BitmaskEnum.h:42
uint64_t getOffsetInBits() const
bool isPrivate() const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1131
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
DITypeRef operator[](unsigned I) const
static bool isConstant(const MachineInstr &MI)
bool isTypePassByValue() const
unsigned getLine() const
LLVMContext & Context
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:236
StringRef getName() const
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
StringRef getName() const
unsigned getRuntimeVersion() const
Metadata * getRawGlobalVariables() const
bool isVirtual() const
Metadata * getRawScope() const
MDString * getRawName() const
StringRef getGetterName() const
Metadata * getRawVTableHolder() const
unsigned size() const
MDTuple * operator->() const
void replaceTemplateParams(DITemplateParameterArray TemplateParams)
MDString * getRawName() const
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:446
Metadata * getRawFile() const
bool operator!=(const expr_op_iterator &X) const
DIFile * getFile() const
DIScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, ArrayRef< Metadata *> Ops)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
DITypeRef getBaseType() const
static bool classof(const Metadata *MD)
unsigned getDiscriminator() const
MDString * getRawValue() const
Metadata * getRawFile() const
Return the raw underlying file.
TypedDINodeRef(std::nullptr_t)
static bool classof(const Metadata *MD)
bool isVector() const
This file contains the declarations for metadata subclasses.
void setSplitDebugInlining(bool SplitDebugInlining)
Metadata * getRawInlinedAt() const
DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags, ArrayRef< Metadata *> Ops)
static enum BaseType getBaseType(const Value *Val)
Return the baseType for Val which states whether Val is exclusively derived from constant/null, or not exclusively derived from constant.
unsigned getSize() const
Return the size of the operand.
ArrayRef< uint64_t >::iterator element_iterator
DICompositeTypeArray getEnumTypes() const
const ExprOperand & operator*() const
DEFINE_MDNODE_GET(DISubrange,(int64_t Count, int64_t LowerBound=0),(Count, LowerBound)) TempDISubrange clone() const
uint64_t getDWOId() const
static bool classof(const Metadata *MD)
static bool classof(const Metadata *MD)
Metadata node.
Definition: Metadata.h:862
F(f)
Metadata * getRawScope() const
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1067
static bool classof(const Metadata *MD)
StringRef getConfigurationMacros() const
static bool classof(const Metadata *MD)
static bool classof(const Metadata *MD)
StringRef getProducer() const
static bool classof(const Metadata *MD)
bool isForwardDecl() const
bool getDebugInfoForProfiling() const
unsigned getVirtuality(StringRef VirtualityString)
Definition: Dwarf.cpp:291
TempDIType clone() const
#define DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS)
op_iterator op_end() const
Definition: Metadata.h:1061
StringRef getName() const
Tuple of metadata.
Definition: Metadata.h:1104
A scope for locals.
Tagged DWARF-like metadata node.
void replaceRetainedTypes(DITypeArray N)
const DILocation * setBaseDiscriminator(unsigned BD) const
Returns a new DILocation with updated base discriminator BD.
bool operator!=(const TypedDINodeRef< T > &X) const
DINodeArray getElements() const
TempMDNode clone() const
Create a (temporary) clone of this.
Definition: Metadata.cpp:514
const DILocation * cloneWithDuplicationFactor(unsigned DF) const
Returns a new DILocation with duplication factor DF encoded in the discriminator. ...
MDString * getRawName() const
op_range dwarf_operands() const
static bool classof(const Metadata *MD)
StringRef getStringOperand(unsigned I) const
DIScope * getScope() const
Metadata * getRawTypeArray() const
Ty * getOperandAs(unsigned I) const
StringRef getSplitDebugFilename() const
StringRef getName() const
StringRef getFlags() const
StringRef getName() const
bool isLValueReference() const
bool isStaticMember() const
unsigned getTag() const
static bool classof(const Metadata *MD)
DIGlobalVariable * getVariable() const
static bool classof(const Metadata *MD)
Array subrange.
expr_op_iterator expr_op_begin() const
Visit the elements via ExprOperand wrappers.
MDString * getRawSetterName() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
static bool classof(const Metadata *MD)
iterator(MDNode::op_iterator I)
static StringRef getName(Value *V)
const uint64_t * get() const
uint64_t getSizeInBits() const
Holds a subclass of DINode.
StringRef getDirectory() const
Metadata * getRawType() const
DITypeRef getVTableHolder() const
StringRef getFilename() const
MDString * getRawISysRoot() const
op_iterator op_begin() const
Definition: Metadata.h:1057
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
bool getExportSymbols() const
Subprogram description.
Metadata * getRawImportedEntities() const
expr_op_iterator expr_op_end() const
int64_t getLowerBound() const
TypedDINodeRef(const T *MD)
StringRef getIncludePath() const
Holds the characteristics of one fragment of a larger variable.
iterator end() const
unsigned getRuntimeLang() const
unsigned getDuplicationFactor() const
Returns the duplication factor stored in the discriminator.
DITypeRef getType() const
MDString * getRawName() const
#define T
Enumeration value.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
DIMacroNodeArray getElements() const
uint32_t getAlignInBytes() const
unsigned getMetadataID() const
Definition: Metadata.h:98
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
const MDOperand & getDwarfOperand(unsigned I) const
uint32_t getAlignInBits() const
DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, ArrayRef< Metadata *> Ops1, ArrayRef< Metadata *> Ops2=None)
Metadata * getRawEntity() const
Debug location.
StringRef getFilename() const
DIScope * getScope() const
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:980
uint64_t getArg(unsigned I) const
Get an argument to the operand.
StringRef getDirectory() const
Metadata * getRawFile() const
unsigned getLine() const
StringRef getStringOperand(unsigned I) const
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:121
DIScope * getScope() const
static bool classof(const Metadata *MD)
uint64_t getOp() const
Get the operand code.
DIMacroNodeArray getMacros() const
op_iterator dwarf_op_begin() const
void replaceVTableHolder(DITypeRef VTableHolder)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1164
DITemplateParameterArray getTemplateParams() const
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:406
unsigned getColumn() const
TypedDINodeRef()=default
TypedDINodeRef< DINode > DINodeRef
static bool classof(const Metadata *MD)
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
static bool classof(const Metadata *MD)
void replaceDwarfOperandWith(unsigned I, Metadata *New)
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
This is an important base class in LLVM.
Definition: Constant.h:42
SourceLanguage
Definition: Dwarf.h:179
Base class for template parameters.
unsigned getAttributes() const
Ty * getOperandAs(unsigned I) const
StorageType
Active type of storage.
Definition: Metadata.h:66
DIExpression * getExpression() const
StringRef getName() const
A lightweight wrapper around an expression operand.
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this variable.
A pair of DIGlobalVariable and DIExpression.
iterator begin() const
DIImportedEntityArray getImportedEntities() const
static MDString * getCanonicalMDString(LLVMContext &Context, StringRef S)
void replaceEnumTypes(DICompositeTypeArray N)
Replace arrays.
void mutate(unsigned Tag, unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags)
Change fields in place.
DIDerivedType * getStaticDataMemberDeclaration() const
static const unsigned End
Optional< FragmentInfo > getFragmentInfo() const
Retrieve the details of this fragment expression.
DEFINE_MDNODE_GET(DIGlobalVariableExpression,(Metadata *Variable, Metadata *Expression),(Variable, Expression)) TempDIGlobalVariableExpression clone() const
Base class for variables.
TypedDINodeRef(const TypedDINodeRef< U > &X, typename std::enable_if< std::is_convertible< U *, T *>::value >::type *=nullptr)
DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Line, ArrayRef< Metadata *> Ops, uint32_t AlignInBits=0)
void init(unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags)
bool isObjcClassComplete() const
StringRef getHeader() const
static bool classof(const Metadata *MD)
MDString * getRawConfigurationMacros() const
StringRef getDirectory() const
unsigned getLine() const
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&... Args)
Definition: DIBuilder.cpp:680
element_iterator elements_end() const
static wasm::ValType getType(const TargetRegisterClass *RC)
uint64_t getElement(unsigned I) const
int64_t getCount() const
static void get()=delete
Metadata * getRawType() const
MDString * getRawChecksum() const
static bool classof(const Metadata *MD)
MDString * getRawName() const
MDTuple * get() const
MDString * getRawName() const
static bool classof(const Metadata *MD)
bool isRValueReference() const
static bool classof(const Metadata *MD)
An imported module (C++ using directive or similar).
StringRef getSetterName() const
Base class for scope-like contexts.
iterator_range< expr_op_iterator > expr_ops() const
op_iterator dwarf_op_end() const
void setTag(unsigned Tag)
Allow subclasses to mutate the tag.
Metadata * getRawElements() const
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
bool isPublic() const
int64_t getValue() const
static SimpleType getSimplifiedValue(const TypedDINodeRef< T > &MD)
static bool classof(const Metadata *MD)
Metadata * getRawScope() const
MDString * getRawFilename() const
static unsigned getBaseDiscriminatorFromDiscriminator(unsigned D)
Returns the base discriminator for a given encoded discriminator D.
void setDWOId(uint64_t DwoId)
static MDString * getCanonicalMDString(LLVMContext &Context, StringRef S)
DITemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage, unsigned Tag, ArrayRef< Metadata *> Ops)
Base class for types.
Metadata * getRawTemplateParams() const
static bool classof(const Metadata *MD)
static unsigned getDuplicationFactorFromDiscriminator(unsigned D)
Returns the duplication factor for a given encoded discriminator D.
unsigned getLine() const
DIFile * getFile() const
unsigned getCopyIdentifier() const
Returns the copy identifier stored in the discriminator.
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:862
static bool classof(const Metadata *MD)
static bool classof(const Metadata *MD)
TypedDINodeRef(const Metadata *MD)
MDString * getRawHeader() const
const ExprOperand * operator->() const
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
DIFile * getFile() const
MDTuple & operator*() const
static unsigned getCopyIdentifierFromDiscriminator(unsigned D)
Returns the copy identifier for a given encoded discriminator D.
bool isProtected() const
static Optional< unsigned > getTag(const TargetRegisterInfo *TRI, const MachineInstr &MI, const LoadInfo &LI)
void setFlags(DIFlags NewFlags)
Metadata * getRawElements() const
Metadata * getRawFile() const
StringRef getDisplayName() const
DWARF expression.
DebugEmissionKind getEmissionKind() const
unsigned getSourceLanguage() const
StringRef getLinkageName() const
A range adaptor for a pair of iterators.
This file contains constants used for implementing Dwarf debug support.
Metadata * getRawFile() const
A (clang) module that has been imported by the compile unit.
DIGlobalVariableExpressionArray getGlobalVariables() const
bool isBlockByrefStruct() const
Generic tagged DWARF-like metadata node.
unsigned getNumElements() const
amdgpu Simplify well known AMD library false Value Value * Arg
Metadata * getRawBaseType() const
StringRef getIdentifier() const
Type array for a subprogram.
static bool classof(const Metadata *MD)
bool getSplitDebugInlining() const
DIFlags
Debug info flags.
MDString * getRawIdentifier() const
Macro Info DWARF-like metadata node.
unsigned getBaseDiscriminator() const
Returns the base discriminator stored in the discriminator.
static bool classof(const Metadata *MD)
bool isArtificial() const
Metadata * getRawEnumTypes() const
unsigned getEncoding() const
Metadata * getRawScope() const
MDString * getRawSplitDebugFilename() const
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType, ArrayRef< Metadata *> Ops1, ArrayRef< Metadata *> Ops2=None)
static bool classof(const Metadata *MD)
MDString * getRawDirectory() const
MDString * getRawProducer() const
MDString * getRawName() const
element_iterator elements_begin() const
LLVM_NODISCARD 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:323
unsigned getMacinfoType() const
StringRef getValue() const
DITypeRefArray(const MDTuple *N)
MDString * getRawLinkageName() const
unsigned getNumDwarfOperands() const
Metadata * getRawStaticDataMemberDeclaration() const
DIScopeArray getRetainedTypes() const
static bool classof(const Metadata *MD)
bool operator!=(const iterator &X) const
DITypeRef getType() const
unsigned getTag() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
uint32_t getAlignInBits() const
aarch64 promote const
uint32_t getAlignInBytes() const
LLVM Value Representation.
Definition: Value.h:73
DIScopeRef getScope() const
static bool classof(const Metadata *MD)
const DILocation * cloneWithDiscriminator(unsigned Discriminator) const
Returns a new DILocation with updated Discriminator.
unsigned getSizeInBits(unsigned Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Get the size in bits of Reg.
void replaceGlobalVariables(DIGlobalVariableExpressionArray N)
Metadata * getRawMacros() const
DINodeRef getEntity() const
DIScope * getScope() const
bool operator==(const TypedDINodeRef< T > &X) const
expr_op_iterator getNext() const
Get the next iterator.
DITypeRefArray getTypeArray() const
bool isBitField() const
bool isAppleBlockExtension() const
Metadata * getRawScope() const
An iterator for expression operands.
void replaceMacros(DIMacroNodeArray N)
TypedDINodeRef< DIScope > DIScopeRef
#define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
DILocalScope * getScope() const
A single uniqued string.
Definition: Metadata.h:602
MDString * getRawIncludePath() const
bool operator==(const iterator &X) const
bool startsWithDeref() const
Return whether the first element a DW_OP_deref.
unsigned getLine() const
Metadata * getRawType() const
Metadata * getRawScope() const
TypedDINodeRef< DIType > DITypeRef
DIFile * getFile() const
static LazyValueInfoImpl & getImpl(void *&PImpl, AssumptionCache *AC, const DataLayout *DL, DominatorTree *DT=nullptr)
This lazily constructs the LazyValueInfoImpl.
DILocalScope * getScope() const
Get the local scope for this variable.
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1073
DILexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage, ArrayRef< Metadata *> Ops)
DEFINE_MDNODE_GET(DIExpression,(ArrayRef< uint64_t > Elements),(Elements)) TempDIExpression clone() const
void replaceElements(DINodeArray Elements)
Replace operands.
bool isFragment() const
Return whether this is a piece of an aggregate variable.
MDString * getRawName() const
Root of the metadata hierarchy.
Definition: Metadata.h:58
unsigned getLine() const
MDString * getRawGetterName() const
StringRef getISysRoot() const
unsigned getHash() const
DILocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, ArrayRef< Metadata *> Ops)
StringRef getName() const
static bool classof(const Metadata *MD)
Metadata * getRawScope() const
void replaceElements(DIMacroNodeArray Elements)
static bool classof(const Metadata *MD)
bool isTypePassByReference() const
static bool classof(const Metadata *MD)
MDString * getRawFlags() const
void replaceImportedEntities(DIImportedEntityArray N)
StringRef getName() const
Basic type, like &#39;int&#39; or &#39;float&#39;.
DIScopeRef getScope() const
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:873