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 DIPropertyKind:
228 case DIImportedEntityKind:
229 case DIModuleKind:
230 case DIGenericSubrangeKind:
231 case DIAssignIDKind:
232 return true;
233 }
234 }
235};
236
237/// Generic tagged DWARF-like metadata node.
238///
239/// An un-specialized DWARF-like metadata node. The first operand is a
240/// (possibly empty) null-separated \a MDString header that contains arbitrary
241/// fields. The remaining operands are \a dwarf_operands(), and are pointers
242/// to other metadata.
243///
244/// Uses the SubclassData32 Metadata slot.
245class GenericDINode : public DINode {
246 friend class LLVMContextImpl;
247 friend class MDNode;
248
249 GenericDINode(LLVMContext &C, StorageType Storage, unsigned Hash,
250 unsigned Tag, ArrayRef<Metadata *> Ops1,
252 : DINode(C, GenericDINodeKind, Storage, Tag, Ops1, Ops2) {
253 setHash(Hash);
254 }
256
257 void setHash(unsigned Hash) { SubclassData32 = Hash; }
258 void recalculateHash();
259
260 static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
262 StorageType Storage, bool ShouldCreate = true) {
263 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
264 DwarfOps, Storage, ShouldCreate);
265 }
266
267 LLVM_ABI static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
268 MDString *Header,
271 bool ShouldCreate = true);
272
273 TempGenericDINode cloneImpl() const {
276 }
277
278public:
279 unsigned getHash() const { return SubclassData32; }
280
281 DEFINE_MDNODE_GET(GenericDINode,
282 (unsigned Tag, StringRef Header,
284 (Tag, Header, DwarfOps))
285 DEFINE_MDNODE_GET(GenericDINode,
286 (unsigned Tag, MDString *Header,
289
290 /// Return a (temporary) clone of this.
291 TempGenericDINode clone() const { return cloneImpl(); }
292
293 LLVM_ABI dwarf::Tag getTag() const;
294 StringRef getHeader() const { return getStringOperand(0); }
296
297 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
298 op_iterator dwarf_op_end() const { return op_end(); }
301 }
302
303 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
304 const MDOperand &getDwarfOperand(unsigned I) const {
305 return getOperand(I + 1);
306 }
307 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
308 replaceOperandWith(I + 1, New);
309 }
310
311 static bool classof(const Metadata *MD) {
312 return MD->getMetadataID() == GenericDINodeKind;
313 }
314};
315
316/// Assignment ID.
317/// Used to link stores (as an attachment) and dbg.assigns (as an operand).
318/// DIAssignID metadata is never uniqued as we compare instances using
319/// referential equality (the instance/address is the ID).
320class DIAssignID : public MDNode {
321 friend class LLVMContextImpl;
322 friend class MDNode;
323
325 : MDNode(C, DIAssignIDKind, Storage, {}) {}
326
327 ~DIAssignID() { dropAllReferences(); }
328
329 LLVM_ABI static DIAssignID *getImpl(LLVMContext &Context, StorageType Storage,
330 bool ShouldCreate = true);
331
332 TempDIAssignID cloneImpl() const { return getTemporary(getContext()); }
333
334public:
335 // This node has no operands to replace.
336 void replaceOperandWith(unsigned I, Metadata *New) = delete;
337
339 return Context.getReplaceableUses()->getAllDbgVariableRecordUsers();
340 }
341
342 static DIAssignID *getDistinct(LLVMContext &Context) {
343 return getImpl(Context, Distinct);
344 }
345 static TempDIAssignID getTemporary(LLVMContext &Context) {
346 return TempDIAssignID(getImpl(Context, Temporary));
347 }
348 // NOTE: Do not define get(LLVMContext&) - see class comment.
349
350 static bool classof(const Metadata *MD) {
351 return MD->getMetadataID() == DIAssignIDKind;
352 }
353};
354
355/// Array subrange.
356class DISubrange : public DINode {
357 friend class LLVMContextImpl;
358 friend class MDNode;
359
361
362 ~DISubrange() = default;
363
364 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, int64_t Count,
366 bool ShouldCreate = true);
367
368 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, Metadata *CountNode,
370 bool ShouldCreate = true);
371
372 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, Metadata *CountNode,
374 Metadata *UpperBound, Metadata *Stride,
376 bool ShouldCreate = true);
377
378 TempDISubrange cloneImpl() const {
379 return getTemporary(getContext(), getRawCountNode(), getRawLowerBound(),
380 getRawUpperBound(), getRawStride());
381 }
382
383public:
384 DEFINE_MDNODE_GET(DISubrange, (int64_t Count, int64_t LowerBound = 0),
385 (Count, LowerBound))
386
387 DEFINE_MDNODE_GET(DISubrange, (Metadata * CountNode, int64_t LowerBound = 0),
389
390 DEFINE_MDNODE_GET(DISubrange,
392 Metadata *UpperBound, Metadata *Stride),
393 (CountNode, LowerBound, UpperBound, Stride))
394
395 TempDISubrange clone() const { return cloneImpl(); }
396
397 Metadata *getRawCountNode() const { return getOperand(0).get(); }
398
399 Metadata *getRawLowerBound() const { return getOperand(1).get(); }
400
401 Metadata *getRawUpperBound() const { return getOperand(2).get(); }
402
403 Metadata *getRawStride() const { return getOperand(3).get(); }
404
405 typedef PointerUnion<ConstantInt *, DIVariable *, DIExpression *> BoundType;
406
407 LLVM_ABI BoundType getCount() const;
408
409 LLVM_ABI BoundType getLowerBound() const;
410
411 LLVM_ABI BoundType getUpperBound() const;
412
413 LLVM_ABI BoundType getStride() const;
414
415 static bool classof(const Metadata *MD) {
416 return MD->getMetadataID() == DISubrangeKind;
417 }
418};
419
420class DIGenericSubrange : public DINode {
421 friend class LLVMContextImpl;
422 friend class MDNode;
423
424 DIGenericSubrange(LLVMContext &C, StorageType Storage,
426
427 ~DIGenericSubrange() = default;
428
429 LLVM_ABI static DIGenericSubrange *
430 getImpl(LLVMContext &Context, Metadata *CountNode, Metadata *LowerBound,
431 Metadata *UpperBound, Metadata *Stride, StorageType Storage,
432 bool ShouldCreate = true);
433
434 TempDIGenericSubrange cloneImpl() const {
437 }
438
439public:
440 DEFINE_MDNODE_GET(DIGenericSubrange,
441 (Metadata * CountNode, Metadata *LowerBound,
442 Metadata *UpperBound, Metadata *Stride),
443 (CountNode, LowerBound, UpperBound, Stride))
444
445 TempDIGenericSubrange clone() const { return cloneImpl(); }
446
447 Metadata *getRawCountNode() const { return getOperand(0).get(); }
448 Metadata *getRawLowerBound() const { return getOperand(1).get(); }
449 Metadata *getRawUpperBound() const { return getOperand(2).get(); }
450 Metadata *getRawStride() const { return getOperand(3).get(); }
451
453
458
459 static bool classof(const Metadata *MD) {
460 return MD->getMetadataID() == DIGenericSubrangeKind;
461 }
462};
463
464/// Enumeration value.
465///
466/// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
467/// longer creates a type cycle.
468class DIEnumerator : public DINode {
469 friend class LLVMContextImpl;
470 friend class MDNode;
471
472 APInt Value;
473 LLVM_ABI DIEnumerator(LLVMContext &C, StorageType Storage, const APInt &Value,
475 DIEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
477 : DIEnumerator(C, Storage, APInt(64, Value, !IsUnsigned), IsUnsigned,
478 Ops) {}
479 ~DIEnumerator() = default;
480
481 static DIEnumerator *getImpl(LLVMContext &Context, const APInt &Value,
483 StorageType Storage, bool ShouldCreate = true) {
484 return getImpl(Context, Value, IsUnsigned,
485 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
486 }
487 LLVM_ABI static DIEnumerator *getImpl(LLVMContext &Context,
488 const APInt &Value, bool IsUnsigned,
489 MDString *Name, StorageType Storage,
490 bool ShouldCreate = true);
491
492 TempDIEnumerator cloneImpl() const {
494 }
495
496public:
497 DEFINE_MDNODE_GET(DIEnumerator,
498 (int64_t Value, bool IsUnsigned, StringRef Name),
499 (APInt(64, Value, !IsUnsigned), IsUnsigned, Name))
500 DEFINE_MDNODE_GET(DIEnumerator,
501 (int64_t Value, bool IsUnsigned, MDString *Name),
502 (APInt(64, Value, !IsUnsigned), IsUnsigned, Name))
503 DEFINE_MDNODE_GET(DIEnumerator,
504 (APInt Value, bool IsUnsigned, StringRef Name),
505 (Value, IsUnsigned, Name))
506 DEFINE_MDNODE_GET(DIEnumerator,
507 (APInt Value, bool IsUnsigned, MDString *Name),
508 (Value, IsUnsigned, Name))
509
510 TempDIEnumerator clone() const { return cloneImpl(); }
511
512 const APInt &getValue() const { return Value; }
513 bool isUnsigned() const { return SubclassData32; }
514 StringRef getName() const { return getStringOperand(0); }
515
517
518 static bool classof(const Metadata *MD) {
519 return MD->getMetadataID() == DIEnumeratorKind;
520 }
521};
522
523/// Base class for scope-like contexts.
524///
525/// Base class for lexical scopes and types (which are also declaration
526/// contexts).
527///
528/// TODO: Separate the concepts of declaration contexts and lexical scopes.
529class DIScope : public DINode {
530protected:
531 DIScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
533 : DINode(C, ID, Storage, Tag, Ops) {}
534 ~DIScope() = default;
535
536public:
538
539 inline StringRef getFilename() const;
540 inline StringRef getDirectory() const;
541 inline std::optional<StringRef> getSource() const;
542
543 LLVM_ABI StringRef getName() const;
544 LLVM_ABI DIScope *getScope() const;
545
546 /// Return the raw underlying file.
547 ///
548 /// A \a DIFile is a \a DIScope, but it doesn't point at a separate file (it
549 /// \em is the file). If \c this is an \a DIFile, we need to return \c this.
550 /// Otherwise, return the first operand, which is where all other subclasses
551 /// store their file pointer.
553 return isa<DIFile>(this) ? const_cast<DIScope *>(this)
554 : static_cast<Metadata *>(getOperand(0));
555 }
556
557 static bool classof(const Metadata *MD) {
558 switch (MD->getMetadataID()) {
559 default:
560 return false;
561 case DIBasicTypeKind:
562 case DIFixedPointTypeKind:
563 case DIStringTypeKind:
564 case DISubrangeTypeKind:
565 case DIDerivedTypeKind:
566 case DICompositeTypeKind:
567 case DISubroutineTypeKind:
568 case DIFileKind:
569 case DICompileUnitKind:
570 case DISubprogramKind:
571 case DILexicalBlockKind:
572 case DILexicalBlockFileKind:
573 case DINamespaceKind:
574 case DICommonBlockKind:
575 case DIModuleKind:
576 return true;
577 }
578 }
579};
580
581/// File.
582///
583/// TODO: Merge with directory/file node (including users).
584/// TODO: Canonicalize paths on creation.
585class DIFile : public DIScope {
586 friend class LLVMContextImpl;
587 friend class MDNode;
588
589public:
590 /// Which algorithm (e.g. MD5) a checksum was generated with.
591 ///
592 /// The encoding is explicit because it is used directly in Bitcode. The
593 /// value 0 is reserved to indicate the absence of a checksum in Bitcode.
595 // The first variant was originally CSK_None, encoded as 0. The new
596 // internal representation removes the need for this by wrapping the
597 // ChecksumInfo in an Optional, but to preserve Bitcode compatibility the 0
598 // encoding is reserved.
602 CSK_Last = CSK_SHA256 // Should be last enumeration.
603 };
604
605 /// A single checksum, represented by a \a Kind and a \a Value (a string).
606 template <typename T> struct ChecksumInfo {
607 /// The kind of checksum which \a Value encodes.
609 /// The string value of the checksum.
611
613 ~ChecksumInfo() = default;
614 bool operator==(const ChecksumInfo<T> &X) const {
615 return Kind == X.Kind && Value == X.Value;
616 }
617 bool operator!=(const ChecksumInfo<T> &X) const { return !(*this == X); }
618 StringRef getKindAsString() const { return getChecksumKindAsString(Kind); }
619 };
620
621private:
622 std::optional<ChecksumInfo<MDString *>> Checksum;
623 /// An optional source. A nullptr means none.
625
627 std::optional<ChecksumInfo<MDString *>> CS, MDString *Src,
629 ~DIFile() = default;
630
631 static DIFile *getImpl(LLVMContext &Context, StringRef Filename,
633 std::optional<ChecksumInfo<StringRef>> CS,
634 std::optional<StringRef> Source, StorageType Storage,
635 bool ShouldCreate = true) {
636 std::optional<ChecksumInfo<MDString *>> MDChecksum;
637 if (CS)
638 MDChecksum.emplace(CS->Kind, getCanonicalMDString(Context, CS->Value));
639 return getImpl(Context, getCanonicalMDString(Context, Filename),
640 getCanonicalMDString(Context, Directory), MDChecksum,
641 Source ? MDString::get(Context, *Source) : nullptr, Storage,
642 ShouldCreate);
643 }
644 LLVM_ABI static DIFile *getImpl(LLVMContext &Context, MDString *Filename,
645 MDString *Directory,
646 std::optional<ChecksumInfo<MDString *>> CS,
647 MDString *Source, StorageType Storage,
648 bool ShouldCreate = true);
649
650 TempDIFile cloneImpl() const {
652 getChecksum(), getSource());
653 }
654
655public:
658 std::optional<ChecksumInfo<StringRef>> CS = std::nullopt,
659 std::optional<StringRef> Source = std::nullopt),
660 (Filename, Directory, CS, Source))
661 DEFINE_MDNODE_GET(DIFile,
663 std::optional<ChecksumInfo<MDString *>> CS = std::nullopt,
664 MDString *Source = nullptr),
665 (Filename, Directory, CS, Source))
666
667 TempDIFile clone() const { return cloneImpl(); }
668
669 StringRef getFilename() const { return getStringOperand(0); }
670 StringRef getDirectory() const { return getStringOperand(1); }
671 std::optional<ChecksumInfo<StringRef>> getChecksum() const {
672 std::optional<ChecksumInfo<StringRef>> StringRefChecksum;
673 if (Checksum)
674 StringRefChecksum.emplace(Checksum->Kind, Checksum->Value->getString());
675 return StringRefChecksum;
676 }
677 std::optional<StringRef> getSource() const {
678 return Source ? std::optional<StringRef>(Source->getString())
679 : std::nullopt;
680 }
681
682 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
683 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
684 std::optional<ChecksumInfo<MDString *>> getRawChecksum() const {
685 return Checksum;
686 }
687 MDString *getRawSource() const { return Source; }
688
689 LLVM_ABI static StringRef getChecksumKindAsString(ChecksumKind CSKind);
690 LLVM_ABI static std::optional<ChecksumKind>
691 getChecksumKind(StringRef CSKindStr);
692
693 static bool classof(const Metadata *MD) {
694 return MD->getMetadataID() == DIFileKind;
695 }
696};
697
699 if (auto *F = getFile())
700 return F->getFilename();
701 return "";
702}
703
705 if (auto *F = getFile())
706 return F->getDirectory();
707 return "";
708}
709
710std::optional<StringRef> DIScope::getSource() const {
711 if (auto *F = getFile())
712 return F->getSource();
713 return std::nullopt;
714}
715
716/// Base class for types.
717///
718/// TODO: Remove the hardcoded name and context, since many types don't use
719/// them.
720/// TODO: Split up flags.
721///
722/// Uses the SubclassData32 Metadata slot.
723class DIType : public DIScope {
724 unsigned Line;
725 DIFlags Flags;
726 uint32_t NumExtraInhabitants;
727
728protected:
729 static constexpr unsigned N_OPERANDS = 5;
730
731 DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
732 unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants,
734 : DIScope(C, ID, Storage, Tag, Ops) {
735 init(Line, AlignInBits, NumExtraInhabitants, Flags);
736 }
737 ~DIType() = default;
738
739 void init(unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants,
740 DIFlags Flags) {
741 this->Line = Line;
742 this->Flags = Flags;
743 this->SubclassData32 = AlignInBits;
744 this->NumExtraInhabitants = NumExtraInhabitants;
745 }
746
747 /// Change fields in place.
748 void mutate(unsigned Tag, unsigned Line, uint32_t AlignInBits,
749 uint32_t NumExtraInhabitants, DIFlags Flags) {
750 assert(isDistinct() && "Only distinct nodes can mutate");
751 setTag(Tag);
752 init(Line, AlignInBits, NumExtraInhabitants, Flags);
753 }
754
755public:
756 TempDIType clone() const {
757 return TempDIType(cast<DIType>(MDNode::clone().release()));
758 }
759
760 unsigned getLine() const { return Line; }
762 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
763 uint32_t getNumExtraInhabitants() const { return NumExtraInhabitants; }
764 DIFlags getFlags() const { return Flags; }
765
767 StringRef getName() const { return getStringOperand(2); }
768
769 Metadata *getRawScope() const { return getOperand(1); }
771
772 Metadata *getRawSizeInBits() const { return getOperand(3); }
775 if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(MD->getValue()))
776 return CI->getZExtValue();
777 }
778 return 0;
779 }
780
781 Metadata *getRawOffsetInBits() const { return getOperand(4); }
784 if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(MD->getValue()))
785 return CI->getZExtValue();
786 }
787 return 0;
788 }
789
790 /// Returns a new temporary DIType with updated Flags
791 TempDIType cloneWithFlags(DIFlags NewFlags) const {
792 auto NewTy = clone();
793 NewTy->Flags = NewFlags;
794 return NewTy;
795 }
796
797 bool isPrivate() const {
798 return (getFlags() & FlagAccessibility) == FlagPrivate;
799 }
800 bool isProtected() const {
801 return (getFlags() & FlagAccessibility) == FlagProtected;
802 }
803 bool isPublic() const {
804 return (getFlags() & FlagAccessibility) == FlagPublic;
805 }
806 bool isForwardDecl() const { return getFlags() & FlagFwdDecl; }
807 bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; }
808 bool isVirtual() const { return getFlags() & FlagVirtual; }
809 bool isArtificial() const { return getFlags() & FlagArtificial; }
810 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
811 bool isObjcClassComplete() const {
812 return getFlags() & FlagObjcClassComplete;
813 }
814 bool isVector() const { return getFlags() & FlagVector; }
815 bool isBitField() const { return getFlags() & FlagBitField; }
816 bool isStaticMember() const { return getFlags() & FlagStaticMember; }
817 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
818 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
819 bool isTypePassByValue() const { return getFlags() & FlagTypePassByValue; }
821 return getFlags() & FlagTypePassByReference;
822 }
823 bool isBigEndian() const { return getFlags() & FlagBigEndian; }
824 bool isLittleEndian() const { return getFlags() & FlagLittleEndian; }
825 bool getExportSymbols() const { return getFlags() & FlagExportSymbols; }
826
827 static bool classof(const Metadata *MD) {
828 switch (MD->getMetadataID()) {
829 default:
830 return false;
831 case DIBasicTypeKind:
832 case DIFixedPointTypeKind:
833 case DIStringTypeKind:
834 case DISubrangeTypeKind:
835 case DIDerivedTypeKind:
836 case DICompositeTypeKind:
837 case DISubroutineTypeKind:
838 return true;
839 }
840 }
841};
842
843/// Basic type, like 'int' or 'float'.
844///
845/// TODO: Split out DW_TAG_unspecified_type.
846/// TODO: Drop unused accessors.
847class DIBasicType : public DIType {
848 friend class LLVMContextImpl;
849 friend class MDNode;
850
851 unsigned Encoding;
852 /// Describes the number of bits used by the value of the object. Non-zero
853 /// when the value of an object does not fully occupy the storage size
854 /// specified by SizeInBits.
855 uint32_t DataSizeInBits;
856
857protected:
859 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
860 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
862 : DIType(C, DIBasicTypeKind, Storage, Tag, LineNo, AlignInBits,
864 Encoding(Encoding), DataSizeInBits(DataSizeInBits) {}
865 DIBasicType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
866 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
867 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
870 Flags, Ops),
871 Encoding(Encoding), DataSizeInBits(DataSizeInBits) {}
872 ~DIBasicType() = default;
873
874 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
875 StringRef Name, DIFile *File, unsigned LineNo,
877 uint32_t AlignInBits, unsigned Encoding,
879 uint32_t DataSizeInBits, DIFlags Flags,
880 StorageType Storage, bool ShouldCreate = true) {
881 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
882 LineNo, Scope, SizeInBits, AlignInBits, Encoding,
883 NumExtraInhabitants, DataSizeInBits, Flags, Storage,
884 ShouldCreate);
885 }
886 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
887 MDString *Name, DIFile *File, unsigned LineNo,
889 uint32_t AlignInBits, unsigned Encoding,
891 uint32_t DataSizeInBits, DIFlags Flags,
892 StorageType Storage, bool ShouldCreate = true) {
893 auto *SizeInBitsNode = ConstantAsMetadata::get(
894 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
895 return getImpl(Context, Tag, Name, File, LineNo, Scope, SizeInBitsNode,
896 AlignInBits, Encoding, NumExtraInhabitants, DataSizeInBits,
897 Flags, Storage, ShouldCreate);
898 }
899 LLVM_ABI static DIBasicType *
900 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
901 unsigned LineNo, Metadata *Scope, Metadata *SizeInBits,
904 bool ShouldCreate = true);
905
906 TempDIBasicType cloneImpl() const {
907 return getTemporary(
911 }
912
913public:
915 (Tag, Name, nullptr, 0, nullptr, 0, 0, 0, 0, 0, FlagZero))
918 (Tag, Name, nullptr, 0, nullptr, SizeInBits, 0, 0, 0, 0,
919 FlagZero))
921 (unsigned Tag, MDString *Name, uint64_t SizeInBits),
922 (Tag, Name, nullptr, 0, nullptr, SizeInBits, 0, 0, 0, 0,
923 FlagZero))
926 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
927 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
928 Encoding, 0, 0, Flags))
930 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
931 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
932 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
933 Encoding, 0, 0, Flags))
936 uint32_t AlignInBits, unsigned Encoding,
938 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
942 uint32_t AlignInBits, unsigned Encoding,
943 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
944 DIFlags Flags),
945 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
946 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
950 uint32_t AlignInBits, unsigned Encoding,
954 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
956 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
957 uint32_t AlignInBits, unsigned Encoding,
958 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
959 DIFlags Flags),
960 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
961 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
964 uint32_t AlignInBits, unsigned Encoding,
967 (Tag, Name, nullptr, 0, nullptr, SizeInBits, AlignInBits,
968 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
970 (unsigned Tag, MDString *Name, Metadata *File,
972 uint32_t AlignInBits, unsigned Encoding,
973 uint32_t NumExtraInhabitants, uint32_t DataSizeInBits,
974 DIFlags Flags),
976 Encoding, NumExtraInhabitants, DataSizeInBits, Flags))
977
978 TempDIBasicType clone() const { return cloneImpl(); }
979
980 unsigned getEncoding() const { return Encoding; }
981
982 uint32_t getDataSizeInBits() const { return DataSizeInBits; }
983
984 enum class Signedness { Signed, Unsigned };
985
986 /// Return the signedness of this type, or std::nullopt if this type is
987 /// neither signed nor unsigned.
988 LLVM_ABI std::optional<Signedness> getSignedness() const;
989
990 static bool classof(const Metadata *MD) {
991 return MD->getMetadataID() == DIBasicTypeKind ||
992 MD->getMetadataID() == DIFixedPointTypeKind;
993 }
994};
995
996/// Fixed-point type.
997class DIFixedPointType : public DIBasicType {
998 friend class LLVMContextImpl;
999 friend class MDNode;
1000
1001 // Actually FixedPointKind.
1002 unsigned Kind;
1003 // Used for binary and decimal.
1004 int Factor;
1005 // Used for rational.
1006 APInt Numerator;
1007 APInt Denominator;
1008
1009 DIFixedPointType(LLVMContext &C, StorageType Storage, unsigned Tag,
1010 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
1011 DIFlags Flags, unsigned Kind, int Factor,
1013 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, LineNo, AlignInBits,
1014 Encoding, 0, 0, Flags, Ops),
1015 Kind(Kind), Factor(Factor) {
1016 assert(Kind == FixedPointBinary || Kind == FixedPointDecimal);
1017 }
1019 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
1020 DIFlags Flags, unsigned Kind, APInt Numerator,
1022 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, LineNo, AlignInBits,
1023 Encoding, 0, 0, Flags, Ops),
1024 Kind(Kind), Factor(0), Numerator(Numerator), Denominator(Denominator) {
1025 assert(Kind == FixedPointRational);
1026 }
1027 DIFixedPointType(LLVMContext &C, StorageType Storage, unsigned Tag,
1028 unsigned LineNo, uint32_t AlignInBits, unsigned Encoding,
1029 DIFlags Flags, unsigned Kind, int Factor, APInt Numerator,
1031 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, LineNo, AlignInBits,
1032 Encoding, 0, 0, Flags, Ops),
1033 Kind(Kind), Factor(Factor), Numerator(Numerator),
1035 ~DIFixedPointType() = default;
1036
1037 static DIFixedPointType *
1038 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1040 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind,
1041 int Factor, APInt Numerator, APInt Denominator, StorageType Storage,
1042 bool ShouldCreate = true) {
1043 auto *SizeInBitsNode = ConstantAsMetadata::get(
1044 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1045 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1046 LineNo, Scope, SizeInBitsNode, AlignInBits, Encoding, Flags,
1047 Kind, Factor, Numerator, Denominator, Storage, ShouldCreate);
1048 }
1049 static DIFixedPointType *
1050 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1051 unsigned LineNo, DIScope *Scope, Metadata *SizeInBits,
1052 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind,
1053 int Factor, APInt Numerator, APInt Denominator, StorageType Storage,
1054 bool ShouldCreate = true) {
1055 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1057 Kind, Factor, Numerator, Denominator, Storage, ShouldCreate);
1058 }
1059 static DIFixedPointType *
1060 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, DIFile *File,
1062 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind,
1063 int Factor, APInt Numerator, APInt Denominator, StorageType Storage,
1064 bool ShouldCreate = true) {
1065 auto *SizeInBitsNode = ConstantAsMetadata::get(
1066 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1067 return getImpl(Context, Tag, Name, File, LineNo, Scope, SizeInBitsNode,
1068 AlignInBits, Encoding, Flags, Kind, Factor, Numerator,
1069 Denominator, Storage, ShouldCreate);
1070 }
1071 LLVM_ABI static DIFixedPointType *
1072 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1074 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind,
1075 int Factor, APInt Numerator, APInt Denominator, StorageType Storage,
1076 bool ShouldCreate = true);
1077
1078 TempDIFixedPointType cloneImpl() const {
1081 getAlignInBits(), getEncoding(), getFlags(), Kind,
1082 Factor, Numerator, Denominator);
1083 }
1084
1085public:
1086 enum FixedPointKind : unsigned {
1087 /// Scale factor 2^Factor.
1089 /// Scale factor 10^Factor.
1091 /// Arbitrary rational scale factor.
1094 };
1095
1096 LLVM_ABI static std::optional<FixedPointKind>
1098 LLVM_ABI static const char *fixedPointKindString(FixedPointKind);
1099
1100 DEFINE_MDNODE_GET(DIFixedPointType,
1101 (unsigned Tag, MDString *Name, DIFile *File,
1104 unsigned Kind, int Factor, APInt Numerator,
1105 APInt Denominator),
1107 Encoding, Flags, Kind, Factor, Numerator, Denominator))
1108 DEFINE_MDNODE_GET(DIFixedPointType,
1112 unsigned Kind, int Factor, APInt Numerator,
1113 APInt Denominator),
1115 Encoding, Flags, Kind, Factor, Numerator, Denominator))
1116 DEFINE_MDNODE_GET(DIFixedPointType,
1117 (unsigned Tag, MDString *Name, Metadata *File,
1120 unsigned Kind, int Factor, APInt Numerator,
1121 APInt Denominator),
1123 Encoding, Flags, Kind, Factor, Numerator, Denominator))
1124
1125 TempDIFixedPointType clone() const { return cloneImpl(); }
1126
1127 bool isBinary() const { return Kind == FixedPointBinary; }
1128 bool isDecimal() const { return Kind == FixedPointDecimal; }
1129 bool isRational() const { return Kind == FixedPointRational; }
1130
1131 LLVM_ABI bool isSigned() const;
1132
1133 FixedPointKind getKind() const { return static_cast<FixedPointKind>(Kind); }
1134
1135 int getFactorRaw() const { return Factor; }
1136 int getFactor() const {
1137 assert(Kind == FixedPointBinary || Kind == FixedPointDecimal);
1138 return Factor;
1139 }
1140
1141 const APInt &getNumeratorRaw() const { return Numerator; }
1142 const APInt &getNumerator() const {
1143 assert(Kind == FixedPointRational);
1144 return Numerator;
1145 }
1146
1147 const APInt &getDenominatorRaw() const { return Denominator; }
1148 const APInt &getDenominator() const {
1149 assert(Kind == FixedPointRational);
1150 return Denominator;
1151 }
1152
1153 static bool classof(const Metadata *MD) {
1154 return MD->getMetadataID() == DIFixedPointTypeKind;
1155 }
1156};
1157
1158/// String type, Fortran CHARACTER(n)
1159class DIStringType : public DIType {
1160 friend class LLVMContextImpl;
1161 friend class MDNode;
1162
1163 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1164
1165 unsigned Encoding;
1166
1167 DIStringType(LLVMContext &C, StorageType Storage, unsigned Tag,
1168 uint32_t AlignInBits, unsigned Encoding,
1170 : DIType(C, DIStringTypeKind, Storage, Tag, 0, AlignInBits, 0, FlagZero,
1171 Ops),
1172 Encoding(Encoding) {}
1173 ~DIStringType() = default;
1174
1175 static DIStringType *getImpl(LLVMContext &Context, unsigned Tag,
1177 Metadata *StrLenExp, Metadata *StrLocationExp,
1179 unsigned Encoding, StorageType Storage,
1180 bool ShouldCreate = true) {
1181 auto *SizeInBitsNode = ConstantAsMetadata::get(
1182 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1183 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
1184 StringLength, StrLenExp, StrLocationExp, SizeInBitsNode,
1185 AlignInBits, Encoding, Storage, ShouldCreate);
1186 }
1187 static DIStringType *getImpl(LLVMContext &Context, unsigned Tag,
1188 MDString *Name, Metadata *StringLength,
1189 Metadata *StrLenExp, Metadata *StrLocationExp,
1191 unsigned Encoding, StorageType Storage,
1192 bool ShouldCreate = true) {
1193 auto *SizeInBitsNode = ConstantAsMetadata::get(
1194 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1195 return getImpl(Context, Tag, Name, StringLength, StrLenExp, StrLocationExp,
1196 SizeInBitsNode, AlignInBits, Encoding, Storage,
1197 ShouldCreate);
1198 }
1199 LLVM_ABI static DIStringType *
1200 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name,
1201 Metadata *StringLength, Metadata *StrLenExp, Metadata *StrLocationExp,
1202 Metadata *SizeInBits, uint32_t AlignInBits, unsigned Encoding,
1203 StorageType Storage, bool ShouldCreate = true);
1204
1205 TempDIStringType cloneImpl() const {
1210 }
1211
1212public:
1213 DEFINE_MDNODE_GET(DIStringType,
1214 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
1216 (Tag, Name, nullptr, nullptr, nullptr, SizeInBits,
1217 AlignInBits, 0))
1218 DEFINE_MDNODE_GET(DIStringType,
1222 unsigned Encoding),
1225 DEFINE_MDNODE_GET(DIStringType,
1226 (unsigned Tag, StringRef Name, Metadata *StringLength,
1229 unsigned Encoding),
1232 DEFINE_MDNODE_GET(DIStringType,
1236 unsigned Encoding),
1239
1240 TempDIStringType clone() const { return cloneImpl(); }
1241
1242 static bool classof(const Metadata *MD) {
1243 return MD->getMetadataID() == DIStringTypeKind;
1244 }
1245
1249
1253
1257
1258 unsigned getEncoding() const { return Encoding; }
1259
1260 Metadata *getRawStringLength() const { return getOperand(MY_FIRST_OPERAND); }
1261
1263 return getOperand(MY_FIRST_OPERAND + 1);
1264 }
1265
1267 return getOperand(MY_FIRST_OPERAND + 2);
1268 }
1269};
1270
1271/// Derived types.
1272///
1273/// This includes qualified types, pointers, references, friends, typedefs, and
1274/// class members.
1275///
1276/// TODO: Split out members (inheritance, fields, methods, etc.).
1277class DIDerivedType : public DIType {
1278public:
1279 /// Pointer authentication (__ptrauth) metadata.
1281 // RawData layout:
1282 // - Bits 0..3: Key
1283 // - Bit 4: IsAddressDiscriminated
1284 // - Bits 5..20: ExtraDiscriminator
1285 // - Bit 21: IsaPointer
1286 // - Bit 22: AuthenticatesNullValues
1287 unsigned RawData;
1288
1289 PtrAuthData(unsigned FromRawData) : RawData(FromRawData) {}
1290 PtrAuthData(unsigned Key, bool IsDiscr, unsigned Discriminator,
1291 bool IsaPointer, bool AuthenticatesNullValues) {
1292 assert(Key < 16);
1293 assert(Discriminator <= 0xffff);
1294 RawData = (Key << 0) | (IsDiscr ? (1 << 4) : 0) | (Discriminator << 5) |
1295 (IsaPointer ? (1 << 21) : 0) |
1296 (AuthenticatesNullValues ? (1 << 22) : 0);
1297 }
1298
1299 unsigned key() { return (RawData >> 0) & 0b1111; }
1300 bool isAddressDiscriminated() { return (RawData >> 4) & 1; }
1301 unsigned extraDiscriminator() { return (RawData >> 5) & 0xffff; }
1302 bool isaPointer() { return (RawData >> 21) & 1; }
1303 bool authenticatesNullValues() { return (RawData >> 22) & 1; }
1304 };
1305
1306private:
1307 friend class LLVMContextImpl;
1308 friend class MDNode;
1309
1310 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1311
1312 /// The DWARF address space of the memory pointed to or referenced by a
1313 /// pointer or reference type respectively.
1314 std::optional<unsigned> DWARFAddressSpace;
1315
1316 DIDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
1317 unsigned Line, uint32_t AlignInBits,
1318 std::optional<unsigned> DWARFAddressSpace,
1319 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1321 : DIType(C, DIDerivedTypeKind, Storage, Tag, Line, AlignInBits, 0, Flags,
1322 Ops),
1323 DWARFAddressSpace(DWARFAddressSpace) {
1324 if (PtrAuthData)
1326 }
1327 ~DIDerivedType() = default;
1328 static DIDerivedType *
1329 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1330 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1332 std::optional<unsigned> DWARFAddressSpace,
1333 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1335 bool ShouldCreate = true) {
1336 auto *SizeInBitsNode = ConstantAsMetadata::get(
1337 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1338 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1339 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1340 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1341 Line, Scope, BaseType, SizeInBitsNode, AlignInBits,
1342 OffsetInBitsNode, DWARFAddressSpace, PtrAuthData, Flags,
1343 ExtraData, Annotations.get(), Storage, ShouldCreate);
1344 }
1345 static DIDerivedType *
1346 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, DIFile *File,
1347 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1349 std::optional<unsigned> DWARFAddressSpace,
1350 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1352 bool ShouldCreate = true) {
1353 auto *SizeInBitsNode = ConstantAsMetadata::get(
1354 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1355 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1356 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1357 return getImpl(Context, Tag, Name, File, Line, Scope, BaseType,
1358 SizeInBitsNode, AlignInBits, OffsetInBitsNode,
1360 Annotations.get(), Storage, ShouldCreate);
1361 }
1362 static DIDerivedType *
1363 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1366 std::optional<unsigned> DWARFAddressSpace,
1367 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1369 bool ShouldCreate = true) {
1370 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1372 DWARFAddressSpace, PtrAuthData, Flags, ExtraData,
1373 Annotations.get(), Storage, ShouldCreate);
1374 }
1375 LLVM_ABI static DIDerivedType *
1376 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1377 unsigned Line, Metadata *Scope, Metadata *BaseType,
1379 std::optional<unsigned> DWARFAddressSpace,
1380 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1382 bool ShouldCreate = true);
1383
1384 TempDIDerivedType cloneImpl() const {
1385 return getTemporary(
1388 getRawOffsetInBits(), getDWARFAddressSpace(), getPtrAuthData(),
1390 }
1391
1392public:
1393 DEFINE_MDNODE_GET(DIDerivedType,
1394 (unsigned Tag, MDString *Name, Metadata *File,
1395 unsigned Line, Metadata *Scope, Metadata *BaseType,
1398 std::optional<unsigned> DWARFAddressSpace,
1399 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1400 Metadata *ExtraData = nullptr,
1401 Metadata *Annotations = nullptr),
1403 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1405 DEFINE_MDNODE_GET(DIDerivedType,
1406 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1409 std::optional<unsigned> DWARFAddressSpace,
1410 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1412 DINodeArray Annotations = nullptr),
1414 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1416 DEFINE_MDNODE_GET(DIDerivedType,
1417 (unsigned Tag, MDString *Name, DIFile *File, unsigned Line,
1420 std::optional<unsigned> DWARFAddressSpace,
1421 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1422 Metadata *ExtraData = nullptr,
1423 DINodeArray Annotations = nullptr),
1425 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1427 DEFINE_MDNODE_GET(DIDerivedType,
1428 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1431 std::optional<unsigned> DWARFAddressSpace,
1432 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1433 Metadata *ExtraData = nullptr,
1434 DINodeArray Annotations = nullptr),
1436 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1438
1439 TempDIDerivedType clone() const { return cloneImpl(); }
1440
1441 /// Get the base type this is derived from.
1442 DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); }
1443 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1444
1445 /// \returns The DWARF address space of the memory pointed to or referenced by
1446 /// a pointer or reference type respectively.
1447 std::optional<unsigned> getDWARFAddressSpace() const {
1448 return DWARFAddressSpace;
1449 }
1450
1451 LLVM_ABI std::optional<PtrAuthData> getPtrAuthData() const;
1452
1453 /// Get extra data associated with this derived type.
1454 ///
1455 /// Class type for pointer-to-members, objective-c property node for ivars,
1456 /// global constant wrapper for static members, virtual base pointer offset
1457 /// for inheritance, a tuple of template parameters for template aliases,
1458 /// discriminant for a variant, or storage offset for a bit field.
1459 ///
1460 /// TODO: Separate out types that need this extra operand: pointer-to-member
1461 /// types and member fields (static members and ivars).
1463 Metadata *getRawExtraData() const { return getOperand(MY_FIRST_OPERAND + 1); }
1464
1465 /// Get the template parameters from a template alias.
1466 DITemplateParameterArray getTemplateParams() const {
1468 }
1469
1470 /// Get annotations associated with this derived type.
1471 DINodeArray getAnnotations() const {
1473 }
1475 return getOperand(MY_FIRST_OPERAND + 2);
1476 }
1477
1478 /// Get casted version of extra data.
1479 /// @{
1480 LLVM_ABI DIType *getClassType() const;
1481
1485
1487
1489
1490 LLVM_ABI Constant *getConstant() const;
1491
1493 /// @}
1494
1495 static bool classof(const Metadata *MD) {
1496 return MD->getMetadataID() == DIDerivedTypeKind;
1497 }
1498};
1499
1502 return Lhs.RawData == Rhs.RawData;
1503}
1504
1507 return !(Lhs == Rhs);
1508}
1509
1510/// Subrange type. This is somewhat similar to DISubrange, but it
1511/// is also a DIType.
1512class DISubrangeType : public DIType {
1513public:
1515 DIDerivedType *>
1517
1518private:
1519 friend class LLVMContextImpl;
1520 friend class MDNode;
1521
1522 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1523
1524 DISubrangeType(LLVMContext &C, StorageType Storage, unsigned Line,
1526
1527 ~DISubrangeType() = default;
1528
1529 static DISubrangeType *
1530 getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
1534 StorageType Storage, bool ShouldCreate = true) {
1535 auto *SizeInBitsNode = ConstantAsMetadata::get(
1536 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1537 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1538 Scope, SizeInBitsNode, AlignInBits, Flags, BaseType,
1539 LowerBound, UpperBound, Stride, Bias, Storage, ShouldCreate);
1540 }
1541
1542 LLVM_ABI static DISubrangeType *
1543 getImpl(LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
1545 DIFlags Flags, Metadata *BaseType, Metadata *LowerBound,
1547 StorageType Storage, bool ShouldCreate = true);
1548
1549 TempDISubrangeType cloneImpl() const {
1554 }
1555
1556 LLVM_ABI BoundType convertRawToBound(Metadata *IN) const;
1557
1558public:
1559 DEFINE_MDNODE_GET(DISubrangeType,
1560 (MDString * Name, Metadata *File, unsigned Line,
1567 DEFINE_MDNODE_GET(DISubrangeType,
1574
1575 TempDISubrangeType clone() const { return cloneImpl(); }
1576
1577 /// Get the base type this is derived from.
1579 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1580
1582 return getOperand(MY_FIRST_OPERAND + 1).get();
1583 }
1584
1586 return getOperand(MY_FIRST_OPERAND + 2).get();
1587 }
1588
1590 return getOperand(MY_FIRST_OPERAND + 3).get();
1591 }
1592
1594 return getOperand(MY_FIRST_OPERAND + 4).get();
1595 }
1596
1598 return convertRawToBound(getRawLowerBound());
1599 }
1600
1602 return convertRawToBound(getRawUpperBound());
1603 }
1604
1605 BoundType getStride() const { return convertRawToBound(getRawStride()); }
1606
1607 BoundType getBias() const { return convertRawToBound(getRawBias()); }
1608
1609 static bool classof(const Metadata *MD) {
1610 return MD->getMetadataID() == DISubrangeTypeKind;
1611 }
1612};
1613
1614/// Composite types.
1615///
1616/// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
1617/// TODO: Create a custom, unrelated node for DW_TAG_array_type.
1618class DICompositeType : public DIType {
1619 friend class LLVMContextImpl;
1620 friend class MDNode;
1621
1622 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1623
1624 unsigned RuntimeLang;
1625 std::optional<uint32_t> EnumKind;
1626
1627 DICompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
1628 unsigned Line, unsigned RuntimeLang, uint32_t AlignInBits,
1630 std::optional<uint32_t> EnumKind, DIFlags Flags,
1632 : DIType(C, DICompositeTypeKind, Storage, Tag, Line, AlignInBits,
1634 RuntimeLang(RuntimeLang), EnumKind(EnumKind) {}
1635 ~DICompositeType() = default;
1636
1637 /// Change fields in place.
1638 void mutate(unsigned Tag, unsigned Line, unsigned RuntimeLang,
1640 std::optional<uint32_t> EnumKind, DIFlags Flags) {
1641 assert(isDistinct() && "Only distinct nodes can mutate");
1642 assert(getRawIdentifier() && "Only ODR-uniqued nodes should mutate");
1643 this->RuntimeLang = RuntimeLang;
1644 this->EnumKind = EnumKind;
1646 }
1647
1648 static DICompositeType *
1649 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
1650 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1652 uint32_t NumExtraInhabitants, DIFlags Flags, DINodeArray Elements,
1653 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1654 DIType *VTableHolder, DITemplateParameterArray TemplateParams,
1655 StringRef Identifier, DIDerivedType *Discriminator,
1657 Metadata *Rank, DINodeArray Annotations, Metadata *BitStride,
1658 StorageType Storage, bool ShouldCreate = true) {
1659 auto *SizeInBitsNode = ConstantAsMetadata::get(
1660 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1661 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1662 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1663 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1664 Line, Scope, BaseType, SizeInBitsNode, AlignInBits,
1665 OffsetInBitsNode, Flags, Elements.get(), RuntimeLang,
1667 getCanonicalMDString(Context, Identifier), Discriminator,
1670 ShouldCreate);
1671 }
1672 static DICompositeType *
1673 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1674 unsigned Line, Metadata *Scope, Metadata *BaseType,
1676 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
1677 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1682 Metadata *BitStride, StorageType Storage, bool ShouldCreate = true) {
1683 auto *SizeInBitsNode = ConstantAsMetadata::get(
1684 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1685 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1686 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1687 return getImpl(Context, Tag, Name, File, Line, Scope, BaseType,
1688 SizeInBitsNode, AlignInBits, OffsetInBitsNode, Flags,
1689 Elements, RuntimeLang, EnumKind, VTableHolder,
1692 NumExtraInhabitants, BitStride, Storage, ShouldCreate);
1693 }
1694 static DICompositeType *
1695 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
1698 uint32_t NumExtraInhabitants, DIFlags Flags, DINodeArray Elements,
1699 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1700 DIType *VTableHolder, DITemplateParameterArray TemplateParams,
1701 StringRef Identifier, DIDerivedType *Discriminator,
1703 Metadata *Rank, DINodeArray Annotations, Metadata *BitStride,
1704 StorageType Storage, bool ShouldCreate = true) {
1705 return getImpl(
1706 Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
1708 RuntimeLang, EnumKind, VTableHolder, TemplateParams.get(),
1711 NumExtraInhabitants, BitStride, Storage, ShouldCreate);
1712 }
1713 LLVM_ABI static DICompositeType *
1714 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1715 unsigned Line, Metadata *Scope, Metadata *BaseType,
1717 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
1718 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1723 Metadata *BitStride, StorageType Storage, bool ShouldCreate = true);
1724
1725 TempDICompositeType cloneImpl() const {
1726 return getTemporary(
1734 getRawBitStride());
1735 }
1736
1737public:
1739 DICompositeType,
1740 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1743 DINodeArray Elements, unsigned RuntimeLang,
1744 std::optional<uint32_t> EnumKind, DIType *VTableHolder,
1745 DITemplateParameterArray TemplateParams = nullptr,
1747 Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
1748 Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
1749 DINodeArray Annotations = nullptr, DIType *Specification = nullptr,
1753 RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier,
1755 BitStride))
1757 DICompositeType,
1758 (unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
1761 Metadata *Elements, unsigned RuntimeLang,
1762 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1765 Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
1766 Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
1768 Metadata *BitStride = nullptr),
1770 OffsetInBits, Flags, Elements, RuntimeLang, EnumKind, VTableHolder,
1773 BitStride))
1775 DICompositeType,
1776 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1779 DINodeArray Elements, unsigned RuntimeLang,
1780 std::optional<uint32_t> EnumKind, DIType *VTableHolder,
1781 DITemplateParameterArray TemplateParams = nullptr,
1783 Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
1784 Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
1785 DINodeArray Annotations = nullptr, DIType *Specification = nullptr,
1789 RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier,
1791 BitStride))
1793 DICompositeType,
1794 (unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
1797 Metadata *Elements, unsigned RuntimeLang,
1798 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1799 Metadata *TemplateParams = nullptr, MDString *Identifier = nullptr,
1800 Metadata *Discriminator = nullptr, Metadata *DataLocation = nullptr,
1801 Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
1802 Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
1804 Metadata *BitStride = nullptr),
1806 OffsetInBits, Flags, Elements, RuntimeLang, EnumKind, VTableHolder,
1809 BitStride))
1810
1811 TempDICompositeType clone() const { return cloneImpl(); }
1812
1813 /// Get a DICompositeType with the given ODR identifier.
1814 ///
1815 /// If \a LLVMContext::isODRUniquingDebugTypes(), gets the mapped
1816 /// DICompositeType for the given ODR \c Identifier. If none exists, creates
1817 /// a new node.
1818 ///
1819 /// Else, returns \c nullptr.
1820 LLVM_ABI static DICompositeType *
1821 getODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1822 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1826 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1832 MDString &Identifier);
1833
1834 /// Build a DICompositeType with the given ODR identifier.
1835 ///
1836 /// Looks up the mapped DICompositeType for the given ODR \c Identifier. If
1837 /// it doesn't exist, creates a new one. If it does exist and \a
1838 /// isForwardDecl(), and the new arguments would be a definition, mutates the
1839 /// the type in place. In either case, returns the type.
1840 ///
1841 /// If not \a LLVMContext::isODRUniquingDebugTypes(), this function returns
1842 /// nullptr.
1843 LLVM_ABI static DICompositeType *
1844 buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1845 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1849 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1854
1856 DINodeArray getElements() const {
1858 }
1862 DITemplateParameterArray getTemplateParams() const {
1864 }
1866 return getStringOperand(MY_FIRST_OPERAND + 4);
1867 }
1868 unsigned getRuntimeLang() const { return RuntimeLang; }
1869 std::optional<uint32_t> getEnumKind() const { return EnumKind; }
1870
1871 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1872 Metadata *getRawElements() const { return getOperand(MY_FIRST_OPERAND + 1); }
1874 return getOperand(MY_FIRST_OPERAND + 2);
1875 }
1877 return getOperand(MY_FIRST_OPERAND + 3);
1878 }
1880 return getOperandAs<MDString>(MY_FIRST_OPERAND + 4);
1881 }
1883 return getOperand(MY_FIRST_OPERAND + 5);
1884 }
1886 return getOperandAs<DIDerivedType>(MY_FIRST_OPERAND + 5);
1887 }
1889 return getOperand(MY_FIRST_OPERAND + 6);
1890 }
1898 return getOperand(MY_FIRST_OPERAND + 7);
1899 }
1906 Metadata *getRawAllocated() const { return getOperand(MY_FIRST_OPERAND + 8); }
1913 Metadata *getRawRank() const { return getOperand(MY_FIRST_OPERAND + 9); }
1916 return dyn_cast_or_null<ConstantInt>(MD->getValue());
1917 return nullptr;
1918 }
1922
1924 return getOperand(MY_FIRST_OPERAND + 10);
1925 }
1926 DINodeArray getAnnotations() const {
1928 }
1929
1931 return getOperand(MY_FIRST_OPERAND + 11);
1932 }
1936
1937 bool isNameSimplified() const { return getFlags() & FlagNameIsSimplified; }
1938
1940 return getOperand(MY_FIRST_OPERAND + 12);
1941 }
1944 return dyn_cast_or_null<ConstantInt>(MD->getValue());
1945 return nullptr;
1946 }
1947
1948 /// Replace operands.
1949 ///
1950 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
1951 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
1952 /// of its movement if necessary.
1953 /// @{
1954 void replaceElements(DINodeArray Elements) {
1955#ifndef NDEBUG
1956 for (DINode *Op : getElements())
1957 assert(is_contained(Elements->operands(), Op) &&
1958 "Lost a member during member list replacement");
1959#endif
1960 replaceOperandWith(MY_FIRST_OPERAND + 1, Elements.get());
1961 }
1962
1964 replaceOperandWith(MY_FIRST_OPERAND + 2, VTableHolder);
1965 }
1966
1967 void replaceTemplateParams(DITemplateParameterArray TemplateParams) {
1968 replaceOperandWith(MY_FIRST_OPERAND + 3, TemplateParams.get());
1969 }
1970 /// @}
1971
1972 static bool classof(const Metadata *MD) {
1973 return MD->getMetadataID() == DICompositeTypeKind;
1974 }
1975};
1976
1977/// Type array for a subprogram.
1978///
1979/// TODO: Fold the array of types in directly as operands.
1980class DISubroutineType : public DIType {
1981 friend class LLVMContextImpl;
1982 friend class MDNode;
1983
1984 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1985
1986 /// The calling convention used with DW_AT_calling_convention. Actually of
1987 /// type dwarf::CallingConvention.
1988 uint8_t CC;
1989
1990 DISubroutineType(LLVMContext &C, StorageType Storage, DIFlags Flags,
1992 ~DISubroutineType() = default;
1993
1994 static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
1995 uint8_t CC, DITypeArray TypeArray,
1997 bool ShouldCreate = true) {
1998 return getImpl(Context, Flags, CC, TypeArray.get(), Storage, ShouldCreate);
1999 }
2000 LLVM_ABI static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
2003 bool ShouldCreate = true);
2004
2005 TempDISubroutineType cloneImpl() const {
2007 }
2008
2009public:
2010 DEFINE_MDNODE_GET(DISubroutineType,
2011 (DIFlags Flags, uint8_t CC, DITypeArray TypeArray),
2012 (Flags, CC, TypeArray))
2013 DEFINE_MDNODE_GET(DISubroutineType,
2016
2017 TempDISubroutineType clone() const { return cloneImpl(); }
2018 // Returns a new temporary DISubroutineType with updated CC
2019 TempDISubroutineType cloneWithCC(uint8_t CC) const {
2020 auto NewTy = clone();
2021 NewTy->CC = CC;
2022 return NewTy;
2023 }
2024
2025 uint8_t getCC() const { return CC; }
2026
2027 DITypeArray getTypeArray() const {
2029 }
2030
2031 Metadata *getRawTypeArray() const { return getOperand(MY_FIRST_OPERAND); }
2032
2033 static bool classof(const Metadata *MD) {
2034 return MD->getMetadataID() == DISubroutineTypeKind;
2035 }
2036};
2037
2038/// Compile unit.
2039class DICompileUnit : public DIScope {
2040 friend class LLVMContextImpl;
2041 friend class MDNode;
2042
2043public:
2051
2059
2060 LLVM_ABI static std::optional<DebugEmissionKind>
2062 LLVM_ABI static const char *emissionKindString(DebugEmissionKind EK);
2063 LLVM_ABI static std::optional<DebugNameTableKind>
2065 LLVM_ABI static const char *nameTableKindString(DebugNameTableKind PK);
2066
2067private:
2068 DISourceLanguageName SourceLanguage;
2069 unsigned RuntimeVersion;
2071 unsigned EmissionKind;
2072 unsigned NameTableKind;
2073 bool IsOptimized;
2074 bool SplitDebugInlining;
2076 bool RangesBaseAddress;
2077
2079 DISourceLanguageName SourceLanguage, bool IsOptimized,
2080 unsigned RuntimeVersion, unsigned EmissionKind, uint64_t DWOId,
2082 unsigned NameTableKind, bool RangesBaseAddress,
2084 ~DICompileUnit() = default;
2085
2086 static DICompileUnit *
2087 getImpl(LLVMContext &Context, DISourceLanguageName SourceLanguage,
2090 unsigned EmissionKind, DICompositeTypeArray EnumTypes,
2091 DIScopeArray RetainedTypes,
2092 DIGlobalVariableExpressionArray GlobalVariables,
2093 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
2096 StringRef SDK, StorageType Storage, bool ShouldCreate = true) {
2097 return getImpl(
2098 Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
2101 EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
2104 getCanonicalMDString(Context, SysRoot),
2105 getCanonicalMDString(Context, SDK), Storage, ShouldCreate);
2106 }
2107 LLVM_ABI static DICompileUnit *
2108 getImpl(LLVMContext &Context, DISourceLanguageName SourceLanguage,
2109 Metadata *File, MDString *Producer, bool IsOptimized, MDString *Flags,
2110 unsigned RuntimeVersion, MDString *SplitDebugFilename,
2114 bool DebugInfoForProfiling, unsigned NameTableKind,
2115 bool RangesBaseAddress, MDString *SysRoot, MDString *SDK,
2116 StorageType Storage, bool ShouldCreate = true);
2117
2118 TempDICompileUnit cloneImpl() const {
2119 return getTemporary(
2126 }
2127
2128public:
2129 static void get() = delete;
2130 static void getIfExists() = delete;
2131
2133 DICompileUnit,
2135 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
2137 DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes,
2138 DIGlobalVariableExpressionArray GlobalVariables,
2139 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
2140 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
2141 DebugNameTableKind NameTableKind, bool RangesBaseAddress,
2143 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
2145 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
2146 DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress,
2147 SysRoot, SDK))
2149 DICompileUnit,
2151 bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
2155 bool SplitDebugInlining, bool DebugInfoForProfiling,
2156 unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
2158 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
2160 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
2161 DebugInfoForProfiling, NameTableKind, RangesBaseAddress, SysRoot, SDK))
2162
2163 TempDICompileUnit clone() const { return cloneImpl(); }
2164
2165 DISourceLanguageName getSourceLanguage() const { return SourceLanguage; }
2166 bool isOptimized() const { return IsOptimized; }
2167 bool isDebugInfoForProfiling() const { return DebugInfoForProfiling; }
2168 unsigned getRuntimeVersion() const { return RuntimeVersion; }
2170 return (DebugEmissionKind)EmissionKind;
2171 }
2172 // Return true if this CU was compiled with debug info disabled
2173 bool isNoDebug() const { return EmissionKind == NoDebug; }
2175 return EmissionKind == DebugDirectivesOnly;
2176 }
2177 bool getDebugInfoForProfiling() const { return DebugInfoForProfiling; }
2179 return (DebugNameTableKind)NameTableKind;
2180 }
2181 bool getRangesBaseAddress() const { return RangesBaseAddress; }
2183 StringRef getFlags() const { return getStringOperand(2); }
2185 DICompositeTypeArray getEnumTypes() const {
2187 }
2188 DIScopeArray getRetainedTypes() const {
2190 }
2191 DIGlobalVariableExpressionArray getGlobalVariables() const {
2193 }
2194 DIImportedEntityArray getImportedEntities() const {
2196 }
2197 DIMacroNodeArray getMacros() const {
2199 }
2200 uint64_t getDWOId() const { return DWOId; }
2201 void setDWOId(uint64_t DwoId) { DWOId = DwoId; }
2202 bool getSplitDebugInlining() const { return SplitDebugInlining; }
2203 void setSplitDebugInlining(bool SplitDebugInlining) {
2204 this->SplitDebugInlining = SplitDebugInlining;
2205 }
2207 StringRef getSDK() const { return getStringOperand(10); }
2208 /// Target-specific language dialect for DWARF.
2209 uint16_t getDialect() const { return SourceLanguage.getDialect(); }
2210
2216 Metadata *getRawEnumTypes() const { return getOperand(4); }
2220 Metadata *getRawMacros() const { return getOperand(8); }
2223 /// Replace arrays.
2224 ///
2225 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
2226 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
2227 /// DICompileUnit should be fairly rare.
2228 /// @{
2229 void replaceEnumTypes(DICompositeTypeArray N) {
2230 replaceOperandWith(4, N.get());
2231 }
2232 void replaceRetainedTypes(DITypeArray N) { replaceOperandWith(5, N.get()); }
2233 void replaceGlobalVariables(DIGlobalVariableExpressionArray N) {
2234 replaceOperandWith(6, N.get());
2235 }
2236 void replaceImportedEntities(DIImportedEntityArray N) {
2237 replaceOperandWith(7, N.get());
2238 }
2239 void replaceMacros(DIMacroNodeArray N) { replaceOperandWith(8, N.get()); }
2240 /// @}
2241
2242 static bool classof(const Metadata *MD) {
2243 return MD->getMetadataID() == DICompileUnitKind;
2244 }
2245};
2246
2247/// A scope for locals.
2248///
2249/// A legal scope for lexical blocks, local variables, and debug info
2250/// locations. Subclasses are \a DISubprogram, \a DILexicalBlock, and \a
2251/// DILexicalBlockFile.
2252class DILocalScope : public DIScope {
2253protected:
2256 : DIScope(C, ID, Storage, Tag, Ops) {}
2257 ~DILocalScope() = default;
2258
2259public:
2260 /// Get the subprogram for this scope.
2261 ///
2262 /// Return this if it's an \a DISubprogram; otherwise, look up the scope
2263 /// chain.
2265
2266 /// Traverses the scope chain rooted at RootScope until it hits a Subprogram,
2267 /// recreating the chain with "NewSP" instead.
2268 LLVM_ABI static DILocalScope *
2270 LLVMContext &Ctx,
2272
2273 /// Get the first non DILexicalBlockFile scope of this scope.
2274 ///
2275 /// Return this if it's not a \a DILexicalBlockFIle; otherwise, look up the
2276 /// scope chain.
2278
2279 static bool classof(const Metadata *MD) {
2280 return MD->getMetadataID() == DISubprogramKind ||
2281 MD->getMetadataID() == DILexicalBlockKind ||
2282 MD->getMetadataID() == DILexicalBlockFileKind;
2283 }
2284};
2285
2286/// Subprogram description. Uses SubclassData1.
2287class DISubprogram : public DILocalScope {
2288 friend class LLVMContextImpl;
2289 friend class MDNode;
2290
2291 unsigned Line;
2292 unsigned ScopeLine;
2293 unsigned VirtualIndex;
2294
2295 /// In the MS ABI, the implicit 'this' parameter is adjusted in the prologue
2296 /// of method overrides from secondary bases by this amount. It may be
2297 /// negative.
2298 int ThisAdjustment;
2299
2300public:
2301 /// Debug info subprogram flags.
2303#define HANDLE_DISP_FLAG(ID, NAME) SPFlag##NAME = ID,
2304#define DISP_FLAG_LARGEST_NEEDED
2305#include "llvm/IR/DebugInfoFlags.def"
2306 SPFlagNonvirtual = SPFlagZero,
2307 SPFlagVirtuality = SPFlagVirtual | SPFlagPureVirtual,
2308 LLVM_MARK_AS_BITMASK_ENUM(SPFlagLargest)
2309 };
2310
2311 LLVM_ABI static DISPFlags getFlag(StringRef Flag);
2312 LLVM_ABI static StringRef getFlagString(DISPFlags Flag);
2313
2314 /// Split up a flags bitfield for easier printing.
2315 ///
2316 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
2317 /// any remaining (unrecognized) bits.
2318 LLVM_ABI static DISPFlags splitFlags(DISPFlags Flags,
2319 SmallVectorImpl<DISPFlags> &SplitFlags);
2320
2321 // Helper for converting old bitfields to new flags word.
2322 LLVM_ABI static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition,
2323 bool IsOptimized,
2324 unsigned Virtuality = SPFlagNonvirtual,
2325 bool IsMainSubprogram = false);
2326
2327private:
2328 DIFlags Flags;
2329 DISPFlags SPFlags;
2330
2331 DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
2332 unsigned ScopeLine, unsigned VirtualIndex, int ThisAdjustment,
2333 DIFlags Flags, DISPFlags SPFlags, bool UsesKeyInstructions,
2335 ~DISubprogram() = default;
2336
2337 static DISubprogram *
2338 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
2339 StringRef LinkageName, DIFile *File, unsigned Line,
2341 unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags,
2342 DISPFlags SPFlags, DICompileUnit *Unit,
2343 DITemplateParameterArray TemplateParams, DISubprogram *Declaration,
2344 MDNodeArray RetainedNodes, DITypeArray ThrownTypes,
2347 bool ShouldCreate = true) {
2348 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
2349 getCanonicalMDString(Context, LinkageName), File, Line, Type,
2351 Flags, SPFlags, Unit, TemplateParams.get(), Declaration,
2352 RetainedNodes.get(), ThrownTypes.get(), Annotations.get(),
2354 UsesKeyInstructions, Storage, ShouldCreate);
2355 }
2356
2357 LLVM_ABI static DISubprogram *
2358 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
2359 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
2360 unsigned ScopeLine, Metadata *ContainingType, unsigned VirtualIndex,
2361 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
2364 MDString *TargetFuncName, bool UsesKeyInstructions,
2365 StorageType Storage, bool ShouldCreate = true);
2366
2367 TempDISubprogram cloneImpl() const {
2369 getFile(), getLine(), getType(), getScopeLine(),
2370 getContainingType(), getVirtualIndex(),
2371 getThisAdjustment(), getFlags(), getSPFlags(),
2372 getUnit(), getTemplateParams(), getDeclaration(),
2373 getRetainedNodes(), getThrownTypes(), getAnnotations(),
2374 getTargetFuncName(), getKeyInstructionsEnabled());
2375 }
2376
2377public:
2379 DISubprogram,
2381 unsigned Line, DISubroutineType *Type, unsigned ScopeLine,
2382 DIType *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
2383 DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit,
2384 DITemplateParameterArray TemplateParams = nullptr,
2385 DISubprogram *Declaration = nullptr, MDNodeArray RetainedNodes = nullptr,
2386 DITypeArray ThrownTypes = nullptr, DINodeArray Annotations = nullptr,
2387 StringRef TargetFuncName = "", bool UsesKeyInstructions = false),
2388 (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
2389 VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
2392
2394 DISubprogram,
2396 unsigned Line, Metadata *Type, unsigned ScopeLine,
2397 Metadata *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
2398 DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
2402 bool UsesKeyInstructions = false),
2403 (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
2404 VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
2407
2408 TempDISubprogram clone() const { return cloneImpl(); }
2409
2410 /// Returns a new temporary DISubprogram with updated Flags
2411 TempDISubprogram cloneWithFlags(DIFlags NewFlags) const {
2412 auto NewSP = clone();
2413 NewSP->Flags = NewFlags;
2414 return NewSP;
2415 }
2416
2417 bool getKeyInstructionsEnabled() const { return SubclassData1; }
2418
2419public:
2420 unsigned getLine() const { return Line; }
2421 unsigned getVirtuality() const { return getSPFlags() & SPFlagVirtuality; }
2422 unsigned getVirtualIndex() const { return VirtualIndex; }
2423 int getThisAdjustment() const { return ThisAdjustment; }
2424 unsigned getScopeLine() const { return ScopeLine; }
2425 void setScopeLine(unsigned L) {
2426 assert(isDistinct());
2427 ScopeLine = L;
2428 }
2429 DIFlags getFlags() const { return Flags; }
2430 DISPFlags getSPFlags() const { return SPFlags; }
2431 bool isLocalToUnit() const { return getSPFlags() & SPFlagLocalToUnit; }
2432 bool isDefinition() const { return getSPFlags() & SPFlagDefinition; }
2433 bool isOptimized() const { return getSPFlags() & SPFlagOptimized; }
2434 bool isMainSubprogram() const { return getSPFlags() & SPFlagMainSubprogram; }
2435
2436 bool isArtificial() const { return getFlags() & FlagArtificial; }
2437 bool isPrivate() const {
2438 return (getFlags() & FlagAccessibility) == FlagPrivate;
2439 }
2440 bool isProtected() const {
2441 return (getFlags() & FlagAccessibility) == FlagProtected;
2442 }
2443 bool isPublic() const {
2444 return (getFlags() & FlagAccessibility) == FlagPublic;
2445 }
2446 bool isExplicit() const { return getFlags() & FlagExplicit; }
2447 bool isPrototyped() const { return getFlags() & FlagPrototyped; }
2448 bool isNameSimplified() const { return getFlags() & FlagNameIsSimplified; }
2449 bool areAllCallsDescribed() const {
2450 return getFlags() & FlagAllCallsDescribed;
2451 }
2452 bool isPure() const { return getSPFlags() & SPFlagPure; }
2453 bool isElemental() const { return getSPFlags() & SPFlagElemental; }
2454 bool isRecursive() const { return getSPFlags() & SPFlagRecursive; }
2455 bool isObjCDirect() const { return getSPFlags() & SPFlagObjCDirect; }
2456
2457 /// Check if this is deleted member function.
2458 ///
2459 /// Return true if this subprogram is a C++11 special
2460 /// member function declared deleted.
2461 bool isDeleted() const { return getSPFlags() & SPFlagDeleted; }
2462
2463 /// Check if this is reference-qualified.
2464 ///
2465 /// Return true if this subprogram is a C++11 reference-qualified non-static
2466 /// member function (void foo() &).
2467 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
2468
2469 /// Check if this is rvalue-reference-qualified.
2470 ///
2471 /// Return true if this subprogram is a C++11 rvalue-reference-qualified
2472 /// non-static member function (void foo() &&).
2473 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
2474
2475 /// Check if this is marked as noreturn.
2476 ///
2477 /// Return true if this subprogram is C++11 noreturn or C11 _Noreturn
2478 bool isNoReturn() const { return getFlags() & FlagNoReturn; }
2479
2480 // Check if this routine is a compiler-generated thunk.
2481 //
2482 // Returns true if this subprogram is a thunk generated by the compiler.
2483 bool isThunk() const { return getFlags() & FlagThunk; }
2484
2485 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2486
2487 StringRef getName() const { return getStringOperand(2); }
2488 StringRef getLinkageName() const { return getStringOperand(3); }
2489 /// Only used by clients of CloneFunction, and only right after the cloning.
2490 void replaceLinkageName(MDString *LN) { replaceOperandWith(3, LN); }
2491
2492 DISubroutineType *getType() const {
2493 return cast_or_null<DISubroutineType>(getRawType());
2494 }
2495 DIType *getContainingType() const {
2496 return cast_or_null<DIType>(getRawContainingType());
2497 }
2498 void replaceType(DISubroutineType *Ty) {
2499 assert(isDistinct() && "Only distinct nodes can mutate");
2500 replaceOperandWith(4, Ty);
2501 }
2502
2503 DICompileUnit *getUnit() const {
2504 return cast_or_null<DICompileUnit>(getRawUnit());
2505 }
2506 void replaceUnit(DICompileUnit *CU) { replaceOperandWith(5, CU); }
2507 DITemplateParameterArray getTemplateParams() const {
2508 return cast_or_null<MDTuple>(getRawTemplateParams());
2509 }
2510 DISubprogram *getDeclaration() const {
2511 return cast_or_null<DISubprogram>(getRawDeclaration());
2512 }
2513 void replaceDeclaration(DISubprogram *Decl) { replaceOperandWith(6, Decl); }
2514 MDNodeArray getRetainedNodes() const {
2515 return cast_or_null<MDTuple>(getRawRetainedNodes());
2516 }
2517 DITypeArray getThrownTypes() const {
2518 return cast_or_null<MDTuple>(getRawThrownTypes());
2519 }
2520 DINodeArray getAnnotations() const {
2521 return cast_or_null<MDTuple>(getRawAnnotations());
2522 }
2523 StringRef getTargetFuncName() const {
2524 return (getRawTargetFuncName()) ? getStringOperand(12) : StringRef();
2525 }
2526
2527 Metadata *getRawScope() const { return getOperand(1); }
2528 MDString *getRawName() const { return getOperandAs<MDString>(2); }
2529 MDString *getRawLinkageName() const { return getOperandAs<MDString>(3); }
2530 Metadata *getRawType() const { return getOperand(4); }
2531 Metadata *getRawUnit() const { return getOperand(5); }
2532 Metadata *getRawDeclaration() const { return getOperand(6); }
2533 Metadata *getRawRetainedNodes() const { return getOperand(7); }
2534 Metadata *getRawContainingType() const {
2535 return getNumOperands() > 8 ? getOperandAs<Metadata>(8) : nullptr;
2536 }
2537 Metadata *getRawTemplateParams() const {
2538 return getNumOperands() > 9 ? getOperandAs<Metadata>(9) : nullptr;
2539 }
2540 Metadata *getRawThrownTypes() const {
2541 return getNumOperands() > 10 ? getOperandAs<Metadata>(10) : nullptr;
2542 }
2543 Metadata *getRawAnnotations() const {
2544 return getNumOperands() > 11 ? getOperandAs<Metadata>(11) : nullptr;
2545 }
2546 MDString *getRawTargetFuncName() const {
2547 return getNumOperands() > 12 ? getOperandAs<MDString>(12) : nullptr;
2548 }
2549
2550 void replaceRawLinkageName(MDString *LinkageName) {
2552 }
2553 void replaceRetainedNodes(MDNodeArray N) { replaceOperandWith(7, N.get()); }
2554
2555 template <typename IterT> void retainNodes(IterT NodesBegin, IterT NodesEnd) {
2556 auto RetainedNodes = getRetainedNodes();
2558 MDs.append(NodesBegin, NodesEnd);
2559 replaceRetainedNodes(MDNode::get(getContext(), MDs));
2560 }
2561
2562 /// For the given retained node of DISubprogram, applies one of the
2563 /// given functions depending on the type of the node.
2564 template <typename T, typename MetadataT, typename FuncLVT,
2565 typename FuncLabelT, typename FuncImportedEntityT,
2566 typename FuncTypeT, typename FuncGVET, typename FuncUnknownT>
2567 static T visitRetainedNode(MetadataT *N, FuncLVT &&FuncLV,
2568 FuncLabelT &&FuncLabel,
2569 FuncImportedEntityT &&FuncIE, FuncTypeT &&FuncType,
2570 FuncGVET &&FuncGVE, FuncUnknownT &&FuncUnknown) {
2571 static_assert(std::is_base_of_v<Metadata, MetadataT>,
2572 "N must point to Metadata or const Metadata");
2573
2574 if (auto *LV = dyn_cast<DILocalVariable>(N))
2575 return FuncLV(LV);
2576 if (auto *L = dyn_cast<DILabel>(N))
2577 return FuncLabel(L);
2578 if (auto *IE = dyn_cast<DIImportedEntity>(N))
2579 return FuncIE(IE);
2580 if (auto *Ty = dyn_cast<DIType>(N))
2581 return FuncType(Ty);
2582 if (auto *GVE = dyn_cast<DIGlobalVariableExpression>(N))
2583 return FuncGVE(GVE);
2584 return FuncUnknown(N);
2585 }
2586
2587 /// Returns the scope of subprogram's retainedNodes.
2588 LLVM_ABI static const DILocalScope *getRetainedNodeScope(const MDNode *N);
2590 // For use in Verifier.
2591 LLVM_ABI static const DIScope *getRawRetainedNodeScope(const MDNode *N);
2593
2594 /// For each retained node, applies one of the given functions depending
2595 /// on the type of a node.
2596 template <typename FuncLVT, typename FuncLabelT, typename FuncImportedEntityT,
2597 typename FuncTypeT, typename FuncGVET>
2598 void forEachRetainedNode(FuncLVT &&FuncLV, FuncLabelT &&FuncLabel,
2599 FuncImportedEntityT &&FuncIE, FuncTypeT &&FuncType,
2600 FuncGVET &&FuncGVE) {
2601 for (MDNode *N : getRetainedNodes())
2602 visitRetainedNode<void>(
2603 N, FuncLV, FuncLabel, FuncIE, FuncType, FuncGVE,
2604 [](auto *N) { llvm_unreachable("Unexpected retained node!"); });
2605 }
2606
2607 /// When IR modules are merged, typically during LTO, the merged module
2608 /// may contain several types having the same linkageName. They are
2609 /// supposed to represent the same type included by multiple source code
2610 /// files from a single header file.
2611 ///
2612 /// DebugTypeODRUniquing feature uniques (deduplicates) such types
2613 /// based on their linkageName during metadata loading, to speed up
2614 /// compilation and reduce debug info size.
2615 ///
2616 /// However, since function-local types are tracked in DISubprogram's
2617 /// retainedNodes field, a single local type may be referenced by multiple
2618 /// DISubprograms via retainedNodes as the result of DebugTypeODRUniquing.
2619 /// But retainedNodes field of a DISubprogram is meant to hold only
2620 /// subprogram's own local entities, therefore such references may
2621 /// cause crashes.
2622 ///
2623 /// To address this problem, this method is called for each new subprogram
2624 /// after module loading. It removes references to types belonging
2625 /// to other DISubprograms from a subprogram's retainedNodes list.
2626 /// If a corresponding IR function refers to local scopes from another
2627 /// subprogram, emitted debug info (e.g. DWARF) should rely
2628 /// on cross-subprogram references (and cross-CU references, as subprograms
2629 /// may belong to different compile units). This is also a drawback:
2630 /// when a subprogram refers to types that are local to another subprogram,
2631 /// it is more complicated for debugger to properly discover local types
2632 /// of a current scope for expression evaluation.
2634
2635 template <typename T> void cleanupRetainedNodesIf(T &&Pred) {
2636 MDTuple *RetainedNodes = dyn_cast_or_null<MDTuple>(getRawRetainedNodes());
2637 // As this is expected to be called during module loading, before
2638 // stripping old or incorrect debug info, perform minimal sanity check.
2639 if (!RetainedNodes)
2640 return;
2641 // replaceRetainedNodes() should not re-unique DISubprogram if new list is
2642 // the same pointer.
2643 replaceRetainedNodes(RetainedNodes->filter(Pred));
2644 }
2645
2646 /// Calls SP->cleanupRetainedNodes() for a range of DISubprograms.
2647 template <typename RangeT>
2648 static void cleanupRetainedNodes(const RangeT &NewDistinctSPs) {
2649 for (DISubprogram *SP : NewDistinctSPs)
2650 SP->cleanupRetainedNodes();
2651 }
2652
2653 /// Check if this subprogram describes the given function.
2654 ///
2655 /// FIXME: Should this be looking through bitcasts?
2656 LLVM_ABI bool describes(const Function *F) const;
2657
2658 static bool classof(const Metadata *MD) {
2659 return MD->getMetadataID() == DISubprogramKind;
2660 }
2661};
2662
2663/// Debug location.
2664///
2665/// A debug location in source code, used for debug info and otherwise.
2666///
2667/// Uses the SubclassData1, SubclassData16 and SubclassData32
2668/// Metadata slots.
2669
2670class DILocation : public MDNode {
2671 friend class LLVMContextImpl;
2672 friend class MDNode;
2673 uint64_t AtomGroup : 61;
2674 uint64_t AtomRank : 3;
2675
2676 DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
2677 unsigned Column, uint64_t AtomGroup, uint8_t AtomRank,
2679 ~DILocation() { dropAllReferences(); }
2680
2681 LLVM_ABI static DILocation *
2682 getImpl(LLVMContext &Context, unsigned Line, unsigned Column, Metadata *Scope,
2684 uint8_t AtomRank, StorageType Storage, bool ShouldCreate = true);
2685 static DILocation *getImpl(LLVMContext &Context, unsigned Line,
2686 unsigned Column, DILocalScope *Scope,
2689 StorageType Storage, bool ShouldCreate = true) {
2690 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
2691 static_cast<Metadata *>(InlinedAt), ImplicitCode, AtomGroup,
2692 AtomRank, Storage, ShouldCreate);
2693 }
2694
2695 TempDILocation cloneImpl() const {
2696 // Get the raw scope/inlinedAt since it is possible to invoke this on
2697 // a DILocation containing temporary metadata.
2698 return getTemporary(getContext(), getLine(), getColumn(), getRawScope(),
2699 getRawInlinedAt(), isImplicitCode(), getAtomGroup(),
2700 getAtomRank());
2701 }
2702
2703public:
2704 uint64_t getAtomGroup() const { return AtomGroup; }
2705 uint8_t getAtomRank() const { return AtomRank; }
2706
2707 const DILocation *getWithoutAtom() const {
2708 if (!getAtomGroup() && !getAtomRank())
2709 return this;
2710 return get(getContext(), getLine(), getColumn(), getScope(), getInlinedAt(),
2711 isImplicitCode());
2712 }
2713
2714 // Disallow replacing operands.
2715 void replaceOperandWith(unsigned I, Metadata *New) = delete;
2716
2718 (unsigned Line, unsigned Column, Metadata *Scope,
2719 Metadata *InlinedAt = nullptr, bool ImplicitCode = false,
2720 uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2721 (Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2722 AtomRank))
2723 DEFINE_MDNODE_GET(DILocation,
2724 (unsigned Line, unsigned Column, DILocalScope *Scope,
2725 DILocation *InlinedAt = nullptr, bool ImplicitCode = false,
2726 uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2727 (Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2728 AtomRank))
2729
2730 /// Return a (temporary) clone of this.
2731 TempDILocation clone() const { return cloneImpl(); }
2732
2733 unsigned getLine() const { return SubclassData32; }
2734 unsigned getColumn() const { return SubclassData16; }
2735 DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
2736
2737 /// Return the linkage name of Subprogram. If the linkage name is empty,
2738 /// return scope name (the demangled name).
2739 StringRef getSubprogramLinkageName() const {
2740 DISubprogram *SP = getScope()->getSubprogram();
2741 if (!SP)
2742 return "";
2743 auto Name = SP->getLinkageName();
2744 if (!Name.empty())
2745 return Name;
2746 return SP->getName();
2747 }
2748
2749 DILocation *getInlinedAt() const {
2751 }
2752
2753 /// Check if the location corresponds to an implicit code.
2754 /// When the ImplicitCode flag is true, it means that the Instruction
2755 /// with this DILocation has been added by the front-end but it hasn't been
2756 /// written explicitly by the user (e.g. cleanup stuff in C++ put on a closing
2757 /// bracket). It's useful for code coverage to not show a counter on "empty"
2758 /// lines.
2759 bool isImplicitCode() const { return SubclassData1; }
2760 void setImplicitCode(bool ImplicitCode) { SubclassData1 = ImplicitCode; }
2761
2762 DIFile *getFile() const { return getScope()->getFile(); }
2763 StringRef getFilename() const { return getScope()->getFilename(); }
2764 StringRef getDirectory() const { return getScope()->getDirectory(); }
2765 std::optional<StringRef> getSource() const { return getScope()->getSource(); }
2766
2767 /// Walk through \a getInlinedAt() and return the \a DILocation of the
2768 /// outermost call site in the inlining chain.
2769 const DILocation *getInlinedAtLocation() const {
2770 const DILocation *Current = this;
2771 while (const DILocation *Next = Current->getInlinedAt())
2772 Current = Next;
2773 return Current;
2774 }
2775
2776 // Return the \a DILocalScope of the outermost call site in the inlining
2777 // chain.
2778 DILocalScope *getInlinedAtScope() const {
2779 return getInlinedAtLocation()->getScope();
2780 }
2781
2782 /// Get the DWARF discriminator.
2783 ///
2784 /// DWARF discriminators distinguish identical file locations between
2785 /// instructions that are on different basic blocks.
2786 ///
2787 /// There are 3 components stored in discriminator, from lower bits:
2788 ///
2789 /// Base discriminator: assigned by AddDiscriminators pass to identify IRs
2790 /// that are defined by the same source line, but
2791 /// different basic blocks.
2792 /// Duplication factor: assigned by optimizations that will scale down
2793 /// the execution frequency of the original IR.
2794 /// Copy Identifier: assigned by optimizations that clones the IR.
2795 /// Each copy of the IR will be assigned an identifier.
2796 ///
2797 /// Encoding:
2798 ///
2799 /// The above 3 components are encoded into a 32bit unsigned integer in
2800 /// order. If the lowest bit is 1, the current component is empty, and the
2801 /// next component will start in the next bit. Otherwise, the current
2802 /// component is non-empty, and its content starts in the next bit. The
2803 /// value of each components is either 5 bit or 12 bit: if the 7th bit
2804 /// is 0, the bit 2~6 (5 bits) are used to represent the component; if the
2805 /// 7th bit is 1, the bit 2~6 (5 bits) and 8~14 (7 bits) are combined to
2806 /// represent the component. Thus, the number of bits used for a component
2807 /// is either 0 (if it and all the next components are empty); 1 - if it is
2808 /// empty; 7 - if its value is up to and including 0x1f (lsb and msb are both
2809 /// 0); or 14, if its value is up to and including 0x1ff. Note that the last
2810 /// component is also capped at 0x1ff, even in the case when both first
2811 /// components are 0, and we'd technically have 29 bits available.
2812 ///
2813 /// For precise control over the data being encoded in the discriminator,
2814 /// use encodeDiscriminator/decodeDiscriminator.
2815
2816 inline unsigned getDiscriminator() const;
2817
2818 // For the regular discriminator, it stands for all empty components if all
2819 // the lowest 3 bits are non-zero and all higher 29 bits are unused(zero by
2820 // default). Here we fully leverage the higher 29 bits for pseudo probe use.
2821 // This is the format:
2822 // [2:0] - 0x7
2823 // [31:3] - pseudo probe fields guaranteed to be non-zero as a whole
2824 // So if the lower 3 bits is non-zero and the others has at least one
2825 // non-zero bit, it guarantees to be a pseudo probe discriminator
2826 inline static bool isPseudoProbeDiscriminator(unsigned Discriminator) {
2827 return ((Discriminator & 0x7) == 0x7) && (Discriminator & 0xFFFFFFF8);
2828 }
2829
2830 /// Returns a new DILocation with updated \p Discriminator.
2831 inline const DILocation *cloneWithDiscriminator(unsigned Discriminator) const;
2832
2833 /// Returns a new DILocation with updated base discriminator \p BD. Only the
2834 /// base discriminator is set in the new DILocation, the other encoded values
2835 /// are elided.
2836 /// If the discriminator cannot be encoded, the function returns std::nullopt.
2837 inline std::optional<const DILocation *>
2838 cloneWithBaseDiscriminator(unsigned BD) const;
2839
2840 /// Returns the duplication factor stored in the discriminator, or 1 if no
2841 /// duplication factor (or 0) is encoded.
2842 inline unsigned getDuplicationFactor() const;
2843
2844 /// Returns the copy identifier stored in the discriminator.
2845 inline unsigned getCopyIdentifier() const;
2846
2847 /// Returns the base discriminator stored in the discriminator.
2848 inline unsigned getBaseDiscriminator() const;
2849
2850 /// Returns a new DILocation with duplication factor \p DF * current
2851 /// duplication factor encoded in the discriminator. The current duplication
2852 /// factor is as defined by getDuplicationFactor().
2853 /// Returns std::nullopt if encoding failed.
2854 inline std::optional<const DILocation *>
2856
2857 /// Attempts to merge \p LocA and \p LocB into a single location; see
2858 /// DebugLoc::getMergedLocation for more details.
2859 /// NB: When merging the locations of instructions, prefer to use
2860 /// DebugLoc::getMergedLocation(), as an instruction's DebugLoc may contain
2861 /// additional metadata that will not be preserved when merging the unwrapped
2862 /// DILocations.
2864 DILocation *LocB);
2865
2866 /// Try to combine the vector of locations passed as input in a single one.
2867 /// This function applies getMergedLocation() repeatedly left-to-right.
2868 /// NB: When merging the locations of instructions, prefer to use
2869 /// DebugLoc::getMergedLocations(), as an instruction's DebugLoc may contain
2870 /// additional metadata that will not be preserved when merging the unwrapped
2871 /// DILocations.
2872 ///
2873 /// \p Locs: The locations to be merged.
2875
2876 /// Return the masked discriminator value for an input discrimnator value D
2877 /// (i.e. zero out the (B+1)-th and above bits for D (B is 0-base).
2878 // Example: an input of (0x1FF, 7) returns 0xFF.
2879 static unsigned getMaskedDiscriminator(unsigned D, unsigned B) {
2880 return (D & getN1Bits(B));
2881 }
2882
2883 /// Return the bits used for base discriminators.
2884 static unsigned getBaseDiscriminatorBits() { return getBaseFSBitEnd(); }
2885
2886 /// Returns the base discriminator for a given encoded discriminator \p D.
2887 static unsigned
2889 bool IsFSDiscriminator = false) {
2890 // Extract the dwarf base discriminator if it's encoded in the pseudo probe
2891 // discriminator.
2893 auto DwarfBaseDiscriminator =
2895 if (DwarfBaseDiscriminator)
2896 return *DwarfBaseDiscriminator;
2897 // Return the probe id instead of zero for a pseudo probe discriminator.
2898 // This should help differenciate callsites with same line numbers to
2899 // achieve a decent AutoFDO profile under -fpseudo-probe-for-profiling,
2900 // where the original callsite dwarf discriminator is overwritten by
2901 // callsite probe information.
2903 }
2904
2905 if (IsFSDiscriminator)
2908 }
2909
2910 /// Raw encoding of the discriminator. APIs such as cloneWithDuplicationFactor
2911 /// have certain special case behavior (e.g. treating empty duplication factor
2912 /// as the value '1').
2913 /// This API, in conjunction with cloneWithDiscriminator, may be used to
2914 /// encode the raw values provided.
2915 ///
2916 /// \p BD: base discriminator
2917 /// \p DF: duplication factor
2918 /// \p CI: copy index
2919 ///
2920 /// The return is std::nullopt if the values cannot be encoded in 32 bits -
2921 /// for example, values for BD or DF larger than 12 bits. Otherwise, the
2922 /// return is the encoded value.
2923 LLVM_ABI static std::optional<unsigned>
2924 encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI);
2925
2926 /// Raw decoder for values in an encoded discriminator D.
2927 LLVM_ABI static void decodeDiscriminator(unsigned D, unsigned &BD,
2928 unsigned &DF, unsigned &CI);
2929
2930 /// Returns the duplication factor for a given encoded discriminator \p D, or
2931 /// 1 if no value or 0 is encoded.
2932 static unsigned getDuplicationFactorFromDiscriminator(unsigned D) {
2934 return 1;
2936 unsigned Ret = getUnsignedFromPrefixEncoding(D);
2937 if (Ret == 0)
2938 return 1;
2939 return Ret;
2940 }
2941
2942 /// Returns the copy identifier for a given encoded discriminator \p D.
2947
2948 Metadata *getRawScope() const { return getOperand(0); }
2950 if (getNumOperands() == 2)
2951 return getOperand(1);
2952 return nullptr;
2953 }
2954
2955 static bool classof(const Metadata *MD) {
2956 return MD->getMetadataID() == DILocationKind;
2957 }
2958};
2959
2961protected:
2965
2966public:
2968
2969 Metadata *getRawScope() const { return getOperand(1); }
2970
2971 void replaceScope(DIScope *Scope) {
2972 assert(!isUniqued());
2973 setOperand(1, Scope);
2974 }
2975
2976 static bool classof(const Metadata *MD) {
2977 return MD->getMetadataID() == DILexicalBlockKind ||
2978 MD->getMetadataID() == DILexicalBlockFileKind;
2979 }
2980};
2981
2982/// Debug lexical block.
2983///
2984/// Uses the SubclassData32 Metadata slot.
2985class DILexicalBlock : public DILexicalBlockBase {
2986 friend class LLVMContextImpl;
2987 friend class MDNode;
2988
2989 uint16_t Column;
2990
2991 DILexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
2992 unsigned Column, ArrayRef<Metadata *> Ops)
2993 : DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops),
2994 Column(Column) {
2996 assert(Column < (1u << 16) && "Expected 16-bit column");
2997 }
2998 ~DILexicalBlock() = default;
2999
3000 static DILexicalBlock *getImpl(LLVMContext &Context, DILocalScope *Scope,
3001 DIFile *File, unsigned Line, unsigned Column,
3003 bool ShouldCreate = true) {
3004 return getImpl(Context, static_cast<Metadata *>(Scope),
3005 static_cast<Metadata *>(File), Line, Column, Storage,
3006 ShouldCreate);
3007 }
3008
3009 LLVM_ABI static DILexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
3010 Metadata *File, unsigned Line,
3011 unsigned Column, StorageType Storage,
3012 bool ShouldCreate = true);
3013
3014 TempDILexicalBlock cloneImpl() const {
3016 getColumn());
3017 }
3018
3019public:
3020 DEFINE_MDNODE_GET(DILexicalBlock,
3021 (DILocalScope * Scope, DIFile *File, unsigned Line,
3022 unsigned Column),
3023 (Scope, File, Line, Column))
3024 DEFINE_MDNODE_GET(DILexicalBlock,
3026 unsigned Column),
3027 (Scope, File, Line, Column))
3028
3029 TempDILexicalBlock clone() const { return cloneImpl(); }
3030
3031 unsigned getLine() const { return SubclassData32; }
3032 unsigned getColumn() const { return Column; }
3033
3034 static bool classof(const Metadata *MD) {
3035 return MD->getMetadataID() == DILexicalBlockKind;
3036 }
3037};
3038
3039class DILexicalBlockFile : public DILexicalBlockBase {
3040 friend class LLVMContextImpl;
3041 friend class MDNode;
3042
3043 DILexicalBlockFile(LLVMContext &C, StorageType Storage,
3045 : DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops) {
3047 }
3048 ~DILexicalBlockFile() = default;
3049
3050 static DILexicalBlockFile *getImpl(LLVMContext &Context, DILocalScope *Scope,
3051 DIFile *File, unsigned Discriminator,
3053 bool ShouldCreate = true) {
3054 return getImpl(Context, static_cast<Metadata *>(Scope),
3055 static_cast<Metadata *>(File), Discriminator, Storage,
3056 ShouldCreate);
3057 }
3058
3059 LLVM_ABI static DILexicalBlockFile *getImpl(LLVMContext &Context,
3060 Metadata *Scope, Metadata *File,
3061 unsigned Discriminator,
3063 bool ShouldCreate = true);
3064
3065 TempDILexicalBlockFile cloneImpl() const {
3066 return getTemporary(getContext(), getScope(), getFile(),
3068 }
3069
3070public:
3071 DEFINE_MDNODE_GET(DILexicalBlockFile,
3073 unsigned Discriminator),
3075 DEFINE_MDNODE_GET(DILexicalBlockFile,
3078
3079 TempDILexicalBlockFile clone() const { return cloneImpl(); }
3080 unsigned getDiscriminator() const { return SubclassData32; }
3081
3082 static bool classof(const Metadata *MD) {
3083 return MD->getMetadataID() == DILexicalBlockFileKind;
3084 }
3085};
3086
3087unsigned DILocation::getDiscriminator() const {
3089 return F->getDiscriminator();
3090 return 0;
3091}
3092
3093const DILocation *
3094DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
3095 DIScope *Scope = getScope();
3096 // Skip all parent DILexicalBlockFile that already have a discriminator
3097 // assigned. We do not want to have nested DILexicalBlockFiles that have
3098 // multiple discriminators because only the leaf DILexicalBlockFile's
3099 // dominator will be used.
3100 for (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope);
3101 LBF && LBF->getDiscriminator() != 0;
3103 Scope = LBF->getScope();
3104 DILexicalBlockFile *NewScope =
3105 DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator);
3106 return DILocation::get(getContext(), getLine(), getColumn(), NewScope,
3107 getInlinedAt(), isImplicitCode(), getAtomGroup(),
3108 getAtomRank());
3109}
3110
3112 return getBaseDiscriminatorFromDiscriminator(getDiscriminator(),
3114}
3115
3117 return getDuplicationFactorFromDiscriminator(getDiscriminator());
3118}
3119
3121 return getCopyIdentifierFromDiscriminator(getDiscriminator());
3122}
3123
3124std::optional<const DILocation *>
3126 // Do not interfere with pseudo probes. Pseudo probe at a callsite uses
3127 // the dwarf discriminator to store pseudo probe related information,
3128 // such as the probe id.
3129 if (isPseudoProbeDiscriminator(getDiscriminator()))
3130 return this;
3131
3132 unsigned BD, DF, CI;
3133
3135 BD = getBaseDiscriminator();
3136 if (D == BD)
3137 return this;
3138 return cloneWithDiscriminator(D);
3139 }
3140
3141 decodeDiscriminator(getDiscriminator(), BD, DF, CI);
3142 if (D == BD)
3143 return this;
3144 if (std::optional<unsigned> Encoded = encodeDiscriminator(D, DF, CI))
3145 return cloneWithDiscriminator(*Encoded);
3146 return std::nullopt;
3147}
3148
3149std::optional<const DILocation *>
3151 assert(!EnableFSDiscriminator && "FSDiscriminator should not call this.");
3152 // Do no interfere with pseudo probes. Pseudo probe doesn't need duplication
3153 // factor support as samples collected on cloned probes will be aggregated.
3154 // Also pseudo probe at a callsite uses the dwarf discriminator to store
3155 // pseudo probe related information, such as the probe id.
3156 if (isPseudoProbeDiscriminator(getDiscriminator()))
3157 return this;
3158
3160 if (DF <= 1)
3161 return this;
3162
3163 unsigned BD = getBaseDiscriminator();
3164 unsigned CI = getCopyIdentifier();
3165 if (std::optional<unsigned> D = encodeDiscriminator(BD, DF, CI))
3166 return cloneWithDiscriminator(*D);
3167 return std::nullopt;
3168}
3169
3170/// Debug lexical block.
3171///
3172/// Uses the SubclassData1 Metadata slot.
3173class DINamespace : public DIScope {
3174 friend class LLVMContextImpl;
3175 friend class MDNode;
3176
3177 DINamespace(LLVMContext &Context, StorageType Storage, bool ExportSymbols,
3179 ~DINamespace() = default;
3180
3181 static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope,
3183 StorageType Storage, bool ShouldCreate = true) {
3184 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
3185 ExportSymbols, Storage, ShouldCreate);
3186 }
3187 LLVM_ABI static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope,
3190 bool ShouldCreate = true);
3191
3192 TempDINamespace cloneImpl() const {
3193 return getTemporary(getContext(), getScope(), getName(),
3195 }
3196
3197public:
3201 DEFINE_MDNODE_GET(DINamespace,
3204
3205 TempDINamespace clone() const { return cloneImpl(); }
3206
3207 bool getExportSymbols() const { return SubclassData1; }
3209 StringRef getName() const { return getStringOperand(2); }
3210
3211 Metadata *getRawScope() const { return getOperand(1); }
3213
3214 static bool classof(const Metadata *MD) {
3215 return MD->getMetadataID() == DINamespaceKind;
3216 }
3217};
3218
3219/// Represents a module in the programming language, for example, a Clang
3220/// module, or a Fortran module.
3221///
3222/// Uses the SubclassData1 and SubclassData32 Metadata slots.
3223class DIModule : public DIScope {
3224 friend class LLVMContextImpl;
3225 friend class MDNode;
3226
3227 DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo,
3228 bool IsDecl, ArrayRef<Metadata *> Ops);
3229 ~DIModule() = default;
3230
3231 static DIModule *getImpl(LLVMContext &Context, DIFile *File, DIScope *Scope,
3234 unsigned LineNo, bool IsDecl, StorageType Storage,
3235 bool ShouldCreate = true) {
3236 return getImpl(Context, File, Scope, getCanonicalMDString(Context, Name),
3239 getCanonicalMDString(Context, APINotesFile), LineNo, IsDecl,
3240 Storage, ShouldCreate);
3241 }
3242 LLVM_ABI static DIModule *
3243 getImpl(LLVMContext &Context, Metadata *File, Metadata *Scope, MDString *Name,
3245 MDString *APINotesFile, unsigned LineNo, bool IsDecl,
3246 StorageType Storage, bool ShouldCreate = true);
3247
3248 TempDIModule cloneImpl() const {
3250 getConfigurationMacros(), getIncludePath(),
3251 getAPINotesFile(), getLineNo(), getIsDecl());
3252 }
3253
3254public:
3258 StringRef APINotesFile, unsigned LineNo,
3259 bool IsDecl = false),
3261 APINotesFile, LineNo, IsDecl))
3262 DEFINE_MDNODE_GET(DIModule,
3266 bool IsDecl = false),
3268 APINotesFile, LineNo, IsDecl))
3269
3270 TempDIModule clone() const { return cloneImpl(); }
3271
3272 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
3273 StringRef getName() const { return getStringOperand(2); }
3274 StringRef getConfigurationMacros() const { return getStringOperand(3); }
3275 StringRef getIncludePath() const { return getStringOperand(4); }
3276 StringRef getAPINotesFile() const { return getStringOperand(5); }
3277 unsigned getLineNo() const { return SubclassData32; }
3278 bool getIsDecl() const { return SubclassData1; }
3279
3280 Metadata *getRawScope() const { return getOperand(1); }
3281 MDString *getRawName() const { return getOperandAs<MDString>(2); }
3282 MDString *getRawConfigurationMacros() const {
3283 return getOperandAs<MDString>(3);
3284 }
3285 MDString *getRawIncludePath() const { return getOperandAs<MDString>(4); }
3286 MDString *getRawAPINotesFile() const { return getOperandAs<MDString>(5); }
3287
3288 static bool classof(const Metadata *MD) {
3289 return MD->getMetadataID() == DIModuleKind;
3290 }
3291};
3292
3293/// Base class for template parameters.
3294///
3295/// Uses the SubclassData1 Metadata slot.
3297protected:
3299 unsigned Tag, bool IsDefault, ArrayRef<Metadata *> Ops)
3300 : DINode(Context, ID, Storage, Tag, Ops) {
3301 SubclassData1 = IsDefault;
3302 }
3304
3305public:
3306 StringRef getName() const { return getStringOperand(0); }
3308
3310 Metadata *getRawType() const { return getOperand(1); }
3311 bool isDefault() const { return SubclassData1; }
3312
3313 static bool classof(const Metadata *MD) {
3314 return MD->getMetadataID() == DITemplateTypeParameterKind ||
3315 MD->getMetadataID() == DITemplateValueParameterKind;
3316 }
3317};
3318
3319class DITemplateTypeParameter : public DITemplateParameter {
3320 friend class LLVMContextImpl;
3321 friend class MDNode;
3322
3323 DITemplateTypeParameter(LLVMContext &Context, StorageType Storage,
3325 ~DITemplateTypeParameter() = default;
3326
3327 static DITemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
3328 DIType *Type, bool IsDefault,
3330 bool ShouldCreate = true) {
3331 return getImpl(Context, getCanonicalMDString(Context, Name), Type,
3332 IsDefault, Storage, ShouldCreate);
3333 }
3335 getImpl(LLVMContext &Context, MDString *Name, Metadata *Type, bool IsDefault,
3336 StorageType Storage, bool ShouldCreate = true);
3337
3338 TempDITemplateTypeParameter cloneImpl() const {
3339 return getTemporary(getContext(), getName(), getType(), isDefault());
3340 }
3341
3342public:
3343 DEFINE_MDNODE_GET(DITemplateTypeParameter,
3345 (Name, Type, IsDefault))
3346 DEFINE_MDNODE_GET(DITemplateTypeParameter,
3349
3350 TempDITemplateTypeParameter clone() const { return cloneImpl(); }
3351
3352 static bool classof(const Metadata *MD) {
3353 return MD->getMetadataID() == DITemplateTypeParameterKind;
3354 }
3355};
3356
3357class DITemplateValueParameter : public DITemplateParameter {
3358 friend class LLVMContextImpl;
3359 friend class MDNode;
3360
3361 DITemplateValueParameter(LLVMContext &Context, StorageType Storage,
3362 unsigned Tag, bool IsDefault,
3364 : DITemplateParameter(Context, DITemplateValueParameterKind, Storage, Tag,
3365 IsDefault, Ops) {}
3366 ~DITemplateValueParameter() = default;
3367
3368 static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
3370 bool IsDefault, Metadata *Value,
3372 bool ShouldCreate = true) {
3373 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
3374 IsDefault, Value, Storage, ShouldCreate);
3375 }
3376 LLVM_ABI static DITemplateValueParameter *
3377 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
3378 bool IsDefault, Metadata *Value, StorageType Storage,
3379 bool ShouldCreate = true);
3380
3381 TempDITemplateValueParameter cloneImpl() const {
3382 return getTemporary(getContext(), getTag(), getName(), getType(),
3383 isDefault(), getValue());
3384 }
3385
3386public:
3387 DEFINE_MDNODE_GET(DITemplateValueParameter,
3388 (unsigned Tag, StringRef Name, DIType *Type, bool IsDefault,
3389 Metadata *Value),
3390 (Tag, Name, Type, IsDefault, Value))
3391 DEFINE_MDNODE_GET(DITemplateValueParameter,
3395
3396 TempDITemplateValueParameter clone() const { return cloneImpl(); }
3397
3398 Metadata *getValue() const { return getOperand(2); }
3399
3400 static bool classof(const Metadata *MD) {
3401 return MD->getMetadataID() == DITemplateValueParameterKind;
3402 }
3403};
3404
3405/// Base class for variables.
3406///
3407/// Uses the SubclassData32 Metadata slot.
3408class DIVariable : public DINode {
3409 unsigned Line;
3410
3411protected:
3413 signed Line, ArrayRef<Metadata *> Ops,
3414 uint32_t AlignInBits = 0);
3415 ~DIVariable() = default;
3416
3417public:
3418 unsigned getLine() const { return Line; }
3420 StringRef getName() const { return getStringOperand(1); }
3424 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
3425 /// Determines the size of the variable's type.
3426 LLVM_ABI std::optional<uint64_t> getSizeInBits() const;
3427
3428 /// Return the signedness of this variable's type, or std::nullopt if this
3429 /// type is neither signed nor unsigned.
3430 std::optional<DIBasicType::Signedness> getSignedness() const {
3431 if (auto *BT = dyn_cast<DIBasicType>(getType()))
3432 return BT->getSignedness();
3433 return std::nullopt;
3434 }
3435
3437 if (auto *F = getFile())
3438 return F->getFilename();
3439 return "";
3440 }
3441
3443 if (auto *F = getFile())
3444 return F->getDirectory();
3445 return "";
3446 }
3447
3448 std::optional<StringRef> getSource() const {
3449 if (auto *F = getFile())
3450 return F->getSource();
3451 return std::nullopt;
3452 }
3453
3454 Metadata *getRawScope() const { return getOperand(0); }
3456 Metadata *getRawFile() const { return getOperand(2); }
3457 Metadata *getRawType() const { return getOperand(3); }
3458
3459 static bool classof(const Metadata *MD) {
3460 return MD->getMetadataID() == DILocalVariableKind ||
3461 MD->getMetadataID() == DIGlobalVariableKind;
3462 }
3463};
3464
3465/// DWARF expression.
3466///
3467/// This is (almost) a DWARF expression that modifies the location of a
3468/// variable, or the location of a single piece of a variable, or (when using
3469/// DW_OP_stack_value) is the constant variable value.
3470///
3471/// TODO: Co-allocate the expression elements.
3472/// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
3473/// storage types.
3474class DIExpression : public MDNode {
3475 friend class LLVMContextImpl;
3476 friend class MDNode;
3477
3478 std::vector<uint64_t> Elements;
3479
3480 DIExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
3481 : MDNode(C, DIExpressionKind, Storage, {}),
3482 Elements(Elements.begin(), Elements.end()) {}
3483 ~DIExpression() = default;
3484
3485 LLVM_ABI static DIExpression *getImpl(LLVMContext &Context,
3486 ArrayRef<uint64_t> Elements,
3488 bool ShouldCreate = true);
3489
3490 TempDIExpression cloneImpl() const {
3491 return getTemporary(getContext(), getElements());
3492 }
3493
3494public:
3495 DEFINE_MDNODE_GET(DIExpression, (ArrayRef<uint64_t> Elements), (Elements))
3496
3497 TempDIExpression clone() const { return cloneImpl(); }
3498
3499 ArrayRef<uint64_t> getElements() const { return Elements; }
3500
3501 unsigned getNumElements() const { return Elements.size(); }
3502
3503 uint64_t getElement(unsigned I) const {
3504 assert(I < Elements.size() && "Index out of range");
3505 return Elements[I];
3506 }
3507
3509 /// Determine whether this represents a constant value, if so
3510 // return it's sign information.
3511 LLVM_ABI std::optional<SignedOrUnsignedConstant> isConstant() const;
3512
3513 /// Return the number of unique location operands referred to (via
3514 /// DW_OP_LLVM_arg) in this expression; this is not necessarily the number of
3515 /// instances of DW_OP_LLVM_arg within the expression.
3516 /// For example, for the expression:
3517 /// (DW_OP_LLVM_arg 0, DW_OP_LLVM_arg 1, DW_OP_plus,
3518 /// DW_OP_LLVM_arg 0, DW_OP_mul)
3519 /// This function would return 2, as there are two unique location operands
3520 /// (0 and 1).
3522
3524
3527
3528 /// A lightweight wrapper around an expression operand.
3529 ///
3530 /// TODO: Store arguments directly and change \a DIExpression to store a
3531 /// range of these.
3533 const uint64_t *Op = nullptr;
3534
3535 public:
3536 ExprOperand() = default;
3537 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
3538
3539 explicit operator bool() const { return Op != nullptr; }
3540
3541 const uint64_t *get() const { return Op; }
3542
3543 /// Get the operand code.
3544 ///
3545 /// The operand has to be present.
3546 uint64_t getOp() const {
3547 assert(Op && "operand is not present");
3548 return *Op;
3549 }
3550
3551 /// Return true if this is \p Opcode.
3552 bool is(uint64_t Opcode) const { return getOp() == Opcode; }
3553
3554 /// Get an argument to the operand.
3555 ///
3556 /// Never returns the operand itself. The operand has to be present and \p I
3557 /// has to be less than getNumArgs().
3558 uint64_t getArg(unsigned I) const {
3559 assert(Op && "operand is not present");
3560 return Op[I + 1];
3561 }
3562
3563 unsigned getNumArgs() const { return getSize() - 1; }
3564
3565 /// Return the size of the operand.
3566 ///
3567 /// Return the number of elements in the operand (1 + args).
3568 LLVM_ABI unsigned getSize() const;
3569
3570 /// Return true if CodeGen handles this operand without adding bytes to the
3571 /// DWARF expression.
3572 LLVM_ABI bool isNonEmitting() const;
3573
3574 /// Append the elements of this operand to \p V.
3576 V.append(get(), get() + getSize());
3577 }
3578 };
3579
3580 // Typed views name an ExprOperand's arguments. Use cast<FragmentOp>(Op) for a
3581 // known opcode and dyn_cast<ArgOp>(Op) for a conditional match. A failed
3582 // dyn_cast returns an empty view, which tests false and holds no operand to
3583 // read, so check it before calling an accessor. Keep using ExprOperand for
3584 // operations without a typed view.
3585 //
3586 // A view takes an operand rather than an optional one. A cursor hands back
3587 // std::optional<ExprOperand>, so check it and then dereference it.
3588 // dyn_cast_if_present does not compile on std::optional<ExprOperand>, because
3589 // an operand is constructible from a null pointer, which leaves
3590 // ValueIsPresent ambiguous between its optional and its nullable
3591 // specialization.
3592
3593 /// A view of a DW_OP_LLVM_arg operation.
3594 class ArgOp : public ExprOperand {
3595 template <typename To, typename From, typename Enable>
3596 friend struct llvm::CastInfo;
3597
3598 explicit ArgOp(ExprOperand Op) : ExprOperand(Op) {}
3599
3600 public:
3601 /// Return the location operand index.
3602 uint64_t getIndex() const { return getArg(0); }
3603
3604 LLVM_ABI static bool classof(const ExprOperand *Op);
3605 };
3606
3607 /// A view of a DW_OP_LLVM_fragment operation.
3608 class FragmentOp : public ExprOperand {
3609 template <typename To, typename From, typename Enable>
3610 friend struct llvm::CastInfo;
3611
3612 explicit FragmentOp(ExprOperand Op) : ExprOperand(Op) {}
3613
3614 public:
3615 /// Return the fragment offset in bits.
3616 uint64_t getOffsetInBits() const { return getArg(0); }
3617
3618 /// Return the fragment size in bits.
3619 uint64_t getSizeInBits() const { return getArg(1); }
3620
3621 LLVM_ABI static bool classof(const ExprOperand *Op);
3622 };
3623
3624 /// A view of the DW_OP_LLVM_extract_bits_[sz]ext operations.
3625 class ExtractBitsOp : public ExprOperand {
3626 template <typename To, typename From, typename Enable>
3627 friend struct llvm::CastInfo;
3628
3629 explicit ExtractBitsOp(ExprOperand Op) : ExprOperand(Op) {}
3630
3631 public:
3632 /// Return the extract offset in bits.
3633 uint64_t getOffsetInBits() const { return getArg(0); }
3634
3635 /// Return the extract size in bits.
3636 uint64_t getSizeInBits() const { return getArg(1); }
3637
3638 /// Return whether the extracted value is sign-extended.
3639 LLVM_ABI bool isSigned() const;
3640
3641 LLVM_ABI static bool classof(const ExprOperand *Op);
3642 };
3643
3644 /// A view of a DW_OP_LLVM_convert operation.
3645 class ConvertOp : public ExprOperand {
3646 template <typename To, typename From, typename Enable>
3647 friend struct llvm::CastInfo;
3648
3649 explicit ConvertOp(ExprOperand Op) : ExprOperand(Op) {}
3650
3651 public:
3652 /// Return the destination size in bits.
3653 uint64_t getBitSize() const { return getArg(0); }
3654
3655 /// Return the raw destination type encoding.
3656 uint64_t getEncoding() const { return getArg(1); }
3657
3658 LLVM_ABI static bool classof(const ExprOperand *Op);
3659 };
3660
3661 /// A view of a DW_OP_LLVM_entry_value operation.
3662 class EntryValueOp : public ExprOperand {
3663 template <typename To, typename From, typename Enable>
3664 friend struct llvm::CastInfo;
3665
3666 explicit EntryValueOp(ExprOperand Op) : ExprOperand(Op) {}
3667
3668 public:
3669 /// Return the number of operations the entry value covers. The count
3670 /// includes the operation that precedes it, so the operations that follow
3671 /// are one fewer than this.
3672 uint64_t getNumOperations() const { return getArg(0); }
3673
3674 LLVM_ABI static bool classof(const ExprOperand *Op);
3675 };
3676
3677 /// A view of a DW_OP_LLVM_tag_offset operation.
3678 class TagOffsetOp : public ExprOperand {
3679 template <typename To, typename From, typename Enable>
3680 friend struct llvm::CastInfo;
3681
3682 explicit TagOffsetOp(ExprOperand Op) : ExprOperand(Op) {}
3683
3684 public:
3685 /// Return the offset a memory tag is derived from. How a target derives
3686 /// the tag from it is implementation defined.
3687 uint64_t getTagOffset() const { return getArg(0); }
3688
3689 LLVM_ABI static bool classof(const ExprOperand *Op);
3690 };
3691
3692 /// A view of a DW_OP_constu operation.
3693 class ConstuOp : public ExprOperand {
3694 template <typename To, typename From, typename Enable>
3695 friend struct llvm::CastInfo;
3696
3697 explicit ConstuOp(ExprOperand Op) : ExprOperand(Op) {}
3698
3699 public:
3700 /// Return the unsigned constant value.
3701 uint64_t getValue() const { return getArg(0); }
3702
3703 LLVM_ABI static bool classof(const ExprOperand *Op);
3704 };
3705
3706 /// A view of a DW_OP_plus_uconst operation.
3707 class PlusUconstOp : public ExprOperand {
3708 template <typename To, typename From, typename Enable>
3709 friend struct llvm::CastInfo;
3710
3711 explicit PlusUconstOp(ExprOperand Op) : ExprOperand(Op) {}
3712
3713 public:
3714 /// Return the unsigned offset.
3715 uint64_t getOffset() const { return getArg(0); }
3716
3717 LLVM_ABI static bool classof(const ExprOperand *Op);
3718 };
3719
3720 /// An iterator for expression operands.
3722 ExprOperand Op;
3723
3724 public:
3725 using iterator_category = std::input_iterator_tag;
3727 using difference_type = std::ptrdiff_t;
3730
3731 expr_op_iterator() = default;
3733
3734 element_iterator getBase() const { return Op.get(); }
3735 const ExprOperand &operator*() const { return Op; }
3736 const ExprOperand *operator->() const { return &Op; }
3737
3739 increment();
3740 return *this;
3741 }
3743 expr_op_iterator T(*this);
3744 increment();
3745 return T;
3746 }
3747
3748 /// Get the next iterator.
3749 ///
3750 /// \a std::next() doesn't work because this is technically an
3751 /// input_iterator, but it's a perfectly valid operation. This is an
3752 /// accessor to provide the same functionality.
3753 expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
3754
3755 bool operator==(const expr_op_iterator &X) const {
3756 return getBase() == X.getBase();
3757 }
3758 bool operator!=(const expr_op_iterator &X) const {
3759 return getBase() != X.getBase();
3760 }
3761
3762 private:
3763 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
3764 };
3765
3766 /// Visit the elements via ExprOperand wrappers.
3767 ///
3768 /// These range iterators visit elements through \a ExprOperand wrappers.
3769 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
3770 /// true.
3771 ///
3772 /// \pre \a isValid() gives \c true.
3773 /// @{
3783 /// @}
3784
3785 LLVM_ABI bool isValid() const;
3786
3787 static bool classof(const Metadata *MD) {
3788 return MD->getMetadataID() == DIExpressionKind;
3789 }
3790
3791 /// Return whether the first element a DW_OP_deref.
3792 LLVM_ABI bool startsWithDeref() const;
3793
3794 /// Return whether there is exactly one operator and it is a DW_OP_deref;
3795 LLVM_ABI bool isDeref() const;
3796
3798
3799 /// Return the number of bits that have an active value, i.e. those that
3800 /// aren't known to be zero/sign (depending on the type of Var) and which
3801 /// are within the size of this fragment (if it is one). If we can't deduce
3802 /// anything from the expression this will return the size of Var.
3803 LLVM_ABI std::optional<uint64_t> getActiveBits(DIVariable *Var);
3804
3805 /// Retrieve the details of this fragment expression.
3806 LLVM_ABI static std::optional<FragmentInfo>
3808
3809 /// Retrieve the details of this fragment expression.
3810 std::optional<FragmentInfo> getFragmentInfo() const {
3812 }
3813
3814 /// Return whether this is a piece of an aggregate variable.
3815 bool isFragment() const { return getFragmentInfo().has_value(); }
3816
3817 /// Return whether this is an implicit location description.
3818 LLVM_ABI bool isImplicit() const;
3819
3820 /// Return whether the location is computed on the expression stack, meaning
3821 /// it cannot be a simple register location.
3822 LLVM_ABI bool isComplex() const;
3823
3824 /// Return whether the evaluated expression makes use of a single location at
3825 /// the start of the expression, i.e. if it contains only a single
3826 /// DW_OP_LLVM_arg op as its first operand, or if it contains none.
3828
3829 /// Returns a reference to the elements contained in this expression, skipping
3830 /// past the leading `DW_OP_LLVM_arg, 0` if one is present.
3831 /// Similar to `convertToNonVariadicExpression`, but faster and cheaper - it
3832 /// does not check whether the expression is a single-location expression, and
3833 /// it returns elements rather than creating a new DIExpression.
3834 LLVM_ABI std::optional<ArrayRef<uint64_t>>
3836
3837 /// Removes all elements from \p Expr that do not apply to an undef debug
3838 /// value, which includes every operator that computes the value/location on
3839 /// the DWARF stack, including any DW_OP_LLVM_arg elements (making the result
3840 /// of this function always a single-location expression) while leaving
3841 /// everything that defines what the computed value applies to, i.e. the
3842 /// fragment information.
3843 LLVM_ABI static const DIExpression *
3845
3846 /// If \p Expr is a non-variadic expression (i.e. one that does not contain
3847 /// DW_OP_LLVM_arg), returns \p Expr converted to variadic form by adding a
3848 /// leading [DW_OP_LLVM_arg, 0] to the expression; otherwise returns \p Expr.
3849 LLVM_ABI static const DIExpression *
3851
3852 /// If \p Expr is a valid single-location expression, i.e. it refers to only a
3853 /// single debug operand at the start of the expression, then return that
3854 /// expression in a non-variadic form by removing DW_OP_LLVM_arg from the
3855 /// expression if it is present; otherwise returns std::nullopt.
3856 /// See also `getSingleLocationExpressionElements` above, which skips
3857 /// checking `isSingleLocationExpression` and returns a list of elements
3858 /// rather than a DIExpression.
3859 LLVM_ABI static std::optional<const DIExpression *>
3861
3862 /// Inserts the elements of \p Expr into \p Ops modified to a canonical form,
3863 /// which uses DW_OP_LLVM_arg (i.e. is a variadic expression) and folds the
3864 /// implied derefence from the \p IsIndirect flag into the expression. This
3865 /// allows us to check equivalence between expressions with differing
3866 /// directness or variadicness.
3868 const DIExpression *Expr,
3869 bool IsIndirect);
3870
3871 /// Determines whether two debug values should produce equivalent DWARF
3872 /// expressions, using their DIExpressions and directness, ignoring the
3873 /// differences between otherwise identical expressions in variadic and
3874 /// non-variadic form and not considering the debug operands.
3875 /// \p FirstExpr is the DIExpression for the first debug value.
3876 /// \p FirstIndirect should be true if the first debug value is indirect; in
3877 /// IR this should be true for dbg.declare intrinsics and false for
3878 /// dbg.values, and in MIR this should be true only for DBG_VALUE instructions
3879 /// whose second operand is an immediate value.
3880 /// \p SecondExpr and \p SecondIndirect have the same meaning as the prior
3881 /// arguments, but apply to the second debug value.
3882 LLVM_ABI static bool isEqualExpression(const DIExpression *FirstExpr,
3883 bool FirstIndirect,
3884 const DIExpression *SecondExpr,
3885 bool SecondIndirect);
3886
3887 /// Append \p Ops with operations to apply the \p Offset.
3889 int64_t Offset);
3890
3891 LLVM_ABI static bool
3892 extractLeadingOffset(ArrayRef<uint64_t> Ops, int64_t &OffsetInBytes,
3893 SmallVectorImpl<uint64_t> &RemainingOps);
3894
3895 /// If this is a constant offset, extract it. If there is no expression,
3896 /// return true with an offset of zero.
3897 LLVM_ABI bool extractIfOffset(int64_t &Offset) const;
3898
3899 /// Assuming that the expression operates on an address, extract a constant
3900 /// offset and the successive ops. Return false if the expression contains
3901 /// any incompatible ops (including non-zero DW_OP_LLVM_args - only a single
3902 /// address operand to the expression is permitted).
3903 ///
3904 /// We don't try very hard to interpret the expression because we assume that
3905 /// foldConstantMath has canonicalized the expression.
3906 LLVM_ABI bool
3907 extractLeadingOffset(int64_t &OffsetInBytes,
3908 SmallVectorImpl<uint64_t> &RemainingOps) const;
3909
3910 /// Returns true iff this DIExpression contains at least one instance of
3911 /// `DW_OP_LLVM_arg, n` for all n in [0, N).
3912 LLVM_ABI bool hasAllLocationOps(unsigned N) const;
3913
3914 /// Checks if the last 4 elements of the expression are DW_OP_constu <DWARF
3915 /// Address Space> DW_OP_swap DW_OP_xderef and extracts the <DWARF Address
3916 /// Space>.
3917 LLVM_ABI static const DIExpression *
3918 extractAddressClass(const DIExpression *Expr, unsigned &AddrClass);
3919
3920 /// Used for DIExpression::prepend.
3923 DerefBefore = 1 << 0,
3924 DerefAfter = 1 << 1,
3925 StackValue = 1 << 2,
3926 EntryValue = 1 << 3
3927 };
3928
3929 /// Prepend \p DIExpr with a deref and offset operation and optionally turn it
3930 /// into a stack value or/and an entry value.
3931 LLVM_ABI static DIExpression *prepend(const DIExpression *Expr, uint8_t Flags,
3932 int64_t Offset = 0);
3933
3934 /// Prepend \p DIExpr with the given opcodes and optionally turn it into a
3935 /// stack value.
3938 bool StackValue = false,
3939 bool EntryValue = false);
3940
3941 /// Append the opcodes \p Ops to \p DIExpr. Unlike \ref appendToStack, the
3942 /// returned expression is a stack value only if \p DIExpr is a stack value.
3943 /// If \p DIExpr describes a fragment, the returned expression will describe
3944 /// the same fragment.
3945 LLVM_ABI static DIExpression *append(const DIExpression *Expr,
3947
3948 /// Convert \p DIExpr into a stack value if it isn't one already by appending
3949 /// DW_OP_deref if needed, and appending \p Ops to the resulting expression.
3950 /// If \p DIExpr describes a fragment, the returned expression will describe
3951 /// the same fragment.
3952 LLVM_ABI static DIExpression *appendToStack(const DIExpression *Expr,
3954
3955 /// Create a copy of \p Expr by appending the given list of \p Ops to each
3956 /// instance of the operand `DW_OP_LLVM_arg, \p ArgNo`. This is used to
3957 /// modify a specific location used by \p Expr, such as when salvaging that
3958 /// location.
3961 unsigned ArgNo,
3962 bool StackValue = false);
3963
3964 /// Create a copy of \p Expr with each instance of
3965 /// `DW_OP_LLVM_arg, \p OldArg` replaced with `DW_OP_LLVM_arg, \p NewArg`,
3966 /// and each instance of `DW_OP_LLVM_arg, Arg` with `DW_OP_LLVM_arg, Arg - 1`
3967 /// for all Arg > \p OldArg.
3968 /// This is used when replacing one of the operands of a debug value list
3969 /// with another operand in the same list and deleting the old operand.
3970 LLVM_ABI static DIExpression *replaceArg(const DIExpression *Expr,
3971 uint64_t OldArg, uint64_t NewArg);
3972
3973 /// Create a DIExpression to describe one part of an aggregate variable that
3974 /// is fragmented across multiple Values. The DW_OP_LLVM_fragment operation
3975 /// will be appended to the elements of \c Expr. If \c Expr already contains
3976 /// a \c DW_OP_LLVM_fragment \c OffsetInBits is interpreted as an offset
3977 /// into the existing fragment.
3978 ///
3979 /// \param OffsetInBits Offset of the piece in bits.
3980 /// \param SizeInBits Size of the piece in bits.
3981 /// \return Creating a fragment expression may fail if \c Expr
3982 /// contains arithmetic operations that would be
3983 /// truncated.
3984 LLVM_ABI static std::optional<DIExpression *>
3985 createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits,
3986 unsigned SizeInBits);
3987
3988 /// Determine the relative position of the fragments passed in.
3989 /// Returns -1 if this is entirely before Other, 0 if this and Other overlap,
3990 /// 1 if this is entirely after Other.
3991 static int fragmentCmp(const FragmentInfo &A, const FragmentInfo &B) {
3992 uint64_t l1 = A.OffsetInBits;
3993 uint64_t l2 = B.OffsetInBits;
3994 uint64_t r1 = l1 + A.SizeInBits;
3995 uint64_t r2 = l2 + B.SizeInBits;
3996 if (r1 <= l2)
3997 return -1;
3998 else if (r2 <= l1)
3999 return 1;
4000 else
4001 return 0;
4002 }
4003
4004 /// Computes a fragment, bit-extract operation if needed, and new constant
4005 /// offset to describe a part of a variable covered by some memory.
4006 ///
4007 /// The memory region starts at:
4008 /// \p SliceStart + \p SliceOffsetInBits
4009 /// And is size:
4010 /// \p SliceSizeInBits
4011 ///
4012 /// The location of the existing variable fragment \p VarFrag is:
4013 /// \p DbgPtr + \p DbgPtrOffsetInBits + \p DbgExtractOffsetInBits.
4014 ///
4015 /// It is intended that these arguments are derived from a debug record:
4016 /// - \p DbgPtr is the (single) DIExpression operand.
4017 /// - \p DbgPtrOffsetInBits is the constant offset applied to \p DbgPtr.
4018 /// - \p DbgExtractOffsetInBits is the offset from a
4019 /// DW_OP_LLVM_bit_extract_[sz]ext operation.
4020 ///
4021 /// Results and return value:
4022 /// - Return false if the result can't be calculated for any reason.
4023 /// - \p Result is set to nullopt if the intersect equals \p VarFrag.
4024 /// - \p Result contains a zero-sized fragment if there's no intersect.
4025 /// - \p OffsetFromLocationInBits is set to the difference between the first
4026 /// bit of the variable location and the first bit of the slice. The
4027 /// magnitude of a negative value therefore indicates the number of bits
4028 /// into the variable fragment that the memory region begins.
4029 ///
4030 /// We don't pass in a debug record directly to get the constituent parts
4031 /// and offsets because different debug records store the information in
4032 /// different places (dbg_assign has two DIExpressions - one contains the
4033 /// fragment info for the entire intrinsic).
4035 const DataLayout &DL, const Value *SliceStart, uint64_t SliceOffsetInBits,
4036 uint64_t SliceSizeInBits, const Value *DbgPtr, int64_t DbgPtrOffsetInBits,
4037 int64_t DbgExtractOffsetInBits, DIExpression::FragmentInfo VarFrag,
4038 std::optional<DIExpression::FragmentInfo> &Result,
4039 int64_t &OffsetFromLocationInBits);
4040
4041 using ExtOps = std::array<uint64_t, 6>;
4042
4043 /// Returns the ops for a zero- or sign-extension in a DIExpression.
4044 LLVM_ABI static ExtOps getExtOps(unsigned FromSize, unsigned ToSize,
4045 bool Signed);
4046
4047 /// Append a zero- or sign-extension to \p Expr. Converts the expression to a
4048 /// stack value if it isn't one already.
4049 LLVM_ABI static DIExpression *appendExt(const DIExpression *Expr,
4050 unsigned FromSize, unsigned ToSize,
4051 bool Signed);
4052
4053 /// Check if fragments overlap between a pair of FragmentInfos.
4054 static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B) {
4055 return fragmentCmp(A, B) == 0;
4056 }
4057
4058 /// Determine the relative position of the fragments described by this
4059 /// DIExpression and \p Other. Calls static fragmentCmp implementation.
4060 int fragmentCmp(const DIExpression *Other) const {
4061 auto Fragment1 = *getFragmentInfo();
4062 auto Fragment2 = *Other->getFragmentInfo();
4063 return fragmentCmp(Fragment1, Fragment2);
4064 }
4065
4066 /// Check if fragments overlap between this DIExpression and \p Other.
4067 bool fragmentsOverlap(const DIExpression *Other) const {
4068 if (!isFragment() || !Other->isFragment())
4069 return true;
4070 return fragmentCmp(Other) == 0;
4071 }
4072
4073 /// Check if the expression consists of exactly one entry value operand.
4074 /// (This is the only configuration of entry values that is supported.)
4075 LLVM_ABI bool isEntryValue() const;
4076
4077 /// Try to shorten an expression with an initial constant operand.
4078 /// Returns a new expression and constant on success, or the original
4079 /// expression and constant on failure.
4080 LLVM_ABI std::pair<DIExpression *, const ConstantInt *>
4081 constantFold(const ConstantInt *CI);
4082
4083 /// Try to shorten an expression with constant math operations that can be
4084 /// evaluated at compile time. Returns a new expression on success, or the old
4085 /// expression if there is nothing to be reduced.
4087};
4088
4089template <typename To, typename From>
4091 To, From,
4092 std::enable_if_t<
4093 std::is_same_v<std::remove_const_t<From>, DIExpression::ExprOperand> &&
4094 !std::is_same_v<std::remove_const_t<To>, DIExpression::ExprOperand>>>
4095 : CastIsPossible<To, From>,
4096 DefaultDoCastIfPossible<To, From, CastInfo<To, From>> {
4097 static To doCast(const From &Op) { return To(Op); }
4098 static To castFailed() { return To(DIExpression::ExprOperand()); }
4099};
4100
4101/// Treat a default-constructed expression operand as absent.
4102template <> struct ValueIsPresent<DIExpression::ExprOperand> {
4104
4106 return bool(Op);
4107 }
4108
4112};
4113
4116 return std::tie(A.SizeInBits, A.OffsetInBits) ==
4117 std::tie(B.SizeInBits, B.OffsetInBits);
4118}
4119
4122 return std::tie(A.SizeInBits, A.OffsetInBits) <
4123 std::tie(B.SizeInBits, B.OffsetInBits);
4124}
4125
4126template <> struct DenseMapInfo<DIExpression::FragmentInfo> {
4128 static const uint64_t MaxVal = std::numeric_limits<uint64_t>::max();
4129
4130 static unsigned getHashValue(const FragInfo &Frag) {
4131 return (Frag.SizeInBits & 0xffff) << 16 | (Frag.OffsetInBits & 0xffff);
4132 }
4133
4134 static bool isEqual(const FragInfo &A, const FragInfo &B) { return A == B; }
4135};
4136
4137/// Holds a DIExpression and keeps track of how many operands have been consumed
4138/// so far.
4141
4142public:
4144 if (!Expr) {
4145 assert(Start == End);
4146 return;
4147 }
4148 Start = Expr->expr_op_begin();
4149 End = Expr->expr_op_end();
4150 }
4151
4153 : Start(Expr.begin()), End(Expr.end()) {}
4154
4156
4157 /// Consume one operation.
4158 std::optional<DIExpression::ExprOperand> take() {
4159 if (Start == End)
4160 return std::nullopt;
4161 return *(Start++);
4162 }
4163
4164 /// Consume N operations.
4165 void consume(unsigned N) { std::advance(Start, N); }
4166
4167 /// Return the current operation.
4168 std::optional<DIExpression::ExprOperand> peek() const {
4169 if (Start == End)
4170 return std::nullopt;
4171 return *(Start);
4172 }
4173
4174 /// Return the next operation.
4175 std::optional<DIExpression::ExprOperand> peekNext() const {
4176 if (Start == End)
4177 return std::nullopt;
4178
4179 auto Next = Start.getNext();
4180 if (Next == End)
4181 return std::nullopt;
4182
4183 return *Next;
4184 }
4185
4186 std::optional<DIExpression::ExprOperand> peekNextN(unsigned N) const {
4187 if (Start == End)
4188 return std::nullopt;
4190 for (unsigned I = 0; I < N; I++) {
4191 Nth = Nth.getNext();
4192 if (Nth == End)
4193 return std::nullopt;
4194 }
4195 return *Nth;
4196 }
4197
4199 this->Start = DIExpression::expr_op_iterator(Expr.begin());
4200 this->End = DIExpression::expr_op_iterator(Expr.end());
4201 }
4202
4203 /// Determine whether there are any operations left in this expression.
4204 operator bool() const { return Start != End; }
4205
4206 DIExpression::expr_op_iterator begin() const { return Start; }
4207 DIExpression::expr_op_iterator end() const { return End; }
4208
4209 /// Retrieve the fragment information, if any.
4210 std::optional<DIExpression::FragmentInfo> getFragmentInfo() const {
4211 return DIExpression::getFragmentInfo(Start, End);
4212 }
4213};
4214
4215/// Global variables.
4216///
4217/// TODO: Remove DisplayName. It's always equal to Name.
4218class DIGlobalVariable : public DIVariable {
4219 friend class LLVMContextImpl;
4220 friend class MDNode;
4221
4222 bool IsLocalToUnit;
4223 bool IsDefinition;
4224
4225 DIGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
4226 bool IsLocalToUnit, bool IsDefinition, uint32_t AlignInBits,
4228 : DIVariable(C, DIGlobalVariableKind, Storage, Line, Ops, AlignInBits),
4229 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
4230 ~DIGlobalVariable() = default;
4231
4232 static DIGlobalVariable *
4233 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
4234 StringRef LinkageName, DIFile *File, unsigned Line, DIType *Type,
4235 bool IsLocalToUnit, bool IsDefinition,
4238 bool ShouldCreate = true) {
4239 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
4240 getCanonicalMDString(Context, LinkageName), File, Line, Type,
4243 Annotations.get(), Storage, ShouldCreate);
4244 }
4245 LLVM_ABI static DIGlobalVariable *
4246 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
4247 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
4248 bool IsLocalToUnit, bool IsDefinition,
4251 bool ShouldCreate = true);
4252
4253 TempDIGlobalVariable cloneImpl() const {
4258 getAnnotations());
4259 }
4260
4261public:
4263 DIGlobalVariable,
4265 unsigned Line, DIType *Type, bool IsLocalToUnit, bool IsDefinition,
4267 uint32_t AlignInBits, DINodeArray Annotations),
4268 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
4271 DIGlobalVariable,
4273 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
4276 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
4278
4279 TempDIGlobalVariable clone() const { return cloneImpl(); }
4280
4281 bool isLocalToUnit() const { return IsLocalToUnit; }
4282 bool isDefinition() const { return IsDefinition; }
4288 DINodeArray getAnnotations() const {
4290 }
4291
4296 Metadata *getRawAnnotations() const { return getOperand(8); }
4297
4298 static bool classof(const Metadata *MD) {
4299 return MD->getMetadataID() == DIGlobalVariableKind;
4300 }
4301};
4302
4303/// Debug common block.
4304///
4305/// Uses the SubclassData32 Metadata slot.
4306class DICommonBlock : public DIScope {
4307 friend class LLVMContextImpl;
4308 friend class MDNode;
4309
4310 DICommonBlock(LLVMContext &Context, StorageType Storage, unsigned LineNo,
4312
4313 static DICommonBlock *getImpl(LLVMContext &Context, DIScope *Scope,
4315 DIFile *File, unsigned LineNo,
4316 StorageType Storage, bool ShouldCreate = true) {
4317 return getImpl(Context, Scope, Decl, getCanonicalMDString(Context, Name),
4318 File, LineNo, Storage, ShouldCreate);
4319 }
4320 LLVM_ABI static DICommonBlock *getImpl(LLVMContext &Context, Metadata *Scope,
4322 Metadata *File, unsigned LineNo,
4324 bool ShouldCreate = true);
4325
4326 TempDICommonBlock cloneImpl() const {
4328 getFile(), getLineNo());
4329 }
4330
4331public:
4332 DEFINE_MDNODE_GET(DICommonBlock,
4334 DIFile *File, unsigned LineNo),
4335 (Scope, Decl, Name, File, LineNo))
4336 DEFINE_MDNODE_GET(DICommonBlock,
4338 Metadata *File, unsigned LineNo),
4340
4341 TempDICommonBlock clone() const { return cloneImpl(); }
4342
4347 StringRef getName() const { return getStringOperand(2); }
4349 unsigned getLineNo() const { return SubclassData32; }
4350
4351 Metadata *getRawScope() const { return getOperand(0); }
4352 Metadata *getRawDecl() const { return getOperand(1); }
4354 Metadata *getRawFile() const { return getOperand(3); }
4355
4356 static bool classof(const Metadata *MD) {
4357 return MD->getMetadataID() == DICommonBlockKind;
4358 }
4359};
4360
4361/// Local variable.
4362///
4363/// TODO: Split up flags.
4364class DILocalVariable : public DIVariable {
4365 friend class LLVMContextImpl;
4366 friend class MDNode;
4367
4368 unsigned Arg : 16;
4369 DIFlags Flags;
4370
4371 DILocalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
4372 unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
4374 : DIVariable(C, DILocalVariableKind, Storage, Line, Ops, AlignInBits),
4375 Arg(Arg), Flags(Flags) {
4376 assert(Arg < (1 << 16) && "DILocalVariable: Arg out of range");
4377 }
4378 ~DILocalVariable() = default;
4379
4380 static DILocalVariable *getImpl(LLVMContext &Context, DIScope *Scope,
4381 StringRef Name, DIFile *File, unsigned Line,
4382 DIType *Type, unsigned Arg, DIFlags Flags,
4383 uint32_t AlignInBits, DINodeArray Annotations,
4385 bool ShouldCreate = true) {
4386 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
4387 Line, Type, Arg, Flags, AlignInBits, Annotations.get(),
4388 Storage, ShouldCreate);
4389 }
4390 LLVM_ABI static DILocalVariable *
4391 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, Metadata *File,
4392 unsigned Line, Metadata *Type, unsigned Arg, DIFlags Flags,
4394 bool ShouldCreate = true);
4395
4396 TempDILocalVariable cloneImpl() const {
4398 getLine(), getType(), getArg(), getFlags(),
4400 }
4401
4402public:
4403 DEFINE_MDNODE_GET(DILocalVariable,
4405 unsigned Line, DIType *Type, unsigned Arg, DIFlags Flags,
4406 uint32_t AlignInBits, DINodeArray Annotations),
4407 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits,
4408 Annotations))
4409 DEFINE_MDNODE_GET(DILocalVariable,
4411 unsigned Line, Metadata *Type, unsigned Arg, DIFlags Flags,
4413 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits,
4414 Annotations))
4415
4416 TempDILocalVariable clone() const { return cloneImpl(); }
4417
4418 /// Get the local scope for this variable.
4419 ///
4420 /// Variables must be defined in a local scope.
4424
4425 bool isParameter() const { return Arg; }
4426 unsigned getArg() const { return Arg; }
4427 DIFlags getFlags() const { return Flags; }
4428
4429 DINodeArray getAnnotations() const {
4431 }
4432 Metadata *getRawAnnotations() const { return getOperand(4); }
4433
4434 bool isArtificial() const { return getFlags() & FlagArtificial; }
4435 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
4436
4437 /// Check that a location is valid for this variable.
4438 ///
4439 /// Check that \c DL exists, is in the same subprogram, and has the same
4440 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
4441 /// to a \a DbgInfoIntrinsic.)
4443 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
4444 }
4445
4446 static bool classof(const Metadata *MD) {
4447 return MD->getMetadataID() == DILocalVariableKind;
4448 }
4449};
4450
4451/// Label.
4452///
4453/// Uses the SubclassData32 Metadata slot.
4454class DILabel : public DINode {
4455 friend class LLVMContextImpl;
4456 friend class MDNode;
4457
4458 unsigned Column;
4459 std::optional<unsigned> CoroSuspendIdx;
4460 bool IsArtificial;
4461
4462 DILabel(LLVMContext &C, StorageType Storage, unsigned Line, unsigned Column,
4463 bool IsArtificial, std::optional<unsigned> CoroSuspendIdx,
4465 ~DILabel() = default;
4466
4467 static DILabel *getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
4468 DIFile *File, unsigned Line, unsigned Column,
4469 bool IsArtificial,
4470 std::optional<unsigned> CoroSuspendIdx,
4471 StorageType Storage, bool ShouldCreate = true) {
4472 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
4473 Line, Column, IsArtificial, CoroSuspendIdx, Storage,
4474 ShouldCreate);
4475 }
4476 LLVM_ABI static DILabel *
4477 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, Metadata *File,
4478 unsigned Line, unsigned Column, bool IsArtificial,
4479 std::optional<unsigned> CoroSuspendIdx, StorageType Storage,
4480 bool ShouldCreate = true);
4481
4482 TempDILabel cloneImpl() const {
4486 }
4487
4488public:
4491 unsigned Line, unsigned Column, bool IsArtificial,
4492 std::optional<unsigned> CoroSuspendIdx),
4493 (Scope, Name, File, Line, Column, IsArtificial,
4494 CoroSuspendIdx))
4495 DEFINE_MDNODE_GET(DILabel,
4497 unsigned Line, unsigned Column, bool IsArtificial,
4498 std::optional<unsigned> CoroSuspendIdx),
4499 (Scope, Name, File, Line, Column, IsArtificial,
4500 CoroSuspendIdx))
4501
4502 TempDILabel clone() const { return cloneImpl(); }
4503
4504 /// Get the local scope for this label.
4505 ///
4506 /// Labels must be defined in a local scope.
4510 unsigned getLine() const { return SubclassData32; }
4511 unsigned getColumn() const { return Column; }
4512 StringRef getName() const { return getStringOperand(1); }
4514 bool isArtificial() const { return IsArtificial; }
4515 std::optional<unsigned> getCoroSuspendIdx() const { return CoroSuspendIdx; }
4516
4517 Metadata *getRawScope() const { return getOperand(0); }
4519 Metadata *getRawFile() const { return getOperand(2); }
4520
4521 /// Check that a location is valid for this label.
4522 ///
4523 /// Check that \c DL exists, is in the same subprogram, and has the same
4524 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
4525 /// to a \a DbgInfoIntrinsic.)
4527 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
4528 }
4529
4530 static bool classof(const Metadata *MD) {
4531 return MD->getMetadataID() == DILabelKind;
4532 }
4533};
4534
4535class DIObjCProperty : public DINode {
4536 friend class LLVMContextImpl;
4537 friend class MDNode;
4538
4539 unsigned Line;
4540 unsigned Attributes;
4541
4542 DIObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
4543 unsigned Attributes, ArrayRef<Metadata *> Ops);
4544 ~DIObjCProperty() = default;
4545
4546 static DIObjCProperty *
4547 getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
4548 StringRef GetterName, StringRef SetterName, unsigned Attributes,
4549 DIType *Type, StorageType Storage, bool ShouldCreate = true) {
4550 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
4552 getCanonicalMDString(Context, SetterName), Attributes, Type,
4553 Storage, ShouldCreate);
4554 }
4555 LLVM_ABI static DIObjCProperty *
4556 getImpl(LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
4557 MDString *GetterName, MDString *SetterName, unsigned Attributes,
4558 Metadata *Type, StorageType Storage, bool ShouldCreate = true);
4559
4560 TempDIObjCProperty cloneImpl() const {
4561 return getTemporary(getContext(), getName(), getFile(), getLine(),
4563 getType());
4564 }
4565
4566public:
4567 DEFINE_MDNODE_GET(DIObjCProperty,
4568 (StringRef Name, DIFile *File, unsigned Line,
4570 unsigned Attributes, DIType *Type),
4571 (Name, File, Line, GetterName, SetterName, Attributes,
4572 Type))
4573 DEFINE_MDNODE_GET(DIObjCProperty,
4574 (MDString * Name, Metadata *File, unsigned Line,
4576 unsigned Attributes, Metadata *Type),
4577 (Name, File, Line, GetterName, SetterName, Attributes,
4578 Type))
4579
4580 TempDIObjCProperty clone() const { return cloneImpl(); }
4581
4582 unsigned getLine() const { return Line; }
4583 unsigned getAttributes() const { return Attributes; }
4584 StringRef getName() const { return getStringOperand(0); }
4589
4591 if (auto *F = getFile())
4592 return F->getFilename();
4593 return "";
4594 }
4595
4597 if (auto *F = getFile())
4598 return F->getDirectory();
4599 return "";
4600 }
4601
4603 Metadata *getRawFile() const { return getOperand(1); }
4606 Metadata *getRawType() const { return getOperand(4); }
4607
4608 static bool classof(const Metadata *MD) {
4609 return MD->getMetadataID() == DIObjCPropertyKind;
4610 }
4611};
4612
4613/// A property of a class or structure.
4614///
4615/// An entity that is syntactically accessed like a data member, but whose
4616/// access is implemented by invoking a user-defined or compiler-generated
4617/// accessor.
4618///
4619/// Currently only the backing storage is modelled, and it must be a data
4620/// member holding the property's storage.
4621class DIProperty : public DINode {
4622 friend class LLVMContextImpl;
4623 friend class MDNode;
4624
4625 unsigned Line;
4626
4627 DIProperty(LLVMContext &C, StorageType Storage, unsigned Line,
4629 ~DIProperty() = default;
4630
4631 static DIProperty *getImpl(LLVMContext &Context, StringRef Name, DIFile *File,
4632 unsigned Line, DIType *Type,
4634 bool ShouldCreate = true) {
4635 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
4636 Type, BackingStorage, Storage, ShouldCreate);
4637 }
4638 LLVM_ABI static DIProperty *getImpl(LLVMContext &Context, MDString *Name,
4639 Metadata *File, unsigned Line,
4642 bool ShouldCreate = true);
4643
4644 TempDIProperty cloneImpl() const {
4645 return getTemporary(getContext(), getName(), getFile(), getLine(),
4647 }
4648
4649public:
4651 (StringRef Name, DIFile *File, unsigned Line, DIType *Type,
4653 (Name, File, Line, Type, BackingStorage))
4654 DEFINE_MDNODE_GET(DIProperty,
4655 (MDString * Name, Metadata *File, unsigned Line,
4658
4659 TempDIProperty clone() const { return cloneImpl(); }
4660
4661 unsigned getLine() const { return Line; }
4662 StringRef getName() const { return getStringOperand(0); }
4665
4666 /// The data member holding the property's backing storage, i.e. the target
4667 /// of \c DW_AT_property_forward on this property's
4668 /// \c DW_TAG_property_getter child.
4672
4674 if (auto *F = getFile())
4675 return F->getFilename();
4676 return "";
4677 }
4678
4680 if (auto *F = getFile())
4681 return F->getDirectory();
4682 return "";
4683 }
4684
4686 Metadata *getRawFile() const { return getOperand(1); }
4687 Metadata *getRawType() const { return getOperand(2); }
4689
4690 static bool classof(const Metadata *MD) {
4691 return MD->getMetadataID() == DIPropertyKind;
4692 }
4693};
4694
4695/// An imported module (C++ using directive or similar).
4696///
4697/// Uses the SubclassData32 Metadata slot.
4698class DIImportedEntity : public DINode {
4699 friend class LLVMContextImpl;
4700 friend class MDNode;
4701
4702 DIImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
4703 unsigned Line, ArrayRef<Metadata *> Ops)
4704 : DINode(C, DIImportedEntityKind, Storage, Tag, Ops) {
4706 }
4707 ~DIImportedEntity() = default;
4708
4709 static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
4710 DIScope *Scope, DINode *Entity, DIFile *File,
4711 unsigned Line, StringRef Name,
4712 DINodeArray Elements, StorageType Storage,
4713 bool ShouldCreate = true) {
4714 return getImpl(Context, Tag, Scope, Entity, File, Line,
4715 getCanonicalMDString(Context, Name), Elements.get(), Storage,
4716 ShouldCreate);
4717 }
4718 LLVM_ABI static DIImportedEntity *
4719 getImpl(LLVMContext &Context, unsigned Tag, Metadata *Scope, Metadata *Entity,
4720 Metadata *File, unsigned Line, MDString *Name, Metadata *Elements,
4721 StorageType Storage, bool ShouldCreate = true);
4722
4723 TempDIImportedEntity cloneImpl() const {
4724 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
4725 getFile(), getLine(), getName(), getElements());
4726 }
4727
4728public:
4729 DEFINE_MDNODE_GET(DIImportedEntity,
4730 (unsigned Tag, DIScope *Scope, DINode *Entity, DIFile *File,
4731 unsigned Line, StringRef Name = "",
4732 DINodeArray Elements = nullptr),
4733 (Tag, Scope, Entity, File, Line, Name, Elements))
4734 DEFINE_MDNODE_GET(DIImportedEntity,
4737 Metadata *Elements = nullptr),
4738 (Tag, Scope, Entity, File, Line, Name, Elements))
4739
4740 TempDIImportedEntity clone() const { return cloneImpl(); }
4741
4742 unsigned getLine() const { return SubclassData32; }
4743 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
4744 DINode *getEntity() const { return cast_or_null<DINode>(getRawEntity()); }
4745 StringRef getName() const { return getStringOperand(2); }
4746 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
4747 DINodeArray getElements() const {
4748 return cast_or_null<MDTuple>(getRawElements());
4749 }
4750
4751 Metadata *getRawScope() const { return getOperand(0); }
4752 Metadata *getRawEntity() const { return getOperand(1); }
4753 MDString *getRawName() const { return getOperandAs<MDString>(2); }
4754 Metadata *getRawFile() const { return getOperand(3); }
4755 Metadata *getRawElements() const { return getOperand(4); }
4756
4757 static bool classof(const Metadata *MD) {
4758 return MD->getMetadataID() == DIImportedEntityKind;
4759 }
4760};
4761
4762/// A pair of DIGlobalVariable and DIExpression.
4763class DIGlobalVariableExpression : public MDNode {
4764 friend class LLVMContextImpl;
4765 friend class MDNode;
4766
4767 DIGlobalVariableExpression(LLVMContext &C, StorageType Storage,
4769 : MDNode(C, DIGlobalVariableExpressionKind, Storage, Ops) {}
4770 ~DIGlobalVariableExpression() = default;
4771
4773 getImpl(LLVMContext &Context, Metadata *Variable, Metadata *Expression,
4774 StorageType Storage, bool ShouldCreate = true);
4775
4776 TempDIGlobalVariableExpression cloneImpl() const {
4778 }
4779
4780public:
4781 DEFINE_MDNODE_GET(DIGlobalVariableExpression,
4782 (Metadata * Variable, Metadata *Expression),
4783 (Variable, Expression))
4784
4785 TempDIGlobalVariableExpression clone() const { return cloneImpl(); }
4786
4787 Metadata *getRawVariable() const { return getOperand(0); }
4788
4792
4793 Metadata *getRawExpression() const { return getOperand(1); }
4794
4798
4799 static bool classof(const Metadata *MD) {
4800 return MD->getMetadataID() == DIGlobalVariableExpressionKind;
4801 }
4802};
4803
4804/// Macro Info DWARF-like metadata node.
4805///
4806/// A metadata node with a DWARF macro info (i.e., a constant named
4807/// \c DW_MACINFO_*, defined in llvm/BinaryFormat/Dwarf.h). Called \a
4808/// DIMacroNode
4809/// because it's potentially used for non-DWARF output.
4810///
4811/// Uses the SubclassData16 Metadata slot.
4812class DIMacroNode : public MDNode {
4813 friend class LLVMContextImpl;
4814 friend class MDNode;
4815
4816protected:
4817 DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType,
4819 : MDNode(C, ID, Storage, Ops1, Ops2) {
4820 assert(MIType < 1u << 16);
4821 SubclassData16 = MIType;
4822 }
4823 ~DIMacroNode() = default;
4824
4825 template <class Ty> Ty *getOperandAs(unsigned I) const {
4826 return cast_or_null<Ty>(getOperand(I));
4827 }
4828
4829 StringRef getStringOperand(unsigned I) const {
4830 if (auto *S = getOperandAs<MDString>(I))
4831 return S->getString();
4832 return StringRef();
4833 }
4834
4836 if (S.empty())
4837 return nullptr;
4838 return MDString::get(Context, S);
4839 }
4840
4841public:
4842 unsigned getMacinfoType() const { return SubclassData16; }
4843
4844 static bool classof(const Metadata *MD) {
4845 switch (MD->getMetadataID()) {
4846 default:
4847 return false;
4848 case DIMacroKind:
4849 case DIMacroFileKind:
4850 return true;
4851 }
4852 }
4853};
4854
4855/// Macro
4856///
4857/// Uses the SubclassData32 Metadata slot.
4858class DIMacro : public DIMacroNode {
4859 friend class LLVMContextImpl;
4860 friend class MDNode;
4861
4862 DIMacro(LLVMContext &C, StorageType Storage, unsigned MIType, unsigned Line,
4864 : DIMacroNode(C, DIMacroKind, Storage, MIType, Ops) {
4866 }
4867 ~DIMacro() = default;
4868
4869 static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
4871 bool ShouldCreate = true) {
4872 return getImpl(Context, MIType, Line, getCanonicalMDString(Context, Name),
4873 getCanonicalMDString(Context, Value), Storage, ShouldCreate);
4874 }
4875 LLVM_ABI static DIMacro *getImpl(LLVMContext &Context, unsigned MIType,
4876 unsigned Line, MDString *Name,
4877 MDString *Value, StorageType Storage,
4878 bool ShouldCreate = true);
4879
4880 TempDIMacro cloneImpl() const {
4882 getValue());
4883 }
4884
4885public:
4887 (unsigned MIType, unsigned Line, StringRef Name,
4888 StringRef Value = ""),
4889 (MIType, Line, Name, Value))
4890 DEFINE_MDNODE_GET(DIMacro,
4891 (unsigned MIType, unsigned Line, MDString *Name,
4894
4895 TempDIMacro clone() const { return cloneImpl(); }
4896
4897 unsigned getLine() const { return SubclassData32; }
4898
4899 StringRef getName() const { return getStringOperand(0); }
4900 StringRef getValue() const { return getStringOperand(1); }
4901
4904
4905 static bool classof(const Metadata *MD) {
4906 return MD->getMetadataID() == DIMacroKind;
4907 }
4908};
4909
4910/// Macro file
4911///
4912/// Uses the SubclassData32 Metadata slot.
4913class DIMacroFile : public DIMacroNode {
4914 friend class LLVMContextImpl;
4915 friend class MDNode;
4916
4917 DIMacroFile(LLVMContext &C, StorageType Storage, unsigned MIType,
4918 unsigned Line, ArrayRef<Metadata *> Ops)
4919 : DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops) {
4921 }
4922 ~DIMacroFile() = default;
4923
4924 static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
4925 unsigned Line, DIFile *File,
4926 DIMacroNodeArray Elements, StorageType Storage,
4927 bool ShouldCreate = true) {
4928 return getImpl(Context, MIType, Line, static_cast<Metadata *>(File),
4929 Elements.get(), Storage, ShouldCreate);
4930 }
4931
4932 LLVM_ABI static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
4933 unsigned Line, Metadata *File,
4935 bool ShouldCreate = true);
4936
4937 TempDIMacroFile cloneImpl() const {
4939 getElements());
4940 }
4941
4942public:
4944 (unsigned MIType, unsigned Line, DIFile *File,
4945 DIMacroNodeArray Elements),
4946 (MIType, Line, File, Elements))
4947 DEFINE_MDNODE_GET(DIMacroFile,
4948 (unsigned MIType, unsigned Line, Metadata *File,
4951
4952 TempDIMacroFile clone() const { return cloneImpl(); }
4953
4954 void replaceElements(DIMacroNodeArray Elements) {
4955#ifndef NDEBUG
4956 for (DIMacroNode *Op : getElements())
4957 assert(is_contained(Elements->operands(), Op) &&
4958 "Lost a macro node during macro node list replacement");
4959#endif
4960 replaceOperandWith(1, Elements.get());
4961 }
4962
4963 unsigned getLine() const { return SubclassData32; }
4965
4966 DIMacroNodeArray getElements() const {
4968 }
4969
4970 Metadata *getRawFile() const { return getOperand(0); }
4971 Metadata *getRawElements() const { return getOperand(1); }
4972
4973 static bool classof(const Metadata *MD) {
4974 return MD->getMetadataID() == DIMacroFileKind;
4975 }
4976};
4977
4978/// List of ValueAsMetadata, to be used as an argument to a dbg.value
4979/// intrinsic.
4980class DIArgList : public Metadata, ReplaceableMetadataImpl {
4982 friend class LLVMContextImpl;
4984
4986
4987 DIArgList(LLVMContext &Context, ArrayRef<ValueAsMetadata *> Args)
4988 : Metadata(DIArgListKind, Uniqued), ReplaceableMetadataImpl(Context),
4989 Args(Args) {
4990 track();
4991 }
4992 ~DIArgList() { untrack(); }
4993
4994 LLVM_ABI void track();
4995 LLVM_ABI void untrack();
4996 void dropAllReferences(bool Untrack);
4997
4998public:
4999 LLVM_ABI static DIArgList *get(LLVMContext &Context,
5001
5002 ArrayRef<ValueAsMetadata *> getArgs() const { return Args; }
5003
5004 iterator args_begin() { return Args.begin(); }
5005 iterator args_end() { return Args.end(); }
5006
5007 static bool classof(const Metadata *MD) {
5008 return MD->getMetadataID() == DIArgListKind;
5009 }
5010
5014
5015 LLVM_ABI void handleChangedOperand(void *Ref, Metadata *New);
5016};
5017
5018/// Identifies a unique instance of a variable.
5019///
5020/// Storage for identifying a potentially inlined instance of a variable,
5021/// or a fragment thereof. This guarantees that exactly one variable instance
5022/// may be identified by this class, even when that variable is a fragment of
5023/// an aggregate variable and/or there is another inlined instance of the same
5024/// source code variable nearby.
5025/// This class does not necessarily uniquely identify that variable: it is
5026/// possible that a DebugVariable with different parameters may point to the
5027/// same variable instance, but not that one DebugVariable points to multiple
5028/// variable instances.
5030 using FragmentInfo = DIExpression::FragmentInfo;
5031
5032 const DILocalVariable *Variable;
5033 std::optional<FragmentInfo> Fragment;
5034 const DILocation *InlinedAt;
5035
5036 /// Fragment that will overlap all other fragments. Used as default when
5037 /// caller demands a fragment.
5038 LLVM_ABI static const FragmentInfo DefaultFragment;
5039
5040public:
5042
5044 std::optional<FragmentInfo> FragmentInfo,
5045 const DILocation *InlinedAt)
5046 : Variable(Var), Fragment(FragmentInfo), InlinedAt(InlinedAt) {}
5047
5048 DebugVariable(const DILocalVariable *Var, const DIExpression *DIExpr,
5049 const DILocation *InlinedAt)
5050 : Variable(Var),
5051 Fragment(DIExpr ? DIExpr->getFragmentInfo() : std::nullopt),
5052 InlinedAt(InlinedAt) {}
5053
5054 const DILocalVariable *getVariable() const { return Variable; }
5055 std::optional<FragmentInfo> getFragment() const { return Fragment; }
5056 const DILocation *getInlinedAt() const { return InlinedAt; }
5057
5058 FragmentInfo getFragmentOrDefault() const {
5059 return Fragment.value_or(DefaultFragment);
5060 }
5061
5062 static bool isDefaultFragment(const FragmentInfo F) {
5063 return F == DefaultFragment;
5064 }
5065
5066 bool operator==(const DebugVariable &Other) const {
5067 return std::tie(Variable, Fragment, InlinedAt) ==
5068 std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
5069 }
5070
5071 bool operator<(const DebugVariable &Other) const {
5072 return std::tie(Variable, Fragment, InlinedAt) <
5073 std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
5074 }
5075};
5076
5077template <> struct DenseMapInfo<DebugVariable> {
5079
5080 static unsigned getHashValue(const DebugVariable &D) {
5081 unsigned HV = 0;
5082 const std::optional<FragmentInfo> Fragment = D.getFragment();
5083 if (Fragment)
5085
5086 return hash_combine(D.getVariable(), HV, D.getInlinedAt());
5087 }
5088
5089 static bool isEqual(const DebugVariable &A, const DebugVariable &B) {
5090 return A == B;
5091 }
5092};
5093
5094/// Identifies a unique instance of a whole variable (discards/ignores fragment
5095/// information).
5102
5103template <>
5105 : public DenseMapInfo<DebugVariable> {};
5106
5107template <typename NodeT> static const DIScope *getScope(const NodeT *N) {
5108 return N->getScope();
5109}
5110
5111template <typename NodeT> static DIScope *getScope(NodeT *N) {
5112 return N->getScope();
5113}
5114
5115template <>
5116[[maybe_unused]] const DIScope *
5118 return N->getVariable()->getScope();
5119}
5120template <>
5122 return N->getVariable()->getScope();
5123}
5124} // end namespace llvm
5125
5126#undef DEFINE_MDNODE_GET_UNPACK_IMPL
5127#undef DEFINE_MDNODE_GET_UNPACK
5128#undef DEFINE_MDNODE_GET
5129
5130#endif // LLVM_IR_DEBUGINFOMETADATA_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned uint64_t
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static std::string getLinkageName(GlobalValue::LinkageTypes LT)
#define X(NUM, ENUM, NAME)
Definition ELF.h:857
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
A property of a class or structure.
MDString Metadata unsigned Metadata * Type
MDString Metadata unsigned Metadata Metadata BackingStorage TempDIProperty clone() const
unsigned getLine() const
static bool classof(const Metadata *MD)
Metadata * getRawFile() const
StringRef getFilename() const
DINode * getBackingStorage() const
The data member holding the property's backing storage, i.e.
Metadata * getRawType() const
DIFile * getFile() const
MDString Metadata unsigned Metadata Metadata * BackingStorage
friend class LLVMContextImpl
StringRef getDirectory() const
MDString * getRawName() const
StringRef getName() const
DEFINE_MDNODE_GET(DIProperty,(StringRef Name, DIFile *File, unsigned Line, DIType *Type, DINode *BackingStorage),(Name, File, Line, Type, BackingStorage)) DEFINE_MDNODE_GET(DIProperty
Metadata * getRawBackingStorage() const
DIType * getType() const
MDString Metadata * File
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:386
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:2140
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