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