LLVM  13.0.0git
DebugInfoMetadata.h
Go to the documentation of this file.
1 //===- llvm/IR/DebugInfoMetadata.h - Debug info metadata --------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Declarations for metadata specific to debug info.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_IR_DEBUGINFOMETADATA_H
14 #define LLVM_IR_DEBUGINFOMETADATA_H
15 
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/BitmaskEnum.h"
18 #include "llvm/ADT/None.h"
19 #include "llvm/ADT/Optional.h"
20 #include "llvm/ADT/PointerUnion.h"
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/StringRef.h"
26 #include "llvm/IR/Constants.h"
27 #include "llvm/IR/Metadata.h"
28 #include "llvm/Support/Casting.h"
29 #include <cassert>
30 #include <climits>
31 #include <cstddef>
32 #include <cstdint>
33 #include <iterator>
34 #include <type_traits>
35 #include <vector>
36 
37 // Helper macros for defining get() overrides.
38 #define DEFINE_MDNODE_GET_UNPACK_IMPL(...) __VA_ARGS__
39 #define DEFINE_MDNODE_GET_UNPACK(ARGS) DEFINE_MDNODE_GET_UNPACK_IMPL ARGS
40 #define DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS) \
41  static CLASS *getDistinct(LLVMContext &Context, \
42  DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
43  return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct); \
44  } \
45  static Temp##CLASS getTemporary(LLVMContext &Context, \
46  DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
47  return Temp##CLASS( \
48  getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary)); \
49  }
50 #define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS) \
51  static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
52  return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued); \
53  } \
54  static CLASS *getIfExists(LLVMContext &Context, \
55  DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
56  return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued, \
57  /* ShouldCreate */ false); \
58  } \
59  DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS)
60 
61 namespace llvm {
62 
64  const MDTuple *N = nullptr;
65 
66 public:
67  DITypeRefArray() = default;
68  DITypeRefArray(const MDTuple *N) : N(N) {}
69 
70  explicit operator bool() const { return get(); }
71  explicit operator MDTuple *() const { return get(); }
72 
73  MDTuple *get() const { return const_cast<MDTuple *>(N); }
74  MDTuple *operator->() const { return get(); }
75  MDTuple &operator*() const { return *get(); }
76 
77  // FIXME: Fix callers and remove condition on N.
78  unsigned size() const { return N ? N->getNumOperands() : 0u; }
79  DIType *operator[](unsigned I) const {
80  return cast_or_null<DIType>(N->getOperand(I));
81  }
82 
83  class iterator {
84  MDNode::op_iterator I = nullptr;
85 
86  public:
87  using iterator_category = std::input_iterator_tag;
88  using value_type = DIType *;
89  using difference_type = std::ptrdiff_t;
90  using pointer = void;
91  using reference = DIType *;
92 
93  iterator() = default;
94  explicit iterator(MDNode::op_iterator I) : I(I) {}
95 
96  DIType *operator*() const { return cast_or_null<DIType>(*I); }
97 
99  ++I;
100  return *this;
101  }
102 
104  iterator Temp(*this);
105  ++I;
106  return Temp;
107  }
108 
109  bool operator==(const iterator &X) const { return I == X.I; }
110  bool operator!=(const iterator &X) const { return I != X.I; }
111  };
112 
113  // FIXME: Fix callers and remove condition on N.
114  iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); }
115  iterator end() const { return N ? iterator(N->op_end()) : iterator(); }
116 };
117 
118 /// Tagged DWARF-like metadata node.
119 ///
120 /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
121 /// defined in llvm/BinaryFormat/Dwarf.h). Called \a DINode because it's
122 /// potentially used for non-DWARF output.
123 class DINode : public MDNode {
124  friend class LLVMContextImpl;
125  friend class MDNode;
126 
127 protected:
128  DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
130  : MDNode(C, ID, Storage, Ops1, Ops2) {
131  assert(Tag < 1u << 16);
133  }
134  ~DINode() = default;
135 
136  template <class Ty> Ty *getOperandAs(unsigned I) const {
137  return cast_or_null<Ty>(getOperand(I));
138  }
139 
140  StringRef getStringOperand(unsigned I) const {
141  if (auto *S = getOperandAs<MDString>(I))
142  return S->getString();
143  return StringRef();
144  }
145 
147  if (S.empty())
148  return nullptr;
149  return MDString::get(Context, S);
150  }
151 
152  /// Allow subclasses to mutate the tag.
153  void setTag(unsigned Tag) { SubclassData16 = Tag; }
154 
155 public:
156  unsigned getTag() const { return SubclassData16; }
157 
158  /// Debug info flags.
159  ///
160  /// The three accessibility flags are mutually exclusive and rolled together
161  /// in the first two bits.
162  enum DIFlags : uint32_t {
163 #define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
164 #define DI_FLAG_LARGEST_NEEDED
165 #include "llvm/IR/DebugInfoFlags.def"
166  FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic,
167  FlagPtrToMemberRep = FlagSingleInheritance | FlagMultipleInheritance |
168  FlagVirtualInheritance,
169  LLVM_MARK_AS_BITMASK_ENUM(FlagLargest)
170  };
171 
172  static DIFlags getFlag(StringRef Flag);
174 
175  /// Split up a flags bitfield.
176  ///
177  /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
178  /// any remaining (unrecognized) bits.
179  static DIFlags splitFlags(DIFlags Flags,
180  SmallVectorImpl<DIFlags> &SplitFlags);
181 
182  static bool classof(const Metadata *MD) {
183  switch (MD->getMetadataID()) {
184  default:
185  return false;
186  case GenericDINodeKind:
187  case DISubrangeKind:
188  case DIEnumeratorKind:
189  case DIBasicTypeKind:
190  case DIStringTypeKind:
191  case DIDerivedTypeKind:
192  case DICompositeTypeKind:
193  case DISubroutineTypeKind:
194  case DIFileKind:
195  case DICompileUnitKind:
196  case DISubprogramKind:
197  case DILexicalBlockKind:
198  case DILexicalBlockFileKind:
199  case DINamespaceKind:
200  case DICommonBlockKind:
201  case DITemplateTypeParameterKind:
202  case DITemplateValueParameterKind:
203  case DIGlobalVariableKind:
204  case DILocalVariableKind:
205  case DILabelKind:
206  case DIObjCPropertyKind:
207  case DIImportedEntityKind:
208  case DIModuleKind:
209  case DIGenericSubrangeKind:
210  return true;
211  }
212  }
213 };
214 
215 /// Generic tagged DWARF-like metadata node.
216 ///
217 /// An un-specialized DWARF-like metadata node. The first operand is a
218 /// (possibly empty) null-separated \a MDString header that contains arbitrary
219 /// fields. The remaining operands are \a dwarf_operands(), and are pointers
220 /// to other metadata.
221 class GenericDINode : public DINode {
222  friend class LLVMContextImpl;
223  friend class MDNode;
224 
225  GenericDINode(LLVMContext &C, StorageType Storage, unsigned Hash,
226  unsigned Tag, ArrayRef<Metadata *> Ops1,
228  : DINode(C, GenericDINodeKind, Storage, Tag, Ops1, Ops2) {
229  setHash(Hash);
230  }
232 
233  void setHash(unsigned Hash) { SubclassData32 = Hash; }
234  void recalculateHash();
235 
236  static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
237  StringRef Header, ArrayRef<Metadata *> DwarfOps,
238  StorageType Storage, bool ShouldCreate = true) {
240  DwarfOps, Storage, ShouldCreate);
241  }
242 
243  static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
244  MDString *Header, ArrayRef<Metadata *> DwarfOps,
245  StorageType Storage, bool ShouldCreate = true);
246 
247  TempGenericDINode cloneImpl() const {
248  return getTemporary(getContext(), getTag(), getHeader(),
249  SmallVector<Metadata *, 4>(dwarf_operands()));
250  }
251 
252 public:
253  unsigned getHash() const { return SubclassData32; }
254 
257  (Tag, Header, DwarfOps))
261 
262  /// Return a (temporary) clone of this.
263  TempGenericDINode clone() const { return cloneImpl(); }
264 
265  unsigned getTag() const { return SubclassData16; }
266  StringRef getHeader() const { return getStringOperand(0); }
267  MDString *getRawHeader() const { return getOperandAs<MDString>(0); }
268 
269  op_iterator dwarf_op_begin() const { return op_begin() + 1; }
270  op_iterator dwarf_op_end() const { return op_end(); }
272  return op_range(dwarf_op_begin(), dwarf_op_end());
273  }
274 
275  unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
276  const MDOperand &getDwarfOperand(unsigned I) const {
277  return getOperand(I + 1);
278  }
279  void replaceDwarfOperandWith(unsigned I, Metadata *New) {
280  replaceOperandWith(I + 1, New);
281  }
282 
283  static bool classof(const Metadata *MD) {
284  return MD->getMetadataID() == GenericDINodeKind;
285  }
286 };
287 
288 /// Array subrange.
289 ///
290 /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
291 /// type.
292 class DISubrange : public DINode {
293  friend class LLVMContextImpl;
294  friend class MDNode;
295 
297  : DINode(C, DISubrangeKind, Storage, dwarf::DW_TAG_subrange_type, Ops) {}
298 
299  ~DISubrange() = default;
300 
301  static DISubrange *getImpl(LLVMContext &Context, int64_t Count,
302  int64_t LowerBound, StorageType Storage,
303  bool ShouldCreate = true);
304 
306  int64_t LowerBound, StorageType Storage,
307  bool ShouldCreate = true);
308 
310  Metadata *LowerBound, Metadata *UpperBound,
311  Metadata *Stride, StorageType Storage,
312  bool ShouldCreate = true);
313 
314  TempDISubrange cloneImpl() const {
315  return getTemporary(getContext(), getRawCountNode(), getRawLowerBound(),
316  getRawUpperBound(), getRawStride());
317  }
318 
319 public:
320  DEFINE_MDNODE_GET(DISubrange, (int64_t Count, int64_t LowerBound = 0),
321  (Count, LowerBound))
322 
325 
328  Metadata *UpperBound, Metadata *Stride),
329  (CountNode, LowerBound, UpperBound, Stride))
330 
331  TempDISubrange clone() const { return cloneImpl(); }
332 
333  Metadata *getRawCountNode() const {
334  return getOperand(0).get();
335  }
336 
337  Metadata *getRawLowerBound() const { return getOperand(1).get(); }
338 
339  Metadata *getRawUpperBound() const { return getOperand(2).get(); }
340 
341  Metadata *getRawStride() const { return getOperand(3).get(); }
342 
343  typedef PointerUnion<ConstantInt *, DIVariable *, DIExpression *> BoundType;
344 
345  BoundType getCount() const;
346 
347  BoundType getLowerBound() const;
348 
349  BoundType getUpperBound() const;
350 
351  BoundType getStride() const;
352 
353  static bool classof(const Metadata *MD) {
354  return MD->getMetadataID() == DISubrangeKind;
355  }
356 };
357 
358 class DIGenericSubrange : public DINode {
359  friend class LLVMContextImpl;
360  friend class MDNode;
361 
364  : DINode(C, DIGenericSubrangeKind, Storage,
365  dwarf::DW_TAG_generic_subrange, Ops) {}
366 
367  ~DIGenericSubrange() = default;
368 
370  Metadata *LowerBound, Metadata *UpperBound,
371  Metadata *Stride, StorageType Storage,
372  bool ShouldCreate = true);
373 
374  TempDIGenericSubrange cloneImpl() const {
377  }
378 
379 public:
381  (Metadata * CountNode, Metadata *LowerBound,
382  Metadata *UpperBound, Metadata *Stride),
383  (CountNode, LowerBound, UpperBound, Stride))
384 
385  TempDIGenericSubrange clone() const { return cloneImpl(); }
386 
387  Metadata *getRawCountNode() const { return getOperand(0).get(); }
388  Metadata *getRawLowerBound() const { return getOperand(1).get(); }
389  Metadata *getRawUpperBound() const { return getOperand(2).get(); }
390  Metadata *getRawStride() const { return getOperand(3).get(); }
391 
393 
394  BoundType getCount() const;
395  BoundType getLowerBound() const;
396  BoundType getUpperBound() const;
397  BoundType getStride() const;
398 
399  static bool classof(const Metadata *MD) {
400  return MD->getMetadataID() == DIGenericSubrangeKind;
401  }
402 };
403 
404 /// Enumeration value.
405 ///
406 /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
407 /// longer creates a type cycle.
408 class DIEnumerator : public DINode {
409  friend class LLVMContextImpl;
410  friend class MDNode;
411 
412  APInt Value;
415  : DINode(C, DIEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
416  Value(Value) {
418  }
422  Ops) {}
423  ~DIEnumerator() = default;
424 
425  static DIEnumerator *getImpl(LLVMContext &Context, const APInt &Value,
426  bool IsUnsigned, StringRef Name,
427  StorageType Storage, bool ShouldCreate = true) {
428  return getImpl(Context, Value, IsUnsigned,
429  getCanonicalMDString(Context, Name), Storage, ShouldCreate);
430  }
431  static DIEnumerator *getImpl(LLVMContext &Context, const APInt &Value,
432  bool IsUnsigned, MDString *Name,
433  StorageType Storage, bool ShouldCreate = true);
434 
435  TempDIEnumerator cloneImpl() const {
437  }
438 
439 public:
440  DEFINE_MDNODE_GET(DIEnumerator,
441  (int64_t Value, bool IsUnsigned, StringRef Name),
442  (APInt(64, Value, !IsUnsigned), IsUnsigned, Name))
443  DEFINE_MDNODE_GET(DIEnumerator,
444  (int64_t Value, bool IsUnsigned, MDString *Name),
448  (Value, IsUnsigned, Name))
452 
453  TempDIEnumerator clone() const { return cloneImpl(); }
454 
455  const APInt &getValue() const { return Value; }
456  bool isUnsigned() const { return SubclassData32; }
457  StringRef getName() const { return getStringOperand(0); }
458 
459  MDString *getRawName() const { return getOperandAs<MDString>(0); }
460 
461  static bool classof(const Metadata *MD) {
462  return MD->getMetadataID() == DIEnumeratorKind;
463  }
464 };
465 
466 /// Base class for scope-like contexts.
467 ///
468 /// Base class for lexical scopes and types (which are also declaration
469 /// contexts).
470 ///
471 /// TODO: Separate the concepts of declaration contexts and lexical scopes.
472 class DIScope : public DINode {
473 protected:
474  DIScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
476  : DINode(C, ID, Storage, Tag, Ops) {}
477  ~DIScope() = default;
478 
479 public:
480  DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
481 
482  inline StringRef getFilename() const;
483  inline StringRef getDirectory() const;
484  inline Optional<StringRef> getSource() const;
485 
486  StringRef getName() const;
487  DIScope *getScope() const;
488 
489  /// Return the raw underlying file.
490  ///
491  /// A \a DIFile is a \a DIScope, but it doesn't point at a separate file (it
492  /// \em is the file). If \c this is an \a DIFile, we need to return \c this.
493  /// Otherwise, return the first operand, which is where all other subclasses
494  /// store their file pointer.
495  Metadata *getRawFile() const {
496  return isa<DIFile>(this) ? const_cast<DIScope *>(this)
497  : static_cast<Metadata *>(getOperand(0));
498  }
499 
500  static bool classof(const Metadata *MD) {
501  switch (MD->getMetadataID()) {
502  default:
503  return false;
504  case DIBasicTypeKind:
505  case DIStringTypeKind:
506  case DIDerivedTypeKind:
507  case DICompositeTypeKind:
508  case DISubroutineTypeKind:
509  case DIFileKind:
510  case DICompileUnitKind:
511  case DISubprogramKind:
512  case DILexicalBlockKind:
513  case DILexicalBlockFileKind:
514  case DINamespaceKind:
515  case DICommonBlockKind:
516  case DIModuleKind:
517  return true;
518  }
519  }
520 };
521 
522 /// File.
523 ///
524 /// TODO: Merge with directory/file node (including users).
525 /// TODO: Canonicalize paths on creation.
526 class DIFile : public DIScope {
527  friend class LLVMContextImpl;
528  friend class MDNode;
529 
530 public:
531  /// Which algorithm (e.g. MD5) a checksum was generated with.
532  ///
533  /// The encoding is explicit because it is used directly in Bitcode. The
534  /// value 0 is reserved to indicate the absence of a checksum in Bitcode.
536  // The first variant was originally CSK_None, encoded as 0. The new
537  // internal representation removes the need for this by wrapping the
538  // ChecksumInfo in an Optional, but to preserve Bitcode compatibility the 0
539  // encoding is reserved.
540  CSK_MD5 = 1,
541  CSK_SHA1 = 2,
543  CSK_Last = CSK_SHA256 // Should be last enumeration.
544  };
545 
546  /// A single checksum, represented by a \a Kind and a \a Value (a string).
547  template <typename T>
548  struct ChecksumInfo {
549  /// The kind of checksum which \a Value encodes.
551  /// The string value of the checksum.
553 
555  ~ChecksumInfo() = default;
556  bool operator==(const ChecksumInfo<T> &X) const {
557  return Kind == X.Kind && Value == X.Value;
558  }
559  bool operator!=(const ChecksumInfo<T> &X) const { return !(*this == X); }
560  StringRef getKindAsString() const { return getChecksumKindAsString(Kind); }
561  };
562 
563 private:
565  Optional<MDString *> Source;
566 
568  Optional<ChecksumInfo<MDString *>> CS, Optional<MDString *> Src,
570  : DIScope(C, DIFileKind, Storage, dwarf::DW_TAG_file_type, Ops),
571  Checksum(CS), Source(Src) {}
572  ~DIFile() = default;
573 
574  static DIFile *getImpl(LLVMContext &Context, StringRef Filename,
575  StringRef Directory,
576  Optional<ChecksumInfo<StringRef>> CS,
577  Optional<StringRef> Source,
578  StorageType Storage, bool ShouldCreate = true) {
579  Optional<ChecksumInfo<MDString *>> MDChecksum;
580  if (CS)
581  MDChecksum.emplace(CS->Kind, getCanonicalMDString(Context, CS->Value));
582  return getImpl(Context, getCanonicalMDString(Context, Filename),
583  getCanonicalMDString(Context, Directory), MDChecksum,
584  Source ? Optional<MDString *>(getCanonicalMDString(Context, *Source)) : None,
585  Storage, ShouldCreate);
586  }
587  static DIFile *getImpl(LLVMContext &Context, MDString *Filename,
588  MDString *Directory,
589  Optional<ChecksumInfo<MDString *>> CS,
590  Optional<MDString *> Source, StorageType Storage,
591  bool ShouldCreate = true);
592 
593  TempDIFile cloneImpl() const {
595  getChecksum(), getSource());
596  }
597 
598 public:
599  DEFINE_MDNODE_GET(DIFile, (StringRef Filename, StringRef Directory,
600  Optional<ChecksumInfo<StringRef>> CS = None,
601  Optional<StringRef> Source = None),
602  (Filename, Directory, CS, Source))
605  Optional<MDString *> Source = None),
606  (Filename, Directory, CS, Source))
607 
608  TempDIFile clone() const { return cloneImpl(); }
609 
610  StringRef getFilename() const { return getStringOperand(0); }
611  StringRef getDirectory() const { return getStringOperand(1); }
612  Optional<ChecksumInfo<StringRef>> getChecksum() const {
613  Optional<ChecksumInfo<StringRef>> StringRefChecksum;
614  if (Checksum)
615  StringRefChecksum.emplace(Checksum->Kind, Checksum->Value->getString());
616  return StringRefChecksum;
617  }
618  Optional<StringRef> getSource() const {
619  return Source ? Optional<StringRef>((*Source)->getString()) : None;
620  }
621 
622  MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
623  MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
624  Optional<ChecksumInfo<MDString *>> getRawChecksum() const { return Checksum; }
625  Optional<MDString *> getRawSource() const { return Source; }
626 
627  static StringRef getChecksumKindAsString(ChecksumKind CSKind);
628  static Optional<ChecksumKind> getChecksumKind(StringRef CSKindStr);
629 
630  static bool classof(const Metadata *MD) {
631  return MD->getMetadataID() == DIFileKind;
632  }
633 };
634 
636  if (auto *F = getFile())
637  return F->getFilename();
638  return "";
639 }
640 
642  if (auto *F = getFile())
643  return F->getDirectory();
644  return "";
645 }
646 
648  if (auto *F = getFile())
649  return F->getSource();
650  return None;
651 }
652 
653 /// Base class for types.
654 ///
655 /// TODO: Remove the hardcoded name and context, since many types don't use
656 /// them.
657 /// TODO: Split up flags.
658 class DIType : public DIScope {
659  unsigned Line;
660  DIFlags Flags;
661  uint64_t SizeInBits;
662  uint64_t OffsetInBits;
663  uint32_t AlignInBits;
664 
665 protected:
666  DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
667  unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits,
668  uint64_t OffsetInBits, DIFlags Flags, ArrayRef<Metadata *> Ops)
669  : DIScope(C, ID, Storage, Tag, Ops) {
670  init(Line, SizeInBits, AlignInBits, OffsetInBits, Flags);
671  }
672  ~DIType() = default;
673 
674  void init(unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits,
675  uint64_t OffsetInBits, DIFlags Flags) {
676  this->Line = Line;
677  this->Flags = Flags;
678  this->SizeInBits = SizeInBits;
679  this->AlignInBits = AlignInBits;
680  this->OffsetInBits = OffsetInBits;
681  }
682 
683  /// Change fields in place.
684  void mutate(unsigned Tag, unsigned Line, uint64_t SizeInBits,
685  uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags) {
686  assert(isDistinct() && "Only distinct nodes can mutate");
687  setTag(Tag);
688  init(Line, SizeInBits, AlignInBits, OffsetInBits, Flags);
689  }
690 
691 public:
692  TempDIType clone() const {
693  return TempDIType(cast<DIType>(MDNode::clone().release()));
694  }
695 
696  unsigned getLine() const { return Line; }
697  uint64_t getSizeInBits() const { return SizeInBits; }
698  uint32_t getAlignInBits() const { return AlignInBits; }
699  uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
700  uint64_t getOffsetInBits() const { return OffsetInBits; }
701  DIFlags getFlags() const { return Flags; }
702 
703  DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
704  StringRef getName() const { return getStringOperand(2); }
705 
706 
707  Metadata *getRawScope() const { return getOperand(1); }
708  MDString *getRawName() const { return getOperandAs<MDString>(2); }
709 
710  /// Returns a new temporary DIType with updated Flags
711  TempDIType cloneWithFlags(DIFlags NewFlags) const {
712  auto NewTy = clone();
713  NewTy->Flags = NewFlags;
714  return NewTy;
715  }
716 
717  bool isPrivate() const {
718  return (getFlags() & FlagAccessibility) == FlagPrivate;
719  }
720  bool isProtected() const {
721  return (getFlags() & FlagAccessibility) == FlagProtected;
722  }
723  bool isPublic() const {
724  return (getFlags() & FlagAccessibility) == FlagPublic;
725  }
726  bool isForwardDecl() const { return getFlags() & FlagFwdDecl; }
727  bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; }
728  bool isVirtual() const { return getFlags() & FlagVirtual; }
729  bool isArtificial() const { return getFlags() & FlagArtificial; }
730  bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
731  bool isObjcClassComplete() const {
732  return getFlags() & FlagObjcClassComplete;
733  }
734  bool isVector() const { return getFlags() & FlagVector; }
735  bool isBitField() const { return getFlags() & FlagBitField; }
736  bool isStaticMember() const { return getFlags() & FlagStaticMember; }
737  bool isLValueReference() const { return getFlags() & FlagLValueReference; }
738  bool isRValueReference() const { return getFlags() & FlagRValueReference; }
739  bool isTypePassByValue() const { return getFlags() & FlagTypePassByValue; }
740  bool isTypePassByReference() const {
741  return getFlags() & FlagTypePassByReference;
742  }
743  bool isBigEndian() const { return getFlags() & FlagBigEndian; }
744  bool isLittleEndian() const { return getFlags() & FlagLittleEndian; }
745  bool getExportSymbols() const { return getFlags() & FlagExportSymbols; }
746 
747  static bool classof(const Metadata *MD) {
748  switch (MD->getMetadataID()) {
749  default:
750  return false;
751  case DIBasicTypeKind:
752  case DIStringTypeKind:
753  case DIDerivedTypeKind:
754  case DICompositeTypeKind:
755  case DISubroutineTypeKind:
756  return true;
757  }
758  }
759 };
760 
761 /// Basic type, like 'int' or 'float'.
762 ///
763 /// TODO: Split out DW_TAG_unspecified_type.
764 /// TODO: Drop unused accessors.
765 class DIBasicType : public DIType {
766  friend class LLVMContextImpl;
767  friend class MDNode;
768 
769  unsigned Encoding;
770 
772  uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
774  : DIType(C, DIBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
775  Flags, Ops),
776  Encoding(Encoding) {}
777  ~DIBasicType() = default;
778 
779  static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
780  StringRef Name, uint64_t SizeInBits,
781  uint32_t AlignInBits, unsigned Encoding,
783  bool ShouldCreate = true) {
785  SizeInBits, AlignInBits, Encoding, Flags, Storage,
786  ShouldCreate);
787  }
788  static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
789  MDString *Name, uint64_t SizeInBits,
790  uint32_t AlignInBits, unsigned Encoding,
792  bool ShouldCreate = true);
793 
794  TempDIBasicType cloneImpl() const {
797  }
798 
799 public:
800  DEFINE_MDNODE_GET(DIBasicType, (unsigned Tag, StringRef Name),
801  (Tag, Name, 0, 0, 0, FlagZero))
802  DEFINE_MDNODE_GET(DIBasicType,
803  (unsigned Tag, StringRef Name, uint64_t SizeInBits),
804  (Tag, Name, SizeInBits, 0, 0, FlagZero))
806  (unsigned Tag, MDString *Name, uint64_t SizeInBits),
807  (Tag, Name, SizeInBits, 0, 0, FlagZero))
809  (unsigned Tag, StringRef Name, uint64_t SizeInBits,
810  uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
813  (unsigned Tag, MDString *Name, uint64_t SizeInBits,
814  uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
815  (Tag, Name, SizeInBits, AlignInBits, Encoding, Flags))
816 
817  TempDIBasicType clone() const { return cloneImpl(); }
818 
819  unsigned getEncoding() const { return Encoding; }
820 
821  enum class Signedness { Signed, Unsigned };
822 
823  /// Return the signedness of this type, or None if this type is neither
824  /// signed nor unsigned.
826 
827  static bool classof(const Metadata *MD) {
828  return MD->getMetadataID() == DIBasicTypeKind;
829  }
830 };
831 
832 /// String type, Fortran CHARACTER(n)
833 class DIStringType : public DIType {
834  friend class LLVMContextImpl;
835  friend class MDNode;
836 
837  unsigned Encoding;
838 
840  uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
842  : DIType(C, DIStringTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
843  FlagZero, Ops),
844  Encoding(Encoding) {}
845  ~DIStringType() = default;
846 
847  static DIStringType *getImpl(LLVMContext &Context, unsigned Tag,
849  Metadata *StrLenExp, uint64_t SizeInBits,
850  uint32_t AlignInBits, unsigned Encoding,
851  StorageType Storage, bool ShouldCreate = true) {
853  StringLength, StrLenExp, SizeInBits, AlignInBits, Encoding,
854  Storage, ShouldCreate);
855  }
856  static DIStringType *getImpl(LLVMContext &Context, unsigned Tag,
857  MDString *Name, Metadata *StringLength,
858  Metadata *StrLenExp, uint64_t SizeInBits,
859  uint32_t AlignInBits, unsigned Encoding,
860  StorageType Storage, bool ShouldCreate = true);
861 
862  TempDIStringType cloneImpl() const {
863  return getTemporary(getContext(), getTag(), getRawName(),
866  }
867 
868 public:
869  DEFINE_MDNODE_GET(DIStringType,
870  (unsigned Tag, StringRef Name, uint64_t SizeInBits,
872  (Tag, Name, nullptr, nullptr, SizeInBits, AlignInBits, 0))
873  DEFINE_MDNODE_GET(DIStringType,
876  uint32_t AlignInBits, unsigned Encoding),
878  AlignInBits, Encoding))
880  (unsigned Tag, StringRef Name, Metadata *StringLength,
882  uint32_t AlignInBits, unsigned Encoding),
884  AlignInBits, Encoding))
885 
886  TempDIStringType clone() const { return cloneImpl(); }
887 
888  static bool classof(const Metadata *MD) {
889  return MD->getMetadataID() == DIStringTypeKind;
890  }
891 
893  return cast_or_null<DIVariable>(getRawStringLength());
894  }
895 
897  return cast_or_null<DIExpression>(getRawStringLengthExp());
898  }
899 
900  unsigned getEncoding() const { return Encoding; }
901 
902  Metadata *getRawStringLength() const { return getOperand(3); }
903 
904  Metadata *getRawStringLengthExp() const { return getOperand(4); }
905 };
906 
907 /// Derived types.
908 ///
909 /// This includes qualified types, pointers, references, friends, typedefs, and
910 /// class members.
911 ///
912 /// TODO: Split out members (inheritance, fields, methods, etc.).
913 class DIDerivedType : public DIType {
914  friend class LLVMContextImpl;
915  friend class MDNode;
916 
917  /// The DWARF address space of the memory pointed to or referenced by a
918  /// pointer or reference type respectively.
919  Optional<unsigned> DWARFAddressSpace;
920 
922  unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits,
923  uint64_t OffsetInBits, Optional<unsigned> DWARFAddressSpace,
925  : DIType(C, DIDerivedTypeKind, Storage, Tag, Line, SizeInBits,
927  DWARFAddressSpace(DWARFAddressSpace) {}
928  ~DIDerivedType() = default;
929 
930  static DIDerivedType *
932  unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
934  Optional<unsigned> DWARFAddressSpace, DIFlags Flags,
935  Metadata *ExtraData, StorageType Storage, bool ShouldCreate = true) {
938  DWARFAddressSpace, Flags, ExtraData, Storage, ShouldCreate);
939  }
940  static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
941  MDString *Name, Metadata *File, unsigned Line,
943  uint64_t SizeInBits, uint32_t AlignInBits,
944  uint64_t OffsetInBits,
945  Optional<unsigned> DWARFAddressSpace,
946  DIFlags Flags, Metadata *ExtraData,
947  StorageType Storage, bool ShouldCreate = true);
948 
949  TempDIDerivedType cloneImpl() const {
950  return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
953  getDWARFAddressSpace(), getFlags(), getExtraData());
954  }
955 
956 public:
957  DEFINE_MDNODE_GET(DIDerivedType,
958  (unsigned Tag, MDString *Name, Metadata *File,
959  unsigned Line, Metadata *Scope, Metadata *BaseType,
960  uint64_t SizeInBits, uint32_t AlignInBits,
961  uint64_t OffsetInBits,
962  Optional<unsigned> DWARFAddressSpace, DIFlags Flags,
963  Metadata *ExtraData = nullptr),
965  AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
966  ExtraData))
967  DEFINE_MDNODE_GET(DIDerivedType,
968  (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
971  Optional<unsigned> DWARFAddressSpace, DIFlags Flags,
972  Metadata *ExtraData = nullptr),
974  AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
975  ExtraData))
976 
977  TempDIDerivedType clone() const { return cloneImpl(); }
978 
979  /// Get the base type this is derived from.
980  DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); }
981  Metadata *getRawBaseType() const { return getOperand(3); }
982 
983  /// \returns The DWARF address space of the memory pointed to or referenced by
984  /// a pointer or reference type respectively.
985  Optional<unsigned> getDWARFAddressSpace() const { return DWARFAddressSpace; }
986 
987  /// Get extra data associated with this derived type.
988  ///
989  /// Class type for pointer-to-members, objective-c property node for ivars,
990  /// global constant wrapper for static members, or virtual base pointer offset
991  /// for inheritance.
992  ///
993  /// TODO: Separate out types that need this extra operand: pointer-to-member
994  /// types and member fields (static members and ivars).
995  Metadata *getExtraData() const { return getRawExtraData(); }
996  Metadata *getRawExtraData() const { return getOperand(4); }
997 
998  /// Get casted version of extra data.
999  /// @{
1000  DIType *getClassType() const {
1001  assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
1002  return cast_or_null<DIType>(getExtraData());
1003  }
1004 
1005  DIObjCProperty *getObjCProperty() const {
1006  return dyn_cast_or_null<DIObjCProperty>(getExtraData());
1007  }
1008 
1009  uint32_t getVBPtrOffset() const {
1010  assert(getTag() == dwarf::DW_TAG_inheritance);
1011  if (auto *CM = cast_or_null<ConstantAsMetadata>(getExtraData()))
1012  if (auto *CI = dyn_cast_or_null<ConstantInt>(CM->getValue()))
1013  return static_cast<uint32_t>(CI->getZExtValue());
1014  return 0;
1015  }
1016 
1017  Constant *getStorageOffsetInBits() const {
1018  assert(getTag() == dwarf::DW_TAG_member && isBitField());
1019  if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
1020  return C->getValue();
1021  return nullptr;
1022  }
1023 
1024  Constant *getConstant() const {
1025  assert(getTag() == dwarf::DW_TAG_member && isStaticMember());
1026  if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
1027  return C->getValue();
1028  return nullptr;
1029  }
1030  Constant *getDiscriminantValue() const {
1031  assert(getTag() == dwarf::DW_TAG_member && !isStaticMember());
1032  if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
1033  return C->getValue();
1034  return nullptr;
1035  }
1036  /// @}
1037 
1038  static bool classof(const Metadata *MD) {
1039  return MD->getMetadataID() == DIDerivedTypeKind;
1040  }
1041 };
1042 
1043 /// Composite types.
1044 ///
1045 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
1046 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
1047 class DICompositeType : public DIType {
1048  friend class LLVMContextImpl;
1049  friend class MDNode;
1050 
1051  unsigned RuntimeLang;
1052 
1054  unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
1057  : DIType(C, DICompositeTypeKind, Storage, Tag, Line, SizeInBits,
1058  AlignInBits, OffsetInBits, Flags, Ops),
1059  RuntimeLang(RuntimeLang) {}
1060  ~DICompositeType() = default;
1061 
1062  /// Change fields in place.
1063  void mutate(unsigned Tag, unsigned Line, unsigned RuntimeLang,
1064  uint64_t SizeInBits, uint32_t AlignInBits,
1065  uint64_t OffsetInBits, DIFlags Flags) {
1066  assert(isDistinct() && "Only distinct nodes can mutate");
1067  assert(getRawIdentifier() && "Only ODR-uniqued nodes should mutate");
1068  this->RuntimeLang = RuntimeLang;
1070  }
1071 
1072  static DICompositeType *
1073  getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
1074  unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1076  DINodeArray Elements, unsigned RuntimeLang, DIType *VTableHolder,
1077  DITemplateParameterArray TemplateParams, StringRef Identifier,
1078  DIDerivedType *Discriminator, Metadata *DataLocation,
1080  StorageType Storage, bool ShouldCreate = true) {
1081  return getImpl(
1084  RuntimeLang, VTableHolder, TemplateParams.get(),
1086  Associated, Allocated, Rank, Storage, ShouldCreate);
1087  }
1088  static DICompositeType *
1089  getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1090  unsigned Line, Metadata *Scope, Metadata *BaseType,
1091  uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
1092  DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
1096  StorageType Storage, bool ShouldCreate = true);
1097 
1098  TempDICompositeType cloneImpl() const {
1099  return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
1106  }
1107 
1108 public:
1110  DICompositeType,
1111  (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1112  DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1114  DINodeArray Elements, unsigned RuntimeLang, DIType *VTableHolder,
1115  DITemplateParameterArray TemplateParams = nullptr,
1116  StringRef Identifier = "", DIDerivedType *Discriminator = nullptr,
1117  Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
1118  Metadata *Allocated = nullptr, Metadata *Rank = nullptr),
1123  DICompositeType,
1124  (unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
1127  Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
1128  Metadata *TemplateParams = nullptr, MDString *Identifier = nullptr,
1130  Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
1131  Metadata *Rank = nullptr),
1135 
1136  TempDICompositeType clone() const { return cloneImpl(); }
1137 
1138  /// Get a DICompositeType with the given ODR identifier.
1139  ///
1140  /// If \a LLVMContext::isODRUniquingDebugTypes(), gets the mapped
1141  /// DICompositeType for the given ODR \c Identifier. If none exists, creates
1142  /// a new node.
1143  ///
1144  /// Else, returns \c nullptr.
1145  static DICompositeType *
1146  getODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1147  MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1150  unsigned RuntimeLang, Metadata *VTableHolder,
1153  Metadata *Rank);
1155  MDString &Identifier);
1156 
1157  /// Build a DICompositeType with the given ODR identifier.
1158  ///
1159  /// Looks up the mapped DICompositeType for the given ODR \c Identifier. If
1160  /// it doesn't exist, creates a new one. If it does exist and \a
1161  /// isForwardDecl(), and the new arguments would be a definition, mutates the
1162  /// the type in place. In either case, returns the type.
1163  ///
1164  /// If not \a LLVMContext::isODRUniquingDebugTypes(), this function returns
1165  /// nullptr.
1166  static DICompositeType *
1168  MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1171  unsigned RuntimeLang, Metadata *VTableHolder,
1175 
1176  DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); }
1177  DINodeArray getElements() const {
1178  return cast_or_null<MDTuple>(getRawElements());
1179  }
1181  return cast_or_null<DIType>(getRawVTableHolder());
1182  }
1183  DITemplateParameterArray getTemplateParams() const {
1184  return cast_or_null<MDTuple>(getRawTemplateParams());
1185  }
1187  unsigned getRuntimeLang() const { return RuntimeLang; }
1188 
1189  Metadata *getRawBaseType() const { return getOperand(3); }
1190  Metadata *getRawElements() const { return getOperand(4); }
1191  Metadata *getRawVTableHolder() const { return getOperand(5); }
1192  Metadata *getRawTemplateParams() const { return getOperand(6); }
1193  MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
1194  Metadata *getRawDiscriminator() const { return getOperand(8); }
1195  DIDerivedType *getDiscriminator() const { return getOperandAs<DIDerivedType>(8); }
1196  Metadata *getRawDataLocation() const { return getOperand(9); }
1198  return dyn_cast_or_null<DIVariable>(getRawDataLocation());
1199  }
1201  return dyn_cast_or_null<DIExpression>(getRawDataLocation());
1202  }
1203  Metadata *getRawAssociated() const { return getOperand(10); }
1205  return dyn_cast_or_null<DIVariable>(getRawAssociated());
1206  }
1208  return dyn_cast_or_null<DIExpression>(getRawAssociated());
1209  }
1210  Metadata *getRawAllocated() const { return getOperand(11); }
1212  return dyn_cast_or_null<DIVariable>(getRawAllocated());
1213  }
1215  return dyn_cast_or_null<DIExpression>(getRawAllocated());
1216  }
1217  Metadata *getRawRank() const { return getOperand(12); }
1219  if (auto *MD = dyn_cast_or_null<ConstantAsMetadata>(getRawRank()))
1220  return dyn_cast_or_null<ConstantInt>(MD->getValue());
1221  return nullptr;
1222  }
1224  return dyn_cast_or_null<DIExpression>(getRawRank());
1225  }
1226 
1227  /// Replace operands.
1228  ///
1229  /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
1230  /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
1231  /// of its movement if necessary.
1232  /// @{
1233  void replaceElements(DINodeArray Elements) {
1234 #ifndef NDEBUG
1235  for (DINode *Op : getElements())
1236  assert(is_contained(Elements->operands(), Op) &&
1237  "Lost a member during member list replacement");
1238 #endif
1240  }
1241 
1244  }
1245 
1246  void replaceTemplateParams(DITemplateParameterArray TemplateParams) {
1248  }
1249  /// @}
1250 
1251  static bool classof(const Metadata *MD) {
1252  return MD->getMetadataID() == DICompositeTypeKind;
1253  }
1254 };
1255 
1256 /// Type array for a subprogram.
1257 ///
1258 /// TODO: Fold the array of types in directly as operands.
1259 class DISubroutineType : public DIType {
1260  friend class LLVMContextImpl;
1261  friend class MDNode;
1262 
1263  /// The calling convention used with DW_AT_calling_convention. Actually of
1264  /// type dwarf::CallingConvention.
1265  uint8_t CC;
1266 
1268  uint8_t CC, ArrayRef<Metadata *> Ops)
1269  : DIType(C, DISubroutineTypeKind, Storage, dwarf::DW_TAG_subroutine_type,
1270  0, 0, 0, 0, Flags, Ops),
1271  CC(CC) {}
1272  ~DISubroutineType() = default;
1273 
1275  uint8_t CC, DITypeRefArray TypeArray,
1277  bool ShouldCreate = true) {
1278  return getImpl(Context, Flags, CC, TypeArray.get(), Storage, ShouldCreate);
1279  }
1280  static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
1281  uint8_t CC, Metadata *TypeArray,
1283  bool ShouldCreate = true);
1284 
1285  TempDISubroutineType cloneImpl() const {
1286  return getTemporary(getContext(), getFlags(), getCC(), getTypeArray());
1287  }
1288 
1289 public:
1290  DEFINE_MDNODE_GET(DISubroutineType,
1291  (DIFlags Flags, uint8_t CC, DITypeRefArray TypeArray),
1292  (Flags, CC, TypeArray))
1293  DEFINE_MDNODE_GET(DISubroutineType,
1294  (DIFlags Flags, uint8_t CC, Metadata *TypeArray),
1296 
1297  TempDISubroutineType clone() const { return cloneImpl(); }
1298 
1299  uint8_t getCC() const { return CC; }
1300 
1302  return cast_or_null<MDTuple>(getRawTypeArray());
1303  }
1304 
1305  Metadata *getRawTypeArray() const { return getOperand(3); }
1306 
1307  static bool classof(const Metadata *MD) {
1308  return MD->getMetadataID() == DISubroutineTypeKind;
1309  }
1310 };
1311 
1312 /// Compile unit.
1313 class DICompileUnit : public DIScope {
1314  friend class LLVMContextImpl;
1315  friend class MDNode;
1316 
1317 public:
1318  enum DebugEmissionKind : unsigned {
1319  NoDebug = 0,
1324  };
1325 
1326  enum class DebugNameTableKind : unsigned {
1327  Default = 0,
1328  GNU = 1,
1329  None = 2,
1331  };
1332 
1334  static const char *emissionKindString(DebugEmissionKind EK);
1336  static const char *nameTableKindString(DebugNameTableKind PK);
1337 
1338 private:
1339  unsigned SourceLanguage;
1340  bool IsOptimized;
1341  unsigned RuntimeVersion;
1342  unsigned EmissionKind;
1343  uint64_t DWOId;
1344  bool SplitDebugInlining;
1345  bool DebugInfoForProfiling;
1346  unsigned NameTableKind;
1347  bool RangesBaseAddress;
1348 
1349  DICompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
1350  bool IsOptimized, unsigned RuntimeVersion,
1351  unsigned EmissionKind, uint64_t DWOId, bool SplitDebugInlining,
1352  bool DebugInfoForProfiling, unsigned NameTableKind,
1353  bool RangesBaseAddress, ArrayRef<Metadata *> Ops)
1354  : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
1355  SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
1356  RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind),
1357  DWOId(DWOId), SplitDebugInlining(SplitDebugInlining),
1358  DebugInfoForProfiling(DebugInfoForProfiling),
1359  NameTableKind(NameTableKind), RangesBaseAddress(RangesBaseAddress) {
1360  assert(Storage != Uniqued);
1361  }
1362  ~DICompileUnit() = default;
1363 
1364  static DICompileUnit *
1365  getImpl(LLVMContext &Context, unsigned SourceLanguage, DIFile *File,
1366  StringRef Producer, bool IsOptimized, StringRef Flags,
1367  unsigned RuntimeVersion, StringRef SplitDebugFilename,
1368  unsigned EmissionKind, DICompositeTypeArray EnumTypes,
1369  DIScopeArray RetainedTypes,
1370  DIGlobalVariableExpressionArray GlobalVariables,
1371  DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
1372  uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
1373  unsigned NameTableKind, bool RangesBaseAddress, StringRef SysRoot,
1374  StringRef SDK, StorageType Storage, bool ShouldCreate = true) {
1375  return getImpl(
1376  Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
1377  IsOptimized, getCanonicalMDString(Context, Flags), RuntimeVersion,
1378  getCanonicalMDString(Context, SplitDebugFilename), EmissionKind,
1379  EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
1380  ImportedEntities.get(), Macros.get(), DWOId, SplitDebugInlining,
1381  DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
1382  getCanonicalMDString(Context, SysRoot),
1383  getCanonicalMDString(Context, SDK), Storage, ShouldCreate);
1384  }
1385  static DICompileUnit *
1386  getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
1387  MDString *Producer, bool IsOptimized, MDString *Flags,
1388  unsigned RuntimeVersion, MDString *SplitDebugFilename,
1389  unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
1391  Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining,
1392  bool DebugInfoForProfiling, unsigned NameTableKind,
1393  bool RangesBaseAddress, MDString *SysRoot, MDString *SDK,
1394  StorageType Storage, bool ShouldCreate = true);
1395 
1396  TempDICompileUnit cloneImpl() const {
1397  return getTemporary(
1404  }
1405 
1406 public:
1407  static void get() = delete;
1408  static void getIfExists() = delete;
1409 
1411  DICompileUnit,
1412  (unsigned SourceLanguage, DIFile *File, StringRef Producer,
1413  bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
1414  StringRef SplitDebugFilename, DebugEmissionKind EmissionKind,
1415  DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes,
1416  DIGlobalVariableExpressionArray GlobalVariables,
1417  DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
1418  uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
1419  DebugNameTableKind NameTableKind, bool RangesBaseAddress,
1420  StringRef SysRoot, StringRef SDK),
1421  (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
1422  SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
1423  GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
1424  DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress,
1425  SysRoot, SDK))
1427  DICompileUnit,
1428  (unsigned SourceLanguage, Metadata *File, MDString *Producer,
1429  bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
1430  MDString *SplitDebugFilename, unsigned EmissionKind, Metadata *EnumTypes,
1433  bool SplitDebugInlining, bool DebugInfoForProfiling,
1434  unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
1436  (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
1438  GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
1439  DebugInfoForProfiling, NameTableKind, RangesBaseAddress, SysRoot, SDK))
1440 
1441  TempDICompileUnit clone() const { return cloneImpl(); }
1442 
1443  unsigned getSourceLanguage() const { return SourceLanguage; }
1444  bool isOptimized() const { return IsOptimized; }
1445  unsigned getRuntimeVersion() const { return RuntimeVersion; }
1447  return (DebugEmissionKind)EmissionKind;
1448  }
1449  bool isDebugDirectivesOnly() const {
1450  return EmissionKind == DebugDirectivesOnly;
1451  }
1452  bool getDebugInfoForProfiling() const { return DebugInfoForProfiling; }
1454  return (DebugNameTableKind)NameTableKind;
1455  }
1456  bool getRangesBaseAddress() const { return RangesBaseAddress; }
1457  StringRef getProducer() const { return getStringOperand(1); }
1458  StringRef getFlags() const { return getStringOperand(2); }
1460  DICompositeTypeArray getEnumTypes() const {
1461  return cast_or_null<MDTuple>(getRawEnumTypes());
1462  }
1463  DIScopeArray getRetainedTypes() const {
1464  return cast_or_null<MDTuple>(getRawRetainedTypes());
1465  }
1466  DIGlobalVariableExpressionArray getGlobalVariables() const {
1467  return cast_or_null<MDTuple>(getRawGlobalVariables());
1468  }
1469  DIImportedEntityArray getImportedEntities() const {
1470  return cast_or_null<MDTuple>(getRawImportedEntities());
1471  }
1472  DIMacroNodeArray getMacros() const {
1473  return cast_or_null<MDTuple>(getRawMacros());
1474  }
1475  uint64_t getDWOId() const { return DWOId; }
1476  void setDWOId(uint64_t DwoId) { DWOId = DwoId; }
1477  bool getSplitDebugInlining() const { return SplitDebugInlining; }
1478  void setSplitDebugInlining(bool SplitDebugInlining) {
1479  this->SplitDebugInlining = SplitDebugInlining;
1480  }
1481  StringRef getSysRoot() const { return getStringOperand(9); }
1482  StringRef getSDK() const { return getStringOperand(10); }
1483 
1484  MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
1485  MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
1487  return getOperandAs<MDString>(3);
1488  }
1489  Metadata *getRawEnumTypes() const { return getOperand(4); }
1490  Metadata *getRawRetainedTypes() const { return getOperand(5); }
1493  Metadata *getRawMacros() const { return getOperand(8); }
1494  MDString *getRawSysRoot() const { return getOperandAs<MDString>(9); }
1495  MDString *getRawSDK() const { return getOperandAs<MDString>(10); }
1496 
1497  /// Replace arrays.
1498  ///
1499  /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
1500  /// deleted on a uniquing collision. In practice, uniquing collisions on \a
1501  /// DICompileUnit should be fairly rare.
1502  /// @{
1503  void replaceEnumTypes(DICompositeTypeArray N) {
1504  replaceOperandWith(4, N.get());
1505  }
1506  void replaceRetainedTypes(DITypeArray N) {
1507  replaceOperandWith(5, N.get());
1508  }
1509  void replaceGlobalVariables(DIGlobalVariableExpressionArray N) {
1510  replaceOperandWith(6, N.get());
1511  }
1512  void replaceImportedEntities(DIImportedEntityArray N) {
1513  replaceOperandWith(7, N.get());
1514  }
1515  void replaceMacros(DIMacroNodeArray N) { replaceOperandWith(8, N.get()); }
1516  /// @}
1517 
1518  static bool classof(const Metadata *MD) {
1519  return MD->getMetadataID() == DICompileUnitKind;
1520  }
1521 };
1522 
1523 /// A scope for locals.
1524 ///
1525 /// A legal scope for lexical blocks, local variables, and debug info
1526 /// locations. Subclasses are \a DISubprogram, \a DILexicalBlock, and \a
1527 /// DILexicalBlockFile.
1528 class DILocalScope : public DIScope {
1529 protected:
1530  DILocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1532  : DIScope(C, ID, Storage, Tag, Ops) {}
1533  ~DILocalScope() = default;
1534 
1535 public:
1536  /// Get the subprogram for this scope.
1537  ///
1538  /// Return this if it's an \a DISubprogram; otherwise, look up the scope
1539  /// chain.
1540  DISubprogram *getSubprogram() const;
1541 
1542  /// Get the first non DILexicalBlockFile scope of this scope.
1543  ///
1544  /// Return this if it's not a \a DILexicalBlockFIle; otherwise, look up the
1545  /// scope chain.
1547 
1548  static bool classof(const Metadata *MD) {
1549  return MD->getMetadataID() == DISubprogramKind ||
1550  MD->getMetadataID() == DILexicalBlockKind ||
1551  MD->getMetadataID() == DILexicalBlockFileKind;
1552  }
1553 };
1554 
1555 /// Debug location.
1556 ///
1557 /// A debug location in source code, used for debug info and otherwise.
1558 class DILocation : public MDNode {
1559  friend class LLVMContextImpl;
1560  friend class MDNode;
1561 
1563  unsigned Column, ArrayRef<Metadata *> MDs, bool ImplicitCode);
1564  ~DILocation() { dropAllReferences(); }
1565 
1566  static DILocation *getImpl(LLVMContext &Context, unsigned Line,
1567  unsigned Column, Metadata *Scope,
1569  StorageType Storage, bool ShouldCreate = true);
1570  static DILocation *getImpl(LLVMContext &Context, unsigned Line,
1571  unsigned Column, DILocalScope *Scope,
1573  StorageType Storage, bool ShouldCreate = true) {
1574  return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
1575  static_cast<Metadata *>(InlinedAt), ImplicitCode, Storage,
1576  ShouldCreate);
1577  }
1578 
1579  /// With a given unsigned int \p U, use up to 13 bits to represent it.
1580  /// old_bit 1~5 --> new_bit 1~5
1581  /// old_bit 6~12 --> new_bit 7~13
1582  /// new_bit_6 is 0 if higher bits (7~13) are all 0
1583  static unsigned getPrefixEncodingFromUnsigned(unsigned U) {
1584  U &= 0xfff;
1585  return U > 0x1f ? (((U & 0xfe0) << 1) | (U & 0x1f) | 0x20) : U;
1586  }
1587 
1588  /// Reverse transformation as getPrefixEncodingFromUnsigned.
1589  static unsigned getUnsignedFromPrefixEncoding(unsigned U) {
1590  if (U & 1)
1591  return 0;
1592  U >>= 1;
1593  return (U & 0x20) ? (((U >> 1) & 0xfe0) | (U & 0x1f)) : (U & 0x1f);
1594  }
1595 
1596  /// Returns the next component stored in discriminator.
1597  static unsigned getNextComponentInDiscriminator(unsigned D) {
1598  if ((D & 1) == 0)
1599  return D >> ((D & 0x40) ? 14 : 7);
1600  else
1601  return D >> 1;
1602  }
1603 
1604  TempDILocation cloneImpl() const {
1605  // Get the raw scope/inlinedAt since it is possible to invoke this on
1606  // a DILocation containing temporary metadata.
1607  return getTemporary(getContext(), getLine(), getColumn(), getRawScope(),
1608  getRawInlinedAt(), isImplicitCode());
1609  }
1610 
1611  static unsigned encodeComponent(unsigned C) {
1612  return (C == 0) ? 1U : (getPrefixEncodingFromUnsigned(C) << 1);
1613  }
1614 
1615  static unsigned encodingBits(unsigned C) {
1616  return (C == 0) ? 1 : (C > 0x1f ? 14 : 7);
1617  }
1618 
1619 public:
1620  // Disallow replacing operands.
1621  void replaceOperandWith(unsigned I, Metadata *New) = delete;
1622 
1623  DEFINE_MDNODE_GET(DILocation,
1624  (unsigned Line, unsigned Column, Metadata *Scope,
1625  Metadata *InlinedAt = nullptr, bool ImplicitCode = false),
1627  DEFINE_MDNODE_GET(DILocation,
1628  (unsigned Line, unsigned Column, DILocalScope *Scope,
1629  DILocation *InlinedAt = nullptr,
1630  bool ImplicitCode = false),
1632 
1633  /// Return a (temporary) clone of this.
1634  TempDILocation clone() const { return cloneImpl(); }
1635 
1636  unsigned getLine() const { return SubclassData32; }
1637  unsigned getColumn() const { return SubclassData16; }
1638  DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
1639 
1640  DILocation *getInlinedAt() const {
1641  return cast_or_null<DILocation>(getRawInlinedAt());
1642  }
1643 
1644  /// Check if the location corresponds to an implicit code.
1645  /// When the ImplicitCode flag is true, it means that the Instruction
1646  /// with this DILocation has been added by the front-end but it hasn't been
1647  /// written explicitly by the user (e.g. cleanup stuff in C++ put on a closing
1648  /// bracket). It's useful for code coverage to not show a counter on "empty"
1649  /// lines.
1650  bool isImplicitCode() const { return SubclassData1; }
1651  void setImplicitCode(bool ImplicitCode) { SubclassData1 = ImplicitCode; }
1652 
1653  DIFile *getFile() const { return getScope()->getFile(); }
1654  StringRef getFilename() const { return getScope()->getFilename(); }
1655  StringRef getDirectory() const { return getScope()->getDirectory(); }
1656  Optional<StringRef> getSource() const { return getScope()->getSource(); }
1657 
1658  /// Get the scope where this is inlined.
1659  ///
1660  /// Walk through \a getInlinedAt() and return \a getScope() from the deepest
1661  /// location.
1662  DILocalScope *getInlinedAtScope() const {
1663  if (auto *IA = getInlinedAt())
1664  return IA->getInlinedAtScope();
1665  return getScope();
1666  }
1667 
1668  /// Get the DWARF discriminator.
1669  ///
1670  /// DWARF discriminators distinguish identical file locations between
1671  /// instructions that are on different basic blocks.
1672  ///
1673  /// There are 3 components stored in discriminator, from lower bits:
1674  ///
1675  /// Base discriminator: assigned by AddDiscriminators pass to identify IRs
1676  /// that are defined by the same source line, but
1677  /// different basic blocks.
1678  /// Duplication factor: assigned by optimizations that will scale down
1679  /// the execution frequency of the original IR.
1680  /// Copy Identifier: assigned by optimizations that clones the IR.
1681  /// Each copy of the IR will be assigned an identifier.
1682  ///
1683  /// Encoding:
1684  ///
1685  /// The above 3 components are encoded into a 32bit unsigned integer in
1686  /// order. If the lowest bit is 1, the current component is empty, and the
1687  /// next component will start in the next bit. Otherwise, the current
1688  /// component is non-empty, and its content starts in the next bit. The
1689  /// value of each components is either 5 bit or 12 bit: if the 7th bit
1690  /// is 0, the bit 2~6 (5 bits) are used to represent the component; if the
1691  /// 7th bit is 1, the bit 2~6 (5 bits) and 8~14 (7 bits) are combined to
1692  /// represent the component. Thus, the number of bits used for a component
1693  /// is either 0 (if it and all the next components are empty); 1 - if it is
1694  /// empty; 7 - if its value is up to and including 0x1f (lsb and msb are both
1695  /// 0); or 14, if its value is up to and including 0x1ff. Note that the last
1696  /// component is also capped at 0x1ff, even in the case when both first
1697  /// components are 0, and we'd technically have 29 bits available.
1698  ///
1699  /// For precise control over the data being encoded in the discriminator,
1700  /// use encodeDiscriminator/decodeDiscriminator.
1701 
1702  inline unsigned getDiscriminator() const;
1703 
1704  // For the regular discriminator, it stands for all empty components if all
1705  // the lowest 3 bits are non-zero and all higher 29 bits are unused(zero by
1706  // default). Here we fully leverage the higher 29 bits for pseudo probe use.
1707  // This is the format:
1708  // [2:0] - 0x7
1709  // [31:3] - pseudo probe fields guaranteed to be non-zero as a whole
1710  // So if the lower 3 bits is non-zero and the others has at least one
1711  // non-zero bit, it guarantees to be a pseudo probe discriminator
1712  inline static bool isPseudoProbeDiscriminator(unsigned Discriminator) {
1713  return ((Discriminator & 0x7) == 0x7) && (Discriminator & 0xFFFFFFF8);
1714  }
1715 
1716  /// Returns a new DILocation with updated \p Discriminator.
1717  inline const DILocation *cloneWithDiscriminator(unsigned Discriminator) const;
1718 
1719  /// Returns a new DILocation with updated base discriminator \p BD. Only the
1720  /// base discriminator is set in the new DILocation, the other encoded values
1721  /// are elided.
1722  /// If the discriminator cannot be encoded, the function returns None.
1723  inline Optional<const DILocation *> cloneWithBaseDiscriminator(unsigned BD) const;
1724 
1725  /// Returns the duplication factor stored in the discriminator, or 1 if no
1726  /// duplication factor (or 0) is encoded.
1727  inline unsigned getDuplicationFactor() const;
1728 
1729  /// Returns the copy identifier stored in the discriminator.
1730  inline unsigned getCopyIdentifier() const;
1731 
1732  /// Returns the base discriminator stored in the discriminator.
1733  inline unsigned getBaseDiscriminator() const;
1734 
1735  /// Returns a new DILocation with duplication factor \p DF * current
1736  /// duplication factor encoded in the discriminator. The current duplication
1737  /// factor is as defined by getDuplicationFactor().
1738  /// Returns None if encoding failed.
1740 
1741  /// When two instructions are combined into a single instruction we also
1742  /// need to combine the original locations into a single location.
1743  ///
1744  /// When the locations are the same we can use either location. When they
1745  /// differ, we need a third location which is distinct from either. If they
1746  /// have the same file/line but have a different discriminator we could
1747  /// create a location with a new discriminator. If they are from different
1748  /// files/lines the location is ambiguous and can't be represented in a line
1749  /// entry. In this case, if \p GenerateLocation is true, we will set the
1750  /// merged debug location as line 0 of the nearest common scope where the two
1751  /// locations are inlined from.
1752  ///
1753  /// \p GenerateLocation: Whether the merged location can be generated when
1754  /// \p LocA and \p LocB differ.
1755  static const DILocation *getMergedLocation(const DILocation *LocA,
1756  const DILocation *LocB);
1757 
1758  /// Try to combine the vector of locations passed as input in a single one.
1759  /// This function applies getMergedLocation() repeatedly left-to-right.
1760  ///
1761  /// \p Locs: The locations to be merged.
1762  static
1764 
1765  /// Returns the base discriminator for a given encoded discriminator \p D.
1766  static unsigned getBaseDiscriminatorFromDiscriminator(unsigned D) {
1767  return getUnsignedFromPrefixEncoding(D);
1768  }
1769 
1770  /// Raw encoding of the discriminator. APIs such as cloneWithDuplicationFactor
1771  /// have certain special case behavior (e.g. treating empty duplication factor
1772  /// as the value '1').
1773  /// This API, in conjunction with cloneWithDiscriminator, may be used to encode
1774  /// the raw values provided. \p BD: base discriminator \p DF: duplication factor
1775  /// \p CI: copy index
1776  /// The return is None if the values cannot be encoded in 32 bits - for
1777  /// example, values for BD or DF larger than 12 bits. Otherwise, the return
1778  /// is the encoded value.
1779  static Optional<unsigned> encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI);
1780 
1781  /// Raw decoder for values in an encoded discriminator D.
1782  static void decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF,
1783  unsigned &CI);
1784 
1785  /// Returns the duplication factor for a given encoded discriminator \p D, or
1786  /// 1 if no value or 0 is encoded.
1787  static unsigned getDuplicationFactorFromDiscriminator(unsigned D) {
1788  D = getNextComponentInDiscriminator(D);
1789  unsigned Ret = getUnsignedFromPrefixEncoding(D);
1790  if (Ret == 0)
1791  return 1;
1792  return Ret;
1793  }
1794 
1795  /// Returns the copy identifier for a given encoded discriminator \p D.
1796  static unsigned getCopyIdentifierFromDiscriminator(unsigned D) {
1797  return getUnsignedFromPrefixEncoding(getNextComponentInDiscriminator(
1798  getNextComponentInDiscriminator(D)));
1799  }
1800 
1801 
1802  Metadata *getRawScope() const { return getOperand(0); }
1804  if (getNumOperands() == 2)
1805  return getOperand(1);
1806  return nullptr;
1807  }
1808 
1809  static bool classof(const Metadata *MD) {
1810  return MD->getMetadataID() == DILocationKind;
1811  }
1812 };
1813 
1814 /// Subprogram description.
1815 class DISubprogram : public DILocalScope {
1816  friend class LLVMContextImpl;
1817  friend class MDNode;
1818 
1819  unsigned Line;
1820  unsigned ScopeLine;
1821  unsigned VirtualIndex;
1822 
1823  /// In the MS ABI, the implicit 'this' parameter is adjusted in the prologue
1824  /// of method overrides from secondary bases by this amount. It may be
1825  /// negative.
1826  int ThisAdjustment;
1827 
1828 public:
1829  /// Debug info subprogram flags.
1831 #define HANDLE_DISP_FLAG(ID, NAME) SPFlag##NAME = ID,
1832 #define DISP_FLAG_LARGEST_NEEDED
1833 #include "llvm/IR/DebugInfoFlags.def"
1834  SPFlagNonvirtual = SPFlagZero,
1835  SPFlagVirtuality = SPFlagVirtual | SPFlagPureVirtual,
1836  LLVM_MARK_AS_BITMASK_ENUM(SPFlagLargest)
1837  };
1838 
1839  static DISPFlags getFlag(StringRef Flag);
1841 
1842  /// Split up a flags bitfield for easier printing.
1843  ///
1844  /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
1845  /// any remaining (unrecognized) bits.
1846  static DISPFlags splitFlags(DISPFlags Flags,
1847  SmallVectorImpl<DISPFlags> &SplitFlags);
1848 
1849  // Helper for converting old bitfields to new flags word.
1850  static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition,
1851  bool IsOptimized,
1852  unsigned Virtuality = SPFlagNonvirtual,
1853  bool IsMainSubprogram = false) {
1854  // We're assuming virtuality is the low-order field.
1855  static_assert(
1856  int(SPFlagVirtual) == int(dwarf::DW_VIRTUALITY_virtual) &&
1857  int(SPFlagPureVirtual) == int(dwarf::DW_VIRTUALITY_pure_virtual),
1858  "Virtuality constant mismatch");
1859  return static_cast<DISPFlags>(
1860  (Virtuality & SPFlagVirtuality) |
1861  (IsLocalToUnit ? SPFlagLocalToUnit : SPFlagZero) |
1862  (IsDefinition ? SPFlagDefinition : SPFlagZero) |
1863  (IsOptimized ? SPFlagOptimized : SPFlagZero) |
1864  (IsMainSubprogram ? SPFlagMainSubprogram : SPFlagZero));
1865  }
1866 
1867 private:
1868  DIFlags Flags;
1869  DISPFlags SPFlags;
1870 
1871  DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1872  unsigned ScopeLine, unsigned VirtualIndex, int ThisAdjustment,
1873  DIFlags Flags, DISPFlags SPFlags, ArrayRef<Metadata *> Ops)
1874  : DILocalScope(C, DISubprogramKind, Storage, dwarf::DW_TAG_subprogram,
1875  Ops),
1876  Line(Line), ScopeLine(ScopeLine), VirtualIndex(VirtualIndex),
1877  ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags) {
1878  static_assert(dwarf::DW_VIRTUALITY_max < 4, "Virtuality out of range");
1879  }
1880  ~DISubprogram() = default;
1881 
1882  static DISubprogram *
1883  getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
1884  StringRef LinkageName, DIFile *File, unsigned Line,
1885  DISubroutineType *Type, unsigned ScopeLine, DIType *ContainingType,
1886  unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags,
1887  DISPFlags SPFlags, DICompileUnit *Unit,
1888  DITemplateParameterArray TemplateParams, DISubprogram *Declaration,
1889  DINodeArray RetainedNodes, DITypeArray ThrownTypes,
1890  StorageType Storage, bool ShouldCreate = true) {
1893  ScopeLine, ContainingType, VirtualIndex, ThisAdjustment,
1894  Flags, SPFlags, Unit, TemplateParams.get(), Declaration,
1895  RetainedNodes.get(), ThrownTypes.get(), Storage,
1896  ShouldCreate);
1897  }
1898  static DISubprogram *getImpl(LLVMContext &Context, Metadata *Scope,
1899  MDString *Name, MDString *LinkageName,
1900  Metadata *File, unsigned Line, Metadata *Type,
1901  unsigned ScopeLine, Metadata *ContainingType,
1902  unsigned VirtualIndex, int ThisAdjustment,
1903  DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
1906  StorageType Storage, bool ShouldCreate = true);
1907 
1908  TempDISubprogram cloneImpl() const {
1910  getFile(), getLine(), getType(), getScopeLine(),
1911  getContainingType(), getVirtualIndex(),
1912  getThisAdjustment(), getFlags(), getSPFlags(),
1913  getUnit(), getTemplateParams(), getDeclaration(),
1914  getRetainedNodes(), getThrownTypes());
1915  }
1916 
1917 public:
1919  DISubprogram,
1920  (DIScope * Scope, StringRef Name, StringRef LinkageName, DIFile *File,
1921  unsigned Line, DISubroutineType *Type, unsigned ScopeLine,
1922  DIType *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
1923  DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit,
1924  DITemplateParameterArray TemplateParams = nullptr,
1925  DISubprogram *Declaration = nullptr, DINodeArray RetainedNodes = nullptr,
1926  DITypeArray ThrownTypes = nullptr),
1927  (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
1928  VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
1930 
1932  DISubprogram,
1934  unsigned Line, Metadata *Type, unsigned ScopeLine,
1935  Metadata *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
1936  DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
1938  Metadata *RetainedNodes = nullptr, Metadata *ThrownTypes = nullptr),
1939  (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
1940  VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
1942 
1943  TempDISubprogram clone() const { return cloneImpl(); }
1944 
1945  /// Returns a new temporary DISubprogram with updated Flags
1946  TempDISubprogram cloneWithFlags(DIFlags NewFlags) const {
1947  auto NewSP = clone();
1948  NewSP->Flags = NewFlags;
1949  return NewSP;
1950  }
1951 
1952 public:
1953  unsigned getLine() const { return Line; }
1954  unsigned getVirtuality() const { return getSPFlags() & SPFlagVirtuality; }
1955  unsigned getVirtualIndex() const { return VirtualIndex; }
1956  int getThisAdjustment() const { return ThisAdjustment; }
1957  unsigned getScopeLine() const { return ScopeLine; }
1958  void setScopeLine(unsigned L) { assert(isDistinct()); ScopeLine = L; }
1959  DIFlags getFlags() const { return Flags; }
1960  DISPFlags getSPFlags() const { return SPFlags; }
1961  bool isLocalToUnit() const { return getSPFlags() & SPFlagLocalToUnit; }
1962  bool isDefinition() const { return getSPFlags() & SPFlagDefinition; }
1963  bool isOptimized() const { return getSPFlags() & SPFlagOptimized; }
1964  bool isMainSubprogram() const { return getSPFlags() & SPFlagMainSubprogram; }
1965 
1966  bool isArtificial() const { return getFlags() & FlagArtificial; }
1967  bool isPrivate() const {
1968  return (getFlags() & FlagAccessibility) == FlagPrivate;
1969  }
1970  bool isProtected() const {
1971  return (getFlags() & FlagAccessibility) == FlagProtected;
1972  }
1973  bool isPublic() const {
1974  return (getFlags() & FlagAccessibility) == FlagPublic;
1975  }
1976  bool isExplicit() const { return getFlags() & FlagExplicit; }
1977  bool isPrototyped() const { return getFlags() & FlagPrototyped; }
1978  bool areAllCallsDescribed() const {
1979  return getFlags() & FlagAllCallsDescribed;
1980  }
1981  bool isPure() const { return getSPFlags() & SPFlagPure; }
1982  bool isElemental() const { return getSPFlags() & SPFlagElemental; }
1983  bool isRecursive() const { return getSPFlags() & SPFlagRecursive; }
1984  bool isObjCDirect() const { return getSPFlags() & SPFlagObjCDirect; }
1985 
1986  /// Check if this is deleted member function.
1987  ///
1988  /// Return true if this subprogram is a C++11 special
1989  /// member function declared deleted.
1990  bool isDeleted() const { return getSPFlags() & SPFlagDeleted; }
1991 
1992  /// Check if this is reference-qualified.
1993  ///
1994  /// Return true if this subprogram is a C++11 reference-qualified non-static
1995  /// member function (void foo() &).
1996  bool isLValueReference() const { return getFlags() & FlagLValueReference; }
1997 
1998  /// Check if this is rvalue-reference-qualified.
1999  ///
2000  /// Return true if this subprogram is a C++11 rvalue-reference-qualified
2001  /// non-static member function (void foo() &&).
2002  bool isRValueReference() const { return getFlags() & FlagRValueReference; }
2003 
2004  /// Check if this is marked as noreturn.
2005  ///
2006  /// Return true if this subprogram is C++11 noreturn or C11 _Noreturn
2007  bool isNoReturn() const { return getFlags() & FlagNoReturn; }
2008 
2009  // Check if this routine is a compiler-generated thunk.
2010  //
2011  // Returns true if this subprogram is a thunk generated by the compiler.
2012  bool isThunk() const { return getFlags() & FlagThunk; }
2013 
2014  DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2015 
2016  StringRef getName() const { return getStringOperand(2); }
2017  StringRef getLinkageName() const { return getStringOperand(3); }
2018  /// Only used by clients of CloneFunction, and only right after the cloning.
2019  void replaceLinkageName(MDString *LN) { replaceOperandWith(3, LN); }
2020 
2021  DISubroutineType *getType() const {
2022  return cast_or_null<DISubroutineType>(getRawType());
2023  }
2024  DIType *getContainingType() const {
2025  return cast_or_null<DIType>(getRawContainingType());
2026  }
2027 
2028  DICompileUnit *getUnit() const {
2029  return cast_or_null<DICompileUnit>(getRawUnit());
2030  }
2031  void replaceUnit(DICompileUnit *CU) { replaceOperandWith(5, CU); }
2032  DITemplateParameterArray getTemplateParams() const {
2033  return cast_or_null<MDTuple>(getRawTemplateParams());
2034  }
2035  DISubprogram *getDeclaration() const {
2036  return cast_or_null<DISubprogram>(getRawDeclaration());
2037  }
2038  DINodeArray getRetainedNodes() const {
2039  return cast_or_null<MDTuple>(getRawRetainedNodes());
2040  }
2041  DITypeArray getThrownTypes() const {
2042  return cast_or_null<MDTuple>(getRawThrownTypes());
2043  }
2044 
2045  Metadata *getRawScope() const { return getOperand(1); }
2046  MDString *getRawName() const { return getOperandAs<MDString>(2); }
2047  MDString *getRawLinkageName() const { return getOperandAs<MDString>(3); }
2048  Metadata *getRawType() const { return getOperand(4); }
2049  Metadata *getRawUnit() const { return getOperand(5); }
2050  Metadata *getRawDeclaration() const { return getOperand(6); }
2051  Metadata *getRawRetainedNodes() const { return getOperand(7); }
2052  Metadata *getRawContainingType() const {
2053  return getNumOperands() > 8 ? getOperandAs<Metadata>(8) : nullptr;
2054  }
2055  Metadata *getRawTemplateParams() const {
2056  return getNumOperands() > 9 ? getOperandAs<Metadata>(9) : nullptr;
2057  }
2058  Metadata *getRawThrownTypes() const {
2059  return getNumOperands() > 10 ? getOperandAs<Metadata>(10) : nullptr;
2060  }
2061 
2062  void replaceRawLinkageName(MDString *LinkageName) {
2064  }
2065 
2066  /// Check if this subprogram describes the given function.
2067  ///
2068  /// FIXME: Should this be looking through bitcasts?
2069  bool describes(const Function *F) const;
2070 
2071  static bool classof(const Metadata *MD) {
2072  return MD->getMetadataID() == DISubprogramKind;
2073  }
2074 };
2075 
2077 protected:
2080  : DILocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
2081  ~DILexicalBlockBase() = default;
2082 
2083 public:
2084  DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
2085 
2086  Metadata *getRawScope() const { return getOperand(1); }
2087 
2088  static bool classof(const Metadata *MD) {
2089  return MD->getMetadataID() == DILexicalBlockKind ||
2090  MD->getMetadataID() == DILexicalBlockFileKind;
2091  }
2092 };
2093 
2095  friend class LLVMContextImpl;
2096  friend class MDNode;
2097 
2098  unsigned Line;
2099  uint16_t Column;
2100 
2101  DILexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
2102  unsigned Column, ArrayRef<Metadata *> Ops)
2103  : DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops), Line(Line),
2104  Column(Column) {
2105  assert(Column < (1u << 16) && "Expected 16-bit column");
2106  }
2107  ~DILexicalBlock() = default;
2108 
2110  DIFile *File, unsigned Line, unsigned Column,
2112  bool ShouldCreate = true) {
2113  return getImpl(Context, static_cast<Metadata *>(Scope),
2114  static_cast<Metadata *>(File), Line, Column, Storage,
2115  ShouldCreate);
2116  }
2117 
2118  static DILexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
2119  Metadata *File, unsigned Line, unsigned Column,
2120  StorageType Storage, bool ShouldCreate = true);
2121 
2122  TempDILexicalBlock cloneImpl() const {
2123  return getTemporary(getContext(), getScope(), getFile(), getLine(),
2124  getColumn());
2125  }
2126 
2127 public:
2128  DEFINE_MDNODE_GET(DILexicalBlock, (DILocalScope * Scope, DIFile *File,
2129  unsigned Line, unsigned Column),
2130  (Scope, File, Line, Column))
2132  unsigned Line, unsigned Column),
2133  (Scope, File, Line, Column))
2134 
2135  TempDILexicalBlock clone() const { return cloneImpl(); }
2136 
2137  unsigned getLine() const { return Line; }
2138  unsigned getColumn() const { return Column; }
2139 
2140  static bool classof(const Metadata *MD) {
2141  return MD->getMetadataID() == DILexicalBlockKind;
2142  }
2143 };
2144 
2146  friend class LLVMContextImpl;
2147  friend class MDNode;
2148 
2149  unsigned Discriminator;
2150 
2152  unsigned Discriminator, ArrayRef<Metadata *> Ops)
2153  : DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops),
2154  Discriminator(Discriminator) {}
2155  ~DILexicalBlockFile() = default;
2156 
2158  DIFile *File, unsigned Discriminator,
2160  bool ShouldCreate = true) {
2161  return getImpl(Context, static_cast<Metadata *>(Scope),
2162  static_cast<Metadata *>(File), Discriminator, Storage,
2163  ShouldCreate);
2164  }
2165 
2166  static DILexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
2167  Metadata *File, unsigned Discriminator,
2169  bool ShouldCreate = true);
2170 
2171  TempDILexicalBlockFile cloneImpl() const {
2172  return getTemporary(getContext(), getScope(), getFile(),
2173  getDiscriminator());
2174  }
2175 
2176 public:
2177  DEFINE_MDNODE_GET(DILexicalBlockFile, (DILocalScope * Scope, DIFile *File,
2178  unsigned Discriminator),
2179  (Scope, File, Discriminator))
2180  DEFINE_MDNODE_GET(DILexicalBlockFile,
2181  (Metadata * Scope, Metadata *File, unsigned Discriminator),
2182  (Scope, File, Discriminator))
2183 
2184  TempDILexicalBlockFile clone() const { return cloneImpl(); }
2185  unsigned getDiscriminator() const { return Discriminator; }
2186 
2187  static bool classof(const Metadata *MD) {
2188  return MD->getMetadataID() == DILexicalBlockFileKind;
2189  }
2190 };
2191 
2192 unsigned DILocation::getDiscriminator() const {
2193  if (auto *F = dyn_cast<DILexicalBlockFile>(getScope()))
2194  return F->getDiscriminator();
2195  return 0;
2196 }
2197 
2198 const DILocation *
2199 DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
2200  DIScope *Scope = getScope();
2201  // Skip all parent DILexicalBlockFile that already have a discriminator
2202  // assigned. We do not want to have nested DILexicalBlockFiles that have
2203  // mutliple discriminators because only the leaf DILexicalBlockFile's
2204  // dominator will be used.
2205  for (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope);
2206  LBF && LBF->getDiscriminator() != 0;
2207  LBF = dyn_cast<DILexicalBlockFile>(Scope))
2208  Scope = LBF->getScope();
2209  DILexicalBlockFile *NewScope =
2210  DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator);
2211  return DILocation::get(getContext(), getLine(), getColumn(), NewScope,
2212  getInlinedAt());
2213 }
2214 
2216  return getBaseDiscriminatorFromDiscriminator(getDiscriminator());
2217 }
2218 
2220  return getDuplicationFactorFromDiscriminator(getDiscriminator());
2221 }
2222 
2224  return getCopyIdentifierFromDiscriminator(getDiscriminator());
2225 }
2226 
2228  unsigned BD, DF, CI;
2229  decodeDiscriminator(getDiscriminator(), BD, DF, CI);
2230  if (D == BD)
2231  return this;
2232  if (Optional<unsigned> Encoded = encodeDiscriminator(D, DF, CI))
2233  return cloneWithDiscriminator(*Encoded);
2234  return None;
2235 }
2236 
2238  DF *= getDuplicationFactor();
2239  if (DF <= 1)
2240  return this;
2241 
2242  unsigned BD = getBaseDiscriminator();
2243  unsigned CI = getCopyIdentifier();
2244  if (Optional<unsigned> D = encodeDiscriminator(BD, DF, CI))
2245  return cloneWithDiscriminator(*D);
2246  return None;
2247 }
2248 
2249 class DINamespace : public DIScope {
2250  friend class LLVMContextImpl;
2251  friend class MDNode;
2252 
2253  unsigned ExportSymbols : 1;
2254 
2255  DINamespace(LLVMContext &Context, StorageType Storage, bool ExportSymbols,
2257  : DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace,
2258  Ops),
2259  ExportSymbols(ExportSymbols) {}
2260  ~DINamespace() = default;
2261 
2263  StringRef Name, bool ExportSymbols,
2264  StorageType Storage, bool ShouldCreate = true) {
2266  ExportSymbols, Storage, ShouldCreate);
2267  }
2268  static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope,
2269  MDString *Name, bool ExportSymbols,
2270  StorageType Storage, bool ShouldCreate = true);
2271 
2272  TempDINamespace cloneImpl() const {
2273  return getTemporary(getContext(), getScope(), getName(),
2274  getExportSymbols());
2275  }
2276 
2277 public:
2278  DEFINE_MDNODE_GET(DINamespace,
2279  (DIScope *Scope, StringRef Name, bool ExportSymbols),
2280  (Scope, Name, ExportSymbols))
2281  DEFINE_MDNODE_GET(DINamespace,
2282  (Metadata *Scope, MDString *Name, bool ExportSymbols),
2283  (Scope, Name, ExportSymbols))
2284 
2285  TempDINamespace clone() const { return cloneImpl(); }
2286 
2287  bool getExportSymbols() const { return ExportSymbols; }
2288  DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2289  StringRef getName() const { return getStringOperand(2); }
2290 
2291  Metadata *getRawScope() const { return getOperand(1); }
2292  MDString *getRawName() const { return getOperandAs<MDString>(2); }
2293 
2294  static bool classof(const Metadata *MD) {
2295  return MD->getMetadataID() == DINamespaceKind;
2296  }
2297 };
2298 
2299 /// Represents a module in the programming language, for example, a Clang
2300 /// module, or a Fortran module.
2301 class DIModule : public DIScope {
2302  friend class LLVMContextImpl;
2303  friend class MDNode;
2304  unsigned LineNo;
2305  bool IsDecl;
2306 
2307  DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo,
2308  bool IsDecl, ArrayRef<Metadata *> Ops)
2309  : DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops),
2310  LineNo(LineNo), IsDecl(IsDecl) {}
2311  ~DIModule() = default;
2312 
2316  unsigned LineNo, bool IsDecl, StorageType Storage,
2317  bool ShouldCreate = true) {
2321  getCanonicalMDString(Context, APINotesFile), LineNo, IsDecl,
2322  Storage, ShouldCreate);
2323  }
2324  static DIModule *getImpl(LLVMContext &Context, Metadata *File,
2325  Metadata *Scope, MDString *Name,
2326  MDString *ConfigurationMacros, MDString *IncludePath,
2327  MDString *APINotesFile, unsigned LineNo, bool IsDecl,
2328  StorageType Storage, bool ShouldCreate = true);
2329 
2330  TempDIModule cloneImpl() const {
2331  return getTemporary(getContext(), getFile(), getScope(), getName(),
2332  getConfigurationMacros(), getIncludePath(),
2333  getAPINotesFile(), getLineNo(), getIsDecl());
2334  }
2335 
2336 public:
2337  DEFINE_MDNODE_GET(DIModule,
2338  (DIFile * File, DIScope *Scope, StringRef Name,
2339  StringRef ConfigurationMacros, StringRef IncludePath,
2340  StringRef APINotesFile, unsigned LineNo,
2341  bool IsDecl = false),
2343  APINotesFile, LineNo, IsDecl))
2344  DEFINE_MDNODE_GET(DIModule,
2347  MDString *APINotesFile, unsigned LineNo,
2348  bool IsDecl = false),
2350  APINotesFile, LineNo, IsDecl))
2351 
2352  TempDIModule clone() const { return cloneImpl(); }
2353 
2354  DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2355  StringRef getName() const { return getStringOperand(2); }
2356  StringRef getConfigurationMacros() const { return getStringOperand(3); }
2357  StringRef getIncludePath() const { return getStringOperand(4); }
2358  StringRef getAPINotesFile() const { return getStringOperand(5); }
2359  unsigned getLineNo() const { return LineNo; }
2360  bool getIsDecl() const { return IsDecl; }
2361 
2362  Metadata *getRawScope() const { return getOperand(1); }
2363  MDString *getRawName() const { return getOperandAs<MDString>(2); }
2364  MDString *getRawConfigurationMacros() const {
2365  return getOperandAs<MDString>(3);
2366  }
2367  MDString *getRawIncludePath() const { return getOperandAs<MDString>(4); }
2368  MDString *getRawAPINotesFile() const { return getOperandAs<MDString>(5); }
2369 
2370  static bool classof(const Metadata *MD) {
2371  return MD->getMetadataID() == DIModuleKind;
2372  }
2373 };
2374 
2375 /// Base class for template parameters.
2376 class DITemplateParameter : public DINode {
2377 protected:
2379 
2381  unsigned Tag, bool IsDefault, ArrayRef<Metadata *> Ops)
2382  : DINode(Context, ID, Storage, Tag, Ops), IsDefault(IsDefault) {}
2383  ~DITemplateParameter() = default;
2384 
2385 public:
2386  StringRef getName() const { return getStringOperand(0); }
2387  DIType *getType() const { return cast_or_null<DIType>(getRawType()); }
2388 
2389  MDString *getRawName() const { return getOperandAs<MDString>(0); }
2390  Metadata *getRawType() const { return getOperand(1); }
2391  bool isDefault() const { return IsDefault; }
2392 
2393  static bool classof(const Metadata *MD) {
2394  return MD->getMetadataID() == DITemplateTypeParameterKind ||
2395  MD->getMetadataID() == DITemplateValueParameterKind;
2396  }
2397 };
2398 
2400  friend class LLVMContextImpl;
2401  friend class MDNode;
2402 
2404  bool IsDefault, ArrayRef<Metadata *> Ops)
2405  : DITemplateParameter(Context, DITemplateTypeParameterKind, Storage,
2406  dwarf::DW_TAG_template_type_parameter, IsDefault,
2407  Ops) {}
2408  ~DITemplateTypeParameter() = default;
2409 
2411  DIType *Type, bool IsDefault,
2413  bool ShouldCreate = true) {
2415  IsDefault, Storage, ShouldCreate);
2416  }
2417  static DITemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
2418  Metadata *Type, bool IsDefault,
2420  bool ShouldCreate = true);
2421 
2422  TempDITemplateTypeParameter cloneImpl() const {
2423  return getTemporary(getContext(), getName(), getType(), isDefault());
2424  }
2425 
2426 public:
2427  DEFINE_MDNODE_GET(DITemplateTypeParameter,
2428  (StringRef Name, DIType *Type, bool IsDefault),
2429  (Name, Type, IsDefault))
2430  DEFINE_MDNODE_GET(DITemplateTypeParameter,
2433 
2434  TempDITemplateTypeParameter clone() const { return cloneImpl(); }
2435 
2436  static bool classof(const Metadata *MD) {
2437  return MD->getMetadataID() == DITemplateTypeParameterKind;
2438  }
2439 };
2440 
2442  friend class LLVMContextImpl;
2443  friend class MDNode;
2444 
2446  unsigned Tag, bool IsDefault,
2448  : DITemplateParameter(Context, DITemplateValueParameterKind, Storage, Tag,
2449  IsDefault, Ops) {}
2450  ~DITemplateValueParameter() = default;
2451 
2454  bool IsDefault, Metadata *Value,
2456  bool ShouldCreate = true) {
2458  IsDefault, Value, Storage, ShouldCreate);
2459  }
2460  static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
2461  MDString *Name, Metadata *Type,
2462  bool IsDefault, Metadata *Value,
2464  bool ShouldCreate = true);
2465 
2466  TempDITemplateValueParameter cloneImpl() const {
2467  return getTemporary(getContext(), getTag(), getName(), getType(),
2468  isDefault(), getValue());
2469  }
2470 
2471 public:
2472  DEFINE_MDNODE_GET(DITemplateValueParameter,
2473  (unsigned Tag, StringRef Name, DIType *Type, bool IsDefault,
2474  Metadata *Value),
2475  (Tag, Name, Type, IsDefault, Value))
2476  DEFINE_MDNODE_GET(DITemplateValueParameter,
2477  (unsigned Tag, MDString *Name, Metadata *Type,
2480 
2481  TempDITemplateValueParameter clone() const { return cloneImpl(); }
2482 
2483  Metadata *getValue() const { return getOperand(2); }
2484 
2485  static bool classof(const Metadata *MD) {
2486  return MD->getMetadataID() == DITemplateValueParameterKind;
2487  }
2488 };
2489 
2490 /// Base class for variables.
2491 class DIVariable : public DINode {
2492  unsigned Line;
2493  uint32_t AlignInBits;
2494 
2495 protected:
2496  DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Line,
2497  ArrayRef<Metadata *> Ops, uint32_t AlignInBits = 0)
2498  : DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line),
2499  AlignInBits(AlignInBits) {}
2500  ~DIVariable() = default;
2501 
2502 public:
2503  unsigned getLine() const { return Line; }
2504  DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2505  StringRef getName() const { return getStringOperand(1); }
2506  DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
2507  DIType *getType() const { return cast_or_null<DIType>(getRawType()); }
2508  uint32_t getAlignInBits() const { return AlignInBits; }
2509  uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
2510  /// Determines the size of the variable's type.
2512 
2513  /// Return the signedness of this variable's type, or None if this type is
2514  /// neither signed nor unsigned.
2516  if (auto *BT = dyn_cast<DIBasicType>(getType()))
2517  return BT->getSignedness();
2518  return None;
2519  }
2520 
2522  if (auto *F = getFile())
2523  return F->getFilename();
2524  return "";
2525  }
2526 
2528  if (auto *F = getFile())
2529  return F->getDirectory();
2530  return "";
2531  }
2532 
2534  if (auto *F = getFile())
2535  return F->getSource();
2536  return None;
2537  }
2538 
2539  Metadata *getRawScope() const { return getOperand(0); }
2540  MDString *getRawName() const { return getOperandAs<MDString>(1); }
2541  Metadata *getRawFile() const { return getOperand(2); }
2542  Metadata *getRawType() const { return getOperand(3); }
2543 
2544  static bool classof(const Metadata *MD) {
2545  return MD->getMetadataID() == DILocalVariableKind ||
2546  MD->getMetadataID() == DIGlobalVariableKind;
2547  }
2548 };
2549 
2550 /// DWARF expression.
2551 ///
2552 /// This is (almost) a DWARF expression that modifies the location of a
2553 /// variable, or the location of a single piece of a variable, or (when using
2554 /// DW_OP_stack_value) is the constant variable value.
2555 ///
2556 /// TODO: Co-allocate the expression elements.
2557 /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
2558 /// storage types.
2559 class DIExpression : public MDNode {
2560  friend class LLVMContextImpl;
2561  friend class MDNode;
2562 
2563  std::vector<uint64_t> Elements;
2564 
2566  : MDNode(C, DIExpressionKind, Storage, None),
2567  Elements(Elements.begin(), Elements.end()) {}
2568  ~DIExpression() = default;
2569 
2572  bool ShouldCreate = true);
2573 
2574  TempDIExpression cloneImpl() const {
2575  return getTemporary(getContext(), getElements());
2576  }
2577 
2578 public:
2580 
2581  TempDIExpression clone() const { return cloneImpl(); }
2582 
2583  ArrayRef<uint64_t> getElements() const { return Elements; }
2584 
2585  unsigned getNumElements() const { return Elements.size(); }
2586 
2587  uint64_t getElement(unsigned I) const {
2588  assert(I < Elements.size() && "Index out of range");
2589  return Elements[I];
2590  }
2591 
2593  /// Determine whether this represents a constant value, if so
2594  // return it's sign information.
2596 
2598 
2601 
2602  /// A lightweight wrapper around an expression operand.
2603  ///
2604  /// TODO: Store arguments directly and change \a DIExpression to store a
2605  /// range of these.
2606  class ExprOperand {
2607  const uint64_t *Op = nullptr;
2608 
2609  public:
2610  ExprOperand() = default;
2611  explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
2612 
2613  const uint64_t *get() const { return Op; }
2614 
2615  /// Get the operand code.
2616  uint64_t getOp() const { return *Op; }
2617 
2618  /// Get an argument to the operand.
2619  ///
2620  /// Never returns the operand itself.
2621  uint64_t getArg(unsigned I) const { return Op[I + 1]; }
2622 
2623  unsigned getNumArgs() const { return getSize() - 1; }
2624 
2625  /// Return the size of the operand.
2626  ///
2627  /// Return the number of elements in the operand (1 + args).
2628  unsigned getSize() const;
2629 
2630  /// Append the elements of this operand to \p V.
2632  V.append(get(), get() + getSize());
2633  }
2634  };
2635 
2636  /// An iterator for expression operands.
2638  ExprOperand Op;
2639 
2640  public:
2641  using iterator_category = std::input_iterator_tag;
2643  using difference_type = std::ptrdiff_t;
2644  using pointer = value_type *;
2646 
2647  expr_op_iterator() = default;
2649 
2650  element_iterator getBase() const { return Op.get(); }
2651  const ExprOperand &operator*() const { return Op; }
2652  const ExprOperand *operator->() const { return &Op; }
2653 
2655  increment();
2656  return *this;
2657  }
2659  expr_op_iterator T(*this);
2660  increment();
2661  return T;
2662  }
2663 
2664  /// Get the next iterator.
2665  ///
2666  /// \a std::next() doesn't work because this is technically an
2667  /// input_iterator, but it's a perfectly valid operation. This is an
2668  /// accessor to provide the same functionality.
2669  expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
2670 
2671  bool operator==(const expr_op_iterator &X) const {
2672  return getBase() == X.getBase();
2673  }
2674  bool operator!=(const expr_op_iterator &X) const {
2675  return getBase() != X.getBase();
2676  }
2677 
2678  private:
2679  void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
2680  };
2681 
2682  /// Visit the elements via ExprOperand wrappers.
2683  ///
2684  /// These range iterators visit elements through \a ExprOperand wrappers.
2685  /// This is not guaranteed to be a valid range unless \a isValid() gives \c
2686  /// true.
2687  ///
2688  /// \pre \a isValid() gives \c true.
2689  /// @{
2691  return expr_op_iterator(elements_begin());
2692  }
2694  return expr_op_iterator(elements_end());
2695  }
2697  return {expr_op_begin(), expr_op_end()};
2698  }
2699  /// @}
2700 
2701  bool isValid() const;
2702 
2703  static bool classof(const Metadata *MD) {
2704  return MD->getMetadataID() == DIExpressionKind;
2705  }
2706 
2707  /// Return whether the first element a DW_OP_deref.
2708  bool startsWithDeref() const {
2709  return getNumElements() > 0 && getElement(0) == dwarf::DW_OP_deref;
2710  }
2711 
2712  /// Holds the characteristics of one fragment of a larger variable.
2713  struct FragmentInfo {
2714  uint64_t SizeInBits;
2715  uint64_t OffsetInBits;
2716  };
2717 
2718  /// Retrieve the details of this fragment expression.
2720  expr_op_iterator End);
2721 
2722  /// Retrieve the details of this fragment expression.
2725  }
2726 
2727  /// Return whether this is a piece of an aggregate variable.
2728  bool isFragment() const { return getFragmentInfo().hasValue(); }
2729 
2730  /// Return whether this is an implicit location description.
2731  bool isImplicit() const;
2732 
2733  /// Return whether the location is computed on the expression stack, meaning
2734  /// it cannot be a simple register location.
2735  bool isComplex() const;
2736 
2737  /// Append \p Ops with operations to apply the \p Offset.
2738  static void appendOffset(SmallVectorImpl<uint64_t> &Ops, int64_t Offset);
2739 
2740  /// If this is a constant offset, extract it. If there is no expression,
2741  /// return true with an offset of zero.
2742  bool extractIfOffset(int64_t &Offset) const;
2743 
2744  /// Checks if the last 4 elements of the expression are DW_OP_constu <DWARF
2745  /// Address Space> DW_OP_swap DW_OP_xderef and extracts the <DWARF Address
2746  /// Space>.
2747  static const DIExpression *extractAddressClass(const DIExpression *Expr,
2748  unsigned &AddrClass);
2749 
2750  /// Used for DIExpression::prepend.
2751  enum PrependOps : uint8_t {
2753  DerefBefore = 1 << 0,
2754  DerefAfter = 1 << 1,
2755  StackValue = 1 << 2,
2756  EntryValue = 1 << 3
2757  };
2758 
2759  /// Prepend \p DIExpr with a deref and offset operation and optionally turn it
2760  /// into a stack value or/and an entry value.
2761  static DIExpression *prepend(const DIExpression *Expr, uint8_t Flags,
2762  int64_t Offset = 0);
2763 
2764  /// Prepend \p DIExpr with the given opcodes and optionally turn it into a
2765  /// stack value.
2766  static DIExpression *prependOpcodes(const DIExpression *Expr,
2768  bool StackValue = false,
2769  bool EntryValue = false);
2770 
2771  /// Append the opcodes \p Ops to \p DIExpr. Unlike \ref appendToStack, the
2772  /// returned expression is a stack value only if \p DIExpr is a stack value.
2773  /// If \p DIExpr describes a fragment, the returned expression will describe
2774  /// the same fragment.
2775  static DIExpression *append(const DIExpression *Expr, ArrayRef<uint64_t> Ops);
2776 
2777  /// Convert \p DIExpr into a stack value if it isn't one already by appending
2778  /// DW_OP_deref if needed, and appending \p Ops to the resulting expression.
2779  /// If \p DIExpr describes a fragment, the returned expression will describe
2780  /// the same fragment.
2781  static DIExpression *appendToStack(const DIExpression *Expr,
2782  ArrayRef<uint64_t> Ops);
2783 
2784  /// Create a copy of \p Expr by appending the given list of \p Ops to each
2785  /// instance of the operand `DW_OP_LLVM_arg, \p ArgNo`. This is used to
2786  /// modify a specific location used by \p Expr, such as when salvaging that
2787  /// location.
2788  static DIExpression *appendOpsToArg(const DIExpression *Expr,
2789  ArrayRef<uint64_t> Ops, unsigned ArgNo,
2790  bool StackValue = false);
2791 
2792  /// Create a copy of \p Expr with each instance of
2793  /// `DW_OP_LLVM_arg, \p OldArg` replaced with `DW_OP_LLVM_arg, \p NewArg`,
2794  /// and each instance of `DW_OP_LLVM_arg, Arg` with `DW_OP_LLVM_arg, Arg - 1`
2795  /// for all Arg > \p OldArg.
2796  /// This is used when replacing one of the operands of a debug value list
2797  /// with another operand in the same list and deleting the old operand.
2798  static DIExpression *replaceArg(const DIExpression *Expr, uint64_t OldArg,
2799  uint64_t NewArg);
2800 
2801  /// Create a DIExpression to describe one part of an aggregate variable that
2802  /// is fragmented across multiple Values. The DW_OP_LLVM_fragment operation
2803  /// will be appended to the elements of \c Expr. If \c Expr already contains
2804  /// a \c DW_OP_LLVM_fragment \c OffsetInBits is interpreted as an offset
2805  /// into the existing fragment.
2806  ///
2807  /// \param OffsetInBits Offset of the piece in bits.
2808  /// \param SizeInBits Size of the piece in bits.
2809  /// \return Creating a fragment expression may fail if \c Expr
2810  /// contains arithmetic operations that would be truncated.
2812  createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits,
2813  unsigned SizeInBits);
2814 
2815  /// Determine the relative position of the fragments passed in.
2816  /// Returns -1 if this is entirely before Other, 0 if this and Other overlap,
2817  /// 1 if this is entirely after Other.
2818  static int fragmentCmp(const FragmentInfo &A, const FragmentInfo &B) {
2819  uint64_t l1 = A.OffsetInBits;
2820  uint64_t l2 = B.OffsetInBits;
2821  uint64_t r1 = l1 + A.SizeInBits;
2822  uint64_t r2 = l2 + B.SizeInBits;
2823  if (r1 <= l2)
2824  return -1;
2825  else if (r2 <= l1)
2826  return 1;
2827  else
2828  return 0;
2829  }
2830 
2831  using ExtOps = std::array<uint64_t, 6>;
2832 
2833  /// Returns the ops for a zero- or sign-extension in a DIExpression.
2834  static ExtOps getExtOps(unsigned FromSize, unsigned ToSize, bool Signed);
2835 
2836  /// Append a zero- or sign-extension to \p Expr. Converts the expression to a
2837  /// stack value if it isn't one already.
2838  static DIExpression *appendExt(const DIExpression *Expr, unsigned FromSize,
2839  unsigned ToSize, bool Signed);
2840 
2841  /// Check if fragments overlap between a pair of FragmentInfos.
2842  static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B) {
2843  return fragmentCmp(A, B) == 0;
2844  }
2845 
2846  /// Determine the relative position of the fragments described by this
2847  /// DIExpression and \p Other. Calls static fragmentCmp implementation.
2848  int fragmentCmp(const DIExpression *Other) const {
2849  auto Fragment1 = *getFragmentInfo();
2850  auto Fragment2 = *Other->getFragmentInfo();
2851  return fragmentCmp(Fragment1, Fragment2);
2852  }
2853 
2854  /// Check if fragments overlap between this DIExpression and \p Other.
2855  bool fragmentsOverlap(const DIExpression *Other) const {
2856  if (!isFragment() || !Other->isFragment())
2857  return true;
2858  return fragmentCmp(Other) == 0;
2859  }
2860 
2861  /// Check if the expression consists of exactly one entry value operand.
2862  /// (This is the only configuration of entry values that is supported.)
2863  bool isEntryValue() const {
2864  return getNumElements() > 0 &&
2866  }
2867 };
2868 
2870  const DIExpression::FragmentInfo &B) {
2871  return std::tie(A.SizeInBits, A.OffsetInBits) ==
2872  std::tie(B.SizeInBits, B.OffsetInBits);
2873 }
2874 
2876  const DIExpression::FragmentInfo &B) {
2877  return std::tie(A.SizeInBits, A.OffsetInBits) <
2878  std::tie(B.SizeInBits, B.OffsetInBits);
2879 }
2880 
2881 template <> struct DenseMapInfo<DIExpression::FragmentInfo> {
2883  static const uint64_t MaxVal = std::numeric_limits<uint64_t>::max();
2884 
2885  static inline FragInfo getEmptyKey() { return {MaxVal, MaxVal}; }
2886 
2887  static inline FragInfo getTombstoneKey() { return {MaxVal - 1, MaxVal - 1}; }
2888 
2889  static unsigned getHashValue(const FragInfo &Frag) {
2890  return (Frag.SizeInBits & 0xffff) << 16 | (Frag.OffsetInBits & 0xffff);
2891  }
2892 
2893  static bool isEqual(const FragInfo &A, const FragInfo &B) { return A == B; }
2894 };
2895 
2896 /// Global variables.
2897 ///
2898 /// TODO: Remove DisplayName. It's always equal to Name.
2900  friend class LLVMContextImpl;
2901  friend class MDNode;
2902 
2903  bool IsLocalToUnit;
2904  bool IsDefinition;
2905 
2907  bool IsLocalToUnit, bool IsDefinition, uint32_t AlignInBits,
2909  : DIVariable(C, DIGlobalVariableKind, Storage, Line, Ops, AlignInBits),
2910  IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
2911  ~DIGlobalVariable() = default;
2912 
2913  static DIGlobalVariable *
2916  bool IsLocalToUnit, bool IsDefinition,
2918  uint32_t AlignInBits, StorageType Storage, bool ShouldCreate = true) {
2921  IsLocalToUnit, IsDefinition, StaticDataMemberDeclaration,
2922  cast_or_null<Metadata>(TemplateParams), AlignInBits, Storage,
2923  ShouldCreate);
2924  }
2925  static DIGlobalVariable *
2926  getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
2927  MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
2928  bool IsLocalToUnit, bool IsDefinition,
2930  uint32_t AlignInBits, StorageType Storage, bool ShouldCreate = true);
2931 
2932  TempDIGlobalVariable cloneImpl() const {
2934  getFile(), getLine(), getType(), isLocalToUnit(),
2937  }
2938 
2939 public:
2940  DEFINE_MDNODE_GET(DIGlobalVariable,
2941  (DIScope * Scope, StringRef Name, StringRef LinkageName,
2942  DIFile *File, unsigned Line, DIType *Type,
2943  bool IsLocalToUnit, bool IsDefinition,
2944  DIDerivedType *StaticDataMemberDeclaration,
2945  MDTuple *TemplateParams, uint32_t AlignInBits),
2946  (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
2948  AlignInBits))
2949  DEFINE_MDNODE_GET(DIGlobalVariable,
2952  bool IsLocalToUnit, bool IsDefinition,
2955  (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
2957  AlignInBits))
2958 
2959  TempDIGlobalVariable clone() const { return cloneImpl(); }
2960 
2961  bool isLocalToUnit() const { return IsLocalToUnit; }
2962  bool isDefinition() const { return IsDefinition; }
2966  return cast_or_null<DIDerivedType>(getRawStaticDataMemberDeclaration());
2967  }
2968 
2969  MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
2971  Metadata *getRawTemplateParams() const { return getOperand(7); }
2972  MDTuple *getTemplateParams() const { return getOperandAs<MDTuple>(7); }
2973 
2974  static bool classof(const Metadata *MD) {
2975  return MD->getMetadataID() == DIGlobalVariableKind;
2976  }
2977 };
2978 
2979 class DICommonBlock : public DIScope {
2980  unsigned LineNo;
2981 
2982  friend class LLVMContextImpl;
2983  friend class MDNode;
2984 
2987  : DIScope(Context, DICommonBlockKind, Storage, dwarf::DW_TAG_common_block,
2988  Ops), LineNo(LineNo) {}
2989 
2992  DIFile *File, unsigned LineNo,
2994  bool ShouldCreate = true) {
2996  File, LineNo, Storage, ShouldCreate);
2997  }
2998  static DICommonBlock *getImpl(LLVMContext &Context, Metadata *Scope,
2999  Metadata *Decl, MDString *Name, Metadata *File,
3000  unsigned LineNo,
3001  StorageType Storage, bool ShouldCreate = true);
3002 
3003  TempDICommonBlock cloneImpl() const {
3004  return getTemporary(getContext(), getScope(), getDecl(), getName(),
3005  getFile(), getLineNo());
3006  }
3007 
3008 public:
3009  DEFINE_MDNODE_GET(DICommonBlock,
3010  (DIScope *Scope, DIGlobalVariable *Decl, StringRef Name,
3011  DIFile *File, unsigned LineNo),
3012  (Scope, Decl, Name, File, LineNo))
3013  DEFINE_MDNODE_GET(DICommonBlock,
3015  Metadata *File, unsigned LineNo),
3016  (Scope, Decl, Name, File, LineNo))
3017 
3018  TempDICommonBlock clone() const { return cloneImpl(); }
3019 
3020  DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
3022  return cast_or_null<DIGlobalVariable>(getRawDecl());
3023  }
3024  StringRef getName() const { return getStringOperand(2); }
3025  DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
3026  unsigned getLineNo() const { return LineNo; }
3027 
3028  Metadata *getRawScope() const { return getOperand(0); }
3029  Metadata *getRawDecl() const { return getOperand(1); }
3030  MDString *getRawName() const { return getOperandAs<MDString>(2); }
3031  Metadata *getRawFile() const { return getOperand(3); }
3032 
3033  static bool classof(const Metadata *MD) {
3034  return MD->getMetadataID() == DICommonBlockKind;
3035  }
3036 };
3037 
3038 /// Local variable.
3039 ///
3040 /// TODO: Split up flags.
3041 class DILocalVariable : public DIVariable {
3042  friend class LLVMContextImpl;
3043  friend class MDNode;
3044 
3045  unsigned Arg : 16;
3046  DIFlags Flags;
3047 
3049  unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
3051  : DIVariable(C, DILocalVariableKind, Storage, Line, Ops, AlignInBits),
3052  Arg(Arg), Flags(Flags) {
3053  assert(Arg < (1 << 16) && "DILocalVariable: Arg out of range");
3054  }
3055  ~DILocalVariable() = default;
3056 
3058  StringRef Name, DIFile *File, unsigned Line,
3059  DIType *Type, unsigned Arg, DIFlags Flags,
3061  bool ShouldCreate = true) {
3063  Line, Type, Arg, Flags, AlignInBits, Storage, ShouldCreate);
3064  }
3065  static DILocalVariable *getImpl(LLVMContext &Context, Metadata *Scope,
3066  MDString *Name, Metadata *File, unsigned Line,
3067  Metadata *Type, unsigned Arg, DIFlags Flags,
3069  bool ShouldCreate = true);
3070 
3071  TempDILocalVariable cloneImpl() const {
3072  return getTemporary(getContext(), getScope(), getName(), getFile(),
3073  getLine(), getType(), getArg(), getFlags(),
3074  getAlignInBits());
3075  }
3076 
3077 public:
3078  DEFINE_MDNODE_GET(DILocalVariable,
3079  (DILocalScope * Scope, StringRef Name, DIFile *File,
3080  unsigned Line, DIType *Type, unsigned Arg, DIFlags Flags,
3082  (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits))
3083  DEFINE_MDNODE_GET(DILocalVariable,
3085  unsigned Line, Metadata *Type, unsigned Arg,
3088 
3089  TempDILocalVariable clone() const { return cloneImpl(); }
3090 
3091  /// Get the local scope for this variable.
3092  ///
3093  /// Variables must be defined in a local scope.
3095  return cast<DILocalScope>(DIVariable::getScope());
3096  }
3097 
3098  bool isParameter() const { return Arg; }
3099  unsigned getArg() const { return Arg; }
3100  DIFlags getFlags() const { return Flags; }
3101 
3102  bool isArtificial() const { return getFlags() & FlagArtificial; }
3103  bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
3104 
3105  /// Check that a location is valid for this variable.
3106  ///
3107  /// Check that \c DL exists, is in the same subprogram, and has the same
3108  /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
3109  /// to a \a DbgInfoIntrinsic.)
3111  return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
3112  }
3113 
3114  static bool classof(const Metadata *MD) {
3115  return MD->getMetadataID() == DILocalVariableKind;
3116  }
3117 };
3118 
3119 /// Label.
3120 ///
3121 class DILabel : public DINode {
3122  friend class LLVMContextImpl;
3123  friend class MDNode;
3124 
3125  unsigned Line;
3126 
3127  DILabel(LLVMContext &C, StorageType Storage, unsigned Line,
3129  : DINode(C, DILabelKind, Storage, dwarf::DW_TAG_label, Ops), Line(Line) {}
3130  ~DILabel() = default;
3131 
3133  StringRef Name, DIFile *File, unsigned Line,
3135  bool ShouldCreate = true) {
3137  Line, Storage, ShouldCreate);
3138  }
3139  static DILabel *getImpl(LLVMContext &Context, Metadata *Scope,
3140  MDString *Name, Metadata *File, unsigned Line,
3142  bool ShouldCreate = true);
3143 
3144  TempDILabel cloneImpl() const {
3145  return getTemporary(getContext(), getScope(), getName(), getFile(),
3146  getLine());
3147  }
3148 
3149 public:
3150  DEFINE_MDNODE_GET(DILabel,
3151  (DILocalScope * Scope, StringRef Name, DIFile *File,
3152  unsigned Line),
3153  (Scope, Name, File, Line))
3154  DEFINE_MDNODE_GET(DILabel,
3156  unsigned Line),
3157  (Scope, Name, File, Line))
3158 
3159  TempDILabel clone() const { return cloneImpl(); }
3160 
3161  /// Get the local scope for this label.
3162  ///
3163  /// Labels must be defined in a local scope.
3165  return cast_or_null<DILocalScope>(getRawScope());
3166  }
3167  unsigned getLine() const { return Line; }
3168  StringRef getName() const { return getStringOperand(1); }
3169  DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
3170 
3171  Metadata *getRawScope() const { return getOperand(0); }
3172  MDString *getRawName() const { return getOperandAs<MDString>(1); }
3173  Metadata *getRawFile() const { return getOperand(2); }
3174 
3175  /// Check that a location is valid for this label.
3176  ///
3177  /// Check that \c DL exists, is in the same subprogram, and has the same
3178  /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
3179  /// to a \a DbgInfoIntrinsic.)
3181  return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
3182  }
3183 
3184  static bool classof(const Metadata *MD) {
3185  return MD->getMetadataID() == DILabelKind;
3186  }
3187 };
3188 
3189 class DIObjCProperty : public DINode {
3190  friend class LLVMContextImpl;
3191  friend class MDNode;
3192 
3193  unsigned Line;
3194  unsigned Attributes;
3195 
3196  DIObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
3197  unsigned Attributes, ArrayRef<Metadata *> Ops)
3198  : DINode(C, DIObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
3199  Ops),
3200  Line(Line), Attributes(Attributes) {}
3201  ~DIObjCProperty() = default;
3202 
3203  static DIObjCProperty *
3204  getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
3205  StringRef GetterName, StringRef SetterName, unsigned Attributes,
3206  DIType *Type, StorageType Storage, bool ShouldCreate = true) {
3210  Storage, ShouldCreate);
3211  }
3212  static DIObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
3213  Metadata *File, unsigned Line,
3214  MDString *GetterName, MDString *SetterName,
3215  unsigned Attributes, Metadata *Type,
3216  StorageType Storage, bool ShouldCreate = true);
3217 
3218  TempDIObjCProperty cloneImpl() const {
3219  return getTemporary(getContext(), getName(), getFile(), getLine(),
3221  getType());
3222  }
3223 
3224 public:
3225  DEFINE_MDNODE_GET(DIObjCProperty,
3226  (StringRef Name, DIFile *File, unsigned Line,
3227  StringRef GetterName, StringRef SetterName,
3228  unsigned Attributes, DIType *Type),
3229  (Name, File, Line, GetterName, SetterName, Attributes,
3230  Type))
3231  DEFINE_MDNODE_GET(DIObjCProperty,
3232  (MDString * Name, Metadata *File, unsigned Line,
3234  unsigned Attributes, Metadata *Type),
3235  (Name, File, Line, GetterName, SetterName, Attributes,
3236  Type))
3237 
3238  TempDIObjCProperty clone() const { return cloneImpl(); }
3239 
3240  unsigned getLine() const { return Line; }
3241  unsigned getAttributes() const { return Attributes; }
3242  StringRef getName() const { return getStringOperand(0); }
3243  DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
3246  DIType *getType() const { return cast_or_null<DIType>(getRawType()); }
3247 
3249  if (auto *F = getFile())
3250  return F->getFilename();
3251  return "";
3252  }
3253 
3255  if (auto *F = getFile())
3256  return F->getDirectory();
3257  return "";
3258  }
3259 
3260  MDString *getRawName() const { return getOperandAs<MDString>(0); }
3261  Metadata *getRawFile() const { return getOperand(1); }
3262  MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
3263  MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
3264  Metadata *getRawType() const { return getOperand(4); }
3265 
3266  static bool classof(const Metadata *MD) {
3267  return MD->getMetadataID() == DIObjCPropertyKind;
3268  }
3269 };
3270 
3271 /// An imported module (C++ using directive or similar).
3272 class DIImportedEntity : public DINode {
3273  friend class LLVMContextImpl;
3274  friend class MDNode;
3275 
3276  unsigned Line;
3277 
3279  unsigned Line, ArrayRef<Metadata *> Ops)
3280  : DINode(C, DIImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
3281  ~DIImportedEntity() = default;
3282 
3283  static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
3285  unsigned Line, StringRef Name,
3287  bool ShouldCreate = true) {
3288  return getImpl(Context, Tag, Scope, Entity, File, Line,
3289  getCanonicalMDString(Context, Name), Storage, ShouldCreate);
3290  }
3291  static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
3293  Metadata *File, unsigned Line,
3294  MDString *Name, StorageType Storage,
3295  bool ShouldCreate = true);
3296 
3297  TempDIImportedEntity cloneImpl() const {
3298  return getTemporary(getContext(), getTag(), getScope(), getEntity(),
3299  getFile(), getLine(), getName());
3300  }
3301 
3302 public:
3303  DEFINE_MDNODE_GET(DIImportedEntity,
3304  (unsigned Tag, DIScope *Scope, DINode *Entity, DIFile *File,
3305  unsigned Line, StringRef Name = ""),
3306  (Tag, Scope, Entity, File, Line, Name))
3307  DEFINE_MDNODE_GET(DIImportedEntity,
3309  Metadata *File, unsigned Line, MDString *Name),
3310  (Tag, Scope, Entity, File, Line, Name))
3311 
3312  TempDIImportedEntity clone() const { return cloneImpl(); }
3313 
3314  unsigned getLine() const { return Line; }
3315  DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
3316  DINode *getEntity() const { return cast_or_null<DINode>(getRawEntity()); }
3317  StringRef getName() const { return getStringOperand(2); }
3318  DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
3319 
3320  Metadata *getRawScope() const { return getOperand(0); }
3321  Metadata *getRawEntity() const { return getOperand(1); }
3322  MDString *getRawName() const { return getOperandAs<MDString>(2); }
3323  Metadata *getRawFile() const { return getOperand(3); }
3324 
3325  static bool classof(const Metadata *MD) {
3326  return MD->getMetadataID() == DIImportedEntityKind;
3327  }
3328 };
3329 
3330 /// A pair of DIGlobalVariable and DIExpression.
3332  friend class LLVMContextImpl;
3333  friend class MDNode;
3334 
3337  : MDNode(C, DIGlobalVariableExpressionKind, Storage, Ops) {}
3338  ~DIGlobalVariableExpression() = default;
3339 
3342  StorageType Storage, bool ShouldCreate = true);
3343 
3344  TempDIGlobalVariableExpression cloneImpl() const {
3346  }
3347 
3348 public:
3350  (Metadata * Variable, Metadata *Expression),
3351  (Variable, Expression))
3352 
3353  TempDIGlobalVariableExpression clone() const { return cloneImpl(); }
3354 
3355  Metadata *getRawVariable() const { return getOperand(0); }
3356 
3358  return cast_or_null<DIGlobalVariable>(getRawVariable());
3359  }
3360 
3361  Metadata *getRawExpression() const { return getOperand(1); }
3362 
3364  return cast<DIExpression>(getRawExpression());
3365  }
3366 
3367  static bool classof(const Metadata *MD) {
3368  return MD->getMetadataID() == DIGlobalVariableExpressionKind;
3369  }
3370 };
3371 
3372 /// Macro Info DWARF-like metadata node.
3373 ///
3374 /// A metadata node with a DWARF macro info (i.e., a constant named
3375 /// \c DW_MACINFO_*, defined in llvm/BinaryFormat/Dwarf.h). Called \a
3376 /// DIMacroNode
3377 /// because it's potentially used for non-DWARF output.
3378 class DIMacroNode : public MDNode {
3379  friend class LLVMContextImpl;
3380  friend class MDNode;
3381 
3382 protected:
3383  DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType,
3385  : MDNode(C, ID, Storage, Ops1, Ops2) {
3386  assert(MIType < 1u << 16);
3387  SubclassData16 = MIType;
3388  }
3389  ~DIMacroNode() = default;
3390 
3391  template <class Ty> Ty *getOperandAs(unsigned I) const {
3392  return cast_or_null<Ty>(getOperand(I));
3393  }
3394 
3395  StringRef getStringOperand(unsigned I) const {
3396  if (auto *S = getOperandAs<MDString>(I))
3397  return S->getString();
3398  return StringRef();
3399  }
3400 
3402  if (S.empty())
3403  return nullptr;
3404  return MDString::get(Context, S);
3405  }
3406 
3407 public:
3408  unsigned getMacinfoType() const { return SubclassData16; }
3409 
3410  static bool classof(const Metadata *MD) {
3411  switch (MD->getMetadataID()) {
3412  default:
3413  return false;
3414  case DIMacroKind:
3415  case DIMacroFileKind:
3416  return true;
3417  }
3418  }
3419 };
3420 
3421 class DIMacro : public DIMacroNode {
3422  friend class LLVMContextImpl;
3423  friend class MDNode;
3424 
3425  unsigned Line;
3426 
3427  DIMacro(LLVMContext &C, StorageType Storage, unsigned MIType, unsigned Line,
3429  : DIMacroNode(C, DIMacroKind, Storage, MIType, Ops), Line(Line) {}
3430  ~DIMacro() = default;
3431 
3432  static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
3434  bool ShouldCreate = true) {
3436  getCanonicalMDString(Context, Value), Storage, ShouldCreate);
3437  }
3438  static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
3439  MDString *Name, MDString *Value, StorageType Storage,
3440  bool ShouldCreate = true);
3441 
3442  TempDIMacro cloneImpl() const {
3444  getValue());
3445  }
3446 
3447 public:
3448  DEFINE_MDNODE_GET(DIMacro, (unsigned MIType, unsigned Line, StringRef Name,
3449  StringRef Value = ""),
3450  (MIType, Line, Name, Value))
3451  DEFINE_MDNODE_GET(DIMacro, (unsigned MIType, unsigned Line, MDString *Name,
3453  (MIType, Line, Name, Value))
3454 
3455  TempDIMacro clone() const { return cloneImpl(); }
3456 
3457  unsigned getLine() const { return Line; }
3458 
3459  StringRef getName() const { return getStringOperand(0); }
3460  StringRef getValue() const { return getStringOperand(1); }
3461 
3462  MDString *getRawName() const { return getOperandAs<MDString>(0); }
3463  MDString *getRawValue() const { return getOperandAs<MDString>(1); }
3464 
3465  static bool classof(const Metadata *MD) {
3466  return MD->getMetadataID() == DIMacroKind;
3467  }
3468 };
3469 
3470 class DIMacroFile : public DIMacroNode {
3471  friend class LLVMContextImpl;
3472  friend class MDNode;
3473 
3474  unsigned Line;
3475 
3477  unsigned Line, ArrayRef<Metadata *> Ops)
3478  : DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops), Line(Line) {}
3479  ~DIMacroFile() = default;
3480 
3481  static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
3482  unsigned Line, DIFile *File,
3483  DIMacroNodeArray Elements, StorageType Storage,
3484  bool ShouldCreate = true) {
3485  return getImpl(Context, MIType, Line, static_cast<Metadata *>(File),
3486  Elements.get(), Storage, ShouldCreate);
3487  }
3488 
3489  static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
3490  unsigned Line, Metadata *File, Metadata *Elements,
3491  StorageType Storage, bool ShouldCreate = true);
3492 
3493  TempDIMacroFile cloneImpl() const {
3495  getElements());
3496  }
3497 
3498 public:
3499  DEFINE_MDNODE_GET(DIMacroFile, (unsigned MIType, unsigned Line, DIFile *File,
3500  DIMacroNodeArray Elements),
3501  (MIType, Line, File, Elements))
3502  DEFINE_MDNODE_GET(DIMacroFile, (unsigned MIType, unsigned Line,
3504  (MIType, Line, File, Elements))
3505 
3506  TempDIMacroFile clone() const { return cloneImpl(); }
3507 
3508  void replaceElements(DIMacroNodeArray Elements) {
3509 #ifndef NDEBUG
3510  for (DIMacroNode *Op : getElements())
3511  assert(is_contained(Elements->operands(), Op) &&
3512  "Lost a macro node during macro node list replacement");
3513 #endif
3514  replaceOperandWith(1, Elements.get());
3515  }
3516 
3517  unsigned getLine() const { return Line; }
3518  DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
3519 
3520  DIMacroNodeArray getElements() const {
3521  return cast_or_null<MDTuple>(getRawElements());
3522  }
3523 
3524  Metadata *getRawFile() const { return getOperand(0); }
3525  Metadata *getRawElements() const { return getOperand(1); }
3526 
3527  static bool classof(const Metadata *MD) {
3528  return MD->getMetadataID() == DIMacroFileKind;
3529  }
3530 };
3531 
3532 /// List of ValueAsMetadata, to be used as an argument to a dbg.value
3533 /// intrinsic.
3534 class DIArgList : public MDNode {
3535  friend class LLVMContextImpl;
3536  friend class MDNode;
3538 
3540 
3543  : MDNode(C, DIArgListKind, Storage, None),
3544  Args(Args.begin(), Args.end()) {
3545  track();
3546  }
3547  ~DIArgList() { untrack(); }
3548 
3549  static DIArgList *getImpl(LLVMContext &Context,
3550  ArrayRef<ValueAsMetadata *> Args,
3551  StorageType Storage, bool ShouldCreate = true);
3552 
3553  TempDIArgList cloneImpl() const {
3554  return getTemporary(getContext(), getArgs());
3555  }
3556 
3557  void track();
3558  void untrack();
3559  void dropAllReferences();
3560 
3561 public:
3563 
3564  TempDIArgList clone() const { return cloneImpl(); }
3565 
3567 
3568  iterator args_begin() { return Args.begin(); }
3569  iterator args_end() { return Args.end(); }
3570 
3571  static bool classof(const Metadata *MD) {
3572  return MD->getMetadataID() == DIArgListKind;
3573  }
3574 
3575  void handleChangedOperand(void *Ref, Metadata *New);
3576 };
3577 
3578 /// Identifies a unique instance of a variable.
3579 ///
3580 /// Storage for identifying a potentially inlined instance of a variable,
3581 /// or a fragment thereof. This guarantees that exactly one variable instance
3582 /// may be identified by this class, even when that variable is a fragment of
3583 /// an aggregate variable and/or there is another inlined instance of the same
3584 /// source code variable nearby.
3585 /// This class does not necessarily uniquely identify that variable: it is
3586 /// possible that a DebugVariable with different parameters may point to the
3587 /// same variable instance, but not that one DebugVariable points to multiple
3588 /// variable instances.
3591 
3592  const DILocalVariable *Variable;
3593  Optional<FragmentInfo> Fragment;
3594  const DILocation *InlinedAt;
3595 
3596  /// Fragment that will overlap all other fragments. Used as default when
3597  /// caller demands a fragment.
3598  static const FragmentInfo DefaultFragment;
3599 
3600 public:
3602  const DILocation *InlinedAt)
3603  : Variable(Var), Fragment(FragmentInfo), InlinedAt(InlinedAt) {}
3604 
3605  DebugVariable(const DILocalVariable *Var, const DIExpression *DIExpr,
3606  const DILocation *InlinedAt)
3607  : Variable(Var),
3608  Fragment(DIExpr ? DIExpr->getFragmentInfo() : NoneType()),
3609  InlinedAt(InlinedAt) {}
3610 
3611  const DILocalVariable *getVariable() const { return Variable; }
3612  Optional<FragmentInfo> getFragment() const { return Fragment; }
3613  const DILocation *getInlinedAt() const { return InlinedAt; }
3614 
3616  return Fragment.getValueOr(DefaultFragment);
3617  }
3618 
3619  static bool isDefaultFragment(const FragmentInfo F) {
3620  return F == DefaultFragment;
3621  }
3622 
3623  bool operator==(const DebugVariable &Other) const {
3624  return std::tie(Variable, Fragment, InlinedAt) ==
3625  std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
3626  }
3627 
3628  bool operator<(const DebugVariable &Other) const {
3629  return std::tie(Variable, Fragment, InlinedAt) <
3630  std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
3631  }
3632 };
3633 
3634 template <> struct DenseMapInfo<DebugVariable> {
3636 
3637  /// Empty key: no key should be generated that has no DILocalVariable.
3638  static inline DebugVariable getEmptyKey() {
3639  return DebugVariable(nullptr, NoneType(), nullptr);
3640  }
3641 
3642  /// Difference in tombstone is that the Optional is meaningful.
3643  static inline DebugVariable getTombstoneKey() {
3644  return DebugVariable(nullptr, {{0, 0}}, nullptr);
3645  }
3646 
3647  static unsigned getHashValue(const DebugVariable &D) {
3648  unsigned HV = 0;
3649  const Optional<FragmentInfo> Fragment = D.getFragment();
3650  if (Fragment)
3652 
3653  return hash_combine(D.getVariable(), HV, D.getInlinedAt());
3654  }
3655 
3656  static bool isEqual(const DebugVariable &A, const DebugVariable &B) {
3657  return A == B;
3658  }
3659 };
3660 
3661 } // end namespace llvm
3662 
3663 #undef DEFINE_MDNODE_GET_UNPACK_IMPL
3664 #undef DEFINE_MDNODE_GET_UNPACK
3665 #undef DEFINE_MDNODE_GET
3666 
3667 #endif // LLVM_IR_DEBUGINFOMETADATA_H
llvm::DIScope::getFilename
StringRef getFilename() const
Definition: DebugInfoMetadata.h:635
llvm::DIExpression::prepend
static DIExpression * prepend(const DIExpression *Expr, uint8_t Flags, int64_t Offset=0)
Prepend DIExpr with a deref and offset operation and optionally turn it into a stack value or/and an ...
Definition: DebugInfoMetadata.cpp:1267
llvm::DIType::getScope
DIScope * getScope() const
Definition: DebugInfoMetadata.h:703
llvm::DILocation::getCopyIdentifier
unsigned getCopyIdentifier() const
Returns the copy identifier stored in the discriminator.
Definition: DebugInfoMetadata.h:2223
llvm::DILocation::cloneByMultiplyingDuplicationFactor
Optional< const DILocation * > cloneByMultiplyingDuplicationFactor(unsigned DF) const
Returns a new DILocation with duplication factor DF * current duplication factor encoded in the discr...
Definition: DebugInfoMetadata.h:2237
llvm::DIGlobalVariableExpression::getExpression
DIExpression * getExpression() const
Definition: DebugInfoMetadata.h:3363
llvm::DICompositeType::getRankExp
DIExpression * getRankExp() const
Definition: DebugInfoMetadata.h:1223
llvm::DICompileUnit::Macros
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata * Macros
Definition: DebugInfoMetadata.h:1432
llvm::DICompileUnit::DebugNameTableKind::GNU
@ GNU
llvm::dwarf::DW_VIRTUALITY_max
@ DW_VIRTUALITY_max
Definition: Dwarf.h:191
llvm::DISubrange::LowerBound
Metadata int64_t LowerBound
Definition: DebugInfoMetadata.h:323
llvm::DebugVariable::operator==
bool operator==(const DebugVariable &Other) const
Definition: DebugInfoMetadata.h:3623
llvm::DIDerivedType::DEFINE_MDNODE_GET
DEFINE_MDNODE_GET(DIDerivedType,(unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, Optional< unsigned > DWARFAddressSpace, DIFlags Flags, Metadata *ExtraData=nullptr),(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits, DWARFAddressSpace, Flags, ExtraData)) DEFINE_MDNODE_GET(DIDerivedType
llvm::DILabel::getLine
unsigned getLine() const
Definition: DebugInfoMetadata.h:3167
llvm::DICompositeType::getVTableHolder
DIType * getVTableHolder() const
Definition: DebugInfoMetadata.h:1180
llvm::DITypeRefArray::DITypeRefArray
DITypeRefArray()=default
Signed
@ Signed
Definition: NVPTXISelLowering.cpp:4543
llvm::DIObjCProperty::getFile
DIFile * getFile() const
Definition: DebugInfoMetadata.h:3243
llvm::DIGenericSubrange::getRawLowerBound
Metadata * getRawLowerBound() const
Definition: DebugInfoMetadata.h:388
llvm::DICompositeType::getBaseType
DIType * getBaseType() const
Definition: DebugInfoMetadata.h:1176
llvm::DIArgList
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
Definition: DebugInfoMetadata.h:3534
llvm::DIImportedEntity::DEFINE_MDNODE_GET
DEFINE_MDNODE_GET(DIImportedEntity,(unsigned Tag, DIScope *Scope, DINode *Entity, DIFile *File, unsigned Line, StringRef Name=""),(Tag, Scope, Entity, File, Line, Name)) DEFINE_MDNODE_GET(DIImportedEntity
llvm::DIMacroFile::classof
static bool classof(const Metadata *MD)
Definition: DebugInfoMetadata.h:3527
llvm::DINamespace::DEFINE_MDNODE_GET
DEFINE_MDNODE_GET(DINamespace,(DIScope *Scope, StringRef Name, bool ExportSymbols),(Scope, Name, ExportSymbols)) DEFINE_MDNODE_GET(DINamespace
llvm::DIBasicType::Tag
unsigned Tag
Definition: DebugInfoMetadata.h:803
llvm::DICompileUnit::nameTableKindString
static const char * nameTableKindString(DebugNameTableKind PK)
Definition: DebugInfoMetadata.cpp:793
llvm
Definition: AllocatorList.h:23
llvm::DIType
Base class for types.
Definition: DebugInfoMetadata.h:658
llvm::DITemplateValueParameter::clone
unsigned MDString Metadata bool Metadata Value TempDITemplateValueParameter clone() const
Definition: DebugInfoMetadata.h:2481
llvm::DIVariable::getAlignInBytes
uint32_t getAlignInBytes() const
Definition: DebugInfoMetadata.h:2509
llvm::DILocalScope::getSubprogram
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
Definition: DebugInfoMetadata.cpp:805
llvm::DIFile::ChecksumInfo::Value
T Value
The string value of the checksum.
Definition: DebugInfoMetadata.h:552
llvm::DILabel::Name
Metadata MDString * Name
Definition: DebugInfoMetadata.h:3155
llvm::DICompositeType::getRawDataLocation
Metadata * getRawDataLocation() const
Definition: DebugInfoMetadata.h:1196
llvm::DILexicalBlockFile::File
Metadata Metadata * File
Definition: DebugInfoMetadata.h:2181
llvm::DIExpression::createFragmentExpression
static Optional< DIExpression * > createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits)
Create a DIExpression to describe one part of an aggregate variable that is fragmented across multipl...
Definition: DebugInfoMetadata.cpp:1420
llvm::DICompileUnit::getRawGlobalVariables
Metadata * getRawGlobalVariables() const
Definition: DebugInfoMetadata.h:1491
llvm::DIEnumerator::Name
int64_t bool MDString * Name
Definition: DebugInfoMetadata.h:444
Optional.h
llvm::DILabel::File
Metadata MDString Metadata * File
Definition: DebugInfoMetadata.h:3155
llvm::DIGenericSubrange::getRawCountNode
Metadata * getRawCountNode() const
Definition: DebugInfoMetadata.h:387
llvm::DILocalScope::DILocalScope
DILocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, ArrayRef< Metadata * > Ops)
Definition: DebugInfoMetadata.h:1530
llvm::DIExpression::ExprOperand::ExprOperand
ExprOperand()=default
llvm::DIImportedEntity::classof
static bool classof(const Metadata *MD)
Definition: DebugInfoMetadata.h:3325
llvm::DIMacroNode::getMacinfoType
unsigned getMacinfoType() const
Definition: DebugInfoMetadata.h:3408
llvm::DIMacro::MIType
unsigned MIType
Definition: DebugInfoMetadata.h:3451
llvm::DICompileUnit::File
unsigned Metadata * File
Definition: DebugInfoMetadata.h:1428
llvm::Intrinsic::getDeclaration
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:1295
Metadata.h
llvm::DIArgList::DEFINE_MDNODE_GET
DEFINE_MDNODE_GET(DIArgList,(ArrayRef< ValueAsMetadata * > Args),(Args)) TempDIArgList clone() const
Definition: DebugInfoMetadata.h:3562
llvm::DINode::getOperandAs
Ty * getOperandAs(unsigned I) const
Definition: DebugInfoMetadata.h:136
llvm::DIType::getSizeInBits
uint64_t getSizeInBits() const
Definition: DebugInfoMetadata.h:697
llvm::DICommonBlock::getFile
DIFile * getFile() const
Definition: DebugInfoMetadata.h:3025
llvm::DILocation::getMergedLocation
static const DILocation * getMergedLocation(const DILocation *LocA, const DILocation *LocB)
When two instructions are combined into a single instruction we also need to combine the original loc...
Definition: DebugInfoMetadata.cpp:93
llvm::DIObjCProperty::getRawGetterName
MDString * getRawGetterName() const
Definition: DebugInfoMetadata.h:3262
llvm::DICompileUnit::setSplitDebugInlining
void setSplitDebugInlining(bool SplitDebugInlining)
Definition: DebugInfoMetadata.h:1478
llvm::DIScope::~DIScope
~DIScope()=default
llvm::DICompileUnit::getMacros
DIMacroNodeArray getMacros() const
Definition: DebugInfoMetadata.h:1472
llvm::DIGenericSubrange
Definition: DebugInfoMetadata.h:358
llvm::DIDerivedType::File
unsigned StringRef DIFile * File
Definition: DebugInfoMetadata.h:968
llvm::DIExpression::expr_op_iterator::operator*
const ExprOperand & operator*() const
Definition: DebugInfoMetadata.h:2651
llvm::DIType::isProtected
bool isProtected() const
Definition: DebugInfoMetadata.h:720
LLVM_MARK_AS_BITMASK_ENUM
#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:41
llvm::DIExpression::expr_op_iterator::operator++
expr_op_iterator & operator++()
Definition: DebugInfoMetadata.h:2654
llvm::DICompositeType::Identifier
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned Metadata Metadata MDString * Identifier
Definition: DebugInfoMetadata.h:1128
StringRef.h
llvm::DICompileUnit::ImportedEntities
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata * ImportedEntities
Definition: DebugInfoMetadata.h:1432
llvm::DIExpression::fragmentCmp
static int fragmentCmp(const FragmentInfo &A, const FragmentInfo &B)
Determine the relative position of the fragments passed in.
Definition: DebugInfoMetadata.h:2818
llvm::DICommonBlock::getRawDecl
Metadata * getRawDecl() const
Definition: DebugInfoMetadata.h:3029
llvm::DILocalVariable::Name
Metadata MDString * Name
Definition: DebugInfoMetadata.h:3084
llvm::DIType::isAppleBlockExtension
bool isAppleBlockExtension() const
Definition: DebugInfoMetadata.h:727
llvm::DICompileUnit::SDK
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString MDString * SDK
Definition: DebugInfoMetadata.h:1435
llvm::DICommonBlock::File
Metadata Metadata MDString Metadata * File
Definition: DebugInfoMetadata.h:3015
llvm::DITypeRefArray::operator*
MDTuple & operator*() const
Definition: DebugInfoMetadata.h:75
llvm::DenseMapInfo< DebugVariable >::getHashValue
static unsigned getHashValue(const DebugVariable &D)
Definition: DebugInfoMetadata.h:3647
llvm::DIObjCProperty::getRawSetterName
MDString * getRawSetterName() const
Definition: DebugInfoMetadata.h:3263
llvm::DITypeRefArray::iterator::operator++
iterator operator++(int)
Definition: DebugInfoMetadata.h:103
llvm::DIGenericSubrange::DEFINE_MDNODE_GET
DEFINE_MDNODE_GET(DIGenericSubrange,(Metadata *CountNode, Metadata *LowerBound, Metadata *UpperBound, Metadata *Stride),(CountNode, LowerBound, UpperBound, Stride)) TempDIGenericSubrange clone() const
Definition: DebugInfoMetadata.h:380
llvm::DILexicalBlockFile
Definition: DebugInfoMetadata.h:2145
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
getImpl
static LazyValueInfoImpl & getImpl(void *&PImpl, AssumptionCache *AC, const Module *M)
This lazily constructs the LazyValueInfoImpl.
Definition: LazyValueInfo.cpp:1480
llvm::DIVariable::getSizeInBits
Optional< uint64_t > getSizeInBits() const
Determines the size of the variable's type.
Definition: DebugInfoMetadata.cpp:1011
llvm::DIStringType
String type, Fortran CHARACTER(n)
Definition: DebugInfoMetadata.h:833
llvm::DICompileUnit::getRawImportedEntities
Metadata * getRawImportedEntities() const
Definition: DebugInfoMetadata.h:1492
llvm::DITemplateParameter::isDefault
bool isDefault() const
Definition: DebugInfoMetadata.h:2391
llvm::DIFile::ChecksumInfo
A single checksum, represented by a Kind and a Value (a string).
Definition: DebugInfoMetadata.h:548
llvm::DICompileUnit::replaceRetainedTypes
void replaceRetainedTypes(DITypeArray N)
Definition: DebugInfoMetadata.h:1506
llvm::DIFile::Directory
MDString MDString * Directory
Definition: DebugInfoMetadata.h:603
llvm::DITemplateTypeParameter::IsDefault
MDString Metadata bool IsDefault
Definition: DebugInfoMetadata.h:2431
llvm::Metadata::SubclassData32
unsigned SubclassData32
Definition: Metadata.h:77
llvm::dwarf::getVirtuality
unsigned getVirtuality(StringRef VirtualityString)
Definition: Dwarf.cpp:319
llvm::DILexicalBlockFile::Scope
Metadata * Scope
Definition: DebugInfoMetadata.h:2181
llvm::DISubroutineType::TypeArray
DIFlags uint8_t Metadata * TypeArray
Definition: DebugInfoMetadata.h:1294
llvm::DIBasicType::classof
static bool classof(const Metadata *MD)
Definition: DebugInfoMetadata.h:827
llvm::DICompositeType::Scope
unsigned MDString Metadata unsigned Metadata * Scope
Definition: DebugInfoMetadata.h:1125
llvm::DIObjCProperty::getRawName
MDString * getRawName() const
Definition: DebugInfoMetadata.h:3260
llvm::DIBasicType::DEFINE_MDNODE_GET
DEFINE_MDNODE_GET(DIBasicType,(unsigned Tag, StringRef Name),(Tag, Name, 0, 0, 0, FlagZero)) DEFINE_MDNODE_GET(DIBasicType
llvm::DIEnumerator::isUnsigned
bool isUnsigned() const
Definition: DebugInfoMetadata.h:456
llvm::DIMacro::getValue
StringRef getValue() const
Definition: DebugInfoMetadata.h:3460
llvm::DIType::cloneWithFlags
TempDIType cloneWithFlags(DIFlags NewFlags) const
Returns a new temporary DIType with updated Flags.
Definition: DebugInfoMetadata.h:711
llvm::DIExpression::expr_op_iterator::getNext
expr_op_iterator getNext() const
Get the next iterator.
Definition: DebugInfoMetadata.h:2669
llvm::DICompositeType::TemplateParams
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned Metadata Metadata * TemplateParams
Definition: DebugInfoMetadata.h:1128
llvm::DILocation::isPseudoProbeDiscriminator
static bool isPseudoProbeDiscriminator(unsigned Discriminator)
Definition: DebugInfoMetadata.h:1712
llvm::DIScope::getName
StringRef getName() const
Definition: DebugInfoMetadata.cpp:254
llvm::DICompileUnit::GlobalVariables
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata * GlobalVariables
Definition: DebugInfoMetadata.h:1431
llvm::DIBasicType::Signedness::Unsigned
@ Unsigned
llvm::DISubprogram::TemplateParams
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata * TemplateParams
Definition: DebugInfoMetadata.h:1937
llvm::DICompositeType::getRankConst
ConstantInt * getRankConst() const
Definition: DebugInfoMetadata.h:1218
llvm::DIType::isStaticMember
bool isStaticMember() const
Definition: DebugInfoMetadata.h:736
llvm::DIEnumerator::clone
int64_t bool MDString Name APInt bool MDString Name TempDIEnumerator clone() const
Definition: DebugInfoMetadata.h:453
llvm::DILocation
Debug location.
Definition: DebugInfoMetadata.h:1558
llvm::DIType::getAlignInBits
uint32_t getAlignInBits() const
Definition: DebugInfoMetadata.h:698
llvm::DINamespace::classof
static bool classof(const Metadata *MD)
Definition: DebugInfoMetadata.h:2294
llvm::DISubrange::getUpperBound
BoundType getUpperBound() const
Definition: DebugInfoMetadata.cpp:404
llvm::DIModule::ConfigurationMacros
Metadata Metadata MDString MDString * ConfigurationMacros
Definition: DebugInfoMetadata.h:2346
llvm::DILocalVariable::isObjectPointer
bool isObjectPointer() const
Definition: DebugInfoMetadata.h:3103
llvm::DIType::isVirtual
bool isVirtual() const
Definition: DebugInfoMetadata.h:728
llvm::Metadata::SubclassData16
unsigned short SubclassData16
Definition: Metadata.h:76
llvm::DILabel::getName
StringRef getName() const
Definition: DebugInfoMetadata.h:3168
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::DIEnumerator::getRawName
MDString * getRawName() const
Definition: DebugInfoMetadata.h:459
llvm::AtomicOrderingCABI::release
@ release
llvm::DITemplateValueParameter::classof
static bool classof(const Metadata *MD)
Definition: DebugInfoMetadata.h:2485
llvm::DISubprogram::File
Metadata MDString MDString Metadata * File
Definition: DebugInfoMetadata.h:1933
llvm::DebugVariable::getFragment
Optional< FragmentInfo > getFragment() const
Definition: DebugInfoMetadata.h:3612
llvm::DIExpression::ExprOperand
A lightweight wrapper around an expression operand.
Definition: DebugInfoMetadata.h:2606
llvm::DIExpression::expr_op_iterator::getBase
element_iterator getBase() const
Definition: DebugInfoMetadata.h:2650
llvm::DIGlobalVariable::getDisplayName
StringRef getDisplayName() const