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