LLVM 21.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"
30#include <cassert>
31#include <climits>
32#include <cstddef>
33#include <cstdint>
34#include <iterator>
35#include <optional>
36#include <vector>
37
38// Helper macros for defining get() overrides.
39#define DEFINE_MDNODE_GET_UNPACK_IMPL(...) __VA_ARGS__
40#define DEFINE_MDNODE_GET_UNPACK(ARGS) DEFINE_MDNODE_GET_UNPACK_IMPL ARGS
41#define DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS) \
42 static CLASS *getDistinct(LLVMContext &Context, \
43 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
44 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct); \
45 } \
46 static Temp##CLASS getTemporary(LLVMContext &Context, \
47 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
48 return Temp##CLASS( \
49 getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary)); \
50 }
51#define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS) \
52 static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
53 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued); \
54 } \
55 static CLASS *getIfExists(LLVMContext &Context, \
56 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
57 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued, \
58 /* ShouldCreate */ false); \
59 } \
60 DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS)
61
62namespace llvm {
63
64namespace dwarf {
65enum Tag : uint16_t;
66}
67
68class DbgVariableIntrinsic;
69class DbgVariableRecord;
70
71extern cl::opt<bool> EnableFSDiscriminator;
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 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 static DIFlags getFlag(StringRef Flag);
185 static StringRef getFlagString(DIFlags 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 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 DIStringTypeKind:
203 case DIDerivedTypeKind:
204 case DICompositeTypeKind:
205 case DISubroutineTypeKind:
206 case DIFileKind:
207 case DICompileUnitKind:
208 case DISubprogramKind:
209 case DILexicalBlockKind:
210 case DILexicalBlockFileKind:
211 case DINamespaceKind:
212 case DICommonBlockKind:
213 case DITemplateTypeParameterKind:
214 case DITemplateValueParameterKind:
215 case DIGlobalVariableKind:
216 case DILocalVariableKind:
217 case DILabelKind:
218 case DIObjCPropertyKind:
219 case DIImportedEntityKind:
220 case DIModuleKind:
221 case DIGenericSubrangeKind:
222 case DIAssignIDKind:
223 return true;
224 }
225 }
226};
227
228/// Generic tagged DWARF-like metadata node.
229///
230/// An un-specialized DWARF-like metadata node. The first operand is a
231/// (possibly empty) null-separated \a MDString header that contains arbitrary
232/// fields. The remaining operands are \a dwarf_operands(), and are pointers
233/// to other metadata.
234///
235/// Uses the SubclassData32 Metadata slot.
236class GenericDINode : public DINode {
237 friend class LLVMContextImpl;
238 friend class MDNode;
239
241 unsigned Tag, ArrayRef<Metadata *> Ops1,
243 : DINode(C, GenericDINodeKind, Storage, Tag, Ops1, Ops2) {
244 setHash(Hash);
245 }
247
248 void setHash(unsigned Hash) { SubclassData32 = Hash; }
249 void recalculateHash();
250
251 static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
252 StringRef Header, ArrayRef<Metadata *> DwarfOps,
253 StorageType Storage, bool ShouldCreate = true) {
254 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
255 DwarfOps, Storage, ShouldCreate);
256 }
257
258 static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
259 MDString *Header, ArrayRef<Metadata *> DwarfOps,
260 StorageType Storage, bool ShouldCreate = true);
261
262 TempGenericDINode cloneImpl() const {
264 SmallVector<Metadata *, 4>(dwarf_operands()));
265 }
266
267public:
268 unsigned getHash() const { return SubclassData32; }
269
271 (unsigned Tag, StringRef Header,
273 (Tag, Header, DwarfOps))
275 (unsigned Tag, MDString *Header,
278
279 /// Return a (temporary) clone of this.
280 TempGenericDINode clone() const { return cloneImpl(); }
281
282 dwarf::Tag getTag() const;
283 StringRef getHeader() const { return getStringOperand(0); }
284 MDString *getRawHeader() const { return getOperandAs<MDString>(0); }
285
286 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
287 op_iterator dwarf_op_end() const { return op_end(); }
290 }
291
292 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
293 const MDOperand &getDwarfOperand(unsigned I) const {
294 return getOperand(I + 1);
295 }
296 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
297 replaceOperandWith(I + 1, New);
298 }
299
300 static bool classof(const Metadata *MD) {
301 return MD->getMetadataID() == GenericDINodeKind;
302 }
303};
304
305/// Assignment ID.
306/// Used to link stores (as an attachment) and dbg.assigns (as an operand).
307/// DIAssignID metadata is never uniqued as we compare instances using
308/// referential equality (the instance/address is the ID).
309class DIAssignID : public MDNode {
310 friend class LLVMContextImpl;
311 friend class MDNode;
312
314 : MDNode(C, DIAssignIDKind, Storage, {}) {}
315
316 ~DIAssignID() { dropAllReferences(); }
317
318 static DIAssignID *getImpl(LLVMContext &Context, StorageType Storage,
319 bool ShouldCreate = true);
320
321 TempDIAssignID cloneImpl() const { return getTemporary(getContext()); }
322
323public:
324 // This node has no operands to replace.
325 void replaceOperandWith(unsigned I, Metadata *New) = delete;
326
328 return Context.getReplaceableUses()->getAllDbgVariableRecordUsers();
329 }
330
332 return getImpl(Context, Distinct);
333 }
334 static TempDIAssignID getTemporary(LLVMContext &Context) {
335 return TempDIAssignID(getImpl(Context, Temporary));
336 }
337 // NOTE: Do not define get(LLVMContext&) - see class comment.
338
339 static bool classof(const Metadata *MD) {
340 return MD->getMetadataID() == DIAssignIDKind;
341 }
342};
343
344/// Array subrange.
345///
346/// TODO: Merge into node for DW_TAG_array_type, which should have a custom
347/// type.
348class DISubrange : public DINode {
349 friend class LLVMContextImpl;
350 friend class MDNode;
351
353
354 ~DISubrange() = default;
355
356 static DISubrange *getImpl(LLVMContext &Context, int64_t Count,
358 bool ShouldCreate = true);
359
360 static DISubrange *getImpl(LLVMContext &Context, Metadata *CountNode,
362 bool ShouldCreate = true);
363
364 static DISubrange *getImpl(LLVMContext &Context, Metadata *CountNode,
365 Metadata *LowerBound, Metadata *UpperBound,
367 bool ShouldCreate = true);
368
369 TempDISubrange cloneImpl() const {
370 return getTemporary(getContext(), getRawCountNode(), getRawLowerBound(),
371 getRawUpperBound(), getRawStride());
372 }
373
374public:
375 DEFINE_MDNODE_GET(DISubrange, (int64_t Count, int64_t LowerBound = 0),
376 (Count, LowerBound))
377
380
383 Metadata *UpperBound, Metadata *Stride),
384 (CountNode, LowerBound, UpperBound, Stride))
385
386 TempDISubrange clone() const { return cloneImpl(); }
387
388 Metadata *getRawCountNode() const { return getOperand(0).get(); }
389
390 Metadata *getRawLowerBound() const { return getOperand(1).get(); }
391
392 Metadata *getRawUpperBound() const { return getOperand(2).get(); }
393
394 Metadata *getRawStride() const { return getOperand(3).get(); }
395
396 typedef PointerUnion<ConstantInt *, DIVariable *, DIExpression *> BoundType;
397
398 BoundType getCount() const;
399
400 BoundType getLowerBound() const;
401
402 BoundType getUpperBound() const;
403
404 BoundType getStride() const;
405
406 static bool classof(const Metadata *MD) {
407 return MD->getMetadataID() == DISubrangeKind;
408 }
409};
410
411class DIGenericSubrange : public DINode {
412 friend class LLVMContextImpl;
413 friend class MDNode;
414
417
418 ~DIGenericSubrange() = default;
419
420 static DIGenericSubrange *getImpl(LLVMContext &Context, Metadata *CountNode,
421 Metadata *LowerBound, Metadata *UpperBound,
423 bool ShouldCreate = true);
424
425 TempDIGenericSubrange cloneImpl() const {
428 }
429
430public:
432 (Metadata * CountNode, Metadata *LowerBound,
433 Metadata *UpperBound, Metadata *Stride),
434 (CountNode, LowerBound, UpperBound, Stride))
435
436 TempDIGenericSubrange clone() const { return cloneImpl(); }
437
438 Metadata *getRawCountNode() const { return getOperand(0).get(); }
439 Metadata *getRawLowerBound() const { return getOperand(1).get(); }
440 Metadata *getRawUpperBound() const { return getOperand(2).get(); }
441 Metadata *getRawStride() const { return getOperand(3).get(); }
442
444
445 BoundType getCount() const;
446 BoundType getLowerBound() const;
447 BoundType getUpperBound() const;
448 BoundType getStride() const;
449
450 static bool classof(const Metadata *MD) {
451 return MD->getMetadataID() == DIGenericSubrangeKind;
452 }
453};
454
455/// Enumeration value.
456///
457/// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
458/// longer creates a type cycle.
459class DIEnumerator : public DINode {
460 friend class LLVMContextImpl;
461 friend class MDNode;
462
463 APInt Value;
469 Ops) {}
470 ~DIEnumerator() = default;
471
472 static DIEnumerator *getImpl(LLVMContext &Context, const APInt &Value,
474 StorageType Storage, bool ShouldCreate = true) {
475 return getImpl(Context, Value, IsUnsigned,
476 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
477 }
478 static DIEnumerator *getImpl(LLVMContext &Context, const APInt &Value,
479 bool IsUnsigned, MDString *Name,
480 StorageType Storage, bool ShouldCreate = true);
481
482 TempDIEnumerator cloneImpl() const {
484 }
485
486public:
488 (int64_t Value, bool IsUnsigned, StringRef Name),
491 (int64_t Value, bool IsUnsigned, MDString *Name),
499
500 TempDIEnumerator clone() const { return cloneImpl(); }
501
502 const APInt &getValue() const { return Value; }
503 bool isUnsigned() const { return SubclassData32; }
504 StringRef getName() const { return getStringOperand(0); }
505
506 MDString *getRawName() const { return getOperandAs<MDString>(0); }
507
508 static bool classof(const Metadata *MD) {
509 return MD->getMetadataID() == DIEnumeratorKind;
510 }
511};
512
513/// Base class for scope-like contexts.
514///
515/// Base class for lexical scopes and types (which are also declaration
516/// contexts).
517///
518/// TODO: Separate the concepts of declaration contexts and lexical scopes.
519class DIScope : public DINode {
520protected:
523 : DINode(C, ID, Storage, Tag, Ops) {}
524 ~DIScope() = default;
525
526public:
527 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
528
529 inline StringRef getFilename() const;
530 inline StringRef getDirectory() const;
531 inline std::optional<StringRef> getSource() const;
532
533 StringRef getName() const;
534 DIScope *getScope() const;
535
536 /// Return the raw underlying file.
537 ///
538 /// A \a DIFile is a \a DIScope, but it doesn't point at a separate file (it
539 /// \em is the file). If \c this is an \a DIFile, we need to return \c this.
540 /// Otherwise, return the first operand, which is where all other subclasses
541 /// store their file pointer.
543 return isa<DIFile>(this) ? const_cast<DIScope *>(this)
544 : static_cast<Metadata *>(getOperand(0));
545 }
546
547 static bool classof(const Metadata *MD) {
548 switch (MD->getMetadataID()) {
549 default:
550 return false;
551 case DIBasicTypeKind:
552 case DIStringTypeKind:
553 case DIDerivedTypeKind:
554 case DICompositeTypeKind:
555 case DISubroutineTypeKind:
556 case DIFileKind:
557 case DICompileUnitKind:
558 case DISubprogramKind:
559 case DILexicalBlockKind:
560 case DILexicalBlockFileKind:
561 case DINamespaceKind:
562 case DICommonBlockKind:
563 case DIModuleKind:
564 return true;
565 }
566 }
567};
568
569/// File.
570///
571/// TODO: Merge with directory/file node (including users).
572/// TODO: Canonicalize paths on creation.
573class DIFile : public DIScope {
574 friend class LLVMContextImpl;
575 friend class MDNode;
576
577public:
578 /// Which algorithm (e.g. MD5) a checksum was generated with.
579 ///
580 /// The encoding is explicit because it is used directly in Bitcode. The
581 /// value 0 is reserved to indicate the absence of a checksum in Bitcode.
583 // The first variant was originally CSK_None, encoded as 0. The new
584 // internal representation removes the need for this by wrapping the
585 // ChecksumInfo in an Optional, but to preserve Bitcode compatibility the 0
586 // encoding is reserved.
590 CSK_Last = CSK_SHA256 // Should be last enumeration.
591 };
592
593 /// A single checksum, represented by a \a Kind and a \a Value (a string).
594 template <typename T> struct ChecksumInfo {
595 /// The kind of checksum which \a Value encodes.
597 /// The string value of the checksum.
599
601 ~ChecksumInfo() = default;
602 bool operator==(const ChecksumInfo<T> &X) const {
603 return Kind == X.Kind && Value == X.Value;
604 }
605 bool operator!=(const ChecksumInfo<T> &X) const { return !(*this == X); }
606 StringRef getKindAsString() const { return getChecksumKindAsString(Kind); }
607 };
608
609private:
610 std::optional<ChecksumInfo<MDString *>> Checksum;
611 /// An optional source. A nullptr means none.
612 MDString *Source;
613
615 std::optional<ChecksumInfo<MDString *>> CS, MDString *Src,
617 ~DIFile() = default;
618
619 static DIFile *getImpl(LLVMContext &Context, StringRef Filename,
621 std::optional<ChecksumInfo<StringRef>> CS,
622 std::optional<StringRef> Source, StorageType Storage,
623 bool ShouldCreate = true) {
624 std::optional<ChecksumInfo<MDString *>> MDChecksum;
625 if (CS)
626 MDChecksum.emplace(CS->Kind, getCanonicalMDString(Context, CS->Value));
627 return getImpl(Context, getCanonicalMDString(Context, Filename),
628 getCanonicalMDString(Context, Directory), MDChecksum,
629 Source ? MDString::get(Context, *Source) : nullptr, Storage,
630 ShouldCreate);
631 }
632 static DIFile *getImpl(LLVMContext &Context, MDString *Filename,
633 MDString *Directory,
634 std::optional<ChecksumInfo<MDString *>> CS,
635 MDString *Source, StorageType Storage,
636 bool ShouldCreate = true);
637
638 TempDIFile cloneImpl() const {
640 getChecksum(), getSource());
641 }
642
643public:
646 std::optional<ChecksumInfo<StringRef>> CS = std::nullopt,
647 std::optional<StringRef> Source = std::nullopt),
648 (Filename, Directory, CS, Source))
651 std::optional<ChecksumInfo<MDString *>> CS = std::nullopt,
652 MDString *Source = nullptr),
653 (Filename, Directory, CS, Source))
654
655 TempDIFile clone() const { return cloneImpl(); }
656
657 StringRef getFilename() const { return getStringOperand(0); }
658 StringRef getDirectory() const { return getStringOperand(1); }
659 std::optional<ChecksumInfo<StringRef>> getChecksum() const {
660 std::optional<ChecksumInfo<StringRef>> StringRefChecksum;
661 if (Checksum)
662 StringRefChecksum.emplace(Checksum->Kind, Checksum->Value->getString());
663 return StringRefChecksum;
664 }
665 std::optional<StringRef> getSource() const {
666 return Source ? std::optional<StringRef>(Source->getString())
667 : std::nullopt;
668 }
669
670 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
671 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
672 std::optional<ChecksumInfo<MDString *>> getRawChecksum() const {
673 return Checksum;
674 }
675 MDString *getRawSource() const { return Source; }
676
677 static StringRef getChecksumKindAsString(ChecksumKind CSKind);
678 static std::optional<ChecksumKind> getChecksumKind(StringRef CSKindStr);
679
680 static bool classof(const Metadata *MD) {
681 return MD->getMetadataID() == DIFileKind;
682 }
683};
684
686 if (auto *F = getFile())
687 return F->getFilename();
688 return "";
689}
690
692 if (auto *F = getFile())
693 return F->getDirectory();
694 return "";
695}
696
697std::optional<StringRef> DIScope::getSource() const {
698 if (auto *F = getFile())
699 return F->getSource();
700 return std::nullopt;
701}
702
703/// Base class for types.
704///
705/// TODO: Remove the hardcoded name and context, since many types don't use
706/// them.
707/// TODO: Split up flags.
708///
709/// Uses the SubclassData32 Metadata slot.
710class DIType : public DIScope {
711 unsigned Line;
712 DIFlags Flags;
713 uint64_t SizeInBits;
714 uint64_t OffsetInBits;
715 uint32_t NumExtraInhabitants;
716
717protected:
718 DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
719 unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits,
720 uint64_t OffsetInBits, uint32_t NumExtraInhabitants, DIFlags Flags,
722 : DIScope(C, ID, Storage, Tag, Ops) {
723 init(Line, SizeInBits, AlignInBits, OffsetInBits, NumExtraInhabitants,
724 Flags);
725 }
726 ~DIType() = default;
727
728 void init(unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits,
729 uint64_t OffsetInBits, uint32_t NumExtraInhabitants,
730 DIFlags Flags) {
731 this->Line = Line;
732 this->Flags = Flags;
733 this->SizeInBits = SizeInBits;
734 this->SubclassData32 = AlignInBits;
735 this->OffsetInBits = OffsetInBits;
736 this->NumExtraInhabitants = NumExtraInhabitants;
737 }
738
739 /// Change fields in place.
740 void mutate(unsigned Tag, unsigned Line, uint64_t SizeInBits,
741 uint32_t AlignInBits, uint64_t OffsetInBits,
742 uint32_t NumExtraInhabitants, DIFlags Flags) {
743 assert(isDistinct() && "Only distinct nodes can mutate");
744 setTag(Tag);
745 init(Line, SizeInBits, AlignInBits, OffsetInBits, NumExtraInhabitants,
746 Flags);
747 }
748
749public:
750 TempDIType clone() const {
751 return TempDIType(cast<DIType>(MDNode::clone().release()));
752 }
753
754 unsigned getLine() const { return Line; }
755 uint64_t getSizeInBits() const { return SizeInBits; }
756 uint32_t getAlignInBits() const;
757 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
758 uint64_t getOffsetInBits() const { return OffsetInBits; }
759 uint32_t getNumExtraInhabitants() const { return NumExtraInhabitants; }
760 DIFlags getFlags() const { return Flags; }
761
762 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
763 StringRef getName() const { return getStringOperand(2); }
764
765 Metadata *getRawScope() const { return getOperand(1); }
766 MDString *getRawName() const { return getOperandAs<MDString>(2); }
767
768 /// Returns a new temporary DIType with updated Flags
769 TempDIType cloneWithFlags(DIFlags NewFlags) const {
770 auto NewTy = clone();
771 NewTy->Flags = NewFlags;
772 return NewTy;
773 }
774
775 bool isPrivate() const {
776 return (getFlags() & FlagAccessibility) == FlagPrivate;
777 }
778 bool isProtected() const {
779 return (getFlags() & FlagAccessibility) == FlagProtected;
780 }
781 bool isPublic() const {
782 return (getFlags() & FlagAccessibility) == FlagPublic;
783 }
784 bool isForwardDecl() const { return getFlags() & FlagFwdDecl; }
785 bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; }
786 bool isVirtual() const { return getFlags() & FlagVirtual; }
787 bool isArtificial() const { return getFlags() & FlagArtificial; }
788 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
789 bool isObjcClassComplete() const {
790 return getFlags() & FlagObjcClassComplete;
791 }
792 bool isVector() const { return getFlags() & FlagVector; }
793 bool isBitField() const { return getFlags() & FlagBitField; }
794 bool isStaticMember() const { return getFlags() & FlagStaticMember; }
795 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
796 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
797 bool isTypePassByValue() const { return getFlags() & FlagTypePassByValue; }
799 return getFlags() & FlagTypePassByReference;
800 }
801 bool isBigEndian() const { return getFlags() & FlagBigEndian; }
802 bool isLittleEndian() const { return getFlags() & FlagLittleEndian; }
803 bool getExportSymbols() const { return getFlags() & FlagExportSymbols; }
804
805 static bool classof(const Metadata *MD) {
806 switch (MD->getMetadataID()) {
807 default:
808 return false;
809 case DIBasicTypeKind:
810 case DIStringTypeKind:
811 case DIDerivedTypeKind:
812 case DICompositeTypeKind:
813 case DISubroutineTypeKind:
814 return true;
815 }
816 }
817};
818
819/// Basic type, like 'int' or 'float'.
820///
821/// TODO: Split out DW_TAG_unspecified_type.
822/// TODO: Drop unused accessors.
823class DIBasicType : public DIType {
824 friend class LLVMContextImpl;
825 friend class MDNode;
826
827 unsigned Encoding;
828
830 uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
833 : DIType(C, DIBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
835 Encoding(Encoding) {}
836 ~DIBasicType() = default;
837
838 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
840 uint32_t AlignInBits, unsigned Encoding,
842 StorageType Storage, bool ShouldCreate = true) {
843 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
845 Flags, Storage, ShouldCreate);
846 }
847 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
848 MDString *Name, uint64_t SizeInBits,
849 uint32_t AlignInBits, unsigned Encoding,
851 StorageType Storage, bool ShouldCreate = true);
852
853 TempDIBasicType cloneImpl() const {
857 }
858
859public:
861 (Tag, Name, 0, 0, 0, 0, FlagZero))
864 (Tag, Name, SizeInBits, 0, 0, 0, FlagZero))
866 (unsigned Tag, MDString *Name, uint64_t SizeInBits),
867 (Tag, Name, SizeInBits, 0, 0, 0, FlagZero))
870 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
871 (Tag, Name, SizeInBits, AlignInBits, Encoding, 0, Flags))
873 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
874 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
875 (Tag, Name, SizeInBits, AlignInBits, Encoding, 0, Flags))
878 uint32_t AlignInBits, unsigned Encoding,
883 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
884 uint32_t AlignInBits, unsigned Encoding,
886 (Tag, Name, SizeInBits, AlignInBits, Encoding,
888
889 TempDIBasicType clone() const { return cloneImpl(); }
890
891 unsigned getEncoding() const { return Encoding; }
892
893 enum class Signedness { Signed, Unsigned };
894
895 /// Return the signedness of this type, or std::nullopt if this type is
896 /// neither signed nor unsigned.
897 std::optional<Signedness> getSignedness() const;
898
899 static bool classof(const Metadata *MD) {
900 return MD->getMetadataID() == DIBasicTypeKind;
901 }
902};
903
904/// String type, Fortran CHARACTER(n)
905class DIStringType : public DIType {
906 friend class LLVMContextImpl;
907 friend class MDNode;
908
909 unsigned Encoding;
910
912 uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
914 : DIType(C, DIStringTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
915 0, FlagZero, Ops),
916 Encoding(Encoding) {}
917 ~DIStringType() = default;
918
919 static DIStringType *getImpl(LLVMContext &Context, unsigned Tag,
921 Metadata *StrLenExp, Metadata *StrLocationExp,
923 unsigned Encoding, StorageType Storage,
924 bool ShouldCreate = true) {
925 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
926 StringLength, StrLenExp, StrLocationExp, SizeInBits,
927 AlignInBits, Encoding, Storage, ShouldCreate);
928 }
929 static DIStringType *getImpl(LLVMContext &Context, unsigned Tag,
930 MDString *Name, Metadata *StringLength,
931 Metadata *StrLenExp, Metadata *StrLocationExp,
933 unsigned Encoding, StorageType Storage,
934 bool ShouldCreate = true);
935
936 TempDIStringType cloneImpl() const {
941 }
942
943public:
947 (Tag, Name, nullptr, nullptr, nullptr, SizeInBits,
948 AlignInBits, 0))
953 unsigned Encoding),
960 unsigned Encoding),
963
964 TempDIStringType clone() const { return cloneImpl(); }
965
966 static bool classof(const Metadata *MD) {
967 return MD->getMetadataID() == DIStringTypeKind;
968 }
969
971 return cast_or_null<DIVariable>(getRawStringLength());
972 }
973
975 return cast_or_null<DIExpression>(getRawStringLengthExp());
976 }
977
979 return cast_or_null<DIExpression>(getRawStringLocationExp());
980 }
981
982 unsigned getEncoding() const { return Encoding; }
983
984 Metadata *getRawStringLength() const { return getOperand(3); }
985
987
989};
990
991/// Derived types.
992///
993/// This includes qualified types, pointers, references, friends, typedefs, and
994/// class members.
995///
996/// TODO: Split out members (inheritance, fields, methods, etc.).
997class DIDerivedType : public DIType {
998public:
999 /// Pointer authentication (__ptrauth) metadata.
1001 // RawData layout:
1002 // - Bits 0..3: Key
1003 // - Bit 4: IsAddressDiscriminated
1004 // - Bits 5..20: ExtraDiscriminator
1005 // - Bit 21: IsaPointer
1006 // - Bit 22: AuthenticatesNullValues
1007 unsigned RawData;
1008
1009 PtrAuthData(unsigned FromRawData) : RawData(FromRawData) {}
1010 PtrAuthData(unsigned Key, bool IsDiscr, unsigned Discriminator,
1011 bool IsaPointer, bool AuthenticatesNullValues) {
1012 assert(Key < 16);
1013 assert(Discriminator <= 0xffff);
1014 RawData = (Key << 0) | (IsDiscr ? (1 << 4) : 0) | (Discriminator << 5) |
1015 (IsaPointer ? (1 << 21) : 0) |
1016 (AuthenticatesNullValues ? (1 << 22) : 0);
1017 }
1018
1019 unsigned key() { return (RawData >> 0) & 0b1111; }
1020 bool isAddressDiscriminated() { return (RawData >> 4) & 1; }
1021 unsigned extraDiscriminator() { return (RawData >> 5) & 0xffff; }
1022 bool isaPointer() { return (RawData >> 21) & 1; }
1023 bool authenticatesNullValues() { return (RawData >> 22) & 1; }
1024 };
1025
1026private:
1027 friend class LLVMContextImpl;
1028 friend class MDNode;
1029
1030 /// The DWARF address space of the memory pointed to or referenced by a
1031 /// pointer or reference type respectively.
1032 std::optional<unsigned> DWARFAddressSpace;
1033
1037 std::optional<unsigned> DWARFAddressSpace,
1038 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1040 : DIType(C, DIDerivedTypeKind, Storage, Tag, Line, SizeInBits,
1041 AlignInBits, OffsetInBits, 0, Flags, Ops),
1042 DWARFAddressSpace(DWARFAddressSpace) {
1043 if (PtrAuthData)
1045 }
1046 ~DIDerivedType() = default;
1047 static DIDerivedType *
1048 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1051 std::optional<unsigned> DWARFAddressSpace,
1052 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1054 bool ShouldCreate = true) {
1055 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1057 DWARFAddressSpace, PtrAuthData, Flags, ExtraData,
1058 Annotations.get(), Storage, ShouldCreate);
1059 }
1060 static DIDerivedType *
1061 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1062 unsigned Line, Metadata *Scope, Metadata *BaseType,
1064 std::optional<unsigned> DWARFAddressSpace,
1065 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1067 bool ShouldCreate = true);
1068
1069 TempDIDerivedType cloneImpl() const {
1070 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
1073 getDWARFAddressSpace(), getPtrAuthData(), getFlags(),
1075 }
1076
1077public:
1079 (unsigned Tag, MDString *Name, Metadata *File,
1080 unsigned Line, Metadata *Scope, Metadata *BaseType,
1083 std::optional<unsigned> DWARFAddressSpace,
1084 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1085 Metadata *ExtraData = nullptr,
1086 Metadata *Annotations = nullptr),
1088 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1091 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1094 std::optional<unsigned> DWARFAddressSpace,
1095 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1097 DINodeArray Annotations = nullptr),
1099 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1101
1102 TempDIDerivedType clone() const { return cloneImpl(); }
1103
1104 /// Get the base type this is derived from.
1105 DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); }
1106 Metadata *getRawBaseType() const { return getOperand(3); }
1107
1108 /// \returns The DWARF address space of the memory pointed to or referenced by
1109 /// a pointer or reference type respectively.
1110 std::optional<unsigned> getDWARFAddressSpace() const {
1111 return DWARFAddressSpace;
1112 }
1113
1114 std::optional<PtrAuthData> getPtrAuthData() const;
1115
1116 /// Get extra data associated with this derived type.
1117 ///
1118 /// Class type for pointer-to-members, objective-c property node for ivars,
1119 /// global constant wrapper for static members, virtual base pointer offset
1120 /// for inheritance, or a tuple of template parameters for template aliases.
1121 ///
1122 /// TODO: Separate out types that need this extra operand: pointer-to-member
1123 /// types and member fields (static members and ivars).
1125 Metadata *getRawExtraData() const { return getOperand(4); }
1126
1127 /// Get the template parameters from a template alias.
1128 DITemplateParameterArray getTemplateParams() const {
1129 return cast_or_null<MDTuple>(getExtraData());
1130 }
1131
1132 /// Get annotations associated with this derived type.
1133 DINodeArray getAnnotations() const {
1134 return cast_or_null<MDTuple>(getRawAnnotations());
1135 }
1136 Metadata *getRawAnnotations() const { return getOperand(5); }
1137
1138 /// Get casted version of extra data.
1139 /// @{
1140 DIType *getClassType() const;
1141
1143 return dyn_cast_or_null<DIObjCProperty>(getExtraData());
1144 }
1145
1146 uint32_t getVBPtrOffset() const;
1147
1149
1150 Constant *getConstant() const;
1151
1153 /// @}
1154
1155 static bool classof(const Metadata *MD) {
1156 return MD->getMetadataID() == DIDerivedTypeKind;
1157 }
1158};
1159
1162 return Lhs.RawData == Rhs.RawData;
1163}
1164
1167 return !(Lhs == Rhs);
1168}
1169
1170/// Composite types.
1171///
1172/// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
1173/// TODO: Create a custom, unrelated node for DW_TAG_array_type.
1174class DICompositeType : public DIType {
1175 friend class LLVMContextImpl;
1176 friend class MDNode;
1177
1178 unsigned RuntimeLang;
1179 std::optional<uint32_t> EnumKind;
1180
1182 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
1185 std::optional<uint32_t> EnumKind, DIFlags Flags,
1187 : DIType(C, DICompositeTypeKind, Storage, Tag, Line, SizeInBits,
1189 RuntimeLang(RuntimeLang), EnumKind(EnumKind) {}
1190 ~DICompositeType() = default;
1191
1192 /// Change fields in place.
1193 void mutate(unsigned Tag, unsigned Line, unsigned RuntimeLang,
1195 uint32_t NumExtraInhabitants, std::optional<uint32_t> EnumKind,
1196 DIFlags Flags) {
1197 assert(isDistinct() && "Only distinct nodes can mutate");
1198 assert(getRawIdentifier() && "Only ODR-uniqued nodes should mutate");
1199 this->RuntimeLang = RuntimeLang;
1200 this->EnumKind = EnumKind;
1203 }
1204
1205 static DICompositeType *
1206 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
1207 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1210 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1211 DIType *VTableHolder, DITemplateParameterArray TemplateParams,
1212 StringRef Identifier, DIDerivedType *Discriminator,
1215 bool ShouldCreate = true) {
1216 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1218 Flags, Elements.get(), RuntimeLang, EnumKind, VTableHolder,
1219 TemplateParams.get(),
1222 Specification, NumExtraInhabitants, Storage, ShouldCreate);
1223 }
1224 static DICompositeType *
1225 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1226 unsigned Line, Metadata *Scope, Metadata *BaseType,
1228 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
1229 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1234 StorageType Storage, bool ShouldCreate = true);
1235
1236 TempDICompositeType cloneImpl() const {
1237 return getTemporary(
1245 }
1246
1247public:
1250 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1253 DINodeArray Elements, unsigned RuntimeLang,
1254 std::optional<uint32_t> EnumKind, DIType *VTableHolder,
1255 DITemplateParameterArray TemplateParams = nullptr,
1257 Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
1258 Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
1259 DINodeArray Annotations = nullptr, DIType *Specification = nullptr,
1263 RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier,
1267 (unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
1270 Metadata *Elements, unsigned RuntimeLang,
1271 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1274 Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
1275 Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
1278 OffsetInBits, Flags, Elements, RuntimeLang, EnumKind, VTableHolder,
1281
1282 TempDICompositeType clone() const { return cloneImpl(); }
1283
1284 /// Get a DICompositeType with the given ODR identifier.
1285 ///
1286 /// If \a LLVMContext::isODRUniquingDebugTypes(), gets the mapped
1287 /// DICompositeType for the given ODR \c Identifier. If none exists, creates
1288 /// a new node.
1289 ///
1290 /// Else, returns \c nullptr.
1291 static DICompositeType *
1292 getODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1293 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1297 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1304
1305 /// Build a DICompositeType with the given ODR identifier.
1306 ///
1307 /// Looks up the mapped DICompositeType for the given ODR \c Identifier. If
1308 /// it doesn't exist, creates a new one. If it does exist and \a
1309 /// isForwardDecl(), and the new arguments would be a definition, mutates the
1310 /// the type in place. In either case, returns the type.
1311 ///
1312 /// If not \a LLVMContext::isODRUniquingDebugTypes(), this function returns
1313 /// nullptr.
1314 static DICompositeType *
1315 buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1316 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1320 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1325
1326 DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); }
1327 DINodeArray getElements() const {
1328 return cast_or_null<MDTuple>(getRawElements());
1329 }
1331 return cast_or_null<DIType>(getRawVTableHolder());
1332 }
1333 DITemplateParameterArray getTemplateParams() const {
1334 return cast_or_null<MDTuple>(getRawTemplateParams());
1335 }
1337 unsigned getRuntimeLang() const { return RuntimeLang; }
1338 std::optional<uint32_t> getEnumKind() const { return EnumKind; }
1339
1340 Metadata *getRawBaseType() const { return getOperand(3); }
1341 Metadata *getRawElements() const { return getOperand(4); }
1344 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
1347 return getOperandAs<DIDerivedType>(8);
1348 }
1351 return dyn_cast_or_null<DIVariable>(getRawDataLocation());
1352 }
1354 return dyn_cast_or_null<DIExpression>(getRawDataLocation());
1355 }
1356 Metadata *getRawAssociated() const { return getOperand(10); }
1358 return dyn_cast_or_null<DIVariable>(getRawAssociated());
1359 }
1361 return dyn_cast_or_null<DIExpression>(getRawAssociated());
1362 }
1363 Metadata *getRawAllocated() const { return getOperand(11); }
1365 return dyn_cast_or_null<DIVariable>(getRawAllocated());
1366 }
1368 return dyn_cast_or_null<DIExpression>(getRawAllocated());
1369 }
1370 Metadata *getRawRank() const { return getOperand(12); }
1372 if (auto *MD = dyn_cast_or_null<ConstantAsMetadata>(getRawRank()))
1373 return dyn_cast_or_null<ConstantInt>(MD->getValue());
1374 return nullptr;
1375 }
1377 return dyn_cast_or_null<DIExpression>(getRawRank());
1378 }
1379
1380 Metadata *getRawAnnotations() const { return getOperand(13); }
1381 DINodeArray getAnnotations() const {
1382 return cast_or_null<MDTuple>(getRawAnnotations());
1383 }
1384
1385 Metadata *getRawSpecification() const { return getOperand(14); }
1387 return cast_or_null<DIType>(getRawSpecification());
1388 }
1389 /// Replace operands.
1390 ///
1391 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
1392 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
1393 /// of its movement if necessary.
1394 /// @{
1395 void replaceElements(DINodeArray Elements) {
1396#ifndef NDEBUG
1397 for (DINode *Op : getElements())
1398 assert(is_contained(Elements->operands(), Op) &&
1399 "Lost a member during member list replacement");
1400#endif
1401 replaceOperandWith(4, Elements.get());
1402 }
1403
1406 }
1407
1408 void replaceTemplateParams(DITemplateParameterArray TemplateParams) {
1410 }
1411 /// @}
1412
1413 static bool classof(const Metadata *MD) {
1414 return MD->getMetadataID() == DICompositeTypeKind;
1415 }
1416};
1417
1418/// Type array for a subprogram.
1419///
1420/// TODO: Fold the array of types in directly as operands.
1421class DISubroutineType : public DIType {
1422 friend class LLVMContextImpl;
1423 friend class MDNode;
1424
1425 /// The calling convention used with DW_AT_calling_convention. Actually of
1426 /// type dwarf::CallingConvention.
1427 uint8_t CC;
1428
1431 ~DISubroutineType() = default;
1432
1433 static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
1436 bool ShouldCreate = true) {
1437 return getImpl(Context, Flags, CC, TypeArray.get(), Storage, ShouldCreate);
1438 }
1439 static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
1442 bool ShouldCreate = true);
1443
1444 TempDISubroutineType cloneImpl() const {
1446 }
1447
1448public:
1451 (Flags, CC, TypeArray))
1455
1456 TempDISubroutineType clone() const { return cloneImpl(); }
1457 // Returns a new temporary DISubroutineType with updated CC
1458 TempDISubroutineType cloneWithCC(uint8_t CC) const {
1459 auto NewTy = clone();
1460 NewTy->CC = CC;
1461 return NewTy;
1462 }
1463
1464 uint8_t getCC() const { return CC; }
1465
1467 return cast_or_null<MDTuple>(getRawTypeArray());
1468 }
1469
1470 Metadata *getRawTypeArray() const { return getOperand(3); }
1471
1472 static bool classof(const Metadata *MD) {
1473 return MD->getMetadataID() == DISubroutineTypeKind;
1474 }
1475};
1476
1477/// Compile unit.
1478class DICompileUnit : public DIScope {
1479 friend class LLVMContextImpl;
1480 friend class MDNode;
1481
1482public:
1483 enum DebugEmissionKind : unsigned {
1490
1491 enum class DebugNameTableKind : unsigned {
1492 Default = 0,
1493 GNU = 1,
1494 None = 2,
1495 Apple = 3,
1497 };
1498
1499 static std::optional<DebugEmissionKind> getEmissionKind(StringRef Str);
1500 static const char *emissionKindString(DebugEmissionKind EK);
1501 static std::optional<DebugNameTableKind> getNameTableKind(StringRef Str);
1502 static const char *nameTableKindString(DebugNameTableKind PK);
1503
1504private:
1505 unsigned SourceLanguage;
1506 unsigned RuntimeVersion;
1507 uint64_t DWOId;
1508 unsigned EmissionKind;
1509 unsigned NameTableKind;
1510 bool IsOptimized;
1511 bool SplitDebugInlining;
1512 bool DebugInfoForProfiling;
1513 bool RangesBaseAddress;
1514
1516 bool IsOptimized, unsigned RuntimeVersion,
1517 unsigned EmissionKind, uint64_t DWOId, bool SplitDebugInlining,
1518 bool DebugInfoForProfiling, unsigned NameTableKind,
1519 bool RangesBaseAddress, ArrayRef<Metadata *> Ops);
1520 ~DICompileUnit() = default;
1521
1522 static DICompileUnit *
1523 getImpl(LLVMContext &Context, unsigned SourceLanguage, DIFile *File,
1524 StringRef Producer, bool IsOptimized, StringRef Flags,
1525 unsigned RuntimeVersion, StringRef SplitDebugFilename,
1526 unsigned EmissionKind, DICompositeTypeArray EnumTypes,
1527 DIScopeArray RetainedTypes,
1528 DIGlobalVariableExpressionArray GlobalVariables,
1529 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
1530 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
1531 unsigned NameTableKind, bool RangesBaseAddress, StringRef SysRoot,
1532 StringRef SDK, StorageType Storage, bool ShouldCreate = true) {
1533 return getImpl(
1534 Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
1535 IsOptimized, getCanonicalMDString(Context, Flags), RuntimeVersion,
1536 getCanonicalMDString(Context, SplitDebugFilename), EmissionKind,
1537 EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
1538 ImportedEntities.get(), Macros.get(), DWOId, SplitDebugInlining,
1539 DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
1540 getCanonicalMDString(Context, SysRoot),
1541 getCanonicalMDString(Context, SDK), Storage, ShouldCreate);
1542 }
1543 static DICompileUnit *
1544 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
1545 MDString *Producer, bool IsOptimized, MDString *Flags,
1546 unsigned RuntimeVersion, MDString *SplitDebugFilename,
1547 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
1549 Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining,
1550 bool DebugInfoForProfiling, unsigned NameTableKind,
1551 bool RangesBaseAddress, MDString *SysRoot, MDString *SDK,
1552 StorageType Storage, bool ShouldCreate = true);
1553
1554 TempDICompileUnit cloneImpl() const {
1555 return getTemporary(
1562 }
1563
1564public:
1565 static void get() = delete;
1566 static void getIfExists() = delete;
1567
1571 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
1573 DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes,
1574 DIGlobalVariableExpressionArray GlobalVariables,
1575 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
1576 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
1577 DebugNameTableKind NameTableKind, bool RangesBaseAddress,
1579 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
1581 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
1582 DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress,
1583 SysRoot, SDK))
1587 bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
1591 bool SplitDebugInlining, bool DebugInfoForProfiling,
1592 unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
1594 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
1596 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
1597 DebugInfoForProfiling, NameTableKind, RangesBaseAddress, SysRoot, SDK))
1598
1599 TempDICompileUnit clone() const { return cloneImpl(); }
1600
1601 unsigned getSourceLanguage() const { return SourceLanguage; }
1602 bool isOptimized() const { return IsOptimized; }
1603 unsigned getRuntimeVersion() const { return RuntimeVersion; }
1605 return (DebugEmissionKind)EmissionKind;
1606 }
1608 return EmissionKind == DebugDirectivesOnly;
1609 }
1610 bool getDebugInfoForProfiling() const { return DebugInfoForProfiling; }
1612 return (DebugNameTableKind)NameTableKind;
1613 }
1614 bool getRangesBaseAddress() const { return RangesBaseAddress; }
1616 StringRef getFlags() const { return getStringOperand(2); }
1618 DICompositeTypeArray getEnumTypes() const {
1619 return cast_or_null<MDTuple>(getRawEnumTypes());
1620 }
1621 DIScopeArray getRetainedTypes() const {
1622 return cast_or_null<MDTuple>(getRawRetainedTypes());
1623 }
1624 DIGlobalVariableExpressionArray getGlobalVariables() const {
1625 return cast_or_null<MDTuple>(getRawGlobalVariables());
1626 }
1627 DIImportedEntityArray getImportedEntities() const {
1628 return cast_or_null<MDTuple>(getRawImportedEntities());
1629 }
1630 DIMacroNodeArray getMacros() const {
1631 return cast_or_null<MDTuple>(getRawMacros());
1632 }
1633 uint64_t getDWOId() const { return DWOId; }
1634 void setDWOId(uint64_t DwoId) { DWOId = DwoId; }
1635 bool getSplitDebugInlining() const { return SplitDebugInlining; }
1636 void setSplitDebugInlining(bool SplitDebugInlining) {
1637 this->SplitDebugInlining = SplitDebugInlining;
1638 }
1640 StringRef getSDK() const { return getStringOperand(10); }
1641
1642 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
1643 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
1645 return getOperandAs<MDString>(3);
1646 }
1647 Metadata *getRawEnumTypes() const { return getOperand(4); }
1651 Metadata *getRawMacros() const { return getOperand(8); }
1652 MDString *getRawSysRoot() const { return getOperandAs<MDString>(9); }
1653 MDString *getRawSDK() const { return getOperandAs<MDString>(10); }
1654
1655 /// Replace arrays.
1656 ///
1657 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
1658 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
1659 /// DICompileUnit should be fairly rare.
1660 /// @{
1661 void replaceEnumTypes(DICompositeTypeArray N) {
1662 replaceOperandWith(4, N.get());
1663 }
1664 void replaceRetainedTypes(DITypeArray N) { replaceOperandWith(5, N.get()); }
1665 void replaceGlobalVariables(DIGlobalVariableExpressionArray N) {
1666 replaceOperandWith(6, N.get());
1667 }
1668 void replaceImportedEntities(DIImportedEntityArray N) {
1669 replaceOperandWith(7, N.get());
1670 }
1671 void replaceMacros(DIMacroNodeArray N) { replaceOperandWith(8, N.get()); }
1672 /// @}
1673
1674 static bool classof(const Metadata *MD) {
1675 return MD->getMetadataID() == DICompileUnitKind;
1676 }
1677};
1678
1679/// A scope for locals.
1680///
1681/// A legal scope for lexical blocks, local variables, and debug info
1682/// locations. Subclasses are \a DISubprogram, \a DILexicalBlock, and \a
1683/// DILexicalBlockFile.
1684class DILocalScope : public DIScope {
1685protected:
1688 : DIScope(C, ID, Storage, Tag, Ops) {}
1689 ~DILocalScope() = default;
1690
1691public:
1692 /// Get the subprogram for this scope.
1693 ///
1694 /// Return this if it's an \a DISubprogram; otherwise, look up the scope
1695 /// chain.
1696 DISubprogram *getSubprogram() const;
1697
1698 /// Traverses the scope chain rooted at RootScope until it hits a Subprogram,
1699 /// recreating the chain with "NewSP" instead.
1700 static DILocalScope *
1702 LLVMContext &Ctx,
1704
1705 /// Get the first non DILexicalBlockFile scope of this scope.
1706 ///
1707 /// Return this if it's not a \a DILexicalBlockFIle; otherwise, look up the
1708 /// scope chain.
1710
1711 static bool classof(const Metadata *MD) {
1712 return MD->getMetadataID() == DISubprogramKind ||
1713 MD->getMetadataID() == DILexicalBlockKind ||
1714 MD->getMetadataID() == DILexicalBlockFileKind;
1715 }
1716};
1717
1718/// Subprogram description.
1720 friend class LLVMContextImpl;
1721 friend class MDNode;
1722
1723 unsigned Line;
1724 unsigned ScopeLine;
1725 unsigned VirtualIndex;
1726
1727 /// In the MS ABI, the implicit 'this' parameter is adjusted in the prologue
1728 /// of method overrides from secondary bases by this amount. It may be
1729 /// negative.
1730 int ThisAdjustment;
1731
1732public:
1733 /// Debug info subprogram flags.
1735#define HANDLE_DISP_FLAG(ID, NAME) SPFlag##NAME = ID,
1736#define DISP_FLAG_LARGEST_NEEDED
1737#include "llvm/IR/DebugInfoFlags.def"
1738 SPFlagNonvirtual = SPFlagZero,
1739 SPFlagVirtuality = SPFlagVirtual | SPFlagPureVirtual,
1740 LLVM_MARK_AS_BITMASK_ENUM(SPFlagLargest)
1741 };
1742
1743 static DISPFlags getFlag(StringRef Flag);
1744 static StringRef getFlagString(DISPFlags Flag);
1745
1746 /// Split up a flags bitfield for easier printing.
1747 ///
1748 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
1749 /// any remaining (unrecognized) bits.
1750 static DISPFlags splitFlags(DISPFlags Flags,
1751 SmallVectorImpl<DISPFlags> &SplitFlags);
1752
1753 // Helper for converting old bitfields to new flags word.
1754 static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition,
1755 bool IsOptimized,
1756 unsigned Virtuality = SPFlagNonvirtual,
1757 bool IsMainSubprogram = false);
1758
1759private:
1760 DIFlags Flags;
1761 DISPFlags SPFlags;
1762
1763 DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1764 unsigned ScopeLine, unsigned VirtualIndex, int ThisAdjustment,
1765 DIFlags Flags, DISPFlags SPFlags, ArrayRef<Metadata *> Ops);
1766 ~DISubprogram() = default;
1767
1768 static DISubprogram *
1769 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
1770 StringRef LinkageName, DIFile *File, unsigned Line,
1771 DISubroutineType *Type, unsigned ScopeLine, DIType *ContainingType,
1772 unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags,
1773 DISPFlags SPFlags, DICompileUnit *Unit,
1774 DITemplateParameterArray TemplateParams, DISubprogram *Declaration,
1775 DINodeArray RetainedNodes, DITypeArray ThrownTypes,
1777 StorageType Storage, bool ShouldCreate = true) {
1778 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1779 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1780 ScopeLine, ContainingType, VirtualIndex, ThisAdjustment,
1781 Flags, SPFlags, Unit, TemplateParams.get(), Declaration,
1782 RetainedNodes.get(), ThrownTypes.get(), Annotations.get(),
1784 Storage, ShouldCreate);
1785 }
1786 static DISubprogram *
1787 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1788 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1789 unsigned ScopeLine, Metadata *ContainingType, unsigned VirtualIndex,
1790 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
1794 bool ShouldCreate = true);
1795
1796 TempDISubprogram cloneImpl() const {
1798 getFile(), getLine(), getType(), getScopeLine(),
1799 getContainingType(), getVirtualIndex(),
1800 getThisAdjustment(), getFlags(), getSPFlags(),
1801 getUnit(), getTemplateParams(), getDeclaration(),
1802 getRetainedNodes(), getThrownTypes(), getAnnotations(),
1803 getTargetFuncName());
1804 }
1805
1806public:
1810 unsigned Line, DISubroutineType *Type, unsigned ScopeLine,
1811 DIType *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
1812 DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit,
1813 DITemplateParameterArray TemplateParams = nullptr,
1814 DISubprogram *Declaration = nullptr, DINodeArray RetainedNodes = nullptr,
1815 DITypeArray ThrownTypes = nullptr, DINodeArray Annotations = nullptr,
1817 (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
1818 VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
1820
1824 unsigned Line, Metadata *Type, unsigned ScopeLine,
1825 Metadata *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
1826 DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
1830 (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
1831 VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
1833
1834 TempDISubprogram clone() const { return cloneImpl(); }
1835
1836 /// Returns a new temporary DISubprogram with updated Flags
1837 TempDISubprogram cloneWithFlags(DIFlags NewFlags) const {
1838 auto NewSP = clone();
1839 NewSP->Flags = NewFlags;
1840 return NewSP;
1841 }
1842
1843public:
1844 unsigned getLine() const { return Line; }
1845 unsigned getVirtuality() const { return getSPFlags() & SPFlagVirtuality; }
1846 unsigned getVirtualIndex() const { return VirtualIndex; }
1847 int getThisAdjustment() const { return ThisAdjustment; }
1848 unsigned getScopeLine() const { return ScopeLine; }
1849 void setScopeLine(unsigned L) {
1850 assert(isDistinct());
1851 ScopeLine = L;
1852 }
1853 DIFlags getFlags() const { return Flags; }
1854 DISPFlags getSPFlags() const { return SPFlags; }
1855 bool isLocalToUnit() const { return getSPFlags() & SPFlagLocalToUnit; }
1856 bool isDefinition() const { return getSPFlags() & SPFlagDefinition; }
1857 bool isOptimized() const { return getSPFlags() & SPFlagOptimized; }
1858 bool isMainSubprogram() const { return getSPFlags() & SPFlagMainSubprogram; }
1859
1860 bool isArtificial() const { return getFlags() & FlagArtificial; }
1861 bool isPrivate() const {
1862 return (getFlags() & FlagAccessibility) == FlagPrivate;
1863 }
1864 bool isProtected() const {
1865 return (getFlags() & FlagAccessibility) == FlagProtected;
1866 }
1867 bool isPublic() const {
1868 return (getFlags() & FlagAccessibility) == FlagPublic;
1869 }
1870 bool isExplicit() const { return getFlags() & FlagExplicit; }
1871 bool isPrototyped() const { return getFlags() & FlagPrototyped; }
1872 bool areAllCallsDescribed() const {
1873 return getFlags() & FlagAllCallsDescribed;
1874 }
1875 bool isPure() const { return getSPFlags() & SPFlagPure; }
1876 bool isElemental() const { return getSPFlags() & SPFlagElemental; }
1877 bool isRecursive() const { return getSPFlags() & SPFlagRecursive; }
1878 bool isObjCDirect() const { return getSPFlags() & SPFlagObjCDirect; }
1879
1880 /// Check if this is deleted member function.
1881 ///
1882 /// Return true if this subprogram is a C++11 special
1883 /// member function declared deleted.
1884 bool isDeleted() const { return getSPFlags() & SPFlagDeleted; }
1885
1886 /// Check if this is reference-qualified.
1887 ///
1888 /// Return true if this subprogram is a C++11 reference-qualified non-static
1889 /// member function (void foo() &).
1890 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
1891
1892 /// Check if this is rvalue-reference-qualified.
1893 ///
1894 /// Return true if this subprogram is a C++11 rvalue-reference-qualified
1895 /// non-static member function (void foo() &&).
1896 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
1897
1898 /// Check if this is marked as noreturn.
1899 ///
1900 /// Return true if this subprogram is C++11 noreturn or C11 _Noreturn
1901 bool isNoReturn() const { return getFlags() & FlagNoReturn; }
1902
1903 // Check if this routine is a compiler-generated thunk.
1904 //
1905 // Returns true if this subprogram is a thunk generated by the compiler.
1906 bool isThunk() const { return getFlags() & FlagThunk; }
1907
1908 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
1909
1910 StringRef getName() const { return getStringOperand(2); }
1911 StringRef getLinkageName() const { return getStringOperand(3); }
1912 /// Only used by clients of CloneFunction, and only right after the cloning.
1913 void replaceLinkageName(MDString *LN) { replaceOperandWith(3, LN); }
1914
1915 DISubroutineType *getType() const {
1916 return cast_or_null<DISubroutineType>(getRawType());
1917 }
1918 DIType *getContainingType() const {
1919 return cast_or_null<DIType>(getRawContainingType());
1920 }
1921 void replaceType(DISubroutineType *Ty) {
1922 assert(isDistinct() && "Only distinct nodes can mutate");
1923 replaceOperandWith(4, Ty);
1924 }
1925
1926 DICompileUnit *getUnit() const {
1927 return cast_or_null<DICompileUnit>(getRawUnit());
1928 }
1929 void replaceUnit(DICompileUnit *CU) { replaceOperandWith(5, CU); }
1930 DITemplateParameterArray getTemplateParams() const {
1931 return cast_or_null<MDTuple>(getRawTemplateParams());
1932 }
1933 DISubprogram *getDeclaration() const {
1934 return cast_or_null<DISubprogram>(getRawDeclaration());
1935 }
1936 void replaceDeclaration(DISubprogram *Decl) { replaceOperandWith(6, Decl); }
1937 DINodeArray getRetainedNodes() const {
1938 return cast_or_null<MDTuple>(getRawRetainedNodes());
1939 }
1940 DITypeArray getThrownTypes() const {
1941 return cast_or_null<MDTuple>(getRawThrownTypes());
1942 }
1943 DINodeArray getAnnotations() const {
1944 return cast_or_null<MDTuple>(getRawAnnotations());
1945 }
1946 StringRef getTargetFuncName() const {
1947 return (getRawTargetFuncName()) ? getStringOperand(12) : StringRef();
1948 }
1949
1950 Metadata *getRawScope() const { return getOperand(1); }
1951 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1952 MDString *getRawLinkageName() const { return getOperandAs<MDString>(3); }
1953 Metadata *getRawType() const { return getOperand(4); }
1954 Metadata *getRawUnit() const { return getOperand(5); }
1955 Metadata *getRawDeclaration() const { return getOperand(6); }
1956 Metadata *getRawRetainedNodes() const { return getOperand(7); }
1957 Metadata *getRawContainingType() const {
1958 return getNumOperands() > 8 ? getOperandAs<Metadata>(8) : nullptr;
1959 }
1960 Metadata *getRawTemplateParams() const {
1961 return getNumOperands() > 9 ? getOperandAs<Metadata>(9) : nullptr;
1962 }
1963 Metadata *getRawThrownTypes() const {
1964 return getNumOperands() > 10 ? getOperandAs<Metadata>(10) : nullptr;
1965 }
1966 Metadata *getRawAnnotations() const {
1967 return getNumOperands() > 11 ? getOperandAs<Metadata>(11) : nullptr;
1968 }
1969 MDString *getRawTargetFuncName() const {
1970 return getNumOperands() > 12 ? getOperandAs<MDString>(12) : nullptr;
1971 }
1972
1973 void replaceRawLinkageName(MDString *LinkageName) {
1975 }
1976 void replaceRetainedNodes(DINodeArray N) {
1977 replaceOperandWith(7, N.get());
1978 }
1979
1980 /// Check if this subprogram describes the given function.
1981 ///
1982 /// FIXME: Should this be looking through bitcasts?
1983 bool describes(const Function *F) const;
1984
1985 static bool classof(const Metadata *MD) {
1986 return MD->getMetadataID() == DISubprogramKind;
1987 }
1988};
1989
1990/// Debug location.
1991///
1992/// A debug location in source code, used for debug info and otherwise.
1993///
1994/// Uses the SubclassData1, SubclassData16 and SubclassData32
1995/// Metadata slots.
1996
1997class DILocation : public MDNode {
1998 friend class LLVMContextImpl;
1999 friend class MDNode;
2000
2002 unsigned Column, ArrayRef<Metadata *> MDs, bool ImplicitCode);
2004
2005 static DILocation *getImpl(LLVMContext &Context, unsigned Line,
2006 unsigned Column, Metadata *Scope,
2008 StorageType Storage, bool ShouldCreate = true);
2009 static DILocation *getImpl(LLVMContext &Context, unsigned Line,
2010 unsigned Column, DILocalScope *Scope,
2012 StorageType Storage, bool ShouldCreate = true) {
2013 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
2014 static_cast<Metadata *>(InlinedAt), ImplicitCode, Storage,
2015 ShouldCreate);
2016 }
2017
2018 TempDILocation cloneImpl() const {
2019 // Get the raw scope/inlinedAt since it is possible to invoke this on
2020 // a DILocation containing temporary metadata.
2021 return getTemporary(getContext(), getLine(), getColumn(), getRawScope(),
2022 getRawInlinedAt(), isImplicitCode());
2023 }
2024
2025public:
2026 // Disallow replacing operands.
2027 void replaceOperandWith(unsigned I, Metadata *New) = delete;
2028
2030 (unsigned Line, unsigned Column, Metadata *Scope,
2031 Metadata *InlinedAt = nullptr, bool ImplicitCode = false),
2034 (unsigned Line, unsigned Column, DILocalScope *Scope,
2036 bool ImplicitCode = false),
2038
2039 /// Return a (temporary) clone of this.
2040 TempDILocation clone() const { return cloneImpl(); }
2041
2042 unsigned getLine() const { return SubclassData32; }
2043 unsigned getColumn() const { return SubclassData16; }
2044 DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
2045
2046 /// Return the linkage name of Subprogram. If the linkage name is empty,
2047 /// return scope name (the demangled name).
2048 StringRef getSubprogramLinkageName() const {
2049 DISubprogram *SP = getScope()->getSubprogram();
2050 if (!SP)
2051 return "";
2052 auto Name = SP->getLinkageName();
2053 if (!Name.empty())
2054 return Name;
2055 return SP->getName();
2056 }
2057
2058 DILocation *getInlinedAt() const {
2059 return cast_or_null<DILocation>(getRawInlinedAt());
2060 }
2061
2062 /// Check if the location corresponds to an implicit code.
2063 /// When the ImplicitCode flag is true, it means that the Instruction
2064 /// with this DILocation has been added by the front-end but it hasn't been
2065 /// written explicitly by the user (e.g. cleanup stuff in C++ put on a closing
2066 /// bracket). It's useful for code coverage to not show a counter on "empty"
2067 /// lines.
2068 bool isImplicitCode() const { return SubclassData1; }
2069 void setImplicitCode(bool ImplicitCode) { SubclassData1 = ImplicitCode; }
2070
2071 DIFile *getFile() const { return getScope()->getFile(); }
2072 StringRef getFilename() const { return getScope()->getFilename(); }
2073 StringRef getDirectory() const { return getScope()->getDirectory(); }
2074 std::optional<StringRef> getSource() const { return getScope()->getSource(); }
2075
2076 /// Get the scope where this is inlined.
2077 ///
2078 /// Walk through \a getInlinedAt() and return \a getScope() from the deepest
2079 /// location.
2080 DILocalScope *getInlinedAtScope() const {
2081 if (auto *IA = getInlinedAt())
2082 return IA->getInlinedAtScope();
2083 return getScope();
2084 }
2085
2086 /// Get the DWARF discriminator.
2087 ///
2088 /// DWARF discriminators distinguish identical file locations between
2089 /// instructions that are on different basic blocks.
2090 ///
2091 /// There are 3 components stored in discriminator, from lower bits:
2092 ///
2093 /// Base discriminator: assigned by AddDiscriminators pass to identify IRs
2094 /// that are defined by the same source line, but
2095 /// different basic blocks.
2096 /// Duplication factor: assigned by optimizations that will scale down
2097 /// the execution frequency of the original IR.
2098 /// Copy Identifier: assigned by optimizations that clones the IR.
2099 /// Each copy of the IR will be assigned an identifier.
2100 ///
2101 /// Encoding:
2102 ///
2103 /// The above 3 components are encoded into a 32bit unsigned integer in
2104 /// order. If the lowest bit is 1, the current component is empty, and the
2105 /// next component will start in the next bit. Otherwise, the current
2106 /// component is non-empty, and its content starts in the next bit. The
2107 /// value of each components is either 5 bit or 12 bit: if the 7th bit
2108 /// is 0, the bit 2~6 (5 bits) are used to represent the component; if the
2109 /// 7th bit is 1, the bit 2~6 (5 bits) and 8~14 (7 bits) are combined to
2110 /// represent the component. Thus, the number of bits used for a component
2111 /// is either 0 (if it and all the next components are empty); 1 - if it is
2112 /// empty; 7 - if its value is up to and including 0x1f (lsb and msb are both
2113 /// 0); or 14, if its value is up to and including 0x1ff. Note that the last
2114 /// component is also capped at 0x1ff, even in the case when both first
2115 /// components are 0, and we'd technically have 29 bits available.
2116 ///
2117 /// For precise control over the data being encoded in the discriminator,
2118 /// use encodeDiscriminator/decodeDiscriminator.
2119
2120 inline unsigned getDiscriminator() const;
2121
2122 // For the regular discriminator, it stands for all empty components if all
2123 // the lowest 3 bits are non-zero and all higher 29 bits are unused(zero by
2124 // default). Here we fully leverage the higher 29 bits for pseudo probe use.
2125 // This is the format:
2126 // [2:0] - 0x7
2127 // [31:3] - pseudo probe fields guaranteed to be non-zero as a whole
2128 // So if the lower 3 bits is non-zero and the others has at least one
2129 // non-zero bit, it guarantees to be a pseudo probe discriminator
2130 inline static bool isPseudoProbeDiscriminator(unsigned Discriminator) {
2131 return ((Discriminator & 0x7) == 0x7) && (Discriminator & 0xFFFFFFF8);
2132 }
2133
2134 /// Returns a new DILocation with updated \p Discriminator.
2135 inline const DILocation *cloneWithDiscriminator(unsigned Discriminator) const;
2136
2137 /// Returns a new DILocation with updated base discriminator \p BD. Only the
2138 /// base discriminator is set in the new DILocation, the other encoded values
2139 /// are elided.
2140 /// If the discriminator cannot be encoded, the function returns std::nullopt.
2141 inline std::optional<const DILocation *>
2142 cloneWithBaseDiscriminator(unsigned BD) const;
2143
2144 /// Returns the duplication factor stored in the discriminator, or 1 if no
2145 /// duplication factor (or 0) is encoded.
2146 inline unsigned getDuplicationFactor() const;
2147
2148 /// Returns the copy identifier stored in the discriminator.
2149 inline unsigned getCopyIdentifier() const;
2150
2151 /// Returns the base discriminator stored in the discriminator.
2152 inline unsigned getBaseDiscriminator() const;
2153
2154 /// Returns a new DILocation with duplication factor \p DF * current
2155 /// duplication factor encoded in the discriminator. The current duplication
2156 /// factor is as defined by getDuplicationFactor().
2157 /// Returns std::nullopt if encoding failed.
2158 inline std::optional<const DILocation *>
2160
2161 /// When two instructions are combined into a single instruction we also
2162 /// need to combine the original locations into a single location.
2163 /// When the locations are the same we can use either location.
2164 /// When they differ, we need a third location which is distinct from either.
2165 /// If they share a common scope, use this scope and compare the line/column
2166 /// pair of the locations with the common scope:
2167 /// * if both match, keep the line and column;
2168 /// * if only the line number matches, keep the line and set the column as 0;
2169 /// * otherwise set line and column as 0.
2170 /// If they do not share a common scope the location is ambiguous and can't be
2171 /// represented in a line entry. In this case, set line and column as 0 and
2172 /// use the scope of any location.
2173 ///
2174 /// \p LocA \p LocB: The locations to be merged.
2175 static DILocation *getMergedLocation(DILocation *LocA, DILocation *LocB);
2176
2177 /// Try to combine the vector of locations passed as input in a single one.
2178 /// This function applies getMergedLocation() repeatedly left-to-right.
2179 ///
2180 /// \p Locs: The locations to be merged.
2182
2183 /// Return the masked discriminator value for an input discrimnator value D
2184 /// (i.e. zero out the (B+1)-th and above bits for D (B is 0-base).
2185 // Example: an input of (0x1FF, 7) returns 0xFF.
2186 static unsigned getMaskedDiscriminator(unsigned D, unsigned B) {
2187 return (D & getN1Bits(B));
2188 }
2189
2190 /// Return the bits used for base discriminators.
2191 static unsigned getBaseDiscriminatorBits() { return getBaseFSBitEnd(); }
2192
2193 /// Returns the base discriminator for a given encoded discriminator \p D.
2194 static unsigned
2196 bool IsFSDiscriminator = false) {
2197 // Extract the dwarf base discriminator if it's encoded in the pseudo probe
2198 // discriminator.
2200 auto DwarfBaseDiscriminator =
2202 if (DwarfBaseDiscriminator)
2203 return *DwarfBaseDiscriminator;
2204 // Return the probe id instead of zero for a pseudo probe discriminator.
2205 // This should help differenciate callsites with same line numbers to
2206 // achieve a decent AutoFDO profile under -fpseudo-probe-for-profiling,
2207 // where the original callsite dwarf discriminator is overwritten by
2208 // callsite probe information.
2210 }
2211
2212 if (IsFSDiscriminator)
2215 }
2216
2217 /// Raw encoding of the discriminator. APIs such as cloneWithDuplicationFactor
2218 /// have certain special case behavior (e.g. treating empty duplication factor
2219 /// as the value '1').
2220 /// This API, in conjunction with cloneWithDiscriminator, may be used to
2221 /// encode the raw values provided.
2222 ///
2223 /// \p BD: base discriminator
2224 /// \p DF: duplication factor
2225 /// \p CI: copy index
2226 ///
2227 /// The return is std::nullopt if the values cannot be encoded in 32 bits -
2228 /// for example, values for BD or DF larger than 12 bits. Otherwise, the
2229 /// return is the encoded value.
2230 static std::optional<unsigned> encodeDiscriminator(unsigned BD, unsigned DF,
2231 unsigned CI);
2232
2233 /// Raw decoder for values in an encoded discriminator D.
2234 static void decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF,
2235 unsigned &CI);
2236
2237 /// Returns the duplication factor for a given encoded discriminator \p D, or
2238 /// 1 if no value or 0 is encoded.
2239 static unsigned getDuplicationFactorFromDiscriminator(unsigned D) {
2241 return 1;
2243 unsigned Ret = getUnsignedFromPrefixEncoding(D);
2244 if (Ret == 0)
2245 return 1;
2246 return Ret;
2247 }
2248
2249 /// Returns the copy identifier for a given encoded discriminator \p D.
2250 static unsigned getCopyIdentifierFromDiscriminator(unsigned D) {
2253 }
2254
2255 Metadata *getRawScope() const { return getOperand(0); }
2257 if (getNumOperands() == 2)
2258 return getOperand(1);
2259 return nullptr;
2260 }
2261
2262 static bool classof(const Metadata *MD) {
2263 return MD->getMetadataID() == DILocationKind;
2264 }
2265};
2266
2268protected:
2272
2273public:
2274 DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
2275
2276 Metadata *getRawScope() const { return getOperand(1); }
2277
2278 void replaceScope(DIScope *Scope) {
2279 assert(!isUniqued());
2280 setOperand(1, Scope);
2281 }
2282
2283 static bool classof(const Metadata *MD) {
2284 return MD->getMetadataID() == DILexicalBlockKind ||
2285 MD->getMetadataID() == DILexicalBlockFileKind;
2286 }
2287};
2288
2289/// Debug lexical block.
2290///
2291/// Uses the SubclassData32 Metadata slot.
2293 friend class LLVMContextImpl;
2294 friend class MDNode;
2295
2296 uint16_t Column;
2297
2299 unsigned Column, ArrayRef<Metadata *> Ops)
2300 : DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops),
2301 Column(Column) {
2303 assert(Column < (1u << 16) && "Expected 16-bit column");
2304 }
2305 ~DILexicalBlock() = default;
2306
2307 static DILexicalBlock *getImpl(LLVMContext &Context, DILocalScope *Scope,
2308 DIFile *File, unsigned Line, unsigned Column,
2310 bool ShouldCreate = true) {
2311 return getImpl(Context, static_cast<Metadata *>(Scope),
2312 static_cast<Metadata *>(File), Line, Column, Storage,
2313 ShouldCreate);
2314 }
2315
2316 static DILexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
2317 Metadata *File, unsigned Line, unsigned Column,
2318 StorageType Storage, bool ShouldCreate = true);
2319
2320 TempDILexicalBlock cloneImpl() const {
2322 getColumn());
2323 }
2324
2325public:
2327 (DILocalScope * Scope, DIFile *File, unsigned Line,
2328 unsigned Column),
2329 (Scope, File, Line, Column))
2332 unsigned Column),
2333 (Scope, File, Line, Column))
2334
2335 TempDILexicalBlock clone() const { return cloneImpl(); }
2336
2337 unsigned getLine() const { return SubclassData32; }
2338 unsigned getColumn() const { return Column; }
2339
2340 static bool classof(const Metadata *MD) {
2341 return MD->getMetadataID() == DILexicalBlockKind;
2342 }
2343};
2344
2346 friend class LLVMContextImpl;
2347 friend class MDNode;
2348
2350 unsigned Discriminator, ArrayRef<Metadata *> Ops)
2351 : DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops) {
2353 }
2354 ~DILexicalBlockFile() = default;
2355
2356 static DILexicalBlockFile *getImpl(LLVMContext &Context, DILocalScope *Scope,
2357 DIFile *File, unsigned Discriminator,
2359 bool ShouldCreate = true) {
2360 return getImpl(Context, static_cast<Metadata *>(Scope),
2361 static_cast<Metadata *>(File), Discriminator, Storage,
2362 ShouldCreate);
2363 }
2364
2365 static DILexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
2366 Metadata *File, unsigned Discriminator,
2368 bool ShouldCreate = true);
2369
2370 TempDILexicalBlockFile cloneImpl() const {
2371 return getTemporary(getContext(), getScope(), getFile(),
2373 }
2374
2375public:
2378 unsigned Discriminator),
2383
2384 TempDILexicalBlockFile clone() const { return cloneImpl(); }
2385 unsigned getDiscriminator() const { return SubclassData32; }
2386
2387 static bool classof(const Metadata *MD) {
2388 return MD->getMetadataID() == DILexicalBlockFileKind;
2389 }
2390};
2391
2392unsigned DILocation::getDiscriminator() const {
2393 if (auto *F = dyn_cast<DILexicalBlockFile>(getScope()))
2394 return F->getDiscriminator();
2395 return 0;
2396}
2397
2398const DILocation *
2399DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
2400 DIScope *Scope = getScope();
2401 // Skip all parent DILexicalBlockFile that already have a discriminator
2402 // assigned. We do not want to have nested DILexicalBlockFiles that have
2403 // multiple discriminators because only the leaf DILexicalBlockFile's
2404 // dominator will be used.
2405 for (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope);
2406 LBF && LBF->getDiscriminator() != 0;
2407 LBF = dyn_cast<DILexicalBlockFile>(Scope))
2408 Scope = LBF->getScope();
2409 DILexicalBlockFile *NewScope =
2410 DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator);
2411 return DILocation::get(getContext(), getLine(), getColumn(), NewScope,
2412 getInlinedAt());
2413}
2414
2416 return getBaseDiscriminatorFromDiscriminator(getDiscriminator(),
2418}
2419
2421 return getDuplicationFactorFromDiscriminator(getDiscriminator());
2422}
2423
2425 return getCopyIdentifierFromDiscriminator(getDiscriminator());
2426}
2427
2428std::optional<const DILocation *>
2430 unsigned BD, DF, CI;
2431
2433 BD = getBaseDiscriminator();
2434 if (D == BD)
2435 return this;
2436 return cloneWithDiscriminator(D);
2437 }
2438
2439 decodeDiscriminator(getDiscriminator(), BD, DF, CI);
2440 if (D == BD)
2441 return this;
2442 if (std::optional<unsigned> Encoded = encodeDiscriminator(D, DF, CI))
2443 return cloneWithDiscriminator(*Encoded);
2444 return std::nullopt;
2445}
2446
2447std::optional<const DILocation *>
2449 assert(!EnableFSDiscriminator && "FSDiscriminator should not call this.");
2450 // Do no interfere with pseudo probes. Pseudo probe doesn't need duplication
2451 // factor support as samples collected on cloned probes will be aggregated.
2452 // Also pseudo probe at a callsite uses the dwarf discriminator to store
2453 // pseudo probe related information, such as the probe id.
2454 if (isPseudoProbeDiscriminator(getDiscriminator()))
2455 return this;
2456
2458 if (DF <= 1)
2459 return this;
2460
2461 unsigned BD = getBaseDiscriminator();
2462 unsigned CI = getCopyIdentifier();
2463 if (std::optional<unsigned> D = encodeDiscriminator(BD, DF, CI))
2464 return cloneWithDiscriminator(*D);
2465 return std::nullopt;
2466}
2467
2468/// Debug lexical block.
2469///
2470/// Uses the SubclassData1 Metadata slot.
2471class DINamespace : public DIScope {
2472 friend class LLVMContextImpl;
2473 friend class MDNode;
2474
2477 ~DINamespace() = default;
2478
2479 static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope,
2481 StorageType Storage, bool ShouldCreate = true) {
2482 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
2483 ExportSymbols, Storage, ShouldCreate);
2484 }
2485 static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope,
2487 StorageType Storage, bool ShouldCreate = true);
2488
2489 TempDINamespace cloneImpl() const {
2490 return getTemporary(getContext(), getScope(), getName(),
2492 }
2493
2494public:
2501
2502 TempDINamespace clone() const { return cloneImpl(); }
2503
2504 bool getExportSymbols() const { return SubclassData1; }
2505 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2506 StringRef getName() const { return getStringOperand(2); }
2507
2508 Metadata *getRawScope() const { return getOperand(1); }
2509 MDString *getRawName() const { return getOperandAs<MDString>(2); }
2510
2511 static bool classof(const Metadata *MD) {
2512 return MD->getMetadataID() == DINamespaceKind;
2513 }
2514};
2515
2516/// Represents a module in the programming language, for example, a Clang
2517/// module, or a Fortran module.
2518///
2519/// Uses the SubclassData1 and SubclassData32 Metadata slots.
2520class DIModule : public DIScope {
2521 friend class LLVMContextImpl;
2522 friend class MDNode;
2523
2524 DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo,
2525 bool IsDecl, ArrayRef<Metadata *> Ops);
2526 ~DIModule() = default;
2527
2528 static DIModule *getImpl(LLVMContext &Context, DIFile *File, DIScope *Scope,
2531 unsigned LineNo, bool IsDecl, StorageType Storage,
2532 bool ShouldCreate = true) {
2533 return getImpl(Context, File, Scope, getCanonicalMDString(Context, Name),
2536 getCanonicalMDString(Context, APINotesFile), LineNo, IsDecl,
2537 Storage, ShouldCreate);
2538 }
2539 static DIModule *getImpl(LLVMContext &Context, Metadata *File,
2542 MDString *APINotesFile, unsigned LineNo, bool IsDecl,
2543 StorageType Storage, bool ShouldCreate = true);
2544
2545 TempDIModule cloneImpl() const {
2547 getConfigurationMacros(), getIncludePath(),
2548 getAPINotesFile(), getLineNo(), getIsDecl());
2549 }
2550
2551public:
2555 StringRef APINotesFile, unsigned LineNo,
2556 bool IsDecl = false),
2558 APINotesFile, LineNo, IsDecl))
2563 bool IsDecl = false),
2565 APINotesFile, LineNo, IsDecl))
2566
2567 TempDIModule clone() const { return cloneImpl(); }
2568
2569 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2570 StringRef getName() const { return getStringOperand(2); }
2571 StringRef getConfigurationMacros() const { return getStringOperand(3); }
2572 StringRef getIncludePath() const { return getStringOperand(4); }
2573 StringRef getAPINotesFile() const { return getStringOperand(5); }
2574 unsigned getLineNo() const { return SubclassData32; }
2575 bool getIsDecl() const { return SubclassData1; }
2576
2577 Metadata *getRawScope() const { return getOperand(1); }
2578 MDString *getRawName() const { return getOperandAs<MDString>(2); }
2579 MDString *getRawConfigurationMacros() const {
2580 return getOperandAs<MDString>(3);
2581 }
2582 MDString *getRawIncludePath() const { return getOperandAs<MDString>(4); }
2583 MDString *getRawAPINotesFile() const { return getOperandAs<MDString>(5); }
2584
2585 static bool classof(const Metadata *MD) {
2586 return MD->getMetadataID() == DIModuleKind;
2587 }
2588};
2589
2590/// Base class for template parameters.
2591///
2592/// Uses the SubclassData1 Metadata slot.
2594protected:
2596 unsigned Tag, bool IsDefault, ArrayRef<Metadata *> Ops)
2597 : DINode(Context, ID, Storage, Tag, Ops) {
2598 SubclassData1 = IsDefault;
2599 }
2601
2602public:
2603 StringRef getName() const { return getStringOperand(0); }
2604 DIType *getType() const { return cast_or_null<DIType>(getRawType()); }
2605
2606 MDString *getRawName() const { return getOperandAs<MDString>(0); }
2607 Metadata *getRawType() const { return getOperand(1); }
2608 bool isDefault() const { return SubclassData1; }
2609
2610 static bool classof(const Metadata *MD) {
2611 return MD->getMetadataID() == DITemplateTypeParameterKind ||
2612 MD->getMetadataID() == DITemplateValueParameterKind;
2613 }
2614};
2615
2617 friend class LLVMContextImpl;
2618 friend class MDNode;
2619
2622 ~DITemplateTypeParameter() = default;
2623
2624 static DITemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
2625 DIType *Type, bool IsDefault,
2627 bool ShouldCreate = true) {
2628 return getImpl(Context, getCanonicalMDString(Context, Name), Type,
2629 IsDefault, Storage, ShouldCreate);
2630 }
2631 static DITemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
2632 Metadata *Type, bool IsDefault,
2634 bool ShouldCreate = true);
2635
2636 TempDITemplateTypeParameter cloneImpl() const {
2637 return getTemporary(getContext(), getName(), getType(), isDefault());
2638 }
2639
2640public:
2643 (Name, Type, IsDefault))
2647
2648 TempDITemplateTypeParameter clone() const { return cloneImpl(); }
2649
2650 static bool classof(const Metadata *MD) {
2651 return MD->getMetadataID() == DITemplateTypeParameterKind;
2652 }
2653};
2654
2656 friend class LLVMContextImpl;
2657 friend class MDNode;
2658
2660 unsigned Tag, bool IsDefault,
2662 : DITemplateParameter(Context, DITemplateValueParameterKind, Storage, Tag,
2663 IsDefault, Ops) {}
2664 ~DITemplateValueParameter() = default;
2665
2666 static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
2668 bool IsDefault, Metadata *Value,
2670 bool ShouldCreate = true) {
2671 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
2672 IsDefault, Value, Storage, ShouldCreate);
2673 }
2674 static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
2675 MDString *Name, Metadata *Type,
2676 bool IsDefault, Metadata *Value,
2678 bool ShouldCreate = true);
2679
2680 TempDITemplateValueParameter cloneImpl() const {
2681 return getTemporary(getContext(), getTag(), getName(), getType(),
2682 isDefault(), getValue());
2683 }
2684
2685public:
2687 (unsigned Tag, StringRef Name, DIType *Type, bool IsDefault,
2688 Metadata *Value),
2689 (Tag, Name, Type, IsDefault, Value))
2694
2695 TempDITemplateValueParameter clone() const { return cloneImpl(); }
2696
2697 Metadata *getValue() const { return getOperand(2); }
2698
2699 static bool classof(const Metadata *MD) {
2700 return MD->getMetadataID() == DITemplateValueParameterKind;
2701 }
2702};
2703
2704/// Base class for variables.
2705///
2706/// Uses the SubclassData32 Metadata slot.
2707class DIVariable : public DINode {
2708 unsigned Line;
2709
2710protected:
2711 DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, signed Line,
2712 ArrayRef<Metadata *> Ops, uint32_t AlignInBits = 0);
2713 ~DIVariable() = default;
2714
2715public:
2716 unsigned getLine() const { return Line; }
2717 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2718 StringRef getName() const { return getStringOperand(1); }
2719 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
2720 DIType *getType() const { return cast_or_null<DIType>(getRawType()); }
2722 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
2723 /// Determines the size of the variable's type.
2724 std::optional<uint64_t> getSizeInBits() const;
2725
2726 /// Return the signedness of this variable's type, or std::nullopt if this
2727 /// type is neither signed nor unsigned.
2728 std::optional<DIBasicType::Signedness> getSignedness() const {
2729 if (auto *BT = dyn_cast<DIBasicType>(getType()))
2730 return BT->getSignedness();
2731 return std::nullopt;
2732 }
2733
2735 if (auto *F = getFile())
2736 return F->getFilename();
2737 return "";
2738 }
2739
2741 if (auto *F = getFile())
2742 return F->getDirectory();
2743 return "";
2744 }
2745
2746 std::optional<StringRef> getSource() const {
2747 if (auto *F = getFile())
2748 return F->getSource();
2749 return std::nullopt;
2750 }
2751
2752 Metadata *getRawScope() const { return getOperand(0); }
2753 MDString *getRawName() const { return getOperandAs<MDString>(1); }
2754 Metadata *getRawFile() const { return getOperand(2); }
2755 Metadata *getRawType() const { return getOperand(3); }
2756
2757 static bool classof(const Metadata *MD) {
2758 return MD->getMetadataID() == DILocalVariableKind ||
2759 MD->getMetadataID() == DIGlobalVariableKind;
2760 }
2761};
2762
2763/// DWARF expression.
2764///
2765/// This is (almost) a DWARF expression that modifies the location of a
2766/// variable, or the location of a single piece of a variable, or (when using
2767/// DW_OP_stack_value) is the constant variable value.
2768///
2769/// TODO: Co-allocate the expression elements.
2770/// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
2771/// storage types.
2772class DIExpression : public MDNode {
2773 friend class LLVMContextImpl;
2774 friend class MDNode;
2775
2776 std::vector<uint64_t> Elements;
2777
2779 : MDNode(C, DIExpressionKind, Storage, {}),
2780 Elements(Elements.begin(), Elements.end()) {}
2781 ~DIExpression() = default;
2782
2783 static DIExpression *getImpl(LLVMContext &Context,
2784 ArrayRef<uint64_t> Elements, StorageType Storage,
2785 bool ShouldCreate = true);
2786
2787 TempDIExpression cloneImpl() const {
2788 return getTemporary(getContext(), getElements());
2789 }
2790
2791public:
2793
2794 TempDIExpression clone() const { return cloneImpl(); }
2795
2796 ArrayRef<uint64_t> getElements() const { return Elements; }
2797
2798 unsigned getNumElements() const { return Elements.size(); }
2799
2800 uint64_t getElement(unsigned I) const {
2801 assert(I < Elements.size() && "Index out of range");
2802 return Elements[I];
2803 }
2804
2806 /// Determine whether this represents a constant value, if so
2807 // return it's sign information.
2808 std::optional<SignedOrUnsignedConstant> isConstant() const;
2809
2810 /// Return the number of unique location operands referred to (via
2811 /// DW_OP_LLVM_arg) in this expression; this is not necessarily the number of
2812 /// instances of DW_OP_LLVM_arg within the expression.
2813 /// For example, for the expression:
2814 /// (DW_OP_LLVM_arg 0, DW_OP_LLVM_arg 1, DW_OP_plus,
2815 /// DW_OP_LLVM_arg 0, DW_OP_mul)
2816 /// This function would return 2, as there are two unique location operands
2817 /// (0 and 1).
2819
2821
2824
2825 /// A lightweight wrapper around an expression operand.
2826 ///
2827 /// TODO: Store arguments directly and change \a DIExpression to store a
2828 /// range of these.
2830 const uint64_t *Op = nullptr;
2831
2832 public:
2833 ExprOperand() = default;
2834 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
2835
2836 const uint64_t *get() const { return Op; }
2837
2838 /// Get the operand code.
2839 uint64_t getOp() const { return *Op; }
2840
2841 /// Get an argument to the operand.
2842 ///
2843 /// Never returns the operand itself.
2844 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
2845
2846 unsigned getNumArgs() const { return getSize() - 1; }
2847
2848 /// Return the size of the operand.
2849 ///
2850 /// Return the number of elements in the operand (1 + args).
2851 unsigned getSize() const;
2852
2853 /// Append the elements of this operand to \p V.
2855 V.append(get(), get() + getSize());
2856 }
2857 };
2858
2859 /// An iterator for expression operands.
2862
2863 public:
2864 using iterator_category = std::input_iterator_tag;
2866 using difference_type = std::ptrdiff_t;
2869
2870 expr_op_iterator() = default;
2872
2873 element_iterator getBase() const { return Op.get(); }
2874 const ExprOperand &operator*() const { return Op; }
2875 const ExprOperand *operator->() const { return &Op; }
2876
2878 increment();
2879 return *this;
2880 }
2882 expr_op_iterator T(*this);
2883 increment();
2884 return T;
2885 }
2886
2887 /// Get the next iterator.
2888 ///
2889 /// \a std::next() doesn't work because this is technically an
2890 /// input_iterator, but it's a perfectly valid operation. This is an
2891 /// accessor to provide the same functionality.
2892 expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
2893
2894 bool operator==(const expr_op_iterator &X) const {
2895 return getBase() == X.getBase();
2896 }
2897 bool operator!=(const expr_op_iterator &X) const {
2898 return getBase() != X.getBase();
2899 }
2900
2901 private:
2902 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
2903 };
2904
2905 /// Visit the elements via ExprOperand wrappers.
2906 ///
2907 /// These range iterators visit elements through \a ExprOperand wrappers.
2908 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
2909 /// true.
2910 ///
2911 /// \pre \a isValid() gives \c true.
2912 /// @{
2915 }
2918 }
2920 return {expr_op_begin(), expr_op_end()};
2921 }
2922 /// @}
2923
2924 bool isValid() const;
2925
2926 static bool classof(const Metadata *MD) {
2927 return MD->getMetadataID() == DIExpressionKind;
2928 }
2929
2930 /// Return whether the first element a DW_OP_deref.
2931 bool startsWithDeref() const;
2932
2933 /// Return whether there is exactly one operator and it is a DW_OP_deref;
2934 bool isDeref() const;
2935
2937
2938 /// Return the number of bits that have an active value, i.e. those that
2939 /// aren't known to be zero/sign (depending on the type of Var) and which
2940 /// are within the size of this fragment (if it is one). If we can't deduce
2941 /// anything from the expression this will return the size of Var.
2942 std::optional<uint64_t> getActiveBits(DIVariable *Var);
2943
2944 /// Retrieve the details of this fragment expression.
2945 static std::optional<FragmentInfo> getFragmentInfo(expr_op_iterator Start,
2947
2948 /// Retrieve the details of this fragment expression.
2949 std::optional<FragmentInfo> getFragmentInfo() const {
2951 }
2952
2953 /// Return whether this is a piece of an aggregate variable.
2954 bool isFragment() const { return getFragmentInfo().has_value(); }
2955
2956 /// Return whether this is an implicit location description.
2957 bool isImplicit() const;
2958
2959 /// Return whether the location is computed on the expression stack, meaning
2960 /// it cannot be a simple register location.
2961 bool isComplex() const;
2962
2963 /// Return whether the evaluated expression makes use of a single location at
2964 /// the start of the expression, i.e. if it contains only a single
2965 /// DW_OP_LLVM_arg op as its first operand, or if it contains none.
2966 bool isSingleLocationExpression() const;
2967
2968 /// Returns a reference to the elements contained in this expression, skipping
2969 /// past the leading `DW_OP_LLVM_arg, 0` if one is present.
2970 /// Similar to `convertToNonVariadicExpression`, but faster and cheaper - it
2971 /// does not check whether the expression is a single-location expression, and
2972 /// it returns elements rather than creating a new DIExpression.
2973 std::optional<ArrayRef<uint64_t>> getSingleLocationExpressionElements() const;
2974
2975 /// Removes all elements from \p Expr that do not apply to an undef debug
2976 /// value, which includes every operator that computes the value/location on
2977 /// the DWARF stack, including any DW_OP_LLVM_arg elements (making the result
2978 /// of this function always a single-location expression) while leaving
2979 /// everything that defines what the computed value applies to, i.e. the
2980 /// fragment information.
2981 static const DIExpression *convertToUndefExpression(const DIExpression *Expr);
2982
2983 /// If \p Expr is a non-variadic expression (i.e. one that does not contain
2984 /// DW_OP_LLVM_arg), returns \p Expr converted to variadic form by adding a
2985 /// leading [DW_OP_LLVM_arg, 0] to the expression; otherwise returns \p Expr.
2986 static const DIExpression *
2988
2989 /// If \p Expr is a valid single-location expression, i.e. it refers to only a
2990 /// single debug operand at the start of the expression, then return that
2991 /// expression in a non-variadic form by removing DW_OP_LLVM_arg from the
2992 /// expression if it is present; otherwise returns std::nullopt.
2993 /// See also `getSingleLocationExpressionElements` above, which skips
2994 /// checking `isSingleLocationExpression` and returns a list of elements
2995 /// rather than a DIExpression.
2996 static std::optional<const DIExpression *>
2998
2999 /// Inserts the elements of \p Expr into \p Ops modified to a canonical form,
3000 /// which uses DW_OP_LLVM_arg (i.e. is a variadic expression) and folds the
3001 /// implied derefence from the \p IsIndirect flag into the expression. This
3002 /// allows us to check equivalence between expressions with differing
3003 /// directness or variadicness.
3005 const DIExpression *Expr,
3006 bool IsIndirect);
3007
3008 /// Determines whether two debug values should produce equivalent DWARF
3009 /// expressions, using their DIExpressions and directness, ignoring the
3010 /// differences between otherwise identical expressions in variadic and
3011 /// non-variadic form and not considering the debug operands.
3012 /// \p FirstExpr is the DIExpression for the first debug value.
3013 /// \p FirstIndirect should be true if the first debug value is indirect; in
3014 /// IR this should be true for dbg.declare intrinsics and false for
3015 /// dbg.values, and in MIR this should be true only for DBG_VALUE instructions
3016 /// whose second operand is an immediate value.
3017 /// \p SecondExpr and \p SecondIndirect have the same meaning as the prior
3018 /// arguments, but apply to the second debug value.
3019 static bool isEqualExpression(const DIExpression *FirstExpr,
3020 bool FirstIndirect,
3021 const DIExpression *SecondExpr,
3022 bool SecondIndirect);
3023
3024 /// Append \p Ops with operations to apply the \p Offset.
3025 static void appendOffset(SmallVectorImpl<uint64_t> &Ops, int64_t Offset);
3026
3027 /// If this is a constant offset, extract it. If there is no expression,
3028 /// return true with an offset of zero.
3029 bool extractIfOffset(int64_t &Offset) const;
3030
3031 /// Assuming that the expression operates on an address, extract a constant
3032 /// offset and the successive ops. Return false if the expression contains
3033 /// any incompatible ops (including non-zero DW_OP_LLVM_args - only a single
3034 /// address operand to the expression is permitted).
3035 ///
3036 /// We don't try very hard to interpret the expression because we assume that
3037 /// foldConstantMath has canonicalized the expression.
3038 bool extractLeadingOffset(int64_t &OffsetInBytes,
3039 SmallVectorImpl<uint64_t> &RemainingOps) const;
3040
3041 /// Returns true iff this DIExpression contains at least one instance of
3042 /// `DW_OP_LLVM_arg, n` for all n in [0, N).
3043 bool hasAllLocationOps(unsigned N) const;
3044
3045 /// Checks if the last 4 elements of the expression are DW_OP_constu <DWARF
3046 /// Address Space> DW_OP_swap DW_OP_xderef and extracts the <DWARF Address
3047 /// Space>.
3048 static const DIExpression *extractAddressClass(const DIExpression *Expr,
3049 unsigned &AddrClass);
3050
3051 /// Used for DIExpression::prepend.
3054 DerefBefore = 1 << 0,
3055 DerefAfter = 1 << 1,
3056 StackValue = 1 << 2,
3057 EntryValue = 1 << 3
3059
3060 /// Prepend \p DIExpr with a deref and offset operation and optionally turn it
3061 /// into a stack value or/and an entry value.
3062 static DIExpression *prepend(const DIExpression *Expr, uint8_t Flags,
3063 int64_t Offset = 0);
3064
3065 /// Prepend \p DIExpr with the given opcodes and optionally turn it into a
3066 /// stack value.
3067 static DIExpression *prependOpcodes(const DIExpression *Expr,
3069 bool StackValue = false,
3070 bool EntryValue = false);
3071
3072 /// Append the opcodes \p Ops to \p DIExpr. Unlike \ref appendToStack, the
3073 /// returned expression is a stack value only if \p DIExpr is a stack value.
3074 /// If \p DIExpr describes a fragment, the returned expression will describe
3075 /// the same fragment.
3076 static DIExpression *append(const DIExpression *Expr, ArrayRef<uint64_t> Ops);
3077
3078 /// Convert \p DIExpr into a stack value if it isn't one already by appending
3079 /// DW_OP_deref if needed, and appending \p Ops to the resulting expression.
3080 /// If \p DIExpr describes a fragment, the returned expression will describe
3081 /// the same fragment.
3082 static DIExpression *appendToStack(const DIExpression *Expr,
3083 ArrayRef<uint64_t> Ops);
3084
3085 /// Create a copy of \p Expr by appending the given list of \p Ops to each
3086 /// instance of the operand `DW_OP_LLVM_arg, \p ArgNo`. This is used to
3087 /// modify a specific location used by \p Expr, such as when salvaging that
3088 /// location.
3089 static DIExpression *appendOpsToArg(const DIExpression *Expr,
3090 ArrayRef<uint64_t> Ops, unsigned ArgNo,
3091 bool StackValue = false);
3092
3093 /// Create a copy of \p Expr with each instance of
3094 /// `DW_OP_LLVM_arg, \p OldArg` replaced with `DW_OP_LLVM_arg, \p NewArg`,
3095 /// and each instance of `DW_OP_LLVM_arg, Arg` with `DW_OP_LLVM_arg, Arg - 1`
3096 /// for all Arg > \p OldArg.
3097 /// This is used when replacing one of the operands of a debug value list
3098 /// with another operand in the same list and deleting the old operand.
3099 static DIExpression *replaceArg(const DIExpression *Expr, uint64_t OldArg,
3100 uint64_t NewArg);
3101
3102 /// Create a DIExpression to describe one part of an aggregate variable that
3103 /// is fragmented across multiple Values. The DW_OP_LLVM_fragment operation
3104 /// will be appended to the elements of \c Expr. If \c Expr already contains
3105 /// a \c DW_OP_LLVM_fragment \c OffsetInBits is interpreted as an offset
3106 /// into the existing fragment.
3107 ///
3108 /// \param OffsetInBits Offset of the piece in bits.
3109 /// \param SizeInBits Size of the piece in bits.
3110 /// \return Creating a fragment expression may fail if \c Expr
3111 /// contains arithmetic operations that would be
3112 /// truncated.
3113 static std::optional<DIExpression *>
3114 createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits,
3115 unsigned SizeInBits);
3116
3117 /// Determine the relative position of the fragments passed in.
3118 /// Returns -1 if this is entirely before Other, 0 if this and Other overlap,
3119 /// 1 if this is entirely after Other.
3120 static int fragmentCmp(const FragmentInfo &A, const FragmentInfo &B) {
3121 uint64_t l1 = A.OffsetInBits;
3122 uint64_t l2 = B.OffsetInBits;
3123 uint64_t r1 = l1 + A.SizeInBits;
3124 uint64_t r2 = l2 + B.SizeInBits;
3125 if (r1 <= l2)
3126 return -1;
3127 else if (r2 <= l1)
3128 return 1;
3129 else
3130 return 0;
3131 }
3132
3133 /// Computes a fragment, bit-extract operation if needed, and new constant
3134 /// offset to describe a part of a variable covered by some memory.
3135 ///
3136 /// The memory region starts at:
3137 /// \p SliceStart + \p SliceOffsetInBits
3138 /// And is size:
3139 /// \p SliceSizeInBits
3140 ///
3141 /// The location of the existing variable fragment \p VarFrag is:
3142 /// \p DbgPtr + \p DbgPtrOffsetInBits + \p DbgExtractOffsetInBits.
3143 ///
3144 /// It is intended that these arguments are derived from a debug record:
3145 /// - \p DbgPtr is the (single) DIExpression operand.
3146 /// - \p DbgPtrOffsetInBits is the constant offset applied to \p DbgPtr.
3147 /// - \p DbgExtractOffsetInBits is the offset from a
3148 /// DW_OP_LLVM_bit_extract_[sz]ext operation.
3149 ///
3150 /// Results and return value:
3151 /// - Return false if the result can't be calculated for any reason.
3152 /// - \p Result is set to nullopt if the intersect equals \p VarFarg.
3153 /// - \p Result contains a zero-sized fragment if there's no intersect.
3154 /// - \p OffsetFromLocationInBits is set to the difference between the first
3155 /// bit of the variable location and the first bit of the slice. The
3156 /// magnitude of a negative value therefore indicates the number of bits
3157 /// into the variable fragment that the memory region begins.
3158 ///
3159 /// We don't pass in a debug record directly to get the constituent parts
3160 /// and offsets because different debug records store the information in
3161 /// different places (dbg_assign has two DIExpressions - one contains the
3162 /// fragment info for the entire intrinsic).
3163 static bool calculateFragmentIntersect(
3164 const DataLayout &DL, const Value *SliceStart, uint64_t SliceOffsetInBits,
3165 uint64_t SliceSizeInBits, const Value *DbgPtr, int64_t DbgPtrOffsetInBits,
3166 int64_t DbgExtractOffsetInBits, DIExpression::FragmentInfo VarFrag,
3167 std::optional<DIExpression::FragmentInfo> &Result,
3168 int64_t &OffsetFromLocationInBits);
3169
3170 using ExtOps = std::array<uint64_t, 6>;
3171
3172 /// Returns the ops for a zero- or sign-extension in a DIExpression.
3173 static ExtOps getExtOps(unsigned FromSize, unsigned ToSize, bool Signed);
3174
3175 /// Append a zero- or sign-extension to \p Expr. Converts the expression to a
3176 /// stack value if it isn't one already.
3177 static DIExpression *appendExt(const DIExpression *Expr, unsigned FromSize,
3178 unsigned ToSize, bool Signed);
3179
3180 /// Check if fragments overlap between a pair of FragmentInfos.
3181 static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B) {
3182 return fragmentCmp(A, B) == 0;
3183 }
3184
3185 /// Determine the relative position of the fragments described by this
3186 /// DIExpression and \p Other. Calls static fragmentCmp implementation.
3187 int fragmentCmp(const DIExpression *Other) const {
3188 auto Fragment1 = *getFragmentInfo();
3189 auto Fragment2 = *Other->getFragmentInfo();
3190 return fragmentCmp(Fragment1, Fragment2);
3191 }
3192
3193 /// Check if fragments overlap between this DIExpression and \p Other.
3195 if (!isFragment() || !Other->isFragment())
3196 return true;
3197 return fragmentCmp(Other) == 0;
3198 }
3199
3200 /// Check if the expression consists of exactly one entry value operand.
3201 /// (This is the only configuration of entry values that is supported.)
3202 bool isEntryValue() const;
3203
3204 /// Try to shorten an expression with an initial constant operand.
3205 /// Returns a new expression and constant on success, or the original
3206 /// expression and constant on failure.
3207 std::pair<DIExpression *, const ConstantInt *>
3208 constantFold(const ConstantInt *CI);
3209
3210 /// Try to shorten an expression with constant math operations that can be
3211 /// evaluated at compile time. Returns a new expression on success, or the old
3212 /// expression if there is nothing to be reduced.
3214};
3215
3218 return std::tie(A.SizeInBits, A.OffsetInBits) ==
3219 std::tie(B.SizeInBits, B.OffsetInBits);
3220}
3221
3224 return std::tie(A.SizeInBits, A.OffsetInBits) <
3225 std::tie(B.SizeInBits, B.OffsetInBits);
3226}
3227
3228template <> struct DenseMapInfo<DIExpression::FragmentInfo> {
3230 static const uint64_t MaxVal = std::numeric_limits<uint64_t>::max();
3231
3232 static inline FragInfo getEmptyKey() { return {MaxVal, MaxVal}; }
3233
3234 static inline FragInfo getTombstoneKey() { return {MaxVal - 1, MaxVal - 1}; }
3235
3236 static unsigned getHashValue(const FragInfo &Frag) {
3237 return (Frag.SizeInBits & 0xffff) << 16 | (Frag.OffsetInBits & 0xffff);
3238 }
3239
3240 static bool isEqual(const FragInfo &A, const FragInfo &B) { return A == B; }
3241};
3242
3243/// Holds a DIExpression and keeps track of how many operands have been consumed
3244/// so far.
3247
3248public:
3250 if (!Expr) {
3251 assert(Start == End);
3252 return;
3253 }
3254 Start = Expr->expr_op_begin();
3255 End = Expr->expr_op_end();
3256 }
3257
3259 : Start(Expr.begin()), End(Expr.end()) {}
3260
3262
3263 /// Consume one operation.
3264 std::optional<DIExpression::ExprOperand> take() {
3265 if (Start == End)
3266 return std::nullopt;
3267 return *(Start++);
3268 }
3269
3270 /// Consume N operations.
3271 void consume(unsigned N) { std::advance(Start, N); }
3272
3273 /// Return the current operation.
3274 std::optional<DIExpression::ExprOperand> peek() const {
3275 if (Start == End)
3276 return std::nullopt;
3277 return *(Start);
3278 }
3279
3280 /// Return the next operation.
3281 std::optional<DIExpression::ExprOperand> peekNext() const {
3282 if (Start == End)
3283 return std::nullopt;
3284
3285 auto Next = Start.getNext();
3286 if (Next == End)
3287 return std::nullopt;
3288
3289 return *Next;
3290 }
3291
3292 std::optional<DIExpression::ExprOperand> peekNextN(unsigned N) const {
3293 if (Start == End)
3294 return std::nullopt;
3296 for (unsigned I = 0; I < N; I++) {
3297 Nth = Nth.getNext();
3298 if (Nth == End)
3299 return std::nullopt;
3300 }
3301 return *Nth;
3302 }
3303
3305 this->Start = DIExpression::expr_op_iterator(Expr.begin());
3306 this->End = DIExpression::expr_op_iterator(Expr.end());
3307 }
3308
3309 /// Determine whether there are any operations left in this expression.
3310 operator bool() const { return Start != End; }
3311
3312 DIExpression::expr_op_iterator begin() const { return Start; }
3314
3315 /// Retrieve the fragment information, if any.
3316 std::optional<DIExpression::FragmentInfo> getFragmentInfo() const {
3317 return DIExpression::getFragmentInfo(Start, End);
3318 }
3319};
3320
3321/// Global variables.
3322///
3323/// TODO: Remove DisplayName. It's always equal to Name.
3325 friend class LLVMContextImpl;
3326 friend class MDNode;
3327
3328 bool IsLocalToUnit;
3329 bool IsDefinition;
3330
3332 bool IsLocalToUnit, bool IsDefinition, uint32_t AlignInBits,
3334 : DIVariable(C, DIGlobalVariableKind, Storage, Line, Ops, AlignInBits),
3335 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
3336 ~DIGlobalVariable() = default;
3337
3338 static DIGlobalVariable *
3339 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
3341 bool IsLocalToUnit, bool IsDefinition,
3344 bool ShouldCreate = true) {
3345 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
3347 IsLocalToUnit, IsDefinition, StaticDataMemberDeclaration,
3348 cast_or_null<Metadata>(TemplateParams), AlignInBits,
3349 Annotations.get(), Storage, ShouldCreate);
3350 }
3351 static DIGlobalVariable *
3352 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
3353 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
3354 bool IsLocalToUnit, bool IsDefinition,
3357 bool ShouldCreate = true);
3358
3359 TempDIGlobalVariable cloneImpl() const {
3364 getAnnotations());
3365 }
3366
3367public:
3371 unsigned Line, DIType *Type, bool IsLocalToUnit, bool IsDefinition,
3373 uint32_t AlignInBits, DINodeArray Annotations),
3374 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
3379 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
3382 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
3384
3385 TempDIGlobalVariable clone() const { return cloneImpl(); }
3386
3387 bool isLocalToUnit() const { return IsLocalToUnit; }
3388 bool isDefinition() const { return IsDefinition; }
3392 return cast_or_null<DIDerivedType>(getRawStaticDataMemberDeclaration());
3393 }
3394 DINodeArray getAnnotations() const {
3395 return cast_or_null<MDTuple>(getRawAnnotations());
3396 }
3397
3398 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
3401 MDTuple *getTemplateParams() const { return getOperandAs<MDTuple>(7); }
3402 Metadata *getRawAnnotations() const { return getOperand(8); }
3403
3404 static bool classof(const Metadata *MD) {
3405 return MD->getMetadataID() == DIGlobalVariableKind;
3406 }
3407};
3408
3409/// Debug common block.
3410///
3411/// Uses the SubclassData32 Metadata slot.
3412class DICommonBlock : public DIScope {
3413 friend class LLVMContextImpl;
3414 friend class MDNode;
3415
3418
3419 static DICommonBlock *getImpl(LLVMContext &Context, DIScope *Scope,
3421 DIFile *File, unsigned LineNo,
3422 StorageType Storage, bool ShouldCreate = true) {
3423 return getImpl(Context, Scope, Decl, getCanonicalMDString(Context, Name),
3424 File, LineNo, Storage, ShouldCreate);
3425 }
3426 static DICommonBlock *getImpl(LLVMContext &Context, Metadata *Scope,
3428 unsigned LineNo, StorageType Storage,
3429 bool ShouldCreate = true);
3430
3431 TempDICommonBlock cloneImpl() const {
3433 getFile(), getLineNo());
3434 }
3435
3436public:
3439 DIFile *File, unsigned LineNo),
3440 (Scope, Decl, Name, File, LineNo))
3443 Metadata *File, unsigned LineNo),
3445
3446 TempDICommonBlock clone() const { return cloneImpl(); }
3447
3448 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
3450 return cast_or_null<DIGlobalVariable>(getRawDecl());
3451 }
3452 StringRef getName() const { return getStringOperand(2); }
3453 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
3454 unsigned getLineNo() const { return SubclassData32; }
3455
3456 Metadata *getRawScope() const { return getOperand(0); }
3457 Metadata *getRawDecl() const { return getOperand(1); }
3458 MDString *getRawName() const { return getOperandAs<MDString>(2); }
3459 Metadata *getRawFile() const { return getOperand(3); }
3460
3461 static bool classof(const Metadata *MD) {
3462 return MD->getMetadataID() == DICommonBlockKind;
3463 }
3464};
3465
3466/// Local variable.
3467///
3468/// TODO: Split up flags.
3470 friend class LLVMContextImpl;
3471 friend class MDNode;
3472
3473 unsigned Arg : 16;
3474 DIFlags Flags;
3475
3477 unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
3479 : DIVariable(C, DILocalVariableKind, Storage, Line, Ops, AlignInBits),
3480 Arg(Arg), Flags(Flags) {
3481 assert(Arg < (1 << 16) && "DILocalVariable: Arg out of range");
3482 }
3483 ~DILocalVariable() = default;
3484
3485 static DILocalVariable *getImpl(LLVMContext &Context, DIScope *Scope,
3486 StringRef Name, DIFile *File, unsigned Line,
3487 DIType *Type, unsigned Arg, DIFlags Flags,
3488 uint32_t AlignInBits, DINodeArray Annotations,
3490 bool ShouldCreate = true) {
3491 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
3492 Line, Type, Arg, Flags, AlignInBits, Annotations.get(),
3493 Storage, ShouldCreate);
3494 }
3495 static DILocalVariable *getImpl(LLVMContext &Context, Metadata *Scope,
3496 MDString *Name, Metadata *File, unsigned Line,
3497 Metadata *Type, unsigned Arg, DIFlags Flags,
3500 bool ShouldCreate = true);
3501
3502 TempDILocalVariable cloneImpl() const {
3504 getLine(), getType(), getArg(), getFlags(),
3506 }
3507
3508public:
3511 unsigned Line, DIType *Type, unsigned Arg, DIFlags Flags,
3512 uint32_t AlignInBits, DINodeArray Annotations),
3513 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits,
3514 Annotations))
3517 unsigned Line, Metadata *Type, unsigned Arg, DIFlags Flags,
3519 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits,
3520 Annotations))
3521
3522 TempDILocalVariable clone() const { return cloneImpl(); }
3523
3524 /// Get the local scope for this variable.
3525 ///
3526 /// Variables must be defined in a local scope.
3528 return cast<DILocalScope>(DIVariable::getScope());
3529 }
3530
3531 bool isParameter() const { return Arg; }
3532 unsigned getArg() const { return Arg; }
3533 DIFlags getFlags() const { return Flags; }
3534
3535 DINodeArray getAnnotations() const {
3536 return cast_or_null<MDTuple>(getRawAnnotations());
3537 }
3538 Metadata *getRawAnnotations() const { return getOperand(4); }
3539
3540 bool isArtificial() const { return getFlags() & FlagArtificial; }
3541 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
3542
3543 /// Check that a location is valid for this variable.
3544 ///
3545 /// Check that \c DL exists, is in the same subprogram, and has the same
3546 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
3547 /// to a \a DbgInfoIntrinsic.)
3549 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
3550 }
3551
3552 static bool classof(const Metadata *MD) {
3553 return MD->getMetadataID() == DILocalVariableKind;
3554 }
3555};
3556
3557/// Label.
3558///
3559/// Uses the SubclassData32 Metadata slot.
3560class DILabel : public DINode {
3561 friend class LLVMContextImpl;
3562 friend class MDNode;
3563
3566 ~DILabel() = default;
3567
3568 static DILabel *getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
3569 DIFile *File, unsigned Line, StorageType Storage,
3570 bool ShouldCreate = true) {
3571 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
3572 Line, Storage, ShouldCreate);
3573 }
3574 static DILabel *getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
3575 Metadata *File, unsigned Line, StorageType Storage,
3576 bool ShouldCreate = true);
3577
3578 TempDILabel cloneImpl() const {
3580 getLine());
3581 }
3582
3583public:
3586 unsigned Line),
3587 (Scope, Name, File, Line))
3590 unsigned Line),
3592
3593 TempDILabel clone() const { return cloneImpl(); }
3594
3595 /// Get the local scope for this label.
3596 ///
3597 /// Labels must be defined in a local scope.
3599 return cast_or_null<DILocalScope>(getRawScope());
3600 }
3601 unsigned getLine() const { return SubclassData32; }
3602 StringRef getName() const { return getStringOperand(1); }
3603 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
3604
3605 Metadata *getRawScope() const { return getOperand(0); }
3606 MDString *getRawName() const { return getOperandAs<MDString>(1); }
3607 Metadata *getRawFile() const { return getOperand(2); }
3608
3609 /// Check that a location is valid for this label.
3610 ///
3611 /// Check that \c DL exists, is in the same subprogram, and has the same
3612 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
3613 /// to a \a DbgInfoIntrinsic.)
3615 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
3616 }
3617
3618 static bool classof(const Metadata *MD) {
3619 return MD->getMetadataID() == DILabelKind;
3620 }
3621};
3622
3623class DIObjCProperty : public DINode {
3624 friend class LLVMContextImpl;
3625 friend class MDNode;
3626
3627 unsigned Line;
3628 unsigned Attributes;
3629
3631 unsigned Attributes, ArrayRef<Metadata *> Ops);
3632 ~DIObjCProperty() = default;
3633
3634 static DIObjCProperty *
3635 getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
3636 StringRef GetterName, StringRef SetterName, unsigned Attributes,
3637 DIType *Type, StorageType Storage, bool ShouldCreate = true) {
3638 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
3640 getCanonicalMDString(Context, SetterName), Attributes, Type,
3641 Storage, ShouldCreate);
3642 }
3643 static DIObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
3644 Metadata *File, unsigned Line,
3646 unsigned Attributes, Metadata *Type,
3647 StorageType Storage, bool ShouldCreate = true);
3648
3649 TempDIObjCProperty cloneImpl() const {
3650 return getTemporary(getContext(), getName(), getFile(), getLine(),
3652 getType());
3653 }
3654
3655public:
3657 (StringRef Name, DIFile *File, unsigned Line,
3659 unsigned Attributes, DIType *Type),
3660 (Name, File, Line, GetterName, SetterName, Attributes,
3661 Type))
3663 (MDString * Name, Metadata *File, unsigned Line,
3665 unsigned Attributes, Metadata *Type),
3666 (Name, File, Line, GetterName, SetterName, Attributes,
3667 Type))
3668
3669 TempDIObjCProperty clone() const { return cloneImpl(); }
3670
3671 unsigned getLine() const { return Line; }
3672 unsigned getAttributes() const { return Attributes; }
3673 StringRef getName() const { return getStringOperand(0); }
3674 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
3677 DIType *getType() const { return cast_or_null<DIType>(getRawType()); }
3678
3680 if (auto *F = getFile())
3681 return F->getFilename();
3682 return "";
3683 }
3684
3686 if (auto *F = getFile())
3687 return F->getDirectory();
3688 return "";
3689 }
3690
3691 MDString *getRawName() const { return getOperandAs<MDString>(0); }
3692 Metadata *getRawFile() const { return getOperand(1); }
3693 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
3694 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
3695 Metadata *getRawType() const { return getOperand(4); }
3696
3697 static bool classof(const Metadata *MD) {
3698 return MD->getMetadataID() == DIObjCPropertyKind;
3699 }
3700};
3701
3702/// An imported module (C++ using directive or similar).
3703///
3704/// Uses the SubclassData32 Metadata slot.
3705class DIImportedEntity : public DINode {
3706 friend class LLVMContextImpl;
3707 friend class MDNode;
3708
3710 unsigned Line, ArrayRef<Metadata *> Ops)
3711 : DINode(C, DIImportedEntityKind, Storage, Tag, Ops) {
3713 }
3714 ~DIImportedEntity() = default;
3715
3716 static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
3718 unsigned Line, StringRef Name,
3719 DINodeArray Elements, StorageType Storage,
3720 bool ShouldCreate = true) {
3721 return getImpl(Context, Tag, Scope, Entity, File, Line,
3722 getCanonicalMDString(Context, Name), Elements.get(), Storage,
3723 ShouldCreate);
3724 }
3725 static DIImportedEntity *
3726 getImpl(LLVMContext &Context, unsigned Tag, Metadata *Scope, Metadata *Entity,
3727 Metadata *File, unsigned Line, MDString *Name, Metadata *Elements,
3728 StorageType Storage, bool ShouldCreate = true);
3729
3730 TempDIImportedEntity cloneImpl() const {
3731 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
3732 getFile(), getLine(), getName(), getElements());
3733 }
3734
3735public:
3737 (unsigned Tag, DIScope *Scope, DINode *Entity, DIFile *File,
3738 unsigned Line, StringRef Name = "",
3739 DINodeArray Elements = nullptr),
3740 (Tag, Scope, Entity, File, Line, Name, Elements))
3744 Metadata *Elements = nullptr),
3745 (Tag, Scope, Entity, File, Line, Name, Elements))
3746
3747 TempDIImportedEntity clone() const { return cloneImpl(); }
3748
3749 unsigned getLine() const { return SubclassData32; }
3750 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
3751 DINode *getEntity() const { return cast_or_null<DINode>(getRawEntity()); }
3752 StringRef getName() const { return getStringOperand(2); }
3753 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
3754 DINodeArray getElements() const {
3755 return cast_or_null<MDTuple>(getRawElements());
3756 }
3757
3758 Metadata *getRawScope() const { return getOperand(0); }
3759 Metadata *getRawEntity() const { return getOperand(1); }
3760 MDString *getRawName() const { return getOperandAs<MDString>(2); }
3761 Metadata *getRawFile() const { return getOperand(3); }
3762 Metadata *getRawElements() const { return getOperand(4); }
3763
3764 static bool classof(const Metadata *MD) {
3765 return MD->getMetadataID() == DIImportedEntityKind;
3766 }
3767};
3768
3769/// A pair of DIGlobalVariable and DIExpression.
3771 friend class LLVMContextImpl;
3772 friend class MDNode;
3773
3776 : MDNode(C, DIGlobalVariableExpressionKind, Storage, Ops) {}
3777 ~DIGlobalVariableExpression() = default;
3778
3780 getImpl(LLVMContext &Context, Metadata *Variable, Metadata *Expression,
3781 StorageType Storage, bool ShouldCreate = true);
3782
3783 TempDIGlobalVariableExpression cloneImpl() const {
3785 }
3786
3787public:
3789 (Metadata * Variable, Metadata *Expression),
3790 (Variable, Expression))
3791
3792 TempDIGlobalVariableExpression clone() const { return cloneImpl(); }
3793
3794 Metadata *getRawVariable() const { return getOperand(0); }
3795
3797 return cast_or_null<DIGlobalVariable>(getRawVariable());
3798 }
3799
3800 Metadata *getRawExpression() const { return getOperand(1); }
3801
3803 return cast<DIExpression>(getRawExpression());
3804 }
3805
3806 static bool classof(const Metadata *MD) {
3807 return MD->getMetadataID() == DIGlobalVariableExpressionKind;
3808 }
3809};
3810
3811/// Macro Info DWARF-like metadata node.
3812///
3813/// A metadata node with a DWARF macro info (i.e., a constant named
3814/// \c DW_MACINFO_*, defined in llvm/BinaryFormat/Dwarf.h). Called \a
3815/// DIMacroNode
3816/// because it's potentially used for non-DWARF output.
3817///
3818/// Uses the SubclassData16 Metadata slot.
3819class DIMacroNode : public MDNode {
3820 friend class LLVMContextImpl;
3821 friend class MDNode;
3822
3823protected:
3824 DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType,
3826 : MDNode(C, ID, Storage, Ops1, Ops2) {
3827 assert(MIType < 1u << 16);
3828 SubclassData16 = MIType;
3829 }
3830 ~DIMacroNode() = default;
3831
3832 template <class Ty> Ty *getOperandAs(unsigned I) const {
3833 return cast_or_null<Ty>(getOperand(I));
3834 }
3835
3836 StringRef getStringOperand(unsigned I) const {
3837 if (auto *S = getOperandAs<MDString>(I))
3838 return S->getString();
3839 return StringRef();
3840 }
3841
3843 if (S.empty())
3844 return nullptr;
3845 return MDString::get(Context, S);
3846 }
3847
3848public:
3849 unsigned getMacinfoType() const { return SubclassData16; }
3850
3851 static bool classof(const Metadata *MD) {
3852 switch (MD->getMetadataID()) {
3853 default:
3854 return false;
3855 case DIMacroKind:
3856 case DIMacroFileKind:
3857 return true;
3858 }
3859 }
3860};
3861
3862/// Macro
3863///
3864/// Uses the SubclassData32 Metadata slot.
3865class DIMacro : public DIMacroNode {
3866 friend class LLVMContextImpl;
3867 friend class MDNode;
3868
3869 DIMacro(LLVMContext &C, StorageType Storage, unsigned MIType, unsigned Line,
3871 : DIMacroNode(C, DIMacroKind, Storage, MIType, Ops) {
3873 }
3874 ~DIMacro() = default;
3875
3876 static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
3878 bool ShouldCreate = true) {
3879 return getImpl(Context, MIType, Line, getCanonicalMDString(Context, Name),
3880 getCanonicalMDString(Context, Value), Storage, ShouldCreate);
3881 }
3882 static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
3883 MDString *Name, MDString *Value, StorageType Storage,
3884 bool ShouldCreate = true);
3885
3886 TempDIMacro cloneImpl() const {
3888 getValue());
3889 }
3890
3891public:
3893 (unsigned MIType, unsigned Line, StringRef Name,
3894 StringRef Value = ""),
3895 (MIType, Line, Name, Value))
3897 (unsigned MIType, unsigned Line, MDString *Name,
3900
3901 TempDIMacro clone() const { return cloneImpl(); }
3902
3903 unsigned getLine() const { return SubclassData32; }
3904
3905 StringRef getName() const { return getStringOperand(0); }
3906 StringRef getValue() const { return getStringOperand(1); }
3907
3908 MDString *getRawName() const { return getOperandAs<MDString>(0); }
3909 MDString *getRawValue() const { return getOperandAs<MDString>(1); }
3910
3911 static bool classof(const Metadata *MD) {
3912 return MD->getMetadataID() == DIMacroKind;
3913 }
3914};
3915
3916/// Macro file
3917///
3918/// Uses the SubclassData32 Metadata slot.
3919class DIMacroFile : public DIMacroNode {
3920 friend class LLVMContextImpl;
3921 friend class MDNode;
3922
3924 unsigned Line, ArrayRef<Metadata *> Ops)
3925 : DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops) {
3927 }
3928 ~DIMacroFile() = default;
3929
3930 static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
3931 unsigned Line, DIFile *File,
3932 DIMacroNodeArray Elements, StorageType Storage,
3933 bool ShouldCreate = true) {
3934 return getImpl(Context, MIType, Line, static_cast<Metadata *>(File),
3935 Elements.get(), Storage, ShouldCreate);
3936 }
3937
3938 static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
3939 unsigned Line, Metadata *File, Metadata *Elements,
3940 StorageType Storage, bool ShouldCreate = true);
3941
3942 TempDIMacroFile cloneImpl() const {
3944 getElements());
3945 }
3946
3947public:
3949 (unsigned MIType, unsigned Line, DIFile *File,
3950 DIMacroNodeArray Elements),
3951 (MIType, Line, File, Elements))
3953 (unsigned MIType, unsigned Line, Metadata *File,
3956
3957 TempDIMacroFile clone() const { return cloneImpl(); }
3958
3959 void replaceElements(DIMacroNodeArray Elements) {
3960#ifndef NDEBUG
3961 for (DIMacroNode *Op : getElements())
3962 assert(is_contained(Elements->operands(), Op) &&
3963 "Lost a macro node during macro node list replacement");
3964#endif
3965 replaceOperandWith(1, Elements.get());
3966 }
3967
3968 unsigned getLine() const { return SubclassData32; }
3969 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
3970
3971 DIMacroNodeArray getElements() const {
3972 return cast_or_null<MDTuple>(getRawElements());
3973 }
3974
3975 Metadata *getRawFile() const { return getOperand(0); }
3976 Metadata *getRawElements() const { return getOperand(1); }
3977
3978 static bool classof(const Metadata *MD) {
3979 return MD->getMetadataID() == DIMacroFileKind;
3980 }
3981};
3982
3983/// List of ValueAsMetadata, to be used as an argument to a dbg.value
3984/// intrinsic.
3987 friend class LLVMContextImpl;
3989
3991
3993 : Metadata(DIArgListKind, Uniqued), ReplaceableMetadataImpl(Context),
3994 Args(Args) {
3995 track();
3996 }
3997 ~DIArgList() { untrack(); }
3998
3999 void track();
4000 void untrack();
4001 void dropAllReferences(bool Untrack);
4002
4003public:
4004 static DIArgList *get(LLVMContext &Context, ArrayRef<ValueAsMetadata *> Args);
4005
4006 ArrayRef<ValueAsMetadata *> getArgs() const { return Args; }
4007
4008 iterator args_begin() { return Args.begin(); }
4009 iterator args_end() { return Args.end(); }
4010
4011 static bool classof(const Metadata *MD) {
4012 return MD->getMetadataID() == DIArgListKind;
4013 }
4014
4017 }
4018
4019 void handleChangedOperand(void *Ref, Metadata *New);
4020};
4021
4022/// Identifies a unique instance of a variable.
4023///
4024/// Storage for identifying a potentially inlined instance of a variable,
4025/// or a fragment thereof. This guarantees that exactly one variable instance
4026/// may be identified by this class, even when that variable is a fragment of
4027/// an aggregate variable and/or there is another inlined instance of the same
4028/// source code variable nearby.
4029/// This class does not necessarily uniquely identify that variable: it is
4030/// possible that a DebugVariable with different parameters may point to the
4031/// same variable instance, but not that one DebugVariable points to multiple
4032/// variable instances.
4035
4036 const DILocalVariable *Variable;
4037 std::optional<FragmentInfo> Fragment;
4038 const DILocation *InlinedAt;
4039
4040 /// Fragment that will overlap all other fragments. Used as default when
4041 /// caller demands a fragment.
4042 static const FragmentInfo DefaultFragment;
4043
4044public:
4046 DebugVariable(const DbgVariableRecord *DVR);
4047
4049 std::optional<FragmentInfo> FragmentInfo,
4050 const DILocation *InlinedAt)
4051 : Variable(Var), Fragment(FragmentInfo), InlinedAt(InlinedAt) {}
4052
4053 DebugVariable(const DILocalVariable *Var, const DIExpression *DIExpr,
4054 const DILocation *InlinedAt)
4055 : Variable(Var),
4056 Fragment(DIExpr ? DIExpr->getFragmentInfo() : std::nullopt),
4057 InlinedAt(InlinedAt) {}
4058
4059 const DILocalVariable *getVariable() const { return Variable; }
4060 std::optional<FragmentInfo> getFragment() const { return Fragment; }
4061 const DILocation *getInlinedAt() const { return InlinedAt; }
4062
4064 return Fragment.value_or(DefaultFragment);
4065 }
4066
4067 static bool isDefaultFragment(const FragmentInfo F) {
4068 return F == DefaultFragment;
4069 }
4070
4071 bool operator==(const DebugVariable &Other) const {
4072 return std::tie(Variable, Fragment, InlinedAt) ==
4073 std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
4074 }
4075
4076 bool operator<(const DebugVariable &Other) const {
4077 return std::tie(Variable, Fragment, InlinedAt) <
4078 std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
4079 }
4080};
4081
4082template <> struct DenseMapInfo<DebugVariable> {
4084
4085 /// Empty key: no key should be generated that has no DILocalVariable.
4086 static inline DebugVariable getEmptyKey() {
4087 return DebugVariable(nullptr, std::nullopt, nullptr);
4088 }
4089
4090 /// Difference in tombstone is that the Optional is meaningful.
4092 return DebugVariable(nullptr, {{0, 0}}, nullptr);
4093 }
4094
4095 static unsigned getHashValue(const DebugVariable &D) {
4096 unsigned HV = 0;
4097 const std::optional<FragmentInfo> Fragment = D.getFragment();
4098 if (Fragment)
4100
4101 return hash_combine(D.getVariable(), HV, D.getInlinedAt());
4102 }
4103
4104 static bool isEqual(const DebugVariable &A, const DebugVariable &B) {
4105 return A == B;
4106 }
4107};
4108
4109/// Identifies a unique instance of a whole variable (discards/ignores fragment
4110/// information).
4112public:
4115 : DebugVariable(V.getVariable(), std::nullopt, V.getInlinedAt()) {}
4116};
4117
4118template <>
4120 : public DenseMapInfo<DebugVariable> {};
4121} // end namespace llvm
4122
4123#undef DEFINE_MDNODE_GET_UNPACK_IMPL
4124#undef DEFINE_MDNODE_GET_UNPACK
4125#undef DEFINE_MDNODE_GET
4126
4127#endif // LLVM_IR_DEBUGINFOMETADATA_H
AMDGPU Kernel Attributes
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static std::string getLinkageName(GlobalValue::LinkageTypes LT)
Definition: AsmWriter.cpp:3331
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")
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 DISubprogram *SP)
Extract a filename for a DISubprogram.
#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
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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:157
iterator begin() const
Definition: ArrayRef.h:156
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
This is an important base class in LLVM.
Definition: Constant.h:42
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
ArrayRef< ValueAsMetadata * > getArgs() const
void handleChangedOperand(void *Ref, Metadata *New)
static bool classof(const Metadata *MD)
static 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
static bool classof(const Metadata *MD)
unsigned StringRef uint64_t SizeInBits
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 const char * nameTableKindString(DebugNameTableKind PK)
static 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
static DICompositeType * buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t 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)
Build a DICompositeType with the given ODR identifier.
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
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 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.
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),(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits, Specification, NumExtraInhabitants, Flags, Elements, RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier, Discriminator, DataLocation, Associated, Allocated, Rank, Annotations)) DEFINE_MDNODE_GET(DICompositeType
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 * getRawBaseType() const
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
DIType * getBaseType() const
Metadata * getRawExtraData() const
DINodeArray getAnnotations() const
Get annotations associated with this derived type.
unsigned StringRef DIFile unsigned DIScope DIType uint64_t uint32_t uint64_t std::optional< unsigned > std::optional< PtrAuthData > DIFlags Metadata * ExtraData
unsigned StringRef DIFile unsigned DIScope DIType uint64_t SizeInBits
Metadata * getExtraData() const
Get extra data associated with this derived type.
unsigned StringRef DIFile unsigned DIScope DIType uint64_t uint32_t uint64_t std::optional< unsigned > std::optional< PtrAuthData > DIFlags Metadata DINodeArray Annotations
DITemplateParameterArray getTemplateParams() const
Get the template parameters from a template alias.
unsigned StringRef DIFile * File
unsigned StringRef DIFile unsigned DIScope DIType uint64_t uint32_t uint64_t OffsetInBits
DIObjCProperty * getObjCProperty() const
unsigned StringRef DIFile unsigned DIScope DIType uint64_t uint32_t AlignInBits
unsigned StringRef DIFile unsigned DIScope * Scope
Metadata * getRawAnnotations() const
DIType * getClassType() const
Get casted version of extra data.
static bool classof(const Metadata *MD)
Constant * getConstant() const
Constant * getStorageOffsetInBits() const
Constant * getDiscriminantValue() const
unsigned StringRef Name
uint32_t getVBPtrOffset() const
unsigned StringRef DIFile unsigned DIScope DIType uint64_t uint32_t uint64_t std::optional< unsigned > std::optional< PtrAuthData > DIFlags Flags
unsigned StringRef DIFile unsigned Line
DEFINE_MDNODE_GET(DIDerivedType,(unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t 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
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.
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
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 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 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.
bool extractIfOffset(int64_t &Offset) const
If this is a constant offset, extract it.
static 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.
bool startsWithDeref() const
Return whether the first element a DW_OP_deref.
static 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
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 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
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 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.
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.
DIExpression * foldConstantMath()
Try to shorten an expression with constant math operations that can be evaluated at compile time.
static std::optional< const DIExpression * > convertToNonVariadicExpression(const DIExpression *Expr)
If Expr is a valid single-location expression, i.e.
std::pair< DIExpression *, const ConstantInt * > constantFold(const ConstantInt *CI)
Try to shorten an expression with an initial constant operand.
bool isDeref() const
Return whether there is exactly one operator and it is a DW_OP_deref;.
static const DIExpression * convertToVariadicExpression(const DIExpression *Expr)
If Expr is a non-variadic expression (i.e.
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 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)
std::optional< uint64_t > getActiveBits(DIVariable *Var)
Return the number of bits that have an active value, i.e.
static 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 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 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 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 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 DIExpression * appendExt(const DIExpression *Expr, unsigned FromSize, unsigned ToSize, bool Signed)
Append a zero- or sign-extension to Expr.
std::optional< ArrayRef< uint64_t > > getSingleLocationExpressionElements() const
Returns a reference to the elements contained in this expression, skipping past the leading DW_OP_LLV...
bool isSingleLocationExpression() const
Return whether the evaluated expression makes use of a single location at the start of the expression...
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...
std::optional< SignedOrUnsignedConstant > isConstant() const
Determine whether this represents a constant value, if so.
static 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 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 std::optional< ChecksumKind > getChecksumKind(StringRef CSKindStr)
ChecksumKind
Which algorithm (e.g.
MDString MDString std::optional< ChecksumInfo< MDString * > > CS
Metadata * getRawLowerBound() const
Metadata * getRawCountNode() const
Metadata * getRawStride() const
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)
BoundType getUpperBound() 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
StringRef getName() const
static bool classof(const Metadata *MD)
unsigned getLine() const
Metadata MDString Metadata unsigned Line TempDILabel clone() const
DEFINE_MDNODE_GET(DILabel,(DILocalScope *Scope, StringRef Name, DIFile *File, unsigned Line),(Scope, Name, File, Line)) DEFINE_MDNODE_GET(DILabel
Metadata * getRawFile() const
DILocalScope * getScope() const
Get the local scope for this label.
MDString * getRawName() const
Metadata MDString Metadata unsigned Line
Metadata MDString * Name
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.
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
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 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
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...
static DILocation * getMergedLocations(ArrayRef< DILocation * > Locs)
Try to combine the vector of locations passed as input in a single one.
DEFINE_MDNODE_GET(DILocation,(unsigned Line, unsigned Column, Metadata *Scope, Metadata *InlinedAt=nullptr, bool ImplicitCode=false),(Line, Column, Scope, InlinedAt, ImplicitCode)) DEFINE_MDNODE_GET(DILocation
static unsigned getBaseDiscriminatorBits()
Return the bits used for base discriminators.
static 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 void decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF, unsigned &CI)
Raw decoder for values in an encoded discriminator D.
static DILocation * getMergedLocation(DILocation *LocA, DILocation *LocB)
When two instructions are combined into a single instruction we also need to combine the original loc...
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.
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.
dwarf::Tag getTag() const
static MDString * getCanonicalMDString(LLVMContext &Context, StringRef S)
static DIFlags getFlag(StringRef Flag)
static 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 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
StringRef getName() const
static bool classof(const Metadata *MD)
DIFile * getFile() const
StringRef getDirectory() const
std::optional< StringRef > getSource() const
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
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.
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 * 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 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
static DISPFlags getFlag(StringRef Flag)
Metadata MDString MDString Metadata * File
static 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 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
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=""),(Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType, VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams, Declaration, RetainedNodes, ThrownTypes, Annotations, TargetFuncName)) DEFINE_MDNODE_GET(DISubprogram
DISPFlags
Debug info subprogram flags.
Array subrange.
static bool classof(const Metadata *MD)
BoundType getUpperBound() const
BoundType getStride() const
BoundType getLowerBound() const
DEFINE_MDNODE_GET(DISubrange,(int64_t Count, int64_t LowerBound=0),(Count, LowerBound)) DEFINE_MDNODE_GET(DISubrange
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
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
DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, uint32_t NumExtraInhabitants, DIFlags Flags, ArrayRef< Metadata * > Ops)
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)
uint32_t getAlignInBytes() const
uint32_t getAlignInBits() const
unsigned getLine() const
void mutate(unsigned Tag, unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, uint32_t NumExtraInhabitants, DIFlags Flags)
Change fields in place.
void init(unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, uint32_t NumExtraInhabitants, DIFlags Flags)
bool isRValueReference() const
bool isArtificial() const
bool getExportSymbols() const
TempDIType clone() const
DIScope * getScope() const
bool isTypePassByReference() 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
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
This is the common base class for debug info intrinsics for variables.
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.
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:67
Metadata node.
Definition: Metadata.h:1073
friend class DIAssignID
Definition: Metadata.h:1076
void replaceOperandWith(unsigned I, Metadata *New)
Replace a specific operand.
Definition: Metadata.cpp:1077
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1434
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1561
op_iterator op_end() const
Definition: Metadata.h:1428
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1549
bool isUniqued() const
Definition: Metadata.h:1255
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1440
iterator_range< op_iterator > op_range
Definition: Metadata.h:1422
TempMDNode clone() const
Create a (temporary) clone of this.
Definition: Metadata.cpp:667
bool isDistinct() const
Definition: Metadata.h:1256
void setOperand(unsigned I, Metadata *New)
Set an operand.
Definition: Metadata.cpp:1089
op_iterator op_begin() const
Definition: Metadata.h:1424
LLVMContext & getContext() const
Definition: Metadata.h:1237
void dropAllReferences()
Definition: Metadata.cpp:907
Tracking metadata reference owned by Metadata.
Definition: Metadata.h:895
Metadata * get() const
Definition: Metadata.h:924
A single uniqued string.
Definition: Metadata.h:724
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:606
Tuple of metadata.
Definition: Metadata.h:1479
Root of the metadata hierarchy.
Definition: Metadata.h:62
StorageType
Active type of storage.
Definition: Metadata.h:70
unsigned short SubclassData16
Definition: Metadata.h:76
unsigned SubclassData32
Definition: Metadata.h:77
unsigned char Storage
Storage flag for non-uniqued, otherwise unowned, metadata.
Definition: Metadata.h:73
unsigned getMetadataID() const
Definition: Metadata.h:102
unsigned char SubclassData1
Definition: Metadata.h:75
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:386
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:573
typename SuperClass::iterator iterator
Definition: SmallVector.h:577
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
A range adaptor for a pair of iterators.
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
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
bool operator<(int64_t V1, const APSInt &V2)
Definition: APSInt.h:361
bool operator!=(uint64_t V1, const APInt &V2)
Definition: APInt.h:2082
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
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:1903
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition: Hashing.h:590
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
#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:52
static uint32_t extractProbeIndex(uint32_t Value)
Definition: PseudoProbe.h:74
static std::optional< uint32_t > extractDwarfBaseDiscriminator(uint32_t Value)
Definition: PseudoProbe.h:80