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