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