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 source language identity metadata that includes
70/// language name, optional language version, and an optional language dialect.
71///
72/// Some debug-info formats, particularly DWARF, distniguish between
73/// language codes that include the version name and codes that don't.
74/// DISourceLanguageName may hold either of these.
75///
77 /// Language version. The version scheme is language
78 /// dependent.
79 uint32_t Version = 0;
80
81 /// Language name.
82 /// If \ref HasVersion is \c true, then this name
83 /// is version independent (i.e., doesn't include the language
84 /// version in its name).
85 uint16_t Name;
86
87 /// If \c true, then \ref Version is interpretable and \ref Name
88 /// is a version independent name.
89 bool HasVersion;
90
91 /// Optional target-specific language dialect for DWARF that can be used to
92 /// indicate the programming/execution model.
93 ///
94 /// This is intentionally not modeled as a DICompileUnit operand. Code that
95 /// introspects DICompileUnit through getNumOperands()/getOperand(i) will not
96 /// see this field.
97 uint16_t Dialect = 0;
98
99public:
100 bool hasVersionedName() const { return HasVersion; }
101
102 /// Returns a versioned or unversioned language name.
103 uint16_t getName() const { return Name; }
104
105 /// Transitional API for cases where we do not yet support
106 /// versioned source language names. Use \ref getName instead.
107 ///
108 /// FIXME: remove once all callers of this API account for versioned
109 /// names.
112 return Name;
113 }
114
115 /// Returns language version. Only valid for versioned language names.
118 return Version;
119 }
120
121 uint16_t getDialect() const { return Dialect; }
122
123 DISourceLanguageName(uint16_t Lang, uint32_t Version, uint16_t Dialect = 0)
124 : Version(Version), Name(Lang), HasVersion(true), Dialect(Dialect) {}
126 : Version(0), Name(Lang), HasVersion(false), Dialect(Dialect) {}
127};
128
129class DbgVariableRecord;
130
132
133/// Tagged DWARF-like metadata node.
134///
135/// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
136/// defined in llvm/BinaryFormat/Dwarf.h). Called \a DINode because it's
137/// potentially used for non-DWARF output.
138///
139/// Uses the SubclassData16 Metadata slot.
140class DINode : public MDNode {
141 friend class LLVMContextImpl;
142 friend class MDNode;
143
144protected:
145 DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
147 : MDNode(C, ID, Storage, Ops1, Ops2) {
148 assert(Tag < 1u << 16);
150 }
151 ~DINode() = default;
152
153 template <class Ty> Ty *getOperandAs(unsigned I) const {
155 }
156
157 StringRef getStringOperand(unsigned I) const {
158 if (auto *S = getOperandAs<MDString>(I))
159 return S->getString();
160 return StringRef();
161 }
162
164 if (S.empty())
165 return nullptr;
166 return MDString::get(Context, S);
167 }
168
169 /// Allow subclasses to mutate the tag.
170 void setTag(unsigned Tag) { SubclassData16 = Tag; }
171
172public:
173 LLVM_ABI dwarf::Tag getTag() const;
174
175 /// Debug info flags.
176 ///
177 /// The three accessibility flags are mutually exclusive and rolled together
178 /// in the first two bits.
180#define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
181#define DI_FLAG_LARGEST_NEEDED
182#include "llvm/IR/DebugInfoFlags.def"
183 FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic,
184 FlagPtrToMemberRep = FlagSingleInheritance | FlagMultipleInheritance |
185 FlagVirtualInheritance,
186 LLVM_MARK_AS_BITMASK_ENUM(FlagLargest)
187 };
188
189 LLVM_ABI static DIFlags getFlag(StringRef Flag);
190 LLVM_ABI static StringRef getFlagString(DIFlags Flag);
191
192 /// Split up a flags bitfield.
193 ///
194 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
195 /// any remaining (unrecognized) bits.
196 LLVM_ABI static DIFlags splitFlags(DIFlags Flags,
197 SmallVectorImpl<DIFlags> &SplitFlags);
198
199 static bool classof(const Metadata *MD) {
200 switch (MD->getMetadataID()) {
201 default:
202 return false;
203 case GenericDINodeKind:
204 case DISubrangeKind:
205 case DIEnumeratorKind:
206 case DIBasicTypeKind:
207 case DIFixedPointTypeKind:
208 case DIStringTypeKind:
209 case DISubrangeTypeKind:
210 case DIDerivedTypeKind:
211 case DICompositeTypeKind:
212 case DISubroutineTypeKind:
213 case DIFileKind:
214 case DICompileUnitKind:
215 case DISubprogramKind:
216 case DILexicalBlockKind:
217 case DILexicalBlockFileKind:
218 case DINamespaceKind:
219 case DICommonBlockKind:
220 case DITemplateTypeParameterKind:
221 case DITemplateValueParameterKind:
222 case DIGlobalVariableKind:
223 case DILocalVariableKind:
224 case DILabelKind:
225 case DIObjCPropertyKind:
226 case DIImportedEntityKind:
227 case DIModuleKind:
228 case DIGenericSubrangeKind:
229 case DIAssignIDKind:
230 return true;
231 }
232 }
233};
234
235/// Generic tagged DWARF-like metadata node.
236///
237/// An un-specialized DWARF-like metadata node. The first operand is a
238/// (possibly empty) null-separated \a MDString header that contains arbitrary
239/// fields. The remaining operands are \a dwarf_operands(), and are pointers
240/// to other metadata.
241///
242/// Uses the SubclassData32 Metadata slot.
243class GenericDINode : public DINode {
244 friend class LLVMContextImpl;
245 friend class MDNode;
246
247 GenericDINode(LLVMContext &C, StorageType Storage, unsigned Hash,
248 unsigned Tag, ArrayRef<Metadata *> Ops1,
250 : DINode(C, GenericDINodeKind, Storage, Tag, Ops1, Ops2) {
251 setHash(Hash);
252 }
254
255 void setHash(unsigned Hash) { SubclassData32 = Hash; }
256 void recalculateHash();
257
258 static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
260 StorageType Storage, bool ShouldCreate = true) {
261 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
262 DwarfOps, Storage, ShouldCreate);
263 }
264
265 LLVM_ABI static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
266 MDString *Header,
269 bool ShouldCreate = true);
270
271 TempGenericDINode cloneImpl() const {
274 }
275
276public:
277 unsigned getHash() const { return SubclassData32; }
278
279 DEFINE_MDNODE_GET(GenericDINode,
280 (unsigned Tag, StringRef Header,
282 (Tag, Header, DwarfOps))
283 DEFINE_MDNODE_GET(GenericDINode,
284 (unsigned Tag, MDString *Header,
287
288 /// Return a (temporary) clone of this.
289 TempGenericDINode clone() const { return cloneImpl(); }
290
291 LLVM_ABI dwarf::Tag getTag() const;
292 StringRef getHeader() const { return getStringOperand(0); }
294
295 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
296 op_iterator dwarf_op_end() const { return op_end(); }
299 }
300
301 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
302 const MDOperand &getDwarfOperand(unsigned I) const {
303 return getOperand(I + 1);
304 }
305 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
306 replaceOperandWith(I + 1, New);
307 }
308
309 static bool classof(const Metadata *MD) {
310 return MD->getMetadataID() == GenericDINodeKind;
311 }
312};
313
314/// Assignment ID.
315/// Used to link stores (as an attachment) and dbg.assigns (as an operand).
316/// DIAssignID metadata is never uniqued as we compare instances using
317/// referential equality (the instance/address is the ID).
318class DIAssignID : public MDNode {
319 friend class LLVMContextImpl;
320 friend class MDNode;
321
323 : MDNode(C, DIAssignIDKind, Storage, {}) {}
324
325 ~DIAssignID() { dropAllReferences(); }
326
327 LLVM_ABI static DIAssignID *getImpl(LLVMContext &Context, StorageType Storage,
328 bool ShouldCreate = true);
329
330 TempDIAssignID cloneImpl() const { return getTemporary(getContext()); }
331
332public:
333 // This node has no operands to replace.
334 void replaceOperandWith(unsigned I, Metadata *New) = delete;
335
337 return Context.getReplaceableUses()->getAllDbgVariableRecordUsers();
338 }
339
340 static DIAssignID *getDistinct(LLVMContext &Context) {
341 return getImpl(Context, Distinct);
342 }
343 static TempDIAssignID getTemporary(LLVMContext &Context) {
344 return TempDIAssignID(getImpl(Context, Temporary));
345 }
346 // NOTE: Do not define get(LLVMContext&) - see class comment.
347
348 static bool classof(const Metadata *MD) {
349 return MD->getMetadataID() == DIAssignIDKind;
350 }
351};
352
353/// Array subrange.
354class DISubrange : public DINode {
355 friend class LLVMContextImpl;
356 friend class MDNode;
357
359
360 ~DISubrange() = default;
361
362 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, int64_t Count,
364 bool ShouldCreate = true);
365
366 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, Metadata *CountNode,
368 bool ShouldCreate = true);
369
370 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, Metadata *CountNode,
372 Metadata *UpperBound, Metadata *Stride,
374 bool ShouldCreate = true);
375
376 TempDISubrange cloneImpl() const {
377 return getTemporary(getContext(), getRawCountNode(), getRawLowerBound(),
378 getRawUpperBound(), getRawStride());
379 }
380
381public:
382 DEFINE_MDNODE_GET(DISubrange, (int64_t Count, int64_t LowerBound = 0),
383 (Count, LowerBound))
384
385 DEFINE_MDNODE_GET(DISubrange, (Metadata * CountNode, int64_t LowerBound = 0),
387
388 DEFINE_MDNODE_GET(DISubrange,
390 Metadata *UpperBound, Metadata *Stride),
391 (CountNode, LowerBound, UpperBound, Stride))
392
393 TempDISubrange clone() const { return cloneImpl(); }
394
395 Metadata *getRawCountNode() const { return getOperand(0).get(); }
396
397 Metadata *getRawLowerBound() const { return getOperand(1).get(); }
398
399 Metadata *getRawUpperBound() const { return getOperand(2).get(); }
400
401 Metadata *getRawStride() const { return getOperand(3).get(); }
402
403 typedef PointerUnion<ConstantInt *, DIVariable *, DIExpression *> BoundType;
404
405 LLVM_ABI BoundType getCount() const;
406
407 LLVM_ABI BoundType getLowerBound() const;
408
409 LLVM_ABI BoundType getUpperBound() const;
410
411 LLVM_ABI BoundType getStride() const;
412
413 static bool classof(const Metadata *MD) {
414 return MD->getMetadataID() == DISubrangeKind;
415 }
416};
417
418class DIGenericSubrange : public DINode {
419 friend class LLVMContextImpl;
420 friend class MDNode;
421
422 DIGenericSubrange(LLVMContext &C, StorageType Storage,
424
425 ~DIGenericSubrange() = default;
426
427 LLVM_ABI static DIGenericSubrange *
428 getImpl(LLVMContext &Context, Metadata *CountNode, Metadata *LowerBound,
429 Metadata *UpperBound, Metadata *Stride, StorageType Storage,
430 bool ShouldCreate = true);
431
432 TempDIGenericSubrange cloneImpl() const {
435 }
436
437public:
438 DEFINE_MDNODE_GET(DIGenericSubrange,
439 (Metadata * CountNode, Metadata *LowerBound,
440 Metadata *UpperBound, Metadata *Stride),
441 (CountNode, LowerBound, UpperBound, Stride))
442
443 TempDIGenericSubrange clone() const { return cloneImpl(); }
444
445 Metadata *getRawCountNode() const { return getOperand(0).get(); }
446 Metadata *getRawLowerBound() const { return getOperand(1).get(); }
447 Metadata *getRawUpperBound() const { return getOperand(2).get(); }
448 Metadata *getRawStride() const { return getOperand(3).get(); }
449
451
456
457 static bool classof(const Metadata *MD) {
458 return MD->getMetadataID() == DIGenericSubrangeKind;
459 }
460};
461
462/// Enumeration value.
463///
464/// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
465/// longer creates a type cycle.
466class DIEnumerator : public DINode {
467 friend class LLVMContextImpl;
468 friend class MDNode;
469
470 APInt Value;
471 LLVM_ABI DIEnumerator(LLVMContext &C, StorageType Storage, const APInt &Value,
473 DIEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
475 : DIEnumerator(C, Storage, APInt(64, Value, !IsUnsigned), IsUnsigned,
476 Ops) {}
477 ~DIEnumerator() = default;
478
479 static DIEnumerator *getImpl(LLVMContext &Context, const APInt &Value,
481 StorageType Storage, bool ShouldCreate = true) {
482 return getImpl(Context, Value, IsUnsigned,
483 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
484 }
485 LLVM_ABI static DIEnumerator *getImpl(LLVMContext &Context,
486 const APInt &Value, bool IsUnsigned,
487 MDString *Name, StorageType Storage,
488 bool ShouldCreate = true);
489
490 TempDIEnumerator cloneImpl() const {
492 }
493
494public:
495 DEFINE_MDNODE_GET(DIEnumerator,
496 (int64_t Value, bool IsUnsigned, StringRef Name),
497 (APInt(64, Value, !IsUnsigned), IsUnsigned, Name))
498 DEFINE_MDNODE_GET(DIEnumerator,
499 (int64_t Value, bool IsUnsigned, MDString *Name),
500 (APInt(64, Value, !IsUnsigned), IsUnsigned, Name))
501 DEFINE_MDNODE_GET(DIEnumerator,
502 (APInt Value, bool IsUnsigned, StringRef Name),
503 (Value, IsUnsigned, Name))
504 DEFINE_MDNODE_GET(DIEnumerator,
505 (APInt Value, bool IsUnsigned, MDString *Name),
506 (Value, IsUnsigned, Name))
507
508 TempDIEnumerator clone() const { return cloneImpl(); }
509
510 const APInt &getValue() const { return Value; }
511 bool isUnsigned() const { return SubclassData32; }
512 StringRef getName() const { return getStringOperand(0); }
513
515
516 static bool classof(const Metadata *MD) {
517 return MD->getMetadataID() == DIEnumeratorKind;
518 }
519};
520
521/// Base class for scope-like contexts.
522///
523/// Base class for lexical scopes and types (which are also declaration
524/// contexts).
525///
526/// TODO: Separate the concepts of declaration contexts and lexical scopes.
527class DIScope : public DINode {
528protected:
532 ~DIScope() = default;
533
534public:
536
537 inline StringRef getFilename() const;
538 inline StringRef getDirectory() const;
539 inline std::optional<StringRef> getSource() const;
540
541 LLVM_ABI StringRef getName() const;
542 LLVM_ABI DIScope *getScope() const;
543
544 /// Return the raw underlying file.
545 ///
546 /// A \a DIFile is a \a DIScope, but it doesn't point at a separate file (it
547 /// \em is the file). If \c this is an \a DIFile, we need to return \c this.
548 /// Otherwise, return the first operand, which is where all other subclasses
549 /// store their file pointer.
551 return isa<DIFile>(this) ? const_cast<DIScope *>(this)
552 : static_cast<Metadata *>(getOperand(0));
553 }
554
555 static bool classof(const Metadata *MD) {
556 switch (MD->getMetadataID()) {
557 default:
558 return false;
559 case DIBasicTypeKind:
560 case DIFixedPointTypeKind:
561 case DIStringTypeKind:
562 case DISubrangeTypeKind:
563 case DIDerivedTypeKind:
564 case DICompositeTypeKind:
565 case DISubroutineTypeKind:
566 case DIFileKind:
567 case DICompileUnitKind:
568 case DISubprogramKind:
569 case DILexicalBlockKind:
570 case DILexicalBlockFileKind:
571 case DINamespaceKind:
572 case DICommonBlockKind:
573 case DIModuleKind:
574 return true;
575 }
576 }
577};
578
579/// File.
580///
581/// TODO: Merge with directory/file node (including users).
582/// TODO: Canonicalize paths on creation.
583class DIFile : public DIScope {
584 friend class LLVMContextImpl;
585 friend class MDNode;
586
587public:
588 /// Which algorithm (e.g. MD5) a checksum was generated with.
589 ///
590 /// The encoding is explicit because it is used directly in Bitcode. The
591 /// value 0 is reserved to indicate the absence of a checksum in Bitcode.
593 // The first variant was originally CSK_None, encoded as 0. The new
594 // internal representation removes the need for this by wrapping the
595 // ChecksumInfo in an Optional, but to preserve Bitcode compatibility the 0
596 // encoding is reserved.
600 CSK_Last = CSK_SHA256 // Should be last enumeration.
601 };
602
603 /// A single checksum, represented by a \a Kind and a \a Value (a string).
604 template <typename T> struct ChecksumInfo {
605 /// The kind of checksum which \a Value encodes.
607 /// The string value of the checksum.
609
611 ~ChecksumInfo() = default;
612 bool operator==(const ChecksumInfo<T> &X) const {
613 return Kind == X.Kind && Value == X.Value;
614 }
615 bool operator!=(const ChecksumInfo<T> &X) const { return !(*this == X); }
616 StringRef getKindAsString() const { return getChecksumKindAsString(Kind); }
617 };
618
619private:
620 std::optional<ChecksumInfo<MDString *>> Checksum;
621 /// An optional source. A nullptr means none.
623
625 std::optional<ChecksumInfo<MDString *>> CS, MDString *Src,
627 ~DIFile() = default;
628
629 static DIFile *getImpl(LLVMContext &Context, StringRef Filename,
631 std::optional<ChecksumInfo<StringRef>> CS,
632 std::optional<StringRef> Source, StorageType Storage,
633 bool ShouldCreate = true) {
634 std::optional<ChecksumInfo<MDString *>> MDChecksum;
635 if (CS)
636 MDChecksum.emplace(CS->Kind, getCanonicalMDString(Context, CS->Value));
637 return getImpl(Context, getCanonicalMDString(Context, Filename),
638 getCanonicalMDString(Context, Directory), MDChecksum,
639 Source ? MDString::get(Context, *Source) : nullptr, Storage,
640 ShouldCreate);
641 }
642 LLVM_ABI static DIFile *getImpl(LLVMContext &Context, MDString *Filename,
643 MDString *Directory,
644 std::optional<ChecksumInfo<MDString *>> CS,
645 MDString *Source, StorageType Storage,
646 bool ShouldCreate = true);
647
648 TempDIFile cloneImpl() const {
650 getChecksum(), getSource());
651 }
652
653public:
656 std::optional<ChecksumInfo<StringRef>> CS = std::nullopt,
657 std::optional<StringRef> Source = std::nullopt),
658 (Filename, Directory, CS, Source))
659 DEFINE_MDNODE_GET(DIFile,
661 std::optional<ChecksumInfo<MDString *>> CS = std::nullopt,
662 MDString *Source = nullptr),
663 (Filename, Directory, CS, Source))
664
665 TempDIFile clone() const { return cloneImpl(); }
666
667 StringRef getFilename() const { return getStringOperand(0); }
668 StringRef getDirectory() const { return getStringOperand(1); }
669 std::optional<ChecksumInfo<StringRef>> getChecksum() const {
670 std::optional<ChecksumInfo<StringRef>> StringRefChecksum;
671 if (Checksum)
672 StringRefChecksum.emplace(Checksum->Kind, Checksum->Value->getString());
673 return StringRefChecksum;
674 }
675 std::optional<StringRef> getSource() const {
676 return Source ? std::optional<StringRef>(Source->getString())
677 : std::nullopt;
678 }
679
680 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
681 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
682 std::optional<ChecksumInfo<MDString *>> getRawChecksum() const {
683 return Checksum;
684 }
685 MDString *getRawSource() const { return Source; }
686
687 LLVM_ABI static StringRef getChecksumKindAsString(ChecksumKind CSKind);
688 LLVM_ABI static std::optional<ChecksumKind>
689 getChecksumKind(StringRef CSKindStr);
690
691 static bool classof(const Metadata *MD) {
692 return MD->getMetadataID() == DIFileKind;
693 }
694};
695
697 if (auto *F = getFile())
698 return F->getFilename();
699 return "";
700}
701
703 if (auto *F = getFile())
704 return F->getDirectory();
705 return "";
706}
707
708std::optional<StringRef> DIScope::getSource() const {
709 if (auto *F = getFile())
710 return F->getSource();
711 return std::nullopt;
712}
713
714/// Base class for types.
715///
716/// TODO: Remove the hardcoded name and context, since many types don't use
717/// them.
718/// TODO: Split up flags.
719///
720/// Uses the SubclassData32 Metadata slot.
721class DIType : public DIScope {
722 unsigned Line;
723 DIFlags Flags;
724 uint32_t NumExtraInhabitants;
725
726protected:
727 static constexpr unsigned N_OPERANDS = 5;
728
729 DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
730 unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants,
732 : DIScope(C, ID, Storage, Tag, Ops) {
733 init(Line, AlignInBits, NumExtraInhabitants, Flags);
734 }
735 ~DIType() = default;
736
737 void init(unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants,
738 DIFlags Flags) {
739 this->Line = Line;
740 this->Flags = Flags;
741 this->SubclassData32 = AlignInBits;
742 this->NumExtraInhabitants = NumExtraInhabitants;
743 }
744
745 /// Change fields in place.
746 void mutate(unsigned Tag, unsigned Line, uint32_t AlignInBits,
747 uint32_t NumExtraInhabitants, DIFlags Flags) {
748 assert(isDistinct() && "Only distinct nodes can mutate");
749 setTag(Tag);
750 init(Line, AlignInBits, NumExtraInhabitants, Flags);
751 }
752
753public:
754 TempDIType clone() const {
755 return TempDIType(cast<DIType>(MDNode::clone().release()));
756 }
757
758 unsigned getLine() const { return Line; }
760 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
761 uint32_t getNumExtraInhabitants() const { return NumExtraInhabitants; }
762 DIFlags getFlags() const { return Flags; }
763
765 StringRef getName() const { return getStringOperand(2); }
766
767 Metadata *getRawScope() const { return getOperand(1); }
769
770 Metadata *getRawSizeInBits() const { return getOperand(3); }
773 if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(MD->getValue()))
774 return CI->getZExtValue();
775 }
776 return 0;
777 }
778
779 Metadata *getRawOffsetInBits() const { return getOperand(4); }
782 if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(MD->getValue()))
783 return CI->getZExtValue();
784 }
785 return 0;
786 }
787
788 /// Returns a new temporary DIType with updated Flags
789 TempDIType cloneWithFlags(DIFlags NewFlags) const {
790 auto NewTy = clone();
791 NewTy->Flags = NewFlags;
792 return NewTy;
793 }
794
795 bool isPrivate() const {
796 return (getFlags() & FlagAccessibility) == FlagPrivate;
797 }
798 bool isProtected() const {
799 return (getFlags() & FlagAccessibility) == FlagProtected;
800 }
801 bool isPublic() const {
802 return (getFlags() & FlagAccessibility) == FlagPublic;
803 }
804 bool isForwardDecl() const { return getFlags() & FlagFwdDecl; }
805 bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; }
806 bool isVirtual() const { return getFlags() & FlagVirtual; }
807 bool isArtificial() const { return getFlags() & FlagArtificial; }
808 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
809 bool isObjcClassComplete() const {
810 return getFlags() & FlagObjcClassComplete;
811 }
812 bool isVector() const { return getFlags() & FlagVector; }
813 bool isBitField() const { return getFlags() & FlagBitField; }
814 bool isStaticMember() const { return getFlags() & FlagStaticMember; }
815 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
816 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
817 bool isTypePassByValue() const { return getFlags() & FlagTypePassByValue; }
819 return getFlags() & FlagTypePassByReference;
820 }
821 bool isBigEndian() const { return getFlags() & FlagBigEndian; }
822 bool isLittleEndian() const { return getFlags() & FlagLittleEndian; }
823 bool getExportSymbols() const { return getFlags() & FlagExportSymbols; }
824
825 static bool classof(const Metadata *MD) {
826 switch (MD->getMetadataID()) {
827 default:
828 return false;
829 case DIBasicTypeKind:
830 case DIFixedPointTypeKind:
831 case DIStringTypeKind:
832 case DISubrangeTypeKind:
833 case DIDerivedTypeKind:
834 case DICompositeTypeKind:
835 case DISubroutineTypeKind:
836 return true;
837 }
838 }
839};
840
841/// Basic type, like 'int' or 'float'.
842///
843/// TODO: Split out DW_TAG_unspecified_type.
844/// TODO: Drop unused accessors.
845class DIBasicType : public DIType {
846 friend class LLVMContextImpl;
847 friend class MDNode;
848
849 unsigned Encoding;
850 /// Describes the number of bits used by the value of the object. Non-zero
851 /// when the value of an object does not fully occupy the storage size
852 /// specified by SizeInBits.
853 uint32_t DataSizeInBits;
854
855protected:
857 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
858 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
860 : DIType(C, DIBasicTypeKind, Storage, Tag, LineNo, AlignInBits,
862 Encoding(Encoding), DataSizeInBits(DataSizeInBits) {}
864 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
865 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
868 Flags, Ops),
869 Encoding(Encoding), DataSizeInBits(DataSizeInBits) {}
870 ~DIBasicType() = default;
871
872 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
873 StringRef Name, DIFile *File, unsigned LineNo,
875 uint32_t AlignInBits, unsigned Encoding,
877 uint32_t DataSizeInBits, DIFlags Flags,
878 StorageType Storage, bool ShouldCreate = true) {
879 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
880 LineNo, Scope, SizeInBits, AlignInBits, Encoding,
881 NumExtraInhabitants, DataSizeInBits, Flags, Storage,
882 ShouldCreate);
883 }
884 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
885 MDString *Name, DIFile *File, unsigned LineNo,
887 uint32_t AlignInBits, unsigned Encoding,
889 uint32_t DataSizeInBits, DIFlags Flags,
890 StorageType Storage, bool ShouldCreate = true) {
891 auto *SizeInBitsNode = ConstantAsMetadata::get(
892 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
893 return getImpl(Context, Tag, Name, File, LineNo, Scope, SizeInBitsNode,
894 AlignInBits, Encoding, NumExtraInhabitants, DataSizeInBits,
895 Flags, Storage, ShouldCreate);
896 }
897 LLVM_ABI static DIBasicType *
898 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
899 unsigned LineNo, Metadata *Scope, Metadata *SizeInBits,
902 bool ShouldCreate = true);
903
904 TempDIBasicType cloneImpl() const {
905 return getTemporary(
909 }
910
911public:
913 (Tag, Name, nullptr, 0, nullptr, 0, 0, 0, 0, 0, FlagZero))
916 (Tag, Name, nullptr, 0, nullptr, SizeInBits, 0, 0, 0, 0,
917 FlagZero))
919 (unsigned Tag, MDString *Name, uint64_t SizeInBits),
920 (Tag, Name, nullptr, 0, nullptr, SizeInBits, 0, 0, 0, 0,
921 FlagZero))
924 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
925 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
926 Encoding, 0, 0, Flags))
928 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
929 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
930 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
931 Encoding, 0, 0, Flags))
934 uint32_t AlignInBits, unsigned Encoding,
936 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
940 uint32_t AlignInBits, unsigned Encoding,
941 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
942 DIFlags Flags),
943 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
944 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
948 uint32_t AlignInBits, unsigned Encoding,
952 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
954 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
955 uint32_t AlignInBits, unsigned Encoding,
956 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
957 DIFlags Flags),
958 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
959 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
962 uint32_t AlignInBits, unsigned Encoding,
965 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
966 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
968 (unsigned Tag, MDString *Name, Metadata *File,
970 uint32_t AlignInBits, unsigned Encoding,
971 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
972 DIFlags Flags),
974 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
975
976 TempDIBasicType clone() const { return cloneImpl(); }
977
978 unsigned getEncoding() const { return Encoding; }
979
980 uint32_t getDataSizeInBits() const { return DataSizeInBits; }
981
982 enum class Signedness { Signed, Unsigned };
983
984 /// Return the signedness of this type, or std::nullopt if this type is
985 /// neither signed nor unsigned.
986 LLVM_ABI std::optional<Signedness> getSignedness() const;
987
988 static bool classof(const Metadata *MD) {
989 return MD->getMetadataID() == DIBasicTypeKind ||
990 MD->getMetadataID() == DIFixedPointTypeKind;
991 }
992};
993
994/// Fixed-point type.
995class DIFixedPointType : public DIBasicType {
996 friend class LLVMContextImpl;
997 friend class MDNode;
998
999 // Actually FixedPointKind.
1000 unsigned Kind;
1001 // Used for binary and decimal.
1002 int Factor;
1003 // Used for rational.
1004 APInt Numerator;
1005 APInt Denominator;
1006
1007 DIFixedPointType(LLVMContext &C, StorageType Storage, unsigned Tag,
1008 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
1009 DIFlags Flags, unsigned Kind, int Factor,
1011 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, LineNo, AlignInBits,
1012 Encoding, 0, 0, Flags, Ops),
1013 Kind(Kind), Factor(Factor) {
1014 assert(Kind == FixedPointBinary || Kind == FixedPointDecimal);
1015 }
1017 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
1018 DIFlags Flags, unsigned Kind, APInt Numerator,
1020 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, LineNo, AlignInBits,
1021 Encoding, 0, 0, Flags, Ops),
1022 Kind(Kind), Factor(0), Numerator(Numerator), Denominator(Denominator) {
1023 assert(Kind == FixedPointRational);
1024 }
1025 DIFixedPointType(LLVMContext &C, StorageType Storage, unsigned Tag,
1026 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
1027 DIFlags Flags, unsigned Kind, int Factor, APInt Numerator,
1029 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, LineNo, AlignInBits,
1030 Encoding, 0, 0, Flags, Ops),
1031 Kind(Kind), Factor(Factor), Numerator(Numerator),
1033 ~DIFixedPointType() = default;
1034
1035 static DIFixedPointType *
1036 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1037 unsigned LineNo, DIScope *Scope, uint64_t SizeInBits,
1038 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind,
1039 int Factor, APInt Numerator, APInt Denominator, StorageType Storage,
1040 bool ShouldCreate = true) {
1041 auto *SizeInBitsNode = ConstantAsMetadata::get(
1042 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1043 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1044 LineNo, Scope, SizeInBitsNode, AlignInBits, Encoding, Flags,
1045 Kind, Factor, Numerator, Denominator, Storage, ShouldCreate);
1046 }
1047 static DIFixedPointType *
1048 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1049 unsigned LineNo, DIScope *Scope, Metadata *SizeInBits,
1050 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind,
1051 int Factor, APInt Numerator, APInt Denominator, StorageType Storage,
1052 bool ShouldCreate = true) {
1053 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1055 Kind, Factor, Numerator, Denominator, Storage, ShouldCreate);
1056 }
1057 static DIFixedPointType *
1058 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, DIFile *File,
1059 unsigned LineNo, DIScope *Scope, uint64_t SizeInBits,
1060 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind,
1061 int Factor, APInt Numerator, APInt Denominator, StorageType Storage,
1062 bool ShouldCreate = true) {
1063 auto *SizeInBitsNode = ConstantAsMetadata::get(
1064 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1065 return getImpl(Context, Tag, Name, File, LineNo, Scope, SizeInBitsNode,
1066 AlignInBits, Encoding, Flags, Kind, Factor, Numerator,
1067 Denominator, Storage, ShouldCreate);
1068 }
1069 LLVM_ABI static DIFixedPointType *
1070 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1072 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind,
1073 int Factor, APInt Numerator, APInt Denominator, StorageType Storage,
1074 bool ShouldCreate = true);
1075
1076 TempDIFixedPointType cloneImpl() const {
1079 getAlignInBits(), getEncoding(), getFlags(), Kind,
1080 Factor, Numerator, Denominator);
1081 }
1082
1083public:
1084 enum FixedPointKind : unsigned {
1085 /// Scale factor 2^Factor.
1087 /// Scale factor 10^Factor.
1089 /// Arbitrary rational scale factor.
1092 };
1093
1094 LLVM_ABI static std::optional<FixedPointKind>
1096 LLVM_ABI static const char *fixedPointKindString(FixedPointKind);
1097
1098 DEFINE_MDNODE_GET(DIFixedPointType,
1099 (unsigned Tag, MDString *Name, DIFile *File,
1102 unsigned Kind, int Factor, APInt Numerator,
1103 APInt Denominator),
1105 Encoding, Flags, Kind, Factor, Numerator, Denominator))
1106 DEFINE_MDNODE_GET(DIFixedPointType,
1110 unsigned Kind, int Factor, APInt Numerator,
1111 APInt Denominator),
1113 Encoding, Flags, Kind, Factor, Numerator, Denominator))
1114 DEFINE_MDNODE_GET(DIFixedPointType,
1115 (unsigned Tag, MDString *Name, Metadata *File,
1118 unsigned Kind, int Factor, APInt Numerator,
1119 APInt Denominator),
1121 Encoding, Flags, Kind, Factor, Numerator, Denominator))
1122
1123 TempDIFixedPointType clone() const { return cloneImpl(); }
1124
1125 bool isBinary() const { return Kind == FixedPointBinary; }
1126 bool isDecimal() const { return Kind == FixedPointDecimal; }
1127 bool isRational() const { return Kind == FixedPointRational; }
1128
1129 LLVM_ABI bool isSigned() const;
1130
1131 FixedPointKind getKind() const { return static_cast<FixedPointKind>(Kind); }
1132
1133 int getFactorRaw() const { return Factor; }
1134 int getFactor() const {
1135 assert(Kind == FixedPointBinary || Kind == FixedPointDecimal);
1136 return Factor;
1137 }
1138
1139 const APInt &getNumeratorRaw() const { return Numerator; }
1140 const APInt &getNumerator() const {
1141 assert(Kind == FixedPointRational);
1142 return Numerator;
1143 }
1144
1145 const APInt &getDenominatorRaw() const { return Denominator; }
1146 const APInt &getDenominator() const {
1147 assert(Kind == FixedPointRational);
1148 return Denominator;
1149 }
1150
1151 static bool classof(const Metadata *MD) {
1152 return MD->getMetadataID() == DIFixedPointTypeKind;
1153 }
1154};
1155
1156/// String type, Fortran CHARACTER(n)
1157class DIStringType : public DIType {
1158 friend class LLVMContextImpl;
1159 friend class MDNode;
1160
1161 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1162
1163 unsigned Encoding;
1164
1165 DIStringType(LLVMContext &C, StorageType Storage, unsigned Tag,
1166 uint32_t AlignInBits, unsigned Encoding,
1168 : DIType(C, DIStringTypeKind, Storage, Tag, 0, AlignInBits, 0, FlagZero,
1169 Ops),
1170 Encoding(Encoding) {}
1171 ~DIStringType() = default;
1172
1173 static DIStringType *getImpl(LLVMContext &Context, unsigned Tag,
1175 Metadata *StrLenExp, Metadata *StrLocationExp,
1177 unsigned Encoding, StorageType Storage,
1178 bool ShouldCreate = true) {
1179 auto *SizeInBitsNode = ConstantAsMetadata::get(
1180 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1181 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
1182 StringLength, StrLenExp, StrLocationExp, SizeInBitsNode,
1183 AlignInBits, Encoding, Storage, ShouldCreate);
1184 }
1185 static DIStringType *getImpl(LLVMContext &Context, unsigned Tag,
1186 MDString *Name, Metadata *StringLength,
1187 Metadata *StrLenExp, Metadata *StrLocationExp,
1189 unsigned Encoding, StorageType Storage,
1190 bool ShouldCreate = true) {
1191 auto *SizeInBitsNode = ConstantAsMetadata::get(
1192 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1193 return getImpl(Context, Tag, Name, StringLength, StrLenExp, StrLocationExp,
1194 SizeInBitsNode, AlignInBits, Encoding, Storage,
1195 ShouldCreate);
1196 }
1197 LLVM_ABI static DIStringType *
1198 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name,
1199 Metadata *StringLength, Metadata *StrLenExp, Metadata *StrLocationExp,
1200 Metadata *SizeInBits, uint32_t AlignInBits, unsigned Encoding,
1201 StorageType Storage, bool ShouldCreate = true);
1202
1203 TempDIStringType cloneImpl() const {
1208 }
1209
1210public:
1211 DEFINE_MDNODE_GET(DIStringType,
1212 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
1214 (Tag, Name, nullptr, nullptr, nullptr, SizeInBits,
1215 AlignInBits, 0))
1216 DEFINE_MDNODE_GET(DIStringType,
1220 unsigned Encoding),
1223 DEFINE_MDNODE_GET(DIStringType,
1224 (unsigned Tag, StringRef Name, Metadata *StringLength,
1227 unsigned Encoding),
1230 DEFINE_MDNODE_GET(DIStringType,
1234 unsigned Encoding),
1237
1238 TempDIStringType clone() const { return cloneImpl(); }
1239
1240 static bool classof(const Metadata *MD) {
1241 return MD->getMetadataID() == DIStringTypeKind;
1242 }
1243
1247
1251
1255
1256 unsigned getEncoding() const { return Encoding; }
1257
1258 Metadata *getRawStringLength() const { return getOperand(MY_FIRST_OPERAND); }
1259
1261 return getOperand(MY_FIRST_OPERAND + 1);
1262 }
1263
1265 return getOperand(MY_FIRST_OPERAND + 2);
1266 }
1267};
1268
1269/// Derived types.
1270///
1271/// This includes qualified types, pointers, references, friends, typedefs, and
1272/// class members.
1273///
1274/// TODO: Split out members (inheritance, fields, methods, etc.).
1275class DIDerivedType : public DIType {
1276public:
1277 /// Pointer authentication (__ptrauth) metadata.
1279 // RawData layout:
1280 // - Bits 0..3: Key
1281 // - Bit 4: IsAddressDiscriminated
1282 // - Bits 5..20: ExtraDiscriminator
1283 // - Bit 21: IsaPointer
1284 // - Bit 22: AuthenticatesNullValues
1285 unsigned RawData;
1286
1287 PtrAuthData(unsigned FromRawData) : RawData(FromRawData) {}
1288 PtrAuthData(unsigned Key, bool IsDiscr, unsigned Discriminator,
1289 bool IsaPointer, bool AuthenticatesNullValues) {
1290 assert(Key < 16);
1291 assert(Discriminator <= 0xffff);
1292 RawData = (Key << 0) | (IsDiscr ? (1 << 4) : 0) | (Discriminator << 5) |
1293 (IsaPointer ? (1 << 21) : 0) |
1294 (AuthenticatesNullValues ? (1 << 22) : 0);
1295 }
1296
1297 unsigned key() { return (RawData >> 0) & 0b1111; }
1298 bool isAddressDiscriminated() { return (RawData >> 4) & 1; }
1299 unsigned extraDiscriminator() { return (RawData >> 5) & 0xffff; }
1300 bool isaPointer() { return (RawData >> 21) & 1; }
1301 bool authenticatesNullValues() { return (RawData >> 22) & 1; }
1302 };
1303
1304private:
1305 friend class LLVMContextImpl;
1306 friend class MDNode;
1307
1308 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1309
1310 /// The DWARF address space of the memory pointed to or referenced by a
1311 /// pointer or reference type respectively.
1312 std::optional<unsigned> DWARFAddressSpace;
1313
1314 DIDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
1315 unsigned Line, uint32_t AlignInBits,
1316 std::optional<unsigned> DWARFAddressSpace,
1317 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1319 : DIType(C, DIDerivedTypeKind, Storage, Tag, Line, AlignInBits, 0, Flags,
1320 Ops),
1321 DWARFAddressSpace(DWARFAddressSpace) {
1322 if (PtrAuthData)
1324 }
1325 ~DIDerivedType() = default;
1326 static DIDerivedType *
1327 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1328 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1330 std::optional<unsigned> DWARFAddressSpace,
1331 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1333 bool ShouldCreate = true) {
1334 auto *SizeInBitsNode = ConstantAsMetadata::get(
1335 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1336 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1337 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1338 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1339 Line, Scope, BaseType, SizeInBitsNode, AlignInBits,
1340 OffsetInBitsNode, DWARFAddressSpace, PtrAuthData, Flags,
1341 ExtraData, Annotations.get(), Storage, ShouldCreate);
1342 }
1343 static DIDerivedType *
1344 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, DIFile *File,
1345 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1347 std::optional<unsigned> DWARFAddressSpace,
1348 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1350 bool ShouldCreate = true) {
1351 auto *SizeInBitsNode = ConstantAsMetadata::get(
1352 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1353 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1354 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1355 return getImpl(Context, Tag, Name, File, Line, Scope, BaseType,
1356 SizeInBitsNode, AlignInBits, OffsetInBitsNode,
1358 Annotations.get(), Storage, ShouldCreate);
1359 }
1360 static DIDerivedType *
1361 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1364 std::optional<unsigned> DWARFAddressSpace,
1365 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1367 bool ShouldCreate = true) {
1368 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1370 DWARFAddressSpace, PtrAuthData, Flags, ExtraData,
1371 Annotations.get(), Storage, ShouldCreate);
1372 }
1373 LLVM_ABI static DIDerivedType *
1374 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1375 unsigned Line, Metadata *Scope, Metadata *BaseType,
1377 std::optional<unsigned> DWARFAddressSpace,
1378 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1380 bool ShouldCreate = true);
1381
1382 TempDIDerivedType cloneImpl() const {
1383 return getTemporary(
1386 getRawOffsetInBits(), getDWARFAddressSpace(), getPtrAuthData(),
1388 }
1389
1390public:
1391 DEFINE_MDNODE_GET(DIDerivedType,
1392 (unsigned Tag, MDString *Name, Metadata *File,
1393 unsigned Line, Metadata *Scope, Metadata *BaseType,
1396 std::optional<unsigned> DWARFAddressSpace,
1397 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1398 Metadata *ExtraData = nullptr,
1399 Metadata *Annotations = nullptr),
1401 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1403 DEFINE_MDNODE_GET(DIDerivedType,
1404 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1407 std::optional<unsigned> DWARFAddressSpace,
1408 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1410 DINodeArray Annotations = nullptr),
1412 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1414 DEFINE_MDNODE_GET(DIDerivedType,
1415 (unsigned Tag, MDString *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 DEFINE_MDNODE_GET(DIDerivedType,
1426 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1429 std::optional<unsigned> DWARFAddressSpace,
1430 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1431 Metadata *ExtraData = nullptr,
1432 DINodeArray Annotations = nullptr),
1434 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1436
1437 TempDIDerivedType clone() const { return cloneImpl(); }
1438
1439 /// Get the base type this is derived from.
1440 DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); }
1441 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1442
1443 /// \returns The DWARF address space of the memory pointed to or referenced by
1444 /// a pointer or reference type respectively.
1445 std::optional<unsigned> getDWARFAddressSpace() const {
1446 return DWARFAddressSpace;
1447 }
1448
1449 LLVM_ABI std::optional<PtrAuthData> getPtrAuthData() const;
1450
1451 /// Get extra data associated with this derived type.
1452 ///
1453 /// Class type for pointer-to-members, objective-c property node for ivars,
1454 /// global constant wrapper for static members, virtual base pointer offset
1455 /// for inheritance, a tuple of template parameters for template aliases,
1456 /// discriminant for a variant, or storage offset for a bit field.
1457 ///
1458 /// TODO: Separate out types that need this extra operand: pointer-to-member
1459 /// types and member fields (static members and ivars).
1461 Metadata *getRawExtraData() const { return getOperand(MY_FIRST_OPERAND + 1); }
1462
1463 /// Get the template parameters from a template alias.
1464 DITemplateParameterArray getTemplateParams() const {
1466 }
1467
1468 /// Get annotations associated with this derived type.
1469 DINodeArray getAnnotations() const {
1471 }
1473 return getOperand(MY_FIRST_OPERAND + 2);
1474 }
1475
1476 /// Get casted version of extra data.
1477 /// @{
1478 LLVM_ABI DIType *getClassType() const;
1479
1483
1485
1487
1488 LLVM_ABI Constant *getConstant() const;
1489
1491 /// @}
1492
1493 static bool classof(const Metadata *MD) {
1494 return MD->getMetadataID() == DIDerivedTypeKind;
1495 }
1496};
1497
1500 return Lhs.RawData == Rhs.RawData;
1501}
1502
1505 return !(Lhs == Rhs);
1506}
1507
1508/// Subrange type. This is somewhat similar to DISubrange, but it
1509/// is also a DIType.
1510class DISubrangeType : public DIType {
1511public:
1513 DIDerivedType *>
1515
1516private:
1517 friend class LLVMContextImpl;
1518 friend class MDNode;
1519
1520 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1521
1522 DISubrangeType(LLVMContext &C, StorageType Storage, unsigned Line,
1524
1525 ~DISubrangeType() = default;
1526
1527 static DISubrangeType *
1528 getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
1532 StorageType Storage, bool ShouldCreate = true) {
1533 auto *SizeInBitsNode = ConstantAsMetadata::get(
1534 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1535 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1536 Scope, SizeInBitsNode, AlignInBits, Flags, BaseType,
1537 LowerBound, UpperBound, Stride, Bias, Storage, ShouldCreate);
1538 }
1539
1540 LLVM_ABI static DISubrangeType *
1541 getImpl(LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
1543 DIFlags Flags, Metadata *BaseType, Metadata *LowerBound,
1545 StorageType Storage, bool ShouldCreate = true);
1546
1547 TempDISubrangeType cloneImpl() const {
1552 }
1553
1554 LLVM_ABI BoundType convertRawToBound(Metadata *IN) const;
1555
1556public:
1557 DEFINE_MDNODE_GET(DISubrangeType,
1558 (MDString * Name, Metadata *File, unsigned Line,
1565 DEFINE_MDNODE_GET(DISubrangeType,
1572
1573 TempDISubrangeType clone() const { return cloneImpl(); }
1574
1575 /// Get the base type this is derived from.
1577 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1578
1580 return getOperand(MY_FIRST_OPERAND + 1).get();
1581 }
1582
1584 return getOperand(MY_FIRST_OPERAND + 2).get();
1585 }
1586
1588 return getOperand(MY_FIRST_OPERAND + 3).get();
1589 }
1590
1592 return getOperand(MY_FIRST_OPERAND + 4).get();
1593 }
1594
1596 return convertRawToBound(getRawLowerBound());
1597 }
1598
1600 return convertRawToBound(getRawUpperBound());
1601 }
1602
1603 BoundType getStride() const { return convertRawToBound(getRawStride()); }
1604
1605 BoundType getBias() const { return convertRawToBound(getRawBias()); }
1606
1607 static bool classof(const Metadata *MD) {
1608 return MD->getMetadataID() == DISubrangeTypeKind;
1609 }
1610};
1611
1612/// Composite types.
1613///
1614/// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
1615/// TODO: Create a custom, unrelated node for DW_TAG_array_type.
1616class DICompositeType : public DIType {
1617 friend class LLVMContextImpl;
1618 friend class MDNode;
1619
1620 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1621
1622 unsigned RuntimeLang;
1623 std::optional<uint32_t> EnumKind;
1624
1625 DICompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
1626 unsigned Line, unsigned RuntimeLang, uint32_t AlignInBits,
1628 std::optional<uint32_t> EnumKind, DIFlags Flags,
1630 : DIType(C, DICompositeTypeKind, Storage, Tag, Line, AlignInBits,
1632 RuntimeLang(RuntimeLang), EnumKind(EnumKind) {}
1633 ~DICompositeType() = default;
1634
1635 /// Change fields in place.
1636 void mutate(unsigned Tag, unsigned Line, unsigned RuntimeLang,
1638 std::optional<uint32_t> EnumKind, DIFlags Flags) {
1639 assert(isDistinct() && "Only distinct nodes can mutate");
1640 assert(getRawIdentifier() && "Only ODR-uniqued nodes should mutate");
1641 this->RuntimeLang = RuntimeLang;
1642 this->EnumKind = EnumKind;
1644 }
1645
1646 static DICompositeType *
1647 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
1648 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1650 uint32_t NumExtraInhabitants, DIFlags Flags, DINodeArray Elements,
1651 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1652 DIType *VTableHolder, DITemplateParameterArray TemplateParams,
1653 StringRef Identifier, DIDerivedType *Discriminator,
1655 Metadata *Rank, DINodeArray Annotations, Metadata *BitStride,
1656 StorageType Storage, bool ShouldCreate = true) {
1657 auto *SizeInBitsNode = ConstantAsMetadata::get(
1658 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1659 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1660 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1661 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1662 Line, Scope, BaseType, SizeInBitsNode, AlignInBits,
1663 OffsetInBitsNode, Flags, Elements.get(), RuntimeLang,
1665 getCanonicalMDString(Context, Identifier), Discriminator,
1668 ShouldCreate);
1669 }
1670 static DICompositeType *
1671 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1672 unsigned Line, Metadata *Scope, Metadata *BaseType,
1673 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
1674 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
1675 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1680 Metadata *BitStride, StorageType Storage, bool ShouldCreate = true) {
1681 auto *SizeInBitsNode = ConstantAsMetadata::get(
1682 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1683 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1684 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1685 return getImpl(Context, Tag, Name, File, Line, Scope, BaseType,
1686 SizeInBitsNode, AlignInBits, OffsetInBitsNode, Flags,
1687 Elements, RuntimeLang, EnumKind, VTableHolder,
1690 NumExtraInhabitants, BitStride, Storage, ShouldCreate);
1691 }
1692 static DICompositeType *
1693 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
1696 uint32_t NumExtraInhabitants, DIFlags Flags, DINodeArray Elements,
1697 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1698 DIType *VTableHolder, DITemplateParameterArray TemplateParams,
1699 StringRef Identifier, DIDerivedType *Discriminator,
1701 Metadata *Rank, DINodeArray Annotations, Metadata *BitStride,
1702 StorageType Storage, bool ShouldCreate = true) {
1703 return getImpl(
1704 Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
1706 RuntimeLang, EnumKind, VTableHolder, TemplateParams.get(),
1709 NumExtraInhabitants, BitStride, Storage, ShouldCreate);
1710 }
1711 LLVM_ABI static DICompositeType *
1712 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1713 unsigned Line, Metadata *Scope, Metadata *BaseType,
1715 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
1716 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1721 Metadata *BitStride, StorageType Storage, bool ShouldCreate = true);
1722
1723 TempDICompositeType cloneImpl() const {
1724 return getTemporary(
1732 getRawBitStride());
1733 }
1734
1735public:
1737 DICompositeType,
1738 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1741 DINodeArray Elements, unsigned RuntimeLang,
1742 std::optional<uint32_t> EnumKind, DIType *VTableHolder,
1743 DITemplateParameterArray TemplateParams = nullptr,
1745 Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
1746 Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
1747 DINodeArray Annotations = nullptr, DIType *Specification = nullptr,
1751 RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier,
1753 BitStride))
1755 DICompositeType,
1756 (unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
1759 Metadata *Elements, unsigned RuntimeLang,
1760 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1763 Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
1764 Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
1766 Metadata *BitStride = nullptr),
1768 OffsetInBits, Flags, Elements, RuntimeLang, EnumKind, VTableHolder,
1771 BitStride))
1773 DICompositeType,
1774 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1777 DINodeArray Elements, unsigned RuntimeLang,
1778 std::optional<uint32_t> EnumKind, DIType *VTableHolder,
1779 DITemplateParameterArray TemplateParams = nullptr,
1781 Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
1782 Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
1783 DINodeArray Annotations = nullptr, DIType *Specification = nullptr,
1787 RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier,
1789 BitStride))
1791 DICompositeType,
1792 (unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
1795 Metadata *Elements, unsigned RuntimeLang,
1796 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1797 Metadata *TemplateParams = nullptr, MDString *Identifier = nullptr,
1798 Metadata *Discriminator = nullptr, Metadata *DataLocation = nullptr,
1799 Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
1800 Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
1802 Metadata *BitStride = nullptr),
1804 OffsetInBits, Flags, Elements, RuntimeLang, EnumKind, VTableHolder,
1807 BitStride))
1808
1809 TempDICompositeType clone() const { return cloneImpl(); }
1810
1811 /// Get a DICompositeType with the given ODR identifier.
1812 ///
1813 /// If \a LLVMContext::isODRUniquingDebugTypes(), gets the mapped
1814 /// DICompositeType for the given ODR \c Identifier. If none exists, creates
1815 /// a new node.
1816 ///
1817 /// Else, returns \c nullptr.
1818 LLVM_ABI static DICompositeType *
1819 getODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1820 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1824 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1830 MDString &Identifier);
1831
1832 /// Build a DICompositeType with the given ODR identifier.
1833 ///
1834 /// Looks up the mapped DICompositeType for the given ODR \c Identifier. If
1835 /// it doesn't exist, creates a new one. If it does exist and \a
1836 /// isForwardDecl(), and the new arguments would be a definition, mutates the
1837 /// the type in place. In either case, returns the type.
1838 ///
1839 /// If not \a LLVMContext::isODRUniquingDebugTypes(), this function returns
1840 /// nullptr.
1841 LLVM_ABI static DICompositeType *
1842 buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1843 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1847 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1852
1854 DINodeArray getElements() const {
1856 }
1860 DITemplateParameterArray getTemplateParams() const {
1862 }
1864 return getStringOperand(MY_FIRST_OPERAND + 4);
1865 }
1866 unsigned getRuntimeLang() const { return RuntimeLang; }
1867 std::optional<uint32_t> getEnumKind() const { return EnumKind; }
1868
1869 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1870 Metadata *getRawElements() const { return getOperand(MY_FIRST_OPERAND + 1); }
1872 return getOperand(MY_FIRST_OPERAND + 2);
1873 }
1875 return getOperand(MY_FIRST_OPERAND + 3);
1876 }
1878 return getOperandAs<MDString>(MY_FIRST_OPERAND + 4);
1879 }
1881 return getOperand(MY_FIRST_OPERAND + 5);
1882 }
1884 return getOperandAs<DIDerivedType>(MY_FIRST_OPERAND + 5);
1885 }
1887 return getOperand(MY_FIRST_OPERAND + 6);
1888 }
1896 return getOperand(MY_FIRST_OPERAND + 7);
1897 }
1904 Metadata *getRawAllocated() const { return getOperand(MY_FIRST_OPERAND + 8); }
1911 Metadata *getRawRank() const { return getOperand(MY_FIRST_OPERAND + 9); }
1914 return dyn_cast_or_null<ConstantInt>(MD->getValue());
1915 return nullptr;
1916 }
1920
1922 return getOperand(MY_FIRST_OPERAND + 10);
1923 }
1924 DINodeArray getAnnotations() const {
1926 }
1927
1929 return getOperand(MY_FIRST_OPERAND + 11);
1930 }
1934
1935 bool isNameSimplified() const { return getFlags() & FlagNameIsSimplified; }
1936
1938 return getOperand(MY_FIRST_OPERAND + 12);
1939 }
1942 return dyn_cast_or_null<ConstantInt>(MD->getValue());
1943 return nullptr;
1944 }
1945
1946 /// Replace operands.
1947 ///
1948 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
1949 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
1950 /// of its movement if necessary.
1951 /// @{
1952 void replaceElements(DINodeArray Elements) {
1953#ifndef NDEBUG
1954 for (DINode *Op : getElements())
1955 assert(is_contained(Elements->operands(), Op) &&
1956 "Lost a member during member list replacement");
1957#endif
1958 replaceOperandWith(MY_FIRST_OPERAND + 1, Elements.get());
1959 }
1960
1962 replaceOperandWith(MY_FIRST_OPERAND + 2, VTableHolder);
1963 }
1964
1965 void replaceTemplateParams(DITemplateParameterArray TemplateParams) {
1966 replaceOperandWith(MY_FIRST_OPERAND + 3, TemplateParams.get());
1967 }
1968 /// @}
1969
1970 static bool classof(const Metadata *MD) {
1971 return MD->getMetadataID() == DICompositeTypeKind;
1972 }
1973};
1974
1975/// Type array for a subprogram.
1976///
1977/// TODO: Fold the array of types in directly as operands.
1978class DISubroutineType : public DIType {
1979 friend class LLVMContextImpl;
1980 friend class MDNode;
1981
1982 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1983
1984 /// The calling convention used with DW_AT_calling_convention. Actually of
1985 /// type dwarf::CallingConvention.
1986 uint8_t CC;
1987
1988 DISubroutineType(LLVMContext &C, StorageType Storage, DIFlags Flags,
1990 ~DISubroutineType() = default;
1991
1992 static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
1993 uint8_t CC, DITypeArray TypeArray,
1995 bool ShouldCreate = true) {
1996 return getImpl(Context, Flags, CC, TypeArray.get(), Storage, ShouldCreate);
1997 }
1998 LLVM_ABI static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
2001 bool ShouldCreate = true);
2002
2003 TempDISubroutineType cloneImpl() const {
2005 }
2006
2007public:
2008 DEFINE_MDNODE_GET(DISubroutineType,
2009 (DIFlags Flags, uint8_t CC, DITypeArray TypeArray),
2010 (Flags, CC, TypeArray))
2011 DEFINE_MDNODE_GET(DISubroutineType,
2014
2015 TempDISubroutineType clone() const { return cloneImpl(); }
2016 // Returns a new temporary DISubroutineType with updated CC
2017 TempDISubroutineType cloneWithCC(uint8_t CC) const {
2018 auto NewTy = clone();
2019 NewTy->CC = CC;
2020 return NewTy;
2021 }
2022
2023 uint8_t getCC() const { return CC; }
2024
2025 DITypeArray getTypeArray() const {
2027 }
2028
2029 Metadata *getRawTypeArray() const { return getOperand(MY_FIRST_OPERAND); }
2030
2031 static bool classof(const Metadata *MD) {
2032 return MD->getMetadataID() == DISubroutineTypeKind;
2033 }
2034};
2035
2036/// Compile unit.
2037class DICompileUnit : public DIScope {
2038 friend class LLVMContextImpl;
2039 friend class MDNode;
2040
2041public:
2049
2057
2058 LLVM_ABI static std::optional<DebugEmissionKind>
2060 LLVM_ABI static const char *emissionKindString(DebugEmissionKind EK);
2061 LLVM_ABI static std::optional<DebugNameTableKind>
2063 LLVM_ABI static const char *nameTableKindString(DebugNameTableKind PK);
2064
2065private:
2066 DISourceLanguageName SourceLanguage;
2067 unsigned RuntimeVersion;
2069 unsigned EmissionKind;
2070 unsigned NameTableKind;
2071 bool IsOptimized;
2072 bool SplitDebugInlining;
2074 bool RangesBaseAddress;
2075
2077 DISourceLanguageName SourceLanguage, bool IsOptimized,
2078 unsigned RuntimeVersion, unsigned EmissionKind, uint64_t DWOId,
2080 unsigned NameTableKind, bool RangesBaseAddress,
2082 ~DICompileUnit() = default;
2083
2084 static DICompileUnit *
2085 getImpl(LLVMContext &Context, DISourceLanguageName SourceLanguage,
2088 unsigned EmissionKind, DICompositeTypeArray EnumTypes,
2089 DIScopeArray RetainedTypes,
2090 DIGlobalVariableExpressionArray GlobalVariables,
2091 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
2094 StringRef SDK, StorageType Storage, bool ShouldCreate = true) {
2095 return getImpl(
2096 Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
2099 EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
2102 getCanonicalMDString(Context, SysRoot),
2103 getCanonicalMDString(Context, SDK), Storage, ShouldCreate);
2104 }
2105 LLVM_ABI static DICompileUnit *
2106 getImpl(LLVMContext &Context, DISourceLanguageName SourceLanguage,
2107 Metadata *File, MDString *Producer, bool IsOptimized, MDString *Flags,
2108 unsigned RuntimeVersion, MDString *SplitDebugFilename,
2112 bool DebugInfoForProfiling, unsigned NameTableKind,
2113 bool RangesBaseAddress, MDString *SysRoot, MDString *SDK,
2114 StorageType Storage, bool ShouldCreate = true);
2115
2116 TempDICompileUnit cloneImpl() const {
2117 return getTemporary(
2124 }
2125
2126public:
2127 static void get() = delete;
2128 static void getIfExists() = delete;
2129
2131 DICompileUnit,
2133 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
2135 DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes,
2136 DIGlobalVariableExpressionArray GlobalVariables,
2137 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
2138 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
2139 DebugNameTableKind NameTableKind, bool RangesBaseAddress,
2141 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
2143 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
2144 DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress,
2145 SysRoot, SDK))
2147 DICompileUnit,
2149 bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
2153 bool SplitDebugInlining, bool DebugInfoForProfiling,
2154 unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
2156 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
2158 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
2159 DebugInfoForProfiling, NameTableKind, RangesBaseAddress, SysRoot, SDK))
2160
2161 TempDICompileUnit clone() const { return cloneImpl(); }
2162
2163 DISourceLanguageName getSourceLanguage() const { return SourceLanguage; }
2164 bool isOptimized() const { return IsOptimized; }
2165 bool isDebugInfoForProfiling() const { return DebugInfoForProfiling; }
2166 unsigned getRuntimeVersion() const { return RuntimeVersion; }
2168 return (DebugEmissionKind)EmissionKind;
2169 }
2170 // Return true if this CU was compiled with debug info disabled
2171 bool isNoDebug() const { return EmissionKind == NoDebug; }
2173 return EmissionKind == DebugDirectivesOnly;
2174 }
2175 bool getDebugInfoForProfiling() const { return DebugInfoForProfiling; }
2177 return (DebugNameTableKind)NameTableKind;
2178 }
2179 bool getRangesBaseAddress() const { return RangesBaseAddress; }
2181 StringRef getFlags() const { return getStringOperand(2); }
2183 DICompositeTypeArray getEnumTypes() const {
2185 }
2186 DIScopeArray getRetainedTypes() const {
2188 }
2189 DIGlobalVariableExpressionArray getGlobalVariables() const {
2191 }
2192 DIImportedEntityArray getImportedEntities() const {
2194 }
2195 DIMacroNodeArray getMacros() const {
2197 }
2198 uint64_t getDWOId() const { return DWOId; }
2199 void setDWOId(uint64_t DwoId) { DWOId = DwoId; }
2200 bool getSplitDebugInlining() const { return SplitDebugInlining; }
2201 void setSplitDebugInlining(bool SplitDebugInlining) {
2202 this->SplitDebugInlining = SplitDebugInlining;
2203 }
2205 StringRef getSDK() const { return getStringOperand(10); }
2206 /// Target-specific language dialect for DWARF.
2207 uint16_t getDialect() const { return SourceLanguage.getDialect(); }
2208
2214 Metadata *getRawEnumTypes() const { return getOperand(4); }
2218 Metadata *getRawMacros() const { return getOperand(8); }
2221 /// Replace arrays.
2222 ///
2223 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
2224 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
2225 /// DICompileUnit should be fairly rare.
2226 /// @{
2227 void replaceEnumTypes(DICompositeTypeArray N) {
2228 replaceOperandWith(4, N.get());
2229 }
2230 void replaceRetainedTypes(DITypeArray N) { replaceOperandWith(5, N.get()); }
2231 void replaceGlobalVariables(DIGlobalVariableExpressionArray N) {
2232 replaceOperandWith(6, N.get());
2233 }
2234 void replaceImportedEntities(DIImportedEntityArray N) {
2235 replaceOperandWith(7, N.get());
2236 }
2237 void replaceMacros(DIMacroNodeArray N) { replaceOperandWith(8, N.get()); }
2238 /// @}
2239
2240 static bool classof(const Metadata *MD) {
2241 return MD->getMetadataID() == DICompileUnitKind;
2242 }
2243};
2244
2245/// A scope for locals.
2246///
2247/// A legal scope for lexical blocks, local variables, and debug info
2248/// locations. Subclasses are \a DISubprogram, \a DILexicalBlock, and \a
2249/// DILexicalBlockFile.
2250class DILocalScope : public DIScope {
2251protected:
2255 ~DILocalScope() = default;
2256
2257public:
2258 /// Get the subprogram for this scope.
2259 ///
2260 /// Return this if it's an \a DISubprogram; otherwise, look up the scope
2261 /// chain.
2263
2264 /// Traverses the scope chain rooted at RootScope until it hits a Subprogram,
2265 /// recreating the chain with "NewSP" instead.
2266 LLVM_ABI static DILocalScope *
2268 LLVMContext &Ctx,
2270
2271 /// Get the first non DILexicalBlockFile scope of this scope.
2272 ///
2273 /// Return this if it's not a \a DILexicalBlockFIle; otherwise, look up the
2274 /// scope chain.
2276
2277 static bool classof(const Metadata *MD) {
2278 return MD->getMetadataID() == DISubprogramKind ||
2279 MD->getMetadataID() == DILexicalBlockKind ||
2280 MD->getMetadataID() == DILexicalBlockFileKind;
2281 }
2282};
2283
2284/// Subprogram description. Uses SubclassData1.
2285class DISubprogram : public DILocalScope {
2286 friend class LLVMContextImpl;
2287 friend class MDNode;
2288
2289 unsigned Line;
2290 unsigned ScopeLine;
2291 unsigned VirtualIndex;
2292
2293 /// In the MS ABI, the implicit 'this' parameter is adjusted in the prologue
2294 /// of method overrides from secondary bases by this amount. It may be
2295 /// negative.
2296 int ThisAdjustment;
2297
2298public:
2299 /// Debug info subprogram flags.
2301#define HANDLE_DISP_FLAG(ID, NAME) SPFlag##NAME = ID,
2302#define DISP_FLAG_LARGEST_NEEDED
2303#include "llvm/IR/DebugInfoFlags.def"
2304 SPFlagNonvirtual = SPFlagZero,
2305 SPFlagVirtuality = SPFlagVirtual | SPFlagPureVirtual,
2306 LLVM_MARK_AS_BITMASK_ENUM(SPFlagLargest)
2307 };
2308
2309 LLVM_ABI static DISPFlags getFlag(StringRef Flag);
2310 LLVM_ABI static StringRef getFlagString(DISPFlags Flag);
2311
2312 /// Split up a flags bitfield for easier printing.
2313 ///
2314 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
2315 /// any remaining (unrecognized) bits.
2316 LLVM_ABI static DISPFlags splitFlags(DISPFlags Flags,
2317 SmallVectorImpl<DISPFlags> &SplitFlags);
2318
2319 // Helper for converting old bitfields to new flags word.
2320 LLVM_ABI static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition,
2321 bool IsOptimized,
2322 unsigned Virtuality = SPFlagNonvirtual,
2323 bool IsMainSubprogram = false);
2324
2325private:
2326 DIFlags Flags;
2327 DISPFlags SPFlags;
2328
2329 DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
2330 unsigned ScopeLine, unsigned VirtualIndex, int ThisAdjustment,
2331 DIFlags Flags, DISPFlags SPFlags, bool UsesKeyInstructions,
2333 ~DISubprogram() = default;
2334
2335 static DISubprogram *
2336 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
2337 StringRef LinkageName, DIFile *File, unsigned Line,
2339 unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags,
2340 DISPFlags SPFlags, DICompileUnit *Unit,
2341 DITemplateParameterArray TemplateParams, DISubprogram *Declaration,
2342 MDNodeArray RetainedNodes, DITypeArray ThrownTypes,
2345 bool ShouldCreate = true) {
2346 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
2347 getCanonicalMDString(Context, LinkageName), File, Line, Type,
2349 Flags, SPFlags, Unit, TemplateParams.get(), Declaration,
2350 RetainedNodes.get(), ThrownTypes.get(), Annotations.get(),
2352 UsesKeyInstructions, Storage, ShouldCreate);
2353 }
2354
2355 LLVM_ABI static DISubprogram *
2356 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
2357 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
2358 unsigned ScopeLine, Metadata *ContainingType, unsigned VirtualIndex,
2359 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
2362 MDString *TargetFuncName, bool UsesKeyInstructions,
2363 StorageType Storage, bool ShouldCreate = true);
2364
2365 TempDISubprogram cloneImpl() const {
2367 getFile(), getLine(), getType(), getScopeLine(),
2368 getContainingType(), getVirtualIndex(),
2369 getThisAdjustment(), getFlags(), getSPFlags(),
2370 getUnit(), getTemplateParams(), getDeclaration(),
2371 getRetainedNodes(), getThrownTypes(), getAnnotations(),
2372 getTargetFuncName(), getKeyInstructionsEnabled());
2373 }
2374
2375public:
2377 DISubprogram,
2379 unsigned Line, DISubroutineType *Type, unsigned ScopeLine,
2380 DIType *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
2381 DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit,
2382 DITemplateParameterArray TemplateParams = nullptr,
2383 DISubprogram *Declaration = nullptr, MDNodeArray RetainedNodes = nullptr,
2384 DITypeArray ThrownTypes = nullptr, DINodeArray Annotations = nullptr,
2385 StringRef TargetFuncName = "", bool UsesKeyInstructions = false),
2386 (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
2387 VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
2390
2392 DISubprogram,
2394 unsigned Line, Metadata *Type, unsigned ScopeLine,
2395 Metadata *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
2396 DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
2400 bool UsesKeyInstructions = false),
2401 (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
2402 VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
2405
2406 TempDISubprogram clone() const { return cloneImpl(); }
2407
2408 /// Returns a new temporary DISubprogram with updated Flags
2409 TempDISubprogram cloneWithFlags(DIFlags NewFlags) const {
2410 auto NewSP = clone();
2411 NewSP->Flags = NewFlags;
2412 return NewSP;
2413 }
2414
2415 bool getKeyInstructionsEnabled() const { return SubclassData1; }
2416
2417public:
2418 unsigned getLine() const { return Line; }
2419 unsigned getVirtuality() const { return getSPFlags() & SPFlagVirtuality; }
2420 unsigned getVirtualIndex() const { return VirtualIndex; }
2421 int getThisAdjustment() const { return ThisAdjustment; }
2422 unsigned getScopeLine() const { return ScopeLine; }
2423 void setScopeLine(unsigned L) {
2424 assert(isDistinct());
2425 ScopeLine = L;
2426 }
2427 DIFlags getFlags() const { return Flags; }
2428 DISPFlags getSPFlags() const { return SPFlags; }
2429 bool isLocalToUnit() const { return getSPFlags() & SPFlagLocalToUnit; }
2430 bool isDefinition() const { return getSPFlags() & SPFlagDefinition; }
2431 bool isOptimized() const { return getSPFlags() & SPFlagOptimized; }
2432 bool isMainSubprogram() const { return getSPFlags() & SPFlagMainSubprogram; }
2433
2434 bool isArtificial() const { return getFlags() & FlagArtificial; }
2435 bool isPrivate() const {
2436 return (getFlags() & FlagAccessibility) == FlagPrivate;
2437 }
2438 bool isProtected() const {
2439 return (getFlags() & FlagAccessibility) == FlagProtected;
2440 }
2441 bool isPublic() const {
2442 return (getFlags() & FlagAccessibility) == FlagPublic;
2443 }
2444 bool isExplicit() const { return getFlags() & FlagExplicit; }
2445 bool isPrototyped() const { return getFlags() & FlagPrototyped; }
2446 bool isNameSimplified() const { return getFlags() & FlagNameIsSimplified; }
2447 bool areAllCallsDescribed() const {
2448 return getFlags() & FlagAllCallsDescribed;
2449 }
2450 bool isPure() const { return getSPFlags() & SPFlagPure; }
2451 bool isElemental() const { return getSPFlags() & SPFlagElemental; }
2452 bool isRecursive() const { return getSPFlags() & SPFlagRecursive; }
2453 bool isObjCDirect() const { return getSPFlags() & SPFlagObjCDirect; }
2454
2455 /// Check if this is deleted member function.
2456 ///
2457 /// Return true if this subprogram is a C++11 special
2458 /// member function declared deleted.
2459 bool isDeleted() const { return getSPFlags() & SPFlagDeleted; }
2460
2461 /// Check if this is reference-qualified.
2462 ///
2463 /// Return true if this subprogram is a C++11 reference-qualified non-static
2464 /// member function (void foo() &).
2465 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
2466
2467 /// Check if this is rvalue-reference-qualified.
2468 ///
2469 /// Return true if this subprogram is a C++11 rvalue-reference-qualified
2470 /// non-static member function (void foo() &&).
2471 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
2472
2473 /// Check if this is marked as noreturn.
2474 ///
2475 /// Return true if this subprogram is C++11 noreturn or C11 _Noreturn
2476 bool isNoReturn() const { return getFlags() & FlagNoReturn; }
2477
2478 // Check if this routine is a compiler-generated thunk.
2479 //
2480 // Returns true if this subprogram is a thunk generated by the compiler.
2481 bool isThunk() const { return getFlags() & FlagThunk; }
2482
2483 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2484
2485 StringRef getName() const { return getStringOperand(2); }
2486 StringRef getLinkageName() const { return getStringOperand(3); }
2487 /// Only used by clients of CloneFunction, and only right after the cloning.
2488 void replaceLinkageName(MDString *LN) { replaceOperandWith(3, LN); }
2489
2490 DISubroutineType *getType() const {
2491 return cast_or_null<DISubroutineType>(getRawType());
2492 }
2493 DIType *getContainingType() const {
2494 return cast_or_null<DIType>(getRawContainingType());
2495 }
2496 void replaceType(DISubroutineType *Ty) {
2497 assert(isDistinct() && "Only distinct nodes can mutate");
2498 replaceOperandWith(4, Ty);
2499 }
2500
2501 DICompileUnit *getUnit() const {
2502 return cast_or_null<DICompileUnit>(getRawUnit());
2503 }
2504 void replaceUnit(DICompileUnit *CU) { replaceOperandWith(5, CU); }
2505 DITemplateParameterArray getTemplateParams() const {
2506 return cast_or_null<MDTuple>(getRawTemplateParams());
2507 }
2508 DISubprogram *getDeclaration() const {
2509 return cast_or_null<DISubprogram>(getRawDeclaration());
2510 }
2511 void replaceDeclaration(DISubprogram *Decl) { replaceOperandWith(6, Decl); }
2512 MDNodeArray getRetainedNodes() const {
2513 return cast_or_null<MDTuple>(getRawRetainedNodes());
2514 }
2515 DITypeArray getThrownTypes() const {
2516 return cast_or_null<MDTuple>(getRawThrownTypes());
2517 }
2518 DINodeArray getAnnotations() const {
2519 return cast_or_null<MDTuple>(getRawAnnotations());
2520 }
2521 StringRef getTargetFuncName() const {
2522 return (getRawTargetFuncName()) ? getStringOperand(12) : StringRef();
2523 }
2524
2525 Metadata *getRawScope() const { return getOperand(1); }
2526 MDString *getRawName() const { return getOperandAs<MDString>(2); }
2527 MDString *getRawLinkageName() const { return getOperandAs<MDString>(3); }
2528 Metadata *getRawType() const { return getOperand(4); }
2529 Metadata *getRawUnit() const { return getOperand(5); }
2530 Metadata *getRawDeclaration() const { return getOperand(6); }
2531 Metadata *getRawRetainedNodes() const { return getOperand(7); }
2532 Metadata *getRawContainingType() const {
2533 return getNumOperands() > 8 ? getOperandAs<Metadata>(8) : nullptr;
2534 }
2535 Metadata *getRawTemplateParams() const {
2536 return getNumOperands() > 9 ? getOperandAs<Metadata>(9) : nullptr;
2537 }
2538 Metadata *getRawThrownTypes() const {
2539 return getNumOperands() > 10 ? getOperandAs<Metadata>(10) : nullptr;
2540 }
2541 Metadata *getRawAnnotations() const {
2542 return getNumOperands() > 11 ? getOperandAs<Metadata>(11) : nullptr;
2543 }
2544 MDString *getRawTargetFuncName() const {
2545 return getNumOperands() > 12 ? getOperandAs<MDString>(12) : nullptr;
2546 }
2547
2548 void replaceRawLinkageName(MDString *LinkageName) {
2550 }
2551 void replaceRetainedNodes(MDNodeArray N) { replaceOperandWith(7, N.get()); }
2552
2553 template <typename IterT> void retainNodes(IterT NodesBegin, IterT NodesEnd) {
2554 auto RetainedNodes = getRetainedNodes();
2556 MDs.append(NodesBegin, NodesEnd);
2557 replaceRetainedNodes(MDNode::get(getContext(), MDs));
2558 }
2559
2560 /// For the given retained node of DISubprogram, applies one of the
2561 /// given functions depending on the type of the node.
2562 template <typename T, typename MetadataT, typename FuncLVT,
2563 typename FuncLabelT, typename FuncImportedEntityT,
2564 typename FuncTypeT, typename FuncGVET, typename FuncUnknownT>
2565 static T visitRetainedNode(MetadataT *N, FuncLVT &&FuncLV,
2566 FuncLabelT &&FuncLabel,
2567 FuncImportedEntityT &&FuncIE, FuncTypeT &&FuncType,
2568 FuncGVET &&FuncGVE, FuncUnknownT &&FuncUnknown) {
2569 static_assert(std::is_base_of_v<Metadata, MetadataT>,
2570 "N must point to Metadata or const Metadata");
2571
2572 if (auto *LV = dyn_cast<DILocalVariable>(N))
2573 return FuncLV(LV);
2574 if (auto *L = dyn_cast<DILabel>(N))
2575 return FuncLabel(L);
2576 if (auto *IE = dyn_cast<DIImportedEntity>(N))
2577 return FuncIE(IE);
2578 if (auto *Ty = dyn_cast<DIType>(N))
2579 return FuncType(Ty);
2580 if (auto *GVE = dyn_cast<DIGlobalVariableExpression>(N))
2581 return FuncGVE(GVE);
2582 return FuncUnknown(N);
2583 }
2584
2585 /// Returns the scope of subprogram's retainedNodes.
2586 LLVM_ABI static const DILocalScope *getRetainedNodeScope(const MDNode *N);
2588 // For use in Verifier.
2589 LLVM_ABI static const DIScope *getRawRetainedNodeScope(const MDNode *N);
2591
2592 /// For each retained node, applies one of the given functions depending
2593 /// on the type of a node.
2594 template <typename FuncLVT, typename FuncLabelT, typename FuncImportedEntityT,
2595 typename FuncTypeT, typename FuncGVET>
2596 void forEachRetainedNode(FuncLVT &&FuncLV, FuncLabelT &&FuncLabel,
2597 FuncImportedEntityT &&FuncIE, FuncTypeT &&FuncType,
2598 FuncGVET &&FuncGVE) {
2599 for (MDNode *N : getRetainedNodes())
2600 visitRetainedNode<void>(
2601 N, FuncLV, FuncLabel, FuncIE, FuncType, FuncGVE,
2602 [](auto *N) { llvm_unreachable("Unexpected retained node!"); });
2603 }
2604
2605 /// When IR modules are merged, typically during LTO, the merged module
2606 /// may contain several types having the same linkageName. They are
2607 /// supposed to represent the same type included by multiple source code
2608 /// files from a single header file.
2609 ///
2610 /// DebugTypeODRUniquing feature uniques (deduplicates) such types
2611 /// based on their linkageName during metadata loading, to speed up
2612 /// compilation and reduce debug info size.
2613 ///
2614 /// However, since function-local types are tracked in DISubprogram's
2615 /// retainedNodes field, a single local type may be referenced by multiple
2616 /// DISubprograms via retainedNodes as the result of DebugTypeODRUniquing.
2617 /// But retainedNodes field of a DISubprogram is meant to hold only
2618 /// subprogram's own local entities, therefore such references may
2619 /// cause crashes.
2620 ///
2621 /// To address this problem, this method is called for each new subprogram
2622 /// after module loading. It removes references to types belonging
2623 /// to other DISubprograms from a subprogram's retainedNodes list.
2624 /// If a corresponding IR function refers to local scopes from another
2625 /// subprogram, emitted debug info (e.g. DWARF) should rely
2626 /// on cross-subprogram references (and cross-CU references, as subprograms
2627 /// may belong to different compile units). This is also a drawback:
2628 /// when a subprogram refers to types that are local to another subprogram,
2629 /// it is more complicated for debugger to properly discover local types
2630 /// of a current scope for expression evaluation.
2632
2633 template <typename T> void cleanupRetainedNodesIf(T &&Pred) {
2634 MDTuple *RetainedNodes = dyn_cast_or_null<MDTuple>(getRawRetainedNodes());
2635 // As this is expected to be called during module loading, before
2636 // stripping old or incorrect debug info, perform minimal sanity check.
2637 if (!RetainedNodes)
2638 return;
2639 // replaceRetainedNodes() should not re-unique DISubprogram if new list is
2640 // the same pointer.
2641 replaceRetainedNodes(RetainedNodes->filter(Pred));
2642 }
2643
2644 /// Calls SP->cleanupRetainedNodes() for a range of DISubprograms.
2645 template <typename RangeT>
2646 static void cleanupRetainedNodes(const RangeT &NewDistinctSPs) {
2647 for (DISubprogram *SP : NewDistinctSPs)
2648 SP->cleanupRetainedNodes();
2649 }
2650
2651 /// Check if this subprogram describes the given function.
2652 ///
2653 /// FIXME: Should this be looking through bitcasts?
2654 LLVM_ABI bool describes(const Function *F) const;
2655
2656 static bool classof(const Metadata *MD) {
2657 return MD->getMetadataID() == DISubprogramKind;
2658 }
2659};
2660
2661/// Debug location.
2662///
2663/// A debug location in source code, used for debug info and otherwise.
2664///
2665/// Uses the SubclassData1, SubclassData16 and SubclassData32
2666/// Metadata slots.
2667
2668class DILocation : public MDNode {
2669 friend class LLVMContextImpl;
2670 friend class MDNode;
2671 uint64_t AtomGroup : 61;
2672 uint64_t AtomRank : 3;
2673
2674 DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
2675 unsigned Column, uint64_t AtomGroup, uint8_t AtomRank,
2677 ~DILocation() { dropAllReferences(); }
2678
2679 LLVM_ABI static DILocation *
2680 getImpl(LLVMContext &Context, unsigned Line, unsigned Column, Metadata *Scope,
2682 uint8_t AtomRank, StorageType Storage, bool ShouldCreate = true);
2683 static DILocation *getImpl(LLVMContext &Context, unsigned Line,
2684 unsigned Column, DILocalScope *Scope,
2687 StorageType Storage, bool ShouldCreate = true) {
2688 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
2689 static_cast<Metadata *>(InlinedAt), ImplicitCode, AtomGroup,
2690 AtomRank, Storage, ShouldCreate);
2691 }
2692
2693 TempDILocation cloneImpl() const {
2694 // Get the raw scope/inlinedAt since it is possible to invoke this on
2695 // a DILocation containing temporary metadata.
2696 return getTemporary(getContext(), getLine(), getColumn(), getRawScope(),
2697 getRawInlinedAt(), isImplicitCode(), getAtomGroup(),
2698 getAtomRank());
2699 }
2700
2701public:
2702 uint64_t getAtomGroup() const { return AtomGroup; }
2703 uint8_t getAtomRank() const { return AtomRank; }
2704
2705 const DILocation *getWithoutAtom() const {
2706 if (!getAtomGroup() && !getAtomRank())
2707 return this;
2708 return get(getContext(), getLine(), getColumn(), getScope(), getInlinedAt(),
2709 isImplicitCode());
2710 }
2711
2712 // Disallow replacing operands.
2713 void replaceOperandWith(unsigned I, Metadata *New) = delete;
2714
2716 (unsigned Line, unsigned Column, Metadata *Scope,
2717 Metadata *InlinedAt = nullptr, bool ImplicitCode = false,
2718 uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2719 (Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2720 AtomRank))
2721 DEFINE_MDNODE_GET(DILocation,
2722 (unsigned Line, unsigned Column, DILocalScope *Scope,
2723 DILocation *InlinedAt = nullptr, bool ImplicitCode = false,
2724 uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2725 (Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2726 AtomRank))
2727
2728 /// Return a (temporary) clone of this.
2729 TempDILocation clone() const { return cloneImpl(); }
2730
2731 unsigned getLine() const { return SubclassData32; }
2732 unsigned getColumn() const { return SubclassData16; }
2733 DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
2734
2735 /// Return the linkage name of Subprogram. If the linkage name is empty,
2736 /// return scope name (the demangled name).
2737 StringRef getSubprogramLinkageName() const {
2738 DISubprogram *SP = getScope()->getSubprogram();
2739 if (!SP)
2740 return "";
2741 auto Name = SP->getLinkageName();
2742 if (!Name.empty())
2743 return Name;
2744 return SP->getName();
2745 }
2746
2747 DILocation *getInlinedAt() const {
2749 }
2750
2751 /// Check if the location corresponds to an implicit code.
2752 /// When the ImplicitCode flag is true, it means that the Instruction
2753 /// with this DILocation has been added by the front-end but it hasn't been
2754 /// written explicitly by the user (e.g. cleanup stuff in C++ put on a closing
2755 /// bracket). It's useful for code coverage to not show a counter on "empty"
2756 /// lines.
2757 bool isImplicitCode() const { return SubclassData1; }
2758 void setImplicitCode(bool ImplicitCode) { SubclassData1 = ImplicitCode; }
2759
2760 DIFile *getFile() const { return getScope()->getFile(); }
2761 StringRef getFilename() const { return getScope()->getFilename(); }
2762 StringRef getDirectory() const { return getScope()->getDirectory(); }
2763 std::optional<StringRef> getSource() const { return getScope()->getSource(); }
2764
2765 /// Walk through \a getInlinedAt() and return the \a DILocation of the
2766 /// outermost call site in the inlining chain.
2767 const DILocation *getInlinedAtLocation() const {
2768 const DILocation *Current = this;
2769 while (const DILocation *Next = Current->getInlinedAt())
2770 Current = Next;
2771 return Current;
2772 }
2773
2774 // Return the \a DILocalScope of the outermost call site in the inlining
2775 // chain.
2776 DILocalScope *getInlinedAtScope() const {
2777 return getInlinedAtLocation()->getScope();
2778 }
2779
2780 /// Get the DWARF discriminator.
2781 ///
2782 /// DWARF discriminators distinguish identical file locations between
2783 /// instructions that are on different basic blocks.
2784 ///
2785 /// There are 3 components stored in discriminator, from lower bits:
2786 ///
2787 /// Base discriminator: assigned by AddDiscriminators pass to identify IRs
2788 /// that are defined by the same source line, but
2789 /// different basic blocks.
2790 /// Duplication factor: assigned by optimizations that will scale down
2791 /// the execution frequency of the original IR.
2792 /// Copy Identifier: assigned by optimizations that clones the IR.
2793 /// Each copy of the IR will be assigned an identifier.
2794 ///
2795 /// Encoding:
2796 ///
2797 /// The above 3 components are encoded into a 32bit unsigned integer in
2798 /// order. If the lowest bit is 1, the current component is empty, and the
2799 /// next component will start in the next bit. Otherwise, the current
2800 /// component is non-empty, and its content starts in the next bit. The
2801 /// value of each components is either 5 bit or 12 bit: if the 7th bit
2802 /// is 0, the bit 2~6 (5 bits) are used to represent the component; if the
2803 /// 7th bit is 1, the bit 2~6 (5 bits) and 8~14 (7 bits) are combined to
2804 /// represent the component. Thus, the number of bits used for a component
2805 /// is either 0 (if it and all the next components are empty); 1 - if it is
2806 /// empty; 7 - if its value is up to and including 0x1f (lsb and msb are both
2807 /// 0); or 14, if its value is up to and including 0x1ff. Note that the last
2808 /// component is also capped at 0x1ff, even in the case when both first
2809 /// components are 0, and we'd technically have 29 bits available.
2810 ///
2811 /// For precise control over the data being encoded in the discriminator,
2812 /// use encodeDiscriminator/decodeDiscriminator.
2813
2814 inline unsigned getDiscriminator() const;
2815
2816 // For the regular discriminator, it stands for all empty components if all
2817 // the lowest 3 bits are non-zero and all higher 29 bits are unused(zero by
2818 // default). Here we fully leverage the higher 29 bits for pseudo probe use.
2819 // This is the format:
2820 // [2:0] - 0x7
2821 // [31:3] - pseudo probe fields guaranteed to be non-zero as a whole
2822 // So if the lower 3 bits is non-zero and the others has at least one
2823 // non-zero bit, it guarantees to be a pseudo probe discriminator
2824 inline static bool isPseudoProbeDiscriminator(unsigned Discriminator) {
2825 return ((Discriminator & 0x7) == 0x7) && (Discriminator & 0xFFFFFFF8);
2826 }
2827
2828 /// Returns a new DILocation with updated \p Discriminator.
2829 inline const DILocation *cloneWithDiscriminator(unsigned Discriminator) const;
2830
2831 /// Returns a new DILocation with updated base discriminator \p BD. Only the
2832 /// base discriminator is set in the new DILocation, the other encoded values
2833 /// are elided.
2834 /// If the discriminator cannot be encoded, the function returns std::nullopt.
2835 inline std::optional<const DILocation *>
2836 cloneWithBaseDiscriminator(unsigned BD) const;
2837
2838 /// Returns the duplication factor stored in the discriminator, or 1 if no
2839 /// duplication factor (or 0) is encoded.
2840 inline unsigned getDuplicationFactor() const;
2841
2842 /// Returns the copy identifier stored in the discriminator.
2843 inline unsigned getCopyIdentifier() const;
2844
2845 /// Returns the base discriminator stored in the discriminator.
2846 inline unsigned getBaseDiscriminator() const;
2847
2848 /// Returns a new DILocation with duplication factor \p DF * current
2849 /// duplication factor encoded in the discriminator. The current duplication
2850 /// factor is as defined by getDuplicationFactor().
2851 /// Returns std::nullopt if encoding failed.
2852 inline std::optional<const DILocation *>
2854
2855 /// Attempts to merge \p LocA and \p LocB into a single location; see
2856 /// DebugLoc::getMergedLocation for more details.
2857 /// NB: When merging the locations of instructions, prefer to use
2858 /// DebugLoc::getMergedLocation(), as an instruction's DebugLoc may contain
2859 /// additional metadata that will not be preserved when merging the unwrapped
2860 /// DILocations.
2862 DILocation *LocB);
2863
2864 /// Try to combine the vector of locations passed as input in a single one.
2865 /// This function applies getMergedLocation() repeatedly left-to-right.
2866 /// NB: When merging the locations of instructions, prefer to use
2867 /// DebugLoc::getMergedLocations(), as an instruction's DebugLoc may contain
2868 /// additional metadata that will not be preserved when merging the unwrapped
2869 /// DILocations.
2870 ///
2871 /// \p Locs: The locations to be merged.
2873
2874 /// Return the masked discriminator value for an input discrimnator value D
2875 /// (i.e. zero out the (B+1)-th and above bits for D (B is 0-base).
2876 // Example: an input of (0x1FF, 7) returns 0xFF.
2877 static unsigned getMaskedDiscriminator(unsigned D, unsigned B) {
2878 return (D & getN1Bits(B));
2879 }
2880
2881 /// Return the bits used for base discriminators.
2882 static unsigned getBaseDiscriminatorBits() { return getBaseFSBitEnd(); }
2883
2884 /// Returns the base discriminator for a given encoded discriminator \p D.
2885 static unsigned
2887 bool IsFSDiscriminator = false) {
2888 // Extract the dwarf base discriminator if it's encoded in the pseudo probe
2889 // discriminator.
2891 auto DwarfBaseDiscriminator =
2893 if (DwarfBaseDiscriminator)
2894 return *DwarfBaseDiscriminator;
2895 // Return the probe id instead of zero for a pseudo probe discriminator.
2896 // This should help differenciate callsites with same line numbers to
2897 // achieve a decent AutoFDO profile under -fpseudo-probe-for-profiling,
2898 // where the original callsite dwarf discriminator is overwritten by
2899 // callsite probe information.
2901 }
2902
2903 if (IsFSDiscriminator)
2906 }
2907
2908 /// Raw encoding of the discriminator. APIs such as cloneWithDuplicationFactor
2909 /// have certain special case behavior (e.g. treating empty duplication factor
2910 /// as the value '1').
2911 /// This API, in conjunction with cloneWithDiscriminator, may be used to
2912 /// encode the raw values provided.
2913 ///
2914 /// \p BD: base discriminator
2915 /// \p DF: duplication factor
2916 /// \p CI: copy index
2917 ///
2918 /// The return is std::nullopt if the values cannot be encoded in 32 bits -
2919 /// for example, values for BD or DF larger than 12 bits. Otherwise, the
2920 /// return is the encoded value.
2921 LLVM_ABI static std::optional<unsigned>
2922 encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI);
2923
2924 /// Raw decoder for values in an encoded discriminator D.
2925 LLVM_ABI static void decodeDiscriminator(unsigned D, unsigned &BD,
2926 unsigned &DF, unsigned &CI);
2927
2928 /// Returns the duplication factor for a given encoded discriminator \p D, or
2929 /// 1 if no value or 0 is encoded.
2930 static unsigned getDuplicationFactorFromDiscriminator(unsigned D) {
2932 return 1;
2934 unsigned Ret = getUnsignedFromPrefixEncoding(D);
2935 if (Ret == 0)
2936 return 1;
2937 return Ret;
2938 }
2939
2940 /// Returns the copy identifier for a given encoded discriminator \p D.
2945
2946 Metadata *getRawScope() const { return getOperand(0); }
2948 if (getNumOperands() == 2)
2949 return getOperand(1);
2950 return nullptr;
2951 }
2952
2953 static bool classof(const Metadata *MD) {
2954 return MD->getMetadataID() == DILocationKind;
2955 }
2956};
2957
2959protected:
2963
2964public:
2966
2967 Metadata *getRawScope() const { return getOperand(1); }
2968
2969 void replaceScope(DIScope *Scope) {
2970 assert(!isUniqued());
2971 setOperand(1, Scope);
2972 }
2973
2974 static bool classof(const Metadata *MD) {
2975 return MD->getMetadataID() == DILexicalBlockKind ||
2976 MD->getMetadataID() == DILexicalBlockFileKind;
2977 }
2978};
2979
2980/// Debug lexical block.
2981///
2982/// Uses the SubclassData32 Metadata slot.
2983class DILexicalBlock : public DILexicalBlockBase {
2984 friend class LLVMContextImpl;
2985 friend class MDNode;
2986
2987 uint16_t Column;
2988
2989 DILexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
2990 unsigned Column, ArrayRef<Metadata *> Ops)
2991 : DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops),
2992 Column(Column) {
2994 assert(Column < (1u << 16) && "Expected 16-bit column");
2995 }
2996 ~DILexicalBlock() = default;
2997
2998 static DILexicalBlock *getImpl(LLVMContext &Context, DILocalScope *Scope,
2999 DIFile *File, unsigned Line, unsigned Column,
3001 bool ShouldCreate = true) {
3002 return getImpl(Context, static_cast<Metadata *>(Scope),
3003 static_cast<Metadata *>(File), Line, Column, Storage,
3004 ShouldCreate);
3005 }
3006
3007 LLVM_ABI static DILexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
3008 Metadata *File, unsigned Line,
3009 unsigned Column, StorageType Storage,
3010 bool ShouldCreate = true);
3011
3012 TempDILexicalBlock cloneImpl() const {
3014 getColumn());
3015 }
3016
3017public:
3018 DEFINE_MDNODE_GET(DILexicalBlock,
3019 (DILocalScope * Scope, DIFile *File, unsigned Line,
3020 unsigned Column),
3021 (Scope, File, Line, Column))
3022 DEFINE_MDNODE_GET(DILexicalBlock,
3024 unsigned Column),
3025 (Scope, File, Line, Column))
3026
3027 TempDILexicalBlock clone() const { return cloneImpl(); }
3028
3029 unsigned getLine() const { return SubclassData32; }
3030 unsigned getColumn() const { return Column; }
3031
3032 static bool classof(const Metadata *MD) {
3033 return MD->getMetadataID() == DILexicalBlockKind;
3034 }
3035};
3036
3037class DILexicalBlockFile : public DILexicalBlockBase {
3038 friend class LLVMContextImpl;
3039 friend class MDNode;
3040
3041 DILexicalBlockFile(LLVMContext &C, StorageType Storage,
3043 : DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops) {
3045 }
3046 ~DILexicalBlockFile() = default;
3047
3048 static DILexicalBlockFile *getImpl(LLVMContext &Context, DILocalScope *Scope,
3049 DIFile *File, unsigned Discriminator,
3051 bool ShouldCreate = true) {
3052 return getImpl(Context, static_cast<Metadata *>(Scope),
3053 static_cast<Metadata *>(File), Discriminator, Storage,
3054 ShouldCreate);
3055 }
3056
3057 LLVM_ABI static DILexicalBlockFile *getImpl(LLVMContext &Context,
3058 Metadata *Scope, Metadata *File,
3059 unsigned Discriminator,
3061 bool ShouldCreate = true);
3062
3063 TempDILexicalBlockFile cloneImpl() const {
3064 return getTemporary(getContext(), getScope(), getFile(),
3066 }
3067
3068public:
3069 DEFINE_MDNODE_GET(DILexicalBlockFile,
3071 unsigned Discriminator),
3073 DEFINE_MDNODE_GET(DILexicalBlockFile,
3076
3077 TempDILexicalBlockFile clone() const { return cloneImpl(); }
3078 unsigned getDiscriminator() const { return SubclassData32; }
3079
3080 static bool classof(const Metadata *MD) {
3081 return MD->getMetadataID() == DILexicalBlockFileKind;
3082 }
3083};
3084
3085unsigned DILocation::getDiscriminator() const {
3087 return F->getDiscriminator();
3088 return 0;
3089}
3090
3091const DILocation *
3092DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
3093 DIScope *Scope = getScope();
3094 // Skip all parent DILexicalBlockFile that already have a discriminator
3095 // assigned. We do not want to have nested DILexicalBlockFiles that have
3096 // multiple discriminators because only the leaf DILexicalBlockFile's
3097 // dominator will be used.
3098 for (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope);
3099 LBF && LBF->getDiscriminator() != 0;
3101 Scope = LBF->getScope();
3102 DILexicalBlockFile *NewScope =
3103 DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator);
3104 return DILocation::get(getContext(), getLine(), getColumn(), NewScope,
3105 getInlinedAt(), isImplicitCode(), getAtomGroup(),
3106 getAtomRank());
3107}
3108
3110 return getBaseDiscriminatorFromDiscriminator(getDiscriminator(),
3112}
3113
3115 return getDuplicationFactorFromDiscriminator(getDiscriminator());
3116}
3117
3119 return getCopyIdentifierFromDiscriminator(getDiscriminator());
3120}
3121
3122std::optional<const DILocation *>
3124 // Do not interfere with pseudo probes. Pseudo probe at a callsite uses
3125 // the dwarf discriminator to store pseudo probe related information,
3126 // such as the probe id.
3127 if (isPseudoProbeDiscriminator(getDiscriminator()))
3128 return this;
3129
3130 unsigned BD, DF, CI;
3131
3133 BD = getBaseDiscriminator();
3134 if (D == BD)
3135 return this;
3136 return cloneWithDiscriminator(D);
3137 }
3138
3139 decodeDiscriminator(getDiscriminator(), BD, DF, CI);
3140 if (D == BD)
3141 return this;
3142 if (std::optional<unsigned> Encoded = encodeDiscriminator(D, DF, CI))
3143 return cloneWithDiscriminator(*Encoded);
3144 return std::nullopt;
3145}
3146
3147std::optional<const DILocation *>
3149 assert(!EnableFSDiscriminator && "FSDiscriminator should not call this.");
3150 // Do no interfere with pseudo probes. Pseudo probe doesn't need duplication
3151 // factor support as samples collected on cloned probes will be aggregated.
3152 // Also pseudo probe at a callsite uses the dwarf discriminator to store
3153 // pseudo probe related information, such as the probe id.
3154 if (isPseudoProbeDiscriminator(getDiscriminator()))
3155 return this;
3156
3158 if (DF <= 1)
3159 return this;
3160
3161 unsigned BD = getBaseDiscriminator();
3162 unsigned CI = getCopyIdentifier();
3163 if (std::optional<unsigned> D = encodeDiscriminator(BD, DF, CI))
3164 return cloneWithDiscriminator(*D);
3165 return std::nullopt;
3166}
3167
3168/// Debug lexical block.
3169///
3170/// Uses the SubclassData1 Metadata slot.
3171class DINamespace : public DIScope {
3172 friend class LLVMContextImpl;
3173 friend class MDNode;
3174
3175 DINamespace(LLVMContext &Context, StorageType Storage, bool ExportSymbols,
3177 ~DINamespace() = default;
3178
3179 static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope,
3181 StorageType Storage, bool ShouldCreate = true) {
3182 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
3183 ExportSymbols, Storage, ShouldCreate);
3184 }
3185 LLVM_ABI static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope,
3188 bool ShouldCreate = true);
3189
3190 TempDINamespace cloneImpl() const {
3191 return getTemporary(getContext(), getScope(), getName(),
3193 }
3194
3195public:
3199 DEFINE_MDNODE_GET(DINamespace,
3202
3203 TempDINamespace clone() const { return cloneImpl(); }
3204
3205 bool getExportSymbols() const { return SubclassData1; }
3207 StringRef getName() const { return getStringOperand(2); }
3208
3209 Metadata *getRawScope() const { return getOperand(1); }
3211
3212 static bool classof(const Metadata *MD) {
3213 return MD->getMetadataID() == DINamespaceKind;
3214 }
3215};
3216
3217/// Represents a module in the programming language, for example, a Clang
3218/// module, or a Fortran module.
3219///
3220/// Uses the SubclassData1 and SubclassData32 Metadata slots.
3221class DIModule : public DIScope {
3222 friend class LLVMContextImpl;
3223 friend class MDNode;
3224
3225 DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo,
3226 bool IsDecl, ArrayRef<Metadata *> Ops);
3227 ~DIModule() = default;
3228
3229 static DIModule *getImpl(LLVMContext &Context, DIFile *File, DIScope *Scope,
3232 unsigned LineNo, bool IsDecl, StorageType Storage,
3233 bool ShouldCreate = true) {
3234 return getImpl(Context, File, Scope, getCanonicalMDString(Context, Name),
3237 getCanonicalMDString(Context, APINotesFile), LineNo, IsDecl,
3238 Storage, ShouldCreate);
3239 }
3240 LLVM_ABI static DIModule *
3241 getImpl(LLVMContext &Context, Metadata *File, Metadata *Scope, MDString *Name,
3243 MDString *APINotesFile, unsigned LineNo, bool IsDecl,
3244 StorageType Storage, bool ShouldCreate = true);
3245
3246 TempDIModule cloneImpl() const {
3248 getConfigurationMacros(), getIncludePath(),
3249 getAPINotesFile(), getLineNo(), getIsDecl());
3250 }
3251
3252public:
3256 StringRef APINotesFile, unsigned LineNo,
3257 bool IsDecl = false),
3259 APINotesFile, LineNo, IsDecl))
3260 DEFINE_MDNODE_GET(DIModule,
3264 bool IsDecl = false),
3266 APINotesFile, LineNo, IsDecl))
3267
3268 TempDIModule clone() const { return cloneImpl(); }
3269
3270 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
3271 StringRef getName() const { return getStringOperand(2); }
3272 StringRef getConfigurationMacros() const { return getStringOperand(3); }
3273 StringRef getIncludePath() const { return getStringOperand(4); }
3274 StringRef getAPINotesFile() const { return getStringOperand(5); }
3275 unsigned getLineNo() const { return SubclassData32; }
3276 bool getIsDecl() const { return SubclassData1; }
3277
3278 Metadata *getRawScope() const { return getOperand(1); }
3279 MDString *getRawName() const { return getOperandAs<MDString>(2); }
3280 MDString *getRawConfigurationMacros() const {
3281 return getOperandAs<MDString>(3);
3282 }
3283 MDString *getRawIncludePath() const { return getOperandAs<MDString>(4); }
3284 MDString *getRawAPINotesFile() const { return getOperandAs<MDString>(5); }
3285
3286 static bool classof(const Metadata *MD) {
3287 return MD->getMetadataID() == DIModuleKind;
3288 }
3289};
3290
3291/// Base class for template parameters.
3292///
3293/// Uses the SubclassData1 Metadata slot.
3295protected:
3297 unsigned Tag, bool IsDefault, ArrayRef<Metadata *> Ops)
3298 : DINode(Context, ID, Storage, Tag, Ops) {
3299 SubclassData1 = IsDefault;
3300 }
3302
3303public:
3304 StringRef getName() const { return getStringOperand(0); }
3306
3308 Metadata *getRawType() const { return getOperand(1); }
3309 bool isDefault() const { return SubclassData1; }
3310
3311 static bool classof(const Metadata *MD) {
3312 return MD->getMetadataID() == DITemplateTypeParameterKind ||
3313 MD->getMetadataID() == DITemplateValueParameterKind;
3314 }
3315};
3316
3317class DITemplateTypeParameter : public DITemplateParameter {
3318 friend class LLVMContextImpl;
3319 friend class MDNode;
3320
3321 DITemplateTypeParameter(LLVMContext &Context, StorageType Storage,
3323 ~DITemplateTypeParameter() = default;
3324
3325 static DITemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
3326 DIType *Type, bool IsDefault,
3328 bool ShouldCreate = true) {
3329 return getImpl(Context, getCanonicalMDString(Context, Name), Type,
3330 IsDefault, Storage, ShouldCreate);
3331 }
3333 getImpl(LLVMContext &Context, MDString *Name, Metadata *Type, bool IsDefault,
3334 StorageType Storage, bool ShouldCreate = true);
3335
3336 TempDITemplateTypeParameter cloneImpl() const {
3337 return getTemporary(getContext(), getName(), getType(), isDefault());
3338 }
3339
3340public:
3341 DEFINE_MDNODE_GET(DITemplateTypeParameter,
3343 (Name, Type, IsDefault))
3344 DEFINE_MDNODE_GET(DITemplateTypeParameter,
3347
3348 TempDITemplateTypeParameter clone() const { return cloneImpl(); }
3349
3350 static bool classof(const Metadata *MD) {
3351 return MD->getMetadataID() == DITemplateTypeParameterKind;
3352 }
3353};
3354
3355class DITemplateValueParameter : public DITemplateParameter {
3356 friend class LLVMContextImpl;
3357 friend class MDNode;
3358
3359 DITemplateValueParameter(LLVMContext &Context, StorageType Storage,
3360 unsigned Tag, bool IsDefault,
3362 : DITemplateParameter(Context, DITemplateValueParameterKind, Storage, Tag,
3363 IsDefault, Ops) {}
3364 ~DITemplateValueParameter() = default;
3365
3366 static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
3368 bool IsDefault, Metadata *Value,
3370 bool ShouldCreate = true) {
3371 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
3372 IsDefault, Value, Storage, ShouldCreate);
3373 }
3374 LLVM_ABI static DITemplateValueParameter *
3375 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
3376 bool IsDefault, Metadata *Value, StorageType Storage,
3377 bool ShouldCreate = true);
3378
3379 TempDITemplateValueParameter cloneImpl() const {
3380 return getTemporary(getContext(), getTag(), getName(), getType(),
3381 isDefault(), getValue());
3382 }
3383
3384public:
3385 DEFINE_MDNODE_GET(DITemplateValueParameter,
3386 (unsigned Tag, StringRef Name, DIType *Type, bool IsDefault,
3387 Metadata *Value),
3388 (Tag, Name, Type, IsDefault, Value))
3389 DEFINE_MDNODE_GET(DITemplateValueParameter,
3393
3394 TempDITemplateValueParameter clone() const { return cloneImpl(); }
3395
3396 Metadata *getValue() const { return getOperand(2); }
3397
3398 static bool classof(const Metadata *MD) {
3399 return MD->getMetadataID() == DITemplateValueParameterKind;
3400 }
3401};
3402
3403/// Base class for variables.
3404///
3405/// Uses the SubclassData32 Metadata slot.
3406class DIVariable : public DINode {
3407 unsigned Line;
3408
3409protected:
3411 signed Line, ArrayRef<Metadata *> Ops,
3412 uint32_t AlignInBits = 0);
3413 ~DIVariable() = default;
3414
3415public:
3416 unsigned getLine() const { return Line; }
3418 StringRef getName() const { return getStringOperand(1); }
3422 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
3423 /// Determines the size of the variable's type.
3424 LLVM_ABI std::optional<uint64_t> getSizeInBits() const;
3425
3426 /// Return the signedness of this variable's type, or std::nullopt if this
3427 /// type is neither signed nor unsigned.
3428 std::optional<DIBasicType::Signedness> getSignedness() const {
3429 if (auto *BT = dyn_cast<DIBasicType>(getType()))
3430 return BT->getSignedness();
3431 return std::nullopt;
3432 }
3433
3435 if (auto *F = getFile())
3436 return F->getFilename();
3437 return "";
3438 }
3439
3441 if (auto *F = getFile())
3442 return F->getDirectory();
3443 return "";
3444 }
3445
3446 std::optional<StringRef> getSource() const {
3447 if (auto *F = getFile())
3448 return F->getSource();
3449 return std::nullopt;
3450 }
3451
3452 Metadata *getRawScope() const { return getOperand(0); }
3454 Metadata *getRawFile() const { return getOperand(2); }
3455 Metadata *getRawType() const { return getOperand(3); }
3456
3457 static bool classof(const Metadata *MD) {
3458 return MD->getMetadataID() == DILocalVariableKind ||
3459 MD->getMetadataID() == DIGlobalVariableKind;
3460 }
3461};
3462
3463/// DWARF expression.
3464///
3465/// This is (almost) a DWARF expression that modifies the location of a
3466/// variable, or the location of a single piece of a variable, or (when using
3467/// DW_OP_stack_value) is the constant variable value.
3468///
3469/// TODO: Co-allocate the expression elements.
3470/// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
3471/// storage types.
3472class DIExpression : public MDNode {
3473 friend class LLVMContextImpl;
3474 friend class MDNode;
3475
3476 std::vector<uint64_t> Elements;
3477
3478 DIExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
3479 : MDNode(C, DIExpressionKind, Storage, {}),
3480 Elements(Elements.begin(), Elements.end()) {}
3481 ~DIExpression() = default;
3482
3483 LLVM_ABI static DIExpression *getImpl(LLVMContext &Context,
3484 ArrayRef<uint64_t> Elements,
3486 bool ShouldCreate = true);
3487
3488 TempDIExpression cloneImpl() const {
3489 return getTemporary(getContext(), getElements());
3490 }
3491
3492public:
3493 DEFINE_MDNODE_GET(DIExpression, (ArrayRef<uint64_t> Elements), (Elements))
3494
3495 TempDIExpression clone() const { return cloneImpl(); }
3496
3497 ArrayRef<uint64_t> getElements() const { return Elements; }
3498
3499 unsigned getNumElements() const { return Elements.size(); }
3500
3501 uint64_t getElement(unsigned I) const {
3502 assert(I < Elements.size() && "Index out of range");
3503 return Elements[I];
3504 }
3505
3507 /// Determine whether this represents a constant value, if so
3508 // return it's sign information.
3509 LLVM_ABI std::optional<SignedOrUnsignedConstant> isConstant() const;
3510
3511 /// Return the number of unique location operands referred to (via
3512 /// DW_OP_LLVM_arg) in this expression; this is not necessarily the number of
3513 /// instances of DW_OP_LLVM_arg within the expression.
3514 /// For example, for the expression:
3515 /// (DW_OP_LLVM_arg 0, DW_OP_LLVM_arg 1, DW_OP_plus,
3516 /// DW_OP_LLVM_arg 0, DW_OP_mul)
3517 /// This function would return 2, as there are two unique location operands
3518 /// (0 and 1).
3520
3522
3525
3526 /// A lightweight wrapper around an expression operand.
3527 ///
3528 /// TODO: Store arguments directly and change \a DIExpression to store a
3529 /// range of these.
3531 const uint64_t *Op = nullptr;
3532
3533 public:
3534 ExprOperand() = default;
3535 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
3536
3537 const uint64_t *get() const { return Op; }
3538
3539 /// Get the operand code.
3540 uint64_t getOp() const { return *Op; }
3541
3542 /// Get an argument to the operand.
3543 ///
3544 /// Never returns the operand itself.
3545 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
3546
3547 unsigned getNumArgs() const { return getSize() - 1; }
3548
3549 /// Return the size of the operand.
3550 ///
3551 /// Return the number of elements in the operand (1 + args).
3552 LLVM_ABI unsigned getSize() const;
3553
3554 /// Append the elements of this operand to \p V.
3556 V.append(get(), get() + getSize());
3557 }
3558 };
3559
3560 /// An iterator for expression operands.
3562 ExprOperand Op;
3563
3564 public:
3565 using iterator_category = std::input_iterator_tag;
3567 using difference_type = std::ptrdiff_t;
3570
3571 expr_op_iterator() = default;
3573
3574 element_iterator getBase() const { return Op.get(); }
3575 const ExprOperand &operator*() const { return Op; }
3576 const ExprOperand *operator->() const { return &Op; }
3577
3579 increment();
3580 return *this;
3581 }
3583 expr_op_iterator T(*this);
3584 increment();
3585 return T;
3586 }
3587
3588 /// Get the next iterator.
3589 ///
3590 /// \a std::next() doesn't work because this is technically an
3591 /// input_iterator, but it's a perfectly valid operation. This is an
3592 /// accessor to provide the same functionality.
3593 expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
3594
3595 bool operator==(const expr_op_iterator &X) const {
3596 return getBase() == X.getBase();
3597 }
3598 bool operator!=(const expr_op_iterator &X) const {
3599 return getBase() != X.getBase();
3600 }
3601
3602 private:
3603 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
3604 };
3605
3606 /// Visit the elements via ExprOperand wrappers.
3607 ///
3608 /// These range iterators visit elements through \a ExprOperand wrappers.
3609 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
3610 /// true.
3611 ///
3612 /// \pre \a isValid() gives \c true.
3613 /// @{
3623 /// @}
3624
3625 LLVM_ABI bool isValid() const;
3626
3627 static bool classof(const Metadata *MD) {
3628 return MD->getMetadataID() == DIExpressionKind;
3629 }
3630
3631 /// Return whether the first element a DW_OP_deref.
3632 LLVM_ABI bool startsWithDeref() const;
3633
3634 /// Return whether there is exactly one operator and it is a DW_OP_deref;
3635 LLVM_ABI bool isDeref() const;
3636
3638
3639 /// Return the number of bits that have an active value, i.e. those that
3640 /// aren't known to be zero/sign (depending on the type of Var) and which
3641 /// are within the size of this fragment (if it is one). If we can't deduce
3642 /// anything from the expression this will return the size of Var.
3643 LLVM_ABI std::optional<uint64_t> getActiveBits(DIVariable *Var);
3644
3645 /// Retrieve the details of this fragment expression.
3646 LLVM_ABI static std::optional<FragmentInfo>
3648
3649 /// Retrieve the details of this fragment expression.
3650 std::optional<FragmentInfo> getFragmentInfo() const {
3652 }
3653
3654 /// Return whether this is a piece of an aggregate variable.
3655 bool isFragment() const { return getFragmentInfo().has_value(); }
3656
3657 /// Return whether this is an implicit location description.
3658 LLVM_ABI bool isImplicit() const;
3659
3660 /// Return whether the location is computed on the expression stack, meaning
3661 /// it cannot be a simple register location.
3662 LLVM_ABI bool isComplex() const;
3663
3664 /// Return whether the evaluated expression makes use of a single location at
3665 /// the start of the expression, i.e. if it contains only a single
3666 /// DW_OP_LLVM_arg op as its first operand, or if it contains none.
3668
3669 /// Returns a reference to the elements contained in this expression, skipping
3670 /// past the leading `DW_OP_LLVM_arg, 0` if one is present.
3671 /// Similar to `convertToNonVariadicExpression`, but faster and cheaper - it
3672 /// does not check whether the expression is a single-location expression, and
3673 /// it returns elements rather than creating a new DIExpression.
3674 LLVM_ABI std::optional<ArrayRef<uint64_t>>
3676
3677 /// Removes all elements from \p Expr that do not apply to an undef debug
3678 /// value, which includes every operator that computes the value/location on
3679 /// the DWARF stack, including any DW_OP_LLVM_arg elements (making the result
3680 /// of this function always a single-location expression) while leaving
3681 /// everything that defines what the computed value applies to, i.e. the
3682 /// fragment information.
3683 LLVM_ABI static const DIExpression *
3685
3686 /// If \p Expr is a non-variadic expression (i.e. one that does not contain
3687 /// DW_OP_LLVM_arg), returns \p Expr converted to variadic form by adding a
3688 /// leading [DW_OP_LLVM_arg, 0] to the expression; otherwise returns \p Expr.
3689 LLVM_ABI static const DIExpression *
3691
3692 /// If \p Expr is a valid single-location expression, i.e. it refers to only a
3693 /// single debug operand at the start of the expression, then return that
3694 /// expression in a non-variadic form by removing DW_OP_LLVM_arg from the
3695 /// expression if it is present; otherwise returns std::nullopt.
3696 /// See also `getSingleLocationExpressionElements` above, which skips
3697 /// checking `isSingleLocationExpression` and returns a list of elements
3698 /// rather than a DIExpression.
3699 LLVM_ABI static std::optional<const DIExpression *>
3701
3702 /// Inserts the elements of \p Expr into \p Ops modified to a canonical form,
3703 /// which uses DW_OP_LLVM_arg (i.e. is a variadic expression) and folds the
3704 /// implied derefence from the \p IsIndirect flag into the expression. This
3705 /// allows us to check equivalence between expressions with differing
3706 /// directness or variadicness.
3708 const DIExpression *Expr,
3709 bool IsIndirect);
3710
3711 /// Determines whether two debug values should produce equivalent DWARF
3712 /// expressions, using their DIExpressions and directness, ignoring the
3713 /// differences between otherwise identical expressions in variadic and
3714 /// non-variadic form and not considering the debug operands.
3715 /// \p FirstExpr is the DIExpression for the first debug value.
3716 /// \p FirstIndirect should be true if the first debug value is indirect; in
3717 /// IR this should be true for dbg.declare intrinsics and false for
3718 /// dbg.values, and in MIR this should be true only for DBG_VALUE instructions
3719 /// whose second operand is an immediate value.
3720 /// \p SecondExpr and \p SecondIndirect have the same meaning as the prior
3721 /// arguments, but apply to the second debug value.
3722 LLVM_ABI static bool isEqualExpression(const DIExpression *FirstExpr,
3723 bool FirstIndirect,
3724 const DIExpression *SecondExpr,
3725 bool SecondIndirect);
3726
3727 /// Append \p Ops with operations to apply the \p Offset.
3729 int64_t Offset);
3730
3731 LLVM_ABI static bool
3732 extractLeadingOffset(ArrayRef<uint64_t> Ops, int64_t &OffsetInBytes,
3733 SmallVectorImpl<uint64_t> &RemainingOps);
3734
3735 /// If this is a constant offset, extract it. If there is no expression,
3736 /// return true with an offset of zero.
3737 LLVM_ABI bool extractIfOffset(int64_t &Offset) const;
3738
3739 /// Assuming that the expression operates on an address, extract a constant
3740 /// offset and the successive ops. Return false if the expression contains
3741 /// any incompatible ops (including non-zero DW_OP_LLVM_args - only a single
3742 /// address operand to the expression is permitted).
3743 ///
3744 /// We don't try very hard to interpret the expression because we assume that
3745 /// foldConstantMath has canonicalized the expression.
3746 LLVM_ABI bool
3747 extractLeadingOffset(int64_t &OffsetInBytes,
3748 SmallVectorImpl<uint64_t> &RemainingOps) const;
3749
3750 /// Returns true iff this DIExpression contains at least one instance of
3751 /// `DW_OP_LLVM_arg, n` for all n in [0, N).
3752 LLVM_ABI bool hasAllLocationOps(unsigned N) const;
3753
3754 /// Checks if the last 4 elements of the expression are DW_OP_constu <DWARF
3755 /// Address Space> DW_OP_swap DW_OP_xderef and extracts the <DWARF Address
3756 /// Space>.
3757 LLVM_ABI static const DIExpression *
3758 extractAddressClass(const DIExpression *Expr, unsigned &AddrClass);
3759
3760 /// Used for DIExpression::prepend.
3763 DerefBefore = 1 << 0,
3764 DerefAfter = 1 << 1,
3765 StackValue = 1 << 2,
3766 EntryValue = 1 << 3
3767 };
3768
3769 /// Prepend \p DIExpr with a deref and offset operation and optionally turn it
3770 /// into a stack value or/and an entry value.
3771 LLVM_ABI static DIExpression *prepend(const DIExpression *Expr, uint8_t Flags,
3772 int64_t Offset = 0);
3773
3774 /// Prepend \p DIExpr with the given opcodes and optionally turn it into a
3775 /// stack value.
3778 bool StackValue = false,
3779 bool EntryValue = false);
3780
3781 /// Append the opcodes \p Ops to \p DIExpr. Unlike \ref appendToStack, the
3782 /// returned expression is a stack value only if \p DIExpr is a stack value.
3783 /// If \p DIExpr describes a fragment, the returned expression will describe
3784 /// the same fragment.
3785 LLVM_ABI static DIExpression *append(const DIExpression *Expr,
3787
3788 /// Convert \p DIExpr into a stack value if it isn't one already by appending
3789 /// DW_OP_deref if needed, and appending \p Ops to the resulting expression.
3790 /// If \p DIExpr describes a fragment, the returned expression will describe
3791 /// the same fragment.
3792 LLVM_ABI static DIExpression *appendToStack(const DIExpression *Expr,
3794
3795 /// Create a copy of \p Expr by appending the given list of \p Ops to each
3796 /// instance of the operand `DW_OP_LLVM_arg, \p ArgNo`. This is used to
3797 /// modify a specific location used by \p Expr, such as when salvaging that
3798 /// location.
3801 unsigned ArgNo,
3802 bool StackValue = false);
3803
3804 /// Create a copy of \p Expr with each instance of
3805 /// `DW_OP_LLVM_arg, \p OldArg` replaced with `DW_OP_LLVM_arg, \p NewArg`,
3806 /// and each instance of `DW_OP_LLVM_arg, Arg` with `DW_OP_LLVM_arg, Arg - 1`
3807 /// for all Arg > \p OldArg.
3808 /// This is used when replacing one of the operands of a debug value list
3809 /// with another operand in the same list and deleting the old operand.
3810 LLVM_ABI static DIExpression *replaceArg(const DIExpression *Expr,
3811 uint64_t OldArg, uint64_t NewArg);
3812
3813 /// Create a DIExpression to describe one part of an aggregate variable that
3814 /// is fragmented across multiple Values. The DW_OP_LLVM_fragment operation
3815 /// will be appended to the elements of \c Expr. If \c Expr already contains
3816 /// a \c DW_OP_LLVM_fragment \c OffsetInBits is interpreted as an offset
3817 /// into the existing fragment.
3818 ///
3819 /// \param OffsetInBits Offset of the piece in bits.
3820 /// \param SizeInBits Size of the piece in bits.
3821 /// \return Creating a fragment expression may fail if \c Expr
3822 /// contains arithmetic operations that would be
3823 /// truncated.
3824 LLVM_ABI static std::optional<DIExpression *>
3825 createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits,
3826 unsigned SizeInBits);
3827
3828 /// Determine the relative position of the fragments passed in.
3829 /// Returns -1 if this is entirely before Other, 0 if this and Other overlap,
3830 /// 1 if this is entirely after Other.
3831 static int fragmentCmp(const FragmentInfo &A, const FragmentInfo &B) {
3832 uint64_t l1 = A.OffsetInBits;
3833 uint64_t l2 = B.OffsetInBits;
3834 uint64_t r1 = l1 + A.SizeInBits;
3835 uint64_t r2 = l2 + B.SizeInBits;
3836 if (r1 <= l2)
3837 return -1;
3838 else if (r2 <= l1)
3839 return 1;
3840 else
3841 return 0;
3842 }
3843
3844 /// Computes a fragment, bit-extract operation if needed, and new constant
3845 /// offset to describe a part of a variable covered by some memory.
3846 ///
3847 /// The memory region starts at:
3848 /// \p SliceStart + \p SliceOffsetInBits
3849 /// And is size:
3850 /// \p SliceSizeInBits
3851 ///
3852 /// The location of the existing variable fragment \p VarFrag is:
3853 /// \p DbgPtr + \p DbgPtrOffsetInBits + \p DbgExtractOffsetInBits.
3854 ///
3855 /// It is intended that these arguments are derived from a debug record:
3856 /// - \p DbgPtr is the (single) DIExpression operand.
3857 /// - \p DbgPtrOffsetInBits is the constant offset applied to \p DbgPtr.
3858 /// - \p DbgExtractOffsetInBits is the offset from a
3859 /// DW_OP_LLVM_bit_extract_[sz]ext operation.
3860 ///
3861 /// Results and return value:
3862 /// - Return false if the result can't be calculated for any reason.
3863 /// - \p Result is set to nullopt if the intersect equals \p VarFarg.
3864 /// - \p Result contains a zero-sized fragment if there's no intersect.
3865 /// - \p OffsetFromLocationInBits is set to the difference between the first
3866 /// bit of the variable location and the first bit of the slice. The
3867 /// magnitude of a negative value therefore indicates the number of bits
3868 /// into the variable fragment that the memory region begins.
3869 ///
3870 /// We don't pass in a debug record directly to get the constituent parts
3871 /// and offsets because different debug records store the information in
3872 /// different places (dbg_assign has two DIExpressions - one contains the
3873 /// fragment info for the entire intrinsic).
3875 const DataLayout &DL, const Value *SliceStart, uint64_t SliceOffsetInBits,
3876 uint64_t SliceSizeInBits, const Value *DbgPtr, int64_t DbgPtrOffsetInBits,
3877 int64_t DbgExtractOffsetInBits, DIExpression::FragmentInfo VarFrag,
3878 std::optional<DIExpression::FragmentInfo> &Result,
3879 int64_t &OffsetFromLocationInBits);
3880
3881 using ExtOps = std::array<uint64_t, 6>;
3882
3883 /// Returns the ops for a zero- or sign-extension in a DIExpression.
3884 LLVM_ABI static ExtOps getExtOps(unsigned FromSize, unsigned ToSize,
3885 bool Signed);
3886
3887 /// Append a zero- or sign-extension to \p Expr. Converts the expression to a
3888 /// stack value if it isn't one already.
3889 LLVM_ABI static DIExpression *appendExt(const DIExpression *Expr,
3890 unsigned FromSize, unsigned ToSize,
3891 bool Signed);
3892
3893 /// Check if fragments overlap between a pair of FragmentInfos.
3894 static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B) {
3895 return fragmentCmp(A, B) == 0;
3896 }
3897
3898 /// Determine the relative position of the fragments described by this
3899 /// DIExpression and \p Other. Calls static fragmentCmp implementation.
3900 int fragmentCmp(const DIExpression *Other) const {
3901 auto Fragment1 = *getFragmentInfo();
3902 auto Fragment2 = *Other->getFragmentInfo();
3903 return fragmentCmp(Fragment1, Fragment2);
3904 }
3905
3906 /// Check if fragments overlap between this DIExpression and \p Other.
3907 bool fragmentsOverlap(const DIExpression *Other) const {
3908 if (!isFragment() || !Other->isFragment())
3909 return true;
3910 return fragmentCmp(Other) == 0;
3911 }
3912
3913 /// Check if the expression consists of exactly one entry value operand.
3914 /// (This is the only configuration of entry values that is supported.)
3915 LLVM_ABI bool isEntryValue() const;
3916
3917 /// Try to shorten an expression with an initial constant operand.
3918 /// Returns a new expression and constant on success, or the original
3919 /// expression and constant on failure.
3920 LLVM_ABI std::pair<DIExpression *, const ConstantInt *>
3921 constantFold(const ConstantInt *CI);
3922
3923 /// Try to shorten an expression with constant math operations that can be
3924 /// evaluated at compile time. Returns a new expression on success, or the old
3925 /// expression if there is nothing to be reduced.
3927};
3928
3931 return std::tie(A.SizeInBits, A.OffsetInBits) ==
3932 std::tie(B.SizeInBits, B.OffsetInBits);
3933}
3934
3937 return std::tie(A.SizeInBits, A.OffsetInBits) <
3938 std::tie(B.SizeInBits, B.OffsetInBits);
3939}
3940
3941template <> struct DenseMapInfo<DIExpression::FragmentInfo> {
3943 static const uint64_t MaxVal = std::numeric_limits<uint64_t>::max();
3944
3945 static unsigned getHashValue(const FragInfo &Frag) {
3946 return (Frag.SizeInBits & 0xffff) << 16 | (Frag.OffsetInBits & 0xffff);
3947 }
3948
3949 static bool isEqual(const FragInfo &A, const FragInfo &B) { return A == B; }
3950};
3951
3952/// Holds a DIExpression and keeps track of how many operands have been consumed
3953/// so far.
3956
3957public:
3959 if (!Expr) {
3960 assert(Start == End);
3961 return;
3962 }
3963 Start = Expr->expr_op_begin();
3964 End = Expr->expr_op_end();
3965 }
3966
3968 : Start(Expr.begin()), End(Expr.end()) {}
3969
3971
3972 /// Consume one operation.
3973 std::optional<DIExpression::ExprOperand> take() {
3974 if (Start == End)
3975 return std::nullopt;
3976 return *(Start++);
3977 }
3978
3979 /// Consume N operations.
3980 void consume(unsigned N) { std::advance(Start, N); }
3981
3982 /// Return the current operation.
3983 std::optional<DIExpression::ExprOperand> peek() const {
3984 if (Start == End)
3985 return std::nullopt;
3986 return *(Start);
3987 }
3988
3989 /// Return the next operation.
3990 std::optional<DIExpression::ExprOperand> peekNext() const {
3991 if (Start == End)
3992 return std::nullopt;
3993
3994 auto Next = Start.getNext();
3995 if (Next == End)
3996 return std::nullopt;
3997
3998 return *Next;
3999 }
4000
4001 std::optional<DIExpression::ExprOperand> peekNextN(unsigned N) const {
4002 if (Start == End)
4003 return std::nullopt;
4005 for (unsigned I = 0; I < N; I++) {
4006 Nth = Nth.getNext();
4007 if (Nth == End)
4008 return std::nullopt;
4009 }
4010 return *Nth;
4011 }
4012
4014 this->Start = DIExpression::expr_op_iterator(Expr.begin());
4015 this->End = DIExpression::expr_op_iterator(Expr.end());
4016 }
4017
4018 /// Determine whether there are any operations left in this expression.
4019 operator bool() const { return Start != End; }
4020
4021 DIExpression::expr_op_iterator begin() const { return Start; }
4022 DIExpression::expr_op_iterator end() const { return End; }
4023
4024 /// Retrieve the fragment information, if any.
4025 std::optional<DIExpression::FragmentInfo> getFragmentInfo() const {
4026 return DIExpression::getFragmentInfo(Start, End);
4027 }
4028};
4029
4030/// Global variables.
4031///
4032/// TODO: Remove DisplayName. It's always equal to Name.
4033class DIGlobalVariable : public DIVariable {
4034 friend class LLVMContextImpl;
4035 friend class MDNode;
4036
4037 bool IsLocalToUnit;
4038 bool IsDefinition;
4039
4040 DIGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
4041 bool IsLocalToUnit, bool IsDefinition, uint32_t AlignInBits,
4043 : DIVariable(C, DIGlobalVariableKind, Storage, Line, Ops, AlignInBits),
4044 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
4045 ~DIGlobalVariable() = default;
4046
4047 static DIGlobalVariable *
4048 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
4049 StringRef LinkageName, DIFile *File, unsigned Line, DIType *Type,
4050 bool IsLocalToUnit, bool IsDefinition,
4053 bool ShouldCreate = true) {
4054 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
4055 getCanonicalMDString(Context, LinkageName), File, Line, Type,
4058 Annotations.get(), Storage, ShouldCreate);
4059 }
4060 LLVM_ABI static DIGlobalVariable *
4061 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
4062 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
4063 bool IsLocalToUnit, bool IsDefinition,
4066 bool ShouldCreate = true);
4067
4068 TempDIGlobalVariable cloneImpl() const {
4073 getAnnotations());
4074 }
4075
4076public:
4078 DIGlobalVariable,
4080 unsigned Line, DIType *Type, bool IsLocalToUnit, bool IsDefinition,
4082 uint32_t AlignInBits, DINodeArray Annotations),
4083 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
4086 DIGlobalVariable,
4088 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
4091 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
4093
4094 TempDIGlobalVariable clone() const { return cloneImpl(); }
4095
4096 bool isLocalToUnit() const { return IsLocalToUnit; }
4097 bool isDefinition() const { return IsDefinition; }
4103 DINodeArray getAnnotations() const {
4105 }
4106
4111 Metadata *getRawAnnotations() const { return getOperand(8); }
4112
4113 static bool classof(const Metadata *MD) {
4114 return MD->getMetadataID() == DIGlobalVariableKind;
4115 }
4116};
4117
4118/// Debug common block.
4119///
4120/// Uses the SubclassData32 Metadata slot.
4121class DICommonBlock : public DIScope {
4122 friend class LLVMContextImpl;
4123 friend class MDNode;
4124
4125 DICommonBlock(LLVMContext &Context, StorageType Storage, unsigned LineNo,
4127
4128 static DICommonBlock *getImpl(LLVMContext &Context, DIScope *Scope,
4130 DIFile *File, unsigned LineNo,
4131 StorageType Storage, bool ShouldCreate = true) {
4132 return getImpl(Context, Scope, Decl, getCanonicalMDString(Context, Name),
4133 File, LineNo, Storage, ShouldCreate);
4134 }
4135 LLVM_ABI static DICommonBlock *getImpl(LLVMContext &Context, Metadata *Scope,
4137 Metadata *File, unsigned LineNo,
4139 bool ShouldCreate = true);
4140
4141 TempDICommonBlock cloneImpl() const {
4143 getFile(), getLineNo());
4144 }
4145
4146public:
4147 DEFINE_MDNODE_GET(DICommonBlock,
4149 DIFile *File, unsigned LineNo),
4150 (Scope, Decl, Name, File, LineNo))
4151 DEFINE_MDNODE_GET(DICommonBlock,
4153 Metadata *File, unsigned LineNo),
4155
4156 TempDICommonBlock clone() const { return cloneImpl(); }
4157
4162 StringRef getName() const { return getStringOperand(2); }
4164 unsigned getLineNo() const { return SubclassData32; }
4165
4166 Metadata *getRawScope() const { return getOperand(0); }
4167 Metadata *getRawDecl() const { return getOperand(1); }
4169 Metadata *getRawFile() const { return getOperand(3); }
4170
4171 static bool classof(const Metadata *MD) {
4172 return MD->getMetadataID() == DICommonBlockKind;
4173 }
4174};
4175
4176/// Local variable.
4177///
4178/// TODO: Split up flags.
4179class DILocalVariable : public DIVariable {
4180 friend class LLVMContextImpl;
4181 friend class MDNode;
4182
4183 unsigned Arg : 16;
4184 DIFlags Flags;
4185
4186 DILocalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
4187 unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
4189 : DIVariable(C, DILocalVariableKind, Storage, Line, Ops, AlignInBits),
4190 Arg(Arg), Flags(Flags) {
4191 assert(Arg < (1 << 16) && "DILocalVariable: Arg out of range");
4192 }
4193 ~DILocalVariable() = default;
4194
4195 static DILocalVariable *getImpl(LLVMContext &Context, DIScope *Scope,
4196 StringRef Name, DIFile *File, unsigned Line,
4197 DIType *Type, unsigned Arg, DIFlags Flags,
4198 uint32_t AlignInBits, DINodeArray Annotations,
4200 bool ShouldCreate = true) {
4201 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
4202 Line, Type, Arg, Flags, AlignInBits, Annotations.get(),
4203 Storage, ShouldCreate);
4204 }
4205 LLVM_ABI static DILocalVariable *
4206 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, Metadata *File,
4207 unsigned Line, Metadata *Type, unsigned Arg, DIFlags Flags,
4209 bool ShouldCreate = true);
4210
4211 TempDILocalVariable cloneImpl() const {
4213 getLine(), getType(), getArg(), getFlags(),
4215 }
4216
4217public:
4218 DEFINE_MDNODE_GET(DILocalVariable,
4220 unsigned Line, DIType *Type, unsigned Arg, DIFlags Flags,
4221 uint32_t AlignInBits, DINodeArray Annotations),
4222 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits,
4223 Annotations))
4224 DEFINE_MDNODE_GET(DILocalVariable,
4226 unsigned Line, Metadata *Type, unsigned Arg, DIFlags Flags,
4228 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits,
4229 Annotations))
4230
4231 TempDILocalVariable clone() const { return cloneImpl(); }
4232
4233 /// Get the local scope for this variable.
4234 ///
4235 /// Variables must be defined in a local scope.
4239
4240 bool isParameter() const { return Arg; }
4241 unsigned getArg() const { return Arg; }
4242 DIFlags getFlags() const { return Flags; }
4243
4244 DINodeArray getAnnotations() const {
4246 }
4247 Metadata *getRawAnnotations() const { return getOperand(4); }
4248
4249 bool isArtificial() const { return getFlags() & FlagArtificial; }
4250 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
4251
4252 /// Check that a location is valid for this variable.
4253 ///
4254 /// Check that \c DL exists, is in the same subprogram, and has the same
4255 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
4256 /// to a \a DbgInfoIntrinsic.)
4258 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
4259 }
4260
4261 static bool classof(const Metadata *MD) {
4262 return MD->getMetadataID() == DILocalVariableKind;
4263 }
4264};
4265
4266/// Label.
4267///
4268/// Uses the SubclassData32 Metadata slot.
4269class DILabel : public DINode {
4270 friend class LLVMContextImpl;
4271 friend class MDNode;
4272
4273 unsigned Column;
4274 std::optional<unsigned> CoroSuspendIdx;
4275 bool IsArtificial;
4276
4277 DILabel(LLVMContext &C, StorageType Storage, unsigned Line, unsigned Column,
4278 bool IsArtificial, std::optional<unsigned> CoroSuspendIdx,
4280 ~DILabel() = default;
4281
4282 static DILabel *getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
4283 DIFile *File, unsigned Line, unsigned Column,
4284 bool IsArtificial,
4285 std::optional<unsigned> CoroSuspendIdx,
4286 StorageType Storage, bool ShouldCreate = true) {
4287 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
4288 Line, Column, IsArtificial, CoroSuspendIdx, Storage,
4289 ShouldCreate);
4290 }
4291 LLVM_ABI static DILabel *
4292 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, Metadata *File,
4293 unsigned Line, unsigned Column, bool IsArtificial,
4294 std::optional<unsigned> CoroSuspendIdx, StorageType Storage,
4295 bool ShouldCreate = true);
4296
4297 TempDILabel cloneImpl() const {
4301 }
4302
4303public:
4306 unsigned Line, unsigned Column, bool IsArtificial,
4307 std::optional<unsigned> CoroSuspendIdx),
4308 (Scope, Name, File, Line, Column, IsArtificial,
4309 CoroSuspendIdx))
4310 DEFINE_MDNODE_GET(DILabel,
4312 unsigned Line, unsigned Column, bool IsArtificial,
4313 std::optional<unsigned> CoroSuspendIdx),
4314 (Scope, Name, File, Line, Column, IsArtificial,
4315 CoroSuspendIdx))
4316
4317 TempDILabel clone() const { return cloneImpl(); }
4318
4319 /// Get the local scope for this label.
4320 ///
4321 /// Labels must be defined in a local scope.
4325 unsigned getLine() const { return SubclassData32; }
4326 unsigned getColumn() const { return Column; }
4327 StringRef getName() const { return getStringOperand(1); }
4329 bool isArtificial() const { return IsArtificial; }
4330 std::optional<unsigned> getCoroSuspendIdx() const { return CoroSuspendIdx; }
4331
4332 Metadata *getRawScope() const { return getOperand(0); }
4334 Metadata *getRawFile() const { return getOperand(2); }
4335
4336 /// Check that a location is valid for this label.
4337 ///
4338 /// Check that \c DL exists, is in the same subprogram, and has the same
4339 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
4340 /// to a \a DbgInfoIntrinsic.)
4342 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
4343 }
4344
4345 static bool classof(const Metadata *MD) {
4346 return MD->getMetadataID() == DILabelKind;
4347 }
4348};
4349
4350class DIObjCProperty : public DINode {
4351 friend class LLVMContextImpl;
4352 friend class MDNode;
4353
4354 unsigned Line;
4355 unsigned Attributes;
4356
4357 DIObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
4358 unsigned Attributes, ArrayRef<Metadata *> Ops);
4359 ~DIObjCProperty() = default;
4360
4361 static DIObjCProperty *
4362 getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
4363 StringRef GetterName, StringRef SetterName, unsigned Attributes,
4364 DIType *Type, StorageType Storage, bool ShouldCreate = true) {
4365 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
4367 getCanonicalMDString(Context, SetterName), Attributes, Type,
4368 Storage, ShouldCreate);
4369 }
4370 LLVM_ABI static DIObjCProperty *
4371 getImpl(LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
4372 MDString *GetterName, MDString *SetterName, unsigned Attributes,
4373 Metadata *Type, StorageType Storage, bool ShouldCreate = true);
4374
4375 TempDIObjCProperty cloneImpl() const {
4376 return getTemporary(getContext(), getName(), getFile(), getLine(),
4378 getType());
4379 }
4380
4381public:
4382 DEFINE_MDNODE_GET(DIObjCProperty,
4383 (StringRef Name, DIFile *File, unsigned Line,
4385 unsigned Attributes, DIType *Type),
4386 (Name, File, Line, GetterName, SetterName, Attributes,
4387 Type))
4388 DEFINE_MDNODE_GET(DIObjCProperty,
4389 (MDString * Name, Metadata *File, unsigned Line,
4391 unsigned Attributes, Metadata *Type),
4392 (Name, File, Line, GetterName, SetterName, Attributes,
4393 Type))
4394
4395 TempDIObjCProperty clone() const { return cloneImpl(); }
4396
4397 unsigned getLine() const { return Line; }
4398 unsigned getAttributes() const { return Attributes; }
4399 StringRef getName() const { return getStringOperand(0); }
4404
4406 if (auto *F = getFile())
4407 return F->getFilename();
4408 return "";
4409 }
4410
4412 if (auto *F = getFile())
4413 return F->getDirectory();
4414 return "";
4415 }
4416
4418 Metadata *getRawFile() const { return getOperand(1); }
4421 Metadata *getRawType() const { return getOperand(4); }
4422
4423 static bool classof(const Metadata *MD) {
4424 return MD->getMetadataID() == DIObjCPropertyKind;
4425 }
4426};
4427
4428/// An imported module (C++ using directive or similar).
4429///
4430/// Uses the SubclassData32 Metadata slot.
4431class DIImportedEntity : public DINode {
4432 friend class LLVMContextImpl;
4433 friend class MDNode;
4434
4435 DIImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
4436 unsigned Line, ArrayRef<Metadata *> Ops)
4437 : DINode(C, DIImportedEntityKind, Storage, Tag, Ops) {
4439 }
4440 ~DIImportedEntity() = default;
4441
4442 static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
4443 DIScope *Scope, DINode *Entity, DIFile *File,
4444 unsigned Line, StringRef Name,
4445 DINodeArray Elements, StorageType Storage,
4446 bool ShouldCreate = true) {
4447 return getImpl(Context, Tag, Scope, Entity, File, Line,
4448 getCanonicalMDString(Context, Name), Elements.get(), Storage,
4449 ShouldCreate);
4450 }
4451 LLVM_ABI static DIImportedEntity *
4452 getImpl(LLVMContext &Context, unsigned Tag, Metadata *Scope, Metadata *Entity,
4453 Metadata *File, unsigned Line, MDString *Name, Metadata *Elements,
4454 StorageType Storage, bool ShouldCreate = true);
4455
4456 TempDIImportedEntity cloneImpl() const {
4457 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
4458 getFile(), getLine(), getName(), getElements());
4459 }
4460
4461public:
4462 DEFINE_MDNODE_GET(DIImportedEntity,
4463 (unsigned Tag, DIScope *Scope, DINode *Entity, DIFile *File,
4464 unsigned Line, StringRef Name = "",
4465 DINodeArray Elements = nullptr),
4466 (Tag, Scope, Entity, File, Line, Name, Elements))
4467 DEFINE_MDNODE_GET(DIImportedEntity,
4470 Metadata *Elements = nullptr),
4471 (Tag, Scope, Entity, File, Line, Name, Elements))
4472
4473 TempDIImportedEntity clone() const { return cloneImpl(); }
4474
4475 unsigned getLine() const { return SubclassData32; }
4476 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
4477 DINode *getEntity() const { return cast_or_null<DINode>(getRawEntity()); }
4478 StringRef getName() const { return getStringOperand(2); }
4479 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
4480 DINodeArray getElements() const {
4481 return cast_or_null<MDTuple>(getRawElements());
4482 }
4483
4484 Metadata *getRawScope() const { return getOperand(0); }
4485 Metadata *getRawEntity() const { return getOperand(1); }
4486 MDString *getRawName() const { return getOperandAs<MDString>(2); }
4487 Metadata *getRawFile() const { return getOperand(3); }
4488 Metadata *getRawElements() const { return getOperand(4); }
4489
4490 static bool classof(const Metadata *MD) {
4491 return MD->getMetadataID() == DIImportedEntityKind;
4492 }
4493};
4494
4495/// A pair of DIGlobalVariable and DIExpression.
4496class DIGlobalVariableExpression : public MDNode {
4497 friend class LLVMContextImpl;
4498 friend class MDNode;
4499
4500 DIGlobalVariableExpression(LLVMContext &C, StorageType Storage,
4502 : MDNode(C, DIGlobalVariableExpressionKind, Storage, Ops) {}
4503 ~DIGlobalVariableExpression() = default;
4504
4506 getImpl(LLVMContext &Context, Metadata *Variable, Metadata *Expression,
4507 StorageType Storage, bool ShouldCreate = true);
4508
4509 TempDIGlobalVariableExpression cloneImpl() const {
4511 }
4512
4513public:
4514 DEFINE_MDNODE_GET(DIGlobalVariableExpression,
4515 (Metadata * Variable, Metadata *Expression),
4516 (Variable, Expression))
4517
4518 TempDIGlobalVariableExpression clone() const { return cloneImpl(); }
4519
4520 Metadata *getRawVariable() const { return getOperand(0); }
4521
4525
4526 Metadata *getRawExpression() const { return getOperand(1); }
4527
4531
4532 static bool classof(const Metadata *MD) {
4533 return MD->getMetadataID() == DIGlobalVariableExpressionKind;
4534 }
4535};
4536
4537/// Macro Info DWARF-like metadata node.
4538///
4539/// A metadata node with a DWARF macro info (i.e., a constant named
4540/// \c DW_MACINFO_*, defined in llvm/BinaryFormat/Dwarf.h). Called \a
4541/// DIMacroNode
4542/// because it's potentially used for non-DWARF output.
4543///
4544/// Uses the SubclassData16 Metadata slot.
4545class DIMacroNode : public MDNode {
4546 friend class LLVMContextImpl;
4547 friend class MDNode;
4548
4549protected:
4550 DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType,
4552 : MDNode(C, ID, Storage, Ops1, Ops2) {
4553 assert(MIType < 1u << 16);
4554 SubclassData16 = MIType;
4555 }
4556 ~DIMacroNode() = default;
4557
4558 template <class Ty> Ty *getOperandAs(unsigned I) const {
4559 return cast_or_null<Ty>(getOperand(I));
4560 }
4561
4562 StringRef getStringOperand(unsigned I) const {
4563 if (auto *S = getOperandAs<MDString>(I))
4564 return S->getString();
4565 return StringRef();
4566 }
4567
4569 if (S.empty())
4570 return nullptr;
4571 return MDString::get(Context, S);
4572 }
4573
4574public:
4575 unsigned getMacinfoType() const { return SubclassData16; }
4576
4577 static bool classof(const Metadata *MD) {
4578 switch (MD->getMetadataID()) {
4579 default:
4580 return false;
4581 case DIMacroKind:
4582 case DIMacroFileKind:
4583 return true;
4584 }
4585 }
4586};
4587
4588/// Macro
4589///
4590/// Uses the SubclassData32 Metadata slot.
4591class DIMacro : public DIMacroNode {
4592 friend class LLVMContextImpl;
4593 friend class MDNode;
4594
4595 DIMacro(LLVMContext &C, StorageType Storage, unsigned MIType, unsigned Line,
4597 : DIMacroNode(C, DIMacroKind, Storage, MIType, Ops) {
4599 }
4600 ~DIMacro() = default;
4601
4602 static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
4604 bool ShouldCreate = true) {
4605 return getImpl(Context, MIType, Line, getCanonicalMDString(Context, Name),
4606 getCanonicalMDString(Context, Value), Storage, ShouldCreate);
4607 }
4608 LLVM_ABI static DIMacro *getImpl(LLVMContext &Context, unsigned MIType,
4609 unsigned Line, MDString *Name,
4610 MDString *Value, StorageType Storage,
4611 bool ShouldCreate = true);
4612
4613 TempDIMacro cloneImpl() const {
4615 getValue());
4616 }
4617
4618public:
4620 (unsigned MIType, unsigned Line, StringRef Name,
4621 StringRef Value = ""),
4622 (MIType, Line, Name, Value))
4623 DEFINE_MDNODE_GET(DIMacro,
4624 (unsigned MIType, unsigned Line, MDString *Name,
4627
4628 TempDIMacro clone() const { return cloneImpl(); }
4629
4630 unsigned getLine() const { return SubclassData32; }
4631
4632 StringRef getName() const { return getStringOperand(0); }
4633 StringRef getValue() const { return getStringOperand(1); }
4634
4637
4638 static bool classof(const Metadata *MD) {
4639 return MD->getMetadataID() == DIMacroKind;
4640 }
4641};
4642
4643/// Macro file
4644///
4645/// Uses the SubclassData32 Metadata slot.
4646class DIMacroFile : public DIMacroNode {
4647 friend class LLVMContextImpl;
4648 friend class MDNode;
4649
4650 DIMacroFile(LLVMContext &C, StorageType Storage, unsigned MIType,
4651 unsigned Line, ArrayRef<Metadata *> Ops)
4652 : DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops) {
4654 }
4655 ~DIMacroFile() = default;
4656
4657 static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
4658 unsigned Line, DIFile *File,
4659 DIMacroNodeArray Elements, StorageType Storage,
4660 bool ShouldCreate = true) {
4661 return getImpl(Context, MIType, Line, static_cast<Metadata *>(File),
4662 Elements.get(), Storage, ShouldCreate);
4663 }
4664
4665 LLVM_ABI static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
4666 unsigned Line, Metadata *File,
4668 bool ShouldCreate = true);
4669
4670 TempDIMacroFile cloneImpl() const {
4672 getElements());
4673 }
4674
4675public:
4677 (unsigned MIType, unsigned Line, DIFile *File,
4678 DIMacroNodeArray Elements),
4679 (MIType, Line, File, Elements))
4680 DEFINE_MDNODE_GET(DIMacroFile,
4681 (unsigned MIType, unsigned Line, Metadata *File,
4684
4685 TempDIMacroFile clone() const { return cloneImpl(); }
4686
4687 void replaceElements(DIMacroNodeArray Elements) {
4688#ifndef NDEBUG
4689 for (DIMacroNode *Op : getElements())
4690 assert(is_contained(Elements->operands(), Op) &&
4691 "Lost a macro node during macro node list replacement");
4692#endif
4693 replaceOperandWith(1, Elements.get());
4694 }
4695
4696 unsigned getLine() const { return SubclassData32; }
4698
4699 DIMacroNodeArray getElements() const {
4701 }
4702
4703 Metadata *getRawFile() const { return getOperand(0); }
4704 Metadata *getRawElements() const { return getOperand(1); }
4705
4706 static bool classof(const Metadata *MD) {
4707 return MD->getMetadataID() == DIMacroFileKind;
4708 }
4709};
4710
4711/// List of ValueAsMetadata, to be used as an argument to a dbg.value
4712/// intrinsic.
4713class DIArgList : public Metadata, ReplaceableMetadataImpl {
4715 friend class LLVMContextImpl;
4717
4719
4720 DIArgList(LLVMContext &Context, ArrayRef<ValueAsMetadata *> Args)
4721 : Metadata(DIArgListKind, Uniqued), ReplaceableMetadataImpl(Context),
4722 Args(Args) {
4723 track();
4724 }
4725 ~DIArgList() { untrack(); }
4726
4727 LLVM_ABI void track();
4728 LLVM_ABI void untrack();
4729 void dropAllReferences(bool Untrack);
4730
4731public:
4732 LLVM_ABI static DIArgList *get(LLVMContext &Context,
4734
4735 ArrayRef<ValueAsMetadata *> getArgs() const { return Args; }
4736
4737 iterator args_begin() { return Args.begin(); }
4738 iterator args_end() { return Args.end(); }
4739
4740 static bool classof(const Metadata *MD) {
4741 return MD->getMetadataID() == DIArgListKind;
4742 }
4743
4747
4748 LLVM_ABI void handleChangedOperand(void *Ref, Metadata *New);
4749};
4750
4751/// Identifies a unique instance of a variable.
4752///
4753/// Storage for identifying a potentially inlined instance of a variable,
4754/// or a fragment thereof. This guarantees that exactly one variable instance
4755/// may be identified by this class, even when that variable is a fragment of
4756/// an aggregate variable and/or there is another inlined instance of the same
4757/// source code variable nearby.
4758/// This class does not necessarily uniquely identify that variable: it is
4759/// possible that a DebugVariable with different parameters may point to the
4760/// same variable instance, but not that one DebugVariable points to multiple
4761/// variable instances.
4763 using FragmentInfo = DIExpression::FragmentInfo;
4764
4765 const DILocalVariable *Variable;
4766 std::optional<FragmentInfo> Fragment;
4767 const DILocation *InlinedAt;
4768
4769 /// Fragment that will overlap all other fragments. Used as default when
4770 /// caller demands a fragment.
4771 LLVM_ABI static const FragmentInfo DefaultFragment;
4772
4773public:
4775
4777 std::optional<FragmentInfo> FragmentInfo,
4778 const DILocation *InlinedAt)
4779 : Variable(Var), Fragment(FragmentInfo), InlinedAt(InlinedAt) {}
4780
4781 DebugVariable(const DILocalVariable *Var, const DIExpression *DIExpr,
4782 const DILocation *InlinedAt)
4783 : Variable(Var),
4784 Fragment(DIExpr ? DIExpr->getFragmentInfo() : std::nullopt),
4785 InlinedAt(InlinedAt) {}
4786
4787 const DILocalVariable *getVariable() const { return Variable; }
4788 std::optional<FragmentInfo> getFragment() const { return Fragment; }
4789 const DILocation *getInlinedAt() const { return InlinedAt; }
4790
4791 FragmentInfo getFragmentOrDefault() const {
4792 return Fragment.value_or(DefaultFragment);
4793 }
4794
4795 static bool isDefaultFragment(const FragmentInfo F) {
4796 return F == DefaultFragment;
4797 }
4798
4799 bool operator==(const DebugVariable &Other) const {
4800 return std::tie(Variable, Fragment, InlinedAt) ==
4801 std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
4802 }
4803
4804 bool operator<(const DebugVariable &Other) const {
4805 return std::tie(Variable, Fragment, InlinedAt) <
4806 std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
4807 }
4808};
4809
4810template <> struct DenseMapInfo<DebugVariable> {
4812
4813 static unsigned getHashValue(const DebugVariable &D) {
4814 unsigned HV = 0;
4815 const std::optional<FragmentInfo> Fragment = D.getFragment();
4816 if (Fragment)
4818
4819 return hash_combine(D.getVariable(), HV, D.getInlinedAt());
4820 }
4821
4822 static bool isEqual(const DebugVariable &A, const DebugVariable &B) {
4823 return A == B;
4824 }
4825};
4826
4827/// Identifies a unique instance of a whole variable (discards/ignores fragment
4828/// information).
4835
4836template <>
4838 : public DenseMapInfo<DebugVariable> {};
4839
4840template <typename NodeT> static const DIScope *getScope(const NodeT *N) {
4841 return N->getScope();
4842}
4843
4844template <typename NodeT> static DIScope *getScope(NodeT *N) {
4845 return N->getScope();
4846}
4847
4848template <>
4849[[maybe_unused]] const DIScope *
4851 return N->getVariable()->getScope();
4852}
4853template <>
4855 return N->getVariable()->getScope();
4856}
4857} // end namespace llvm
4858
4859#undef DEFINE_MDNODE_GET_UNPACK_IMPL
4860#undef DEFINE_MDNODE_GET_UNPACK
4861#undef DEFINE_MDNODE_GET
4862
4863#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:856
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:215
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
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
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:67
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)
uint16_t getDialect() const
Target-specific language dialect for DWARF.
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 source language identity metadata that includes language name,...
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, uint16_t Dialect=0)
DISourceLanguageName(uint16_t Lang, uint32_t Version, uint16_t Dialect=0)
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 forEachRetainedNode(FuncLVT &&FuncLV, FuncLabelT &&FuncLabel, FuncImportedEntityT &&FuncIE, FuncTypeT &&FuncType, FuncGVET &&FuncGVE)
For each retained node, applies one of the given functions depending on the type of a node.
LLVM_ABI 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
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, MDNodeArray 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 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 LLVM_ABI const DIScope * getRawRetainedNodeScope(const MDNode *N)
void cleanupRetainedNodesIf(T &&Pred)
Metadata MDString * Name
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata * ThrownTypes
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:1069
friend class DIAssignID
Definition Metadata.h:1072
LLVM_ABI void replaceOperandWith(unsigned I, Metadata *New)
Replace a specific operand.
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1426
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1577
op_iterator op_end() const
Definition Metadata.h:1420
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1565
bool isUniqued() const
Definition Metadata.h:1251
unsigned getNumOperands() const
Return number of MDNode operands.
Definition Metadata.h:1432
iterator_range< op_iterator > op_range
Definition Metadata.h:1414
LLVM_ABI TempMDNode clone() const
Create a (temporary) clone of this.
Definition Metadata.cpp:683
bool isDistinct() const
Definition Metadata.h:1252
LLVM_ABI void setOperand(unsigned I, Metadata *New)
Set an operand.
op_iterator op_begin() const
Definition Metadata.h:1416
LLVMContext & getContext() const
Definition Metadata.h:1233
LLVM_ABI void dropAllReferences()
Definition Metadata.cpp:923
const MDOperand * op_iterator
Definition Metadata.h:1413
Tracking metadata reference owned by Metadata.
Definition Metadata.h:891
Metadata * get() const
Definition Metadata.h:920
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:1482
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:310
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:573
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:2144
auto cast_or_null(const Y &Val)
Definition Casting.h:714
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
static const DIScope * getScope(const NodeT *N)
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
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)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
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:1947
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
Definition InstrProf.h:147
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition Hashing.h:305
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:860
#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)
DIExpression::FragmentInfo FragmentInfo
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