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