LLVM 24.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 <type_traits>
38#include <vector>
39
40// Helper macros for defining get() overrides.
41#define DEFINE_MDNODE_GET_UNPACK_IMPL(...) __VA_ARGS__
42#define DEFINE_MDNODE_GET_UNPACK(ARGS) DEFINE_MDNODE_GET_UNPACK_IMPL ARGS
43#define DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS) \
44 static CLASS *getDistinct(LLVMContext &Context, \
45 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
46 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct); \
47 } \
48 static Temp##CLASS getTemporary(LLVMContext &Context, \
49 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
50 return Temp##CLASS( \
51 getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary)); \
52 }
53#define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS) \
54 static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
55 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued); \
56 } \
57 static CLASS *getIfExists(LLVMContext &Context, \
58 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
59 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued, \
60 /* ShouldCreate */ false); \
61 } \
62 DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS)
63
64namespace llvm {
65
66namespace dwarf {
67enum Tag : uint16_t;
68}
69
70/// Wrapper structure that holds source language identity metadata that includes
71/// language name, optional language version, and an optional language dialect.
72///
73/// Some debug-info formats, particularly DWARF, distniguish between
74/// language codes that include the version name and codes that don't.
75/// DISourceLanguageName may hold either of these.
76///
78 /// Language version. The version scheme is language
79 /// dependent.
80 uint32_t Version = 0;
81
82 /// Language name.
83 /// If \ref HasVersion is \c true, then this name
84 /// is version independent (i.e., doesn't include the language
85 /// version in its name).
86 uint16_t Name;
87
88 /// If \c true, then \ref Version is interpretable and \ref Name
89 /// is a version independent name.
90 bool HasVersion;
91
92 /// Optional target-specific language dialect for DWARF that can be used to
93 /// indicate the programming/execution model.
94 ///
95 /// This is intentionally not modeled as a DICompileUnit operand. Code that
96 /// introspects DICompileUnit through getNumOperands()/getOperand(i) will not
97 /// see this field.
98 uint16_t Dialect = 0;
99
100public:
101 bool hasVersionedName() const { return HasVersion; }
102
103 /// Returns a versioned or unversioned language name.
104 uint16_t getName() const { return Name; }
105
106 /// Transitional API for cases where we do not yet support
107 /// versioned source language names. Use \ref getName instead.
108 ///
109 /// FIXME: remove once all callers of this API account for versioned
110 /// names.
113 return Name;
114 }
115
116 /// Returns language version. Only valid for versioned language names.
119 return Version;
120 }
121
122 uint16_t getDialect() const { return Dialect; }
123
124 DISourceLanguageName(uint16_t Lang, uint32_t Version, uint16_t Dialect = 0)
125 : Version(Version), Name(Lang), HasVersion(true), Dialect(Dialect) {}
127 : Version(0), Name(Lang), HasVersion(false), Dialect(Dialect) {}
128};
129
130class DbgVariableRecord;
131
133
134/// Tagged DWARF-like metadata node.
135///
136/// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
137/// defined in llvm/BinaryFormat/Dwarf.h). Called \a DINode because it's
138/// potentially used for non-DWARF output.
139///
140/// Uses the SubclassData16 Metadata slot.
141class DINode : public MDNode {
142 friend class LLVMContextImpl;
143 friend class MDNode;
144
145protected:
146 DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
148 : MDNode(C, ID, Storage, Ops1, Ops2) {
149 assert(Tag < 1u << 16);
151 }
152 ~DINode() = default;
153
154 template <class Ty> Ty *getOperandAs(unsigned I) const {
156 }
157
158 StringRef getStringOperand(unsigned I) const {
159 if (auto *S = getOperandAs<MDString>(I))
160 return S->getString();
161 return StringRef();
162 }
163
165 if (S.empty())
166 return nullptr;
167 return MDString::get(Context, S);
168 }
169
170 /// Allow subclasses to mutate the tag.
171 void setTag(unsigned Tag) { SubclassData16 = Tag; }
172
173public:
174 LLVM_ABI dwarf::Tag getTag() const;
175
176 /// Debug info flags.
177 ///
178 /// The three accessibility flags are mutually exclusive and rolled together
179 /// in the first two bits.
181#define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
182#define DI_FLAG_LARGEST_NEEDED
183#include "llvm/IR/DebugInfoFlags.def"
184 FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic,
185 FlagPtrToMemberRep = FlagSingleInheritance | FlagMultipleInheritance |
186 FlagVirtualInheritance,
187 LLVM_MARK_AS_BITMASK_ENUM(FlagLargest)
188 };
189
190 LLVM_ABI static DIFlags getFlag(StringRef Flag);
191 LLVM_ABI static StringRef getFlagString(DIFlags Flag);
192
193 /// Split up a flags bitfield.
194 ///
195 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
196 /// any remaining (unrecognized) bits.
197 LLVM_ABI static DIFlags splitFlags(DIFlags Flags,
198 SmallVectorImpl<DIFlags> &SplitFlags);
199
200 static bool classof(const Metadata *MD) {
201 switch (MD->getMetadataID()) {
202 default:
203 return false;
204 case GenericDINodeKind:
205 case DISubrangeKind:
206 case DIEnumeratorKind:
207 case DIBasicTypeKind:
208 case DIFixedPointTypeKind:
209 case DIStringTypeKind:
210 case DISubrangeTypeKind:
211 case DIDerivedTypeKind:
212 case DICompositeTypeKind:
213 case DISubroutineTypeKind:
214 case DIFileKind:
215 case DICompileUnitKind:
216 case DISubprogramKind:
217 case DILexicalBlockKind:
218 case DILexicalBlockFileKind:
219 case DINamespaceKind:
220 case DICommonBlockKind:
221 case DITemplateTypeParameterKind:
222 case DITemplateValueParameterKind:
223 case DIGlobalVariableKind:
224 case DILocalVariableKind:
225 case DILabelKind:
226 case DIObjCPropertyKind:
227 case DIImportedEntityKind:
228 case DIModuleKind:
229 case DIGenericSubrangeKind:
230 case DIAssignIDKind:
231 return true;
232 }
233 }
234};
235
236/// Generic tagged DWARF-like metadata node.
237///
238/// An un-specialized DWARF-like metadata node. The first operand is a
239/// (possibly empty) null-separated \a MDString header that contains arbitrary
240/// fields. The remaining operands are \a dwarf_operands(), and are pointers
241/// to other metadata.
242///
243/// Uses the SubclassData32 Metadata slot.
244class GenericDINode : public DINode {
245 friend class LLVMContextImpl;
246 friend class MDNode;
247
248 GenericDINode(LLVMContext &C, StorageType Storage, unsigned Hash,
249 unsigned Tag, ArrayRef<Metadata *> Ops1,
251 : DINode(C, GenericDINodeKind, Storage, Tag, Ops1, Ops2) {
252 setHash(Hash);
253 }
255
256 void setHash(unsigned Hash) { SubclassData32 = Hash; }
257 void recalculateHash();
258
259 static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
261 StorageType Storage, bool ShouldCreate = true) {
262 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
263 DwarfOps, Storage, ShouldCreate);
264 }
265
266 LLVM_ABI static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
267 MDString *Header,
270 bool ShouldCreate = true);
271
272 TempGenericDINode cloneImpl() const {
275 }
276
277public:
278 unsigned getHash() const { return SubclassData32; }
279
280 DEFINE_MDNODE_GET(GenericDINode,
281 (unsigned Tag, StringRef Header,
283 (Tag, Header, DwarfOps))
284 DEFINE_MDNODE_GET(GenericDINode,
285 (unsigned Tag, MDString *Header,
288
289 /// Return a (temporary) clone of this.
290 TempGenericDINode clone() const { return cloneImpl(); }
291
292 LLVM_ABI dwarf::Tag getTag() const;
293 StringRef getHeader() const { return getStringOperand(0); }
295
296 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
297 op_iterator dwarf_op_end() const { return op_end(); }
300 }
301
302 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
303 const MDOperand &getDwarfOperand(unsigned I) const {
304 return getOperand(I + 1);
305 }
306 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
307 replaceOperandWith(I + 1, New);
308 }
309
310 static bool classof(const Metadata *MD) {
311 return MD->getMetadataID() == GenericDINodeKind;
312 }
313};
314
315/// Assignment ID.
316/// Used to link stores (as an attachment) and dbg.assigns (as an operand).
317/// DIAssignID metadata is never uniqued as we compare instances using
318/// referential equality (the instance/address is the ID).
319class DIAssignID : public MDNode {
320 friend class LLVMContextImpl;
321 friend class MDNode;
322
324 : MDNode(C, DIAssignIDKind, Storage, {}) {}
325
326 ~DIAssignID() { dropAllReferences(); }
327
328 LLVM_ABI static DIAssignID *getImpl(LLVMContext &Context, StorageType Storage,
329 bool ShouldCreate = true);
330
331 TempDIAssignID cloneImpl() const { return getTemporary(getContext()); }
332
333public:
334 // This node has no operands to replace.
335 void replaceOperandWith(unsigned I, Metadata *New) = delete;
336
338 return Context.getReplaceableUses()->getAllDbgVariableRecordUsers();
339 }
340
341 static DIAssignID *getDistinct(LLVMContext &Context) {
342 return getImpl(Context, Distinct);
343 }
344 static TempDIAssignID getTemporary(LLVMContext &Context) {
345 return TempDIAssignID(getImpl(Context, Temporary));
346 }
347 // NOTE: Do not define get(LLVMContext&) - see class comment.
348
349 static bool classof(const Metadata *MD) {
350 return MD->getMetadataID() == DIAssignIDKind;
351 }
352};
353
354/// Array subrange.
355class DISubrange : public DINode {
356 friend class LLVMContextImpl;
357 friend class MDNode;
358
360
361 ~DISubrange() = default;
362
363 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, int64_t Count,
365 bool ShouldCreate = true);
366
367 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, Metadata *CountNode,
369 bool ShouldCreate = true);
370
371 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, Metadata *CountNode,
373 Metadata *UpperBound, Metadata *Stride,
375 bool ShouldCreate = true);
376
377 TempDISubrange cloneImpl() const {
378 return getTemporary(getContext(), getRawCountNode(), getRawLowerBound(),
379 getRawUpperBound(), getRawStride());
380 }
381
382public:
383 DEFINE_MDNODE_GET(DISubrange, (int64_t Count, int64_t LowerBound = 0),
384 (Count, LowerBound))
385
386 DEFINE_MDNODE_GET(DISubrange, (Metadata * CountNode, int64_t LowerBound = 0),
388
389 DEFINE_MDNODE_GET(DISubrange,
391 Metadata *UpperBound, Metadata *Stride),
392 (CountNode, LowerBound, UpperBound, Stride))
393
394 TempDISubrange clone() const { return cloneImpl(); }
395
396 Metadata *getRawCountNode() const { return getOperand(0).get(); }
397
398 Metadata *getRawLowerBound() const { return getOperand(1).get(); }
399
400 Metadata *getRawUpperBound() const { return getOperand(2).get(); }
401
402 Metadata *getRawStride() const { return getOperand(3).get(); }
403
404 typedef PointerUnion<ConstantInt *, DIVariable *, DIExpression *> BoundType;
405
406 LLVM_ABI BoundType getCount() const;
407
408 LLVM_ABI BoundType getLowerBound() const;
409
410 LLVM_ABI BoundType getUpperBound() const;
411
412 LLVM_ABI BoundType getStride() const;
413
414 static bool classof(const Metadata *MD) {
415 return MD->getMetadataID() == DISubrangeKind;
416 }
417};
418
419class DIGenericSubrange : public DINode {
420 friend class LLVMContextImpl;
421 friend class MDNode;
422
423 DIGenericSubrange(LLVMContext &C, StorageType Storage,
425
426 ~DIGenericSubrange() = default;
427
428 LLVM_ABI static DIGenericSubrange *
429 getImpl(LLVMContext &Context, Metadata *CountNode, Metadata *LowerBound,
430 Metadata *UpperBound, Metadata *Stride, StorageType Storage,
431 bool ShouldCreate = true);
432
433 TempDIGenericSubrange cloneImpl() const {
436 }
437
438public:
439 DEFINE_MDNODE_GET(DIGenericSubrange,
440 (Metadata * CountNode, Metadata *LowerBound,
441 Metadata *UpperBound, Metadata *Stride),
442 (CountNode, LowerBound, UpperBound, Stride))
443
444 TempDIGenericSubrange clone() const { return cloneImpl(); }
445
446 Metadata *getRawCountNode() const { return getOperand(0).get(); }
447 Metadata *getRawLowerBound() const { return getOperand(1).get(); }
448 Metadata *getRawUpperBound() const { return getOperand(2).get(); }
449 Metadata *getRawStride() const { return getOperand(3).get(); }
450
452
457
458 static bool classof(const Metadata *MD) {
459 return MD->getMetadataID() == DIGenericSubrangeKind;
460 }
461};
462
463/// Enumeration value.
464///
465/// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
466/// longer creates a type cycle.
467class DIEnumerator : public DINode {
468 friend class LLVMContextImpl;
469 friend class MDNode;
470
471 APInt Value;
472 LLVM_ABI DIEnumerator(LLVMContext &C, StorageType Storage, const APInt &Value,
474 DIEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
476 : DIEnumerator(C, Storage, APInt(64, Value, !IsUnsigned), IsUnsigned,
477 Ops) {}
478 ~DIEnumerator() = default;
479
480 static DIEnumerator *getImpl(LLVMContext &Context, const APInt &Value,
482 StorageType Storage, bool ShouldCreate = true) {
483 return getImpl(Context, Value, IsUnsigned,
484 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
485 }
486 LLVM_ABI static DIEnumerator *getImpl(LLVMContext &Context,
487 const APInt &Value, bool IsUnsigned,
488 MDString *Name, StorageType Storage,
489 bool ShouldCreate = true);
490
491 TempDIEnumerator cloneImpl() const {
493 }
494
495public:
496 DEFINE_MDNODE_GET(DIEnumerator,
497 (int64_t Value, bool IsUnsigned, StringRef Name),
498 (APInt(64, Value, !IsUnsigned), IsUnsigned, Name))
499 DEFINE_MDNODE_GET(DIEnumerator,
500 (int64_t Value, bool IsUnsigned, MDString *Name),
501 (APInt(64, Value, !IsUnsigned), IsUnsigned, Name))
502 DEFINE_MDNODE_GET(DIEnumerator,
503 (APInt Value, bool IsUnsigned, StringRef Name),
504 (Value, IsUnsigned, Name))
505 DEFINE_MDNODE_GET(DIEnumerator,
506 (APInt Value, bool IsUnsigned, MDString *Name),
507 (Value, IsUnsigned, Name))
508
509 TempDIEnumerator clone() const { return cloneImpl(); }
510
511 const APInt &getValue() const { return Value; }
512 bool isUnsigned() const { return SubclassData32; }
513 StringRef getName() const { return getStringOperand(0); }
514
516
517 static bool classof(const Metadata *MD) {
518 return MD->getMetadataID() == DIEnumeratorKind;
519 }
520};
521
522/// Base class for scope-like contexts.
523///
524/// Base class for lexical scopes and types (which are also declaration
525/// contexts).
526///
527/// TODO: Separate the concepts of declaration contexts and lexical scopes.
528class DIScope : public DINode {
529protected:
530 DIScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
532 : DINode(C, ID, Storage, Tag, Ops) {}
533 ~DIScope() = default;
534
535public:
537
538 inline StringRef getFilename() const;
539 inline StringRef getDirectory() const;
540 inline std::optional<StringRef> getSource() const;
541
542 LLVM_ABI StringRef getName() const;
543 LLVM_ABI DIScope *getScope() const;
544
545 /// Return the raw underlying file.
546 ///
547 /// A \a DIFile is a \a DIScope, but it doesn't point at a separate file (it
548 /// \em is the file). If \c this is an \a DIFile, we need to return \c this.
549 /// Otherwise, return the first operand, which is where all other subclasses
550 /// store their file pointer.
552 return isa<DIFile>(this) ? const_cast<DIScope *>(this)
553 : static_cast<Metadata *>(getOperand(0));
554 }
555
556 static bool classof(const Metadata *MD) {
557 switch (MD->getMetadataID()) {
558 default:
559 return false;
560 case DIBasicTypeKind:
561 case DIFixedPointTypeKind:
562 case DIStringTypeKind:
563 case DISubrangeTypeKind:
564 case DIDerivedTypeKind:
565 case DICompositeTypeKind:
566 case DISubroutineTypeKind:
567 case DIFileKind:
568 case DICompileUnitKind:
569 case DISubprogramKind:
570 case DILexicalBlockKind:
571 case DILexicalBlockFileKind:
572 case DINamespaceKind:
573 case DICommonBlockKind:
574 case DIModuleKind:
575 return true;
576 }
577 }
578};
579
580/// File.
581///
582/// TODO: Merge with directory/file node (including users).
583/// TODO: Canonicalize paths on creation.
584class DIFile : public DIScope {
585 friend class LLVMContextImpl;
586 friend class MDNode;
587
588public:
589 /// Which algorithm (e.g. MD5) a checksum was generated with.
590 ///
591 /// The encoding is explicit because it is used directly in Bitcode. The
592 /// value 0 is reserved to indicate the absence of a checksum in Bitcode.
594 // The first variant was originally CSK_None, encoded as 0. The new
595 // internal representation removes the need for this by wrapping the
596 // ChecksumInfo in an Optional, but to preserve Bitcode compatibility the 0
597 // encoding is reserved.
601 CSK_Last = CSK_SHA256 // Should be last enumeration.
602 };
603
604 /// A single checksum, represented by a \a Kind and a \a Value (a string).
605 template <typename T> struct ChecksumInfo {
606 /// The kind of checksum which \a Value encodes.
608 /// The string value of the checksum.
610
612 ~ChecksumInfo() = default;
613 bool operator==(const ChecksumInfo<T> &X) const {
614 return Kind == X.Kind && Value == X.Value;
615 }
616 bool operator!=(const ChecksumInfo<T> &X) const { return !(*this == X); }
617 StringRef getKindAsString() const { return getChecksumKindAsString(Kind); }
618 };
619
620private:
621 std::optional<ChecksumInfo<MDString *>> Checksum;
622 /// An optional source. A nullptr means none.
624
626 std::optional<ChecksumInfo<MDString *>> CS, MDString *Src,
628 ~DIFile() = default;
629
630 static DIFile *getImpl(LLVMContext &Context, StringRef Filename,
632 std::optional<ChecksumInfo<StringRef>> CS,
633 std::optional<StringRef> Source, StorageType Storage,
634 bool ShouldCreate = true) {
635 std::optional<ChecksumInfo<MDString *>> MDChecksum;
636 if (CS)
637 MDChecksum.emplace(CS->Kind, getCanonicalMDString(Context, CS->Value));
638 return getImpl(Context, getCanonicalMDString(Context, Filename),
639 getCanonicalMDString(Context, Directory), MDChecksum,
640 Source ? MDString::get(Context, *Source) : nullptr, Storage,
641 ShouldCreate);
642 }
643 LLVM_ABI static DIFile *getImpl(LLVMContext &Context, MDString *Filename,
644 MDString *Directory,
645 std::optional<ChecksumInfo<MDString *>> CS,
646 MDString *Source, StorageType Storage,
647 bool ShouldCreate = true);
648
649 TempDIFile cloneImpl() const {
651 getChecksum(), getSource());
652 }
653
654public:
657 std::optional<ChecksumInfo<StringRef>> CS = std::nullopt,
658 std::optional<StringRef> Source = std::nullopt),
659 (Filename, Directory, CS, Source))
660 DEFINE_MDNODE_GET(DIFile,
662 std::optional<ChecksumInfo<MDString *>> CS = std::nullopt,
663 MDString *Source = nullptr),
664 (Filename, Directory, CS, Source))
665
666 TempDIFile clone() const { return cloneImpl(); }
667
668 StringRef getFilename() const { return getStringOperand(0); }
669 StringRef getDirectory() const { return getStringOperand(1); }
670 std::optional<ChecksumInfo<StringRef>> getChecksum() const {
671 std::optional<ChecksumInfo<StringRef>> StringRefChecksum;
672 if (Checksum)
673 StringRefChecksum.emplace(Checksum->Kind, Checksum->Value->getString());
674 return StringRefChecksum;
675 }
676 std::optional<StringRef> getSource() const {
677 return Source ? std::optional<StringRef>(Source->getString())
678 : std::nullopt;
679 }
680
681 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
682 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
683 std::optional<ChecksumInfo<MDString *>> getRawChecksum() const {
684 return Checksum;
685 }
686 MDString *getRawSource() const { return Source; }
687
688 LLVM_ABI static StringRef getChecksumKindAsString(ChecksumKind CSKind);
689 LLVM_ABI static std::optional<ChecksumKind>
690 getChecksumKind(StringRef CSKindStr);
691
692 static bool classof(const Metadata *MD) {
693 return MD->getMetadataID() == DIFileKind;
694 }
695};
696
698 if (auto *F = getFile())
699 return F->getFilename();
700 return "";
701}
702
704 if (auto *F = getFile())
705 return F->getDirectory();
706 return "";
707}
708
709std::optional<StringRef> DIScope::getSource() const {
710 if (auto *F = getFile())
711 return F->getSource();
712 return std::nullopt;
713}
714
715/// Base class for types.
716///
717/// TODO: Remove the hardcoded name and context, since many types don't use
718/// them.
719/// TODO: Split up flags.
720///
721/// Uses the SubclassData32 Metadata slot.
722class DIType : public DIScope {
723 unsigned Line;
724 DIFlags Flags;
725 uint32_t NumExtraInhabitants;
726
727protected:
728 static constexpr unsigned N_OPERANDS = 5;
729
730 DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
731 unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants,
733 : DIScope(C, ID, Storage, Tag, Ops) {
734 init(Line, AlignInBits, NumExtraInhabitants, Flags);
735 }
736 ~DIType() = default;
737
738 void init(unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants,
739 DIFlags Flags) {
740 this->Line = Line;
741 this->Flags = Flags;
742 this->SubclassData32 = AlignInBits;
743 this->NumExtraInhabitants = NumExtraInhabitants;
744 }
745
746 /// Change fields in place.
747 void mutate(unsigned Tag, unsigned Line, uint32_t AlignInBits,
748 uint32_t NumExtraInhabitants, DIFlags Flags) {
749 assert(isDistinct() && "Only distinct nodes can mutate");
750 setTag(Tag);
751 init(Line, AlignInBits, NumExtraInhabitants, Flags);
752 }
753
754public:
755 TempDIType clone() const {
756 return TempDIType(cast<DIType>(MDNode::clone().release()));
757 }
758
759 unsigned getLine() const { return Line; }
761 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
762 uint32_t getNumExtraInhabitants() const { return NumExtraInhabitants; }
763 DIFlags getFlags() const { return Flags; }
764
766 StringRef getName() const { return getStringOperand(2); }
767
768 Metadata *getRawScope() const { return getOperand(1); }
770
771 Metadata *getRawSizeInBits() const { return getOperand(3); }
774 if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(MD->getValue()))
775 return CI->getZExtValue();
776 }
777 return 0;
778 }
779
780 Metadata *getRawOffsetInBits() const { return getOperand(4); }
783 if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(MD->getValue()))
784 return CI->getZExtValue();
785 }
786 return 0;
787 }
788
789 /// Returns a new temporary DIType with updated Flags
790 TempDIType cloneWithFlags(DIFlags NewFlags) const {
791 auto NewTy = clone();
792 NewTy->Flags = NewFlags;
793 return NewTy;
794 }
795
796 bool isPrivate() const {
797 return (getFlags() & FlagAccessibility) == FlagPrivate;
798 }
799 bool isProtected() const {
800 return (getFlags() & FlagAccessibility) == FlagProtected;
801 }
802 bool isPublic() const {
803 return (getFlags() & FlagAccessibility) == FlagPublic;
804 }
805 bool isForwardDecl() const { return getFlags() & FlagFwdDecl; }
806 bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; }
807 bool isVirtual() const { return getFlags() & FlagVirtual; }
808 bool isArtificial() const { return getFlags() & FlagArtificial; }
809 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
810 bool isObjcClassComplete() const {
811 return getFlags() & FlagObjcClassComplete;
812 }
813 bool isVector() const { return getFlags() & FlagVector; }
814 bool isBitField() const { return getFlags() & FlagBitField; }
815 bool isStaticMember() const { return getFlags() & FlagStaticMember; }
816 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
817 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
818 bool isTypePassByValue() const { return getFlags() & FlagTypePassByValue; }
820 return getFlags() & FlagTypePassByReference;
821 }
822 bool isBigEndian() const { return getFlags() & FlagBigEndian; }
823 bool isLittleEndian() const { return getFlags() & FlagLittleEndian; }
824 bool getExportSymbols() const { return getFlags() & FlagExportSymbols; }
825
826 static bool classof(const Metadata *MD) {
827 switch (MD->getMetadataID()) {
828 default:
829 return false;
830 case DIBasicTypeKind:
831 case DIFixedPointTypeKind:
832 case DIStringTypeKind:
833 case DISubrangeTypeKind:
834 case DIDerivedTypeKind:
835 case DICompositeTypeKind:
836 case DISubroutineTypeKind:
837 return true;
838 }
839 }
840};
841
842/// Basic type, like 'int' or 'float'.
843///
844/// TODO: Split out DW_TAG_unspecified_type.
845/// TODO: Drop unused accessors.
846class DIBasicType : public DIType {
847 friend class LLVMContextImpl;
848 friend class MDNode;
849
850 unsigned Encoding;
851 /// Describes the number of bits used by the value of the object. Non-zero
852 /// when the value of an object does not fully occupy the storage size
853 /// specified by SizeInBits.
854 uint32_t DataSizeInBits;
855
856protected:
858 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
859 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
861 : DIType(C, DIBasicTypeKind, Storage, Tag, LineNo, AlignInBits,
863 Encoding(Encoding), DataSizeInBits(DataSizeInBits) {}
864 DIBasicType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
865 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
866 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
869 Flags, Ops),
870 Encoding(Encoding), DataSizeInBits(DataSizeInBits) {}
871 ~DIBasicType() = default;
872
873 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
874 StringRef Name, DIFile *File, unsigned LineNo,
876 uint32_t AlignInBits, unsigned Encoding,
878 uint32_t DataSizeInBits, DIFlags Flags,
879 StorageType Storage, bool ShouldCreate = true) {
880 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
881 LineNo, Scope, SizeInBits, AlignInBits, Encoding,
882 NumExtraInhabitants, DataSizeInBits, Flags, Storage,
883 ShouldCreate);
884 }
885 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
886 MDString *Name, DIFile *File, unsigned LineNo,
888 uint32_t AlignInBits, unsigned Encoding,
890 uint32_t DataSizeInBits, DIFlags Flags,
891 StorageType Storage, bool ShouldCreate = true) {
892 auto *SizeInBitsNode = ConstantAsMetadata::get(
893 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
894 return getImpl(Context, Tag, Name, File, LineNo, Scope, SizeInBitsNode,
895 AlignInBits, Encoding, NumExtraInhabitants, DataSizeInBits,
896 Flags, Storage, ShouldCreate);
897 }
898 LLVM_ABI static DIBasicType *
899 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
900 unsigned LineNo, Metadata *Scope, Metadata *SizeInBits,
903 bool ShouldCreate = true);
904
905 TempDIBasicType cloneImpl() const {
906 return getTemporary(
910 }
911
912public:
914 (Tag, Name, nullptr, 0, nullptr, 0, 0, 0, 0, 0, FlagZero))
917 (Tag, Name, nullptr, 0, nullptr, SizeInBits, 0, 0, 0, 0,
918 FlagZero))
920 (unsigned Tag, MDString *Name, uint64_t SizeInBits),
921 (Tag, Name, nullptr, 0, nullptr, SizeInBits, 0, 0, 0, 0,
922 FlagZero))
925 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
926 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
927 Encoding, 0, 0, Flags))
929 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
930 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
931 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
932 Encoding, 0, 0, Flags))
935 uint32_t AlignInBits, unsigned Encoding,
937 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
941 uint32_t AlignInBits, unsigned Encoding,
942 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
943 DIFlags Flags),
944 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
945 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
949 uint32_t AlignInBits, unsigned Encoding,
953 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
955 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
956 uint32_t AlignInBits, unsigned Encoding,
957 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
958 DIFlags Flags),
959 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
960 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
963 uint32_t AlignInBits, unsigned Encoding,
966 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
967 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
969 (unsigned Tag, MDString *Name, Metadata *File,
971 uint32_t AlignInBits, unsigned Encoding,
972 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
973 DIFlags Flags),
975 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
976
977 TempDIBasicType clone() const { return cloneImpl(); }
978
979 unsigned getEncoding() const { return Encoding; }
980
981 uint32_t getDataSizeInBits() const { return DataSizeInBits; }
982
983 enum class Signedness { Signed, Unsigned };
984
985 /// Return the signedness of this type, or std::nullopt if this type is
986 /// neither signed nor unsigned.
987 LLVM_ABI std::optional<Signedness> getSignedness() const;
988
989 static bool classof(const Metadata *MD) {
990 return MD->getMetadataID() == DIBasicTypeKind ||
991 MD->getMetadataID() == DIFixedPointTypeKind;
992 }
993};
994
995/// Fixed-point type.
996class DIFixedPointType : public DIBasicType {
997 friend class LLVMContextImpl;
998 friend class MDNode;
999
1000 // Actually FixedPointKind.
1001 unsigned Kind;
1002 // Used for binary and decimal.
1003 int Factor;
1004 // Used for rational.
1005 APInt Numerator;
1006 APInt Denominator;
1007
1008 DIFixedPointType(LLVMContext &C, StorageType Storage, unsigned Tag,
1009 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
1010 DIFlags Flags, unsigned Kind, int Factor,
1012 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, LineNo, AlignInBits,
1013 Encoding, 0, 0, Flags, Ops),
1014 Kind(Kind), Factor(Factor) {
1015 assert(Kind == FixedPointBinary || Kind == FixedPointDecimal);
1016 }
1018 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
1019 DIFlags Flags, unsigned Kind, APInt Numerator,
1021 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, LineNo, AlignInBits,
1022 Encoding, 0, 0, Flags, Ops),
1023 Kind(Kind), Factor(0), Numerator(Numerator), Denominator(Denominator) {
1024 assert(Kind == FixedPointRational);
1025 }
1026 DIFixedPointType(LLVMContext &C, StorageType Storage, unsigned Tag,
1027 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
1028 DIFlags Flags, unsigned Kind, int Factor, APInt Numerator,
1030 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, LineNo, AlignInBits,
1031 Encoding, 0, 0, Flags, Ops),
1032 Kind(Kind), Factor(Factor), Numerator(Numerator),
1034 ~DIFixedPointType() = default;
1035
1036 static DIFixedPointType *
1037 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1038 unsigned LineNo, DIScope *Scope, uint64_t SizeInBits,
1039 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind,
1040 int Factor, APInt Numerator, APInt Denominator, StorageType Storage,
1041 bool ShouldCreate = true) {
1042 auto *SizeInBitsNode = ConstantAsMetadata::get(
1043 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1044 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1045 LineNo, Scope, SizeInBitsNode, AlignInBits, Encoding, Flags,
1046 Kind, Factor, Numerator, Denominator, Storage, ShouldCreate);
1047 }
1048 static DIFixedPointType *
1049 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1050 unsigned LineNo, DIScope *Scope, Metadata *SizeInBits,
1051 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind,
1052 int Factor, APInt Numerator, APInt Denominator, StorageType Storage,
1053 bool ShouldCreate = true) {
1054 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1056 Kind, Factor, Numerator, Denominator, Storage, ShouldCreate);
1057 }
1058 static DIFixedPointType *
1059 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, DIFile *File,
1060 unsigned LineNo, DIScope *Scope, uint64_t SizeInBits,
1061 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind,
1062 int Factor, APInt Numerator, APInt Denominator, StorageType Storage,
1063 bool ShouldCreate = true) {
1064 auto *SizeInBitsNode = ConstantAsMetadata::get(
1065 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1066 return getImpl(Context, Tag, Name, File, LineNo, Scope, SizeInBitsNode,
1067 AlignInBits, Encoding, Flags, Kind, Factor, Numerator,
1068 Denominator, Storage, ShouldCreate);
1069 }
1070 LLVM_ABI static DIFixedPointType *
1071 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1073 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind,
1074 int Factor, APInt Numerator, APInt Denominator, StorageType Storage,
1075 bool ShouldCreate = true);
1076
1077 TempDIFixedPointType cloneImpl() const {
1080 getAlignInBits(), getEncoding(), getFlags(), Kind,
1081 Factor, Numerator, Denominator);
1082 }
1083
1084public:
1085 enum FixedPointKind : unsigned {
1086 /// Scale factor 2^Factor.
1088 /// Scale factor 10^Factor.
1090 /// Arbitrary rational scale factor.
1093 };
1094
1095 LLVM_ABI static std::optional<FixedPointKind>
1097 LLVM_ABI static const char *fixedPointKindString(FixedPointKind);
1098
1099 DEFINE_MDNODE_GET(DIFixedPointType,
1100 (unsigned Tag, MDString *Name, DIFile *File,
1103 unsigned Kind, int Factor, APInt Numerator,
1104 APInt Denominator),
1106 Encoding, Flags, Kind, Factor, Numerator, Denominator))
1107 DEFINE_MDNODE_GET(DIFixedPointType,
1111 unsigned Kind, int Factor, APInt Numerator,
1112 APInt Denominator),
1114 Encoding, Flags, Kind, Factor, Numerator, Denominator))
1115 DEFINE_MDNODE_GET(DIFixedPointType,
1116 (unsigned Tag, MDString *Name, Metadata *File,
1119 unsigned Kind, int Factor, APInt Numerator,
1120 APInt Denominator),
1122 Encoding, Flags, Kind, Factor, Numerator, Denominator))
1123
1124 TempDIFixedPointType clone() const { return cloneImpl(); }
1125
1126 bool isBinary() const { return Kind == FixedPointBinary; }
1127 bool isDecimal() const { return Kind == FixedPointDecimal; }
1128 bool isRational() const { return Kind == FixedPointRational; }
1129
1130 LLVM_ABI bool isSigned() const;
1131
1132 FixedPointKind getKind() const { return static_cast<FixedPointKind>(Kind); }
1133
1134 int getFactorRaw() const { return Factor; }
1135 int getFactor() const {
1136 assert(Kind == FixedPointBinary || Kind == FixedPointDecimal);
1137 return Factor;
1138 }
1139
1140 const APInt &getNumeratorRaw() const { return Numerator; }
1141 const APInt &getNumerator() const {
1142 assert(Kind == FixedPointRational);
1143 return Numerator;
1144 }
1145
1146 const APInt &getDenominatorRaw() const { return Denominator; }
1147 const APInt &getDenominator() const {
1148 assert(Kind == FixedPointRational);
1149 return Denominator;
1150 }
1151
1152 static bool classof(const Metadata *MD) {
1153 return MD->getMetadataID() == DIFixedPointTypeKind;
1154 }
1155};
1156
1157/// String type, Fortran CHARACTER(n)
1158class DIStringType : public DIType {
1159 friend class LLVMContextImpl;
1160 friend class MDNode;
1161
1162 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1163
1164 unsigned Encoding;
1165
1166 DIStringType(LLVMContext &C, StorageType Storage, unsigned Tag,
1167 uint32_t AlignInBits, unsigned Encoding,
1169 : DIType(C, DIStringTypeKind, Storage, Tag, 0, AlignInBits, 0, FlagZero,
1170 Ops),
1171 Encoding(Encoding) {}
1172 ~DIStringType() = default;
1173
1174 static DIStringType *getImpl(LLVMContext &Context, unsigned Tag,
1176 Metadata *StrLenExp, Metadata *StrLocationExp,
1178 unsigned Encoding, StorageType Storage,
1179 bool ShouldCreate = true) {
1180 auto *SizeInBitsNode = ConstantAsMetadata::get(
1181 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1182 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
1183 StringLength, StrLenExp, StrLocationExp, SizeInBitsNode,
1184 AlignInBits, Encoding, Storage, ShouldCreate);
1185 }
1186 static DIStringType *getImpl(LLVMContext &Context, unsigned Tag,
1187 MDString *Name, Metadata *StringLength,
1188 Metadata *StrLenExp, Metadata *StrLocationExp,
1190 unsigned Encoding, StorageType Storage,
1191 bool ShouldCreate = true) {
1192 auto *SizeInBitsNode = ConstantAsMetadata::get(
1193 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1194 return getImpl(Context, Tag, Name, StringLength, StrLenExp, StrLocationExp,
1195 SizeInBitsNode, AlignInBits, Encoding, Storage,
1196 ShouldCreate);
1197 }
1198 LLVM_ABI static DIStringType *
1199 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name,
1200 Metadata *StringLength, Metadata *StrLenExp, Metadata *StrLocationExp,
1201 Metadata *SizeInBits, uint32_t AlignInBits, unsigned Encoding,
1202 StorageType Storage, bool ShouldCreate = true);
1203
1204 TempDIStringType cloneImpl() const {
1209 }
1210
1211public:
1212 DEFINE_MDNODE_GET(DIStringType,
1213 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
1215 (Tag, Name, nullptr, nullptr, nullptr, SizeInBits,
1216 AlignInBits, 0))
1217 DEFINE_MDNODE_GET(DIStringType,
1221 unsigned Encoding),
1224 DEFINE_MDNODE_GET(DIStringType,
1225 (unsigned Tag, StringRef Name, Metadata *StringLength,
1228 unsigned Encoding),
1231 DEFINE_MDNODE_GET(DIStringType,
1235 unsigned Encoding),
1238
1239 TempDIStringType clone() const { return cloneImpl(); }
1240
1241 static bool classof(const Metadata *MD) {
1242 return MD->getMetadataID() == DIStringTypeKind;
1243 }
1244
1248
1252
1256
1257 unsigned getEncoding() const { return Encoding; }
1258
1259 Metadata *getRawStringLength() const { return getOperand(MY_FIRST_OPERAND); }
1260
1262 return getOperand(MY_FIRST_OPERAND + 1);
1263 }
1264
1266 return getOperand(MY_FIRST_OPERAND + 2);
1267 }
1268};
1269
1270/// Derived types.
1271///
1272/// This includes qualified types, pointers, references, friends, typedefs, and
1273/// class members.
1274///
1275/// TODO: Split out members (inheritance, fields, methods, etc.).
1276class DIDerivedType : public DIType {
1277public:
1278 /// Pointer authentication (__ptrauth) metadata.
1280 // RawData layout:
1281 // - Bits 0..3: Key
1282 // - Bit 4: IsAddressDiscriminated
1283 // - Bits 5..20: ExtraDiscriminator
1284 // - Bit 21: IsaPointer
1285 // - Bit 22: AuthenticatesNullValues
1286 unsigned RawData;
1287
1288 PtrAuthData(unsigned FromRawData) : RawData(FromRawData) {}
1289 PtrAuthData(unsigned Key, bool IsDiscr, unsigned Discriminator,
1290 bool IsaPointer, bool AuthenticatesNullValues) {
1291 assert(Key < 16);
1292 assert(Discriminator <= 0xffff);
1293 RawData = (Key << 0) | (IsDiscr ? (1 << 4) : 0) | (Discriminator << 5) |
1294 (IsaPointer ? (1 << 21) : 0) |
1295 (AuthenticatesNullValues ? (1 << 22) : 0);
1296 }
1297
1298 unsigned key() { return (RawData >> 0) & 0b1111; }
1299 bool isAddressDiscriminated() { return (RawData >> 4) & 1; }
1300 unsigned extraDiscriminator() { return (RawData >> 5) & 0xffff; }
1301 bool isaPointer() { return (RawData >> 21) & 1; }
1302 bool authenticatesNullValues() { return (RawData >> 22) & 1; }
1303 };
1304
1305private:
1306 friend class LLVMContextImpl;
1307 friend class MDNode;
1308
1309 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1310
1311 /// The DWARF address space of the memory pointed to or referenced by a
1312 /// pointer or reference type respectively.
1313 std::optional<unsigned> DWARFAddressSpace;
1314
1315 DIDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
1316 unsigned Line, uint32_t AlignInBits,
1317 std::optional<unsigned> DWARFAddressSpace,
1318 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1320 : DIType(C, DIDerivedTypeKind, Storage, Tag, Line, AlignInBits, 0, Flags,
1321 Ops),
1322 DWARFAddressSpace(DWARFAddressSpace) {
1323 if (PtrAuthData)
1325 }
1326 ~DIDerivedType() = default;
1327 static DIDerivedType *
1328 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1329 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1331 std::optional<unsigned> DWARFAddressSpace,
1332 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1334 bool ShouldCreate = true) {
1335 auto *SizeInBitsNode = ConstantAsMetadata::get(
1336 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1337 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1338 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1339 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1340 Line, Scope, BaseType, SizeInBitsNode, AlignInBits,
1341 OffsetInBitsNode, DWARFAddressSpace, PtrAuthData, Flags,
1342 ExtraData, Annotations.get(), Storage, ShouldCreate);
1343 }
1344 static DIDerivedType *
1345 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, DIFile *File,
1346 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1348 std::optional<unsigned> DWARFAddressSpace,
1349 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1351 bool ShouldCreate = true) {
1352 auto *SizeInBitsNode = ConstantAsMetadata::get(
1353 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1354 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1355 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1356 return getImpl(Context, Tag, Name, File, Line, Scope, BaseType,
1357 SizeInBitsNode, AlignInBits, OffsetInBitsNode,
1359 Annotations.get(), Storage, ShouldCreate);
1360 }
1361 static DIDerivedType *
1362 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1365 std::optional<unsigned> DWARFAddressSpace,
1366 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1368 bool ShouldCreate = true) {
1369 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1371 DWARFAddressSpace, PtrAuthData, Flags, ExtraData,
1372 Annotations.get(), Storage, ShouldCreate);
1373 }
1374 LLVM_ABI static DIDerivedType *
1375 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1376 unsigned Line, Metadata *Scope, Metadata *BaseType,
1378 std::optional<unsigned> DWARFAddressSpace,
1379 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1381 bool ShouldCreate = true);
1382
1383 TempDIDerivedType cloneImpl() const {
1384 return getTemporary(
1387 getRawOffsetInBits(), getDWARFAddressSpace(), getPtrAuthData(),
1389 }
1390
1391public:
1392 DEFINE_MDNODE_GET(DIDerivedType,
1393 (unsigned Tag, MDString *Name, Metadata *File,
1394 unsigned Line, Metadata *Scope, Metadata *BaseType,
1397 std::optional<unsigned> DWARFAddressSpace,
1398 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1399 Metadata *ExtraData = nullptr,
1400 Metadata *Annotations = nullptr),
1402 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1404 DEFINE_MDNODE_GET(DIDerivedType,
1405 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1408 std::optional<unsigned> DWARFAddressSpace,
1409 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1411 DINodeArray Annotations = nullptr),
1413 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1415 DEFINE_MDNODE_GET(DIDerivedType,
1416 (unsigned Tag, MDString *Name, DIFile *File, unsigned Line,
1419 std::optional<unsigned> DWARFAddressSpace,
1420 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1421 Metadata *ExtraData = nullptr,
1422 DINodeArray Annotations = nullptr),
1424 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1426 DEFINE_MDNODE_GET(DIDerivedType,
1427 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1430 std::optional<unsigned> DWARFAddressSpace,
1431 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1432 Metadata *ExtraData = nullptr,
1433 DINodeArray Annotations = nullptr),
1435 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1437
1438 TempDIDerivedType clone() const { return cloneImpl(); }
1439
1440 /// Get the base type this is derived from.
1441 DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); }
1442 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1443
1444 /// \returns The DWARF address space of the memory pointed to or referenced by
1445 /// a pointer or reference type respectively.
1446 std::optional<unsigned> getDWARFAddressSpace() const {
1447 return DWARFAddressSpace;
1448 }
1449
1450 LLVM_ABI std::optional<PtrAuthData> getPtrAuthData() const;
1451
1452 /// Get extra data associated with this derived type.
1453 ///
1454 /// Class type for pointer-to-members, objective-c property node for ivars,
1455 /// global constant wrapper for static members, virtual base pointer offset
1456 /// for inheritance, a tuple of template parameters for template aliases,
1457 /// discriminant for a variant, or storage offset for a bit field.
1458 ///
1459 /// TODO: Separate out types that need this extra operand: pointer-to-member
1460 /// types and member fields (static members and ivars).
1462 Metadata *getRawExtraData() const { return getOperand(MY_FIRST_OPERAND + 1); }
1463
1464 /// Get the template parameters from a template alias.
1465 DITemplateParameterArray getTemplateParams() const {
1467 }
1468
1469 /// Get annotations associated with this derived type.
1470 DINodeArray getAnnotations() const {
1472 }
1474 return getOperand(MY_FIRST_OPERAND + 2);
1475 }
1476
1477 /// Get casted version of extra data.
1478 /// @{
1479 LLVM_ABI DIType *getClassType() const;
1480
1484
1486
1488
1489 LLVM_ABI Constant *getConstant() const;
1490
1492 /// @}
1493
1494 static bool classof(const Metadata *MD) {
1495 return MD->getMetadataID() == DIDerivedTypeKind;
1496 }
1497};
1498
1501 return Lhs.RawData == Rhs.RawData;
1502}
1503
1506 return !(Lhs == Rhs);
1507}
1508
1509/// Subrange type. This is somewhat similar to DISubrange, but it
1510/// is also a DIType.
1511class DISubrangeType : public DIType {
1512public:
1514 DIDerivedType *>
1516
1517private:
1518 friend class LLVMContextImpl;
1519 friend class MDNode;
1520
1521 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1522
1523 DISubrangeType(LLVMContext &C, StorageType Storage, unsigned Line,
1525
1526 ~DISubrangeType() = default;
1527
1528 static DISubrangeType *
1529 getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
1533 StorageType Storage, bool ShouldCreate = true) {
1534 auto *SizeInBitsNode = ConstantAsMetadata::get(
1535 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1536 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1537 Scope, SizeInBitsNode, AlignInBits, Flags, BaseType,
1538 LowerBound, UpperBound, Stride, Bias, Storage, ShouldCreate);
1539 }
1540
1541 LLVM_ABI static DISubrangeType *
1542 getImpl(LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
1544 DIFlags Flags, Metadata *BaseType, Metadata *LowerBound,
1546 StorageType Storage, bool ShouldCreate = true);
1547
1548 TempDISubrangeType cloneImpl() const {
1553 }
1554
1555 LLVM_ABI BoundType convertRawToBound(Metadata *IN) const;
1556
1557public:
1558 DEFINE_MDNODE_GET(DISubrangeType,
1559 (MDString * Name, Metadata *File, unsigned Line,
1566 DEFINE_MDNODE_GET(DISubrangeType,
1573
1574 TempDISubrangeType clone() const { return cloneImpl(); }
1575
1576 /// Get the base type this is derived from.
1578 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1579
1581 return getOperand(MY_FIRST_OPERAND + 1).get();
1582 }
1583
1585 return getOperand(MY_FIRST_OPERAND + 2).get();
1586 }
1587
1589 return getOperand(MY_FIRST_OPERAND + 3).get();
1590 }
1591
1593 return getOperand(MY_FIRST_OPERAND + 4).get();
1594 }
1595
1597 return convertRawToBound(getRawLowerBound());
1598 }
1599
1601 return convertRawToBound(getRawUpperBound());
1602 }
1603
1604 BoundType getStride() const { return convertRawToBound(getRawStride()); }
1605
1606 BoundType getBias() const { return convertRawToBound(getRawBias()); }
1607
1608 static bool classof(const Metadata *MD) {
1609 return MD->getMetadataID() == DISubrangeTypeKind;
1610 }
1611};
1612
1613/// Composite types.
1614///
1615/// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
1616/// TODO: Create a custom, unrelated node for DW_TAG_array_type.
1617class DICompositeType : public DIType {
1618 friend class LLVMContextImpl;
1619 friend class MDNode;
1620
1621 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1622
1623 unsigned RuntimeLang;
1624 std::optional<uint32_t> EnumKind;
1625
1626 DICompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
1627 unsigned Line, unsigned RuntimeLang, uint32_t AlignInBits,
1629 std::optional<uint32_t> EnumKind, DIFlags Flags,
1631 : DIType(C, DICompositeTypeKind, Storage, Tag, Line, AlignInBits,
1633 RuntimeLang(RuntimeLang), EnumKind(EnumKind) {}
1634 ~DICompositeType() = default;
1635
1636 /// Change fields in place.
1637 void mutate(unsigned Tag, unsigned Line, unsigned RuntimeLang,
1639 std::optional<uint32_t> EnumKind, DIFlags Flags) {
1640 assert(isDistinct() && "Only distinct nodes can mutate");
1641 assert(getRawIdentifier() && "Only ODR-uniqued nodes should mutate");
1642 this->RuntimeLang = RuntimeLang;
1643 this->EnumKind = EnumKind;
1645 }
1646
1647 static DICompositeType *
1648 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
1649 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1651 uint32_t NumExtraInhabitants, DIFlags Flags, DINodeArray Elements,
1652 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1653 DIType *VTableHolder, DITemplateParameterArray TemplateParams,
1654 StringRef Identifier, DIDerivedType *Discriminator,
1656 Metadata *Rank, DINodeArray Annotations, Metadata *BitStride,
1657 StorageType Storage, bool ShouldCreate = true) {
1658 auto *SizeInBitsNode = ConstantAsMetadata::get(
1659 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1660 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1661 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1662 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1663 Line, Scope, BaseType, SizeInBitsNode, AlignInBits,
1664 OffsetInBitsNode, Flags, Elements.get(), RuntimeLang,
1666 getCanonicalMDString(Context, Identifier), Discriminator,
1669 ShouldCreate);
1670 }
1671 static DICompositeType *
1672 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1673 unsigned Line, Metadata *Scope, Metadata *BaseType,
1674 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
1675 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
1676 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1681 Metadata *BitStride, StorageType Storage, bool ShouldCreate = true) {
1682 auto *SizeInBitsNode = ConstantAsMetadata::get(
1683 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1684 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1685 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1686 return getImpl(Context, Tag, Name, File, Line, Scope, BaseType,
1687 SizeInBitsNode, AlignInBits, OffsetInBitsNode, Flags,
1688 Elements, RuntimeLang, EnumKind, VTableHolder,
1691 NumExtraInhabitants, BitStride, Storage, ShouldCreate);
1692 }
1693 static DICompositeType *
1694 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
1697 uint32_t NumExtraInhabitants, DIFlags Flags, DINodeArray Elements,
1698 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1699 DIType *VTableHolder, DITemplateParameterArray TemplateParams,
1700 StringRef Identifier, DIDerivedType *Discriminator,
1702 Metadata *Rank, DINodeArray Annotations, Metadata *BitStride,
1703 StorageType Storage, bool ShouldCreate = true) {
1704 return getImpl(
1705 Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
1707 RuntimeLang, EnumKind, VTableHolder, TemplateParams.get(),
1710 NumExtraInhabitants, BitStride, Storage, ShouldCreate);
1711 }
1712 LLVM_ABI static DICompositeType *
1713 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1714 unsigned Line, Metadata *Scope, Metadata *BaseType,
1716 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
1717 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1722 Metadata *BitStride, StorageType Storage, bool ShouldCreate = true);
1723
1724 TempDICompositeType cloneImpl() const {
1725 return getTemporary(
1733 getRawBitStride());
1734 }
1735
1736public:
1738 DICompositeType,
1739 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1742 DINodeArray Elements, unsigned RuntimeLang,
1743 std::optional<uint32_t> EnumKind, DIType *VTableHolder,
1744 DITemplateParameterArray TemplateParams = nullptr,
1746 Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
1747 Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
1748 DINodeArray Annotations = nullptr, DIType *Specification = nullptr,
1752 RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier,
1754 BitStride))
1756 DICompositeType,
1757 (unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
1760 Metadata *Elements, unsigned RuntimeLang,
1761 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1764 Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
1765 Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
1767 Metadata *BitStride = nullptr),
1769 OffsetInBits, Flags, Elements, RuntimeLang, EnumKind, VTableHolder,
1772 BitStride))
1774 DICompositeType,
1775 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1778 DINodeArray Elements, unsigned RuntimeLang,
1779 std::optional<uint32_t> EnumKind, DIType *VTableHolder,
1780 DITemplateParameterArray TemplateParams = nullptr,
1782 Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
1783 Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
1784 DINodeArray Annotations = nullptr, DIType *Specification = nullptr,
1788 RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier,
1790 BitStride))
1792 DICompositeType,
1793 (unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
1796 Metadata *Elements, unsigned RuntimeLang,
1797 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1798 Metadata *TemplateParams = nullptr, MDString *Identifier = nullptr,
1799 Metadata *Discriminator = nullptr, Metadata *DataLocation = nullptr,
1800 Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
1801 Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
1803 Metadata *BitStride = nullptr),
1805 OffsetInBits, Flags, Elements, RuntimeLang, EnumKind, VTableHolder,
1808 BitStride))
1809
1810 TempDICompositeType clone() const { return cloneImpl(); }
1811
1812 /// Get a DICompositeType with the given ODR identifier.
1813 ///
1814 /// If \a LLVMContext::isODRUniquingDebugTypes(), gets the mapped
1815 /// DICompositeType for the given ODR \c Identifier. If none exists, creates
1816 /// a new node.
1817 ///
1818 /// Else, returns \c nullptr.
1819 LLVM_ABI static DICompositeType *
1820 getODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1821 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1825 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1831 MDString &Identifier);
1832
1833 /// Build a DICompositeType with the given ODR identifier.
1834 ///
1835 /// Looks up the mapped DICompositeType for the given ODR \c Identifier. If
1836 /// it doesn't exist, creates a new one. If it does exist and \a
1837 /// isForwardDecl(), and the new arguments would be a definition, mutates the
1838 /// the type in place. In either case, returns the type.
1839 ///
1840 /// If not \a LLVMContext::isODRUniquingDebugTypes(), this function returns
1841 /// nullptr.
1842 LLVM_ABI static DICompositeType *
1843 buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1844 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1848 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1853
1855 DINodeArray getElements() const {
1857 }
1861 DITemplateParameterArray getTemplateParams() const {
1863 }
1865 return getStringOperand(MY_FIRST_OPERAND + 4);
1866 }
1867 unsigned getRuntimeLang() const { return RuntimeLang; }
1868 std::optional<uint32_t> getEnumKind() const { return EnumKind; }
1869
1870 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1871 Metadata *getRawElements() const { return getOperand(MY_FIRST_OPERAND + 1); }
1873 return getOperand(MY_FIRST_OPERAND + 2);
1874 }
1876 return getOperand(MY_FIRST_OPERAND + 3);
1877 }
1879 return getOperandAs<MDString>(MY_FIRST_OPERAND + 4);
1880 }
1882 return getOperand(MY_FIRST_OPERAND + 5);
1883 }
1885 return getOperandAs<DIDerivedType>(MY_FIRST_OPERAND + 5);
1886 }
1888 return getOperand(MY_FIRST_OPERAND + 6);
1889 }
1897 return getOperand(MY_FIRST_OPERAND + 7);
1898 }
1905 Metadata *getRawAllocated() const { return getOperand(MY_FIRST_OPERAND + 8); }
1912 Metadata *getRawRank() const { return getOperand(MY_FIRST_OPERAND + 9); }
1915 return dyn_cast_or_null<ConstantInt>(MD->getValue());
1916 return nullptr;
1917 }
1921
1923 return getOperand(MY_FIRST_OPERAND + 10);
1924 }
1925 DINodeArray getAnnotations() const {
1927 }
1928
1930 return getOperand(MY_FIRST_OPERAND + 11);
1931 }
1935
1936 bool isNameSimplified() const { return getFlags() & FlagNameIsSimplified; }
1937
1939 return getOperand(MY_FIRST_OPERAND + 12);
1940 }
1943 return dyn_cast_or_null<ConstantInt>(MD->getValue());
1944 return nullptr;
1945 }
1946
1947 /// Replace operands.
1948 ///
1949 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
1950 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
1951 /// of its movement if necessary.
1952 /// @{
1953 void replaceElements(DINodeArray Elements) {
1954#ifndef NDEBUG
1955 for (DINode *Op : getElements())
1956 assert(is_contained(Elements->operands(), Op) &&
1957 "Lost a member during member list replacement");
1958#endif
1959 replaceOperandWith(MY_FIRST_OPERAND + 1, Elements.get());
1960 }
1961
1963 replaceOperandWith(MY_FIRST_OPERAND + 2, VTableHolder);
1964 }
1965
1966 void replaceTemplateParams(DITemplateParameterArray TemplateParams) {
1967 replaceOperandWith(MY_FIRST_OPERAND + 3, TemplateParams.get());
1968 }
1969 /// @}
1970
1971 static bool classof(const Metadata *MD) {
1972 return MD->getMetadataID() == DICompositeTypeKind;
1973 }
1974};
1975
1976/// Type array for a subprogram.
1977///
1978/// TODO: Fold the array of types in directly as operands.
1979class DISubroutineType : public DIType {
1980 friend class LLVMContextImpl;
1981 friend class MDNode;
1982
1983 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1984
1985 /// The calling convention used with DW_AT_calling_convention. Actually of
1986 /// type dwarf::CallingConvention.
1987 uint8_t CC;
1988
1989 DISubroutineType(LLVMContext &C, StorageType Storage, DIFlags Flags,
1991 ~DISubroutineType() = default;
1992
1993 static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
1994 uint8_t CC, DITypeArray TypeArray,
1996 bool ShouldCreate = true) {
1997 return getImpl(Context, Flags, CC, TypeArray.get(), Storage, ShouldCreate);
1998 }
1999 LLVM_ABI static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
2002 bool ShouldCreate = true);
2003
2004 TempDISubroutineType cloneImpl() const {
2006 }
2007
2008public:
2009 DEFINE_MDNODE_GET(DISubroutineType,
2010 (DIFlags Flags, uint8_t CC, DITypeArray TypeArray),
2011 (Flags, CC, TypeArray))
2012 DEFINE_MDNODE_GET(DISubroutineType,
2015
2016 TempDISubroutineType clone() const { return cloneImpl(); }
2017 // Returns a new temporary DISubroutineType with updated CC
2018 TempDISubroutineType cloneWithCC(uint8_t CC) const {
2019 auto NewTy = clone();
2020 NewTy->CC = CC;
2021 return NewTy;
2022 }
2023
2024 uint8_t getCC() const { return CC; }
2025
2026 DITypeArray getTypeArray() const {
2028 }
2029
2030 Metadata *getRawTypeArray() const { return getOperand(MY_FIRST_OPERAND); }
2031
2032 static bool classof(const Metadata *MD) {
2033 return MD->getMetadataID() == DISubroutineTypeKind;
2034 }
2035};
2036
2037/// Compile unit.
2038class DICompileUnit : public DIScope {
2039 friend class LLVMContextImpl;
2040 friend class MDNode;
2041
2042public:
2050
2058
2059 LLVM_ABI static std::optional<DebugEmissionKind>
2061 LLVM_ABI static const char *emissionKindString(DebugEmissionKind EK);
2062 LLVM_ABI static std::optional<DebugNameTableKind>
2064 LLVM_ABI static const char *nameTableKindString(DebugNameTableKind PK);
2065
2066private:
2067 DISourceLanguageName SourceLanguage;
2068 unsigned RuntimeVersion;
2070 unsigned EmissionKind;
2071 unsigned NameTableKind;
2072 bool IsOptimized;
2073 bool SplitDebugInlining;
2075 bool RangesBaseAddress;
2076
2078 DISourceLanguageName SourceLanguage, bool IsOptimized,
2079 unsigned RuntimeVersion, unsigned EmissionKind, uint64_t DWOId,
2081 unsigned NameTableKind, bool RangesBaseAddress,
2083 ~DICompileUnit() = default;
2084
2085 static DICompileUnit *
2086 getImpl(LLVMContext &Context, DISourceLanguageName SourceLanguage,
2089 unsigned EmissionKind, DICompositeTypeArray EnumTypes,
2090 DIScopeArray RetainedTypes,
2091 DIGlobalVariableExpressionArray GlobalVariables,
2092 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
2095 StringRef SDK, StorageType Storage, bool ShouldCreate = true) {
2096 return getImpl(
2097 Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
2100 EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
2103 getCanonicalMDString(Context, SysRoot),
2104 getCanonicalMDString(Context, SDK), Storage, ShouldCreate);
2105 }
2106 LLVM_ABI static DICompileUnit *
2107 getImpl(LLVMContext &Context, DISourceLanguageName SourceLanguage,
2108 Metadata *File, MDString *Producer, bool IsOptimized, MDString *Flags,
2109 unsigned RuntimeVersion, MDString *SplitDebugFilename,
2113 bool DebugInfoForProfiling, unsigned NameTableKind,
2114 bool RangesBaseAddress, MDString *SysRoot, MDString *SDK,
2115 StorageType Storage, bool ShouldCreate = true);
2116
2117 TempDICompileUnit cloneImpl() const {
2118 return getTemporary(
2125 }
2126
2127public:
2128 static void get() = delete;
2129 static void getIfExists() = delete;
2130
2132 DICompileUnit,
2134 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
2136 DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes,
2137 DIGlobalVariableExpressionArray GlobalVariables,
2138 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
2139 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
2140 DebugNameTableKind NameTableKind, bool RangesBaseAddress,
2142 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
2144 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
2145 DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress,
2146 SysRoot, SDK))
2148 DICompileUnit,
2150 bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
2154 bool SplitDebugInlining, bool DebugInfoForProfiling,
2155 unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
2157 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
2159 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
2160 DebugInfoForProfiling, NameTableKind, RangesBaseAddress, SysRoot, SDK))
2161
2162 TempDICompileUnit clone() const { return cloneImpl(); }
2163
2164 DISourceLanguageName getSourceLanguage() const { return SourceLanguage; }
2165 bool isOptimized() const { return IsOptimized; }
2166 bool isDebugInfoForProfiling() const { return DebugInfoForProfiling; }
2167 unsigned getRuntimeVersion() const { return RuntimeVersion; }
2169 return (DebugEmissionKind)EmissionKind;
2170 }
2171 // Return true if this CU was compiled with debug info disabled
2172 bool isNoDebug() const { return EmissionKind == NoDebug; }
2174 return EmissionKind == DebugDirectivesOnly;
2175 }
2176 bool getDebugInfoForProfiling() const { return DebugInfoForProfiling; }
2178 return (DebugNameTableKind)NameTableKind;
2179 }
2180 bool getRangesBaseAddress() const { return RangesBaseAddress; }
2182 StringRef getFlags() const { return getStringOperand(2); }
2184 DICompositeTypeArray getEnumTypes() const {
2186 }
2187 DIScopeArray getRetainedTypes() const {
2189 }
2190 DIGlobalVariableExpressionArray getGlobalVariables() const {
2192 }
2193 DIImportedEntityArray getImportedEntities() const {
2195 }
2196 DIMacroNodeArray getMacros() const {
2198 }
2199 uint64_t getDWOId() const { return DWOId; }
2200 void setDWOId(uint64_t DwoId) { DWOId = DwoId; }
2201 bool getSplitDebugInlining() const { return SplitDebugInlining; }
2202 void setSplitDebugInlining(bool SplitDebugInlining) {
2203 this->SplitDebugInlining = SplitDebugInlining;
2204 }
2206 StringRef getSDK() const { return getStringOperand(10); }
2207 /// Target-specific language dialect for DWARF.
2208 uint16_t getDialect() const { return SourceLanguage.getDialect(); }
2209
2215 Metadata *getRawEnumTypes() const { return getOperand(4); }
2219 Metadata *getRawMacros() const { return getOperand(8); }
2222 /// Replace arrays.
2223 ///
2224 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
2225 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
2226 /// DICompileUnit should be fairly rare.
2227 /// @{
2228 void replaceEnumTypes(DICompositeTypeArray N) {
2229 replaceOperandWith(4, N.get());
2230 }
2231 void replaceRetainedTypes(DITypeArray N) { replaceOperandWith(5, N.get()); }
2232 void replaceGlobalVariables(DIGlobalVariableExpressionArray N) {
2233 replaceOperandWith(6, N.get());
2234 }
2235 void replaceImportedEntities(DIImportedEntityArray N) {
2236 replaceOperandWith(7, N.get());
2237 }
2238 void replaceMacros(DIMacroNodeArray N) { replaceOperandWith(8, N.get()); }
2239 /// @}
2240
2241 static bool classof(const Metadata *MD) {
2242 return MD->getMetadataID() == DICompileUnitKind;
2243 }
2244};
2245
2246/// A scope for locals.
2247///
2248/// A legal scope for lexical blocks, local variables, and debug info
2249/// locations. Subclasses are \a DISubprogram, \a DILexicalBlock, and \a
2250/// DILexicalBlockFile.
2251class DILocalScope : public DIScope {
2252protected:
2255 : DIScope(C, ID, Storage, Tag, Ops) {}
2256 ~DILocalScope() = default;
2257
2258public:
2259 /// Get the subprogram for this scope.
2260 ///
2261 /// Return this if it's an \a DISubprogram; otherwise, look up the scope
2262 /// chain.
2264
2265 /// Traverses the scope chain rooted at RootScope until it hits a Subprogram,
2266 /// recreating the chain with "NewSP" instead.
2267 LLVM_ABI static DILocalScope *
2269 LLVMContext &Ctx,
2271
2272 /// Get the first non DILexicalBlockFile scope of this scope.
2273 ///
2274 /// Return this if it's not a \a DILexicalBlockFIle; otherwise, look up the
2275 /// scope chain.
2277
2278 static bool classof(const Metadata *MD) {
2279 return MD->getMetadataID() == DISubprogramKind ||
2280 MD->getMetadataID() == DILexicalBlockKind ||
2281 MD->getMetadataID() == DILexicalBlockFileKind;
2282 }
2283};
2284
2285/// Subprogram description. Uses SubclassData1.
2286class DISubprogram : public DILocalScope {
2287 friend class LLVMContextImpl;
2288 friend class MDNode;
2289
2290 unsigned Line;
2291 unsigned ScopeLine;
2292 unsigned VirtualIndex;
2293
2294 /// In the MS ABI, the implicit 'this' parameter is adjusted in the prologue
2295 /// of method overrides from secondary bases by this amount. It may be
2296 /// negative.
2297 int ThisAdjustment;
2298
2299public:
2300 /// Debug info subprogram flags.
2302#define HANDLE_DISP_FLAG(ID, NAME) SPFlag##NAME = ID,
2303#define DISP_FLAG_LARGEST_NEEDED
2304#include "llvm/IR/DebugInfoFlags.def"
2305 SPFlagNonvirtual = SPFlagZero,
2306 SPFlagVirtuality = SPFlagVirtual | SPFlagPureVirtual,
2307 LLVM_MARK_AS_BITMASK_ENUM(SPFlagLargest)
2308 };
2309
2310 LLVM_ABI static DISPFlags getFlag(StringRef Flag);
2311 LLVM_ABI static StringRef getFlagString(DISPFlags Flag);
2312
2313 /// Split up a flags bitfield for easier printing.
2314 ///
2315 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
2316 /// any remaining (unrecognized) bits.
2317 LLVM_ABI static DISPFlags splitFlags(DISPFlags Flags,
2318 SmallVectorImpl<DISPFlags> &SplitFlags);
2319
2320 // Helper for converting old bitfields to new flags word.
2321 LLVM_ABI static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition,
2322 bool IsOptimized,
2323 unsigned Virtuality = SPFlagNonvirtual,
2324 bool IsMainSubprogram = false);
2325
2326private:
2327 DIFlags Flags;
2328 DISPFlags SPFlags;
2329
2330 DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
2331 unsigned ScopeLine, unsigned VirtualIndex, int ThisAdjustment,
2332 DIFlags Flags, DISPFlags SPFlags, bool UsesKeyInstructions,
2334 ~DISubprogram() = default;
2335
2336 static DISubprogram *
2337 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
2338 StringRef LinkageName, DIFile *File, unsigned Line,
2340 unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags,
2341 DISPFlags SPFlags, DICompileUnit *Unit,
2342 DITemplateParameterArray TemplateParams, DISubprogram *Declaration,
2343 MDNodeArray RetainedNodes, DITypeArray ThrownTypes,
2346 bool ShouldCreate = true) {
2347 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
2348 getCanonicalMDString(Context, LinkageName), File, Line, Type,
2350 Flags, SPFlags, Unit, TemplateParams.get(), Declaration,
2351 RetainedNodes.get(), ThrownTypes.get(), Annotations.get(),
2353 UsesKeyInstructions, Storage, ShouldCreate);
2354 }
2355
2356 LLVM_ABI static DISubprogram *
2357 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
2358 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
2359 unsigned ScopeLine, Metadata *ContainingType, unsigned VirtualIndex,
2360 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
2363 MDString *TargetFuncName, bool UsesKeyInstructions,
2364 StorageType Storage, bool ShouldCreate = true);
2365
2366 TempDISubprogram cloneImpl() const {
2368 getFile(), getLine(), getType(), getScopeLine(),
2369 getContainingType(), getVirtualIndex(),
2370 getThisAdjustment(), getFlags(), getSPFlags(),
2371 getUnit(), getTemplateParams(), getDeclaration(),
2372 getRetainedNodes(), getThrownTypes(), getAnnotations(),
2373 getTargetFuncName(), getKeyInstructionsEnabled());
2374 }
2375
2376public:
2378 DISubprogram,
2380 unsigned Line, DISubroutineType *Type, unsigned ScopeLine,
2381 DIType *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
2382 DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit,
2383 DITemplateParameterArray TemplateParams = nullptr,
2384 DISubprogram *Declaration = nullptr, MDNodeArray RetainedNodes = nullptr,
2385 DITypeArray ThrownTypes = nullptr, DINodeArray Annotations = nullptr,
2386 StringRef TargetFuncName = "", bool UsesKeyInstructions = false),
2387 (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
2388 VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
2391
2393 DISubprogram,
2395 unsigned Line, Metadata *Type, unsigned ScopeLine,
2396 Metadata *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
2397 DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
2401 bool UsesKeyInstructions = false),
2402 (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
2403 VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
2406
2407 TempDISubprogram clone() const { return cloneImpl(); }
2408
2409 /// Returns a new temporary DISubprogram with updated Flags
2410 TempDISubprogram cloneWithFlags(DIFlags NewFlags) const {
2411 auto NewSP = clone();
2412 NewSP->Flags = NewFlags;
2413 return NewSP;
2414 }
2415
2416 bool getKeyInstructionsEnabled() const { return SubclassData1; }
2417
2418public:
2419 unsigned getLine() const { return Line; }
2420 unsigned getVirtuality() const { return getSPFlags() & SPFlagVirtuality; }
2421 unsigned getVirtualIndex() const { return VirtualIndex; }
2422 int getThisAdjustment() const { return ThisAdjustment; }
2423 unsigned getScopeLine() const { return ScopeLine; }
2424 void setScopeLine(unsigned L) {
2425 assert(isDistinct());
2426 ScopeLine = L;
2427 }
2428 DIFlags getFlags() const { return Flags; }
2429 DISPFlags getSPFlags() const { return SPFlags; }
2430 bool isLocalToUnit() const { return getSPFlags() & SPFlagLocalToUnit; }
2431 bool isDefinition() const { return getSPFlags() & SPFlagDefinition; }
2432 bool isOptimized() const { return getSPFlags() & SPFlagOptimized; }
2433 bool isMainSubprogram() const { return getSPFlags() & SPFlagMainSubprogram; }
2434
2435 bool isArtificial() const { return getFlags() & FlagArtificial; }
2436 bool isPrivate() const {
2437 return (getFlags() & FlagAccessibility) == FlagPrivate;
2438 }
2439 bool isProtected() const {
2440 return (getFlags() & FlagAccessibility) == FlagProtected;
2441 }
2442 bool isPublic() const {
2443 return (getFlags() & FlagAccessibility) == FlagPublic;
2444 }
2445 bool isExplicit() const { return getFlags() & FlagExplicit; }
2446 bool isPrototyped() const { return getFlags() & FlagPrototyped; }
2447 bool isNameSimplified() const { return getFlags() & FlagNameIsSimplified; }
2448 bool areAllCallsDescribed() const {
2449 return getFlags() & FlagAllCallsDescribed;
2450 }
2451 bool isPure() const { return getSPFlags() & SPFlagPure; }
2452 bool isElemental() const { return getSPFlags() & SPFlagElemental; }
2453 bool isRecursive() const { return getSPFlags() & SPFlagRecursive; }
2454 bool isObjCDirect() const { return getSPFlags() & SPFlagObjCDirect; }
2455
2456 /// Check if this is deleted member function.
2457 ///
2458 /// Return true if this subprogram is a C++11 special
2459 /// member function declared deleted.
2460 bool isDeleted() const { return getSPFlags() & SPFlagDeleted; }
2461
2462 /// Check if this is reference-qualified.
2463 ///
2464 /// Return true if this subprogram is a C++11 reference-qualified non-static
2465 /// member function (void foo() &).
2466 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
2467
2468 /// Check if this is rvalue-reference-qualified.
2469 ///
2470 /// Return true if this subprogram is a C++11 rvalue-reference-qualified
2471 /// non-static member function (void foo() &&).
2472 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
2473
2474 /// Check if this is marked as noreturn.
2475 ///
2476 /// Return true if this subprogram is C++11 noreturn or C11 _Noreturn
2477 bool isNoReturn() const { return getFlags() & FlagNoReturn; }
2478
2479 // Check if this routine is a compiler-generated thunk.
2480 //
2481 // Returns true if this subprogram is a thunk generated by the compiler.
2482 bool isThunk() const { return getFlags() & FlagThunk; }
2483
2484 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2485
2486 StringRef getName() const { return getStringOperand(2); }
2487 StringRef getLinkageName() const { return getStringOperand(3); }
2488 /// Only used by clients of CloneFunction, and only right after the cloning.
2489 void replaceLinkageName(MDString *LN) { replaceOperandWith(3, LN); }
2490
2491 DISubroutineType *getType() const {
2492 return cast_or_null<DISubroutineType>(getRawType());
2493 }
2494 DIType *getContainingType() const {
2495 return cast_or_null<DIType>(getRawContainingType());
2496 }
2497 void replaceType(DISubroutineType *Ty) {
2498 assert(isDistinct() && "Only distinct nodes can mutate");
2499 replaceOperandWith(4, Ty);
2500 }
2501
2502 DICompileUnit *getUnit() const {
2503 return cast_or_null<DICompileUnit>(getRawUnit());
2504 }
2505 void replaceUnit(DICompileUnit *CU) { replaceOperandWith(5, CU); }
2506 DITemplateParameterArray getTemplateParams() const {
2507 return cast_or_null<MDTuple>(getRawTemplateParams());
2508 }
2509 DISubprogram *getDeclaration() const {
2510 return cast_or_null<DISubprogram>(getRawDeclaration());
2511 }
2512 void replaceDeclaration(DISubprogram *Decl) { replaceOperandWith(6, Decl); }
2513 MDNodeArray getRetainedNodes() const {
2514 return cast_or_null<MDTuple>(getRawRetainedNodes());
2515 }
2516 DITypeArray getThrownTypes() const {
2517 return cast_or_null<MDTuple>(getRawThrownTypes());
2518 }
2519 DINodeArray getAnnotations() const {
2520 return cast_or_null<MDTuple>(getRawAnnotations());
2521 }
2522 StringRef getTargetFuncName() const {
2523 return (getRawTargetFuncName()) ? getStringOperand(12) : StringRef();
2524 }
2525
2526 Metadata *getRawScope() const { return getOperand(1); }
2527 MDString *getRawName() const { return getOperandAs<MDString>(2); }
2528 MDString *getRawLinkageName() const { return getOperandAs<MDString>(3); }
2529 Metadata *getRawType() const { return getOperand(4); }
2530 Metadata *getRawUnit() const { return getOperand(5); }
2531 Metadata *getRawDeclaration() const { return getOperand(6); }
2532 Metadata *getRawRetainedNodes() const { return getOperand(7); }
2533 Metadata *getRawContainingType() const {
2534 return getNumOperands() > 8 ? getOperandAs<Metadata>(8) : nullptr;
2535 }
2536 Metadata *getRawTemplateParams() const {
2537 return getNumOperands() > 9 ? getOperandAs<Metadata>(9) : nullptr;
2538 }
2539 Metadata *getRawThrownTypes() const {
2540 return getNumOperands() > 10 ? getOperandAs<Metadata>(10) : nullptr;
2541 }
2542 Metadata *getRawAnnotations() const {
2543 return getNumOperands() > 11 ? getOperandAs<Metadata>(11) : nullptr;
2544 }
2545 MDString *getRawTargetFuncName() const {
2546 return getNumOperands() > 12 ? getOperandAs<MDString>(12) : nullptr;
2547 }
2548
2549 void replaceRawLinkageName(MDString *LinkageName) {
2551 }
2552 void replaceRetainedNodes(MDNodeArray N) { replaceOperandWith(7, N.get()); }
2553
2554 template <typename IterT> void retainNodes(IterT NodesBegin, IterT NodesEnd) {
2555 auto RetainedNodes = getRetainedNodes();
2557 MDs.append(NodesBegin, NodesEnd);
2558 replaceRetainedNodes(MDNode::get(getContext(), MDs));
2559 }
2560
2561 /// For the given retained node of DISubprogram, applies one of the
2562 /// given functions depending on the type of the node.
2563 template <typename T, typename MetadataT, typename FuncLVT,
2564 typename FuncLabelT, typename FuncImportedEntityT,
2565 typename FuncTypeT, typename FuncGVET, typename FuncUnknownT>
2566 static T visitRetainedNode(MetadataT *N, FuncLVT &&FuncLV,
2567 FuncLabelT &&FuncLabel,
2568 FuncImportedEntityT &&FuncIE, FuncTypeT &&FuncType,
2569 FuncGVET &&FuncGVE, FuncUnknownT &&FuncUnknown) {
2570 static_assert(std::is_base_of_v<Metadata, MetadataT>,
2571 "N must point to Metadata or const Metadata");
2572
2573 if (auto *LV = dyn_cast<DILocalVariable>(N))
2574 return FuncLV(LV);
2575 if (auto *L = dyn_cast<DILabel>(N))
2576 return FuncLabel(L);
2577 if (auto *IE = dyn_cast<DIImportedEntity>(N))
2578 return FuncIE(IE);
2579 if (auto *Ty = dyn_cast<DIType>(N))
2580 return FuncType(Ty);
2581 if (auto *GVE = dyn_cast<DIGlobalVariableExpression>(N))
2582 return FuncGVE(GVE);
2583 return FuncUnknown(N);
2584 }
2585
2586 /// Returns the scope of subprogram's retainedNodes.
2587 LLVM_ABI static const DILocalScope *getRetainedNodeScope(const MDNode *N);
2589 // For use in Verifier.
2590 LLVM_ABI static const DIScope *getRawRetainedNodeScope(const MDNode *N);
2592
2593 /// For each retained node, applies one of the given functions depending
2594 /// on the type of a node.
2595 template <typename FuncLVT, typename FuncLabelT, typename FuncImportedEntityT,
2596 typename FuncTypeT, typename FuncGVET>
2597 void forEachRetainedNode(FuncLVT &&FuncLV, FuncLabelT &&FuncLabel,
2598 FuncImportedEntityT &&FuncIE, FuncTypeT &&FuncType,
2599 FuncGVET &&FuncGVE) {
2600 for (MDNode *N : getRetainedNodes())
2601 visitRetainedNode<void>(
2602 N, FuncLV, FuncLabel, FuncIE, FuncType, FuncGVE,
2603 [](auto *N) { llvm_unreachable("Unexpected retained node!"); });
2604 }
2605
2606 /// When IR modules are merged, typically during LTO, the merged module
2607 /// may contain several types having the same linkageName. They are
2608 /// supposed to represent the same type included by multiple source code
2609 /// files from a single header file.
2610 ///
2611 /// DebugTypeODRUniquing feature uniques (deduplicates) such types
2612 /// based on their linkageName during metadata loading, to speed up
2613 /// compilation and reduce debug info size.
2614 ///
2615 /// However, since function-local types are tracked in DISubprogram's
2616 /// retainedNodes field, a single local type may be referenced by multiple
2617 /// DISubprograms via retainedNodes as the result of DebugTypeODRUniquing.
2618 /// But retainedNodes field of a DISubprogram is meant to hold only
2619 /// subprogram's own local entities, therefore such references may
2620 /// cause crashes.
2621 ///
2622 /// To address this problem, this method is called for each new subprogram
2623 /// after module loading. It removes references to types belonging
2624 /// to other DISubprograms from a subprogram's retainedNodes list.
2625 /// If a corresponding IR function refers to local scopes from another
2626 /// subprogram, emitted debug info (e.g. DWARF) should rely
2627 /// on cross-subprogram references (and cross-CU references, as subprograms
2628 /// may belong to different compile units). This is also a drawback:
2629 /// when a subprogram refers to types that are local to another subprogram,
2630 /// it is more complicated for debugger to properly discover local types
2631 /// of a current scope for expression evaluation.
2633
2634 template <typename T> void cleanupRetainedNodesIf(T &&Pred) {
2635 MDTuple *RetainedNodes = dyn_cast_or_null<MDTuple>(getRawRetainedNodes());
2636 // As this is expected to be called during module loading, before
2637 // stripping old or incorrect debug info, perform minimal sanity check.
2638 if (!RetainedNodes)
2639 return;
2640 // replaceRetainedNodes() should not re-unique DISubprogram if new list is
2641 // the same pointer.
2642 replaceRetainedNodes(RetainedNodes->filter(Pred));
2643 }
2644
2645 /// Calls SP->cleanupRetainedNodes() for a range of DISubprograms.
2646 template <typename RangeT>
2647 static void cleanupRetainedNodes(const RangeT &NewDistinctSPs) {
2648 for (DISubprogram *SP : NewDistinctSPs)
2649 SP->cleanupRetainedNodes();
2650 }
2651
2652 /// Check if this subprogram describes the given function.
2653 ///
2654 /// FIXME: Should this be looking through bitcasts?
2655 LLVM_ABI bool describes(const Function *F) const;
2656
2657 static bool classof(const Metadata *MD) {
2658 return MD->getMetadataID() == DISubprogramKind;
2659 }
2660};
2661
2662/// Debug location.
2663///
2664/// A debug location in source code, used for debug info and otherwise.
2665///
2666/// Uses the SubclassData1, SubclassData16 and SubclassData32
2667/// Metadata slots.
2668
2669class DILocation : public MDNode {
2670 friend class LLVMContextImpl;
2671 friend class MDNode;
2672 uint64_t AtomGroup : 61;
2673 uint64_t AtomRank : 3;
2674
2675 DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
2676 unsigned Column, uint64_t AtomGroup, uint8_t AtomRank,
2678 ~DILocation() { dropAllReferences(); }
2679
2680 LLVM_ABI static DILocation *
2681 getImpl(LLVMContext &Context, unsigned Line, unsigned Column, Metadata *Scope,
2683 uint8_t AtomRank, StorageType Storage, bool ShouldCreate = true);
2684 static DILocation *getImpl(LLVMContext &Context, unsigned Line,
2685 unsigned Column, DILocalScope *Scope,
2688 StorageType Storage, bool ShouldCreate = true) {
2689 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
2690 static_cast<Metadata *>(InlinedAt), ImplicitCode, AtomGroup,
2691 AtomRank, Storage, ShouldCreate);
2692 }
2693
2694 TempDILocation cloneImpl() const {
2695 // Get the raw scope/inlinedAt since it is possible to invoke this on
2696 // a DILocation containing temporary metadata.
2697 return getTemporary(getContext(), getLine(), getColumn(), getRawScope(),
2698 getRawInlinedAt(), isImplicitCode(), getAtomGroup(),
2699 getAtomRank());
2700 }
2701
2702public:
2703 uint64_t getAtomGroup() const { return AtomGroup; }
2704 uint8_t getAtomRank() const { return AtomRank; }
2705
2706 const DILocation *getWithoutAtom() const {
2707 if (!getAtomGroup() && !getAtomRank())
2708 return this;
2709 return get(getContext(), getLine(), getColumn(), getScope(), getInlinedAt(),
2710 isImplicitCode());
2711 }
2712
2713 // Disallow replacing operands.
2714 void replaceOperandWith(unsigned I, Metadata *New) = delete;
2715
2717 (unsigned Line, unsigned Column, Metadata *Scope,
2718 Metadata *InlinedAt = nullptr, bool ImplicitCode = false,
2719 uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2720 (Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2721 AtomRank))
2722 DEFINE_MDNODE_GET(DILocation,
2723 (unsigned Line, unsigned Column, DILocalScope *Scope,
2724 DILocation *InlinedAt = nullptr, bool ImplicitCode = false,
2725 uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2726 (Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2727 AtomRank))
2728
2729 /// Return a (temporary) clone of this.
2730 TempDILocation clone() const { return cloneImpl(); }
2731
2732 unsigned getLine() const { return SubclassData32; }
2733 unsigned getColumn() const { return SubclassData16; }
2734 DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
2735
2736 /// Return the linkage name of Subprogram. If the linkage name is empty,
2737 /// return scope name (the demangled name).
2738 StringRef getSubprogramLinkageName() const {
2739 DISubprogram *SP = getScope()->getSubprogram();
2740 if (!SP)
2741 return "";
2742 auto Name = SP->getLinkageName();
2743 if (!Name.empty())
2744 return Name;
2745 return SP->getName();
2746 }
2747
2748 DILocation *getInlinedAt() const {
2750 }
2751
2752 /// Check if the location corresponds to an implicit code.
2753 /// When the ImplicitCode flag is true, it means that the Instruction
2754 /// with this DILocation has been added by the front-end but it hasn't been
2755 /// written explicitly by the user (e.g. cleanup stuff in C++ put on a closing
2756 /// bracket). It's useful for code coverage to not show a counter on "empty"
2757 /// lines.
2758 bool isImplicitCode() const { return SubclassData1; }
2759 void setImplicitCode(bool ImplicitCode) { SubclassData1 = ImplicitCode; }
2760
2761 DIFile *getFile() const { return getScope()->getFile(); }
2762 StringRef getFilename() const { return getScope()->getFilename(); }
2763 StringRef getDirectory() const { return getScope()->getDirectory(); }
2764 std::optional<StringRef> getSource() const { return getScope()->getSource(); }
2765
2766 /// Walk through \a getInlinedAt() and return the \a DILocation of the
2767 /// outermost call site in the inlining chain.
2768 const DILocation *getInlinedAtLocation() const {
2769 const DILocation *Current = this;
2770 while (const DILocation *Next = Current->getInlinedAt())
2771 Current = Next;
2772 return Current;
2773 }
2774
2775 // Return the \a DILocalScope of the outermost call site in the inlining
2776 // chain.
2777 DILocalScope *getInlinedAtScope() const {
2778 return getInlinedAtLocation()->getScope();
2779 }
2780
2781 /// Get the DWARF discriminator.
2782 ///
2783 /// DWARF discriminators distinguish identical file locations between
2784 /// instructions that are on different basic blocks.
2785 ///
2786 /// There are 3 components stored in discriminator, from lower bits:
2787 ///
2788 /// Base discriminator: assigned by AddDiscriminators pass to identify IRs
2789 /// that are defined by the same source line, but
2790 /// different basic blocks.
2791 /// Duplication factor: assigned by optimizations that will scale down
2792 /// the execution frequency of the original IR.
2793 /// Copy Identifier: assigned by optimizations that clones the IR.
2794 /// Each copy of the IR will be assigned an identifier.
2795 ///
2796 /// Encoding:
2797 ///
2798 /// The above 3 components are encoded into a 32bit unsigned integer in
2799 /// order. If the lowest bit is 1, the current component is empty, and the
2800 /// next component will start in the next bit. Otherwise, the current
2801 /// component is non-empty, and its content starts in the next bit. The
2802 /// value of each components is either 5 bit or 12 bit: if the 7th bit
2803 /// is 0, the bit 2~6 (5 bits) are used to represent the component; if the
2804 /// 7th bit is 1, the bit 2~6 (5 bits) and 8~14 (7 bits) are combined to
2805 /// represent the component. Thus, the number of bits used for a component
2806 /// is either 0 (if it and all the next components are empty); 1 - if it is
2807 /// empty; 7 - if its value is up to and including 0x1f (lsb and msb are both
2808 /// 0); or 14, if its value is up to and including 0x1ff. Note that the last
2809 /// component is also capped at 0x1ff, even in the case when both first
2810 /// components are 0, and we'd technically have 29 bits available.
2811 ///
2812 /// For precise control over the data being encoded in the discriminator,
2813 /// use encodeDiscriminator/decodeDiscriminator.
2814
2815 inline unsigned getDiscriminator() const;
2816
2817 // For the regular discriminator, it stands for all empty components if all
2818 // the lowest 3 bits are non-zero and all higher 29 bits are unused(zero by
2819 // default). Here we fully leverage the higher 29 bits for pseudo probe use.
2820 // This is the format:
2821 // [2:0] - 0x7
2822 // [31:3] - pseudo probe fields guaranteed to be non-zero as a whole
2823 // So if the lower 3 bits is non-zero and the others has at least one
2824 // non-zero bit, it guarantees to be a pseudo probe discriminator
2825 inline static bool isPseudoProbeDiscriminator(unsigned Discriminator) {
2826 return ((Discriminator & 0x7) == 0x7) && (Discriminator & 0xFFFFFFF8);
2827 }
2828
2829 /// Returns a new DILocation with updated \p Discriminator.
2830 inline const DILocation *cloneWithDiscriminator(unsigned Discriminator) const;
2831
2832 /// Returns a new DILocation with updated base discriminator \p BD. Only the
2833 /// base discriminator is set in the new DILocation, the other encoded values
2834 /// are elided.
2835 /// If the discriminator cannot be encoded, the function returns std::nullopt.
2836 inline std::optional<const DILocation *>
2837 cloneWithBaseDiscriminator(unsigned BD) const;
2838
2839 /// Returns the duplication factor stored in the discriminator, or 1 if no
2840 /// duplication factor (or 0) is encoded.
2841 inline unsigned getDuplicationFactor() const;
2842
2843 /// Returns the copy identifier stored in the discriminator.
2844 inline unsigned getCopyIdentifier() const;
2845
2846 /// Returns the base discriminator stored in the discriminator.
2847 inline unsigned getBaseDiscriminator() const;
2848
2849 /// Returns a new DILocation with duplication factor \p DF * current
2850 /// duplication factor encoded in the discriminator. The current duplication
2851 /// factor is as defined by getDuplicationFactor().
2852 /// Returns std::nullopt if encoding failed.
2853 inline std::optional<const DILocation *>
2855
2856 /// Attempts to merge \p LocA and \p LocB into a single location; see
2857 /// DebugLoc::getMergedLocation for more details.
2858 /// NB: When merging the locations of instructions, prefer to use
2859 /// DebugLoc::getMergedLocation(), as an instruction's DebugLoc may contain
2860 /// additional metadata that will not be preserved when merging the unwrapped
2861 /// DILocations.
2863 DILocation *LocB);
2864
2865 /// Try to combine the vector of locations passed as input in a single one.
2866 /// This function applies getMergedLocation() repeatedly left-to-right.
2867 /// NB: When merging the locations of instructions, prefer to use
2868 /// DebugLoc::getMergedLocations(), as an instruction's DebugLoc may contain
2869 /// additional metadata that will not be preserved when merging the unwrapped
2870 /// DILocations.
2871 ///
2872 /// \p Locs: The locations to be merged.
2874
2875 /// Return the masked discriminator value for an input discrimnator value D
2876 /// (i.e. zero out the (B+1)-th and above bits for D (B is 0-base).
2877 // Example: an input of (0x1FF, 7) returns 0xFF.
2878 static unsigned getMaskedDiscriminator(unsigned D, unsigned B) {
2879 return (D & getN1Bits(B));
2880 }
2881
2882 /// Return the bits used for base discriminators.
2883 static unsigned getBaseDiscriminatorBits() { return getBaseFSBitEnd(); }
2884
2885 /// Returns the base discriminator for a given encoded discriminator \p D.
2886 static unsigned
2888 bool IsFSDiscriminator = false) {
2889 // Extract the dwarf base discriminator if it's encoded in the pseudo probe
2890 // discriminator.
2892 auto DwarfBaseDiscriminator =
2894 if (DwarfBaseDiscriminator)
2895 return *DwarfBaseDiscriminator;
2896 // Return the probe id instead of zero for a pseudo probe discriminator.
2897 // This should help differenciate callsites with same line numbers to
2898 // achieve a decent AutoFDO profile under -fpseudo-probe-for-profiling,
2899 // where the original callsite dwarf discriminator is overwritten by
2900 // callsite probe information.
2902 }
2903
2904 if (IsFSDiscriminator)
2907 }
2908
2909 /// Raw encoding of the discriminator. APIs such as cloneWithDuplicationFactor
2910 /// have certain special case behavior (e.g. treating empty duplication factor
2911 /// as the value '1').
2912 /// This API, in conjunction with cloneWithDiscriminator, may be used to
2913 /// encode the raw values provided.
2914 ///
2915 /// \p BD: base discriminator
2916 /// \p DF: duplication factor
2917 /// \p CI: copy index
2918 ///
2919 /// The return is std::nullopt if the values cannot be encoded in 32 bits -
2920 /// for example, values for BD or DF larger than 12 bits. Otherwise, the
2921 /// return is the encoded value.
2922 LLVM_ABI static std::optional<unsigned>
2923 encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI);
2924
2925 /// Raw decoder for values in an encoded discriminator D.
2926 LLVM_ABI static void decodeDiscriminator(unsigned D, unsigned &BD,
2927 unsigned &DF, unsigned &CI);
2928
2929 /// Returns the duplication factor for a given encoded discriminator \p D, or
2930 /// 1 if no value or 0 is encoded.
2931 static unsigned getDuplicationFactorFromDiscriminator(unsigned D) {
2933 return 1;
2935 unsigned Ret = getUnsignedFromPrefixEncoding(D);
2936 if (Ret == 0)
2937 return 1;
2938 return Ret;
2939 }
2940
2941 /// Returns the copy identifier for a given encoded discriminator \p D.
2946
2947 Metadata *getRawScope() const { return getOperand(0); }
2949 if (getNumOperands() == 2)
2950 return getOperand(1);
2951 return nullptr;
2952 }
2953
2954 static bool classof(const Metadata *MD) {
2955 return MD->getMetadataID() == DILocationKind;
2956 }
2957};
2958
2960protected:
2964
2965public:
2967
2968 Metadata *getRawScope() const { return getOperand(1); }
2969
2970 void replaceScope(DIScope *Scope) {
2971 assert(!isUniqued());
2972 setOperand(1, Scope);
2973 }
2974
2975 static bool classof(const Metadata *MD) {
2976 return MD->getMetadataID() == DILexicalBlockKind ||
2977 MD->getMetadataID() == DILexicalBlockFileKind;
2978 }
2979};
2980
2981/// Debug lexical block.
2982///
2983/// Uses the SubclassData32 Metadata slot.
2984class DILexicalBlock : public DILexicalBlockBase {
2985 friend class LLVMContextImpl;
2986 friend class MDNode;
2987
2988 uint16_t Column;
2989
2990 DILexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
2991 unsigned Column, ArrayRef<Metadata *> Ops)
2992 : DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops),
2993 Column(Column) {
2995 assert(Column < (1u << 16) && "Expected 16-bit column");
2996 }
2997 ~DILexicalBlock() = default;
2998
2999 static DILexicalBlock *getImpl(LLVMContext &Context, DILocalScope *Scope,
3000 DIFile *File, unsigned Line, unsigned Column,
3002 bool ShouldCreate = true) {
3003 return getImpl(Context, static_cast<Metadata *>(Scope),
3004 static_cast<Metadata *>(File), Line, Column, Storage,
3005 ShouldCreate);
3006 }
3007
3008 LLVM_ABI static DILexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
3009 Metadata *File, unsigned Line,
3010 unsigned Column, StorageType Storage,
3011 bool ShouldCreate = true);
3012
3013 TempDILexicalBlock cloneImpl() const {
3015 getColumn());
3016 }
3017
3018public:
3019 DEFINE_MDNODE_GET(DILexicalBlock,
3020 (DILocalScope * Scope, DIFile *File, unsigned Line,
3021 unsigned Column),
3022 (Scope, File, Line, Column))
3023 DEFINE_MDNODE_GET(DILexicalBlock,
3025 unsigned Column),
3026 (Scope, File, Line, Column))
3027
3028 TempDILexicalBlock clone() const { return cloneImpl(); }
3029
3030 unsigned getLine() const { return SubclassData32; }
3031 unsigned getColumn() const { return Column; }
3032
3033 static bool classof(const Metadata *MD) {
3034 return MD->getMetadataID() == DILexicalBlockKind;
3035 }
3036};
3037
3038class DILexicalBlockFile : public DILexicalBlockBase {
3039 friend class LLVMContextImpl;
3040 friend class MDNode;
3041
3042 DILexicalBlockFile(LLVMContext &C, StorageType Storage,
3044 : DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops) {
3046 }
3047 ~DILexicalBlockFile() = default;
3048
3049 static DILexicalBlockFile *getImpl(LLVMContext &Context, DILocalScope *Scope,
3050 DIFile *File, unsigned Discriminator,
3052 bool ShouldCreate = true) {
3053 return getImpl(Context, static_cast<Metadata *>(Scope),
3054 static_cast<Metadata *>(File), Discriminator, Storage,
3055 ShouldCreate);
3056 }
3057
3058 LLVM_ABI static DILexicalBlockFile *getImpl(LLVMContext &Context,
3059 Metadata *Scope, Metadata *File,
3060 unsigned Discriminator,
3062 bool ShouldCreate = true);
3063
3064 TempDILexicalBlockFile cloneImpl() const {
3065 return getTemporary(getContext(), getScope(), getFile(),
3067 }
3068
3069public:
3070 DEFINE_MDNODE_GET(DILexicalBlockFile,
3072 unsigned Discriminator),
3074 DEFINE_MDNODE_GET(DILexicalBlockFile,
3077
3078 TempDILexicalBlockFile clone() const { return cloneImpl(); }
3079 unsigned getDiscriminator() const { return SubclassData32; }
3080
3081 static bool classof(const Metadata *MD) {
3082 return MD->getMetadataID() == DILexicalBlockFileKind;
3083 }
3084};
3085
3086unsigned DILocation::getDiscriminator() const {
3088 return F->getDiscriminator();
3089 return 0;
3090}
3091
3092const DILocation *
3093DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
3094 DIScope *Scope = getScope();
3095 // Skip all parent DILexicalBlockFile that already have a discriminator
3096 // assigned. We do not want to have nested DILexicalBlockFiles that have
3097 // multiple discriminators because only the leaf DILexicalBlockFile's
3098 // dominator will be used.
3099 for (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope);
3100 LBF && LBF->getDiscriminator() != 0;
3102 Scope = LBF->getScope();
3103 DILexicalBlockFile *NewScope =
3104 DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator);
3105 return DILocation::get(getContext(), getLine(), getColumn(), NewScope,
3106 getInlinedAt(), isImplicitCode(), getAtomGroup(),
3107 getAtomRank());
3108}
3109
3111 return getBaseDiscriminatorFromDiscriminator(getDiscriminator(),
3113}
3114
3116 return getDuplicationFactorFromDiscriminator(getDiscriminator());
3117}
3118
3120 return getCopyIdentifierFromDiscriminator(getDiscriminator());
3121}
3122
3123std::optional<const DILocation *>
3125 // Do not interfere with pseudo probes. Pseudo probe at a callsite uses
3126 // the dwarf discriminator to store pseudo probe related information,
3127 // such as the probe id.
3128 if (isPseudoProbeDiscriminator(getDiscriminator()))
3129 return this;
3130
3131 unsigned BD, DF, CI;
3132
3134 BD = getBaseDiscriminator();
3135 if (D == BD)
3136 return this;
3137 return cloneWithDiscriminator(D);
3138 }
3139
3140 decodeDiscriminator(getDiscriminator(), BD, DF, CI);
3141 if (D == BD)
3142 return this;
3143 if (std::optional<unsigned> Encoded = encodeDiscriminator(D, DF, CI))
3144 return cloneWithDiscriminator(*Encoded);
3145 return std::nullopt;
3146}
3147
3148std::optional<const DILocation *>
3150 assert(!EnableFSDiscriminator && "FSDiscriminator should not call this.");
3151 // Do no interfere with pseudo probes. Pseudo probe doesn't need duplication
3152 // factor support as samples collected on cloned probes will be aggregated.
3153 // Also pseudo probe at a callsite uses the dwarf discriminator to store
3154 // pseudo probe related information, such as the probe id.
3155 if (isPseudoProbeDiscriminator(getDiscriminator()))
3156 return this;
3157
3159 if (DF <= 1)
3160 return this;
3161
3162 unsigned BD = getBaseDiscriminator();
3163 unsigned CI = getCopyIdentifier();
3164 if (std::optional<unsigned> D = encodeDiscriminator(BD, DF, CI))
3165 return cloneWithDiscriminator(*D);
3166 return std::nullopt;
3167}
3168
3169/// Debug lexical block.
3170///
3171/// Uses the SubclassData1 Metadata slot.
3172class DINamespace : public DIScope {
3173 friend class LLVMContextImpl;
3174 friend class MDNode;
3175
3176 DINamespace(LLVMContext &Context, StorageType Storage, bool ExportSymbols,
3178 ~DINamespace() = default;
3179
3180 static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope,
3182 StorageType Storage, bool ShouldCreate = true) {
3183 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
3184 ExportSymbols, Storage, ShouldCreate);
3185 }
3186 LLVM_ABI static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope,
3189 bool ShouldCreate = true);
3190
3191 TempDINamespace cloneImpl() const {
3192 return getTemporary(getContext(), getScope(), getName(),
3194 }
3195
3196public:
3200 DEFINE_MDNODE_GET(DINamespace,
3203
3204 TempDINamespace clone() const { return cloneImpl(); }
3205
3206 bool getExportSymbols() const { return SubclassData1; }
3208 StringRef getName() const { return getStringOperand(2); }
3209
3210 Metadata *getRawScope() const { return getOperand(1); }
3212
3213 static bool classof(const Metadata *MD) {
3214 return MD->getMetadataID() == DINamespaceKind;
3215 }
3216};
3217
3218/// Represents a module in the programming language, for example, a Clang
3219/// module, or a Fortran module.
3220///
3221/// Uses the SubclassData1 and SubclassData32 Metadata slots.
3222class DIModule : public DIScope {
3223 friend class LLVMContextImpl;
3224 friend class MDNode;
3225
3226 DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo,
3227 bool IsDecl, ArrayRef<Metadata *> Ops);
3228 ~DIModule() = default;
3229
3230 static DIModule *getImpl(LLVMContext &Context, DIFile *File, DIScope *Scope,
3233 unsigned LineNo, bool IsDecl, StorageType Storage,
3234 bool ShouldCreate = true) {
3235 return getImpl(Context, File, Scope, getCanonicalMDString(Context, Name),
3238 getCanonicalMDString(Context, APINotesFile), LineNo, IsDecl,
3239 Storage, ShouldCreate);
3240 }
3241 LLVM_ABI static DIModule *
3242 getImpl(LLVMContext &Context, Metadata *File, Metadata *Scope, MDString *Name,
3244 MDString *APINotesFile, unsigned LineNo, bool IsDecl,
3245 StorageType Storage, bool ShouldCreate = true);
3246
3247 TempDIModule cloneImpl() const {
3249 getConfigurationMacros(), getIncludePath(),
3250 getAPINotesFile(), getLineNo(), getIsDecl());
3251 }
3252
3253public:
3257 StringRef APINotesFile, unsigned LineNo,
3258 bool IsDecl = false),
3260 APINotesFile, LineNo, IsDecl))
3261 DEFINE_MDNODE_GET(DIModule,
3265 bool IsDecl = false),
3267 APINotesFile, LineNo, IsDecl))
3268
3269 TempDIModule clone() const { return cloneImpl(); }
3270
3271 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
3272 StringRef getName() const { return getStringOperand(2); }
3273 StringRef getConfigurationMacros() const { return getStringOperand(3); }
3274 StringRef getIncludePath() const { return getStringOperand(4); }
3275 StringRef getAPINotesFile() const { return getStringOperand(5); }
3276 unsigned getLineNo() const { return SubclassData32; }
3277 bool getIsDecl() const { return SubclassData1; }
3278
3279 Metadata *getRawScope() const { return getOperand(1); }
3280 MDString *getRawName() const { return getOperandAs<MDString>(2); }
3281 MDString *getRawConfigurationMacros() const {
3282 return getOperandAs<MDString>(3);
3283 }
3284 MDString *getRawIncludePath() const { return getOperandAs<MDString>(4); }
3285 MDString *getRawAPINotesFile() const { return getOperandAs<MDString>(5); }
3286
3287 static bool classof(const Metadata *MD) {
3288 return MD->getMetadataID() == DIModuleKind;
3289 }
3290};
3291
3292/// Base class for template parameters.
3293///
3294/// Uses the SubclassData1 Metadata slot.
3296protected:
3298 unsigned Tag, bool IsDefault, ArrayRef<Metadata *> Ops)
3299 : DINode(Context, ID, Storage, Tag, Ops) {
3300 SubclassData1 = IsDefault;
3301 }
3303
3304public:
3305 StringRef getName() const { return getStringOperand(0); }
3307
3309 Metadata *getRawType() const { return getOperand(1); }
3310 bool isDefault() const { return SubclassData1; }
3311
3312 static bool classof(const Metadata *MD) {
3313 return MD->getMetadataID() == DITemplateTypeParameterKind ||
3314 MD->getMetadataID() == DITemplateValueParameterKind;
3315 }
3316};
3317
3318class DITemplateTypeParameter : public DITemplateParameter {
3319 friend class LLVMContextImpl;
3320 friend class MDNode;
3321
3322 DITemplateTypeParameter(LLVMContext &Context, StorageType Storage,
3324 ~DITemplateTypeParameter() = default;
3325
3326 static DITemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
3327 DIType *Type, bool IsDefault,
3329 bool ShouldCreate = true) {
3330 return getImpl(Context, getCanonicalMDString(Context, Name), Type,
3331 IsDefault, Storage, ShouldCreate);
3332 }
3334 getImpl(LLVMContext &Context, MDString *Name, Metadata *Type, bool IsDefault,
3335 StorageType Storage, bool ShouldCreate = true);
3336
3337 TempDITemplateTypeParameter cloneImpl() const {
3338 return getTemporary(getContext(), getName(), getType(), isDefault());
3339 }
3340
3341public:
3342 DEFINE_MDNODE_GET(DITemplateTypeParameter,
3344 (Name, Type, IsDefault))
3345 DEFINE_MDNODE_GET(DITemplateTypeParameter,
3348
3349 TempDITemplateTypeParameter clone() const { return cloneImpl(); }
3350
3351 static bool classof(const Metadata *MD) {
3352 return MD->getMetadataID() == DITemplateTypeParameterKind;
3353 }
3354};
3355
3356class DITemplateValueParameter : public DITemplateParameter {
3357 friend class LLVMContextImpl;
3358 friend class MDNode;
3359
3360 DITemplateValueParameter(LLVMContext &Context, StorageType Storage,
3361 unsigned Tag, bool IsDefault,
3363 : DITemplateParameter(Context, DITemplateValueParameterKind, Storage, Tag,
3364 IsDefault, Ops) {}
3365 ~DITemplateValueParameter() = default;
3366
3367 static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
3369 bool IsDefault, Metadata *Value,
3371 bool ShouldCreate = true) {
3372 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
3373 IsDefault, Value, Storage, ShouldCreate);
3374 }
3375 LLVM_ABI static DITemplateValueParameter *
3376 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
3377 bool IsDefault, Metadata *Value, StorageType Storage,
3378 bool ShouldCreate = true);
3379
3380 TempDITemplateValueParameter cloneImpl() const {
3381 return getTemporary(getContext(), getTag(), getName(), getType(),
3382 isDefault(), getValue());
3383 }
3384
3385public:
3386 DEFINE_MDNODE_GET(DITemplateValueParameter,
3387 (unsigned Tag, StringRef Name, DIType *Type, bool IsDefault,
3388 Metadata *Value),
3389 (Tag, Name, Type, IsDefault, Value))
3390 DEFINE_MDNODE_GET(DITemplateValueParameter,
3394
3395 TempDITemplateValueParameter clone() const { return cloneImpl(); }
3396
3397 Metadata *getValue() const { return getOperand(2); }
3398
3399 static bool classof(const Metadata *MD) {
3400 return MD->getMetadataID() == DITemplateValueParameterKind;
3401 }
3402};
3403
3404/// Base class for variables.
3405///
3406/// Uses the SubclassData32 Metadata slot.
3407class DIVariable : public DINode {
3408 unsigned Line;
3409
3410protected:
3412 signed Line, ArrayRef<Metadata *> Ops,
3413 uint32_t AlignInBits = 0);
3414 ~DIVariable() = default;
3415
3416public:
3417 unsigned getLine() const { return Line; }
3419 StringRef getName() const { return getStringOperand(1); }
3423 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
3424 /// Determines the size of the variable's type.
3425 LLVM_ABI std::optional<uint64_t> getSizeInBits() const;
3426
3427 /// Return the signedness of this variable's type, or std::nullopt if this
3428 /// type is neither signed nor unsigned.
3429 std::optional<DIBasicType::Signedness> getSignedness() const {
3430 if (auto *BT = dyn_cast<DIBasicType>(getType()))
3431 return BT->getSignedness();
3432 return std::nullopt;
3433 }
3434
3436 if (auto *F = getFile())
3437 return F->getFilename();
3438 return "";
3439 }
3440
3442 if (auto *F = getFile())
3443 return F->getDirectory();
3444 return "";
3445 }
3446
3447 std::optional<StringRef> getSource() const {
3448 if (auto *F = getFile())
3449 return F->getSource();
3450 return std::nullopt;
3451 }
3452
3453 Metadata *getRawScope() const { return getOperand(0); }
3455 Metadata *getRawFile() const { return getOperand(2); }
3456 Metadata *getRawType() const { return getOperand(3); }
3457
3458 static bool classof(const Metadata *MD) {
3459 return MD->getMetadataID() == DILocalVariableKind ||
3460 MD->getMetadataID() == DIGlobalVariableKind;
3461 }
3462};
3463
3464/// DWARF expression.
3465///
3466/// This is (almost) a DWARF expression that modifies the location of a
3467/// variable, or the location of a single piece of a variable, or (when using
3468/// DW_OP_stack_value) is the constant variable value.
3469///
3470/// TODO: Co-allocate the expression elements.
3471/// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
3472/// storage types.
3473class DIExpression : public MDNode {
3474 friend class LLVMContextImpl;
3475 friend class MDNode;
3476
3477 std::vector<uint64_t> Elements;
3478
3479 DIExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
3480 : MDNode(C, DIExpressionKind, Storage, {}),
3481 Elements(Elements.begin(), Elements.end()) {}
3482 ~DIExpression() = default;
3483
3484 LLVM_ABI static DIExpression *getImpl(LLVMContext &Context,
3485 ArrayRef<uint64_t> Elements,
3487 bool ShouldCreate = true);
3488
3489 TempDIExpression cloneImpl() const {
3490 return getTemporary(getContext(), getElements());
3491 }
3492
3493public:
3494 DEFINE_MDNODE_GET(DIExpression, (ArrayRef<uint64_t> Elements), (Elements))
3495
3496 TempDIExpression clone() const { return cloneImpl(); }
3497
3498 ArrayRef<uint64_t> getElements() const { return Elements; }
3499
3500 unsigned getNumElements() const { return Elements.size(); }
3501
3502 uint64_t getElement(unsigned I) const {
3503 assert(I < Elements.size() && "Index out of range");
3504 return Elements[I];
3505 }
3506
3508 /// Determine whether this represents a constant value, if so
3509 // return it's sign information.
3510 LLVM_ABI std::optional<SignedOrUnsignedConstant> isConstant() const;
3511
3512 /// Return the number of unique location operands referred to (via
3513 /// DW_OP_LLVM_arg) in this expression; this is not necessarily the number of
3514 /// instances of DW_OP_LLVM_arg within the expression.
3515 /// For example, for the expression:
3516 /// (DW_OP_LLVM_arg 0, DW_OP_LLVM_arg 1, DW_OP_plus,
3517 /// DW_OP_LLVM_arg 0, DW_OP_mul)
3518 /// This function would return 2, as there are two unique location operands
3519 /// (0 and 1).
3521
3523
3526
3527 /// A lightweight wrapper around an expression operand.
3528 ///
3529 /// TODO: Store arguments directly and change \a DIExpression to store a
3530 /// range of these.
3532 const uint64_t *Op = nullptr;
3533
3534 public:
3535 ExprOperand() = default;
3536 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
3537
3538 explicit operator bool() const { return Op != nullptr; }
3539
3540 const uint64_t *get() const { return Op; }
3541
3542 /// Get the operand code.
3543 ///
3544 /// The operand has to be present.
3545 uint64_t getOp() const {
3546 assert(Op && "operand is not present");
3547 return *Op;
3548 }
3549
3550 /// Return true if this is \p Opcode.
3551 bool is(uint64_t Opcode) const { return getOp() == Opcode; }
3552
3553 /// Get an argument to the operand.
3554 ///
3555 /// Never returns the operand itself. The operand has to be present and \p I
3556 /// has to be less than getNumArgs().
3557 uint64_t getArg(unsigned I) const {
3558 assert(Op && "operand is not present");
3559 return Op[I + 1];
3560 }
3561
3562 unsigned getNumArgs() const { return getSize() - 1; }
3563
3564 /// Return the size of the operand.
3565 ///
3566 /// Return the number of elements in the operand (1 + args).
3567 LLVM_ABI unsigned getSize() const;
3568
3569 /// Return true if CodeGen handles this operand without adding bytes to the
3570 /// DWARF expression.
3571 LLVM_ABI bool isNonEmitting() const;
3572
3573 /// Append the elements of this operand to \p V.
3575 V.append(get(), get() + getSize());
3576 }
3577 };
3578
3579 // Typed views name an ExprOperand's arguments. Use cast<FragmentOp>(Op) for a
3580 // known opcode and dyn_cast<ArgOp>(Op) for a conditional match. A failed
3581 // dyn_cast returns an empty view, which tests false and holds no operand to
3582 // read, so check it before calling an accessor. Keep using ExprOperand for
3583 // operations without a typed view.
3584 //
3585 // A view takes an operand rather than an optional one. A cursor hands back
3586 // std::optional<ExprOperand>, so check it and then dereference it.
3587 // dyn_cast_if_present does not compile on std::optional<ExprOperand>, because
3588 // an operand is constructible from a null pointer, which leaves
3589 // ValueIsPresent ambiguous between its optional and its nullable
3590 // specialization.
3591
3592 /// A view of a DW_OP_LLVM_arg operation.
3593 class ArgOp : public ExprOperand {
3594 template <typename To, typename From, typename Enable>
3595 friend struct llvm::CastInfo;
3596
3597 explicit ArgOp(ExprOperand Op) : ExprOperand(Op) {}
3598
3599 public:
3600 /// Return the location operand index.
3601 uint64_t getIndex() const { return getArg(0); }
3602
3603 LLVM_ABI static bool classof(const ExprOperand *Op);
3604 };
3605
3606 /// A view of a DW_OP_LLVM_fragment operation.
3607 class FragmentOp : public ExprOperand {
3608 template <typename To, typename From, typename Enable>
3609 friend struct llvm::CastInfo;
3610
3611 explicit FragmentOp(ExprOperand Op) : ExprOperand(Op) {}
3612
3613 public:
3614 /// Return the fragment offset in bits.
3615 uint64_t getOffsetInBits() const { return getArg(0); }
3616
3617 /// Return the fragment size in bits.
3618 uint64_t getSizeInBits() const { return getArg(1); }
3619
3620 LLVM_ABI static bool classof(const ExprOperand *Op);
3621 };
3622
3623 /// A view of the DW_OP_LLVM_extract_bits_[sz]ext operations.
3624 class ExtractBitsOp : public ExprOperand {
3625 template <typename To, typename From, typename Enable>
3626 friend struct llvm::CastInfo;
3627
3628 explicit ExtractBitsOp(ExprOperand Op) : ExprOperand(Op) {}
3629
3630 public:
3631 /// Return the extract offset in bits.
3632 uint64_t getOffsetInBits() const { return getArg(0); }
3633
3634 /// Return the extract size in bits.
3635 uint64_t getSizeInBits() const { return getArg(1); }
3636
3637 /// Return whether the extracted value is sign-extended.
3638 LLVM_ABI bool isSigned() const;
3639
3640 LLVM_ABI static bool classof(const ExprOperand *Op);
3641 };
3642
3643 /// A view of a DW_OP_LLVM_convert operation.
3644 class ConvertOp : public ExprOperand {
3645 template <typename To, typename From, typename Enable>
3646 friend struct llvm::CastInfo;
3647
3648 explicit ConvertOp(ExprOperand Op) : ExprOperand(Op) {}
3649
3650 public:
3651 /// Return the destination size in bits.
3652 uint64_t getBitSize() const { return getArg(0); }
3653
3654 /// Return the raw destination type encoding.
3655 uint64_t getEncoding() const { return getArg(1); }
3656
3657 LLVM_ABI static bool classof(const ExprOperand *Op);
3658 };
3659
3660 /// A view of a DW_OP_LLVM_entry_value operation.
3661 class EntryValueOp : public ExprOperand {
3662 template <typename To, typename From, typename Enable>
3663 friend struct llvm::CastInfo;
3664
3665 explicit EntryValueOp(ExprOperand Op) : ExprOperand(Op) {}
3666
3667 public:
3668 /// Return the number of operations the entry value covers. The count
3669 /// includes the operation that precedes it, so the operations that follow
3670 /// are one fewer than this.
3671 uint64_t getNumOperations() const { return getArg(0); }
3672
3673 LLVM_ABI static bool classof(const ExprOperand *Op);
3674 };
3675
3676 /// A view of a DW_OP_LLVM_tag_offset operation.
3677 class TagOffsetOp : public ExprOperand {
3678 template <typename To, typename From, typename Enable>
3679 friend struct llvm::CastInfo;
3680
3681 explicit TagOffsetOp(ExprOperand Op) : ExprOperand(Op) {}
3682
3683 public:
3684 /// Return the offset a memory tag is derived from. How a target derives
3685 /// the tag from it is implementation defined.
3686 uint64_t getTagOffset() const { return getArg(0); }
3687
3688 LLVM_ABI static bool classof(const ExprOperand *Op);
3689 };
3690
3691 /// A view of a DW_OP_constu operation.
3692 class ConstuOp : public ExprOperand {
3693 template <typename To, typename From, typename Enable>
3694 friend struct llvm::CastInfo;
3695
3696 explicit ConstuOp(ExprOperand Op) : ExprOperand(Op) {}
3697
3698 public:
3699 /// Return the unsigned constant value.
3700 uint64_t getValue() const { return getArg(0); }
3701
3702 LLVM_ABI static bool classof(const ExprOperand *Op);
3703 };
3704
3705 /// A view of a DW_OP_plus_uconst operation.
3706 class PlusUconstOp : public ExprOperand {
3707 template <typename To, typename From, typename Enable>
3708 friend struct llvm::CastInfo;
3709
3710 explicit PlusUconstOp(ExprOperand Op) : ExprOperand(Op) {}
3711
3712 public:
3713 /// Return the unsigned offset.
3714 uint64_t getOffset() const { return getArg(0); }
3715
3716 LLVM_ABI static bool classof(const ExprOperand *Op);
3717 };
3718
3719 /// An iterator for expression operands.
3721 ExprOperand Op;
3722
3723 public:
3724 using iterator_category = std::input_iterator_tag;
3726 using difference_type = std::ptrdiff_t;
3729
3730 expr_op_iterator() = default;
3732
3733 element_iterator getBase() const { return Op.get(); }
3734 const ExprOperand &operator*() const { return Op; }
3735 const ExprOperand *operator->() const { return &Op; }
3736
3738 increment();
3739 return *this;
3740 }
3742 expr_op_iterator T(*this);
3743 increment();
3744 return T;
3745 }
3746
3747 /// Get the next iterator.
3748 ///
3749 /// \a std::next() doesn't work because this is technically an
3750 /// input_iterator, but it's a perfectly valid operation. This is an
3751 /// accessor to provide the same functionality.
3752 expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
3753
3754 bool operator==(const expr_op_iterator &X) const {
3755 return getBase() == X.getBase();
3756 }
3757 bool operator!=(const expr_op_iterator &X) const {
3758 return getBase() != X.getBase();
3759 }
3760
3761 private:
3762 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
3763 };
3764
3765 /// Visit the elements via ExprOperand wrappers.
3766 ///
3767 /// These range iterators visit elements through \a ExprOperand wrappers.
3768 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
3769 /// true.
3770 ///
3771 /// \pre \a isValid() gives \c true.
3772 /// @{
3782 /// @}
3783
3784 LLVM_ABI bool isValid() const;
3785
3786 static bool classof(const Metadata *MD) {
3787 return MD->getMetadataID() == DIExpressionKind;
3788 }
3789
3790 /// Return whether the first element a DW_OP_deref.
3791 LLVM_ABI bool startsWithDeref() const;
3792
3793 /// Return whether there is exactly one operator and it is a DW_OP_deref;
3794 LLVM_ABI bool isDeref() const;
3795
3797
3798 /// Return the number of bits that have an active value, i.e. those that
3799 /// aren't known to be zero/sign (depending on the type of Var) and which
3800 /// are within the size of this fragment (if it is one). If we can't deduce
3801 /// anything from the expression this will return the size of Var.
3802 LLVM_ABI std::optional<uint64_t> getActiveBits(DIVariable *Var);
3803
3804 /// Retrieve the details of this fragment expression.
3805 LLVM_ABI static std::optional<FragmentInfo>
3807
3808 /// Retrieve the details of this fragment expression.
3809 std::optional<FragmentInfo> getFragmentInfo() const {
3811 }
3812
3813 /// Return whether this is a piece of an aggregate variable.
3814 bool isFragment() const { return getFragmentInfo().has_value(); }
3815
3816 /// Return whether this is an implicit location description.
3817 LLVM_ABI bool isImplicit() const;
3818
3819 /// Return whether the location is computed on the expression stack, meaning
3820 /// it cannot be a simple register location.
3821 LLVM_ABI bool isComplex() const;
3822
3823 /// Return whether the evaluated expression makes use of a single location at
3824 /// the start of the expression, i.e. if it contains only a single
3825 /// DW_OP_LLVM_arg op as its first operand, or if it contains none.
3827
3828 /// Returns a reference to the elements contained in this expression, skipping
3829 /// past the leading `DW_OP_LLVM_arg, 0` if one is present.
3830 /// Similar to `convertToNonVariadicExpression`, but faster and cheaper - it
3831 /// does not check whether the expression is a single-location expression, and
3832 /// it returns elements rather than creating a new DIExpression.
3833 LLVM_ABI std::optional<ArrayRef<uint64_t>>
3835
3836 /// Removes all elements from \p Expr that do not apply to an undef debug
3837 /// value, which includes every operator that computes the value/location on
3838 /// the DWARF stack, including any DW_OP_LLVM_arg elements (making the result
3839 /// of this function always a single-location expression) while leaving
3840 /// everything that defines what the computed value applies to, i.e. the
3841 /// fragment information.
3842 LLVM_ABI static const DIExpression *
3844
3845 /// If \p Expr is a non-variadic expression (i.e. one that does not contain
3846 /// DW_OP_LLVM_arg), returns \p Expr converted to variadic form by adding a
3847 /// leading [DW_OP_LLVM_arg, 0] to the expression; otherwise returns \p Expr.
3848 LLVM_ABI static const DIExpression *
3850
3851 /// If \p Expr is a valid single-location expression, i.e. it refers to only a
3852 /// single debug operand at the start of the expression, then return that
3853 /// expression in a non-variadic form by removing DW_OP_LLVM_arg from the
3854 /// expression if it is present; otherwise returns std::nullopt.
3855 /// See also `getSingleLocationExpressionElements` above, which skips
3856 /// checking `isSingleLocationExpression` and returns a list of elements
3857 /// rather than a DIExpression.
3858 LLVM_ABI static std::optional<const DIExpression *>
3860
3861 /// Inserts the elements of \p Expr into \p Ops modified to a canonical form,
3862 /// which uses DW_OP_LLVM_arg (i.e. is a variadic expression) and folds the
3863 /// implied derefence from the \p IsIndirect flag into the expression. This
3864 /// allows us to check equivalence between expressions with differing
3865 /// directness or variadicness.
3867 const DIExpression *Expr,
3868 bool IsIndirect);
3869
3870 /// Determines whether two debug values should produce equivalent DWARF
3871 /// expressions, using their DIExpressions and directness, ignoring the
3872 /// differences between otherwise identical expressions in variadic and
3873 /// non-variadic form and not considering the debug operands.
3874 /// \p FirstExpr is the DIExpression for the first debug value.
3875 /// \p FirstIndirect should be true if the first debug value is indirect; in
3876 /// IR this should be true for dbg.declare intrinsics and false for
3877 /// dbg.values, and in MIR this should be true only for DBG_VALUE instructions
3878 /// whose second operand is an immediate value.
3879 /// \p SecondExpr and \p SecondIndirect have the same meaning as the prior
3880 /// arguments, but apply to the second debug value.
3881 LLVM_ABI static bool isEqualExpression(const DIExpression *FirstExpr,
3882 bool FirstIndirect,
3883 const DIExpression *SecondExpr,
3884 bool SecondIndirect);
3885
3886 /// Append \p Ops with operations to apply the \p Offset.
3888 int64_t Offset);
3889
3890 LLVM_ABI static bool
3891 extractLeadingOffset(ArrayRef<uint64_t> Ops, int64_t &OffsetInBytes,
3892 SmallVectorImpl<uint64_t> &RemainingOps);
3893
3894 /// If this is a constant offset, extract it. If there is no expression,
3895 /// return true with an offset of zero.
3896 LLVM_ABI bool extractIfOffset(int64_t &Offset) const;
3897
3898 /// Assuming that the expression operates on an address, extract a constant
3899 /// offset and the successive ops. Return false if the expression contains
3900 /// any incompatible ops (including non-zero DW_OP_LLVM_args - only a single
3901 /// address operand to the expression is permitted).
3902 ///
3903 /// We don't try very hard to interpret the expression because we assume that
3904 /// foldConstantMath has canonicalized the expression.
3905 LLVM_ABI bool
3906 extractLeadingOffset(int64_t &OffsetInBytes,
3907 SmallVectorImpl<uint64_t> &RemainingOps) const;
3908
3909 /// Returns true iff this DIExpression contains at least one instance of
3910 /// `DW_OP_LLVM_arg, n` for all n in [0, N).
3911 LLVM_ABI bool hasAllLocationOps(unsigned N) const;
3912
3913 /// Checks if the last 4 elements of the expression are DW_OP_constu <DWARF
3914 /// Address Space> DW_OP_swap DW_OP_xderef and extracts the <DWARF Address
3915 /// Space>.
3916 LLVM_ABI static const DIExpression *
3917 extractAddressClass(const DIExpression *Expr, unsigned &AddrClass);
3918
3919 /// Used for DIExpression::prepend.
3922 DerefBefore = 1 << 0,
3923 DerefAfter = 1 << 1,
3924 StackValue = 1 << 2,
3925 EntryValue = 1 << 3
3926 };
3927
3928 /// Prepend \p DIExpr with a deref and offset operation and optionally turn it
3929 /// into a stack value or/and an entry value.
3930 LLVM_ABI static DIExpression *prepend(const DIExpression *Expr, uint8_t Flags,
3931 int64_t Offset = 0);
3932
3933 /// Prepend \p DIExpr with the given opcodes and optionally turn it into a
3934 /// stack value.
3937 bool StackValue = false,
3938 bool EntryValue = false);
3939
3940 /// Append the opcodes \p Ops to \p DIExpr. Unlike \ref appendToStack, the
3941 /// returned expression is a stack value only if \p DIExpr is a stack value.
3942 /// If \p DIExpr describes a fragment, the returned expression will describe
3943 /// the same fragment.
3944 LLVM_ABI static DIExpression *append(const DIExpression *Expr,
3946
3947 /// Convert \p DIExpr into a stack value if it isn't one already by appending
3948 /// DW_OP_deref if needed, and appending \p Ops to the resulting expression.
3949 /// If \p DIExpr describes a fragment, the returned expression will describe
3950 /// the same fragment.
3951 LLVM_ABI static DIExpression *appendToStack(const DIExpression *Expr,
3953
3954 /// Create a copy of \p Expr by appending the given list of \p Ops to each
3955 /// instance of the operand `DW_OP_LLVM_arg, \p ArgNo`. This is used to
3956 /// modify a specific location used by \p Expr, such as when salvaging that
3957 /// location.
3960 unsigned ArgNo,
3961 bool StackValue = false);
3962
3963 /// Create a copy of \p Expr with each instance of
3964 /// `DW_OP_LLVM_arg, \p OldArg` replaced with `DW_OP_LLVM_arg, \p NewArg`,
3965 /// and each instance of `DW_OP_LLVM_arg, Arg` with `DW_OP_LLVM_arg, Arg - 1`
3966 /// for all Arg > \p OldArg.
3967 /// This is used when replacing one of the operands of a debug value list
3968 /// with another operand in the same list and deleting the old operand.
3969 LLVM_ABI static DIExpression *replaceArg(const DIExpression *Expr,
3970 uint64_t OldArg, uint64_t NewArg);
3971
3972 /// Create a DIExpression to describe one part of an aggregate variable that
3973 /// is fragmented across multiple Values. The DW_OP_LLVM_fragment operation
3974 /// will be appended to the elements of \c Expr. If \c Expr already contains
3975 /// a \c DW_OP_LLVM_fragment \c OffsetInBits is interpreted as an offset
3976 /// into the existing fragment.
3977 ///
3978 /// \param OffsetInBits Offset of the piece in bits.
3979 /// \param SizeInBits Size of the piece in bits.
3980 /// \return Creating a fragment expression may fail if \c Expr
3981 /// contains arithmetic operations that would be
3982 /// truncated.
3983 LLVM_ABI static std::optional<DIExpression *>
3984 createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits,
3985 unsigned SizeInBits);
3986
3987 /// Determine the relative position of the fragments passed in.
3988 /// Returns -1 if this is entirely before Other, 0 if this and Other overlap,
3989 /// 1 if this is entirely after Other.
3990 static int fragmentCmp(const FragmentInfo &A, const FragmentInfo &B) {
3991 uint64_t l1 = A.OffsetInBits;
3992 uint64_t l2 = B.OffsetInBits;
3993 uint64_t r1 = l1 + A.SizeInBits;
3994 uint64_t r2 = l2 + B.SizeInBits;
3995 if (r1 <= l2)
3996 return -1;
3997 else if (r2 <= l1)
3998 return 1;
3999 else
4000 return 0;
4001 }
4002
4003 /// Computes a fragment, bit-extract operation if needed, and new constant
4004 /// offset to describe a part of a variable covered by some memory.
4005 ///
4006 /// The memory region starts at:
4007 /// \p SliceStart + \p SliceOffsetInBits
4008 /// And is size:
4009 /// \p SliceSizeInBits
4010 ///
4011 /// The location of the existing variable fragment \p VarFrag is:
4012 /// \p DbgPtr + \p DbgPtrOffsetInBits + \p DbgExtractOffsetInBits.
4013 ///
4014 /// It is intended that these arguments are derived from a debug record:
4015 /// - \p DbgPtr is the (single) DIExpression operand.
4016 /// - \p DbgPtrOffsetInBits is the constant offset applied to \p DbgPtr.
4017 /// - \p DbgExtractOffsetInBits is the offset from a
4018 /// DW_OP_LLVM_bit_extract_[sz]ext operation.
4019 ///
4020 /// Results and return value:
4021 /// - Return false if the result can't be calculated for any reason.
4022 /// - \p Result is set to nullopt if the intersect equals \p VarFrag.
4023 /// - \p Result contains a zero-sized fragment if there's no intersect.
4024 /// - \p OffsetFromLocationInBits is set to the difference between the first
4025 /// bit of the variable location and the first bit of the slice. The
4026 /// magnitude of a negative value therefore indicates the number of bits
4027 /// into the variable fragment that the memory region begins.
4028 ///
4029 /// We don't pass in a debug record directly to get the constituent parts
4030 /// and offsets because different debug records store the information in
4031 /// different places (dbg_assign has two DIExpressions - one contains the
4032 /// fragment info for the entire intrinsic).
4034 const DataLayout &DL, const Value *SliceStart, uint64_t SliceOffsetInBits,
4035 uint64_t SliceSizeInBits, const Value *DbgPtr, int64_t DbgPtrOffsetInBits,
4036 int64_t DbgExtractOffsetInBits, DIExpression::FragmentInfo VarFrag,
4037 std::optional<DIExpression::FragmentInfo> &Result,
4038 int64_t &OffsetFromLocationInBits);
4039
4040 using ExtOps = std::array<uint64_t, 6>;
4041
4042 /// Returns the ops for a zero- or sign-extension in a DIExpression.
4043 LLVM_ABI static ExtOps getExtOps(unsigned FromSize, unsigned ToSize,
4044 bool Signed);
4045
4046 /// Append a zero- or sign-extension to \p Expr. Converts the expression to a
4047 /// stack value if it isn't one already.
4048 LLVM_ABI static DIExpression *appendExt(const DIExpression *Expr,
4049 unsigned FromSize, unsigned ToSize,
4050 bool Signed);
4051
4052 /// Check if fragments overlap between a pair of FragmentInfos.
4053 static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B) {
4054 return fragmentCmp(A, B) == 0;
4055 }
4056
4057 /// Determine the relative position of the fragments described by this
4058 /// DIExpression and \p Other. Calls static fragmentCmp implementation.
4059 int fragmentCmp(const DIExpression *Other) const {
4060 auto Fragment1 = *getFragmentInfo();
4061 auto Fragment2 = *Other->getFragmentInfo();
4062 return fragmentCmp(Fragment1, Fragment2);
4063 }
4064
4065 /// Check if fragments overlap between this DIExpression and \p Other.
4066 bool fragmentsOverlap(const DIExpression *Other) const {
4067 if (!isFragment() || !Other->isFragment())
4068 return true;
4069 return fragmentCmp(Other) == 0;
4070 }
4071
4072 /// Check if the expression consists of exactly one entry value operand.
4073 /// (This is the only configuration of entry values that is supported.)
4074 LLVM_ABI bool isEntryValue() const;
4075
4076 /// Try to shorten an expression with an initial constant operand.
4077 /// Returns a new expression and constant on success, or the original
4078 /// expression and constant on failure.
4079 LLVM_ABI std::pair<DIExpression *, const ConstantInt *>
4080 constantFold(const ConstantInt *CI);
4081
4082 /// Try to shorten an expression with constant math operations that can be
4083 /// evaluated at compile time. Returns a new expression on success, or the old
4084 /// expression if there is nothing to be reduced.
4086};
4087
4088template <typename To, typename From>
4090 To, From,
4091 std::enable_if_t<
4092 std::is_same_v<std::remove_const_t<From>, DIExpression::ExprOperand> &&
4093 !std::is_same_v<std::remove_const_t<To>, DIExpression::ExprOperand>>>
4094 : CastIsPossible<To, From>,
4095 DefaultDoCastIfPossible<To, From, CastInfo<To, From>> {
4096 static To doCast(const From &Op) { return To(Op); }
4097 static To castFailed() { return To(DIExpression::ExprOperand()); }
4098};
4099
4100/// Treat a default-constructed expression operand as absent.
4101template <> struct ValueIsPresent<DIExpression::ExprOperand> {
4103
4105 return bool(Op);
4106 }
4107
4111};
4112
4115 return std::tie(A.SizeInBits, A.OffsetInBits) ==
4116 std::tie(B.SizeInBits, B.OffsetInBits);
4117}
4118
4121 return std::tie(A.SizeInBits, A.OffsetInBits) <
4122 std::tie(B.SizeInBits, B.OffsetInBits);
4123}
4124
4125template <> struct DenseMapInfo<DIExpression::FragmentInfo> {
4127 static const uint64_t MaxVal = std::numeric_limits<uint64_t>::max();
4128
4129 static unsigned getHashValue(const FragInfo &Frag) {
4130 return (Frag.SizeInBits & 0xffff) << 16 | (Frag.OffsetInBits & 0xffff);
4131 }
4132
4133 static bool isEqual(const FragInfo &A, const FragInfo &B) { return A == B; }
4134};
4135
4136/// Holds a DIExpression and keeps track of how many operands have been consumed
4137/// so far.
4140
4141public:
4143 if (!Expr) {
4144 assert(Start == End);
4145 return;
4146 }
4147 Start = Expr->expr_op_begin();
4148 End = Expr->expr_op_end();
4149 }
4150
4152 : Start(Expr.begin()), End(Expr.end()) {}
4153
4155
4156 /// Consume one operation.
4157 std::optional<DIExpression::ExprOperand> take() {
4158 if (Start == End)
4159 return std::nullopt;
4160 return *(Start++);
4161 }
4162
4163 /// Consume N operations.
4164 void consume(unsigned N) { std::advance(Start, N); }
4165
4166 /// Return the current operation.
4167 std::optional<DIExpression::ExprOperand> peek() const {
4168 if (Start == End)
4169 return std::nullopt;
4170 return *(Start);
4171 }
4172
4173 /// Return the next operation.
4174 std::optional<DIExpression::ExprOperand> peekNext() const {
4175 if (Start == End)
4176 return std::nullopt;
4177
4178 auto Next = Start.getNext();
4179 if (Next == End)
4180 return std::nullopt;
4181
4182 return *Next;
4183 }
4184
4185 std::optional<DIExpression::ExprOperand> peekNextN(unsigned N) const {
4186 if (Start == End)
4187 return std::nullopt;
4189 for (unsigned I = 0; I < N; I++) {
4190 Nth = Nth.getNext();
4191 if (Nth == End)
4192 return std::nullopt;
4193 }
4194 return *Nth;
4195 }
4196
4198 this->Start = DIExpression::expr_op_iterator(Expr.begin());
4199 this->End = DIExpression::expr_op_iterator(Expr.end());
4200 }
4201
4202 /// Determine whether there are any operations left in this expression.
4203 operator bool() const { return Start != End; }
4204
4205 DIExpression::expr_op_iterator begin() const { return Start; }
4206 DIExpression::expr_op_iterator end() const { return End; }
4207
4208 /// Retrieve the fragment information, if any.
4209 std::optional<DIExpression::FragmentInfo> getFragmentInfo() const {
4210 return DIExpression::getFragmentInfo(Start, End);
4211 }
4212};
4213
4214/// Global variables.
4215///
4216/// TODO: Remove DisplayName. It's always equal to Name.
4217class DIGlobalVariable : public DIVariable {
4218 friend class LLVMContextImpl;
4219 friend class MDNode;
4220
4221 bool IsLocalToUnit;
4222 bool IsDefinition;
4223
4224 DIGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
4225 bool IsLocalToUnit, bool IsDefinition, uint32_t AlignInBits,
4227 : DIVariable(C, DIGlobalVariableKind, Storage, Line, Ops, AlignInBits),
4228 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
4229 ~DIGlobalVariable() = default;
4230
4231 static DIGlobalVariable *
4232 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
4233 StringRef LinkageName, DIFile *File, unsigned Line, DIType *Type,
4234 bool IsLocalToUnit, bool IsDefinition,
4237 bool ShouldCreate = true) {
4238 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
4239 getCanonicalMDString(Context, LinkageName), File, Line, Type,
4242 Annotations.get(), Storage, ShouldCreate);
4243 }
4244 LLVM_ABI static DIGlobalVariable *
4245 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
4246 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
4247 bool IsLocalToUnit, bool IsDefinition,
4250 bool ShouldCreate = true);
4251
4252 TempDIGlobalVariable cloneImpl() const {
4257 getAnnotations());
4258 }
4259
4260public:
4262 DIGlobalVariable,
4264 unsigned Line, DIType *Type, bool IsLocalToUnit, bool IsDefinition,
4266 uint32_t AlignInBits, DINodeArray Annotations),
4267 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
4270 DIGlobalVariable,
4272 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
4275 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
4277
4278 TempDIGlobalVariable clone() const { return cloneImpl(); }
4279
4280 bool isLocalToUnit() const { return IsLocalToUnit; }
4281 bool isDefinition() const { return IsDefinition; }
4287 DINodeArray getAnnotations() const {
4289 }
4290
4295 Metadata *getRawAnnotations() const { return getOperand(8); }
4296
4297 static bool classof(const Metadata *MD) {
4298 return MD->getMetadataID() == DIGlobalVariableKind;
4299 }
4300};
4301
4302/// Debug common block.
4303///
4304/// Uses the SubclassData32 Metadata slot.
4305class DICommonBlock : public DIScope {
4306 friend class LLVMContextImpl;
4307 friend class MDNode;
4308
4309 DICommonBlock(LLVMContext &Context, StorageType Storage, unsigned LineNo,
4311
4312 static DICommonBlock *getImpl(LLVMContext &Context, DIScope *Scope,
4314 DIFile *File, unsigned LineNo,
4315 StorageType Storage, bool ShouldCreate = true) {
4316 return getImpl(Context, Scope, Decl, getCanonicalMDString(Context, Name),
4317 File, LineNo, Storage, ShouldCreate);
4318 }
4319 LLVM_ABI static DICommonBlock *getImpl(LLVMContext &Context, Metadata *Scope,
4321 Metadata *File, unsigned LineNo,
4323 bool ShouldCreate = true);
4324
4325 TempDICommonBlock cloneImpl() const {
4327 getFile(), getLineNo());
4328 }
4329
4330public:
4331 DEFINE_MDNODE_GET(DICommonBlock,
4333 DIFile *File, unsigned LineNo),
4334 (Scope, Decl, Name, File, LineNo))
4335 DEFINE_MDNODE_GET(DICommonBlock,
4337 Metadata *File, unsigned LineNo),
4339
4340 TempDICommonBlock clone() const { return cloneImpl(); }
4341
4346 StringRef getName() const { return getStringOperand(2); }
4348 unsigned getLineNo() const { return SubclassData32; }
4349
4350 Metadata *getRawScope() const { return getOperand(0); }
4351 Metadata *getRawDecl() const { return getOperand(1); }
4353 Metadata *getRawFile() const { return getOperand(3); }
4354
4355 static bool classof(const Metadata *MD) {
4356 return MD->getMetadataID() == DICommonBlockKind;
4357 }
4358};
4359
4360/// Local variable.
4361///
4362/// TODO: Split up flags.
4363class DILocalVariable : public DIVariable {
4364 friend class LLVMContextImpl;
4365 friend class MDNode;
4366
4367 unsigned Arg : 16;
4368 DIFlags Flags;
4369
4370 DILocalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
4371 unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
4373 : DIVariable(C, DILocalVariableKind, Storage, Line, Ops, AlignInBits),
4374 Arg(Arg), Flags(Flags) {
4375 assert(Arg < (1 << 16) && "DILocalVariable: Arg out of range");
4376 }
4377 ~DILocalVariable() = default;
4378
4379 static DILocalVariable *getImpl(LLVMContext &Context, DIScope *Scope,
4380 StringRef Name, DIFile *File, unsigned Line,
4381 DIType *Type, unsigned Arg, DIFlags Flags,
4382 uint32_t AlignInBits, DINodeArray Annotations,
4384 bool ShouldCreate = true) {
4385 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
4386 Line, Type, Arg, Flags, AlignInBits, Annotations.get(),
4387 Storage, ShouldCreate);
4388 }
4389 LLVM_ABI static DILocalVariable *
4390 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, Metadata *File,
4391 unsigned Line, Metadata *Type, unsigned Arg, DIFlags Flags,
4393 bool ShouldCreate = true);
4394
4395 TempDILocalVariable cloneImpl() const {
4397 getLine(), getType(), getArg(), getFlags(),
4399 }
4400
4401public:
4402 DEFINE_MDNODE_GET(DILocalVariable,
4404 unsigned Line, DIType *Type, unsigned Arg, DIFlags Flags,
4405 uint32_t AlignInBits, DINodeArray Annotations),
4406 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits,
4407 Annotations))
4408 DEFINE_MDNODE_GET(DILocalVariable,
4410 unsigned Line, Metadata *Type, unsigned Arg, DIFlags Flags,
4412 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits,
4413 Annotations))
4414
4415 TempDILocalVariable clone() const { return cloneImpl(); }
4416
4417 /// Get the local scope for this variable.
4418 ///
4419 /// Variables must be defined in a local scope.
4423
4424 bool isParameter() const { return Arg; }
4425 unsigned getArg() const { return Arg; }
4426 DIFlags getFlags() const { return Flags; }
4427
4428 DINodeArray getAnnotations() const {
4430 }
4431 Metadata *getRawAnnotations() const { return getOperand(4); }
4432
4433 bool isArtificial() const { return getFlags() & FlagArtificial; }
4434 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
4435
4436 /// Check that a location is valid for this variable.
4437 ///
4438 /// Check that \c DL exists, is in the same subprogram, and has the same
4439 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
4440 /// to a \a DbgInfoIntrinsic.)
4442 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
4443 }
4444
4445 static bool classof(const Metadata *MD) {
4446 return MD->getMetadataID() == DILocalVariableKind;
4447 }
4448};
4449
4450/// Label.
4451///
4452/// Uses the SubclassData32 Metadata slot.
4453class DILabel : public DINode {
4454 friend class LLVMContextImpl;
4455 friend class MDNode;
4456
4457 unsigned Column;
4458 std::optional<unsigned> CoroSuspendIdx;
4459 bool IsArtificial;
4460
4461 DILabel(LLVMContext &C, StorageType Storage, unsigned Line, unsigned Column,
4462 bool IsArtificial, std::optional<unsigned> CoroSuspendIdx,
4464 ~DILabel() = default;
4465
4466 static DILabel *getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
4467 DIFile *File, unsigned Line, unsigned Column,
4468 bool IsArtificial,
4469 std::optional<unsigned> CoroSuspendIdx,
4470 StorageType Storage, bool ShouldCreate = true) {
4471 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
4472 Line, Column, IsArtificial, CoroSuspendIdx, Storage,
4473 ShouldCreate);
4474 }
4475 LLVM_ABI static DILabel *
4476 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, Metadata *File,
4477 unsigned Line, unsigned Column, bool IsArtificial,
4478 std::optional<unsigned> CoroSuspendIdx, StorageType Storage,
4479 bool ShouldCreate = true);
4480
4481 TempDILabel cloneImpl() const {
4485 }
4486
4487public:
4490 unsigned Line, unsigned Column, bool IsArtificial,
4491 std::optional<unsigned> CoroSuspendIdx),
4492 (Scope, Name, File, Line, Column, IsArtificial,
4493 CoroSuspendIdx))
4494 DEFINE_MDNODE_GET(DILabel,
4496 unsigned Line, unsigned Column, bool IsArtificial,
4497 std::optional<unsigned> CoroSuspendIdx),
4498 (Scope, Name, File, Line, Column, IsArtificial,
4499 CoroSuspendIdx))
4500
4501 TempDILabel clone() const { return cloneImpl(); }
4502
4503 /// Get the local scope for this label.
4504 ///
4505 /// Labels must be defined in a local scope.
4509 unsigned getLine() const { return SubclassData32; }
4510 unsigned getColumn() const { return Column; }
4511 StringRef getName() const { return getStringOperand(1); }
4513 bool isArtificial() const { return IsArtificial; }
4514 std::optional<unsigned> getCoroSuspendIdx() const { return CoroSuspendIdx; }
4515
4516 Metadata *getRawScope() const { return getOperand(0); }
4518 Metadata *getRawFile() const { return getOperand(2); }
4519
4520 /// Check that a location is valid for this label.
4521 ///
4522 /// Check that \c DL exists, is in the same subprogram, and has the same
4523 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
4524 /// to a \a DbgInfoIntrinsic.)
4526 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
4527 }
4528
4529 static bool classof(const Metadata *MD) {
4530 return MD->getMetadataID() == DILabelKind;
4531 }
4532};
4533
4534class DIObjCProperty : public DINode {
4535 friend class LLVMContextImpl;
4536 friend class MDNode;
4537
4538 unsigned Line;
4539 unsigned Attributes;
4540
4541 DIObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
4542 unsigned Attributes, ArrayRef<Metadata *> Ops);
4543 ~DIObjCProperty() = default;
4544
4545 static DIObjCProperty *
4546 getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
4547 StringRef GetterName, StringRef SetterName, unsigned Attributes,
4548 DIType *Type, StorageType Storage, bool ShouldCreate = true) {
4549 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
4551 getCanonicalMDString(Context, SetterName), Attributes, Type,
4552 Storage, ShouldCreate);
4553 }
4554 LLVM_ABI static DIObjCProperty *
4555 getImpl(LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
4556 MDString *GetterName, MDString *SetterName, unsigned Attributes,
4557 Metadata *Type, StorageType Storage, bool ShouldCreate = true);
4558
4559 TempDIObjCProperty cloneImpl() const {
4560 return getTemporary(getContext(), getName(), getFile(), getLine(),
4562 getType());
4563 }
4564
4565public:
4566 DEFINE_MDNODE_GET(DIObjCProperty,
4567 (StringRef Name, DIFile *File, unsigned Line,
4569 unsigned Attributes, DIType *Type),
4570 (Name, File, Line, GetterName, SetterName, Attributes,
4571 Type))
4572 DEFINE_MDNODE_GET(DIObjCProperty,
4573 (MDString * Name, Metadata *File, unsigned Line,
4575 unsigned Attributes, Metadata *Type),
4576 (Name, File, Line, GetterName, SetterName, Attributes,
4577 Type))
4578
4579 TempDIObjCProperty clone() const { return cloneImpl(); }
4580
4581 unsigned getLine() const { return Line; }
4582 unsigned getAttributes() const { return Attributes; }
4583 StringRef getName() const { return getStringOperand(0); }
4588
4590 if (auto *F = getFile())
4591 return F->getFilename();
4592 return "";
4593 }
4594
4596 if (auto *F = getFile())
4597 return F->getDirectory();
4598 return "";
4599 }
4600
4602 Metadata *getRawFile() const { return getOperand(1); }
4605 Metadata *getRawType() const { return getOperand(4); }
4606
4607 static bool classof(const Metadata *MD) {
4608 return MD->getMetadataID() == DIObjCPropertyKind;
4609 }
4610};
4611
4612/// An imported module (C++ using directive or similar).
4613///
4614/// Uses the SubclassData32 Metadata slot.
4615class DIImportedEntity : public DINode {
4616 friend class LLVMContextImpl;
4617 friend class MDNode;
4618
4619 DIImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
4620 unsigned Line, ArrayRef<Metadata *> Ops)
4621 : DINode(C, DIImportedEntityKind, Storage, Tag, Ops) {
4623 }
4624 ~DIImportedEntity() = default;
4625
4626 static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
4627 DIScope *Scope, DINode *Entity, DIFile *File,
4628 unsigned Line, StringRef Name,
4629 DINodeArray Elements, StorageType Storage,
4630 bool ShouldCreate = true) {
4631 return getImpl(Context, Tag, Scope, Entity, File, Line,
4632 getCanonicalMDString(Context, Name), Elements.get(), Storage,
4633 ShouldCreate);
4634 }
4635 LLVM_ABI static DIImportedEntity *
4636 getImpl(LLVMContext &Context, unsigned Tag, Metadata *Scope, Metadata *Entity,
4637 Metadata *File, unsigned Line, MDString *Name, Metadata *Elements,
4638 StorageType Storage, bool ShouldCreate = true);
4639
4640 TempDIImportedEntity cloneImpl() const {
4641 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
4642 getFile(), getLine(), getName(), getElements());
4643 }
4644
4645public:
4646 DEFINE_MDNODE_GET(DIImportedEntity,
4647 (unsigned Tag, DIScope *Scope, DINode *Entity, DIFile *File,
4648 unsigned Line, StringRef Name = "",
4649 DINodeArray Elements = nullptr),
4650 (Tag, Scope, Entity, File, Line, Name, Elements))
4651 DEFINE_MDNODE_GET(DIImportedEntity,
4654 Metadata *Elements = nullptr),
4655 (Tag, Scope, Entity, File, Line, Name, Elements))
4656
4657 TempDIImportedEntity clone() const { return cloneImpl(); }
4658
4659 unsigned getLine() const { return SubclassData32; }
4660 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
4661 DINode *getEntity() const { return cast_or_null<DINode>(getRawEntity()); }
4662 StringRef getName() const { return getStringOperand(2); }
4663 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
4664 DINodeArray getElements() const {
4665 return cast_or_null<MDTuple>(getRawElements());
4666 }
4667
4668 Metadata *getRawScope() const { return getOperand(0); }
4669 Metadata *getRawEntity() const { return getOperand(1); }
4670 MDString *getRawName() const { return getOperandAs<MDString>(2); }
4671 Metadata *getRawFile() const { return getOperand(3); }
4672 Metadata *getRawElements() const { return getOperand(4); }
4673
4674 static bool classof(const Metadata *MD) {
4675 return MD->getMetadataID() == DIImportedEntityKind;
4676 }
4677};
4678
4679/// A pair of DIGlobalVariable and DIExpression.
4680class DIGlobalVariableExpression : public MDNode {
4681 friend class LLVMContextImpl;
4682 friend class MDNode;
4683
4684 DIGlobalVariableExpression(LLVMContext &C, StorageType Storage,
4686 : MDNode(C, DIGlobalVariableExpressionKind, Storage, Ops) {}
4687 ~DIGlobalVariableExpression() = default;
4688
4690 getImpl(LLVMContext &Context, Metadata *Variable, Metadata *Expression,
4691 StorageType Storage, bool ShouldCreate = true);
4692
4693 TempDIGlobalVariableExpression cloneImpl() const {
4695 }
4696
4697public:
4698 DEFINE_MDNODE_GET(DIGlobalVariableExpression,
4699 (Metadata * Variable, Metadata *Expression),
4700 (Variable, Expression))
4701
4702 TempDIGlobalVariableExpression clone() const { return cloneImpl(); }
4703
4704 Metadata *getRawVariable() const { return getOperand(0); }
4705
4709
4710 Metadata *getRawExpression() const { return getOperand(1); }
4711
4715
4716 static bool classof(const Metadata *MD) {
4717 return MD->getMetadataID() == DIGlobalVariableExpressionKind;
4718 }
4719};
4720
4721/// Macro Info DWARF-like metadata node.
4722///
4723/// A metadata node with a DWARF macro info (i.e., a constant named
4724/// \c DW_MACINFO_*, defined in llvm/BinaryFormat/Dwarf.h). Called \a
4725/// DIMacroNode
4726/// because it's potentially used for non-DWARF output.
4727///
4728/// Uses the SubclassData16 Metadata slot.
4729class DIMacroNode : public MDNode {
4730 friend class LLVMContextImpl;
4731 friend class MDNode;
4732
4733protected:
4734 DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType,
4736 : MDNode(C, ID, Storage, Ops1, Ops2) {
4737 assert(MIType < 1u << 16);
4738 SubclassData16 = MIType;
4739 }
4740 ~DIMacroNode() = default;
4741
4742 template <class Ty> Ty *getOperandAs(unsigned I) const {
4743 return cast_or_null<Ty>(getOperand(I));
4744 }
4745
4746 StringRef getStringOperand(unsigned I) const {
4747 if (auto *S = getOperandAs<MDString>(I))
4748 return S->getString();
4749 return StringRef();
4750 }
4751
4753 if (S.empty())
4754 return nullptr;
4755 return MDString::get(Context, S);
4756 }
4757
4758public:
4759 unsigned getMacinfoType() const { return SubclassData16; }
4760
4761 static bool classof(const Metadata *MD) {
4762 switch (MD->getMetadataID()) {
4763 default:
4764 return false;
4765 case DIMacroKind:
4766 case DIMacroFileKind:
4767 return true;
4768 }
4769 }
4770};
4771
4772/// Macro
4773///
4774/// Uses the SubclassData32 Metadata slot.
4775class DIMacro : public DIMacroNode {
4776 friend class LLVMContextImpl;
4777 friend class MDNode;
4778
4779 DIMacro(LLVMContext &C, StorageType Storage, unsigned MIType, unsigned Line,
4781 : DIMacroNode(C, DIMacroKind, Storage, MIType, Ops) {
4783 }
4784 ~DIMacro() = default;
4785
4786 static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
4788 bool ShouldCreate = true) {
4789 return getImpl(Context, MIType, Line, getCanonicalMDString(Context, Name),
4790 getCanonicalMDString(Context, Value), Storage, ShouldCreate);
4791 }
4792 LLVM_ABI static DIMacro *getImpl(LLVMContext &Context, unsigned MIType,
4793 unsigned Line, MDString *Name,
4794 MDString *Value, StorageType Storage,
4795 bool ShouldCreate = true);
4796
4797 TempDIMacro cloneImpl() const {
4799 getValue());
4800 }
4801
4802public:
4804 (unsigned MIType, unsigned Line, StringRef Name,
4805 StringRef Value = ""),
4806 (MIType, Line, Name, Value))
4807 DEFINE_MDNODE_GET(DIMacro,
4808 (unsigned MIType, unsigned Line, MDString *Name,
4811
4812 TempDIMacro clone() const { return cloneImpl(); }
4813
4814 unsigned getLine() const { return SubclassData32; }
4815
4816 StringRef getName() const { return getStringOperand(0); }
4817 StringRef getValue() const { return getStringOperand(1); }
4818
4821
4822 static bool classof(const Metadata *MD) {
4823 return MD->getMetadataID() == DIMacroKind;
4824 }
4825};
4826
4827/// Macro file
4828///
4829/// Uses the SubclassData32 Metadata slot.
4830class DIMacroFile : public DIMacroNode {
4831 friend class LLVMContextImpl;
4832 friend class MDNode;
4833
4834 DIMacroFile(LLVMContext &C, StorageType Storage, unsigned MIType,
4835 unsigned Line, ArrayRef<Metadata *> Ops)
4836 : DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops) {
4838 }
4839 ~DIMacroFile() = default;
4840
4841 static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
4842 unsigned Line, DIFile *File,
4843 DIMacroNodeArray Elements, StorageType Storage,
4844 bool ShouldCreate = true) {
4845 return getImpl(Context, MIType, Line, static_cast<Metadata *>(File),
4846 Elements.get(), Storage, ShouldCreate);
4847 }
4848
4849 LLVM_ABI static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
4850 unsigned Line, Metadata *File,
4852 bool ShouldCreate = true);
4853
4854 TempDIMacroFile cloneImpl() const {
4856 getElements());
4857 }
4858
4859public:
4861 (unsigned MIType, unsigned Line, DIFile *File,
4862 DIMacroNodeArray Elements),
4863 (MIType, Line, File, Elements))
4864 DEFINE_MDNODE_GET(DIMacroFile,
4865 (unsigned MIType, unsigned Line, Metadata *File,
4868
4869 TempDIMacroFile clone() const { return cloneImpl(); }
4870
4871 void replaceElements(DIMacroNodeArray Elements) {
4872#ifndef NDEBUG
4873 for (DIMacroNode *Op : getElements())
4874 assert(is_contained(Elements->operands(), Op) &&
4875 "Lost a macro node during macro node list replacement");
4876#endif
4877 replaceOperandWith(1, Elements.get());
4878 }
4879
4880 unsigned getLine() const { return SubclassData32; }
4882
4883 DIMacroNodeArray getElements() const {
4885 }
4886
4887 Metadata *getRawFile() const { return getOperand(0); }
4888 Metadata *getRawElements() const { return getOperand(1); }
4889
4890 static bool classof(const Metadata *MD) {
4891 return MD->getMetadataID() == DIMacroFileKind;
4892 }
4893};
4894
4895/// List of ValueAsMetadata, to be used as an argument to a dbg.value
4896/// intrinsic.
4897class DIArgList : public Metadata, ReplaceableMetadataImpl {
4899 friend class LLVMContextImpl;
4901
4903
4904 DIArgList(LLVMContext &Context, ArrayRef<ValueAsMetadata *> Args)
4905 : Metadata(DIArgListKind, Uniqued), ReplaceableMetadataImpl(Context),
4906 Args(Args) {
4907 track();
4908 }
4909 ~DIArgList() { untrack(); }
4910
4911 LLVM_ABI void track();
4912 LLVM_ABI void untrack();
4913 void dropAllReferences(bool Untrack);
4914
4915public:
4916 LLVM_ABI static DIArgList *get(LLVMContext &Context,
4918
4919 ArrayRef<ValueAsMetadata *> getArgs() const { return Args; }
4920
4921 iterator args_begin() { return Args.begin(); }
4922 iterator args_end() { return Args.end(); }
4923
4924 static bool classof(const Metadata *MD) {
4925 return MD->getMetadataID() == DIArgListKind;
4926 }
4927
4931
4932 LLVM_ABI void handleChangedOperand(void *Ref, Metadata *New);
4933};
4934
4935/// Identifies a unique instance of a variable.
4936///
4937/// Storage for identifying a potentially inlined instance of a variable,
4938/// or a fragment thereof. This guarantees that exactly one variable instance
4939/// may be identified by this class, even when that variable is a fragment of
4940/// an aggregate variable and/or there is another inlined instance of the same
4941/// source code variable nearby.
4942/// This class does not necessarily uniquely identify that variable: it is
4943/// possible that a DebugVariable with different parameters may point to the
4944/// same variable instance, but not that one DebugVariable points to multiple
4945/// variable instances.
4947 using FragmentInfo = DIExpression::FragmentInfo;
4948
4949 const DILocalVariable *Variable;
4950 std::optional<FragmentInfo> Fragment;
4951 const DILocation *InlinedAt;
4952
4953 /// Fragment that will overlap all other fragments. Used as default when
4954 /// caller demands a fragment.
4955 LLVM_ABI static const FragmentInfo DefaultFragment;
4956
4957public:
4959
4961 std::optional<FragmentInfo> FragmentInfo,
4962 const DILocation *InlinedAt)
4963 : Variable(Var), Fragment(FragmentInfo), InlinedAt(InlinedAt) {}
4964
4965 DebugVariable(const DILocalVariable *Var, const DIExpression *DIExpr,
4966 const DILocation *InlinedAt)
4967 : Variable(Var),
4968 Fragment(DIExpr ? DIExpr->getFragmentInfo() : std::nullopt),
4969 InlinedAt(InlinedAt) {}
4970
4971 const DILocalVariable *getVariable() const { return Variable; }
4972 std::optional<FragmentInfo> getFragment() const { return Fragment; }
4973 const DILocation *getInlinedAt() const { return InlinedAt; }
4974
4975 FragmentInfo getFragmentOrDefault() const {
4976 return Fragment.value_or(DefaultFragment);
4977 }
4978
4979 static bool isDefaultFragment(const FragmentInfo F) {
4980 return F == DefaultFragment;
4981 }
4982
4983 bool operator==(const DebugVariable &Other) const {
4984 return std::tie(Variable, Fragment, InlinedAt) ==
4985 std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
4986 }
4987
4988 bool operator<(const DebugVariable &Other) const {
4989 return std::tie(Variable, Fragment, InlinedAt) <
4990 std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
4991 }
4992};
4993
4994template <> struct DenseMapInfo<DebugVariable> {
4996
4997 static unsigned getHashValue(const DebugVariable &D) {
4998 unsigned HV = 0;
4999 const std::optional<FragmentInfo> Fragment = D.getFragment();
5000 if (Fragment)
5002
5003 return hash_combine(D.getVariable(), HV, D.getInlinedAt());
5004 }
5005
5006 static bool isEqual(const DebugVariable &A, const DebugVariable &B) {
5007 return A == B;
5008 }
5009};
5010
5011/// Identifies a unique instance of a whole variable (discards/ignores fragment
5012/// information).
5019
5020template <>
5022 : public DenseMapInfo<DebugVariable> {};
5023
5024template <typename NodeT> static const DIScope *getScope(const NodeT *N) {
5025 return N->getScope();
5026}
5027
5028template <typename NodeT> static DIScope *getScope(NodeT *N) {
5029 return N->getScope();
5030}
5031
5032template <>
5033[[maybe_unused]] const DIScope *
5035 return N->getVariable()->getScope();
5036}
5037template <>
5039 return N->getVariable()->getScope();
5040}
5041} // end namespace llvm
5042
5043#undef DEFINE_MDNODE_GET_UNPACK_IMPL
5044#undef DEFINE_MDNODE_GET_UNPACK
5045#undef DEFINE_MDNODE_GET
5046
5047#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)
uint64_t getIndex() const
Return the location operand index.
static LLVM_ABI bool classof(const ExprOperand *Op)
uint64_t getValue() const
Return the unsigned constant value.
static LLVM_ABI bool classof(const ExprOperand *Op)
uint64_t getBitSize() const
Return the destination size in bits.
uint64_t getEncoding() const
Return the raw destination type encoding.
static LLVM_ABI bool classof(const ExprOperand *Op)
static LLVM_ABI bool classof(const ExprOperand *Op)
uint64_t getNumOperations() const
Return the number of operations the entry value covers.
A lightweight wrapper around an expression operand.
LLVM_ABI bool isNonEmitting() const
Return true if CodeGen handles this operand without adding bytes to the DWARF expression.
LLVM_ABI unsigned getSize() const
Return the size of the operand.
uint64_t getArg(unsigned I) const
Get an argument to the operand.
bool is(uint64_t Opcode) const
Return true if this is Opcode.
uint64_t getOp() const
Get the operand code.
void appendToVector(SmallVectorImpl< uint64_t > &V) const
Append the elements of this operand to V.
static LLVM_ABI bool classof(const ExprOperand *Op)
uint64_t getOffsetInBits() const
Return the extract offset in bits.
uint64_t getSizeInBits() const
Return the extract size in bits.
LLVM_ABI bool isSigned() const
Return whether the extracted value is sign-extended.
uint64_t getSizeInBits() const
Return the fragment size in bits.
static LLVM_ABI bool classof(const ExprOperand *Op)
uint64_t getOffsetInBits() const
Return the fragment offset in bits.
static LLVM_ABI bool classof(const ExprOperand *Op)
uint64_t getOffset() const
Return the unsigned offset.
static LLVM_ABI bool classof(const ExprOperand *Op)
uint64_t getTagOffset() const
Return the offset a memory tag is derived from.
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:1579
op_iterator op_end() const
Definition Metadata.h:1420
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1567
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:684
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:924
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:615
Tuple of metadata.
Definition Metadata.h:1484
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:280
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.
template class LLVM_TEMPLATE_ABI opt< bool >
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:578
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:878
#define N
This struct provides a method for customizing the way a cast is performed.
Definition Casting.h:476
This struct provides a way to check if a given cast is possible.
Definition Casting.h:253
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
This cast trait just provides the default implementation of doCastIfPossible to make CastInfo special...
Definition Casting.h:309
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
static bool isPresent(const DIExpression::ExprOperand &Op)
static DIExpression::ExprOperand & unwrapValue(DIExpression::ExprOperand &Op)
ValueIsPresent provides a way to check if a value is, well, present.
Definition Casting.h:596