Thanks to visit codestin.com
Credit goes to llvm.org

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
69/// Wrapper structure that holds a language name and its version.
70///
71/// Some debug-info formats, particularly DWARF, distniguish between
72/// language codes that include the version name and codes that don't.
73/// DISourceLanguageName may hold either of these.
74///
76 /// Language version. The version scheme is language
77 /// dependent.
78 uint32_t Version = 0;
79
80 /// Language name.
81 /// If \ref HasVersion is \c true, then this name
82 /// is version independent (i.e., doesn't include the language
83 /// version in its name).
84 uint16_t Name;
85
86 /// If \c true, then \ref Version is interpretable and \ref Name
87 /// is a version independent name.
88 bool HasVersion;
89
90public:
91 bool hasVersionedName() const { return HasVersion; }
92
93 /// Returns a versioned or unversioned language name.
94 uint16_t getName() const { return Name; }
95
96 /// Transitional API for cases where we do not yet support
97 /// versioned source language names. Use \ref getName instead.
98 ///
99 /// FIXME: remove once all callers of this API account for versioned
100 /// names.
103 return Name;
104 }
105
106 /// Returns language version. Only valid for versioned language names.
109 return Version;
110 }
111
113 : Version(Version), Name(Lang), HasVersion(true) {};
115 : Version(0), Name(Lang), HasVersion(false) {};
116};
117
118class DbgVariableRecord;
119
121
123 const MDTuple *N = nullptr;
124
125public:
126 DITypeRefArray() = default;
127 DITypeRefArray(const MDTuple *N) : N(N) {}
128
129 explicit operator bool() const { return get(); }
130 explicit operator MDTuple *() const { return get(); }
131
132 MDTuple *get() const { return const_cast<MDTuple *>(N); }
133 MDTuple *operator->() const { return get(); }
134 MDTuple &operator*() const { return *get(); }
135
136 // FIXME: Fix callers and remove condition on N.
137 unsigned size() const { return N ? N->getNumOperands() : 0u; }
138 DIType *operator[](unsigned I) const {
139 return cast_or_null<DIType>(N->getOperand(I));
140 }
141
142 class iterator {
143 MDNode::op_iterator I = nullptr;
144
145 public:
146 using iterator_category = std::input_iterator_tag;
148 using difference_type = std::ptrdiff_t;
149 using pointer = void;
150 using reference = DIType *;
151
152 iterator() = default;
153 explicit iterator(MDNode::op_iterator I) : I(I) {}
154
155 DIType *operator*() const { return cast_or_null<DIType>(*I); }
156
158 ++I;
159 return *this;
160 }
161
163 iterator Temp(*this);
164 ++I;
165 return Temp;
166 }
167
168 bool operator==(const iterator &X) const { return I == X.I; }
169 bool operator!=(const iterator &X) const { return I != X.I; }
170 };
171
172 // FIXME: Fix callers and remove condition on N.
173 iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); }
174 iterator end() const { return N ? iterator(N->op_end()) : iterator(); }
175};
176
177/// Tagged DWARF-like metadata node.
178///
179/// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
180/// defined in llvm/BinaryFormat/Dwarf.h). Called \a DINode because it's
181/// potentially used for non-DWARF output.
182///
183/// Uses the SubclassData16 Metadata slot.
184class DINode : public MDNode {
185 friend class LLVMContextImpl;
186 friend class MDNode;
187
188protected:
189 DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
191 : MDNode(C, ID, Storage, Ops1, Ops2) {
192 assert(Tag < 1u << 16);
194 }
195 ~DINode() = default;
196
197 template <class Ty> Ty *getOperandAs(unsigned I) const {
199 }
200
201 StringRef getStringOperand(unsigned I) const {
202 if (auto *S = getOperandAs<MDString>(I))
203 return S->getString();
204 return StringRef();
205 }
206
208 if (S.empty())
209 return nullptr;
210 return MDString::get(Context, S);
211 }
212
213 /// Allow subclasses to mutate the tag.
214 void setTag(unsigned Tag) { SubclassData16 = Tag; }
215
216public:
217 LLVM_ABI dwarf::Tag getTag() const;
218
219 /// Debug info flags.
220 ///
221 /// The three accessibility flags are mutually exclusive and rolled together
222 /// in the first two bits.
224#define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
225#define DI_FLAG_LARGEST_NEEDED
226#include "llvm/IR/DebugInfoFlags.def"
227 FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic,
228 FlagPtrToMemberRep = FlagSingleInheritance | FlagMultipleInheritance |
229 FlagVirtualInheritance,
230 LLVM_MARK_AS_BITMASK_ENUM(FlagLargest)
231 };
232
233 LLVM_ABI static DIFlags getFlag(StringRef Flag);
234 LLVM_ABI static StringRef getFlagString(DIFlags Flag);
235
236 /// Split up a flags bitfield.
237 ///
238 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
239 /// any remaining (unrecognized) bits.
240 LLVM_ABI static DIFlags splitFlags(DIFlags Flags,
241 SmallVectorImpl<DIFlags> &SplitFlags);
242
243 static bool classof(const Metadata *MD) {
244 switch (MD->getMetadataID()) {
245 default:
246 return false;
247 case GenericDINodeKind:
248 case DISubrangeKind:
249 case DIEnumeratorKind:
250 case DIBasicTypeKind:
251 case DIFixedPointTypeKind:
252 case DIStringTypeKind:
253 case DISubrangeTypeKind:
254 case DIDerivedTypeKind:
255 case DICompositeTypeKind:
256 case DISubroutineTypeKind:
257 case DIFileKind:
258 case DICompileUnitKind:
259 case DISubprogramKind:
260 case DILexicalBlockKind:
261 case DILexicalBlockFileKind:
262 case DINamespaceKind:
263 case DICommonBlockKind:
264 case DITemplateTypeParameterKind:
265 case DITemplateValueParameterKind:
266 case DIGlobalVariableKind:
267 case DILocalVariableKind:
268 case DILabelKind:
269 case DIObjCPropertyKind:
270 case DIImportedEntityKind:
271 case DIModuleKind:
272 case DIGenericSubrangeKind:
273 case DIAssignIDKind:
274 return true;
275 }
276 }
277};
278
279/// Generic tagged DWARF-like metadata node.
280///
281/// An un-specialized DWARF-like metadata node. The first operand is a
282/// (possibly empty) null-separated \a MDString header that contains arbitrary
283/// fields. The remaining operands are \a dwarf_operands(), and are pointers
284/// to other metadata.
285///
286/// Uses the SubclassData32 Metadata slot.
287class GenericDINode : public DINode {
288 friend class LLVMContextImpl;
289 friend class MDNode;
290
291 GenericDINode(LLVMContext &C, StorageType Storage, unsigned Hash,
292 unsigned Tag, ArrayRef<Metadata *> Ops1,
294 : DINode(C, GenericDINodeKind, Storage, Tag, Ops1, Ops2) {
295 setHash(Hash);
296 }
298
299 void setHash(unsigned Hash) { SubclassData32 = Hash; }
300 void recalculateHash();
301
302 static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
304 StorageType Storage, bool ShouldCreate = true) {
305 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
306 DwarfOps, Storage, ShouldCreate);
307 }
308
309 LLVM_ABI static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
310 MDString *Header,
313 bool ShouldCreate = true);
314
315 TempGenericDINode cloneImpl() const {
318 }
319
320public:
321 unsigned getHash() const { return SubclassData32; }
322
323 DEFINE_MDNODE_GET(GenericDINode,
324 (unsigned Tag, StringRef Header,
326 (Tag, Header, DwarfOps))
327 DEFINE_MDNODE_GET(GenericDINode,
328 (unsigned Tag, MDString *Header,
331
332 /// Return a (temporary) clone of this.
333 TempGenericDINode clone() const { return cloneImpl(); }
334
335 LLVM_ABI dwarf::Tag getTag() const;
336 StringRef getHeader() const { return getStringOperand(0); }
338
339 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
340 op_iterator dwarf_op_end() const { return op_end(); }
343 }
344
345 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
346 const MDOperand &getDwarfOperand(unsigned I) const {
347 return getOperand(I + 1);
348 }
349 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
350 replaceOperandWith(I + 1, New);
351 }
352
353 static bool classof(const Metadata *MD) {
354 return MD->getMetadataID() == GenericDINodeKind;
355 }
356};
357
358/// Assignment ID.
359/// Used to link stores (as an attachment) and dbg.assigns (as an operand).
360/// DIAssignID metadata is never uniqued as we compare instances using
361/// referential equality (the instance/address is the ID).
362class DIAssignID : public MDNode {
363 friend class LLVMContextImpl;
364 friend class MDNode;
365
367 : MDNode(C, DIAssignIDKind, Storage, {}) {}
368
369 ~DIAssignID() { dropAllReferences(); }
370
371 LLVM_ABI static DIAssignID *getImpl(LLVMContext &Context, StorageType Storage,
372 bool ShouldCreate = true);
373
374 TempDIAssignID cloneImpl() const { return getTemporary(getContext()); }
375
376public:
377 // This node has no operands to replace.
378 void replaceOperandWith(unsigned I, Metadata *New) = delete;
379
381 return Context.getReplaceableUses()->getAllDbgVariableRecordUsers();
382 }
383
384 static DIAssignID *getDistinct(LLVMContext &Context) {
385 return getImpl(Context, Distinct);
386 }
387 static TempDIAssignID getTemporary(LLVMContext &Context) {
388 return TempDIAssignID(getImpl(Context, Temporary));
389 }
390 // NOTE: Do not define get(LLVMContext&) - see class comment.
391
392 static bool classof(const Metadata *MD) {
393 return MD->getMetadataID() == DIAssignIDKind;
394 }
395};
396
397/// Array subrange.
398class DISubrange : public DINode {
399 friend class LLVMContextImpl;
400 friend class MDNode;
401
403
404 ~DISubrange() = default;
405
406 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, int64_t Count,
408 bool ShouldCreate = true);
409
410 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, Metadata *CountNode,
412 bool ShouldCreate = true);
413
414 LLVM_ABI static DISubrange *getImpl(LLVMContext &Context, Metadata *CountNode,
416 Metadata *UpperBound, Metadata *Stride,
418 bool ShouldCreate = true);
419
420 TempDISubrange cloneImpl() const {
421 return getTemporary(getContext(), getRawCountNode(), getRawLowerBound(),
422 getRawUpperBound(), getRawStride());
423 }
424
425public:
426 DEFINE_MDNODE_GET(DISubrange, (int64_t Count, int64_t LowerBound = 0),
427 (Count, LowerBound))
428
429 DEFINE_MDNODE_GET(DISubrange, (Metadata * CountNode, int64_t LowerBound = 0),
431
432 DEFINE_MDNODE_GET(DISubrange,
434 Metadata *UpperBound, Metadata *Stride),
435 (CountNode, LowerBound, UpperBound, Stride))
436
437 TempDISubrange clone() const { return cloneImpl(); }
438
439 Metadata *getRawCountNode() const { return getOperand(0).get(); }
440
441 Metadata *getRawLowerBound() const { return getOperand(1).get(); }
442
443 Metadata *getRawUpperBound() const { return getOperand(2).get(); }
444
445 Metadata *getRawStride() const { return getOperand(3).get(); }
446
447 typedef PointerUnion<ConstantInt *, DIVariable *, DIExpression *> BoundType;
448
449 LLVM_ABI BoundType getCount() const;
450
451 LLVM_ABI BoundType getLowerBound() const;
452
453 LLVM_ABI BoundType getUpperBound() const;
454
455 LLVM_ABI BoundType getStride() const;
456
457 static bool classof(const Metadata *MD) {
458 return MD->getMetadataID() == DISubrangeKind;
459 }
460};
461
462class DIGenericSubrange : public DINode {
463 friend class LLVMContextImpl;
464 friend class MDNode;
465
466 DIGenericSubrange(LLVMContext &C, StorageType Storage,
468
469 ~DIGenericSubrange() = default;
470
471 LLVM_ABI static DIGenericSubrange *
472 getImpl(LLVMContext &Context, Metadata *CountNode, Metadata *LowerBound,
473 Metadata *UpperBound, Metadata *Stride, StorageType Storage,
474 bool ShouldCreate = true);
475
476 TempDIGenericSubrange cloneImpl() const {
479 }
480
481public:
482 DEFINE_MDNODE_GET(DIGenericSubrange,
483 (Metadata * CountNode, Metadata *LowerBound,
484 Metadata *UpperBound, Metadata *Stride),
485 (CountNode, LowerBound, UpperBound, Stride))
486
487 TempDIGenericSubrange clone() const { return cloneImpl(); }
488
489 Metadata *getRawCountNode() const { return getOperand(0).get(); }
490 Metadata *getRawLowerBound() const { return getOperand(1).get(); }
491 Metadata *getRawUpperBound() const { return getOperand(2).get(); }
492 Metadata *getRawStride() const { return getOperand(3).get(); }
493
495
500
501 static bool classof(const Metadata *MD) {
502 return MD->getMetadataID() == DIGenericSubrangeKind;
503 }
504};
505
506/// Enumeration value.
507///
508/// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
509/// longer creates a type cycle.
510class DIEnumerator : public DINode {
511 friend class LLVMContextImpl;
512 friend class MDNode;
513
514 APInt Value;
515 LLVM_ABI DIEnumerator(LLVMContext &C, StorageType Storage, const APInt &Value,
517 DIEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
519 : DIEnumerator(C, Storage, APInt(64, Value, !IsUnsigned), IsUnsigned,
520 Ops) {}
521 ~DIEnumerator() = default;
522
523 static DIEnumerator *getImpl(LLVMContext &Context, const APInt &Value,
525 StorageType Storage, bool ShouldCreate = true) {
526 return getImpl(Context, Value, IsUnsigned,
527 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
528 }
529 LLVM_ABI static DIEnumerator *getImpl(LLVMContext &Context,
530 const APInt &Value, bool IsUnsigned,
531 MDString *Name, StorageType Storage,
532 bool ShouldCreate = true);
533
534 TempDIEnumerator cloneImpl() const {
536 }
537
538public:
539 DEFINE_MDNODE_GET(DIEnumerator,
540 (int64_t Value, bool IsUnsigned, StringRef Name),
541 (APInt(64, Value, !IsUnsigned), IsUnsigned, Name))
542 DEFINE_MDNODE_GET(DIEnumerator,
543 (int64_t Value, bool IsUnsigned, MDString *Name),
544 (APInt(64, Value, !IsUnsigned), IsUnsigned, Name))
545 DEFINE_MDNODE_GET(DIEnumerator,
546 (APInt Value, bool IsUnsigned, StringRef Name),
547 (Value, IsUnsigned, Name))
548 DEFINE_MDNODE_GET(DIEnumerator,
549 (APInt Value, bool IsUnsigned, MDString *Name),
550 (Value, IsUnsigned, Name))
551
552 TempDIEnumerator clone() const { return cloneImpl(); }
553
554 const APInt &getValue() const { return Value; }
555 bool isUnsigned() const { return SubclassData32; }
556 StringRef getName() const { return getStringOperand(0); }
557
559
560 static bool classof(const Metadata *MD) {
561 return MD->getMetadataID() == DIEnumeratorKind;
562 }
563};
564
565/// Base class for scope-like contexts.
566///
567/// Base class for lexical scopes and types (which are also declaration
568/// contexts).
569///
570/// TODO: Separate the concepts of declaration contexts and lexical scopes.
571class DIScope : public DINode {
572protected:
576 ~DIScope() = default;
577
578public:
580
581 inline StringRef getFilename() const;
582 inline StringRef getDirectory() const;
583 inline std::optional<StringRef> getSource() const;
584
585 LLVM_ABI StringRef getName() const;
586 LLVM_ABI DIScope *getScope() const;
587
588 /// Return the raw underlying file.
589 ///
590 /// A \a DIFile is a \a DIScope, but it doesn't point at a separate file (it
591 /// \em is the file). If \c this is an \a DIFile, we need to return \c this.
592 /// Otherwise, return the first operand, which is where all other subclasses
593 /// store their file pointer.
595 return isa<DIFile>(this) ? const_cast<DIScope *>(this)
596 : static_cast<Metadata *>(getOperand(0));
597 }
598
599 static bool classof(const Metadata *MD) {
600 switch (MD->getMetadataID()) {
601 default:
602 return false;
603 case DIBasicTypeKind:
604 case DIFixedPointTypeKind:
605 case DIStringTypeKind:
606 case DISubrangeTypeKind:
607 case DIDerivedTypeKind:
608 case DICompositeTypeKind:
609 case DISubroutineTypeKind:
610 case DIFileKind:
611 case DICompileUnitKind:
612 case DISubprogramKind:
613 case DILexicalBlockKind:
614 case DILexicalBlockFileKind:
615 case DINamespaceKind:
616 case DICommonBlockKind:
617 case DIModuleKind:
618 return true;
619 }
620 }
621};
622
623/// File.
624///
625/// TODO: Merge with directory/file node (including users).
626/// TODO: Canonicalize paths on creation.
627class DIFile : public DIScope {
628 friend class LLVMContextImpl;
629 friend class MDNode;
630
631public:
632 /// Which algorithm (e.g. MD5) a checksum was generated with.
633 ///
634 /// The encoding is explicit because it is used directly in Bitcode. The
635 /// value 0 is reserved to indicate the absence of a checksum in Bitcode.
637 // The first variant was originally CSK_None, encoded as 0. The new
638 // internal representation removes the need for this by wrapping the
639 // ChecksumInfo in an Optional, but to preserve Bitcode compatibility the 0
640 // encoding is reserved.
644 CSK_Last = CSK_SHA256 // Should be last enumeration.
645 };
646
647 /// A single checksum, represented by a \a Kind and a \a Value (a string).
648 template <typename T> struct ChecksumInfo {
649 /// The kind of checksum which \a Value encodes.
651 /// The string value of the checksum.
653
655 ~ChecksumInfo() = default;
656 bool operator==(const ChecksumInfo<T> &X) const {
657 return Kind == X.Kind && Value == X.Value;
658 }
659 bool operator!=(const ChecksumInfo<T> &X) const { return !(*this == X); }
660 StringRef getKindAsString() const { return getChecksumKindAsString(Kind); }
661 };
662
663private:
664 std::optional<ChecksumInfo<MDString *>> Checksum;
665 /// An optional source. A nullptr means none.
667
669 std::optional<ChecksumInfo<MDString *>> CS, MDString *Src,
671 ~DIFile() = default;
672
673 static DIFile *getImpl(LLVMContext &Context, StringRef Filename,
675 std::optional<ChecksumInfo<StringRef>> CS,
676 std::optional<StringRef> Source, StorageType Storage,
677 bool ShouldCreate = true) {
678 std::optional<ChecksumInfo<MDString *>> MDChecksum;
679 if (CS)
680 MDChecksum.emplace(CS->Kind, getCanonicalMDString(Context, CS->Value));
681 return getImpl(Context, getCanonicalMDString(Context, Filename),
682 getCanonicalMDString(Context, Directory), MDChecksum,
683 Source ? MDString::get(Context, *Source) : nullptr, Storage,
684 ShouldCreate);
685 }
686 LLVM_ABI static DIFile *getImpl(LLVMContext &Context, MDString *Filename,
687 MDString *Directory,
688 std::optional<ChecksumInfo<MDString *>> CS,
689 MDString *Source, StorageType Storage,
690 bool ShouldCreate = true);
691
692 TempDIFile cloneImpl() const {
694 getChecksum(), getSource());
695 }
696
697public:
700 std::optional<ChecksumInfo<StringRef>> CS = std::nullopt,
701 std::optional<StringRef> Source = std::nullopt),
702 (Filename, Directory, CS, Source))
703 DEFINE_MDNODE_GET(DIFile,
705 std::optional<ChecksumInfo<MDString *>> CS = std::nullopt,
706 MDString *Source = nullptr),
707 (Filename, Directory, CS, Source))
708
709 TempDIFile clone() const { return cloneImpl(); }
710
711 StringRef getFilename() const { return getStringOperand(0); }
712 StringRef getDirectory() const { return getStringOperand(1); }
713 std::optional<ChecksumInfo<StringRef>> getChecksum() const {
714 std::optional<ChecksumInfo<StringRef>> StringRefChecksum;
715 if (Checksum)
716 StringRefChecksum.emplace(Checksum->Kind, Checksum->Value->getString());
717 return StringRefChecksum;
718 }
719 std::optional<StringRef> getSource() const {
720 return Source ? std::optional<StringRef>(Source->getString())
721 : std::nullopt;
722 }
723
724 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
725 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
726 std::optional<ChecksumInfo<MDString *>> getRawChecksum() const {
727 return Checksum;
728 }
729 MDString *getRawSource() const { return Source; }
730
731 LLVM_ABI static StringRef getChecksumKindAsString(ChecksumKind CSKind);
732 LLVM_ABI static std::optional<ChecksumKind>
733 getChecksumKind(StringRef CSKindStr);
734
735 static bool classof(const Metadata *MD) {
736 return MD->getMetadataID() == DIFileKind;
737 }
738};
739
741 if (auto *F = getFile())
742 return F->getFilename();
743 return "";
744}
745
747 if (auto *F = getFile())
748 return F->getDirectory();
749 return "";
750}
751
752std::optional<StringRef> DIScope::getSource() const {
753 if (auto *F = getFile())
754 return F->getSource();
755 return std::nullopt;
756}
757
758/// Base class for types.
759///
760/// TODO: Remove the hardcoded name and context, since many types don't use
761/// them.
762/// TODO: Split up flags.
763///
764/// Uses the SubclassData32 Metadata slot.
765class DIType : public DIScope {
766 unsigned Line;
767 DIFlags Flags;
768 uint32_t NumExtraInhabitants;
769
770protected:
771 static constexpr unsigned N_OPERANDS = 5;
772
773 DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
774 unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants,
776 : DIScope(C, ID, Storage, Tag, Ops) {
777 init(Line, AlignInBits, NumExtraInhabitants, Flags);
778 }
779 ~DIType() = default;
780
781 void init(unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants,
782 DIFlags Flags) {
783 this->Line = Line;
784 this->Flags = Flags;
785 this->SubclassData32 = AlignInBits;
786 this->NumExtraInhabitants = NumExtraInhabitants;
787 }
788
789 /// Change fields in place.
790 void mutate(unsigned Tag, unsigned Line, uint32_t AlignInBits,
791 uint32_t NumExtraInhabitants, DIFlags Flags) {
792 assert(isDistinct() && "Only distinct nodes can mutate");
793 setTag(Tag);
794 init(Line, AlignInBits, NumExtraInhabitants, Flags);
795 }
796
797public:
798 TempDIType clone() const {
799 return TempDIType(cast<DIType>(MDNode::clone().release()));
800 }
801
802 unsigned getLine() const { return Line; }
804 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
805 uint32_t getNumExtraInhabitants() const { return NumExtraInhabitants; }
806 DIFlags getFlags() const { return Flags; }
807
809 StringRef getName() const { return getStringOperand(2); }
810
811 Metadata *getRawScope() const { return getOperand(1); }
813
814 Metadata *getRawSizeInBits() const { return getOperand(3); }
817 if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(MD->getValue()))
818 return CI->getZExtValue();
819 }
820 return 0;
821 }
822
823 Metadata *getRawOffsetInBits() const { return getOperand(4); }
826 if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(MD->getValue()))
827 return CI->getZExtValue();
828 }
829 return 0;
830 }
831
832 /// Returns a new temporary DIType with updated Flags
833 TempDIType cloneWithFlags(DIFlags NewFlags) const {
834 auto NewTy = clone();
835 NewTy->Flags = NewFlags;
836 return NewTy;
837 }
838
839 bool isPrivate() const {
840 return (getFlags() & FlagAccessibility) == FlagPrivate;
841 }
842 bool isProtected() const {
843 return (getFlags() & FlagAccessibility) == FlagProtected;
844 }
845 bool isPublic() const {
846 return (getFlags() & FlagAccessibility) == FlagPublic;
847 }
848 bool isForwardDecl() const { return getFlags() & FlagFwdDecl; }
849 bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; }
850 bool isVirtual() const { return getFlags() & FlagVirtual; }
851 bool isArtificial() const { return getFlags() & FlagArtificial; }
852 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
853 bool isObjcClassComplete() const {
854 return getFlags() & FlagObjcClassComplete;
855 }
856 bool isVector() const { return getFlags() & FlagVector; }
857 bool isBitField() const { return getFlags() & FlagBitField; }
858 bool isStaticMember() const { return getFlags() & FlagStaticMember; }
859 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
860 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
861 bool isTypePassByValue() const { return getFlags() & FlagTypePassByValue; }
863 return getFlags() & FlagTypePassByReference;
864 }
865 bool isBigEndian() const { return getFlags() & FlagBigEndian; }
866 bool isLittleEndian() const { return getFlags() & FlagLittleEndian; }
867 bool getExportSymbols() const { return getFlags() & FlagExportSymbols; }
868
869 static bool classof(const Metadata *MD) {
870 switch (MD->getMetadataID()) {
871 default:
872 return false;
873 case DIBasicTypeKind:
874 case DIFixedPointTypeKind:
875 case DIStringTypeKind:
876 case DISubrangeTypeKind:
877 case DIDerivedTypeKind:
878 case DICompositeTypeKind:
879 case DISubroutineTypeKind:
880 return true;
881 }
882 }
883};
884
885/// Basic type, like 'int' or 'float'.
886///
887/// TODO: Split out DW_TAG_unspecified_type.
888/// TODO: Drop unused accessors.
889class DIBasicType : public DIType {
890 friend class LLVMContextImpl;
891 friend class MDNode;
892
893 unsigned Encoding;
894
895protected:
897 uint32_t AlignInBits, unsigned Encoding,
900 : DIType(C, DIBasicTypeKind, Storage, Tag, 0, AlignInBits,
902 Encoding(Encoding) {}
904 uint32_t AlignInBits, unsigned Encoding,
908 Ops),
909 Encoding(Encoding) {}
910 ~DIBasicType() = default;
911
912 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
914 uint32_t AlignInBits, unsigned Encoding,
916 StorageType Storage, bool ShouldCreate = true) {
917 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
919 Flags, Storage, ShouldCreate);
920 }
921 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
923 uint32_t AlignInBits, unsigned Encoding,
925 StorageType Storage, bool ShouldCreate = true) {
926 auto *SizeInBitsNode = ConstantAsMetadata::get(
927 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
928 return getImpl(Context, Tag, Name, SizeInBitsNode, AlignInBits, Encoding,
929 NumExtraInhabitants, Flags, Storage, ShouldCreate);
930 }
931 LLVM_ABI static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
933 uint32_t AlignInBits, unsigned Encoding,
935 DIFlags Flags, StorageType Storage,
936 bool ShouldCreate = true);
937
938 TempDIBasicType cloneImpl() const {
942 }
943
944public:
946 (Tag, Name, 0, 0, 0, 0, FlagZero))
949 (Tag, Name, SizeInBits, 0, 0, 0, FlagZero))
951 (unsigned Tag, MDString *Name, uint64_t SizeInBits),
952 (Tag, Name, SizeInBits, 0, 0, 0, FlagZero))
955 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
956 (Tag, Name, SizeInBits, AlignInBits, Encoding, 0, Flags))
958 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
959 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
960 (Tag, Name, SizeInBits, AlignInBits, Encoding, 0, Flags))
963 uint32_t AlignInBits, unsigned Encoding,
968 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
969 uint32_t AlignInBits, unsigned Encoding,
971 (Tag, Name, SizeInBits, AlignInBits, Encoding,
975 uint32_t AlignInBits, unsigned Encoding,
979
980 TempDIBasicType clone() const { return cloneImpl(); }
981
982 unsigned getEncoding() const { return Encoding; }
983
984 enum class Signedness { Signed, Unsigned };
985
986 /// Return the signedness of this type, or std::nullopt if this type is
987 /// neither signed nor unsigned.
988 LLVM_ABI std::optional<Signedness> getSignedness() const;
989
990 static bool classof(const Metadata *MD) {
991 return MD->getMetadataID() == DIBasicTypeKind ||
992 MD->getMetadataID() == DIFixedPointTypeKind;
993 }
994};
995
996/// Fixed-point type.
997class DIFixedPointType : public DIBasicType {
998 friend class LLVMContextImpl;
999 friend class MDNode;
1000
1001 // Actually FixedPointKind.
1002 unsigned Kind;
1003 // Used for binary and decimal.
1004 int Factor;
1005 // Used for rational.
1006 APInt Numerator;
1007 APInt Denominator;
1008
1009 DIFixedPointType(LLVMContext &C, StorageType Storage, unsigned Tag,
1011 unsigned Kind, int Factor, ArrayRef<Metadata *> Ops)
1012 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, AlignInBits,
1013 Encoding, 0, Flags, Ops),
1014 Kind(Kind), Factor(Factor) {
1015 assert(Kind == FixedPointBinary || Kind == FixedPointDecimal);
1016 }
1018 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags,
1019 unsigned Kind, APInt Numerator, APInt Denominator,
1021 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, AlignInBits,
1022 Encoding, 0, Flags, Ops),
1023 Kind(Kind), Factor(0), Numerator(Numerator), Denominator(Denominator) {
1024 assert(Kind == FixedPointRational);
1025 }
1026 DIFixedPointType(LLVMContext &C, StorageType Storage, unsigned Tag,
1027 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags,
1028 unsigned Kind, int Factor, APInt Numerator,
1030 : DIBasicType(C, DIFixedPointTypeKind, Storage, Tag, AlignInBits,
1031 Encoding, 0, Flags, Ops),
1032 Kind(Kind), Factor(Factor), Numerator(Numerator),
1034 ~DIFixedPointType() = default;
1035
1036 static DIFixedPointType *
1037 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name,
1038 uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
1039 DIFlags Flags, unsigned Kind, int Factor, APInt Numerator,
1040 APInt Denominator, StorageType Storage, bool ShouldCreate = true) {
1041 auto *SizeInBitsNode = ConstantAsMetadata::get(
1042 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1043 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
1044 SizeInBitsNode, AlignInBits, Encoding, Flags, Kind, Factor,
1045 Numerator, Denominator, Storage, ShouldCreate);
1046 }
1047 static DIFixedPointType *
1048 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name,
1049 Metadata *SizeInBits, uint32_t AlignInBits, unsigned Encoding,
1050 DIFlags Flags, unsigned Kind, int Factor, APInt Numerator,
1051 APInt Denominator, StorageType Storage, bool ShouldCreate = true) {
1052 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
1053 SizeInBits, AlignInBits, Encoding, Flags, Kind, Factor,
1054 Numerator, Denominator, Storage, ShouldCreate);
1055 }
1056 static DIFixedPointType *
1057 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name,
1058 uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
1059 DIFlags Flags, unsigned Kind, int Factor, APInt Numerator,
1060 APInt Denominator, StorageType Storage, bool ShouldCreate = true) {
1061 auto *SizeInBitsNode = ConstantAsMetadata::get(
1062 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1063 return getImpl(Context, Tag, Name, SizeInBitsNode, AlignInBits, Encoding,
1064 Flags, Kind, Factor, Numerator, Denominator, Storage,
1065 ShouldCreate);
1066 }
1067 LLVM_ABI static DIFixedPointType *
1068 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name,
1069 Metadata *SizeInBits, uint32_t AlignInBits, unsigned Encoding,
1070 DIFlags Flags, unsigned Kind, int Factor, APInt Numerator,
1071 APInt Denominator, StorageType Storage, bool ShouldCreate = true);
1072
1073 TempDIFixedPointType cloneImpl() const {
1076 getFlags(), Kind, Factor, Numerator, Denominator);
1077 }
1078
1079public:
1080 enum FixedPointKind : unsigned {
1081 /// Scale factor 2^Factor.
1083 /// Scale factor 10^Factor.
1085 /// Arbitrary rational scale factor.
1088 };
1089
1090 LLVM_ABI static std::optional<FixedPointKind>
1092 LLVM_ABI static const char *fixedPointKindString(FixedPointKind);
1093
1094 DEFINE_MDNODE_GET(DIFixedPointType,
1095 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
1097 unsigned Kind, int Factor, APInt Numerator,
1098 APInt Denominator),
1100 Factor, Numerator, Denominator))
1101 DEFINE_MDNODE_GET(DIFixedPointType,
1104 unsigned Kind, int Factor, APInt Numerator,
1105 APInt Denominator),
1107 Factor, Numerator, Denominator))
1108 DEFINE_MDNODE_GET(DIFixedPointType,
1109 (unsigned Tag, MDString *Name, Metadata *SizeInBits,
1111 unsigned Kind, int Factor, APInt Numerator,
1112 APInt Denominator),
1114 Factor, Numerator, Denominator))
1115
1116 TempDIFixedPointType clone() const { return cloneImpl(); }
1117
1118 bool isBinary() const { return Kind == FixedPointBinary; }
1119 bool isDecimal() const { return Kind == FixedPointDecimal; }
1120 bool isRational() const { return Kind == FixedPointRational; }
1121
1122 LLVM_ABI bool isSigned() const;
1123
1124 FixedPointKind getKind() const { return static_cast<FixedPointKind>(Kind); }
1125
1126 int getFactorRaw() const { return Factor; }
1127 int getFactor() const {
1128 assert(Kind == FixedPointBinary || Kind == FixedPointDecimal);
1129 return Factor;
1130 }
1131
1132 const APInt &getNumeratorRaw() const { return Numerator; }
1133 const APInt &getNumerator() const {
1134 assert(Kind == FixedPointRational);
1135 return Numerator;
1136 }
1137
1138 const APInt &getDenominatorRaw() const { return Denominator; }
1139 const APInt &getDenominator() const {
1140 assert(Kind == FixedPointRational);
1141 return Denominator;
1142 }
1143
1144 static bool classof(const Metadata *MD) {
1145 return MD->getMetadataID() == DIFixedPointTypeKind;
1146 }
1147};
1148
1149/// String type, Fortran CHARACTER(n)
1150class DIStringType : public DIType {
1151 friend class LLVMContextImpl;
1152 friend class MDNode;
1153
1154 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1155
1156 unsigned Encoding;
1157
1158 DIStringType(LLVMContext &C, StorageType Storage, unsigned Tag,
1159 uint32_t AlignInBits, unsigned Encoding,
1161 : DIType(C, DIStringTypeKind, Storage, Tag, 0, AlignInBits, 0, FlagZero,
1162 Ops),
1163 Encoding(Encoding) {}
1164 ~DIStringType() = default;
1165
1166 static DIStringType *getImpl(LLVMContext &Context, unsigned Tag,
1168 Metadata *StrLenExp, Metadata *StrLocationExp,
1170 unsigned Encoding, StorageType Storage,
1171 bool ShouldCreate = true) {
1172 auto *SizeInBitsNode = ConstantAsMetadata::get(
1173 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1174 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
1175 StringLength, StrLenExp, StrLocationExp, SizeInBitsNode,
1176 AlignInBits, Encoding, Storage, ShouldCreate);
1177 }
1178 static DIStringType *getImpl(LLVMContext &Context, unsigned Tag,
1179 MDString *Name, Metadata *StringLength,
1180 Metadata *StrLenExp, Metadata *StrLocationExp,
1182 unsigned Encoding, StorageType Storage,
1183 bool ShouldCreate = true) {
1184 auto *SizeInBitsNode = ConstantAsMetadata::get(
1185 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1186 return getImpl(Context, Tag, Name, StringLength, StrLenExp, StrLocationExp,
1187 SizeInBitsNode, AlignInBits, Encoding, Storage,
1188 ShouldCreate);
1189 }
1190 LLVM_ABI static DIStringType *
1191 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name,
1192 Metadata *StringLength, Metadata *StrLenExp, Metadata *StrLocationExp,
1193 Metadata *SizeInBits, uint32_t AlignInBits, unsigned Encoding,
1194 StorageType Storage, bool ShouldCreate = true);
1195
1196 TempDIStringType cloneImpl() const {
1201 }
1202
1203public:
1204 DEFINE_MDNODE_GET(DIStringType,
1205 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
1207 (Tag, Name, nullptr, nullptr, nullptr, SizeInBits,
1208 AlignInBits, 0))
1209 DEFINE_MDNODE_GET(DIStringType,
1213 unsigned Encoding),
1216 DEFINE_MDNODE_GET(DIStringType,
1217 (unsigned Tag, StringRef Name, Metadata *StringLength,
1220 unsigned Encoding),
1223 DEFINE_MDNODE_GET(DIStringType,
1227 unsigned Encoding),
1230
1231 TempDIStringType clone() const { return cloneImpl(); }
1232
1233 static bool classof(const Metadata *MD) {
1234 return MD->getMetadataID() == DIStringTypeKind;
1235 }
1236
1240
1244
1248
1249 unsigned getEncoding() const { return Encoding; }
1250
1251 Metadata *getRawStringLength() const { return getOperand(MY_FIRST_OPERAND); }
1252
1254 return getOperand(MY_FIRST_OPERAND + 1);
1255 }
1256
1258 return getOperand(MY_FIRST_OPERAND + 2);
1259 }
1260};
1261
1262/// Derived types.
1263///
1264/// This includes qualified types, pointers, references, friends, typedefs, and
1265/// class members.
1266///
1267/// TODO: Split out members (inheritance, fields, methods, etc.).
1268class DIDerivedType : public DIType {
1269public:
1270 /// Pointer authentication (__ptrauth) metadata.
1272 // RawData layout:
1273 // - Bits 0..3: Key
1274 // - Bit 4: IsAddressDiscriminated
1275 // - Bits 5..20: ExtraDiscriminator
1276 // - Bit 21: IsaPointer
1277 // - Bit 22: AuthenticatesNullValues
1278 unsigned RawData;
1279
1280 PtrAuthData(unsigned FromRawData) : RawData(FromRawData) {}
1281 PtrAuthData(unsigned Key, bool IsDiscr, unsigned Discriminator,
1282 bool IsaPointer, bool AuthenticatesNullValues) {
1283 assert(Key < 16);
1284 assert(Discriminator <= 0xffff);
1285 RawData = (Key << 0) | (IsDiscr ? (1 << 4) : 0) | (Discriminator << 5) |
1286 (IsaPointer ? (1 << 21) : 0) |
1287 (AuthenticatesNullValues ? (1 << 22) : 0);
1288 }
1289
1290 unsigned key() { return (RawData >> 0) & 0b1111; }
1291 bool isAddressDiscriminated() { return (RawData >> 4) & 1; }
1292 unsigned extraDiscriminator() { return (RawData >> 5) & 0xffff; }
1293 bool isaPointer() { return (RawData >> 21) & 1; }
1294 bool authenticatesNullValues() { return (RawData >> 22) & 1; }
1295 };
1296
1297private:
1298 friend class LLVMContextImpl;
1299 friend class MDNode;
1300
1301 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1302
1303 /// The DWARF address space of the memory pointed to or referenced by a
1304 /// pointer or reference type respectively.
1305 std::optional<unsigned> DWARFAddressSpace;
1306
1307 DIDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
1308 unsigned Line, uint32_t AlignInBits,
1309 std::optional<unsigned> DWARFAddressSpace,
1310 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1312 : DIType(C, DIDerivedTypeKind, Storage, Tag, Line, AlignInBits, 0, Flags,
1313 Ops),
1314 DWARFAddressSpace(DWARFAddressSpace) {
1315 if (PtrAuthData)
1317 }
1318 ~DIDerivedType() = default;
1319 static DIDerivedType *
1320 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1321 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1323 std::optional<unsigned> DWARFAddressSpace,
1324 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1326 bool ShouldCreate = true) {
1327 auto *SizeInBitsNode = ConstantAsMetadata::get(
1328 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1329 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1330 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1331 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1332 Line, Scope, BaseType, SizeInBitsNode, AlignInBits,
1333 OffsetInBitsNode, DWARFAddressSpace, PtrAuthData, Flags,
1334 ExtraData, Annotations.get(), Storage, ShouldCreate);
1335 }
1336 static DIDerivedType *
1337 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, DIFile *File,
1338 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1340 std::optional<unsigned> DWARFAddressSpace,
1341 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1343 bool ShouldCreate = true) {
1344 auto *SizeInBitsNode = ConstantAsMetadata::get(
1345 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1346 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1347 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1348 return getImpl(Context, Tag, Name, File, Line, Scope, BaseType,
1349 SizeInBitsNode, AlignInBits, OffsetInBitsNode,
1351 Annotations.get(), Storage, ShouldCreate);
1352 }
1353 static DIDerivedType *
1354 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File,
1357 std::optional<unsigned> DWARFAddressSpace,
1358 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1360 bool ShouldCreate = true) {
1361 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1363 DWARFAddressSpace, PtrAuthData, Flags, ExtraData,
1364 Annotations.get(), Storage, ShouldCreate);
1365 }
1366 LLVM_ABI static DIDerivedType *
1367 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1368 unsigned Line, Metadata *Scope, Metadata *BaseType,
1370 std::optional<unsigned> DWARFAddressSpace,
1371 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1373 bool ShouldCreate = true);
1374
1375 TempDIDerivedType cloneImpl() const {
1376 return getTemporary(
1379 getRawOffsetInBits(), getDWARFAddressSpace(), getPtrAuthData(),
1381 }
1382
1383public:
1384 DEFINE_MDNODE_GET(DIDerivedType,
1385 (unsigned Tag, MDString *Name, Metadata *File,
1386 unsigned Line, Metadata *Scope, Metadata *BaseType,
1389 std::optional<unsigned> DWARFAddressSpace,
1390 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1391 Metadata *ExtraData = nullptr,
1392 Metadata *Annotations = nullptr),
1394 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1396 DEFINE_MDNODE_GET(DIDerivedType,
1397 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1400 std::optional<unsigned> DWARFAddressSpace,
1401 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1403 DINodeArray Annotations = nullptr),
1405 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1407 DEFINE_MDNODE_GET(DIDerivedType,
1408 (unsigned Tag, MDString *Name, DIFile *File, unsigned Line,
1411 std::optional<unsigned> DWARFAddressSpace,
1412 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1413 Metadata *ExtraData = nullptr,
1414 DINodeArray Annotations = nullptr),
1416 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1418 DEFINE_MDNODE_GET(DIDerivedType,
1419 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1422 std::optional<unsigned> DWARFAddressSpace,
1423 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags,
1424 Metadata *ExtraData = nullptr,
1425 DINodeArray Annotations = nullptr),
1427 AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData,
1429
1430 TempDIDerivedType clone() const { return cloneImpl(); }
1431
1432 /// Get the base type this is derived from.
1433 DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); }
1434 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1435
1436 /// \returns The DWARF address space of the memory pointed to or referenced by
1437 /// a pointer or reference type respectively.
1438 std::optional<unsigned> getDWARFAddressSpace() const {
1439 return DWARFAddressSpace;
1440 }
1441
1442 LLVM_ABI std::optional<PtrAuthData> getPtrAuthData() const;
1443
1444 /// Get extra data associated with this derived type.
1445 ///
1446 /// Class type for pointer-to-members, objective-c property node for ivars,
1447 /// global constant wrapper for static members, virtual base pointer offset
1448 /// for inheritance, a tuple of template parameters for template aliases,
1449 /// discriminant for a variant, or storage offset for a bit field.
1450 ///
1451 /// TODO: Separate out types that need this extra operand: pointer-to-member
1452 /// types and member fields (static members and ivars).
1454 Metadata *getRawExtraData() const { return getOperand(MY_FIRST_OPERAND + 1); }
1455
1456 /// Get the template parameters from a template alias.
1457 DITemplateParameterArray getTemplateParams() const {
1459 }
1460
1461 /// Get annotations associated with this derived type.
1462 DINodeArray getAnnotations() const {
1464 }
1466 return getOperand(MY_FIRST_OPERAND + 2);
1467 }
1468
1469 /// Get casted version of extra data.
1470 /// @{
1471 LLVM_ABI DIType *getClassType() const;
1472
1476
1478
1480
1481 LLVM_ABI Constant *getConstant() const;
1482
1484 /// @}
1485
1486 static bool classof(const Metadata *MD) {
1487 return MD->getMetadataID() == DIDerivedTypeKind;
1488 }
1489};
1490
1493 return Lhs.RawData == Rhs.RawData;
1494}
1495
1498 return !(Lhs == Rhs);
1499}
1500
1501/// Subrange type. This is somewhat similar to DISubrange, but it
1502/// is also a DIType.
1503class DISubrangeType : public DIType {
1504public:
1506
1507private:
1508 friend class LLVMContextImpl;
1509 friend class MDNode;
1510
1511 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1512
1513 DISubrangeType(LLVMContext &C, StorageType Storage, unsigned Line,
1515
1516 ~DISubrangeType() = default;
1517
1518 static DISubrangeType *
1519 getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
1523 StorageType Storage, bool ShouldCreate = true) {
1524 auto *SizeInBitsNode = ConstantAsMetadata::get(
1525 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1526 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
1527 Scope, SizeInBitsNode, AlignInBits, Flags, BaseType,
1528 LowerBound, UpperBound, Stride, Bias, Storage, ShouldCreate);
1529 }
1530
1531 LLVM_ABI static DISubrangeType *
1532 getImpl(LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
1534 DIFlags Flags, Metadata *BaseType, Metadata *LowerBound,
1536 StorageType Storage, bool ShouldCreate = true);
1537
1538 TempDISubrangeType cloneImpl() const {
1543 }
1544
1545 LLVM_ABI BoundType convertRawToBound(Metadata *IN) const;
1546
1547public:
1548 DEFINE_MDNODE_GET(DISubrangeType,
1549 (MDString * Name, Metadata *File, unsigned Line,
1556 DEFINE_MDNODE_GET(DISubrangeType,
1563
1564 TempDISubrangeType clone() const { return cloneImpl(); }
1565
1566 /// Get the base type this is derived from.
1568 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1569
1571 return getOperand(MY_FIRST_OPERAND + 1).get();
1572 }
1573
1575 return getOperand(MY_FIRST_OPERAND + 2).get();
1576 }
1577
1579 return getOperand(MY_FIRST_OPERAND + 3).get();
1580 }
1581
1583 return getOperand(MY_FIRST_OPERAND + 4).get();
1584 }
1585
1587 return convertRawToBound(getRawLowerBound());
1588 }
1589
1591 return convertRawToBound(getRawUpperBound());
1592 }
1593
1594 BoundType getStride() const { return convertRawToBound(getRawStride()); }
1595
1596 BoundType getBias() const { return convertRawToBound(getRawBias()); }
1597
1598 static bool classof(const Metadata *MD) {
1599 return MD->getMetadataID() == DISubrangeTypeKind;
1600 }
1601};
1602
1603/// Composite types.
1604///
1605/// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
1606/// TODO: Create a custom, unrelated node for DW_TAG_array_type.
1607class DICompositeType : public DIType {
1608 friend class LLVMContextImpl;
1609 friend class MDNode;
1610
1611 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1612
1613 unsigned RuntimeLang;
1614 std::optional<uint32_t> EnumKind;
1615
1616 DICompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
1617 unsigned Line, unsigned RuntimeLang, uint32_t AlignInBits,
1619 std::optional<uint32_t> EnumKind, DIFlags Flags,
1621 : DIType(C, DICompositeTypeKind, Storage, Tag, Line, AlignInBits,
1623 RuntimeLang(RuntimeLang), EnumKind(EnumKind) {}
1624 ~DICompositeType() = default;
1625
1626 /// Change fields in place.
1627 void mutate(unsigned Tag, unsigned Line, unsigned RuntimeLang,
1629 std::optional<uint32_t> EnumKind, DIFlags Flags) {
1630 assert(isDistinct() && "Only distinct nodes can mutate");
1631 assert(getRawIdentifier() && "Only ODR-uniqued nodes should mutate");
1632 this->RuntimeLang = RuntimeLang;
1633 this->EnumKind = EnumKind;
1635 }
1636
1637 static DICompositeType *
1638 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
1639 unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
1641 uint32_t NumExtraInhabitants, DIFlags Flags, DINodeArray Elements,
1642 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1643 DIType *VTableHolder, DITemplateParameterArray TemplateParams,
1644 StringRef Identifier, DIDerivedType *Discriminator,
1646 Metadata *Rank, DINodeArray Annotations, Metadata *BitStride,
1647 StorageType Storage, bool ShouldCreate = true) {
1648 auto *SizeInBitsNode = ConstantAsMetadata::get(
1649 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1650 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1651 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1652 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1653 Line, Scope, BaseType, SizeInBitsNode, AlignInBits,
1654 OffsetInBitsNode, Flags, Elements.get(), RuntimeLang,
1656 getCanonicalMDString(Context, Identifier), Discriminator,
1659 ShouldCreate);
1660 }
1661 static DICompositeType *
1662 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1663 unsigned Line, Metadata *Scope, Metadata *BaseType,
1664 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
1665 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
1666 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1671 Metadata *BitStride, StorageType Storage, bool ShouldCreate = true) {
1672 auto *SizeInBitsNode = ConstantAsMetadata::get(
1673 ConstantInt::get(Type::getInt64Ty(Context), SizeInBits));
1674 auto *OffsetInBitsNode = ConstantAsMetadata::get(
1675 ConstantInt::get(Type::getInt64Ty(Context), OffsetInBits));
1676 return getImpl(Context, Tag, Name, File, Line, Scope, BaseType,
1677 SizeInBitsNode, AlignInBits, OffsetInBitsNode, Flags,
1678 Elements, RuntimeLang, EnumKind, VTableHolder,
1681 NumExtraInhabitants, BitStride, Storage, ShouldCreate);
1682 }
1683 static DICompositeType *
1684 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
1687 uint32_t NumExtraInhabitants, DIFlags Flags, DINodeArray Elements,
1688 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1689 DIType *VTableHolder, DITemplateParameterArray TemplateParams,
1690 StringRef Identifier, DIDerivedType *Discriminator,
1692 Metadata *Rank, DINodeArray Annotations, Metadata *BitStride,
1693 StorageType Storage, bool ShouldCreate = true) {
1694 return getImpl(
1695 Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
1697 RuntimeLang, EnumKind, VTableHolder, TemplateParams.get(),
1700 NumExtraInhabitants, BitStride, Storage, ShouldCreate);
1701 }
1702 LLVM_ABI static DICompositeType *
1703 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1704 unsigned Line, Metadata *Scope, Metadata *BaseType,
1706 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
1707 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1712 Metadata *BitStride, StorageType Storage, bool ShouldCreate = true);
1713
1714 TempDICompositeType cloneImpl() const {
1715 return getTemporary(
1723 getRawBitStride());
1724 }
1725
1726public:
1728 DICompositeType,
1729 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1732 DINodeArray Elements, unsigned RuntimeLang,
1733 std::optional<uint32_t> EnumKind, DIType *VTableHolder,
1734 DITemplateParameterArray TemplateParams = nullptr,
1736 Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
1737 Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
1738 DINodeArray Annotations = nullptr, DIType *Specification = nullptr,
1742 RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier,
1744 BitStride))
1746 DICompositeType,
1747 (unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
1750 Metadata *Elements, unsigned RuntimeLang,
1751 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1754 Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
1755 Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
1757 Metadata *BitStride = nullptr),
1759 OffsetInBits, Flags, Elements, RuntimeLang, EnumKind, VTableHolder,
1762 BitStride))
1764 DICompositeType,
1765 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
1768 DINodeArray Elements, unsigned RuntimeLang,
1769 std::optional<uint32_t> EnumKind, DIType *VTableHolder,
1770 DITemplateParameterArray TemplateParams = nullptr,
1772 Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
1773 Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
1774 DINodeArray Annotations = nullptr, DIType *Specification = nullptr,
1778 RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier,
1780 BitStride))
1782 DICompositeType,
1783 (unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
1786 Metadata *Elements, unsigned RuntimeLang,
1787 std::optional<uint32_t> EnumKind, Metadata *VTableHolder,
1788 Metadata *TemplateParams = nullptr, MDString *Identifier = nullptr,
1789 Metadata *Discriminator = nullptr, Metadata *DataLocation = nullptr,
1790 Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
1791 Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
1793 Metadata *BitStride = nullptr),
1795 OffsetInBits, Flags, Elements, RuntimeLang, EnumKind, VTableHolder,
1798 BitStride))
1799
1800 TempDICompositeType clone() const { return cloneImpl(); }
1801
1802 /// Get a DICompositeType with the given ODR identifier.
1803 ///
1804 /// If \a LLVMContext::isODRUniquingDebugTypes(), gets the mapped
1805 /// DICompositeType for the given ODR \c Identifier. If none exists, creates
1806 /// a new node.
1807 ///
1808 /// Else, returns \c nullptr.
1809 LLVM_ABI static DICompositeType *
1810 getODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1811 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1815 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1821 MDString &Identifier);
1822
1823 /// Build a DICompositeType with the given ODR identifier.
1824 ///
1825 /// Looks up the mapped DICompositeType for the given ODR \c Identifier. If
1826 /// it doesn't exist, creates a new one. If it does exist and \a
1827 /// isForwardDecl(), and the new arguments would be a definition, mutates the
1828 /// the type in place. In either case, returns the type.
1829 ///
1830 /// If not \a LLVMContext::isODRUniquingDebugTypes(), this function returns
1831 /// nullptr.
1832 LLVM_ABI static DICompositeType *
1833 buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1834 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1838 unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1843
1845 DINodeArray getElements() const {
1847 }
1851 DITemplateParameterArray getTemplateParams() const {
1853 }
1855 return getStringOperand(MY_FIRST_OPERAND + 4);
1856 }
1857 unsigned getRuntimeLang() const { return RuntimeLang; }
1858 std::optional<uint32_t> getEnumKind() const { return EnumKind; }
1859
1860 Metadata *getRawBaseType() const { return getOperand(MY_FIRST_OPERAND); }
1861 Metadata *getRawElements() const { return getOperand(MY_FIRST_OPERAND + 1); }
1863 return getOperand(MY_FIRST_OPERAND + 2);
1864 }
1866 return getOperand(MY_FIRST_OPERAND + 3);
1867 }
1869 return getOperandAs<MDString>(MY_FIRST_OPERAND + 4);
1870 }
1872 return getOperand(MY_FIRST_OPERAND + 5);
1873 }
1875 return getOperandAs<DIDerivedType>(MY_FIRST_OPERAND + 5);
1876 }
1878 return getOperand(MY_FIRST_OPERAND + 6);
1879 }
1887 return getOperand(MY_FIRST_OPERAND + 7);
1888 }
1895 Metadata *getRawAllocated() const { return getOperand(MY_FIRST_OPERAND + 8); }
1902 Metadata *getRawRank() const { return getOperand(MY_FIRST_OPERAND + 9); }
1905 return dyn_cast_or_null<ConstantInt>(MD->getValue());
1906 return nullptr;
1907 }
1911
1913 return getOperand(MY_FIRST_OPERAND + 10);
1914 }
1915 DINodeArray getAnnotations() const {
1917 }
1918
1920 return getOperand(MY_FIRST_OPERAND + 11);
1921 }
1925
1927 return getOperand(MY_FIRST_OPERAND + 12);
1928 }
1931 return dyn_cast_or_null<ConstantInt>(MD->getValue());
1932 return nullptr;
1933 }
1934
1935 /// Replace operands.
1936 ///
1937 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
1938 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
1939 /// of its movement if necessary.
1940 /// @{
1941 void replaceElements(DINodeArray Elements) {
1942#ifndef NDEBUG
1943 for (DINode *Op : getElements())
1944 assert(is_contained(Elements->operands(), Op) &&
1945 "Lost a member during member list replacement");
1946#endif
1947 replaceOperandWith(MY_FIRST_OPERAND + 1, Elements.get());
1948 }
1949
1951 replaceOperandWith(MY_FIRST_OPERAND + 2, VTableHolder);
1952 }
1953
1954 void replaceTemplateParams(DITemplateParameterArray TemplateParams) {
1955 replaceOperandWith(MY_FIRST_OPERAND + 3, TemplateParams.get());
1956 }
1957 /// @}
1958
1959 static bool classof(const Metadata *MD) {
1960 return MD->getMetadataID() == DICompositeTypeKind;
1961 }
1962};
1963
1964/// Type array for a subprogram.
1965///
1966/// TODO: Fold the array of types in directly as operands.
1967class DISubroutineType : public DIType {
1968 friend class LLVMContextImpl;
1969 friend class MDNode;
1970
1971 static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1972
1973 /// The calling convention used with DW_AT_calling_convention. Actually of
1974 /// type dwarf::CallingConvention.
1975 uint8_t CC;
1976
1977 DISubroutineType(LLVMContext &C, StorageType Storage, DIFlags Flags,
1979 ~DISubroutineType() = default;
1980
1981 static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
1984 bool ShouldCreate = true) {
1985 return getImpl(Context, Flags, CC, TypeArray.get(), Storage, ShouldCreate);
1986 }
1987 LLVM_ABI static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
1990 bool ShouldCreate = true);
1991
1992 TempDISubroutineType cloneImpl() const {
1994 }
1995
1996public:
1997 DEFINE_MDNODE_GET(DISubroutineType,
1999 (Flags, CC, TypeArray))
2000 DEFINE_MDNODE_GET(DISubroutineType,
2003
2004 TempDISubroutineType clone() const { return cloneImpl(); }
2005 // Returns a new temporary DISubroutineType with updated CC
2006 TempDISubroutineType cloneWithCC(uint8_t CC) const {
2007 auto NewTy = clone();
2008 NewTy->CC = CC;
2009 return NewTy;
2010 }
2011
2012 uint8_t getCC() const { return CC; }
2013
2017
2018 Metadata *getRawTypeArray() const { return getOperand(MY_FIRST_OPERAND); }
2019
2020 static bool classof(const Metadata *MD) {
2021 return MD->getMetadataID() == DISubroutineTypeKind;
2022 }
2023};
2024
2025/// Compile unit.
2026class DICompileUnit : public DIScope {
2027 friend class LLVMContextImpl;
2028 friend class MDNode;
2029
2030public:
2038
2046
2047 LLVM_ABI static std::optional<DebugEmissionKind>
2049 LLVM_ABI static const char *emissionKindString(DebugEmissionKind EK);
2050 LLVM_ABI static std::optional<DebugNameTableKind>
2052 LLVM_ABI static const char *nameTableKindString(DebugNameTableKind PK);
2053
2054private:
2056 unsigned RuntimeVersion;
2058 unsigned EmissionKind;
2059 unsigned NameTableKind;
2060 bool IsOptimized;
2061 bool SplitDebugInlining;
2063 bool RangesBaseAddress;
2064
2067 unsigned RuntimeVersion, unsigned EmissionKind, uint64_t DWOId,
2069 unsigned NameTableKind, bool RangesBaseAddress,
2071 ~DICompileUnit() = default;
2072
2073 static DICompileUnit *
2077 unsigned EmissionKind, DICompositeTypeArray EnumTypes,
2078 DIScopeArray RetainedTypes,
2079 DIGlobalVariableExpressionArray GlobalVariables,
2080 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
2083 StringRef SDK, StorageType Storage, bool ShouldCreate = true) {
2084 return getImpl(
2085 Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
2088 EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
2091 getCanonicalMDString(Context, SysRoot),
2092 getCanonicalMDString(Context, SDK), Storage, ShouldCreate);
2093 }
2094 LLVM_ABI static DICompileUnit *
2095 getImpl(LLVMContext &Context, DISourceLanguageName SourceLanguage,
2096 Metadata *File, MDString *Producer, bool IsOptimized, MDString *Flags,
2097 unsigned RuntimeVersion, MDString *SplitDebugFilename,
2101 bool DebugInfoForProfiling, unsigned NameTableKind,
2102 bool RangesBaseAddress, MDString *SysRoot, MDString *SDK,
2103 StorageType Storage, bool ShouldCreate = true);
2104
2105 TempDICompileUnit cloneImpl() const {
2106 return getTemporary(
2113 }
2114
2115public:
2116 static void get() = delete;
2117 static void getIfExists() = delete;
2118
2120 DICompileUnit,
2122 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
2124 DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes,
2125 DIGlobalVariableExpressionArray GlobalVariables,
2126 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
2127 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
2128 DebugNameTableKind NameTableKind, bool RangesBaseAddress,
2130 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
2132 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
2133 DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress,
2134 SysRoot, SDK))
2136 DICompileUnit,
2138 bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
2142 bool SplitDebugInlining, bool DebugInfoForProfiling,
2143 unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
2145 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
2147 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
2148 DebugInfoForProfiling, NameTableKind, RangesBaseAddress, SysRoot, SDK))
2149
2150 TempDICompileUnit clone() const { return cloneImpl(); }
2151
2152 DISourceLanguageName getSourceLanguage() const { return SourceLanguage; }
2153 bool isOptimized() const { return IsOptimized; }
2154 unsigned getRuntimeVersion() const { return RuntimeVersion; }
2156 return (DebugEmissionKind)EmissionKind;
2157 }
2159 return EmissionKind == DebugDirectivesOnly;
2160 }
2161 bool getDebugInfoForProfiling() const { return DebugInfoForProfiling; }
2163 return (DebugNameTableKind)NameTableKind;
2164 }
2165 bool getRangesBaseAddress() const { return RangesBaseAddress; }
2167 StringRef getFlags() const { return getStringOperand(2); }
2169 DICompositeTypeArray getEnumTypes() const {
2171 }
2172 DIScopeArray getRetainedTypes() const {
2174 }
2175 DIGlobalVariableExpressionArray getGlobalVariables() const {
2177 }
2178 DIImportedEntityArray getImportedEntities() const {
2180 }
2181 DIMacroNodeArray getMacros() const {
2183 }
2184 uint64_t getDWOId() const { return DWOId; }
2185 void setDWOId(uint64_t DwoId) { DWOId = DwoId; }
2186 bool getSplitDebugInlining() const { return SplitDebugInlining; }
2187 void setSplitDebugInlining(bool SplitDebugInlining) {
2188 this->SplitDebugInlining = SplitDebugInlining;
2189 }
2191 StringRef getSDK() const { return getStringOperand(10); }
2192
2198 Metadata *getRawEnumTypes() const { return getOperand(4); }
2202 Metadata *getRawMacros() const { return getOperand(8); }
2205
2206 /// Replace arrays.
2207 ///
2208 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
2209 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
2210 /// DICompileUnit should be fairly rare.
2211 /// @{
2212 void replaceEnumTypes(DICompositeTypeArray N) {
2213 replaceOperandWith(4, N.get());
2214 }
2215 void replaceRetainedTypes(DITypeArray N) { replaceOperandWith(5, N.get()); }
2216 void replaceGlobalVariables(DIGlobalVariableExpressionArray N) {
2217 replaceOperandWith(6, N.get());
2218 }
2219 void replaceImportedEntities(DIImportedEntityArray N) {
2220 replaceOperandWith(7, N.get());
2221 }
2222 void replaceMacros(DIMacroNodeArray N) { replaceOperandWith(8, N.get()); }
2223 /// @}
2224
2225 static bool classof(const Metadata *MD) {
2226 return MD->getMetadataID() == DICompileUnitKind;
2227 }
2228};
2229
2230/// A scope for locals.
2231///
2232/// A legal scope for lexical blocks, local variables, and debug info
2233/// locations. Subclasses are \a DISubprogram, \a DILexicalBlock, and \a
2234/// DILexicalBlockFile.
2235class DILocalScope : public DIScope {
2236protected:
2240 ~DILocalScope() = default;
2241
2242public:
2243 /// Get the subprogram for this scope.
2244 ///
2245 /// Return this if it's an \a DISubprogram; otherwise, look up the scope
2246 /// chain.
2248
2249 /// Traverses the scope chain rooted at RootScope until it hits a Subprogram,
2250 /// recreating the chain with "NewSP" instead.
2251 LLVM_ABI static DILocalScope *
2253 LLVMContext &Ctx,
2255
2256 /// Get the first non DILexicalBlockFile scope of this scope.
2257 ///
2258 /// Return this if it's not a \a DILexicalBlockFIle; otherwise, look up the
2259 /// scope chain.
2261
2262 static bool classof(const Metadata *MD) {
2263 return MD->getMetadataID() == DISubprogramKind ||
2264 MD->getMetadataID() == DILexicalBlockKind ||
2265 MD->getMetadataID() == DILexicalBlockFileKind;
2266 }
2267};
2268
2269/// Subprogram description. Uses SubclassData1.
2270class DISubprogram : public DILocalScope {
2271 friend class LLVMContextImpl;
2272 friend class MDNode;
2273
2274 unsigned Line;
2275 unsigned ScopeLine;
2276 unsigned VirtualIndex;
2277
2278 /// In the MS ABI, the implicit 'this' parameter is adjusted in the prologue
2279 /// of method overrides from secondary bases by this amount. It may be
2280 /// negative.
2281 int ThisAdjustment;
2282
2283public:
2284 /// Debug info subprogram flags.
2286#define HANDLE_DISP_FLAG(ID, NAME) SPFlag##NAME = ID,
2287#define DISP_FLAG_LARGEST_NEEDED
2288#include "llvm/IR/DebugInfoFlags.def"
2289 SPFlagNonvirtual = SPFlagZero,
2290 SPFlagVirtuality = SPFlagVirtual | SPFlagPureVirtual,
2291 LLVM_MARK_AS_BITMASK_ENUM(SPFlagLargest)
2292 };
2293
2294 LLVM_ABI static DISPFlags getFlag(StringRef Flag);
2295 LLVM_ABI static StringRef getFlagString(DISPFlags Flag);
2296
2297 /// Split up a flags bitfield for easier printing.
2298 ///
2299 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
2300 /// any remaining (unrecognized) bits.
2301 LLVM_ABI static DISPFlags splitFlags(DISPFlags Flags,
2302 SmallVectorImpl<DISPFlags> &SplitFlags);
2303
2304 // Helper for converting old bitfields to new flags word.
2305 LLVM_ABI static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition,
2306 bool IsOptimized,
2307 unsigned Virtuality = SPFlagNonvirtual,
2308 bool IsMainSubprogram = false);
2309
2310private:
2311 DIFlags Flags;
2312 DISPFlags SPFlags;
2313
2314 DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
2315 unsigned ScopeLine, unsigned VirtualIndex, int ThisAdjustment,
2316 DIFlags Flags, DISPFlags SPFlags, bool UsesKeyInstructions,
2318 ~DISubprogram() = default;
2319
2320 static DISubprogram *
2321 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
2322 StringRef LinkageName, DIFile *File, unsigned Line,
2324 unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags,
2325 DISPFlags SPFlags, DICompileUnit *Unit,
2326 DITemplateParameterArray TemplateParams, DISubprogram *Declaration,
2327 DINodeArray RetainedNodes, DITypeArray ThrownTypes,
2330 bool ShouldCreate = true) {
2331 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
2332 getCanonicalMDString(Context, LinkageName), File, Line, Type,
2334 Flags, SPFlags, Unit, TemplateParams.get(), Declaration,
2335 RetainedNodes.get(), ThrownTypes.get(), Annotations.get(),
2337 UsesKeyInstructions, Storage, ShouldCreate);
2338 }
2339
2340 LLVM_ABI static DISubprogram *
2341 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
2342 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
2343 unsigned ScopeLine, Metadata *ContainingType, unsigned VirtualIndex,
2344 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
2347 MDString *TargetFuncName, bool UsesKeyInstructions,
2348 StorageType Storage, bool ShouldCreate = true);
2349
2350 TempDISubprogram cloneImpl() const {
2352 getFile(), getLine(), getType(), getScopeLine(),
2353 getContainingType(), getVirtualIndex(),
2354 getThisAdjustment(), getFlags(), getSPFlags(),
2355 getUnit(), getTemplateParams(), getDeclaration(),
2356 getRetainedNodes(), getThrownTypes(), getAnnotations(),
2357 getTargetFuncName(), getKeyInstructionsEnabled());
2358 }
2359
2360public:
2362 DISubprogram,
2364 unsigned Line, DISubroutineType *Type, unsigned ScopeLine,
2365 DIType *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
2366 DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit,
2367 DITemplateParameterArray TemplateParams = nullptr,
2368 DISubprogram *Declaration = nullptr, DINodeArray RetainedNodes = nullptr,
2369 DITypeArray ThrownTypes = nullptr, DINodeArray Annotations = nullptr,
2370 StringRef TargetFuncName = "", bool UsesKeyInstructions = false),
2371 (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
2372 VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
2375
2377 DISubprogram,
2379 unsigned Line, Metadata *Type, unsigned ScopeLine,
2380 Metadata *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
2381 DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
2385 bool UsesKeyInstructions = false),
2386 (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
2387 VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
2390
2391 TempDISubprogram clone() const { return cloneImpl(); }
2392
2393 /// Returns a new temporary DISubprogram with updated Flags
2394 TempDISubprogram cloneWithFlags(DIFlags NewFlags) const {
2395 auto NewSP = clone();
2396 NewSP->Flags = NewFlags;
2397 return NewSP;
2398 }
2399
2400 bool getKeyInstructionsEnabled() const { return SubclassData1; }
2401
2402public:
2403 unsigned getLine() const { return Line; }
2404 unsigned getVirtuality() const { return getSPFlags() & SPFlagVirtuality; }
2405 unsigned getVirtualIndex() const { return VirtualIndex; }
2406 int getThisAdjustment() const { return ThisAdjustment; }
2407 unsigned getScopeLine() const { return ScopeLine; }
2408 void setScopeLine(unsigned L) {
2409 assert(isDistinct());
2410 ScopeLine = L;
2411 }
2412 DIFlags getFlags() const { return Flags; }
2413 DISPFlags getSPFlags() const { return SPFlags; }
2414 bool isLocalToUnit() const { return getSPFlags() & SPFlagLocalToUnit; }
2415 bool isDefinition() const { return getSPFlags() & SPFlagDefinition; }
2416 bool isOptimized() const { return getSPFlags() & SPFlagOptimized; }
2417 bool isMainSubprogram() const { return getSPFlags() & SPFlagMainSubprogram; }
2418
2419 bool isArtificial() const { return getFlags() & FlagArtificial; }
2420 bool isPrivate() const {
2421 return (getFlags() & FlagAccessibility) == FlagPrivate;
2422 }
2423 bool isProtected() const {
2424 return (getFlags() & FlagAccessibility) == FlagProtected;
2425 }
2426 bool isPublic() const {
2427 return (getFlags() & FlagAccessibility) == FlagPublic;
2428 }
2429 bool isExplicit() const { return getFlags() & FlagExplicit; }
2430 bool isPrototyped() const { return getFlags() & FlagPrototyped; }
2431 bool areAllCallsDescribed() const {
2432 return getFlags() & FlagAllCallsDescribed;
2433 }
2434 bool isPure() const { return getSPFlags() & SPFlagPure; }
2435 bool isElemental() const { return getSPFlags() & SPFlagElemental; }
2436 bool isRecursive() const { return getSPFlags() & SPFlagRecursive; }
2437 bool isObjCDirect() const { return getSPFlags() & SPFlagObjCDirect; }
2438
2439 /// Check if this is deleted member function.
2440 ///
2441 /// Return true if this subprogram is a C++11 special
2442 /// member function declared deleted.
2443 bool isDeleted() const { return getSPFlags() & SPFlagDeleted; }
2444
2445 /// Check if this is reference-qualified.
2446 ///
2447 /// Return true if this subprogram is a C++11 reference-qualified non-static
2448 /// member function (void foo() &).
2449 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
2450
2451 /// Check if this is rvalue-reference-qualified.
2452 ///
2453 /// Return true if this subprogram is a C++11 rvalue-reference-qualified
2454 /// non-static member function (void foo() &&).
2455 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
2456
2457 /// Check if this is marked as noreturn.
2458 ///
2459 /// Return true if this subprogram is C++11 noreturn or C11 _Noreturn
2460 bool isNoReturn() const { return getFlags() & FlagNoReturn; }
2461
2462 // Check if this routine is a compiler-generated thunk.
2463 //
2464 // Returns true if this subprogram is a thunk generated by the compiler.
2465 bool isThunk() const { return getFlags() & FlagThunk; }
2466
2467 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2468
2469 StringRef getName() const { return getStringOperand(2); }
2470 StringRef getLinkageName() const { return getStringOperand(3); }
2471 /// Only used by clients of CloneFunction, and only right after the cloning.
2472 void replaceLinkageName(MDString *LN) { replaceOperandWith(3, LN); }
2473
2474 DISubroutineType *getType() const {
2475 return cast_or_null<DISubroutineType>(getRawType());
2476 }
2477 DIType *getContainingType() const {
2478 return cast_or_null<DIType>(getRawContainingType());
2479 }
2480 void replaceType(DISubroutineType *Ty) {
2481 assert(isDistinct() && "Only distinct nodes can mutate");
2482 replaceOperandWith(4, Ty);
2483 }
2484
2485 DICompileUnit *getUnit() const {
2486 return cast_or_null<DICompileUnit>(getRawUnit());
2487 }
2488 void replaceUnit(DICompileUnit *CU) { replaceOperandWith(5, CU); }
2489 DITemplateParameterArray getTemplateParams() const {
2490 return cast_or_null<MDTuple>(getRawTemplateParams());
2491 }
2492 DISubprogram *getDeclaration() const {
2493 return cast_or_null<DISubprogram>(getRawDeclaration());
2494 }
2495 void replaceDeclaration(DISubprogram *Decl) { replaceOperandWith(6, Decl); }
2496 DINodeArray getRetainedNodes() const {
2497 return cast_or_null<MDTuple>(getRawRetainedNodes());
2498 }
2499 DITypeArray getThrownTypes() const {
2500 return cast_or_null<MDTuple>(getRawThrownTypes());
2501 }
2502 DINodeArray getAnnotations() const {
2503 return cast_or_null<MDTuple>(getRawAnnotations());
2504 }
2505 StringRef getTargetFuncName() const {
2506 return (getRawTargetFuncName()) ? getStringOperand(12) : StringRef();
2507 }
2508
2509 Metadata *getRawScope() const { return getOperand(1); }
2510 MDString *getRawName() const { return getOperandAs<MDString>(2); }
2511 MDString *getRawLinkageName() const { return getOperandAs<MDString>(3); }
2512 Metadata *getRawType() const { return getOperand(4); }
2513 Metadata *getRawUnit() const { return getOperand(5); }
2514 Metadata *getRawDeclaration() const { return getOperand(6); }
2515 Metadata *getRawRetainedNodes() const { return getOperand(7); }
2516 Metadata *getRawContainingType() const {
2517 return getNumOperands() > 8 ? getOperandAs<Metadata>(8) : nullptr;
2518 }
2519 Metadata *getRawTemplateParams() const {
2520 return getNumOperands() > 9 ? getOperandAs<Metadata>(9) : nullptr;
2521 }
2522 Metadata *getRawThrownTypes() const {
2523 return getNumOperands() > 10 ? getOperandAs<Metadata>(10) : nullptr;
2524 }
2525 Metadata *getRawAnnotations() const {
2526 return getNumOperands() > 11 ? getOperandAs<Metadata>(11) : nullptr;
2527 }
2528 MDString *getRawTargetFuncName() const {
2529 return getNumOperands() > 12 ? getOperandAs<MDString>(12) : nullptr;
2530 }
2531
2532 void replaceRawLinkageName(MDString *LinkageName) {
2534 }
2535 void replaceRetainedNodes(DINodeArray N) {
2536 replaceOperandWith(7, N.get());
2537 }
2538
2539 /// Check if this subprogram describes the given function.
2540 ///
2541 /// FIXME: Should this be looking through bitcasts?
2542 LLVM_ABI bool describes(const Function *F) const;
2543
2544 static bool classof(const Metadata *MD) {
2545 return MD->getMetadataID() == DISubprogramKind;
2546 }
2547};
2548
2549/// Debug location.
2550///
2551/// A debug location in source code, used for debug info and otherwise.
2552///
2553/// Uses the SubclassData1, SubclassData16 and SubclassData32
2554/// Metadata slots.
2555
2556class DILocation : public MDNode {
2557 friend class LLVMContextImpl;
2558 friend class MDNode;
2559 uint64_t AtomGroup : 61;
2560 uint64_t AtomRank : 3;
2561
2562 DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
2563 unsigned Column, uint64_t AtomGroup, uint8_t AtomRank,
2565 ~DILocation() { dropAllReferences(); }
2566
2567 LLVM_ABI static DILocation *
2568 getImpl(LLVMContext &Context, unsigned Line, unsigned Column, Metadata *Scope,
2570 uint8_t AtomRank, StorageType Storage, bool ShouldCreate = true);
2571 static DILocation *getImpl(LLVMContext &Context, unsigned Line,
2572 unsigned Column, DILocalScope *Scope,
2575 StorageType Storage, bool ShouldCreate = true) {
2576 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
2577 static_cast<Metadata *>(InlinedAt), ImplicitCode, AtomGroup,
2578 AtomRank, Storage, ShouldCreate);
2579 }
2580
2581 TempDILocation cloneImpl() const {
2582 // Get the raw scope/inlinedAt since it is possible to invoke this on
2583 // a DILocation containing temporary metadata.
2584 return getTemporary(getContext(), getLine(), getColumn(), getRawScope(),
2585 getRawInlinedAt(), isImplicitCode(), getAtomGroup(),
2586 getAtomRank());
2587 }
2588
2589public:
2590 uint64_t getAtomGroup() const { return AtomGroup; }
2591 uint8_t getAtomRank() const { return AtomRank; }
2592
2593 const DILocation *getWithoutAtom() const {
2594 if (!getAtomGroup() && !getAtomRank())
2595 return this;
2596 return get(getContext(), getLine(), getColumn(), getScope(), getInlinedAt(),
2597 isImplicitCode());
2598 }
2599
2600 // Disallow replacing operands.
2601 void replaceOperandWith(unsigned I, Metadata *New) = delete;
2602
2604 (unsigned Line, unsigned Column, Metadata *Scope,
2605 Metadata *InlinedAt = nullptr, bool ImplicitCode = false,
2606 uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2607 (Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2608 AtomRank))
2609 DEFINE_MDNODE_GET(DILocation,
2610 (unsigned Line, unsigned Column, DILocalScope *Scope,
2611 DILocation *InlinedAt = nullptr, bool ImplicitCode = false,
2612 uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2613 (Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2614 AtomRank))
2615
2616 /// Return a (temporary) clone of this.
2617 TempDILocation clone() const { return cloneImpl(); }
2618
2619 unsigned getLine() const { return SubclassData32; }
2620 unsigned getColumn() const { return SubclassData16; }
2621 DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
2622
2623 /// Return the linkage name of Subprogram. If the linkage name is empty,
2624 /// return scope name (the demangled name).
2625 StringRef getSubprogramLinkageName() const {
2626 DISubprogram *SP = getScope()->getSubprogram();
2627 if (!SP)
2628 return "";
2629 auto Name = SP->getLinkageName();
2630 if (!Name.empty())
2631 return Name;
2632 return SP->getName();
2633 }
2634
2635 DILocation *getInlinedAt() const {
2637 }
2638
2639 /// Check if the location corresponds to an implicit code.
2640 /// When the ImplicitCode flag is true, it means that the Instruction
2641 /// with this DILocation has been added by the front-end but it hasn't been
2642 /// written explicitly by the user (e.g. cleanup stuff in C++ put on a closing
2643 /// bracket). It's useful for code coverage to not show a counter on "empty"
2644 /// lines.
2645 bool isImplicitCode() const { return SubclassData1; }
2646 void setImplicitCode(bool ImplicitCode) { SubclassData1 = ImplicitCode; }
2647
2648 DIFile *getFile() const { return getScope()->getFile(); }
2649 StringRef getFilename() const { return getScope()->getFilename(); }
2650 StringRef getDirectory() const { return getScope()->getDirectory(); }
2651 std::optional<StringRef> getSource() const { return getScope()->getSource(); }
2652
2653 /// Walk through \a getInlinedAt() and return the \a DILocation of the
2654 /// outermost call site in the inlining chain.
2655 const DILocation *getInlinedAtLocation() const {
2656 const DILocation *Current = this;
2657 while (const DILocation *Next = Current->getInlinedAt())
2658 Current = Next;
2659 return Current;
2660 }
2661
2662 // Return the \a DILocalScope of the outermost call site in the inlining
2663 // chain.
2664 DILocalScope *getInlinedAtScope() const {
2665 return getInlinedAtLocation()->getScope();
2666 }
2667
2668 /// Get the DWARF discriminator.
2669 ///
2670 /// DWARF discriminators distinguish identical file locations between
2671 /// instructions that are on different basic blocks.
2672 ///
2673 /// There are 3 components stored in discriminator, from lower bits:
2674 ///
2675 /// Base discriminator: assigned by AddDiscriminators pass to identify IRs
2676 /// that are defined by the same source line, but
2677 /// different basic blocks.
2678 /// Duplication factor: assigned by optimizations that will scale down
2679 /// the execution frequency of the original IR.
2680 /// Copy Identifier: assigned by optimizations that clones the IR.
2681 /// Each copy of the IR will be assigned an identifier.
2682 ///
2683 /// Encoding:
2684 ///
2685 /// The above 3 components are encoded into a 32bit unsigned integer in
2686 /// order. If the lowest bit is 1, the current component is empty, and the
2687 /// next component will start in the next bit. Otherwise, the current
2688 /// component is non-empty, and its content starts in the next bit. The
2689 /// value of each components is either 5 bit or 12 bit: if the 7th bit
2690 /// is 0, the bit 2~6 (5 bits) are used to represent the component; if the
2691 /// 7th bit is 1, the bit 2~6 (5 bits) and 8~14 (7 bits) are combined to
2692 /// represent the component. Thus, the number of bits used for a component
2693 /// is either 0 (if it and all the next components are empty); 1 - if it is
2694 /// empty; 7 - if its value is up to and including 0x1f (lsb and msb are both
2695 /// 0); or 14, if its value is up to and including 0x1ff. Note that the last
2696 /// component is also capped at 0x1ff, even in the case when both first
2697 /// components are 0, and we'd technically have 29 bits available.
2698 ///
2699 /// For precise control over the data being encoded in the discriminator,
2700 /// use encodeDiscriminator/decodeDiscriminator.
2701
2702 inline unsigned getDiscriminator() const;
2703
2704 // For the regular discriminator, it stands for all empty components if all
2705 // the lowest 3 bits are non-zero and all higher 29 bits are unused(zero by
2706 // default). Here we fully leverage the higher 29 bits for pseudo probe use.
2707 // This is the format:
2708 // [2:0] - 0x7
2709 // [31:3] - pseudo probe fields guaranteed to be non-zero as a whole
2710 // So if the lower 3 bits is non-zero and the others has at least one
2711 // non-zero bit, it guarantees to be a pseudo probe discriminator
2712 inline static bool isPseudoProbeDiscriminator(unsigned Discriminator) {
2713 return ((Discriminator & 0x7) == 0x7) && (Discriminator & 0xFFFFFFF8);
2714 }
2715
2716 /// Returns a new DILocation with updated \p Discriminator.
2717 inline const DILocation *cloneWithDiscriminator(unsigned Discriminator) const;
2718
2719 /// Returns a new DILocation with updated base discriminator \p BD. Only the
2720 /// base discriminator is set in the new DILocation, the other encoded values
2721 /// are elided.
2722 /// If the discriminator cannot be encoded, the function returns std::nullopt.
2723 inline std::optional<const DILocation *>
2724 cloneWithBaseDiscriminator(unsigned BD) const;
2725
2726 /// Returns the duplication factor stored in the discriminator, or 1 if no
2727 /// duplication factor (or 0) is encoded.
2728 inline unsigned getDuplicationFactor() const;
2729
2730 /// Returns the copy identifier stored in the discriminator.
2731 inline unsigned getCopyIdentifier() const;
2732
2733 /// Returns the base discriminator stored in the discriminator.
2734 inline unsigned getBaseDiscriminator() const;
2735
2736 /// Returns a new DILocation with duplication factor \p DF * current
2737 /// duplication factor encoded in the discriminator. The current duplication
2738 /// factor is as defined by getDuplicationFactor().
2739 /// Returns std::nullopt if encoding failed.
2740 inline std::optional<const DILocation *>
2742
2743 /// Attempts to merge \p LocA and \p LocB into a single location; see
2744 /// DebugLoc::getMergedLocation for more details.
2745 /// NB: When merging the locations of instructions, prefer to use
2746 /// DebugLoc::getMergedLocation(), as an instruction's DebugLoc may contain
2747 /// additional metadata that will not be preserved when merging the unwrapped
2748 /// DILocations.
2750 DILocation *LocB);
2751
2752 /// Try to combine the vector of locations passed as input in a single one.
2753 /// This function applies getMergedLocation() repeatedly left-to-right.
2754 /// NB: When merging the locations of instructions, prefer to use
2755 /// DebugLoc::getMergedLocations(), as an instruction's DebugLoc may contain
2756 /// additional metadata that will not be preserved when merging the unwrapped
2757 /// DILocations.
2758 ///
2759 /// \p Locs: The locations to be merged.
2761
2762 /// Return the masked discriminator value for an input discrimnator value D
2763 /// (i.e. zero out the (B+1)-th and above bits for D (B is 0-base).
2764 // Example: an input of (0x1FF, 7) returns 0xFF.
2765 static unsigned getMaskedDiscriminator(unsigned D, unsigned B) {
2766 return (D & getN1Bits(B));
2767 }
2768
2769 /// Return the bits used for base discriminators.
2770 static unsigned getBaseDiscriminatorBits() { return getBaseFSBitEnd(); }
2771
2772 /// Returns the base discriminator for a given encoded discriminator \p D.
2773 static unsigned
2775 bool IsFSDiscriminator = false) {
2776 // Extract the dwarf base discriminator if it's encoded in the pseudo probe
2777 // discriminator.
2779 auto DwarfBaseDiscriminator =
2781 if (DwarfBaseDiscriminator)
2782 return *DwarfBaseDiscriminator;
2783 // Return the probe id instead of zero for a pseudo probe discriminator.
2784 // This should help differenciate callsites with same line numbers to
2785 // achieve a decent AutoFDO profile under -fpseudo-probe-for-profiling,
2786 // where the original callsite dwarf discriminator is overwritten by
2787 // callsite probe information.
2789 }
2790
2791 if (IsFSDiscriminator)
2794 }
2795
2796 /// Raw encoding of the discriminator. APIs such as cloneWithDuplicationFactor
2797 /// have certain special case behavior (e.g. treating empty duplication factor
2798 /// as the value '1').
2799 /// This API, in conjunction with cloneWithDiscriminator, may be used to
2800 /// encode the raw values provided.
2801 ///
2802 /// \p BD: base discriminator
2803 /// \p DF: duplication factor
2804 /// \p CI: copy index
2805 ///
2806 /// The return is std::nullopt if the values cannot be encoded in 32 bits -
2807 /// for example, values for BD or DF larger than 12 bits. Otherwise, the
2808 /// return is the encoded value.
2809 LLVM_ABI static std::optional<unsigned>
2810 encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI);
2811
2812 /// Raw decoder for values in an encoded discriminator D.
2813 LLVM_ABI static void decodeDiscriminator(unsigned D, unsigned &BD,
2814 unsigned &DF, unsigned &CI);
2815
2816 /// Returns the duplication factor for a given encoded discriminator \p D, or
2817 /// 1 if no value or 0 is encoded.
2818 static unsigned getDuplicationFactorFromDiscriminator(unsigned D) {
2820 return 1;
2822 unsigned Ret = getUnsignedFromPrefixEncoding(D);
2823 if (Ret == 0)
2824 return 1;
2825 return Ret;
2826 }
2827
2828 /// Returns the copy identifier for a given encoded discriminator \p D.
2833
2834 Metadata *getRawScope() const { return getOperand(0); }
2836 if (getNumOperands() == 2)
2837 return getOperand(1);
2838 return nullptr;
2839 }
2840
2841 static bool classof(const Metadata *MD) {
2842 return MD->getMetadataID() == DILocationKind;
2843 }
2844};
2845
2847protected:
2851
2852public:
2854
2855 Metadata *getRawScope() const { return getOperand(1); }
2856
2857 void replaceScope(DIScope *Scope) {
2858 assert(!isUniqued());
2859 setOperand(1, Scope);
2860 }
2861
2862 static bool classof(const Metadata *MD) {
2863 return MD->getMetadataID() == DILexicalBlockKind ||
2864 MD->getMetadataID() == DILexicalBlockFileKind;
2865 }
2866};
2867
2868/// Debug lexical block.
2869///
2870/// Uses the SubclassData32 Metadata slot.
2871class DILexicalBlock : public DILexicalBlockBase {
2872 friend class LLVMContextImpl;
2873 friend class MDNode;
2874
2875 uint16_t Column;
2876
2877 DILexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
2878 unsigned Column, ArrayRef<Metadata *> Ops)
2879 : DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops),
2880 Column(Column) {
2882 assert(Column < (1u << 16) && "Expected 16-bit column");
2883 }
2884 ~DILexicalBlock() = default;
2885
2886 static DILexicalBlock *getImpl(LLVMContext &Context, DILocalScope *Scope,
2887 DIFile *File, unsigned Line, unsigned Column,
2889 bool ShouldCreate = true) {
2890 return getImpl(Context, static_cast<Metadata *>(Scope),
2891 static_cast<Metadata *>(File), Line, Column, Storage,
2892 ShouldCreate);
2893 }
2894
2895 LLVM_ABI static DILexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
2896 Metadata *File, unsigned Line,
2897 unsigned Column, StorageType Storage,
2898 bool ShouldCreate = true);
2899
2900 TempDILexicalBlock cloneImpl() const {
2902 getColumn());
2903 }
2904
2905public:
2906 DEFINE_MDNODE_GET(DILexicalBlock,
2907 (DILocalScope * Scope, DIFile *File, unsigned Line,
2908 unsigned Column),
2909 (Scope, File, Line, Column))
2910 DEFINE_MDNODE_GET(DILexicalBlock,
2912 unsigned Column),
2913 (Scope, File, Line, Column))
2914
2915 TempDILexicalBlock clone() const { return cloneImpl(); }
2916
2917 unsigned getLine() const { return SubclassData32; }
2918 unsigned getColumn() const { return Column; }
2919
2920 static bool classof(const Metadata *MD) {
2921 return MD->getMetadataID() == DILexicalBlockKind;
2922 }
2923};
2924
2925class DILexicalBlockFile : public DILexicalBlockBase {
2926 friend class LLVMContextImpl;
2927 friend class MDNode;
2928
2929 DILexicalBlockFile(LLVMContext &C, StorageType Storage,
2931 : DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops) {
2933 }
2934 ~DILexicalBlockFile() = default;
2935
2936 static DILexicalBlockFile *getImpl(LLVMContext &Context, DILocalScope *Scope,
2937 DIFile *File, unsigned Discriminator,
2939 bool ShouldCreate = true) {
2940 return getImpl(Context, static_cast<Metadata *>(Scope),
2941 static_cast<Metadata *>(File), Discriminator, Storage,
2942 ShouldCreate);
2943 }
2944
2945 LLVM_ABI static DILexicalBlockFile *getImpl(LLVMContext &Context,
2946 Metadata *Scope, Metadata *File,
2947 unsigned Discriminator,
2949 bool ShouldCreate = true);
2950
2951 TempDILexicalBlockFile cloneImpl() const {
2952 return getTemporary(getContext(), getScope(), getFile(),
2954 }
2955
2956public:
2957 DEFINE_MDNODE_GET(DILexicalBlockFile,
2959 unsigned Discriminator),
2961 DEFINE_MDNODE_GET(DILexicalBlockFile,
2964
2965 TempDILexicalBlockFile clone() const { return cloneImpl(); }
2966 unsigned getDiscriminator() const { return SubclassData32; }
2967
2968 static bool classof(const Metadata *MD) {
2969 return MD->getMetadataID() == DILexicalBlockFileKind;
2970 }
2971};
2972
2973unsigned DILocation::getDiscriminator() const {
2974 if (auto *F = dyn_cast<DILexicalBlockFile>(getScope()))
2975 return F->getDiscriminator();
2976 return 0;
2977}
2978
2979const DILocation *
2980DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
2981 DIScope *Scope = getScope();
2982 // Skip all parent DILexicalBlockFile that already have a discriminator
2983 // assigned. We do not want to have nested DILexicalBlockFiles that have
2984 // multiple discriminators because only the leaf DILexicalBlockFile's
2985 // dominator will be used.
2986 for (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope);
2987 LBF && LBF->getDiscriminator() != 0;
2989 Scope = LBF->getScope();
2990 DILexicalBlockFile *NewScope =
2991 DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator);
2992 return DILocation::get(getContext(), getLine(), getColumn(), NewScope,
2993 getInlinedAt(), isImplicitCode(), getAtomGroup(),
2994 getAtomRank());
2995}
2996
2998 return getBaseDiscriminatorFromDiscriminator(getDiscriminator(),
3000}
3001
3003 return getDuplicationFactorFromDiscriminator(getDiscriminator());
3004}
3005
3007 return getCopyIdentifierFromDiscriminator(getDiscriminator());
3008}
3009
3010std::optional<const DILocation *>
3012 unsigned BD, DF, CI;
3013
3015 BD = getBaseDiscriminator();
3016 if (D == BD)
3017 return this;
3018 return cloneWithDiscriminator(D);
3019 }
3020
3021 decodeDiscriminator(getDiscriminator(), BD, DF, CI);
3022 if (D == BD)
3023 return this;
3024 if (std::optional<unsigned> Encoded = encodeDiscriminator(D, DF, CI))
3025 return cloneWithDiscriminator(*Encoded);
3026 return std::nullopt;
3027}
3028
3029std::optional<const DILocation *>
3031 assert(!EnableFSDiscriminator && "FSDiscriminator should not call this.");
3032 // Do no interfere with pseudo probes. Pseudo probe doesn't need duplication
3033 // factor support as samples collected on cloned probes will be aggregated.
3034 // Also pseudo probe at a callsite uses the dwarf discriminator to store
3035 // pseudo probe related information, such as the probe id.
3036 if (isPseudoProbeDiscriminator(getDiscriminator()))
3037 return this;
3038
3040 if (DF <= 1)
3041 return this;
3042
3043 unsigned BD = getBaseDiscriminator();
3044 unsigned CI = getCopyIdentifier();
3045 if (std::optional<unsigned> D = encodeDiscriminator(BD, DF, CI))
3046 return cloneWithDiscriminator(*D);
3047 return std::nullopt;
3048}
3049
3050/// Debug lexical block.
3051///
3052/// Uses the SubclassData1 Metadata slot.
3053class DINamespace : public DIScope {
3054 friend class LLVMContextImpl;
3055 friend class MDNode;
3056
3057 DINamespace(LLVMContext &Context, StorageType Storage, bool ExportSymbols,
3059 ~DINamespace() = default;
3060
3061 static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope,
3063 StorageType Storage, bool ShouldCreate = true) {
3064 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
3065 ExportSymbols, Storage, ShouldCreate);
3066 }
3067 LLVM_ABI static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope,
3070 bool ShouldCreate = true);
3071
3072 TempDINamespace cloneImpl() const {
3073 return getTemporary(getContext(), getScope(), getName(),
3075 }
3076
3077public:
3081 DEFINE_MDNODE_GET(DINamespace,
3084
3085 TempDINamespace clone() const { return cloneImpl(); }
3086
3087 bool getExportSymbols() const { return SubclassData1; }
3089 StringRef getName() const { return getStringOperand(2); }
3090
3091 Metadata *getRawScope() const { return getOperand(1); }
3093
3094 static bool classof(const Metadata *MD) {
3095 return MD->getMetadataID() == DINamespaceKind;
3096 }
3097};
3098
3099/// Represents a module in the programming language, for example, a Clang
3100/// module, or a Fortran module.
3101///
3102/// Uses the SubclassData1 and SubclassData32 Metadata slots.
3103class DIModule : public DIScope {
3104 friend class LLVMContextImpl;
3105 friend class MDNode;
3106
3107 DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo,
3108 bool IsDecl, ArrayRef<Metadata *> Ops);
3109 ~DIModule() = default;
3110
3111 static DIModule *getImpl(LLVMContext &Context, DIFile *File, DIScope *Scope,
3114 unsigned LineNo, bool IsDecl, StorageType Storage,
3115 bool ShouldCreate = true) {
3116 return getImpl(Context, File, Scope, getCanonicalMDString(Context, Name),
3119 getCanonicalMDString(Context, APINotesFile), LineNo, IsDecl,
3120 Storage, ShouldCreate);
3121 }
3122 LLVM_ABI static DIModule *
3123 getImpl(LLVMContext &Context, Metadata *File, Metadata *Scope, MDString *Name,
3125 MDString *APINotesFile, unsigned LineNo, bool IsDecl,
3126 StorageType Storage, bool ShouldCreate = true);
3127
3128 TempDIModule cloneImpl() const {
3130 getConfigurationMacros(), getIncludePath(),
3131 getAPINotesFile(), getLineNo(), getIsDecl());
3132 }
3133
3134public:
3138 StringRef APINotesFile, unsigned LineNo,
3139 bool IsDecl = false),
3141 APINotesFile, LineNo, IsDecl))
3142 DEFINE_MDNODE_GET(DIModule,
3146 bool IsDecl = false),
3148 APINotesFile, LineNo, IsDecl))
3149
3150 TempDIModule clone() const { return cloneImpl(); }
3151
3152 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
3153 StringRef getName() const { return getStringOperand(2); }
3154 StringRef getConfigurationMacros() const { return getStringOperand(3); }
3155 StringRef getIncludePath() const { return getStringOperand(4); }
3156 StringRef getAPINotesFile() const { return getStringOperand(5); }
3157 unsigned getLineNo() const { return SubclassData32; }
3158 bool getIsDecl() const { return SubclassData1; }
3159
3160 Metadata *getRawScope() const { return getOperand(1); }
3161 MDString *getRawName() const { return getOperandAs<MDString>(2); }
3162 MDString *getRawConfigurationMacros() const {
3163 return getOperandAs<MDString>(3);
3164 }
3165 MDString *getRawIncludePath() const { return getOperandAs<MDString>(4); }
3166 MDString *getRawAPINotesFile() const { return getOperandAs<MDString>(5); }
3167
3168 static bool classof(const Metadata *MD) {
3169 return MD->getMetadataID() == DIModuleKind;
3170 }
3171};
3172
3173/// Base class for template parameters.
3174///
3175/// Uses the SubclassData1 Metadata slot.
3177protected:
3179 unsigned Tag, bool IsDefault, ArrayRef<Metadata *> Ops)
3180 : DINode(Context, ID, Storage, Tag, Ops) {
3181 SubclassData1 = IsDefault;
3182 }
3184
3185public:
3186 StringRef getName() const { return getStringOperand(0); }
3188
3190 Metadata *getRawType() const { return getOperand(1); }
3191 bool isDefault() const { return SubclassData1; }
3192
3193 static bool classof(const Metadata *MD) {
3194 return MD->getMetadataID() == DITemplateTypeParameterKind ||
3195 MD->getMetadataID() == DITemplateValueParameterKind;
3196 }
3197};
3198
3199class DITemplateTypeParameter : public DITemplateParameter {
3200 friend class LLVMContextImpl;
3201 friend class MDNode;
3202
3203 DITemplateTypeParameter(LLVMContext &Context, StorageType Storage,
3205 ~DITemplateTypeParameter() = default;
3206
3207 static DITemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
3208 DIType *Type, bool IsDefault,
3210 bool ShouldCreate = true) {
3211 return getImpl(Context, getCanonicalMDString(Context, Name), Type,
3212 IsDefault, Storage, ShouldCreate);
3213 }
3215 getImpl(LLVMContext &Context, MDString *Name, Metadata *Type, bool IsDefault,
3216 StorageType Storage, bool ShouldCreate = true);
3217
3218 TempDITemplateTypeParameter cloneImpl() const {
3219 return getTemporary(getContext(), getName(), getType(), isDefault());
3220 }
3221
3222public:
3223 DEFINE_MDNODE_GET(DITemplateTypeParameter,
3225 (Name, Type, IsDefault))
3226 DEFINE_MDNODE_GET(DITemplateTypeParameter,
3229
3230 TempDITemplateTypeParameter clone() const { return cloneImpl(); }
3231
3232 static bool classof(const Metadata *MD) {
3233 return MD->getMetadataID() == DITemplateTypeParameterKind;
3234 }
3235};
3236
3237class DITemplateValueParameter : public DITemplateParameter {
3238 friend class LLVMContextImpl;
3239 friend class MDNode;
3240
3241 DITemplateValueParameter(LLVMContext &Context, StorageType Storage,
3242 unsigned Tag, bool IsDefault,
3244 : DITemplateParameter(Context, DITemplateValueParameterKind, Storage, Tag,
3245 IsDefault, Ops) {}
3246 ~DITemplateValueParameter() = default;
3247
3248 static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
3250 bool IsDefault, Metadata *Value,
3252 bool ShouldCreate = true) {
3253 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
3254 IsDefault, Value, Storage, ShouldCreate);
3255 }
3256 LLVM_ABI static DITemplateValueParameter *
3257 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
3258 bool IsDefault, Metadata *Value, StorageType Storage,
3259 bool ShouldCreate = true);
3260
3261 TempDITemplateValueParameter cloneImpl() const {
3262 return getTemporary(getContext(), getTag(), getName(), getType(),
3263 isDefault(), getValue());
3264 }
3265
3266public:
3267 DEFINE_MDNODE_GET(DITemplateValueParameter,
3268 (unsigned Tag, StringRef Name, DIType *Type, bool IsDefault,
3269 Metadata *Value),
3270 (Tag, Name, Type, IsDefault, Value))
3271 DEFINE_MDNODE_GET(DITemplateValueParameter,
3275
3276 TempDITemplateValueParameter clone() const { return cloneImpl(); }
3277
3278 Metadata *getValue() const { return getOperand(2); }
3279
3280 static bool classof(const Metadata *MD) {
3281 return MD->getMetadataID() == DITemplateValueParameterKind;
3282 }
3283};
3284
3285/// Base class for variables.
3286///
3287/// Uses the SubclassData32 Metadata slot.
3288class DIVariable : public DINode {
3289 unsigned Line;
3290
3291protected:
3293 signed Line, ArrayRef<Metadata *> Ops,
3294 uint32_t AlignInBits = 0);
3295 ~DIVariable() = default;
3296
3297public:
3298 unsigned getLine() const { return Line; }
3300 StringRef getName() const { return getStringOperand(1); }
3304 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
3305 /// Determines the size of the variable's type.
3306 LLVM_ABI std::optional<uint64_t> getSizeInBits() const;
3307
3308 /// Return the signedness of this variable's type, or std::nullopt if this
3309 /// type is neither signed nor unsigned.
3310 std::optional<DIBasicType::Signedness> getSignedness() const {
3311 if (auto *BT = dyn_cast<DIBasicType>(getType()))
3312 return BT->getSignedness();
3313 return std::nullopt;
3314 }
3315
3317 if (auto *F = getFile())
3318 return F->getFilename();
3319 return "";
3320 }
3321
3323 if (auto *F = getFile())
3324 return F->getDirectory();
3325 return "";
3326 }
3327
3328 std::optional<StringRef> getSource() const {
3329 if (auto *F = getFile())
3330 return F->getSource();
3331 return std::nullopt;
3332 }
3333
3334 Metadata *getRawScope() const { return getOperand(0); }
3336 Metadata *getRawFile() const { return getOperand(2); }
3337 Metadata *getRawType() const { return getOperand(3); }
3338
3339 static bool classof(const Metadata *MD) {
3340 return MD->getMetadataID() == DILocalVariableKind ||
3341 MD->getMetadataID() == DIGlobalVariableKind;
3342 }
3343};
3344
3345/// DWARF expression.
3346///
3347/// This is (almost) a DWARF expression that modifies the location of a
3348/// variable, or the location of a single piece of a variable, or (when using
3349/// DW_OP_stack_value) is the constant variable value.
3350///
3351/// TODO: Co-allocate the expression elements.
3352/// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
3353/// storage types.
3354class DIExpression : public MDNode {
3355 friend class LLVMContextImpl;
3356 friend class MDNode;
3357
3358 std::vector<uint64_t> Elements;
3359
3360 DIExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
3361 : MDNode(C, DIExpressionKind, Storage, {}),
3362 Elements(Elements.begin(), Elements.end()) {}
3363 ~DIExpression() = default;
3364
3365 LLVM_ABI static DIExpression *getImpl(LLVMContext &Context,
3366 ArrayRef<uint64_t> Elements,
3368 bool ShouldCreate = true);
3369
3370 TempDIExpression cloneImpl() const {
3371 return getTemporary(getContext(), getElements());
3372 }
3373
3374public:
3375 DEFINE_MDNODE_GET(DIExpression, (ArrayRef<uint64_t> Elements), (Elements))
3376
3377 TempDIExpression clone() const { return cloneImpl(); }
3378
3379 ArrayRef<uint64_t> getElements() const { return Elements; }
3380
3381 unsigned getNumElements() const { return Elements.size(); }
3382
3383 uint64_t getElement(unsigned I) const {
3384 assert(I < Elements.size() && "Index out of range");
3385 return Elements[I];
3386 }
3387
3389 /// Determine whether this represents a constant value, if so
3390 // return it's sign information.
3391 LLVM_ABI std::optional<SignedOrUnsignedConstant> isConstant() const;
3392
3393 /// Return the number of unique location operands referred to (via
3394 /// DW_OP_LLVM_arg) in this expression; this is not necessarily the number of
3395 /// instances of DW_OP_LLVM_arg within the expression.
3396 /// For example, for the expression:
3397 /// (DW_OP_LLVM_arg 0, DW_OP_LLVM_arg 1, DW_OP_plus,
3398 /// DW_OP_LLVM_arg 0, DW_OP_mul)
3399 /// This function would return 2, as there are two unique location operands
3400 /// (0 and 1).
3402
3404
3407
3408 /// A lightweight wrapper around an expression operand.
3409 ///
3410 /// TODO: Store arguments directly and change \a DIExpression to store a
3411 /// range of these.
3413 const uint64_t *Op = nullptr;
3414
3415 public:
3416 ExprOperand() = default;
3417 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
3418
3419 const uint64_t *get() const { return Op; }
3420
3421 /// Get the operand code.
3422 uint64_t getOp() const { return *Op; }
3423
3424 /// Get an argument to the operand.
3425 ///
3426 /// Never returns the operand itself.
3427 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
3428
3429 unsigned getNumArgs() const { return getSize() - 1; }
3430
3431 /// Return the size of the operand.
3432 ///
3433 /// Return the number of elements in the operand (1 + args).
3434 LLVM_ABI unsigned getSize() const;
3435
3436 /// Append the elements of this operand to \p V.
3438 V.append(get(), get() + getSize());
3439 }
3440 };
3441
3442 /// An iterator for expression operands.
3444 ExprOperand Op;
3445
3446 public:
3447 using iterator_category = std::input_iterator_tag;
3449 using difference_type = std::ptrdiff_t;
3452
3453 expr_op_iterator() = default;
3455
3456 element_iterator getBase() const { return Op.get(); }
3457 const ExprOperand &operator*() const { return Op; }
3458 const ExprOperand *operator->() const { return &Op; }
3459
3461 increment();
3462 return *this;
3463 }
3465 expr_op_iterator T(*this);
3466 increment();
3467 return T;
3468 }
3469
3470 /// Get the next iterator.
3471 ///
3472 /// \a std::next() doesn't work because this is technically an
3473 /// input_iterator, but it's a perfectly valid operation. This is an
3474 /// accessor to provide the same functionality.
3475 expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
3476
3477 bool operator==(const expr_op_iterator &X) const {
3478 return getBase() == X.getBase();
3479 }
3480 bool operator!=(const expr_op_iterator &X) const {
3481 return getBase() != X.getBase();
3482 }
3483
3484 private:
3485 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
3486 };
3487
3488 /// Visit the elements via ExprOperand wrappers.
3489 ///
3490 /// These range iterators visit elements through \a ExprOperand wrappers.
3491 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
3492 /// true.
3493 ///
3494 /// \pre \a isValid() gives \c true.
3495 /// @{
3505 /// @}
3506
3507 LLVM_ABI bool isValid() const;
3508
3509 static bool classof(const Metadata *MD) {
3510 return MD->getMetadataID() == DIExpressionKind;
3511 }
3512
3513 /// Return whether the first element a DW_OP_deref.
3514 LLVM_ABI bool startsWithDeref() const;
3515
3516 /// Return whether there is exactly one operator and it is a DW_OP_deref;
3517 LLVM_ABI bool isDeref() const;
3518
3520
3521 /// Return the number of bits that have an active value, i.e. those that
3522 /// aren't known to be zero/sign (depending on the type of Var) and which
3523 /// are within the size of this fragment (if it is one). If we can't deduce
3524 /// anything from the expression this will return the size of Var.
3525 LLVM_ABI std::optional<uint64_t> getActiveBits(DIVariable *Var);
3526
3527 /// Retrieve the details of this fragment expression.
3528 LLVM_ABI static std::optional<FragmentInfo>
3530
3531 /// Retrieve the details of this fragment expression.
3532 std::optional<FragmentInfo> getFragmentInfo() const {
3534 }
3535
3536 /// Return whether this is a piece of an aggregate variable.
3537 bool isFragment() const { return getFragmentInfo().has_value(); }
3538
3539 /// Return whether this is an implicit location description.
3540 LLVM_ABI bool isImplicit() const;
3541
3542 /// Return whether the location is computed on the expression stack, meaning
3543 /// it cannot be a simple register location.
3544 LLVM_ABI bool isComplex() const;
3545
3546 /// Return whether the evaluated expression makes use of a single location at
3547 /// the start of the expression, i.e. if it contains only a single
3548 /// DW_OP_LLVM_arg op as its first operand, or if it contains none.
3550
3551 /// Returns a reference to the elements contained in this expression, skipping
3552 /// past the leading `DW_OP_LLVM_arg, 0` if one is present.
3553 /// Similar to `convertToNonVariadicExpression`, but faster and cheaper - it
3554 /// does not check whether the expression is a single-location expression, and
3555 /// it returns elements rather than creating a new DIExpression.
3556 LLVM_ABI std::optional<ArrayRef<uint64_t>>
3558
3559 /// Removes all elements from \p Expr that do not apply to an undef debug
3560 /// value, which includes every operator that computes the value/location on
3561 /// the DWARF stack, including any DW_OP_LLVM_arg elements (making the result
3562 /// of this function always a single-location expression) while leaving
3563 /// everything that defines what the computed value applies to, i.e. the
3564 /// fragment information.
3565 LLVM_ABI static const DIExpression *
3567
3568 /// If \p Expr is a non-variadic expression (i.e. one that does not contain
3569 /// DW_OP_LLVM_arg), returns \p Expr converted to variadic form by adding a
3570 /// leading [DW_OP_LLVM_arg, 0] to the expression; otherwise returns \p Expr.
3571 LLVM_ABI static const DIExpression *
3573
3574 /// If \p Expr is a valid single-location expression, i.e. it refers to only a
3575 /// single debug operand at the start of the expression, then return that
3576 /// expression in a non-variadic form by removing DW_OP_LLVM_arg from the
3577 /// expression if it is present; otherwise returns std::nullopt.
3578 /// See also `getSingleLocationExpressionElements` above, which skips
3579 /// checking `isSingleLocationExpression` and returns a list of elements
3580 /// rather than a DIExpression.
3581 LLVM_ABI static std::optional<const DIExpression *>
3583
3584 /// Inserts the elements of \p Expr into \p Ops modified to a canonical form,
3585 /// which uses DW_OP_LLVM_arg (i.e. is a variadic expression) and folds the
3586 /// implied derefence from the \p IsIndirect flag into the expression. This
3587 /// allows us to check equivalence between expressions with differing
3588 /// directness or variadicness.
3590 const DIExpression *Expr,
3591 bool IsIndirect);
3592
3593 /// Determines whether two debug values should produce equivalent DWARF
3594 /// expressions, using their DIExpressions and directness, ignoring the
3595 /// differences between otherwise identical expressions in variadic and
3596 /// non-variadic form and not considering the debug operands.
3597 /// \p FirstExpr is the DIExpression for the first debug value.
3598 /// \p FirstIndirect should be true if the first debug value is indirect; in
3599 /// IR this should be true for dbg.declare intrinsics and false for
3600 /// dbg.values, and in MIR this should be true only for DBG_VALUE instructions
3601 /// whose second operand is an immediate value.
3602 /// \p SecondExpr and \p SecondIndirect have the same meaning as the prior
3603 /// arguments, but apply to the second debug value.
3604 LLVM_ABI static bool isEqualExpression(const DIExpression *FirstExpr,
3605 bool FirstIndirect,
3606 const DIExpression *SecondExpr,
3607 bool SecondIndirect);
3608
3609 /// Append \p Ops with operations to apply the \p Offset.
3611 int64_t Offset);
3612
3613 /// If this is a constant offset, extract it. If there is no expression,
3614 /// return true with an offset of zero.
3615 LLVM_ABI bool extractIfOffset(int64_t &Offset) const;
3616
3617 /// Assuming that the expression operates on an address, extract a constant
3618 /// offset and the successive ops. Return false if the expression contains
3619 /// any incompatible ops (including non-zero DW_OP_LLVM_args - only a single
3620 /// address operand to the expression is permitted).
3621 ///
3622 /// We don't try very hard to interpret the expression because we assume that
3623 /// foldConstantMath has canonicalized the expression.
3624 LLVM_ABI bool
3625 extractLeadingOffset(int64_t &OffsetInBytes,
3626 SmallVectorImpl<uint64_t> &RemainingOps) const;
3627
3628 /// Returns true iff this DIExpression contains at least one instance of
3629 /// `DW_OP_LLVM_arg, n` for all n in [0, N).
3630 LLVM_ABI bool hasAllLocationOps(unsigned N) const;
3631
3632 /// Checks if the last 4 elements of the expression are DW_OP_constu <DWARF
3633 /// Address Space> DW_OP_swap DW_OP_xderef and extracts the <DWARF Address
3634 /// Space>.
3635 LLVM_ABI static const DIExpression *
3636 extractAddressClass(const DIExpression *Expr, unsigned &AddrClass);
3637
3638 /// Used for DIExpression::prepend.
3641 DerefBefore = 1 << 0,
3642 DerefAfter = 1 << 1,
3643 StackValue = 1 << 2,
3644 EntryValue = 1 << 3
3645 };
3646
3647 /// Prepend \p DIExpr with a deref and offset operation and optionally turn it
3648 /// into a stack value or/and an entry value.
3649 LLVM_ABI static DIExpression *prepend(const DIExpression *Expr, uint8_t Flags,
3650 int64_t Offset = 0);
3651
3652 /// Prepend \p DIExpr with the given opcodes and optionally turn it into a
3653 /// stack value.
3656 bool StackValue = false,
3657 bool EntryValue = false);
3658
3659 /// Append the opcodes \p Ops to \p DIExpr. Unlike \ref appendToStack, the
3660 /// returned expression is a stack value only if \p DIExpr is a stack value.
3661 /// If \p DIExpr describes a fragment, the returned expression will describe
3662 /// the same fragment.
3663 LLVM_ABI static DIExpression *append(const DIExpression *Expr,
3665
3666 /// Convert \p DIExpr into a stack value if it isn't one already by appending
3667 /// DW_OP_deref if needed, and appending \p Ops to the resulting expression.
3668 /// If \p DIExpr describes a fragment, the returned expression will describe
3669 /// the same fragment.
3670 LLVM_ABI static DIExpression *appendToStack(const DIExpression *Expr,
3672
3673 /// Create a copy of \p Expr by appending the given list of \p Ops to each
3674 /// instance of the operand `DW_OP_LLVM_arg, \p ArgNo`. This is used to
3675 /// modify a specific location used by \p Expr, such as when salvaging that
3676 /// location.
3679 unsigned ArgNo,
3680 bool StackValue = false);
3681
3682 /// Create a copy of \p Expr with each instance of
3683 /// `DW_OP_LLVM_arg, \p OldArg` replaced with `DW_OP_LLVM_arg, \p NewArg`,
3684 /// and each instance of `DW_OP_LLVM_arg, Arg` with `DW_OP_LLVM_arg, Arg - 1`
3685 /// for all Arg > \p OldArg.
3686 /// This is used when replacing one of the operands of a debug value list
3687 /// with another operand in the same list and deleting the old operand.
3688 LLVM_ABI static DIExpression *replaceArg(const DIExpression *Expr,
3689 uint64_t OldArg, uint64_t NewArg);
3690
3691 /// Create a DIExpression to describe one part of an aggregate variable that
3692 /// is fragmented across multiple Values. The DW_OP_LLVM_fragment operation
3693 /// will be appended to the elements of \c Expr. If \c Expr already contains
3694 /// a \c DW_OP_LLVM_fragment \c OffsetInBits is interpreted as an offset
3695 /// into the existing fragment.
3696 ///
3697 /// \param OffsetInBits Offset of the piece in bits.
3698 /// \param SizeInBits Size of the piece in bits.
3699 /// \return Creating a fragment expression may fail if \c Expr
3700 /// contains arithmetic operations that would be
3701 /// truncated.
3702 LLVM_ABI static std::optional<DIExpression *>
3703 createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits,
3704 unsigned SizeInBits);
3705
3706 /// Determine the relative position of the fragments passed in.
3707 /// Returns -1 if this is entirely before Other, 0 if this and Other overlap,
3708 /// 1 if this is entirely after Other.
3709 static int fragmentCmp(const FragmentInfo &A, const FragmentInfo &B) {
3710 uint64_t l1 = A.OffsetInBits;
3711 uint64_t l2 = B.OffsetInBits;
3712 uint64_t r1 = l1 + A.SizeInBits;
3713 uint64_t r2 = l2 + B.SizeInBits;
3714 if (r1 <= l2)
3715 return -1;
3716 else if (r2 <= l1)
3717 return 1;
3718 else
3719 return 0;
3720 }
3721
3722 /// Computes a fragment, bit-extract operation if needed, and new constant
3723 /// offset to describe a part of a variable covered by some memory.
3724 ///
3725 /// The memory region starts at:
3726 /// \p SliceStart + \p SliceOffsetInBits
3727 /// And is size:
3728 /// \p SliceSizeInBits
3729 ///
3730 /// The location of the existing variable fragment \p VarFrag is:
3731 /// \p DbgPtr + \p DbgPtrOffsetInBits + \p DbgExtractOffsetInBits.
3732 ///
3733 /// It is intended that these arguments are derived from a debug record:
3734 /// - \p DbgPtr is the (single) DIExpression operand.
3735 /// - \p DbgPtrOffsetInBits is the constant offset applied to \p DbgPtr.
3736 /// - \p DbgExtractOffsetInBits is the offset from a
3737 /// DW_OP_LLVM_bit_extract_[sz]ext operation.
3738 ///
3739 /// Results and return value:
3740 /// - Return false if the result can't be calculated for any reason.
3741 /// - \p Result is set to nullopt if the intersect equals \p VarFarg.
3742 /// - \p Result contains a zero-sized fragment if there's no intersect.
3743 /// - \p OffsetFromLocationInBits is set to the difference between the first
3744 /// bit of the variable location and the first bit of the slice. The
3745 /// magnitude of a negative value therefore indicates the number of bits
3746 /// into the variable fragment that the memory region begins.
3747 ///
3748 /// We don't pass in a debug record directly to get the constituent parts
3749 /// and offsets because different debug records store the information in
3750 /// different places (dbg_assign has two DIExpressions - one contains the
3751 /// fragment info for the entire intrinsic).
3753 const DataLayout &DL, const Value *SliceStart, uint64_t SliceOffsetInBits,
3754 uint64_t SliceSizeInBits, const Value *DbgPtr, int64_t DbgPtrOffsetInBits,
3755 int64_t DbgExtractOffsetInBits, DIExpression::FragmentInfo VarFrag,
3756 std::optional<DIExpression::FragmentInfo> &Result,
3757 int64_t &OffsetFromLocationInBits);
3758
3759 using ExtOps = std::array<uint64_t, 6>;
3760
3761 /// Returns the ops for a zero- or sign-extension in a DIExpression.
3762 LLVM_ABI static ExtOps getExtOps(unsigned FromSize, unsigned ToSize,
3763 bool Signed);
3764
3765 /// Append a zero- or sign-extension to \p Expr. Converts the expression to a
3766 /// stack value if it isn't one already.
3767 LLVM_ABI static DIExpression *appendExt(const DIExpression *Expr,
3768 unsigned FromSize, unsigned ToSize,
3769 bool Signed);
3770
3771 /// Check if fragments overlap between a pair of FragmentInfos.
3772 static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B) {
3773 return fragmentCmp(A, B) == 0;
3774 }
3775
3776 /// Determine the relative position of the fragments described by this
3777 /// DIExpression and \p Other. Calls static fragmentCmp implementation.
3778 int fragmentCmp(const DIExpression *Other) const {
3779 auto Fragment1 = *getFragmentInfo();
3780 auto Fragment2 = *Other->getFragmentInfo();
3781 return fragmentCmp(Fragment1, Fragment2);
3782 }
3783
3784 /// Check if fragments overlap between this DIExpression and \p Other.
3785 bool fragmentsOverlap(const DIExpression *Other) const {
3786 if (!isFragment() || !Other->isFragment())
3787 return true;
3788 return fragmentCmp(Other) == 0;
3789 }
3790
3791 /// Check if the expression consists of exactly one entry value operand.
3792 /// (This is the only configuration of entry values that is supported.)
3793 LLVM_ABI bool isEntryValue() const;
3794
3795 /// Try to shorten an expression with an initial constant operand.
3796 /// Returns a new expression and constant on success, or the original
3797 /// expression and constant on failure.
3798 LLVM_ABI std::pair<DIExpression *, const ConstantInt *>
3799 constantFold(const ConstantInt *CI);
3800
3801 /// Try to shorten an expression with constant math operations that can be
3802 /// evaluated at compile time. Returns a new expression on success, or the old
3803 /// expression if there is nothing to be reduced.
3805};
3806
3809 return std::tie(A.SizeInBits, A.OffsetInBits) ==
3810 std::tie(B.SizeInBits, B.OffsetInBits);
3811}
3812
3815 return std::tie(A.SizeInBits, A.OffsetInBits) <
3816 std::tie(B.SizeInBits, B.OffsetInBits);
3817}
3818
3819template <> struct DenseMapInfo<DIExpression::FragmentInfo> {
3821 static const uint64_t MaxVal = std::numeric_limits<uint64_t>::max();
3822
3823 static inline FragInfo getEmptyKey() { return {MaxVal, MaxVal}; }
3824
3825 static inline FragInfo getTombstoneKey() { return {MaxVal - 1, MaxVal - 1}; }
3826
3827 static unsigned getHashValue(const FragInfo &Frag) {
3828 return (Frag.SizeInBits & 0xffff) << 16 | (Frag.OffsetInBits & 0xffff);
3829 }
3830
3831 static bool isEqual(const FragInfo &A, const FragInfo &B) { return A == B; }
3832};
3833
3834/// Holds a DIExpression and keeps track of how many operands have been consumed
3835/// so far.
3838
3839public:
3841 if (!Expr) {
3842 assert(Start == End);
3843 return;
3844 }
3845 Start = Expr->expr_op_begin();
3846 End = Expr->expr_op_end();
3847 }
3848
3850 : Start(Expr.begin()), End(Expr.end()) {}
3851
3853
3854 /// Consume one operation.
3855 std::optional<DIExpression::ExprOperand> take() {
3856 if (Start == End)
3857 return std::nullopt;
3858 return *(Start++);
3859 }
3860
3861 /// Consume N operations.
3862 void consume(unsigned N) { std::advance(Start, N); }
3863
3864 /// Return the current operation.
3865 std::optional<DIExpression::ExprOperand> peek() const {
3866 if (Start == End)
3867 return std::nullopt;
3868 return *(Start);
3869 }
3870
3871 /// Return the next operation.
3872 std::optional<DIExpression::ExprOperand> peekNext() const {
3873 if (Start == End)
3874 return std::nullopt;
3875
3876 auto Next = Start.getNext();
3877 if (Next == End)
3878 return std::nullopt;
3879
3880 return *Next;
3881 }
3882
3883 std::optional<DIExpression::ExprOperand> peekNextN(unsigned N) const {
3884 if (Start == End)
3885 return std::nullopt;
3887 for (unsigned I = 0; I < N; I++) {
3888 Nth = Nth.getNext();
3889 if (Nth == End)
3890 return std::nullopt;
3891 }
3892 return *Nth;
3893 }
3894
3896 this->Start = DIExpression::expr_op_iterator(Expr.begin());
3897 this->End = DIExpression::expr_op_iterator(Expr.end());
3898 }
3899
3900 /// Determine whether there are any operations left in this expression.
3901 operator bool() const { return Start != End; }
3902
3903 DIExpression::expr_op_iterator begin() const { return Start; }
3904 DIExpression::expr_op_iterator end() const { return End; }
3905
3906 /// Retrieve the fragment information, if any.
3907 std::optional<DIExpression::FragmentInfo> getFragmentInfo() const {
3908 return DIExpression::getFragmentInfo(Start, End);
3909 }
3910};
3911
3912/// Global variables.
3913///
3914/// TODO: Remove DisplayName. It's always equal to Name.
3915class DIGlobalVariable : public DIVariable {
3916 friend class LLVMContextImpl;
3917 friend class MDNode;
3918
3919 bool IsLocalToUnit;
3920 bool IsDefinition;
3921
3922 DIGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
3923 bool IsLocalToUnit, bool IsDefinition, uint32_t AlignInBits,
3925 : DIVariable(C, DIGlobalVariableKind, Storage, Line, Ops, AlignInBits),
3926 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
3927 ~DIGlobalVariable() = default;
3928
3929 static DIGlobalVariable *
3930 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
3931 StringRef LinkageName, DIFile *File, unsigned Line, DIType *Type,
3932 bool IsLocalToUnit, bool IsDefinition,
3935 bool ShouldCreate = true) {
3936 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
3937 getCanonicalMDString(Context, LinkageName), File, Line, Type,
3940 Annotations.get(), Storage, ShouldCreate);
3941 }
3942 LLVM_ABI static DIGlobalVariable *
3943 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
3944 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
3945 bool IsLocalToUnit, bool IsDefinition,
3948 bool ShouldCreate = true);
3949
3950 TempDIGlobalVariable cloneImpl() const {
3955 getAnnotations());
3956 }
3957
3958public:
3960 DIGlobalVariable,
3962 unsigned Line, DIType *Type, bool IsLocalToUnit, bool IsDefinition,
3964 uint32_t AlignInBits, DINodeArray Annotations),
3965 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
3968 DIGlobalVariable,
3970 unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
3973 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
3975
3976 TempDIGlobalVariable clone() const { return cloneImpl(); }
3977
3978 bool isLocalToUnit() const { return IsLocalToUnit; }
3979 bool isDefinition() const { return IsDefinition; }
3985 DINodeArray getAnnotations() const {
3987 }
3988
3993 Metadata *getRawAnnotations() const { return getOperand(8); }
3994
3995 static bool classof(const Metadata *MD) {
3996 return MD->getMetadataID() == DIGlobalVariableKind;
3997 }
3998};
3999
4000/// Debug common block.
4001///
4002/// Uses the SubclassData32 Metadata slot.
4003class DICommonBlock : public DIScope {
4004 friend class LLVMContextImpl;
4005 friend class MDNode;
4006
4007 DICommonBlock(LLVMContext &Context, StorageType Storage, unsigned LineNo,
4009
4010 static DICommonBlock *getImpl(LLVMContext &Context, DIScope *Scope,
4012 DIFile *File, unsigned LineNo,
4013 StorageType Storage, bool ShouldCreate = true) {
4014 return getImpl(Context, Scope, Decl, getCanonicalMDString(Context, Name),
4015 File, LineNo, Storage, ShouldCreate);
4016 }
4017 LLVM_ABI static DICommonBlock *getImpl(LLVMContext &Context, Metadata *Scope,
4019 Metadata *File, unsigned LineNo,
4021 bool ShouldCreate = true);
4022
4023 TempDICommonBlock cloneImpl() const {
4025 getFile(), getLineNo());
4026 }
4027
4028public:
4029 DEFINE_MDNODE_GET(DICommonBlock,
4031 DIFile *File, unsigned LineNo),
4032 (Scope, Decl, Name, File, LineNo))
4033 DEFINE_MDNODE_GET(DICommonBlock,
4035 Metadata *File, unsigned LineNo),
4037
4038 TempDICommonBlock clone() const { return cloneImpl(); }
4039
4044 StringRef getName() const { return getStringOperand(2); }
4046 unsigned getLineNo() const { return SubclassData32; }
4047
4048 Metadata *getRawScope() const { return getOperand(0); }
4049 Metadata *getRawDecl() const { return getOperand(1); }
4051 Metadata *getRawFile() const { return getOperand(3); }
4052
4053 static bool classof(const Metadata *MD) {
4054 return MD->getMetadataID() == DICommonBlockKind;
4055 }
4056};
4057
4058/// Local variable.
4059///
4060/// TODO: Split up flags.
4061class DILocalVariable : public DIVariable {
4062 friend class LLVMContextImpl;
4063 friend class MDNode;
4064
4065 unsigned Arg : 16;
4066 DIFlags Flags;
4067
4068 DILocalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
4069 unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
4071 : DIVariable(C, DILocalVariableKind, Storage, Line, Ops, AlignInBits),
4072 Arg(Arg), Flags(Flags) {
4073 assert(Arg < (1 << 16) && "DILocalVariable: Arg out of range");
4074 }
4075 ~DILocalVariable() = default;
4076
4077 static DILocalVariable *getImpl(LLVMContext &Context, DIScope *Scope,
4078 StringRef Name, DIFile *File, unsigned Line,
4079 DIType *Type, unsigned Arg, DIFlags Flags,
4080 uint32_t AlignInBits, DINodeArray Annotations,
4082 bool ShouldCreate = true) {
4083 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
4084 Line, Type, Arg, Flags, AlignInBits, Annotations.get(),
4085 Storage, ShouldCreate);
4086 }
4087 LLVM_ABI static DILocalVariable *
4088 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, Metadata *File,
4089 unsigned Line, Metadata *Type, unsigned Arg, DIFlags Flags,
4091 bool ShouldCreate = true);
4092
4093 TempDILocalVariable cloneImpl() const {
4095 getLine(), getType(), getArg(), getFlags(),
4097 }
4098
4099public:
4100 DEFINE_MDNODE_GET(DILocalVariable,
4102 unsigned Line, DIType *Type, unsigned Arg, DIFlags Flags,
4103 uint32_t AlignInBits, DINodeArray Annotations),
4104 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits,
4105 Annotations))
4106 DEFINE_MDNODE_GET(DILocalVariable,
4108 unsigned Line, Metadata *Type, unsigned Arg, DIFlags Flags,
4110 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits,
4111 Annotations))
4112
4113 TempDILocalVariable clone() const { return cloneImpl(); }
4114
4115 /// Get the local scope for this variable.
4116 ///
4117 /// Variables must be defined in a local scope.
4121
4122 bool isParameter() const { return Arg; }
4123 unsigned getArg() const { return Arg; }
4124 DIFlags getFlags() const { return Flags; }
4125
4126 DINodeArray getAnnotations() const {
4128 }
4129 Metadata *getRawAnnotations() const { return getOperand(4); }
4130
4131 bool isArtificial() const { return getFlags() & FlagArtificial; }
4132 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
4133
4134 /// Check that a location is valid for this variable.
4135 ///
4136 /// Check that \c DL exists, is in the same subprogram, and has the same
4137 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
4138 /// to a \a DbgInfoIntrinsic.)
4140 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
4141 }
4142
4143 static bool classof(const Metadata *MD) {
4144 return MD->getMetadataID() == DILocalVariableKind;
4145 }
4146};
4147
4148/// Label.
4149///
4150/// Uses the SubclassData32 Metadata slot.
4151class DILabel : public DINode {
4152 friend class LLVMContextImpl;
4153 friend class MDNode;
4154
4155 unsigned Column;
4156 std::optional<unsigned> CoroSuspendIdx;
4157 bool IsArtificial;
4158
4159 DILabel(LLVMContext &C, StorageType Storage, unsigned Line, unsigned Column,
4160 bool IsArtificial, std::optional<unsigned> CoroSuspendIdx,
4162 ~DILabel() = default;
4163
4164 static DILabel *getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
4165 DIFile *File, unsigned Line, unsigned Column,
4166 bool IsArtificial,
4167 std::optional<unsigned> CoroSuspendIdx,
4168 StorageType Storage, bool ShouldCreate = true) {
4169 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
4170 Line, Column, IsArtificial, CoroSuspendIdx, Storage,
4171 ShouldCreate);
4172 }
4173 LLVM_ABI static DILabel *
4174 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, Metadata *File,
4175 unsigned Line, unsigned Column, bool IsArtificial,
4176 std::optional<unsigned> CoroSuspendIdx, StorageType Storage,
4177 bool ShouldCreate = true);
4178
4179 TempDILabel cloneImpl() const {
4183 }
4184
4185public:
4188 unsigned Line, unsigned Column, bool IsArtificial,
4189 std::optional<unsigned> CoroSuspendIdx),
4190 (Scope, Name, File, Line, Column, IsArtificial,
4191 CoroSuspendIdx))
4192 DEFINE_MDNODE_GET(DILabel,
4194 unsigned Line, unsigned Column, bool IsArtificial,
4195 std::optional<unsigned> CoroSuspendIdx),
4196 (Scope, Name, File, Line, Column, IsArtificial,
4197 CoroSuspendIdx))
4198
4199 TempDILabel clone() const { return cloneImpl(); }
4200
4201 /// Get the local scope for this label.
4202 ///
4203 /// Labels must be defined in a local scope.
4207 unsigned getLine() const { return SubclassData32; }
4208 unsigned getColumn() const { return Column; }
4209 StringRef getName() const { return getStringOperand(1); }
4211 bool isArtificial() const { return IsArtificial; }
4212 std::optional<unsigned> getCoroSuspendIdx() const { return CoroSuspendIdx; }
4213
4214 Metadata *getRawScope() const { return getOperand(0); }
4216 Metadata *getRawFile() const { return getOperand(2); }
4217
4218 /// Check that a location is valid for this label.
4219 ///
4220 /// Check that \c DL exists, is in the same subprogram, and has the same
4221 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
4222 /// to a \a DbgInfoIntrinsic.)
4224 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
4225 }
4226
4227 static bool classof(const Metadata *MD) {
4228 return MD->getMetadataID() == DILabelKind;
4229 }
4230};
4231
4232class DIObjCProperty : public DINode {
4233 friend class LLVMContextImpl;
4234 friend class MDNode;
4235
4236 unsigned Line;
4237 unsigned Attributes;
4238
4239 DIObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
4240 unsigned Attributes, ArrayRef<Metadata *> Ops);
4241 ~DIObjCProperty() = default;
4242
4243 static DIObjCProperty *
4244 getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
4245 StringRef GetterName, StringRef SetterName, unsigned Attributes,
4246 DIType *Type, StorageType Storage, bool ShouldCreate = true) {
4247 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
4249 getCanonicalMDString(Context, SetterName), Attributes, Type,
4250 Storage, ShouldCreate);
4251 }
4252 LLVM_ABI static DIObjCProperty *
4253 getImpl(LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
4254 MDString *GetterName, MDString *SetterName, unsigned Attributes,
4255 Metadata *Type, StorageType Storage, bool ShouldCreate = true);
4256
4257 TempDIObjCProperty cloneImpl() const {
4258 return getTemporary(getContext(), getName(), getFile(), getLine(),
4260 getType());
4261 }
4262
4263public:
4264 DEFINE_MDNODE_GET(DIObjCProperty,
4265 (StringRef Name, DIFile *File, unsigned Line,
4267 unsigned Attributes, DIType *Type),
4268 (Name, File, Line, GetterName, SetterName, Attributes,
4269 Type))
4270 DEFINE_MDNODE_GET(DIObjCProperty,
4271 (MDString * Name, Metadata *File, unsigned Line,
4273 unsigned Attributes, Metadata *Type),
4274 (Name, File, Line, GetterName, SetterName, Attributes,
4275 Type))
4276
4277 TempDIObjCProperty clone() const { return cloneImpl(); }
4278
4279 unsigned getLine() const { return Line; }
4280 unsigned getAttributes() const { return Attributes; }
4281 StringRef getName() const { return getStringOperand(0); }
4286
4288 if (auto *F = getFile())
4289 return F->getFilename();
4290 return "";
4291 }
4292
4294 if (auto *F = getFile())
4295 return F->getDirectory();
4296 return "";
4297 }
4298
4300 Metadata *getRawFile() const { return getOperand(1); }
4303 Metadata *getRawType() const { return getOperand(4); }
4304
4305 static bool classof(const Metadata *MD) {
4306 return MD->getMetadataID() == DIObjCPropertyKind;
4307 }
4308};
4309
4310/// An imported module (C++ using directive or similar).
4311///
4312/// Uses the SubclassData32 Metadata slot.
4313class DIImportedEntity : public DINode {
4314 friend class LLVMContextImpl;
4315 friend class MDNode;
4316
4317 DIImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
4318 unsigned Line, ArrayRef<Metadata *> Ops)
4319 : DINode(C, DIImportedEntityKind, Storage, Tag, Ops) {
4321 }
4322 ~DIImportedEntity() = default;
4323
4324 static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
4325 DIScope *Scope, DINode *Entity, DIFile *File,
4326 unsigned Line, StringRef Name,
4327 DINodeArray Elements, StorageType Storage,
4328 bool ShouldCreate = true) {
4329 return getImpl(Context, Tag, Scope, Entity, File, Line,
4330 getCanonicalMDString(Context, Name), Elements.get(), Storage,
4331 ShouldCreate);
4332 }
4333 LLVM_ABI static DIImportedEntity *
4334 getImpl(LLVMContext &Context, unsigned Tag, Metadata *Scope, Metadata *Entity,
4335 Metadata *File, unsigned Line, MDString *Name, Metadata *Elements,
4336 StorageType Storage, bool ShouldCreate = true);
4337
4338 TempDIImportedEntity cloneImpl() const {
4339 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
4340 getFile(), getLine(), getName(), getElements());
4341 }
4342
4343public:
4344 DEFINE_MDNODE_GET(DIImportedEntity,
4345 (unsigned Tag, DIScope *Scope, DINode *Entity, DIFile *File,
4346 unsigned Line, StringRef Name = "",
4347 DINodeArray Elements = nullptr),
4348 (Tag, Scope, Entity, File, Line, Name, Elements))
4349 DEFINE_MDNODE_GET(DIImportedEntity,
4352 Metadata *Elements = nullptr),
4353 (Tag, Scope, Entity, File, Line, Name, Elements))
4354
4355 TempDIImportedEntity clone() const { return cloneImpl(); }
4356
4357 unsigned getLine() const { return SubclassData32; }
4358 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
4359 DINode *getEntity() const { return cast_or_null<DINode>(getRawEntity()); }
4360 StringRef getName() const { return getStringOperand(2); }
4361 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
4362 DINodeArray getElements() const {
4363 return cast_or_null<MDTuple>(getRawElements());
4364 }
4365
4366 Metadata *getRawScope() const { return getOperand(0); }
4367 Metadata *getRawEntity() const { return getOperand(1); }
4368 MDString *getRawName() const { return getOperandAs<MDString>(2); }
4369 Metadata *getRawFile() const { return getOperand(3); }
4370 Metadata *getRawElements() const { return getOperand(4); }
4371
4372 static bool classof(const Metadata *MD) {
4373 return MD->getMetadataID() == DIImportedEntityKind;
4374 }
4375};
4376
4377/// A pair of DIGlobalVariable and DIExpression.
4378class DIGlobalVariableExpression : public MDNode {
4379 friend class LLVMContextImpl;
4380 friend class MDNode;
4381
4382 DIGlobalVariableExpression(LLVMContext &C, StorageType Storage,
4384 : MDNode(C, DIGlobalVariableExpressionKind, Storage, Ops) {}
4385 ~DIGlobalVariableExpression() = default;
4386
4388 getImpl(LLVMContext &Context, Metadata *Variable, Metadata *Expression,
4389 StorageType Storage, bool ShouldCreate = true);
4390
4391 TempDIGlobalVariableExpression cloneImpl() const {
4393 }
4394
4395public:
4396 DEFINE_MDNODE_GET(DIGlobalVariableExpression,
4397 (Metadata * Variable, Metadata *Expression),
4398 (Variable, Expression))
4399
4400 TempDIGlobalVariableExpression clone() const { return cloneImpl(); }
4401
4402 Metadata *getRawVariable() const { return getOperand(0); }
4403
4407
4408 Metadata *getRawExpression() const { return getOperand(1); }
4409
4413
4414 static bool classof(const Metadata *MD) {
4415 return MD->getMetadataID() == DIGlobalVariableExpressionKind;
4416 }
4417};
4418
4419/// Macro Info DWARF-like metadata node.
4420///
4421/// A metadata node with a DWARF macro info (i.e., a constant named
4422/// \c DW_MACINFO_*, defined in llvm/BinaryFormat/Dwarf.h). Called \a
4423/// DIMacroNode
4424/// because it's potentially used for non-DWARF output.
4425///
4426/// Uses the SubclassData16 Metadata slot.
4427class DIMacroNode : public MDNode {
4428 friend class LLVMContextImpl;
4429 friend class MDNode;
4430
4431protected:
4432 DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType,
4434 : MDNode(C, ID, Storage, Ops1, Ops2) {
4435 assert(MIType < 1u << 16);
4436 SubclassData16 = MIType;
4437 }
4438 ~DIMacroNode() = default;
4439
4440 template <class Ty> Ty *getOperandAs(unsigned I) const {
4441 return cast_or_null<Ty>(getOperand(I));
4442 }
4443
4444 StringRef getStringOperand(unsigned I) const {
4445 if (auto *S = getOperandAs<MDString>(I))
4446 return S->getString();
4447 return StringRef();
4448 }
4449
4451 if (S.empty())
4452 return nullptr;
4453 return MDString::get(Context, S);
4454 }
4455
4456public:
4457 unsigned getMacinfoType() const { return SubclassData16; }
4458
4459 static bool classof(const Metadata *MD) {
4460 switch (MD->getMetadataID()) {
4461 default:
4462 return false;
4463 case DIMacroKind:
4464 case DIMacroFileKind:
4465 return true;
4466 }
4467 }
4468};
4469
4470/// Macro
4471///
4472/// Uses the SubclassData32 Metadata slot.
4473class DIMacro : public DIMacroNode {
4474 friend class LLVMContextImpl;
4475 friend class MDNode;
4476
4477 DIMacro(LLVMContext &C, StorageType Storage, unsigned MIType, unsigned Line,
4479 : DIMacroNode(C, DIMacroKind, Storage, MIType, Ops) {
4481 }
4482 ~DIMacro() = default;
4483
4484 static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
4486 bool ShouldCreate = true) {
4487 return getImpl(Context, MIType, Line, getCanonicalMDString(Context, Name),
4488 getCanonicalMDString(Context, Value), Storage, ShouldCreate);
4489 }
4490 LLVM_ABI static DIMacro *getImpl(LLVMContext &Context, unsigned MIType,
4491 unsigned Line, MDString *Name,
4492 MDString *Value, StorageType Storage,
4493 bool ShouldCreate = true);
4494
4495 TempDIMacro cloneImpl() const {
4497 getValue());
4498 }
4499
4500public:
4502 (unsigned MIType, unsigned Line, StringRef Name,
4503 StringRef Value = ""),
4504 (MIType, Line, Name, Value))
4505 DEFINE_MDNODE_GET(DIMacro,
4506 (unsigned MIType, unsigned Line, MDString *Name,
4509
4510 TempDIMacro clone() const { return cloneImpl(); }
4511
4512 unsigned getLine() const { return SubclassData32; }
4513
4514 StringRef getName() const { return getStringOperand(0); }
4515 StringRef getValue() const { return getStringOperand(1); }
4516
4519
4520 static bool classof(const Metadata *MD) {
4521 return MD->getMetadataID() == DIMacroKind;
4522 }
4523};
4524
4525/// Macro file
4526///
4527/// Uses the SubclassData32 Metadata slot.
4528class DIMacroFile : public DIMacroNode {
4529 friend class LLVMContextImpl;
4530 friend class MDNode;
4531
4532 DIMacroFile(LLVMContext &C, StorageType Storage, unsigned MIType,
4533 unsigned Line, ArrayRef<Metadata *> Ops)
4534 : DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops) {
4536 }
4537 ~DIMacroFile() = default;
4538
4539 static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
4540 unsigned Line, DIFile *File,
4541 DIMacroNodeArray Elements, StorageType Storage,
4542 bool ShouldCreate = true) {
4543 return getImpl(Context, MIType, Line, static_cast<Metadata *>(File),
4544 Elements.get(), Storage, ShouldCreate);
4545 }
4546
4547 LLVM_ABI static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
4548 unsigned Line, Metadata *File,
4550 bool ShouldCreate = true);
4551
4552 TempDIMacroFile cloneImpl() const {
4554 getElements());
4555 }
4556
4557public:
4559 (unsigned MIType, unsigned Line, DIFile *File,
4560 DIMacroNodeArray Elements),
4561 (MIType, Line, File, Elements))
4562 DEFINE_MDNODE_GET(DIMacroFile,
4563 (unsigned MIType, unsigned Line, Metadata *File,
4566
4567 TempDIMacroFile clone() const { return cloneImpl(); }
4568
4569 void replaceElements(DIMacroNodeArray Elements) {
4570#ifndef NDEBUG
4571 for (DIMacroNode *Op : getElements())
4572 assert(is_contained(Elements->operands(), Op) &&
4573 "Lost a macro node during macro node list replacement");
4574#endif
4575 replaceOperandWith(1, Elements.get());
4576 }
4577
4578 unsigned getLine() const { return SubclassData32; }
4580
4581 DIMacroNodeArray getElements() const {
4583 }
4584
4585 Metadata *getRawFile() const { return getOperand(0); }
4586 Metadata *getRawElements() const { return getOperand(1); }
4587
4588 static bool classof(const Metadata *MD) {
4589 return MD->getMetadataID() == DIMacroFileKind;
4590 }
4591};
4592
4593/// List of ValueAsMetadata, to be used as an argument to a dbg.value
4594/// intrinsic.
4595class DIArgList : public Metadata, ReplaceableMetadataImpl {
4597 friend class LLVMContextImpl;
4599
4601
4602 DIArgList(LLVMContext &Context, ArrayRef<ValueAsMetadata *> Args)
4603 : Metadata(DIArgListKind, Uniqued), ReplaceableMetadataImpl(Context),
4604 Args(Args) {
4605 track();
4606 }
4607 ~DIArgList() { untrack(); }
4608
4609 LLVM_ABI void track();
4610 LLVM_ABI void untrack();
4611 void dropAllReferences(bool Untrack);
4612
4613public:
4614 LLVM_ABI static DIArgList *get(LLVMContext &Context,
4616
4617 ArrayRef<ValueAsMetadata *> getArgs() const { return Args; }
4618
4619 iterator args_begin() { return Args.begin(); }
4620 iterator args_end() { return Args.end(); }
4621
4622 static bool classof(const Metadata *MD) {
4623 return MD->getMetadataID() == DIArgListKind;
4624 }
4625
4629
4630 LLVM_ABI void handleChangedOperand(void *Ref, Metadata *New);
4631};
4632
4633/// Identifies a unique instance of a variable.
4634///
4635/// Storage for identifying a potentially inlined instance of a variable,
4636/// or a fragment thereof. This guarantees that exactly one variable instance
4637/// may be identified by this class, even when that variable is a fragment of
4638/// an aggregate variable and/or there is another inlined instance of the same
4639/// source code variable nearby.
4640/// This class does not necessarily uniquely identify that variable: it is
4641/// possible that a DebugVariable with different parameters may point to the
4642/// same variable instance, but not that one DebugVariable points to multiple
4643/// variable instances.
4645 using FragmentInfo = DIExpression::FragmentInfo;
4646
4647 const DILocalVariable *Variable;
4648 std::optional<FragmentInfo> Fragment;
4649 const DILocation *InlinedAt;
4650
4651 /// Fragment that will overlap all other fragments. Used as default when
4652 /// caller demands a fragment.
4653 LLVM_ABI static const FragmentInfo DefaultFragment;
4654
4655public:
4657
4659 std::optional<FragmentInfo> FragmentInfo,
4660 const DILocation *InlinedAt)
4661 : Variable(Var), Fragment(FragmentInfo), InlinedAt(InlinedAt) {}
4662
4663 DebugVariable(const DILocalVariable *Var, const DIExpression *DIExpr,
4664 const DILocation *InlinedAt)
4665 : Variable(Var),
4666 Fragment(DIExpr ? DIExpr->getFragmentInfo() : std::nullopt),
4667 InlinedAt(InlinedAt) {}
4668
4669 const DILocalVariable *getVariable() const { return Variable; }
4670 std::optional<FragmentInfo> getFragment() const { return Fragment; }
4671 const DILocation *getInlinedAt() const { return InlinedAt; }
4672
4673 FragmentInfo getFragmentOrDefault() const {
4674 return Fragment.value_or(DefaultFragment);
4675 }
4676
4677 static bool isDefaultFragment(const FragmentInfo F) {
4678 return F == DefaultFragment;
4679 }
4680
4681 bool operator==(const DebugVariable &Other) const {
4682 return std::tie(Variable, Fragment, InlinedAt) ==
4683 std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
4684 }
4685
4686 bool operator<(const DebugVariable &Other) const {
4687 return std::tie(Variable, Fragment, InlinedAt) <
4688 std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
4689 }
4690};
4691
4692template <> struct DenseMapInfo<DebugVariable> {
4694
4695 /// Empty key: no key should be generated that has no DILocalVariable.
4696 static inline DebugVariable getEmptyKey() {
4697 return DebugVariable(nullptr, std::nullopt, nullptr);
4698 }
4699
4700 /// Difference in tombstone is that the Optional is meaningful.
4702 return DebugVariable(nullptr, {{0, 0}}, nullptr);
4703 }
4704
4705 static unsigned getHashValue(const DebugVariable &D) {
4706 unsigned HV = 0;
4707 const std::optional<FragmentInfo> Fragment = D.getFragment();
4708 if (Fragment)
4710
4711 return hash_combine(D.getVariable(), HV, D.getInlinedAt());
4712 }
4713
4714 static bool isEqual(const DebugVariable &A, const DebugVariable &B) {
4715 return A == B;
4716 }
4717};
4718
4719/// Identifies a unique instance of a whole variable (discards/ignores fragment
4720/// information).
4727
4728template <>
4730 : public DenseMapInfo<DebugVariable> {};
4731} // end namespace llvm
4732
4733#undef DEFINE_MDNODE_GET_UNPACK_IMPL
4734#undef DEFINE_MDNODE_GET_UNPACK
4735#undef DEFINE_MDNODE_GET
4736
4737#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
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned NameTableKind
MDString * getRawSplitDebugFilename() const
bool getDebugInfoForProfiling() const
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool DebugInfoForProfiling
Metadata * getRawRetainedTypes() const
static LLVM_ABI const char * nameTableKindString(DebugNameTableKind PK)
static LLVM_ABI const char * emissionKindString(DebugEmissionKind EK)
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString * SysRoot
DISourceLanguageName Metadata MDString bool MDString * Flags
void setSplitDebugInlining(bool SplitDebugInlining)
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString MDString * SDK
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata * GlobalVariables
DICompositeTypeArray getEnumTypes() const
DebugEmissionKind getEmissionKind() const
bool isDebugDirectivesOnly() const
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t DWOId
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata * EnumTypes
StringRef getFlags() const
MDString * getRawProducer() const
DISourceLanguageName Metadata MDString * Producer
void replaceEnumTypes(DICompositeTypeArray N)
Replace arrays.
MDString * getRawSysRoot() const
DISourceLanguageName Metadata MDString bool MDString unsigned RuntimeVersion
StringRef getSDK() const
static void getIfExists()=delete
bool getRangesBaseAddress() const
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata * RetainedTypes
DIMacroNodeArray getMacros() const
unsigned getRuntimeVersion() const
Metadata * getRawMacros() const
void replaceRetainedTypes(DITypeArray N)
static bool classof(const Metadata *MD)
DISourceLanguageName Metadata MDString bool MDString unsigned MDString * SplitDebugFilename
void replaceGlobalVariables(DIGlobalVariableExpressionArray N)
void replaceMacros(DIMacroNodeArray N)
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString MDString SDK TempDICompileUnit clone() const
bool getSplitDebugInlining() const
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata * ImportedEntities
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata * Macros
StringRef getSysRoot() const
DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(DICompileUnit,(DISourceLanguageName SourceLanguage, DIFile *File, StringRef Producer, bool IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling, DebugNameTableKind NameTableKind, bool RangesBaseAddress, StringRef SysRoot, StringRef SDK),(SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling,(unsigned) NameTableKind, RangesBaseAddress, SysRoot, SDK)) DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(DICompileUnit
DebugNameTableKind getNameTableKind() const
MDString * getRawSDK() const
DISourceLanguageName Metadata MDString bool IsOptimized
DISourceLanguageName Metadata * File
MDString * getRawFlags() const
DIImportedEntityArray getImportedEntities() const
Metadata * getRawEnumTypes() const
StringRef getProducer() const
void setDWOId(uint64_t DwoId)
DIScopeArray getRetainedTypes() const
void replaceImportedEntities(DIImportedEntityArray N)
Metadata * getRawGlobalVariables() const
DIGlobalVariableExpressionArray getGlobalVariables() const
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool SplitDebugInlining
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned EmissionKind
DISourceLanguageName getSourceLanguage() const
Metadata * getRawImportedEntities() const
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool RangesBaseAddress
uint64_t getDWOId() const
StringRef getSplitDebugFilename() const
static void get()=delete
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t AlignInBits
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > EnumKind
Metadata * getRawVTableHolder() const
DIExpression * getRankExp() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata * DataLocation
static LLVM_ABI DICompositeType * buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, Metadata *SizeInBits, uint32_t AlignInBits, Metadata *OffsetInBits, Metadata *Specification, uint32_t NumExtraInhabitants, DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, std::optional< uint32_t > EnumKind, Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator, Metadata *DataLocation, Metadata *Associated, Metadata *Allocated, Metadata *Rank, Metadata *Annotations, Metadata *BitStride)
Build a DICompositeType with the given ODR identifier.
unsigned MDString Metadata unsigned Line
Metadata * getRawRank() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata * Elements
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned RuntimeLang
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata * Annotations
Metadata * getRawSpecification() const
DIExpression * getAssociatedExp() const
DIVariable * getAllocated() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString * Identifier
DIExpression * getDataLocationExp() const
Metadata * getRawDiscriminator() const
static LLVM_ABI DICompositeType * getODRTypeIfExists(LLVMContext &Context, MDString &Identifier)
DIVariable * getAssociated() const
DIDerivedType * getDiscriminator() const
DIVariable * getDataLocation() const
unsigned getRuntimeLang() const
DIType * getSpecification() const
Metadata * getRawElements() const
unsigned MDString * Name
void replaceVTableHolder(DIType *VTableHolder)
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata * Discriminator
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata * TemplateParams
StringRef getIdentifier() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t OffsetInBits
unsigned MDString Metadata unsigned Metadata * Scope
unsigned MDString Metadata * File
Metadata * getRawDataLocation() const
Metadata * getRawTemplateParams() const
unsigned MDString Metadata unsigned Metadata Metadata * BaseType
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Flags
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata * Allocated
DINodeArray getElements() const
DITemplateParameterArray getTemplateParams() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata Metadata * Specification
Metadata * getRawAnnotations() const
Metadata * getRawAllocated() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata * VTableHolder
DIExpression * getAllocatedExp() const
void replaceElements(DINodeArray Elements)
Replace operands.
ConstantInt * getBitStrideConst() const
std::optional< uint32_t > getEnumKind() const
unsigned MDString Metadata unsigned Metadata Metadata uint64_t SizeInBits
DIType * getVTableHolder() const
DINodeArray getAnnotations() const
Metadata * getRawAssociated() const
ConstantInt * getRankConst() const
void replaceTemplateParams(DITemplateParameterArray TemplateParams)
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata * Associated
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata Metadata uint32_t NumExtraInhabitants
Metadata * getRawBitStride() const
Metadata * getRawBaseType() const
DEFINE_MDNODE_GET(DICompositeType,(unsigned Tag, StringRef Name, DIFile *File, unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags, DINodeArray Elements, unsigned RuntimeLang, std::optional< uint32_t > EnumKind, DIType *VTableHolder, DITemplateParameterArray TemplateParams=nullptr, StringRef Identifier="", DIDerivedType *Discriminator=nullptr, Metadata *DataLocation=nullptr, Metadata *Associated=nullptr, Metadata *Allocated=nullptr, Metadata *Rank=nullptr, DINodeArray Annotations=nullptr, DIType *Specification=nullptr, uint32_t NumExtraInhabitants=0, Metadata *BitStride=nullptr),(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits, Specification, NumExtraInhabitants, Flags, Elements, RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier, Discriminator, DataLocation, Associated, Allocated, Rank, Annotations, BitStride)) DEFINE_MDNODE_GET(DICompositeType
MDString * getRawIdentifier() const
static bool classof(const Metadata *MD)
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata * Rank
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata Metadata uint32_t Metadata * BitStride
DIType * getBaseType() const
Metadata * getRawExtraData() const
unsigned StringRef DIFile unsigned DIScope DIType * BaseType
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata * OffsetInBits
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > std::optional< PtrAuthData > DIFlags Flags
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t AlignInBits
DINodeArray getAnnotations() const
Get annotations associated with this derived type.
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > std::optional< PtrAuthData > PtrAuthData
DEFINE_MDNODE_GET(DIDerivedType,(unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, Metadata *SizeInBits, uint32_t AlignInBits, Metadata *OffsetInBits, std::optional< unsigned > DWARFAddressSpace, std::optional< PtrAuthData > PtrAuthData, DIFlags Flags, Metadata *ExtraData=nullptr, Metadata *Annotations=nullptr),(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits, DWARFAddressSpace, PtrAuthData, Flags, ExtraData, Annotations)) DEFINE_MDNODE_GET(DIDerivedType
Metadata * getExtraData() const
Get extra data associated with this derived type.
DITemplateParameterArray getTemplateParams() const
Get the template parameters from a template alias.
unsigned StringRef DIFile * File
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > std::optional< PtrAuthData > DIFlags Metadata DINodeArray Annotations
DIObjCProperty * getObjCProperty() const
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > DWARFAddressSpace
unsigned StringRef DIFile unsigned DIScope * Scope
Metadata * getRawAnnotations() const
LLVM_ABI DIType * getClassType() const
Get casted version of extra data.
static bool classof(const Metadata *MD)
LLVM_ABI Constant * getConstant() const
unsigned StringRef DIFile unsigned DIScope DIType Metadata * SizeInBits
LLVM_ABI Constant * getStorageOffsetInBits() const
LLVM_ABI Constant * getDiscriminantValue() const
unsigned StringRef Name
LLVM_ABI uint32_t getVBPtrOffset() const
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > std::optional< PtrAuthData > DIFlags Metadata * ExtraData
unsigned StringRef DIFile unsigned Line
Enumeration value.
int64_t bool MDString APInt(64, Value, !IsUnsigned)
const APInt & getValue() const
int64_t bool MDString Name APInt bool MDString Name TempDIEnumerator clone() const
MDString * getRawName() const
StringRef getName() const
friend class LLVMContextImpl
DEFINE_MDNODE_GET(DIEnumerator,(int64_t Value, bool IsUnsigned, StringRef Name),(APInt(64, Value, !IsUnsigned), IsUnsigned, Name)) DEFINE_MDNODE_GET(DIEnumerator
static bool classof(const Metadata *MD)
int64_t bool MDString * Name
std::optional< DIExpression::ExprOperand > peekNext() const
Return the next operation.
std::optional< DIExpression::FragmentInfo > getFragmentInfo() const
Retrieve the fragment information, if any.
DIExpressionCursor(const DIExpressionCursor &)=default
DIExpressionCursor(const DIExpression *Expr)
DIExpression::expr_op_iterator end() const
std::optional< DIExpression::ExprOperand > peekNextN(unsigned N) const
std::optional< DIExpression::ExprOperand > peek() const
Return the current operation.
void consume(unsigned N)
Consume N operations.
std::optional< DIExpression::ExprOperand > take()
Consume one operation.
DIExpressionCursor(ArrayRef< uint64_t > Expr)
DIExpression::expr_op_iterator begin() const
void assignNewExpr(ArrayRef< uint64_t > Expr)
A lightweight wrapper around an expression operand.
LLVM_ABI unsigned getSize() const
Return the size of the operand.
uint64_t getArg(unsigned I) const
Get an argument to the operand.
uint64_t getOp() const
Get the operand code.
void appendToVector(SmallVectorImpl< uint64_t > &V) const
Append the elements of this operand to V.
An iterator for expression operands.
bool operator==(const expr_op_iterator &X) const
const ExprOperand * operator->() const
bool operator!=(const expr_op_iterator &X) const
const ExprOperand & operator*() const
expr_op_iterator getNext() const
Get the next iterator.
DWARF expression.
element_iterator elements_end() const
LLVM_ABI bool isEntryValue() const
Check if the expression consists of exactly one entry value operand.
iterator_range< expr_op_iterator > expr_ops() const
bool isFragment() const
Return whether this is a piece of an aggregate variable.
static LLVM_ABI DIExpression * append(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Append the opcodes Ops to DIExpr.
std::array< uint64_t, 6 > ExtOps
unsigned getNumElements() const
ArrayRef< uint64_t >::iterator element_iterator
static LLVM_ABI ExtOps getExtOps(unsigned FromSize, unsigned ToSize, bool Signed)
Returns the ops for a zero- or sign-extension in a DIExpression.
expr_op_iterator expr_op_begin() const
Visit the elements via ExprOperand wrappers.
LLVM_ABI bool extractIfOffset(int64_t &Offset) const
If this is a constant offset, extract it.
static LLVM_ABI void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
DbgVariableFragmentInfo FragmentInfo
int fragmentCmp(const DIExpression *Other) const
Determine the relative position of the fragments described by this DIExpression and Other.
LLVM_ABI bool startsWithDeref() const
Return whether the first element a DW_OP_deref.
static LLVM_ABI bool isEqualExpression(const DIExpression *FirstExpr, bool FirstIndirect, const DIExpression *SecondExpr, bool SecondIndirect)
Determines whether two debug values should produce equivalent DWARF expressions, using their DIExpres...
expr_op_iterator expr_op_end() const
LLVM_ABI bool isImplicit() const
Return whether this is an implicit location description.
DEFINE_MDNODE_GET(DIExpression,(ArrayRef< uint64_t > Elements),(Elements)) TempDIExpression clone() const
static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B)
Check if fragments overlap between a pair of FragmentInfos.
static LLVM_ABI bool calculateFragmentIntersect(const DataLayout &DL, const Value *SliceStart, uint64_t SliceOffsetInBits, uint64_t SliceSizeInBits, const Value *DbgPtr, int64_t DbgPtrOffsetInBits, int64_t DbgExtractOffsetInBits, DIExpression::FragmentInfo VarFrag, std::optional< DIExpression::FragmentInfo > &Result, int64_t &OffsetFromLocationInBits)
Computes a fragment, bit-extract operation if needed, and new constant offset to describe a part of a...
element_iterator elements_begin() const
LLVM_ABI bool hasAllLocationOps(unsigned N) const
Returns true iff this DIExpression contains at least one instance of DW_OP_LLVM_arg,...
std::optional< FragmentInfo > getFragmentInfo() const
Retrieve the details of this fragment expression.
static LLVM_ABI DIExpression * appendOpsToArg(const DIExpression *Expr, ArrayRef< uint64_t > Ops, unsigned ArgNo, bool StackValue=false)
Create a copy of Expr by appending the given list of Ops to each instance of the operand DW_OP_LLVM_a...
PrependOps
Used for DIExpression::prepend.
static int fragmentCmp(const FragmentInfo &A, const FragmentInfo &B)
Determine the relative position of the fragments passed in.
LLVM_ABI bool isComplex() const
Return whether the location is computed on the expression stack, meaning it cannot be a simple regist...
bool fragmentsOverlap(const DIExpression *Other) const
Check if fragments overlap between this DIExpression and Other.
LLVM_ABI DIExpression * foldConstantMath()
Try to shorten an expression with constant math operations that can be evaluated at compile time.
static LLVM_ABI std::optional< const DIExpression * > convertToNonVariadicExpression(const DIExpression *Expr)
If Expr is a valid single-location expression, i.e.
LLVM_ABI std::pair< DIExpression *, const ConstantInt * > constantFold(const ConstantInt *CI)
Try to shorten an expression with an initial constant operand.
LLVM_ABI bool isDeref() const
Return whether there is exactly one operator and it is a DW_OP_deref;.
static LLVM_ABI const DIExpression * convertToVariadicExpression(const DIExpression *Expr)
If Expr is a non-variadic expression (i.e.
LLVM_ABI uint64_t getNumLocationOperands() const
Return the number of unique location operands referred to (via DW_OP_LLVM_arg) in this expression; th...
ArrayRef< uint64_t > getElements() const
static LLVM_ABI DIExpression * replaceArg(const DIExpression *Expr, uint64_t OldArg, uint64_t NewArg)
Create a copy of Expr with each instance of DW_OP_LLVM_arg, \p OldArg replaced with DW_OP_LLVM_arg,...
static bool classof(const Metadata *MD)
LLVM_ABI std::optional< uint64_t > getActiveBits(DIVariable *Var)
Return the number of bits that have an active value, i.e.
static LLVM_ABI void canonicalizeExpressionOps(SmallVectorImpl< uint64_t > &Ops, const DIExpression *Expr, bool IsIndirect)
Inserts the elements of Expr into Ops modified to a canonical form, which uses DW_OP_LLVM_arg (i....
uint64_t getElement(unsigned I) const
static LLVM_ABI 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)
Wrapper structure that holds a language name and its version.
uint16_t getUnversionedName() const
Transitional API for cases where we do not yet support versioned source language names.
uint32_t getVersion() const
Returns language version. Only valid for versioned language names.
DISourceLanguageName(uint16_t Lang, uint32_t Version)
uint16_t getName() const
Returns a versioned or unversioned language name.
String type, Fortran CHARACTER(n)
unsigned MDString * Name
unsigned MDString Metadata Metadata Metadata uint64_t SizeInBits
unsigned getEncoding() const
unsigned MDString Metadata Metadata Metadata uint64_t uint32_t AlignInBits
static bool classof(const Metadata *MD)
unsigned MDString Metadata Metadata Metadata * StringLocationExp
unsigned MDString Metadata Metadata Metadata uint64_t uint32_t unsigned Encoding unsigned MDString Metadata Metadata Metadata Metadata uint32_t unsigned Encoding TempDIStringType clone() const
DIExpression * getStringLengthExp() const
unsigned MDString Metadata Metadata * StringLengthExp
Metadata * getRawStringLengthExp() const
unsigned MDString Metadata Metadata Metadata uint64_t uint32_t unsigned Encoding
Metadata * getRawStringLength() const
DIVariable * getStringLength() const
DIExpression * getStringLocationExp() const
unsigned MDString Metadata * StringLength
Metadata * getRawStringLocationExp() const
DEFINE_MDNODE_GET(DIStringType,(unsigned Tag, StringRef Name, uint64_t SizeInBits, uint32_t AlignInBits),(Tag, Name, nullptr, nullptr, nullptr, SizeInBits, AlignInBits, 0)) DEFINE_MDNODE_GET(DIStringType
Subprogram description. Uses SubclassData1.
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata * Unit
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata Metadata MDString bool UsesKeyInstructions
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata Metadata * Annotations
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)
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