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