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  bool RangesBaseAddress;
1196 
1197  DICompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
1198  bool IsOptimized, unsigned RuntimeVersion,
1199  unsigned EmissionKind, uint64_t DWOId, bool SplitDebugInlining,
1200  bool DebugInfoForProfiling, unsigned NameTableKind,
1201  bool RangesBaseAddress, ArrayRef<Metadata *> Ops)
1202  : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
1203  SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
1204  RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind),
1205  DWOId(DWOId), SplitDebugInlining(SplitDebugInlining),
1206  DebugInfoForProfiling(DebugInfoForProfiling),
1207  NameTableKind(NameTableKind), RangesBaseAddress(RangesBaseAddress) {
1208  assert(Storage != Uniqued);
1209  }
1210  ~DICompileUnit() = default;
1211 
1212  static DICompileUnit *
1213  getImpl(LLVMContext &Context, unsigned SourceLanguage, DIFile *File,
1214  StringRef Producer, bool IsOptimized, StringRef Flags,
1215  unsigned RuntimeVersion, StringRef SplitDebugFilename,
1216  unsigned EmissionKind, DICompositeTypeArray EnumTypes,
1217  DIScopeArray RetainedTypes,
1218  DIGlobalVariableExpressionArray GlobalVariables,
1219  DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
1220  uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
1221  unsigned NameTableKind, bool RangesBaseAddress, StorageType Storage,
1222  bool ShouldCreate = true) {
1223  return getImpl(Context, SourceLanguage, File,
1224  getCanonicalMDString(Context, Producer), IsOptimized,
1225  getCanonicalMDString(Context, Flags), RuntimeVersion,
1226  getCanonicalMDString(Context, SplitDebugFilename),
1227  EmissionKind, EnumTypes.get(), RetainedTypes.get(),
1228  GlobalVariables.get(), ImportedEntities.get(), Macros.get(),
1229  DWOId, SplitDebugInlining, DebugInfoForProfiling,
1230  NameTableKind, RangesBaseAddress, Storage, ShouldCreate);
1231  }
1232  static DICompileUnit *
1233  getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
1234  MDString *Producer, bool IsOptimized, MDString *Flags,
1235  unsigned RuntimeVersion, MDString *SplitDebugFilename,
1236  unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
1237  Metadata *GlobalVariables, Metadata *ImportedEntities,
1238  Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining,
1239  bool DebugInfoForProfiling, unsigned NameTableKind,
1240  bool RangesBaseAddress, StorageType Storage, bool ShouldCreate = true);
1241 
1242  TempDICompileUnit cloneImpl() const {
1243  return getTemporary(
1244  getContext(), getSourceLanguage(), getFile(), getProducer(),
1245  isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
1246  getEmissionKind(), getEnumTypes(), getRetainedTypes(),
1247  getGlobalVariables(), getImportedEntities(), getMacros(), DWOId,
1248  getSplitDebugInlining(), getDebugInfoForProfiling(), getNameTableKind(),
1249  getRangesBaseAddress());
1250  }
1251 
1252 public:
1253  static void get() = delete;
1254  static void getIfExists() = delete;
1255 
1257  DICompileUnit,
1258  (unsigned SourceLanguage, DIFile *File, StringRef Producer,
1259  bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
1260  StringRef SplitDebugFilename, DebugEmissionKind EmissionKind,
1261  DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes,
1262  DIGlobalVariableExpressionArray GlobalVariables,
1263  DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
1264  uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
1265  DebugNameTableKind NameTableKind, bool RangesBaseAddress),
1266  (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
1267  SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
1268  GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
1269  DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress))
1271  DICompileUnit,
1272  (unsigned SourceLanguage, Metadata *File, MDString *Producer,
1273  bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
1274  MDString *SplitDebugFilename, unsigned EmissionKind, Metadata *EnumTypes,
1275  Metadata *RetainedTypes, Metadata *GlobalVariables,
1276  Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId,
1277  bool SplitDebugInlining, bool DebugInfoForProfiling,
1278  unsigned NameTableKind, bool RangesBaseAddress),
1279  (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
1280  SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
1281  GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
1282  DebugInfoForProfiling, NameTableKind, RangesBaseAddress))
1283 
1284  TempDICompileUnit clone() const { return cloneImpl(); }
1285 
1286  unsigned getSourceLanguage() const { return SourceLanguage; }
1287  bool isOptimized() const { return IsOptimized; }
1288  unsigned getRuntimeVersion() const { return RuntimeVersion; }
1291  }
1292  bool isDebugDirectivesOnly() const {
1293  return EmissionKind == DebugDirectivesOnly;
1294  }
1295  bool getDebugInfoForProfiling() const { return DebugInfoForProfiling; }
1298  }
1299  bool getRangesBaseAddress() const {
1300  return RangesBaseAddress; }
1302  return getStringOperand(1); }
1304  return getStringOperand(2); }
1306  return getStringOperand(3); }
1307  DICompositeTypeArray getEnumTypes() const {
1308  return cast_or_null<MDTuple>(getRawEnumTypes());
1309  }
1310  DIScopeArray getRetainedTypes() const {
1311  return cast_or_null<MDTuple>(getRawRetainedTypes());
1312  }
1313  DIGlobalVariableExpressionArray getGlobalVariables() const {
1314  return cast_or_null<MDTuple>(getRawGlobalVariables());
1315  }
1316  DIImportedEntityArray getImportedEntities() const {
1317  return cast_or_null<MDTuple>(getRawImportedEntities());
1318  }
1319  DIMacroNodeArray getMacros() const {
1320  return cast_or_null<MDTuple>(getRawMacros());
1321  }
1322  uint64_t getDWOId() const { return DWOId; }
1323  void setDWOId(uint64_t DwoId) { DWOId = DwoId; }
1324  bool getSplitDebugInlining() const { return SplitDebugInlining; }
1325  void setSplitDebugInlining(bool SplitDebugInlining) {
1326  this->SplitDebugInlining = SplitDebugInlining;
1327  }
1328 
1329  MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
1330  MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
1332  return getOperandAs<MDString>(3);
1333  }
1334  Metadata *getRawEnumTypes() const { return getOperand(4); }
1335  Metadata *getRawRetainedTypes() const { return getOperand(5); }
1336  Metadata *getRawGlobalVariables() const { return getOperand(6); }
1337  Metadata *getRawImportedEntities() const { return getOperand(7); }
1338  Metadata *getRawMacros() const { return getOperand(8); }
1339 
1340  /// Replace arrays.
1341  ///
1342  /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
1343  /// deleted on a uniquing collision. In practice, uniquing collisions on \a
1344  /// DICompileUnit should be fairly rare.
1345  /// @{
1346  void replaceEnumTypes(DICompositeTypeArray N) {
1347  replaceOperandWith(4, N.get());
1348  }
1349  void replaceRetainedTypes(DITypeArray N) {
1350  replaceOperandWith(5, N.get());
1351  }
1352  void replaceGlobalVariables(DIGlobalVariableExpressionArray N) {
1353  replaceOperandWith(6, N.get());
1354  }
1355  void replaceImportedEntities(DIImportedEntityArray N) {
1356  replaceOperandWith(7, N.get());
1357  }
1358  void replaceMacros(DIMacroNodeArray N) { replaceOperandWith(8, N.get()); }
1359  /// @}
1360 
1361  static bool classof(const Metadata *MD) {
1362  return MD->getMetadataID() == DICompileUnitKind;
1363  }
1364 };
1365 
1366 /// A scope for locals.
1367 ///
1368 /// A legal scope for lexical blocks, local variables, and debug info
1369 /// locations. Subclasses are \a DISubprogram, \a DILexicalBlock, and \a
1370 /// DILexicalBlockFile.
1371 class DILocalScope : public DIScope {
1372 protected:
1373  DILocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1375  : DIScope(C, ID, Storage, Tag, Ops) {}
1376  ~DILocalScope() = default;
1377 
1378 public:
1379  /// Get the subprogram for this scope.
1380  ///
1381  /// Return this if it's an \a DISubprogram; otherwise, look up the scope
1382  /// chain.
1383  DISubprogram *getSubprogram() const;
1384 
1385  /// Get the first non DILexicalBlockFile scope of this scope.
1386  ///
1387  /// Return this if it's not a \a DILexicalBlockFIle; otherwise, look up the
1388  /// scope chain.
1389  DILocalScope *getNonLexicalBlockFileScope() const;
1390 
1391  static bool classof(const Metadata *MD) {
1392  return MD->getMetadataID() == DISubprogramKind ||
1393  MD->getMetadataID() == DILexicalBlockKind ||
1394  MD->getMetadataID() == DILexicalBlockFileKind;
1395  }
1396 };
1397 
1398 /// Debug location.
1399 ///
1400 /// A debug location in source code, used for debug info and otherwise.
1401 class DILocation : public MDNode {
1402  friend class LLVMContextImpl;
1403  friend class MDNode;
1404 
1405  DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
1406  unsigned Column, ArrayRef<Metadata *> MDs, bool ImplicitCode);
1407  ~DILocation() { dropAllReferences(); }
1408 
1409  static DILocation *getImpl(LLVMContext &Context, unsigned Line,
1410  unsigned Column, Metadata *Scope,
1411  Metadata *InlinedAt, bool ImplicitCode,
1412  StorageType Storage, bool ShouldCreate = true);
1413  static DILocation *getImpl(LLVMContext &Context, unsigned Line,
1414  unsigned Column, DILocalScope *Scope,
1415  DILocation *InlinedAt, bool ImplicitCode,
1416  StorageType Storage, bool ShouldCreate = true) {
1417  return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
1418  static_cast<Metadata *>(InlinedAt), ImplicitCode, Storage,
1419  ShouldCreate);
1420  }
1421 
1422  /// With a given unsigned int \p U, use up to 13 bits to represent it.
1423  /// old_bit 1~5 --> new_bit 1~5
1424  /// old_bit 6~12 --> new_bit 7~13
1425  /// new_bit_6 is 0 if higher bits (7~13) are all 0
1426  static unsigned getPrefixEncodingFromUnsigned(unsigned U) {
1427  U &= 0xfff;
1428  return U > 0x1f ? (((U & 0xfe0) << 1) | (U & 0x1f) | 0x20) : U;
1429  }
1430 
1431  /// Reverse transformation as getPrefixEncodingFromUnsigned.
1432  static unsigned getUnsignedFromPrefixEncoding(unsigned U) {
1433  return (U & 0x20) ? (((U >> 1) & 0xfe0) | (U & 0x1f)) : (U & 0x1f);
1434  }
1435 
1436  /// Returns the next component stored in discriminator.
1437  static unsigned getNextComponentInDiscriminator(unsigned D) {
1438  if ((D & 1) == 0)
1439  return D >> ((D & 0x40) ? 14 : 7);
1440  else
1441  return D >> 1;
1442  }
1443 
1444  TempDILocation cloneImpl() const {
1445  // Get the raw scope/inlinedAt since it is possible to invoke this on
1446  // a DILocation containing temporary metadata.
1447  return getTemporary(getContext(), getLine(), getColumn(), getRawScope(),
1448  getRawInlinedAt(), isImplicitCode());
1449  }
1450 
1451 public:
1452  // Disallow replacing operands.
1453  void replaceOperandWith(unsigned I, Metadata *New) = delete;
1454 
1456  (unsigned Line, unsigned Column, Metadata *Scope,
1457  Metadata *InlinedAt = nullptr, bool ImplicitCode = false),
1458  (Line, Column, Scope, InlinedAt, ImplicitCode))
1460  (unsigned Line, unsigned Column, DILocalScope *Scope,
1461  DILocation *InlinedAt = nullptr,
1462  bool ImplicitCode = false),
1463  (Line, Column, Scope, InlinedAt, ImplicitCode))
1464 
1465  /// Return a (temporary) clone of this.
1466  TempDILocation clone() const { return cloneImpl(); }
1467 
1468  unsigned getLine() const { return SubclassData32; }
1469  unsigned getColumn() const { return SubclassData16; }
1470  DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
1471 
1472  DILocation *getInlinedAt() const {
1473  return cast_or_null<DILocation>(getRawInlinedAt());
1474  }
1475 
1476  /// Check if the location corresponds to an implicit code.
1477  /// When the ImplicitCode flag is true, it means that the Instruction
1478  /// with this DILocation has been added by the front-end but it hasn't been
1479  /// written explicitly by the user (e.g. cleanup stuff in C++ put on a closing
1480  /// bracket). It's useful for code coverage to not show a counter on "empty"
1481  /// lines.
1482  bool isImplicitCode() const { return ImplicitCode; }
1483  void setImplicitCode(bool ImplicitCode) { this->ImplicitCode = ImplicitCode; }
1484 
1485  DIFile *getFile() const { return getScope()->getFile(); }
1486  StringRef getFilename() const { return getScope()->getFilename(); }
1487  StringRef getDirectory() const { return getScope()->getDirectory(); }
1488  Optional<StringRef> getSource() const { return getScope()->getSource(); }
1489 
1490  /// Get the scope where this is inlined.
1491  ///
1492  /// Walk through \a getInlinedAt() and return \a getScope() from the deepest
1493  /// location.
1494  DILocalScope *getInlinedAtScope() const {
1495  if (auto *IA = getInlinedAt())
1496  return IA->getInlinedAtScope();
1497  return getScope();
1498  }
1499 
1500  /// Get the DWARF discriminator.
1501  ///
1502  /// DWARF discriminators distinguish identical file locations between
1503  /// instructions that are on different basic blocks.
1504  ///
1505  /// There are 3 components stored in discriminator, from lower bits:
1506  ///
1507  /// Base discriminator: assigned by AddDiscriminators pass to identify IRs
1508  /// that are defined by the same source line, but
1509  /// different basic blocks.
1510  /// Duplication factor: assigned by optimizations that will scale down
1511  /// the execution frequency of the original IR.
1512  /// Copy Identifier: assigned by optimizations that clones the IR.
1513  /// Each copy of the IR will be assigned an identifier.
1514  ///
1515  /// Encoding:
1516  ///
1517  /// The above 3 components are encoded into a 32bit unsigned integer in
1518  /// order. If the lowest bit is 1, the current component is empty, and the
1519  /// next component will start in the next bit. Otherwise, the current
1520  /// component is non-empty, and its content starts in the next bit. The
1521  /// length of each components is either 5 bit or 12 bit: if the 7th bit
1522  /// is 0, the bit 2~6 (5 bits) are used to represent the component; if the
1523  /// 7th bit is 1, the bit 2~6 (5 bits) and 8~14 (7 bits) are combined to
1524  /// represent the component.
1525 
1526  inline unsigned getDiscriminator() const;
1527 
1528  /// Returns a new DILocation with updated \p Discriminator.
1529  inline const DILocation *cloneWithDiscriminator(unsigned Discriminator) const;
1530 
1531  /// Returns a new DILocation with updated base discriminator \p BD.
1532  inline const DILocation *setBaseDiscriminator(unsigned BD) const;
1533 
1534  /// Returns the duplication factor stored in the discriminator.
1535  inline unsigned getDuplicationFactor() const;
1536 
1537  /// Returns the copy identifier stored in the discriminator.
1538  inline unsigned getCopyIdentifier() const;
1539 
1540  /// Returns the base discriminator stored in the discriminator.
1541  inline unsigned getBaseDiscriminator() const;
1542 
1543  /// Returns a new DILocation with duplication factor \p DF encoded in the
1544  /// discriminator.
1545  inline const DILocation *cloneWithDuplicationFactor(unsigned DF) const;
1546 
1547  /// When two instructions are combined into a single instruction we also
1548  /// need to combine the original locations into a single location.
1549  ///
1550  /// When the locations are the same we can use either location. When they
1551  /// differ, we need a third location which is distinct from either. If they
1552  /// have the same file/line but have a different discriminator we could
1553  /// create a location with a new discriminator. If they are from different
1554  /// files/lines the location is ambiguous and can't be represented in a line
1555  /// entry. In this case, if \p GenerateLocation is true, we will set the
1556  /// merged debug location as line 0 of the nearest common scope where the two
1557  /// locations are inlined from.
1558  ///
1559  /// \p GenerateLocation: Whether the merged location can be generated when
1560  /// \p LocA and \p LocB differ.
1561  static const DILocation *getMergedLocation(const DILocation *LocA,
1562  const DILocation *LocB);
1563 
1564  /// Returns the base discriminator for a given encoded discriminator \p D.
1565  static unsigned getBaseDiscriminatorFromDiscriminator(unsigned D) {
1566  if ((D & 1) == 0)
1567  return getUnsignedFromPrefixEncoding(D >> 1);
1568  else
1569  return 0;
1570  }
1571 
1572  /// Returns the duplication factor for a given encoded discriminator \p D.
1573  static unsigned getDuplicationFactorFromDiscriminator(unsigned D) {
1574  D = getNextComponentInDiscriminator(D);
1575  if (D == 0 || (D & 1))
1576  return 1;
1577  else
1578  return getUnsignedFromPrefixEncoding(D >> 1);
1579  }
1580 
1581  /// Returns the copy identifier for a given encoded discriminator \p D.
1582  static unsigned getCopyIdentifierFromDiscriminator(unsigned D) {
1583  return getUnsignedFromPrefixEncoding(getNextComponentInDiscriminator(
1584  getNextComponentInDiscriminator(D)));
1585  }
1586 
1587 
1588  Metadata *getRawScope() const { return getOperand(0); }
1590  if (getNumOperands() == 2)
1591  return getOperand(1);
1592  return nullptr;
1593  }
1594 
1595  static bool classof(const Metadata *MD) {
1596  return MD->getMetadataID() == DILocationKind;
1597  }
1598 };
1599 
1600 /// Subprogram description.
1601 ///
1602 /// TODO: Remove DisplayName. It's always equal to Name.
1603 /// TODO: Split up flags.
1604 class DISubprogram : public DILocalScope {
1605  friend class LLVMContextImpl;
1606  friend class MDNode;
1607 
1608  unsigned Line;
1609  unsigned ScopeLine;
1610  unsigned VirtualIndex;
1611 
1612  /// In the MS ABI, the implicit 'this' parameter is adjusted in the prologue
1613  /// of method overrides from secondary bases by this amount. It may be
1614  /// negative.
1615  int ThisAdjustment;
1616 
1617 public:
1618  /// Debug info subprogram flags.
1620 #define HANDLE_DISP_FLAG(ID, NAME) SPFlag##NAME = ID,
1621 #define DISP_FLAG_LARGEST_NEEDED
1622 #include "llvm/IR/DebugInfoFlags.def"
1623  SPFlagNonvirtual = SPFlagZero,
1624  SPFlagVirtuality = SPFlagVirtual | SPFlagPureVirtual,
1625  LLVM_MARK_AS_BITMASK_ENUM(SPFlagLargest)
1626  };
1627 
1628  static DISPFlags getFlag(StringRef Flag);
1629  static StringRef getFlagString(DISPFlags Flag);
1630 
1631  /// Split up a flags bitfield for easier printing.
1632  ///
1633  /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
1634  /// any remaining (unrecognized) bits.
1635  static DISPFlags splitFlags(DISPFlags Flags,
1636  SmallVectorImpl<DISPFlags> &SplitFlags);
1637 
1638  // Helper for converting old bitfields to new flags word.
1639  static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition,
1640  bool IsOptimized,
1641  unsigned Virtuality = SPFlagNonvirtual) {
1642  // We're assuming virtuality is the low-order field.
1643  static_assert(
1644  int(SPFlagVirtual) == int(dwarf::DW_VIRTUALITY_virtual) &&
1645  int(SPFlagPureVirtual) == int(dwarf::DW_VIRTUALITY_pure_virtual),
1646  "Virtuality constant mismatch");
1647  return static_cast<DISPFlags>(
1648  (Virtuality & SPFlagVirtuality) |
1649  (IsLocalToUnit ? SPFlagLocalToUnit : SPFlagZero) |
1650  (IsDefinition ? SPFlagDefinition : SPFlagZero) |
1651  (IsOptimized ? SPFlagOptimized : SPFlagZero));
1652  }
1653 
1654 private:
1655  DIFlags Flags;
1656  DISPFlags SPFlags;
1657 
1658  DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1659  unsigned ScopeLine, unsigned VirtualIndex, int ThisAdjustment,
1660  DIFlags Flags, DISPFlags SPFlags, ArrayRef<Metadata *> Ops)
1661  : DILocalScope(C, DISubprogramKind, Storage, dwarf::DW_TAG_subprogram,
1662  Ops),
1663  Line(Line), ScopeLine(ScopeLine), VirtualIndex(VirtualIndex),
1664  ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags) {
1665  static_assert(dwarf::DW_VIRTUALITY_max < 4, "Virtuality out of range");
1666  }
1667  ~DISubprogram() = default;
1668 
1669  static DISubprogram *
1670  getImpl(LLVMContext &Context, DIScopeRef Scope, StringRef Name,
1671  StringRef LinkageName, DIFile *File, unsigned Line,
1672  DISubroutineType *Type, unsigned ScopeLine, DITypeRef ContainingType,
1673  unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags,
1674  DISPFlags SPFlags, DICompileUnit *Unit,
1675  DITemplateParameterArray TemplateParams, DISubprogram *Declaration,
1676  DINodeArray RetainedNodes, DITypeArray ThrownTypes,
1677  StorageType Storage, bool ShouldCreate = true) {
1678  return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1679  getCanonicalMDString(Context, LinkageName), File, Line, Type,
1680  ScopeLine, ContainingType, VirtualIndex, ThisAdjustment,
1681  Flags, SPFlags, Unit, TemplateParams.get(), Declaration,
1682  RetainedNodes.get(), ThrownTypes.get(), Storage,
1683  ShouldCreate);
1684  }
1685  static DISubprogram *getImpl(LLVMContext &Context, Metadata *Scope,
1686  MDString *Name, MDString *LinkageName,
1687  Metadata *File, unsigned Line, Metadata *Type,
1688  unsigned ScopeLine, Metadata *ContainingType,
1689  unsigned VirtualIndex, int ThisAdjustment,
1690  DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
1691  Metadata *TemplateParams, Metadata *Declaration,
1692  Metadata *RetainedNodes, Metadata *ThrownTypes,
1693  StorageType Storage, bool ShouldCreate = true);
1694 
1695  TempDISubprogram cloneImpl() const {
1696  return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1697  getFile(), getLine(), getType(), getScopeLine(),
1698  getContainingType(), getVirtualIndex(),
1699  getThisAdjustment(), getFlags(), getSPFlags(),
1700  getUnit(), getTemplateParams(), getDeclaration(),
1701  getRetainedNodes(), getThrownTypes());
1702  }
1703 
1704 public:
1706  DISubprogram,
1707  (DIScopeRef Scope, StringRef Name, StringRef LinkageName, DIFile *File,
1708  unsigned Line, DISubroutineType *Type, unsigned ScopeLine,
1709  DITypeRef ContainingType, unsigned VirtualIndex, int ThisAdjustment,
1710  DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit,
1711  DITemplateParameterArray TemplateParams = nullptr,
1712  DISubprogram *Declaration = nullptr, DINodeArray RetainedNodes = nullptr,
1713  DITypeArray ThrownTypes = nullptr),
1714  (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
1715  VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
1716  Declaration, RetainedNodes, ThrownTypes))
1717 
1719  DISubprogram,
1720  (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
1721  unsigned Line, Metadata *Type, unsigned ScopeLine,
1722  Metadata *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
1723  DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
1724  Metadata *TemplateParams = nullptr, Metadata *Declaration = nullptr,
1725  Metadata *RetainedNodes = nullptr, Metadata *ThrownTypes = nullptr),
1726  (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
1727  VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
1728  Declaration, RetainedNodes, ThrownTypes))
1729 
1730  TempDISubprogram clone() const { return cloneImpl(); }
1731 
1732  /// Returns a new temporary DISubprogram with updated Flags
1733  TempDISubprogram cloneWithFlags(DIFlags NewFlags) const {
1734  auto NewSP = clone();
1735  NewSP->Flags = NewFlags;
1736  return NewSP;
1737  }
1738 
1739 public:
1740  unsigned getLine() const { return Line; }
1741  unsigned getVirtuality() const { return getSPFlags() & SPFlagVirtuality; }
1742  unsigned getVirtualIndex() const { return VirtualIndex; }
1743  int getThisAdjustment() const { return ThisAdjustment; }
1744  unsigned getScopeLine() const { return ScopeLine; }
1745  DIFlags getFlags() const { return Flags; }
1746  DISPFlags getSPFlags() const { return SPFlags; }
1747  bool isLocalToUnit() const { return getSPFlags() & SPFlagLocalToUnit; }
1748  bool isDefinition() const { return getSPFlags() & SPFlagDefinition; }
1749  bool isOptimized() const { return getSPFlags() & SPFlagOptimized; }
1750 
1751  bool isArtificial() const { return getFlags() & FlagArtificial; }
1752  bool isPrivate() const {
1753  return (getFlags() & FlagAccessibility) == FlagPrivate;
1754  }
1755  bool isProtected() const {
1756  return (getFlags() & FlagAccessibility) == FlagProtected;
1757  }
1758  bool isPublic() const {
1759  return (getFlags() & FlagAccessibility) == FlagPublic;
1760  }
1761  bool isExplicit() const { return getFlags() & FlagExplicit; }
1762  bool isPrototyped() const { return getFlags() & FlagPrototyped; }
1763  bool areAllCallsDescribed() const {
1764  return getFlags() & FlagAllCallsDescribed;
1765  }
1766  bool isMainSubprogram() const { return getFlags() & FlagMainSubprogram; }
1767 
1768  /// Check if this is reference-qualified.
1769  ///
1770  /// Return true if this subprogram is a C++11 reference-qualified non-static
1771  /// member function (void foo() &).
1772  bool isLValueReference() const { return getFlags() & FlagLValueReference; }
1773 
1774  /// Check if this is rvalue-reference-qualified.
1775  ///
1776  /// Return true if this subprogram is a C++11 rvalue-reference-qualified
1777  /// non-static member function (void foo() &&).
1778  bool isRValueReference() const { return getFlags() & FlagRValueReference; }
1779 
1780  /// Check if this is marked as noreturn.
1781  ///
1782  /// Return true if this subprogram is C++11 noreturn or C11 _Noreturn
1783  bool isNoReturn() const { return getFlags() & FlagNoReturn; }
1784 
1785  // Check if this routine is a compiler-generated thunk.
1786  //
1787  // Returns true if this subprogram is a thunk generated by the compiler.
1788  bool isThunk() const { return getFlags() & FlagThunk; }
1789 
1790  DIScopeRef getScope() const { return DIScopeRef(getRawScope()); }
1791 
1792  StringRef getName() const { return getStringOperand(2); }
1793  StringRef getLinkageName() const { return getStringOperand(3); }
1794 
1795  DISubroutineType *getType() const {
1796  return cast_or_null<DISubroutineType>(getRawType());
1797  }
1798  DITypeRef getContainingType() const {
1799  return DITypeRef(getRawContainingType());
1800  }
1801 
1802  DICompileUnit *getUnit() const {
1803  return cast_or_null<DICompileUnit>(getRawUnit());
1804  }
1805  void replaceUnit(DICompileUnit *CU) { replaceOperandWith(5, CU); }
1806  DITemplateParameterArray getTemplateParams() const {
1807  return cast_or_null<MDTuple>(getRawTemplateParams());
1808  }
1809  DISubprogram *getDeclaration() const {
1810  return cast_or_null<DISubprogram>(getRawDeclaration());
1811  }
1812  DINodeArray getRetainedNodes() const {
1813  return cast_or_null<MDTuple>(getRawRetainedNodes());
1814  }
1815  DITypeArray getThrownTypes() const {
1816  return cast_or_null<MDTuple>(getRawThrownTypes());
1817  }
1818 
1819  Metadata *getRawScope() const { return getOperand(1); }
1820  MDString *getRawName() const { return getOperandAs<MDString>(2); }
1821  MDString *getRawLinkageName() const { return getOperandAs<MDString>(3); }
1822  Metadata *getRawType() const { return getOperand(4); }
1823  Metadata *getRawUnit() const { return getOperand(5); }
1824  Metadata *getRawDeclaration() const { return getOperand(6); }
1825  Metadata *getRawRetainedNodes() const { return getOperand(7); }
1826  Metadata *getRawContainingType() const {
1827  return getNumOperands() > 8 ? getOperandAs<Metadata>(8) : nullptr;
1828  }
1829  Metadata *getRawTemplateParams() const {
1830  return getNumOperands() > 9 ? getOperandAs<Metadata>(9) : nullptr;
1831  }
1832  Metadata *getRawThrownTypes() const {
1833  return getNumOperands() > 10 ? getOperandAs<Metadata>(10) : nullptr;
1834  }
1835 
1836  /// Check if this subprogram describes the given function.
1837  ///
1838  /// FIXME: Should this be looking through bitcasts?
1839  bool describes(const Function *F) const;
1840 
1841  static bool classof(const Metadata *MD) {
1842  return MD->getMetadataID() == DISubprogramKind;
1843  }
1844 };
1845 
1847 protected:
1850  : DILocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1851  ~DILexicalBlockBase() = default;
1852 
1853 public:
1854  DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
1855 
1856  Metadata *getRawScope() const { return getOperand(1); }
1857 
1858  static bool classof(const Metadata *MD) {
1859  return MD->getMetadataID() == DILexicalBlockKind ||
1860  MD->getMetadataID() == DILexicalBlockFileKind;
1861  }
1862 };
1863 
1865  friend class LLVMContextImpl;
1866  friend class MDNode;
1867 
1868  unsigned Line;
1869  uint16_t Column;
1870 
1871  DILexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1872  unsigned Column, ArrayRef<Metadata *> Ops)
1873  : DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops), Line(Line),
1874  Column(Column) {
1875  assert(Column < (1u << 16) && "Expected 16-bit column");
1876  }
1877  ~DILexicalBlock() = default;
1878 
1879  static DILexicalBlock *getImpl(LLVMContext &Context, DILocalScope *Scope,
1880  DIFile *File, unsigned Line, unsigned Column,
1881  StorageType Storage,
1882  bool ShouldCreate = true) {
1883  return getImpl(Context, static_cast<Metadata *>(Scope),
1884  static_cast<Metadata *>(File), Line, Column, Storage,
1885  ShouldCreate);
1886  }
1887 
1888  static DILexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1889  Metadata *File, unsigned Line, unsigned Column,
1890  StorageType Storage, bool ShouldCreate = true);
1891 
1892  TempDILexicalBlock cloneImpl() const {
1893  return getTemporary(getContext(), getScope(), getFile(), getLine(),
1894  getColumn());
1895  }
1896 
1897 public:
1899  unsigned Line, unsigned Column),
1900  (Scope, File, Line, Column))
1902  unsigned Line, unsigned Column),
1903  (Scope, File, Line, Column))
1904 
1905  TempDILexicalBlock clone() const { return cloneImpl(); }
1906 
1907  unsigned getLine() const { return Line; }
1908  unsigned getColumn() const { return Column; }
1909 
1910  static bool classof(const Metadata *MD) {
1911  return MD->getMetadataID() == DILexicalBlockKind;
1912  }
1913 };
1914 
1916  friend class LLVMContextImpl;
1917  friend class MDNode;
1918 
1919  unsigned Discriminator;
1920 
1922  unsigned Discriminator, ArrayRef<Metadata *> Ops)
1923  : DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops),
1924  Discriminator(Discriminator) {}
1925  ~DILexicalBlockFile() = default;
1926 
1927  static DILexicalBlockFile *getImpl(LLVMContext &Context, DILocalScope *Scope,
1928  DIFile *File, unsigned Discriminator,
1929  StorageType Storage,
1930  bool ShouldCreate = true) {
1931  return getImpl(Context, static_cast<Metadata *>(Scope),
1932  static_cast<Metadata *>(File), Discriminator, Storage,
1933  ShouldCreate);
1934  }
1935 
1936  static DILexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1937  Metadata *File, unsigned Discriminator,
1938  StorageType Storage,
1939  bool ShouldCreate = true);
1940 
1941  TempDILexicalBlockFile cloneImpl() const {
1942  return getTemporary(getContext(), getScope(), getFile(),
1943  getDiscriminator());
1944  }
1945 
1946 public:
1948  unsigned Discriminator),
1949  (Scope, File, Discriminator))
1951  (Metadata * Scope, Metadata *File, unsigned Discriminator),
1952  (Scope, File, Discriminator))
1953 
1954  TempDILexicalBlockFile clone() const { return cloneImpl(); }
1955 
1956  // TODO: Remove these once they're gone from DILexicalBlockBase.
1957  unsigned getLine() const = delete;
1958  unsigned getColumn() const = delete;
1959 
1960  unsigned getDiscriminator() const { return Discriminator; }
1961 
1962  static bool classof(const Metadata *MD) {
1963  return MD->getMetadataID() == DILexicalBlockFileKind;
1964  }
1965 };
1966 
1967 unsigned DILocation::getDiscriminator() const {
1968  if (auto *F = dyn_cast<DILexicalBlockFile>(getScope()))
1969  return F->getDiscriminator();
1970  return 0;
1971 }
1972 
1973 const DILocation *
1974 DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
1975  DIScope *Scope = getScope();
1976  // Skip all parent DILexicalBlockFile that already have a discriminator
1977  // assigned. We do not want to have nested DILexicalBlockFiles that have
1978  // mutliple discriminators because only the leaf DILexicalBlockFile's
1979  // dominator will be used.
1980  for (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope);
1981  LBF && LBF->getDiscriminator() != 0;
1982  LBF = dyn_cast<DILexicalBlockFile>(Scope))
1983  Scope = LBF->getScope();
1984  DILexicalBlockFile *NewScope =
1985  DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator);
1986  return DILocation::get(getContext(), getLine(), getColumn(), NewScope,
1987  getInlinedAt());
1988 }
1989 
1991  return getBaseDiscriminatorFromDiscriminator(getDiscriminator());
1992 }
1993 
1995  return getDuplicationFactorFromDiscriminator(getDiscriminator());
1996 }
1997 
1999  return getCopyIdentifierFromDiscriminator(getDiscriminator());
2000 }
2001 
2003  if (D == 0)
2004  return this;
2005  else
2006  return cloneWithDiscriminator(getPrefixEncodingFromUnsigned(D) << 1);
2007 }
2008 
2010  DF *= getDuplicationFactor();
2011  if (DF <= 1)
2012  return this;
2013 
2014  unsigned BD = getBaseDiscriminator();
2015  unsigned CI = getCopyIdentifier() << (DF > 0x1f ? 14 : 7);
2016  unsigned D = CI | (getPrefixEncodingFromUnsigned(DF) << 1);
2017 
2018  if (BD == 0)
2019  D = (D << 1) | 1;
2020  else
2021  D = (D << (BD > 0x1f ? 14 : 7)) | (getPrefixEncodingFromUnsigned(BD) << 1);
2022 
2023  return cloneWithDiscriminator(D);
2024 }
2025 
2026 class DINamespace : public DIScope {
2027  friend class LLVMContextImpl;
2028  friend class MDNode;
2029 
2030  unsigned ExportSymbols : 1;
2031 
2032  DINamespace(LLVMContext &Context, StorageType Storage, bool ExportSymbols,
2034  : DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace,
2035  Ops),
2036  ExportSymbols(ExportSymbols) {}
2037  ~DINamespace() = default;
2038 
2039  static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope,
2040  StringRef Name, bool ExportSymbols,
2041  StorageType Storage, bool ShouldCreate = true) {
2042  return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
2043  ExportSymbols, Storage, ShouldCreate);
2044  }
2045  static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope,
2046  MDString *Name, bool ExportSymbols,
2047  StorageType Storage, bool ShouldCreate = true);
2048 
2049  TempDINamespace cloneImpl() const {
2050  return getTemporary(getContext(), getScope(), getName(),
2051  getExportSymbols());
2052  }
2053 
2054 public:
2056  (DIScope *Scope, StringRef Name, bool ExportSymbols),
2057  (Scope, Name, ExportSymbols))
2059  (Metadata *Scope, MDString *Name, bool ExportSymbols),
2060  (Scope, Name, ExportSymbols))
2061 
2062  TempDINamespace clone() const { return cloneImpl(); }
2063 
2064  bool getExportSymbols() const { return ExportSymbols; }
2065  DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2066  StringRef getName() const { return getStringOperand(2); }
2067 
2068  Metadata *getRawScope() const { return getOperand(1); }
2069  MDString *getRawName() const { return getOperandAs<MDString>(2); }
2070 
2071  static bool classof(const Metadata *MD) {
2072  return MD->getMetadataID() == DINamespaceKind;
2073  }
2074 };
2075 
2076 /// A (clang) module that has been imported by the compile unit.
2077 ///
2078 class DIModule : public DIScope {
2079  friend class LLVMContextImpl;
2080  friend class MDNode;
2081 
2082  DIModule(LLVMContext &Context, StorageType Storage, ArrayRef<Metadata *> Ops)
2083  : DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops) {}
2084  ~DIModule() = default;
2085 
2086  static DIModule *getImpl(LLVMContext &Context, DIScope *Scope,
2087  StringRef Name, StringRef ConfigurationMacros,
2088  StringRef IncludePath, StringRef ISysRoot,
2089  StorageType Storage, bool ShouldCreate = true) {
2090  return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
2091  getCanonicalMDString(Context, ConfigurationMacros),
2092  getCanonicalMDString(Context, IncludePath),
2093  getCanonicalMDString(Context, ISysRoot),
2094  Storage, ShouldCreate);
2095  }
2096  static DIModule *getImpl(LLVMContext &Context, Metadata *Scope,
2097  MDString *Name, MDString *ConfigurationMacros,
2098  MDString *IncludePath, MDString *ISysRoot,
2099  StorageType Storage, bool ShouldCreate = true);
2100 
2101  TempDIModule cloneImpl() const {
2102  return getTemporary(getContext(), getScope(), getName(),
2103  getConfigurationMacros(), getIncludePath(),
2104  getISysRoot());
2105  }
2106 
2107 public:
2109  StringRef ConfigurationMacros, StringRef IncludePath,
2110  StringRef ISysRoot),
2111  (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot))
2113  (Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
2114  MDString *IncludePath, MDString *ISysRoot),
2115  (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot))
2116 
2117  TempDIModule clone() const { return cloneImpl(); }
2118 
2119  DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2120  StringRef getName() const { return getStringOperand(1); }
2121  StringRef getConfigurationMacros() const { return getStringOperand(2); }
2122  StringRef getIncludePath() const { return getStringOperand(3); }
2123  StringRef getISysRoot() const { return getStringOperand(4); }
2124 
2125  Metadata *getRawScope() const { return getOperand(0); }
2126  MDString *getRawName() const { return getOperandAs<MDString>(1); }
2127  MDString *getRawConfigurationMacros() const { return getOperandAs<MDString>(2); }
2128  MDString *getRawIncludePath() const { return getOperandAs<MDString>(3); }
2129  MDString *getRawISysRoot() const { return getOperandAs<MDString>(4); }
2130 
2131  static bool classof(const Metadata *MD) {
2132  return MD->getMetadataID() == DIModuleKind;
2133  }
2134 };
2135 
2136 /// Base class for template parameters.
2137 class DITemplateParameter : public DINode {
2138 protected:
2139  DITemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
2140  unsigned Tag, ArrayRef<Metadata *> Ops)
2141  : DINode(Context, ID, Storage, Tag, Ops) {}
2142  ~DITemplateParameter() = default;
2143 
2144 public:
2145  StringRef getName() const { return getStringOperand(0); }
2146  DITypeRef getType() const { return DITypeRef(getRawType()); }
2147 
2148  MDString *getRawName() const { return getOperandAs<MDString>(0); }
2149  Metadata *getRawType() const { return getOperand(1); }
2150 
2151  static bool classof(const Metadata *MD) {
2152  return MD->getMetadataID() == DITemplateTypeParameterKind ||
2153  MD->getMetadataID() == DITemplateValueParameterKind;
2154  }
2155 };
2156 
2158  friend class LLVMContextImpl;
2159  friend class MDNode;
2160 
2163  : DITemplateParameter(Context, DITemplateTypeParameterKind, Storage,
2164  dwarf::DW_TAG_template_type_parameter, Ops) {}
2165  ~DITemplateTypeParameter() = default;
2166 
2167  static DITemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
2168  DITypeRef Type, StorageType Storage,
2169  bool ShouldCreate = true) {
2170  return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
2171  ShouldCreate);
2172  }
2173  static DITemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
2174  Metadata *Type, StorageType Storage,
2175  bool ShouldCreate = true);
2176 
2177  TempDITemplateTypeParameter cloneImpl() const {
2178  return getTemporary(getContext(), getName(), getType());
2179  }
2180 
2181 public:
2183  (Name, Type))
2185  (Name, Type))
2186 
2187  TempDITemplateTypeParameter clone() const { return cloneImpl(); }
2188 
2189  static bool classof(const Metadata *MD) {
2190  return MD->getMetadataID() == DITemplateTypeParameterKind;
2191  }
2192 };
2193 
2195  friend class LLVMContextImpl;
2196  friend class MDNode;
2197 
2199  unsigned Tag, ArrayRef<Metadata *> Ops)
2200  : DITemplateParameter(Context, DITemplateValueParameterKind, Storage, Tag,
2201  Ops) {}
2202  ~DITemplateValueParameter() = default;
2203 
2204  static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
2205  StringRef Name, DITypeRef Type,
2206  Metadata *Value, StorageType Storage,
2207  bool ShouldCreate = true) {
2208  return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
2209  Value, Storage, ShouldCreate);
2210  }
2211  static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
2212  MDString *Name, Metadata *Type,
2213  Metadata *Value, StorageType Storage,
2214  bool ShouldCreate = true);
2215 
2216  TempDITemplateValueParameter cloneImpl() const {
2217  return getTemporary(getContext(), getTag(), getName(), getType(),
2218  getValue());
2219  }
2220 
2221 public:
2223  DITypeRef Type, Metadata *Value),
2224  (Tag, Name, Type, Value))
2226  Metadata *Type, Metadata *Value),
2227  (Tag, Name, Type, Value))
2228 
2229  TempDITemplateValueParameter clone() const { return cloneImpl(); }
2230 
2231  Metadata *getValue() const { return getOperand(2); }
2232 
2233  static bool classof(const Metadata *MD) {
2234  return MD->getMetadataID() == DITemplateValueParameterKind;
2235  }
2236 };
2237 
2238 /// Base class for variables.
2239 class DIVariable : public DINode {
2240  unsigned Line;
2241  uint32_t AlignInBits;
2242 
2243 protected:
2244  DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Line,
2245  ArrayRef<Metadata *> Ops, uint32_t AlignInBits = 0)
2246  : DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line),
2247  AlignInBits(AlignInBits) {}
2248  ~DIVariable() = default;
2249 
2250 public:
2251  unsigned getLine() const { return Line; }
2252  DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2253  StringRef getName() const { return getStringOperand(1); }
2254  DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
2255  DITypeRef getType() const { return DITypeRef(getRawType()); }
2256  uint32_t getAlignInBits() const { return AlignInBits; }
2257  uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
2258  /// Determines the size of the variable's type.
2260 
2261  /// Return the signedness of this variable's type, or None if this type is
2262  /// neither signed nor unsigned.
2264  if (auto *BT = dyn_cast<DIBasicType>(getType().resolve()))
2265  return BT->getSignedness();
2266  return None;
2267  }
2268 
2270  if (auto *F = getFile())
2271  return F->getFilename();
2272  return "";
2273  }
2274 
2276  if (auto *F = getFile())
2277  return F->getDirectory();
2278  return "";
2279  }
2280 
2282  if (auto *F = getFile())
2283  return F->getSource();
2284  return None;
2285  }
2286 
2287  Metadata *getRawScope() const { return getOperand(0); }
2288  MDString *getRawName() const { return getOperandAs<MDString>(1); }
2289  Metadata *getRawFile() const { return getOperand(2); }
2290  Metadata *getRawType() const { return getOperand(3); }
2291 
2292  static bool classof(const Metadata *MD) {
2293  return MD->getMetadataID() == DILocalVariableKind ||
2294  MD->getMetadataID() == DIGlobalVariableKind;
2295  }
2296 };
2297 
2298 /// DWARF expression.
2299 ///
2300 /// This is (almost) a DWARF expression that modifies the location of a
2301 /// variable, or the location of a single piece of a variable, or (when using
2302 /// DW_OP_stack_value) is the constant variable value.
2303 ///
2304 /// TODO: Co-allocate the expression elements.
2305 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
2306 /// storage types.
2307 class DIExpression : public MDNode {
2308  friend class LLVMContextImpl;
2309  friend class MDNode;
2310 
2311  std::vector<uint64_t> Elements;
2312 
2314  : MDNode(C, DIExpressionKind, Storage, None),
2315  Elements(Elements.begin(), Elements.end()) {}
2316  ~DIExpression() = default;
2317 
2318  static DIExpression *getImpl(LLVMContext &Context,
2319  ArrayRef<uint64_t> Elements, StorageType Storage,
2320  bool ShouldCreate = true);
2321 
2322  TempDIExpression cloneImpl() const {
2323  return getTemporary(getContext(), getElements());
2324  }
2325 
2326 public:
2328 
2329  TempDIExpression clone() const { return cloneImpl(); }
2330 
2331  ArrayRef<uint64_t> getElements() const { return Elements; }
2332 
2333  unsigned getNumElements() const { return Elements.size(); }
2334 
2335  uint64_t getElement(unsigned I) const {
2336  assert(I < Elements.size() && "Index out of range");
2337  return Elements[I];
2338  }
2339 
2340  /// Determine whether this represents a standalone constant value.
2341  bool isConstant() const;
2342 
2344 
2345  element_iterator elements_begin() const { return getElements().begin(); }
2346  element_iterator elements_end() const { return getElements().end(); }
2347 
2348  /// A lightweight wrapper around an expression operand.
2349  ///
2350  /// TODO: Store arguments directly and change \a DIExpression to store a
2351  /// range of these.
2352  class ExprOperand {
2353  const uint64_t *Op = nullptr;
2354 
2355  public:
2356  ExprOperand() = default;
2357  explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
2358 
2359  const uint64_t *get() const { return Op; }
2360 
2361  /// Get the operand code.
2362  uint64_t getOp() const { return *Op; }
2363 
2364  /// Get an argument to the operand.
2365  ///
2366  /// Never returns the operand itself.
2367  uint64_t getArg(unsigned I) const { return Op[I + 1]; }
2368 
2369  unsigned getNumArgs() const { return getSize() - 1; }
2370 
2371  /// Return the size of the operand.
2372  ///
2373  /// Return the number of elements in the operand (1 + args).
2374  unsigned getSize() const;
2375 
2376  /// Append the elements of this operand to \p V.
2378  V.append(get(), get() + getSize());
2379  }
2380  };
2381 
2382  /// An iterator for expression operands.
2384  : public std::iterator<std::input_iterator_tag, ExprOperand> {
2385  ExprOperand Op;
2386 
2387  public:
2388  expr_op_iterator() = default;
2389  explicit expr_op_iterator(element_iterator I) : Op(I) {}
2390 
2391  element_iterator getBase() const { return Op.get(); }
2392  const ExprOperand &operator*() const { return Op; }
2393  const ExprOperand *operator->() const { return &Op; }
2394 
2396  increment();
2397  return *this;
2398  }
2400  expr_op_iterator T(*this);
2401  increment();
2402  return T;
2403  }
2404 
2405  /// Get the next iterator.
2406  ///
2407  /// \a std::next() doesn't work because this is technically an
2408  /// input_iterator, but it's a perfectly valid operation. This is an
2409  /// accessor to provide the same functionality.
2410  expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
2411 
2412  bool operator==(const expr_op_iterator &X) const {
2413  return getBase() == X.getBase();
2414  }
2415  bool operator!=(const expr_op_iterator &X) const {
2416  return getBase() != X.getBase();
2417  }
2418 
2419  private:
2420  void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
2421  };
2422 
2423  /// Visit the elements via ExprOperand wrappers.
2424  ///
2425  /// These range iterators visit elements through \a ExprOperand wrappers.
2426  /// This is not guaranteed to be a valid range unless \a isValid() gives \c
2427  /// true.
2428  ///
2429  /// \pre \a isValid() gives \c true.
2430  /// @{
2432  return expr_op_iterator(elements_begin());
2433  }
2435  return expr_op_iterator(elements_end());
2436  }
2438  return {expr_op_begin(), expr_op_end()};
2439  }
2440  /// @}
2441 
2442  bool isValid() const;
2443 
2444  static bool classof(const Metadata *MD) {
2445  return MD->getMetadataID() == DIExpressionKind;
2446  }
2447 
2448  /// Return whether the first element a DW_OP_deref.
2449  bool startsWithDeref() const {
2450  return getNumElements() > 0 && getElement(0) == dwarf::DW_OP_deref;
2451  }
2452 
2453  /// Holds the characteristics of one fragment of a larger variable.
2454  struct FragmentInfo {
2455  uint64_t SizeInBits;
2456  uint64_t OffsetInBits;
2457  };
2458 
2459  /// Retrieve the details of this fragment expression.
2460  static Optional<FragmentInfo> getFragmentInfo(expr_op_iterator Start,
2461  expr_op_iterator End);
2462 
2463  /// Retrieve the details of this fragment expression.
2465  return getFragmentInfo(expr_op_begin(), expr_op_end());
2466  }
2467 
2468  /// Return whether this is a piece of an aggregate variable.
2469  bool isFragment() const { return getFragmentInfo().hasValue(); }
2470 
2471  /// Append \p Ops with operations to apply the \p Offset.
2472  static void appendOffset(SmallVectorImpl<uint64_t> &Ops, int64_t Offset);
2473 
2474  /// If this is a constant offset, extract it. If there is no expression,
2475  /// return true with an offset of zero.
2476  bool extractIfOffset(int64_t &Offset) const;
2477 
2478  /// Constants for DIExpression::prepend.
2479  enum { NoDeref = false, WithDeref = true, WithStackValue = true };
2480 
2481  /// Prepend \p DIExpr with a deref and offset operation and optionally turn it
2482  /// into a stack value.
2483  static DIExpression *prepend(const DIExpression *Expr, bool DerefBefore,
2484  int64_t Offset = 0, bool DerefAfter = false,
2485  bool StackValue = false);
2486 
2487  /// Prepend \p DIExpr with the given opcodes and optionally turn it into a
2488  /// stack value.
2489  static DIExpression *prependOpcodes(const DIExpression *Expr,
2491  bool StackValue = false);
2492 
2493  /// Append the opcodes \p Ops to \p DIExpr. Unlike \ref appendToStack, the
2494  /// returned expression is a stack value only if \p DIExpr is a stack value.
2495  /// If \p DIExpr describes a fragment, the returned expression will describe
2496  /// the same fragment.
2497  static DIExpression *append(const DIExpression *Expr, ArrayRef<uint64_t> Ops);
2498 
2499  /// Convert \p DIExpr into a stack value if it isn't one already by appending
2500  /// DW_OP_deref if needed, and appending \p Ops to the resulting expression.
2501  /// If \p DIExpr describes a fragment, the returned expression will describe
2502  /// the same fragment.
2503  static DIExpression *appendToStack(const DIExpression *Expr,
2504  ArrayRef<uint64_t> Ops);
2505 
2506  /// Create a DIExpression to describe one part of an aggregate variable that
2507  /// is fragmented across multiple Values. The DW_OP_LLVM_fragment operation
2508  /// will be appended to the elements of \c Expr. If \c Expr already contains
2509  /// a \c DW_OP_LLVM_fragment \c OffsetInBits is interpreted as an offset
2510  /// into the existing fragment.
2511  ///
2512  /// \param OffsetInBits Offset of the piece in bits.
2513  /// \param SizeInBits Size of the piece in bits.
2514  /// \return Creating a fragment expression may fail if \c Expr
2515  /// contains arithmetic operations that would be truncated.
2517  createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits,
2518  unsigned SizeInBits);
2519 
2520  /// Determine the relative position of the fragments described by this
2521  /// DIExpression and \p Other.
2522  /// Returns -1 if this is entirely before Other, 0 if this and Other overlap,
2523  /// 1 if this is entirely after Other.
2524  int fragmentCmp(const DIExpression *Other) const {
2525  auto Fragment1 = *getFragmentInfo();
2526  auto Fragment2 = *Other->getFragmentInfo();
2527  unsigned l1 = Fragment1.OffsetInBits;
2528  unsigned l2 = Fragment2.OffsetInBits;
2529  unsigned r1 = l1 + Fragment1.SizeInBits;
2530  unsigned r2 = l2 + Fragment2.SizeInBits;
2531  if (r1 <= l2)
2532  return -1;
2533  else if (r2 <= l1)
2534  return 1;
2535  else
2536  return 0;
2537  }
2538 
2539  /// Check if fragments overlap between this DIExpression and \p Other.
2540  bool fragmentsOverlap(const DIExpression *Other) const {
2541  if (!isFragment() || !Other->isFragment())
2542  return true;
2543  return fragmentCmp(Other) == 0;
2544  }
2545 };
2546 
2547 /// Global variables.
2548 ///
2549 /// TODO: Remove DisplayName. It's always equal to Name.
2551  friend class LLVMContextImpl;
2552  friend class MDNode;
2553 
2554  bool IsLocalToUnit;
2555  bool IsDefinition;
2556 
2557  DIGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
2558  bool IsLocalToUnit, bool IsDefinition, uint32_t AlignInBits,
2560  : DIVariable(C, DIGlobalVariableKind, Storage, Line, Ops, AlignInBits),
2561  IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
2562  ~DIGlobalVariable() = default;
2563 
2564  static DIGlobalVariable *
2565  getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
2566  StringRef LinkageName, DIFile *File, unsigned Line, DITypeRef Type,
2567  bool IsLocalToUnit, bool IsDefinition,
2568  DIDerivedType *StaticDataMemberDeclaration, MDTuple *TemplateParams,
2569  uint32_t AlignInBits, StorageType Storage, bool ShouldCreate = true) {
2570  return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
2571  getCanonicalMDString(Context, LinkageName), File, Line, Type,
2572  IsLocalToUnit, IsDefinition, StaticDataMemberDeclaration,
2573  cast_or_null<Metadata>(TemplateParams), AlignInBits, Storage,
2574  ShouldCreate);
2575  }
2576  static DIGlobalVariable *
2577  getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
2578  MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
2579  bool IsLocalToUnit, bool IsDefinition,
2580  Metadata *StaticDataMemberDeclaration, Metadata *TemplateParams,
2581  uint32_t AlignInBits, StorageType Storage, bool ShouldCreate = true);
2582 
2583  TempDIGlobalVariable cloneImpl() const {
2584  return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
2585  getFile(), getLine(), getType(), isLocalToUnit(),
2586  isDefinition(), getStaticDataMemberDeclaration(),
2587  getTemplateParams(), getAlignInBits());
2588  }
2589 
2590 public:
2592  (DIScope * Scope, StringRef Name, StringRef LinkageName,
2593  DIFile *File, unsigned Line, DITypeRef Type,
2594  bool IsLocalToUnit, bool IsDefinition,
2595  DIDerivedType *StaticDataMemberDeclaration,
2596  MDTuple *TemplateParams, uint32_t AlignInBits),
2597  (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
2598  IsDefinition, StaticDataMemberDeclaration, TemplateParams,
2599  AlignInBits))
2601  (Metadata * Scope, MDString *Name, MDString *LinkageName,
2602  Metadata *File, unsigned Line, Metadata *Type,
2603  bool IsLocalToUnit, bool IsDefinition,
2604  Metadata *StaticDataMemberDeclaration,
2605  Metadata *TemplateParams, uint32_t AlignInBits),
2606  (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
2607  IsDefinition, StaticDataMemberDeclaration, TemplateParams,
2608  AlignInBits))
2609 
2610  TempDIGlobalVariable clone() const { return cloneImpl(); }
2611 
2612  bool isLocalToUnit() const { return IsLocalToUnit; }
2613  bool isDefinition() const { return IsDefinition; }
2614  StringRef getDisplayName() const { return getStringOperand(4); }
2615  StringRef getLinkageName() const { return getStringOperand(5); }
2617  return cast_or_null<DIDerivedType>(getRawStaticDataMemberDeclaration());
2618  }
2619 
2620  MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
2621  Metadata *getRawStaticDataMemberDeclaration() const { return getOperand(6); }
2622  Metadata *getRawTemplateParams() const { return getOperand(7); }
2623  MDTuple *getTemplateParams() const { return getOperandAs<MDTuple>(7); }
2624 
2625  static bool classof(const Metadata *MD) {
2626  return MD->getMetadataID() == DIGlobalVariableKind;
2627  }
2628 };
2629 
2630 /// Local variable.
2631 ///
2632 /// TODO: Split up flags.
2633 class DILocalVariable : public DIVariable {
2634  friend class LLVMContextImpl;
2635  friend class MDNode;
2636 
2637  unsigned Arg : 16;
2638  DIFlags Flags;
2639 
2640  DILocalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
2641  unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
2643  : DIVariable(C, DILocalVariableKind, Storage, Line, Ops, AlignInBits),
2644  Arg(Arg), Flags(Flags) {
2645  assert(Arg < (1 << 16) && "DILocalVariable: Arg out of range");
2646  }
2647  ~DILocalVariable() = default;
2648 
2649  static DILocalVariable *getImpl(LLVMContext &Context, DIScope *Scope,
2650  StringRef Name, DIFile *File, unsigned Line,
2651  DITypeRef Type, unsigned Arg, DIFlags Flags,
2652  uint32_t AlignInBits, StorageType Storage,
2653  bool ShouldCreate = true) {
2654  return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
2655  Line, Type, Arg, Flags, AlignInBits, Storage, ShouldCreate);
2656  }
2657  static DILocalVariable *getImpl(LLVMContext &Context, Metadata *Scope,
2658  MDString *Name, Metadata *File, unsigned Line,
2659  Metadata *Type, unsigned Arg, DIFlags Flags,
2660  uint32_t AlignInBits, StorageType Storage,
2661  bool ShouldCreate = true);
2662 
2663  TempDILocalVariable cloneImpl() const {
2664  return getTemporary(getContext(), getScope(), getName(), getFile(),
2665  getLine(), getType(), getArg(), getFlags(),
2666  getAlignInBits());
2667  }
2668 
2669 public:
2671  (DILocalScope * Scope, StringRef Name, DIFile *File,
2672  unsigned Line, DITypeRef Type, unsigned Arg,
2673  DIFlags Flags, uint32_t AlignInBits),
2674  (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits))
2676  (Metadata * Scope, MDString *Name, Metadata *File,
2677  unsigned Line, Metadata *Type, unsigned Arg,
2678  DIFlags Flags, uint32_t AlignInBits),
2679  (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits))
2680 
2681  TempDILocalVariable clone() const { return cloneImpl(); }
2682 
2683  /// Get the local scope for this variable.
2684  ///
2685  /// Variables must be defined in a local scope.
2687  return cast<DILocalScope>(DIVariable::getScope());
2688  }
2689 
2690  bool isParameter() const { return Arg; }
2691  unsigned getArg() const { return Arg; }
2692  DIFlags getFlags() const { return Flags; }
2693 
2694  bool isArtificial() const { return getFlags() & FlagArtificial; }
2695  bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
2696 
2697  /// Check that a location is valid for this variable.
2698  ///
2699  /// Check that \c DL exists, is in the same subprogram, and has the same
2700  /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
2701  /// to a \a DbgInfoIntrinsic.)
2702  bool isValidLocationForIntrinsic(const DILocation *DL) const {
2703  return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
2704  }
2705 
2706  static bool classof(const Metadata *MD) {
2707  return MD->getMetadataID() == DILocalVariableKind;
2708  }
2709 };
2710 
2711 /// Label.
2712 ///
2713 class DILabel : public DINode {
2714  friend class LLVMContextImpl;
2715  friend class MDNode;
2716 
2717  unsigned Line;
2718 
2719  DILabel(LLVMContext &C, StorageType Storage, unsigned Line,
2721  : DINode(C, DILabelKind, Storage, dwarf::DW_TAG_label, Ops), Line(Line) {}
2722  ~DILabel() = default;
2723 
2724  static DILabel *getImpl(LLVMContext &Context, DIScope *Scope,
2725  StringRef Name, DIFile *File, unsigned Line,
2726  StorageType Storage,
2727  bool ShouldCreate = true) {
2728  return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
2729  Line, Storage, ShouldCreate);
2730  }
2731  static DILabel *getImpl(LLVMContext &Context, Metadata *Scope,
2732  MDString *Name, Metadata *File, unsigned Line,
2733  StorageType Storage,
2734  bool ShouldCreate = true);
2735 
2736  TempDILabel cloneImpl() const {
2737  return getTemporary(getContext(), getScope(), getName(), getFile(),
2738  getLine());
2739  }
2740 
2741 public:
2743  (DILocalScope * Scope, StringRef Name, DIFile *File,
2744  unsigned Line),
2745  (Scope, Name, File, Line))
2747  (Metadata * Scope, MDString *Name, Metadata *File,
2748  unsigned Line),
2749  (Scope, Name, File, Line))
2750 
2751  TempDILabel clone() const { return cloneImpl(); }
2752 
2753  /// Get the local scope for this label.
2754  ///
2755  /// Labels must be defined in a local scope.
2757  return cast_or_null<DILocalScope>(getRawScope());
2758  }
2759  unsigned getLine() const { return Line; }
2760  StringRef getName() const { return getStringOperand(1); }
2761  DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
2762 
2763  Metadata *getRawScope() const { return getOperand(0); }
2764  MDString *getRawName() const { return getOperandAs<MDString>(1); }
2765  Metadata *getRawFile() const { return getOperand(2); }
2766 
2767  /// Check that a location is valid for this label.
2768  ///
2769  /// Check that \c DL exists, is in the same subprogram, and has the same
2770  /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
2771  /// to a \a DbgInfoIntrinsic.)
2772  bool isValidLocationForIntrinsic(const DILocation *DL) const {
2773  return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
2774  }
2775 
2776  static bool classof(const Metadata *MD) {
2777  return MD->getMetadataID() == DILabelKind;
2778  }
2779 };
2780 
2781 class DIObjCProperty : public DINode {
2782  friend class LLVMContextImpl;
2783  friend class MDNode;
2784 
2785  unsigned Line;
2786  unsigned Attributes;
2787 
2788  DIObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
2789  unsigned Attributes, ArrayRef<Metadata *> Ops)
2790  : DINode(C, DIObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
2791  Ops),
2792  Line(Line), Attributes(Attributes) {}
2793  ~DIObjCProperty() = default;
2794 
2795  static DIObjCProperty *
2796  getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
2797  StringRef GetterName, StringRef SetterName, unsigned Attributes,
2798  DITypeRef Type, StorageType Storage, bool ShouldCreate = true) {
2799  return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
2800  getCanonicalMDString(Context, GetterName),
2801  getCanonicalMDString(Context, SetterName), Attributes, Type,
2802  Storage, ShouldCreate);
2803  }
2804  static DIObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
2805  Metadata *File, unsigned Line,
2806  MDString *GetterName, MDString *SetterName,
2807  unsigned Attributes, Metadata *Type,
2808  StorageType Storage, bool ShouldCreate = true);
2809 
2810  TempDIObjCProperty cloneImpl() const {
2811  return getTemporary(getContext(), getName(), getFile(), getLine(),
2812  getGetterName(), getSetterName(), getAttributes(),
2813  getType());
2814  }
2815 
2816 public:
2818  (StringRef Name, DIFile *File, unsigned Line,
2819  StringRef GetterName, StringRef SetterName,
2820  unsigned Attributes, DITypeRef Type),
2821  (Name, File, Line, GetterName, SetterName, Attributes,
2822  Type))
2824  (MDString * Name, Metadata *File, unsigned Line,
2825  MDString *GetterName, MDString *SetterName,
2826  unsigned Attributes, Metadata *Type),
2827  (Name, File, Line, GetterName, SetterName, Attributes,
2828  Type))
2829 
2830  TempDIObjCProperty clone() const { return cloneImpl(); }
2831 
2832  unsigned getLine() const { return Line; }
2833  unsigned getAttributes() const { return Attributes; }
2834  StringRef getName() const { return getStringOperand(0); }
2835  DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
2836  StringRef getGetterName() const { return getStringOperand(2); }
2837  StringRef getSetterName() const { return getStringOperand(3); }
2838  DITypeRef getType() const { return DITypeRef(getRawType()); }
2839 
2841  if (auto *F = getFile())
2842  return F->getFilename();
2843  return "";
2844  }
2845 
2847  if (auto *F = getFile())
2848  return F->getDirectory();
2849  return "";
2850  }
2851 
2853  if (auto *F = getFile())
2854  return F->getSource();
2855  return None;
2856  }
2857 
2858  MDString *getRawName() const { return getOperandAs<MDString>(0); }
2859  Metadata *getRawFile() const { return getOperand(1); }
2860  MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
2861  MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
2862  Metadata *getRawType() const { return getOperand(4); }
2863 
2864  static bool classof(const Metadata *MD) {
2865  return MD->getMetadataID() == DIObjCPropertyKind;
2866  }
2867 };
2868 
2869 /// An imported module (C++ using directive or similar).
2870 class DIImportedEntity : public DINode {
2871  friend class LLVMContextImpl;
2872  friend class MDNode;
2873 
2874  unsigned Line;
2875 
2876  DIImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
2877  unsigned Line, ArrayRef<Metadata *> Ops)
2878  : DINode(C, DIImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
2879  ~DIImportedEntity() = default;
2880 
2881  static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
2882  DIScope *Scope, DINodeRef Entity,
2883  DIFile *File, unsigned Line, StringRef Name,
2884  StorageType Storage,
2885  bool ShouldCreate = true) {
2886  return getImpl(Context, Tag, Scope, Entity, File, Line,
2887  getCanonicalMDString(Context, Name), Storage, ShouldCreate);
2888  }
2889  static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
2890  Metadata *Scope, Metadata *Entity,
2891  Metadata *File, unsigned Line,
2892  MDString *Name, StorageType Storage,
2893  bool ShouldCreate = true);
2894 
2895  TempDIImportedEntity cloneImpl() const {
2896  return getTemporary(getContext(), getTag(), getScope(), getEntity(),
2897  getFile(), getLine(), getName());
2898  }
2899 
2900 public:
2902  (unsigned Tag, DIScope *Scope, DINodeRef Entity,
2903  DIFile *File, unsigned Line, StringRef Name = ""),
2904  (Tag, Scope, Entity, File, Line, Name))
2906  (unsigned Tag, Metadata *Scope, Metadata *Entity,
2907  Metadata *File, unsigned Line, MDString *Name),
2908  (Tag, Scope, Entity, File, Line, Name))
2909 
2910  TempDIImportedEntity clone() const { return cloneImpl(); }
2911 
2912  unsigned getLine() const { return Line; }
2913  DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2914  DINodeRef getEntity() const { return DINodeRef(getRawEntity()); }
2915  StringRef getName() const { return getStringOperand(2); }
2916  DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
2917 
2918  Metadata *getRawScope() const { return getOperand(0); }
2919  Metadata *getRawEntity() const { return getOperand(1); }
2920  MDString *getRawName() const { return getOperandAs<MDString>(2); }
2921  Metadata *getRawFile() const { return getOperand(3); }
2922 
2923  static bool classof(const Metadata *MD) {
2924  return MD->getMetadataID() == DIImportedEntityKind;
2925  }
2926 };
2927 
2928 /// A pair of DIGlobalVariable and DIExpression.
2930  friend class LLVMContextImpl;
2931  friend class MDNode;
2932 
2935  : MDNode(C, DIGlobalVariableExpressionKind, Storage, Ops) {}
2936  ~DIGlobalVariableExpression() = default;
2937 
2939  getImpl(LLVMContext &Context, Metadata *Variable, Metadata *Expression,
2940  StorageType Storage, bool ShouldCreate = true);
2941 
2942  TempDIGlobalVariableExpression cloneImpl() const {
2943  return getTemporary(getContext(), getVariable(), getExpression());
2944  }
2945 
2946 public:
2948  (Metadata * Variable, Metadata *Expression),
2949  (Variable, Expression))
2950 
2951  TempDIGlobalVariableExpression clone() const { return cloneImpl(); }
2952 
2953  Metadata *getRawVariable() const { return getOperand(0); }
2954 
2956  return cast_or_null<DIGlobalVariable>(getRawVariable());
2957  }
2958 
2959  Metadata *getRawExpression() const { return getOperand(1); }
2960 
2962  return cast<DIExpression>(getRawExpression());
2963  }
2964 
2965  static bool classof(const Metadata *MD) {
2966  return MD->getMetadataID() == DIGlobalVariableExpressionKind;
2967  }
2968 };
2969 
2970 /// Macro Info DWARF-like metadata node.
2971 ///
2972 /// A metadata node with a DWARF macro info (i.e., a constant named
2973 /// \c DW_MACINFO_*, defined in llvm/BinaryFormat/Dwarf.h). Called \a
2974 /// DIMacroNode
2975 /// because it's potentially used for non-DWARF output.
2976 class DIMacroNode : public MDNode {
2977  friend class LLVMContextImpl;
2978  friend class MDNode;
2979 
2980 protected:
2981  DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType,
2983  : MDNode(C, ID, Storage, Ops1, Ops2) {
2984  assert(MIType < 1u << 16);
2985  SubclassData16 = MIType;
2986  }
2987  ~DIMacroNode() = default;
2988 
2989  template <class Ty> Ty *getOperandAs(unsigned I) const {
2990  return cast_or_null<Ty>(getOperand(I));
2991  }
2992 
2993  StringRef getStringOperand(unsigned I) const {
2994  if (auto *S = getOperandAs<MDString>(I))
2995  return S->getString();
2996  return StringRef();
2997  }
2998 
3000  if (S.empty())
3001  return nullptr;
3002  return MDString::get(Context, S);
3003  }
3004 
3005 public:
3006  unsigned getMacinfoType() const { return SubclassData16; }
3007 
3008  static bool classof(const Metadata *MD) {
3009  switch (MD->getMetadataID()) {
3010  default:
3011  return false;
3012  case DIMacroKind:
3013  case DIMacroFileKind:
3014  return true;
3015  }
3016  }
3017 };
3018 
3019 class DIMacro : public DIMacroNode {
3020  friend class LLVMContextImpl;
3021  friend class MDNode;
3022 
3023  unsigned Line;
3024 
3025  DIMacro(LLVMContext &C, StorageType Storage, unsigned MIType, unsigned Line,
3027  : DIMacroNode(C, DIMacroKind, Storage, MIType, Ops), Line(Line) {}
3028  ~DIMacro() = default;
3029 
3030  static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
3031  StringRef Name, StringRef Value, StorageType Storage,
3032  bool ShouldCreate = true) {
3033  return getImpl(Context, MIType, Line, getCanonicalMDString(Context, Name),
3034  getCanonicalMDString(Context, Value), Storage, ShouldCreate);
3035  }
3036  static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
3037  MDString *Name, MDString *Value, StorageType Storage,
3038  bool ShouldCreate = true);
3039 
3040  TempDIMacro cloneImpl() const {
3041  return getTemporary(getContext(), getMacinfoType(), getLine(), getName(),
3042  getValue());
3043  }
3044 
3045 public:
3046  DEFINE_MDNODE_GET(DIMacro, (unsigned MIType, unsigned Line, StringRef Name,
3047  StringRef Value = ""),
3048  (MIType, Line, Name, Value))
3049  DEFINE_MDNODE_GET(DIMacro, (unsigned MIType, unsigned Line, MDString *Name,
3050  MDString *Value),
3051  (MIType, Line, Name, Value))
3052 
3053  TempDIMacro clone() const { return cloneImpl(); }
3054 
3055  unsigned getLine() const { return Line; }
3056 
3057  StringRef getName() const { return getStringOperand(0); }
3058  StringRef getValue() const { return getStringOperand(1); }
3059 
3060  MDString *getRawName() const { return getOperandAs<MDString>(0); }
3061  MDString *getRawValue() const { return getOperandAs<MDString>(1); }
3062 
3063  static bool classof(const Metadata *MD) {
3064  return MD->getMetadataID() == DIMacroKind;
3065  }
3066 };
3067 
3068 class DIMacroFile : public DIMacroNode {
3069  friend class LLVMContextImpl;
3070  friend class MDNode;
3071 
3072  unsigned Line;
3073 
3074  DIMacroFile(LLVMContext &C, StorageType Storage, unsigned MIType,
3075  unsigned Line, ArrayRef<Metadata *> Ops)
3076  : DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops), Line(Line) {}
3077  ~DIMacroFile() = default;
3078 
3079  static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
3080  unsigned Line, DIFile *File,
3081  DIMacroNodeArray Elements, StorageType Storage,
3082  bool ShouldCreate = true) {
3083  return getImpl(Context, MIType, Line, static_cast<Metadata *>(File),
3084  Elements.get(), Storage, ShouldCreate);
3085  }
3086 
3087  static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
3088  unsigned Line, Metadata *File, Metadata *Elements,
3089  StorageType Storage, bool ShouldCreate = true);
3090 
3091  TempDIMacroFile cloneImpl() const {
3092  return getTemporary(getContext(), getMacinfoType(), getLine(), getFile(),
3093  getElements());
3094  }
3095 
3096 public:
3097  DEFINE_MDNODE_GET(DIMacroFile, (unsigned MIType, unsigned Line, DIFile *File,
3098  DIMacroNodeArray Elements),
3099  (MIType, Line, File, Elements))
3100  DEFINE_MDNODE_GET(DIMacroFile, (unsigned MIType, unsigned Line,
3101  Metadata *File, Metadata *Elements),
3102  (MIType, Line, File, Elements))
3103 
3104  TempDIMacroFile clone() const { return cloneImpl(); }
3105 
3106  void replaceElements(DIMacroNodeArray Elements) {
3107 #ifndef NDEBUG
3108  for (DIMacroNode *Op : getElements())
3109  assert(is_contained(Elements->operands(), Op) &&
3110  "Lost a macro node during macro node list replacement");
3111 #endif
3112  replaceOperandWith(1, Elements.get());
3113  }
3114 
3115  unsigned getLine() const { return Line; }
3116  DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
3117 
3118  DIMacroNodeArray getElements() const {
3119  return cast_or_null<MDTuple>(getRawElements());
3120  }
3121 
3122  Metadata *getRawFile() const { return getOperand(0); }
3123  Metadata *getRawElements() const { return getOperand(1); }
3124 
3125  static bool classof(const Metadata *MD) {
3126  return MD->getMetadataID() == DIMacroFileKind;
3127  }
3128 };
3129 
3130 } // end namespace llvm
3131 
3132 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
3133 #undef DEFINE_MDNODE_GET_UNPACK
3134 #undef DEFINE_MDNODE_GET
3135 
3136 #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:2848
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.
This class represents lattice values for constants.
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
SmallString< 128 > getFilename(const DISubprogram *SP)
Extract a filename for a DISubprogram.
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:135
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
bool getRangesBaseAddress() 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
static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized, unsigned Virtuality=SPFlagNonvirtual)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:419
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
struct UnitT Unit
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:746
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)
DISPFlags
Debug info subprogram flags.
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:1239