LLVM 22.0.0git
DebugInfoMetadata.h
Go to the documentation of this file.
1//===- llvm/IR/DebugInfoMetadata.h - Debug info metadata --------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Declarations for metadata specific to debug info.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_IR_DEBUGINFOMETADATA_H
14#define LLVM_IR_DEBUGINFOMETADATA_H
15
16#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/STLExtras.h"
21#include "llvm/ADT/StringRef.h"
23#include "llvm/IR/Constants.h"
25#include "llvm/IR/Metadata.h"
26#include "llvm/IR/PseudoProbe.h"
31#include <cassert>
32#include <climits>
33#include <cstddef>
34#include <cstdint>
35#include <iterator>
36#include <optional>
37#include <vector>
38
39// Helper macros for defining get() overrides.
40#define DEFINE_MDNODE_GET_UNPACK_IMPL(...) __VA_ARGS__
41#define DEFINE_MDNODE_GET_UNPACK(ARGS) DEFINE_MDNODE_GET_UNPACK_IMPL ARGS
42#define DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS) \
43 static CLASS *getDistinct(LLVMContext &Context, \
44 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
45 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct); \
46 } \
47 static Temp##CLASS getTemporary(LLVMContext &Context, \
48 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
49 return Temp##CLASS( \
50 getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary)); \
51 }
52#define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS) \
53 static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
54 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued); \
55 } \
56 static CLASS *getIfExists(LLVMContext &Context, \
57 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
58 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued, \
59 /* ShouldCreate */ false); \
60 } \
61 DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS)
62
63namespace llvm {
64
65namespace dwarf {
66enum Tag : uint16_t;
67}
68
69class DbgVariableRecord;
70
72
74 const MDTuple *N = nullptr;
75
76public:
77 DITypeRefArray() = default;
78 DITypeRefArray(const MDTuple *N) : N(N) {}
79
80 explicit operator bool() const { return get(); }
81 explicit operator MDTuple *() const { return get(); }
82
83 MDTuple *get() const { return const_cast<MDTuple *>(N); }
84 MDTuple *operator->() const { return get(); }
85 MDTuple &operator*() const { return *get(); }
86
87 // FIXME: Fix callers and remove condition on N.
88 unsigned size() const { return N ? N->getNumOperands() : 0u; }
89 DIType *operator[](unsigned I) const {
90 return cast_or_null<DIType>(N->getOperand(I));
91 }
92
93 class iterator {
94 MDNode::op_iterator I = nullptr;
95
96 public:
97 using iterator_category = std::input_iterator_tag;
98 using value_type = DIType *;
99 using difference_type = std::ptrdiff_t;
100 using pointer = void;
101 using reference = DIType *;
102
103 iterator() = default;
104 explicit iterator(MDNode::op_iterator I) : I(I) {}
105
106 DIType *operator*() const { return cast_or_null<DIType>(*I); }
107
109 ++I;
110 return *this;
111 }
112
114 iterator Temp(*this);
115 ++I;
116 return Temp;
117 }
118
119 bool operator==(const iterator &X) const { return I == X.I; }
120 bool operator!=(const iterator &X) const { return I != X.I; }
121 };
122
123 // FIXME: Fix callers and remove condition on N.
124 iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); }
125 iterator end() const { return N ? iterator(N->op_end()) : iterator(); }
126};
127
128/// Tagged DWARF-like metadata node.
129///
130/// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
131/// defined in llvm/BinaryFormat/Dwarf.h). Called \a DINode because it's
132/// potentially used for non-DWARF output.
133///
134/// Uses the SubclassData16 Metadata slot.
135class DINode : public MDNode {
136 friend class LLVMContextImpl;
137 friend class MDNode;
138
139protected:
140 DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
142 : MDNode(C, ID, Storage, Ops1, Ops2) {
143 assert(Tag < 1u << 16);
145 }
146 ~DINode() = default;
147
148 template <class Ty> Ty *getOperandAs(unsigned I) const {
149 return cast_or_null<Ty>(getOperand(I));
150 }
151
152 StringRef getStringOperand(unsigned I) const {
153 if (auto *S = getOperandAs<MDString>(I))
154 return S->getString();
155 return StringRef();
156 }
157
159 if (S.empty())
160 return nullptr;
161 return MDString::get(Context, S);
162 }
163
164 /// Allow subclasses to mutate the tag.
165 void setTag(unsigned Tag) { SubclassData16 = Tag; }
166
167public:
168 LLVM_ABI dwarf::Tag getTag() const;
169
170 /// Debug info flags.
171 ///
172 /// The three accessibility flags are mutually exclusive and rolled together
173 /// in the first two bits.
175#define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
176#define DI_FLAG_LARGEST_NEEDED
177#include "llvm/IR/DebugInfoFlags.def"
178 FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic,
179 FlagPtrToMemberRep = FlagSingleInheritance | FlagMultipleInheritance |
180 FlagVirtualInheritance,
181 LLVM_MARK_AS_BITMASK_ENUM(FlagLargest)
182 };
183
184 LLVM_ABI static DIFlags getFlag(StringRef Flag);
186
187 /// Split up a flags bitfield.
188 ///
189 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
190 /// any remaining (unrecognized) bits.
191 LLVM_ABI static DIFlags splitFlags(DIFlags Flags,
192 SmallVectorImpl<DIFlags> &SplitFlags);
193
194 static bool classof(const Metadata *MD) {
195 switch (MD->getMetadataID()) {
196 default:
197 return false;
198 case GenericDINodeKind:
199 case DISubrangeKind:
200 case DIEnumeratorKind:
201 case DIBasicTypeKind:
202 case DIFixedPointTypeKind:
203 case DIStringTypeKind:
204 case DISubrangeTypeKind:
205 case DIDerivedTypeKind:
206 case DICompositeTypeKind:
207 case DISubroutineTypeKind:
208 case DIFileKind:
209 case DICompileUnitKind:
210 case DISubprogramKind:
211 case DILexicalBlockKind:
212 case DILexicalBlockFileKind:
213 case DINamespaceKind:
214 case DICommonBlockKind:
215 case DITemplateTypeParameterKind:
216 case DITemplateValueParameterKind:
217 case DIGlobalVariableKind:
218 case DILocalVariableKind:
219 case DILabelKind:
220 case DIObjCPropertyKind:
221 case DIImportedEntityKind:
222 case DIModuleKind:
223 case DIGenericSubrangeKind:
224 case DIAssignIDKind:
225 return true;
226 }
227 }
228};
229
230/// Generic tagged DWARF-like metadata node.
231///
232/// An un-specialized DWARF-like metadata node. The first operand is a
233/// (possibly empty) null-separated \a MDString header that contains arbitrary
234/// fields. The remaining operands are \a dwarf_operands(), and are pointers
235/// to other metadata.
236///
237/// Uses the SubclassData32 Metadata slot.
238class GenericDINode : public DINode {
239 friend class LLVMContextImpl;
240 friend class MDNode;
241
243 unsigned Tag, ArrayRef<Metadata *> Ops1,
245 : DINode(C, GenericDINodeKind, Storage, Tag, Ops1, Ops2) {
246 setHash(Hash);
247 }
249
250 void setHash(unsigned Hash) { SubclassData32 = Hash; }
251 void recalculateHash();
252
253 static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
254 StringRef Header, ArrayRef<Metadata *> DwarfOps,
255 StorageType Storage, bool ShouldCreate = true) {
256 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
257 DwarfOps, Storage, ShouldCreate);
258 }
259
260 LLVM_ABI static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
261 MDString *Header,
262 ArrayRef<Metadata *> DwarfOps,
264 bool ShouldCreate = true);
265
266 TempGenericDINode cloneImpl() const {
268 SmallVector<Metadata *, 4>(dwarf_operands()));
269 }
270
271public:
272 unsigned getHash() const { return SubclassData32; }
273
275 (unsigned Tag, StringRef Header,
277 (Tag, Header, DwarfOps))
279 (unsigned Tag, MDString *Header,
282
283 /// Return a (temporary) clone of this.
284 TempGenericDINode clone() const { return cloneImpl(); }
285
286 LLVM_ABI dwarf::Tag getTag() const;
287 StringRef getHeader() const { return getStringOperand(0); }
288 MDString *getRawHeader() const { return getOperandAs<MDString>(0); }
289
290 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
291 op_iterator dwarf_op_end() const { return op_end(); }
294 }
295
296 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
297 const MDOperand &getDwarfOperand(unsigned I) const {
298 return getOperand(I + 1);
299 }
300 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
301 replaceOperandWith(I + 1, New);
302 }
303
304 static bool classof(const Metadata *MD) {
305 return MD->getMetadataID() == GenericDINodeKind;
306 }
307};
308
309/// Assignment ID.
310/// Used to link stores (as an attachment) and dbg.assigns (as an operand).
311/// DIAssignID metadata is never uniqued as we compare instances using
312/// referential equality (the instance/address is the ID).
313class DIAssignID : public MDNode {
314 friend class LLVMContextImpl;
315 friend class MDNode;
316
318 : MDNode(C, DIAssignIDKind, Storage, {}) {}
319
320 ~DIAssignID() { dropAllReferences(); }
321
322 LLVM_ABI static DIAssignID *getImpl(LLVMContext &Context, StorageType Storage,
323 bool ShouldCreate = true);
324
325 TempDIAssignID cloneImpl() const { return getTemporary(getContext()); }
326
327public:
328 // This node has no operands to replace.
329 void replaceOperandWith(unsigned I, Metadata *New) = delete;
330
332 return Context.getReplaceableUses()->getAllDbgVariableRecordUsers();
333 }
334
336 return getImpl(Context, Distinct);
337 }
338 static TempDIAssignID getTemporary(LLVMContext &Context) {
339 return TempDIAssignID(getImpl(Context, Temporary));
340 }
341 // NOTE: Do not define get(LLVMContext&) - see class comment.
342
343 static bool classof(const Metadata *MD) {
344 return MD->getMetadataID() == DIAssignIDKind;
345 }
346};
347
348/// Array subrange.
349class DISubrange : public DINode {
350 friend class LLVMContextImpl;
351 friend class MDNode;
352
354
355 ~DISubrange() = default;
356
357 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, int64_t Count,
359 bool ShouldCreate = true);
360
361 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, Metadata *CountNode,
363 bool ShouldCreate = true);
364
365 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, Metadata *CountNode,
367 Metadata *UpperBound, Metadata *Stride,
369 bool ShouldCreate = true);
370
371 TempDISubrange cloneImpl() const {
372 return getTemporary(getContext(), getRawCountNode(), getRawLowerBound(),
373 getRawUpperBound(), getRawStride());
374 }
375
376public:
377 DEFINE_MDNODE_GET(DISubrange, (int64_t Count, int64_t LowerBound = 0),
378 (Count, LowerBound))
379
382
385 Metadata *UpperBound, Metadata *Stride),
386 (CountNode, LowerBound, UpperBound, Stride))
387
388 TempDISubrange clone() const { return cloneImpl(); }
389
390 Metadata *getRawCountNode() const { return getOperand(0).get(); }
391
392 Metadata *getRawLowerBound() const { return getOperand(1).get(); }
393
394 Metadata *getRawUpperBound() const { return getOperand(2).get(); }
395
396 Metadata *getRawStride() const { return getOperand(3).get(); }
397
398 typedef PointerUnion<ConstantInt *, DIVariable *, DIExpression *> BoundType;
399
400 LLVM_ABI BoundType getCount() const;
401
402 LLVM_ABI BoundType getLowerBound() const;
403
404 LLVM_ABI BoundType getUpperBound() const;
405
406 LLVM_ABI BoundType getStride() const;
407
408 static bool classof(const Metadata *MD) {
409 return MD->getMetadataID() == DISubrangeKind;
410 }
411};
412
413class DIGenericSubrange : public DINode {
414 friend class LLVMContextImpl;
415 friend class MDNode;
416
419
420 ~DIGenericSubrange() = default;
421
423 getImpl(LLVMContext &Context, Metadata *CountNode, Metadata *LowerBound,
424 Metadata *UpperBound, Metadata *Stride, StorageType Storage,
425 bool ShouldCreate = true);
426
427 TempDIGenericSubrange cloneImpl() const {
430 }
431
432public:
434 (Metadata * CountNode, Metadata *LowerBound,
435 Metadata *UpperBound, Metadata *Stride),
436 (CountNode, LowerBound, UpperBound, Stride))
437
438 TempDIGenericSubrange clone() const { return cloneImpl(); }
439
440 Metadata *getRawCountNode() const { return getOperand(0).get(); }
441 Metadata *getRawLowerBound() const { return getOperand(1).get(); }
442 Metadata *getRawUpperBound() const { return getOperand(2).get(); }
443 Metadata *getRawStride() const { return getOperand(3).get(); }
444
446
451
452 static bool classof(const Metadata *MD) {
453 return MD->getMetadataID() == DIGenericSubrangeKind;
454 }
455};
456
457/// Enumeration value.
458///
459/// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
460/// longer creates a type cycle.
461class DIEnumerator : public DINode {
462 friend class LLVMContextImpl;
463 friend class MDNode;
464
465 APInt Value;
471 Ops) {}
472 ~DIEnumerator() = default;
473
474 static DIEnumerator *getImpl(LLVMContext &Context, const APInt &Value,
476 StorageType Storage, bool ShouldCreate = true) {
477 return getImpl(Context, Value, IsUnsigned,
478 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
479 }
480 LLVM_ABI static DIEnumerator *getImpl(LLVMContext &Context,
481 const APInt &Value, bool IsUnsigned,
482 MDString *Name, StorageType Storage,
483 bool ShouldCreate = true);
484
485 TempDIEnumerator cloneImpl() const {
487 }
488
489public:
491 (int64_t Value, bool IsUnsigned, StringRef Name),
494 (int64_t Value, bool IsUnsigned, MDString *Name),
502
503 TempDIEnumerator clone() const { return cloneImpl(); }
504
505 const APInt &getValue() const { return Value; }
506 bool isUnsigned() const { return SubclassData32; }
507 StringRef getName() const { return getStringOperand(0); }
508
509 MDString *getRawName() const { return getOperandAs<MDString>(0); }
510
511 static bool classof(const Metadata *MD) {
512 return MD->getMetadataID() == DIEnumeratorKind;
513 }
514};
515
516/// Base class for scope-like contexts.
517///
518/// Base class for lexical scopes and types (which are also declaration
519/// contexts).
520///
521/// TODO: Separate the concepts of declaration contexts and lexical scopes.
522class DIScope : public DINode {
523protected:
526 : DINode(C, ID, Storage, Tag, Ops) {}
527 ~DIScope() = default;
528
529public:
530 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
531
532 inline StringRef getFilename() const;
533 inline StringRef getDirectory() const;
534 inline std::optional<StringRef> getSource() const;
535
536 LLVM_ABI StringRef getName() const;
537 LLVM_ABI DIScope *getScope() const;
538
539 /// Return the raw underlying file.
540 ///
541 /// A \a DIFile is a \a DIScope, but it doesn't point at a separate file (it
542 /// \em is the file). If \c this is an \a DIFile, we need to return \c this.
543 /// Otherwise, return the first operand, which is where all other subclasses
544 /// store their file pointer.
546 return isa<DIFile>(this) ? const_cast<DIScope *>(this)
547 : static_cast<Metadata *>(getOperand(0));
548 }
549
550 static bool classof(const Metadata *MD) {
551 switch (MD->getMetadataID()) {
552 default:
553 return false;
554 case DIBasicTypeKind:
555 case DIFixedPointTypeKind:
556 case DIStringTypeKind:
557 case DISubrangeTypeKind:
558 case DIDerivedTypeKind:
559 case DICompositeTypeKind:
560 case DISubroutineTypeKind:
561 case DIFileKind:
562 case DICompileUnitKind:
563 case DISubprogramKind:
564 case DILexicalBlockKind:
565 case DILexicalBlockFileKind:
566 case DINamespaceKind:
567 case DICommonBlockKind:
568 case DIModuleKind:
569 return true;
570 }
571 }
572};
573
574/// File.
575///
576/// TODO: Merge with directory/file node (including users).
577/// TODO: Canonicalize paths on creation.
578class DIFile : public DIScope {
579 friend class LLVMContextImpl;
580 friend class MDNode;
581
582public:
583 /// Which algorithm (e.g. MD5) a checksum was generated with.
584 ///
585 /// The encoding is explicit because it is used directly in Bitcode. The
586 /// value 0 is reserved to indicate the absence of a checksum in Bitcode.
588 // The first variant was originally CSK_None, encoded as 0. The new
589 // internal representation removes the need for this by wrapping the
590 // ChecksumInfo in an Optional, but to preserve Bitcode compatibility the 0
591 // encoding is reserved.
595 CSK_Last = CSK_SHA256 // Should be last enumeration.
596 };
597
598 /// A single checksum, represented by a \a Kind and a \a Value (a string).
599 template <typename T> struct ChecksumInfo {
600 /// The kind of checksum which \a Value encodes.
602 /// The string value of the checksum.
604
606 ~ChecksumInfo() = default;
607 bool operator==(const ChecksumInfo<T> &X) const {
608 return Kind == X.Kind && Value == X.Value;
609 }
610 bool operator!=(const ChecksumInfo<T> &X) const { return !(*this == X); }
611 StringRef getKindAsString() const { return getChecksumKindAsString(Kind); }
612 };
613
614private:
615 std::optional<ChecksumInfo<MDString *>> Checksum;
616 /// An optional source. A nullptr means none.
617 MDString *Source;
618
620 std::optional<ChecksumInfo<MDString *>> CS, MDString *Src,
622 ~DIFile() = default;
623
624 static DIFile *getImpl(LLVMContext &Context, StringRef Filename,
626 std::optional<ChecksumInfo<StringRef>> CS,
627 std::optional<StringRef> Source, StorageType Storage,
628 bool ShouldCreate = true) {
629 std::optional<ChecksumInfo<MDString *>> MDChecksum;
630 if (CS)
631 MDChecksum.emplace(CS->Kind, getCanonicalMDString(Context, CS->Value));
632 return getImpl(Context, getCanonicalMDString(Context, Filename),
633 getCanonicalMDString(Context, Directory), MDChecksum,
634 Source ? MDString::get(Context, *Source) : nullptr, Storage,
635 ShouldCreate);
636 }
637 LLVM_ABI static DIFile *getImpl(LLVMContext &Context, MDString *Filename,
638 MDString *Directory,
639 std::optional<ChecksumInfo<MDString *>> CS,
640 MDString *Source, StorageType Storage,
641 bool ShouldCreate = true);
642
643 TempDIFile cloneImpl() const {
645 getChecksum(), getSource());
646 }
647
648public:
651 std::optional<ChecksumInfo<StringRef>> CS = std::nullopt,
652 std::optional<StringRef> Source = std::nullopt),
653 (Filename, Directory, CS, Source))
656 std::optional<ChecksumInfo<MDString *>> CS = std::nullopt,
657 MDString *Source = nullptr),
658 (Filename, Directory, CS, Source))
659
660 TempDIFile clone() const { return cloneImpl(); }
661
662 StringRef getFilename() const { return getStringOperand(0); }
663 StringRef getDirectory() const { return getStringOperand(1); }
664 std::optional<ChecksumInfo<StringRef>> getChecksum() const {
665 std::optional<ChecksumInfo<StringRef>> StringRefChecksum;
666 if (Checksum)
667 StringRefChecksum.emplace(Checksum->Kind, Checksum->Value->getString());
668 return StringRefChecksum;
669 }
670 std::optional<StringRef> getSource() const {
671 return Source ? std::optional<StringRef>(Source->getString())
672 : std::nullopt;
673 }
674
675 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
676 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
677 std::optional<ChecksumInfo<MDString *>> getRawChecksum() const {
678 return Checksum;
679 }
680 MDString *getRawSource() const { return Source; }
681
682 LLVM_ABI static StringRef getChecksumKindAsString(ChecksumKind CSKind);
683 LLVM_ABI static std::optional<ChecksumKind>
684 getChecksumKind(StringRef CSKindStr);
685
686 static bool classof(const Metadata *MD) {
687 return MD->getMetadataID() == DIFileKind;
688 }
689};
690
692 if (auto *F = getFile())
693 return F->getFilename();
694 return "";
695}
696
698 if (auto *F = getFile())
699 return F->getDirectory();
700 return "";
701}
702
703std::optional<StringRef> DIScope::getSource() const {
704 if (auto *F = getFile())
705 return F->getSource();
706 return std::nullopt;
707}
708
709/// Base class for types.
710///
711/// TODO: Remove the hardcoded name and context, since many types don't use
712/// them.
713/// TODO: Split up flags.
714///
715/// Uses the SubclassData32 Metadata slot.
716class DIType : public DIScope {
717 unsigned Line;
718 DIFlags Flags;
719 uint32_t NumExtraInhabitants;
720
721protected:
722 static constexpr unsigned N_OPERANDS = 5;
723
724 DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
725 unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants,
726 DIFlags Flags, ArrayRef<Metadata *> Ops)
727 : DIScope(C, ID, Storage, Tag, Ops) {
728 init(Line, AlignInBits, NumExtraInhabitants, Flags);
729 }
730 ~DIType() = default;
731
732 void init(unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants,
733 DIFlags Flags) {
734 this->Line = Line;
735 this->Flags = Flags;
736 this->SubclassData32 = AlignInBits;
737 this->NumExtraInhabitants = NumExtraInhabitants;
738 }
739
740 /// Change fields in place.
741 void mutate(unsigned Tag, unsigned Line, uint32_t AlignInBits,
742 uint32_t NumExtraInhabitants, DIFlags Flags) {
743 assert(isDistinct() && "Only distinct nodes can mutate");
744 setTag(Tag);
745 init(Line, AlignInBits, NumExtraInhabitants, Flags);
746 }
747
748public:
749 TempDIType clone() const {
750 return TempDIType(cast<DIType>(MDNode::clone().release()));
751 }
752
753 unsigned getLine() const { return Line; }
755 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
756 uint32_t getNumExtraInhabitants() const { return NumExtraInhabitants; }
757 DIFlags getFlags() const { return Flags; }
758
759 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
760 StringRef getName() const { return getStringOperand(2); }
761
762 Metadata *getRawScope() const { return getOperand(1); }
763 MDString *getRawName() const { return getOperandAs<MDString>(2); }
764
765 Metadata *getRawSizeInBits() const { return getOperand(3); }
767 if (auto *MD = dyn_cast_or_null<ConstantAsMetadata>(getRawSizeInBits())) {
768 if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(MD->getValue()))
769 return CI->getZExtValue();
770 }
771 return 0;
772 }
773
774 Metadata *getRawOffsetInBits() const { return getOperand(4); }
776 if (auto *MD = dyn_cast_or_null<ConstantAsMetadata>(getRawOffsetInBits())) {
777 if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(MD->getValue()))
778 return CI->getZExtValue();
779 }
780 return 0;
781 }
782
783 /// Returns a new temporary DIType with updated Flags
784 TempDIType cloneWithFlags(DIFlags NewFlags) const {
785 auto NewTy = clone();
786 NewTy->Flags = NewFlags;
787 return NewTy;
788 }
789
790 bool isPrivate() const {
791 return (getFlags() & FlagAccessibility) == FlagPrivate;
792 }
793 bool isProtected() const {
794 return (getFlags() & FlagAccessibility) == FlagProtected;
795 }
796 bool isPublic() const {
797 return (getFlags() & FlagAccessibility) == FlagPublic;
798 }
799 bool isForwardDecl() const { return getFlags() & FlagFwdDecl; }
800 bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; }
801 bool isVirtual() const { return getFlags() & FlagVirtual; }
802 bool isArtificial() const { return getFlags() & FlagArtificial; }
803 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
804 bool isObjcClassComplete() const {
805 return getFlags() & FlagObjcClassComplete;
806 }
807 bool isVector() const { return getFlags() & FlagVector; }
808 bool isBitField() const { return getFlags() & FlagBitField; }
809 bool isStaticMember() const { return getFlags() & FlagStaticMember; }
810 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
811 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
812 bool isTypePassByValue() const { return getFlags() & FlagTypePassByValue; }
814 return getFlags() & FlagTypePassByReference;
815 }
816 bool isBigEndian() const { return getFlags() & FlagBigEndian; }
817 bool isLittleEndian() const { return getFlags() & FlagLittleEndian; }
818 bool getExportSymbols() const { return getFlags() & FlagExportSymbols; }
819
820 static bool classof(const Metadata *MD) {
821 switch (MD->getMetadataID()) {
822 default:
823 return false;
824 case DIBasicTypeKind:
825 case DIFixedPointTypeKind:
826 case DIStringTypeKind:
827 case DISubrangeTypeKind:
828 case DIDerivedTypeKind:
829 case DICompositeTypeKind:
830 case DISubroutineTypeKind:
831 return true;
832 }
833 }
834};
835
836/// Basic type, like 'int' or 'float'.
837///
838/// TODO: Split out DW_TAG_unspecified_type.
839/// TODO: Drop unused accessors.
840class DIBasicType : public DIType {
841 friend class LLVMContextImpl;
842 friend class MDNode;
843
844 unsigned Encoding;
845
846protected:
848 uint32_t AlignInBits, unsigned Encoding,
851 : DIType(C, DIBasicTypeKind, Storage, Tag, 0, AlignInBits,
853 Encoding(Encoding) {}
855 uint32_t AlignInBits, unsigned Encoding,
859 Ops),
860 Encoding(Encoding) {}
861 ~DIBasicType() = default;
862
863 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
865 uint32_t AlignInBits, unsigned Encoding,
867 StorageType Storage, bool ShouldCreate = true) {
870 Flags, Storage, ShouldCreate);
871 }
872 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
874 uint32_t AlignInBits, unsigned Encoding,
876 StorageType Storage, bool ShouldCreate = true) {
877 auto *SizeInBitsNode = ConstantAsMetadata::get(
878 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
879 return getImpl(Context, Tag, Name, SizeInBitsNode, AlignInBits, Encoding,
880 NumExtraInhabitants, Flags, Storage, ShouldCreate);
881 }
882 LLVM_ABI static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
884 uint32_t AlignInBits, unsigned Encoding,
887 bool ShouldCreate = true);
888
889 TempDIBasicType cloneImpl() const {
893 }
894
895public:
897 (Tag, Name, 0, 0, 0, 0, FlagZero))
900 (Tag, Name, SizeInBits, 0, 0, 0, FlagZero))
902 (unsigned Tag, MDString *Name, uint64_t SizeInBits),
903 (Tag, Name, SizeInBits, 0, 0, 0, FlagZero))
906 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
907 (Tag, Name, SizeInBits, AlignInBits, Encoding, 0, Flags))
909 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
910 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
911 (Tag, Name, SizeInBits, AlignInBits, Encoding, 0, Flags))
914 uint32_t AlignInBits, unsigned Encoding,
919 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
920 uint32_t AlignInBits, unsigned Encoding,
922 (Tag, Name, SizeInBits, AlignInBits, Encoding,
926 uint32_t AlignInBits, unsigned Encoding,
930
931 TempDIBasicType clone() const { return cloneImpl(); }
932
933 unsigned getEncoding() const { return Encoding; }
934
935 enum class Signedness { Signed, Unsigned };
936
937 /// Return the signedness of this type, or std::nullopt if this type is
938 /// neither signed nor unsigned.
939 LLVM_ABI std::optional<Signedness> getSignedness() const;
940
941 static bool classof(const Metadata *MD) {
942 return MD->getMetadataID() == DIBasicTypeKind ||
943 MD->getMetadataID() == DIFixedPointTypeKind;
944 }
945};
946
947/// Fixed-point type.
949 friend class LLVMContextImpl;
950 friend class MDNode;
951
952 // Actually FixedPointKind.
953 unsigned Kind;
954 // Used for binary and decimal.
955 int Factor;
956 // Used for rational.
957 APInt Numerator;
958 APInt Denominator;
959
962 unsigned Kind, int Factor, ArrayRef<Metadata *> Ops)
963 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, AlignInBits,
964 Encoding, 0, Flags, Ops),
965 Kind(Kind), Factor(Factor) {
966 assert(Kind == FixedPointBinary || Kind == FixedPointDecimal);
967 }
970 unsigned Kind, APInt Numerator, APInt Denominator,
972 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, AlignInBits,
973 Encoding, 0, Flags, Ops),
974 Kind(Kind), Factor(0), Numerator(Numerator), Denominator(Denominator) {
975 assert(Kind == FixedPointRational);
976 }
977 DIFixedPointType(LLVMContext &C, StorageType Storage, unsigned Tag,
979 unsigned Kind, int Factor, APInt Numerator,
980 APInt Denominator, ArrayRef<Metadata *> Ops)
981 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, AlignInBits,
982 Encoding, 0, Flags, Ops),
983 Kind(Kind), Factor(Factor), Numerator(Numerator),
984 Denominator(Denominator) {}
985 ~DIFixedPointType() = default;
986
987 static DIFixedPointType *
988 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name,
990 DIFlags Flags, unsigned Kind, int Factor, APInt Numerator,
991 APInt Denominator, StorageType Storage, bool ShouldCreate = true) {
992 auto *SizeInBitsNode = ConstantAsMetadata::get(
993 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
994 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
995 SizeInBitsNode, AlignInBits, Encoding, Flags, Kind, Factor,
996 Numerator, Denominator, Storage, ShouldCreate);
997 }
998 static DIFixedPointType *
999 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name,
1001 DIFlags Flags, unsigned Kind, int Factor, APInt Numerator,
1002 APInt Denominator, StorageType Storage, bool ShouldCreate = true) {
1003 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
1004 SizeInBits, AlignInBits, Encoding, Flags, Kind, Factor,
1005 Numerator, Denominator, Storage, ShouldCreate);
1006 }
1007 static DIFixedPointType *
1008 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name,
1010 DIFlags Flags, unsigned Kind, int Factor, APInt Numerator,
1011 APInt Denominator, StorageType Storage, bool ShouldCreate = true) {
1012 auto *SizeInBitsNode = ConstantAsMetadata::get(
1013 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1014 return getImpl(Context, Tag, Name, SizeInBitsNode, AlignInBits, Encoding,
1015 Flags, Kind, Factor, Numerator, Denominator, Storage,
1016 ShouldCreate);
1017 }
1018 LLVM_ABI static DIFixedPointType *
1019 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name,
1021 DIFlags Flags, unsigned Kind, int Factor, APInt Numerator,
1022 APInt Denominator, StorageType Storage, bool ShouldCreate = true);
1023
1024 TempDIFixedPointType cloneImpl() const {
1027 getFlags(), Kind, Factor, Numerator, Denominator);
1028 }
1029
1030public:
1031 enum FixedPointKind : unsigned {
1032 /// Scale factor 2^Factor.
1034 /// Scale factor 10^Factor.
1036 /// Arbitrary rational scale factor.
1039 };
1040
1041 LLVM_ABI static std::optional<FixedPointKind>
1043 LLVM_ABI static const char *fixedPointKindString(FixedPointKind);
1044
1046 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
1048 unsigned Kind, int Factor, APInt Numerator,
1049 APInt Denominator),
1051 Factor, Numerator, Denominator))
1055 unsigned Kind, int Factor, APInt Numerator,
1056 APInt Denominator),
1058 Factor, Numerator, Denominator))
1060 (unsigned Tag, MDString *Name, Metadata *SizeInBits,
1062 unsigned Kind, int Factor, APInt Numerator,
1063 APInt Denominator),
1065 Factor, Numerator, Denominator))
1066
1067 TempDIFixedPointType clone() const { return cloneImpl(); }
1068
1069 bool isBinary() const { return Kind == FixedPointBinary; }
1070 bool isDecimal() const { return Kind == FixedPointDecimal; }
1071 bool isRational() const { return Kind == FixedPointRational; }
1072
1073 LLVM_ABI bool isSigned() const;
1074
1075 FixedPointKind getKind() const { return static_cast<FixedPointKind>(Kind); }
1076
1077 int getFactorRaw() const { return Factor; }
1078 int getFactor() const {
1079 assert(Kind == FixedPointBinary || Kind == FixedPointDecimal);
1080 return Factor;
1081 }
1082
1083 const APInt &getNumeratorRaw() const { return Numerator; }
1084 const APInt &getNumerator() const {
1085 assert(Kind == FixedPointRational);
1086 return Numerator;
1087 }
1088
1089 const APInt &getDenominatorRaw() const { return Denominator; }
1090 const APInt &getDenominator() const {
1091 assert(Kind == FixedPointRational);
1092 return Denominator;
1093 }
1094
1095 static bool classof(const Metadata *MD) {
1096 return MD->getMetadataID() == DIFixedPointTypeKind;
1097 }
1098};
1099
1100/// String type, Fortran CHARACTER(n)
1101class DIStringType : public DIType {
1102 friend class LLVMContextImpl;
1103 friend class MDNode;
1104
1105 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1106
1107 unsigned Encoding;
1108
1110 uint32_t AlignInBits, unsigned Encoding,
1112 : DIType(C, DIStringTypeKind, Storage, Tag, 0, AlignInBits, 0, FlagZero,
1113 Ops),
1114 Encoding(Encoding) {}
1115 ~DIStringType() = default;
1116
1117 static DIStringType *getImpl(LLVMContext &Context, unsigned Tag,
1119 Metadata *StrLenExp, Metadata *StrLocationExp,
1121 unsigned Encoding, StorageType Storage,
1122 bool ShouldCreate = true) {
1123 auto *SizeInBitsNode = ConstantAsMetadata::get(
1124 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1125 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
1126 StringLength, StrLenExp, StrLocationExp, SizeInBitsNode,
1127 AlignInBits, Encoding, Storage, ShouldCreate);
1128 }
1129 static DIStringType *getImpl(LLVMContext &Context, unsigned Tag,
1130 MDString *Name, Metadata *StringLength,
1131 Metadata *StrLenExp, Metadata *StrLocationExp,
1133 unsigned Encoding, StorageType Storage,
1134 bool ShouldCreate = true) {
1135 auto *SizeInBitsNode = ConstantAsMetadata::get(
1136 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1137 return getImpl(Context, Tag, Name, StringLength, StrLenExp, StrLocationExp,
1138 SizeInBitsNode, AlignInBits, Encoding, Storage,
1139 ShouldCreate);
1140 }
1141 LLVM_ABI static DIStringType *
1142 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name,
1143 Metadata *StringLength, Metadata *StrLenExp, Metadata *StrLocationExp,
1144 Metadata *SizeInBits, uint32_t AlignInBits, unsigned Encoding,
1145 StorageType Storage, bool ShouldCreate = true);
1146
1147 TempDIStringType cloneImpl() const {
1152 }
1153
1154public:
1156 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
1158 (Tag, Name, nullptr, nullptr, nullptr, SizeInBits,
1159 AlignInBits, 0))
1164 unsigned Encoding),
1168 (unsigned Tag, StringRef Name, Metadata *StringLength,
1171 unsigned Encoding),
1178 unsigned Encoding),
1181
1182 TempDIStringType clone() const { return cloneImpl(); }
1183
1184 static bool classof(const Metadata *MD) {
1185 return MD->getMetadataID() == DIStringTypeKind;
1186 }
1187
1189 return cast_or_null<DIVariable>(getRawStringLength());
1190 }
1191
1193 return cast_or_null<DIExpression>(getRawStringLengthExp());
1194 }
1195
1197 return cast_or_null<DIExpression>(getRawStringLocationExp());
1198 }
1199
1200 unsigned getEncoding() const { return Encoding; }
1201
1202 Metadata *getRawStringLength() const { return getOperand(MY_FIRST_OPERAND); }
1203
1205 return getOperand(MY_FIRST_OPERAND + 1);
1206 }
1207
1209 return getOperand(MY_FIRST_OPERAND + 2);
1210 }
1211};
1212
1213/// Derived types.
1214///
1215/// This includes qualified types, pointers, references, friends, typedefs, and
1216/// class members.
1217///
1218/// TODO: Split out members (inheritance, fields, methods, etc.).
1219class DIDerivedType : public DIType {
1220public:
1221 /// Pointer authentication (__ptrauth) metadata.
1223 // RawData layout:
1224 // - Bits 0..3: Key
1225 // - Bit 4: IsAddressDiscriminated
1226 // - Bits 5..20: ExtraDiscriminator
1227 // - Bit 21: IsaPointer
1228 // - Bit 22: AuthenticatesNullValues
1229 unsigned RawData;
1230
1231 PtrAuthData(unsigned FromRawData) : RawData(FromRawData) {}
1232 PtrAuthData(unsigned Key, bool IsDiscr, unsigned Discriminator,
1233 bool IsaPointer, bool AuthenticatesNullValues) {
1234 assert(Key < 16);
1235 assert(Discriminator <= 0xffff);
1236 RawData = (Key << 0) | (IsDiscr ? (1 << 4) : 0) | (Discriminator << 5) |
1237 (IsaPointer ? (1 << 21) : 0) |
1238 (AuthenticatesNullValues ? (1 << 22) : 0);
1239 }
1240
1241 unsigned key() { return (RawData >> 0) & 0b1111; }
1242 bool isAddressDiscriminated() { return (RawData >> 4) & 1; }
1243 unsigned extraDiscriminator() { return (RawData >> 5) & 0xffff; }
1244 bool isaPointer() { return (RawData >> 21) & 1; }
1245 bool authenticatesNullValues() { return (RawData >> 22) & 1; }
1246 };
1247
1248private:
1249 friend class LLVMContextImpl;
1250 friend class MDNode;
1251
1252 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1253
1254 /// The DWARF address space of the memory pointed to or referenced by a
1255 /// pointer or reference type respectively.
1256 std::optional<unsigned> DWARFAddressSpace;
1257
1259 unsigned Line, uint32_t AlignInBits,
1260 std::optional<unsigned> DWARFAddressSpace,
1261 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1263 : DIType(C, DIDerivedTypeKind, Storage, Tag, Line, AlignInBits, 0, Flags,
1264 Ops),
1265 DWARFAddressSpace(DWARFAddressSpace) {
1266 if (PtrAuthData)
1268 }
1269 ~DIDerivedType() = default;
1270 static DIDerivedType *
1271 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1274 std::optional<unsigned> DWARFAddressSpace,
1275 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1277 bool ShouldCreate = true) {
1278 auto *SizeInBitsNode = ConstantAsMetadata::get(
1279 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1280 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1281 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1282 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1283 Line, Scope, BaseType, SizeInBitsNode, AlignInBits,
1284 OffsetInBitsNode, DWARFAddressSpace, PtrAuthData, Flags,
1285 ExtraData, Annotations.get(), Storage, ShouldCreate);
1286 }
1287 static DIDerivedType *
1288 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, DIFile *File,
1289 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1291 std::optional<unsigned> DWARFAddressSpace,
1292 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1294 bool ShouldCreate = true) {
1295 auto *SizeInBitsNode = ConstantAsMetadata::get(
1296 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1297 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1298 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1299 return getImpl(Context, Tag, Name, File, Line, Scope, BaseType,
1300 SizeInBitsNode, AlignInBits, OffsetInBitsNode,
1301 DWARFAddressSpace, PtrAuthData, Flags, ExtraData,
1302 Annotations.get(), Storage, ShouldCreate);
1303 }
1304 static DIDerivedType *
1305 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1306 unsigned Line, DIScope *Scope, DIType *BaseType, Metadata *SizeInBits,
1308 std::optional<unsigned> DWARFAddressSpace,
1309 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1311 bool ShouldCreate = true) {
1312 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1314 DWARFAddressSpace, PtrAuthData, Flags, ExtraData,
1315 Annotations.get(), Storage, ShouldCreate);
1316 }
1317 LLVM_ABI static DIDerivedType *
1318 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1319 unsigned Line, Metadata *Scope, Metadata *BaseType,
1321 std::optional<unsigned> DWARFAddressSpace,
1322 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1324 bool ShouldCreate = true);
1325
1326 TempDIDerivedType cloneImpl() const {
1327 return getTemporary(
1330 getRawOffsetInBits(), getDWARFAddressSpace(), getPtrAuthData(),
1332 }
1333
1334public:
1336 (unsigned Tag, MDString *Name, Metadata *File,
1337 unsigned Line, Metadata *Scope, Metadata *BaseType,
1340 std::optional<unsigned> DWARFAddressSpace,
1341 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1342 Metadata *ExtraData = nullptr,
1343 Metadata *Annotations = nullptr),
1345 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1348 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1351 std::optional<unsigned> DWARFAddressSpace,
1352 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1354 DINodeArray Annotations = nullptr),
1356 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1359 (unsigned Tag, MDString *Name, DIFile *File, unsigned Line,
1362 std::optional<unsigned> DWARFAddressSpace,
1363 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1364 Metadata *ExtraData = nullptr,
1365 DINodeArray Annotations = nullptr),
1367 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1370 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1373 std::optional<unsigned> DWARFAddressSpace,
1374 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1375 Metadata *ExtraData = nullptr,
1376 DINodeArray Annotations = nullptr),
1378 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1380
1381 TempDIDerivedType clone() const { return cloneImpl(); }
1382
1383 /// Get the base type this is derived from.
1384 DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); }
1385 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1386
1387 /// \returns The DWARF address space of the memory pointed to or referenced by
1388 /// a pointer or reference type respectively.
1389 std::optional<unsigned> getDWARFAddressSpace() const {
1390 return DWARFAddressSpace;
1391 }
1392
1393 LLVM_ABI std::optional<PtrAuthData> getPtrAuthData() const;
1394
1395 /// Get extra data associated with this derived type.
1396 ///
1397 /// Class type for pointer-to-members, objective-c property node for ivars,
1398 /// global constant wrapper for static members, virtual base pointer offset
1399 /// for inheritance, a tuple of template parameters for template aliases,
1400 /// discriminant for a variant, or storage offset for a bit field.
1401 ///
1402 /// TODO: Separate out types that need this extra operand: pointer-to-member
1403 /// types and member fields (static members and ivars).
1405 Metadata *getRawExtraData() const { return getOperand(MY_FIRST_OPERAND + 1); }
1406
1407 /// Get the template parameters from a template alias.
1408 DITemplateParameterArray getTemplateParams() const {
1409 return cast_or_null<MDTuple>(getExtraData());
1410 }
1411
1412 /// Get annotations associated with this derived type.
1413 DINodeArray getAnnotations() const {
1414 return cast_or_null<MDTuple>(getRawAnnotations());
1415 }
1417 return getOperand(MY_FIRST_OPERAND + 2);
1418 }
1419
1420 /// Get casted version of extra data.
1421 /// @{
1422 LLVM_ABI DIType *getClassType() const;
1423
1425 return dyn_cast_or_null<DIObjCProperty>(getExtraData());
1426 }
1427
1429
1431
1432 LLVM_ABI Constant *getConstant() const;
1433
1435 /// @}
1436
1437 static bool classof(const Metadata *MD) {
1438 return MD->getMetadataID() == DIDerivedTypeKind;
1439 }
1440};
1441
1444 return Lhs.RawData == Rhs.RawData;
1445}
1446
1449 return !(Lhs == Rhs);
1450}
1451
1452/// Subrange type. This is somewhat similar to DISubrange, but it
1453/// is also a DIType.
1454class DISubrangeType : public DIType {
1455public:
1457
1458private:
1459 friend class LLVMContextImpl;
1460 friend class MDNode;
1461
1462 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1463
1466
1467 ~DISubrangeType() = default;
1468
1469 static DISubrangeType *
1470 getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
1474 StorageType Storage, bool ShouldCreate = true) {
1475 auto *SizeInBitsNode = ConstantAsMetadata::get(
1476 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1477 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1478 Scope, SizeInBitsNode, AlignInBits, Flags, BaseType,
1479 LowerBound, UpperBound, Stride, Bias, Storage, ShouldCreate);
1480 }
1481
1482 LLVM_ABI static DISubrangeType *
1483 getImpl(LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
1487 StorageType Storage, bool ShouldCreate = true);
1488
1489 TempDISubrangeType cloneImpl() const {
1494 }
1495
1496 LLVM_ABI BoundType convertRawToBound(Metadata *IN) const;
1497
1498public:
1500 (MDString * Name, Metadata *File, unsigned Line,
1514
1515 TempDISubrangeType clone() const { return cloneImpl(); }
1516
1517 /// Get the base type this is derived from.
1518 DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); }
1519 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1520
1522 return getOperand(MY_FIRST_OPERAND + 1).get();
1523 }
1524
1526 return getOperand(MY_FIRST_OPERAND + 2).get();
1527 }
1528
1530 return getOperand(MY_FIRST_OPERAND + 3).get();
1531 }
1532
1534 return getOperand(MY_FIRST_OPERAND + 4).get();
1535 }
1536
1538 return convertRawToBound(getRawLowerBound());
1539 }
1540
1542 return convertRawToBound(getRawUpperBound());
1543 }
1544
1545 BoundType getStride() const { return convertRawToBound(getRawStride()); }
1546
1547 BoundType getBias() const { return convertRawToBound(getRawBias()); }
1548
1549 static bool classof(const Metadata *MD) {
1550 return MD->getMetadataID() == DISubrangeTypeKind;
1551 }
1552};
1553
1554/// Composite types.
1555///
1556/// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
1557/// TODO: Create a custom, unrelated node for DW_TAG_array_type.
1558class DICompositeType : public DIType {
1559 friend class LLVMContextImpl;
1560 friend class MDNode;
1561
1562 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1563
1564 unsigned RuntimeLang;
1565 std::optional<uint32_t> EnumKind;
1566
1568 unsigned Line, unsigned RuntimeLang, uint32_t AlignInBits,
1570 std::optional<uint32_t> EnumKind, DIFlags Flags,
1572 : DIType(C, DICompositeTypeKind, Storage, Tag, Line, AlignInBits,
1574 RuntimeLang(RuntimeLang), EnumKind(EnumKind) {}
1575 ~DICompositeType() = default;
1576
1577 /// Change fields in place.
1578 void mutate(unsigned Tag, unsigned Line, unsigned RuntimeLang,
1580 std::optional<uint32_t> EnumKind, DIFlags Flags) {
1581 assert(isDistinct() && "Only distinct nodes can mutate");
1582 assert(getRawIdentifier() && "Only ODR-uniqued nodes should mutate");
1583 this->RuntimeLang = RuntimeLang;
1584 this->EnumKind = EnumKind;
1586 }
1587
1588 static DICompositeType *
1589 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
1590 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1593 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1594 DIType *VTableHolder, DITemplateParameterArray TemplateParams,
1595 StringRef Identifier, DIDerivedType *Discriminator,
1597 Metadata *Rank, DINodeArray Annotations, Metadata *BitStride,
1598 StorageType Storage, bool ShouldCreate = true) {
1599 auto *SizeInBitsNode = ConstantAsMetadata::get(
1600 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1601 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1602 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1603 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1604 Line, Scope, BaseType, SizeInBitsNode, AlignInBits,
1605 OffsetInBitsNode, Flags, Elements.get(), RuntimeLang,
1606 EnumKind, VTableHolder, TemplateParams.get(),
1610 ShouldCreate);
1611 }
1612 static DICompositeType *
1613 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1614 unsigned Line, Metadata *Scope, Metadata *BaseType,
1616 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
1617 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1622 Metadata *BitStride, StorageType Storage, bool ShouldCreate = true) {
1623 auto *SizeInBitsNode = ConstantAsMetadata::get(
1624 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1625 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1626 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1627 return getImpl(Context, Tag, Name, File, Line, Scope, BaseType,
1628 SizeInBitsNode, AlignInBits, OffsetInBitsNode, Flags,
1629 Elements, RuntimeLang, EnumKind, VTableHolder,
1632 NumExtraInhabitants, BitStride, Storage, ShouldCreate);
1633 }
1634 static DICompositeType *
1635 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
1636 unsigned Line, DIScope *Scope, DIType *BaseType, Metadata *SizeInBits,
1639 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1640 DIType *VTableHolder, DITemplateParameterArray TemplateParams,
1641 StringRef Identifier, DIDerivedType *Discriminator,
1643 Metadata *Rank, DINodeArray Annotations, Metadata *BitStride,
1644 StorageType Storage, bool ShouldCreate = true) {
1645 return getImpl(
1646 Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
1648 RuntimeLang, EnumKind, VTableHolder, TemplateParams.get(),
1651 NumExtraInhabitants, BitStride, Storage, ShouldCreate);
1652 }
1653 LLVM_ABI static DICompositeType *
1654 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1655 unsigned Line, Metadata *Scope, Metadata *BaseType,
1657 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
1658 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1663 Metadata *BitStride, StorageType Storage, bool ShouldCreate = true);
1664
1665 TempDICompositeType cloneImpl() const {
1666 return getTemporary(
1674 getRawBitStride());
1675 }
1676
1677public:
1680 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1683 DINodeArray Elements, unsigned RuntimeLang,
1684 std::optional<uint32_t> EnumKind, DIType *VTableHolder,
1685 DITemplateParameterArray TemplateParams = nullptr,
1687 Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
1688 Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
1689 DINodeArray Annotations = nullptr, DIType *Specification = nullptr,
1693 RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier,
1695 BitStride))
1698 (unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
1701 Metadata *Elements, unsigned RuntimeLang,
1702 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1705 Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
1706 Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
1708 Metadata *BitStride = nullptr),
1710 OffsetInBits, Flags, Elements, RuntimeLang, EnumKind, VTableHolder,
1713 BitStride))
1716 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1719 DINodeArray Elements, unsigned RuntimeLang,
1720 std::optional<uint32_t> EnumKind, DIType *VTableHolder,
1721 DITemplateParameterArray TemplateParams = nullptr,
1723 Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
1724 Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
1725 DINodeArray Annotations = nullptr, DIType *Specification = nullptr,
1729 RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier,
1731 BitStride))
1734 (unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
1737 Metadata *Elements, unsigned RuntimeLang,
1738 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1739 Metadata *TemplateParams = nullptr, MDString *Identifier = nullptr,
1740 Metadata *Discriminator = nullptr, Metadata *DataLocation = nullptr,
1741 Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
1742 Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
1744 Metadata *BitStride = nullptr),
1746 OffsetInBits, Flags, Elements, RuntimeLang, EnumKind, VTableHolder,
1749 BitStride))
1750
1751 TempDICompositeType clone() const { return cloneImpl(); }
1752
1753 /// Get a DICompositeType with the given ODR identifier.
1754 ///
1755 /// If \a LLVMContext::isODRUniquingDebugTypes(), gets the mapped
1756 /// DICompositeType for the given ODR \c Identifier. If none exists, creates
1757 /// a new node.
1758 ///
1759 /// Else, returns \c nullptr.
1760 LLVM_ABI static DICompositeType *
1761 getODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1762 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1766 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1773
1774 /// Build a DICompositeType with the given ODR identifier.
1775 ///
1776 /// Looks up the mapped DICompositeType for the given ODR \c Identifier. If
1777 /// it doesn't exist, creates a new one. If it does exist and \a
1778 /// isForwardDecl(), and the new arguments would be a definition, mutates the
1779 /// the type in place. In either case, returns the type.
1780 ///
1781 /// If not \a LLVMContext::isODRUniquingDebugTypes(), this function returns
1782 /// nullptr.
1783 LLVM_ABI static DICompositeType *
1784 buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1785 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1789 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1794
1795 DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); }
1796 DINodeArray getElements() const {
1797 return cast_or_null<MDTuple>(getRawElements());
1798 }
1800 return cast_or_null<DIType>(getRawVTableHolder());
1801 }
1802 DITemplateParameterArray getTemplateParams() const {
1803 return cast_or_null<MDTuple>(getRawTemplateParams());
1804 }
1806 return getStringOperand(MY_FIRST_OPERAND + 4);
1807 }
1808 unsigned getRuntimeLang() const { return RuntimeLang; }
1809 std::optional<uint32_t> getEnumKind() const { return EnumKind; }
1810
1811 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1812 Metadata *getRawElements() const { return getOperand(MY_FIRST_OPERAND + 1); }
1814 return getOperand(MY_FIRST_OPERAND + 2);
1815 }
1817 return getOperand(MY_FIRST_OPERAND + 3);
1818 }
1820 return getOperandAs<MDString>(MY_FIRST_OPERAND + 4);
1821 }
1823 return getOperand(MY_FIRST_OPERAND + 5);
1824 }
1826 return getOperandAs<DIDerivedType>(MY_FIRST_OPERAND + 5);
1827 }
1829 return getOperand(MY_FIRST_OPERAND + 6);
1830 }
1832 return dyn_cast_or_null<DIVariable>(getRawDataLocation());
1833 }
1835 return dyn_cast_or_null<DIExpression>(getRawDataLocation());
1836 }
1838 return getOperand(MY_FIRST_OPERAND + 7);
1839 }
1841 return dyn_cast_or_null<DIVariable>(getRawAssociated());
1842 }
1844 return dyn_cast_or_null<DIExpression>(getRawAssociated());
1845 }
1846 Metadata *getRawAllocated() const { return getOperand(MY_FIRST_OPERAND + 8); }
1848 return dyn_cast_or_null<DIVariable>(getRawAllocated());
1849 }
1851 return dyn_cast_or_null<DIExpression>(getRawAllocated());
1852 }
1853 Metadata *getRawRank() const { return getOperand(MY_FIRST_OPERAND + 9); }
1855 if (auto *MD = dyn_cast_or_null<ConstantAsMetadata>(getRawRank()))
1856 return dyn_cast_or_null<ConstantInt>(MD->getValue());
1857 return nullptr;
1858 }
1860 return dyn_cast_or_null<DIExpression>(getRawRank());
1861 }
1862
1864 return getOperand(MY_FIRST_OPERAND + 10);
1865 }
1866 DINodeArray getAnnotations() const {
1867 return cast_or_null<MDTuple>(getRawAnnotations());
1868 }
1869
1871 return getOperand(MY_FIRST_OPERAND + 11);
1872 }
1874 return cast_or_null<DIType>(getRawSpecification());
1875 }
1876
1878 return getOperand(MY_FIRST_OPERAND + 12);
1879 }
1881 if (auto *MD = dyn_cast_or_null<ConstantAsMetadata>(getRawBitStride()))
1882 return dyn_cast_or_null<ConstantInt>(MD->getValue());
1883 return nullptr;
1884 }
1885
1886 /// Replace operands.
1887 ///
1888 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
1889 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
1890 /// of its movement if necessary.
1891 /// @{
1892 void replaceElements(DINodeArray Elements) {
1893#ifndef NDEBUG
1894 for (DINode *Op : getElements())
1895 assert(is_contained(Elements->operands(), Op) &&
1896 "Lost a member during member list replacement");
1897#endif
1898 replaceOperandWith(MY_FIRST_OPERAND + 1, Elements.get());
1899 }
1900
1902 replaceOperandWith(MY_FIRST_OPERAND + 2, VTableHolder);
1903 }
1904
1905 void replaceTemplateParams(DITemplateParameterArray TemplateParams) {
1906 replaceOperandWith(MY_FIRST_OPERAND + 3, TemplateParams.get());
1907 }
1908 /// @}
1909
1910 static bool classof(const Metadata *MD) {
1911 return MD->getMetadataID() == DICompositeTypeKind;
1912 }
1913};
1914
1915/// Type array for a subprogram.
1916///
1917/// TODO: Fold the array of types in directly as operands.
1918class DISubroutineType : public DIType {
1919 friend class LLVMContextImpl;
1920 friend class MDNode;
1921
1922 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1923
1924 /// The calling convention used with DW_AT_calling_convention. Actually of
1925 /// type dwarf::CallingConvention.
1926 uint8_t CC;
1927
1930 ~DISubroutineType() = default;
1931
1932 static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
1935 bool ShouldCreate = true) {
1936 return getImpl(Context, Flags, CC, TypeArray.get(), Storage, ShouldCreate);
1937 }
1938 LLVM_ABI static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
1941 bool ShouldCreate = true);
1942
1943 TempDISubroutineType cloneImpl() const {
1945 }
1946
1947public:
1950 (Flags, CC, TypeArray))
1954
1955 TempDISubroutineType clone() const { return cloneImpl(); }
1956 // Returns a new temporary DISubroutineType with updated CC
1957 TempDISubroutineType cloneWithCC(uint8_t CC) const {
1958 auto NewTy = clone();
1959 NewTy->CC = CC;
1960 return NewTy;
1961 }
1962
1963 uint8_t getCC() const { return CC; }
1964
1966 return cast_or_null<MDTuple>(getRawTypeArray());
1967 }
1968
1969 Metadata *getRawTypeArray() const { return getOperand(MY_FIRST_OPERAND); }
1970
1971 static bool classof(const Metadata *MD) {
1972 return MD->getMetadataID() == DISubroutineTypeKind;
1973 }
1974};
1975
1976/// Compile unit.
1977class DICompileUnit : public DIScope {
1978 friend class LLVMContextImpl;
1979 friend class MDNode;
1980
1981public:
1982 enum DebugEmissionKind : unsigned {
1989
1990 enum class DebugNameTableKind : unsigned {
1991 Default = 0,
1992 GNU = 1,
1993 None = 2,
1994 Apple = 3,
1996 };
1997
1998 LLVM_ABI static std::optional<DebugEmissionKind>
2000 LLVM_ABI static const char *emissionKindString(DebugEmissionKind EK);
2001 LLVM_ABI static std::optional<DebugNameTableKind>
2003 LLVM_ABI static const char *nameTableKindString(DebugNameTableKind PK);
2004
2005private:
2006 unsigned SourceLanguage;
2007 unsigned RuntimeVersion;
2008 uint64_t DWOId;
2009 unsigned EmissionKind;
2010 unsigned NameTableKind;
2011 bool IsOptimized;
2012 bool SplitDebugInlining;
2013 bool DebugInfoForProfiling;
2014 bool RangesBaseAddress;
2015
2017 bool IsOptimized, unsigned RuntimeVersion,
2018 unsigned EmissionKind, uint64_t DWOId, bool SplitDebugInlining,
2019 bool DebugInfoForProfiling, unsigned NameTableKind,
2020 bool RangesBaseAddress, ArrayRef<Metadata *> Ops);
2021 ~DICompileUnit() = default;
2022
2023 static DICompileUnit *
2024 getImpl(LLVMContext &Context, unsigned SourceLanguage, DIFile *File,
2025 StringRef Producer, bool IsOptimized, StringRef Flags,
2026 unsigned RuntimeVersion, StringRef SplitDebugFilename,
2027 unsigned EmissionKind, DICompositeTypeArray EnumTypes,
2028 DIScopeArray RetainedTypes,
2029 DIGlobalVariableExpressionArray GlobalVariables,
2030 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
2031 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
2032 unsigned NameTableKind, bool RangesBaseAddress, StringRef SysRoot,
2033 StringRef SDK, StorageType Storage, bool ShouldCreate = true) {
2034 return getImpl(
2035 Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
2036 IsOptimized, getCanonicalMDString(Context, Flags), RuntimeVersion,
2037 getCanonicalMDString(Context, SplitDebugFilename), EmissionKind,
2038 EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
2039 ImportedEntities.get(), Macros.get(), DWOId, SplitDebugInlining,
2040 DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
2041 getCanonicalMDString(Context, SysRoot),
2042 getCanonicalMDString(Context, SDK), Storage, ShouldCreate);
2043 }
2044 LLVM_ABI static DICompileUnit *
2045 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
2046 MDString *Producer, bool IsOptimized, MDString *Flags,
2047 unsigned RuntimeVersion, MDString *SplitDebugFilename,
2048 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
2050 Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining,
2051 bool DebugInfoForProfiling, unsigned NameTableKind,
2052 bool RangesBaseAddress, MDString *SysRoot, MDString *SDK,
2053 StorageType Storage, bool ShouldCreate = true);
2054
2055 TempDICompileUnit cloneImpl() const {
2056 return getTemporary(
2063 }
2064
2065public:
2066 static void get() = delete;
2067 static void getIfExists() = delete;
2068
2072 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
2074 DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes,
2075 DIGlobalVariableExpressionArray GlobalVariables,
2076 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
2077 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
2078 DebugNameTableKind NameTableKind, bool RangesBaseAddress,
2080 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
2082 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
2083 DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress,
2084 SysRoot, SDK))
2088 bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
2092 bool SplitDebugInlining, bool DebugInfoForProfiling,
2093 unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
2095 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
2097 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
2098 DebugInfoForProfiling, NameTableKind, RangesBaseAddress, SysRoot, SDK))
2099
2100 TempDICompileUnit clone() const { return cloneImpl(); }
2101
2102 unsigned getSourceLanguage() const { return SourceLanguage; }
2103 bool isOptimized() const { return IsOptimized; }
2104 unsigned getRuntimeVersion() const { return RuntimeVersion; }
2106 return (DebugEmissionKind)EmissionKind;
2107 }
2109 return EmissionKind == DebugDirectivesOnly;
2110 }
2111 bool getDebugInfoForProfiling() const { return DebugInfoForProfiling; }
2113 return (DebugNameTableKind)NameTableKind;
2114 }
2115 bool getRangesBaseAddress() const { return RangesBaseAddress; }
2117 StringRef getFlags() const { return getStringOperand(2); }
2119 DICompositeTypeArray getEnumTypes() const {
2120 return cast_or_null<MDTuple>(getRawEnumTypes());
2121 }
2122 DIScopeArray getRetainedTypes() const {
2123 return cast_or_null<MDTuple>(getRawRetainedTypes());
2124 }
2125 DIGlobalVariableExpressionArray getGlobalVariables() const {
2126 return cast_or_null<MDTuple>(getRawGlobalVariables());
2127 }
2128 DIImportedEntityArray getImportedEntities() const {
2129 return cast_or_null<MDTuple>(getRawImportedEntities());
2130 }
2131 DIMacroNodeArray getMacros() const {
2132 return cast_or_null<MDTuple>(getRawMacros());
2133 }
2134 uint64_t getDWOId() const { return DWOId; }
2135 void setDWOId(uint64_t DwoId) { DWOId = DwoId; }
2136 bool getSplitDebugInlining() const { return SplitDebugInlining; }
2137 void setSplitDebugInlining(bool SplitDebugInlining) {
2138 this->SplitDebugInlining = SplitDebugInlining;
2139 }
2141 StringRef getSDK() const { return getStringOperand(10); }
2142
2143 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
2144 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
2146 return getOperandAs<MDString>(3);
2147 }
2148 Metadata *getRawEnumTypes() const { return getOperand(4); }
2152 Metadata *getRawMacros() const { return getOperand(8); }
2153 MDString *getRawSysRoot() const { return getOperandAs<MDString>(9); }
2154 MDString *getRawSDK() const { return getOperandAs<MDString>(10); }
2155
2156 /// Replace arrays.
2157 ///
2158 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
2159 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
2160 /// DICompileUnit should be fairly rare.
2161 /// @{
2162 void replaceEnumTypes(DICompositeTypeArray N) {
2163 replaceOperandWith(4, N.get());
2164 }
2165 void replaceRetainedTypes(DITypeArray N) { replaceOperandWith(5, N.get()); }
2166 void replaceGlobalVariables(DIGlobalVariableExpressionArray N) {
2167 replaceOperandWith(6, N.get());
2168 }
2169 void replaceImportedEntities(DIImportedEntityArray N) {
2170 replaceOperandWith(7, N.get());
2171 }
2172 void replaceMacros(DIMacroNodeArray N) { replaceOperandWith(8, N.get()); }
2173 /// @}
2174
2175 static bool classof(const Metadata *MD) {
2176 return MD->getMetadataID() == DICompileUnitKind;
2177 }
2178};
2179
2180/// A scope for locals.
2181///
2182/// A legal scope for lexical blocks, local variables, and debug info
2183/// locations. Subclasses are \a DISubprogram, \a DILexicalBlock, and \a
2184/// DILexicalBlockFile.
2185class DILocalScope : public DIScope {
2186protected:
2189 : DIScope(C, ID, Storage, Tag, Ops) {}
2190 ~DILocalScope() = default;
2191
2192public:
2193 /// Get the subprogram for this scope.
2194 ///
2195 /// Return this if it's an \a DISubprogram; otherwise, look up the scope
2196 /// chain.
2198
2199 /// Traverses the scope chain rooted at RootScope until it hits a Subprogram,
2200 /// recreating the chain with "NewSP" instead.
2201 LLVM_ABI static DILocalScope *
2203 LLVMContext &Ctx,
2205
2206 /// Get the first non DILexicalBlockFile scope of this scope.
2207 ///
2208 /// Return this if it's not a \a DILexicalBlockFIle; otherwise, look up the
2209 /// scope chain.
2211
2212 static bool classof(const Metadata *MD) {
2213 return MD->getMetadataID() == DISubprogramKind ||
2214 MD->getMetadataID() == DILexicalBlockKind ||
2215 MD->getMetadataID() == DILexicalBlockFileKind;
2216 }
2217};
2218
2219/// Subprogram description. Uses SubclassData1.
2221 friend class LLVMContextImpl;
2222 friend class MDNode;
2223
2224 unsigned Line;
2225 unsigned ScopeLine;
2226 unsigned VirtualIndex;
2227
2228 /// In the MS ABI, the implicit 'this' parameter is adjusted in the prologue
2229 /// of method overrides from secondary bases by this amount. It may be
2230 /// negative.
2231 int ThisAdjustment;
2232
2233public:
2234 /// Debug info subprogram flags.
2236#define HANDLE_DISP_FLAG(ID, NAME) SPFlag##NAME = ID,
2237#define DISP_FLAG_LARGEST_NEEDED
2238#include "llvm/IR/DebugInfoFlags.def"
2239 SPFlagNonvirtual = SPFlagZero,
2240 SPFlagVirtuality = SPFlagVirtual | SPFlagPureVirtual,
2241 LLVM_MARK_AS_BITMASK_ENUM(SPFlagLargest)
2242 };
2243
2244 LLVM_ABI static DISPFlags getFlag(StringRef Flag);
2246
2247 /// Split up a flags bitfield for easier printing.
2248 ///
2249 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
2250 /// any remaining (unrecognized) bits.
2252 SmallVectorImpl<DISPFlags> &SplitFlags);
2253
2254 // Helper for converting old bitfields to new flags word.
2255 LLVM_ABI static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition,
2256 bool IsOptimized,
2257 unsigned Virtuality = SPFlagNonvirtual,
2258 bool IsMainSubprogram = false);
2259
2260private:
2261 DIFlags Flags;
2262 DISPFlags SPFlags;
2263
2264 DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
2265 unsigned ScopeLine, unsigned VirtualIndex, int ThisAdjustment,
2266 DIFlags Flags, DISPFlags SPFlags, bool UsesKeyInstructions,
2268 ~DISubprogram() = default;
2269
2270 static DISubprogram *
2271 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
2272 StringRef LinkageName, DIFile *File, unsigned Line,
2273 DISubroutineType *Type, unsigned ScopeLine, DIType *ContainingType,
2274 unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags,
2275 DISPFlags SPFlags, DICompileUnit *Unit,
2276 DITemplateParameterArray TemplateParams, DISubprogram *Declaration,
2277 DINodeArray RetainedNodes, DITypeArray ThrownTypes,
2280 bool ShouldCreate = true) {
2281 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
2282 getCanonicalMDString(Context, LinkageName), File, Line, Type,
2283 ScopeLine, ContainingType, VirtualIndex, ThisAdjustment,
2284 Flags, SPFlags, Unit, TemplateParams.get(), Declaration,
2285 RetainedNodes.get(), ThrownTypes.get(), Annotations.get(),
2287 UsesKeyInstructions, Storage, ShouldCreate);
2288 }
2289
2290 LLVM_ABI static DISubprogram *
2291 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
2292 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
2293 unsigned ScopeLine, Metadata *ContainingType, unsigned VirtualIndex,
2294 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
2297 MDString *TargetFuncName, bool UsesKeyInstructions,
2298 StorageType Storage, bool ShouldCreate = true);
2299
2300 TempDISubprogram cloneImpl() const {
2302 getFile(), getLine(), getType(), getScopeLine(),
2303 getContainingType(), getVirtualIndex(),
2304 getThisAdjustment(), getFlags(), getSPFlags(),
2305 getUnit(), getTemplateParams(), getDeclaration(),
2306 getRetainedNodes(), getThrownTypes(), getAnnotations(),
2307 getTargetFuncName(), getKeyInstructionsEnabled());
2308 }
2309
2310public:
2314 unsigned Line, DISubroutineType *Type, unsigned ScopeLine,
2315 DIType *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
2316 DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit,
2317 DITemplateParameterArray TemplateParams = nullptr,
2318 DISubprogram *Declaration = nullptr, DINodeArray RetainedNodes = nullptr,
2319 DITypeArray ThrownTypes = nullptr, DINodeArray Annotations = nullptr,
2320 StringRef TargetFuncName = "", bool UsesKeyInstructions = false),
2321 (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
2322 VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
2325
2329 unsigned Line, Metadata *Type, unsigned ScopeLine,
2330 Metadata *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
2331 DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
2335 bool UsesKeyInstructions = false),
2336 (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
2337 VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
2340
2341 TempDISubprogram clone() const { return cloneImpl(); }
2342
2343 /// Returns a new temporary DISubprogram with updated Flags
2344 TempDISubprogram cloneWithFlags(DIFlags NewFlags) const {
2345 auto NewSP = clone();
2346 NewSP->Flags = NewFlags;
2347 return NewSP;
2348 }
2349
2350 bool getKeyInstructionsEnabled() const { return SubclassData1; }
2351
2352public:
2353 unsigned getLine() const { return Line; }
2354 unsigned getVirtuality() const { return getSPFlags() & SPFlagVirtuality; }
2355 unsigned getVirtualIndex() const { return VirtualIndex; }
2356 int getThisAdjustment() const { return ThisAdjustment; }
2357 unsigned getScopeLine() const { return ScopeLine; }
2358 void setScopeLine(unsigned L) {
2359 assert(isDistinct());
2360 ScopeLine = L;
2361 }
2362 DIFlags getFlags() const { return Flags; }
2363 DISPFlags getSPFlags() const { return SPFlags; }
2364 bool isLocalToUnit() const { return getSPFlags() & SPFlagLocalToUnit; }
2365 bool isDefinition() const { return getSPFlags() & SPFlagDefinition; }
2366 bool isOptimized() const { return getSPFlags() & SPFlagOptimized; }
2367 bool isMainSubprogram() const { return getSPFlags() & SPFlagMainSubprogram; }
2368
2369 bool isArtificial() const { return getFlags() & FlagArtificial; }
2370 bool isPrivate() const {
2371 return (getFlags() & FlagAccessibility) == FlagPrivate;
2372 }
2373 bool isProtected() const {
2374 return (getFlags() & FlagAccessibility) == FlagProtected;
2375 }
2376 bool isPublic() const {
2377 return (getFlags() & FlagAccessibility) == FlagPublic;
2378 }
2379 bool isExplicit() const { return getFlags() & FlagExplicit; }
2380 bool isPrototyped() const { return getFlags() & FlagPrototyped; }
2381 bool areAllCallsDescribed() const {
2382 return getFlags() & FlagAllCallsDescribed;
2383 }
2384 bool isPure() const { return getSPFlags() & SPFlagPure; }
2385 bool isElemental() const { return getSPFlags() & SPFlagElemental; }
2386 bool isRecursive() const { return getSPFlags() & SPFlagRecursive; }
2387 bool isObjCDirect() const { return getSPFlags() & SPFlagObjCDirect; }
2388
2389 /// Check if this is deleted member function.
2390 ///
2391 /// Return true if this subprogram is a C++11 special
2392 /// member function declared deleted.
2393 bool isDeleted() const { return getSPFlags() & SPFlagDeleted; }
2394
2395 /// Check if this is reference-qualified.
2396 ///
2397 /// Return true if this subprogram is a C++11 reference-qualified non-static
2398 /// member function (void foo() &).
2399 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
2400
2401 /// Check if this is rvalue-reference-qualified.
2402 ///
2403 /// Return true if this subprogram is a C++11 rvalue-reference-qualified
2404 /// non-static member function (void foo() &&).
2405 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
2406
2407 /// Check if this is marked as noreturn.
2408 ///
2409 /// Return true if this subprogram is C++11 noreturn or C11 _Noreturn
2410 bool isNoReturn() const { return getFlags() & FlagNoReturn; }
2411
2412 // Check if this routine is a compiler-generated thunk.
2413 //
2414 // Returns true if this subprogram is a thunk generated by the compiler.
2415 bool isThunk() const { return getFlags() & FlagThunk; }
2416
2417 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2418
2419 StringRef getName() const { return getStringOperand(2); }
2420 StringRef getLinkageName() const { return getStringOperand(3); }
2421 /// Only used by clients of CloneFunction, and only right after the cloning.
2422 void replaceLinkageName(MDString *LN) { replaceOperandWith(3, LN); }
2423
2424 DISubroutineType *getType() const {
2425 return cast_or_null<DISubroutineType>(getRawType());
2426 }
2427 DIType *getContainingType() const {
2428 return cast_or_null<DIType>(getRawContainingType());
2429 }
2430 void replaceType(DISubroutineType *Ty) {
2431 assert(isDistinct() && "Only distinct nodes can mutate");
2432 replaceOperandWith(4, Ty);
2433 }
2434
2435 DICompileUnit *getUnit() const {
2436 return cast_or_null<DICompileUnit>(getRawUnit());
2437 }
2438 void replaceUnit(DICompileUnit *CU) { replaceOperandWith(5, CU); }
2439 DITemplateParameterArray getTemplateParams() const {
2440 return cast_or_null<MDTuple>(getRawTemplateParams());
2441 }
2442 DISubprogram *getDeclaration() const {
2443 return cast_or_null<DISubprogram>(getRawDeclaration());
2444 }
2445 void replaceDeclaration(DISubprogram *Decl) { replaceOperandWith(6, Decl); }
2446 DINodeArray getRetainedNodes() const {
2447 return cast_or_null<MDTuple>(getRawRetainedNodes());
2448 }
2449 DITypeArray getThrownTypes() const {
2450 return cast_or_null<MDTuple>(getRawThrownTypes());
2451 }
2452 DINodeArray getAnnotations() const {
2453 return cast_or_null<MDTuple>(getRawAnnotations());
2454 }
2455 StringRef getTargetFuncName() const {
2456 return (getRawTargetFuncName()) ? getStringOperand(12) : StringRef();
2457 }
2458
2459 Metadata *getRawScope() const { return getOperand(1); }
2460 MDString *getRawName() const { return getOperandAs<MDString>(2); }
2461 MDString *getRawLinkageName() const { return getOperandAs<MDString>(3); }
2462 Metadata *getRawType() const { return getOperand(4); }
2463 Metadata *getRawUnit() const { return getOperand(5); }
2464 Metadata *getRawDeclaration() const { return getOperand(6); }
2465 Metadata *getRawRetainedNodes() const { return getOperand(7); }
2466 Metadata *getRawContainingType() const {
2467 return getNumOperands() > 8 ? getOperandAs<Metadata>(8) : nullptr;
2468 }
2469 Metadata *getRawTemplateParams() const {
2470 return getNumOperands() > 9 ? getOperandAs<Metadata>(9) : nullptr;
2471 }
2472 Metadata *getRawThrownTypes() const {
2473 return getNumOperands() > 10 ? getOperandAs<Metadata>(10) : nullptr;
2474 }
2475 Metadata *getRawAnnotations() const {
2476 return getNumOperands() > 11 ? getOperandAs<Metadata>(11) : nullptr;
2477 }
2478 MDString *getRawTargetFuncName() const {
2479 return getNumOperands() > 12 ? getOperandAs<MDString>(12) : nullptr;
2480 }
2481
2482 void replaceRawLinkageName(MDString *LinkageName) {
2484 }
2485 void replaceRetainedNodes(DINodeArray N) {
2486 replaceOperandWith(7, N.get());
2487 }
2488
2489 /// Check if this subprogram describes the given function.
2490 ///
2491 /// FIXME: Should this be looking through bitcasts?
2492 LLVM_ABI bool describes(const Function *F) const;
2493
2494 static bool classof(const Metadata *MD) {
2495 return MD->getMetadataID() == DISubprogramKind;
2496 }
2497};
2498
2499/// Debug location.
2500///
2501/// A debug location in source code, used for debug info and otherwise.
2502///
2503/// Uses the SubclassData1, SubclassData16 and SubclassData32
2504/// Metadata slots.
2505
2506class DILocation : public MDNode {
2507 friend class LLVMContextImpl;
2508 friend class MDNode;
2509 uint64_t AtomGroup : 61;
2510 uint64_t AtomRank : 3;
2511
2513 unsigned Column, uint64_t AtomGroup, uint8_t AtomRank,
2516
2517 LLVM_ABI static DILocation *
2518 getImpl(LLVMContext &Context, unsigned Line, unsigned Column, Metadata *Scope,
2519 Metadata *InlinedAt, bool ImplicitCode, uint64_t AtomGroup,
2520 uint8_t AtomRank, StorageType Storage, bool ShouldCreate = true);
2521 static DILocation *getImpl(LLVMContext &Context, unsigned Line,
2522 unsigned Column, DILocalScope *Scope,
2524 uint64_t AtomGroup, uint8_t AtomRank,
2525 StorageType Storage, bool ShouldCreate = true) {
2526 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
2527 static_cast<Metadata *>(InlinedAt), ImplicitCode, AtomGroup,
2528 AtomRank, Storage, ShouldCreate);
2529 }
2530
2531 TempDILocation cloneImpl() const {
2532 // Get the raw scope/inlinedAt since it is possible to invoke this on
2533 // a DILocation containing temporary metadata.
2534 return getTemporary(getContext(), getLine(), getColumn(), getRawScope(),
2535 getRawInlinedAt(), isImplicitCode(), getAtomGroup(),
2536 getAtomRank());
2537 }
2538
2539public:
2540 uint64_t getAtomGroup() const { return AtomGroup; }
2541 uint8_t getAtomRank() const { return AtomRank; }
2542
2544 if (!getAtomGroup() && !getAtomRank())
2545 return this;
2546 return get(getContext(), getLine(), getColumn(), getScope(), getInlinedAt(),
2547 isImplicitCode());
2548 }
2549
2550 // Disallow replacing operands.
2551 void replaceOperandWith(unsigned I, Metadata *New) = delete;
2552
2554 (unsigned Line, unsigned Column, Metadata *Scope,
2555 Metadata *InlinedAt = nullptr, bool ImplicitCode = false,
2556 uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2557 (Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2558 AtomRank))
2560 (unsigned Line, unsigned Column, DILocalScope *Scope,
2561 DILocation *InlinedAt = nullptr, bool ImplicitCode = false,
2562 uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2563 (Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2564 AtomRank))
2565
2566 /// Return a (temporary) clone of this.
2567 TempDILocation clone() const { return cloneImpl(); }
2568
2569 unsigned getLine() const { return SubclassData32; }
2570 unsigned getColumn() const { return SubclassData16; }
2571 DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
2572
2573 /// Return the linkage name of Subprogram. If the linkage name is empty,
2574 /// return scope name (the demangled name).
2575 StringRef getSubprogramLinkageName() const {
2576 DISubprogram *SP = getScope()->getSubprogram();
2577 if (!SP)
2578 return "";
2579 auto Name = SP->getLinkageName();
2580 if (!Name.empty())
2581 return Name;
2582 return SP->getName();
2583 }
2584
2585 DILocation *getInlinedAt() const {
2586 return cast_or_null<DILocation>(getRawInlinedAt());
2587 }
2588
2589 /// Check if the location corresponds to an implicit code.
2590 /// When the ImplicitCode flag is true, it means that the Instruction
2591 /// with this DILocation has been added by the front-end but it hasn't been
2592 /// written explicitly by the user (e.g. cleanup stuff in C++ put on a closing
2593 /// bracket). It's useful for code coverage to not show a counter on "empty"
2594 /// lines.
2595 bool isImplicitCode() const { return SubclassData1; }
2596 void setImplicitCode(bool ImplicitCode) { SubclassData1 = ImplicitCode; }
2597
2598 DIFile *getFile() const { return getScope()->getFile(); }
2599 StringRef getFilename() const { return getScope()->getFilename(); }
2600 StringRef getDirectory() const { return getScope()->getDirectory(); }
2601 std::optional<StringRef> getSource() const { return getScope()->getSource(); }
2602
2603 /// Get the scope where this is inlined.
2604 ///
2605 /// Walk through \a getInlinedAt() and return \a getScope() from the deepest
2606 /// location.
2607 DILocalScope *getInlinedAtScope() const {
2608 if (auto *IA = getInlinedAt())
2609 return IA->getInlinedAtScope();
2610 return getScope();
2611 }
2612
2613 /// Get the DWARF discriminator.
2614 ///
2615 /// DWARF discriminators distinguish identical file locations between
2616 /// instructions that are on different basic blocks.
2617 ///
2618 /// There are 3 components stored in discriminator, from lower bits:
2619 ///
2620 /// Base discriminator: assigned by AddDiscriminators pass to identify IRs
2621 /// that are defined by the same source line, but
2622 /// different basic blocks.
2623 /// Duplication factor: assigned by optimizations that will scale down
2624 /// the execution frequency of the original IR.
2625 /// Copy Identifier: assigned by optimizations that clones the IR.
2626 /// Each copy of the IR will be assigned an identifier.
2627 ///
2628 /// Encoding:
2629 ///
2630 /// The above 3 components are encoded into a 32bit unsigned integer in
2631 /// order. If the lowest bit is 1, the current component is empty, and the
2632 /// next component will start in the next bit. Otherwise, the current
2633 /// component is non-empty, and its content starts in the next bit. The
2634 /// value of each components is either 5 bit or 12 bit: if the 7th bit
2635 /// is 0, the bit 2~6 (5 bits) are used to represent the component; if the
2636 /// 7th bit is 1, the bit 2~6 (5 bits) and 8~14 (7 bits) are combined to
2637 /// represent the component. Thus, the number of bits used for a component
2638 /// is either 0 (if it and all the next components are empty); 1 - if it is
2639 /// empty; 7 - if its value is up to and including 0x1f (lsb and msb are both
2640 /// 0); or 14, if its value is up to and including 0x1ff. Note that the last
2641 /// component is also capped at 0x1ff, even in the case when both first
2642 /// components are 0, and we'd technically have 29 bits available.
2643 ///
2644 /// For precise control over the data being encoded in the discriminator,
2645 /// use encodeDiscriminator/decodeDiscriminator.
2646
2647 inline unsigned getDiscriminator() const;
2648
2649 // For the regular discriminator, it stands for all empty components if all
2650 // the lowest 3 bits are non-zero and all higher 29 bits are unused(zero by
2651 // default). Here we fully leverage the higher 29 bits for pseudo probe use.
2652 // This is the format:
2653 // [2:0] - 0x7
2654 // [31:3] - pseudo probe fields guaranteed to be non-zero as a whole
2655 // So if the lower 3 bits is non-zero and the others has at least one
2656 // non-zero bit, it guarantees to be a pseudo probe discriminator
2657 inline static bool isPseudoProbeDiscriminator(unsigned Discriminator) {
2658 return ((Discriminator & 0x7) == 0x7) && (Discriminator & 0xFFFFFFF8);
2659 }
2660
2661 /// Returns a new DILocation with updated \p Discriminator.
2662 inline const DILocation *cloneWithDiscriminator(unsigned Discriminator) const;
2663
2664 /// Returns a new DILocation with updated base discriminator \p BD. Only the
2665 /// base discriminator is set in the new DILocation, the other encoded values
2666 /// are elided.
2667 /// If the discriminator cannot be encoded, the function returns std::nullopt.
2668 inline std::optional<const DILocation *>
2669 cloneWithBaseDiscriminator(unsigned BD) const;
2670
2671 /// Returns the duplication factor stored in the discriminator, or 1 if no
2672 /// duplication factor (or 0) is encoded.
2673 inline unsigned getDuplicationFactor() const;
2674
2675 /// Returns the copy identifier stored in the discriminator.
2676 inline unsigned getCopyIdentifier() const;
2677
2678 /// Returns the base discriminator stored in the discriminator.
2679 inline unsigned getBaseDiscriminator() const;
2680
2681 /// Returns a new DILocation with duplication factor \p DF * current
2682 /// duplication factor encoded in the discriminator. The current duplication
2683 /// factor is as defined by getDuplicationFactor().
2684 /// Returns std::nullopt if encoding failed.
2685 inline std::optional<const DILocation *>
2687
2688 /// Attempts to merge \p LocA and \p LocB into a single location; see
2689 /// DebugLoc::getMergedLocation for more details.
2690 /// NB: When merging the locations of instructions, prefer to use
2691 /// DebugLoc::getMergedLocation(), as an instruction's DebugLoc may contain
2692 /// additional metadata that will not be preserved when merging the unwrapped
2693 /// DILocations.
2695 DILocation *LocB);
2696
2697 /// Try to combine the vector of locations passed as input in a single one.
2698 /// This function applies getMergedLocation() repeatedly left-to-right.
2699 /// NB: When merging the locations of instructions, prefer to use
2700 /// DebugLoc::getMergedLocations(), as an instruction's DebugLoc may contain
2701 /// additional metadata that will not be preserved when merging the unwrapped
2702 /// DILocations.
2703 ///
2704 /// \p Locs: The locations to be merged.
2706
2707 /// Return the masked discriminator value for an input discrimnator value D
2708 /// (i.e. zero out the (B+1)-th and above bits for D (B is 0-base).
2709 // Example: an input of (0x1FF, 7) returns 0xFF.
2710 static unsigned getMaskedDiscriminator(unsigned D, unsigned B) {
2711 return (D & getN1Bits(B));
2712 }
2713
2714 /// Return the bits used for base discriminators.
2715 static unsigned getBaseDiscriminatorBits() { return getBaseFSBitEnd(); }
2716
2717 /// Returns the base discriminator for a given encoded discriminator \p D.
2718 static unsigned
2720 bool IsFSDiscriminator = false) {
2721 // Extract the dwarf base discriminator if it's encoded in the pseudo probe
2722 // discriminator.
2724 auto DwarfBaseDiscriminator =
2726 if (DwarfBaseDiscriminator)
2727 return *DwarfBaseDiscriminator;
2728 // Return the probe id instead of zero for a pseudo probe discriminator.
2729 // This should help differenciate callsites with same line numbers to
2730 // achieve a decent AutoFDO profile under -fpseudo-probe-for-profiling,
2731 // where the original callsite dwarf discriminator is overwritten by
2732 // callsite probe information.
2734 }
2735
2736 if (IsFSDiscriminator)
2739 }
2740
2741 /// Raw encoding of the discriminator. APIs such as cloneWithDuplicationFactor
2742 /// have certain special case behavior (e.g. treating empty duplication factor
2743 /// as the value '1').
2744 /// This API, in conjunction with cloneWithDiscriminator, may be used to
2745 /// encode the raw values provided.
2746 ///
2747 /// \p BD: base discriminator
2748 /// \p DF: duplication factor
2749 /// \p CI: copy index
2750 ///
2751 /// The return is std::nullopt if the values cannot be encoded in 32 bits -
2752 /// for example, values for BD or DF larger than 12 bits. Otherwise, the
2753 /// return is the encoded value.
2754 LLVM_ABI static std::optional<unsigned>
2755 encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI);
2756
2757 /// Raw decoder for values in an encoded discriminator D.
2758 LLVM_ABI static void decodeDiscriminator(unsigned D, unsigned &BD,
2759 unsigned &DF, unsigned &CI);
2760
2761 /// Returns the duplication factor for a given encoded discriminator \p D, or
2762 /// 1 if no value or 0 is encoded.
2763 static unsigned getDuplicationFactorFromDiscriminator(unsigned D) {
2765 return 1;
2767 unsigned Ret = getUnsignedFromPrefixEncoding(D);
2768 if (Ret == 0)
2769 return 1;
2770 return Ret;
2771 }
2772
2773 /// Returns the copy identifier for a given encoded discriminator \p D.
2774 static unsigned getCopyIdentifierFromDiscriminator(unsigned D) {
2777 }
2778
2779 Metadata *getRawScope() const { return getOperand(0); }
2781 if (getNumOperands() == 2)
2782 return getOperand(1);
2783 return nullptr;
2784 }
2785
2786 static bool classof(const Metadata *MD) {
2787 return MD->getMetadataID() == DILocationKind;
2788 }
2789};
2790
2792protected:
2796
2797public:
2798 DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
2799
2800 Metadata *getRawScope() const { return getOperand(1); }
2801
2802 void replaceScope(DIScope *Scope) {
2803 assert(!isUniqued());
2804 setOperand(1, Scope);
2805 }
2806
2807 static bool classof(const Metadata *MD) {
2808 return MD->getMetadataID() == DILexicalBlockKind ||
2809 MD->getMetadataID() == DILexicalBlockFileKind;
2810 }
2811};
2812
2813/// Debug lexical block.
2814///
2815/// Uses the SubclassData32 Metadata slot.
2817 friend class LLVMContextImpl;
2818 friend class MDNode;
2819
2820 uint16_t Column;
2821
2823 unsigned Column, ArrayRef<Metadata *> Ops)
2824 : DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops),
2825 Column(Column) {
2827 assert(Column < (1u << 16) && "Expected 16-bit column");
2828 }
2829 ~DILexicalBlock() = default;
2830
2831 static DILexicalBlock *getImpl(LLVMContext &Context, DILocalScope *Scope,
2832 DIFile *File, unsigned Line, unsigned Column,
2834 bool ShouldCreate = true) {
2835 return getImpl(Context, static_cast<Metadata *>(Scope),
2836 static_cast<Metadata *>(File), Line, Column, Storage,
2837 ShouldCreate);
2838 }
2839
2840 LLVM_ABI static DILexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
2841 Metadata *File, unsigned Line,
2842 unsigned Column, StorageType Storage,
2843 bool ShouldCreate = true);
2844
2845 TempDILexicalBlock cloneImpl() const {
2847 getColumn());
2848 }
2849
2850public:
2852 (DILocalScope * Scope, DIFile *File, unsigned Line,
2853 unsigned Column),
2854 (Scope, File, Line, Column))
2857 unsigned Column),
2858 (Scope, File, Line, Column))
2859
2860 TempDILexicalBlock clone() const { return cloneImpl(); }
2861
2862 unsigned getLine() const { return SubclassData32; }
2863 unsigned getColumn() const { return Column; }
2864
2865 static bool classof(const Metadata *MD) {
2866 return MD->getMetadataID() == DILexicalBlockKind;
2867 }
2868};
2869
2871 friend class LLVMContextImpl;
2872 friend class MDNode;
2873
2875 unsigned Discriminator, ArrayRef<Metadata *> Ops)
2876 : DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops) {
2878 }
2879 ~DILexicalBlockFile() = default;
2880
2881 static DILexicalBlockFile *getImpl(LLVMContext &Context, DILocalScope *Scope,
2882 DIFile *File, unsigned Discriminator,
2884 bool ShouldCreate = true) {
2885 return getImpl(Context, static_cast<Metadata *>(Scope),
2886 static_cast<Metadata *>(File), Discriminator, Storage,
2887 ShouldCreate);
2888 }
2889
2890 LLVM_ABI static DILexicalBlockFile *getImpl(LLVMContext &Context,
2892 unsigned Discriminator,
2894 bool ShouldCreate = true);
2895
2896 TempDILexicalBlockFile cloneImpl() const {
2897 return getTemporary(getContext(), getScope(), getFile(),
2899 }
2900
2901public:
2904 unsigned Discriminator),
2909
2910 TempDILexicalBlockFile clone() const { return cloneImpl(); }
2911 unsigned getDiscriminator() const { return SubclassData32; }
2912
2913 static bool classof(const Metadata *MD) {
2914 return MD->getMetadataID() == DILexicalBlockFileKind;
2915 }
2916};
2917
2918unsigned DILocation::getDiscriminator() const {
2919 if (auto *F = dyn_cast<DILexicalBlockFile>(getScope()))
2920 return F->getDiscriminator();
2921 return 0;
2922}
2923
2924const DILocation *
2925DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
2926 DIScope *Scope = getScope();
2927 // Skip all parent DILexicalBlockFile that already have a discriminator
2928 // assigned. We do not want to have nested DILexicalBlockFiles that have
2929 // multiple discriminators because only the leaf DILexicalBlockFile's
2930 // dominator will be used.
2931 for (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope);
2932 LBF && LBF->getDiscriminator() != 0;
2933 LBF = dyn_cast<DILexicalBlockFile>(Scope))
2934 Scope = LBF->getScope();
2935 DILexicalBlockFile *NewScope =
2936 DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator);
2937 return DILocation::get(getContext(), getLine(), getColumn(), NewScope,
2938 getInlinedAt(), isImplicitCode(), getAtomGroup(),
2939 getAtomRank());
2940}
2941
2943 return getBaseDiscriminatorFromDiscriminator(getDiscriminator(),
2945}
2946
2948 return getDuplicationFactorFromDiscriminator(getDiscriminator());
2949}
2950
2952 return getCopyIdentifierFromDiscriminator(getDiscriminator());
2953}
2954
2955std::optional<const DILocation *>
2957 unsigned BD, DF, CI;
2958
2960 BD = getBaseDiscriminator();
2961 if (D == BD)
2962 return this;
2963 return cloneWithDiscriminator(D);
2964 }
2965
2966 decodeDiscriminator(getDiscriminator(), BD, DF, CI);
2967 if (D == BD)
2968 return this;
2969 if (std::optional<unsigned> Encoded = encodeDiscriminator(D, DF, CI))
2970 return cloneWithDiscriminator(*Encoded);
2971 return std::nullopt;
2972}
2973
2974std::optional<const DILocation *>
2976 assert(!EnableFSDiscriminator && "FSDiscriminator should not call this.");
2977 // Do no interfere with pseudo probes. Pseudo probe doesn't need duplication
2978 // factor support as samples collected on cloned probes will be aggregated.
2979 // Also pseudo probe at a callsite uses the dwarf discriminator to store
2980 // pseudo probe related information, such as the probe id.
2981 if (isPseudoProbeDiscriminator(getDiscriminator()))
2982 return this;
2983
2985 if (DF <= 1)
2986 return this;
2987
2988 unsigned BD = getBaseDiscriminator();
2989 unsigned CI = getCopyIdentifier();
2990 if (std::optional<unsigned> D = encodeDiscriminator(BD, DF, CI))
2991 return cloneWithDiscriminator(*D);
2992 return std::nullopt;
2993}
2994
2995/// Debug lexical block.
2996///
2997/// Uses the SubclassData1 Metadata slot.
2998class DINamespace : public DIScope {
2999 friend class LLVMContextImpl;
3000 friend class MDNode;
3001
3004 ~DINamespace() = default;
3005
3006 static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope,
3008 StorageType Storage, bool ShouldCreate = true) {
3009 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
3010 ExportSymbols, Storage, ShouldCreate);
3011 }
3012 LLVM_ABI static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope,
3015 bool ShouldCreate = true);
3016
3017 TempDINamespace cloneImpl() const {
3018 return getTemporary(getContext(), getScope(), getName(),
3020 }
3021
3022public:
3029
3030 TempDINamespace clone() const { return cloneImpl(); }
3031
3032 bool getExportSymbols() const { return SubclassData1; }
3033 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
3034 StringRef getName() const { return getStringOperand(2); }
3035
3036 Metadata *getRawScope() const { return getOperand(1); }
3037 MDString *getRawName() const { return getOperandAs<MDString>(2); }
3038
3039 static bool classof(const Metadata *MD) {
3040 return MD->getMetadataID() == DINamespaceKind;
3041 }
3042};
3043
3044/// Represents a module in the programming language, for example, a Clang
3045/// module, or a Fortran module.
3046///
3047/// Uses the SubclassData1 and SubclassData32 Metadata slots.
3048class DIModule : public DIScope {
3049 friend class LLVMContextImpl;
3050 friend class MDNode;
3051
3052 DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo,
3053 bool IsDecl, ArrayRef<Metadata *> Ops);
3054 ~DIModule() = default;
3055
3056 static DIModule *getImpl(LLVMContext &Context, DIFile *File, DIScope *Scope,
3059 unsigned LineNo, bool IsDecl, StorageType Storage,
3060 bool ShouldCreate = true) {
3061 return getImpl(Context, File, Scope, getCanonicalMDString(Context, Name),
3064 getCanonicalMDString(Context, APINotesFile), LineNo, IsDecl,
3065 Storage, ShouldCreate);
3066 }
3067 LLVM_ABI static DIModule *
3068 getImpl(LLVMContext &Context, Metadata *File, Metadata *Scope, MDString *Name,
3070 MDString *APINotesFile, unsigned LineNo, bool IsDecl,
3071 StorageType Storage, bool ShouldCreate = true);
3072
3073 TempDIModule cloneImpl() const {
3075 getConfigurationMacros(), getIncludePath(),
3076 getAPINotesFile(), getLineNo(), getIsDecl());
3077 }
3078
3079public:
3083 StringRef APINotesFile, unsigned LineNo,
3084 bool IsDecl = false),
3086 APINotesFile, LineNo, IsDecl))
3091 bool IsDecl = false),
3093 APINotesFile, LineNo, IsDecl))
3094
3095 TempDIModule clone() const { return cloneImpl(); }
3096
3097 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
3098 StringRef getName() const { return getStringOperand(2); }
3099 StringRef getConfigurationMacros() const { return getStringOperand(3); }
3100 StringRef getIncludePath() const { return getStringOperand(4); }
3101 StringRef getAPINotesFile() const { return getStringOperand(5); }
3102 unsigned getLineNo() const { return SubclassData32; }
3103 bool getIsDecl() const { return SubclassData1; }
3104
3105 Metadata *getRawScope() const { return getOperand(1); }
3106 MDString *getRawName() const { return getOperandAs<MDString>(2); }
3107 MDString *getRawConfigurationMacros() const {
3108 return getOperandAs<MDString>(3);
3109 }
3110 MDString *getRawIncludePath() const { return getOperandAs<MDString>(4); }
3111 MDString *getRawAPINotesFile() const { return getOperandAs<MDString>(5); }
3112
3113 static bool classof(const Metadata *MD) {
3114 return MD->getMetadataID() == DIModuleKind;
3115 }
3116};
3117
3118/// Base class for template parameters.
3119///
3120/// Uses the SubclassData1 Metadata slot.
3122protected:
3124 unsigned Tag, bool IsDefault, ArrayRef<Metadata *> Ops)
3125 : DINode(Context, ID, Storage, Tag, Ops) {
3126 SubclassData1 = IsDefault;
3127 }
3129
3130public:
3131 StringRef getName() const { return getStringOperand(0); }
3132 DIType *getType() const { return cast_or_null<DIType>(getRawType()); }
3133
3134 MDString *getRawName() const { return getOperandAs<MDString>(0); }
3135 Metadata *getRawType() const { return getOperand(1); }
3136 bool isDefault() const { return SubclassData1; }
3137
3138 static bool classof(const Metadata *MD) {
3139 return MD->getMetadataID() == DITemplateTypeParameterKind ||
3140 MD->getMetadataID() == DITemplateValueParameterKind;
3141 }
3142};
3143
3145 friend class LLVMContextImpl;
3146 friend class MDNode;
3147
3150 ~DITemplateTypeParameter() = default;
3151
3152 static DITemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
3153 DIType *Type, bool IsDefault,
3155 bool ShouldCreate = true) {
3156 return getImpl(Context, getCanonicalMDString(Context, Name), Type,
3157 IsDefault, Storage, ShouldCreate);
3158 }
3160 getImpl(LLVMContext &Context, MDString *Name, Metadata *Type, bool IsDefault,
3161 StorageType Storage, bool ShouldCreate = true);
3162
3163 TempDITemplateTypeParameter cloneImpl() const {
3164 return getTemporary(getContext(), getName(), getType(), isDefault());
3165 }
3166
3167public:
3170 (Name, Type, IsDefault))
3174
3175 TempDITemplateTypeParameter clone() const { return cloneImpl(); }
3176
3177 static bool classof(const Metadata *MD) {
3178 return MD->getMetadataID() == DITemplateTypeParameterKind;
3179 }
3180};
3181
3183 friend class LLVMContextImpl;
3184 friend class MDNode;
3185
3187 unsigned Tag, bool IsDefault,
3189 : DITemplateParameter(Context, DITemplateValueParameterKind, Storage, Tag,
3190 IsDefault, Ops) {}
3191 ~DITemplateValueParameter() = default;
3192
3193 static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
3195 bool IsDefault, Metadata *Value,
3197 bool ShouldCreate = true) {
3198 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
3199 IsDefault, Value, Storage, ShouldCreate);
3200 }
3201 LLVM_ABI static DITemplateValueParameter *
3202 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
3204 bool ShouldCreate = true);
3205
3206 TempDITemplateValueParameter cloneImpl() const {
3207 return getTemporary(getContext(), getTag(), getName(), getType(),
3208 isDefault(), getValue());
3209 }
3210
3211public:
3213 (unsigned Tag, StringRef Name, DIType *Type, bool IsDefault,
3214 Metadata *Value),
3215 (Tag, Name, Type, IsDefault, Value))
3220
3221 TempDITemplateValueParameter clone() const { return cloneImpl(); }
3222
3223 Metadata *getValue() const { return getOperand(2); }
3224
3225 static bool classof(const Metadata *MD) {
3226 return MD->getMetadataID() == DITemplateValueParameterKind;
3227 }
3228};
3229
3230/// Base class for variables.
3231///
3232/// Uses the SubclassData32 Metadata slot.
3233class DIVariable : public DINode {
3234 unsigned Line;
3235
3236protected:
3238 signed Line, ArrayRef<Metadata *> Ops,
3239 uint32_t AlignInBits = 0);
3240 ~DIVariable() = default;
3241
3242public:
3243 unsigned getLine() const { return Line; }
3244 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
3245 StringRef getName() const { return getStringOperand(1); }
3246 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
3247 DIType *getType() const { return cast_or_null<DIType>(getRawType()); }
3249 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
3250 /// Determines the size of the variable's type.
3251 LLVM_ABI std::optional<uint64_t> getSizeInBits() const;
3252
3253 /// Return the signedness of this variable's type, or std::nullopt if this
3254 /// type is neither signed nor unsigned.
3255 std::optional<DIBasicType::Signedness> getSignedness() const {
3256 if (auto *BT = dyn_cast<DIBasicType>(getType()))
3257 return BT->getSignedness();
3258 return std::nullopt;
3259 }
3260
3262 if (auto *F = getFile())
3263 return F->getFilename();
3264 return "";
3265 }
3266
3268 if (auto *F = getFile())
3269 return F->getDirectory();
3270 return "";
3271 }
3272
3273 std::optional<StringRef> getSource() const {
3274 if (auto *F = getFile())
3275 return F->getSource();
3276 return std::nullopt;
3277 }
3278
3279 Metadata *getRawScope() const { return getOperand(0); }
3280 MDString *getRawName() const { return getOperandAs<MDString>(1); }
3281 Metadata *getRawFile() const { return getOperand(2); }
3282 Metadata *getRawType() const { return getOperand(3); }
3283
3284 static bool classof(const Metadata *MD) {
3285 return MD->getMetadataID() == DILocalVariableKind ||
3286 MD->getMetadataID() == DIGlobalVariableKind;
3287 }
3288};
3289
3290/// DWARF expression.
3291///
3292/// This is (almost) a DWARF expression that modifies the location of a
3293/// variable, or the location of a single piece of a variable, or (when using
3294/// DW_OP_stack_value) is the constant variable value.
3295///
3296/// TODO: Co-allocate the expression elements.
3297/// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
3298/// storage types.
3299class DIExpression : public MDNode {
3300 friend class LLVMContextImpl;
3301 friend class MDNode;
3302
3303 std::vector<uint64_t> Elements;
3304
3306 : MDNode(C, DIExpressionKind, Storage, {}),
3307 Elements(Elements.begin(), Elements.end()) {}
3308 ~DIExpression() = default;
3309
3310 LLVM_ABI static DIExpression *getImpl(LLVMContext &Context,
3311 ArrayRef<uint64_t> Elements,
3313 bool ShouldCreate = true);
3314
3315 TempDIExpression cloneImpl() const {
3316 return getTemporary(getContext(), getElements());
3317 }
3318
3319public:
3321
3322 TempDIExpression clone() const { return cloneImpl(); }
3323
3324 ArrayRef<uint64_t> getElements() const { return Elements; }
3325
3326 unsigned getNumElements() const { return Elements.size(); }
3327
3328 uint64_t getElement(unsigned I) const {
3329 assert(I < Elements.size() && "Index out of range");
3330 return Elements[I];
3331 }
3332
3334 /// Determine whether this represents a constant value, if so
3335 // return it's sign information.
3336 LLVM_ABI std::optional<SignedOrUnsignedConstant> isConstant() const;
3337
3338 /// Return the number of unique location operands referred to (via
3339 /// DW_OP_LLVM_arg) in this expression; this is not necessarily the number of
3340 /// instances of DW_OP_LLVM_arg within the expression.
3341 /// For example, for the expression:
3342 /// (DW_OP_LLVM_arg 0, DW_OP_LLVM_arg 1, DW_OP_plus,
3343 /// DW_OP_LLVM_arg 0, DW_OP_mul)
3344 /// This function would return 2, as there are two unique location operands
3345 /// (0 and 1).
3347
3349
3352
3353 /// A lightweight wrapper around an expression operand.
3354 ///
3355 /// TODO: Store arguments directly and change \a DIExpression to store a
3356 /// range of these.
3358 const uint64_t *Op = nullptr;
3359
3360 public:
3361 ExprOperand() = default;
3362 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
3363
3364 const uint64_t *get() const { return Op; }
3365
3366 /// Get the operand code.
3367 uint64_t getOp() const { return *Op; }
3368
3369 /// Get an argument to the operand.
3370 ///
3371 /// Never returns the operand itself.
3372 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
3373
3374 unsigned getNumArgs() const { return getSize() - 1; }
3375
3376 /// Return the size of the operand.
3377 ///
3378 /// Return the number of elements in the operand (1 + args).
3379 LLVM_ABI unsigned getSize() const;
3380
3381 /// Append the elements of this operand to \p V.
3383 V.append(get(), get() + getSize());
3384 }
3385 };
3386
3387 /// An iterator for expression operands.
3390
3391 public:
3392 using iterator_category = std::input_iterator_tag;
3394 using difference_type = std::ptrdiff_t;
3397
3398 expr_op_iterator() = default;
3400
3401 element_iterator getBase() const { return Op.get(); }
3402 const ExprOperand &operator*() const { return Op; }
3403 const ExprOperand *operator->() const { return &Op; }
3404
3406 increment();
3407 return *this;
3408 }
3410 expr_op_iterator T(*this);
3411 increment();
3412 return T;
3413 }
3414
3415 /// Get the next iterator.
3416 ///
3417 /// \a std::next() doesn't work because this is technically an
3418 /// input_iterator, but it's a perfectly valid operation. This is an
3419 /// accessor to provide the same functionality.
3420 expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
3421
3422 bool operator==(const expr_op_iterator &X) const {
3423 return getBase() == X.getBase();
3424 }
3425 bool operator!=(const expr_op_iterator &X) const {
3426 return getBase() != X.getBase();
3427 }
3428
3429 private:
3430 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
3431 };
3432
3433 /// Visit the elements via ExprOperand wrappers.
3434 ///
3435 /// These range iterators visit elements through \a ExprOperand wrappers.
3436 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
3437 /// true.
3438 ///
3439 /// \pre \a isValid() gives \c true.
3440 /// @{
3443 }
3446 }
3448 return {expr_op_begin(), expr_op_end()};
3449 }
3450 /// @}
3451
3452 LLVM_ABI bool isValid() const;
3453
3454 static bool classof(const Metadata *MD) {
3455 return MD->getMetadataID() == DIExpressionKind;
3456 }
3457
3458 /// Return whether the first element a DW_OP_deref.
3459 LLVM_ABI bool startsWithDeref() const;
3460
3461 /// Return whether there is exactly one operator and it is a DW_OP_deref;
3462 LLVM_ABI bool isDeref() const;
3463
3465
3466 /// Return the number of bits that have an active value, i.e. those that
3467 /// aren't known to be zero/sign (depending on the type of Var) and which
3468 /// are within the size of this fragment (if it is one). If we can't deduce
3469 /// anything from the expression this will return the size of Var.
3470 LLVM_ABI std::optional<uint64_t> getActiveBits(DIVariable *Var);
3471
3472 /// Retrieve the details of this fragment expression.
3473 LLVM_ABI static std::optional<FragmentInfo>
3475
3476 /// Retrieve the details of this fragment expression.
3477 std::optional<FragmentInfo> getFragmentInfo() const {
3479 }
3480
3481 /// Return whether this is a piece of an aggregate variable.
3482 bool isFragment() const { return getFragmentInfo().has_value(); }
3483
3484 /// Return whether this is an implicit location description.
3485 LLVM_ABI bool isImplicit() const;
3486
3487 /// Return whether the location is computed on the expression stack, meaning
3488 /// it cannot be a simple register location.
3489 LLVM_ABI bool isComplex() const;
3490
3491 /// Return whether the evaluated expression makes use of a single location at
3492 /// the start of the expression, i.e. if it contains only a single
3493 /// DW_OP_LLVM_arg op as its first operand, or if it contains none.
3495
3496 /// Returns a reference to the elements contained in this expression, skipping
3497 /// past the leading `DW_OP_LLVM_arg, 0` if one is present.
3498 /// Similar to `convertToNonVariadicExpression`, but faster and cheaper - it
3499 /// does not check whether the expression is a single-location expression, and
3500 /// it returns elements rather than creating a new DIExpression.
3501 LLVM_ABI std::optional<ArrayRef<uint64_t>>
3503
3504 /// Removes all elements from \p Expr that do not apply to an undef debug
3505 /// value, which includes every operator that computes the value/location on
3506 /// the DWARF stack, including any DW_OP_LLVM_arg elements (making the result
3507 /// of this function always a single-location expression) while leaving
3508 /// everything that defines what the computed value applies to, i.e. the
3509 /// fragment information.
3510 LLVM_ABI static const DIExpression *
3512
3513 /// If \p Expr is a non-variadic expression (i.e. one that does not contain
3514 /// DW_OP_LLVM_arg), returns \p Expr converted to variadic form by adding a
3515 /// leading [DW_OP_LLVM_arg, 0] to the expression; otherwise returns \p Expr.
3516 LLVM_ABI static const DIExpression *
3518
3519 /// If \p Expr is a valid single-location expression, i.e. it refers to only a
3520 /// single debug operand at the start of the expression, then return that
3521 /// expression in a non-variadic form by removing DW_OP_LLVM_arg from the
3522 /// expression if it is present; otherwise returns std::nullopt.
3523 /// See also `getSingleLocationExpressionElements` above, which skips
3524 /// checking `isSingleLocationExpression` and returns a list of elements
3525 /// rather than a DIExpression.
3526 LLVM_ABI static std::optional<const DIExpression *>
3528
3529 /// Inserts the elements of \p Expr into \p Ops modified to a canonical form,
3530 /// which uses DW_OP_LLVM_arg (i.e. is a variadic expression) and folds the
3531 /// implied derefence from the \p IsIndirect flag into the expression. This
3532 /// allows us to check equivalence between expressions with differing
3533 /// directness or variadicness.
3535 const DIExpression *Expr,
3536 bool IsIndirect);
3537
3538 /// Determines whether two debug values should produce equivalent DWARF
3539 /// expressions, using their DIExpressions and directness, ignoring the
3540 /// differences between otherwise identical expressions in variadic and
3541 /// non-variadic form and not considering the debug operands.
3542 /// \p FirstExpr is the DIExpression for the first debug value.
3543 /// \p FirstIndirect should be true if the first debug value is indirect; in
3544 /// IR this should be true for dbg.declare intrinsics and false for
3545 /// dbg.values, and in MIR this should be true only for DBG_VALUE instructions
3546 /// whose second operand is an immediate value.
3547 /// \p SecondExpr and \p SecondIndirect have the same meaning as the prior
3548 /// arguments, but apply to the second debug value.
3549 LLVM_ABI static bool isEqualExpression(const DIExpression *FirstExpr,
3550 bool FirstIndirect,
3551 const DIExpression *SecondExpr,
3552 bool SecondIndirect);
3553
3554 /// Append \p Ops with operations to apply the \p Offset.
3556 int64_t Offset);
3557
3558 /// If this is a constant offset, extract it. If there is no expression,
3559 /// return true with an offset of zero.
3560 LLVM_ABI bool extractIfOffset(int64_t &Offset) const;
3561
3562 /// Assuming that the expression operates on an address, extract a constant
3563 /// offset and the successive ops. Return false if the expression contains
3564 /// any incompatible ops (including non-zero DW_OP_LLVM_args - only a single
3565 /// address operand to the expression is permitted).
3566 ///
3567 /// We don't try very hard to interpret the expression because we assume that
3568 /// foldConstantMath has canonicalized the expression.
3569 LLVM_ABI bool
3570 extractLeadingOffset(int64_t &OffsetInBytes,
3571 SmallVectorImpl<uint64_t> &RemainingOps) const;
3572
3573 /// Returns true iff this DIExpression contains at least one instance of
3574 /// `DW_OP_LLVM_arg, n` for all n in [0, N).
3575 LLVM_ABI bool hasAllLocationOps(unsigned N) const;
3576
3577 /// Checks if the last 4 elements of the expression are DW_OP_constu <DWARF
3578 /// Address Space> DW_OP_swap DW_OP_xderef and extracts the <DWARF Address
3579 /// Space>.
3580 LLVM_ABI static const DIExpression *
3581 extractAddressClass(const DIExpression *Expr, unsigned &AddrClass);
3582
3583 /// Used for DIExpression::prepend.
3586 DerefBefore = 1 << 0,
3587 DerefAfter = 1 << 1,
3588 StackValue = 1 << 2,
3589 EntryValue = 1 << 3
3591
3592 /// Prepend \p DIExpr with a deref and offset operation and optionally turn it
3593 /// into a stack value or/and an entry value.
3594 LLVM_ABI static DIExpression *prepend(const DIExpression *Expr, uint8_t Flags,
3595 int64_t Offset = 0);
3596
3597 /// Prepend \p DIExpr with the given opcodes and optionally turn it into a
3598 /// stack value.
3601 bool StackValue = false,
3602 bool EntryValue = false);
3603
3604 /// Append the opcodes \p Ops to \p DIExpr. Unlike \ref appendToStack, the
3605 /// returned expression is a stack value only if \p DIExpr is a stack value.
3606 /// If \p DIExpr describes a fragment, the returned expression will describe
3607 /// the same fragment.
3608 LLVM_ABI static DIExpression *append(const DIExpression *Expr,
3609 ArrayRef<uint64_t> Ops);
3610
3611 /// Convert \p DIExpr into a stack value if it isn't one already by appending
3612 /// DW_OP_deref if needed, and appending \p Ops to the resulting expression.
3613 /// If \p DIExpr describes a fragment, the returned expression will describe
3614 /// the same fragment.
3615 LLVM_ABI static DIExpression *appendToStack(const DIExpression *Expr,
3616 ArrayRef<uint64_t> Ops);
3617
3618 /// Create a copy of \p Expr by appending the given list of \p Ops to each
3619 /// instance of the operand `DW_OP_LLVM_arg, \p ArgNo`. This is used to
3620 /// modify a specific location used by \p Expr, such as when salvaging that
3621 /// location.
3624 unsigned ArgNo,
3625 bool StackValue = false);
3626
3627 /// Create a copy of \p Expr with each instance of
3628 /// `DW_OP_LLVM_arg, \p OldArg` replaced with `DW_OP_LLVM_arg, \p NewArg`,
3629 /// and each instance of `DW_OP_LLVM_arg, Arg` with `DW_OP_LLVM_arg, Arg - 1`
3630 /// for all Arg > \p OldArg.
3631 /// This is used when replacing one of the operands of a debug value list
3632 /// with another operand in the same list and deleting the old operand.
3633 LLVM_ABI static DIExpression *replaceArg(const DIExpression *Expr,
3634 uint64_t OldArg, uint64_t NewArg);
3635
3636 /// Create a DIExpression to describe one part of an aggregate variable that
3637 /// is fragmented across multiple Values. The DW_OP_LLVM_fragment operation
3638 /// will be appended to the elements of \c Expr. If \c Expr already contains
3639 /// a \c DW_OP_LLVM_fragment \c OffsetInBits is interpreted as an offset
3640 /// into the existing fragment.
3641 ///
3642 /// \param OffsetInBits Offset of the piece in bits.
3643 /// \param SizeInBits Size of the piece in bits.
3644 /// \return Creating a fragment expression may fail if \c Expr
3645 /// contains arithmetic operations that would be
3646 /// truncated.
3647 LLVM_ABI static std::optional<DIExpression *>
3648 createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits,
3649 unsigned SizeInBits);
3650
3651 /// Determine the relative position of the fragments passed in.
3652 /// Returns -1 if this is entirely before Other, 0 if this and Other overlap,
3653 /// 1 if this is entirely after Other.
3654 static int fragmentCmp(const FragmentInfo &A, const FragmentInfo &B) {
3655 uint64_t l1 = A.OffsetInBits;
3656 uint64_t l2 = B.OffsetInBits;
3657 uint64_t r1 = l1 + A.SizeInBits;
3658 uint64_t r2 = l2 + B.SizeInBits;
3659 if (r1 <= l2)
3660 return -1;
3661 else if (r2 <= l1)
3662 return 1;
3663 else
3664 return 0;
3665 }
3666
3667 /// Computes a fragment, bit-extract operation if needed, and new constant
3668 /// offset to describe a part of a variable covered by some memory.
3669 ///
3670 /// The memory region starts at:
3671 /// \p SliceStart + \p SliceOffsetInBits
3672 /// And is size:
3673 /// \p SliceSizeInBits
3674 ///
3675 /// The location of the existing variable fragment \p VarFrag is:
3676 /// \p DbgPtr + \p DbgPtrOffsetInBits + \p DbgExtractOffsetInBits.
3677 ///
3678 /// It is intended that these arguments are derived from a debug record:
3679 /// - \p DbgPtr is the (single) DIExpression operand.
3680 /// - \p DbgPtrOffsetInBits is the constant offset applied to \p DbgPtr.
3681 /// - \p DbgExtractOffsetInBits is the offset from a
3682 /// DW_OP_LLVM_bit_extract_[sz]ext operation.
3683 ///
3684 /// Results and return value:
3685 /// - Return false if the result can't be calculated for any reason.
3686 /// - \p Result is set to nullopt if the intersect equals \p VarFarg.
3687 /// - \p Result contains a zero-sized fragment if there's no intersect.
3688 /// - \p OffsetFromLocationInBits is set to the difference between the first
3689 /// bit of the variable location and the first bit of the slice. The
3690 /// magnitude of a negative value therefore indicates the number of bits
3691 /// into the variable fragment that the memory region begins.
3692 ///
3693 /// We don't pass in a debug record directly to get the constituent parts
3694 /// and offsets because different debug records store the information in
3695 /// different places (dbg_assign has two DIExpressions - one contains the
3696 /// fragment info for the entire intrinsic).
3698 const DataLayout &DL, const Value *SliceStart, uint64_t SliceOffsetInBits,
3699 uint64_t SliceSizeInBits, const Value *DbgPtr, int64_t DbgPtrOffsetInBits,
3700 int64_t DbgExtractOffsetInBits, DIExpression::FragmentInfo VarFrag,
3701 std::optional<DIExpression::FragmentInfo> &Result,
3702 int64_t &OffsetFromLocationInBits);
3703
3704 using ExtOps = std::array<uint64_t, 6>;
3705
3706 /// Returns the ops for a zero- or sign-extension in a DIExpression.
3707 LLVM_ABI static ExtOps getExtOps(unsigned FromSize, unsigned ToSize,
3708 bool Signed);
3709
3710 /// Append a zero- or sign-extension to \p Expr. Converts the expression to a
3711 /// stack value if it isn't one already.
3712 LLVM_ABI static DIExpression *appendExt(const DIExpression *Expr,
3713 unsigned FromSize, unsigned ToSize,
3714 bool Signed);
3715
3716 /// Check if fragments overlap between a pair of FragmentInfos.
3717 static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B) {
3718 return fragmentCmp(A, B) == 0;
3719 }
3720
3721 /// Determine the relative position of the fragments described by this
3722 /// DIExpression and \p Other. Calls static fragmentCmp implementation.
3723 int fragmentCmp(const DIExpression *Other) const {
3724 auto Fragment1 = *getFragmentInfo();
3725 auto Fragment2 = *Other->getFragmentInfo();
3726 return fragmentCmp(Fragment1, Fragment2);
3727 }
3728
3729 /// Check if fragments overlap between this DIExpression and \p Other.
3731 if (!isFragment() || !Other->isFragment())
3732 return true;
3733 return fragmentCmp(Other) == 0;
3734 }
3735
3736 /// Check if the expression consists of exactly one entry value operand.
3737 /// (This is the only configuration of entry values that is supported.)
3738 LLVM_ABI bool isEntryValue() const;
3739
3740 /// Try to shorten an expression with an initial constant operand.
3741 /// Returns a new expression and constant on success, or the original
3742 /// expression and constant on failure.
3743 LLVM_ABI std::pair<DIExpression *, const ConstantInt *>
3744 constantFold(const ConstantInt *CI);
3745
3746 /// Try to shorten an expression with constant math operations that can be
3747 /// evaluated at compile time. Returns a new expression on success, or the old
3748 /// expression if there is nothing to be reduced.
3750};
3751
3754 return std::tie(A.SizeInBits, A.OffsetInBits) ==
3755 std::tie(B.SizeInBits, B.OffsetInBits);
3756}
3757
3760 return std::tie(A.SizeInBits, A.OffsetInBits) <
3761 std::tie(B.SizeInBits, B.OffsetInBits);
3762}
3763
3764template <> struct DenseMapInfo<DIExpression::FragmentInfo> {
3766 static const uint64_t MaxVal = std::numeric_limits<uint64_t>::max();
3767
3768 static inline FragInfo getEmptyKey() { return {MaxVal, MaxVal}; }
3769
3770 static inline FragInfo getTombstoneKey() { return {MaxVal - 1, MaxVal - 1}; }
3771
3772 static unsigned getHashValue(const FragInfo &Frag) {
3773 return (Frag.SizeInBits & 0xffff) << 16 | (Frag.OffsetInBits & 0xffff);
3774 }
3775
3776 static bool isEqual(const FragInfo &A, const FragInfo &B) { return A == B; }
3777};
3778
3779/// Holds a DIExpression and keeps track of how many operands have been consumed
3780/// so far.
3783
3784public:
3786 if (!Expr) {
3787 assert(Start == End);
3788 return;
3789 }
3790 Start = Expr->expr_op_begin();
3791 End = Expr->expr_op_end();
3792 }
3793
3795 : Start(Expr.begin()), End(Expr.end()) {}
3796
3798
3799 /// Consume one operation.
3800 std::optional<DIExpression::ExprOperand> take() {
3801 if (Start == End)
3802 return std::nullopt;
3803 return *(Start++);
3804 }
3805
3806 /// Consume N operations.
3807 void consume(unsigned N) { std::advance(Start, N); }
3808
3809 /// Return the current operation.
3810 std::optional<DIExpression::ExprOperand> peek() const {
3811 if (Start == End)
3812 return std::nullopt;
3813 return *(Start);
3814 }
3815
3816 /// Return the next operation.
3817 std::optional<DIExpression::ExprOperand> peekNext() const {
3818 if (Start == End)
3819 return std::nullopt;
3820
3821 auto Next = Start.getNext();
3822 if (Next == End)
3823 return std::nullopt;
3824
3825 return *Next;
3826 }
3827
3828 std::optional<DIExpression::ExprOperand> peekNextN(unsigned N) const {
3829 if (Start == End)
3830 return std::nullopt;
3832 for (unsigned I = 0; I < N; I++) {
3833 Nth = Nth.getNext();
3834 if (Nth == End)
3835 return std::nullopt;
3836 }
3837 return *Nth;
3838 }
3839
3841 this->Start = DIExpression::expr_op_iterator(Expr.begin());
3842 this->End = DIExpression::expr_op_iterator(Expr.end());
3843 }
3844
3845 /// Determine whether there are any operations left in this expression.
3846 operator bool() const { return Start != End; }
3847
3848 DIExpression::expr_op_iterator begin() const { return Start; }
3850
3851 /// Retrieve the fragment information, if any.
3852 std::optional<DIExpression::FragmentInfo> getFragmentInfo() const {
3853 return DIExpression::getFragmentInfo(Start, End);
3854 }
3855};
3856
3857/// Global variables.
3858///
3859/// TODO: Remove DisplayName. It's always equal to Name.
3861 friend class LLVMContextImpl;
3862 friend class MDNode;
3863
3864 bool IsLocalToUnit;
3865 bool IsDefinition;
3866
3868 bool IsLocalToUnit, bool IsDefinition, uint32_t AlignInBits,
3870 : DIVariable(C, DIGlobalVariableKind, Storage, Line, Ops, AlignInBits),
3871 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
3872 ~DIGlobalVariable() = default;
3873
3874 static DIGlobalVariable *
3875 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
3877 bool IsLocalToUnit, bool IsDefinition,
3880 bool ShouldCreate = true) {
3881 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
3883 IsLocalToUnit, IsDefinition, StaticDataMemberDeclaration,
3884 cast_or_null<Metadata>(TemplateParams), AlignInBits,
3885 Annotations.get(), Storage, ShouldCreate);
3886 }
3887 LLVM_ABI static DIGlobalVariable *
3888 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
3889 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
3890 bool IsLocalToUnit, bool IsDefinition,
3893 bool ShouldCreate = true);
3894
3895 TempDIGlobalVariable cloneImpl() const {
3900 getAnnotations());
3901 }
3902
3903public:
3907 unsigned Line, DIType *Type, bool IsLocalToUnit, bool IsDefinition,
3909 uint32_t AlignInBits, DINodeArray Annotations),
3910 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
3915 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
3918 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
3920
3921 TempDIGlobalVariable clone() const { return cloneImpl(); }
3922
3923 bool isLocalToUnit() const { return IsLocalToUnit; }
3924 bool isDefinition() const { return IsDefinition; }
3928 return cast_or_null<DIDerivedType>(getRawStaticDataMemberDeclaration());
3929 }
3930 DINodeArray getAnnotations() const {
3931 return cast_or_null<MDTuple>(getRawAnnotations());
3932 }
3933
3934 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
3937 MDTuple *getTemplateParams() const { return getOperandAs<MDTuple>(7); }
3938 Metadata *getRawAnnotations() const { return getOperand(8); }
3939
3940 static bool classof(const Metadata *MD) {
3941 return MD->getMetadataID() == DIGlobalVariableKind;
3942 }
3943};
3944
3945/// Debug common block.
3946///
3947/// Uses the SubclassData32 Metadata slot.
3948class DICommonBlock : public DIScope {
3949 friend class LLVMContextImpl;
3950 friend class MDNode;
3951
3954
3955 static DICommonBlock *getImpl(LLVMContext &Context, DIScope *Scope,
3957 DIFile *File, unsigned LineNo,
3958 StorageType Storage, bool ShouldCreate = true) {
3959 return getImpl(Context, Scope, Decl, getCanonicalMDString(Context, Name),
3960 File, LineNo, Storage, ShouldCreate);
3961 }
3962 LLVM_ABI static DICommonBlock *getImpl(LLVMContext &Context, Metadata *Scope,
3964 Metadata *File, unsigned LineNo,
3966 bool ShouldCreate = true);
3967
3968 TempDICommonBlock cloneImpl() const {
3970 getFile(), getLineNo());
3971 }
3972
3973public:
3976 DIFile *File, unsigned LineNo),
3977 (Scope, Decl, Name, File, LineNo))
3980 Metadata *File, unsigned LineNo),
3982
3983 TempDICommonBlock clone() const { return cloneImpl(); }
3984
3985 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
3987 return cast_or_null<DIGlobalVariable>(getRawDecl());
3988 }
3989 StringRef getName() const { return getStringOperand(2); }
3990 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
3991 unsigned getLineNo() const { return SubclassData32; }
3992
3993 Metadata *getRawScope() const { return getOperand(0); }
3994 Metadata *getRawDecl() const { return getOperand(1); }
3995 MDString *getRawName() const { return getOperandAs<MDString>(2); }
3996 Metadata *getRawFile() const { return getOperand(3); }
3997
3998 static bool classof(const Metadata *MD) {
3999 return MD->getMetadataID() == DICommonBlockKind;
4000 }
4001};
4002
4003/// Local variable.
4004///
4005/// TODO: Split up flags.
4007 friend class LLVMContextImpl;
4008 friend class MDNode;
4009
4010 unsigned Arg : 16;
4011 DIFlags Flags;
4012
4014 unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
4016 : DIVariable(C, DILocalVariableKind, Storage, Line, Ops, AlignInBits),
4017 Arg(Arg), Flags(Flags) {
4018 assert(Arg < (1 << 16) && "DILocalVariable: Arg out of range");
4019 }
4020 ~DILocalVariable() = default;
4021
4022 static DILocalVariable *getImpl(LLVMContext &Context, DIScope *Scope,
4023 StringRef Name, DIFile *File, unsigned Line,
4024 DIType *Type, unsigned Arg, DIFlags Flags,
4025 uint32_t AlignInBits, DINodeArray Annotations,
4027 bool ShouldCreate = true) {
4028 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
4029 Line, Type, Arg, Flags, AlignInBits, Annotations.get(),
4030 Storage, ShouldCreate);
4031 }
4032 LLVM_ABI static DILocalVariable *
4033 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, Metadata *File,
4034 unsigned Line, Metadata *Type, unsigned Arg, DIFlags Flags,
4036 bool ShouldCreate = true);
4037
4038 TempDILocalVariable cloneImpl() const {
4040 getLine(), getType(), getArg(), getFlags(),
4042 }
4043
4044public:
4047 unsigned Line, DIType *Type, unsigned Arg, DIFlags Flags,
4048 uint32_t AlignInBits, DINodeArray Annotations),
4049 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits,
4050 Annotations))
4053 unsigned Line, Metadata *Type, unsigned Arg, DIFlags Flags,
4055 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits,
4056 Annotations))
4057
4058 TempDILocalVariable clone() const { return cloneImpl(); }
4059
4060 /// Get the local scope for this variable.
4061 ///
4062 /// Variables must be defined in a local scope.
4064 return cast<DILocalScope>(DIVariable::getScope());
4065 }
4066
4067 bool isParameter() const { return Arg; }
4068 unsigned getArg() const { return Arg; }
4069 DIFlags getFlags() const { return Flags; }
4070
4071 DINodeArray getAnnotations() const {
4072 return cast_or_null<MDTuple>(getRawAnnotations());
4073 }
4074 Metadata *getRawAnnotations() const { return getOperand(4); }
4075
4076 bool isArtificial() const { return getFlags() & FlagArtificial; }
4077 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
4078
4079 /// Check that a location is valid for this variable.
4080 ///
4081 /// Check that \c DL exists, is in the same subprogram, and has the same
4082 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
4083 /// to a \a DbgInfoIntrinsic.)
4085 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
4086 }
4087
4088 static bool classof(const Metadata *MD) {
4089 return MD->getMetadataID() == DILocalVariableKind;
4090 }
4091};
4092
4093/// Label.
4094///
4095/// Uses the SubclassData32 Metadata slot.
4096class DILabel : public DINode {
4097 friend class LLVMContextImpl;
4098 friend class MDNode;
4099
4100 unsigned Column;
4101 std::optional<unsigned> CoroSuspendIdx;
4102 bool IsArtificial;
4103
4104 DILabel(LLVMContext &C, StorageType Storage, unsigned Line, unsigned Column,
4105 bool IsArtificial, std::optional<unsigned> CoroSuspendIdx,
4107 ~DILabel() = default;
4108
4109 static DILabel *getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
4110 DIFile *File, unsigned Line, unsigned Column,
4111 bool IsArtificial,
4112 std::optional<unsigned> CoroSuspendIdx,
4113 StorageType Storage, bool ShouldCreate = true) {
4114 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
4115 Line, Column, IsArtificial, CoroSuspendIdx, Storage,
4116 ShouldCreate);
4117 }
4118 LLVM_ABI static DILabel *
4119 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, Metadata *File,
4120 unsigned Line, unsigned Column, bool IsArtificial,
4121 std::optional<unsigned> CoroSuspendIdx, StorageType Storage,
4122 bool ShouldCreate = true);
4123
4124 TempDILabel cloneImpl() const {
4128 }
4129
4130public:
4133 unsigned Line, unsigned Column, bool IsArtificial,
4134 std::optional<unsigned> CoroSuspendIdx),
4135 (Scope, Name, File, Line, Column, IsArtificial,
4136 CoroSuspendIdx))
4139 unsigned Line, unsigned Column, bool IsArtificial,
4140 std::optional<unsigned> CoroSuspendIdx),
4141 (Scope, Name, File, Line, Column, IsArtificial,
4142 CoroSuspendIdx))
4143
4144 TempDILabel clone() const { return cloneImpl(); }
4145
4146 /// Get the local scope for this label.
4147 ///
4148 /// Labels must be defined in a local scope.
4150 return cast_or_null<DILocalScope>(getRawScope());
4151 }
4152 unsigned getLine() const { return SubclassData32; }
4153 unsigned getColumn() const { return Column; }
4154 StringRef getName() const { return getStringOperand(1); }
4155 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
4156 bool isArtificial() const { return IsArtificial; }
4157 std::optional<unsigned> getCoroSuspendIdx() const { return CoroSuspendIdx; }
4158
4159 Metadata *getRawScope() const { return getOperand(0); }
4160 MDString *getRawName() const { return getOperandAs<MDString>(1); }
4161 Metadata *getRawFile() const { return getOperand(2); }
4162
4163 /// Check that a location is valid for this label.
4164 ///
4165 /// Check that \c DL exists, is in the same subprogram, and has the same
4166 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
4167 /// to a \a DbgInfoIntrinsic.)
4169 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
4170 }
4171
4172 static bool classof(const Metadata *MD) {
4173 return MD->getMetadataID() == DILabelKind;
4174 }
4175};
4176
4177class DIObjCProperty : public DINode {
4178 friend class LLVMContextImpl;
4179 friend class MDNode;
4180
4181 unsigned Line;
4182 unsigned Attributes;
4183
4185 unsigned Attributes, ArrayRef<Metadata *> Ops);
4186 ~DIObjCProperty() = default;
4187
4188 static DIObjCProperty *
4189 getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
4190 StringRef GetterName, StringRef SetterName, unsigned Attributes,
4191 DIType *Type, StorageType Storage, bool ShouldCreate = true) {
4192 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
4194 getCanonicalMDString(Context, SetterName), Attributes, Type,
4195 Storage, ShouldCreate);
4196 }
4197 LLVM_ABI static DIObjCProperty *
4198 getImpl(LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
4199 MDString *GetterName, MDString *SetterName, unsigned Attributes,
4200 Metadata *Type, StorageType Storage, bool ShouldCreate = true);
4201
4202 TempDIObjCProperty cloneImpl() const {
4203 return getTemporary(getContext(), getName(), getFile(), getLine(),
4205 getType());
4206 }
4207
4208public:
4210 (StringRef Name, DIFile *File, unsigned Line,
4212 unsigned Attributes, DIType *Type),
4213 (Name, File, Line, GetterName, SetterName, Attributes,
4214 Type))
4216 (MDString * Name, Metadata *File, unsigned Line,
4218 unsigned Attributes, Metadata *Type),
4219 (Name, File, Line, GetterName, SetterName, Attributes,
4220 Type))
4221
4222 TempDIObjCProperty clone() const { return cloneImpl(); }
4223
4224 unsigned getLine() const { return Line; }
4225 unsigned getAttributes() const { return Attributes; }
4226 StringRef getName() const { return getStringOperand(0); }
4227 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
4230 DIType *getType() const { return cast_or_null<DIType>(getRawType()); }
4231
4233 if (auto *F = getFile())
4234 return F->getFilename();
4235 return "";
4236 }
4237
4239 if (auto *F = getFile())
4240 return F->getDirectory();
4241 return "";
4242 }
4243
4244 MDString *getRawName() const { return getOperandAs<MDString>(0); }
4245 Metadata *getRawFile() const { return getOperand(1); }
4246 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
4247 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
4248 Metadata *getRawType() const { return getOperand(4); }
4249
4250 static bool classof(const Metadata *MD) {
4251 return MD->getMetadataID() == DIObjCPropertyKind;
4252 }
4253};
4254
4255/// An imported module (C++ using directive or similar).
4256///
4257/// Uses the SubclassData32 Metadata slot.
4258class DIImportedEntity : public DINode {
4259 friend class LLVMContextImpl;
4260 friend class MDNode;
4261
4263 unsigned Line, ArrayRef<Metadata *> Ops)
4264 : DINode(C, DIImportedEntityKind, Storage, Tag, Ops) {
4266 }
4267 ~DIImportedEntity() = default;
4268
4269 static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
4271 unsigned Line, StringRef Name,
4272 DINodeArray Elements, StorageType Storage,
4273 bool ShouldCreate = true) {
4274 return getImpl(Context, Tag, Scope, Entity, File, Line,
4275 getCanonicalMDString(Context, Name), Elements.get(), Storage,
4276 ShouldCreate);
4277 }
4278 LLVM_ABI static DIImportedEntity *
4279 getImpl(LLVMContext &Context, unsigned Tag, Metadata *Scope, Metadata *Entity,
4280 Metadata *File, unsigned Line, MDString *Name, Metadata *Elements,
4281 StorageType Storage, bool ShouldCreate = true);
4282
4283 TempDIImportedEntity cloneImpl() const {
4284 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
4285 getFile(), getLine(), getName(), getElements());
4286 }
4287
4288public:
4290 (unsigned Tag, DIScope *Scope, DINode *Entity, DIFile *File,
4291 unsigned Line, StringRef Name = "",
4292 DINodeArray Elements = nullptr),
4293 (Tag, Scope, Entity, File, Line, Name, Elements))
4297 Metadata *Elements = nullptr),
4298 (Tag, Scope, Entity, File, Line, Name, Elements))
4299
4300 TempDIImportedEntity clone() const { return cloneImpl(); }
4301
4302 unsigned getLine() const { return SubclassData32; }
4303 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
4304 DINode *getEntity() const { return cast_or_null<DINode>(getRawEntity()); }
4305 StringRef getName() const { return getStringOperand(2); }
4306 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
4307 DINodeArray getElements() const {
4308 return cast_or_null<MDTuple>(getRawElements());
4309 }
4310
4311 Metadata *getRawScope() const { return getOperand(0); }
4312 Metadata *getRawEntity() const { return getOperand(1); }
4313 MDString *getRawName() const { return getOperandAs<MDString>(2); }
4314 Metadata *getRawFile() const { return getOperand(3); }
4315 Metadata *getRawElements() const { return getOperand(4); }
4316
4317 static bool classof(const Metadata *MD) {
4318 return MD->getMetadataID() == DIImportedEntityKind;
4319 }
4320};
4321
4322/// A pair of DIGlobalVariable and DIExpression.
4324 friend class LLVMContextImpl;
4325 friend class MDNode;
4326
4329 : MDNode(C, DIGlobalVariableExpressionKind, Storage, Ops) {}
4330 ~DIGlobalVariableExpression() = default;
4331
4333 getImpl(LLVMContext &Context, Metadata *Variable, Metadata *Expression,
4334 StorageType Storage, bool ShouldCreate = true);
4335
4336 TempDIGlobalVariableExpression cloneImpl() const {
4338 }
4339
4340public:
4342 (Metadata * Variable, Metadata *Expression),
4343 (Variable, Expression))
4344
4345 TempDIGlobalVariableExpression clone() const { return cloneImpl(); }
4346
4347 Metadata *getRawVariable() const { return getOperand(0); }
4348
4350 return cast_or_null<DIGlobalVariable>(getRawVariable());
4351 }
4352
4353 Metadata *getRawExpression() const { return getOperand(1); }
4354
4356 return cast<DIExpression>(getRawExpression());
4357 }
4358
4359 static bool classof(const Metadata *MD) {
4360 return MD->getMetadataID() == DIGlobalVariableExpressionKind;
4361 }
4362};
4363
4364/// Macro Info DWARF-like metadata node.
4365///
4366/// A metadata node with a DWARF macro info (i.e., a constant named
4367/// \c DW_MACINFO_*, defined in llvm/BinaryFormat/Dwarf.h). Called \a
4368/// DIMacroNode
4369/// because it's potentially used for non-DWARF output.
4370///
4371/// Uses the SubclassData16 Metadata slot.
4372class DIMacroNode : public MDNode {
4373 friend class LLVMContextImpl;
4374 friend class MDNode;
4375
4376protected:
4377 DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType,
4379 : MDNode(C, ID, Storage, Ops1, Ops2) {
4380 assert(MIType < 1u << 16);
4381 SubclassData16 = MIType;
4382 }
4383 ~DIMacroNode() = default;
4384
4385 template <class Ty> Ty *getOperandAs(unsigned I) const {
4386 return cast_or_null<Ty>(getOperand(I));
4387 }
4388
4389 StringRef getStringOperand(unsigned I) const {
4390 if (auto *S = getOperandAs<MDString>(I))
4391 return S->getString();
4392 return StringRef();
4393 }
4394
4396 if (S.empty())
4397 return nullptr;
4398 return MDString::get(Context, S);
4399 }
4400
4401public:
4402 unsigned getMacinfoType() const { return SubclassData16; }
4403
4404 static bool classof(const Metadata *MD) {
4405 switch (MD->getMetadataID()) {
4406 default:
4407 return false;
4408 case DIMacroKind:
4409 case DIMacroFileKind:
4410 return true;
4411 }
4412 }
4413};
4414
4415/// Macro
4416///
4417/// Uses the SubclassData32 Metadata slot.
4418class DIMacro : public DIMacroNode {
4419 friend class LLVMContextImpl;
4420 friend class MDNode;
4421
4422 DIMacro(LLVMContext &C, StorageType Storage, unsigned MIType, unsigned Line,
4424 : DIMacroNode(C, DIMacroKind, Storage, MIType, Ops) {
4426 }
4427 ~DIMacro() = default;
4428
4429 static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
4431 bool ShouldCreate = true) {
4432 return getImpl(Context, MIType, Line, getCanonicalMDString(Context, Name),
4433 getCanonicalMDString(Context, Value), Storage, ShouldCreate);
4434 }
4435 LLVM_ABI static DIMacro *getImpl(LLVMContext &Context, unsigned MIType,
4436 unsigned Line, MDString *Name,
4437 MDString *Value, StorageType Storage,
4438 bool ShouldCreate = true);
4439
4440 TempDIMacro cloneImpl() const {
4442 getValue());
4443 }
4444
4445public:
4447 (unsigned MIType, unsigned Line, StringRef Name,
4448 StringRef Value = ""),
4449 (MIType, Line, Name, Value))
4451 (unsigned MIType, unsigned Line, MDString *Name,
4454
4455 TempDIMacro clone() const { return cloneImpl(); }
4456
4457 unsigned getLine() const { return SubclassData32; }
4458
4459 StringRef getName() const { return getStringOperand(0); }
4460 StringRef getValue() const { return getStringOperand(1); }
4461
4462 MDString *getRawName() const { return getOperandAs<MDString>(0); }
4463 MDString *getRawValue() const { return getOperandAs<MDString>(1); }
4464
4465 static bool classof(const Metadata *MD) {
4466 return MD->getMetadataID() == DIMacroKind;
4467 }
4468};
4469
4470/// Macro file
4471///
4472/// Uses the SubclassData32 Metadata slot.
4473class DIMacroFile : public DIMacroNode {
4474 friend class LLVMContextImpl;
4475 friend class MDNode;
4476
4478 unsigned Line, ArrayRef<Metadata *> Ops)
4479 : DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops) {
4481 }
4482 ~DIMacroFile() = default;
4483
4484 static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
4485 unsigned Line, DIFile *File,
4486 DIMacroNodeArray Elements, StorageType Storage,
4487 bool ShouldCreate = true) {
4488 return getImpl(Context, MIType, Line, static_cast<Metadata *>(File),
4489 Elements.get(), Storage, ShouldCreate);
4490 }
4491
4492 LLVM_ABI static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
4493 unsigned Line, Metadata *File,
4495 bool ShouldCreate = true);
4496
4497 TempDIMacroFile cloneImpl() const {
4499 getElements());
4500 }
4501
4502public:
4504 (unsigned MIType, unsigned Line, DIFile *File,
4505 DIMacroNodeArray Elements),
4506 (MIType, Line, File, Elements))
4508 (unsigned MIType, unsigned Line, Metadata *File,
4511
4512 TempDIMacroFile clone() const { return cloneImpl(); }
4513
4514 void replaceElements(DIMacroNodeArray Elements) {
4515#ifndef NDEBUG
4516 for (DIMacroNode *Op : getElements())
4517 assert(is_contained(Elements->operands(), Op) &&
4518 "Lost a macro node during macro node list replacement");
4519#endif
4520 replaceOperandWith(1, Elements.get());
4521 }
4522
4523 unsigned getLine() const { return SubclassData32; }
4524 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
4525
4526 DIMacroNodeArray getElements() const {
4527 return cast_or_null<MDTuple>(getRawElements());
4528 }
4529
4530 Metadata *getRawFile() const { return getOperand(0); }
4531 Metadata *getRawElements() const { return getOperand(1); }
4532
4533 static bool classof(const Metadata *MD) {
4534 return MD->getMetadataID() == DIMacroFileKind;
4535 }
4536};
4537
4538/// List of ValueAsMetadata, to be used as an argument to a dbg.value
4539/// intrinsic.
4542 friend class LLVMContextImpl;
4544
4546
4548 : Metadata(DIArgListKind, Uniqued), ReplaceableMetadataImpl(Context),
4549 Args(Args) {
4550 track();
4551 }
4552 ~DIArgList() { untrack(); }
4553
4554 LLVM_ABI void track();
4555 LLVM_ABI void untrack();
4556 void dropAllReferences(bool Untrack);
4557
4558public:
4559 LLVM_ABI static DIArgList *get(LLVMContext &Context,
4560 ArrayRef<ValueAsMetadata *> Args);
4561
4562 ArrayRef<ValueAsMetadata *> getArgs() const { return Args; }
4563
4564 iterator args_begin() { return Args.begin(); }
4565 iterator args_end() { return Args.end(); }
4566
4567 static bool classof(const Metadata *MD) {
4568 return MD->getMetadataID() == DIArgListKind;
4569 }
4570
4573 }
4574
4575 LLVM_ABI void handleChangedOperand(void *Ref, Metadata *New);
4576};
4577
4578/// Identifies a unique instance of a variable.
4579///
4580/// Storage for identifying a potentially inlined instance of a variable,
4581/// or a fragment thereof. This guarantees that exactly one variable instance
4582/// may be identified by this class, even when that variable is a fragment of
4583/// an aggregate variable and/or there is another inlined instance of the same
4584/// source code variable nearby.
4585/// This class does not necessarily uniquely identify that variable: it is
4586/// possible that a DebugVariable with different parameters may point to the
4587/// same variable instance, but not that one DebugVariable points to multiple
4588/// variable instances.
4591
4592 const DILocalVariable *Variable;
4593 std::optional<FragmentInfo> Fragment;
4594 const DILocation *InlinedAt;
4595
4596 /// Fragment that will overlap all other fragments. Used as default when
4597 /// caller demands a fragment.
4598 LLVM_ABI static const FragmentInfo DefaultFragment;
4599
4600public:
4602
4604 std::optional<FragmentInfo> FragmentInfo,
4605 const DILocation *InlinedAt)
4606 : Variable(Var), Fragment(FragmentInfo), InlinedAt(InlinedAt) {}
4607
4608 DebugVariable(const DILocalVariable *Var, const DIExpression *DIExpr,
4609 const DILocation *InlinedAt)
4610 : Variable(Var),
4611 Fragment(DIExpr ? DIExpr->getFragmentInfo() : std::nullopt),
4612 InlinedAt(InlinedAt) {}
4613
4614 const DILocalVariable *getVariable() const { return Variable; }
4615 std::optional<FragmentInfo> getFragment() const { return Fragment; }
4616 const DILocation *getInlinedAt() const { return InlinedAt; }
4617
4619 return Fragment.value_or(DefaultFragment);
4620 }
4621
4622 static bool isDefaultFragment(const FragmentInfo F) {
4623 return F == DefaultFragment;
4624 }
4625
4626 bool operator==(const DebugVariable &Other) const {
4627 return std::tie(Variable, Fragment, InlinedAt) ==
4628 std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
4629 }
4630
4631 bool operator<(const DebugVariable &Other) const {
4632 return std::tie(Variable, Fragment, InlinedAt) <
4633 std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
4634 }
4635};
4636
4637template <> struct DenseMapInfo<DebugVariable> {
4639
4640 /// Empty key: no key should be generated that has no DILocalVariable.
4641 static inline DebugVariable getEmptyKey() {
4642 return DebugVariable(nullptr, std::nullopt, nullptr);
4643 }
4644
4645 /// Difference in tombstone is that the Optional is meaningful.
4647 return DebugVariable(nullptr, {{0, 0}}, nullptr);
4648 }
4649
4650 static unsigned getHashValue(const DebugVariable &D) {
4651 unsigned HV = 0;
4652 const std::optional<FragmentInfo> Fragment = D.getFragment();
4653 if (Fragment)
4655
4656 return hash_combine(D.getVariable(), HV, D.getInlinedAt());
4657 }
4658
4659 static bool isEqual(const DebugVariable &A, const DebugVariable &B) {
4660 return A == B;
4661 }
4662};
4663
4664/// Identifies a unique instance of a whole variable (discards/ignores fragment
4665/// information).
4667public:
4669 : DebugVariable(V.getVariable(), std::nullopt, V.getInlinedAt()) {}
4670};
4671
4672template <>
4674 : public DenseMapInfo<DebugVariable> {};
4675} // end namespace llvm
4676
4677#undef DEFINE_MDNODE_GET_UNPACK_IMPL
4678#undef DEFINE_MDNODE_GET_UNPACK
4679#undef DEFINE_MDNODE_GET
4680
4681#endif // LLVM_IR_DEBUGINFOMETADATA_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Kernel Attributes
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static std::string getLinkageName(GlobalValue::LinkageTypes LT)
Definition: AsmWriter.cpp:3453
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_ABI
Definition: Compiler.h:213
This file contains the declarations for the subclasses of Constant, which represent the different fla...
dxil translate DXIL Translate Metadata
#define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS)
#define DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS)
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
static unsigned getNextComponentInDiscriminator(unsigned D)
Returns the next component stored in discriminator.
Definition: Discriminator.h:38
static unsigned getUnsignedFromPrefixEncoding(unsigned U)
Reverse transformation as getPrefixEncodingFromUnsigned.
Definition: Discriminator.h:30
std::string Name
bool End
Definition: ELF_riscv.cpp:480
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static SmallString< 128 > getFilename(const DIScope *SP)
Extract a filename for a DIScope.
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
This file contains the declarations for metadata subclasses.
#define T
This file defines the PointerUnion class, which is a discriminated union of pointer types.
static StringRef getName(Value *V)
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:51
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:45
This file contains some templates that are useful if you are working with the STL at all.
static enum BaseType getBaseType(const Value *Val)
Return the baseType for Val which states whether Val is exclusively derived from constant/null,...
This file defines the SmallVector class.
static uint32_t getFlags(const Symbol *Sym)
Definition: TapiFile.cpp:26
static SymbolRef::Type getType(const Symbol *Sym)
Definition: TapiFile.cpp:39
Class for arbitrary precision integers.
Definition: APInt.h:78
Annotations lets you mark points and ranges inside source code, for tests:
Definition: Annotations.h:53
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
iterator end() const
Definition: ArrayRef.h:136
iterator begin() const
Definition: ArrayRef.h:135
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:535
This is the shared class of boolean and integer constants.
Definition: Constants.h:87
This is an important base class in LLVM.
Definition: Constant.h:43
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
ArrayRef< ValueAsMetadata * > getArgs() const
LLVM_ABI void handleChangedOperand(void *Ref, Metadata *New)
static bool classof(const Metadata *MD)
static LLVM_ABI DIArgList * get(LLVMContext &Context, ArrayRef< ValueAsMetadata * > Args)
SmallVector< DbgVariableRecord * > getAllDbgVariableRecordUsers()
Assignment ID.
static bool classof(const Metadata *MD)
SmallVector< DbgVariableRecord * > getAllDbgVariableRecordUsers()
static TempDIAssignID getTemporary(LLVMContext &Context)
static DIAssignID * getDistinct(LLVMContext &Context)
void replaceOperandWith(unsigned I, Metadata *New)=delete
Basic type, like 'int' or 'float'.
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags
DIBasicType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, uint32_t AlignInBits, unsigned Encoding, uint32_t NumExtraInhabitants, DIFlags Flags, ArrayRef< Metadata * > Ops)
TempDIBasicType cloneImpl() const
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags unsigned StringRef uint64_t uint32_t unsigned uint32_t DIFlags Flags unsigned MDString Metadata uint32_t unsigned uint32_t DIFlags Flags TempDIBasicType clone() const
~DIBasicType()=default
static bool classof(const Metadata *MD)
DIBasicType(LLVMContext &C, StorageType Storage, unsigned Tag, uint32_t AlignInBits, unsigned Encoding, uint32_t NumExtraInhabitants, DIFlags Flags, ArrayRef< Metadata * > Ops)
static DIBasicType * getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, uint32_t NumExtraInhabitants, DIFlags Flags, StorageType Storage, bool ShouldCreate=true)
static DIBasicType * getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, uint32_t NumExtraInhabitants, DIFlags Flags, StorageType Storage, bool ShouldCreate=true)
unsigned StringRef uint64_t SizeInBits
LLVM_ABI std::optional< Signedness > getSignedness() const
Return the signedness of this type, or std::nullopt if this type is neither signed nor unsigned.
unsigned getEncoding() const
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags unsigned StringRef uint64_t uint32_t unsigned uint32_t NumExtraInhabitants
unsigned StringRef Name
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t AlignInBits
DEFINE_MDNODE_GET(DIBasicType,(unsigned Tag, StringRef Name),(Tag, Name, 0, 0, 0, 0, FlagZero)) DEFINE_MDNODE_GET(DIBasicType
Debug common block.
Metadata * getRawScope() const
Metadata Metadata MDString Metadata unsigned LineNo TempDICommonBlock clone() const
Metadata * getRawDecl() const
Metadata Metadata * Decl
Metadata * getRawFile() const
Metadata Metadata MDString Metadata unsigned LineNo
Metadata Metadata MDString * Name
MDString * getRawName() const
DIFile * getFile() const
static bool classof(const Metadata *MD)
unsigned getLineNo() const
Metadata Metadata MDString Metadata * File
StringRef getName() const
DIScope * getScope() const
DEFINE_MDNODE_GET(DICommonBlock,(DIScope *Scope, DIGlobalVariable *Decl, StringRef Name, DIFile *File, unsigned LineNo),(Scope, Decl, Name, File, LineNo)) DEFINE_MDNODE_GET(DICommonBlock
DIGlobalVariable * getDecl() const
MDString * getRawSplitDebugFilename() const
bool getDebugInfoForProfiling() const
Metadata * getRawRetainedTypes() const
static LLVM_ABI const char * nameTableKindString(DebugNameTableKind PK)
static LLVM_ABI const char * emissionKindString(DebugEmissionKind EK)
void setSplitDebugInlining(bool SplitDebugInlining)
DICompositeTypeArray getEnumTypes() const
DebugEmissionKind getEmissionKind() const
unsigned Metadata * File
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata * Macros
unsigned Metadata MDString bool MDString * Flags
bool isDebugDirectivesOnly() const
StringRef getFlags() const
MDString * getRawProducer() const
void replaceEnumTypes(DICompositeTypeArray N)
Replace arrays.
MDString * getRawSysRoot() const
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata * EnumTypes
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata * RetainedTypes
StringRef getSDK() const
static void getIfExists()=delete
bool getRangesBaseAddress() const
DIMacroNodeArray getMacros() const
unsigned getRuntimeVersion() const
Metadata * getRawMacros() const
void replaceRetainedTypes(DITypeArray N)
static bool classof(const Metadata *MD)
void replaceGlobalVariables(DIGlobalVariableExpressionArray N)
void replaceMacros(DIMacroNodeArray N)
bool getSplitDebugInlining() const
StringRef getSysRoot() const
DebugNameTableKind getNameTableKind() const
MDString * getRawSDK() const
MDString * getRawFlags() const
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata * GlobalVariables
DIImportedEntityArray getImportedEntities() const
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString MDString * SDK
unsigned Metadata MDString * Producer
Metadata * getRawEnumTypes() const
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString * SysRoot
StringRef getProducer() const
unsigned Metadata MDString bool MDString unsigned MDString * SplitDebugFilename
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata * ImportedEntities
void setDWOId(uint64_t DwoId)
DIScopeArray getRetainedTypes() const
void replaceImportedEntities(DIImportedEntityArray N)
Metadata * getRawGlobalVariables() const
DIGlobalVariableExpressionArray getGlobalVariables() const
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString MDString SDK TempDICompileUnit clone() const
unsigned getSourceLanguage() const
Metadata * getRawImportedEntities() const
uint64_t getDWOId() const
StringRef getSplitDebugFilename() const
static void get()=delete
DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(DICompileUnit,(unsigned SourceLanguage, DIFile *File, StringRef Producer, bool IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling, DebugNameTableKind NameTableKind, bool RangesBaseAddress, StringRef SysRoot, StringRef SDK),(SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling,(unsigned) NameTableKind, RangesBaseAddress, SysRoot, SDK)) DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(DICompileUnit
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t AlignInBits
Metadata * getRawVTableHolder() const
DIExpression * getRankExp() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata * DataLocation
static LLVM_ABI DICompositeType * buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, Metadata *SizeInBits, uint32_t AlignInBits, Metadata *OffsetInBits, Metadata *Specification, uint32_t NumExtraInhabitants, DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, std::optional< uint32_t > EnumKind, Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator, Metadata *DataLocation, Metadata *Associated, Metadata *Allocated, Metadata *Rank, Metadata *Annotations, Metadata *BitStride)
Build a DICompositeType with the given ODR identifier.
unsigned MDString Metadata unsigned Line
Metadata * getRawRank() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata * Elements
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata * Annotations
Metadata * getRawSpecification() const
DIExpression * getAssociatedExp() const
DIVariable * getAllocated() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString * Identifier
DIExpression * getDataLocationExp() const
Metadata * getRawDiscriminator() const
static LLVM_ABI DICompositeType * getODRTypeIfExists(LLVMContext &Context, MDString &Identifier)
DIVariable * getAssociated() const
DIDerivedType * getDiscriminator() const
DIVariable * getDataLocation() const
unsigned getRuntimeLang() const
DIType * getSpecification() const
Metadata * getRawElements() const
unsigned MDString * Name
void replaceVTableHolder(DIType *VTableHolder)
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata * Discriminator
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata * TemplateParams
StringRef getIdentifier() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t OffsetInBits
unsigned MDString Metadata unsigned Metadata * Scope
unsigned MDString Metadata * File
Metadata * getRawDataLocation() const
Metadata * getRawTemplateParams() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Flags
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata * Allocated
DINodeArray getElements() const
DITemplateParameterArray getTemplateParams() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata Metadata * Specification
Metadata * getRawAnnotations() const
Metadata * getRawAllocated() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata * VTableHolder
DIExpression * getAllocatedExp() const
void replaceElements(DINodeArray Elements)
Replace operands.
ConstantInt * getBitStrideConst() const
std::optional< uint32_t > getEnumKind() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t SizeInBits
DIType * getVTableHolder() const
DINodeArray getAnnotations() const
Metadata * getRawAssociated() const
ConstantInt * getRankConst() const
void replaceTemplateParams(DITemplateParameterArray TemplateParams)
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata * Associated
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata Metadata uint32_t NumExtraInhabitants
Metadata * getRawBitStride() const
Metadata * getRawBaseType() const
DEFINE_MDNODE_GET(DICompositeType,(unsigned Tag, StringRef Name, DIFile *File, unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags, DINodeArray Elements, unsigned RuntimeLang, std::optional< uint32_t > EnumKind, DIType *VTableHolder, DITemplateParameterArray TemplateParams=nullptr, StringRef Identifier="", DIDerivedType *Discriminator=nullptr, Metadata *DataLocation=nullptr, Metadata *Associated=nullptr, Metadata *Allocated=nullptr, Metadata *Rank=nullptr, DINodeArray Annotations=nullptr, DIType *Specification=nullptr, uint32_t NumExtraInhabitants=0, Metadata *BitStride=nullptr),(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits, Specification, NumExtraInhabitants, Flags, Elements, RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier, Discriminator, DataLocation, Associated, Allocated, Rank, Annotations, BitStride)) DEFINE_MDNODE_GET(DICompositeType
MDString * getRawIdentifier() const
static bool classof(const Metadata *MD)
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata * Rank
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata Metadata uint32_t Metadata * BitStride
DIType * getBaseType() const
Metadata * getRawExtraData() const
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata * OffsetInBits
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > std::optional< PtrAuthData > DIFlags Flags
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t AlignInBits
DINodeArray getAnnotations() const
Get annotations associated with this derived type.
DEFINE_MDNODE_GET(DIDerivedType,(unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, Metadata *SizeInBits, uint32_t AlignInBits, Metadata *OffsetInBits, std::optional< unsigned > DWARFAddressSpace, std::optional< PtrAuthData > PtrAuthData, DIFlags Flags, Metadata *ExtraData=nullptr, Metadata *Annotations=nullptr),(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData, Flags, ExtraData, Annotations)) DEFINE_MDNODE_GET(DIDerivedType
Metadata * getExtraData() const
Get extra data associated with this derived type.
DITemplateParameterArray getTemplateParams() const
Get the template parameters from a template alias.
unsigned StringRef DIFile * File
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > std::optional< PtrAuthData > DIFlags Metadata DINodeArray Annotations
DIObjCProperty * getObjCProperty() const
unsigned StringRef DIFile unsigned DIScope * Scope
Metadata * getRawAnnotations() const
LLVM_ABI DIType * getClassType() const
Get casted version of extra data.
static bool classof(const Metadata *MD)
LLVM_ABI Constant * getConstant() const
unsigned StringRef DIFile unsigned DIScope DIType Metadata * SizeInBits
LLVM_ABI Constant * getStorageOffsetInBits() const
LLVM_ABI Constant * getDiscriminantValue() const
unsigned StringRef Name
LLVM_ABI uint32_t getVBPtrOffset() const
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > std::optional< PtrAuthData > DIFlags Metadata * ExtraData
unsigned StringRef DIFile unsigned Line
Enumeration value.
int64_t bool MDString APInt(64, Value, !IsUnsigned)
const APInt & getValue() const
int64_t bool MDString Name APInt bool MDString Name TempDIEnumerator clone() const
MDString * getRawName() const
StringRef getName() const
DEFINE_MDNODE_GET(DIEnumerator,(int64_t Value, bool IsUnsigned, StringRef Name),(APInt(64, Value, !IsUnsigned), IsUnsigned, Name)) DEFINE_MDNODE_GET(DIEnumerator
static bool classof(const Metadata *MD)
int64_t bool MDString * Name
Holds a DIExpression and keeps track of how many operands have been consumed so far.
std::optional< DIExpression::ExprOperand > peekNext() const
Return the next operation.
std::optional< DIExpression::FragmentInfo > getFragmentInfo() const
Retrieve the fragment information, if any.
DIExpressionCursor(const DIExpressionCursor &)=default
DIExpressionCursor(const DIExpression *Expr)
DIExpression::expr_op_iterator end() const
std::optional< DIExpression::ExprOperand > peekNextN(unsigned N) const
std::optional< DIExpression::ExprOperand > peek() const
Return the current operation.
void consume(unsigned N)
Consume N operations.
std::optional< DIExpression::ExprOperand > take()
Consume one operation.
DIExpressionCursor(ArrayRef< uint64_t > Expr)
DIExpression::expr_op_iterator begin() const
void assignNewExpr(ArrayRef< uint64_t > Expr)
A lightweight wrapper around an expression operand.
LLVM_ABI unsigned getSize() const
Return the size of the operand.
uint64_t getArg(unsigned I) const
Get an argument to the operand.
uint64_t getOp() const
Get the operand code.
const uint64_t * get() const
void appendToVector(SmallVectorImpl< uint64_t > &V) const
Append the elements of this operand to V.
An iterator for expression operands.
bool operator==(const expr_op_iterator &X) const
std::input_iterator_tag iterator_category
const ExprOperand * operator->() const
bool operator!=(const expr_op_iterator &X) const
const ExprOperand & operator*() const
expr_op_iterator getNext() const
Get the next iterator.
DWARF expression.
element_iterator elements_end() const
LLVM_ABI bool isEntryValue() const
Check if the expression consists of exactly one entry value operand.
iterator_range< expr_op_iterator > expr_ops() const
bool isFragment() const
Return whether this is a piece of an aggregate variable.
static LLVM_ABI DIExpression * append(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Append the opcodes Ops to DIExpr.
std::array< uint64_t, 6 > ExtOps
unsigned getNumElements() const
ArrayRef< uint64_t >::iterator element_iterator
static LLVM_ABI ExtOps getExtOps(unsigned FromSize, unsigned ToSize, bool Signed)
Returns the ops for a zero- or sign-extension in a DIExpression.
expr_op_iterator expr_op_begin() const
Visit the elements via ExprOperand wrappers.
LLVM_ABI bool extractIfOffset(int64_t &Offset) const
If this is a constant offset, extract it.
static LLVM_ABI void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
DbgVariableFragmentInfo FragmentInfo
int fragmentCmp(const DIExpression *Other) const
Determine the relative position of the fragments described by this DIExpression and Other.
LLVM_ABI bool startsWithDeref() const
Return whether the first element a DW_OP_deref.
static LLVM_ABI bool isEqualExpression(const DIExpression *FirstExpr, bool FirstIndirect, const DIExpression *SecondExpr, bool SecondIndirect)
Determines whether two debug values should produce equivalent DWARF expressions, using their DIExpres...
expr_op_iterator expr_op_end() const
LLVM_ABI bool isImplicit() const
Return whether this is an implicit location description.
DEFINE_MDNODE_GET(DIExpression,(ArrayRef< uint64_t > Elements),(Elements)) TempDIExpression clone() const
static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B)
Check if fragments overlap between a pair of FragmentInfos.
static LLVM_ABI bool calculateFragmentIntersect(const DataLayout &DL, const Value *SliceStart, uint64_t SliceOffsetInBits, uint64_t SliceSizeInBits, const Value *DbgPtr, int64_t DbgPtrOffsetInBits, int64_t DbgExtractOffsetInBits, DIExpression::FragmentInfo VarFrag, std::optional< DIExpression::FragmentInfo > &Result, int64_t &OffsetFromLocationInBits)
Computes a fragment, bit-extract operation if needed, and new constant offset to describe a part of a...
element_iterator elements_begin() const
LLVM_ABI bool hasAllLocationOps(unsigned N) const
Returns true iff this DIExpression contains at least one instance of DW_OP_LLVM_arg,...
std::optional< FragmentInfo > getFragmentInfo() const
Retrieve the details of this fragment expression.
static LLVM_ABI DIExpression * appendOpsToArg(const DIExpression *Expr, ArrayRef< uint64_t > Ops, unsigned ArgNo, bool StackValue=false)
Create a copy of Expr by appending the given list of Ops to each instance of the operand DW_OP_LLVM_a...
PrependOps
Used for DIExpression::prepend.
static int fragmentCmp(const FragmentInfo &A, const FragmentInfo &B)
Determine the relative position of the fragments passed in.
LLVM_ABI bool isComplex() const
Return whether the location is computed on the expression stack, meaning it cannot be a simple regist...
bool fragmentsOverlap(const DIExpression *Other) const
Check if fragments overlap between this DIExpression and Other.
LLVM_ABI DIExpression * foldConstantMath()
Try to shorten an expression with constant math operations that can be evaluated at compile time.
static LLVM_ABI std::optional< const DIExpression * > convertToNonVariadicExpression(const DIExpression *Expr)
If Expr is a valid single-location expression, i.e.
LLVM_ABI std::pair< DIExpression *, const ConstantInt * > constantFold(const ConstantInt *CI)
Try to shorten an expression with an initial constant operand.
LLVM_ABI bool isDeref() const
Return whether there is exactly one operator and it is a DW_OP_deref;.
static LLVM_ABI const DIExpression * convertToVariadicExpression(const DIExpression *Expr)
If Expr is a non-variadic expression (i.e.
LLVM_ABI uint64_t getNumLocationOperands() const
Return the number of unique location operands referred to (via DW_OP_LLVM_arg) in this expression; th...
ArrayRef< uint64_t > getElements() const
static LLVM_ABI DIExpression * replaceArg(const DIExpression *Expr, uint64_t OldArg, uint64_t NewArg)
Create a copy of Expr with each instance of DW_OP_LLVM_arg, \p OldArg replaced with DW_OP_LLVM_arg,...
static bool classof(const Metadata *MD)
LLVM_ABI std::optional< uint64_t > getActiveBits(DIVariable *Var)
Return the number of bits that have an active value, i.e.
static LLVM_ABI void canonicalizeExpressionOps(SmallVectorImpl< uint64_t > &Ops, const DIExpression *Expr, bool IsIndirect)
Inserts the elements of Expr into Ops modified to a canonical form, which uses DW_OP_LLVM_arg (i....
uint64_t getElement(unsigned I) const
static LLVM_ABI std::optional< DIExpression * > createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits)
Create a DIExpression to describe one part of an aggregate variable that is fragmented across multipl...
static LLVM_ABI const DIExpression * convertToUndefExpression(const DIExpression *Expr)
Removes all elements from Expr that do not apply to an undef debug value, which includes every operat...
static LLVM_ABI DIExpression * prepend(const DIExpression *Expr, uint8_t Flags, int64_t Offset=0)
Prepend DIExpr with a deref and offset operation and optionally turn it into a stack value or/and an ...
static LLVM_ABI DIExpression * appendToStack(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Convert DIExpr into a stack value if it isn't one already by appending DW_OP_deref if needed,...
static LLVM_ABI DIExpression * appendExt(const DIExpression *Expr, unsigned FromSize, unsigned ToSize, bool Signed)
Append a zero- or sign-extension to Expr.
LLVM_ABI std::optional< ArrayRef< uint64_t > > getSingleLocationExpressionElements() const
Returns a reference to the elements contained in this expression, skipping past the leading DW_OP_LLV...
LLVM_ABI bool isSingleLocationExpression() const
Return whether the evaluated expression makes use of a single location at the start of the expression...
LLVM_ABI bool extractLeadingOffset(int64_t &OffsetInBytes, SmallVectorImpl< uint64_t > &RemainingOps) const
Assuming that the expression operates on an address, extract a constant offset and the successive ops...
LLVM_ABI std::optional< SignedOrUnsignedConstant > isConstant() const
Determine whether this represents a constant value, if so.
LLVM_ABI bool isValid() const
static LLVM_ABI const DIExpression * extractAddressClass(const DIExpression *Expr, unsigned &AddrClass)
Checks if the last 4 elements of the expression are DW_OP_constu <DWARF Address Space> DW_OP_swap DW_...
static LLVM_ABI DIExpression * prependOpcodes(const DIExpression *Expr, SmallVectorImpl< uint64_t > &Ops, bool StackValue=false, bool EntryValue=false)
Prepend DIExpr with the given opcodes and optionally turn it into a stack value.
static bool classof(const Metadata *MD)
MDString MDString * Directory
DEFINE_MDNODE_GET(DIFile,(StringRef Filename, StringRef Directory, std::optional< ChecksumInfo< StringRef > > CS=std::nullopt, std::optional< StringRef > Source=std::nullopt),(Filename, Directory, CS, Source)) DEFINE_MDNODE_GET(DIFile
MDString * Filename
static LLVM_ABI std::optional< ChecksumKind > getChecksumKind(StringRef CSKindStr)
ChecksumKind
Which algorithm (e.g.
MDString MDString std::optional< ChecksumInfo< MDString * > > CS
static LLVM_ABI std::optional< FixedPointKind > getFixedPointKind(StringRef Str)
static LLVM_ABI const char * fixedPointKindString(FixedPointKind)
const APInt & getNumeratorRaw() const
unsigned StringRef uint64_t uint32_t unsigned Encoding
static bool classof(const Metadata *MD)
const APInt & getDenominator() const
unsigned StringRef Name
unsigned StringRef uint64_t uint32_t AlignInBits
LLVM_ABI bool isSigned() const
@ FixedPointBinary
Scale factor 2^Factor.
@ FixedPointDecimal
Scale factor 10^Factor.
@ FixedPointRational
Arbitrary rational scale factor.
FixedPointKind getKind() const
const APInt & getNumerator() const
DEFINE_MDNODE_GET(DIFixedPointType,(unsigned Tag, MDString *Name, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind, int Factor, APInt Numerator, APInt Denominator),(Tag, Name, SizeInBits, AlignInBits, Encoding, Flags, Kind, Factor, Numerator, Denominator)) DEFINE_MDNODE_GET(DIFixedPointType
unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags
unsigned StringRef uint64_t SizeInBits
const APInt & getDenominatorRaw() const
Metadata * getRawLowerBound() const
Metadata * getRawCountNode() const
Metadata * getRawStride() const
LLVM_ABI BoundType getLowerBound() const
DEFINE_MDNODE_GET(DIGenericSubrange,(Metadata *CountNode, Metadata *LowerBound, Metadata *UpperBound, Metadata *Stride),(CountNode, LowerBound, UpperBound, Stride)) TempDIGenericSubrange clone() const
Metadata * getRawUpperBound() const
static bool classof(const Metadata *MD)
LLVM_ABI BoundType getCount() const
LLVM_ABI BoundType getUpperBound() const
LLVM_ABI BoundType getStride() const
A pair of DIGlobalVariable and DIExpression.
DEFINE_MDNODE_GET(DIGlobalVariableExpression,(Metadata *Variable, Metadata *Expression),(Variable, Expression)) TempDIGlobalVariableExpression clone() const
DIGlobalVariable * getVariable() const
static bool classof(const Metadata *MD)
DIExpression * getExpression() const
Metadata * getRawAnnotations() const
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata Metadata * TemplateParams
Metadata MDString MDString Metadata unsigned Line
Metadata MDString MDString Metadata unsigned Metadata * Type
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata Metadata uint32_t Metadata * Annotations
DIDerivedType * getStaticDataMemberDeclaration() const
DEFINE_MDNODE_GET(DIGlobalVariable,(DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, unsigned Line, DIType *Type, bool IsLocalToUnit, bool IsDefinition, DIDerivedType *StaticDataMemberDeclaration, MDTuple *TemplateParams, uint32_t AlignInBits, DINodeArray Annotations),(Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, StaticDataMemberDeclaration, TemplateParams, AlignInBits, Annotations)) DEFINE_MDNODE_GET(DIGlobalVariable
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata Metadata uint32_t Metadata Annotations TempDIGlobalVariable clone() const
Metadata MDString * Name
MDTuple * getTemplateParams() const
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata * StaticDataMemberDeclaration
Metadata * getRawStaticDataMemberDeclaration() const
Metadata MDString MDString * LinkageName
MDString * getRawLinkageName() const
StringRef getLinkageName() const
static bool classof(const Metadata *MD)
StringRef getDisplayName() const
Metadata MDString MDString Metadata * File
DINodeArray getAnnotations() const
Metadata * getRawTemplateParams() const
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata Metadata uint32_t AlignInBits
An imported module (C++ using directive or similar).
unsigned Metadata Metadata * Entity
DEFINE_MDNODE_GET(DIImportedEntity,(unsigned Tag, DIScope *Scope, DINode *Entity, DIFile *File, unsigned Line, StringRef Name="", DINodeArray Elements=nullptr),(Tag, Scope, Entity, File, Line, Name, Elements)) DEFINE_MDNODE_GET(DIImportedEntity
unsigned Metadata Metadata Metadata unsigned Line
unsigned Metadata Metadata Metadata unsigned MDString * Name
unsigned Metadata Metadata Metadata * File
unsigned Metadata * Scope
DIFile * getFile() const
Metadata MDString Metadata unsigned unsigned bool std::optional< unsigned > CoroSuspendIdx TempDILabel clone() const
StringRef getName() const
static bool classof(const Metadata *MD)
unsigned getLine() const
bool isArtificial() const
Metadata * getRawFile() const
unsigned getColumn() const
DILocalScope * getScope() const
Get the local scope for this label.
MDString * getRawName() const
std::optional< unsigned > getCoroSuspendIdx() const
Metadata MDString Metadata unsigned Line
Metadata MDString * Name
DEFINE_MDNODE_GET(DILabel,(DILocalScope *Scope, StringRef Name, DIFile *File, unsigned Line, unsigned Column, bool IsArtificial, std::optional< unsigned > CoroSuspendIdx),(Scope, Name, File, Line, Column, IsArtificial, CoroSuspendIdx)) DEFINE_MDNODE_GET(DILabel
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this label.
Metadata * getRawScope() const
Metadata MDString Metadata * File
static bool classof(const Metadata *MD)
void replaceScope(DIScope *Scope)
Metadata * getRawScope() const
DILocalScope * getScope() const
Metadata Metadata unsigned Discriminator
static bool classof(const Metadata *MD)
unsigned getDiscriminator() const
Metadata Metadata unsigned Discriminator TempDILexicalBlockFile clone() const
Metadata Metadata * File
DEFINE_MDNODE_GET(DILexicalBlockFile,(DILocalScope *Scope, DIFile *File, unsigned Discriminator),(Scope, File, Discriminator)) DEFINE_MDNODE_GET(DILexicalBlockFile
Debug lexical block.
Metadata Metadata unsigned Line
unsigned getLine() const
DEFINE_MDNODE_GET(DILexicalBlock,(DILocalScope *Scope, DIFile *File, unsigned Line, unsigned Column),(Scope, File, Line, Column)) DEFINE_MDNODE_GET(DILexicalBlock
static bool classof(const Metadata *MD)
Metadata Metadata * File
unsigned getColumn() const
Metadata Metadata unsigned unsigned Column TempDILexicalBlock clone() const
A scope for locals.
LLVM_ABI DISubprogram * getSubprogram() const
Get the subprogram for this scope.
LLVM_ABI DILocalScope * getNonLexicalBlockFileScope() const
Get the first non DILexicalBlockFile scope of this scope.
~DILocalScope()=default
DILocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, ArrayRef< Metadata * > Ops)
static bool classof(const Metadata *MD)
static LLVM_ABI DILocalScope * cloneScopeForSubprogram(DILocalScope &RootScope, DISubprogram &NewSP, LLVMContext &Ctx, DenseMap< const MDNode *, MDNode * > &Cache)
Traverses the scope chain rooted at RootScope until it hits a Subprogram, recreating the chain with "...
Metadata MDString Metadata unsigned Metadata * Type
Metadata MDString Metadata * File
static bool classof(const Metadata *MD)
Metadata MDString Metadata unsigned Metadata unsigned DIFlags uint32_t Metadata Annotations TempDILocalVariable clone() const
DILocalScope * getScope() const
Get the local scope for this variable.
Metadata MDString * Name
DINodeArray getAnnotations() const
DEFINE_MDNODE_GET(DILocalVariable,(DILocalScope *Scope, StringRef Name, DIFile *File, unsigned Line, DIType *Type, unsigned Arg, DIFlags Flags, uint32_t AlignInBits, DINodeArray Annotations),(Scope, Name, File, Line, Type, Arg, Flags, AlignInBits, Annotations)) DEFINE_MDNODE_GET(DILocalVariable
Metadata MDString Metadata unsigned Line
Metadata MDString Metadata unsigned Metadata unsigned DIFlags uint32_t Metadata * Annotations
Metadata MDString Metadata unsigned Metadata unsigned DIFlags uint32_t AlignInBits
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this variable.
Metadata * getRawAnnotations() const
Debug location.
unsigned unsigned DILocalScope * Scope
const DILocation * getWithoutAtom() const
static unsigned getDuplicationFactorFromDiscriminator(unsigned D)
Returns the duplication factor for a given encoded discriminator D, or 1 if no value or 0 is encoded.
static bool isPseudoProbeDiscriminator(unsigned Discriminator)
unsigned getDuplicationFactor() const
Returns the duplication factor stored in the discriminator, or 1 if no duplication factor (or 0) is e...
uint64_t getAtomGroup() const
static LLVM_ABI DILocation * getMergedLocations(ArrayRef< DILocation * > Locs)
Try to combine the vector of locations passed as input in a single one.
static unsigned getBaseDiscriminatorBits()
Return the bits used for base discriminators.
static LLVM_ABI std::optional< unsigned > encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI)
Raw encoding of the discriminator.
unsigned unsigned DILocalScope DILocation bool ImplicitCode
Metadata * getRawScope() const
static LLVM_ABI void decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF, unsigned &CI)
Raw decoder for values in an encoded discriminator D.
static LLVM_ABI DILocation * getMergedLocation(DILocation *LocA, DILocation *LocB)
Attempts to merge LocA and LocB into a single location; see DebugLoc::getMergedLocation for more deta...
std::optional< const DILocation * > cloneWithBaseDiscriminator(unsigned BD) const
Returns a new DILocation with updated base discriminator BD.
unsigned getBaseDiscriminator() const
Returns the base discriminator stored in the discriminator.
static unsigned getBaseDiscriminatorFromDiscriminator(unsigned D, bool IsFSDiscriminator=false)
Returns the base discriminator for a given encoded discriminator D.
unsigned unsigned Column
Metadata * getRawInlinedAt() const
unsigned unsigned DILocalScope DILocation * InlinedAt
static unsigned getMaskedDiscriminator(unsigned D, unsigned B)
Return the masked discriminator value for an input discrimnator value D (i.e.
const DILocation * cloneWithDiscriminator(unsigned Discriminator) const
Returns a new DILocation with updated Discriminator.
static unsigned getCopyIdentifierFromDiscriminator(unsigned D)
Returns the copy identifier for a given encoded discriminator D.
uint8_t getAtomRank() const
DEFINE_MDNODE_GET(DILocation,(unsigned Line, unsigned Column, Metadata *Scope, Metadata *InlinedAt=nullptr, bool ImplicitCode=false, uint64_t AtomGroup=0, uint8_t AtomRank=0),(Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup, AtomRank)) DEFINE_MDNODE_GET(DILocation
void replaceOperandWith(unsigned I, Metadata *New)=delete
std::optional< const DILocation * > cloneByMultiplyingDuplicationFactor(unsigned DF) const
Returns a new DILocation with duplication factor DF * current duplication factor encoded in the discr...
static bool classof(const Metadata *MD)
unsigned getCopyIdentifier() const
Returns the copy identifier stored in the discriminator.
unsigned unsigned Metadata * File
Metadata * getRawElements() const
DEFINE_MDNODE_GET(DIMacroFile,(unsigned MIType, unsigned Line, DIFile *File, DIMacroNodeArray Elements),(MIType, Line, File, Elements)) DEFINE_MDNODE_GET(DIMacroFile
unsigned unsigned Line
DIFile * getFile() const
unsigned getLine() const
unsigned unsigned Metadata Metadata * Elements
Metadata * getRawFile() const
static bool classof(const Metadata *MD)
void replaceElements(DIMacroNodeArray Elements)
unsigned unsigned Metadata Metadata Elements TempDIMacroFile clone() const
DIMacroNodeArray getElements() const
Macro Info DWARF-like metadata node.
DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType, ArrayRef< Metadata * > Ops1, ArrayRef< Metadata * > Ops2={})
unsigned getMacinfoType() const
StringRef getStringOperand(unsigned I) const
static bool classof(const Metadata *MD)
static MDString * getCanonicalMDString(LLVMContext &Context, StringRef S)
Ty * getOperandAs(unsigned I) const
~DIMacroNode()=default
unsigned getLine() const
MDString * getRawName() const
unsigned unsigned MDString MDString Value TempDIMacro clone() const
unsigned unsigned MDString MDString * Value
unsigned unsigned MDString * Name
StringRef getName() const
MDString * getRawValue() const
unsigned unsigned Line
DEFINE_MDNODE_GET(DIMacro,(unsigned MIType, unsigned Line, StringRef Name, StringRef Value=""),(MIType, Line, Name, Value)) DEFINE_MDNODE_GET(DIMacro
StringRef getValue() const
static bool classof(const Metadata *MD)
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
Metadata Metadata * Scope
Metadata Metadata MDString * Name
Metadata Metadata MDString MDString MDString MDString * APINotesFile
Metadata Metadata MDString MDString MDString * IncludePath
Metadata Metadata MDString MDString * ConfigurationMacros
DEFINE_MDNODE_GET(DIModule,(DIFile *File, DIScope *Scope, StringRef Name, StringRef ConfigurationMacros, StringRef IncludePath, StringRef APINotesFile, unsigned LineNo, bool IsDecl=false),(File, Scope, Name, ConfigurationMacros, IncludePath, APINotesFile, LineNo, IsDecl)) DEFINE_MDNODE_GET(DIModule
Metadata Metadata MDString MDString MDString MDString unsigned LineNo
Debug lexical block.
Metadata MDString bool ExportSymbols TempDINamespace clone() const
static bool classof(const Metadata *MD)
DEFINE_MDNODE_GET(DINamespace,(DIScope *Scope, StringRef Name, bool ExportSymbols),(Scope, Name, ExportSymbols)) DEFINE_MDNODE_GET(DINamespace
DIScope * getScope() const
Metadata MDString bool ExportSymbols
StringRef getName() const
MDString * getRawName() const
Metadata MDString * Name
bool getExportSymbols() const
Metadata * getRawScope() const
Tagged DWARF-like metadata node.
LLVM_ABI dwarf::Tag getTag() const
static MDString * getCanonicalMDString(LLVMContext &Context, StringRef S)
static LLVM_ABI DIFlags getFlag(StringRef Flag)
static LLVM_ABI DIFlags splitFlags(DIFlags Flags, SmallVectorImpl< DIFlags > &SplitFlags)
Split up a flags bitfield.
void setTag(unsigned Tag)
Allow subclasses to mutate the tag.
DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, ArrayRef< Metadata * > Ops1, ArrayRef< Metadata * > Ops2={})
StringRef getStringOperand(unsigned I) const
Ty * getOperandAs(unsigned I) const
static bool classof(const Metadata *MD)
static LLVM_ABI StringRef getFlagString(DIFlags Flag)
friend class MDNode
~DINode()=default
DIFlags
Debug info flags.
MDString Metadata unsigned MDString MDString unsigned Metadata Type TempDIObjCProperty clone() const
DIType * getType() const
unsigned getAttributes() const
StringRef getFilename() const
MDString * getRawName() const
unsigned getLine() const
StringRef getDirectory() const
MDString * getRawSetterName() const
Metadata * getRawType() const
StringRef getGetterName() const
MDString Metadata * File
DIFile * getFile() const
static bool classof(const Metadata *MD)
MDString * getRawGetterName() const
Metadata * getRawFile() const
MDString Metadata unsigned MDString * GetterName
MDString Metadata unsigned MDString MDString * SetterName
StringRef getName() const
DEFINE_MDNODE_GET(DIObjCProperty,(StringRef Name, DIFile *File, unsigned Line, StringRef GetterName, StringRef SetterName, unsigned Attributes, DIType *Type),(Name, File, Line, GetterName, SetterName, Attributes, Type)) DEFINE_MDNODE_GET(DIObjCProperty
StringRef getSetterName() const
Base class for scope-like contexts.
~DIScope()=default
StringRef getFilename() const
LLVM_ABI StringRef getName() const
static bool classof(const Metadata *MD)
DIFile * getFile() const
StringRef getDirectory() const
std::optional< StringRef > getSource() const
LLVM_ABI DIScope * getScope() const
Metadata * getRawFile() const
Return the raw underlying file.
DIScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, ArrayRef< Metadata * > Ops)
String type, Fortran CHARACTER(n)
unsigned MDString * Name
unsigned MDString Metadata Metadata Metadata uint64_t SizeInBits
unsigned getEncoding() const
unsigned MDString Metadata Metadata Metadata uint64_t uint32_t AlignInBits
static bool classof(const Metadata *MD)
unsigned MDString Metadata Metadata Metadata * StringLocationExp
unsigned MDString Metadata Metadata Metadata uint64_t uint32_t unsigned Encoding unsigned MDString Metadata Metadata Metadata Metadata uint32_t unsigned Encoding TempDIStringType clone() const
DIExpression * getStringLengthExp() const
unsigned MDString Metadata Metadata * StringLengthExp
Metadata * getRawStringLengthExp() const
Metadata * getRawStringLength() const
DIVariable * getStringLength() const
DIExpression * getStringLocationExp() const
unsigned MDString Metadata * StringLength
Metadata * getRawStringLocationExp() const
DEFINE_MDNODE_GET(DIStringType,(unsigned Tag, StringRef Name, uint64_t SizeInBits, uint32_t AlignInBits),(Tag, Name, nullptr, nullptr, nullptr, SizeInBits, AlignInBits, 0)) DEFINE_MDNODE_GET(DIStringType
Subprogram description. Uses SubclassData1.
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata * Unit
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata Metadata MDString bool UsesKeyInstructions
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata Metadata * Annotations
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata * ContainingType
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata * TemplateParams
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata * Declaration
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata Metadata MDString * TargetFuncName
static LLVM_ABI DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized, unsigned Virtuality=SPFlagNonvirtual, bool IsMainSubprogram=false)
Metadata MDString * Name
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata * ThrownTypes
DEFINE_MDNODE_GET(DISubprogram,(DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, unsigned Line, DISubroutineType *Type, unsigned ScopeLine, DIType *ContainingType, unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit, DITemplateParameterArray TemplateParams=nullptr, DISubprogram *Declaration=nullptr, DINodeArray RetainedNodes=nullptr, DITypeArray ThrownTypes=nullptr, DINodeArray Annotations=nullptr, StringRef TargetFuncName="", bool UsesKeyInstructions=false),(Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType, VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams, Declaration, RetainedNodes, ThrownTypes, Annotations, TargetFuncName, UsesKeyInstructions)) DEFINE_MDNODE_GET(DISubprogram
static LLVM_ABI DISPFlags getFlag(StringRef Flag)
Metadata MDString MDString Metadata * File
static LLVM_ABI DISPFlags splitFlags(DISPFlags Flags, SmallVectorImpl< DISPFlags > &SplitFlags)
Split up a flags bitfield for easier printing.
static bool classof(const Metadata *MD)
Metadata MDString MDString * LinkageName
static LLVM_ABI StringRef getFlagString(DISPFlags Flag)
Metadata MDString MDString Metadata unsigned Metadata * Type
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata * RetainedNodes
DISPFlags
Debug info subprogram flags.
StringRef DIFile unsigned Line
Metadata * getRawUpperBound() const
BoundType getLowerBound() const
StringRef DIFile unsigned DIScope uint64_t uint32_t DIFlags DIType Metadata Metadata * UpperBound
PointerUnion< ConstantInt *, DIVariable *, DIExpression * > BoundType
StringRef DIFile unsigned DIScope uint64_t uint32_t DIFlags DIType Metadata Metadata Metadata Metadata * Bias
StringRef DIFile unsigned DIScope uint64_t uint32_t DIFlags DIType Metadata Metadata Metadata * Stride
StringRef DIFile unsigned DIScope uint64_t SizeInBits
static bool classof(const Metadata *MD)
BoundType getBias() const
DEFINE_MDNODE_GET(DISubrangeType,(MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *SizeInBits, uint32_t AlignInBits, DIFlags Flags, Metadata *BaseType, Metadata *LowerBound, Metadata *UpperBound, Metadata *Stride, Metadata *Bias),(Name, File, Line, Scope, SizeInBits, AlignInBits, Flags, BaseType, LowerBound, UpperBound, Stride, Bias)) DEFINE_MDNODE_GET(DISubrangeType
Metadata * getRawBias() const
Metadata * getRawBaseType() const
StringRef DIFile * File
StringRef DIFile unsigned DIScope * Scope
BoundType getUpperBound() const
DIType * getBaseType() const
Get the base type this is derived from.
BoundType getStride() const
Metadata * getRawLowerBound() const
StringRef DIFile unsigned DIScope uint64_t uint32_t AlignInBits
Metadata * getRawStride() const
StringRef DIFile unsigned DIScope uint64_t uint32_t DIFlags DIType Metadata * LowerBound
StringRef DIFile unsigned DIScope uint64_t uint32_t DIFlags Flags
StringRef DIFile unsigned DIScope uint64_t uint32_t DIFlags DIType Metadata Metadata Metadata Metadata Bias TempDISubrangeType clone() const
Array subrange.
static bool classof(const Metadata *MD)
LLVM_ABI BoundType getUpperBound() const
LLVM_ABI BoundType getStride() const
LLVM_ABI BoundType getLowerBound() const
DEFINE_MDNODE_GET(DISubrange,(int64_t Count, int64_t LowerBound=0),(Count, LowerBound)) DEFINE_MDNODE_GET(DISubrange
LLVM_ABI BoundType getCount() const
Metadata int64_t LowerBound
Type array for a subprogram.
TempDISubroutineType cloneWithCC(uint8_t CC) const
DEFINE_MDNODE_GET(DISubroutineType,(DIFlags Flags, uint8_t CC, DITypeRefArray TypeArray),(Flags, CC, TypeArray)) DEFINE_MDNODE_GET(DISubroutineType
DIFlags uint8_t Metadata * TypeArray
static bool classof(const Metadata *MD)
Metadata * getRawTypeArray() const
DITypeRefArray getTypeArray() const
DIFlags uint8_t Metadata TypeArray TempDISubroutineType clone() const
Base class for template parameters.
Metadata * getRawType() const
static bool classof(const Metadata *MD)
DITemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage, unsigned Tag, bool IsDefault, ArrayRef< Metadata * > Ops)
MDString * getRawName() const
MDString Metadata bool IsDefault
DEFINE_MDNODE_GET(DITemplateTypeParameter,(StringRef Name, DIType *Type, bool IsDefault),(Name, Type, IsDefault)) DEFINE_MDNODE_GET(DITemplateTypeParameter
MDString Metadata bool IsDefault TempDITemplateTypeParameter clone() const
static bool classof(const Metadata *MD)
unsigned MDString Metadata bool Metadata Value TempDITemplateValueParameter clone() const
unsigned MDString Metadata * Type
static bool classof(const Metadata *MD)
DEFINE_MDNODE_GET(DITemplateValueParameter,(unsigned Tag, StringRef Name, DIType *Type, bool IsDefault, Metadata *Value),(Tag, Name, Type, IsDefault, Value)) DEFINE_MDNODE_GET(DITemplateValueParameter
unsigned MDString Metadata bool IsDefault
unsigned MDString Metadata bool Metadata * Value
bool operator!=(const iterator &X) const
bool operator==(const iterator &X) const
std::input_iterator_tag iterator_category
iterator(MDNode::op_iterator I)
DIType * operator[](unsigned I) const
MDTuple & operator*() const
DITypeRefArray()=default
MDTuple * operator->() const
iterator end() const
MDTuple * get() const
iterator begin() const
DITypeRefArray(const MDTuple *N)
unsigned size() const
Base class for types.
bool isLittleEndian() const
static constexpr unsigned N_OPERANDS
bool isPublic() const
bool isPrivate() const
uint32_t getNumExtraInhabitants() const
bool isBigEndian() const
bool isLValueReference() const
bool isBitField() const
~DIType()=default
bool isStaticMember() const
bool isVirtual() const
TempDIType cloneWithFlags(DIFlags NewFlags) const
Returns a new temporary DIType with updated Flags.
bool isObjcClassComplete() const
MDString * getRawName() const
bool isAppleBlockExtension() const
uint64_t getOffsetInBits() const
bool isVector() const
bool isProtected() const
bool isObjectPointer() const
DIFlags getFlags() const
Metadata * getRawScope() const
StringRef getName() const
bool isForwardDecl() const
bool isTypePassByValue() const
uint64_t getSizeInBits() const
static bool classof(const Metadata *MD)
DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants, DIFlags Flags, ArrayRef< Metadata * > Ops)
uint32_t getAlignInBytes() const
void mutate(unsigned Tag, unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants, DIFlags Flags)
Change fields in place.
void init(unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants, DIFlags Flags)
LLVM_ABI uint32_t getAlignInBits() const
Metadata * getRawSizeInBits() const
unsigned getLine() const
bool isRValueReference() const
bool isArtificial() const
bool getExportSymbols() const
TempDIType clone() const
DIScope * getScope() const
bool isTypePassByReference() const
Metadata * getRawOffsetInBits() const
Base class for variables.
std::optional< DIBasicType::Signedness > getSignedness() const
Return the signedness of this variable's type, or std::nullopt if this type is neither signed nor uns...
uint32_t getAlignInBits() const
DIFile * getFile() const
MDString * getRawName() const
uint32_t getAlignInBytes() const
DIScope * getScope() const
~DIVariable()=default
StringRef getDirectory() const
LLVM_ABI std::optional< uint64_t > getSizeInBits() const
Determines the size of the variable's type.
Metadata * getRawFile() const
std::optional< StringRef > getSource() const
StringRef getFilename() const
Metadata * getRawType() const
static bool classof(const Metadata *MD)
DIType * getType() const
unsigned getLine() const
StringRef getName() const
Metadata * getRawScope() const
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
Record of a variable value-assignment, aka a non instruction representation of the dbg....
Identifies a unique instance of a whole variable (discards/ignores fragment information).
DebugVariableAggregate(const DebugVariable &V)
Identifies a unique instance of a variable.
static bool isDefaultFragment(const FragmentInfo F)
DebugVariable(const DILocalVariable *Var, const DIExpression *DIExpr, const DILocation *InlinedAt)
const DILocation * getInlinedAt() const
bool operator<(const DebugVariable &Other) const
DebugVariable(const DILocalVariable *Var, std::optional< FragmentInfo > FragmentInfo, const DILocation *InlinedAt)
bool operator==(const DebugVariable &Other) const
FragmentInfo getFragmentOrDefault() const
std::optional< FragmentInfo > getFragment() const
const DILocalVariable * getVariable() const
Class representing an expression and its matching format.
Generic tagged DWARF-like metadata node.
static bool classof(const Metadata *MD)
unsigned MDString ArrayRef< Metadata * > DwarfOps TempGenericDINode clone() const
Return a (temporary) clone of this.
LLVM_ABI dwarf::Tag getTag() const
StringRef getHeader() const
MDString * getRawHeader() const
const MDOperand & getDwarfOperand(unsigned I) const
unsigned getHash() const
unsigned getNumDwarfOperands() const
op_iterator dwarf_op_end() const
op_iterator dwarf_op_begin() const
unsigned MDString * Header
op_range dwarf_operands() const
DEFINE_MDNODE_GET(GenericDINode,(unsigned Tag, StringRef Header, ArrayRef< Metadata * > DwarfOps),(Tag, Header, DwarfOps)) DEFINE_MDNODE_GET(GenericDINode
void replaceDwarfOperandWith(unsigned I, Metadata *New)
unsigned MDString ArrayRef< Metadata * > DwarfOps
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
Metadata node.
Definition: Metadata.h:1077
friend class DIAssignID
Definition: Metadata.h:1080
LLVM_ABI void replaceOperandWith(unsigned I, Metadata *New)
Replace a specific operand.
Definition: Metadata.cpp:1078
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1445
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1577
op_iterator op_end() const
Definition: Metadata.h:1439
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1565
bool isUniqued() const
Definition: Metadata.h:1259
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1451
iterator_range< op_iterator > op_range
Definition: Metadata.h:1433
LLVM_ABI TempMDNode clone() const
Create a (temporary) clone of this.
Definition: Metadata.cpp:668
bool isDistinct() const
Definition: Metadata.h:1260
LLVM_ABI void setOperand(unsigned I, Metadata *New)
Set an operand.
Definition: Metadata.cpp:1090
op_iterator op_begin() const
Definition: Metadata.h:1435
LLVMContext & getContext() const
Definition: Metadata.h:1241
LLVM_ABI void dropAllReferences()
Definition: Metadata.cpp:908
Tracking metadata reference owned by Metadata.
Definition: Metadata.h:899
Metadata * get() const
Definition: Metadata.h:928
A single uniqued string.
Definition: Metadata.h:720
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:607
Tuple of metadata.
Definition: Metadata.h:1493
Root of the metadata hierarchy.
Definition: Metadata.h:63
StorageType
Active type of storage.
Definition: Metadata.h:71
unsigned short SubclassData16
Definition: Metadata.h:77
unsigned SubclassData32
Definition: Metadata.h:78
unsigned char Storage
Storage flag for non-uniqued, otherwise unowned, metadata.
Definition: Metadata.h:74
unsigned getMetadataID() const
Definition: Metadata.h:103
unsigned char SubclassData1
Definition: Metadata.h:76
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:118
Shared implementation of use-lists for replaceable metadata.
Definition: Metadata.h:389
LLVM_ABI SmallVector< DbgVariableRecord * > getAllDbgVariableRecordUsers()
Returns the list of all DbgVariableRecord users of this.
Definition: Metadata.cpp:272
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
typename SuperClass::iterator iterator
Definition: SmallVector.h:578
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:151
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
LLVM Value Representation.
Definition: Value.h:75
A range adaptor for a pair of iterators.
LLVM_ABI unsigned getVirtuality(StringRef VirtualityString)
Definition: Dwarf.cpp:385
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
template class LLVM_TEMPLATE_ABI opt< bool >
Definition: CommandLine.cpp:79
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
bool operator<(int64_t V1, const APSInt &V2)
Definition: APSInt.h:362
bool operator!=(uint64_t V1, const APInt &V2)
Definition: APInt.h:2113
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
LLVM_ABI cl::opt< bool > EnableFSDiscriminator
static unsigned getBaseFSBitEnd()
@ Ref
The access may reference the value stored in memory.
@ Other
Any other memory.
static unsigned getN1Bits(int N)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1916
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition: Hashing.h:595
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
#define N
Pointer authentication (__ptrauth) metadata.
PtrAuthData(unsigned Key, bool IsDiscr, unsigned Discriminator, bool IsaPointer, bool AuthenticatesNullValues)
A single checksum, represented by a Kind and a Value (a string).
bool operator==(const ChecksumInfo< T > &X) const
T Value
The string value of the checksum.
ChecksumKind Kind
The kind of checksum which Value encodes.
ChecksumInfo(ChecksumKind Kind, T Value)
bool operator!=(const ChecksumInfo< T > &X) const
StringRef getKindAsString() const
static bool isEqual(const FragInfo &A, const FragInfo &B)
static unsigned getHashValue(const FragInfo &Frag)
static unsigned getHashValue(const DebugVariable &D)
static DebugVariable getEmptyKey()
Empty key: no key should be generated that has no DILocalVariable.
static DebugVariable getTombstoneKey()
Difference in tombstone is that the Optional is meaningful.
static bool isEqual(const DebugVariable &A, const DebugVariable &B)
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: DenseMapInfo.h:54
static uint32_t extractProbeIndex(uint32_t Value)
Definition: PseudoProbe.h:75
static std::optional< uint32_t > extractDwarfBaseDiscriminator(uint32_t Value)
Definition: PseudoProbe.h:81