LLVM 22.0.0git
DebugInfoMetadata.h
Go to the documentation of this file.
1//===- llvm/IR/DebugInfoMetadata.h - Debug info metadata --------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Declarations for metadata specific to debug info.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_IR_DEBUGINFOMETADATA_H
14#define LLVM_IR_DEBUGINFOMETADATA_H
15
16#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/STLExtras.h"
21#include "llvm/ADT/StringRef.h"
23#include "llvm/IR/Constants.h"
25#include "llvm/IR/Metadata.h"
26#include "llvm/IR/PseudoProbe.h"
31#include <cassert>
32#include <climits>
33#include <cstddef>
34#include <cstdint>
35#include <iterator>
36#include <optional>
37#include <vector>
38
39// Helper macros for defining get() overrides.
40#define DEFINE_MDNODE_GET_UNPACK_IMPL(...) __VA_ARGS__
41#define DEFINE_MDNODE_GET_UNPACK(ARGS) DEFINE_MDNODE_GET_UNPACK_IMPL ARGS
42#define DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS) \
43 static CLASS *getDistinct(LLVMContext &Context, \
44 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
45 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct); \
46 } \
47 static Temp##CLASS getTemporary(LLVMContext &Context, \
48 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
49 return Temp##CLASS( \
50 getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary)); \
51 }
52#define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS) \
53 static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
54 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued); \
55 } \
56 static CLASS *getIfExists(LLVMContext &Context, \
57 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
58 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued, \
59 /* ShouldCreate */ false); \
60 } \
61 DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS)
62
63namespace llvm {
64
65namespace dwarf {
66enum Tag : uint16_t;
67}
68
69class DbgVariableRecord;
70
72
74 const MDTuple *N = nullptr;
75
76public:
77 DITypeRefArray() = default;
78 DITypeRefArray(const MDTuple *N) : N(N) {}
79
80 explicit operator bool() const { return get(); }
81 explicit operator MDTuple *() const { return get(); }
82
83 MDTuple *get() const { return const_cast<MDTuple *>(N); }
84 MDTuple *operator->() const { return get(); }
85 MDTuple &operator*() const { return *get(); }
86
87 // FIXME: Fix callers and remove condition on N.
88 unsigned size() const { return N ? N->getNumOperands() : 0u; }
89 DIType *operator[](unsigned I) const {
90 return cast_or_null<DIType>(N->getOperand(I));
91 }
92
93 class iterator {
94 MDNode::op_iterator I = nullptr;
95
96 public:
97 using iterator_category = std::input_iterator_tag;
98 using value_type = DIType *;
99 using difference_type = std::ptrdiff_t;
100 using pointer = void;
101 using reference = DIType *;
102
103 iterator() = default;
104 explicit iterator(MDNode::op_iterator I) : I(I) {}
105
106 DIType *operator*() const { return cast_or_null<DIType>(*I); }
107
109 ++I;
110 return *this;
111 }
112
114 iterator Temp(*this);
115 ++I;
116 return Temp;
117 }
118
119 bool operator==(const iterator &X) const { return I == X.I; }
120 bool operator!=(const iterator &X) const { return I != X.I; }
121 };
122
123 // FIXME: Fix callers and remove condition on N.
124 iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); }
125 iterator end() const { return N ? iterator(N->op_end()) : iterator(); }
126};
127
128/// Tagged DWARF-like metadata node.
129///
130/// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
131/// defined in llvm/BinaryFormat/Dwarf.h). Called \a DINode because it's
132/// potentially used for non-DWARF output.
133///
134/// Uses the SubclassData16 Metadata slot.
135class DINode : public MDNode {
136 friend class LLVMContextImpl;
137 friend class MDNode;
138
139protected:
140 DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
142 : MDNode(C, ID, Storage, Ops1, Ops2) {
143 assert(Tag < 1u << 16);
145 }
146 ~DINode() = default;
147
148 template <class Ty> Ty *getOperandAs(unsigned I) const {
150 }
151
152 StringRef getStringOperand(unsigned I) const {
153 if (auto *S = getOperandAs<MDString>(I))
154 return S->getString();
155 return StringRef();
156 }
157
159 if (S.empty())
160 return nullptr;
161 return MDString::get(Context, S);
162 }
163
164 /// Allow subclasses to mutate the tag.
165 void setTag(unsigned Tag) { SubclassData16 = Tag; }
166
167public:
168 LLVM_ABI dwarf::Tag getTag() const;
169
170 /// Debug info flags.
171 ///
172 /// The three accessibility flags are mutually exclusive and rolled together
173 /// in the first two bits.
175#define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
176#define DI_FLAG_LARGEST_NEEDED
177#include "llvm/IR/DebugInfoFlags.def"
178 FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic,
179 FlagPtrToMemberRep = FlagSingleInheritance | FlagMultipleInheritance |
180 FlagVirtualInheritance,
181 LLVM_MARK_AS_BITMASK_ENUM(FlagLargest)
182 };
183
184 LLVM_ABI static DIFlags getFlag(StringRef Flag);
185 LLVM_ABI static StringRef getFlagString(DIFlags Flag);
186
187 /// Split up a flags bitfield.
188 ///
189 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
190 /// any remaining (unrecognized) bits.
191 LLVM_ABI static DIFlags splitFlags(DIFlags Flags,
192 SmallVectorImpl<DIFlags> &SplitFlags);
193
194 static bool classof(const Metadata *MD) {
195 switch (MD->getMetadataID()) {
196 default:
197 return false;
198 case GenericDINodeKind:
199 case DISubrangeKind:
200 case DIEnumeratorKind:
201 case DIBasicTypeKind:
202 case DIFixedPointTypeKind:
203 case DIStringTypeKind:
204 case DISubrangeTypeKind:
205 case DIDerivedTypeKind:
206 case DICompositeTypeKind:
207 case DISubroutineTypeKind:
208 case DIFileKind:
209 case DICompileUnitKind:
210 case DISubprogramKind:
211 case DILexicalBlockKind:
212 case DILexicalBlockFileKind:
213 case DINamespaceKind:
214 case DICommonBlockKind:
215 case DITemplateTypeParameterKind:
216 case DITemplateValueParameterKind:
217 case DIGlobalVariableKind:
218 case DILocalVariableKind:
219 case DILabelKind:
220 case DIObjCPropertyKind:
221 case DIImportedEntityKind:
222 case DIModuleKind:
223 case DIGenericSubrangeKind:
224 case DIAssignIDKind:
225 return true;
226 }
227 }
228};
229
230/// Generic tagged DWARF-like metadata node.
231///
232/// An un-specialized DWARF-like metadata node. The first operand is a
233/// (possibly empty) null-separated \a MDString header that contains arbitrary
234/// fields. The remaining operands are \a dwarf_operands(), and are pointers
235/// to other metadata.
236///
237/// Uses the SubclassData32 Metadata slot.
238class GenericDINode : public DINode {
239 friend class LLVMContextImpl;
240 friend class MDNode;
241
242 GenericDINode(LLVMContext &C, StorageType Storage, unsigned Hash,
243 unsigned Tag, ArrayRef<Metadata *> Ops1,
245 : DINode(C, GenericDINodeKind, Storage, Tag, Ops1, Ops2) {
246 setHash(Hash);
247 }
249
250 void setHash(unsigned Hash) { SubclassData32 = Hash; }
251 void recalculateHash();
252
253 static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
255 StorageType Storage, bool ShouldCreate = true) {
256 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
257 DwarfOps, Storage, ShouldCreate);
258 }
259
260 LLVM_ABI static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
261 MDString *Header,
264 bool ShouldCreate = true);
265
266 TempGenericDINode cloneImpl() const {
269 }
270
271public:
272 unsigned getHash() const { return SubclassData32; }
273
274 DEFINE_MDNODE_GET(GenericDINode,
275 (unsigned Tag, StringRef Header,
277 (Tag, Header, DwarfOps))
278 DEFINE_MDNODE_GET(GenericDINode,
279 (unsigned Tag, MDString *Header,
282
283 /// Return a (temporary) clone of this.
284 TempGenericDINode clone() const { return cloneImpl(); }
285
286 LLVM_ABI dwarf::Tag getTag() const;
287 StringRef getHeader() const { return getStringOperand(0); }
289
290 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
291 op_iterator dwarf_op_end() const { return op_end(); }
294 }
295
296 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
297 const MDOperand &getDwarfOperand(unsigned I) const {
298 return getOperand(I + 1);
299 }
300 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
301 replaceOperandWith(I + 1, New);
302 }
303
304 static bool classof(const Metadata *MD) {
305 return MD->getMetadataID() == GenericDINodeKind;
306 }
307};
308
309/// Assignment ID.
310/// Used to link stores (as an attachment) and dbg.assigns (as an operand).
311/// DIAssignID metadata is never uniqued as we compare instances using
312/// referential equality (the instance/address is the ID).
313class DIAssignID : public MDNode {
314 friend class LLVMContextImpl;
315 friend class MDNode;
316
318 : MDNode(C, DIAssignIDKind, Storage, {}) {}
319
320 ~DIAssignID() { dropAllReferences(); }
321
322 LLVM_ABI static DIAssignID *getImpl(LLVMContext &Context, StorageType Storage,
323 bool ShouldCreate = true);
324
325 TempDIAssignID cloneImpl() const { return getTemporary(getContext()); }
326
327public:
328 // This node has no operands to replace.
329 void replaceOperandWith(unsigned I, Metadata *New) = delete;
330
332 return Context.getReplaceableUses()->getAllDbgVariableRecordUsers();
333 }
334
335 static DIAssignID *getDistinct(LLVMContext &Context) {
336 return getImpl(Context, Distinct);
337 }
338 static TempDIAssignID getTemporary(LLVMContext &Context) {
339 return TempDIAssignID(getImpl(Context, Temporary));
340 }
341 // NOTE: Do not define get(LLVMContext&) - see class comment.
342
343 static bool classof(const Metadata *MD) {
344 return MD->getMetadataID() == DIAssignIDKind;
345 }
346};
347
348/// Array subrange.
349class DISubrange : public DINode {
350 friend class LLVMContextImpl;
351 friend class MDNode;
352
354
355 ~DISubrange() = default;
356
357 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, int64_t Count,
359 bool ShouldCreate = true);
360
361 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, Metadata *CountNode,
363 bool ShouldCreate = true);
364
365 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, Metadata *CountNode,
367 Metadata *UpperBound, Metadata *Stride,
369 bool ShouldCreate = true);
370
371 TempDISubrange cloneImpl() const {
372 return getTemporary(getContext(), getRawCountNode(), getRawLowerBound(),
373 getRawUpperBound(), getRawStride());
374 }
375
376public:
377 DEFINE_MDNODE_GET(DISubrange, (int64_t Count, int64_t LowerBound = 0),
378 (Count, LowerBound))
379
380 DEFINE_MDNODE_GET(DISubrange, (Metadata * CountNode, int64_t LowerBound = 0),
382
383 DEFINE_MDNODE_GET(DISubrange,
385 Metadata *UpperBound, Metadata *Stride),
386 (CountNode, LowerBound, UpperBound, Stride))
387
388 TempDISubrange clone() const { return cloneImpl(); }
389
390 Metadata *getRawCountNode() const { return getOperand(0).get(); }
391
392 Metadata *getRawLowerBound() const { return getOperand(1).get(); }
393
394 Metadata *getRawUpperBound() const { return getOperand(2).get(); }
395
396 Metadata *getRawStride() const { return getOperand(3).get(); }
397
398 typedef PointerUnion<ConstantInt *, DIVariable *, DIExpression *> BoundType;
399
400 LLVM_ABI BoundType getCount() const;
401
402 LLVM_ABI BoundType getLowerBound() const;
403
404 LLVM_ABI BoundType getUpperBound() const;
405
406 LLVM_ABI BoundType getStride() const;
407
408 static bool classof(const Metadata *MD) {
409 return MD->getMetadataID() == DISubrangeKind;
410 }
411};
412
413class DIGenericSubrange : public DINode {
414 friend class LLVMContextImpl;
415 friend class MDNode;
416
417 DIGenericSubrange(LLVMContext &C, StorageType Storage,
419
420 ~DIGenericSubrange() = default;
421
422 LLVM_ABI static DIGenericSubrange *
423 getImpl(LLVMContext &Context, Metadata *CountNode, Metadata *LowerBound,
424 Metadata *UpperBound, Metadata *Stride, StorageType Storage,
425 bool ShouldCreate = true);
426
427 TempDIGenericSubrange cloneImpl() const {
430 }
431
432public:
433 DEFINE_MDNODE_GET(DIGenericSubrange,
434 (Metadata * CountNode, Metadata *LowerBound,
435 Metadata *UpperBound, Metadata *Stride),
436 (CountNode, LowerBound, UpperBound, Stride))
437
438 TempDIGenericSubrange clone() const { return cloneImpl(); }
439
440 Metadata *getRawCountNode() const { return getOperand(0).get(); }
441 Metadata *getRawLowerBound() const { return getOperand(1).get(); }
442 Metadata *getRawUpperBound() const { return getOperand(2).get(); }
443 Metadata *getRawStride() const { return getOperand(3).get(); }
444
446
451
452 static bool classof(const Metadata *MD) {
453 return MD->getMetadataID() == DIGenericSubrangeKind;
454 }
455};
456
457/// Enumeration value.
458///
459/// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
460/// longer creates a type cycle.
461class DIEnumerator : public DINode {
462 friend class LLVMContextImpl;
463 friend class MDNode;
464
465 APInt Value;
466 LLVM_ABI DIEnumerator(LLVMContext &C, StorageType Storage, const APInt &Value,
468 DIEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
470 : DIEnumerator(C, Storage, APInt(64, Value, !IsUnsigned), IsUnsigned,
471 Ops) {}
472 ~DIEnumerator() = default;
473
474 static DIEnumerator *getImpl(LLVMContext &Context, const APInt &Value,
476 StorageType Storage, bool ShouldCreate = true) {
477 return getImpl(Context, Value, IsUnsigned,
478 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
479 }
480 LLVM_ABI static DIEnumerator *getImpl(LLVMContext &Context,
481 const APInt &Value, bool IsUnsigned,
482 MDString *Name, StorageType Storage,
483 bool ShouldCreate = true);
484
485 TempDIEnumerator cloneImpl() const {
487 }
488
489public:
490 DEFINE_MDNODE_GET(DIEnumerator,
491 (int64_t Value, bool IsUnsigned, StringRef Name),
492 (APInt(64, Value, !IsUnsigned), IsUnsigned, Name))
493 DEFINE_MDNODE_GET(DIEnumerator,
494 (int64_t Value, bool IsUnsigned, MDString *Name),
495 (APInt(64, Value, !IsUnsigned), IsUnsigned, Name))
496 DEFINE_MDNODE_GET(DIEnumerator,
497 (APInt Value, bool IsUnsigned, StringRef Name),
498 (Value, IsUnsigned, Name))
499 DEFINE_MDNODE_GET(DIEnumerator,
500 (APInt Value, bool IsUnsigned, MDString *Name),
501 (Value, IsUnsigned, Name))
502
503 TempDIEnumerator clone() const { return cloneImpl(); }
504
505 const APInt &getValue() const { return Value; }
506 bool isUnsigned() const { return SubclassData32; }
507 StringRef getName() const { return getStringOperand(0); }
508
510
511 static bool classof(const Metadata *MD) {
512 return MD->getMetadataID() == DIEnumeratorKind;
513 }
514};
515
516/// Base class for scope-like contexts.
517///
518/// Base class for lexical scopes and types (which are also declaration
519/// contexts).
520///
521/// TODO: Separate the concepts of declaration contexts and lexical scopes.
522class DIScope : public DINode {
523protected:
527 ~DIScope() = default;
528
529public:
531
532 inline StringRef getFilename() const;
533 inline StringRef getDirectory() const;
534 inline std::optional<StringRef> getSource() const;
535
536 LLVM_ABI StringRef getName() const;
537 LLVM_ABI DIScope *getScope() const;
538
539 /// Return the raw underlying file.
540 ///
541 /// A \a DIFile is a \a DIScope, but it doesn't point at a separate file (it
542 /// \em is the file). If \c this is an \a DIFile, we need to return \c this.
543 /// Otherwise, return the first operand, which is where all other subclasses
544 /// store their file pointer.
546 return isa<DIFile>(this) ? const_cast<DIScope *>(this)
547 : static_cast<Metadata *>(getOperand(0));
548 }
549
550 static bool classof(const Metadata *MD) {
551 switch (MD->getMetadataID()) {
552 default:
553 return false;
554 case DIBasicTypeKind:
555 case DIFixedPointTypeKind:
556 case DIStringTypeKind:
557 case DISubrangeTypeKind:
558 case DIDerivedTypeKind:
559 case DICompositeTypeKind:
560 case DISubroutineTypeKind:
561 case DIFileKind:
562 case DICompileUnitKind:
563 case DISubprogramKind:
564 case DILexicalBlockKind:
565 case DILexicalBlockFileKind:
566 case DINamespaceKind:
567 case DICommonBlockKind:
568 case DIModuleKind:
569 return true;
570 }
571 }
572};
573
574/// File.
575///
576/// TODO: Merge with directory/file node (including users).
577/// TODO: Canonicalize paths on creation.
578class DIFile : public DIScope {
579 friend class LLVMContextImpl;
580 friend class MDNode;
581
582public:
583 /// Which algorithm (e.g. MD5) a checksum was generated with.
584 ///
585 /// The encoding is explicit because it is used directly in Bitcode. The
586 /// value 0 is reserved to indicate the absence of a checksum in Bitcode.
588 // The first variant was originally CSK_None, encoded as 0. The new
589 // internal representation removes the need for this by wrapping the
590 // ChecksumInfo in an Optional, but to preserve Bitcode compatibility the 0
591 // encoding is reserved.
595 CSK_Last = CSK_SHA256 // Should be last enumeration.
596 };
597
598 /// A single checksum, represented by a \a Kind and a \a Value (a string).
599 template <typename T> struct ChecksumInfo {
600 /// The kind of checksum which \a Value encodes.
602 /// The string value of the checksum.
604
606 ~ChecksumInfo() = default;
607 bool operator==(const ChecksumInfo<T> &X) const {
608 return Kind == X.Kind && Value == X.Value;
609 }
610 bool operator!=(const ChecksumInfo<T> &X) const { return !(*this == X); }
611 StringRef getKindAsString() const { return getChecksumKindAsString(Kind); }
612 };
613
614private:
615 std::optional<ChecksumInfo<MDString *>> Checksum;
616 /// An optional source. A nullptr means none.
618
620 std::optional<ChecksumInfo<MDString *>> CS, MDString *Src,
622 ~DIFile() = default;
623
624 static DIFile *getImpl(LLVMContext &Context, StringRef Filename,
626 std::optional<ChecksumInfo<StringRef>> CS,
627 std::optional<StringRef> Source, StorageType Storage,
628 bool ShouldCreate = true) {
629 std::optional<ChecksumInfo<MDString *>> MDChecksum;
630 if (CS)
631 MDChecksum.emplace(CS->Kind, getCanonicalMDString(Context, CS->Value));
632 return getImpl(Context, getCanonicalMDString(Context, Filename),
633 getCanonicalMDString(Context, Directory), MDChecksum,
634 Source ? MDString::get(Context, *Source) : nullptr, Storage,
635 ShouldCreate);
636 }
637 LLVM_ABI static DIFile *getImpl(LLVMContext &Context, MDString *Filename,
638 MDString *Directory,
639 std::optional<ChecksumInfo<MDString *>> CS,
640 MDString *Source, StorageType Storage,
641 bool ShouldCreate = true);
642
643 TempDIFile cloneImpl() const {
645 getChecksum(), getSource());
646 }
647
648public:
651 std::optional<ChecksumInfo<StringRef>> CS = std::nullopt,
652 std::optional<StringRef> Source = std::nullopt),
653 (Filename, Directory, CS, Source))
654 DEFINE_MDNODE_GET(DIFile,
656 std::optional<ChecksumInfo<MDString *>> CS = std::nullopt,
657 MDString *Source = nullptr),
658 (Filename, Directory, CS, Source))
659
660 TempDIFile clone() const { return cloneImpl(); }
661
662 StringRef getFilename() const { return getStringOperand(0); }
663 StringRef getDirectory() const { return getStringOperand(1); }
664 std::optional<ChecksumInfo<StringRef>> getChecksum() const {
665 std::optional<ChecksumInfo<StringRef>> StringRefChecksum;
666 if (Checksum)
667 StringRefChecksum.emplace(Checksum->Kind, Checksum->Value->getString());
668 return StringRefChecksum;
669 }
670 std::optional<StringRef> getSource() const {
671 return Source ? std::optional<StringRef>(Source->getString())
672 : std::nullopt;
673 }
674
675 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
676 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
677 std::optional<ChecksumInfo<MDString *>> getRawChecksum() const {
678 return Checksum;
679 }
680 MDString *getRawSource() const { return Source; }
681
682 LLVM_ABI static StringRef getChecksumKindAsString(ChecksumKind CSKind);
683 LLVM_ABI static std::optional<ChecksumKind>
684 getChecksumKind(StringRef CSKindStr);
685
686 static bool classof(const Metadata *MD) {
687 return MD->getMetadataID() == DIFileKind;
688 }
689};
690
692 if (auto *F = getFile())
693 return F->getFilename();
694 return "";
695}
696
698 if (auto *F = getFile())
699 return F->getDirectory();
700 return "";
701}
702
703std::optional<StringRef> DIScope::getSource() const {
704 if (auto *F = getFile())
705 return F->getSource();
706 return std::nullopt;
707}
708
709/// Base class for types.
710///
711/// TODO: Remove the hardcoded name and context, since many types don't use
712/// them.
713/// TODO: Split up flags.
714///
715/// Uses the SubclassData32 Metadata slot.
716class DIType : public DIScope {
717 unsigned Line;
718 DIFlags Flags;
719 uint32_t NumExtraInhabitants;
720
721protected:
722 static constexpr unsigned N_OPERANDS = 5;
723
724 DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
725 unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants,
727 : DIScope(C, ID, Storage, Tag, Ops) {
728 init(Line, AlignInBits, NumExtraInhabitants, Flags);
729 }
730 ~DIType() = default;
731
732 void init(unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants,
733 DIFlags Flags) {
734 this->Line = Line;
735 this->Flags = Flags;
736 this->SubclassData32 = AlignInBits;
737 this->NumExtraInhabitants = NumExtraInhabitants;
738 }
739
740 /// Change fields in place.
741 void mutate(unsigned Tag, unsigned Line, uint32_t AlignInBits,
742 uint32_t NumExtraInhabitants, DIFlags Flags) {
743 assert(isDistinct() && "Only distinct nodes can mutate");
744 setTag(Tag);
745 init(Line, AlignInBits, NumExtraInhabitants, Flags);
746 }
747
748public:
749 TempDIType clone() const {
750 return TempDIType(cast<DIType>(MDNode::clone().release()));
751 }
752
753 unsigned getLine() const { return Line; }
755 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
756 uint32_t getNumExtraInhabitants() const { return NumExtraInhabitants; }
757 DIFlags getFlags() const { return Flags; }
758
760 StringRef getName() const { return getStringOperand(2); }
761
762 Metadata *getRawScope() const { return getOperand(1); }
764
765 Metadata *getRawSizeInBits() const { return getOperand(3); }
768 if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(MD->getValue()))
769 return CI->getZExtValue();
770 }
771 return 0;
772 }
773
774 Metadata *getRawOffsetInBits() const { return getOperand(4); }
777 if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(MD->getValue()))
778 return CI->getZExtValue();
779 }
780 return 0;
781 }
782
783 /// Returns a new temporary DIType with updated Flags
784 TempDIType cloneWithFlags(DIFlags NewFlags) const {
785 auto NewTy = clone();
786 NewTy->Flags = NewFlags;
787 return NewTy;
788 }
789
790 bool isPrivate() const {
791 return (getFlags() & FlagAccessibility) == FlagPrivate;
792 }
793 bool isProtected() const {
794 return (getFlags() & FlagAccessibility) == FlagProtected;
795 }
796 bool isPublic() const {
797 return (getFlags() & FlagAccessibility) == FlagPublic;
798 }
799 bool isForwardDecl() const { return getFlags() & FlagFwdDecl; }
800 bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; }
801 bool isVirtual() const { return getFlags() & FlagVirtual; }
802 bool isArtificial() const { return getFlags() & FlagArtificial; }
803 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
804 bool isObjcClassComplete() const {
805 return getFlags() & FlagObjcClassComplete;
806 }
807 bool isVector() const { return getFlags() & FlagVector; }
808 bool isBitField() const { return getFlags() & FlagBitField; }
809 bool isStaticMember() const { return getFlags() & FlagStaticMember; }
810 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
811 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
812 bool isTypePassByValue() const { return getFlags() & FlagTypePassByValue; }
814 return getFlags() & FlagTypePassByReference;
815 }
816 bool isBigEndian() const { return getFlags() & FlagBigEndian; }
817 bool isLittleEndian() const { return getFlags() & FlagLittleEndian; }
818 bool getExportSymbols() const { return getFlags() & FlagExportSymbols; }
819
820 static bool classof(const Metadata *MD) {
821 switch (MD->getMetadataID()) {
822 default:
823 return false;
824 case DIBasicTypeKind:
825 case DIFixedPointTypeKind:
826 case DIStringTypeKind:
827 case DISubrangeTypeKind:
828 case DIDerivedTypeKind:
829 case DICompositeTypeKind:
830 case DISubroutineTypeKind:
831 return true;
832 }
833 }
834};
835
836/// Basic type, like 'int' or 'float'.
837///
838/// TODO: Split out DW_TAG_unspecified_type.
839/// TODO: Drop unused accessors.
840class DIBasicType : public DIType {
841 friend class LLVMContextImpl;
842 friend class MDNode;
843
844 unsigned Encoding;
845
846protected:
848 uint32_t AlignInBits, unsigned Encoding,
851 : DIType(C, DIBasicTypeKind, Storage, Tag, 0, AlignInBits,
853 Encoding(Encoding) {}
855 uint32_t AlignInBits, unsigned Encoding,
859 Ops),
860 Encoding(Encoding) {}
861 ~DIBasicType() = default;
862
863 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
865 uint32_t AlignInBits, unsigned Encoding,
867 StorageType Storage, bool ShouldCreate = true) {
868 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
870 Flags, Storage, ShouldCreate);
871 }
872 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
874 uint32_t AlignInBits, unsigned Encoding,
876 StorageType Storage, bool ShouldCreate = true) {
877 auto *SizeInBitsNode = ConstantAsMetadata::get(
878 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
879 return getImpl(Context, Tag, Name, SizeInBitsNode, AlignInBits, Encoding,
880 NumExtraInhabitants, Flags, Storage, ShouldCreate);
881 }
882 LLVM_ABI static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
884 uint32_t AlignInBits, unsigned Encoding,
886 DIFlags Flags, StorageType Storage,
887 bool ShouldCreate = true);
888
889 TempDIBasicType cloneImpl() const {
893 }
894
895public:
897 (Tag, Name, 0, 0, 0, 0, FlagZero))
900 (Tag, Name, SizeInBits, 0, 0, 0, FlagZero))
902 (unsigned Tag, MDString *Name, uint64_t SizeInBits),
903 (Tag, Name, SizeInBits, 0, 0, 0, FlagZero))
906 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
907 (Tag, Name, SizeInBits, AlignInBits, Encoding, 0, Flags))
909 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
910 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
911 (Tag, Name, SizeInBits, AlignInBits, Encoding, 0, Flags))
914 uint32_t AlignInBits, unsigned Encoding,
919 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
920 uint32_t AlignInBits, unsigned Encoding,
922 (Tag, Name, SizeInBits, AlignInBits, Encoding,
926 uint32_t AlignInBits, unsigned Encoding,
930
931 TempDIBasicType clone() const { return cloneImpl(); }
932
933 unsigned getEncoding() const { return Encoding; }
934
935 enum class Signedness { Signed, Unsigned };
936
937 /// Return the signedness of this type, or std::nullopt if this type is
938 /// neither signed nor unsigned.
939 LLVM_ABI std::optional<Signedness> getSignedness() const;
940
941 static bool classof(const Metadata *MD) {
942 return MD->getMetadataID() == DIBasicTypeKind ||
943 MD->getMetadataID() == DIFixedPointTypeKind;
944 }
945};
946
947/// Fixed-point type.
948class DIFixedPointType : public DIBasicType {
949 friend class LLVMContextImpl;
950 friend class MDNode;
951
952 // Actually FixedPointKind.
953 unsigned Kind;
954 // Used for binary and decimal.
955 int Factor;
956 // Used for rational.
957 APInt Numerator;
958 APInt Denominator;
959
960 DIFixedPointType(LLVMContext &C, StorageType Storage, unsigned Tag,
962 unsigned Kind, int Factor, ArrayRef<Metadata *> Ops)
963 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, AlignInBits,
964 Encoding, 0, Flags, Ops),
965 Kind(Kind), Factor(Factor) {
966 assert(Kind == FixedPointBinary || Kind == FixedPointDecimal);
967 }
969 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags,
970 unsigned Kind, APInt Numerator, APInt Denominator,
972 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, AlignInBits,
973 Encoding, 0, Flags, Ops),
975 assert(Kind == FixedPointRational);
976 }
977 DIFixedPointType(LLVMContext &C, StorageType Storage, unsigned Tag,
978 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags,
979 unsigned Kind, int Factor, APInt Numerator,
981 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, AlignInBits,
982 Encoding, 0, Flags, Ops),
983 Kind(Kind), Factor(Factor), Numerator(Numerator),
985 ~DIFixedPointType() = default;
986
987 static DIFixedPointType *
988 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name,
989 uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
990 DIFlags Flags, unsigned Kind, int Factor, APInt Numerator,
991 APInt Denominator, StorageType Storage, bool ShouldCreate = true) {
992 auto *SizeInBitsNode = ConstantAsMetadata::get(
993 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
994 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
995 SizeInBitsNode, AlignInBits, Encoding, Flags, Kind, Factor,
996 Numerator, Denominator, Storage, ShouldCreate);
997 }
998 static DIFixedPointType *
999 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name,
1000 Metadata *SizeInBits, uint32_t AlignInBits, unsigned Encoding,
1001 DIFlags Flags, unsigned Kind, int Factor, APInt Numerator,
1002 APInt Denominator, StorageType Storage, bool ShouldCreate = true) {
1003 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
1004 SizeInBits, AlignInBits, Encoding, Flags, Kind, Factor,
1005 Numerator, Denominator, Storage, ShouldCreate);
1006 }
1007 static DIFixedPointType *
1008 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name,
1009 uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
1010 DIFlags Flags, unsigned Kind, int Factor, APInt Numerator,
1011 APInt Denominator, StorageType Storage, bool ShouldCreate = true) {
1012 auto *SizeInBitsNode = ConstantAsMetadata::get(
1013 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1014 return getImpl(Context, Tag, Name, SizeInBitsNode, AlignInBits, Encoding,
1015 Flags, Kind, Factor, Numerator, Denominator, Storage,
1016 ShouldCreate);
1017 }
1018 LLVM_ABI static DIFixedPointType *
1019 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name,
1020 Metadata *SizeInBits, uint32_t AlignInBits, unsigned Encoding,
1021 DIFlags Flags, unsigned Kind, int Factor, APInt Numerator,
1022 APInt Denominator, StorageType Storage, bool ShouldCreate = true);
1023
1024 TempDIFixedPointType cloneImpl() const {
1027 getFlags(), Kind, Factor, Numerator, Denominator);
1028 }
1029
1030public:
1031 enum FixedPointKind : unsigned {
1032 /// Scale factor 2^Factor.
1034 /// Scale factor 10^Factor.
1036 /// Arbitrary rational scale factor.
1039 };
1040
1041 LLVM_ABI static std::optional<FixedPointKind>
1043 LLVM_ABI static const char *fixedPointKindString(FixedPointKind);
1044
1045 DEFINE_MDNODE_GET(DIFixedPointType,
1046 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
1048 unsigned Kind, int Factor, APInt Numerator,
1049 APInt Denominator),
1051 Factor, Numerator, Denominator))
1052 DEFINE_MDNODE_GET(DIFixedPointType,
1055 unsigned Kind, int Factor, APInt Numerator,
1056 APInt Denominator),
1058 Factor, Numerator, Denominator))
1059 DEFINE_MDNODE_GET(DIFixedPointType,
1060 (unsigned Tag, MDString *Name, Metadata *SizeInBits,
1062 unsigned Kind, int Factor, APInt Numerator,
1063 APInt Denominator),
1065 Factor, Numerator, Denominator))
1066
1067 TempDIFixedPointType clone() const { return cloneImpl(); }
1068
1069 bool isBinary() const { return Kind == FixedPointBinary; }
1070 bool isDecimal() const { return Kind == FixedPointDecimal; }
1071 bool isRational() const { return Kind == FixedPointRational; }
1072
1073 LLVM_ABI bool isSigned() const;
1074
1075 FixedPointKind getKind() const { return static_cast<FixedPointKind>(Kind); }
1076
1077 int getFactorRaw() const { return Factor; }
1078 int getFactor() const {
1079 assert(Kind == FixedPointBinary || Kind == FixedPointDecimal);
1080 return Factor;
1081 }
1082
1083 const APInt &getNumeratorRaw() const { return Numerator; }
1084 const APInt &getNumerator() const {
1085 assert(Kind == FixedPointRational);
1086 return Numerator;
1087 }
1088
1089 const APInt &getDenominatorRaw() const { return Denominator; }
1090 const APInt &getDenominator() const {
1091 assert(Kind == FixedPointRational);
1092 return Denominator;
1093 }
1094
1095 static bool classof(const Metadata *MD) {
1096 return MD->getMetadataID() == DIFixedPointTypeKind;
1097 }
1098};
1099
1100/// String type, Fortran CHARACTER(n)
1101class DIStringType : public DIType {
1102 friend class LLVMContextImpl;
1103 friend class MDNode;
1104
1105 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1106
1107 unsigned Encoding;
1108
1109 DIStringType(LLVMContext &C, StorageType Storage, unsigned Tag,
1110 uint32_t AlignInBits, unsigned Encoding,
1112 : DIType(C, DIStringTypeKind, Storage, Tag, 0, AlignInBits, 0, FlagZero,
1113 Ops),
1114 Encoding(Encoding) {}
1115 ~DIStringType() = default;
1116
1117 static DIStringType *getImpl(LLVMContext &Context, unsigned Tag,
1119 Metadata *StrLenExp, Metadata *StrLocationExp,
1121 unsigned Encoding, StorageType Storage,
1122 bool ShouldCreate = true) {
1123 auto *SizeInBitsNode = ConstantAsMetadata::get(
1124 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1125 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
1126 StringLength, StrLenExp, StrLocationExp, SizeInBitsNode,
1127 AlignInBits, Encoding, Storage, ShouldCreate);
1128 }
1129 static DIStringType *getImpl(LLVMContext &Context, unsigned Tag,
1130 MDString *Name, Metadata *StringLength,
1131 Metadata *StrLenExp, Metadata *StrLocationExp,
1133 unsigned Encoding, StorageType Storage,
1134 bool ShouldCreate = true) {
1135 auto *SizeInBitsNode = ConstantAsMetadata::get(
1136 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1137 return getImpl(Context, Tag, Name, StringLength, StrLenExp, StrLocationExp,
1138 SizeInBitsNode, AlignInBits, Encoding, Storage,
1139 ShouldCreate);
1140 }
1141 LLVM_ABI static DIStringType *
1142 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name,
1143 Metadata *StringLength, Metadata *StrLenExp, Metadata *StrLocationExp,
1144 Metadata *SizeInBits, uint32_t AlignInBits, unsigned Encoding,
1145 StorageType Storage, bool ShouldCreate = true);
1146
1147 TempDIStringType cloneImpl() const {
1152 }
1153
1154public:
1155 DEFINE_MDNODE_GET(DIStringType,
1156 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
1158 (Tag, Name, nullptr, nullptr, nullptr, SizeInBits,
1159 AlignInBits, 0))
1160 DEFINE_MDNODE_GET(DIStringType,
1164 unsigned Encoding),
1167 DEFINE_MDNODE_GET(DIStringType,
1168 (unsigned Tag, StringRef Name, Metadata *StringLength,
1171 unsigned Encoding),
1174 DEFINE_MDNODE_GET(DIStringType,
1178 unsigned Encoding),
1181
1182 TempDIStringType clone() const { return cloneImpl(); }
1183
1184 static bool classof(const Metadata *MD) {
1185 return MD->getMetadataID() == DIStringTypeKind;
1186 }
1187
1191
1195
1199
1200 unsigned getEncoding() const { return Encoding; }
1201
1202 Metadata *getRawStringLength() const { return getOperand(MY_FIRST_OPERAND); }
1203
1205 return getOperand(MY_FIRST_OPERAND + 1);
1206 }
1207
1209 return getOperand(MY_FIRST_OPERAND + 2);
1210 }
1211};
1212
1213/// Derived types.
1214///
1215/// This includes qualified types, pointers, references, friends, typedefs, and
1216/// class members.
1217///
1218/// TODO: Split out members (inheritance, fields, methods, etc.).
1219class DIDerivedType : public DIType {
1220public:
1221 /// Pointer authentication (__ptrauth) metadata.
1223 // RawData layout:
1224 // - Bits 0..3: Key
1225 // - Bit 4: IsAddressDiscriminated
1226 // - Bits 5..20: ExtraDiscriminator
1227 // - Bit 21: IsaPointer
1228 // - Bit 22: AuthenticatesNullValues
1229 unsigned RawData;
1230
1231 PtrAuthData(unsigned FromRawData) : RawData(FromRawData) {}
1232 PtrAuthData(unsigned Key, bool IsDiscr, unsigned Discriminator,
1233 bool IsaPointer, bool AuthenticatesNullValues) {
1234 assert(Key < 16);
1235 assert(Discriminator <= 0xffff);
1236 RawData = (Key << 0) | (IsDiscr ? (1 << 4) : 0) | (Discriminator << 5) |
1237 (IsaPointer ? (1 << 21) : 0) |
1238 (AuthenticatesNullValues ? (1 << 22) : 0);
1239 }
1240
1241 unsigned key() { return (RawData >> 0) & 0b1111; }
1242 bool isAddressDiscriminated() { return (RawData >> 4) & 1; }
1243 unsigned extraDiscriminator() { return (RawData >> 5) & 0xffff; }
1244 bool isaPointer() { return (RawData >> 21) & 1; }
1245 bool authenticatesNullValues() { return (RawData >> 22) & 1; }
1246 };
1247
1248private:
1249 friend class LLVMContextImpl;
1250 friend class MDNode;
1251
1252 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1253
1254 /// The DWARF address space of the memory pointed to or referenced by a
1255 /// pointer or reference type respectively.
1256 std::optional<unsigned> DWARFAddressSpace;
1257
1258 DIDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
1259 unsigned Line, uint32_t AlignInBits,
1260 std::optional<unsigned> DWARFAddressSpace,
1261 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1263 : DIType(C, DIDerivedTypeKind, Storage, Tag, Line, AlignInBits, 0, Flags,
1264 Ops),
1265 DWARFAddressSpace(DWARFAddressSpace) {
1266 if (PtrAuthData)
1268 }
1269 ~DIDerivedType() = default;
1270 static DIDerivedType *
1271 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1272 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1274 std::optional<unsigned> DWARFAddressSpace,
1275 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1277 bool ShouldCreate = true) {
1278 auto *SizeInBitsNode = ConstantAsMetadata::get(
1279 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1280 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1281 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1282 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1283 Line, Scope, BaseType, SizeInBitsNode, AlignInBits,
1284 OffsetInBitsNode, DWARFAddressSpace, PtrAuthData, Flags,
1285 ExtraData, Annotations.get(), Storage, ShouldCreate);
1286 }
1287 static DIDerivedType *
1288 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, DIFile *File,
1289 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1291 std::optional<unsigned> DWARFAddressSpace,
1292 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1294 bool ShouldCreate = true) {
1295 auto *SizeInBitsNode = ConstantAsMetadata::get(
1296 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1297 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1298 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1299 return getImpl(Context, Tag, Name, File, Line, Scope, BaseType,
1300 SizeInBitsNode, AlignInBits, OffsetInBitsNode,
1302 Annotations.get(), Storage, ShouldCreate);
1303 }
1304 static DIDerivedType *
1305 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1308 std::optional<unsigned> DWARFAddressSpace,
1309 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1311 bool ShouldCreate = true) {
1312 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1314 DWARFAddressSpace, PtrAuthData, Flags, ExtraData,
1315 Annotations.get(), Storage, ShouldCreate);
1316 }
1317 LLVM_ABI static DIDerivedType *
1318 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1319 unsigned Line, Metadata *Scope, Metadata *BaseType,
1321 std::optional<unsigned> DWARFAddressSpace,
1322 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1324 bool ShouldCreate = true);
1325
1326 TempDIDerivedType cloneImpl() const {
1327 return getTemporary(
1330 getRawOffsetInBits(), getDWARFAddressSpace(), getPtrAuthData(),
1332 }
1333
1334public:
1335 DEFINE_MDNODE_GET(DIDerivedType,
1336 (unsigned Tag, MDString *Name, Metadata *File,
1337 unsigned Line, Metadata *Scope, Metadata *BaseType,
1340 std::optional<unsigned> DWARFAddressSpace,
1341 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1342 Metadata *ExtraData = nullptr,
1343 Metadata *Annotations = nullptr),
1345 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1347 DEFINE_MDNODE_GET(DIDerivedType,
1348 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1351 std::optional<unsigned> DWARFAddressSpace,
1352 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1354 DINodeArray Annotations = nullptr),
1356 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1358 DEFINE_MDNODE_GET(DIDerivedType,
1359 (unsigned Tag, MDString *Name, DIFile *File, unsigned Line,
1362 std::optional<unsigned> DWARFAddressSpace,
1363 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1364 Metadata *ExtraData = nullptr,
1365 DINodeArray Annotations = nullptr),
1367 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1369 DEFINE_MDNODE_GET(DIDerivedType,
1370 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1373 std::optional<unsigned> DWARFAddressSpace,
1374 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1375 Metadata *ExtraData = nullptr,
1376 DINodeArray Annotations = nullptr),
1378 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1380
1381 TempDIDerivedType clone() const { return cloneImpl(); }
1382
1383 /// Get the base type this is derived from.
1384 DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); }
1385 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1386
1387 /// \returns The DWARF address space of the memory pointed to or referenced by
1388 /// a pointer or reference type respectively.
1389 std::optional<unsigned> getDWARFAddressSpace() const {
1390 return DWARFAddressSpace;
1391 }
1392
1393 LLVM_ABI std::optional<PtrAuthData> getPtrAuthData() const;
1394
1395 /// Get extra data associated with this derived type.
1396 ///
1397 /// Class type for pointer-to-members, objective-c property node for ivars,
1398 /// global constant wrapper for static members, virtual base pointer offset
1399 /// for inheritance, a tuple of template parameters for template aliases,
1400 /// discriminant for a variant, or storage offset for a bit field.
1401 ///
1402 /// TODO: Separate out types that need this extra operand: pointer-to-member
1403 /// types and member fields (static members and ivars).
1405 Metadata *getRawExtraData() const { return getOperand(MY_FIRST_OPERAND + 1); }
1406
1407 /// Get the template parameters from a template alias.
1408 DITemplateParameterArray getTemplateParams() const {
1410 }
1411
1412 /// Get annotations associated with this derived type.
1413 DINodeArray getAnnotations() const {
1415 }
1417 return getOperand(MY_FIRST_OPERAND + 2);
1418 }
1419
1420 /// Get casted version of extra data.
1421 /// @{
1422 LLVM_ABI DIType *getClassType() const;
1423
1427
1429
1431
1432 LLVM_ABI Constant *getConstant() const;
1433
1435 /// @}
1436
1437 static bool classof(const Metadata *MD) {
1438 return MD->getMetadataID() == DIDerivedTypeKind;
1439 }
1440};
1441
1444 return Lhs.RawData == Rhs.RawData;
1445}
1446
1449 return !(Lhs == Rhs);
1450}
1451
1452/// Subrange type. This is somewhat similar to DISubrange, but it
1453/// is also a DIType.
1454class DISubrangeType : public DIType {
1455public:
1457
1458private:
1459 friend class LLVMContextImpl;
1460 friend class MDNode;
1461
1462 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1463
1464 DISubrangeType(LLVMContext &C, StorageType Storage, unsigned Line,
1466
1467 ~DISubrangeType() = default;
1468
1469 static DISubrangeType *
1470 getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
1474 StorageType Storage, bool ShouldCreate = true) {
1475 auto *SizeInBitsNode = ConstantAsMetadata::get(
1476 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1477 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1478 Scope, SizeInBitsNode, AlignInBits, Flags, BaseType,
1479 LowerBound, UpperBound, Stride, Bias, Storage, ShouldCreate);
1480 }
1481
1482 LLVM_ABI static DISubrangeType *
1483 getImpl(LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
1485 DIFlags Flags, Metadata *BaseType, Metadata *LowerBound,
1487 StorageType Storage, bool ShouldCreate = true);
1488
1489 TempDISubrangeType cloneImpl() const {
1494 }
1495
1496 LLVM_ABI BoundType convertRawToBound(Metadata *IN) const;
1497
1498public:
1499 DEFINE_MDNODE_GET(DISubrangeType,
1500 (MDString * Name, Metadata *File, unsigned Line,
1507 DEFINE_MDNODE_GET(DISubrangeType,
1514
1515 TempDISubrangeType clone() const { return cloneImpl(); }
1516
1517 /// Get the base type this is derived from.
1519 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1520
1522 return getOperand(MY_FIRST_OPERAND + 1).get();
1523 }
1524
1526 return getOperand(MY_FIRST_OPERAND + 2).get();
1527 }
1528
1530 return getOperand(MY_FIRST_OPERAND + 3).get();
1531 }
1532
1534 return getOperand(MY_FIRST_OPERAND + 4).get();
1535 }
1536
1538 return convertRawToBound(getRawLowerBound());
1539 }
1540
1542 return convertRawToBound(getRawUpperBound());
1543 }
1544
1545 BoundType getStride() const { return convertRawToBound(getRawStride()); }
1546
1547 BoundType getBias() const { return convertRawToBound(getRawBias()); }
1548
1549 static bool classof(const Metadata *MD) {
1550 return MD->getMetadataID() == DISubrangeTypeKind;
1551 }
1552};
1553
1554/// Composite types.
1555///
1556/// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
1557/// TODO: Create a custom, unrelated node for DW_TAG_array_type.
1558class DICompositeType : public DIType {
1559 friend class LLVMContextImpl;
1560 friend class MDNode;
1561
1562 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1563
1564 unsigned RuntimeLang;
1565 std::optional<uint32_t> EnumKind;
1566
1567 DICompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
1568 unsigned Line, unsigned RuntimeLang, uint32_t AlignInBits,
1570 std::optional<uint32_t> EnumKind, DIFlags Flags,
1572 : DIType(C, DICompositeTypeKind, Storage, Tag, Line, AlignInBits,
1574 RuntimeLang(RuntimeLang), EnumKind(EnumKind) {}
1575 ~DICompositeType() = default;
1576
1577 /// Change fields in place.
1578 void mutate(unsigned Tag, unsigned Line, unsigned RuntimeLang,
1580 std::optional<uint32_t> EnumKind, DIFlags Flags) {
1581 assert(isDistinct() && "Only distinct nodes can mutate");
1582 assert(getRawIdentifier() && "Only ODR-uniqued nodes should mutate");
1583 this->RuntimeLang = RuntimeLang;
1584 this->EnumKind = EnumKind;
1586 }
1587
1588 static DICompositeType *
1589 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
1590 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1592 uint32_t NumExtraInhabitants, DIFlags Flags, DINodeArray Elements,
1593 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1594 DIType *VTableHolder, DITemplateParameterArray TemplateParams,
1595 StringRef Identifier, DIDerivedType *Discriminator,
1597 Metadata *Rank, DINodeArray Annotations, Metadata *BitStride,
1598 StorageType Storage, bool ShouldCreate = true) {
1599 auto *SizeInBitsNode = ConstantAsMetadata::get(
1600 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1601 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1602 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1603 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1604 Line, Scope, BaseType, SizeInBitsNode, AlignInBits,
1605 OffsetInBitsNode, Flags, Elements.get(), RuntimeLang,
1607 getCanonicalMDString(Context, Identifier), Discriminator,
1610 ShouldCreate);
1611 }
1612 static DICompositeType *
1613 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1614 unsigned Line, Metadata *Scope, Metadata *BaseType,
1615 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
1616 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
1617 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1622 Metadata *BitStride, StorageType Storage, bool ShouldCreate = true) {
1623 auto *SizeInBitsNode = ConstantAsMetadata::get(
1624 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1625 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1626 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1627 return getImpl(Context, Tag, Name, File, Line, Scope, BaseType,
1628 SizeInBitsNode, AlignInBits, OffsetInBitsNode, Flags,
1629 Elements, RuntimeLang, EnumKind, VTableHolder,
1632 NumExtraInhabitants, BitStride, Storage, ShouldCreate);
1633 }
1634 static DICompositeType *
1635 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
1638 uint32_t NumExtraInhabitants, DIFlags Flags, DINodeArray Elements,
1639 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1640 DIType *VTableHolder, DITemplateParameterArray TemplateParams,
1641 StringRef Identifier, DIDerivedType *Discriminator,
1643 Metadata *Rank, DINodeArray Annotations, Metadata *BitStride,
1644 StorageType Storage, bool ShouldCreate = true) {
1645 return getImpl(
1646 Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
1648 RuntimeLang, EnumKind, VTableHolder, TemplateParams.get(),
1651 NumExtraInhabitants, BitStride, Storage, ShouldCreate);
1652 }
1653 LLVM_ABI static DICompositeType *
1654 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1655 unsigned Line, Metadata *Scope, Metadata *BaseType,
1657 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
1658 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1663 Metadata *BitStride, StorageType Storage, bool ShouldCreate = true);
1664
1665 TempDICompositeType cloneImpl() const {
1666 return getTemporary(
1674 getRawBitStride());
1675 }
1676
1677public:
1679 DICompositeType,
1680 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1683 DINodeArray Elements, unsigned RuntimeLang,
1684 std::optional<uint32_t> EnumKind, DIType *VTableHolder,
1685 DITemplateParameterArray TemplateParams = nullptr,
1687 Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
1688 Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
1689 DINodeArray Annotations = nullptr, DIType *Specification = nullptr,
1693 RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier,
1695 BitStride))
1697 DICompositeType,
1698 (unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
1701 Metadata *Elements, unsigned RuntimeLang,
1702 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1705 Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
1706 Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
1708 Metadata *BitStride = nullptr),
1710 OffsetInBits, Flags, Elements, RuntimeLang, EnumKind, VTableHolder,
1713 BitStride))
1715 DICompositeType,
1716 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1719 DINodeArray Elements, unsigned RuntimeLang,
1720 std::optional<uint32_t> EnumKind, DIType *VTableHolder,
1721 DITemplateParameterArray TemplateParams = nullptr,
1723 Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
1724 Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
1725 DINodeArray Annotations = nullptr, DIType *Specification = nullptr,
1729 RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier,
1731 BitStride))
1733 DICompositeType,
1734 (unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
1737 Metadata *Elements, unsigned RuntimeLang,
1738 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1739 Metadata *TemplateParams = nullptr, MDString *Identifier = nullptr,
1740 Metadata *Discriminator = nullptr, Metadata *DataLocation = nullptr,
1741 Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
1742 Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
1744 Metadata *BitStride = nullptr),
1746 OffsetInBits, Flags, Elements, RuntimeLang, EnumKind, VTableHolder,
1749 BitStride))
1750
1751 TempDICompositeType clone() const { return cloneImpl(); }
1752
1753 /// Get a DICompositeType with the given ODR identifier.
1754 ///
1755 /// If \a LLVMContext::isODRUniquingDebugTypes(), gets the mapped
1756 /// DICompositeType for the given ODR \c Identifier. If none exists, creates
1757 /// a new node.
1758 ///
1759 /// Else, returns \c nullptr.
1760 LLVM_ABI static DICompositeType *
1761 getODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1762 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1766 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1772 MDString &Identifier);
1773
1774 /// Build a DICompositeType with the given ODR identifier.
1775 ///
1776 /// Looks up the mapped DICompositeType for the given ODR \c Identifier. If
1777 /// it doesn't exist, creates a new one. If it does exist and \a
1778 /// isForwardDecl(), and the new arguments would be a definition, mutates the
1779 /// the type in place. In either case, returns the type.
1780 ///
1781 /// If not \a LLVMContext::isODRUniquingDebugTypes(), this function returns
1782 /// nullptr.
1783 LLVM_ABI static DICompositeType *
1784 buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1785 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1789 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1794
1796 DINodeArray getElements() const {
1798 }
1802 DITemplateParameterArray getTemplateParams() const {
1804 }
1806 return getStringOperand(MY_FIRST_OPERAND + 4);
1807 }
1808 unsigned getRuntimeLang() const { return RuntimeLang; }
1809 std::optional<uint32_t> getEnumKind() const { return EnumKind; }
1810
1811 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1812 Metadata *getRawElements() const { return getOperand(MY_FIRST_OPERAND + 1); }
1814 return getOperand(MY_FIRST_OPERAND + 2);
1815 }
1817 return getOperand(MY_FIRST_OPERAND + 3);
1818 }
1820 return getOperandAs<MDString>(MY_FIRST_OPERAND + 4);
1821 }
1823 return getOperand(MY_FIRST_OPERAND + 5);
1824 }
1826 return getOperandAs<DIDerivedType>(MY_FIRST_OPERAND + 5);
1827 }
1829 return getOperand(MY_FIRST_OPERAND + 6);
1830 }
1838 return getOperand(MY_FIRST_OPERAND + 7);
1839 }
1846 Metadata *getRawAllocated() const { return getOperand(MY_FIRST_OPERAND + 8); }
1853 Metadata *getRawRank() const { return getOperand(MY_FIRST_OPERAND + 9); }
1856 return dyn_cast_or_null<ConstantInt>(MD->getValue());
1857 return nullptr;
1858 }
1862
1864 return getOperand(MY_FIRST_OPERAND + 10);
1865 }
1866 DINodeArray getAnnotations() const {
1868 }
1869
1871 return getOperand(MY_FIRST_OPERAND + 11);
1872 }
1876
1878 return getOperand(MY_FIRST_OPERAND + 12);
1879 }
1882 return dyn_cast_or_null<ConstantInt>(MD->getValue());
1883 return nullptr;
1884 }
1885
1886 /// Replace operands.
1887 ///
1888 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
1889 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
1890 /// of its movement if necessary.
1891 /// @{
1892 void replaceElements(DINodeArray Elements) {
1893#ifndef NDEBUG
1894 for (DINode *Op : getElements())
1895 assert(is_contained(Elements->operands(), Op) &&
1896 "Lost a member during member list replacement");
1897#endif
1898 replaceOperandWith(MY_FIRST_OPERAND + 1, Elements.get());
1899 }
1900
1902 replaceOperandWith(MY_FIRST_OPERAND + 2, VTableHolder);
1903 }
1904
1905 void replaceTemplateParams(DITemplateParameterArray TemplateParams) {
1906 replaceOperandWith(MY_FIRST_OPERAND + 3, TemplateParams.get());
1907 }
1908 /// @}
1909
1910 static bool classof(const Metadata *MD) {
1911 return MD->getMetadataID() == DICompositeTypeKind;
1912 }
1913};
1914
1915/// Type array for a subprogram.
1916///
1917/// TODO: Fold the array of types in directly as operands.
1918class DISubroutineType : public DIType {
1919 friend class LLVMContextImpl;
1920 friend class MDNode;
1921
1922 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1923
1924 /// The calling convention used with DW_AT_calling_convention. Actually of
1925 /// type dwarf::CallingConvention.
1926 uint8_t CC;
1927
1928 DISubroutineType(LLVMContext &C, StorageType Storage, DIFlags Flags,
1930 ~DISubroutineType() = default;
1931
1932 static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
1935 bool ShouldCreate = true) {
1936 return getImpl(Context, Flags, CC, TypeArray.get(), Storage, ShouldCreate);
1937 }
1938 LLVM_ABI static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
1941 bool ShouldCreate = true);
1942
1943 TempDISubroutineType cloneImpl() const {
1945 }
1946
1947public:
1948 DEFINE_MDNODE_GET(DISubroutineType,
1950 (Flags, CC, TypeArray))
1951 DEFINE_MDNODE_GET(DISubroutineType,
1954
1955 TempDISubroutineType clone() const { return cloneImpl(); }
1956 // Returns a new temporary DISubroutineType with updated CC
1957 TempDISubroutineType cloneWithCC(uint8_t CC) const {
1958 auto NewTy = clone();
1959 NewTy->CC = CC;
1960 return NewTy;
1961 }
1962
1963 uint8_t getCC() const { return CC; }
1964
1968
1969 Metadata *getRawTypeArray() const { return getOperand(MY_FIRST_OPERAND); }
1970
1971 static bool classof(const Metadata *MD) {
1972 return MD->getMetadataID() == DISubroutineTypeKind;
1973 }
1974};
1975
1976/// Compile unit.
1977class DICompileUnit : public DIScope {
1978 friend class LLVMContextImpl;
1979 friend class MDNode;
1980
1981public:
1989
1997
1998 LLVM_ABI static std::optional<DebugEmissionKind>
2000 LLVM_ABI static const char *emissionKindString(DebugEmissionKind EK);
2001 LLVM_ABI static std::optional<DebugNameTableKind>
2003 LLVM_ABI static const char *nameTableKindString(DebugNameTableKind PK);
2004
2005private:
2006 unsigned SourceLanguage;
2007 unsigned RuntimeVersion;
2009 unsigned EmissionKind;
2010 unsigned NameTableKind;
2011 bool IsOptimized;
2012 bool SplitDebugInlining;
2014 bool RangesBaseAddress;
2015
2017 bool IsOptimized, unsigned RuntimeVersion,
2019 bool DebugInfoForProfiling, unsigned NameTableKind,
2021 ~DICompileUnit() = default;
2022
2023 static DICompileUnit *
2024 getImpl(LLVMContext &Context, unsigned SourceLanguage, DIFile *File,
2027 unsigned EmissionKind, DICompositeTypeArray EnumTypes,
2028 DIScopeArray RetainedTypes,
2029 DIGlobalVariableExpressionArray GlobalVariables,
2030 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
2033 StringRef SDK, StorageType Storage, bool ShouldCreate = true) {
2034 return getImpl(
2035 Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
2038 EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
2041 getCanonicalMDString(Context, SysRoot),
2042 getCanonicalMDString(Context, SDK), Storage, ShouldCreate);
2043 }
2044 LLVM_ABI static DICompileUnit *
2045 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
2046 MDString *Producer, bool IsOptimized, MDString *Flags,
2047 unsigned RuntimeVersion, MDString *SplitDebugFilename,
2051 bool DebugInfoForProfiling, unsigned NameTableKind,
2052 bool RangesBaseAddress, MDString *SysRoot, MDString *SDK,
2053 StorageType Storage, bool ShouldCreate = true);
2054
2055 TempDICompileUnit cloneImpl() const {
2056 return getTemporary(
2063 }
2064
2065public:
2066 static void get() = delete;
2067 static void getIfExists() = delete;
2068
2070 DICompileUnit,
2071 (unsigned SourceLanguage, DIFile *File, StringRef Producer,
2072 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
2074 DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes,
2075 DIGlobalVariableExpressionArray GlobalVariables,
2076 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
2077 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
2078 DebugNameTableKind NameTableKind, bool RangesBaseAddress,
2080 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
2082 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
2083 DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress,
2084 SysRoot, SDK))
2086 DICompileUnit,
2087 (unsigned SourceLanguage, Metadata *File, MDString *Producer,
2088 bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
2092 bool SplitDebugInlining, bool DebugInfoForProfiling,
2093 unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
2095 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
2097 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
2098 DebugInfoForProfiling, NameTableKind, RangesBaseAddress, SysRoot, SDK))
2099
2100 TempDICompileUnit clone() const { return cloneImpl(); }
2101
2102 unsigned getSourceLanguage() const { return SourceLanguage; }
2103 bool isOptimized() const { return IsOptimized; }
2104 unsigned getRuntimeVersion() const { return RuntimeVersion; }
2106 return (DebugEmissionKind)EmissionKind;
2107 }
2109 return EmissionKind == DebugDirectivesOnly;
2110 }
2111 bool getDebugInfoForProfiling() const { return DebugInfoForProfiling; }
2113 return (DebugNameTableKind)NameTableKind;
2114 }
2115 bool getRangesBaseAddress() const { return RangesBaseAddress; }
2117 StringRef getFlags() const { return getStringOperand(2); }
2119 DICompositeTypeArray getEnumTypes() const {
2121 }
2122 DIScopeArray getRetainedTypes() const {
2124 }
2125 DIGlobalVariableExpressionArray getGlobalVariables() const {
2127 }
2128 DIImportedEntityArray getImportedEntities() const {
2130 }
2131 DIMacroNodeArray getMacros() const {
2133 }
2134 uint64_t getDWOId() const { return DWOId; }
2135 void setDWOId(uint64_t DwoId) { DWOId = DwoId; }
2136 bool getSplitDebugInlining() const { return SplitDebugInlining; }
2137 void setSplitDebugInlining(bool SplitDebugInlining) {
2138 this->SplitDebugInlining = SplitDebugInlining;
2139 }
2141 StringRef getSDK() const { return getStringOperand(10); }
2142
2148 Metadata *getRawEnumTypes() const { return getOperand(4); }
2152 Metadata *getRawMacros() const { return getOperand(8); }
2155
2156 /// Replace arrays.
2157 ///
2158 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
2159 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
2160 /// DICompileUnit should be fairly rare.
2161 /// @{
2162 void replaceEnumTypes(DICompositeTypeArray N) {
2163 replaceOperandWith(4, N.get());
2164 }
2165 void replaceRetainedTypes(DITypeArray N) { replaceOperandWith(5, N.get()); }
2166 void replaceGlobalVariables(DIGlobalVariableExpressionArray N) {
2167 replaceOperandWith(6, N.get());
2168 }
2169 void replaceImportedEntities(DIImportedEntityArray N) {
2170 replaceOperandWith(7, N.get());
2171 }
2172 void replaceMacros(DIMacroNodeArray N) { replaceOperandWith(8, N.get()); }
2173 /// @}
2174
2175 static bool classof(const Metadata *MD) {
2176 return MD->getMetadataID() == DICompileUnitKind;
2177 }
2178};
2179
2180/// A scope for locals.
2181///
2182/// A legal scope for lexical blocks, local variables, and debug info
2183/// locations. Subclasses are \a DISubprogram, \a DILexicalBlock, and \a
2184/// DILexicalBlockFile.
2185class DILocalScope : public DIScope {
2186protected:
2190 ~DILocalScope() = default;
2191
2192public:
2193 /// Get the subprogram for this scope.
2194 ///
2195 /// Return this if it's an \a DISubprogram; otherwise, look up the scope
2196 /// chain.
2198
2199 /// Traverses the scope chain rooted at RootScope until it hits a Subprogram,
2200 /// recreating the chain with "NewSP" instead.
2201 LLVM_ABI static DILocalScope *
2203 LLVMContext &Ctx,
2205
2206 /// Get the first non DILexicalBlockFile scope of this scope.
2207 ///
2208 /// Return this if it's not a \a DILexicalBlockFIle; otherwise, look up the
2209 /// scope chain.
2211
2212 static bool classof(const Metadata *MD) {
2213 return MD->getMetadataID() == DISubprogramKind ||
2214 MD->getMetadataID() == DILexicalBlockKind ||
2215 MD->getMetadataID() == DILexicalBlockFileKind;
2216 }
2217};
2218
2219/// Subprogram description. Uses SubclassData1.
2220class DISubprogram : public DILocalScope {
2221 friend class LLVMContextImpl;
2222 friend class MDNode;
2223
2224 unsigned Line;
2225 unsigned ScopeLine;
2226 unsigned VirtualIndex;
2227
2228 /// In the MS ABI, the implicit 'this' parameter is adjusted in the prologue
2229 /// of method overrides from secondary bases by this amount. It may be
2230 /// negative.
2231 int ThisAdjustment;
2232
2233public:
2234 /// Debug info subprogram flags.
2236#define HANDLE_DISP_FLAG(ID, NAME) SPFlag##NAME = ID,
2237#define DISP_FLAG_LARGEST_NEEDED
2238#include "llvm/IR/DebugInfoFlags.def"
2239 SPFlagNonvirtual = SPFlagZero,
2240 SPFlagVirtuality = SPFlagVirtual | SPFlagPureVirtual,
2241 LLVM_MARK_AS_BITMASK_ENUM(SPFlagLargest)
2242 };
2243
2244 LLVM_ABI static DISPFlags getFlag(StringRef Flag);
2245 LLVM_ABI static StringRef getFlagString(DISPFlags Flag);
2246
2247 /// Split up a flags bitfield for easier printing.
2248 ///
2249 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
2250 /// any remaining (unrecognized) bits.
2251 LLVM_ABI static DISPFlags splitFlags(DISPFlags Flags,
2252 SmallVectorImpl<DISPFlags> &SplitFlags);
2253
2254 // Helper for converting old bitfields to new flags word.
2255 LLVM_ABI static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition,
2256 bool IsOptimized,
2257 unsigned Virtuality = SPFlagNonvirtual,
2258 bool IsMainSubprogram = false);
2259
2260private:
2261 DIFlags Flags;
2262 DISPFlags SPFlags;
2263
2264 DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
2265 unsigned ScopeLine, unsigned VirtualIndex, int ThisAdjustment,
2266 DIFlags Flags, DISPFlags SPFlags, bool UsesKeyInstructions,
2268 ~DISubprogram() = default;
2269
2270 static DISubprogram *
2271 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
2272 StringRef LinkageName, DIFile *File, unsigned Line,
2274 unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags,
2275 DISPFlags SPFlags, DICompileUnit *Unit,
2276 DITemplateParameterArray TemplateParams, DISubprogram *Declaration,
2277 DINodeArray RetainedNodes, DITypeArray ThrownTypes,
2280 bool ShouldCreate = true) {
2281 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
2282 getCanonicalMDString(Context, LinkageName), File, Line, Type,
2284 Flags, SPFlags, Unit, TemplateParams.get(), Declaration,
2285 RetainedNodes.get(), ThrownTypes.get(), Annotations.get(),
2287 UsesKeyInstructions, Storage, ShouldCreate);
2288 }
2289
2290 LLVM_ABI static DISubprogram *
2291 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
2292 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
2293 unsigned ScopeLine, Metadata *ContainingType, unsigned VirtualIndex,
2294 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
2297 MDString *TargetFuncName, bool UsesKeyInstructions,
2298 StorageType Storage, bool ShouldCreate = true);
2299
2300 TempDISubprogram cloneImpl() const {
2302 getFile(), getLine(), getType(), getScopeLine(),
2303 getContainingType(), getVirtualIndex(),
2304 getThisAdjustment(), getFlags(), getSPFlags(),
2305 getUnit(), getTemplateParams(), getDeclaration(),
2306 getRetainedNodes(), getThrownTypes(), getAnnotations(),
2307 getTargetFuncName(), getKeyInstructionsEnabled());
2308 }
2309
2310public:
2312 DISubprogram,
2314 unsigned Line, DISubroutineType *Type, unsigned ScopeLine,
2315 DIType *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
2316 DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit,
2317 DITemplateParameterArray TemplateParams = nullptr,
2318 DISubprogram *Declaration = nullptr, DINodeArray RetainedNodes = nullptr,
2319 DITypeArray ThrownTypes = nullptr, DINodeArray Annotations = nullptr,
2320 StringRef TargetFuncName = "", bool UsesKeyInstructions = false),
2321 (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
2322 VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
2325
2327 DISubprogram,
2329 unsigned Line, Metadata *Type, unsigned ScopeLine,
2330 Metadata *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
2331 DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
2335 bool UsesKeyInstructions = false),
2336 (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
2337 VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
2340
2341 TempDISubprogram clone() const { return cloneImpl(); }
2342
2343 /// Returns a new temporary DISubprogram with updated Flags
2344 TempDISubprogram cloneWithFlags(DIFlags NewFlags) const {
2345 auto NewSP = clone();
2346 NewSP->Flags = NewFlags;
2347 return NewSP;
2348 }
2349
2350 bool getKeyInstructionsEnabled() const { return SubclassData1; }
2351
2352public:
2353 unsigned getLine() const { return Line; }
2354 unsigned getVirtuality() const { return getSPFlags() & SPFlagVirtuality; }
2355 unsigned getVirtualIndex() const { return VirtualIndex; }
2356 int getThisAdjustment() const { return ThisAdjustment; }
2357 unsigned getScopeLine() const { return ScopeLine; }
2358 void setScopeLine(unsigned L) {
2359 assert(isDistinct());
2360 ScopeLine = L;
2361 }
2362 DIFlags getFlags() const { return Flags; }
2363 DISPFlags getSPFlags() const { return SPFlags; }
2364 bool isLocalToUnit() const { return getSPFlags() & SPFlagLocalToUnit; }
2365 bool isDefinition() const { return getSPFlags() & SPFlagDefinition; }
2366 bool isOptimized() const { return getSPFlags() & SPFlagOptimized; }
2367 bool isMainSubprogram() const { return getSPFlags() & SPFlagMainSubprogram; }
2368
2369 bool isArtificial() const { return getFlags() & FlagArtificial; }
2370 bool isPrivate() const {
2371 return (getFlags() & FlagAccessibility) == FlagPrivate;
2372 }
2373 bool isProtected() const {
2374 return (getFlags() & FlagAccessibility) == FlagProtected;
2375 }
2376 bool isPublic() const {
2377 return (getFlags() & FlagAccessibility) == FlagPublic;
2378 }
2379 bool isExplicit() const { return getFlags() & FlagExplicit; }
2380 bool isPrototyped() const { return getFlags() & FlagPrototyped; }
2381 bool areAllCallsDescribed() const {
2382 return getFlags() & FlagAllCallsDescribed;
2383 }
2384 bool isPure() const { return getSPFlags() & SPFlagPure; }
2385 bool isElemental() const { return getSPFlags() & SPFlagElemental; }
2386 bool isRecursive() const { return getSPFlags() & SPFlagRecursive; }
2387 bool isObjCDirect() const { return getSPFlags() & SPFlagObjCDirect; }
2388
2389 /// Check if this is deleted member function.
2390 ///
2391 /// Return true if this subprogram is a C++11 special
2392 /// member function declared deleted.
2393 bool isDeleted() const { return getSPFlags() & SPFlagDeleted; }
2394
2395 /// Check if this is reference-qualified.
2396 ///
2397 /// Return true if this subprogram is a C++11 reference-qualified non-static
2398 /// member function (void foo() &).
2399 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
2400
2401 /// Check if this is rvalue-reference-qualified.
2402 ///
2403 /// Return true if this subprogram is a C++11 rvalue-reference-qualified
2404 /// non-static member function (void foo() &&).
2405 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
2406
2407 /// Check if this is marked as noreturn.
2408 ///
2409 /// Return true if this subprogram is C++11 noreturn or C11 _Noreturn
2410 bool isNoReturn() const { return getFlags() & FlagNoReturn; }
2411
2412 // Check if this routine is a compiler-generated thunk.
2413 //
2414 // Returns true if this subprogram is a thunk generated by the compiler.
2415 bool isThunk() const { return getFlags() & FlagThunk; }
2416
2417 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2418
2419 StringRef getName() const { return getStringOperand(2); }
2420 StringRef getLinkageName() const { return getStringOperand(3); }
2421 /// Only used by clients of CloneFunction, and only right after the cloning.
2422 void replaceLinkageName(MDString *LN) { replaceOperandWith(3, LN); }
2423
2424 DISubroutineType *getType() const {
2425 return cast_or_null<DISubroutineType>(getRawType());
2426 }
2427 DIType *getContainingType() const {
2428 return cast_or_null<DIType>(getRawContainingType());
2429 }
2430 void replaceType(DISubroutineType *Ty) {
2431 assert(isDistinct() && "Only distinct nodes can mutate");
2432 replaceOperandWith(4, Ty);
2433 }
2434
2435 DICompileUnit *getUnit() const {
2436 return cast_or_null<DICompileUnit>(getRawUnit());
2437 }
2438 void replaceUnit(DICompileUnit *CU) { replaceOperandWith(5, CU); }
2439 DITemplateParameterArray getTemplateParams() const {
2440 return cast_or_null<MDTuple>(getRawTemplateParams());
2441 }
2442 DISubprogram *getDeclaration() const {
2443 return cast_or_null<DISubprogram>(getRawDeclaration());
2444 }
2445 void replaceDeclaration(DISubprogram *Decl) { replaceOperandWith(6, Decl); }
2446 DINodeArray getRetainedNodes() const {
2447 return cast_or_null<MDTuple>(getRawRetainedNodes());
2448 }
2449 DITypeArray getThrownTypes() const {
2450 return cast_or_null<MDTuple>(getRawThrownTypes());
2451 }
2452 DINodeArray getAnnotations() const {
2453 return cast_or_null<MDTuple>(getRawAnnotations());
2454 }
2455 StringRef getTargetFuncName() const {
2456 return (getRawTargetFuncName()) ? getStringOperand(12) : StringRef();
2457 }
2458
2459 Metadata *getRawScope() const { return getOperand(1); }
2460 MDString *getRawName() const { return getOperandAs<MDString>(2); }
2461 MDString *getRawLinkageName() const { return getOperandAs<MDString>(3); }
2462 Metadata *getRawType() const { return getOperand(4); }
2463 Metadata *getRawUnit() const { return getOperand(5); }
2464 Metadata *getRawDeclaration() const { return getOperand(6); }
2465 Metadata *getRawRetainedNodes() const { return getOperand(7); }
2466 Metadata *getRawContainingType() const {
2467 return getNumOperands() > 8 ? getOperandAs<Metadata>(8) : nullptr;
2468 }
2469 Metadata *getRawTemplateParams() const {
2470 return getNumOperands() > 9 ? getOperandAs<Metadata>(9) : nullptr;
2471 }
2472 Metadata *getRawThrownTypes() const {
2473 return getNumOperands() > 10 ? getOperandAs<Metadata>(10) : nullptr;
2474 }
2475 Metadata *getRawAnnotations() const {
2476 return getNumOperands() > 11 ? getOperandAs<Metadata>(11) : nullptr;
2477 }
2478 MDString *getRawTargetFuncName() const {
2479 return getNumOperands() > 12 ? getOperandAs<MDString>(12) : nullptr;
2480 }
2481
2482 void replaceRawLinkageName(MDString *LinkageName) {
2484 }
2485 void replaceRetainedNodes(DINodeArray N) {
2486 replaceOperandWith(7, N.get());
2487 }
2488
2489 /// Check if this subprogram describes the given function.
2490 ///
2491 /// FIXME: Should this be looking through bitcasts?
2492 LLVM_ABI bool describes(const Function *F) const;
2493
2494 static bool classof(const Metadata *MD) {
2495 return MD->getMetadataID() == DISubprogramKind;
2496 }
2497};
2498
2499/// Debug location.
2500///
2501/// A debug location in source code, used for debug info and otherwise.
2502///
2503/// Uses the SubclassData1, SubclassData16 and SubclassData32
2504/// Metadata slots.
2505
2506class DILocation : public MDNode {
2507 friend class LLVMContextImpl;
2508 friend class MDNode;
2509 uint64_t AtomGroup : 61;
2510 uint64_t AtomRank : 3;
2511
2512 DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
2513 unsigned Column, uint64_t AtomGroup, uint8_t AtomRank,
2515 ~DILocation() { dropAllReferences(); }
2516
2517 LLVM_ABI static DILocation *
2518 getImpl(LLVMContext &Context, unsigned Line, unsigned Column, Metadata *Scope,
2520 uint8_t AtomRank, StorageType Storage, bool ShouldCreate = true);
2521 static DILocation *getImpl(LLVMContext &Context, unsigned Line,
2522 unsigned Column, DILocalScope *Scope,
2525 StorageType Storage, bool ShouldCreate = true) {
2526 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
2527 static_cast<Metadata *>(InlinedAt), ImplicitCode, AtomGroup,
2528 AtomRank, Storage, ShouldCreate);
2529 }
2530
2531 TempDILocation cloneImpl() const {
2532 // Get the raw scope/inlinedAt since it is possible to invoke this on
2533 // a DILocation containing temporary metadata.
2534 return getTemporary(getContext(), getLine(), getColumn(), getRawScope(),
2535 getRawInlinedAt(), isImplicitCode(), getAtomGroup(),
2536 getAtomRank());
2537 }
2538
2539public:
2540 uint64_t getAtomGroup() const { return AtomGroup; }
2541 uint8_t getAtomRank() const { return AtomRank; }
2542
2543 const DILocation *getWithoutAtom() const {
2544 if (!getAtomGroup() && !getAtomRank())
2545 return this;
2546 return get(getContext(), getLine(), getColumn(), getScope(), getInlinedAt(),
2547 isImplicitCode());
2548 }
2549
2550 // Disallow replacing operands.
2551 void replaceOperandWith(unsigned I, Metadata *New) = delete;
2552
2554 (unsigned Line, unsigned Column, Metadata *Scope,
2555 Metadata *InlinedAt = nullptr, bool ImplicitCode = false,
2556 uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2557 (Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2558 AtomRank))
2559 DEFINE_MDNODE_GET(DILocation,
2560 (unsigned Line, unsigned Column, DILocalScope *Scope,
2561 DILocation *InlinedAt = nullptr, bool ImplicitCode = false,
2562 uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2563 (Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2564 AtomRank))
2565
2566 /// Return a (temporary) clone of this.
2567 TempDILocation clone() const { return cloneImpl(); }
2568
2569 unsigned getLine() const { return SubclassData32; }
2570 unsigned getColumn() const { return SubclassData16; }
2571 DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
2572
2573 /// Return the linkage name of Subprogram. If the linkage name is empty,
2574 /// return scope name (the demangled name).
2575 StringRef getSubprogramLinkageName() const {
2576 DISubprogram *SP = getScope()->getSubprogram();
2577 if (!SP)
2578 return "";
2579 auto Name = SP->getLinkageName();
2580 if (!Name.empty())
2581 return Name;
2582 return SP->getName();
2583 }
2584
2585 DILocation *getInlinedAt() const {
2587 }
2588
2589 /// Check if the location corresponds to an implicit code.
2590 /// When the ImplicitCode flag is true, it means that the Instruction
2591 /// with this DILocation has been added by the front-end but it hasn't been
2592 /// written explicitly by the user (e.g. cleanup stuff in C++ put on a closing
2593 /// bracket). It's useful for code coverage to not show a counter on "empty"
2594 /// lines.
2595 bool isImplicitCode() const { return SubclassData1; }
2596 void setImplicitCode(bool ImplicitCode) { SubclassData1 = ImplicitCode; }
2597
2598 DIFile *getFile() const { return getScope()->getFile(); }
2599 StringRef getFilename() const { return getScope()->getFilename(); }
2600 StringRef getDirectory() const { return getScope()->getDirectory(); }
2601 std::optional<StringRef> getSource() const { return getScope()->getSource(); }
2602
2603 /// Walk through \a getInlinedAt() and return the \a DILocation of the
2604 /// outermost call site in the inlining chain.
2605 const DILocation *getInlinedAtLocation() const {
2606 const DILocation *Current = this;
2607 while (const DILocation *Next = Current->getInlinedAt())
2608 Current = Next;
2609 return Current;
2610 }
2611
2612 // Return the \a DILocalScope of the outermost call site in the inlining
2613 // chain.
2614 DILocalScope *getInlinedAtScope() const {
2615 return getInlinedAtLocation()->getScope();
2616 }
2617
2618 /// Get the DWARF discriminator.
2619 ///
2620 /// DWARF discriminators distinguish identical file locations between
2621 /// instructions that are on different basic blocks.
2622 ///
2623 /// There are 3 components stored in discriminator, from lower bits:
2624 ///
2625 /// Base discriminator: assigned by AddDiscriminators pass to identify IRs
2626 /// that are defined by the same source line, but
2627 /// different basic blocks.
2628 /// Duplication factor: assigned by optimizations that will scale down
2629 /// the execution frequency of the original IR.
2630 /// Copy Identifier: assigned by optimizations that clones the IR.
2631 /// Each copy of the IR will be assigned an identifier.
2632 ///
2633 /// Encoding:
2634 ///
2635 /// The above 3 components are encoded into a 32bit unsigned integer in
2636 /// order. If the lowest bit is 1, the current component is empty, and the
2637 /// next component will start in the next bit. Otherwise, the current
2638 /// component is non-empty, and its content starts in the next bit. The
2639 /// value of each components is either 5 bit or 12 bit: if the 7th bit
2640 /// is 0, the bit 2~6 (5 bits) are used to represent the component; if the
2641 /// 7th bit is 1, the bit 2~6 (5 bits) and 8~14 (7 bits) are combined to
2642 /// represent the component. Thus, the number of bits used for a component
2643 /// is either 0 (if it and all the next components are empty); 1 - if it is
2644 /// empty; 7 - if its value is up to and including 0x1f (lsb and msb are both
2645 /// 0); or 14, if its value is up to and including 0x1ff. Note that the last
2646 /// component is also capped at 0x1ff, even in the case when both first
2647 /// components are 0, and we'd technically have 29 bits available.
2648 ///
2649 /// For precise control over the data being encoded in the discriminator,
2650 /// use encodeDiscriminator/decodeDiscriminator.
2651
2652 inline unsigned getDiscriminator() const;
2653
2654 // For the regular discriminator, it stands for all empty components if all
2655 // the lowest 3 bits are non-zero and all higher 29 bits are unused(zero by
2656 // default). Here we fully leverage the higher 29 bits for pseudo probe use.
2657 // This is the format:
2658 // [2:0] - 0x7
2659 // [31:3] - pseudo probe fields guaranteed to be non-zero as a whole
2660 // So if the lower 3 bits is non-zero and the others has at least one
2661 // non-zero bit, it guarantees to be a pseudo probe discriminator
2662 inline static bool isPseudoProbeDiscriminator(unsigned Discriminator) {
2663 return ((Discriminator & 0x7) == 0x7) && (Discriminator & 0xFFFFFFF8);
2664 }
2665
2666 /// Returns a new DILocation with updated \p Discriminator.
2667 inline const DILocation *cloneWithDiscriminator(unsigned Discriminator) const;
2668
2669 /// Returns a new DILocation with updated base discriminator \p BD. Only the
2670 /// base discriminator is set in the new DILocation, the other encoded values
2671 /// are elided.
2672 /// If the discriminator cannot be encoded, the function returns std::nullopt.
2673 inline std::optional<const DILocation *>
2674 cloneWithBaseDiscriminator(unsigned BD) const;
2675
2676 /// Returns the duplication factor stored in the discriminator, or 1 if no
2677 /// duplication factor (or 0) is encoded.
2678 inline unsigned getDuplicationFactor() const;
2679
2680 /// Returns the copy identifier stored in the discriminator.
2681 inline unsigned getCopyIdentifier() const;
2682
2683 /// Returns the base discriminator stored in the discriminator.
2684 inline unsigned getBaseDiscriminator() const;
2685
2686 /// Returns a new DILocation with duplication factor \p DF * current
2687 /// duplication factor encoded in the discriminator. The current duplication
2688 /// factor is as defined by getDuplicationFactor().
2689 /// Returns std::nullopt if encoding failed.
2690 inline std::optional<const DILocation *>
2692
2693 /// Attempts to merge \p LocA and \p LocB into a single location; see
2694 /// DebugLoc::getMergedLocation for more details.
2695 /// NB: When merging the locations of instructions, prefer to use
2696 /// DebugLoc::getMergedLocation(), as an instruction's DebugLoc may contain
2697 /// additional metadata that will not be preserved when merging the unwrapped
2698 /// DILocations.
2700 DILocation *LocB);
2701
2702 /// Try to combine the vector of locations passed as input in a single one.
2703 /// This function applies getMergedLocation() repeatedly left-to-right.
2704 /// NB: When merging the locations of instructions, prefer to use
2705 /// DebugLoc::getMergedLocations(), as an instruction's DebugLoc may contain
2706 /// additional metadata that will not be preserved when merging the unwrapped
2707 /// DILocations.
2708 ///
2709 /// \p Locs: The locations to be merged.
2711
2712 /// Return the masked discriminator value for an input discrimnator value D
2713 /// (i.e. zero out the (B+1)-th and above bits for D (B is 0-base).
2714 // Example: an input of (0x1FF, 7) returns 0xFF.
2715 static unsigned getMaskedDiscriminator(unsigned D, unsigned B) {
2716 return (D & getN1Bits(B));
2717 }
2718
2719 /// Return the bits used for base discriminators.
2720 static unsigned getBaseDiscriminatorBits() { return getBaseFSBitEnd(); }
2721
2722 /// Returns the base discriminator for a given encoded discriminator \p D.
2723 static unsigned
2725 bool IsFSDiscriminator = false) {
2726 // Extract the dwarf base discriminator if it's encoded in the pseudo probe
2727 // discriminator.
2729 auto DwarfBaseDiscriminator =
2731 if (DwarfBaseDiscriminator)
2732 return *DwarfBaseDiscriminator;
2733 // Return the probe id instead of zero for a pseudo probe discriminator.
2734 // This should help differenciate callsites with same line numbers to
2735 // achieve a decent AutoFDO profile under -fpseudo-probe-for-profiling,
2736 // where the original callsite dwarf discriminator is overwritten by
2737 // callsite probe information.
2739 }
2740
2741 if (IsFSDiscriminator)
2744 }
2745
2746 /// Raw encoding of the discriminator. APIs such as cloneWithDuplicationFactor
2747 /// have certain special case behavior (e.g. treating empty duplication factor
2748 /// as the value '1').
2749 /// This API, in conjunction with cloneWithDiscriminator, may be used to
2750 /// encode the raw values provided.
2751 ///
2752 /// \p BD: base discriminator
2753 /// \p DF: duplication factor
2754 /// \p CI: copy index
2755 ///
2756 /// The return is std::nullopt if the values cannot be encoded in 32 bits -
2757 /// for example, values for BD or DF larger than 12 bits. Otherwise, the
2758 /// return is the encoded value.
2759 LLVM_ABI static std::optional<unsigned>
2760 encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI);
2761
2762 /// Raw decoder for values in an encoded discriminator D.
2763 LLVM_ABI static void decodeDiscriminator(unsigned D, unsigned &BD,
2764 unsigned &DF, unsigned &CI);
2765
2766 /// Returns the duplication factor for a given encoded discriminator \p D, or
2767 /// 1 if no value or 0 is encoded.
2768 static unsigned getDuplicationFactorFromDiscriminator(unsigned D) {
2770 return 1;
2772 unsigned Ret = getUnsignedFromPrefixEncoding(D);
2773 if (Ret == 0)
2774 return 1;
2775 return Ret;
2776 }
2777
2778 /// Returns the copy identifier for a given encoded discriminator \p D.
2783
2784 Metadata *getRawScope() const { return getOperand(0); }
2786 if (getNumOperands() == 2)
2787 return getOperand(1);
2788 return nullptr;
2789 }
2790
2791 static bool classof(const Metadata *MD) {
2792 return MD->getMetadataID() == DILocationKind;
2793 }
2794};
2795
2797protected:
2801
2802public:
2804
2805 Metadata *getRawScope() const { return getOperand(1); }
2806
2807 void replaceScope(DIScope *Scope) {
2808 assert(!isUniqued());
2809 setOperand(1, Scope);
2810 }
2811
2812 static bool classof(const Metadata *MD) {
2813 return MD->getMetadataID() == DILexicalBlockKind ||
2814 MD->getMetadataID() == DILexicalBlockFileKind;
2815 }
2816};
2817
2818/// Debug lexical block.
2819///
2820/// Uses the SubclassData32 Metadata slot.
2821class DILexicalBlock : public DILexicalBlockBase {
2822 friend class LLVMContextImpl;
2823 friend class MDNode;
2824
2825 uint16_t Column;
2826
2827 DILexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
2828 unsigned Column, ArrayRef<Metadata *> Ops)
2829 : DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops),
2830 Column(Column) {
2832 assert(Column < (1u << 16) && "Expected 16-bit column");
2833 }
2834 ~DILexicalBlock() = default;
2835
2836 static DILexicalBlock *getImpl(LLVMContext &Context, DILocalScope *Scope,
2837 DIFile *File, unsigned Line, unsigned Column,
2839 bool ShouldCreate = true) {
2840 return getImpl(Context, static_cast<Metadata *>(Scope),
2841 static_cast<Metadata *>(File), Line, Column, Storage,
2842 ShouldCreate);
2843 }
2844
2845 LLVM_ABI static DILexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
2846 Metadata *File, unsigned Line,
2847 unsigned Column, StorageType Storage,
2848 bool ShouldCreate = true);
2849
2850 TempDILexicalBlock cloneImpl() const {
2852 getColumn());
2853 }
2854
2855public:
2856 DEFINE_MDNODE_GET(DILexicalBlock,
2857 (DILocalScope * Scope, DIFile *File, unsigned Line,
2858 unsigned Column),
2859 (Scope, File, Line, Column))
2860 DEFINE_MDNODE_GET(DILexicalBlock,
2862 unsigned Column),
2863 (Scope, File, Line, Column))
2864
2865 TempDILexicalBlock clone() const { return cloneImpl(); }
2866
2867 unsigned getLine() const { return SubclassData32; }
2868 unsigned getColumn() const { return Column; }
2869
2870 static bool classof(const Metadata *MD) {
2871 return MD->getMetadataID() == DILexicalBlockKind;
2872 }
2873};
2874
2875class DILexicalBlockFile : public DILexicalBlockBase {
2876 friend class LLVMContextImpl;
2877 friend class MDNode;
2878
2879 DILexicalBlockFile(LLVMContext &C, StorageType Storage,
2881 : DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops) {
2883 }
2884 ~DILexicalBlockFile() = default;
2885
2886 static DILexicalBlockFile *getImpl(LLVMContext &Context, DILocalScope *Scope,
2887 DIFile *File, unsigned Discriminator,
2889 bool ShouldCreate = true) {
2890 return getImpl(Context, static_cast<Metadata *>(Scope),
2891 static_cast<Metadata *>(File), Discriminator, Storage,
2892 ShouldCreate);
2893 }
2894
2895 LLVM_ABI static DILexicalBlockFile *getImpl(LLVMContext &Context,
2896 Metadata *Scope, Metadata *File,
2897 unsigned Discriminator,
2899 bool ShouldCreate = true);
2900
2901 TempDILexicalBlockFile cloneImpl() const {
2902 return getTemporary(getContext(), getScope(), getFile(),
2904 }
2905
2906public:
2907 DEFINE_MDNODE_GET(DILexicalBlockFile,
2909 unsigned Discriminator),
2911 DEFINE_MDNODE_GET(DILexicalBlockFile,
2914
2915 TempDILexicalBlockFile clone() const { return cloneImpl(); }
2916 unsigned getDiscriminator() const { return SubclassData32; }
2917
2918 static bool classof(const Metadata *MD) {
2919 return MD->getMetadataID() == DILexicalBlockFileKind;
2920 }
2921};
2922
2923unsigned DILocation::getDiscriminator() const {
2924 if (auto *F = dyn_cast<DILexicalBlockFile>(getScope()))
2925 return F->getDiscriminator();
2926 return 0;
2927}
2928
2929const DILocation *
2930DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
2931 DIScope *Scope = getScope();
2932 // Skip all parent DILexicalBlockFile that already have a discriminator
2933 // assigned. We do not want to have nested DILexicalBlockFiles that have
2934 // multiple discriminators because only the leaf DILexicalBlockFile's
2935 // dominator will be used.
2936 for (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope);
2937 LBF && LBF->getDiscriminator() != 0;
2939 Scope = LBF->getScope();
2940 DILexicalBlockFile *NewScope =
2941 DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator);
2942 return DILocation::get(getContext(), getLine(), getColumn(), NewScope,
2943 getInlinedAt(), isImplicitCode(), getAtomGroup(),
2944 getAtomRank());
2945}
2946
2948 return getBaseDiscriminatorFromDiscriminator(getDiscriminator(),
2950}
2951
2953 return getDuplicationFactorFromDiscriminator(getDiscriminator());
2954}
2955
2957 return getCopyIdentifierFromDiscriminator(getDiscriminator());
2958}
2959
2960std::optional<const DILocation *>
2962 unsigned BD, DF, CI;
2963
2965 BD = getBaseDiscriminator();
2966 if (D == BD)
2967 return this;
2968 return cloneWithDiscriminator(D);
2969 }
2970
2971 decodeDiscriminator(getDiscriminator(), BD, DF, CI);
2972 if (D == BD)
2973 return this;
2974 if (std::optional<unsigned> Encoded = encodeDiscriminator(D, DF, CI))
2975 return cloneWithDiscriminator(*Encoded);
2976 return std::nullopt;
2977}
2978
2979std::optional<const DILocation *>
2981 assert(!EnableFSDiscriminator && "FSDiscriminator should not call this.");
2982 // Do no interfere with pseudo probes. Pseudo probe doesn't need duplication
2983 // factor support as samples collected on cloned probes will be aggregated.
2984 // Also pseudo probe at a callsite uses the dwarf discriminator to store
2985 // pseudo probe related information, such as the probe id.
2986 if (isPseudoProbeDiscriminator(getDiscriminator()))
2987 return this;
2988
2990 if (DF <= 1)
2991 return this;
2992
2993 unsigned BD = getBaseDiscriminator();
2994 unsigned CI = getCopyIdentifier();
2995 if (std::optional<unsigned> D = encodeDiscriminator(BD, DF, CI))
2996 return cloneWithDiscriminator(*D);
2997 return std::nullopt;
2998}
2999
3000/// Debug lexical block.
3001///
3002/// Uses the SubclassData1 Metadata slot.
3003class DINamespace : public DIScope {
3004 friend class LLVMContextImpl;
3005 friend class MDNode;
3006
3007 DINamespace(LLVMContext &Context, StorageType Storage, bool ExportSymbols,
3009 ~DINamespace() = default;
3010
3011 static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope,
3013 StorageType Storage, bool ShouldCreate = true) {
3014 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
3015 ExportSymbols, Storage, ShouldCreate);
3016 }
3017 LLVM_ABI static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope,
3020 bool ShouldCreate = true);
3021
3022 TempDINamespace cloneImpl() const {
3023 return getTemporary(getContext(), getScope(), getName(),
3025 }
3026
3027public:
3031 DEFINE_MDNODE_GET(DINamespace,
3034
3035 TempDINamespace clone() const { return cloneImpl(); }
3036
3037 bool getExportSymbols() const { return SubclassData1; }
3039 StringRef getName() const { return getStringOperand(2); }
3040
3041 Metadata *getRawScope() const { return getOperand(1); }
3043
3044 static bool classof(const Metadata *MD) {
3045 return MD->getMetadataID() == DINamespaceKind;
3046 }
3047};
3048
3049/// Represents a module in the programming language, for example, a Clang
3050/// module, or a Fortran module.
3051///
3052/// Uses the SubclassData1 and SubclassData32 Metadata slots.
3053class DIModule : public DIScope {
3054 friend class LLVMContextImpl;
3055 friend class MDNode;
3056
3057 DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo,
3058 bool IsDecl, ArrayRef<Metadata *> Ops);
3059 ~DIModule() = default;
3060
3061 static DIModule *getImpl(LLVMContext &Context, DIFile *File, DIScope *Scope,
3064 unsigned LineNo, bool IsDecl, StorageType Storage,
3065 bool ShouldCreate = true) {
3066 return getImpl(Context, File, Scope, getCanonicalMDString(Context, Name),
3069 getCanonicalMDString(Context, APINotesFile), LineNo, IsDecl,
3070 Storage, ShouldCreate);
3071 }
3072 LLVM_ABI static DIModule *
3073 getImpl(LLVMContext &Context, Metadata *File, Metadata *Scope, MDString *Name,
3075 MDString *APINotesFile, unsigned LineNo, bool IsDecl,
3076 StorageType Storage, bool ShouldCreate = true);
3077
3078 TempDIModule cloneImpl() const {
3080 getConfigurationMacros(), getIncludePath(),
3081 getAPINotesFile(), getLineNo(), getIsDecl());
3082 }
3083
3084public:
3088 StringRef APINotesFile, unsigned LineNo,
3089 bool IsDecl = false),
3091 APINotesFile, LineNo, IsDecl))
3092 DEFINE_MDNODE_GET(DIModule,
3096 bool IsDecl = false),
3098 APINotesFile, LineNo, IsDecl))
3099
3100 TempDIModule clone() const { return cloneImpl(); }
3101
3102 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
3103 StringRef getName() const { return getStringOperand(2); }
3104 StringRef getConfigurationMacros() const { return getStringOperand(3); }
3105 StringRef getIncludePath() const { return getStringOperand(4); }
3106 StringRef getAPINotesFile() const { return getStringOperand(5); }
3107 unsigned getLineNo() const { return SubclassData32; }
3108 bool getIsDecl() const { return SubclassData1; }
3109
3110 Metadata *getRawScope() const { return getOperand(1); }
3111 MDString *getRawName() const { return getOperandAs<MDString>(2); }
3112 MDString *getRawConfigurationMacros() const {
3113 return getOperandAs<MDString>(3);
3114 }
3115 MDString *getRawIncludePath() const { return getOperandAs<MDString>(4); }
3116 MDString *getRawAPINotesFile() const { return getOperandAs<MDString>(5); }
3117
3118 static bool classof(const Metadata *MD) {
3119 return MD->getMetadataID() == DIModuleKind;
3120 }
3121};
3122
3123/// Base class for template parameters.
3124///
3125/// Uses the SubclassData1 Metadata slot.
3127protected:
3129 unsigned Tag, bool IsDefault, ArrayRef<Metadata *> Ops)
3130 : DINode(Context, ID, Storage, Tag, Ops) {
3131 SubclassData1 = IsDefault;
3132 }
3134
3135public:
3136 StringRef getName() const { return getStringOperand(0); }
3138
3140 Metadata *getRawType() const { return getOperand(1); }
3141 bool isDefault() const { return SubclassData1; }
3142
3143 static bool classof(const Metadata *MD) {
3144 return MD->getMetadataID() == DITemplateTypeParameterKind ||
3145 MD->getMetadataID() == DITemplateValueParameterKind;
3146 }
3147};
3148
3149class DITemplateTypeParameter : public DITemplateParameter {
3150 friend class LLVMContextImpl;
3151 friend class MDNode;
3152
3153 DITemplateTypeParameter(LLVMContext &Context, StorageType Storage,
3155 ~DITemplateTypeParameter() = default;
3156
3157 static DITemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
3158 DIType *Type, bool IsDefault,
3160 bool ShouldCreate = true) {
3161 return getImpl(Context, getCanonicalMDString(Context, Name), Type,
3162 IsDefault, Storage, ShouldCreate);
3163 }
3165 getImpl(LLVMContext &Context, MDString *Name, Metadata *Type, bool IsDefault,
3166 StorageType Storage, bool ShouldCreate = true);
3167
3168 TempDITemplateTypeParameter cloneImpl() const {
3169 return getTemporary(getContext(), getName(), getType(), isDefault());
3170 }
3171
3172public:
3173 DEFINE_MDNODE_GET(DITemplateTypeParameter,
3175 (Name, Type, IsDefault))
3176 DEFINE_MDNODE_GET(DITemplateTypeParameter,
3179
3180 TempDITemplateTypeParameter clone() const { return cloneImpl(); }
3181
3182 static bool classof(const Metadata *MD) {
3183 return MD->getMetadataID() == DITemplateTypeParameterKind;
3184 }
3185};
3186
3187class DITemplateValueParameter : public DITemplateParameter {
3188 friend class LLVMContextImpl;
3189 friend class MDNode;
3190
3191 DITemplateValueParameter(LLVMContext &Context, StorageType Storage,
3192 unsigned Tag, bool IsDefault,
3194 : DITemplateParameter(Context, DITemplateValueParameterKind, Storage, Tag,
3195 IsDefault, Ops) {}
3196 ~DITemplateValueParameter() = default;
3197
3198 static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
3200 bool IsDefault, Metadata *Value,
3202 bool ShouldCreate = true) {
3203 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
3204 IsDefault, Value, Storage, ShouldCreate);
3205 }
3206 LLVM_ABI static DITemplateValueParameter *
3207 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
3208 bool IsDefault, Metadata *Value, StorageType Storage,
3209 bool ShouldCreate = true);
3210
3211 TempDITemplateValueParameter cloneImpl() const {
3212 return getTemporary(getContext(), getTag(), getName(), getType(),
3213 isDefault(), getValue());
3214 }
3215
3216public:
3217 DEFINE_MDNODE_GET(DITemplateValueParameter,
3218 (unsigned Tag, StringRef Name, DIType *Type, bool IsDefault,
3219 Metadata *Value),
3220 (Tag, Name, Type, IsDefault, Value))
3221 DEFINE_MDNODE_GET(DITemplateValueParameter,
3225
3226 TempDITemplateValueParameter clone() const { return cloneImpl(); }
3227
3228 Metadata *getValue() const { return getOperand(2); }
3229
3230 static bool classof(const Metadata *MD) {
3231 return MD->getMetadataID() == DITemplateValueParameterKind;
3232 }
3233};
3234
3235/// Base class for variables.
3236///
3237/// Uses the SubclassData32 Metadata slot.
3238class DIVariable : public DINode {
3239 unsigned Line;
3240
3241protected:
3243 signed Line, ArrayRef<Metadata *> Ops,
3244 uint32_t AlignInBits = 0);
3245 ~DIVariable() = default;
3246
3247public:
3248 unsigned getLine() const { return Line; }
3250 StringRef getName() const { return getStringOperand(1); }
3254 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
3255 /// Determines the size of the variable's type.
3256 LLVM_ABI std::optional<uint64_t> getSizeInBits() const;
3257
3258 /// Return the signedness of this variable's type, or std::nullopt if this
3259 /// type is neither signed nor unsigned.
3260 std::optional<DIBasicType::Signedness> getSignedness() const {
3261 if (auto *BT = dyn_cast<DIBasicType>(getType()))
3262 return BT->getSignedness();
3263 return std::nullopt;
3264 }
3265
3267 if (auto *F = getFile())
3268 return F->getFilename();
3269 return "";
3270 }
3271
3273 if (auto *F = getFile())
3274 return F->getDirectory();
3275 return "";
3276 }
3277
3278 std::optional<StringRef> getSource() const {
3279 if (auto *F = getFile())
3280 return F->getSource();
3281 return std::nullopt;
3282 }
3283
3284 Metadata *getRawScope() const { return getOperand(0); }
3286 Metadata *getRawFile() const { return getOperand(2); }
3287 Metadata *getRawType() const { return getOperand(3); }
3288
3289 static bool classof(const Metadata *MD) {
3290 return MD->getMetadataID() == DILocalVariableKind ||
3291 MD->getMetadataID() == DIGlobalVariableKind;
3292 }
3293};
3294
3295/// DWARF expression.
3296///
3297/// This is (almost) a DWARF expression that modifies the location of a
3298/// variable, or the location of a single piece of a variable, or (when using
3299/// DW_OP_stack_value) is the constant variable value.
3300///
3301/// TODO: Co-allocate the expression elements.
3302/// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
3303/// storage types.
3304class DIExpression : public MDNode {
3305 friend class LLVMContextImpl;
3306 friend class MDNode;
3307
3308 std::vector<uint64_t> Elements;
3309
3310 DIExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
3311 : MDNode(C, DIExpressionKind, Storage, {}),
3312 Elements(Elements.begin(), Elements.end()) {}
3313 ~DIExpression() = default;
3314
3315 LLVM_ABI static DIExpression *getImpl(LLVMContext &Context,
3316 ArrayRef<uint64_t> Elements,
3318 bool ShouldCreate = true);
3319
3320 TempDIExpression cloneImpl() const {
3321 return getTemporary(getContext(), getElements());
3322 }
3323
3324public:
3325 DEFINE_MDNODE_GET(DIExpression, (ArrayRef<uint64_t> Elements), (Elements))
3326
3327 TempDIExpression clone() const { return cloneImpl(); }
3328
3329 ArrayRef<uint64_t> getElements() const { return Elements; }
3330
3331 unsigned getNumElements() const { return Elements.size(); }
3332
3333 uint64_t getElement(unsigned I) const {
3334 assert(I < Elements.size() && "Index out of range");
3335 return Elements[I];
3336 }
3337
3339 /// Determine whether this represents a constant value, if so
3340 // return it's sign information.
3341 LLVM_ABI std::optional<SignedOrUnsignedConstant> isConstant() const;
3342
3343 /// Return the number of unique location operands referred to (via
3344 /// DW_OP_LLVM_arg) in this expression; this is not necessarily the number of
3345 /// instances of DW_OP_LLVM_arg within the expression.
3346 /// For example, for the expression:
3347 /// (DW_OP_LLVM_arg 0, DW_OP_LLVM_arg 1, DW_OP_plus,
3348 /// DW_OP_LLVM_arg 0, DW_OP_mul)
3349 /// This function would return 2, as there are two unique location operands
3350 /// (0 and 1).
3352
3354
3357
3358 /// A lightweight wrapper around an expression operand.
3359 ///
3360 /// TODO: Store arguments directly and change \a DIExpression to store a
3361 /// range of these.
3363 const uint64_t *Op = nullptr;
3364
3365 public:
3366 ExprOperand() = default;
3367 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
3368
3369 const uint64_t *get() const { return Op; }
3370
3371 /// Get the operand code.
3372 uint64_t getOp() const { return *Op; }
3373
3374 /// Get an argument to the operand.
3375 ///
3376 /// Never returns the operand itself.
3377 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
3378
3379 unsigned getNumArgs() const { return getSize() - 1; }
3380
3381 /// Return the size of the operand.
3382 ///
3383 /// Return the number of elements in the operand (1 + args).
3384 LLVM_ABI unsigned getSize() const;
3385
3386 /// Append the elements of this operand to \p V.
3388 V.append(get(), get() + getSize());
3389 }
3390 };
3391
3392 /// An iterator for expression operands.
3394 ExprOperand Op;
3395
3396 public:
3397 using iterator_category = std::input_iterator_tag;
3399 using difference_type = std::ptrdiff_t;
3402
3403 expr_op_iterator() = default;
3405
3406 element_iterator getBase() const { return Op.get(); }
3407 const ExprOperand &operator*() const { return Op; }
3408 const ExprOperand *operator->() const { return &Op; }
3409
3411 increment();
3412 return *this;
3413 }
3415 expr_op_iterator T(*this);
3416 increment();
3417 return T;
3418 }
3419
3420 /// Get the next iterator.
3421 ///
3422 /// \a std::next() doesn't work because this is technically an
3423 /// input_iterator, but it's a perfectly valid operation. This is an
3424 /// accessor to provide the same functionality.
3425 expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
3426
3427 bool operator==(const expr_op_iterator &X) const {
3428 return getBase() == X.getBase();
3429 }
3430 bool operator!=(const expr_op_iterator &X) const {
3431 return getBase() != X.getBase();
3432 }
3433
3434 private:
3435 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
3436 };
3437
3438 /// Visit the elements via ExprOperand wrappers.
3439 ///
3440 /// These range iterators visit elements through \a ExprOperand wrappers.
3441 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
3442 /// true.
3443 ///
3444 /// \pre \a isValid() gives \c true.
3445 /// @{
3455 /// @}
3456
3457 LLVM_ABI bool isValid() const;
3458
3459 static bool classof(const Metadata *MD) {
3460 return MD->getMetadataID() == DIExpressionKind;
3461 }
3462
3463 /// Return whether the first element a DW_OP_deref.
3464 LLVM_ABI bool startsWithDeref() const;
3465
3466 /// Return whether there is exactly one operator and it is a DW_OP_deref;
3467 LLVM_ABI bool isDeref() const;
3468
3470
3471 /// Return the number of bits that have an active value, i.e. those that
3472 /// aren't known to be zero/sign (depending on the type of Var) and which
3473 /// are within the size of this fragment (if it is one). If we can't deduce
3474 /// anything from the expression this will return the size of Var.
3475 LLVM_ABI std::optional<uint64_t> getActiveBits(DIVariable *Var);
3476
3477 /// Retrieve the details of this fragment expression.
3478 LLVM_ABI static std::optional<FragmentInfo>
3480
3481 /// Retrieve the details of this fragment expression.
3482 std::optional<FragmentInfo> getFragmentInfo() const {
3484 }
3485
3486 /// Return whether this is a piece of an aggregate variable.
3487 bool isFragment() const { return getFragmentInfo().has_value(); }
3488
3489 /// Return whether this is an implicit location description.
3490 LLVM_ABI bool isImplicit() const;
3491
3492 /// Return whether the location is computed on the expression stack, meaning
3493 /// it cannot be a simple register location.
3494 LLVM_ABI bool isComplex() const;
3495
3496 /// Return whether the evaluated expression makes use of a single location at
3497 /// the start of the expression, i.e. if it contains only a single
3498 /// DW_OP_LLVM_arg op as its first operand, or if it contains none.
3500
3501 /// Returns a reference to the elements contained in this expression, skipping
3502 /// past the leading `DW_OP_LLVM_arg, 0` if one is present.
3503 /// Similar to `convertToNonVariadicExpression`, but faster and cheaper - it
3504 /// does not check whether the expression is a single-location expression, and
3505 /// it returns elements rather than creating a new DIExpression.
3506 LLVM_ABI std::optional<ArrayRef<uint64_t>>
3508
3509 /// Removes all elements from \p Expr that do not apply to an undef debug
3510 /// value, which includes every operator that computes the value/location on
3511 /// the DWARF stack, including any DW_OP_LLVM_arg elements (making the result
3512 /// of this function always a single-location expression) while leaving
3513 /// everything that defines what the computed value applies to, i.e. the
3514 /// fragment information.
3515 LLVM_ABI static const DIExpression *
3517
3518 /// If \p Expr is a non-variadic expression (i.e. one that does not contain
3519 /// DW_OP_LLVM_arg), returns \p Expr converted to variadic form by adding a
3520 /// leading [DW_OP_LLVM_arg, 0] to the expression; otherwise returns \p Expr.
3521 LLVM_ABI static const DIExpression *
3523
3524 /// If \p Expr is a valid single-location expression, i.e. it refers to only a
3525 /// single debug operand at the start of the expression, then return that
3526 /// expression in a non-variadic form by removing DW_OP_LLVM_arg from the
3527 /// expression if it is present; otherwise returns std::nullopt.
3528 /// See also `getSingleLocationExpressionElements` above, which skips
3529 /// checking `isSingleLocationExpression` and returns a list of elements
3530 /// rather than a DIExpression.
3531 LLVM_ABI static std::optional<const DIExpression *>
3533
3534 /// Inserts the elements of \p Expr into \p Ops modified to a canonical form,
3535 /// which uses DW_OP_LLVM_arg (i.e. is a variadic expression) and folds the
3536 /// implied derefence from the \p IsIndirect flag into the expression. This
3537 /// allows us to check equivalence between expressions with differing
3538 /// directness or variadicness.
3540 const DIExpression *Expr,
3541 bool IsIndirect);
3542
3543 /// Determines whether two debug values should produce equivalent DWARF
3544 /// expressions, using their DIExpressions and directness, ignoring the
3545 /// differences between otherwise identical expressions in variadic and
3546 /// non-variadic form and not considering the debug operands.
3547 /// \p FirstExpr is the DIExpression for the first debug value.
3548 /// \p FirstIndirect should be true if the first debug value is indirect; in
3549 /// IR this should be true for dbg.declare intrinsics and false for
3550 /// dbg.values, and in MIR this should be true only for DBG_VALUE instructions
3551 /// whose second operand is an immediate value.
3552 /// \p SecondExpr and \p SecondIndirect have the same meaning as the prior
3553 /// arguments, but apply to the second debug value.
3554 LLVM_ABI static bool isEqualExpression(const DIExpression *FirstExpr,
3555 bool FirstIndirect,
3556 const DIExpression *SecondExpr,
3557 bool SecondIndirect);
3558
3559 /// Append \p Ops with operations to apply the \p Offset.
3561 int64_t Offset);
3562
3563 /// If this is a constant offset, extract it. If there is no expression,
3564 /// return true with an offset of zero.
3565 LLVM_ABI bool extractIfOffset(int64_t &Offset) const;
3566
3567 /// Assuming that the expression operates on an address, extract a constant
3568 /// offset and the successive ops. Return false if the expression contains
3569 /// any incompatible ops (including non-zero DW_OP_LLVM_args - only a single
3570 /// address operand to the expression is permitted).
3571 ///
3572 /// We don't try very hard to interpret the expression because we assume that
3573 /// foldConstantMath has canonicalized the expression.
3574 LLVM_ABI bool
3575 extractLeadingOffset(int64_t &OffsetInBytes,
3576 SmallVectorImpl<uint64_t> &RemainingOps) const;
3577
3578 /// Returns true iff this DIExpression contains at least one instance of
3579 /// `DW_OP_LLVM_arg, n` for all n in [0, N).
3580 LLVM_ABI bool hasAllLocationOps(unsigned N) const;
3581
3582 /// Checks if the last 4 elements of the expression are DW_OP_constu <DWARF
3583 /// Address Space> DW_OP_swap DW_OP_xderef and extracts the <DWARF Address
3584 /// Space>.
3585 LLVM_ABI static const DIExpression *
3586 extractAddressClass(const DIExpression *Expr, unsigned &AddrClass);
3587
3588 /// Used for DIExpression::prepend.
3591 DerefBefore = 1 << 0,
3592 DerefAfter = 1 << 1,
3593 StackValue = 1 << 2,
3594 EntryValue = 1 << 3
3595 };
3596
3597 /// Prepend \p DIExpr with a deref and offset operation and optionally turn it
3598 /// into a stack value or/and an entry value.
3599 LLVM_ABI static DIExpression *prepend(const DIExpression *Expr, uint8_t Flags,
3600 int64_t Offset = 0);
3601
3602 /// Prepend \p DIExpr with the given opcodes and optionally turn it into a
3603 /// stack value.
3606 bool StackValue = false,
3607 bool EntryValue = false);
3608
3609 /// Append the opcodes \p Ops to \p DIExpr. Unlike \ref appendToStack, the
3610 /// returned expression is a stack value only if \p DIExpr is a stack value.
3611 /// If \p DIExpr describes a fragment, the returned expression will describe
3612 /// the same fragment.
3613 LLVM_ABI static DIExpression *append(const DIExpression *Expr,
3615
3616 /// Convert \p DIExpr into a stack value if it isn't one already by appending
3617 /// DW_OP_deref if needed, and appending \p Ops to the resulting expression.
3618 /// If \p DIExpr describes a fragment, the returned expression will describe
3619 /// the same fragment.
3620 LLVM_ABI static DIExpression *appendToStack(const DIExpression *Expr,
3622
3623 /// Create a copy of \p Expr by appending the given list of \p Ops to each
3624 /// instance of the operand `DW_OP_LLVM_arg, \p ArgNo`. This is used to
3625 /// modify a specific location used by \p Expr, such as when salvaging that
3626 /// location.
3629 unsigned ArgNo,
3630 bool StackValue = false);
3631
3632 /// Create a copy of \p Expr with each instance of
3633 /// `DW_OP_LLVM_arg, \p OldArg` replaced with `DW_OP_LLVM_arg, \p NewArg`,
3634 /// and each instance of `DW_OP_LLVM_arg, Arg` with `DW_OP_LLVM_arg, Arg - 1`
3635 /// for all Arg > \p OldArg.
3636 /// This is used when replacing one of the operands of a debug value list
3637 /// with another operand in the same list and deleting the old operand.
3638 LLVM_ABI static DIExpression *replaceArg(const DIExpression *Expr,
3639 uint64_t OldArg, uint64_t NewArg);
3640
3641 /// Create a DIExpression to describe one part of an aggregate variable that
3642 /// is fragmented across multiple Values. The DW_OP_LLVM_fragment operation
3643 /// will be appended to the elements of \c Expr. If \c Expr already contains
3644 /// a \c DW_OP_LLVM_fragment \c OffsetInBits is interpreted as an offset
3645 /// into the existing fragment.
3646 ///
3647 /// \param OffsetInBits Offset of the piece in bits.
3648 /// \param SizeInBits Size of the piece in bits.
3649 /// \return Creating a fragment expression may fail if \c Expr
3650 /// contains arithmetic operations that would be
3651 /// truncated.
3652 LLVM_ABI static std::optional<DIExpression *>
3653 createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits,
3654 unsigned SizeInBits);
3655
3656 /// Determine the relative position of the fragments passed in.
3657 /// Returns -1 if this is entirely before Other, 0 if this and Other overlap,
3658 /// 1 if this is entirely after Other.
3659 static int fragmentCmp(const FragmentInfo &A, const FragmentInfo &B) {
3660 uint64_t l1 = A.OffsetInBits;
3661 uint64_t l2 = B.OffsetInBits;
3662 uint64_t r1 = l1 + A.SizeInBits;
3663 uint64_t r2 = l2 + B.SizeInBits;
3664 if (r1 <= l2)
3665 return -1;
3666 else if (r2 <= l1)
3667 return 1;
3668 else
3669 return 0;
3670 }
3671
3672 /// Computes a fragment, bit-extract operation if needed, and new constant
3673 /// offset to describe a part of a variable covered by some memory.
3674 ///
3675 /// The memory region starts at:
3676 /// \p SliceStart + \p SliceOffsetInBits
3677 /// And is size:
3678 /// \p SliceSizeInBits
3679 ///
3680 /// The location of the existing variable fragment \p VarFrag is:
3681 /// \p DbgPtr + \p DbgPtrOffsetInBits + \p DbgExtractOffsetInBits.
3682 ///
3683 /// It is intended that these arguments are derived from a debug record:
3684 /// - \p DbgPtr is the (single) DIExpression operand.
3685 /// - \p DbgPtrOffsetInBits is the constant offset applied to \p DbgPtr.
3686 /// - \p DbgExtractOffsetInBits is the offset from a
3687 /// DW_OP_LLVM_bit_extract_[sz]ext operation.
3688 ///
3689 /// Results and return value:
3690 /// - Return false if the result can't be calculated for any reason.
3691 /// - \p Result is set to nullopt if the intersect equals \p VarFarg.
3692 /// - \p Result contains a zero-sized fragment if there's no intersect.
3693 /// - \p OffsetFromLocationInBits is set to the difference between the first
3694 /// bit of the variable location and the first bit of the slice. The
3695 /// magnitude of a negative value therefore indicates the number of bits
3696 /// into the variable fragment that the memory region begins.
3697 ///
3698 /// We don't pass in a debug record directly to get the constituent parts
3699 /// and offsets because different debug records store the information in
3700 /// different places (dbg_assign has two DIExpressions - one contains the
3701 /// fragment info for the entire intrinsic).
3703 const DataLayout &DL, const Value *SliceStart, uint64_t SliceOffsetInBits,
3704 uint64_t SliceSizeInBits, const Value *DbgPtr, int64_t DbgPtrOffsetInBits,
3705 int64_t DbgExtractOffsetInBits, DIExpression::FragmentInfo VarFrag,
3706 std::optional<DIExpression::FragmentInfo> &Result,
3707 int64_t &OffsetFromLocationInBits);
3708
3709 using ExtOps = std::array<uint64_t, 6>;
3710
3711 /// Returns the ops for a zero- or sign-extension in a DIExpression.
3712 LLVM_ABI static ExtOps getExtOps(unsigned FromSize, unsigned ToSize,
3713 bool Signed);
3714
3715 /// Append a zero- or sign-extension to \p Expr. Converts the expression to a
3716 /// stack value if it isn't one already.
3717 LLVM_ABI static DIExpression *appendExt(const DIExpression *Expr,
3718 unsigned FromSize, unsigned ToSize,
3719 bool Signed);
3720
3721 /// Check if fragments overlap between a pair of FragmentInfos.
3722 static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B) {
3723 return fragmentCmp(A, B) == 0;
3724 }
3725
3726 /// Determine the relative position of the fragments described by this
3727 /// DIExpression and \p Other. Calls static fragmentCmp implementation.
3728 int fragmentCmp(const DIExpression *Other) const {
3729 auto Fragment1 = *getFragmentInfo();
3730 auto Fragment2 = *Other->getFragmentInfo();
3731 return fragmentCmp(Fragment1, Fragment2);
3732 }
3733
3734 /// Check if fragments overlap between this DIExpression and \p Other.
3735 bool fragmentsOverlap(const DIExpression *Other) const {
3736 if (!isFragment() || !Other->isFragment())
3737 return true;
3738 return fragmentCmp(Other) == 0;
3739 }
3740
3741 /// Check if the expression consists of exactly one entry value operand.
3742 /// (This is the only configuration of entry values that is supported.)
3743 LLVM_ABI bool isEntryValue() const;
3744
3745 /// Try to shorten an expression with an initial constant operand.
3746 /// Returns a new expression and constant on success, or the original
3747 /// expression and constant on failure.
3748 LLVM_ABI std::pair<DIExpression *, const ConstantInt *>
3749 constantFold(const ConstantInt *CI);
3750
3751 /// Try to shorten an expression with constant math operations that can be
3752 /// evaluated at compile time. Returns a new expression on success, or the old
3753 /// expression if there is nothing to be reduced.
3755};
3756
3759 return std::tie(A.SizeInBits, A.OffsetInBits) ==
3760 std::tie(B.SizeInBits, B.OffsetInBits);
3761}
3762
3765 return std::tie(A.SizeInBits, A.OffsetInBits) <
3766 std::tie(B.SizeInBits, B.OffsetInBits);
3767}
3768
3769template <> struct DenseMapInfo<DIExpression::FragmentInfo> {
3771 static const uint64_t MaxVal = std::numeric_limits<uint64_t>::max();
3772
3773 static inline FragInfo getEmptyKey() { return {MaxVal, MaxVal}; }
3774
3775 static inline FragInfo getTombstoneKey() { return {MaxVal - 1, MaxVal - 1}; }
3776
3777 static unsigned getHashValue(const FragInfo &Frag) {
3778 return (Frag.SizeInBits & 0xffff) << 16 | (Frag.OffsetInBits & 0xffff);
3779 }
3780
3781 static bool isEqual(const FragInfo &A, const FragInfo &B) { return A == B; }
3782};
3783
3784/// Holds a DIExpression and keeps track of how many operands have been consumed
3785/// so far.
3788
3789public:
3791 if (!Expr) {
3792 assert(Start == End);
3793 return;
3794 }
3795 Start = Expr->expr_op_begin();
3796 End = Expr->expr_op_end();
3797 }
3798
3800 : Start(Expr.begin()), End(Expr.end()) {}
3801
3803
3804 /// Consume one operation.
3805 std::optional<DIExpression::ExprOperand> take() {
3806 if (Start == End)
3807 return std::nullopt;
3808 return *(Start++);
3809 }
3810
3811 /// Consume N operations.
3812 void consume(unsigned N) { std::advance(Start, N); }
3813
3814 /// Return the current operation.
3815 std::optional<DIExpression::ExprOperand> peek() const {
3816 if (Start == End)
3817 return std::nullopt;
3818 return *(Start);
3819 }
3820
3821 /// Return the next operation.
3822 std::optional<DIExpression::ExprOperand> peekNext() const {
3823 if (Start == End)
3824 return std::nullopt;
3825
3826 auto Next = Start.getNext();
3827 if (Next == End)
3828 return std::nullopt;
3829
3830 return *Next;
3831 }
3832
3833 std::optional<DIExpression::ExprOperand> peekNextN(unsigned N) const {
3834 if (Start == End)
3835 return std::nullopt;
3837 for (unsigned I = 0; I < N; I++) {
3838 Nth = Nth.getNext();
3839 if (Nth == End)
3840 return std::nullopt;
3841 }
3842 return *Nth;
3843 }
3844
3846 this->Start = DIExpression::expr_op_iterator(Expr.begin());
3847 this->End = DIExpression::expr_op_iterator(Expr.end());
3848 }
3849
3850 /// Determine whether there are any operations left in this expression.
3851 operator bool() const { return Start != End; }
3852
3853 DIExpression::expr_op_iterator begin() const { return Start; }
3854 DIExpression::expr_op_iterator end() const { return End; }
3855
3856 /// Retrieve the fragment information, if any.
3857 std::optional<DIExpression::FragmentInfo> getFragmentInfo() const {
3858 return DIExpression::getFragmentInfo(Start, End);
3859 }
3860};
3861
3862/// Global variables.
3863///
3864/// TODO: Remove DisplayName. It's always equal to Name.
3865class DIGlobalVariable : public DIVariable {
3866 friend class LLVMContextImpl;
3867 friend class MDNode;
3868
3869 bool IsLocalToUnit;
3870 bool IsDefinition;
3871
3872 DIGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
3873 bool IsLocalToUnit, bool IsDefinition, uint32_t AlignInBits,
3875 : DIVariable(C, DIGlobalVariableKind, Storage, Line, Ops, AlignInBits),
3876 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
3877 ~DIGlobalVariable() = default;
3878
3879 static DIGlobalVariable *
3880 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
3881 StringRef LinkageName, DIFile *File, unsigned Line, DIType *Type,
3882 bool IsLocalToUnit, bool IsDefinition,
3885 bool ShouldCreate = true) {
3886 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
3887 getCanonicalMDString(Context, LinkageName), File, Line, Type,
3890 Annotations.get(), Storage, ShouldCreate);
3891 }
3892 LLVM_ABI static DIGlobalVariable *
3893 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
3894 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
3895 bool IsLocalToUnit, bool IsDefinition,
3898 bool ShouldCreate = true);
3899
3900 TempDIGlobalVariable cloneImpl() const {
3905 getAnnotations());
3906 }
3907
3908public:
3910 DIGlobalVariable,
3912 unsigned Line, DIType *Type, bool IsLocalToUnit, bool IsDefinition,
3914 uint32_t AlignInBits, DINodeArray Annotations),
3915 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
3918 DIGlobalVariable,
3920 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
3923 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
3925
3926 TempDIGlobalVariable clone() const { return cloneImpl(); }
3927
3928 bool isLocalToUnit() const { return IsLocalToUnit; }
3929 bool isDefinition() const { return IsDefinition; }
3935 DINodeArray getAnnotations() const {
3937 }
3938
3943 Metadata *getRawAnnotations() const { return getOperand(8); }
3944
3945 static bool classof(const Metadata *MD) {
3946 return MD->getMetadataID() == DIGlobalVariableKind;
3947 }
3948};
3949
3950/// Debug common block.
3951///
3952/// Uses the SubclassData32 Metadata slot.
3953class DICommonBlock : public DIScope {
3954 friend class LLVMContextImpl;
3955 friend class MDNode;
3956
3957 DICommonBlock(LLVMContext &Context, StorageType Storage, unsigned LineNo,
3959
3960 static DICommonBlock *getImpl(LLVMContext &Context, DIScope *Scope,
3962 DIFile *File, unsigned LineNo,
3963 StorageType Storage, bool ShouldCreate = true) {
3964 return getImpl(Context, Scope, Decl, getCanonicalMDString(Context, Name),
3965 File, LineNo, Storage, ShouldCreate);
3966 }
3967 LLVM_ABI static DICommonBlock *getImpl(LLVMContext &Context, Metadata *Scope,
3969 Metadata *File, unsigned LineNo,
3971 bool ShouldCreate = true);
3972
3973 TempDICommonBlock cloneImpl() const {
3975 getFile(), getLineNo());
3976 }
3977
3978public:
3979 DEFINE_MDNODE_GET(DICommonBlock,
3981 DIFile *File, unsigned LineNo),
3982 (Scope, Decl, Name, File, LineNo))
3983 DEFINE_MDNODE_GET(DICommonBlock,
3985 Metadata *File, unsigned LineNo),
3987
3988 TempDICommonBlock clone() const { return cloneImpl(); }
3989
3994 StringRef getName() const { return getStringOperand(2); }
3996 unsigned getLineNo() const { return SubclassData32; }
3997
3998 Metadata *getRawScope() const { return getOperand(0); }
3999 Metadata *getRawDecl() const { return getOperand(1); }
4001 Metadata *getRawFile() const { return getOperand(3); }
4002
4003 static bool classof(const Metadata *MD) {
4004 return MD->getMetadataID() == DICommonBlockKind;
4005 }
4006};
4007
4008/// Local variable.
4009///
4010/// TODO: Split up flags.
4011class DILocalVariable : public DIVariable {
4012 friend class LLVMContextImpl;
4013 friend class MDNode;
4014
4015 unsigned Arg : 16;
4016 DIFlags Flags;
4017
4018 DILocalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
4019 unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
4021 : DIVariable(C, DILocalVariableKind, Storage, Line, Ops, AlignInBits),
4022 Arg(Arg), Flags(Flags) {
4023 assert(Arg < (1 << 16) && "DILocalVariable: Arg out of range");
4024 }
4025 ~DILocalVariable() = default;
4026
4027 static DILocalVariable *getImpl(LLVMContext &Context, DIScope *Scope,
4028 StringRef Name, DIFile *File, unsigned Line,
4029 DIType *Type, unsigned Arg, DIFlags Flags,
4030 uint32_t AlignInBits, DINodeArray Annotations,
4032 bool ShouldCreate = true) {
4033 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
4034 Line, Type, Arg, Flags, AlignInBits, Annotations.get(),
4035 Storage, ShouldCreate);
4036 }
4037 LLVM_ABI static DILocalVariable *
4038 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, Metadata *File,
4039 unsigned Line, Metadata *Type, unsigned Arg, DIFlags Flags,
4041 bool ShouldCreate = true);
4042
4043 TempDILocalVariable cloneImpl() const {
4045 getLine(), getType(), getArg(), getFlags(),
4047 }
4048
4049public:
4050 DEFINE_MDNODE_GET(DILocalVariable,
4052 unsigned Line, DIType *Type, unsigned Arg, DIFlags Flags,
4053 uint32_t AlignInBits, DINodeArray Annotations),
4054 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits,
4055 Annotations))
4056 DEFINE_MDNODE_GET(DILocalVariable,
4058 unsigned Line, Metadata *Type, unsigned Arg, DIFlags Flags,
4060 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits,
4061 Annotations))
4062
4063 TempDILocalVariable clone() const { return cloneImpl(); }
4064
4065 /// Get the local scope for this variable.
4066 ///
4067 /// Variables must be defined in a local scope.
4071
4072 bool isParameter() const { return Arg; }
4073 unsigned getArg() const { return Arg; }
4074 DIFlags getFlags() const { return Flags; }
4075
4076 DINodeArray getAnnotations() const {
4078 }
4079 Metadata *getRawAnnotations() const { return getOperand(4); }
4080
4081 bool isArtificial() const { return getFlags() & FlagArtificial; }
4082 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
4083
4084 /// Check that a location is valid for this variable.
4085 ///
4086 /// Check that \c DL exists, is in the same subprogram, and has the same
4087 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
4088 /// to a \a DbgInfoIntrinsic.)
4090 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
4091 }
4092
4093 static bool classof(const Metadata *MD) {
4094 return MD->getMetadataID() == DILocalVariableKind;
4095 }
4096};
4097
4098/// Label.
4099///
4100/// Uses the SubclassData32 Metadata slot.
4101class DILabel : public DINode {
4102 friend class LLVMContextImpl;
4103 friend class MDNode;
4104
4105 unsigned Column;
4106 std::optional<unsigned> CoroSuspendIdx;
4107 bool IsArtificial;
4108
4109 DILabel(LLVMContext &C, StorageType Storage, unsigned Line, unsigned Column,
4110 bool IsArtificial, std::optional<unsigned> CoroSuspendIdx,
4112 ~DILabel() = default;
4113
4114 static DILabel *getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
4115 DIFile *File, unsigned Line, unsigned Column,
4116 bool IsArtificial,
4117 std::optional<unsigned> CoroSuspendIdx,
4118 StorageType Storage, bool ShouldCreate = true) {
4119 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
4120 Line, Column, IsArtificial, CoroSuspendIdx, Storage,
4121 ShouldCreate);
4122 }
4123 LLVM_ABI static DILabel *
4124 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, Metadata *File,
4125 unsigned Line, unsigned Column, bool IsArtificial,
4126 std::optional<unsigned> CoroSuspendIdx, StorageType Storage,
4127 bool ShouldCreate = true);
4128
4129 TempDILabel cloneImpl() const {
4133 }
4134
4135public:
4138 unsigned Line, unsigned Column, bool IsArtificial,
4139 std::optional<unsigned> CoroSuspendIdx),
4140 (Scope, Name, File, Line, Column, IsArtificial,
4141 CoroSuspendIdx))
4142 DEFINE_MDNODE_GET(DILabel,
4144 unsigned Line, unsigned Column, bool IsArtificial,
4145 std::optional<unsigned> CoroSuspendIdx),
4146 (Scope, Name, File, Line, Column, IsArtificial,
4147 CoroSuspendIdx))
4148
4149 TempDILabel clone() const { return cloneImpl(); }
4150
4151 /// Get the local scope for this label.
4152 ///
4153 /// Labels must be defined in a local scope.
4157 unsigned getLine() const { return SubclassData32; }
4158 unsigned getColumn() const { return Column; }
4159 StringRef getName() const { return getStringOperand(1); }
4161 bool isArtificial() const { return IsArtificial; }
4162 std::optional<unsigned> getCoroSuspendIdx() const { return CoroSuspendIdx; }
4163
4164 Metadata *getRawScope() const { return getOperand(0); }
4166 Metadata *getRawFile() const { return getOperand(2); }
4167
4168 /// Check that a location is valid for this label.
4169 ///
4170 /// Check that \c DL exists, is in the same subprogram, and has the same
4171 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
4172 /// to a \a DbgInfoIntrinsic.)
4174 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
4175 }
4176
4177 static bool classof(const Metadata *MD) {
4178 return MD->getMetadataID() == DILabelKind;
4179 }
4180};
4181
4182class DIObjCProperty : public DINode {
4183 friend class LLVMContextImpl;
4184 friend class MDNode;
4185
4186 unsigned Line;
4187 unsigned Attributes;
4188
4189 DIObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
4190 unsigned Attributes, ArrayRef<Metadata *> Ops);
4191 ~DIObjCProperty() = default;
4192
4193 static DIObjCProperty *
4194 getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
4195 StringRef GetterName, StringRef SetterName, unsigned Attributes,
4196 DIType *Type, StorageType Storage, bool ShouldCreate = true) {
4197 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
4199 getCanonicalMDString(Context, SetterName), Attributes, Type,
4200 Storage, ShouldCreate);
4201 }
4202 LLVM_ABI static DIObjCProperty *
4203 getImpl(LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
4204 MDString *GetterName, MDString *SetterName, unsigned Attributes,
4205 Metadata *Type, StorageType Storage, bool ShouldCreate = true);
4206
4207 TempDIObjCProperty cloneImpl() const {
4208 return getTemporary(getContext(), getName(), getFile(), getLine(),
4210 getType());
4211 }
4212
4213public:
4214 DEFINE_MDNODE_GET(DIObjCProperty,
4215 (StringRef Name, DIFile *File, unsigned Line,
4217 unsigned Attributes, DIType *Type),
4218 (Name, File, Line, GetterName, SetterName, Attributes,
4219 Type))
4220 DEFINE_MDNODE_GET(DIObjCProperty,
4221 (MDString * Name, Metadata *File, unsigned Line,
4223 unsigned Attributes, Metadata *Type),
4224 (Name, File, Line, GetterName, SetterName, Attributes,
4225 Type))
4226
4227 TempDIObjCProperty clone() const { return cloneImpl(); }
4228
4229 unsigned getLine() const { return Line; }
4230 unsigned getAttributes() const { return Attributes; }
4231 StringRef getName() const { return getStringOperand(0); }
4236
4238 if (auto *F = getFile())
4239 return F->getFilename();
4240 return "";
4241 }
4242
4244 if (auto *F = getFile())
4245 return F->getDirectory();
4246 return "";
4247 }
4248
4250 Metadata *getRawFile() const { return getOperand(1); }
4253 Metadata *getRawType() const { return getOperand(4); }
4254
4255 static bool classof(const Metadata *MD) {
4256 return MD->getMetadataID() == DIObjCPropertyKind;
4257 }
4258};
4259
4260/// An imported module (C++ using directive or similar).
4261///
4262/// Uses the SubclassData32 Metadata slot.
4263class DIImportedEntity : public DINode {
4264 friend class LLVMContextImpl;
4265 friend class MDNode;
4266
4267 DIImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
4268 unsigned Line, ArrayRef<Metadata *> Ops)
4269 : DINode(C, DIImportedEntityKind, Storage, Tag, Ops) {
4271 }
4272 ~DIImportedEntity() = default;
4273
4274 static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
4275 DIScope *Scope, DINode *Entity, DIFile *File,
4276 unsigned Line, StringRef Name,
4277 DINodeArray Elements, StorageType Storage,
4278 bool ShouldCreate = true) {
4279 return getImpl(Context, Tag, Scope, Entity, File, Line,
4280 getCanonicalMDString(Context, Name), Elements.get(), Storage,
4281 ShouldCreate);
4282 }
4283 LLVM_ABI static DIImportedEntity *
4284 getImpl(LLVMContext &Context, unsigned Tag, Metadata *Scope, Metadata *Entity,
4285 Metadata *File, unsigned Line, MDString *Name, Metadata *Elements,
4286 StorageType Storage, bool ShouldCreate = true);
4287
4288 TempDIImportedEntity cloneImpl() const {
4289 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
4290 getFile(), getLine(), getName(), getElements());
4291 }
4292
4293public:
4294 DEFINE_MDNODE_GET(DIImportedEntity,
4295 (unsigned Tag, DIScope *Scope, DINode *Entity, DIFile *File,
4296 unsigned Line, StringRef Name = "",
4297 DINodeArray Elements = nullptr),
4298 (Tag, Scope, Entity, File, Line, Name, Elements))
4299 DEFINE_MDNODE_GET(DIImportedEntity,
4302 Metadata *Elements = nullptr),
4303 (Tag, Scope, Entity, File, Line, Name, Elements))
4304
4305 TempDIImportedEntity clone() const { return cloneImpl(); }
4306
4307 unsigned getLine() const { return SubclassData32; }
4308 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
4309 DINode *getEntity() const { return cast_or_null<DINode>(getRawEntity()); }
4310 StringRef getName() const { return getStringOperand(2); }
4311 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
4312 DINodeArray getElements() const {
4313 return cast_or_null<MDTuple>(getRawElements());
4314 }
4315
4316 Metadata *getRawScope() const { return getOperand(0); }
4317 Metadata *getRawEntity() const { return getOperand(1); }
4318 MDString *getRawName() const { return getOperandAs<MDString>(2); }
4319 Metadata *getRawFile() const { return getOperand(3); }
4320 Metadata *getRawElements() const { return getOperand(4); }
4321
4322 static bool classof(const Metadata *MD) {
4323 return MD->getMetadataID() == DIImportedEntityKind;
4324 }
4325};
4326
4327/// A pair of DIGlobalVariable and DIExpression.
4328class DIGlobalVariableExpression : public MDNode {
4329 friend class LLVMContextImpl;
4330 friend class MDNode;
4331
4332 DIGlobalVariableExpression(LLVMContext &C, StorageType Storage,
4334 : MDNode(C, DIGlobalVariableExpressionKind, Storage, Ops) {}
4335 ~DIGlobalVariableExpression() = default;
4336
4338 getImpl(LLVMContext &Context, Metadata *Variable, Metadata *Expression,
4339 StorageType Storage, bool ShouldCreate = true);
4340
4341 TempDIGlobalVariableExpression cloneImpl() const {
4343 }
4344
4345public:
4346 DEFINE_MDNODE_GET(DIGlobalVariableExpression,
4347 (Metadata * Variable, Metadata *Expression),
4348 (Variable, Expression))
4349
4350 TempDIGlobalVariableExpression clone() const { return cloneImpl(); }
4351
4352 Metadata *getRawVariable() const { return getOperand(0); }
4353
4357
4358 Metadata *getRawExpression() const { return getOperand(1); }
4359
4363
4364 static bool classof(const Metadata *MD) {
4365 return MD->getMetadataID() == DIGlobalVariableExpressionKind;
4366 }
4367};
4368
4369/// Macro Info DWARF-like metadata node.
4370///
4371/// A metadata node with a DWARF macro info (i.e., a constant named
4372/// \c DW_MACINFO_*, defined in llvm/BinaryFormat/Dwarf.h). Called \a
4373/// DIMacroNode
4374/// because it's potentially used for non-DWARF output.
4375///
4376/// Uses the SubclassData16 Metadata slot.
4377class DIMacroNode : public MDNode {
4378 friend class LLVMContextImpl;
4379 friend class MDNode;
4380
4381protected:
4382 DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType,
4384 : MDNode(C, ID, Storage, Ops1, Ops2) {
4385 assert(MIType < 1u << 16);
4386 SubclassData16 = MIType;
4387 }
4388 ~DIMacroNode() = default;
4389
4390 template <class Ty> Ty *getOperandAs(unsigned I) const {
4391 return cast_or_null<Ty>(getOperand(I));
4392 }
4393
4394 StringRef getStringOperand(unsigned I) const {
4395 if (auto *S = getOperandAs<MDString>(I))
4396 return S->getString();
4397 return StringRef();
4398 }
4399
4401 if (S.empty())
4402 return nullptr;
4403 return MDString::get(Context, S);
4404 }
4405
4406public:
4407 unsigned getMacinfoType() const { return SubclassData16; }
4408
4409 static bool classof(const Metadata *MD) {
4410 switch (MD->getMetadataID()) {
4411 default:
4412 return false;
4413 case DIMacroKind:
4414 case DIMacroFileKind:
4415 return true;
4416 }
4417 }
4418};
4419
4420/// Macro
4421///
4422/// Uses the SubclassData32 Metadata slot.
4423class DIMacro : public DIMacroNode {
4424 friend class LLVMContextImpl;
4425 friend class MDNode;
4426
4427 DIMacro(LLVMContext &C, StorageType Storage, unsigned MIType, unsigned Line,
4429 : DIMacroNode(C, DIMacroKind, Storage, MIType, Ops) {
4431 }
4432 ~DIMacro() = default;
4433
4434 static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
4436 bool ShouldCreate = true) {
4437 return getImpl(Context, MIType, Line, getCanonicalMDString(Context, Name),
4438 getCanonicalMDString(Context, Value), Storage, ShouldCreate);
4439 }
4440 LLVM_ABI static DIMacro *getImpl(LLVMContext &Context, unsigned MIType,
4441 unsigned Line, MDString *Name,
4442 MDString *Value, StorageType Storage,
4443 bool ShouldCreate = true);
4444
4445 TempDIMacro cloneImpl() const {
4447 getValue());
4448 }
4449
4450public:
4452 (unsigned MIType, unsigned Line, StringRef Name,
4453 StringRef Value = ""),
4454 (MIType, Line, Name, Value))
4455 DEFINE_MDNODE_GET(DIMacro,
4456 (unsigned MIType, unsigned Line, MDString *Name,
4459
4460 TempDIMacro clone() const { return cloneImpl(); }
4461
4462 unsigned getLine() const { return SubclassData32; }
4463
4464 StringRef getName() const { return getStringOperand(0); }
4465 StringRef getValue() const { return getStringOperand(1); }
4466
4469
4470 static bool classof(const Metadata *MD) {
4471 return MD->getMetadataID() == DIMacroKind;
4472 }
4473};
4474
4475/// Macro file
4476///
4477/// Uses the SubclassData32 Metadata slot.
4478class DIMacroFile : public DIMacroNode {
4479 friend class LLVMContextImpl;
4480 friend class MDNode;
4481
4482 DIMacroFile(LLVMContext &C, StorageType Storage, unsigned MIType,
4483 unsigned Line, ArrayRef<Metadata *> Ops)
4484 : DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops) {
4486 }
4487 ~DIMacroFile() = default;
4488
4489 static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
4490 unsigned Line, DIFile *File,
4491 DIMacroNodeArray Elements, StorageType Storage,
4492 bool ShouldCreate = true) {
4493 return getImpl(Context, MIType, Line, static_cast<Metadata *>(File),
4494 Elements.get(), Storage, ShouldCreate);
4495 }
4496
4497 LLVM_ABI static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
4498 unsigned Line, Metadata *File,
4500 bool ShouldCreate = true);
4501
4502 TempDIMacroFile cloneImpl() const {
4504 getElements());
4505 }
4506
4507public:
4509 (unsigned MIType, unsigned Line, DIFile *File,
4510 DIMacroNodeArray Elements),
4511 (MIType, Line, File, Elements))
4512 DEFINE_MDNODE_GET(DIMacroFile,
4513 (unsigned MIType, unsigned Line, Metadata *File,
4516
4517 TempDIMacroFile clone() const { return cloneImpl(); }
4518
4519 void replaceElements(DIMacroNodeArray Elements) {
4520#ifndef NDEBUG
4521 for (DIMacroNode *Op : getElements())
4522 assert(is_contained(Elements->operands(), Op) &&
4523 "Lost a macro node during macro node list replacement");
4524#endif
4525 replaceOperandWith(1, Elements.get());
4526 }
4527
4528 unsigned getLine() const { return SubclassData32; }
4530
4531 DIMacroNodeArray getElements() const {
4533 }
4534
4535 Metadata *getRawFile() const { return getOperand(0); }
4536 Metadata *getRawElements() const { return getOperand(1); }
4537
4538 static bool classof(const Metadata *MD) {
4539 return MD->getMetadataID() == DIMacroFileKind;
4540 }
4541};
4542
4543/// List of ValueAsMetadata, to be used as an argument to a dbg.value
4544/// intrinsic.
4545class DIArgList : public Metadata, ReplaceableMetadataImpl {
4547 friend class LLVMContextImpl;
4549
4551
4552 DIArgList(LLVMContext &Context, ArrayRef<ValueAsMetadata *> Args)
4553 : Metadata(DIArgListKind, Uniqued), ReplaceableMetadataImpl(Context),
4554 Args(Args) {
4555 track();
4556 }
4557 ~DIArgList() { untrack(); }
4558
4559 LLVM_ABI void track();
4560 LLVM_ABI void untrack();
4561 void dropAllReferences(bool Untrack);
4562
4563public:
4564 LLVM_ABI static DIArgList *get(LLVMContext &Context,
4566
4567 ArrayRef<ValueAsMetadata *> getArgs() const { return Args; }
4568
4569 iterator args_begin() { return Args.begin(); }
4570 iterator args_end() { return Args.end(); }
4571
4572 static bool classof(const Metadata *MD) {
4573 return MD->getMetadataID() == DIArgListKind;
4574 }
4575
4579
4580 LLVM_ABI void handleChangedOperand(void *Ref, Metadata *New);
4581};
4582
4583/// Identifies a unique instance of a variable.
4584///
4585/// Storage for identifying a potentially inlined instance of a variable,
4586/// or a fragment thereof. This guarantees that exactly one variable instance
4587/// may be identified by this class, even when that variable is a fragment of
4588/// an aggregate variable and/or there is another inlined instance of the same
4589/// source code variable nearby.
4590/// This class does not necessarily uniquely identify that variable: it is
4591/// possible that a DebugVariable with different parameters may point to the
4592/// same variable instance, but not that one DebugVariable points to multiple
4593/// variable instances.
4595 using FragmentInfo = DIExpression::FragmentInfo;
4596
4597 const DILocalVariable *Variable;
4598 std::optional<FragmentInfo> Fragment;
4599 const DILocation *InlinedAt;
4600
4601 /// Fragment that will overlap all other fragments. Used as default when
4602 /// caller demands a fragment.
4603 LLVM_ABI static const FragmentInfo DefaultFragment;
4604
4605public:
4607
4609 std::optional<FragmentInfo> FragmentInfo,
4610 const DILocation *InlinedAt)
4611 : Variable(Var), Fragment(FragmentInfo), InlinedAt(InlinedAt) {}
4612
4613 DebugVariable(const DILocalVariable *Var, const DIExpression *DIExpr,
4614 const DILocation *InlinedAt)
4615 : Variable(Var),
4616 Fragment(DIExpr ? DIExpr->getFragmentInfo() : std::nullopt),
4617 InlinedAt(InlinedAt) {}
4618
4619 const DILocalVariable *getVariable() const { return Variable; }
4620 std::optional<FragmentInfo> getFragment() const { return Fragment; }
4621 const DILocation *getInlinedAt() const { return InlinedAt; }
4622
4623 FragmentInfo getFragmentOrDefault() const {
4624 return Fragment.value_or(DefaultFragment);
4625 }
4626
4627 static bool isDefaultFragment(const FragmentInfo F) {
4628 return F == DefaultFragment;
4629 }
4630
4631 bool operator==(const DebugVariable &Other) const {
4632 return std::tie(Variable, Fragment, InlinedAt) ==
4633 std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
4634 }
4635
4636 bool operator<(const DebugVariable &Other) const {
4637 return std::tie(Variable, Fragment, InlinedAt) <
4638 std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
4639 }
4640};
4641
4642template <> struct DenseMapInfo<DebugVariable> {
4644
4645 /// Empty key: no key should be generated that has no DILocalVariable.
4646 static inline DebugVariable getEmptyKey() {
4647 return DebugVariable(nullptr, std::nullopt, nullptr);
4648 }
4649
4650 /// Difference in tombstone is that the Optional is meaningful.
4652 return DebugVariable(nullptr, {{0, 0}}, nullptr);
4653 }
4654
4655 static unsigned getHashValue(const DebugVariable &D) {
4656 unsigned HV = 0;
4657 const std::optional<FragmentInfo> Fragment = D.getFragment();
4658 if (Fragment)
4660
4661 return hash_combine(D.getVariable(), HV, D.getInlinedAt());
4662 }
4663
4664 static bool isEqual(const DebugVariable &A, const DebugVariable &B) {
4665 return A == B;
4666 }
4667};
4668
4669/// Identifies a unique instance of a whole variable (discards/ignores fragment
4670/// information).
4677
4678template <>
4680 : public DenseMapInfo<DebugVariable> {};
4681} // end namespace llvm
4682
4683#undef DEFINE_MDNODE_GET_UNPACK_IMPL
4684#undef DEFINE_MDNODE_GET_UNPACK
4685#undef DEFINE_MDNODE_GET
4686
4687#endif // LLVM_IR_DEBUGINFOMETADATA_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static std::string getLinkageName(GlobalValue::LinkageTypes LT)
BitTracker BT
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:213
This file contains the declarations for the subclasses of Constant, which represent the different fla...
dxil translate DXIL Translate Metadata
#define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS)
#define DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS)
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
static unsigned getNextComponentInDiscriminator(unsigned D)
Returns the next component stored in discriminator.
static unsigned getUnsignedFromPrefixEncoding(unsigned U)
Reverse transformation as getPrefixEncodingFromUnsigned.
static SmallString< 128 > getFilename(const DIScope *SP, vfs::FileSystem &VFS)
Extract a filename for a DIScope.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:55
#define I(x, y, z)
Definition MD5.cpp:58
This file contains the declarations for metadata subclasses.
#define T
This file defines the PointerUnion class, which is a discriminated union of pointer types.
static StringRef getName(Value *V)
static void r2(uint32_t &A, uint32_t &B, uint32_t &C, uint32_t &D, uint32_t &E, int I, uint32_t *Buf)
Definition SHA1.cpp:51
static void r1(uint32_t &A, uint32_t &B, uint32_t &C, uint32_t &D, uint32_t &E, int I, uint32_t *Buf)
Definition SHA1.cpp:45
This file contains some templates that are useful if you are working with the STL at all.
static enum BaseType getBaseType(const Value *Val)
Return the baseType for Val which states whether Val is exclusively derived from constant/null,...
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
This file defines the SmallVector class.
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
static uint32_t getFlags(const Symbol *Sym)
Definition TapiFile.cpp:26
static SymbolRef::Type getType(const Symbol *Sym)
Definition TapiFile.cpp:39
Class for arbitrary precision integers.
Definition APInt.h:78
Annotations lets you mark points and ranges inside source code, for tests:
Definition Annotations.h:53
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
iterator end() const
Definition ArrayRef.h:136
const_pointer iterator
Definition ArrayRef.h:48
iterator begin() const
Definition ArrayRef.h:135
static ConstantAsMetadata * get(Constant *C)
Definition Metadata.h:536
This is the shared class of boolean and integer constants.
Definition Constants.h:87
This is an important base class in LLVM.
Definition Constant.h:43
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
ArrayRef< ValueAsMetadata * > getArgs() const
LLVM_ABI void handleChangedOperand(void *Ref, Metadata *New)
static bool classof(const Metadata *MD)
static LLVM_ABI DIArgList * get(LLVMContext &Context, ArrayRef< ValueAsMetadata * > Args)
friend class ReplaceableMetadataImpl
friend class LLVMContextImpl
SmallVector< DbgVariableRecord * > getAllDbgVariableRecordUsers()
static bool classof(const Metadata *MD)
SmallVector< DbgVariableRecord * > getAllDbgVariableRecordUsers()
static TempDIAssignID getTemporary(LLVMContext &Context)
static DIAssignID * getDistinct(LLVMContext &Context)
friend class LLVMContextImpl
void replaceOperandWith(unsigned I, Metadata *New)=delete
Basic type, like 'int' or 'float'.
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
DIBasicType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, uint32_t AlignInBits, unsigned Encoding, uint32_t NumExtraInhabitants, DIFlags Flags, ArrayRef< Metadata * > Ops)
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 MDString Metadata uint32_t unsigned uint32_t DIFlags Flags TempDIBasicType clone() const
~DIBasicType()=default
static bool classof(const Metadata *MD)
DIBasicType(LLVMContext &C, StorageType Storage, unsigned Tag, uint32_t AlignInBits, unsigned Encoding, uint32_t NumExtraInhabitants, DIFlags Flags, ArrayRef< Metadata * > Ops)
static DIBasicType * getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, uint32_t NumExtraInhabitants, DIFlags Flags, StorageType Storage, bool ShouldCreate=true)
static DIBasicType * getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, uint32_t NumExtraInhabitants, DIFlags Flags, StorageType Storage, bool ShouldCreate=true)
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
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags unsigned StringRef uint64_t uint32_t unsigned uint32_t NumExtraInhabitants
unsigned StringRef Name
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t AlignInBits
DEFINE_MDNODE_GET(DIBasicType,(unsigned Tag, StringRef Name),(Tag, Name, 0, 0, 0, 0, FlagZero)) DEFINE_MDNODE_GET(DIBasicType
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
MDString * getRawSplitDebugFilename() const
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool DebugInfoForProfiling
unsigned Metadata MDString bool MDString unsigned MDString unsigned EmissionKind
bool getDebugInfoForProfiling() const
Metadata * getRawRetainedTypes() const
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool RangesBaseAddress
static LLVM_ABI const char * nameTableKindString(DebugNameTableKind PK)
static LLVM_ABI const char * emissionKindString(DebugEmissionKind EK)
void setSplitDebugInlining(bool SplitDebugInlining)
DICompositeTypeArray getEnumTypes() const
DebugEmissionKind getEmissionKind() const
unsigned Metadata * File
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata * Macros
unsigned Metadata MDString bool MDString * Flags
bool isDebugDirectivesOnly() const
StringRef getFlags() const
MDString * getRawProducer() const
void replaceEnumTypes(DICompositeTypeArray N)
Replace arrays.
MDString * getRawSysRoot() const
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata * EnumTypes
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata * RetainedTypes
StringRef getSDK() const
static void getIfExists()=delete
bool getRangesBaseAddress() const
DIMacroNodeArray getMacros() const
unsigned getRuntimeVersion() const
Metadata * getRawMacros() const
void replaceRetainedTypes(DITypeArray N)
static bool classof(const Metadata *MD)
void replaceGlobalVariables(DIGlobalVariableExpressionArray N)
void replaceMacros(DIMacroNodeArray N)
unsigned Metadata MDString bool IsOptimized
bool getSplitDebugInlining() const
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned NameTableKind
StringRef getSysRoot() const
DebugNameTableKind getNameTableKind() const
MDString * getRawSDK() const
MDString * getRawFlags() const
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata * GlobalVariables
DIImportedEntityArray getImportedEntities() const
unsigned Metadata MDString bool MDString unsigned RuntimeVersion
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString MDString * SDK
unsigned Metadata MDString * Producer
Metadata * getRawEnumTypes() const
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString * SysRoot
StringRef getProducer() const
unsigned Metadata MDString bool MDString unsigned MDString * SplitDebugFilename
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool SplitDebugInlining
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata * ImportedEntities
void setDWOId(uint64_t DwoId)
DIScopeArray getRetainedTypes() const
void replaceImportedEntities(DIImportedEntityArray N)
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t DWOId
Metadata * getRawGlobalVariables() const
DIGlobalVariableExpressionArray getGlobalVariables() const
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString MDString SDK TempDICompileUnit clone() const
unsigned getSourceLanguage() const
Metadata * getRawImportedEntities() const
uint64_t getDWOId() const
StringRef getSplitDebugFilename() const
static void get()=delete
DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(DICompileUnit,(unsigned 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
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t AlignInBits
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > EnumKind
Metadata * getRawVTableHolder() const
DIExpression * getRankExp() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata * DataLocation
static LLVM_ABI DICompositeType * buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, Metadata *SizeInBits, uint32_t AlignInBits, Metadata *OffsetInBits, Metadata *Specification, uint32_t NumExtraInhabitants, DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, std::optional< uint32_t > EnumKind, Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator, Metadata *DataLocation, Metadata *Associated, Metadata *Allocated, Metadata *Rank, Metadata *Annotations, Metadata *BitStride)
Build a DICompositeType with the given ODR identifier.
unsigned MDString Metadata unsigned Line
Metadata * getRawRank() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata * Elements
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned RuntimeLang
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata * Annotations
Metadata * getRawSpecification() const
DIExpression * getAssociatedExp() const
DIVariable * getAllocated() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString * Identifier
DIExpression * getDataLocationExp() const
Metadata * getRawDiscriminator() const
static LLVM_ABI DICompositeType * getODRTypeIfExists(LLVMContext &Context, MDString &Identifier)
DIVariable * getAssociated() const
DIDerivedType * getDiscriminator() const
DIVariable * getDataLocation() const
unsigned getRuntimeLang() const
DIType * getSpecification() const
Metadata * getRawElements() const
unsigned MDString * Name
void replaceVTableHolder(DIType *VTableHolder)
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata * Discriminator
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata * TemplateParams
StringRef getIdentifier() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t OffsetInBits
unsigned MDString Metadata unsigned Metadata * Scope
unsigned MDString Metadata * File
Metadata * getRawDataLocation() const
Metadata * getRawTemplateParams() const
unsigned MDString Metadata unsigned Metadata Metadata * BaseType
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Flags
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata * Allocated
DINodeArray getElements() const
DITemplateParameterArray getTemplateParams() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata Metadata * Specification
Metadata * getRawAnnotations() const
Metadata * getRawAllocated() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata * VTableHolder
DIExpression * getAllocatedExp() const
void replaceElements(DINodeArray Elements)
Replace operands.
ConstantInt * getBitStrideConst() const
std::optional< uint32_t > getEnumKind() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t SizeInBits
DIType * getVTableHolder() const
DINodeArray getAnnotations() const
Metadata * getRawAssociated() const
ConstantInt * getRankConst() const
void replaceTemplateParams(DITemplateParameterArray TemplateParams)
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata * Associated
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata Metadata uint32_t NumExtraInhabitants
Metadata * getRawBitStride() const
Metadata * getRawBaseType() const
DEFINE_MDNODE_GET(DICompositeType,(unsigned Tag, StringRef Name, DIFile *File, unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags, DINodeArray Elements, unsigned RuntimeLang, std::optional< uint32_t > EnumKind, DIType *VTableHolder, DITemplateParameterArray TemplateParams=nullptr, StringRef Identifier="", DIDerivedType *Discriminator=nullptr, Metadata *DataLocation=nullptr, Metadata *Associated=nullptr, Metadata *Allocated=nullptr, Metadata *Rank=nullptr, DINodeArray Annotations=nullptr, DIType *Specification=nullptr, uint32_t NumExtraInhabitants=0, Metadata *BitStride=nullptr),(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits, Specification, NumExtraInhabitants, Flags, Elements, RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier, Discriminator, DataLocation, Associated, Allocated, Rank, Annotations, BitStride)) DEFINE_MDNODE_GET(DICompositeType
MDString * getRawIdentifier() const
static bool classof(const Metadata *MD)
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata * Rank
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata Metadata uint32_t Metadata * BitStride
DIType * getBaseType() const
Metadata * getRawExtraData() const
unsigned StringRef DIFile unsigned DIScope DIType * BaseType
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata * OffsetInBits
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > std::optional< PtrAuthData > DIFlags Flags
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t AlignInBits
DINodeArray getAnnotations() const
Get annotations associated with this derived type.
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > std::optional< PtrAuthData > PtrAuthData
DEFINE_MDNODE_GET(DIDerivedType,(unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, Metadata *SizeInBits, uint32_t AlignInBits, Metadata *OffsetInBits, std::optional< unsigned > DWARFAddressSpace, std::optional< PtrAuthData > PtrAuthData, DIFlags Flags, Metadata *ExtraData=nullptr, Metadata *Annotations=nullptr),(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData, Flags, ExtraData, Annotations)) DEFINE_MDNODE_GET(DIDerivedType
Metadata * getExtraData() const
Get extra data associated with this derived type.
DITemplateParameterArray getTemplateParams() const
Get the template parameters from a template alias.
unsigned StringRef DIFile * File
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > std::optional< PtrAuthData > DIFlags Metadata DINodeArray Annotations
DIObjCProperty * getObjCProperty() const
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > DWARFAddressSpace
unsigned StringRef DIFile unsigned DIScope * Scope
Metadata * getRawAnnotations() const
LLVM_ABI DIType * getClassType() const
Get casted version of extra data.
static bool classof(const Metadata *MD)
LLVM_ABI Constant * getConstant() const
unsigned StringRef DIFile unsigned DIScope DIType Metadata * SizeInBits
LLVM_ABI Constant * getStorageOffsetInBits() const
LLVM_ABI Constant * getDiscriminantValue() const
unsigned StringRef Name
LLVM_ABI uint32_t getVBPtrOffset() const
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > std::optional< PtrAuthData > DIFlags Metadata * ExtraData
unsigned StringRef DIFile unsigned Line
Enumeration value.
int64_t bool MDString APInt(64, Value, !IsUnsigned)
const APInt & getValue() const
int64_t bool MDString Name APInt bool MDString Name TempDIEnumerator clone() const
MDString * getRawName() const
StringRef getName() const
friend class LLVMContextImpl
DEFINE_MDNODE_GET(DIEnumerator,(int64_t Value, bool IsUnsigned, StringRef Name),(APInt(64, Value, !IsUnsigned), IsUnsigned, Name)) DEFINE_MDNODE_GET(DIEnumerator
static bool classof(const Metadata *MD)
int64_t bool MDString * Name
std::optional< DIExpression::ExprOperand > peekNext() const
Return the next operation.
std::optional< DIExpression::FragmentInfo > getFragmentInfo() const
Retrieve the fragment information, if any.
DIExpressionCursor(const DIExpressionCursor &)=default
DIExpressionCursor(const DIExpression *Expr)
DIExpression::expr_op_iterator end() const
std::optional< DIExpression::ExprOperand > peekNextN(unsigned N) const
std::optional< DIExpression::ExprOperand > peek() const
Return the current operation.
void consume(unsigned N)
Consume N operations.
std::optional< DIExpression::ExprOperand > take()
Consume one operation.
DIExpressionCursor(ArrayRef< uint64_t > Expr)
DIExpression::expr_op_iterator begin() const
void assignNewExpr(ArrayRef< uint64_t > Expr)
A lightweight wrapper around an expression operand.
LLVM_ABI unsigned getSize() const
Return the size of the operand.
uint64_t getArg(unsigned I) const
Get an argument to the operand.
uint64_t getOp() const
Get the operand code.
void appendToVector(SmallVectorImpl< uint64_t > &V) const
Append the elements of this operand to V.
An iterator for expression operands.
bool operator==(const expr_op_iterator &X) const
const ExprOperand * operator->() const
bool operator!=(const expr_op_iterator &X) const
const ExprOperand & operator*() const
expr_op_iterator getNext() const
Get the next iterator.
DWARF expression.
element_iterator elements_end() const
LLVM_ABI bool isEntryValue() const
Check if the expression consists of exactly one entry value operand.
iterator_range< expr_op_iterator > expr_ops() const
bool isFragment() const
Return whether this is a piece of an aggregate variable.
static LLVM_ABI DIExpression * append(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Append the opcodes Ops to DIExpr.
std::array< uint64_t, 6 > ExtOps
unsigned getNumElements() const
ArrayRef< uint64_t >::iterator element_iterator
static LLVM_ABI ExtOps getExtOps(unsigned FromSize, unsigned ToSize, bool Signed)
Returns the ops for a zero- or sign-extension in a DIExpression.
expr_op_iterator expr_op_begin() const
Visit the elements via ExprOperand wrappers.
LLVM_ABI bool extractIfOffset(int64_t &Offset) const
If this is a constant offset, extract it.
static LLVM_ABI void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
DbgVariableFragmentInfo FragmentInfo
int fragmentCmp(const DIExpression *Other) const
Determine the relative position of the fragments described by this DIExpression and Other.
LLVM_ABI bool startsWithDeref() const
Return whether the first element a DW_OP_deref.
static LLVM_ABI bool isEqualExpression(const DIExpression *FirstExpr, bool FirstIndirect, const DIExpression *SecondExpr, bool SecondIndirect)
Determines whether two debug values should produce equivalent DWARF expressions, using their DIExpres...
expr_op_iterator expr_op_end() const
LLVM_ABI bool isImplicit() const
Return whether this is an implicit location description.
DEFINE_MDNODE_GET(DIExpression,(ArrayRef< uint64_t > Elements),(Elements)) TempDIExpression clone() const
static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B)
Check if fragments overlap between a pair of FragmentInfos.
static LLVM_ABI bool calculateFragmentIntersect(const DataLayout &DL, const Value *SliceStart, uint64_t SliceOffsetInBits, uint64_t SliceSizeInBits, const Value *DbgPtr, int64_t DbgPtrOffsetInBits, int64_t DbgExtractOffsetInBits, DIExpression::FragmentInfo VarFrag, std::optional< DIExpression::FragmentInfo > &Result, int64_t &OffsetFromLocationInBits)
Computes a fragment, bit-extract operation if needed, and new constant offset to describe a part of a...
element_iterator elements_begin() const
LLVM_ABI bool hasAllLocationOps(unsigned N) const
Returns true iff this DIExpression contains at least one instance of DW_OP_LLVM_arg,...
std::optional< FragmentInfo > getFragmentInfo() const
Retrieve the details of this fragment expression.
static LLVM_ABI DIExpression * appendOpsToArg(const DIExpression *Expr, ArrayRef< uint64_t > Ops, unsigned ArgNo, bool StackValue=false)
Create a copy of Expr by appending the given list of Ops to each instance of the operand DW_OP_LLVM_a...
PrependOps
Used for DIExpression::prepend.
static int fragmentCmp(const FragmentInfo &A, const FragmentInfo &B)
Determine the relative position of the fragments passed in.
LLVM_ABI bool isComplex() const
Return whether the location is computed on the expression stack, meaning it cannot be a simple regist...
bool fragmentsOverlap(const DIExpression *Other) const
Check if fragments overlap between this DIExpression and Other.
LLVM_ABI DIExpression * foldConstantMath()
Try to shorten an expression with constant math operations that can be evaluated at compile time.
static LLVM_ABI std::optional< const DIExpression * > convertToNonVariadicExpression(const DIExpression *Expr)
If Expr is a valid single-location expression, i.e.
LLVM_ABI std::pair< DIExpression *, const ConstantInt * > constantFold(const ConstantInt *CI)
Try to shorten an expression with an initial constant operand.
LLVM_ABI bool isDeref() const
Return whether there is exactly one operator and it is a DW_OP_deref;.
static LLVM_ABI const DIExpression * convertToVariadicExpression(const DIExpression *Expr)
If Expr is a non-variadic expression (i.e.
LLVM_ABI uint64_t getNumLocationOperands() const
Return the number of unique location operands referred to (via DW_OP_LLVM_arg) in this expression; th...
ArrayRef< uint64_t > getElements() const
static LLVM_ABI DIExpression * replaceArg(const DIExpression *Expr, uint64_t OldArg, uint64_t NewArg)
Create a copy of Expr with each instance of DW_OP_LLVM_arg, \p OldArg replaced with DW_OP_LLVM_arg,...
static bool classof(const Metadata *MD)
LLVM_ABI std::optional< uint64_t > getActiveBits(DIVariable *Var)
Return the number of bits that have an active value, i.e.
static LLVM_ABI void canonicalizeExpressionOps(SmallVectorImpl< uint64_t > &Ops, const DIExpression *Expr, bool IsIndirect)
Inserts the elements of Expr into Ops modified to a canonical form, which uses DW_OP_LLVM_arg (i....
uint64_t getElement(unsigned I) const
static LLVM_ABI 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 bool extractLeadingOffset(int64_t &OffsetInBytes, SmallVectorImpl< uint64_t > &RemainingOps) const
Assuming that the expression operates on an address, extract a constant offset and the successive ops...
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
unsigned StringRef uint64_t uint32_t unsigned DIFlags unsigned int Factor
static LLVM_ABI std::optional< FixedPointKind > getFixedPointKind(StringRef Str)
static LLVM_ABI const char * fixedPointKindString(FixedPointKind)
const APInt & getNumeratorRaw() const
unsigned StringRef uint64_t uint32_t unsigned Encoding
static bool classof(const Metadata *MD)
const APInt & getDenominator() const
unsigned StringRef uint64_t uint32_t AlignInBits
LLVM_ABI bool isSigned() const
@ FixedPointBinary
Scale factor 2^Factor.
@ FixedPointDecimal
Scale factor 10^Factor.
@ FixedPointRational
Arbitrary rational scale factor.
FixedPointKind getKind() const
const APInt & getNumerator() const
DEFINE_MDNODE_GET(DIFixedPointType,(unsigned Tag, MDString *Name, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, DIFlags Flags, unsigned Kind, int Factor, APInt Numerator, APInt Denominator),(Tag, Name, SizeInBits, AlignInBits, Encoding, Flags, Kind, Factor, Numerator, Denominator)) DEFINE_MDNODE_GET(DIFixedPointType
unsigned StringRef uint64_t uint32_t unsigned DIFlags unsigned int APInt Numerator
unsigned StringRef uint64_t uint32_t unsigned DIFlags unsigned int APInt APInt Denominator
unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags
unsigned StringRef uint64_t SizeInBits
const APInt & getDenominatorRaw() const
Metadata * getRawLowerBound() const
Metadata * getRawCountNode() const
Metadata * getRawStride() const
LLVM_ABI BoundType getLowerBound() const
DEFINE_MDNODE_GET(DIGenericSubrange,(Metadata *CountNode, Metadata *LowerBound, Metadata *UpperBound, Metadata *Stride),(CountNode, LowerBound, UpperBound, Stride)) TempDIGenericSubrange clone() const
Metadata * getRawUpperBound() const
static bool classof(const Metadata *MD)
LLVM_ABI BoundType getCount() const
LLVM_ABI BoundType getUpperBound() const
PointerUnion< DIVariable *, DIExpression * > BoundType
LLVM_ABI BoundType getStride() const
A pair of DIGlobalVariable and DIExpression.
DEFINE_MDNODE_GET(DIGlobalVariableExpression,(Metadata *Variable, Metadata *Expression),(Variable, Expression)) TempDIGlobalVariableExpression clone() const
DIGlobalVariable * getVariable() const
static bool classof(const Metadata *MD)
Metadata * getRawAnnotations() const
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata Metadata * TemplateParams
Metadata MDString MDString Metadata unsigned Metadata bool bool IsDefinition
Metadata MDString MDString Metadata unsigned Line
Metadata MDString MDString Metadata unsigned Metadata * Type
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata Metadata uint32_t Metadata * Annotations
DIDerivedType * getStaticDataMemberDeclaration() const
DEFINE_MDNODE_GET(DIGlobalVariable,(DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, unsigned Line, DIType *Type, bool IsLocalToUnit, bool IsDefinition, DIDerivedType *StaticDataMemberDeclaration, MDTuple *TemplateParams, uint32_t AlignInBits, DINodeArray Annotations),(Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, StaticDataMemberDeclaration, TemplateParams, AlignInBits, Annotations)) DEFINE_MDNODE_GET(DIGlobalVariable
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata Metadata uint32_t Metadata Annotations TempDIGlobalVariable clone() const
Metadata MDString * Name
MDTuple * getTemplateParams() const
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata * StaticDataMemberDeclaration
Metadata * getRawStaticDataMemberDeclaration() const
Metadata MDString MDString * LinkageName
MDString * getRawLinkageName() const
StringRef getLinkageName() const
static bool classof(const Metadata *MD)
StringRef getDisplayName() const
Metadata MDString MDString Metadata * File
DINodeArray getAnnotations() const
Metadata MDString MDString Metadata unsigned Metadata bool IsLocalToUnit
Metadata * getRawTemplateParams() const
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata Metadata uint32_t AlignInBits
An imported module (C++ using directive or similar).
unsigned Metadata Metadata * Entity
DEFINE_MDNODE_GET(DIImportedEntity,(unsigned Tag, DIScope *Scope, DINode *Entity, DIFile *File, unsigned Line, StringRef Name="", DINodeArray Elements=nullptr),(Tag, Scope, Entity, File, Line, Name, Elements)) DEFINE_MDNODE_GET(DIImportedEntity
unsigned Metadata Metadata Metadata unsigned Line
unsigned Metadata Metadata Metadata unsigned MDString * Name
unsigned Metadata Metadata Metadata * File
unsigned Metadata * Scope
Metadata MDString Metadata unsigned unsigned bool std::optional< unsigned > CoroSuspendIdx
DIFile * getFile() const
Metadata MDString Metadata unsigned unsigned bool std::optional< unsigned > CoroSuspendIdx TempDILabel clone() const
StringRef getName() const
static bool classof(const Metadata *MD)
Metadata MDString Metadata unsigned unsigned Column
unsigned getLine() const
bool isArtificial() const
Metadata MDString Metadata unsigned unsigned bool IsArtificial
Metadata * getRawFile() const
unsigned getColumn() const
DILocalScope * getScope() const
Get the local scope for this label.
MDString * getRawName() const
std::optional< unsigned > getCoroSuspendIdx() const
Metadata MDString Metadata unsigned Line
Metadata MDString * Name
DEFINE_MDNODE_GET(DILabel,(DILocalScope *Scope, StringRef Name, DIFile *File, unsigned Line, unsigned Column, bool IsArtificial, std::optional< unsigned > CoroSuspendIdx),(Scope, Name, File, Line, Column, IsArtificial, CoroSuspendIdx)) DEFINE_MDNODE_GET(DILabel
friend class LLVMContextImpl
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this label.
Metadata * getRawScope() const
friend class MDNode
Metadata MDString Metadata * File
static bool classof(const Metadata *MD)
void replaceScope(DIScope *Scope)
Metadata * getRawScope() const
LLVM_ABI DILexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage, ArrayRef< Metadata * > Ops)
DILocalScope * getScope() const
Metadata Metadata unsigned Discriminator
static bool classof(const Metadata *MD)
unsigned getDiscriminator() const
Metadata Metadata unsigned Discriminator TempDILexicalBlockFile clone() const
DEFINE_MDNODE_GET(DILexicalBlockFile,(DILocalScope *Scope, DIFile *File, unsigned Discriminator),(Scope, File, Discriminator)) DEFINE_MDNODE_GET(DILexicalBlockFile
Debug lexical block.
Metadata Metadata unsigned unsigned Column
Metadata Metadata unsigned Line
DEFINE_MDNODE_GET(DILexicalBlock,(DILocalScope *Scope, DIFile *File, unsigned Line, unsigned Column),(Scope, File, Line, Column)) DEFINE_MDNODE_GET(DILexicalBlock
static bool classof(const Metadata *MD)
Metadata Metadata * File
unsigned getColumn() const
Metadata Metadata unsigned unsigned Column TempDILexicalBlock clone() const
A scope for locals.
LLVM_ABI DISubprogram * getSubprogram() const
Get the subprogram for this scope.
LLVM_ABI DILocalScope * getNonLexicalBlockFileScope() const
Get the first non DILexicalBlockFile scope of this scope.
~DILocalScope()=default
DILocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, ArrayRef< Metadata * > Ops)
static bool classof(const Metadata *MD)
static LLVM_ABI DILocalScope * cloneScopeForSubprogram(DILocalScope &RootScope, DISubprogram &NewSP, LLVMContext &Ctx, DenseMap< const MDNode *, MDNode * > &Cache)
Traverses the scope chain rooted at RootScope until it hits a Subprogram, recreating the chain with "...
Metadata MDString Metadata unsigned Metadata * Type
Metadata MDString Metadata * File
static bool classof(const Metadata *MD)
Metadata MDString Metadata unsigned Metadata unsigned DIFlags uint32_t Metadata Annotations TempDILocalVariable clone() const
DILocalScope * getScope() const
Get the local scope for this variable.
Metadata MDString * Name
Metadata MDString Metadata unsigned Metadata unsigned Arg
DINodeArray getAnnotations() const
DEFINE_MDNODE_GET(DILocalVariable,(DILocalScope *Scope, StringRef Name, DIFile *File, unsigned Line, DIType *Type, unsigned Arg, DIFlags Flags, uint32_t AlignInBits, DINodeArray Annotations),(Scope, Name, File, Line, Type, Arg, Flags, AlignInBits, Annotations)) DEFINE_MDNODE_GET(DILocalVariable
Metadata MDString Metadata unsigned Line
Metadata MDString Metadata unsigned Metadata unsigned DIFlags uint32_t Metadata * Annotations
Metadata MDString Metadata unsigned Metadata unsigned DIFlags uint32_t AlignInBits
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this variable.
Metadata * getRawAnnotations() const
unsigned unsigned DILocalScope * Scope
const DILocation * getWithoutAtom() const
static unsigned getDuplicationFactorFromDiscriminator(unsigned D)
Returns the duplication factor for a given encoded discriminator D, or 1 if no value or 0 is encoded.
static bool isPseudoProbeDiscriminator(unsigned Discriminator)
unsigned unsigned DILocalScope DILocation bool uint64_t AtomGroup
unsigned getDuplicationFactor() const
Returns the duplication factor stored in the discriminator, or 1 if no duplication factor (or 0) is e...
uint64_t getAtomGroup() const
static LLVM_ABI DILocation * getMergedLocations(ArrayRef< DILocation * > Locs)
Try to combine the vector of locations passed as input in a single one.
static unsigned getBaseDiscriminatorBits()
Return the bits used for base discriminators.
static LLVM_ABI std::optional< unsigned > encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI)
Raw encoding of the discriminator.
unsigned unsigned DILocalScope DILocation bool ImplicitCode
Metadata * getRawScope() const
static LLVM_ABI void decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF, unsigned &CI)
Raw decoder for values in an encoded discriminator D.
static LLVM_ABI DILocation * getMergedLocation(DILocation *LocA, DILocation *LocB)
Attempts to merge LocA and LocB into a single location; see DebugLoc::getMergedLocation for more deta...
std::optional< const DILocation * > cloneWithBaseDiscriminator(unsigned BD) const
Returns a new DILocation with updated base discriminator BD.
unsigned getBaseDiscriminator() const
Returns the base discriminator stored in the discriminator.
static unsigned getBaseDiscriminatorFromDiscriminator(unsigned D, bool IsFSDiscriminator=false)
Returns the base discriminator for a given encoded discriminator D.
unsigned unsigned Column
Metadata * getRawInlinedAt() const
unsigned unsigned DILocalScope DILocation * InlinedAt
friend class LLVMContextImpl
static unsigned getMaskedDiscriminator(unsigned D, unsigned B)
Return the masked discriminator value for an input discrimnator value D (i.e.
const DILocation * cloneWithDiscriminator(unsigned Discriminator) const
Returns a new DILocation with updated Discriminator.
static unsigned getCopyIdentifierFromDiscriminator(unsigned D)
Returns the copy identifier for a given encoded discriminator D.
uint8_t getAtomRank() const
DEFINE_MDNODE_GET(DILocation,(unsigned Line, unsigned Column, Metadata *Scope, Metadata *InlinedAt=nullptr, bool ImplicitCode=false, uint64_t AtomGroup=0, uint8_t AtomRank=0),(Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup, AtomRank)) DEFINE_MDNODE_GET(DILocation
void replaceOperandWith(unsigned I, Metadata *New)=delete
std::optional< const DILocation * > cloneByMultiplyingDuplicationFactor(unsigned DF) const
Returns a new DILocation with duplication factor DF * current duplication factor encoded in the discr...
static bool classof(const Metadata *MD)
unsigned getCopyIdentifier() const
Returns the copy identifier stored in the discriminator.
unsigned unsigned DILocalScope DILocation bool uint64_t uint8_t AtomRank
unsigned unsigned Metadata * File
Metadata * getRawElements() const
DEFINE_MDNODE_GET(DIMacroFile,(unsigned MIType, unsigned Line, DIFile *File, DIMacroNodeArray Elements),(MIType, Line, File, Elements)) DEFINE_MDNODE_GET(DIMacroFile
unsigned unsigned Line
DIFile * getFile() const
unsigned getLine() const
unsigned unsigned Metadata Metadata * Elements
Metadata * getRawFile() const
static bool classof(const Metadata *MD)
friend class LLVMContextImpl
void replaceElements(DIMacroNodeArray Elements)
unsigned unsigned Metadata Metadata Elements TempDIMacroFile clone() const
DIMacroNodeArray getElements() const
DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType, ArrayRef< Metadata * > Ops1, ArrayRef< Metadata * > Ops2={})
unsigned getMacinfoType() const
StringRef getStringOperand(unsigned I) const
static bool classof(const Metadata *MD)
static MDString * getCanonicalMDString(LLVMContext &Context, StringRef S)
friend class LLVMContextImpl
Ty * getOperandAs(unsigned I) const
~DIMacroNode()=default
unsigned getLine() const
MDString * getRawName() const
unsigned unsigned MDString MDString Value TempDIMacro clone() const
unsigned unsigned MDString MDString * Value
unsigned unsigned MDString * Name
StringRef getName() const
MDString * getRawValue() const
unsigned unsigned Line
friend class LLVMContextImpl
DEFINE_MDNODE_GET(DIMacro,(unsigned MIType, unsigned Line, StringRef Name, StringRef Value=""),(MIType, Line, Name, Value)) DEFINE_MDNODE_GET(DIMacro
friend class MDNode
StringRef getValue() const
static bool classof(const Metadata *MD)
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
Metadata Metadata * Scope
Metadata Metadata MDString * Name
Metadata Metadata MDString MDString MDString MDString * APINotesFile
Metadata Metadata MDString MDString MDString * IncludePath
Metadata Metadata MDString MDString * ConfigurationMacros
friend class LLVMContextImpl
DEFINE_MDNODE_GET(DIModule,(DIFile *File, DIScope *Scope, StringRef Name, StringRef ConfigurationMacros, StringRef IncludePath, StringRef APINotesFile, unsigned LineNo, bool IsDecl=false),(File, Scope, Name, ConfigurationMacros, IncludePath, APINotesFile, LineNo, IsDecl)) DEFINE_MDNODE_GET(DIModule
Metadata Metadata MDString MDString MDString MDString unsigned LineNo
Debug lexical block.
Metadata MDString bool ExportSymbols TempDINamespace clone() const
static bool classof(const Metadata *MD)
DEFINE_MDNODE_GET(DINamespace,(DIScope *Scope, StringRef Name, bool ExportSymbols),(Scope, Name, ExportSymbols)) DEFINE_MDNODE_GET(DINamespace
DIScope * getScope() const
Metadata MDString bool ExportSymbols
StringRef getName() const
MDString * getRawName() const
Metadata MDString * Name
friend class LLVMContextImpl
bool getExportSymbols() const
Metadata * getRawScope() const
Tagged DWARF-like metadata node.
LLVM_ABI dwarf::Tag getTag() const
static MDString * getCanonicalMDString(LLVMContext &Context, StringRef S)
static LLVM_ABI DIFlags getFlag(StringRef Flag)
static LLVM_ABI DIFlags splitFlags(DIFlags Flags, SmallVectorImpl< DIFlags > &SplitFlags)
Split up a flags bitfield.
void setTag(unsigned Tag)
Allow subclasses to mutate the tag.
DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, ArrayRef< Metadata * > Ops1, ArrayRef< Metadata * > Ops2={})
StringRef getStringOperand(unsigned I) const
Ty * getOperandAs(unsigned I) const
friend class LLVMContextImpl
static bool classof(const Metadata *MD)
static LLVM_ABI StringRef getFlagString(DIFlags Flag)
friend class MDNode
~DINode()=default
DIFlags
Debug info flags.
MDString Metadata unsigned MDString MDString unsigned Metadata Type TempDIObjCProperty clone() const
unsigned getAttributes() const
StringRef getFilename() const
MDString * getRawName() const
StringRef getDirectory() const
MDString * getRawSetterName() const
Metadata * getRawType() const
StringRef getGetterName() const
MDString Metadata * File
MDString Metadata unsigned MDString MDString unsigned Metadata * Type
static bool classof(const Metadata *MD)
MDString * getRawGetterName() const
Metadata * getRawFile() const
MDString Metadata unsigned MDString * GetterName
MDString Metadata unsigned MDString MDString * SetterName
StringRef getName() const
DEFINE_MDNODE_GET(DIObjCProperty,(StringRef Name, DIFile *File, unsigned Line, StringRef GetterName, StringRef SetterName, unsigned Attributes, DIType *Type),(Name, File, Line, GetterName, SetterName, Attributes, Type)) DEFINE_MDNODE_GET(DIObjCProperty
StringRef getSetterName() const
Base class for scope-like contexts.
~DIScope()=default
StringRef getFilename() const
LLVM_ABI StringRef getName() const
static bool classof(const Metadata *MD)
DIFile * getFile() const
StringRef getDirectory() const
std::optional< StringRef > getSource() const
LLVM_ABI DIScope * getScope() const
Metadata * getRawFile() const
Return the raw underlying file.
DIScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, ArrayRef< Metadata * > Ops)
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
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
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)
Metadata MDString * Name
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata * ThrownTypes
DEFINE_MDNODE_GET(DISubprogram,(DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, unsigned Line, DISubroutineType *Type, unsigned ScopeLine, DIType *ContainingType, unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit, DITemplateParameterArray TemplateParams=nullptr, DISubprogram *Declaration=nullptr, DINodeArray RetainedNodes=nullptr, DITypeArray ThrownTypes=nullptr, DINodeArray Annotations=nullptr, StringRef TargetFuncName="", bool UsesKeyInstructions=false),(Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType, VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams, Declaration, RetainedNodes, ThrownTypes, Annotations, TargetFuncName, UsesKeyInstructions)) DEFINE_MDNODE_GET(DISubprogram
static LLVM_ABI DISPFlags getFlag(StringRef Flag)
Metadata MDString MDString Metadata * File
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned VirtualIndex
static LLVM_ABI DISPFlags splitFlags(DISPFlags Flags, SmallVectorImpl< DISPFlags > &SplitFlags)
Split up a flags bitfield for easier printing.
static bool classof(const Metadata *MD)
Metadata MDString MDString * LinkageName
static LLVM_ABI StringRef getFlagString(DISPFlags Flag)
Metadata MDString MDString Metadata unsigned Metadata * Type
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata * RetainedNodes
DISPFlags
Debug info subprogram flags.
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int ThisAdjustment
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
PointerUnion< ConstantInt *, DIVariable *, DIExpression * > BoundType
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
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.
TempDISubroutineType cloneWithCC(uint8_t CC) const
DEFINE_MDNODE_GET(DISubroutineType,(DIFlags Flags, uint8_t CC, DITypeRefArray TypeArray),(Flags, CC, TypeArray)) DEFINE_MDNODE_GET(DISubroutineType
DIFlags uint8_t Metadata * TypeArray
static bool classof(const Metadata *MD)
Metadata * getRawTypeArray() const
DITypeRefArray getTypeArray() 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
bool operator!=(const iterator &X) const
bool operator==(const iterator &X) const
std::input_iterator_tag iterator_category
iterator(MDNode::op_iterator I)
DIType * operator[](unsigned I) const
MDTuple & operator*() const
DITypeRefArray()=default
MDTuple * operator->() const
MDTuple * get() const
DITypeRefArray(const MDTuple *N)
unsigned size() const
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:63
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:1078
friend class DIAssignID
Definition Metadata.h:1081
LLVM_ABI void replaceOperandWith(unsigned I, Metadata *New)
Replace a specific operand.
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1442
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1581
op_iterator op_end() const
Definition Metadata.h:1436
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1569
bool isUniqued() const
Definition Metadata.h:1260
unsigned getNumOperands() const
Return number of MDNode operands.
Definition Metadata.h:1448
iterator_range< op_iterator > op_range
Definition Metadata.h:1430
LLVM_ABI TempMDNode clone() const
Create a (temporary) clone of this.
Definition Metadata.cpp:669
bool isDistinct() const
Definition Metadata.h:1261
LLVM_ABI void setOperand(unsigned I, Metadata *New)
Set an operand.
op_iterator op_begin() const
Definition Metadata.h:1432
LLVMContext & getContext() const
Definition Metadata.h:1242
LLVM_ABI void dropAllReferences()
Definition Metadata.cpp:909
const MDOperand * op_iterator
Definition Metadata.h:1429
Tracking metadata reference owned by Metadata.
Definition Metadata.h:900
Metadata * get() const
Definition Metadata.h:929
A single uniqued string.
Definition Metadata.h:721
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
Definition Metadata.cpp:608
Tuple of metadata.
Definition Metadata.h:1497
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 bit of the poin...
LLVM_ABI SmallVector< DbgVariableRecord * > getAllDbgVariableRecordUsers()
Returns the list of all DbgVariableRecord users of this.
Definition Metadata.cpp:273
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.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:143
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:298
LLVM Value Representation.
Definition Value.h:75
A range adaptor for a pair of iterators.
LLVM_ABI unsigned getVirtuality(StringRef VirtualityString)
Definition Dwarf.cpp:385
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
template class LLVM_TEMPLATE_ABI opt< bool >
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:477
bool operator<(int64_t V1, const APSInt &V2)
Definition APSInt.h:362
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:644
bool operator!=(uint64_t V1, const APInt &V2)
Definition APInt.h:2113
auto cast_or_null(const Y &Val)
Definition Casting.h:715
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:754
LLVM_ABI cl::opt< bool > EnableFSDiscriminator
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
static unsigned getBaseFSBitEnd()
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:548
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
@ Ref
The access may reference the value stored in memory.
Definition ModRef.h:32
@ LLVM_MARK_AS_BITMASK_ENUM
Definition ModRef.h:37
@ Other
Any other memory.
Definition ModRef.h:68
static unsigned getN1Bits(int N)
FunctionAddr VTableAddr Next
Definition InstrProf.h:141
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:560
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1899
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition Hashing.h:592
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:867
#define N
Pointer authentication (__ptrauth) metadata.
PtrAuthData(unsigned Key, bool IsDiscr, unsigned Discriminator, bool IsaPointer, bool AuthenticatesNullValues)
A single checksum, represented by a Kind and a Value (a string).
bool operator==(const ChecksumInfo< T > &X) const
T Value
The string value of the checksum.
ChecksumKind Kind
The kind of checksum which Value encodes.
ChecksumInfo(ChecksumKind Kind, T Value)
bool operator!=(const ChecksumInfo< T > &X) const
StringRef getKindAsString() const
static bool isEqual(const FragInfo &A, const FragInfo &B)
static unsigned getHashValue(const FragInfo &Frag)
static unsigned getHashValue(const DebugVariable &D)
static DebugVariable getEmptyKey()
Empty key: no key should be generated that has no DILocalVariable.
DIExpression::FragmentInfo FragmentInfo
static DebugVariable getTombstoneKey()
Difference in tombstone is that the Optional is meaningful.
static bool isEqual(const DebugVariable &A, const DebugVariable &B)
An information struct used to provide DenseMap with the various necessary components for a given valu...
static uint32_t extractProbeIndex(uint32_t Value)
Definition PseudoProbe.h:75
static std::optional< uint32_t > extractDwarfBaseDiscriminator(uint32_t Value)
Definition PseudoProbe.h:81