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