LLVM 23.0.0git
DebugInfoMetadata.h
Go to the documentation of this file.
1//===- llvm/IR/DebugInfoMetadata.h - Debug info metadata --------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Declarations for metadata specific to debug info.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_IR_DEBUGINFOMETADATA_H
14#define LLVM_IR_DEBUGINFOMETADATA_H
15
16#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/STLExtras.h"
21#include "llvm/ADT/StringRef.h"
23#include "llvm/IR/Constants.h"
25#include "llvm/IR/Metadata.h"
26#include "llvm/IR/PseudoProbe.h"
31#include <cassert>
32#include <climits>
33#include <cstddef>
34#include <cstdint>
35#include <iterator>
36#include <optional>
37#include <vector>
38
39// Helper macros for defining get() overrides.
40#define DEFINE_MDNODE_GET_UNPACK_IMPL(...) __VA_ARGS__
41#define DEFINE_MDNODE_GET_UNPACK(ARGS) DEFINE_MDNODE_GET_UNPACK_IMPL ARGS
42#define DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS) \
43 static CLASS *getDistinct(LLVMContext &Context, \
44 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
45 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct); \
46 } \
47 static Temp##CLASS getTemporary(LLVMContext &Context, \
48 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
49 return Temp##CLASS( \
50 getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary)); \
51 }
52#define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS) \
53 static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
54 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued); \
55 } \
56 static CLASS *getIfExists(LLVMContext &Context, \
57 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
58 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued, \
59 /* ShouldCreate */ false); \
60 } \
61 DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS)
62
63namespace llvm {
64
65namespace dwarf {
66enum Tag : uint16_t;
67}
68
69/// Wrapper structure that holds a language name and its version.
70///
71/// Some debug-info formats, particularly DWARF, distniguish between
72/// language codes that include the version name and codes that don't.
73/// DISourceLanguageName may hold either of these.
74///
76 /// Language version. The version scheme is language
77 /// dependent.
78 uint32_t Version = 0;
79
80 /// Language name.
81 /// If \ref HasVersion is \c true, then this name
82 /// is version independent (i.e., doesn't include the language
83 /// version in its name).
84 uint16_t Name;
85
86 /// If \c true, then \ref Version is interpretable and \ref Name
87 /// is a version independent name.
88 bool HasVersion;
89
90public:
91 bool hasVersionedName() const { return HasVersion; }
92
93 /// Returns a versioned or unversioned language name.
94 uint16_t getName() const { return Name; }
95
96 /// Transitional API for cases where we do not yet support
97 /// versioned source language names. Use \ref getName instead.
98 ///
99 /// FIXME: remove once all callers of this API account for versioned
100 /// names.
103 return Name;
104 }
105
106 /// Returns language version. Only valid for versioned language names.
109 return Version;
110 }
111
113 : Version(Version), Name(Lang), HasVersion(true) {};
115 : Version(0), Name(Lang), HasVersion(false) {};
116};
117
118class DbgVariableRecord;
119
121
122/// Tagged DWARF-like metadata node.
123///
124/// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
125/// defined in llvm/BinaryFormat/Dwarf.h). Called \a DINode because it's
126/// potentially used for non-DWARF output.
127///
128/// Uses the SubclassData16 Metadata slot.
129class DINode : public MDNode {
130 friend class LLVMContextImpl;
131 friend class MDNode;
132
133protected:
134 DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
136 : MDNode(C, ID, Storage, Ops1, Ops2) {
137 assert(Tag < 1u << 16);
139 }
140 ~DINode() = default;
141
142 template <class Ty> Ty *getOperandAs(unsigned I) const {
144 }
145
146 StringRef getStringOperand(unsigned I) const {
147 if (auto *S = getOperandAs<MDString>(I))
148 return S->getString();
149 return StringRef();
150 }
151
153 if (S.empty())
154 return nullptr;
155 return MDString::get(Context, S);
156 }
157
158 /// Allow subclasses to mutate the tag.
159 void setTag(unsigned Tag) { SubclassData16 = Tag; }
160
161public:
162 LLVM_ABI dwarf::Tag getTag() const;
163
164 /// Debug info flags.
165 ///
166 /// The three accessibility flags are mutually exclusive and rolled together
167 /// in the first two bits.
169#define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
170#define DI_FLAG_LARGEST_NEEDED
171#include "llvm/IR/DebugInfoFlags.def"
172 FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic,
173 FlagPtrToMemberRep = FlagSingleInheritance | FlagMultipleInheritance |
174 FlagVirtualInheritance,
175 LLVM_MARK_AS_BITMASK_ENUM(FlagLargest)
176 };
177
178 LLVM_ABI static DIFlags getFlag(StringRef Flag);
179 LLVM_ABI static StringRef getFlagString(DIFlags Flag);
180
181 /// Split up a flags bitfield.
182 ///
183 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
184 /// any remaining (unrecognized) bits.
185 LLVM_ABI static DIFlags splitFlags(DIFlags Flags,
186 SmallVectorImpl<DIFlags> &SplitFlags);
187
188 static bool classof(const Metadata *MD) {
189 switch (MD->getMetadataID()) {
190 default:
191 return false;
192 case GenericDINodeKind:
193 case DISubrangeKind:
194 case DIEnumeratorKind:
195 case DIBasicTypeKind:
196 case DIFixedPointTypeKind:
197 case DIStringTypeKind:
198 case DISubrangeTypeKind:
199 case DIDerivedTypeKind:
200 case DICompositeTypeKind:
201 case DISubroutineTypeKind:
202 case DIFileKind:
203 case DICompileUnitKind:
204 case DISubprogramKind:
205 case DILexicalBlockKind:
206 case DILexicalBlockFileKind:
207 case DINamespaceKind:
208 case DICommonBlockKind:
209 case DITemplateTypeParameterKind:
210 case DITemplateValueParameterKind:
211 case DIGlobalVariableKind:
212 case DILocalVariableKind:
213 case DILabelKind:
214 case DIObjCPropertyKind:
215 case DIImportedEntityKind:
216 case DIModuleKind:
217 case DIGenericSubrangeKind:
218 case DIAssignIDKind:
219 return true;
220 }
221 }
222};
223
224/// Generic tagged DWARF-like metadata node.
225///
226/// An un-specialized DWARF-like metadata node. The first operand is a
227/// (possibly empty) null-separated \a MDString header that contains arbitrary
228/// fields. The remaining operands are \a dwarf_operands(), and are pointers
229/// to other metadata.
230///
231/// Uses the SubclassData32 Metadata slot.
232class GenericDINode : public DINode {
233 friend class LLVMContextImpl;
234 friend class MDNode;
235
236 GenericDINode(LLVMContext &C, StorageType Storage, unsigned Hash,
237 unsigned Tag, ArrayRef<Metadata *> Ops1,
239 : DINode(C, GenericDINodeKind, Storage, Tag, Ops1, Ops2) {
240 setHash(Hash);
241 }
243
244 void setHash(unsigned Hash) { SubclassData32 = Hash; }
245 void recalculateHash();
246
247 static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
249 StorageType Storage, bool ShouldCreate = true) {
250 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
251 DwarfOps, Storage, ShouldCreate);
252 }
253
254 LLVM_ABI static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
255 MDString *Header,
258 bool ShouldCreate = true);
259
260 TempGenericDINode cloneImpl() const {
263 }
264
265public:
266 unsigned getHash() const { return SubclassData32; }
267
268 DEFINE_MDNODE_GET(GenericDINode,
269 (unsigned Tag, StringRef Header,
271 (Tag, Header, DwarfOps))
272 DEFINE_MDNODE_GET(GenericDINode,
273 (unsigned Tag, MDString *Header,
276
277 /// Return a (temporary) clone of this.
278 TempGenericDINode clone() const { return cloneImpl(); }
279
280 LLVM_ABI dwarf::Tag getTag() const;
281 StringRef getHeader() const { return getStringOperand(0); }
283
284 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
285 op_iterator dwarf_op_end() const { return op_end(); }
288 }
289
290 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
291 const MDOperand &getDwarfOperand(unsigned I) const {
292 return getOperand(I + 1);
293 }
294 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
295 replaceOperandWith(I + 1, New);
296 }
297
298 static bool classof(const Metadata *MD) {
299 return MD->getMetadataID() == GenericDINodeKind;
300 }
301};
302
303/// Assignment ID.
304/// Used to link stores (as an attachment) and dbg.assigns (as an operand).
305/// DIAssignID metadata is never uniqued as we compare instances using
306/// referential equality (the instance/address is the ID).
307class DIAssignID : public MDNode {
308 friend class LLVMContextImpl;
309 friend class MDNode;
310
312 : MDNode(C, DIAssignIDKind, Storage, {}) {}
313
314 ~DIAssignID() { dropAllReferences(); }
315
316 LLVM_ABI static DIAssignID *getImpl(LLVMContext &Context, StorageType Storage,
317 bool ShouldCreate = true);
318
319 TempDIAssignID cloneImpl() const { return getTemporary(getContext()); }
320
321public:
322 // This node has no operands to replace.
323 void replaceOperandWith(unsigned I, Metadata *New) = delete;
324
326 return Context.getReplaceableUses()->getAllDbgVariableRecordUsers();
327 }
328
329 static DIAssignID *getDistinct(LLVMContext &Context) {
330 return getImpl(Context, Distinct);
331 }
332 static TempDIAssignID getTemporary(LLVMContext &Context) {
333 return TempDIAssignID(getImpl(Context, Temporary));
334 }
335 // NOTE: Do not define get(LLVMContext&) - see class comment.
336
337 static bool classof(const Metadata *MD) {
338 return MD->getMetadataID() == DIAssignIDKind;
339 }
340};
341
342/// Array subrange.
343class DISubrange : public DINode {
344 friend class LLVMContextImpl;
345 friend class MDNode;
346
348
349 ~DISubrange() = default;
350
351 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, int64_t Count,
353 bool ShouldCreate = true);
354
355 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, Metadata *CountNode,
357 bool ShouldCreate = true);
358
359 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, Metadata *CountNode,
361 Metadata *UpperBound, Metadata *Stride,
363 bool ShouldCreate = true);
364
365 TempDISubrange cloneImpl() const {
366 return getTemporary(getContext(), getRawCountNode(), getRawLowerBound(),
367 getRawUpperBound(), getRawStride());
368 }
369
370public:
371 DEFINE_MDNODE_GET(DISubrange, (int64_t Count, int64_t LowerBound = 0),
372 (Count, LowerBound))
373
374 DEFINE_MDNODE_GET(DISubrange, (Metadata * CountNode, int64_t LowerBound = 0),
376
377 DEFINE_MDNODE_GET(DISubrange,
379 Metadata *UpperBound, Metadata *Stride),
380 (CountNode, LowerBound, UpperBound, Stride))
381
382 TempDISubrange clone() const { return cloneImpl(); }
383
384 Metadata *getRawCountNode() const { return getOperand(0).get(); }
385
386 Metadata *getRawLowerBound() const { return getOperand(1).get(); }
387
388 Metadata *getRawUpperBound() const { return getOperand(2).get(); }
389
390 Metadata *getRawStride() const { return getOperand(3).get(); }
391
392 typedef PointerUnion<ConstantInt *, DIVariable *, DIExpression *> BoundType;
393
394 LLVM_ABI BoundType getCount() const;
395
396 LLVM_ABI BoundType getLowerBound() const;
397
398 LLVM_ABI BoundType getUpperBound() const;
399
400 LLVM_ABI BoundType getStride() const;
401
402 static bool classof(const Metadata *MD) {
403 return MD->getMetadataID() == DISubrangeKind;
404 }
405};
406
407class DIGenericSubrange : public DINode {
408 friend class LLVMContextImpl;
409 friend class MDNode;
410
411 DIGenericSubrange(LLVMContext &C, StorageType Storage,
413
414 ~DIGenericSubrange() = default;
415
416 LLVM_ABI static DIGenericSubrange *
417 getImpl(LLVMContext &Context, Metadata *CountNode, Metadata *LowerBound,
418 Metadata *UpperBound, Metadata *Stride, StorageType Storage,
419 bool ShouldCreate = true);
420
421 TempDIGenericSubrange cloneImpl() const {
424 }
425
426public:
427 DEFINE_MDNODE_GET(DIGenericSubrange,
428 (Metadata * CountNode, Metadata *LowerBound,
429 Metadata *UpperBound, Metadata *Stride),
430 (CountNode, LowerBound, UpperBound, Stride))
431
432 TempDIGenericSubrange clone() const { return cloneImpl(); }
433
434 Metadata *getRawCountNode() const { return getOperand(0).get(); }
435 Metadata *getRawLowerBound() const { return getOperand(1).get(); }
436 Metadata *getRawUpperBound() const { return getOperand(2).get(); }
437 Metadata *getRawStride() const { return getOperand(3).get(); }
438
440
445
446 static bool classof(const Metadata *MD) {
447 return MD->getMetadataID() == DIGenericSubrangeKind;
448 }
449};
450
451/// Enumeration value.
452///
453/// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
454/// longer creates a type cycle.
455class DIEnumerator : public DINode {
456 friend class LLVMContextImpl;
457 friend class MDNode;
458
459 APInt Value;
460 LLVM_ABI DIEnumerator(LLVMContext &C, StorageType Storage, const APInt &Value,
462 DIEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
464 : DIEnumerator(C, Storage, APInt(64, Value, !IsUnsigned), IsUnsigned,
465 Ops) {}
466 ~DIEnumerator() = default;
467
468 static DIEnumerator *getImpl(LLVMContext &Context, const APInt &Value,
470 StorageType Storage, bool ShouldCreate = true) {
471 return getImpl(Context, Value, IsUnsigned,
472 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
473 }
474 LLVM_ABI static DIEnumerator *getImpl(LLVMContext &Context,
475 const APInt &Value, bool IsUnsigned,
476 MDString *Name, StorageType Storage,
477 bool ShouldCreate = true);
478
479 TempDIEnumerator cloneImpl() const {
481 }
482
483public:
484 DEFINE_MDNODE_GET(DIEnumerator,
485 (int64_t Value, bool IsUnsigned, StringRef Name),
486 (APInt(64, Value, !IsUnsigned), IsUnsigned, Name))
487 DEFINE_MDNODE_GET(DIEnumerator,
488 (int64_t Value, bool IsUnsigned, MDString *Name),
489 (APInt(64, Value, !IsUnsigned), IsUnsigned, Name))
490 DEFINE_MDNODE_GET(DIEnumerator,
491 (APInt Value, bool IsUnsigned, StringRef Name),
492 (Value, IsUnsigned, Name))
493 DEFINE_MDNODE_GET(DIEnumerator,
494 (APInt Value, bool IsUnsigned, MDString *Name),
495 (Value, IsUnsigned, Name))
496
497 TempDIEnumerator clone() const { return cloneImpl(); }
498
499 const APInt &getValue() const { return Value; }
500 bool isUnsigned() const { return SubclassData32; }
501 StringRef getName() const { return getStringOperand(0); }
502
504
505 static bool classof(const Metadata *MD) {
506 return MD->getMetadataID() == DIEnumeratorKind;
507 }
508};
509
510/// Base class for scope-like contexts.
511///
512/// Base class for lexical scopes and types (which are also declaration
513/// contexts).
514///
515/// TODO: Separate the concepts of declaration contexts and lexical scopes.
516class DIScope : public DINode {
517protected:
521 ~DIScope() = default;
522
523public:
525
526 inline StringRef getFilename() const;
527 inline StringRef getDirectory() const;
528 inline std::optional<StringRef> getSource() const;
529
530 LLVM_ABI StringRef getName() const;
531 LLVM_ABI DIScope *getScope() const;
532
533 /// Return the raw underlying file.
534 ///
535 /// A \a DIFile is a \a DIScope, but it doesn't point at a separate file (it
536 /// \em is the file). If \c this is an \a DIFile, we need to return \c this.
537 /// Otherwise, return the first operand, which is where all other subclasses
538 /// store their file pointer.
540 return isa<DIFile>(this) ? const_cast<DIScope *>(this)
541 : static_cast<Metadata *>(getOperand(0));
542 }
543
544 static bool classof(const Metadata *MD) {
545 switch (MD->getMetadataID()) {
546 default:
547 return false;
548 case DIBasicTypeKind:
549 case DIFixedPointTypeKind:
550 case DIStringTypeKind:
551 case DISubrangeTypeKind:
552 case DIDerivedTypeKind:
553 case DICompositeTypeKind:
554 case DISubroutineTypeKind:
555 case DIFileKind:
556 case DICompileUnitKind:
557 case DISubprogramKind:
558 case DILexicalBlockKind:
559 case DILexicalBlockFileKind:
560 case DINamespaceKind:
561 case DICommonBlockKind:
562 case DIModuleKind:
563 return true;
564 }
565 }
566};
567
568/// File.
569///
570/// TODO: Merge with directory/file node (including users).
571/// TODO: Canonicalize paths on creation.
572class DIFile : public DIScope {
573 friend class LLVMContextImpl;
574 friend class MDNode;
575
576public:
577 /// Which algorithm (e.g. MD5) a checksum was generated with.
578 ///
579 /// The encoding is explicit because it is used directly in Bitcode. The
580 /// value 0 is reserved to indicate the absence of a checksum in Bitcode.
582 // The first variant was originally CSK_None, encoded as 0. The new
583 // internal representation removes the need for this by wrapping the
584 // ChecksumInfo in an Optional, but to preserve Bitcode compatibility the 0
585 // encoding is reserved.
589 CSK_Last = CSK_SHA256 // Should be last enumeration.
590 };
591
592 /// A single checksum, represented by a \a Kind and a \a Value (a string).
593 template <typename T> struct ChecksumInfo {
594 /// The kind of checksum which \a Value encodes.
596 /// The string value of the checksum.
598
600 ~ChecksumInfo() = default;
601 bool operator==(const ChecksumInfo<T> &X) const {
602 return Kind == X.Kind && Value == X.Value;
603 }
604 bool operator!=(const ChecksumInfo<T> &X) const { return !(*this == X); }
605 StringRef getKindAsString() const { return getChecksumKindAsString(Kind); }
606 };
607
608private:
609 std::optional<ChecksumInfo<MDString *>> Checksum;
610 /// An optional source. A nullptr means none.
612
614 std::optional<ChecksumInfo<MDString *>> CS, MDString *Src,
616 ~DIFile() = default;
617
618 static DIFile *getImpl(LLVMContext &Context, StringRef Filename,
620 std::optional<ChecksumInfo<StringRef>> CS,
621 std::optional<StringRef> Source, StorageType Storage,
622 bool ShouldCreate = true) {
623 std::optional<ChecksumInfo<MDString *>> MDChecksum;
624 if (CS)
625 MDChecksum.emplace(CS->Kind, getCanonicalMDString(Context, CS->Value));
626 return getImpl(Context, getCanonicalMDString(Context, Filename),
627 getCanonicalMDString(Context, Directory), MDChecksum,
628 Source ? MDString::get(Context, *Source) : nullptr, Storage,
629 ShouldCreate);
630 }
631 LLVM_ABI static DIFile *getImpl(LLVMContext &Context, MDString *Filename,
632 MDString *Directory,
633 std::optional<ChecksumInfo<MDString *>> CS,
634 MDString *Source, StorageType Storage,
635 bool ShouldCreate = true);
636
637 TempDIFile cloneImpl() const {
639 getChecksum(), getSource());
640 }
641
642public:
645 std::optional<ChecksumInfo<StringRef>> CS = std::nullopt,
646 std::optional<StringRef> Source = std::nullopt),
647 (Filename, Directory, CS, Source))
648 DEFINE_MDNODE_GET(DIFile,
650 std::optional<ChecksumInfo<MDString *>> CS = std::nullopt,
651 MDString *Source = nullptr),
652 (Filename, Directory, CS, Source))
653
654 TempDIFile clone() const { return cloneImpl(); }
655
656 StringRef getFilename() const { return getStringOperand(0); }
657 StringRef getDirectory() const { return getStringOperand(1); }
658 std::optional<ChecksumInfo<StringRef>> getChecksum() const {
659 std::optional<ChecksumInfo<StringRef>> StringRefChecksum;
660 if (Checksum)
661 StringRefChecksum.emplace(Checksum->Kind, Checksum->Value->getString());
662 return StringRefChecksum;
663 }
664 std::optional<StringRef> getSource() const {
665 return Source ? std::optional<StringRef>(Source->getString())
666 : std::nullopt;
667 }
668
669 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
670 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
671 std::optional<ChecksumInfo<MDString *>> getRawChecksum() const {
672 return Checksum;
673 }
674 MDString *getRawSource() const { return Source; }
675
676 LLVM_ABI static StringRef getChecksumKindAsString(ChecksumKind CSKind);
677 LLVM_ABI static std::optional<ChecksumKind>
678 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 uint32_t NumExtraInhabitants;
714
715protected:
716 static constexpr unsigned N_OPERANDS = 5;
717
718 DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
719 unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants,
721 : DIScope(C, ID, Storage, Tag, Ops) {
722 init(Line, AlignInBits, NumExtraInhabitants, Flags);
723 }
724 ~DIType() = default;
725
726 void init(unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants,
727 DIFlags Flags) {
728 this->Line = Line;
729 this->Flags = Flags;
730 this->SubclassData32 = AlignInBits;
731 this->NumExtraInhabitants = NumExtraInhabitants;
732 }
733
734 /// Change fields in place.
735 void mutate(unsigned Tag, unsigned Line, uint32_t AlignInBits,
736 uint32_t NumExtraInhabitants, DIFlags Flags) {
737 assert(isDistinct() && "Only distinct nodes can mutate");
738 setTag(Tag);
739 init(Line, AlignInBits, NumExtraInhabitants, Flags);
740 }
741
742public:
743 TempDIType clone() const {
744 return TempDIType(cast<DIType>(MDNode::clone().release()));
745 }
746
747 unsigned getLine() const { return Line; }
749 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
750 uint32_t getNumExtraInhabitants() const { return NumExtraInhabitants; }
751 DIFlags getFlags() const { return Flags; }
752
754 StringRef getName() const { return getStringOperand(2); }
755
756 Metadata *getRawScope() const { return getOperand(1); }
758
759 Metadata *getRawSizeInBits() const { return getOperand(3); }
762 if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(MD->getValue()))
763 return CI->getZExtValue();
764 }
765 return 0;
766 }
767
768 Metadata *getRawOffsetInBits() const { return getOperand(4); }
771 if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(MD->getValue()))
772 return CI->getZExtValue();
773 }
774 return 0;
775 }
776
777 /// Returns a new temporary DIType with updated Flags
778 TempDIType cloneWithFlags(DIFlags NewFlags) const {
779 auto NewTy = clone();
780 NewTy->Flags = NewFlags;
781 return NewTy;
782 }
783
784 bool isPrivate() const {
785 return (getFlags() & FlagAccessibility) == FlagPrivate;
786 }
787 bool isProtected() const {
788 return (getFlags() & FlagAccessibility) == FlagProtected;
789 }
790 bool isPublic() const {
791 return (getFlags() & FlagAccessibility) == FlagPublic;
792 }
793 bool isForwardDecl() const { return getFlags() & FlagFwdDecl; }
794 bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; }
795 bool isVirtual() const { return getFlags() & FlagVirtual; }
796 bool isArtificial() const { return getFlags() & FlagArtificial; }
797 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
798 bool isObjcClassComplete() const {
799 return getFlags() & FlagObjcClassComplete;
800 }
801 bool isVector() const { return getFlags() & FlagVector; }
802 bool isBitField() const { return getFlags() & FlagBitField; }
803 bool isStaticMember() const { return getFlags() & FlagStaticMember; }
804 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
805 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
806 bool isTypePassByValue() const { return getFlags() & FlagTypePassByValue; }
808 return getFlags() & FlagTypePassByReference;
809 }
810 bool isBigEndian() const { return getFlags() & FlagBigEndian; }
811 bool isLittleEndian() const { return getFlags() & FlagLittleEndian; }
812 bool getExportSymbols() const { return getFlags() & FlagExportSymbols; }
813
814 static bool classof(const Metadata *MD) {
815 switch (MD->getMetadataID()) {
816 default:
817 return false;
818 case DIBasicTypeKind:
819 case DIFixedPointTypeKind:
820 case DIStringTypeKind:
821 case DISubrangeTypeKind:
822 case DIDerivedTypeKind:
823 case DICompositeTypeKind:
824 case DISubroutineTypeKind:
825 return true;
826 }
827 }
828};
829
830/// Basic type, like 'int' or 'float'.
831///
832/// TODO: Split out DW_TAG_unspecified_type.
833/// TODO: Drop unused accessors.
834class DIBasicType : public DIType {
835 friend class LLVMContextImpl;
836 friend class MDNode;
837
838 unsigned Encoding;
839 /// Describes the number of bits used by the value of the object. Non-zero
840 /// when the value of an object does not fully occupy the storage size
841 /// specified by SizeInBits.
842 uint32_t DataSizeInBits;
843
844protected:
846 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
847 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
849 : DIType(C, DIBasicTypeKind, Storage, Tag, LineNo, AlignInBits,
851 Encoding(Encoding), DataSizeInBits(DataSizeInBits) {}
853 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
854 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
857 Flags, Ops),
858 Encoding(Encoding), DataSizeInBits(DataSizeInBits) {}
859 ~DIBasicType() = default;
860
861 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
862 StringRef Name, DIFile *File, unsigned LineNo,
864 uint32_t AlignInBits, unsigned Encoding,
866 uint32_t DataSizeInBits, DIFlags Flags,
867 StorageType Storage, bool ShouldCreate = true) {
868 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
869 LineNo, Scope, SizeInBits, AlignInBits, Encoding,
870 NumExtraInhabitants, DataSizeInBits, Flags, Storage,
871 ShouldCreate);
872 }
873 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
874 MDString *Name, DIFile *File, unsigned LineNo,
876 uint32_t AlignInBits, unsigned Encoding,
878 uint32_t DataSizeInBits, DIFlags Flags,
879 StorageType Storage, bool ShouldCreate = true) {
880 auto *SizeInBitsNode = ConstantAsMetadata::get(
881 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
882 return getImpl(Context, Tag, Name, File, LineNo, Scope, SizeInBitsNode,
883 AlignInBits, Encoding, NumExtraInhabitants, DataSizeInBits,
884 Flags, Storage, ShouldCreate);
885 }
886 LLVM_ABI static DIBasicType *
887 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
888 unsigned LineNo, Metadata *Scope, Metadata *SizeInBits,
891 bool ShouldCreate = true);
892
893 TempDIBasicType cloneImpl() const {
894 return getTemporary(
898 }
899
900public:
902 (Tag, Name, nullptr, 0, nullptr, 0, 0, 0, 0, 0, FlagZero))
905 (Tag, Name, nullptr, 0, nullptr, SizeInBits, 0, 0, 0, 0,
906 FlagZero))
908 (unsigned Tag, MDString *Name, uint64_t SizeInBits),
909 (Tag, Name, nullptr, 0, nullptr, SizeInBits, 0, 0, 0, 0,
910 FlagZero))
913 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
914 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
915 Encoding, 0, 0, Flags))
917 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
918 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
919 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
920 Encoding, 0, 0, Flags))
923 uint32_t AlignInBits, unsigned Encoding,
925 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
929 uint32_t AlignInBits, unsigned Encoding,
930 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
931 DIFlags Flags),
932 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
933 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
937 uint32_t AlignInBits, unsigned Encoding,
941 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
943 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
944 uint32_t AlignInBits, unsigned Encoding,
945 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
946 DIFlags Flags),
947 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
948 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
951 uint32_t AlignInBits, unsigned Encoding,
954 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
955 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
957 (unsigned Tag, MDString *Name, Metadata *File,
959 uint32_t AlignInBits, unsigned Encoding,
960 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
961 DIFlags Flags),
963 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
964
965 TempDIBasicType clone() const { return cloneImpl(); }
966
967 unsigned getEncoding() const { return Encoding; }
968
969 uint32_t getDataSizeInBits() const { return DataSizeInBits; }
970
971 enum class Signedness { Signed, Unsigned };
972
973 /// Return the signedness of this type, or std::nullopt if this type is
974 /// neither signed nor unsigned.
975 LLVM_ABI std::optional<Signedness> getSignedness() const;
976
977 static bool classof(const Metadata *MD) {
978 return MD->getMetadataID() == DIBasicTypeKind ||
979 MD->getMetadataID() == DIFixedPointTypeKind;
980 }
981};
982
983/// Fixed-point type.
984class DIFixedPointType : public DIBasicType {
985 friend class LLVMContextImpl;
986 friend class MDNode;
987
988 // Actually FixedPointKind.
989 unsigned Kind;
990 // Used for binary and decimal.
991 int Factor;
992 // Used for rational.
993 APInt Numerator;
994 APInt Denominator;
995
996 DIFixedPointType(LLVMContext &C, StorageType Storage, unsigned Tag,
997 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
998 DIFlags Flags, unsigned Kind, int Factor,
1000 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, LineNo, AlignInBits,
1001 Encoding, 0, 0, Flags, Ops),
1002 Kind(Kind), Factor(Factor) {
1003 assert(Kind == FixedPointBinary || Kind == FixedPointDecimal);
1004 }
1006 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
1007 DIFlags Flags, unsigned Kind, APInt Numerator,
1009 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, LineNo, AlignInBits,
1010 Encoding, 0, 0, Flags, Ops),
1011 Kind(Kind), Factor(0), Numerator(Numerator), Denominator(Denominator) {
1012 assert(Kind == FixedPointRational);
1013 }
1014 DIFixedPointType(LLVMContext &C, StorageType Storage, unsigned Tag,
1015 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
1016 DIFlags Flags, unsigned Kind, int Factor, APInt Numerator,
1018 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, LineNo, AlignInBits,
1019 Encoding, 0, 0, Flags, Ops),
1020 Kind(Kind), Factor(Factor), Numerator(Numerator),
1022 ~DIFixedPointType() = default;
1023
1024 static DIFixedPointType *
1025 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1026 unsigned LineNo, DIScope *Scope, uint64_t SizeInBits,
1027 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind,
1028 int Factor, APInt Numerator, APInt Denominator, StorageType Storage,
1029 bool ShouldCreate = true) {
1030 auto *SizeInBitsNode = ConstantAsMetadata::get(
1031 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1032 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1033 LineNo, Scope, SizeInBitsNode, AlignInBits, Encoding, Flags,
1034 Kind, Factor, Numerator, Denominator, Storage, ShouldCreate);
1035 }
1036 static DIFixedPointType *
1037 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1038 unsigned LineNo, DIScope *Scope, Metadata *SizeInBits,
1039 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind,
1040 int Factor, APInt Numerator, APInt Denominator, StorageType Storage,
1041 bool ShouldCreate = true) {
1042 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1044 Kind, Factor, Numerator, Denominator, Storage, ShouldCreate);
1045 }
1046 static DIFixedPointType *
1047 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, DIFile *File,
1048 unsigned LineNo, DIScope *Scope, uint64_t SizeInBits,
1049 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind,
1050 int Factor, APInt Numerator, APInt Denominator, StorageType Storage,
1051 bool ShouldCreate = true) {
1052 auto *SizeInBitsNode = ConstantAsMetadata::get(
1053 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1054 return getImpl(Context, Tag, Name, File, LineNo, Scope, SizeInBitsNode,
1055 AlignInBits, Encoding, Flags, Kind, Factor, Numerator,
1056 Denominator, Storage, ShouldCreate);
1057 }
1058 LLVM_ABI static DIFixedPointType *
1059 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1061 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind,
1062 int Factor, APInt Numerator, APInt Denominator, StorageType Storage,
1063 bool ShouldCreate = true);
1064
1065 TempDIFixedPointType cloneImpl() const {
1068 getAlignInBits(), getEncoding(), getFlags(), Kind,
1069 Factor, Numerator, Denominator);
1070 }
1071
1072public:
1073 enum FixedPointKind : unsigned {
1074 /// Scale factor 2^Factor.
1076 /// Scale factor 10^Factor.
1078 /// Arbitrary rational scale factor.
1081 };
1082
1083 LLVM_ABI static std::optional<FixedPointKind>
1085 LLVM_ABI static const char *fixedPointKindString(FixedPointKind);
1086
1087 DEFINE_MDNODE_GET(DIFixedPointType,
1088 (unsigned Tag, MDString *Name, DIFile *File,
1091 unsigned Kind, int Factor, APInt Numerator,
1092 APInt Denominator),
1094 Encoding, Flags, Kind, Factor, Numerator, Denominator))
1095 DEFINE_MDNODE_GET(DIFixedPointType,
1099 unsigned Kind, int Factor, APInt Numerator,
1100 APInt Denominator),
1102 Encoding, Flags, Kind, Factor, Numerator, Denominator))
1103 DEFINE_MDNODE_GET(DIFixedPointType,
1104 (unsigned Tag, MDString *Name, Metadata *File,
1107 unsigned Kind, int Factor, APInt Numerator,
1108 APInt Denominator),
1110 Encoding, Flags, Kind, Factor, Numerator, Denominator))
1111
1112 TempDIFixedPointType clone() const { return cloneImpl(); }
1113
1114 bool isBinary() const { return Kind == FixedPointBinary; }
1115 bool isDecimal() const { return Kind == FixedPointDecimal; }
1116 bool isRational() const { return Kind == FixedPointRational; }
1117
1118 LLVM_ABI bool isSigned() const;
1119
1120 FixedPointKind getKind() const { return static_cast<FixedPointKind>(Kind); }
1121
1122 int getFactorRaw() const { return Factor; }
1123 int getFactor() const {
1124 assert(Kind == FixedPointBinary || Kind == FixedPointDecimal);
1125 return Factor;
1126 }
1127
1128 const APInt &getNumeratorRaw() const { return Numerator; }
1129 const APInt &getNumerator() const {
1130 assert(Kind == FixedPointRational);
1131 return Numerator;
1132 }
1133
1134 const APInt &getDenominatorRaw() const { return Denominator; }
1135 const APInt &getDenominator() const {
1136 assert(Kind == FixedPointRational);
1137 return Denominator;
1138 }
1139
1140 static bool classof(const Metadata *MD) {
1141 return MD->getMetadataID() == DIFixedPointTypeKind;
1142 }
1143};
1144
1145/// String type, Fortran CHARACTER(n)
1146class DIStringType : public DIType {
1147 friend class LLVMContextImpl;
1148 friend class MDNode;
1149
1150 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1151
1152 unsigned Encoding;
1153
1154 DIStringType(LLVMContext &C, StorageType Storage, unsigned Tag,
1155 uint32_t AlignInBits, unsigned Encoding,
1157 : DIType(C, DIStringTypeKind, Storage, Tag, 0, AlignInBits, 0, FlagZero,
1158 Ops),
1159 Encoding(Encoding) {}
1160 ~DIStringType() = default;
1161
1162 static DIStringType *getImpl(LLVMContext &Context, unsigned Tag,
1164 Metadata *StrLenExp, Metadata *StrLocationExp,
1166 unsigned Encoding, StorageType Storage,
1167 bool ShouldCreate = true) {
1168 auto *SizeInBitsNode = ConstantAsMetadata::get(
1169 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1170 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
1171 StringLength, StrLenExp, StrLocationExp, SizeInBitsNode,
1172 AlignInBits, Encoding, Storage, ShouldCreate);
1173 }
1174 static DIStringType *getImpl(LLVMContext &Context, unsigned Tag,
1175 MDString *Name, Metadata *StringLength,
1176 Metadata *StrLenExp, Metadata *StrLocationExp,
1178 unsigned Encoding, StorageType Storage,
1179 bool ShouldCreate = true) {
1180 auto *SizeInBitsNode = ConstantAsMetadata::get(
1181 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1182 return getImpl(Context, Tag, Name, StringLength, StrLenExp, StrLocationExp,
1183 SizeInBitsNode, AlignInBits, Encoding, Storage,
1184 ShouldCreate);
1185 }
1186 LLVM_ABI static DIStringType *
1187 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name,
1188 Metadata *StringLength, Metadata *StrLenExp, Metadata *StrLocationExp,
1189 Metadata *SizeInBits, uint32_t AlignInBits, unsigned Encoding,
1190 StorageType Storage, bool ShouldCreate = true);
1191
1192 TempDIStringType cloneImpl() const {
1197 }
1198
1199public:
1200 DEFINE_MDNODE_GET(DIStringType,
1201 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
1203 (Tag, Name, nullptr, nullptr, nullptr, SizeInBits,
1204 AlignInBits, 0))
1205 DEFINE_MDNODE_GET(DIStringType,
1209 unsigned Encoding),
1212 DEFINE_MDNODE_GET(DIStringType,
1213 (unsigned Tag, StringRef Name, Metadata *StringLength,
1216 unsigned Encoding),
1219 DEFINE_MDNODE_GET(DIStringType,
1223 unsigned Encoding),
1226
1227 TempDIStringType clone() const { return cloneImpl(); }
1228
1229 static bool classof(const Metadata *MD) {
1230 return MD->getMetadataID() == DIStringTypeKind;
1231 }
1232
1236
1240
1244
1245 unsigned getEncoding() const { return Encoding; }
1246
1247 Metadata *getRawStringLength() const { return getOperand(MY_FIRST_OPERAND); }
1248
1250 return getOperand(MY_FIRST_OPERAND + 1);
1251 }
1252
1254 return getOperand(MY_FIRST_OPERAND + 2);
1255 }
1256};
1257
1258/// Derived types.
1259///
1260/// This includes qualified types, pointers, references, friends, typedefs, and
1261/// class members.
1262///
1263/// TODO: Split out members (inheritance, fields, methods, etc.).
1264class DIDerivedType : public DIType {
1265public:
1266 /// Pointer authentication (__ptrauth) metadata.
1268 // RawData layout:
1269 // - Bits 0..3: Key
1270 // - Bit 4: IsAddressDiscriminated
1271 // - Bits 5..20: ExtraDiscriminator
1272 // - Bit 21: IsaPointer
1273 // - Bit 22: AuthenticatesNullValues
1274 unsigned RawData;
1275
1276 PtrAuthData(unsigned FromRawData) : RawData(FromRawData) {}
1277 PtrAuthData(unsigned Key, bool IsDiscr, unsigned Discriminator,
1278 bool IsaPointer, bool AuthenticatesNullValues) {
1279 assert(Key < 16);
1280 assert(Discriminator <= 0xffff);
1281 RawData = (Key << 0) | (IsDiscr ? (1 << 4) : 0) | (Discriminator << 5) |
1282 (IsaPointer ? (1 << 21) : 0) |
1283 (AuthenticatesNullValues ? (1 << 22) : 0);
1284 }
1285
1286 unsigned key() { return (RawData >> 0) & 0b1111; }
1287 bool isAddressDiscriminated() { return (RawData >> 4) & 1; }
1288 unsigned extraDiscriminator() { return (RawData >> 5) & 0xffff; }
1289 bool isaPointer() { return (RawData >> 21) & 1; }
1290 bool authenticatesNullValues() { return (RawData >> 22) & 1; }
1291 };
1292
1293private:
1294 friend class LLVMContextImpl;
1295 friend class MDNode;
1296
1297 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1298
1299 /// The DWARF address space of the memory pointed to or referenced by a
1300 /// pointer or reference type respectively.
1301 std::optional<unsigned> DWARFAddressSpace;
1302
1303 DIDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
1304 unsigned Line, uint32_t AlignInBits,
1305 std::optional<unsigned> DWARFAddressSpace,
1306 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1308 : DIType(C, DIDerivedTypeKind, Storage, Tag, Line, AlignInBits, 0, Flags,
1309 Ops),
1310 DWARFAddressSpace(DWARFAddressSpace) {
1311 if (PtrAuthData)
1313 }
1314 ~DIDerivedType() = default;
1315 static DIDerivedType *
1316 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1317 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1319 std::optional<unsigned> DWARFAddressSpace,
1320 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1322 bool ShouldCreate = true) {
1323 auto *SizeInBitsNode = ConstantAsMetadata::get(
1324 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1325 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1326 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1327 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1328 Line, Scope, BaseType, SizeInBitsNode, AlignInBits,
1329 OffsetInBitsNode, DWARFAddressSpace, PtrAuthData, Flags,
1330 ExtraData, Annotations.get(), Storage, ShouldCreate);
1331 }
1332 static DIDerivedType *
1333 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, DIFile *File,
1334 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1336 std::optional<unsigned> DWARFAddressSpace,
1337 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1339 bool ShouldCreate = true) {
1340 auto *SizeInBitsNode = ConstantAsMetadata::get(
1341 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1342 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1343 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1344 return getImpl(Context, Tag, Name, File, Line, Scope, BaseType,
1345 SizeInBitsNode, AlignInBits, OffsetInBitsNode,
1347 Annotations.get(), Storage, ShouldCreate);
1348 }
1349 static DIDerivedType *
1350 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1353 std::optional<unsigned> DWARFAddressSpace,
1354 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1356 bool ShouldCreate = true) {
1357 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1359 DWARFAddressSpace, PtrAuthData, Flags, ExtraData,
1360 Annotations.get(), Storage, ShouldCreate);
1361 }
1362 LLVM_ABI static DIDerivedType *
1363 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1364 unsigned Line, Metadata *Scope, Metadata *BaseType,
1366 std::optional<unsigned> DWARFAddressSpace,
1367 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1369 bool ShouldCreate = true);
1370
1371 TempDIDerivedType cloneImpl() const {
1372 return getTemporary(
1375 getRawOffsetInBits(), getDWARFAddressSpace(), getPtrAuthData(),
1377 }
1378
1379public:
1380 DEFINE_MDNODE_GET(DIDerivedType,
1381 (unsigned Tag, MDString *Name, Metadata *File,
1382 unsigned Line, Metadata *Scope, Metadata *BaseType,
1385 std::optional<unsigned> DWARFAddressSpace,
1386 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1387 Metadata *ExtraData = nullptr,
1388 Metadata *Annotations = nullptr),
1390 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1392 DEFINE_MDNODE_GET(DIDerivedType,
1393 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1396 std::optional<unsigned> DWARFAddressSpace,
1397 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1399 DINodeArray Annotations = nullptr),
1401 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1403 DEFINE_MDNODE_GET(DIDerivedType,
1404 (unsigned Tag, MDString *Name, DIFile *File, unsigned Line,
1407 std::optional<unsigned> DWARFAddressSpace,
1408 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1409 Metadata *ExtraData = nullptr,
1410 DINodeArray Annotations = nullptr),
1412 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1414 DEFINE_MDNODE_GET(DIDerivedType,
1415 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1418 std::optional<unsigned> DWARFAddressSpace,
1419 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1420 Metadata *ExtraData = nullptr,
1421 DINodeArray Annotations = nullptr),
1423 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1425
1426 TempDIDerivedType clone() const { return cloneImpl(); }
1427
1428 /// Get the base type this is derived from.
1429 DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); }
1430 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1431
1432 /// \returns The DWARF address space of the memory pointed to or referenced by
1433 /// a pointer or reference type respectively.
1434 std::optional<unsigned> getDWARFAddressSpace() const {
1435 return DWARFAddressSpace;
1436 }
1437
1438 LLVM_ABI std::optional<PtrAuthData> getPtrAuthData() const;
1439
1440 /// Get extra data associated with this derived type.
1441 ///
1442 /// Class type for pointer-to-members, objective-c property node for ivars,
1443 /// global constant wrapper for static members, virtual base pointer offset
1444 /// for inheritance, a tuple of template parameters for template aliases,
1445 /// discriminant for a variant, or storage offset for a bit field.
1446 ///
1447 /// TODO: Separate out types that need this extra operand: pointer-to-member
1448 /// types and member fields (static members and ivars).
1450 Metadata *getRawExtraData() const { return getOperand(MY_FIRST_OPERAND + 1); }
1451
1452 /// Get the template parameters from a template alias.
1453 DITemplateParameterArray getTemplateParams() const {
1455 }
1456
1457 /// Get annotations associated with this derived type.
1458 DINodeArray getAnnotations() const {
1460 }
1462 return getOperand(MY_FIRST_OPERAND + 2);
1463 }
1464
1465 /// Get casted version of extra data.
1466 /// @{
1467 LLVM_ABI DIType *getClassType() const;
1468
1472
1474
1476
1477 LLVM_ABI Constant *getConstant() const;
1478
1480 /// @}
1481
1482 static bool classof(const Metadata *MD) {
1483 return MD->getMetadataID() == DIDerivedTypeKind;
1484 }
1485};
1486
1489 return Lhs.RawData == Rhs.RawData;
1490}
1491
1494 return !(Lhs == Rhs);
1495}
1496
1497/// Subrange type. This is somewhat similar to DISubrange, but it
1498/// is also a DIType.
1499class DISubrangeType : public DIType {
1500public:
1502 DIDerivedType *>
1504
1505private:
1506 friend class LLVMContextImpl;
1507 friend class MDNode;
1508
1509 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1510
1511 DISubrangeType(LLVMContext &C, StorageType Storage, unsigned Line,
1513
1514 ~DISubrangeType() = default;
1515
1516 static DISubrangeType *
1517 getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
1521 StorageType Storage, bool ShouldCreate = true) {
1522 auto *SizeInBitsNode = ConstantAsMetadata::get(
1523 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1524 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1525 Scope, SizeInBitsNode, AlignInBits, Flags, BaseType,
1526 LowerBound, UpperBound, Stride, Bias, Storage, ShouldCreate);
1527 }
1528
1529 LLVM_ABI static DISubrangeType *
1530 getImpl(LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
1532 DIFlags Flags, Metadata *BaseType, Metadata *LowerBound,
1534 StorageType Storage, bool ShouldCreate = true);
1535
1536 TempDISubrangeType cloneImpl() const {
1541 }
1542
1543 LLVM_ABI BoundType convertRawToBound(Metadata *IN) const;
1544
1545public:
1546 DEFINE_MDNODE_GET(DISubrangeType,
1547 (MDString * Name, Metadata *File, unsigned Line,
1554 DEFINE_MDNODE_GET(DISubrangeType,
1561
1562 TempDISubrangeType clone() const { return cloneImpl(); }
1563
1564 /// Get the base type this is derived from.
1566 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1567
1569 return getOperand(MY_FIRST_OPERAND + 1).get();
1570 }
1571
1573 return getOperand(MY_FIRST_OPERAND + 2).get();
1574 }
1575
1577 return getOperand(MY_FIRST_OPERAND + 3).get();
1578 }
1579
1581 return getOperand(MY_FIRST_OPERAND + 4).get();
1582 }
1583
1585 return convertRawToBound(getRawLowerBound());
1586 }
1587
1589 return convertRawToBound(getRawUpperBound());
1590 }
1591
1592 BoundType getStride() const { return convertRawToBound(getRawStride()); }
1593
1594 BoundType getBias() const { return convertRawToBound(getRawBias()); }
1595
1596 static bool classof(const Metadata *MD) {
1597 return MD->getMetadataID() == DISubrangeTypeKind;
1598 }
1599};
1600
1601/// Composite types.
1602///
1603/// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
1604/// TODO: Create a custom, unrelated node for DW_TAG_array_type.
1605class DICompositeType : public DIType {
1606 friend class LLVMContextImpl;
1607 friend class MDNode;
1608
1609 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1610
1611 unsigned RuntimeLang;
1612 std::optional<uint32_t> EnumKind;
1613
1614 DICompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
1615 unsigned Line, unsigned RuntimeLang, uint32_t AlignInBits,
1617 std::optional<uint32_t> EnumKind, DIFlags Flags,
1619 : DIType(C, DICompositeTypeKind, Storage, Tag, Line, AlignInBits,
1621 RuntimeLang(RuntimeLang), EnumKind(EnumKind) {}
1622 ~DICompositeType() = default;
1623
1624 /// Change fields in place.
1625 void mutate(unsigned Tag, unsigned Line, unsigned RuntimeLang,
1627 std::optional<uint32_t> EnumKind, DIFlags Flags) {
1628 assert(isDistinct() && "Only distinct nodes can mutate");
1629 assert(getRawIdentifier() && "Only ODR-uniqued nodes should mutate");
1630 this->RuntimeLang = RuntimeLang;
1631 this->EnumKind = EnumKind;
1633 }
1634
1635 static DICompositeType *
1636 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
1637 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1639 uint32_t NumExtraInhabitants, DIFlags Flags, DINodeArray Elements,
1640 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1641 DIType *VTableHolder, DITemplateParameterArray TemplateParams,
1642 StringRef Identifier, DIDerivedType *Discriminator,
1644 Metadata *Rank, DINodeArray Annotations, Metadata *BitStride,
1645 StorageType Storage, bool ShouldCreate = true) {
1646 auto *SizeInBitsNode = ConstantAsMetadata::get(
1647 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1648 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1649 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1650 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1651 Line, Scope, BaseType, SizeInBitsNode, AlignInBits,
1652 OffsetInBitsNode, Flags, Elements.get(), RuntimeLang,
1654 getCanonicalMDString(Context, Identifier), Discriminator,
1657 ShouldCreate);
1658 }
1659 static DICompositeType *
1660 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1661 unsigned Line, Metadata *Scope, Metadata *BaseType,
1662 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
1663 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
1664 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1669 Metadata *BitStride, StorageType Storage, bool ShouldCreate = true) {
1670 auto *SizeInBitsNode = ConstantAsMetadata::get(
1671 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1672 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1673 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1674 return getImpl(Context, Tag, Name, File, Line, Scope, BaseType,
1675 SizeInBitsNode, AlignInBits, OffsetInBitsNode, Flags,
1676 Elements, RuntimeLang, EnumKind, VTableHolder,
1679 NumExtraInhabitants, BitStride, Storage, ShouldCreate);
1680 }
1681 static DICompositeType *
1682 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
1685 uint32_t NumExtraInhabitants, DIFlags Flags, DINodeArray Elements,
1686 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1687 DIType *VTableHolder, DITemplateParameterArray TemplateParams,
1688 StringRef Identifier, DIDerivedType *Discriminator,
1690 Metadata *Rank, DINodeArray Annotations, Metadata *BitStride,
1691 StorageType Storage, bool ShouldCreate = true) {
1692 return getImpl(
1693 Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
1695 RuntimeLang, EnumKind, VTableHolder, TemplateParams.get(),
1698 NumExtraInhabitants, BitStride, Storage, ShouldCreate);
1699 }
1700 LLVM_ABI static DICompositeType *
1701 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1702 unsigned Line, Metadata *Scope, Metadata *BaseType,
1704 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
1705 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1710 Metadata *BitStride, StorageType Storage, bool ShouldCreate = true);
1711
1712 TempDICompositeType cloneImpl() const {
1713 return getTemporary(
1721 getRawBitStride());
1722 }
1723
1724public:
1726 DICompositeType,
1727 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1730 DINodeArray Elements, unsigned RuntimeLang,
1731 std::optional<uint32_t> EnumKind, DIType *VTableHolder,
1732 DITemplateParameterArray TemplateParams = nullptr,
1734 Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
1735 Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
1736 DINodeArray Annotations = nullptr, DIType *Specification = nullptr,
1740 RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier,
1742 BitStride))
1744 DICompositeType,
1745 (unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
1748 Metadata *Elements, unsigned RuntimeLang,
1749 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1752 Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
1753 Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
1755 Metadata *BitStride = nullptr),
1757 OffsetInBits, Flags, Elements, RuntimeLang, EnumKind, VTableHolder,
1760 BitStride))
1762 DICompositeType,
1763 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1766 DINodeArray Elements, unsigned RuntimeLang,
1767 std::optional<uint32_t> EnumKind, DIType *VTableHolder,
1768 DITemplateParameterArray TemplateParams = nullptr,
1770 Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
1771 Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
1772 DINodeArray Annotations = nullptr, DIType *Specification = nullptr,
1776 RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier,
1778 BitStride))
1780 DICompositeType,
1781 (unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
1784 Metadata *Elements, unsigned RuntimeLang,
1785 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1786 Metadata *TemplateParams = nullptr, MDString *Identifier = nullptr,
1787 Metadata *Discriminator = nullptr, Metadata *DataLocation = nullptr,
1788 Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
1789 Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
1791 Metadata *BitStride = nullptr),
1793 OffsetInBits, Flags, Elements, RuntimeLang, EnumKind, VTableHolder,
1796 BitStride))
1797
1798 TempDICompositeType clone() const { return cloneImpl(); }
1799
1800 /// Get a DICompositeType with the given ODR identifier.
1801 ///
1802 /// If \a LLVMContext::isODRUniquingDebugTypes(), gets the mapped
1803 /// DICompositeType for the given ODR \c Identifier. If none exists, creates
1804 /// a new node.
1805 ///
1806 /// Else, returns \c nullptr.
1807 LLVM_ABI static DICompositeType *
1808 getODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1809 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1813 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1819 MDString &Identifier);
1820
1821 /// Build a DICompositeType with the given ODR identifier.
1822 ///
1823 /// Looks up the mapped DICompositeType for the given ODR \c Identifier. If
1824 /// it doesn't exist, creates a new one. If it does exist and \a
1825 /// isForwardDecl(), and the new arguments would be a definition, mutates the
1826 /// the type in place. In either case, returns the type.
1827 ///
1828 /// If not \a LLVMContext::isODRUniquingDebugTypes(), this function returns
1829 /// nullptr.
1830 LLVM_ABI static DICompositeType *
1831 buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1832 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1836 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1841
1843 DINodeArray getElements() const {
1845 }
1849 DITemplateParameterArray getTemplateParams() const {
1851 }
1853 return getStringOperand(MY_FIRST_OPERAND + 4);
1854 }
1855 unsigned getRuntimeLang() const { return RuntimeLang; }
1856 std::optional<uint32_t> getEnumKind() const { return EnumKind; }
1857
1858 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1859 Metadata *getRawElements() const { return getOperand(MY_FIRST_OPERAND + 1); }
1861 return getOperand(MY_FIRST_OPERAND + 2);
1862 }
1864 return getOperand(MY_FIRST_OPERAND + 3);
1865 }
1867 return getOperandAs<MDString>(MY_FIRST_OPERAND + 4);
1868 }
1870 return getOperand(MY_FIRST_OPERAND + 5);
1871 }
1873 return getOperandAs<DIDerivedType>(MY_FIRST_OPERAND + 5);
1874 }
1876 return getOperand(MY_FIRST_OPERAND + 6);
1877 }
1885 return getOperand(MY_FIRST_OPERAND + 7);
1886 }
1893 Metadata *getRawAllocated() const { return getOperand(MY_FIRST_OPERAND + 8); }
1900 Metadata *getRawRank() const { return getOperand(MY_FIRST_OPERAND + 9); }
1903 return dyn_cast_or_null<ConstantInt>(MD->getValue());
1904 return nullptr;
1905 }
1909
1911 return getOperand(MY_FIRST_OPERAND + 10);
1912 }
1913 DINodeArray getAnnotations() const {
1915 }
1916
1918 return getOperand(MY_FIRST_OPERAND + 11);
1919 }
1923
1924 bool isNameSimplified() const { return getFlags() & FlagNameIsSimplified; }
1925
1927 return getOperand(MY_FIRST_OPERAND + 12);
1928 }
1931 return dyn_cast_or_null<ConstantInt>(MD->getValue());
1932 return nullptr;
1933 }
1934
1935 /// Replace operands.
1936 ///
1937 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
1938 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
1939 /// of its movement if necessary.
1940 /// @{
1941 void replaceElements(DINodeArray Elements) {
1942#ifndef NDEBUG
1943 for (DINode *Op : getElements())
1944 assert(is_contained(Elements->operands(), Op) &&
1945 "Lost a member during member list replacement");
1946#endif
1947 replaceOperandWith(MY_FIRST_OPERAND + 1, Elements.get());
1948 }
1949
1951 replaceOperandWith(MY_FIRST_OPERAND + 2, VTableHolder);
1952 }
1953
1954 void replaceTemplateParams(DITemplateParameterArray TemplateParams) {
1955 replaceOperandWith(MY_FIRST_OPERAND + 3, TemplateParams.get());
1956 }
1957 /// @}
1958
1959 static bool classof(const Metadata *MD) {
1960 return MD->getMetadataID() == DICompositeTypeKind;
1961 }
1962};
1963
1964/// Type array for a subprogram.
1965///
1966/// TODO: Fold the array of types in directly as operands.
1967class DISubroutineType : public DIType {
1968 friend class LLVMContextImpl;
1969 friend class MDNode;
1970
1971 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1972
1973 /// The calling convention used with DW_AT_calling_convention. Actually of
1974 /// type dwarf::CallingConvention.
1975 uint8_t CC;
1976
1977 DISubroutineType(LLVMContext &C, StorageType Storage, DIFlags Flags,
1979 ~DISubroutineType() = default;
1980
1981 static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
1982 uint8_t CC, DITypeArray TypeArray,
1984 bool ShouldCreate = true) {
1985 return getImpl(Context, Flags, CC, TypeArray.get(), Storage, ShouldCreate);
1986 }
1987 LLVM_ABI static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
1990 bool ShouldCreate = true);
1991
1992 TempDISubroutineType cloneImpl() const {
1994 }
1995
1996public:
1997 DEFINE_MDNODE_GET(DISubroutineType,
1998 (DIFlags Flags, uint8_t CC, DITypeArray TypeArray),
1999 (Flags, CC, TypeArray))
2000 DEFINE_MDNODE_GET(DISubroutineType,
2003
2004 TempDISubroutineType clone() const { return cloneImpl(); }
2005 // Returns a new temporary DISubroutineType with updated CC
2006 TempDISubroutineType cloneWithCC(uint8_t CC) const {
2007 auto NewTy = clone();
2008 NewTy->CC = CC;
2009 return NewTy;
2010 }
2011
2012 uint8_t getCC() const { return CC; }
2013
2014 DITypeArray getTypeArray() const {
2016 }
2017
2018 Metadata *getRawTypeArray() const { return getOperand(MY_FIRST_OPERAND); }
2019
2020 static bool classof(const Metadata *MD) {
2021 return MD->getMetadataID() == DISubroutineTypeKind;
2022 }
2023};
2024
2025/// Compile unit.
2026class DICompileUnit : public DIScope {
2027 friend class LLVMContextImpl;
2028 friend class MDNode;
2029
2030public:
2038
2046
2047 LLVM_ABI static std::optional<DebugEmissionKind>
2049 LLVM_ABI static const char *emissionKindString(DebugEmissionKind EK);
2050 LLVM_ABI static std::optional<DebugNameTableKind>
2052 LLVM_ABI static const char *nameTableKindString(DebugNameTableKind PK);
2053
2054private:
2055 DISourceLanguageName SourceLanguage;
2056 unsigned RuntimeVersion;
2058 unsigned EmissionKind;
2059 unsigned NameTableKind;
2060 bool IsOptimized;
2061 bool SplitDebugInlining;
2063 bool RangesBaseAddress;
2064
2066 DISourceLanguageName SourceLanguage, bool IsOptimized,
2067 unsigned RuntimeVersion, unsigned EmissionKind, uint64_t DWOId,
2069 unsigned NameTableKind, bool RangesBaseAddress,
2071 ~DICompileUnit() = default;
2072
2073 static DICompileUnit *
2074 getImpl(LLVMContext &Context, DISourceLanguageName SourceLanguage,
2077 unsigned EmissionKind, DICompositeTypeArray EnumTypes,
2078 DIScopeArray RetainedTypes,
2079 DIGlobalVariableExpressionArray GlobalVariables,
2080 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
2083 StringRef SDK, StorageType Storage, bool ShouldCreate = true) {
2084 return getImpl(
2085 Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
2088 EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
2091 getCanonicalMDString(Context, SysRoot),
2092 getCanonicalMDString(Context, SDK), Storage, ShouldCreate);
2093 }
2094 LLVM_ABI static DICompileUnit *
2095 getImpl(LLVMContext &Context, DISourceLanguageName SourceLanguage,
2096 Metadata *File, MDString *Producer, bool IsOptimized, MDString *Flags,
2097 unsigned RuntimeVersion, MDString *SplitDebugFilename,
2101 bool DebugInfoForProfiling, unsigned NameTableKind,
2102 bool RangesBaseAddress, MDString *SysRoot, MDString *SDK,
2103 StorageType Storage, bool ShouldCreate = true);
2104
2105 TempDICompileUnit cloneImpl() const {
2106 return getTemporary(
2113 }
2114
2115public:
2116 static void get() = delete;
2117 static void getIfExists() = delete;
2118
2120 DICompileUnit,
2122 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
2124 DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes,
2125 DIGlobalVariableExpressionArray GlobalVariables,
2126 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
2127 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
2128 DebugNameTableKind NameTableKind, bool RangesBaseAddress,
2130 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
2132 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
2133 DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress,
2134 SysRoot, SDK))
2136 DICompileUnit,
2138 bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
2142 bool SplitDebugInlining, bool DebugInfoForProfiling,
2143 unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
2145 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
2147 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
2148 DebugInfoForProfiling, NameTableKind, RangesBaseAddress, SysRoot, SDK))
2149
2150 TempDICompileUnit clone() const { return cloneImpl(); }
2151
2152 DISourceLanguageName getSourceLanguage() const { return SourceLanguage; }
2153 bool isOptimized() const { return IsOptimized; }
2154 bool isDebugInfoForProfiling() const { return DebugInfoForProfiling; }
2155 unsigned getRuntimeVersion() const { return RuntimeVersion; }
2157 return (DebugEmissionKind)EmissionKind;
2158 }
2159 // Return true if this CU was compiled with debug info disabled
2160 bool isNoDebug() const { return EmissionKind == NoDebug; }
2162 return EmissionKind == DebugDirectivesOnly;
2163 }
2164 bool getDebugInfoForProfiling() const { return DebugInfoForProfiling; }
2166 return (DebugNameTableKind)NameTableKind;
2167 }
2168 bool getRangesBaseAddress() const { return RangesBaseAddress; }
2170 StringRef getFlags() const { return getStringOperand(2); }
2172 DICompositeTypeArray getEnumTypes() const {
2174 }
2175 DIScopeArray getRetainedTypes() const {
2177 }
2178 DIGlobalVariableExpressionArray getGlobalVariables() const {
2180 }
2181 DIImportedEntityArray getImportedEntities() const {
2183 }
2184 DIMacroNodeArray getMacros() const {
2186 }
2187 uint64_t getDWOId() const { return DWOId; }
2188 void setDWOId(uint64_t DwoId) { DWOId = DwoId; }
2189 bool getSplitDebugInlining() const { return SplitDebugInlining; }
2190 void setSplitDebugInlining(bool SplitDebugInlining) {
2191 this->SplitDebugInlining = SplitDebugInlining;
2192 }
2194 StringRef getSDK() const { return getStringOperand(10); }
2195
2201 Metadata *getRawEnumTypes() const { return getOperand(4); }
2205 Metadata *getRawMacros() const { return getOperand(8); }
2208
2209 /// Replace arrays.
2210 ///
2211 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
2212 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
2213 /// DICompileUnit should be fairly rare.
2214 /// @{
2215 void replaceEnumTypes(DICompositeTypeArray N) {
2216 replaceOperandWith(4, N.get());
2217 }
2218 void replaceRetainedTypes(DITypeArray N) { replaceOperandWith(5, N.get()); }
2219 void replaceGlobalVariables(DIGlobalVariableExpressionArray N) {
2220 replaceOperandWith(6, N.get());
2221 }
2222 void replaceImportedEntities(DIImportedEntityArray N) {
2223 replaceOperandWith(7, N.get());
2224 }
2225 void replaceMacros(DIMacroNodeArray N) { replaceOperandWith(8, N.get()); }
2226 /// @}
2227
2228 static bool classof(const Metadata *MD) {
2229 return MD->getMetadataID() == DICompileUnitKind;
2230 }
2231};
2232
2233/// A scope for locals.
2234///
2235/// A legal scope for lexical blocks, local variables, and debug info
2236/// locations. Subclasses are \a DISubprogram, \a DILexicalBlock, and \a
2237/// DILexicalBlockFile.
2238class DILocalScope : public DIScope {
2239protected:
2243 ~DILocalScope() = default;
2244
2245public:
2246 /// Get the subprogram for this scope.
2247 ///
2248 /// Return this if it's an \a DISubprogram; otherwise, look up the scope
2249 /// chain.
2251
2252 /// Traverses the scope chain rooted at RootScope until it hits a Subprogram,
2253 /// recreating the chain with "NewSP" instead.
2254 LLVM_ABI static DILocalScope *
2256 LLVMContext &Ctx,
2258
2259 /// Get the first non DILexicalBlockFile scope of this scope.
2260 ///
2261 /// Return this if it's not a \a DILexicalBlockFIle; otherwise, look up the
2262 /// scope chain.
2264
2265 static bool classof(const Metadata *MD) {
2266 return MD->getMetadataID() == DISubprogramKind ||
2267 MD->getMetadataID() == DILexicalBlockKind ||
2268 MD->getMetadataID() == DILexicalBlockFileKind;
2269 }
2270};
2271
2272/// Subprogram description. Uses SubclassData1.
2273class DISubprogram : public DILocalScope {
2274 friend class LLVMContextImpl;
2275 friend class MDNode;
2276
2277 unsigned Line;
2278 unsigned ScopeLine;
2279 unsigned VirtualIndex;
2280
2281 /// In the MS ABI, the implicit 'this' parameter is adjusted in the prologue
2282 /// of method overrides from secondary bases by this amount. It may be
2283 /// negative.
2284 int ThisAdjustment;
2285
2286public:
2287 /// Debug info subprogram flags.
2289#define HANDLE_DISP_FLAG(ID, NAME) SPFlag##NAME = ID,
2290#define DISP_FLAG_LARGEST_NEEDED
2291#include "llvm/IR/DebugInfoFlags.def"
2292 SPFlagNonvirtual = SPFlagZero,
2293 SPFlagVirtuality = SPFlagVirtual | SPFlagPureVirtual,
2294 LLVM_MARK_AS_BITMASK_ENUM(SPFlagLargest)
2295 };
2296
2297 LLVM_ABI static DISPFlags getFlag(StringRef Flag);
2298 LLVM_ABI static StringRef getFlagString(DISPFlags Flag);
2299
2300 /// Split up a flags bitfield for easier printing.
2301 ///
2302 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
2303 /// any remaining (unrecognized) bits.
2304 LLVM_ABI static DISPFlags splitFlags(DISPFlags Flags,
2305 SmallVectorImpl<DISPFlags> &SplitFlags);
2306
2307 // Helper for converting old bitfields to new flags word.
2308 LLVM_ABI static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition,
2309 bool IsOptimized,
2310 unsigned Virtuality = SPFlagNonvirtual,
2311 bool IsMainSubprogram = false);
2312
2313private:
2314 DIFlags Flags;
2315 DISPFlags SPFlags;
2316
2317 DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
2318 unsigned ScopeLine, unsigned VirtualIndex, int ThisAdjustment,
2319 DIFlags Flags, DISPFlags SPFlags, bool UsesKeyInstructions,
2321 ~DISubprogram() = default;
2322
2323 static DISubprogram *
2324 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
2325 StringRef LinkageName, DIFile *File, unsigned Line,
2327 unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags,
2328 DISPFlags SPFlags, DICompileUnit *Unit,
2329 DITemplateParameterArray TemplateParams, DISubprogram *Declaration,
2330 DINodeArray RetainedNodes, DITypeArray ThrownTypes,
2333 bool ShouldCreate = true) {
2334 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
2335 getCanonicalMDString(Context, LinkageName), File, Line, Type,
2337 Flags, SPFlags, Unit, TemplateParams.get(), Declaration,
2338 RetainedNodes.get(), ThrownTypes.get(), Annotations.get(),
2340 UsesKeyInstructions, Storage, ShouldCreate);
2341 }
2342
2343 LLVM_ABI static DISubprogram *
2344 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
2345 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
2346 unsigned ScopeLine, Metadata *ContainingType, unsigned VirtualIndex,
2347 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
2350 MDString *TargetFuncName, bool UsesKeyInstructions,
2351 StorageType Storage, bool ShouldCreate = true);
2352
2353 TempDISubprogram cloneImpl() const {
2355 getFile(), getLine(), getType(), getScopeLine(),
2356 getContainingType(), getVirtualIndex(),
2357 getThisAdjustment(), getFlags(), getSPFlags(),
2358 getUnit(), getTemplateParams(), getDeclaration(),
2359 getRetainedNodes(), getThrownTypes(), getAnnotations(),
2360 getTargetFuncName(), getKeyInstructionsEnabled());
2361 }
2362
2363public:
2365 DISubprogram,
2367 unsigned Line, DISubroutineType *Type, unsigned ScopeLine,
2368 DIType *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
2369 DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit,
2370 DITemplateParameterArray TemplateParams = nullptr,
2371 DISubprogram *Declaration = nullptr, DINodeArray RetainedNodes = nullptr,
2372 DITypeArray ThrownTypes = nullptr, DINodeArray Annotations = nullptr,
2373 StringRef TargetFuncName = "", bool UsesKeyInstructions = false),
2374 (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
2375 VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
2378
2380 DISubprogram,
2382 unsigned Line, Metadata *Type, unsigned ScopeLine,
2383 Metadata *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
2384 DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
2388 bool UsesKeyInstructions = false),
2389 (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
2390 VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
2393
2394 TempDISubprogram clone() const { return cloneImpl(); }
2395
2396 /// Returns a new temporary DISubprogram with updated Flags
2397 TempDISubprogram cloneWithFlags(DIFlags NewFlags) const {
2398 auto NewSP = clone();
2399 NewSP->Flags = NewFlags;
2400 return NewSP;
2401 }
2402
2403 bool getKeyInstructionsEnabled() const { return SubclassData1; }
2404
2405public:
2406 unsigned getLine() const { return Line; }
2407 unsigned getVirtuality() const { return getSPFlags() & SPFlagVirtuality; }
2408 unsigned getVirtualIndex() const { return VirtualIndex; }
2409 int getThisAdjustment() const { return ThisAdjustment; }
2410 unsigned getScopeLine() const { return ScopeLine; }
2411 void setScopeLine(unsigned L) {
2412 assert(isDistinct());
2413 ScopeLine = L;
2414 }
2415 DIFlags getFlags() const { return Flags; }
2416 DISPFlags getSPFlags() const { return SPFlags; }
2417 bool isLocalToUnit() const { return getSPFlags() & SPFlagLocalToUnit; }
2418 bool isDefinition() const { return getSPFlags() & SPFlagDefinition; }
2419 bool isOptimized() const { return getSPFlags() & SPFlagOptimized; }
2420 bool isMainSubprogram() const { return getSPFlags() & SPFlagMainSubprogram; }
2421
2422 bool isArtificial() const { return getFlags() & FlagArtificial; }
2423 bool isPrivate() const {
2424 return (getFlags() & FlagAccessibility) == FlagPrivate;
2425 }
2426 bool isProtected() const {
2427 return (getFlags() & FlagAccessibility) == FlagProtected;
2428 }
2429 bool isPublic() const {
2430 return (getFlags() & FlagAccessibility) == FlagPublic;
2431 }
2432 bool isExplicit() const { return getFlags() & FlagExplicit; }
2433 bool isPrototyped() const { return getFlags() & FlagPrototyped; }
2434 bool isNameSimplified() const { return getFlags() & FlagNameIsSimplified; }
2435 bool areAllCallsDescribed() const {
2436 return getFlags() & FlagAllCallsDescribed;
2437 }
2438 bool isPure() const { return getSPFlags() & SPFlagPure; }
2439 bool isElemental() const { return getSPFlags() & SPFlagElemental; }
2440 bool isRecursive() const { return getSPFlags() & SPFlagRecursive; }
2441 bool isObjCDirect() const { return getSPFlags() & SPFlagObjCDirect; }
2442
2443 /// Check if this is deleted member function.
2444 ///
2445 /// Return true if this subprogram is a C++11 special
2446 /// member function declared deleted.
2447 bool isDeleted() const { return getSPFlags() & SPFlagDeleted; }
2448
2449 /// Check if this is reference-qualified.
2450 ///
2451 /// Return true if this subprogram is a C++11 reference-qualified non-static
2452 /// member function (void foo() &).
2453 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
2454
2455 /// Check if this is rvalue-reference-qualified.
2456 ///
2457 /// Return true if this subprogram is a C++11 rvalue-reference-qualified
2458 /// non-static member function (void foo() &&).
2459 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
2460
2461 /// Check if this is marked as noreturn.
2462 ///
2463 /// Return true if this subprogram is C++11 noreturn or C11 _Noreturn
2464 bool isNoReturn() const { return getFlags() & FlagNoReturn; }
2465
2466 // Check if this routine is a compiler-generated thunk.
2467 //
2468 // Returns true if this subprogram is a thunk generated by the compiler.
2469 bool isThunk() const { return getFlags() & FlagThunk; }
2470
2471 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2472
2473 StringRef getName() const { return getStringOperand(2); }
2474 StringRef getLinkageName() const { return getStringOperand(3); }
2475 /// Only used by clients of CloneFunction, and only right after the cloning.
2476 void replaceLinkageName(MDString *LN) { replaceOperandWith(3, LN); }
2477
2478 DISubroutineType *getType() const {
2479 return cast_or_null<DISubroutineType>(getRawType());
2480 }
2481 DIType *getContainingType() const {
2482 return cast_or_null<DIType>(getRawContainingType());
2483 }
2484 void replaceType(DISubroutineType *Ty) {
2485 assert(isDistinct() && "Only distinct nodes can mutate");
2486 replaceOperandWith(4, Ty);
2487 }
2488
2489 DICompileUnit *getUnit() const {
2490 return cast_or_null<DICompileUnit>(getRawUnit());
2491 }
2492 void replaceUnit(DICompileUnit *CU) { replaceOperandWith(5, CU); }
2493 DITemplateParameterArray getTemplateParams() const {
2494 return cast_or_null<MDTuple>(getRawTemplateParams());
2495 }
2496 DISubprogram *getDeclaration() const {
2497 return cast_or_null<DISubprogram>(getRawDeclaration());
2498 }
2499 void replaceDeclaration(DISubprogram *Decl) { replaceOperandWith(6, Decl); }
2500 DINodeArray getRetainedNodes() const {
2501 return cast_or_null<MDTuple>(getRawRetainedNodes());
2502 }
2503 DITypeArray getThrownTypes() const {
2504 return cast_or_null<MDTuple>(getRawThrownTypes());
2505 }
2506 DINodeArray getAnnotations() const {
2507 return cast_or_null<MDTuple>(getRawAnnotations());
2508 }
2509 StringRef getTargetFuncName() const {
2510 return (getRawTargetFuncName()) ? getStringOperand(12) : StringRef();
2511 }
2512
2513 Metadata *getRawScope() const { return getOperand(1); }
2514 MDString *getRawName() const { return getOperandAs<MDString>(2); }
2515 MDString *getRawLinkageName() const { return getOperandAs<MDString>(3); }
2516 Metadata *getRawType() const { return getOperand(4); }
2517 Metadata *getRawUnit() const { return getOperand(5); }
2518 Metadata *getRawDeclaration() const { return getOperand(6); }
2519 Metadata *getRawRetainedNodes() const { return getOperand(7); }
2520 Metadata *getRawContainingType() const {
2521 return getNumOperands() > 8 ? getOperandAs<Metadata>(8) : nullptr;
2522 }
2523 Metadata *getRawTemplateParams() const {
2524 return getNumOperands() > 9 ? getOperandAs<Metadata>(9) : nullptr;
2525 }
2526 Metadata *getRawThrownTypes() const {
2527 return getNumOperands() > 10 ? getOperandAs<Metadata>(10) : nullptr;
2528 }
2529 Metadata *getRawAnnotations() const {
2530 return getNumOperands() > 11 ? getOperandAs<Metadata>(11) : nullptr;
2531 }
2532 MDString *getRawTargetFuncName() const {
2533 return getNumOperands() > 12 ? getOperandAs<MDString>(12) : nullptr;
2534 }
2535
2536 void replaceRawLinkageName(MDString *LinkageName) {
2538 }
2539 void replaceRetainedNodes(DINodeArray N) {
2540 replaceOperandWith(7, N.get());
2541 }
2542
2543 /// For the given retained node of DISubprogram, applies one of the
2544 /// given functions depending on the type of the node.
2545 template <typename T, typename MetadataT, typename FuncLVT,
2546 typename FuncLabelT, typename FuncImportedEntityT,
2547 typename FuncTypeT, typename FuncUnknownT>
2548 static T visitRetainedNode(MetadataT *N, FuncLVT &&FuncLV,
2549 FuncLabelT &&FuncLabel,
2550 FuncImportedEntityT &&FuncIE, FuncTypeT &&FuncType,
2551 FuncUnknownT &&FuncUnknown) {
2552 static_assert(std::is_base_of_v<Metadata, MetadataT>,
2553 "N must point to Metadata or const Metadata");
2554
2555 if (auto *LV = dyn_cast<DILocalVariable>(N))
2556 return FuncLV(LV);
2557 if (auto *L = dyn_cast<DILabel>(N))
2558 return FuncLabel(L);
2559 if (auto *IE = dyn_cast<DIImportedEntity>(N))
2560 return FuncIE(IE);
2561 if (auto *Ty = dyn_cast<DIType>(N))
2562 return FuncType(Ty);
2563 return FuncUnknown(N);
2564 }
2565
2566 /// Returns the scope of subprogram's retainedNodes.
2567 static const DILocalScope *getRetainedNodeScope(const MDNode *N);
2569 // For use in Verifier.
2570 static const DIScope *getRawRetainedNodeScope(const MDNode *N);
2572
2573 /// For each retained node, applies one of the given functions depending
2574 /// on the type of a node.
2575 template <typename FuncLVT, typename FuncLabelT, typename FuncImportedEntityT,
2576 typename FuncTypeT>
2577 void forEachRetainedNode(FuncLVT &&FuncLV, FuncLabelT &&FuncLabel,
2578 FuncImportedEntityT &&FuncIE, FuncTypeT &&FuncType) {
2579 for (MDNode *N : getRetainedNodes())
2580 visitRetainedNode<void>(
2581 N, FuncLV, FuncLabel, FuncIE, FuncType,
2582 [](auto *N) { llvm_unreachable("Unexpected retained node!"); });
2583 }
2584
2585 /// When IR modules are merged, typically during LTO, the merged module
2586 /// may contain several types having the same linkageName. They are
2587 /// supposed to represent the same type included by multiple source code
2588 /// files from a single header file.
2589 ///
2590 /// DebugTypeODRUniquing feature uniques (deduplicates) such types
2591 /// based on their linkageName during metadata loading, to speed up
2592 /// compilation and reduce debug info size.
2593 ///
2594 /// However, since function-local types are tracked in DISubprogram's
2595 /// retainedNodes field, a single local type may be referenced by multiple
2596 /// DISubprograms via retainedNodes as the result of DebugTypeODRUniquing.
2597 /// But retainedNodes field of a DISubprogram is meant to hold only
2598 /// subprogram's own local entities, therefore such references may
2599 /// cause crashes.
2600 ///
2601 /// To address this problem, this method is called for each new subprogram
2602 /// after module loading. It removes references to types belonging
2603 /// to other DISubprograms from a subprogram's retainedNodes list.
2604 /// If a corresponding IR function refers to local scopes from another
2605 /// subprogram, emitted debug info (e.g. DWARF) should rely
2606 /// on cross-subprogram references (and cross-CU references, as subprograms
2607 /// may belong to different compile units). This is also a drawback:
2608 /// when a subprogram refers to types that are local to another subprogram,
2609 /// it is more complicated for debugger to properly discover local types
2610 /// of a current scope for expression evaluation.
2611 void cleanupRetainedNodes();
2612
2613 /// Calls SP->cleanupRetainedNodes() for a range of DISubprograms.
2614 template <typename RangeT>
2615 static void cleanupRetainedNodes(const RangeT &NewDistinctSPs) {
2616 for (DISubprogram *SP : NewDistinctSPs)
2617 SP->cleanupRetainedNodes();
2618 }
2619
2620 /// Check if this subprogram describes the given function.
2621 ///
2622 /// FIXME: Should this be looking through bitcasts?
2623 LLVM_ABI bool describes(const Function *F) const;
2624
2625 static bool classof(const Metadata *MD) {
2626 return MD->getMetadataID() == DISubprogramKind;
2627 }
2628};
2629
2630/// Debug location.
2631///
2632/// A debug location in source code, used for debug info and otherwise.
2633///
2634/// Uses the SubclassData1, SubclassData16 and SubclassData32
2635/// Metadata slots.
2636
2637class DILocation : public MDNode {
2638 friend class LLVMContextImpl;
2639 friend class MDNode;
2640 uint64_t AtomGroup : 61;
2641 uint64_t AtomRank : 3;
2642
2643 DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
2644 unsigned Column, uint64_t AtomGroup, uint8_t AtomRank,
2646 ~DILocation() { dropAllReferences(); }
2647
2648 LLVM_ABI static DILocation *
2649 getImpl(LLVMContext &Context, unsigned Line, unsigned Column, Metadata *Scope,
2651 uint8_t AtomRank, StorageType Storage, bool ShouldCreate = true);
2652 static DILocation *getImpl(LLVMContext &Context, unsigned Line,
2653 unsigned Column, DILocalScope *Scope,
2656 StorageType Storage, bool ShouldCreate = true) {
2657 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
2658 static_cast<Metadata *>(InlinedAt), ImplicitCode, AtomGroup,
2659 AtomRank, Storage, ShouldCreate);
2660 }
2661
2662 TempDILocation cloneImpl() const {
2663 // Get the raw scope/inlinedAt since it is possible to invoke this on
2664 // a DILocation containing temporary metadata.
2665 return getTemporary(getContext(), getLine(), getColumn(), getRawScope(),
2666 getRawInlinedAt(), isImplicitCode(), getAtomGroup(),
2667 getAtomRank());
2668 }
2669
2670public:
2671 uint64_t getAtomGroup() const { return AtomGroup; }
2672 uint8_t getAtomRank() const { return AtomRank; }
2673
2674 const DILocation *getWithoutAtom() const {
2675 if (!getAtomGroup() && !getAtomRank())
2676 return this;
2677 return get(getContext(), getLine(), getColumn(), getScope(), getInlinedAt(),
2678 isImplicitCode());
2679 }
2680
2681 // Disallow replacing operands.
2682 void replaceOperandWith(unsigned I, Metadata *New) = delete;
2683
2685 (unsigned Line, unsigned Column, Metadata *Scope,
2686 Metadata *InlinedAt = nullptr, bool ImplicitCode = false,
2687 uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2688 (Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2689 AtomRank))
2690 DEFINE_MDNODE_GET(DILocation,
2691 (unsigned Line, unsigned Column, DILocalScope *Scope,
2692 DILocation *InlinedAt = nullptr, bool ImplicitCode = false,
2693 uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2694 (Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2695 AtomRank))
2696
2697 /// Return a (temporary) clone of this.
2698 TempDILocation clone() const { return cloneImpl(); }
2699
2700 unsigned getLine() const { return SubclassData32; }
2701 unsigned getColumn() const { return SubclassData16; }
2702 DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
2703
2704 /// Return the linkage name of Subprogram. If the linkage name is empty,
2705 /// return scope name (the demangled name).
2706 StringRef getSubprogramLinkageName() const {
2707 DISubprogram *SP = getScope()->getSubprogram();
2708 if (!SP)
2709 return "";
2710 auto Name = SP->getLinkageName();
2711 if (!Name.empty())
2712 return Name;
2713 return SP->getName();
2714 }
2715
2716 DILocation *getInlinedAt() const {
2718 }
2719
2720 /// Check if the location corresponds to an implicit code.
2721 /// When the ImplicitCode flag is true, it means that the Instruction
2722 /// with this DILocation has been added by the front-end but it hasn't been
2723 /// written explicitly by the user (e.g. cleanup stuff in C++ put on a closing
2724 /// bracket). It's useful for code coverage to not show a counter on "empty"
2725 /// lines.
2726 bool isImplicitCode() const { return SubclassData1; }
2727 void setImplicitCode(bool ImplicitCode) { SubclassData1 = ImplicitCode; }
2728
2729 DIFile *getFile() const { return getScope()->getFile(); }
2730 StringRef getFilename() const { return getScope()->getFilename(); }
2731 StringRef getDirectory() const { return getScope()->getDirectory(); }
2732 std::optional<StringRef> getSource() const { return getScope()->getSource(); }
2733
2734 /// Walk through \a getInlinedAt() and return the \a DILocation of the
2735 /// outermost call site in the inlining chain.
2736 const DILocation *getInlinedAtLocation() const {
2737 const DILocation *Current = this;
2738 while (const DILocation *Next = Current->getInlinedAt())
2739 Current = Next;
2740 return Current;
2741 }
2742
2743 // Return the \a DILocalScope of the outermost call site in the inlining
2744 // chain.
2745 DILocalScope *getInlinedAtScope() const {
2746 return getInlinedAtLocation()->getScope();
2747 }
2748
2749 /// Get the DWARF discriminator.
2750 ///
2751 /// DWARF discriminators distinguish identical file locations between
2752 /// instructions that are on different basic blocks.
2753 ///
2754 /// There are 3 components stored in discriminator, from lower bits:
2755 ///
2756 /// Base discriminator: assigned by AddDiscriminators pass to identify IRs
2757 /// that are defined by the same source line, but
2758 /// different basic blocks.
2759 /// Duplication factor: assigned by optimizations that will scale down
2760 /// the execution frequency of the original IR.
2761 /// Copy Identifier: assigned by optimizations that clones the IR.
2762 /// Each copy of the IR will be assigned an identifier.
2763 ///
2764 /// Encoding:
2765 ///
2766 /// The above 3 components are encoded into a 32bit unsigned integer in
2767 /// order. If the lowest bit is 1, the current component is empty, and the
2768 /// next component will start in the next bit. Otherwise, the current
2769 /// component is non-empty, and its content starts in the next bit. The
2770 /// value of each components is either 5 bit or 12 bit: if the 7th bit
2771 /// is 0, the bit 2~6 (5 bits) are used to represent the component; if the
2772 /// 7th bit is 1, the bit 2~6 (5 bits) and 8~14 (7 bits) are combined to
2773 /// represent the component. Thus, the number of bits used for a component
2774 /// is either 0 (if it and all the next components are empty); 1 - if it is
2775 /// empty; 7 - if its value is up to and including 0x1f (lsb and msb are both
2776 /// 0); or 14, if its value is up to and including 0x1ff. Note that the last
2777 /// component is also capped at 0x1ff, even in the case when both first
2778 /// components are 0, and we'd technically have 29 bits available.
2779 ///
2780 /// For precise control over the data being encoded in the discriminator,
2781 /// use encodeDiscriminator/decodeDiscriminator.
2782
2783 inline unsigned getDiscriminator() const;
2784
2785 // For the regular discriminator, it stands for all empty components if all
2786 // the lowest 3 bits are non-zero and all higher 29 bits are unused(zero by
2787 // default). Here we fully leverage the higher 29 bits for pseudo probe use.
2788 // This is the format:
2789 // [2:0] - 0x7
2790 // [31:3] - pseudo probe fields guaranteed to be non-zero as a whole
2791 // So if the lower 3 bits is non-zero and the others has at least one
2792 // non-zero bit, it guarantees to be a pseudo probe discriminator
2793 inline static bool isPseudoProbeDiscriminator(unsigned Discriminator) {
2794 return ((Discriminator & 0x7) == 0x7) && (Discriminator & 0xFFFFFFF8);
2795 }
2796
2797 /// Returns a new DILocation with updated \p Discriminator.
2798 inline const DILocation *cloneWithDiscriminator(unsigned Discriminator) const;
2799
2800 /// Returns a new DILocation with updated base discriminator \p BD. Only the
2801 /// base discriminator is set in the new DILocation, the other encoded values
2802 /// are elided.
2803 /// If the discriminator cannot be encoded, the function returns std::nullopt.
2804 inline std::optional<const DILocation *>
2805 cloneWithBaseDiscriminator(unsigned BD) const;
2806
2807 /// Returns the duplication factor stored in the discriminator, or 1 if no
2808 /// duplication factor (or 0) is encoded.
2809 inline unsigned getDuplicationFactor() const;
2810
2811 /// Returns the copy identifier stored in the discriminator.
2812 inline unsigned getCopyIdentifier() const;
2813
2814 /// Returns the base discriminator stored in the discriminator.
2815 inline unsigned getBaseDiscriminator() const;
2816
2817 /// Returns a new DILocation with duplication factor \p DF * current
2818 /// duplication factor encoded in the discriminator. The current duplication
2819 /// factor is as defined by getDuplicationFactor().
2820 /// Returns std::nullopt if encoding failed.
2821 inline std::optional<const DILocation *>
2823
2824 /// Attempts to merge \p LocA and \p LocB into a single location; see
2825 /// DebugLoc::getMergedLocation for more details.
2826 /// NB: When merging the locations of instructions, prefer to use
2827 /// DebugLoc::getMergedLocation(), as an instruction's DebugLoc may contain
2828 /// additional metadata that will not be preserved when merging the unwrapped
2829 /// DILocations.
2831 DILocation *LocB);
2832
2833 /// Try to combine the vector of locations passed as input in a single one.
2834 /// This function applies getMergedLocation() repeatedly left-to-right.
2835 /// NB: When merging the locations of instructions, prefer to use
2836 /// DebugLoc::getMergedLocations(), as an instruction's DebugLoc may contain
2837 /// additional metadata that will not be preserved when merging the unwrapped
2838 /// DILocations.
2839 ///
2840 /// \p Locs: The locations to be merged.
2842
2843 /// Return the masked discriminator value for an input discrimnator value D
2844 /// (i.e. zero out the (B+1)-th and above bits for D (B is 0-base).
2845 // Example: an input of (0x1FF, 7) returns 0xFF.
2846 static unsigned getMaskedDiscriminator(unsigned D, unsigned B) {
2847 return (D & getN1Bits(B));
2848 }
2849
2850 /// Return the bits used for base discriminators.
2851 static unsigned getBaseDiscriminatorBits() { return getBaseFSBitEnd(); }
2852
2853 /// Returns the base discriminator for a given encoded discriminator \p D.
2854 static unsigned
2856 bool IsFSDiscriminator = false) {
2857 // Extract the dwarf base discriminator if it's encoded in the pseudo probe
2858 // discriminator.
2860 auto DwarfBaseDiscriminator =
2862 if (DwarfBaseDiscriminator)
2863 return *DwarfBaseDiscriminator;
2864 // Return the probe id instead of zero for a pseudo probe discriminator.
2865 // This should help differenciate callsites with same line numbers to
2866 // achieve a decent AutoFDO profile under -fpseudo-probe-for-profiling,
2867 // where the original callsite dwarf discriminator is overwritten by
2868 // callsite probe information.
2870 }
2871
2872 if (IsFSDiscriminator)
2875 }
2876
2877 /// Raw encoding of the discriminator. APIs such as cloneWithDuplicationFactor
2878 /// have certain special case behavior (e.g. treating empty duplication factor
2879 /// as the value '1').
2880 /// This API, in conjunction with cloneWithDiscriminator, may be used to
2881 /// encode the raw values provided.
2882 ///
2883 /// \p BD: base discriminator
2884 /// \p DF: duplication factor
2885 /// \p CI: copy index
2886 ///
2887 /// The return is std::nullopt if the values cannot be encoded in 32 bits -
2888 /// for example, values for BD or DF larger than 12 bits. Otherwise, the
2889 /// return is the encoded value.
2890 LLVM_ABI static std::optional<unsigned>
2891 encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI);
2892
2893 /// Raw decoder for values in an encoded discriminator D.
2894 LLVM_ABI static void decodeDiscriminator(unsigned D, unsigned &BD,
2895 unsigned &DF, unsigned &CI);
2896
2897 /// Returns the duplication factor for a given encoded discriminator \p D, or
2898 /// 1 if no value or 0 is encoded.
2899 static unsigned getDuplicationFactorFromDiscriminator(unsigned D) {
2901 return 1;
2903 unsigned Ret = getUnsignedFromPrefixEncoding(D);
2904 if (Ret == 0)
2905 return 1;
2906 return Ret;
2907 }
2908
2909 /// Returns the copy identifier for a given encoded discriminator \p D.
2914
2915 Metadata *getRawScope() const { return getOperand(0); }
2917 if (getNumOperands() == 2)
2918 return getOperand(1);
2919 return nullptr;
2920 }
2921
2922 static bool classof(const Metadata *MD) {
2923 return MD->getMetadataID() == DILocationKind;
2924 }
2925};
2926
2928protected:
2932
2933public:
2935
2936 Metadata *getRawScope() const { return getOperand(1); }
2937
2938 void replaceScope(DIScope *Scope) {
2939 assert(!isUniqued());
2940 setOperand(1, Scope);
2941 }
2942
2943 static bool classof(const Metadata *MD) {
2944 return MD->getMetadataID() == DILexicalBlockKind ||
2945 MD->getMetadataID() == DILexicalBlockFileKind;
2946 }
2947};
2948
2949/// Debug lexical block.
2950///
2951/// Uses the SubclassData32 Metadata slot.
2952class DILexicalBlock : public DILexicalBlockBase {
2953 friend class LLVMContextImpl;
2954 friend class MDNode;
2955
2956 uint16_t Column;
2957
2958 DILexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
2959 unsigned Column, ArrayRef<Metadata *> Ops)
2960 : DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops),
2961 Column(Column) {
2963 assert(Column < (1u << 16) && "Expected 16-bit column");
2964 }
2965 ~DILexicalBlock() = default;
2966
2967 static DILexicalBlock *getImpl(LLVMContext &Context, DILocalScope *Scope,
2968 DIFile *File, unsigned Line, unsigned Column,
2970 bool ShouldCreate = true) {
2971 return getImpl(Context, static_cast<Metadata *>(Scope),
2972 static_cast<Metadata *>(File), Line, Column, Storage,
2973 ShouldCreate);
2974 }
2975
2976 LLVM_ABI static DILexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
2977 Metadata *File, unsigned Line,
2978 unsigned Column, StorageType Storage,
2979 bool ShouldCreate = true);
2980
2981 TempDILexicalBlock cloneImpl() const {
2983 getColumn());
2984 }
2985
2986public:
2987 DEFINE_MDNODE_GET(DILexicalBlock,
2988 (DILocalScope * Scope, DIFile *File, unsigned Line,
2989 unsigned Column),
2990 (Scope, File, Line, Column))
2991 DEFINE_MDNODE_GET(DILexicalBlock,
2993 unsigned Column),
2994 (Scope, File, Line, Column))
2995
2996 TempDILexicalBlock clone() const { return cloneImpl(); }
2997
2998 unsigned getLine() const { return SubclassData32; }
2999 unsigned getColumn() const { return Column; }
3000
3001 static bool classof(const Metadata *MD) {
3002 return MD->getMetadataID() == DILexicalBlockKind;
3003 }
3004};
3005
3006class DILexicalBlockFile : public DILexicalBlockBase {
3007 friend class LLVMContextImpl;
3008 friend class MDNode;
3009
3010 DILexicalBlockFile(LLVMContext &C, StorageType Storage,
3012 : DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops) {
3014 }
3015 ~DILexicalBlockFile() = default;
3016
3017 static DILexicalBlockFile *getImpl(LLVMContext &Context, DILocalScope *Scope,
3018 DIFile *File, unsigned Discriminator,
3020 bool ShouldCreate = true) {
3021 return getImpl(Context, static_cast<Metadata *>(Scope),
3022 static_cast<Metadata *>(File), Discriminator, Storage,
3023 ShouldCreate);
3024 }
3025
3026 LLVM_ABI static DILexicalBlockFile *getImpl(LLVMContext &Context,
3027 Metadata *Scope, Metadata *File,
3028 unsigned Discriminator,
3030 bool ShouldCreate = true);
3031
3032 TempDILexicalBlockFile cloneImpl() const {
3033 return getTemporary(getContext(), getScope(), getFile(),
3035 }
3036
3037public:
3038 DEFINE_MDNODE_GET(DILexicalBlockFile,
3040 unsigned Discriminator),
3042 DEFINE_MDNODE_GET(DILexicalBlockFile,
3045
3046 TempDILexicalBlockFile clone() const { return cloneImpl(); }
3047 unsigned getDiscriminator() const { return SubclassData32; }
3048
3049 static bool classof(const Metadata *MD) {
3050 return MD->getMetadataID() == DILexicalBlockFileKind;
3051 }
3052};
3053
3054unsigned DILocation::getDiscriminator() const {
3055 if (auto *F = dyn_cast<DILexicalBlockFile>(getScope()))
3056 return F->getDiscriminator();
3057 return 0;
3058}
3059
3060const DILocation *
3061DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
3062 DIScope *Scope = getScope();
3063 // Skip all parent DILexicalBlockFile that already have a discriminator
3064 // assigned. We do not want to have nested DILexicalBlockFiles that have
3065 // multiple discriminators because only the leaf DILexicalBlockFile's
3066 // dominator will be used.
3067 for (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope);
3068 LBF && LBF->getDiscriminator() != 0;
3070 Scope = LBF->getScope();
3071 DILexicalBlockFile *NewScope =
3072 DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator);
3073 return DILocation::get(getContext(), getLine(), getColumn(), NewScope,
3074 getInlinedAt(), isImplicitCode(), getAtomGroup(),
3075 getAtomRank());
3076}
3077
3079 return getBaseDiscriminatorFromDiscriminator(getDiscriminator(),
3081}
3082
3084 return getDuplicationFactorFromDiscriminator(getDiscriminator());
3085}
3086
3088 return getCopyIdentifierFromDiscriminator(getDiscriminator());
3089}
3090
3091std::optional<const DILocation *>
3093 // Do not interfere with pseudo probes. Pseudo probe at a callsite uses
3094 // the dwarf discriminator to store pseudo probe related information,
3095 // such as the probe id.
3096 if (isPseudoProbeDiscriminator(getDiscriminator()))
3097 return this;
3098
3099 unsigned BD, DF, CI;
3100
3102 BD = getBaseDiscriminator();
3103 if (D == BD)
3104 return this;
3105 return cloneWithDiscriminator(D);
3106 }
3107
3108 decodeDiscriminator(getDiscriminator(), BD, DF, CI);
3109 if (D == BD)
3110 return this;
3111 if (std::optional<unsigned> Encoded = encodeDiscriminator(D, DF, CI))
3112 return cloneWithDiscriminator(*Encoded);
3113 return std::nullopt;
3114}
3115
3116std::optional<const DILocation *>
3118 assert(!EnableFSDiscriminator && "FSDiscriminator should not call this.");
3119 // Do no interfere with pseudo probes. Pseudo probe doesn't need duplication
3120 // factor support as samples collected on cloned probes will be aggregated.
3121 // Also pseudo probe at a callsite uses the dwarf discriminator to store
3122 // pseudo probe related information, such as the probe id.
3123 if (isPseudoProbeDiscriminator(getDiscriminator()))
3124 return this;
3125
3127 if (DF <= 1)
3128 return this;
3129
3130 unsigned BD = getBaseDiscriminator();
3131 unsigned CI = getCopyIdentifier();
3132 if (std::optional<unsigned> D = encodeDiscriminator(BD, DF, CI))
3133 return cloneWithDiscriminator(*D);
3134 return std::nullopt;
3135}
3136
3137/// Debug lexical block.
3138///
3139/// Uses the SubclassData1 Metadata slot.
3140class DINamespace : public DIScope {
3141 friend class LLVMContextImpl;
3142 friend class MDNode;
3143
3144 DINamespace(LLVMContext &Context, StorageType Storage, bool ExportSymbols,
3146 ~DINamespace() = default;
3147
3148 static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope,
3150 StorageType Storage, bool ShouldCreate = true) {
3151 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
3152 ExportSymbols, Storage, ShouldCreate);
3153 }
3154 LLVM_ABI static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope,
3157 bool ShouldCreate = true);
3158
3159 TempDINamespace cloneImpl() const {
3160 return getTemporary(getContext(), getScope(), getName(),
3162 }
3163
3164public:
3168 DEFINE_MDNODE_GET(DINamespace,
3171
3172 TempDINamespace clone() const { return cloneImpl(); }
3173
3174 bool getExportSymbols() const { return SubclassData1; }
3176 StringRef getName() const { return getStringOperand(2); }
3177
3178 Metadata *getRawScope() const { return getOperand(1); }
3180
3181 static bool classof(const Metadata *MD) {
3182 return MD->getMetadataID() == DINamespaceKind;
3183 }
3184};
3185
3186/// Represents a module in the programming language, for example, a Clang
3187/// module, or a Fortran module.
3188///
3189/// Uses the SubclassData1 and SubclassData32 Metadata slots.
3190class DIModule : public DIScope {
3191 friend class LLVMContextImpl;
3192 friend class MDNode;
3193
3194 DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo,
3195 bool IsDecl, ArrayRef<Metadata *> Ops);
3196 ~DIModule() = default;
3197
3198 static DIModule *getImpl(LLVMContext &Context, DIFile *File, DIScope *Scope,
3201 unsigned LineNo, bool IsDecl, StorageType Storage,
3202 bool ShouldCreate = true) {
3203 return getImpl(Context, File, Scope, getCanonicalMDString(Context, Name),
3206 getCanonicalMDString(Context, APINotesFile), LineNo, IsDecl,
3207 Storage, ShouldCreate);
3208 }
3209 LLVM_ABI static DIModule *
3210 getImpl(LLVMContext &Context, Metadata *File, Metadata *Scope, MDString *Name,
3212 MDString *APINotesFile, unsigned LineNo, bool IsDecl,
3213 StorageType Storage, bool ShouldCreate = true);
3214
3215 TempDIModule cloneImpl() const {
3217 getConfigurationMacros(), getIncludePath(),
3218 getAPINotesFile(), getLineNo(), getIsDecl());
3219 }
3220
3221public:
3225 StringRef APINotesFile, unsigned LineNo,
3226 bool IsDecl = false),
3228 APINotesFile, LineNo, IsDecl))
3229 DEFINE_MDNODE_GET(DIModule,
3233 bool IsDecl = false),
3235 APINotesFile, LineNo, IsDecl))
3236
3237 TempDIModule clone() const { return cloneImpl(); }
3238
3239 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
3240 StringRef getName() const { return getStringOperand(2); }
3241 StringRef getConfigurationMacros() const { return getStringOperand(3); }
3242 StringRef getIncludePath() const { return getStringOperand(4); }
3243 StringRef getAPINotesFile() const { return getStringOperand(5); }
3244 unsigned getLineNo() const { return SubclassData32; }
3245 bool getIsDecl() const { return SubclassData1; }
3246
3247 Metadata *getRawScope() const { return getOperand(1); }
3248 MDString *getRawName() const { return getOperandAs<MDString>(2); }
3249 MDString *getRawConfigurationMacros() const {
3250 return getOperandAs<MDString>(3);
3251 }
3252 MDString *getRawIncludePath() const { return getOperandAs<MDString>(4); }
3253 MDString *getRawAPINotesFile() const { return getOperandAs<MDString>(5); }
3254
3255 static bool classof(const Metadata *MD) {
3256 return MD->getMetadataID() == DIModuleKind;
3257 }
3258};
3259
3260/// Base class for template parameters.
3261///
3262/// Uses the SubclassData1 Metadata slot.
3264protected:
3266 unsigned Tag, bool IsDefault, ArrayRef<Metadata *> Ops)
3267 : DINode(Context, ID, Storage, Tag, Ops) {
3268 SubclassData1 = IsDefault;
3269 }
3271
3272public:
3273 StringRef getName() const { return getStringOperand(0); }
3275
3277 Metadata *getRawType() const { return getOperand(1); }
3278 bool isDefault() const { return SubclassData1; }
3279
3280 static bool classof(const Metadata *MD) {
3281 return MD->getMetadataID() == DITemplateTypeParameterKind ||
3282 MD->getMetadataID() == DITemplateValueParameterKind;
3283 }
3284};
3285
3286class DITemplateTypeParameter : public DITemplateParameter {
3287 friend class LLVMContextImpl;
3288 friend class MDNode;
3289
3290 DITemplateTypeParameter(LLVMContext &Context, StorageType Storage,
3292 ~DITemplateTypeParameter() = default;
3293
3294 static DITemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
3295 DIType *Type, bool IsDefault,
3297 bool ShouldCreate = true) {
3298 return getImpl(Context, getCanonicalMDString(Context, Name), Type,
3299 IsDefault, Storage, ShouldCreate);
3300 }
3302 getImpl(LLVMContext &Context, MDString *Name, Metadata *Type, bool IsDefault,
3303 StorageType Storage, bool ShouldCreate = true);
3304
3305 TempDITemplateTypeParameter cloneImpl() const {
3306 return getTemporary(getContext(), getName(), getType(), isDefault());
3307 }
3308
3309public:
3310 DEFINE_MDNODE_GET(DITemplateTypeParameter,
3312 (Name, Type, IsDefault))
3313 DEFINE_MDNODE_GET(DITemplateTypeParameter,
3316
3317 TempDITemplateTypeParameter clone() const { return cloneImpl(); }
3318
3319 static bool classof(const Metadata *MD) {
3320 return MD->getMetadataID() == DITemplateTypeParameterKind;
3321 }
3322};
3323
3324class DITemplateValueParameter : public DITemplateParameter {
3325 friend class LLVMContextImpl;
3326 friend class MDNode;
3327
3328 DITemplateValueParameter(LLVMContext &Context, StorageType Storage,
3329 unsigned Tag, bool IsDefault,
3331 : DITemplateParameter(Context, DITemplateValueParameterKind, Storage, Tag,
3332 IsDefault, Ops) {}
3333 ~DITemplateValueParameter() = default;
3334
3335 static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
3337 bool IsDefault, Metadata *Value,
3339 bool ShouldCreate = true) {
3340 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
3341 IsDefault, Value, Storage, ShouldCreate);
3342 }
3343 LLVM_ABI static DITemplateValueParameter *
3344 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
3345 bool IsDefault, Metadata *Value, StorageType Storage,
3346 bool ShouldCreate = true);
3347
3348 TempDITemplateValueParameter cloneImpl() const {
3349 return getTemporary(getContext(), getTag(), getName(), getType(),
3350 isDefault(), getValue());
3351 }
3352
3353public:
3354 DEFINE_MDNODE_GET(DITemplateValueParameter,
3355 (unsigned Tag, StringRef Name, DIType *Type, bool IsDefault,
3356 Metadata *Value),
3357 (Tag, Name, Type, IsDefault, Value))
3358 DEFINE_MDNODE_GET(DITemplateValueParameter,
3362
3363 TempDITemplateValueParameter clone() const { return cloneImpl(); }
3364
3365 Metadata *getValue() const { return getOperand(2); }
3366
3367 static bool classof(const Metadata *MD) {
3368 return MD->getMetadataID() == DITemplateValueParameterKind;
3369 }
3370};
3371
3372/// Base class for variables.
3373///
3374/// Uses the SubclassData32 Metadata slot.
3375class DIVariable : public DINode {
3376 unsigned Line;
3377
3378protected:
3380 signed Line, ArrayRef<Metadata *> Ops,
3381 uint32_t AlignInBits = 0);
3382 ~DIVariable() = default;
3383
3384public:
3385 unsigned getLine() const { return Line; }
3387 StringRef getName() const { return getStringOperand(1); }
3391 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
3392 /// Determines the size of the variable's type.
3393 LLVM_ABI std::optional<uint64_t> getSizeInBits() const;
3394
3395 /// Return the signedness of this variable's type, or std::nullopt if this
3396 /// type is neither signed nor unsigned.
3397 std::optional<DIBasicType::Signedness> getSignedness() const {
3398 if (auto *BT = dyn_cast<DIBasicType>(getType()))
3399 return BT->getSignedness();
3400 return std::nullopt;
3401 }
3402
3404 if (auto *F = getFile())
3405 return F->getFilename();
3406 return "";
3407 }
3408
3410 if (auto *F = getFile())
3411 return F->getDirectory();
3412 return "";
3413 }
3414
3415 std::optional<StringRef> getSource() const {
3416 if (auto *F = getFile())
3417 return F->getSource();
3418 return std::nullopt;
3419 }
3420
3421 Metadata *getRawScope() const { return getOperand(0); }
3423 Metadata *getRawFile() const { return getOperand(2); }
3424 Metadata *getRawType() const { return getOperand(3); }
3425
3426 static bool classof(const Metadata *MD) {
3427 return MD->getMetadataID() == DILocalVariableKind ||
3428 MD->getMetadataID() == DIGlobalVariableKind;
3429 }
3430};
3431
3432/// DWARF expression.
3433///
3434/// This is (almost) a DWARF expression that modifies the location of a
3435/// variable, or the location of a single piece of a variable, or (when using
3436/// DW_OP_stack_value) is the constant variable value.
3437///
3438/// TODO: Co-allocate the expression elements.
3439/// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
3440/// storage types.
3441class DIExpression : public MDNode {
3442 friend class LLVMContextImpl;
3443 friend class MDNode;
3444
3445 std::vector<uint64_t> Elements;
3446
3447 DIExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
3448 : MDNode(C, DIExpressionKind, Storage, {}),
3449 Elements(Elements.begin(), Elements.end()) {}
3450 ~DIExpression() = default;
3451
3452 LLVM_ABI static DIExpression *getImpl(LLVMContext &Context,
3453 ArrayRef<uint64_t> Elements,
3455 bool ShouldCreate = true);
3456
3457 TempDIExpression cloneImpl() const {
3458 return getTemporary(getContext(), getElements());
3459 }
3460
3461public:
3462 DEFINE_MDNODE_GET(DIExpression, (ArrayRef<uint64_t> Elements), (Elements))
3463
3464 TempDIExpression clone() const { return cloneImpl(); }
3465
3466 ArrayRef<uint64_t> getElements() const { return Elements; }
3467
3468 unsigned getNumElements() const { return Elements.size(); }
3469
3470 uint64_t getElement(unsigned I) const {
3471 assert(I < Elements.size() && "Index out of range");
3472 return Elements[I];
3473 }
3474
3476 /// Determine whether this represents a constant value, if so
3477 // return it's sign information.
3478 LLVM_ABI std::optional<SignedOrUnsignedConstant> isConstant() const;
3479
3480 /// Return the number of unique location operands referred to (via
3481 /// DW_OP_LLVM_arg) in this expression; this is not necessarily the number of
3482 /// instances of DW_OP_LLVM_arg within the expression.
3483 /// For example, for the expression:
3484 /// (DW_OP_LLVM_arg 0, DW_OP_LLVM_arg 1, DW_OP_plus,
3485 /// DW_OP_LLVM_arg 0, DW_OP_mul)
3486 /// This function would return 2, as there are two unique location operands
3487 /// (0 and 1).
3489
3491
3494
3495 /// A lightweight wrapper around an expression operand.
3496 ///
3497 /// TODO: Store arguments directly and change \a DIExpression to store a
3498 /// range of these.
3500 const uint64_t *Op = nullptr;
3501
3502 public:
3503 ExprOperand() = default;
3504 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
3505
3506 const uint64_t *get() const { return Op; }
3507
3508 /// Get the operand code.
3509 uint64_t getOp() const { return *Op; }
3510
3511 /// Get an argument to the operand.
3512 ///
3513 /// Never returns the operand itself.
3514 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
3515
3516 unsigned getNumArgs() const { return getSize() - 1; }
3517
3518 /// Return the size of the operand.
3519 ///
3520 /// Return the number of elements in the operand (1 + args).
3521 LLVM_ABI unsigned getSize() const;
3522
3523 /// Append the elements of this operand to \p V.
3525 V.append(get(), get() + getSize());
3526 }
3527 };
3528
3529 /// An iterator for expression operands.
3531 ExprOperand Op;
3532
3533 public:
3534 using iterator_category = std::input_iterator_tag;
3536 using difference_type = std::ptrdiff_t;
3539
3540 expr_op_iterator() = default;
3542
3543 element_iterator getBase() const { return Op.get(); }
3544 const ExprOperand &operator*() const { return Op; }
3545 const ExprOperand *operator->() const { return &Op; }
3546
3548 increment();
3549 return *this;
3550 }
3552 expr_op_iterator T(*this);
3553 increment();
3554 return T;
3555 }
3556
3557 /// Get the next iterator.
3558 ///
3559 /// \a std::next() doesn't work because this is technically an
3560 /// input_iterator, but it's a perfectly valid operation. This is an
3561 /// accessor to provide the same functionality.
3562 expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
3563
3564 bool operator==(const expr_op_iterator &X) const {
3565 return getBase() == X.getBase();
3566 }
3567 bool operator!=(const expr_op_iterator &X) const {
3568 return getBase() != X.getBase();
3569 }
3570
3571 private:
3572 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
3573 };
3574
3575 /// Visit the elements via ExprOperand wrappers.
3576 ///
3577 /// These range iterators visit elements through \a ExprOperand wrappers.
3578 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
3579 /// true.
3580 ///
3581 /// \pre \a isValid() gives \c true.
3582 /// @{
3592 /// @}
3593
3594 LLVM_ABI bool isValid() const;
3595
3596 static bool classof(const Metadata *MD) {
3597 return MD->getMetadataID() == DIExpressionKind;
3598 }
3599
3600 /// Return whether the first element a DW_OP_deref.
3601 LLVM_ABI bool startsWithDeref() const;
3602
3603 /// Return whether there is exactly one operator and it is a DW_OP_deref;
3604 LLVM_ABI bool isDeref() const;
3605
3607
3608 /// Return the number of bits that have an active value, i.e. those that
3609 /// aren't known to be zero/sign (depending on the type of Var) and which
3610 /// are within the size of this fragment (if it is one). If we can't deduce
3611 /// anything from the expression this will return the size of Var.
3612 LLVM_ABI std::optional<uint64_t> getActiveBits(DIVariable *Var);
3613
3614 /// Retrieve the details of this fragment expression.
3615 LLVM_ABI static std::optional<FragmentInfo>
3617
3618 /// Retrieve the details of this fragment expression.
3619 std::optional<FragmentInfo> getFragmentInfo() const {
3621 }
3622
3623 /// Return whether this is a piece of an aggregate variable.
3624 bool isFragment() const { return getFragmentInfo().has_value(); }
3625
3626 /// Return whether this is an implicit location description.
3627 LLVM_ABI bool isImplicit() const;
3628
3629 /// Return whether the location is computed on the expression stack, meaning
3630 /// it cannot be a simple register location.
3631 LLVM_ABI bool isComplex() const;
3632
3633 /// Return whether the evaluated expression makes use of a single location at
3634 /// the start of the expression, i.e. if it contains only a single
3635 /// DW_OP_LLVM_arg op as its first operand, or if it contains none.
3637
3638 /// Returns a reference to the elements contained in this expression, skipping
3639 /// past the leading `DW_OP_LLVM_arg, 0` if one is present.
3640 /// Similar to `convertToNonVariadicExpression`, but faster and cheaper - it
3641 /// does not check whether the expression is a single-location expression, and
3642 /// it returns elements rather than creating a new DIExpression.
3643 LLVM_ABI std::optional<ArrayRef<uint64_t>>
3645
3646 /// Removes all elements from \p Expr that do not apply to an undef debug
3647 /// value, which includes every operator that computes the value/location on
3648 /// the DWARF stack, including any DW_OP_LLVM_arg elements (making the result
3649 /// of this function always a single-location expression) while leaving
3650 /// everything that defines what the computed value applies to, i.e. the
3651 /// fragment information.
3652 LLVM_ABI static const DIExpression *
3654
3655 /// If \p Expr is a non-variadic expression (i.e. one that does not contain
3656 /// DW_OP_LLVM_arg), returns \p Expr converted to variadic form by adding a
3657 /// leading [DW_OP_LLVM_arg, 0] to the expression; otherwise returns \p Expr.
3658 LLVM_ABI static const DIExpression *
3660
3661 /// If \p Expr is a valid single-location expression, i.e. it refers to only a
3662 /// single debug operand at the start of the expression, then return that
3663 /// expression in a non-variadic form by removing DW_OP_LLVM_arg from the
3664 /// expression if it is present; otherwise returns std::nullopt.
3665 /// See also `getSingleLocationExpressionElements` above, which skips
3666 /// checking `isSingleLocationExpression` and returns a list of elements
3667 /// rather than a DIExpression.
3668 LLVM_ABI static std::optional<const DIExpression *>
3670
3671 /// Inserts the elements of \p Expr into \p Ops modified to a canonical form,
3672 /// which uses DW_OP_LLVM_arg (i.e. is a variadic expression) and folds the
3673 /// implied derefence from the \p IsIndirect flag into the expression. This
3674 /// allows us to check equivalence between expressions with differing
3675 /// directness or variadicness.
3677 const DIExpression *Expr,
3678 bool IsIndirect);
3679
3680 /// Determines whether two debug values should produce equivalent DWARF
3681 /// expressions, using their DIExpressions and directness, ignoring the
3682 /// differences between otherwise identical expressions in variadic and
3683 /// non-variadic form and not considering the debug operands.
3684 /// \p FirstExpr is the DIExpression for the first debug value.
3685 /// \p FirstIndirect should be true if the first debug value is indirect; in
3686 /// IR this should be true for dbg.declare intrinsics and false for
3687 /// dbg.values, and in MIR this should be true only for DBG_VALUE instructions
3688 /// whose second operand is an immediate value.
3689 /// \p SecondExpr and \p SecondIndirect have the same meaning as the prior
3690 /// arguments, but apply to the second debug value.
3691 LLVM_ABI static bool isEqualExpression(const DIExpression *FirstExpr,
3692 bool FirstIndirect,
3693 const DIExpression *SecondExpr,
3694 bool SecondIndirect);
3695
3696 /// Append \p Ops with operations to apply the \p Offset.
3698 int64_t Offset);
3699
3700 LLVM_ABI static bool
3701 extractLeadingOffset(ArrayRef<uint64_t> Ops, int64_t &OffsetInBytes,
3702 SmallVectorImpl<uint64_t> &RemainingOps);
3703
3704 /// If this is a constant offset, extract it. If there is no expression,
3705 /// return true with an offset of zero.
3706 LLVM_ABI bool extractIfOffset(int64_t &Offset) const;
3707
3708 /// Assuming that the expression operates on an address, extract a constant
3709 /// offset and the successive ops. Return false if the expression contains
3710 /// any incompatible ops (including non-zero DW_OP_LLVM_args - only a single
3711 /// address operand to the expression is permitted).
3712 ///
3713 /// We don't try very hard to interpret the expression because we assume that
3714 /// foldConstantMath has canonicalized the expression.
3715 LLVM_ABI bool
3716 extractLeadingOffset(int64_t &OffsetInBytes,
3717 SmallVectorImpl<uint64_t> &RemainingOps) const;
3718
3719 /// Returns true iff this DIExpression contains at least one instance of
3720 /// `DW_OP_LLVM_arg, n` for all n in [0, N).
3721 LLVM_ABI bool hasAllLocationOps(unsigned N) const;
3722
3723 /// Checks if the last 4 elements of the expression are DW_OP_constu <DWARF
3724 /// Address Space> DW_OP_swap DW_OP_xderef and extracts the <DWARF Address
3725 /// Space>.
3726 LLVM_ABI static const DIExpression *
3727 extractAddressClass(const DIExpression *Expr, unsigned &AddrClass);
3728
3729 /// Used for DIExpression::prepend.
3732 DerefBefore = 1 << 0,
3733 DerefAfter = 1 << 1,
3734 StackValue = 1 << 2,
3735 EntryValue = 1 << 3
3736 };
3737
3738 /// Prepend \p DIExpr with a deref and offset operation and optionally turn it
3739 /// into a stack value or/and an entry value.
3740 LLVM_ABI static DIExpression *prepend(const DIExpression *Expr, uint8_t Flags,
3741 int64_t Offset = 0);
3742
3743 /// Prepend \p DIExpr with the given opcodes and optionally turn it into a
3744 /// stack value.
3747 bool StackValue = false,
3748 bool EntryValue = false);
3749
3750 /// Append the opcodes \p Ops to \p DIExpr. Unlike \ref appendToStack, the
3751 /// returned expression is a stack value only if \p DIExpr is a stack value.
3752 /// If \p DIExpr describes a fragment, the returned expression will describe
3753 /// the same fragment.
3754 LLVM_ABI static DIExpression *append(const DIExpression *Expr,
3756
3757 /// Convert \p DIExpr into a stack value if it isn't one already by appending
3758 /// DW_OP_deref if needed, and appending \p Ops to the resulting expression.
3759 /// If \p DIExpr describes a fragment, the returned expression will describe
3760 /// the same fragment.
3761 LLVM_ABI static DIExpression *appendToStack(const DIExpression *Expr,
3763
3764 /// Create a copy of \p Expr by appending the given list of \p Ops to each
3765 /// instance of the operand `DW_OP_LLVM_arg, \p ArgNo`. This is used to
3766 /// modify a specific location used by \p Expr, such as when salvaging that
3767 /// location.
3770 unsigned ArgNo,
3771 bool StackValue = false);
3772
3773 /// Create a copy of \p Expr with each instance of
3774 /// `DW_OP_LLVM_arg, \p OldArg` replaced with `DW_OP_LLVM_arg, \p NewArg`,
3775 /// and each instance of `DW_OP_LLVM_arg, Arg` with `DW_OP_LLVM_arg, Arg - 1`
3776 /// for all Arg > \p OldArg.
3777 /// This is used when replacing one of the operands of a debug value list
3778 /// with another operand in the same list and deleting the old operand.
3779 LLVM_ABI static DIExpression *replaceArg(const DIExpression *Expr,
3780 uint64_t OldArg, uint64_t NewArg);
3781
3782 /// Create a DIExpression to describe one part of an aggregate variable that
3783 /// is fragmented across multiple Values. The DW_OP_LLVM_fragment operation
3784 /// will be appended to the elements of \c Expr. If \c Expr already contains
3785 /// a \c DW_OP_LLVM_fragment \c OffsetInBits is interpreted as an offset
3786 /// into the existing fragment.
3787 ///
3788 /// \param OffsetInBits Offset of the piece in bits.
3789 /// \param SizeInBits Size of the piece in bits.
3790 /// \return Creating a fragment expression may fail if \c Expr
3791 /// contains arithmetic operations that would be
3792 /// truncated.
3793 LLVM_ABI static std::optional<DIExpression *>
3794 createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits,
3795 unsigned SizeInBits);
3796
3797 /// Determine the relative position of the fragments passed in.
3798 /// Returns -1 if this is entirely before Other, 0 if this and Other overlap,
3799 /// 1 if this is entirely after Other.
3800 static int fragmentCmp(const FragmentInfo &A, const FragmentInfo &B) {
3801 uint64_t l1 = A.OffsetInBits;
3802 uint64_t l2 = B.OffsetInBits;
3803 uint64_t r1 = l1 + A.SizeInBits;
3804 uint64_t r2 = l2 + B.SizeInBits;
3805 if (r1 <= l2)
3806 return -1;
3807 else if (r2 <= l1)
3808 return 1;
3809 else
3810 return 0;
3811 }
3812
3813 /// Computes a fragment, bit-extract operation if needed, and new constant
3814 /// offset to describe a part of a variable covered by some memory.
3815 ///
3816 /// The memory region starts at:
3817 /// \p SliceStart + \p SliceOffsetInBits
3818 /// And is size:
3819 /// \p SliceSizeInBits
3820 ///
3821 /// The location of the existing variable fragment \p VarFrag is:
3822 /// \p DbgPtr + \p DbgPtrOffsetInBits + \p DbgExtractOffsetInBits.
3823 ///
3824 /// It is intended that these arguments are derived from a debug record:
3825 /// - \p DbgPtr is the (single) DIExpression operand.
3826 /// - \p DbgPtrOffsetInBits is the constant offset applied to \p DbgPtr.
3827 /// - \p DbgExtractOffsetInBits is the offset from a
3828 /// DW_OP_LLVM_bit_extract_[sz]ext operation.
3829 ///
3830 /// Results and return value:
3831 /// - Return false if the result can't be calculated for any reason.
3832 /// - \p Result is set to nullopt if the intersect equals \p VarFarg.
3833 /// - \p Result contains a zero-sized fragment if there's no intersect.
3834 /// - \p OffsetFromLocationInBits is set to the difference between the first
3835 /// bit of the variable location and the first bit of the slice. The
3836 /// magnitude of a negative value therefore indicates the number of bits
3837 /// into the variable fragment that the memory region begins.
3838 ///
3839 /// We don't pass in a debug record directly to get the constituent parts
3840 /// and offsets because different debug records store the information in
3841 /// different places (dbg_assign has two DIExpressions - one contains the
3842 /// fragment info for the entire intrinsic).
3844 const DataLayout &DL, const Value *SliceStart, uint64_t SliceOffsetInBits,
3845 uint64_t SliceSizeInBits, const Value *DbgPtr, int64_t DbgPtrOffsetInBits,
3846 int64_t DbgExtractOffsetInBits, DIExpression::FragmentInfo VarFrag,
3847 std::optional<DIExpression::FragmentInfo> &Result,
3848 int64_t &OffsetFromLocationInBits);
3849
3850 using ExtOps = std::array<uint64_t, 6>;
3851
3852 /// Returns the ops for a zero- or sign-extension in a DIExpression.
3853 LLVM_ABI static ExtOps getExtOps(unsigned FromSize, unsigned ToSize,
3854 bool Signed);
3855
3856 /// Append a zero- or sign-extension to \p Expr. Converts the expression to a
3857 /// stack value if it isn't one already.
3858 LLVM_ABI static DIExpression *appendExt(const DIExpression *Expr,
3859 unsigned FromSize, unsigned ToSize,
3860 bool Signed);
3861
3862 /// Check if fragments overlap between a pair of FragmentInfos.
3863 static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B) {
3864 return fragmentCmp(A, B) == 0;
3865 }
3866
3867 /// Determine the relative position of the fragments described by this
3868 /// DIExpression and \p Other. Calls static fragmentCmp implementation.
3869 int fragmentCmp(const DIExpression *Other) const {
3870 auto Fragment1 = *getFragmentInfo();
3871 auto Fragment2 = *Other->getFragmentInfo();
3872 return fragmentCmp(Fragment1, Fragment2);
3873 }
3874
3875 /// Check if fragments overlap between this DIExpression and \p Other.
3876 bool fragmentsOverlap(const DIExpression *Other) const {
3877 if (!isFragment() || !Other->isFragment())
3878 return true;
3879 return fragmentCmp(Other) == 0;
3880 }
3881
3882 /// Check if the expression consists of exactly one entry value operand.
3883 /// (This is the only configuration of entry values that is supported.)
3884 LLVM_ABI bool isEntryValue() const;
3885
3886 /// Try to shorten an expression with an initial constant operand.
3887 /// Returns a new expression and constant on success, or the original
3888 /// expression and constant on failure.
3889 LLVM_ABI std::pair<DIExpression *, const ConstantInt *>
3890 constantFold(const ConstantInt *CI);
3891
3892 /// Try to shorten an expression with constant math operations that can be
3893 /// evaluated at compile time. Returns a new expression on success, or the old
3894 /// expression if there is nothing to be reduced.
3896};
3897
3900 return std::tie(A.SizeInBits, A.OffsetInBits) ==
3901 std::tie(B.SizeInBits, B.OffsetInBits);
3902}
3903
3906 return std::tie(A.SizeInBits, A.OffsetInBits) <
3907 std::tie(B.SizeInBits, B.OffsetInBits);
3908}
3909
3910template <> struct DenseMapInfo<DIExpression::FragmentInfo> {
3912 static const uint64_t MaxVal = std::numeric_limits<uint64_t>::max();
3913
3914 static inline FragInfo getEmptyKey() { return {MaxVal, MaxVal}; }
3915
3916 static inline FragInfo getTombstoneKey() { return {MaxVal - 1, MaxVal - 1}; }
3917
3918 static unsigned getHashValue(const FragInfo &Frag) {
3919 return (Frag.SizeInBits & 0xffff) << 16 | (Frag.OffsetInBits & 0xffff);
3920 }
3921
3922 static bool isEqual(const FragInfo &A, const FragInfo &B) { return A == B; }
3923};
3924
3925/// Holds a DIExpression and keeps track of how many operands have been consumed
3926/// so far.
3929
3930public:
3932 if (!Expr) {
3933 assert(Start == End);
3934 return;
3935 }
3936 Start = Expr->expr_op_begin();
3937 End = Expr->expr_op_end();
3938 }
3939
3941 : Start(Expr.begin()), End(Expr.end()) {}
3942
3944
3945 /// Consume one operation.
3946 std::optional<DIExpression::ExprOperand> take() {
3947 if (Start == End)
3948 return std::nullopt;
3949 return *(Start++);
3950 }
3951
3952 /// Consume N operations.
3953 void consume(unsigned N) { std::advance(Start, N); }
3954
3955 /// Return the current operation.
3956 std::optional<DIExpression::ExprOperand> peek() const {
3957 if (Start == End)
3958 return std::nullopt;
3959 return *(Start);
3960 }
3961
3962 /// Return the next operation.
3963 std::optional<DIExpression::ExprOperand> peekNext() const {
3964 if (Start == End)
3965 return std::nullopt;
3966
3967 auto Next = Start.getNext();
3968 if (Next == End)
3969 return std::nullopt;
3970
3971 return *Next;
3972 }
3973
3974 std::optional<DIExpression::ExprOperand> peekNextN(unsigned N) const {
3975 if (Start == End)
3976 return std::nullopt;
3978 for (unsigned I = 0; I < N; I++) {
3979 Nth = Nth.getNext();
3980 if (Nth == End)
3981 return std::nullopt;
3982 }
3983 return *Nth;
3984 }
3985
3987 this->Start = DIExpression::expr_op_iterator(Expr.begin());
3988 this->End = DIExpression::expr_op_iterator(Expr.end());
3989 }
3990
3991 /// Determine whether there are any operations left in this expression.
3992 operator bool() const { return Start != End; }
3993
3994 DIExpression::expr_op_iterator begin() const { return Start; }
3995 DIExpression::expr_op_iterator end() const { return End; }
3996
3997 /// Retrieve the fragment information, if any.
3998 std::optional<DIExpression::FragmentInfo> getFragmentInfo() const {
3999 return DIExpression::getFragmentInfo(Start, End);
4000 }
4001};
4002
4003/// Global variables.
4004///
4005/// TODO: Remove DisplayName. It's always equal to Name.
4006class DIGlobalVariable : public DIVariable {
4007 friend class LLVMContextImpl;
4008 friend class MDNode;
4009
4010 bool IsLocalToUnit;
4011 bool IsDefinition;
4012
4013 DIGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
4014 bool IsLocalToUnit, bool IsDefinition, uint32_t AlignInBits,
4016 : DIVariable(C, DIGlobalVariableKind, Storage, Line, Ops, AlignInBits),
4017 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
4018 ~DIGlobalVariable() = default;
4019
4020 static DIGlobalVariable *
4021 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
4022 StringRef LinkageName, DIFile *File, unsigned Line, DIType *Type,
4023 bool IsLocalToUnit, bool IsDefinition,
4026 bool ShouldCreate = true) {
4027 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
4028 getCanonicalMDString(Context, LinkageName), File, Line, Type,
4031 Annotations.get(), Storage, ShouldCreate);
4032 }
4033 LLVM_ABI static DIGlobalVariable *
4034 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
4035 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
4036 bool IsLocalToUnit, bool IsDefinition,
4039 bool ShouldCreate = true);
4040
4041 TempDIGlobalVariable cloneImpl() const {
4046 getAnnotations());
4047 }
4048
4049public:
4051 DIGlobalVariable,
4053 unsigned Line, DIType *Type, bool IsLocalToUnit, bool IsDefinition,
4055 uint32_t AlignInBits, DINodeArray Annotations),
4056 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
4059 DIGlobalVariable,
4061 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
4064 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
4066
4067 TempDIGlobalVariable clone() const { return cloneImpl(); }
4068
4069 bool isLocalToUnit() const { return IsLocalToUnit; }
4070 bool isDefinition() const { return IsDefinition; }
4076 DINodeArray getAnnotations() const {
4078 }
4079
4084 Metadata *getRawAnnotations() const { return getOperand(8); }
4085
4086 static bool classof(const Metadata *MD) {
4087 return MD->getMetadataID() == DIGlobalVariableKind;
4088 }
4089};
4090
4091/// Debug common block.
4092///
4093/// Uses the SubclassData32 Metadata slot.
4094class DICommonBlock : public DIScope {
4095 friend class LLVMContextImpl;
4096 friend class MDNode;
4097
4098 DICommonBlock(LLVMContext &Context, StorageType Storage, unsigned LineNo,
4100
4101 static DICommonBlock *getImpl(LLVMContext &Context, DIScope *Scope,
4103 DIFile *File, unsigned LineNo,
4104 StorageType Storage, bool ShouldCreate = true) {
4105 return getImpl(Context, Scope, Decl, getCanonicalMDString(Context, Name),
4106 File, LineNo, Storage, ShouldCreate);
4107 }
4108 LLVM_ABI static DICommonBlock *getImpl(LLVMContext &Context, Metadata *Scope,
4110 Metadata *File, unsigned LineNo,
4112 bool ShouldCreate = true);
4113
4114 TempDICommonBlock cloneImpl() const {
4116 getFile(), getLineNo());
4117 }
4118
4119public:
4120 DEFINE_MDNODE_GET(DICommonBlock,
4122 DIFile *File, unsigned LineNo),
4123 (Scope, Decl, Name, File, LineNo))
4124 DEFINE_MDNODE_GET(DICommonBlock,
4126 Metadata *File, unsigned LineNo),
4128
4129 TempDICommonBlock clone() const { return cloneImpl(); }
4130
4135 StringRef getName() const { return getStringOperand(2); }
4137 unsigned getLineNo() const { return SubclassData32; }
4138
4139 Metadata *getRawScope() const { return getOperand(0); }
4140 Metadata *getRawDecl() const { return getOperand(1); }
4142 Metadata *getRawFile() const { return getOperand(3); }
4143
4144 static bool classof(const Metadata *MD) {
4145 return MD->getMetadataID() == DICommonBlockKind;
4146 }
4147};
4148
4149/// Local variable.
4150///
4151/// TODO: Split up flags.
4152class DILocalVariable : public DIVariable {
4153 friend class LLVMContextImpl;
4154 friend class MDNode;
4155
4156 unsigned Arg : 16;
4157 DIFlags Flags;
4158
4159 DILocalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
4160 unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
4162 : DIVariable(C, DILocalVariableKind, Storage, Line, Ops, AlignInBits),
4163 Arg(Arg), Flags(Flags) {
4164 assert(Arg < (1 << 16) && "DILocalVariable: Arg out of range");
4165 }
4166 ~DILocalVariable() = default;
4167
4168 static DILocalVariable *getImpl(LLVMContext &Context, DIScope *Scope,
4169 StringRef Name, DIFile *File, unsigned Line,
4170 DIType *Type, unsigned Arg, DIFlags Flags,
4171 uint32_t AlignInBits, DINodeArray Annotations,
4173 bool ShouldCreate = true) {
4174 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
4175 Line, Type, Arg, Flags, AlignInBits, Annotations.get(),
4176 Storage, ShouldCreate);
4177 }
4178 LLVM_ABI static DILocalVariable *
4179 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, Metadata *File,
4180 unsigned Line, Metadata *Type, unsigned Arg, DIFlags Flags,
4182 bool ShouldCreate = true);
4183
4184 TempDILocalVariable cloneImpl() const {
4186 getLine(), getType(), getArg(), getFlags(),
4188 }
4189
4190public:
4191 DEFINE_MDNODE_GET(DILocalVariable,
4193 unsigned Line, DIType *Type, unsigned Arg, DIFlags Flags,
4194 uint32_t AlignInBits, DINodeArray Annotations),
4195 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits,
4196 Annotations))
4197 DEFINE_MDNODE_GET(DILocalVariable,
4199 unsigned Line, Metadata *Type, unsigned Arg, DIFlags Flags,
4201 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits,
4202 Annotations))
4203
4204 TempDILocalVariable clone() const { return cloneImpl(); }
4205
4206 /// Get the local scope for this variable.
4207 ///
4208 /// Variables must be defined in a local scope.
4212
4213 bool isParameter() const { return Arg; }
4214 unsigned getArg() const { return Arg; }
4215 DIFlags getFlags() const { return Flags; }
4216
4217 DINodeArray getAnnotations() const {
4219 }
4220 Metadata *getRawAnnotations() const { return getOperand(4); }
4221
4222 bool isArtificial() const { return getFlags() & FlagArtificial; }
4223 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
4224
4225 /// Check that a location is valid for this variable.
4226 ///
4227 /// Check that \c DL exists, is in the same subprogram, and has the same
4228 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
4229 /// to a \a DbgInfoIntrinsic.)
4231 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
4232 }
4233
4234 static bool classof(const Metadata *MD) {
4235 return MD->getMetadataID() == DILocalVariableKind;
4236 }
4237};
4238
4239/// Label.
4240///
4241/// Uses the SubclassData32 Metadata slot.
4242class DILabel : public DINode {
4243 friend class LLVMContextImpl;
4244 friend class MDNode;
4245
4246 unsigned Column;
4247 std::optional<unsigned> CoroSuspendIdx;
4248 bool IsArtificial;
4249
4250 DILabel(LLVMContext &C, StorageType Storage, unsigned Line, unsigned Column,
4251 bool IsArtificial, std::optional<unsigned> CoroSuspendIdx,
4253 ~DILabel() = default;
4254
4255 static DILabel *getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
4256 DIFile *File, unsigned Line, unsigned Column,
4257 bool IsArtificial,
4258 std::optional<unsigned> CoroSuspendIdx,
4259 StorageType Storage, bool ShouldCreate = true) {
4260 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
4261 Line, Column, IsArtificial, CoroSuspendIdx, Storage,
4262 ShouldCreate);
4263 }
4264 LLVM_ABI static DILabel *
4265 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, Metadata *File,
4266 unsigned Line, unsigned Column, bool IsArtificial,
4267 std::optional<unsigned> CoroSuspendIdx, StorageType Storage,
4268 bool ShouldCreate = true);
4269
4270 TempDILabel cloneImpl() const {
4274 }
4275
4276public:
4279 unsigned Line, unsigned Column, bool IsArtificial,
4280 std::optional<unsigned> CoroSuspendIdx),
4281 (Scope, Name, File, Line, Column, IsArtificial,
4282 CoroSuspendIdx))
4283 DEFINE_MDNODE_GET(DILabel,
4285 unsigned Line, unsigned Column, bool IsArtificial,
4286 std::optional<unsigned> CoroSuspendIdx),
4287 (Scope, Name, File, Line, Column, IsArtificial,
4288 CoroSuspendIdx))
4289
4290 TempDILabel clone() const { return cloneImpl(); }
4291
4292 /// Get the local scope for this label.
4293 ///
4294 /// Labels must be defined in a local scope.
4298 unsigned getLine() const { return SubclassData32; }
4299 unsigned getColumn() const { return Column; }
4300 StringRef getName() const { return getStringOperand(1); }
4302 bool isArtificial() const { return IsArtificial; }
4303 std::optional<unsigned> getCoroSuspendIdx() const { return CoroSuspendIdx; }
4304
4305 Metadata *getRawScope() const { return getOperand(0); }
4307 Metadata *getRawFile() const { return getOperand(2); }
4308
4309 /// Check that a location is valid for this label.
4310 ///
4311 /// Check that \c DL exists, is in the same subprogram, and has the same
4312 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
4313 /// to a \a DbgInfoIntrinsic.)
4315 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
4316 }
4317
4318 static bool classof(const Metadata *MD) {
4319 return MD->getMetadataID() == DILabelKind;
4320 }
4321};
4322
4323class DIObjCProperty : public DINode {
4324 friend class LLVMContextImpl;
4325 friend class MDNode;
4326
4327 unsigned Line;
4328 unsigned Attributes;
4329
4330 DIObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
4331 unsigned Attributes, ArrayRef<Metadata *> Ops);
4332 ~DIObjCProperty() = default;
4333
4334 static DIObjCProperty *
4335 getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
4336 StringRef GetterName, StringRef SetterName, unsigned Attributes,
4337 DIType *Type, StorageType Storage, bool ShouldCreate = true) {
4338 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
4340 getCanonicalMDString(Context, SetterName), Attributes, Type,
4341 Storage, ShouldCreate);
4342 }
4343 LLVM_ABI static DIObjCProperty *
4344 getImpl(LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
4345 MDString *GetterName, MDString *SetterName, unsigned Attributes,
4346 Metadata *Type, StorageType Storage, bool ShouldCreate = true);
4347
4348 TempDIObjCProperty cloneImpl() const {
4349 return getTemporary(getContext(), getName(), getFile(), getLine(),
4351 getType());
4352 }
4353
4354public:
4355 DEFINE_MDNODE_GET(DIObjCProperty,
4356 (StringRef Name, DIFile *File, unsigned Line,
4358 unsigned Attributes, DIType *Type),
4359 (Name, File, Line, GetterName, SetterName, Attributes,
4360 Type))
4361 DEFINE_MDNODE_GET(DIObjCProperty,
4362 (MDString * Name, Metadata *File, unsigned Line,
4364 unsigned Attributes, Metadata *Type),
4365 (Name, File, Line, GetterName, SetterName, Attributes,
4366 Type))
4367
4368 TempDIObjCProperty clone() const { return cloneImpl(); }
4369
4370 unsigned getLine() const { return Line; }
4371 unsigned getAttributes() const { return Attributes; }
4372 StringRef getName() const { return getStringOperand(0); }
4377
4379 if (auto *F = getFile())
4380 return F->getFilename();
4381 return "";
4382 }
4383
4385 if (auto *F = getFile())
4386 return F->getDirectory();
4387 return "";
4388 }
4389
4391 Metadata *getRawFile() const { return getOperand(1); }
4394 Metadata *getRawType() const { return getOperand(4); }
4395
4396 static bool classof(const Metadata *MD) {
4397 return MD->getMetadataID() == DIObjCPropertyKind;
4398 }
4399};
4400
4401/// An imported module (C++ using directive or similar).
4402///
4403/// Uses the SubclassData32 Metadata slot.
4404class DIImportedEntity : public DINode {
4405 friend class LLVMContextImpl;
4406 friend class MDNode;
4407
4408 DIImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
4409 unsigned Line, ArrayRef<Metadata *> Ops)
4410 : DINode(C, DIImportedEntityKind, Storage, Tag, Ops) {
4412 }
4413 ~DIImportedEntity() = default;
4414
4415 static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
4416 DIScope *Scope, DINode *Entity, DIFile *File,
4417 unsigned Line, StringRef Name,
4418 DINodeArray Elements, StorageType Storage,
4419 bool ShouldCreate = true) {
4420 return getImpl(Context, Tag, Scope, Entity, File, Line,
4421 getCanonicalMDString(Context, Name), Elements.get(), Storage,
4422 ShouldCreate);
4423 }
4424 LLVM_ABI static DIImportedEntity *
4425 getImpl(LLVMContext &Context, unsigned Tag, Metadata *Scope, Metadata *Entity,
4426 Metadata *File, unsigned Line, MDString *Name, Metadata *Elements,
4427 StorageType Storage, bool ShouldCreate = true);
4428
4429 TempDIImportedEntity cloneImpl() const {
4430 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
4431 getFile(), getLine(), getName(), getElements());
4432 }
4433
4434public:
4435 DEFINE_MDNODE_GET(DIImportedEntity,
4436 (unsigned Tag, DIScope *Scope, DINode *Entity, DIFile *File,
4437 unsigned Line, StringRef Name = "",
4438 DINodeArray Elements = nullptr),
4439 (Tag, Scope, Entity, File, Line, Name, Elements))
4440 DEFINE_MDNODE_GET(DIImportedEntity,
4443 Metadata *Elements = nullptr),
4444 (Tag, Scope, Entity, File, Line, Name, Elements))
4445
4446 TempDIImportedEntity clone() const { return cloneImpl(); }
4447
4448 unsigned getLine() const { return SubclassData32; }
4449 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
4450 DINode *getEntity() const { return cast_or_null<DINode>(getRawEntity()); }
4451 StringRef getName() const { return getStringOperand(2); }
4452 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
4453 DINodeArray getElements() const {
4454 return cast_or_null<MDTuple>(getRawElements());
4455 }
4456
4457 Metadata *getRawScope() const { return getOperand(0); }
4458 Metadata *getRawEntity() const { return getOperand(1); }
4459 MDString *getRawName() const { return getOperandAs<MDString>(2); }
4460 Metadata *getRawFile() const { return getOperand(3); }
4461 Metadata *getRawElements() const { return getOperand(4); }
4462
4463 static bool classof(const Metadata *MD) {
4464 return MD->getMetadataID() == DIImportedEntityKind;
4465 }
4466};
4467
4468/// A pair of DIGlobalVariable and DIExpression.
4469class DIGlobalVariableExpression : public MDNode {
4470 friend class LLVMContextImpl;
4471 friend class MDNode;
4472
4473 DIGlobalVariableExpression(LLVMContext &C, StorageType Storage,
4475 : MDNode(C, DIGlobalVariableExpressionKind, Storage, Ops) {}
4476 ~DIGlobalVariableExpression() = default;
4477
4479 getImpl(LLVMContext &Context, Metadata *Variable, Metadata *Expression,
4480 StorageType Storage, bool ShouldCreate = true);
4481
4482 TempDIGlobalVariableExpression cloneImpl() const {
4484 }
4485
4486public:
4487 DEFINE_MDNODE_GET(DIGlobalVariableExpression,
4488 (Metadata * Variable, Metadata *Expression),
4489 (Variable, Expression))
4490
4491 TempDIGlobalVariableExpression clone() const { return cloneImpl(); }
4492
4493 Metadata *getRawVariable() const { return getOperand(0); }
4494
4498
4499 Metadata *getRawExpression() const { return getOperand(1); }
4500
4504
4505 static bool classof(const Metadata *MD) {
4506 return MD->getMetadataID() == DIGlobalVariableExpressionKind;
4507 }
4508};
4509
4510/// Macro Info DWARF-like metadata node.
4511///
4512/// A metadata node with a DWARF macro info (i.e., a constant named
4513/// \c DW_MACINFO_*, defined in llvm/BinaryFormat/Dwarf.h). Called \a
4514/// DIMacroNode
4515/// because it's potentially used for non-DWARF output.
4516///
4517/// Uses the SubclassData16 Metadata slot.
4518class DIMacroNode : public MDNode {
4519 friend class LLVMContextImpl;
4520 friend class MDNode;
4521
4522protected:
4523 DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType,
4525 : MDNode(C, ID, Storage, Ops1, Ops2) {
4526 assert(MIType < 1u << 16);
4527 SubclassData16 = MIType;
4528 }
4529 ~DIMacroNode() = default;
4530
4531 template <class Ty> Ty *getOperandAs(unsigned I) const {
4532 return cast_or_null<Ty>(getOperand(I));
4533 }
4534
4535 StringRef getStringOperand(unsigned I) const {
4536 if (auto *S = getOperandAs<MDString>(I))
4537 return S->getString();
4538 return StringRef();
4539 }
4540
4542 if (S.empty())
4543 return nullptr;
4544 return MDString::get(Context, S);
4545 }
4546
4547public:
4548 unsigned getMacinfoType() const { return SubclassData16; }
4549
4550 static bool classof(const Metadata *MD) {
4551 switch (MD->getMetadataID()) {
4552 default:
4553 return false;
4554 case DIMacroKind:
4555 case DIMacroFileKind:
4556 return true;
4557 }
4558 }
4559};
4560
4561/// Macro
4562///
4563/// Uses the SubclassData32 Metadata slot.
4564class DIMacro : public DIMacroNode {
4565 friend class LLVMContextImpl;
4566 friend class MDNode;
4567
4568 DIMacro(LLVMContext &C, StorageType Storage, unsigned MIType, unsigned Line,
4570 : DIMacroNode(C, DIMacroKind, Storage, MIType, Ops) {
4572 }
4573 ~DIMacro() = default;
4574
4575 static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
4577 bool ShouldCreate = true) {
4578 return getImpl(Context, MIType, Line, getCanonicalMDString(Context, Name),
4579 getCanonicalMDString(Context, Value), Storage, ShouldCreate);
4580 }
4581 LLVM_ABI static DIMacro *getImpl(LLVMContext &Context, unsigned MIType,
4582 unsigned Line, MDString *Name,
4583 MDString *Value, StorageType Storage,
4584 bool ShouldCreate = true);
4585
4586 TempDIMacro cloneImpl() const {
4588 getValue());
4589 }
4590
4591public:
4593 (unsigned MIType, unsigned Line, StringRef Name,
4594 StringRef Value = ""),
4595 (MIType, Line, Name, Value))
4596 DEFINE_MDNODE_GET(DIMacro,
4597 (unsigned MIType, unsigned Line, MDString *Name,
4600
4601 TempDIMacro clone() const { return cloneImpl(); }
4602
4603 unsigned getLine() const { return SubclassData32; }
4604
4605 StringRef getName() const { return getStringOperand(0); }
4606 StringRef getValue() const { return getStringOperand(1); }
4607
4610
4611 static bool classof(const Metadata *MD) {
4612 return MD->getMetadataID() == DIMacroKind;
4613 }
4614};
4615
4616/// Macro file
4617///
4618/// Uses the SubclassData32 Metadata slot.
4619class DIMacroFile : public DIMacroNode {
4620 friend class LLVMContextImpl;
4621 friend class MDNode;
4622
4623 DIMacroFile(LLVMContext &C, StorageType Storage, unsigned MIType,
4624 unsigned Line, ArrayRef<Metadata *> Ops)
4625 : DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops) {
4627 }
4628 ~DIMacroFile() = default;
4629
4630 static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
4631 unsigned Line, DIFile *File,
4632 DIMacroNodeArray Elements, StorageType Storage,
4633 bool ShouldCreate = true) {
4634 return getImpl(Context, MIType, Line, static_cast<Metadata *>(File),
4635 Elements.get(), Storage, ShouldCreate);
4636 }
4637
4638 LLVM_ABI static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
4639 unsigned Line, Metadata *File,
4641 bool ShouldCreate = true);
4642
4643 TempDIMacroFile cloneImpl() const {
4645 getElements());
4646 }
4647
4648public:
4650 (unsigned MIType, unsigned Line, DIFile *File,
4651 DIMacroNodeArray Elements),
4652 (MIType, Line, File, Elements))
4653 DEFINE_MDNODE_GET(DIMacroFile,
4654 (unsigned MIType, unsigned Line, Metadata *File,
4657
4658 TempDIMacroFile clone() const { return cloneImpl(); }
4659
4660 void replaceElements(DIMacroNodeArray Elements) {
4661#ifndef NDEBUG
4662 for (DIMacroNode *Op : getElements())
4663 assert(is_contained(Elements->operands(), Op) &&
4664 "Lost a macro node during macro node list replacement");
4665#endif
4666 replaceOperandWith(1, Elements.get());
4667 }
4668
4669 unsigned getLine() const { return SubclassData32; }
4671
4672 DIMacroNodeArray getElements() const {
4674 }
4675
4676 Metadata *getRawFile() const { return getOperand(0); }
4677 Metadata *getRawElements() const { return getOperand(1); }
4678
4679 static bool classof(const Metadata *MD) {
4680 return MD->getMetadataID() == DIMacroFileKind;
4681 }
4682};
4683
4684/// List of ValueAsMetadata, to be used as an argument to a dbg.value
4685/// intrinsic.
4686class DIArgList : public Metadata, ReplaceableMetadataImpl {
4688 friend class LLVMContextImpl;
4690
4692
4693 DIArgList(LLVMContext &Context, ArrayRef<ValueAsMetadata *> Args)
4694 : Metadata(DIArgListKind, Uniqued), ReplaceableMetadataImpl(Context),
4695 Args(Args) {
4696 track();
4697 }
4698 ~DIArgList() { untrack(); }
4699
4700 LLVM_ABI void track();
4701 LLVM_ABI void untrack();
4702 void dropAllReferences(bool Untrack);
4703
4704public:
4705 LLVM_ABI static DIArgList *get(LLVMContext &Context,
4707
4708 ArrayRef<ValueAsMetadata *> getArgs() const { return Args; }
4709
4710 iterator args_begin() { return Args.begin(); }
4711 iterator args_end() { return Args.end(); }
4712
4713 static bool classof(const Metadata *MD) {
4714 return MD->getMetadataID() == DIArgListKind;
4715 }
4716
4720
4721 LLVM_ABI void handleChangedOperand(void *Ref, Metadata *New);
4722};
4723
4724/// Identifies a unique instance of a variable.
4725///
4726/// Storage for identifying a potentially inlined instance of a variable,
4727/// or a fragment thereof. This guarantees that exactly one variable instance
4728/// may be identified by this class, even when that variable is a fragment of
4729/// an aggregate variable and/or there is another inlined instance of the same
4730/// source code variable nearby.
4731/// This class does not necessarily uniquely identify that variable: it is
4732/// possible that a DebugVariable with different parameters may point to the
4733/// same variable instance, but not that one DebugVariable points to multiple
4734/// variable instances.
4736 using FragmentInfo = DIExpression::FragmentInfo;
4737
4738 const DILocalVariable *Variable;
4739 std::optional<FragmentInfo> Fragment;
4740 const DILocation *InlinedAt;
4741
4742 /// Fragment that will overlap all other fragments. Used as default when
4743 /// caller demands a fragment.
4744 LLVM_ABI static const FragmentInfo DefaultFragment;
4745
4746public:
4748
4750 std::optional<FragmentInfo> FragmentInfo,
4751 const DILocation *InlinedAt)
4752 : Variable(Var), Fragment(FragmentInfo), InlinedAt(InlinedAt) {}
4753
4754 DebugVariable(const DILocalVariable *Var, const DIExpression *DIExpr,
4755 const DILocation *InlinedAt)
4756 : Variable(Var),
4757 Fragment(DIExpr ? DIExpr->getFragmentInfo() : std::nullopt),
4758 InlinedAt(InlinedAt) {}
4759
4760 const DILocalVariable *getVariable() const { return Variable; }
4761 std::optional<FragmentInfo> getFragment() const { return Fragment; }
4762 const DILocation *getInlinedAt() const { return InlinedAt; }
4763
4764 FragmentInfo getFragmentOrDefault() const {
4765 return Fragment.value_or(DefaultFragment);
4766 }
4767
4768 static bool isDefaultFragment(const FragmentInfo F) {
4769 return F == DefaultFragment;
4770 }
4771
4772 bool operator==(const DebugVariable &Other) const {
4773 return std::tie(Variable, Fragment, InlinedAt) ==
4774 std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
4775 }
4776
4777 bool operator<(const DebugVariable &Other) const {
4778 return std::tie(Variable, Fragment, InlinedAt) <
4779 std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
4780 }
4781};
4782
4783template <> struct DenseMapInfo<DebugVariable> {
4785
4786 /// Empty key: no key should be generated that has no DILocalVariable.
4787 static inline DebugVariable getEmptyKey() {
4788 return DebugVariable(nullptr, std::nullopt, nullptr);
4789 }
4790
4791 /// Difference in tombstone is that the Optional is meaningful.
4793 return DebugVariable(nullptr, {{0, 0}}, nullptr);
4794 }
4795
4796 static unsigned getHashValue(const DebugVariable &D) {
4797 unsigned HV = 0;
4798 const std::optional<FragmentInfo> Fragment = D.getFragment();
4799 if (Fragment)
4801
4802 return hash_combine(D.getVariable(), HV, D.getInlinedAt());
4803 }
4804
4805 static bool isEqual(const DebugVariable &A, const DebugVariable &B) {
4806 return A == B;
4807 }
4808};
4809
4810/// Identifies a unique instance of a whole variable (discards/ignores fragment
4811/// information).
4818
4819template <>
4821 : public DenseMapInfo<DebugVariable> {};
4822} // end namespace llvm
4823
4824#undef DEFINE_MDNODE_GET_UNPACK_IMPL
4825#undef DEFINE_MDNODE_GET_UNPACK
4826#undef DEFINE_MDNODE_GET
4827
4828#endif // LLVM_IR_DEBUGINFOMETADATA_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static std::string getLinkageName(GlobalValue::LinkageTypes LT)
#define X(NUM, ENUM, NAME)
Definition ELF.h:853
BitTracker BT
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:213
This file contains the declarations for the subclasses of Constant, which represent the different fla...
dxil translate DXIL Translate Metadata
#define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS)
#define DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS)
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
static unsigned getNextComponentInDiscriminator(unsigned D)
Returns the next component stored in discriminator.
static unsigned getUnsignedFromPrefixEncoding(unsigned U)
Reverse transformation as getPrefixEncodingFromUnsigned.
static SmallString< 128 > getFilename(const DIScope *SP, vfs::FileSystem &VFS)
Extract a filename for a DIScope.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file contains the declarations for metadata subclasses.
#define T
static constexpr StringLiteral Filename
This file defines the PointerUnion class, which is a discriminated union of pointer types.
static StringRef getName(Value *V)
static void r2(uint32_t &A, uint32_t &B, uint32_t &C, uint32_t &D, uint32_t &E, int I, uint32_t *Buf)
Definition SHA1.cpp:51
static void r1(uint32_t &A, uint32_t &B, uint32_t &C, uint32_t &D, uint32_t &E, int I, uint32_t *Buf)
Definition SHA1.cpp:45
This file contains some templates that are useful if you are working with the STL at all.
static enum BaseType getBaseType(const Value *Val)
Return the baseType for Val which states whether Val is exclusively derived from constant/null,...
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
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
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
iterator end() const
Definition ArrayRef.h:130
const_pointer iterator
Definition ArrayRef.h:47
iterator begin() const
Definition ArrayRef.h:129
static ConstantAsMetadata * get(Constant *C)
Definition Metadata.h:537
This is the shared class of boolean and integer constants.
Definition Constants.h:87
This is an important base class in LLVM.
Definition Constant.h:43
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
ArrayRef< ValueAsMetadata * > getArgs() const
LLVM_ABI void handleChangedOperand(void *Ref, Metadata *New)
static bool classof(const Metadata *MD)
static LLVM_ABI DIArgList * get(LLVMContext &Context, ArrayRef< ValueAsMetadata * > Args)
friend class ReplaceableMetadataImpl
friend class LLVMContextImpl
SmallVector< DbgVariableRecord * > getAllDbgVariableRecordUsers()
static bool classof(const Metadata *MD)
SmallVector< DbgVariableRecord * > getAllDbgVariableRecordUsers()
static TempDIAssignID getTemporary(LLVMContext &Context)
static DIAssignID * getDistinct(LLVMContext &Context)
friend class LLVMContextImpl
void replaceOperandWith(unsigned I, Metadata *New)=delete
Basic type, like 'int' or 'float'.
DIBasicType(LLVMContext &C, StorageType Storage, unsigned Tag, unsigned LineNo, uint32_t AlignInBits, unsigned Encoding, uint32_t NumExtraInhabitants, uint32_t DataSizeInBits, DIFlags Flags, ArrayRef< Metadata * > Ops)
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned Encoding
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags
TempDIBasicType cloneImpl() const
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags unsigned StringRef uint64_t uint32_t unsigned uint32_t DIFlags Flags unsigned StringRef DIFile unsigned DIScope uint64_t uint32_t unsigned uint32_t uint32_t DataSizeInBits
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags unsigned StringRef uint64_t uint32_t unsigned uint32_t DIFlags Flags unsigned StringRef DIFile * File
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags unsigned StringRef uint64_t uint32_t unsigned uint32_t DIFlags Flags unsigned StringRef DIFile unsigned DIScope * Scope
~DIBasicType()=default
static bool classof(const Metadata *MD)
static DIBasicType * getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, DIFile *File, unsigned LineNo, DIScope *Scope, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, uint32_t NumExtraInhabitants, uint32_t DataSizeInBits, DIFlags Flags, StorageType Storage, bool ShouldCreate=true)
uint32_t getDataSizeInBits() const
unsigned StringRef uint64_t SizeInBits
friend class LLVMContextImpl
LLVM_ABI std::optional< Signedness > getSignedness() const
Return the signedness of this type, or std::nullopt if this type is neither signed nor unsigned.
unsigned getEncoding() const
DEFINE_MDNODE_GET(DIBasicType,(unsigned Tag, StringRef Name),(Tag, Name, nullptr, 0, nullptr, 0, 0, 0, 0, 0, FlagZero)) DEFINE_MDNODE_GET(DIBasicType
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags unsigned StringRef uint64_t uint32_t unsigned uint32_t NumExtraInhabitants
DIBasicType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, unsigned LineNo, uint32_t AlignInBits, unsigned Encoding, uint32_t NumExtraInhabitants, uint32_t DataSizeInBits, DIFlags Flags, ArrayRef< Metadata * > Ops)
static DIBasicType * getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File, unsigned LineNo, DIScope *Scope, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, uint32_t NumExtraInhabitants, uint32_t DataSizeInBits, DIFlags Flags, StorageType Storage, bool ShouldCreate=true)
unsigned StringRef Name
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t AlignInBits
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags unsigned StringRef uint64_t uint32_t unsigned uint32_t DIFlags Flags unsigned StringRef DIFile unsigned LineNo
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
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned NameTableKind
MDString * getRawSplitDebugFilename() const
bool getDebugInfoForProfiling() const
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool DebugInfoForProfiling
Metadata * getRawRetainedTypes() const
static LLVM_ABI const char * nameTableKindString(DebugNameTableKind PK)
static LLVM_ABI const char * emissionKindString(DebugEmissionKind EK)
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString * SysRoot
DISourceLanguageName Metadata MDString bool MDString * Flags
void setSplitDebugInlining(bool SplitDebugInlining)
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString MDString * SDK
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata * GlobalVariables
DICompositeTypeArray getEnumTypes() const
DebugEmissionKind getEmissionKind() const
bool isDebugDirectivesOnly() const
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t DWOId
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata * EnumTypes
StringRef getFlags() const
MDString * getRawProducer() const
DISourceLanguageName Metadata MDString * Producer
void replaceEnumTypes(DICompositeTypeArray N)
Replace arrays.
MDString * getRawSysRoot() const
DISourceLanguageName Metadata MDString bool MDString unsigned RuntimeVersion
StringRef getSDK() const
static void getIfExists()=delete
bool getRangesBaseAddress() const
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata * RetainedTypes
DIMacroNodeArray getMacros() const
unsigned getRuntimeVersion() const
Metadata * getRawMacros() const
void replaceRetainedTypes(DITypeArray N)
static bool classof(const Metadata *MD)
DISourceLanguageName Metadata MDString bool MDString unsigned MDString * SplitDebugFilename
void replaceGlobalVariables(DIGlobalVariableExpressionArray N)
void replaceMacros(DIMacroNodeArray N)
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString MDString SDK TempDICompileUnit clone() const
bool getSplitDebugInlining() const
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata * ImportedEntities
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata * Macros
StringRef getSysRoot() const
DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(DICompileUnit,(DISourceLanguageName 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
DebugNameTableKind getNameTableKind() const
MDString * getRawSDK() const
DISourceLanguageName Metadata MDString bool IsOptimized
DISourceLanguageName Metadata * File
MDString * getRawFlags() const
DIImportedEntityArray getImportedEntities() const
bool isDebugInfoForProfiling() const
Metadata * getRawEnumTypes() const
StringRef getProducer() const
void setDWOId(uint64_t DwoId)
DIScopeArray getRetainedTypes() const
void replaceImportedEntities(DIImportedEntityArray N)
Metadata * getRawGlobalVariables() const
DIGlobalVariableExpressionArray getGlobalVariables() const
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool SplitDebugInlining
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned EmissionKind
DISourceLanguageName getSourceLanguage() const
Metadata * getRawImportedEntities() const
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool RangesBaseAddress
uint64_t getDWOId() const
StringRef getSplitDebugFilename() const
static void get()=delete
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t AlignInBits
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > EnumKind
Metadata * getRawVTableHolder() const
DIExpression * getRankExp() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata * DataLocation
static LLVM_ABI DICompositeType * buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, Metadata *SizeInBits, uint32_t AlignInBits, Metadata *OffsetInBits, Metadata *Specification, uint32_t NumExtraInhabitants, DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, std::optional< uint32_t > EnumKind, Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator, Metadata *DataLocation, Metadata *Associated, Metadata *Allocated, Metadata *Rank, Metadata *Annotations, Metadata *BitStride)
Build a DICompositeType with the given ODR identifier.
unsigned MDString Metadata unsigned Line
Metadata * getRawRank() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata * Elements
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned RuntimeLang
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata * Annotations
Metadata * getRawSpecification() const
DIExpression * getAssociatedExp() const
DIVariable * getAllocated() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString * Identifier
DIExpression * getDataLocationExp() const
Metadata * getRawDiscriminator() const
static LLVM_ABI DICompositeType * getODRTypeIfExists(LLVMContext &Context, MDString &Identifier)
DIVariable * getAssociated() const
DIDerivedType * getDiscriminator() const
DIVariable * getDataLocation() const
unsigned getRuntimeLang() const
DIType * getSpecification() const
Metadata * getRawElements() const
unsigned MDString * Name
void replaceVTableHolder(DIType *VTableHolder)
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata * Discriminator
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata * TemplateParams
StringRef getIdentifier() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t OffsetInBits
unsigned MDString Metadata unsigned Metadata * Scope
unsigned MDString Metadata * File
Metadata * getRawDataLocation() const
Metadata * getRawTemplateParams() const
unsigned MDString Metadata unsigned Metadata Metadata * BaseType
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Flags
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata * Allocated
DINodeArray getElements() const
DITemplateParameterArray getTemplateParams() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata Metadata * Specification
Metadata * getRawAnnotations() const
Metadata * getRawAllocated() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata * VTableHolder
DIExpression * getAllocatedExp() const
void replaceElements(DINodeArray Elements)
Replace operands.
ConstantInt * getBitStrideConst() const
std::optional< uint32_t > getEnumKind() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t SizeInBits
DIType * getVTableHolder() const
DINodeArray getAnnotations() const
Metadata * getRawAssociated() const
ConstantInt * getRankConst() const
void replaceTemplateParams(DITemplateParameterArray TemplateParams)
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata * Associated
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata Metadata uint32_t NumExtraInhabitants
Metadata * getRawBitStride() const
Metadata * getRawBaseType() const
DEFINE_MDNODE_GET(DICompositeType,(unsigned Tag, StringRef Name, DIFile *File, unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags, DINodeArray Elements, unsigned RuntimeLang, std::optional< uint32_t > EnumKind, DIType *VTableHolder, DITemplateParameterArray TemplateParams=nullptr, StringRef Identifier="", DIDerivedType *Discriminator=nullptr, Metadata *DataLocation=nullptr, Metadata *Associated=nullptr, Metadata *Allocated=nullptr, Metadata *Rank=nullptr, DINodeArray Annotations=nullptr, DIType *Specification=nullptr, uint32_t NumExtraInhabitants=0, Metadata *BitStride=nullptr),(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits, Specification, NumExtraInhabitants, Flags, Elements, RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier, Discriminator, DataLocation, Associated, Allocated, Rank, Annotations, BitStride)) DEFINE_MDNODE_GET(DICompositeType
MDString * getRawIdentifier() const
static bool classof(const Metadata *MD)
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata * Rank
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata Metadata uint32_t Metadata * BitStride
DIType * getBaseType() const
Metadata * getRawExtraData() const
unsigned StringRef DIFile unsigned DIScope DIType * BaseType
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata * OffsetInBits
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > std::optional< PtrAuthData > DIFlags Flags
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t AlignInBits
DINodeArray getAnnotations() const
Get annotations associated with this derived type.
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > std::optional< PtrAuthData > PtrAuthData
DEFINE_MDNODE_GET(DIDerivedType,(unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, Metadata *SizeInBits, uint32_t AlignInBits, Metadata *OffsetInBits, std::optional< unsigned > DWARFAddressSpace, std::optional< PtrAuthData > PtrAuthData, DIFlags Flags, Metadata *ExtraData=nullptr, Metadata *Annotations=nullptr),(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData, Flags, ExtraData, Annotations)) DEFINE_MDNODE_GET(DIDerivedType
Metadata * getExtraData() const
Get extra data associated with this derived type.
DITemplateParameterArray getTemplateParams() const
Get the template parameters from a template alias.
unsigned StringRef DIFile * File
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > std::optional< PtrAuthData > DIFlags Metadata DINodeArray Annotations
DIObjCProperty * getObjCProperty() const
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > DWARFAddressSpace
unsigned StringRef DIFile unsigned DIScope * Scope
Metadata * getRawAnnotations() const
LLVM_ABI DIType * getClassType() const
Get casted version of extra data.
static bool classof(const Metadata *MD)
LLVM_ABI Constant * getConstant() const
unsigned StringRef DIFile unsigned DIScope DIType Metadata * SizeInBits
LLVM_ABI Constant * getStorageOffsetInBits() const
LLVM_ABI Constant * getDiscriminantValue() const
unsigned StringRef Name
LLVM_ABI uint32_t getVBPtrOffset() const
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > std::optional< PtrAuthData > DIFlags Metadata * ExtraData
unsigned StringRef DIFile unsigned Line
Enumeration value.
int64_t bool MDString APInt(64, Value, !IsUnsigned)
const APInt & getValue() const
int64_t bool MDString Name APInt bool MDString Name TempDIEnumerator clone() const
MDString * getRawName() const
StringRef getName() const
friend class LLVMContextImpl
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
std::optional< DIExpression::ExprOperand > peekNext() const
Return the next operation.
std::optional< DIExpression::FragmentInfo > getFragmentInfo() const
Retrieve the fragment information, if any.
DIExpressionCursor(const DIExpressionCursor &)=default
DIExpressionCursor(const DIExpression *Expr)
DIExpression::expr_op_iterator end() const
std::optional< DIExpression::ExprOperand > peekNextN(unsigned N) const
std::optional< DIExpression::ExprOperand > peek() const
Return the current operation.
void consume(unsigned N)
Consume N operations.
std::optional< DIExpression::ExprOperand > take()
Consume one operation.
DIExpressionCursor(ArrayRef< uint64_t > Expr)
DIExpression::expr_op_iterator begin() const
void assignNewExpr(ArrayRef< uint64_t > Expr)
A lightweight wrapper around an expression operand.
LLVM_ABI unsigned getSize() const
Return the size of the operand.
uint64_t getArg(unsigned I) const
Get an argument to the operand.
uint64_t getOp() const
Get the operand code.
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
const ExprOperand * operator->() const
bool operator!=(const expr_op_iterator &X) const
const ExprOperand & operator*() const
expr_op_iterator getNext() const
Get the next iterator.
DWARF expression.
element_iterator elements_end() const
LLVM_ABI bool isEntryValue() const
Check if the expression consists of exactly one entry value operand.
iterator_range< expr_op_iterator > expr_ops() const
bool isFragment() const
Return whether this is a piece of an aggregate variable.
static LLVM_ABI DIExpression * append(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Append the opcodes Ops to DIExpr.
std::array< uint64_t, 6 > ExtOps
unsigned getNumElements() const
ArrayRef< uint64_t >::iterator element_iterator
static LLVM_ABI ExtOps getExtOps(unsigned FromSize, unsigned ToSize, bool Signed)
Returns the ops for a zero- or sign-extension in a DIExpression.
expr_op_iterator expr_op_begin() const
Visit the elements via ExprOperand wrappers.
LLVM_ABI bool extractIfOffset(int64_t &Offset) const
If this is a constant offset, extract it.
static LLVM_ABI void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
DbgVariableFragmentInfo FragmentInfo
int fragmentCmp(const DIExpression *Other) const
Determine the relative position of the fragments described by this DIExpression and Other.
LLVM_ABI bool startsWithDeref() const
Return whether the first element a DW_OP_deref.
static LLVM_ABI bool isEqualExpression(const DIExpression *FirstExpr, bool FirstIndirect, const DIExpression *SecondExpr, bool SecondIndirect)
Determines whether two debug values should produce equivalent DWARF expressions, using their DIExpres...
expr_op_iterator expr_op_end() const
LLVM_ABI bool isImplicit() const
Return whether this is an implicit location description.
DEFINE_MDNODE_GET(DIExpression,(ArrayRef< uint64_t > Elements),(Elements)) TempDIExpression clone() const
static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B)
Check if fragments overlap between a pair of FragmentInfos.
static LLVM_ABI bool calculateFragmentIntersect(const DataLayout &DL, const Value *SliceStart, uint64_t SliceOffsetInBits, uint64_t SliceSizeInBits, const Value *DbgPtr, int64_t DbgPtrOffsetInBits, int64_t DbgExtractOffsetInBits, DIExpression::FragmentInfo VarFrag, std::optional< DIExpression::FragmentInfo > &Result, int64_t &OffsetFromLocationInBits)
Computes a fragment, bit-extract operation if needed, and new constant offset to describe a part of a...
element_iterator elements_begin() const
LLVM_ABI bool hasAllLocationOps(unsigned N) const
Returns true iff this DIExpression contains at least one instance of DW_OP_LLVM_arg,...
std::optional< FragmentInfo > getFragmentInfo() const
Retrieve the details of this fragment expression.
static LLVM_ABI DIExpression * appendOpsToArg(const DIExpression *Expr, ArrayRef< uint64_t > Ops, unsigned ArgNo, bool StackValue=false)
Create a copy of Expr by appending the given list of Ops to each instance of the operand DW_OP_LLVM_a...
PrependOps
Used for DIExpression::prepend.
static int fragmentCmp(const FragmentInfo &A, const FragmentInfo &B)
Determine the relative position of the fragments passed in.
LLVM_ABI bool isComplex() const
Return whether the location is computed on the expression stack, meaning it cannot be a simple regist...
bool fragmentsOverlap(const DIExpression *Other) const
Check if fragments overlap between this DIExpression and Other.
LLVM_ABI DIExpression * foldConstantMath()
Try to shorten an expression with constant math operations that can be evaluated at compile time.
static LLVM_ABI std::optional< const DIExpression * > convertToNonVariadicExpression(const DIExpression *Expr)
If Expr is a valid single-location expression, i.e.
LLVM_ABI std::pair< DIExpression *, const ConstantInt * > constantFold(const ConstantInt *CI)
Try to shorten an expression with an initial constant operand.
LLVM_ABI bool isDeref() const
Return whether there is exactly one operator and it is a DW_OP_deref;.
static LLVM_ABI const DIExpression * convertToVariadicExpression(const DIExpression *Expr)
If Expr is a non-variadic expression (i.e.
LLVM_ABI uint64_t getNumLocationOperands() const
Return the number of unique location operands referred to (via DW_OP_LLVM_arg) in this expression; th...
ArrayRef< uint64_t > getElements() const
static LLVM_ABI DIExpression * replaceArg(const DIExpression *Expr, uint64_t OldArg, uint64_t NewArg)
Create a copy of Expr with each instance of DW_OP_LLVM_arg, \p OldArg replaced with DW_OP_LLVM_arg,...
static bool classof(const Metadata *MD)
LLVM_ABI std::optional< uint64_t > getActiveBits(DIVariable *Var)
Return the number of bits that have an active value, i.e.
static LLVM_ABI void canonicalizeExpressionOps(SmallVectorImpl< uint64_t > &Ops, const DIExpression *Expr, bool IsIndirect)
Inserts the elements of Expr into Ops modified to a canonical form, which uses DW_OP_LLVM_arg (i....
uint64_t getElement(unsigned I) const
static LLVM_ABI bool extractLeadingOffset(ArrayRef< uint64_t > Ops, int64_t &OffsetInBytes, SmallVectorImpl< uint64_t > &RemainingOps)
static LLVM_ABI std::optional< DIExpression * > createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits)
Create a DIExpression to describe one part of an aggregate variable that is fragmented across multipl...
static LLVM_ABI const DIExpression * convertToUndefExpression(const DIExpression *Expr)
Removes all elements from Expr that do not apply to an undef debug value, which includes every operat...
static LLVM_ABI DIExpression * prepend(const DIExpression *Expr, uint8_t Flags, int64_t Offset=0)
Prepend DIExpr with a deref and offset operation and optionally turn it into a stack value or/and an ...
static LLVM_ABI DIExpression * appendToStack(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Convert DIExpr into a stack value if it isn't one already by appending DW_OP_deref if needed,...
static LLVM_ABI DIExpression * appendExt(const DIExpression *Expr, unsigned FromSize, unsigned ToSize, bool Signed)
Append a zero- or sign-extension to Expr.
LLVM_ABI std::optional< ArrayRef< uint64_t > > getSingleLocationExpressionElements() const
Returns a reference to the elements contained in this expression, skipping past the leading DW_OP_LLV...
LLVM_ABI bool isSingleLocationExpression() const
Return whether the evaluated expression makes use of a single location at the start of the expression...
LLVM_ABI std::optional< SignedOrUnsignedConstant > isConstant() const
Determine whether this represents a constant value, if so.
LLVM_ABI bool isValid() const
static LLVM_ABI const DIExpression * extractAddressClass(const DIExpression *Expr, unsigned &AddrClass)
Checks if the last 4 elements of the expression are DW_OP_constu <DWARFAddress Space> DW_OP_swap DW_O...
static LLVM_ABI DIExpression * prependOpcodes(const DIExpression *Expr, SmallVectorImpl< uint64_t > &Ops, bool StackValue=false, bool EntryValue=false)
Prepend DIExpr with the given opcodes and optionally turn it into a stack value.
static bool classof(const Metadata *MD)
MDString MDString * Directory
MDString MDString std::optional< ChecksumInfo< MDString * > > MDString * Source
DEFINE_MDNODE_GET(DIFile,(StringRef Filename, StringRef Directory, std::optional< ChecksumInfo< StringRef > > CS=std::nullopt, std::optional< StringRef > Source=std::nullopt),(Filename, Directory, CS, Source)) DEFINE_MDNODE_GET(DIFile
MDString * Filename
static LLVM_ABI std::optional< ChecksumKind > getChecksumKind(StringRef CSKindStr)
ChecksumKind
Which algorithm (e.g.
friend class LLVMContextImpl
friend class MDNode
MDString MDString std::optional< ChecksumInfo< MDString * > > CS
static LLVM_ABI std::optional< FixedPointKind > getFixedPointKind(StringRef Str)
static LLVM_ABI const char * fixedPointKindString(FixedPointKind)
unsigned StringRef DIFile unsigned DIScope uint64_t uint32_t unsigned DIFlags unsigned int APInt Numerator
const APInt & getNumeratorRaw() const
static bool classof(const Metadata *MD)
unsigned StringRef DIFile unsigned LineNo
const APInt & getDenominator() const
unsigned StringRef DIFile unsigned DIScope uint64_t uint32_t unsigned Encoding
unsigned StringRef DIFile unsigned DIScope uint64_t uint32_t unsigned DIFlags unsigned int APInt APInt Denominator
unsigned StringRef DIFile unsigned DIScope uint64_t SizeInBits
unsigned StringRef DIFile unsigned DIScope uint64_t uint32_t AlignInBits
LLVM_ABI bool isSigned() const
unsigned StringRef DIFile unsigned DIScope uint64_t uint32_t unsigned DIFlags unsigned int Factor
@ FixedPointBinary
Scale factor 2^Factor.
@ FixedPointDecimal
Scale factor 10^Factor.
@ FixedPointRational
Arbitrary rational scale factor.
DEFINE_MDNODE_GET(DIFixedPointType,(unsigned Tag, MDString *Name, DIFile *File, unsigned LineNo, DIScope *Scope, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind, int Factor, APInt Numerator, APInt Denominator),(Tag, Name, File, LineNo, Scope, SizeInBits, AlignInBits, Encoding, Flags, Kind, Factor, Numerator, Denominator)) DEFINE_MDNODE_GET(DIFixedPointType
FixedPointKind getKind() const
unsigned StringRef DIFile unsigned DIScope * Scope
unsigned StringRef DIFile unsigned DIScope uint64_t uint32_t unsigned DIFlags Flags
const APInt & getNumerator() const
unsigned StringRef DIFile * File
const APInt & getDenominatorRaw() const
Metadata * getRawLowerBound() const
Metadata * getRawCountNode() const
Metadata * getRawStride() const
LLVM_ABI BoundType getLowerBound() const
DEFINE_MDNODE_GET(DIGenericSubrange,(Metadata *CountNode, Metadata *LowerBound, Metadata *UpperBound, Metadata *Stride),(CountNode, LowerBound, UpperBound, Stride)) TempDIGenericSubrange clone() const
Metadata * getRawUpperBound() const
static bool classof(const Metadata *MD)
LLVM_ABI BoundType getCount() const
LLVM_ABI BoundType getUpperBound() const
PointerUnion< DIVariable *, DIExpression * > BoundType
LLVM_ABI BoundType getStride() const
A pair of DIGlobalVariable and DIExpression.
DEFINE_MDNODE_GET(DIGlobalVariableExpression,(Metadata *Variable, Metadata *Expression),(Variable, Expression)) TempDIGlobalVariableExpression clone() const
DIGlobalVariable * getVariable() const
static bool classof(const Metadata *MD)
Metadata * getRawAnnotations() const
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata Metadata * TemplateParams
Metadata MDString MDString Metadata unsigned Metadata bool bool IsDefinition
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 MDString MDString Metadata unsigned Metadata bool IsLocalToUnit
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
Metadata MDString Metadata unsigned unsigned bool std::optional< unsigned > CoroSuspendIdx
DIFile * getFile() const
Metadata MDString Metadata unsigned unsigned bool std::optional< unsigned > CoroSuspendIdx TempDILabel clone() const
StringRef getName() const
static bool classof(const Metadata *MD)
Metadata MDString Metadata unsigned unsigned Column
unsigned getLine() const
bool isArtificial() const
Metadata MDString Metadata unsigned unsigned bool IsArtificial
Metadata * getRawFile() const
unsigned getColumn() const
DILocalScope * getScope() const
Get the local scope for this label.
MDString * getRawName() const
std::optional< unsigned > getCoroSuspendIdx() const
Metadata MDString Metadata unsigned Line
Metadata MDString * Name
DEFINE_MDNODE_GET(DILabel,(DILocalScope *Scope, StringRef Name, DIFile *File, unsigned Line, unsigned Column, bool IsArtificial, std::optional< unsigned > CoroSuspendIdx),(Scope, Name, File, Line, Column, IsArtificial, CoroSuspendIdx)) DEFINE_MDNODE_GET(DILabel
friend class LLVMContextImpl
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this label.
Metadata * getRawScope() const
friend class MDNode
Metadata MDString Metadata * File
static bool classof(const Metadata *MD)
void replaceScope(DIScope *Scope)
Metadata * getRawScope() const
LLVM_ABI DILexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage, ArrayRef< Metadata * > Ops)
DILocalScope * getScope() const
Metadata Metadata unsigned Discriminator
static bool classof(const Metadata *MD)
unsigned getDiscriminator() const
Metadata Metadata unsigned Discriminator TempDILexicalBlockFile clone() const
DEFINE_MDNODE_GET(DILexicalBlockFile,(DILocalScope *Scope, DIFile *File, unsigned Discriminator),(Scope, File, Discriminator)) DEFINE_MDNODE_GET(DILexicalBlockFile
Debug lexical block.
Metadata Metadata unsigned unsigned Column
Metadata Metadata unsigned Line
DEFINE_MDNODE_GET(DILexicalBlock,(DILocalScope *Scope, DIFile *File, unsigned Line, unsigned Column),(Scope, File, Line, Column)) DEFINE_MDNODE_GET(DILexicalBlock
static bool classof(const Metadata *MD)
Metadata Metadata * File
unsigned getColumn() const
Metadata Metadata unsigned unsigned Column TempDILexicalBlock clone() const
A scope for locals.
LLVM_ABI DISubprogram * getSubprogram() const
Get the subprogram for this scope.
LLVM_ABI DILocalScope * getNonLexicalBlockFileScope() const
Get the first non DILexicalBlockFile scope of this scope.
~DILocalScope()=default
DILocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, ArrayRef< Metadata * > Ops)
static bool classof(const Metadata *MD)
static LLVM_ABI DILocalScope * cloneScopeForSubprogram(DILocalScope &RootScope, DISubprogram &NewSP, LLVMContext &Ctx, DenseMap< const MDNode *, MDNode * > &Cache)
Traverses the scope chain rooted at RootScope until it hits a Subprogram, recreating the chain with "...
Metadata MDString Metadata unsigned Metadata * Type
Metadata MDString Metadata * File
static bool classof(const Metadata *MD)
Metadata MDString Metadata unsigned Metadata unsigned DIFlags uint32_t Metadata Annotations TempDILocalVariable clone() const
DILocalScope * getScope() const
Get the local scope for this variable.
Metadata MDString * Name
Metadata MDString Metadata unsigned Metadata unsigned Arg
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
unsigned unsigned DILocalScope * Scope
const DILocation * getWithoutAtom() const
static unsigned getDuplicationFactorFromDiscriminator(unsigned D)
Returns the duplication factor for a given encoded discriminator D, or 1 if no value or 0 is encoded.
static bool isPseudoProbeDiscriminator(unsigned Discriminator)
unsigned unsigned DILocalScope DILocation bool uint64_t AtomGroup
unsigned getDuplicationFactor() const
Returns the duplication factor stored in the discriminator, or 1 if no duplication factor (or 0) is e...
uint64_t getAtomGroup() const
static LLVM_ABI DILocation * getMergedLocations(ArrayRef< DILocation * > Locs)
Try to combine the vector of locations passed as input in a single one.
static unsigned getBaseDiscriminatorBits()
Return the bits used for base discriminators.
static LLVM_ABI std::optional< unsigned > encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI)
Raw encoding of the discriminator.
unsigned unsigned DILocalScope DILocation bool ImplicitCode
Metadata * getRawScope() const
static LLVM_ABI void decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF, unsigned &CI)
Raw decoder for values in an encoded discriminator D.
static LLVM_ABI DILocation * getMergedLocation(DILocation *LocA, DILocation *LocB)
Attempts to merge LocA and LocB into a single location; see DebugLoc::getMergedLocation for more deta...
std::optional< const DILocation * > cloneWithBaseDiscriminator(unsigned BD) const
Returns a new DILocation with updated base discriminator BD.
unsigned getBaseDiscriminator() const
Returns the base discriminator stored in the discriminator.
static unsigned getBaseDiscriminatorFromDiscriminator(unsigned D, bool IsFSDiscriminator=false)
Returns the base discriminator for a given encoded discriminator D.
unsigned unsigned Column
Metadata * getRawInlinedAt() const
unsigned unsigned DILocalScope DILocation * InlinedAt
friend class LLVMContextImpl
static unsigned getMaskedDiscriminator(unsigned D, unsigned B)
Return the masked discriminator value for an input discrimnator value D (i.e.
const DILocation * cloneWithDiscriminator(unsigned Discriminator) const
Returns a new DILocation with updated Discriminator.
static unsigned getCopyIdentifierFromDiscriminator(unsigned D)
Returns the copy identifier for a given encoded discriminator D.
uint8_t getAtomRank() const
DEFINE_MDNODE_GET(DILocation,(unsigned Line, unsigned Column, Metadata *Scope, Metadata *InlinedAt=nullptr, bool ImplicitCode=false, uint64_t AtomGroup=0, uint8_t AtomRank=0),(Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup, AtomRank)) DEFINE_MDNODE_GET(DILocation
void replaceOperandWith(unsigned I, Metadata *New)=delete
std::optional< const DILocation * > cloneByMultiplyingDuplicationFactor(unsigned DF) const
Returns a new DILocation with duplication factor DF * current duplication factor encoded in the discr...
static bool classof(const Metadata *MD)
unsigned getCopyIdentifier() const
Returns the copy identifier stored in the discriminator.
unsigned unsigned DILocalScope DILocation bool uint64_t uint8_t AtomRank
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)
friend class LLVMContextImpl
void replaceElements(DIMacroNodeArray Elements)
unsigned unsigned Metadata Metadata Elements TempDIMacroFile clone() const
DIMacroNodeArray getElements() const
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)
friend class LLVMContextImpl
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
friend class LLVMContextImpl
DEFINE_MDNODE_GET(DIMacro,(unsigned MIType, unsigned Line, StringRef Name, StringRef Value=""),(MIType, Line, Name, Value)) DEFINE_MDNODE_GET(DIMacro
friend class MDNode
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
friend class LLVMContextImpl
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
friend class LLVMContextImpl
bool getExportSymbols() const
Metadata * getRawScope() const
Tagged DWARF-like metadata node.
LLVM_ABI dwarf::Tag getTag() const
static MDString * getCanonicalMDString(LLVMContext &Context, StringRef S)
static LLVM_ABI DIFlags getFlag(StringRef Flag)
static LLVM_ABI DIFlags splitFlags(DIFlags Flags, SmallVectorImpl< DIFlags > &SplitFlags)
Split up a flags bitfield.
void setTag(unsigned Tag)
Allow subclasses to mutate the tag.
DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, ArrayRef< Metadata * > Ops1, ArrayRef< Metadata * > Ops2={})
StringRef getStringOperand(unsigned I) const
Ty * getOperandAs(unsigned I) const
friend class LLVMContextImpl
static bool classof(const Metadata *MD)
static LLVM_ABI StringRef getFlagString(DIFlags Flag)
friend class MDNode
~DINode()=default
DIFlags
Debug info flags.
MDString Metadata unsigned MDString MDString unsigned Metadata Type TempDIObjCProperty clone() const
unsigned getAttributes() const
StringRef getFilename() const
MDString * getRawName() const
StringRef getDirectory() const
MDString * getRawSetterName() const
Metadata * getRawType() const
StringRef getGetterName() const
MDString Metadata * File
MDString Metadata unsigned MDString MDString unsigned Metadata * Type
static bool classof(const Metadata *MD)
MDString * getRawGetterName() const
Metadata * getRawFile() const
MDString Metadata unsigned MDString * GetterName
MDString Metadata unsigned MDString MDString * SetterName
StringRef getName() const
DEFINE_MDNODE_GET(DIObjCProperty,(StringRef Name, DIFile *File, unsigned Line, StringRef GetterName, StringRef SetterName, unsigned Attributes, DIType *Type),(Name, File, Line, GetterName, SetterName, Attributes, Type)) DEFINE_MDNODE_GET(DIObjCProperty
StringRef getSetterName() const
Base class for scope-like contexts.
~DIScope()=default
StringRef getFilename() const
LLVM_ABI StringRef getName() const
static bool classof(const Metadata *MD)
DIFile * getFile() const
StringRef getDirectory() const
std::optional< StringRef > getSource() const
LLVM_ABI DIScope * getScope() const
Metadata * getRawFile() const
Return the raw underlying file.
DIScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, ArrayRef< Metadata * > Ops)
Wrapper structure that holds a language name and its version.
uint16_t getUnversionedName() const
Transitional API for cases where we do not yet support versioned source language names.
uint32_t getVersion() const
Returns language version. Only valid for versioned language names.
DISourceLanguageName(uint16_t Lang, uint32_t Version)
uint16_t getName() const
Returns a versioned or unversioned language name.
String type, Fortran CHARACTER(n)
unsigned MDString * Name
unsigned MDString Metadata Metadata Metadata uint64_t SizeInBits
unsigned getEncoding() const
unsigned MDString Metadata Metadata Metadata uint64_t uint32_t AlignInBits
static bool classof(const Metadata *MD)
unsigned MDString Metadata Metadata Metadata * StringLocationExp
unsigned MDString Metadata Metadata Metadata uint64_t uint32_t unsigned Encoding unsigned MDString Metadata Metadata Metadata Metadata uint32_t unsigned Encoding TempDIStringType clone() const
DIExpression * getStringLengthExp() const
unsigned MDString Metadata Metadata * StringLengthExp
Metadata * getRawStringLengthExp() const
unsigned MDString Metadata Metadata Metadata uint64_t uint32_t unsigned Encoding
Metadata * getRawStringLength() const
DIVariable * getStringLength() const
DIExpression * getStringLocationExp() const
unsigned MDString Metadata * StringLength
Metadata * getRawStringLocationExp() const
DEFINE_MDNODE_GET(DIStringType,(unsigned Tag, StringRef Name, uint64_t SizeInBits, uint32_t AlignInBits),(Tag, Name, nullptr, nullptr, nullptr, SizeInBits, AlignInBits, 0)) DEFINE_MDNODE_GET(DIStringType
Subprogram description. Uses SubclassData1.
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata * Unit
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata Metadata MDString bool UsesKeyInstructions
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata Metadata * Annotations
void cleanupRetainedNodes()
When IR modules are merged, typically during LTO, the merged module may contain several types having ...
Metadata MDString MDString Metadata unsigned Metadata unsigned ScopeLine
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags SPFlags
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
static DILocalScope * getRetainedNodeScope(MDNode *N)
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata Metadata MDString * TargetFuncName
static LLVM_ABI DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized, unsigned Virtuality=SPFlagNonvirtual, bool IsMainSubprogram=false)
static void cleanupRetainedNodes(const RangeT &NewDistinctSPs)
Calls SP->cleanupRetainedNodes() for a range of DISubprograms.
static const DIScope * getRawRetainedNodeScope(const MDNode *N)
void forEachRetainedNode(FuncLVT &&FuncLV, FuncLabelT &&FuncLabel, FuncImportedEntityT &&FuncIE, FuncTypeT &&FuncType)
For each retained node, applies one of the given functions depending on the type of a node.
Metadata MDString * Name
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata * ThrownTypes
DEFINE_MDNODE_GET(DISubprogram,(DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, unsigned Line, DISubroutineType *Type, unsigned ScopeLine, DIType *ContainingType, unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit, DITemplateParameterArray TemplateParams=nullptr, DISubprogram *Declaration=nullptr, DINodeArray RetainedNodes=nullptr, DITypeArray ThrownTypes=nullptr, DINodeArray Annotations=nullptr, StringRef TargetFuncName="", bool UsesKeyInstructions=false),(Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType, VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams, Declaration, RetainedNodes, ThrownTypes, Annotations, TargetFuncName, UsesKeyInstructions)) DEFINE_MDNODE_GET(DISubprogram
static LLVM_ABI DISPFlags getFlag(StringRef Flag)
Metadata MDString MDString Metadata * File
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned VirtualIndex
static LLVM_ABI DISPFlags splitFlags(DISPFlags Flags, SmallVectorImpl< DISPFlags > &SplitFlags)
Split up a flags bitfield for easier printing.
static bool classof(const Metadata *MD)
Metadata MDString MDString * LinkageName
static LLVM_ABI StringRef getFlagString(DISPFlags Flag)
Metadata MDString MDString Metadata unsigned Metadata * Type
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata * RetainedNodes
DISPFlags
Debug info subprogram flags.
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int ThisAdjustment
LLVM_ABI bool describes(const Function *F) const
Check if this subprogram describes the given function.
StringRef DIFile unsigned Line
Metadata * getRawUpperBound() const
BoundType getLowerBound() const
StringRef DIFile unsigned DIScope uint64_t uint32_t DIFlags DIType Metadata Metadata * UpperBound
StringRef DIFile unsigned DIScope uint64_t uint32_t DIFlags DIType * BaseType
StringRef DIFile unsigned DIScope uint64_t uint32_t DIFlags DIType Metadata Metadata Metadata Metadata * Bias
StringRef DIFile unsigned DIScope uint64_t uint32_t DIFlags DIType Metadata Metadata Metadata * Stride
StringRef DIFile unsigned DIScope uint64_t SizeInBits
static bool classof(const Metadata *MD)
BoundType getBias() const
DEFINE_MDNODE_GET(DISubrangeType,(MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *SizeInBits, uint32_t AlignInBits, DIFlags Flags, Metadata *BaseType, Metadata *LowerBound, Metadata *UpperBound, Metadata *Stride, Metadata *Bias),(Name, File, Line, Scope, SizeInBits, AlignInBits, Flags, BaseType, LowerBound, UpperBound, Stride, Bias)) DEFINE_MDNODE_GET(DISubrangeType
Metadata * getRawBias() const
Metadata * getRawBaseType() const
StringRef DIFile * File
PointerUnion< ConstantInt *, DIVariable *, DIExpression *, DIDerivedType * > BoundType
StringRef DIFile unsigned DIScope * Scope
BoundType getUpperBound() const
DIType * getBaseType() const
Get the base type this is derived from.
BoundType getStride() const
Metadata * getRawLowerBound() const
StringRef DIFile unsigned DIScope uint64_t uint32_t AlignInBits
Metadata * getRawStride() const
StringRef DIFile unsigned DIScope uint64_t uint32_t DIFlags DIType Metadata * LowerBound
StringRef DIFile unsigned DIScope uint64_t uint32_t DIFlags Flags
StringRef DIFile unsigned DIScope uint64_t uint32_t DIFlags DIType Metadata Metadata Metadata Metadata Bias TempDISubrangeType clone() const
static bool classof(const Metadata *MD)
LLVM_ABI BoundType getUpperBound() const
LLVM_ABI BoundType getStride() const
LLVM_ABI BoundType getLowerBound() const
DEFINE_MDNODE_GET(DISubrange,(int64_t Count, int64_t LowerBound=0),(Count, LowerBound)) DEFINE_MDNODE_GET(DISubrange
friend class LLVMContextImpl
LLVM_ABI BoundType getCount() const
Metadata int64_t LowerBound
Type array for a subprogram.
DITypeArray getTypeArray() const
TempDISubroutineType cloneWithCC(uint8_t CC) const
DEFINE_MDNODE_GET(DISubroutineType,(DIFlags Flags, uint8_t CC, DITypeArray TypeArray),(Flags, CC, TypeArray)) DEFINE_MDNODE_GET(DISubroutineType
DIFlags uint8_t Metadata * TypeArray
static bool classof(const Metadata *MD)
Metadata * getRawTypeArray() const
DIFlags uint8_t Metadata TypeArray TempDISubroutineType clone() const
static bool classof(const Metadata *MD)
DITemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage, unsigned Tag, bool IsDefault, ArrayRef< Metadata * > Ops)
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
Base class for types.
bool isLittleEndian() const
static constexpr unsigned N_OPERANDS
bool isPublic() const
bool isPrivate() const
uint32_t getNumExtraInhabitants() const
bool isBigEndian() const
bool isLValueReference() const
bool isBitField() const
~DIType()=default
bool isStaticMember() const
bool isVirtual() const
TempDIType cloneWithFlags(DIFlags NewFlags) const
Returns a new temporary DIType with updated Flags.
bool isObjcClassComplete() const
MDString * getRawName() const
bool isAppleBlockExtension() const
uint64_t getOffsetInBits() const
bool isVector() const
bool isProtected() const
bool isObjectPointer() const
DIFlags getFlags() const
Metadata * getRawScope() const
StringRef getName() const
bool isForwardDecl() const
bool isTypePassByValue() const
uint64_t getSizeInBits() const
static bool classof(const Metadata *MD)
DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants, DIFlags Flags, ArrayRef< Metadata * > Ops)
uint32_t getAlignInBytes() const
void mutate(unsigned Tag, unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants, DIFlags Flags)
Change fields in place.
void init(unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants, DIFlags Flags)
LLVM_ABI uint32_t getAlignInBits() const
Metadata * getRawSizeInBits() const
unsigned getLine() const
bool isRValueReference() const
bool isArtificial() const
bool getExportSymbols() const
TempDIType clone() const
DIScope * getScope() const
bool isTypePassByReference() const
Metadata * getRawOffsetInBits() const
Base class for variables.
std::optional< DIBasicType::Signedness > getSignedness() const
Return the signedness of this variable's type, or std::nullopt if this type is neither signed nor uns...
uint32_t getAlignInBits() const
DIFile * getFile() const
MDString * getRawName() const
uint32_t getAlignInBytes() const
DIScope * getScope() const
~DIVariable()=default
StringRef getDirectory() const
LLVM_ABI std::optional< uint64_t > getSizeInBits() const
Determines the size of the variable's type.
Metadata * getRawFile() const
std::optional< StringRef > getSource() const
StringRef getFilename() const
Metadata * getRawType() const
static bool classof(const Metadata *MD)
LLVM_ABI DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, signed Line, ArrayRef< Metadata * > Ops, uint32_t AlignInBits=0)
DIType * getType() const
unsigned getLine() const
StringRef getName() const
Metadata * getRawScope() const
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
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).
LLVM_ABI DebugVariableAggregate(const DbgVariableRecord *DVR)
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
LLVM_ABI DebugVariable(const DbgVariableRecord *DVR)
Class representing an expression and its matching format.
Generic tagged DWARF-like metadata node.
static bool classof(const Metadata *MD)
unsigned MDString ArrayRef< Metadata * > DwarfOps TempGenericDINode clone() const
Return a (temporary) clone of this.
LLVM_ABI dwarf::Tag getTag() const
StringRef getHeader() const
MDString * getRawHeader() const
const MDOperand & getDwarfOperand(unsigned I) const
unsigned getHash() const
unsigned getNumDwarfOperands() const
op_iterator dwarf_op_end() const
op_iterator dwarf_op_begin() const
unsigned MDString * Header
op_range dwarf_operands() const
DEFINE_MDNODE_GET(GenericDINode,(unsigned Tag, StringRef Header, ArrayRef< Metadata * > DwarfOps),(Tag, Header, DwarfOps)) DEFINE_MDNODE_GET(GenericDINode
void replaceDwarfOperandWith(unsigned I, Metadata *New)
unsigned MDString ArrayRef< Metadata * > DwarfOps
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Metadata node.
Definition Metadata.h:1080
friend class DIAssignID
Definition Metadata.h:1083
LLVM_ABI void replaceOperandWith(unsigned I, Metadata *New)
Replace a specific operand.
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1444
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1584
op_iterator op_end() const
Definition Metadata.h:1438
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1572
bool isUniqued() const
Definition Metadata.h:1262
unsigned getNumOperands() const
Return number of MDNode operands.
Definition Metadata.h:1450
iterator_range< op_iterator > op_range
Definition Metadata.h:1432
LLVM_ABI TempMDNode clone() const
Create a (temporary) clone of this.
Definition Metadata.cpp:683
bool isDistinct() const
Definition Metadata.h:1263
LLVM_ABI void setOperand(unsigned I, Metadata *New)
Set an operand.
op_iterator op_begin() const
Definition Metadata.h:1434
LLVMContext & getContext() const
Definition Metadata.h:1244
LLVM_ABI void dropAllReferences()
Definition Metadata.cpp:923
const MDOperand * op_iterator
Definition Metadata.h:1431
Tracking metadata reference owned by Metadata.
Definition Metadata.h:902
Metadata * get() const
Definition Metadata.h:931
A single uniqued string.
Definition Metadata.h:722
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
Definition Metadata.cpp:614
Tuple of metadata.
Definition Metadata.h:1500
Root of the metadata hierarchy.
Definition Metadata.h:64
StorageType
Active type of storage.
Definition Metadata.h:72
unsigned short SubclassData16
Definition Metadata.h:78
unsigned SubclassData32
Definition Metadata.h:79
unsigned char Storage
Storage flag for non-uniqued, otherwise unowned, metadata.
Definition Metadata.h:75
unsigned getMetadataID() const
Definition Metadata.h:104
unsigned char SubclassData1
Definition Metadata.h:77
Metadata(unsigned ID, StorageType Storage)
Definition Metadata.h:88
A discriminated union of two or more pointer types, with the discriminator in the low bits of the poi...
LLVM_ABI SmallVector< DbgVariableRecord * > getAllDbgVariableRecordUsers()
Returns the list of all DbgVariableRecord users of this.
Definition Metadata.cpp:279
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
typename SuperClass::iterator iterator
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:314
LLVM Value Representation.
Definition Value.h:75
A range adaptor for a pair of iterators.
LLVM_ABI unsigned getVirtuality(StringRef VirtualityString)
Definition Dwarf.cpp:385
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
template class LLVM_TEMPLATE_ABI opt< bool >
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:557
bool operator<(int64_t V1, const APSInt &V2)
Definition APSInt.h:360
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI cl::opt< bool > EnableFSDiscriminator
bool operator!=(uint64_t V1, const APInt &V2)
Definition APInt.h:2142
auto cast_or_null(const Y &Val)
Definition Casting.h:714
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
static unsigned getBaseFSBitEnd()
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
@ Ref
The access may reference the value stored in memory.
Definition ModRef.h:32
@ Other
Any other memory.
Definition ModRef.h:68
static unsigned getN1Bits(int N)
FunctionAddr VTableAddr Next
Definition InstrProf.h:141
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1946
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition Hashing.h:325
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:874
#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.
DIExpression::FragmentInfo FragmentInfo
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...
static uint32_t extractProbeIndex(uint32_t Value)
Definition PseudoProbe.h:75
static std::optional< uint32_t > extractDwarfBaseDiscriminator(uint32_t Value)
Definition PseudoProbe.h:81