LLVM 17.0.0git
DebugInfoMetadata.cpp
Go to the documentation of this file.
1//===- DebugInfoMetadata.cpp - Implement debug info metadata --------------===//
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// This file implements the debug info Metadata classes.
10//
11//===----------------------------------------------------------------------===//
12
14#include "LLVMContextImpl.h"
15#include "MetadataImpl.h"
16#include "llvm/ADT/SmallSet.h"
19#include "llvm/IR/Function.h"
21#include "llvm/IR/Type.h"
22#include "llvm/IR/Value.h"
23
24#include <numeric>
25#include <optional>
26
27using namespace llvm;
28
29namespace llvm {
30// Use FS-AFDO discriminator.
32 "enable-fs-discriminator", cl::Hidden,
33 cl::desc("Enable adding flow sensitive discriminators"));
34} // namespace llvm
35
36const DIExpression::FragmentInfo DebugVariable::DefaultFragment = {
37 std::numeric_limits<uint64_t>::max(), std::numeric_limits<uint64_t>::min()};
38
40 : Variable(DII->getVariable()),
41 Fragment(DII->getExpression()->getFragmentInfo()),
42 InlinedAt(DII->getDebugLoc().getInlinedAt()) {}
43
44DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
45 unsigned Column, ArrayRef<Metadata *> MDs,
46 bool ImplicitCode)
47 : MDNode(C, DILocationKind, Storage, MDs) {
48 assert((MDs.size() == 1 || MDs.size() == 2) &&
49 "Expected a scope and optional inlined-at");
50
51 // Set line and column.
52 assert(Column < (1u << 16) && "Expected 16-bit column");
53
54 SubclassData32 = Line;
55 SubclassData16 = Column;
56
57 setImplicitCode(ImplicitCode);
58}
59
60static void adjustColumn(unsigned &Column) {
61 // Set to unknown on overflow. We only have 16 bits to play with here.
62 if (Column >= (1u << 16))
63 Column = 0;
64}
65
66DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
67 unsigned Column, Metadata *Scope,
68 Metadata *InlinedAt, bool ImplicitCode,
69 StorageType Storage, bool ShouldCreate) {
70 // Fixup column.
72
73 if (Storage == Uniqued) {
74 if (auto *N = getUniqued(Context.pImpl->DILocations,
75 DILocationInfo::KeyTy(Line, Column, Scope,
77 return N;
78 if (!ShouldCreate)
79 return nullptr;
80 } else {
81 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
82 }
83
85 Ops.push_back(Scope);
86 if (InlinedAt)
88 return storeImpl(new (Ops.size(), Storage) DILocation(
89 Context, Storage, Line, Column, Ops, ImplicitCode),
90 Storage, Context.pImpl->DILocations);
91}
92
93const DILocation *
95 if (Locs.empty())
96 return nullptr;
97 if (Locs.size() == 1)
98 return Locs[0];
99 auto *Merged = Locs[0];
100 for (const DILocation *L : llvm::drop_begin(Locs)) {
101 Merged = getMergedLocation(Merged, L);
102 if (Merged == nullptr)
103 break;
104 }
105 return Merged;
106}
107
109 const DILocation *LocB) {
110 if (!LocA || !LocB)
111 return nullptr;
112
113 if (LocA == LocB)
114 return LocA;
115
116 LLVMContext &C = LocA->getContext();
118 std::pair<unsigned, unsigned>, 4>
119 Locations;
120
121 DIScope *S = LocA->getScope();
122 DILocation *L = LocA->getInlinedAt();
123 unsigned Line = LocA->getLine();
124 unsigned Col = LocA->getColumn();
125
126 // Walk from the current source locaiton until the file scope;
127 // then, do the same for the inlined-at locations.
128 auto AdvanceToParentLoc = [&S, &L, &Line, &Col]() {
129 S = S->getScope();
130 if (!S && L) {
131 Line = L->getLine();
132 Col = L->getColumn();
133 S = L->getScope();
134 L = L->getInlinedAt();
135 }
136 };
137
138 while (S) {
139 if (auto *LS = dyn_cast<DILocalScope>(S))
140 Locations.try_emplace(std::make_pair(LS, L), std::make_pair(Line, Col));
141 AdvanceToParentLoc();
142 }
143
144 // Walk the source locations of LocB until a match with LocA is found.
145 S = LocB->getScope();
146 L = LocB->getInlinedAt();
147 Line = LocB->getLine();
148 Col = LocB->getColumn();
149 while (S) {
150 if (auto *LS = dyn_cast<DILocalScope>(S)) {
151 auto MatchLoc = Locations.find(std::make_pair(LS, L));
152 if (MatchLoc != Locations.end()) {
153 // If the lines match, keep the line, but set the column to '0'
154 // If the lines don't match, pick a "line 0" location but keep
155 // the current scope and inlined-at.
156 bool SameLine = Line == MatchLoc->second.first;
157 bool SameCol = Col == MatchLoc->second.second;
158 Line = SameLine ? Line : 0;
159 Col = SameLine && SameCol ? Col : 0;
160 break;
161 }
162 }
163 AdvanceToParentLoc();
164 }
165
166 if (!S) {
167 // If the two locations are irreconsilable, pick any scope,
168 // and return a "line 0" location.
169 Line = Col = 0;
170 S = LocA->getScope();
171 }
172
173 return DILocation::get(C, Line, Col, S, L);
174}
175
176std::optional<unsigned>
177DILocation::encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI) {
178 std::array<unsigned, 3> Components = {BD, DF, CI};
179 uint64_t RemainingWork = 0U;
180 // We use RemainingWork to figure out if we have no remaining components to
181 // encode. For example: if BD != 0 but DF == 0 && CI == 0, we don't need to
182 // encode anything for the latter 2.
183 // Since any of the input components is at most 32 bits, their sum will be
184 // less than 34 bits, and thus RemainingWork won't overflow.
185 RemainingWork =
186 std::accumulate(Components.begin(), Components.end(), RemainingWork);
187
188 int I = 0;
189 unsigned Ret = 0;
190 unsigned NextBitInsertionIndex = 0;
191 while (RemainingWork > 0) {
192 unsigned C = Components[I++];
193 RemainingWork -= C;
194 unsigned EC = encodeComponent(C);
195 Ret |= (EC << NextBitInsertionIndex);
196 NextBitInsertionIndex += encodingBits(C);
197 }
198
199 // Encoding may be unsuccessful because of overflow. We determine success by
200 // checking equivalence of components before & after encoding. Alternatively,
201 // we could determine Success during encoding, but the current alternative is
202 // simpler.
203 unsigned TBD, TDF, TCI = 0;
204 decodeDiscriminator(Ret, TBD, TDF, TCI);
205 if (TBD == BD && TDF == DF && TCI == CI)
206 return Ret;
207 return std::nullopt;
208}
209
210void DILocation::decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF,
211 unsigned &CI) {
216}
218
220 return StringSwitch<DIFlags>(Flag)
221#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
222#include "llvm/IR/DebugInfoFlags.def"
223 .Default(DINode::FlagZero);
224}
225
227 switch (Flag) {
228#define HANDLE_DI_FLAG(ID, NAME) \
229 case Flag##NAME: \
230 return "DIFlag" #NAME;
231#include "llvm/IR/DebugInfoFlags.def"
232 }
233 return "";
234}
235
237 SmallVectorImpl<DIFlags> &SplitFlags) {
238 // Flags that are packed together need to be specially handled, so
239 // that, for example, we emit "DIFlagPublic" and not
240 // "DIFlagPrivate | DIFlagProtected".
241 if (DIFlags A = Flags & FlagAccessibility) {
242 if (A == FlagPrivate)
243 SplitFlags.push_back(FlagPrivate);
244 else if (A == FlagProtected)
245 SplitFlags.push_back(FlagProtected);
246 else
247 SplitFlags.push_back(FlagPublic);
248 Flags &= ~A;
249 }
250 if (DIFlags R = Flags & FlagPtrToMemberRep) {
251 if (R == FlagSingleInheritance)
252 SplitFlags.push_back(FlagSingleInheritance);
253 else if (R == FlagMultipleInheritance)
254 SplitFlags.push_back(FlagMultipleInheritance);
255 else
256 SplitFlags.push_back(FlagVirtualInheritance);
257 Flags &= ~R;
258 }
259 if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) {
260 Flags &= ~FlagIndirectVirtualBase;
261 SplitFlags.push_back(FlagIndirectVirtualBase);
262 }
263
264#define HANDLE_DI_FLAG(ID, NAME) \
265 if (DIFlags Bit = Flags & Flag##NAME) { \
266 SplitFlags.push_back(Bit); \
267 Flags &= ~Bit; \
268 }
269#include "llvm/IR/DebugInfoFlags.def"
270 return Flags;
271}
272
274 if (auto *T = dyn_cast<DIType>(this))
275 return T->getScope();
276
277 if (auto *SP = dyn_cast<DISubprogram>(this))
278 return SP->getScope();
279
280 if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
281 return LB->getScope();
282
283 if (auto *NS = dyn_cast<DINamespace>(this))
284 return NS->getScope();
285
286 if (auto *CB = dyn_cast<DICommonBlock>(this))
287 return CB->getScope();
288
289 if (auto *M = dyn_cast<DIModule>(this))
290 return M->getScope();
291
292 assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&
293 "Unhandled type of scope.");
294 return nullptr;
295}
296
298 if (auto *T = dyn_cast<DIType>(this))
299 return T->getName();
300 if (auto *SP = dyn_cast<DISubprogram>(this))
301 return SP->getName();
302 if (auto *NS = dyn_cast<DINamespace>(this))
303 return NS->getName();
304 if (auto *CB = dyn_cast<DICommonBlock>(this))
305 return CB->getName();
306 if (auto *M = dyn_cast<DIModule>(this))
307 return M->getName();
308 assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||
309 isa<DICompileUnit>(this)) &&
310 "Unhandled type of scope.");
311 return "";
312}
313
314#ifndef NDEBUG
315static bool isCanonical(const MDString *S) {
316 return !S || !S->getString().empty();
317}
318#endif
319
321GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
322 MDString *Header,
323 ArrayRef<Metadata *> DwarfOps,
324 StorageType Storage, bool ShouldCreate) {
325 unsigned Hash = 0;
326 if (Storage == Uniqued) {
327 GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps);
328 if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
329 return N;
330 if (!ShouldCreate)
331 return nullptr;
332 Hash = Key.getHash();
333 } else {
334 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
335 }
336
337 // Use a nullptr for empty headers.
338 assert(isCanonical(Header) && "Expected canonical MDString");
339 Metadata *PreOps[] = {Header};
340 return storeImpl(new (DwarfOps.size() + 1, Storage) GenericDINode(
341 Context, Storage, Hash, Tag, PreOps, DwarfOps),
342 Storage, Context.pImpl->GenericDINodes);
343}
344
345void GenericDINode::recalculateHash() {
346 setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
347}
348
349#define UNWRAP_ARGS_IMPL(...) __VA_ARGS__
350#define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS
351#define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS) \
352 do { \
353 if (Storage == Uniqued) { \
354 if (auto *N = getUniqued(Context.pImpl->CLASS##s, \
355 CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS)))) \
356 return N; \
357 if (!ShouldCreate) \
358 return nullptr; \
359 } else { \
360 assert(ShouldCreate && \
361 "Expected non-uniqued nodes to always be created"); \
362 } \
363 } while (false)
364#define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS) \
365 return storeImpl(new (std::size(OPS), Storage) \
366 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
367 Storage, Context.pImpl->CLASS##s)
368#define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS) \
369 return storeImpl(new (0u, Storage) \
370 CLASS(Context, Storage, UNWRAP_ARGS(ARGS)), \
371 Storage, Context.pImpl->CLASS##s)
372#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS) \
373 return storeImpl(new (std::size(OPS), Storage) CLASS(Context, Storage, OPS), \
374 Storage, Context.pImpl->CLASS##s)
375#define DEFINE_GETIMPL_STORE_N(CLASS, ARGS, OPS, NUM_OPS) \
376 return storeImpl(new (NUM_OPS, Storage) \
377 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
378 Storage, Context.pImpl->CLASS##s)
379
380DISubrange::DISubrange(LLVMContext &C, StorageType Storage,
382 : DINode(C, DISubrangeKind, Storage, dwarf::DW_TAG_subrange_type, Ops) {}
383DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
384 StorageType Storage, bool ShouldCreate) {
387 auto *LB = ConstantAsMetadata::get(
389 return getImpl(Context, CountNode, LB, nullptr, nullptr, Storage,
390 ShouldCreate);
391}
392
393DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
394 int64_t Lo, StorageType Storage,
395 bool ShouldCreate) {
396 auto *LB = ConstantAsMetadata::get(
398 return getImpl(Context, CountNode, LB, nullptr, nullptr, Storage,
399 ShouldCreate);
400}
401
402DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
403 Metadata *LB, Metadata *UB, Metadata *Stride,
404 StorageType Storage, bool ShouldCreate) {
405 DEFINE_GETIMPL_LOOKUP(DISubrange, (CountNode, LB, UB, Stride));
406 Metadata *Ops[] = {CountNode, LB, UB, Stride};
408}
409
410DISubrange::BoundType DISubrange::getCount() const {
411 Metadata *CB = getRawCountNode();
412 if (!CB)
413 return BoundType();
414
415 assert((isa<ConstantAsMetadata>(CB) || isa<DIVariable>(CB) ||
416 isa<DIExpression>(CB)) &&
417 "Count must be signed constant or DIVariable or DIExpression");
418
419 if (auto *MD = dyn_cast<ConstantAsMetadata>(CB))
420 return BoundType(cast<ConstantInt>(MD->getValue()));
421
422 if (auto *MD = dyn_cast<DIVariable>(CB))
423 return BoundType(MD);
424
425 if (auto *MD = dyn_cast<DIExpression>(CB))
426 return BoundType(MD);
427
428 return BoundType();
429}
430
431DISubrange::BoundType DISubrange::getLowerBound() const {
432 Metadata *LB = getRawLowerBound();
433 if (!LB)
434 return BoundType();
435
436 assert((isa<ConstantAsMetadata>(LB) || isa<DIVariable>(LB) ||
437 isa<DIExpression>(LB)) &&
438 "LowerBound must be signed constant or DIVariable or DIExpression");
439
440 if (auto *MD = dyn_cast<ConstantAsMetadata>(LB))
441 return BoundType(cast<ConstantInt>(MD->getValue()));
442
443 if (auto *MD = dyn_cast<DIVariable>(LB))
444 return BoundType(MD);
445
446 if (auto *MD = dyn_cast<DIExpression>(LB))
447 return BoundType(MD);
448
449 return BoundType();
450}
451
452DISubrange::BoundType DISubrange::getUpperBound() const {
453 Metadata *UB = getRawUpperBound();
454 if (!UB)
455 return BoundType();
456
457 assert((isa<ConstantAsMetadata>(UB) || isa<DIVariable>(UB) ||
458 isa<DIExpression>(UB)) &&
459 "UpperBound must be signed constant or DIVariable or DIExpression");
460
461 if (auto *MD = dyn_cast<ConstantAsMetadata>(UB))
462 return BoundType(cast<ConstantInt>(MD->getValue()));
463
464 if (auto *MD = dyn_cast<DIVariable>(UB))
465 return BoundType(MD);
466
467 if (auto *MD = dyn_cast<DIExpression>(UB))
468 return BoundType(MD);
469
470 return BoundType();
471}
472
473DISubrange::BoundType DISubrange::getStride() const {
474 Metadata *ST = getRawStride();
475 if (!ST)
476 return BoundType();
477
478 assert((isa<ConstantAsMetadata>(ST) || isa<DIVariable>(ST) ||
479 isa<DIExpression>(ST)) &&
480 "Stride must be signed constant or DIVariable or DIExpression");
481
482 if (auto *MD = dyn_cast<ConstantAsMetadata>(ST))
483 return BoundType(cast<ConstantInt>(MD->getValue()));
484
485 if (auto *MD = dyn_cast<DIVariable>(ST))
486 return BoundType(MD);
487
488 if (auto *MD = dyn_cast<DIExpression>(ST))
489 return BoundType(MD);
490
491 return BoundType();
492}
493DIGenericSubrange::DIGenericSubrange(LLVMContext &C, StorageType Storage,
495 : DINode(C, DIGenericSubrangeKind, Storage, dwarf::DW_TAG_generic_subrange,
496 Ops) {}
497
498DIGenericSubrange *DIGenericSubrange::getImpl(LLVMContext &Context,
499 Metadata *CountNode, Metadata *LB,
500 Metadata *UB, Metadata *Stride,
501 StorageType Storage,
502 bool ShouldCreate) {
503 DEFINE_GETIMPL_LOOKUP(DIGenericSubrange, (CountNode, LB, UB, Stride));
504 Metadata *Ops[] = {CountNode, LB, UB, Stride};
506}
507
510 if (!CB)
511 return BoundType();
512
513 assert((isa<DIVariable>(CB) || isa<DIExpression>(CB)) &&
514 "Count must be signed constant or DIVariable or DIExpression");
515
516 if (auto *MD = dyn_cast<DIVariable>(CB))
517 return BoundType(MD);
518
519 if (auto *MD = dyn_cast<DIExpression>(CB))
520 return BoundType(MD);
521
522 return BoundType();
523}
524
527 if (!LB)
528 return BoundType();
529
530 assert((isa<DIVariable>(LB) || isa<DIExpression>(LB)) &&
531 "LowerBound must be signed constant or DIVariable or DIExpression");
532
533 if (auto *MD = dyn_cast<DIVariable>(LB))
534 return BoundType(MD);
535
536 if (auto *MD = dyn_cast<DIExpression>(LB))
537 return BoundType(MD);
538
539 return BoundType();
540}
541
544 if (!UB)
545 return BoundType();
546
547 assert((isa<DIVariable>(UB) || isa<DIExpression>(UB)) &&
548 "UpperBound must be signed constant or DIVariable or DIExpression");
549
550 if (auto *MD = dyn_cast<DIVariable>(UB))
551 return BoundType(MD);
552
553 if (auto *MD = dyn_cast<DIExpression>(UB))
554 return BoundType(MD);
555
556 return BoundType();
557}
558
560 Metadata *ST = getRawStride();
561 if (!ST)
562 return BoundType();
563
564 assert((isa<DIVariable>(ST) || isa<DIExpression>(ST)) &&
565 "Stride must be signed constant or DIVariable or DIExpression");
566
567 if (auto *MD = dyn_cast<DIVariable>(ST))
568 return BoundType(MD);
569
570 if (auto *MD = dyn_cast<DIExpression>(ST))
571 return BoundType(MD);
572
573 return BoundType();
574}
575
576DIEnumerator::DIEnumerator(LLVMContext &C, StorageType Storage,
577 const APInt &Value, bool IsUnsigned,
579 : DINode(C, DIEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
580 Value(Value) {
581 SubclassData32 = IsUnsigned;
582}
583DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, const APInt &Value,
584 bool IsUnsigned, MDString *Name,
585 StorageType Storage, bool ShouldCreate) {
586 assert(isCanonical(Name) && "Expected canonical MDString");
588 Metadata *Ops[] = {Name};
590}
591
592DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
593 MDString *Name, uint64_t SizeInBits,
594 uint32_t AlignInBits, unsigned Encoding,
595 DIFlags Flags, StorageType Storage,
596 bool ShouldCreate) {
597 assert(isCanonical(Name) && "Expected canonical MDString");
599 (Tag, Name, SizeInBits, AlignInBits, Encoding, Flags));
600 Metadata *Ops[] = {nullptr, nullptr, Name};
602 (Tag, SizeInBits, AlignInBits, Encoding, Flags), Ops);
603}
604
605std::optional<DIBasicType::Signedness> DIBasicType::getSignedness() const {
606 switch (getEncoding()) {
607 case dwarf::DW_ATE_signed:
608 case dwarf::DW_ATE_signed_char:
609 return Signedness::Signed;
610 case dwarf::DW_ATE_unsigned:
611 case dwarf::DW_ATE_unsigned_char:
613 default:
614 return std::nullopt;
615 }
616}
617
618DIStringType *DIStringType::getImpl(LLVMContext &Context, unsigned Tag,
619 MDString *Name, Metadata *StringLength,
620 Metadata *StringLengthExp,
621 Metadata *StringLocationExp,
622 uint64_t SizeInBits, uint32_t AlignInBits,
623 unsigned Encoding, StorageType Storage,
624 bool ShouldCreate) {
625 assert(isCanonical(Name) && "Expected canonical MDString");
629 Metadata *Ops[] = {nullptr, nullptr, Name,
632 Ops);
633}
634DIType *DIDerivedType::getClassType() const {
635 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
636 return cast_or_null<DIType>(getExtraData());
637}
639 assert(getTag() == dwarf::DW_TAG_inheritance);
640 if (auto *CM = cast_or_null<ConstantAsMetadata>(getExtraData()))
641 if (auto *CI = dyn_cast_or_null<ConstantInt>(CM->getValue()))
642 return static_cast<uint32_t>(CI->getZExtValue());
643 return 0;
644}
646 assert(getTag() == dwarf::DW_TAG_member && isBitField());
647 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
648 return C->getValue();
649 return nullptr;
650}
651
653 assert(getTag() == dwarf::DW_TAG_member && isStaticMember());
654 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
655 return C->getValue();
656 return nullptr;
657}
659 assert(getTag() == dwarf::DW_TAG_member && !isStaticMember());
660 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
661 return C->getValue();
662 return nullptr;
663}
664
666DIDerivedType::getImpl(LLVMContext &Context, unsigned Tag, MDString *Name,
667 Metadata *File, unsigned Line, Metadata *Scope,
668 Metadata *BaseType, uint64_t SizeInBits,
669 uint32_t AlignInBits, uint64_t OffsetInBits,
670 std::optional<unsigned> DWARFAddressSpace, DIFlags Flags,
671 Metadata *ExtraData, Metadata *Annotations,
672 StorageType Storage, bool ShouldCreate) {
673 assert(isCanonical(Name) && "Expected canonical MDString");
676 AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
681 DWARFAddressSpace, Flags),
682 Ops);
683}
684
685DICompositeType *DICompositeType::getImpl(
686 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
687 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
688 uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
689 Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
690 Metadata *TemplateParams, MDString *Identifier, Metadata *Discriminator,
691 Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
692 Metadata *Rank, Metadata *Annotations, StorageType Storage,
693 bool ShouldCreate) {
694 assert(isCanonical(Name) && "Expected canonical MDString");
695
696 // Keep this in sync with buildODRType.
702 Rank, Annotations));
703 Metadata *Ops[] = {File, Scope, Name, BaseType,
709 (Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits, Flags),
710 Ops);
711}
712
714 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
715 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
716 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
717 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
718 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
719 Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
720 Metadata *Rank, Metadata *Annotations) {
721 assert(!Identifier.getString().empty() && "Expected valid identifier");
723 return nullptr;
724 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
725 if (!CT)
728 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
731
732 if (CT->getTag() != Tag)
733 return nullptr;
734
735 // Only mutate CT if it's a forward declaration and the new operands aren't.
736 assert(CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?");
737 if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl))
738 return CT;
739
740 // Mutate CT in place. Keep this in sync with getImpl.
741 CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
742 Flags);
743 Metadata *Ops[] = {File, Scope, Name, BaseType,
747 assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&
748 "Mismatched number of operands");
749 for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I)
750 if (Ops[I] != CT->getOperand(I))
751 CT->setOperand(I, Ops[I]);
752 return CT;
753}
754
755DICompositeType *DICompositeType::getODRType(
756 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
757 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
758 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
759 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
760 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
761 Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
762 Metadata *Rank, Metadata *Annotations) {
763 assert(!Identifier.getString().empty() && "Expected valid identifier");
765 return nullptr;
766 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
767 if (!CT) {
769 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
773 } else {
774 if (CT->getTag() != Tag)
775 return nullptr;
776 }
777 return CT;
778}
779
781 MDString &Identifier) {
782 assert(!Identifier.getString().empty() && "Expected valid identifier");
784 return nullptr;
785 return Context.pImpl->DITypeMap->lookup(&Identifier);
786}
787DISubroutineType::DISubroutineType(LLVMContext &C, StorageType Storage,
788 DIFlags Flags, uint8_t CC,
790 : DIType(C, DISubroutineTypeKind, Storage, dwarf::DW_TAG_subroutine_type, 0,
791 0, 0, 0, Flags, Ops),
792 CC(CC) {}
793
794DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags,
795 uint8_t CC, Metadata *TypeArray,
796 StorageType Storage,
797 bool ShouldCreate) {
799 Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
801}
802
803DIFile::DIFile(LLVMContext &C, StorageType Storage,
804 std::optional<ChecksumInfo<MDString *>> CS, MDString *Src,
806 : DIScope(C, DIFileKind, Storage, dwarf::DW_TAG_file_type, Ops),
807 Checksum(CS), Source(Src) {}
808
809// FIXME: Implement this string-enum correspondence with a .def file and macros,
810// so that the association is explicit rather than implied.
811static const char *ChecksumKindName[DIFile::CSK_Last] = {
812 "CSK_MD5",
813 "CSK_SHA1",
814 "CSK_SHA256",
815};
816
817StringRef DIFile::getChecksumKindAsString(ChecksumKind CSKind) {
818 assert(CSKind <= DIFile::CSK_Last && "Invalid checksum kind");
819 // The first space was originally the CSK_None variant, which is now
820 // obsolete, but the space is still reserved in ChecksumKind, so we account
821 // for it here.
822 return ChecksumKindName[CSKind - 1];
823}
824
825std::optional<DIFile::ChecksumKind>
828 .Case("CSK_MD5", DIFile::CSK_MD5)
829 .Case("CSK_SHA1", DIFile::CSK_SHA1)
830 .Case("CSK_SHA256", DIFile::CSK_SHA256)
831 .Default(std::nullopt);
832}
833
834DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
835 MDString *Directory,
836 std::optional<DIFile::ChecksumInfo<MDString *>> CS,
837 MDString *Source, StorageType Storage,
838 bool ShouldCreate) {
839 assert(isCanonical(Filename) && "Expected canonical MDString");
840 assert(isCanonical(Directory) && "Expected canonical MDString");
841 assert((!CS || isCanonical(CS->Value)) && "Expected canonical MDString");
842 // We do *NOT* expect Source to be a canonical MDString because nullptr
843 // means none, so we need something to represent the empty file.
845 Metadata *Ops[] = {Filename, Directory, CS ? CS->Value : nullptr, Source};
846 DEFINE_GETIMPL_STORE(DIFile, (CS, Source), Ops);
847}
848DICompileUnit::DICompileUnit(LLVMContext &C, StorageType Storage,
849 unsigned SourceLanguage, bool IsOptimized,
850 unsigned RuntimeVersion, unsigned EmissionKind,
851 uint64_t DWOId, bool SplitDebugInlining,
852 bool DebugInfoForProfiling, unsigned NameTableKind,
853 bool RangesBaseAddress, ArrayRef<Metadata *> Ops)
854 : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
855 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
856 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind), DWOId(DWOId),
857 SplitDebugInlining(SplitDebugInlining),
858 DebugInfoForProfiling(DebugInfoForProfiling),
859 NameTableKind(NameTableKind), RangesBaseAddress(RangesBaseAddress) {
861}
862
863DICompileUnit *DICompileUnit::getImpl(
864 LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
865 MDString *Producer, bool IsOptimized, MDString *Flags,
866 unsigned RuntimeVersion, MDString *SplitDebugFilename,
867 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
868 Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
869 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
870 unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
871 MDString *SDK, StorageType Storage, bool ShouldCreate) {
872 assert(Storage != Uniqued && "Cannot unique DICompileUnit");
873 assert(isCanonical(Producer) && "Expected canonical MDString");
874 assert(isCanonical(Flags) && "Expected canonical MDString");
875 assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
876
877 Metadata *Ops[] = {File,
878 Producer,
879 Flags,
881 EnumTypes,
885 Macros,
886 SysRoot,
887 SDK};
888 return storeImpl(new (std::size(Ops), Storage) DICompileUnit(
889 Context, Storage, SourceLanguage, IsOptimized,
890 RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
891 DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
892 Ops),
893 Storage);
894}
895
896std::optional<DICompileUnit::DebugEmissionKind>
899 .Case("NoDebug", NoDebug)
900 .Case("FullDebug", FullDebug)
901 .Case("LineTablesOnly", LineTablesOnly)
902 .Case("DebugDirectivesOnly", DebugDirectivesOnly)
903 .Default(std::nullopt);
904}
905
906std::optional<DICompileUnit::DebugNameTableKind>
909 .Case("Default", DebugNameTableKind::Default)
912 .Default(std::nullopt);
913}
914
916 switch (EK) {
917 case NoDebug:
918 return "NoDebug";
919 case FullDebug:
920 return "FullDebug";
921 case LineTablesOnly:
922 return "LineTablesOnly";
924 return "DebugDirectivesOnly";
925 }
926 return nullptr;
927}
928
930 switch (NTK) {
932 return nullptr;
934 return "GNU";
936 return "None";
937 }
938 return nullptr;
939}
940DISubprogram::DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
941 unsigned ScopeLine, unsigned VirtualIndex,
942 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags,
944 : DILocalScope(C, DISubprogramKind, Storage, dwarf::DW_TAG_subprogram, Ops),
945 Line(Line), ScopeLine(ScopeLine), VirtualIndex(VirtualIndex),
946 ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags) {
947 static_assert(dwarf::DW_VIRTUALITY_max < 4, "Virtuality out of range");
948}
950DISubprogram::toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized,
951 unsigned Virtuality, bool IsMainSubprogram) {
952 // We're assuming virtuality is the low-order field.
953 static_assert(int(SPFlagVirtual) == int(dwarf::DW_VIRTUALITY_virtual) &&
954 int(SPFlagPureVirtual) ==
955 int(dwarf::DW_VIRTUALITY_pure_virtual),
956 "Virtuality constant mismatch");
957 return static_cast<DISPFlags>(
958 (Virtuality & SPFlagVirtuality) |
959 (IsLocalToUnit ? SPFlagLocalToUnit : SPFlagZero) |
960 (IsDefinition ? SPFlagDefinition : SPFlagZero) |
961 (IsOptimized ? SPFlagOptimized : SPFlagZero) |
962 (IsMainSubprogram ? SPFlagMainSubprogram : SPFlagZero));
963}
964
966 if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
967 return Block->getScope()->getSubprogram();
968 return const_cast<DISubprogram *>(cast<DISubprogram>(this));
969}
970
972 if (auto *File = dyn_cast<DILexicalBlockFile>(this))
973 return File->getScope()->getNonLexicalBlockFileScope();
974 return const_cast<DILocalScope *>(this);
975}
976
978 DILocalScope &RootScope, DISubprogram &NewSP, LLVMContext &Ctx,
980 SmallVector<DIScope *> ScopeChain;
981 DIScope *CachedResult = nullptr;
982
983 for (DIScope *Scope = &RootScope; !isa<DISubprogram>(Scope);
984 Scope = Scope->getScope()) {
985 if (auto It = Cache.find(Scope); It != Cache.end()) {
986 CachedResult = cast<DIScope>(It->second);
987 break;
988 }
989 ScopeChain.push_back(Scope);
990 }
991
992 // Recreate the scope chain, bottom-up, starting at the new subprogram (or a
993 // cached result).
994 DIScope *UpdatedScope = CachedResult ? CachedResult : &NewSP;
995 for (DIScope *ScopeToUpdate : reverse(ScopeChain)) {
996 TempMDNode ClonedScope = ScopeToUpdate->clone();
997 cast<DILexicalBlockBase>(*ClonedScope).replaceScope(UpdatedScope);
998 UpdatedScope =
999 cast<DIScope>(MDNode::replaceWithUniqued(std::move(ClonedScope)));
1000 Cache[ScopeToUpdate] = UpdatedScope;
1001 }
1002
1003 return cast<DILocalScope>(UpdatedScope);
1004}
1005
1007 return StringSwitch<DISPFlags>(Flag)
1008#define HANDLE_DISP_FLAG(ID, NAME) .Case("DISPFlag" #NAME, SPFlag##NAME)
1009#include "llvm/IR/DebugInfoFlags.def"
1010 .Default(SPFlagZero);
1011}
1012
1014 switch (Flag) {
1015 // Appease a warning.
1016 case SPFlagVirtuality:
1017 return "";
1018#define HANDLE_DISP_FLAG(ID, NAME) \
1019 case SPFlag##NAME: \
1020 return "DISPFlag" #NAME;
1021#include "llvm/IR/DebugInfoFlags.def"
1022 }
1023 return "";
1024}
1025
1028 SmallVectorImpl<DISPFlags> &SplitFlags) {
1029 // Multi-bit fields can require special handling. In our case, however, the
1030 // only multi-bit field is virtuality, and all its values happen to be
1031 // single-bit values, so the right behavior just falls out.
1032#define HANDLE_DISP_FLAG(ID, NAME) \
1033 if (DISPFlags Bit = Flags & SPFlag##NAME) { \
1034 SplitFlags.push_back(Bit); \
1035 Flags &= ~Bit; \
1036 }
1037#include "llvm/IR/DebugInfoFlags.def"
1038 return Flags;
1039}
1040
1041DISubprogram *DISubprogram::getImpl(
1042 LLVMContext &Context, Metadata *Scope, MDString *Name,
1043 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1044 unsigned ScopeLine, Metadata *ContainingType, unsigned VirtualIndex,
1045 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
1046 Metadata *TemplateParams, Metadata *Declaration, Metadata *RetainedNodes,
1047 Metadata *ThrownTypes, Metadata *Annotations, MDString *TargetFuncName,
1048 StorageType Storage, bool ShouldCreate) {
1049 assert(isCanonical(Name) && "Expected canonical MDString");
1050 assert(isCanonical(LinkageName) && "Expected canonical MDString");
1051 assert(isCanonical(TargetFuncName) && "Expected canonical MDString");
1053 (Scope, Name, LinkageName, File, Line, Type, ScopeLine,
1054 ContainingType, VirtualIndex, ThisAdjustment, Flags,
1055 SPFlags, Unit, TemplateParams, Declaration,
1063 if (!TargetFuncName) {
1064 Ops.pop_back();
1065 if (!Annotations) {
1066 Ops.pop_back();
1067 if (!ThrownTypes) {
1068 Ops.pop_back();
1069 if (!TemplateParams) {
1070 Ops.pop_back();
1071 if (!ContainingType)
1072 Ops.pop_back();
1073 }
1074 }
1075 }
1076 }
1079 (Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags, SPFlags), Ops,
1080 Ops.size());
1081}
1082
1083bool DISubprogram::describes(const Function *F) const {
1084 assert(F && "Invalid function");
1085 return F->getSubprogram() == this;
1086}
1088 StorageType Storage,
1090 : DILocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1091
1092DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
1093 Metadata *File, unsigned Line,
1094 unsigned Column, StorageType Storage,
1095 bool ShouldCreate) {
1096 // Fixup column.
1097 adjustColumn(Column);
1098
1099 assert(Scope && "Expected scope");
1101 Metadata *Ops[] = {File, Scope};
1102 DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops);
1103}
1104
1105DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
1106 Metadata *Scope, Metadata *File,
1107 unsigned Discriminator,
1108 StorageType Storage,
1109 bool ShouldCreate) {
1110 assert(Scope && "Expected scope");
1112 Metadata *Ops[] = {File, Scope};
1113 DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops);
1114}
1115
1116DINamespace::DINamespace(LLVMContext &Context, StorageType Storage,
1117 bool ExportSymbols, ArrayRef<Metadata *> Ops)
1118 : DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace, Ops),
1119 ExportSymbols(ExportSymbols) {}
1120DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
1121 MDString *Name, bool ExportSymbols,
1122 StorageType Storage, bool ShouldCreate) {
1123 assert(isCanonical(Name) && "Expected canonical MDString");
1124 DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, Name, ExportSymbols));
1125 // The nullptr is for DIScope's File operand. This should be refactored.
1126 Metadata *Ops[] = {nullptr, Scope, Name};
1127 DEFINE_GETIMPL_STORE(DINamespace, (ExportSymbols), Ops);
1128}
1129
1130DICommonBlock::DICommonBlock(LLVMContext &Context, StorageType Storage,
1131 unsigned LineNo, ArrayRef<Metadata *> Ops)
1132 : DIScope(Context, DICommonBlockKind, Storage, dwarf::DW_TAG_common_block,
1133 Ops),
1134 LineNo(LineNo) {}
1135DICommonBlock *DICommonBlock::getImpl(LLVMContext &Context, Metadata *Scope,
1136 Metadata *Decl, MDString *Name,
1137 Metadata *File, unsigned LineNo,
1138 StorageType Storage, bool ShouldCreate) {
1139 assert(isCanonical(Name) && "Expected canonical MDString");
1141 // The nullptr is for DIScope's File operand. This should be refactored.
1142 Metadata *Ops[] = {Scope, Decl, Name, File};
1143 DEFINE_GETIMPL_STORE(DICommonBlock, (LineNo), Ops);
1144}
1145
1146DIModule::DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo,
1147 bool IsDecl, ArrayRef<Metadata *> Ops)
1148 : DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops),
1149 LineNo(LineNo), IsDecl(IsDecl) {}
1150DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *File,
1151 Metadata *Scope, MDString *Name,
1152 MDString *ConfigurationMacros,
1153 MDString *IncludePath, MDString *APINotesFile,
1154 unsigned LineNo, bool IsDecl, StorageType Storage,
1155 bool ShouldCreate) {
1156 assert(isCanonical(Name) && "Expected canonical MDString");
1158 IncludePath, APINotesFile, LineNo, IsDecl));
1161 DEFINE_GETIMPL_STORE(DIModule, (LineNo, IsDecl), Ops);
1162}
1163DITemplateTypeParameter::DITemplateTypeParameter(LLVMContext &Context,
1164 StorageType Storage,
1165 bool IsDefault,
1167 : DITemplateParameter(Context, DITemplateTypeParameterKind, Storage,
1168 dwarf::DW_TAG_template_type_parameter, IsDefault,
1169 Ops) {}
1170
1172DITemplateTypeParameter::getImpl(LLVMContext &Context, MDString *Name,
1173 Metadata *Type, bool isDefault,
1174 StorageType Storage, bool ShouldCreate) {
1175 assert(isCanonical(Name) && "Expected canonical MDString");
1177 Metadata *Ops[] = {Name, Type};
1179}
1180
1181DITemplateValueParameter *DITemplateValueParameter::getImpl(
1182 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
1183 bool isDefault, Metadata *Value, StorageType Storage, bool ShouldCreate) {
1184 assert(isCanonical(Name) && "Expected canonical MDString");
1186 (Tag, Name, Type, isDefault, Value));
1187 Metadata *Ops[] = {Name, Type, Value};
1189}
1190
1192DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1193 MDString *LinkageName, Metadata *File, unsigned Line,
1194 Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1195 Metadata *StaticDataMemberDeclaration,
1196 Metadata *TemplateParams, uint32_t AlignInBits,
1197 Metadata *Annotations, StorageType Storage,
1198 bool ShouldCreate) {
1199 assert(isCanonical(Name) && "Expected canonical MDString");
1200 assert(isCanonical(LinkageName) && "Expected canonical MDString");
1203 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1205 Metadata *Ops[] = {Scope,
1206 Name,
1207 File,
1208 Type,
1209 Name,
1213 Annotations};
1215 (Line, IsLocalToUnit, IsDefinition, AlignInBits), Ops);
1216}
1217
1219DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1220 Metadata *File, unsigned Line, Metadata *Type,
1221 unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
1222 Metadata *Annotations, StorageType Storage,
1223 bool ShouldCreate) {
1224 // 64K ought to be enough for any frontend.
1225 assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");
1226
1227 assert(Scope && "Expected scope");
1228 assert(isCanonical(Name) && "Expected canonical MDString");
1230 Flags, AlignInBits, Annotations));
1231 Metadata *Ops[] = {Scope, Name, File, Type, Annotations};
1233}
1234
1236 signed Line, ArrayRef<Metadata *> Ops,
1237 uint32_t AlignInBits)
1238 : DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line),
1239 AlignInBits(AlignInBits) {}
1240std::optional<uint64_t> DIVariable::getSizeInBits() const {
1241 // This is used by the Verifier so be mindful of broken types.
1242 const Metadata *RawType = getRawType();
1243 while (RawType) {
1244 // Try to get the size directly.
1245 if (auto *T = dyn_cast<DIType>(RawType))
1246 if (uint64_t Size = T->getSizeInBits())
1247 return Size;
1248
1249 if (auto *DT = dyn_cast<DIDerivedType>(RawType)) {
1250 // Look at the base type.
1251 RawType = DT->getRawBaseType();
1252 continue;
1253 }
1254
1255 // Missing type or size.
1256 break;
1257 }
1258
1259 // Fail gracefully.
1260 return std::nullopt;
1261}
1262
1263DILabel::DILabel(LLVMContext &C, StorageType Storage, unsigned Line,
1265 : DINode(C, DILabelKind, Storage, dwarf::DW_TAG_label, Ops), Line(Line) {}
1266DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1267 Metadata *File, unsigned Line, StorageType Storage,
1268 bool ShouldCreate) {
1269 assert(Scope && "Expected scope");
1270 assert(isCanonical(Name) && "Expected canonical MDString");
1272 Metadata *Ops[] = {Scope, Name, File};
1273 DEFINE_GETIMPL_STORE(DILabel, (Line), Ops);
1274}
1275
1276DIExpression *DIExpression::getImpl(LLVMContext &Context,
1277 ArrayRef<uint64_t> Elements,
1278 StorageType Storage, bool ShouldCreate) {
1281}
1284}
1286 return getNumElements() > 0 && getElement(0) == dwarf::DW_OP_deref;
1287}
1289 return getNumElements() == 1 && startsWithDeref();
1290}
1291
1292DIAssignID *DIAssignID::getImpl(LLVMContext &Context, StorageType Storage,
1293 bool ShouldCreate) {
1294 // Uniqued DIAssignID are not supported as the instance address *is* the ID.
1295 assert(Storage != StorageType::Uniqued && "uniqued DIAssignID unsupported");
1296 return storeImpl(new (0u, Storage) DIAssignID(Context, Storage), Storage);
1297}
1298
1300 uint64_t Op = getOp();
1301
1302 if (Op >= dwarf::DW_OP_breg0 && Op <= dwarf::DW_OP_breg31)
1303 return 2;
1304
1305 switch (Op) {
1308 case dwarf::DW_OP_bregx:
1309 return 3;
1310 case dwarf::DW_OP_constu:
1311 case dwarf::DW_OP_consts:
1312 case dwarf::DW_OP_deref_size:
1313 case dwarf::DW_OP_plus_uconst:
1317 case dwarf::DW_OP_regx:
1318 return 2;
1319 default:
1320 return 1;
1321 }
1322}
1323
1325 for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
1326 // Check that there's space for the operand.
1327 if (I->get() + I->getSize() > E->get())
1328 return false;
1329
1330 uint64_t Op = I->getOp();
1331 if ((Op >= dwarf::DW_OP_reg0 && Op <= dwarf::DW_OP_reg31) ||
1332 (Op >= dwarf::DW_OP_breg0 && Op <= dwarf::DW_OP_breg31))
1333 return true;
1334
1335 // Check that the operand is valid.
1336 switch (Op) {
1337 default:
1338 return false;
1340 // A fragment operator must appear at the end.
1341 return I->get() + I->getSize() == E->get();
1342 case dwarf::DW_OP_stack_value: {
1343 // Must be the last one or followed by a DW_OP_LLVM_fragment.
1344 if (I->get() + I->getSize() == E->get())
1345 break;
1346 auto J = I;
1347 if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment)
1348 return false;
1349 break;
1350 }
1351 case dwarf::DW_OP_swap: {
1352 // Must be more than one implicit element on the stack.
1353
1354 // FIXME: A better way to implement this would be to add a local variable
1355 // that keeps track of the stack depth and introduce something like a
1356 // DW_LLVM_OP_implicit_location as a placeholder for the location this
1357 // DIExpression is attached to, or else pass the number of implicit stack
1358 // elements into isValid.
1359 if (getNumElements() == 1)
1360 return false;
1361 break;
1362 }
1364 // An entry value operator must appear at the beginning or immediately
1365 // following `DW_OP_LLVM_arg 0`, and the number of operations it cover can
1366 // currently only be 1, because we support only entry values of a simple
1367 // register location. One reason for this is that we currently can't
1368 // calculate the size of the resulting DWARF block for other expressions.
1369 auto FirstOp = expr_op_begin();
1370 if (FirstOp->getOp() == dwarf::DW_OP_LLVM_arg && FirstOp->getArg(0) == 0)
1371 ++FirstOp;
1372 return I->get() == FirstOp->get() && I->getArg(0) == 1;
1373 }
1378 case dwarf::DW_OP_constu:
1379 case dwarf::DW_OP_plus_uconst:
1380 case dwarf::DW_OP_plus:
1381 case dwarf::DW_OP_minus:
1382 case dwarf::DW_OP_mul:
1383 case dwarf::DW_OP_div:
1384 case dwarf::DW_OP_mod:
1385 case dwarf::DW_OP_or:
1386 case dwarf::DW_OP_and:
1387 case dwarf::DW_OP_xor:
1388 case dwarf::DW_OP_shl:
1389 case dwarf::DW_OP_shr:
1390 case dwarf::DW_OP_shra:
1391 case dwarf::DW_OP_deref:
1392 case dwarf::DW_OP_deref_size:
1393 case dwarf::DW_OP_xderef:
1394 case dwarf::DW_OP_lit0:
1395 case dwarf::DW_OP_not:
1396 case dwarf::DW_OP_dup:
1397 case dwarf::DW_OP_regx:
1398 case dwarf::DW_OP_bregx:
1399 case dwarf::DW_OP_push_object_address:
1400 case dwarf::DW_OP_over:
1401 case dwarf::DW_OP_consts:
1402 break;
1403 }
1404 }
1405 return true;
1406}
1407
1409 if (!isValid())
1410 return false;
1411
1412 if (getNumElements() == 0)
1413 return false;
1414
1415 for (const auto &It : expr_ops()) {
1416 switch (It.getOp()) {
1417 default:
1418 break;
1419 case dwarf::DW_OP_stack_value:
1421 return true;
1422 }
1423 }
1424
1425 return false;
1426}
1427
1429 if (!isValid())
1430 return false;
1431
1432 if (getNumElements() == 0)
1433 return false;
1434
1435 // If there are any elements other than fragment or tag_offset, then some
1436 // kind of complex computation occurs.
1437 for (const auto &It : expr_ops()) {
1438 switch (It.getOp()) {
1442 continue;
1443 default:
1444 return true;
1445 }
1446 }
1447
1448 return false;
1449}
1450
1452 if (!isValid())
1453 return false;
1454
1455 if (getNumElements() == 0)
1456 return true;
1457
1458 auto ExprOpBegin = expr_ops().begin();
1459 auto ExprOpEnd = expr_ops().end();
1460 if (ExprOpBegin->getOp() == dwarf::DW_OP_LLVM_arg)
1461 ++ExprOpBegin;
1462
1463 return !std::any_of(ExprOpBegin, ExprOpEnd, [](auto Op) {
1464 return Op.getOp() == dwarf::DW_OP_LLVM_arg;
1465 });
1466}
1467
1468const DIExpression *
1470 SmallVector<uint64_t, 3> UndefOps;
1471 if (auto FragmentInfo = Expr->getFragmentInfo()) {
1474 }
1475 return DIExpression::get(Expr->getContext(), UndefOps);
1476}
1477
1478const DIExpression *
1480 if (any_of(Expr->expr_ops(), [](auto ExprOp) {
1481 return ExprOp.getOp() == dwarf::DW_OP_LLVM_arg;
1482 }))
1483 return Expr;
1484 SmallVector<uint64_t> NewOps;
1485 NewOps.reserve(Expr->getNumElements() + 2);
1486 NewOps.append({dwarf::DW_OP_LLVM_arg, 0});
1487 NewOps.append(Expr->elements_begin(), Expr->elements_end());
1488 return DIExpression::get(Expr->getContext(), NewOps);
1489}
1490
1491std::optional<const DIExpression *>
1493 // Check for `isValid` covered by `isSingleLocationExpression`.
1494 if (!Expr->isSingleLocationExpression())
1495 return std::nullopt;
1496
1497 // An empty expression is already non-variadic.
1498 if (!Expr->getNumElements())
1499 return Expr;
1500
1501 auto ElementsBegin = Expr->elements_begin();
1502 // If Expr does not have a leading DW_OP_LLVM_arg then we don't need to do
1503 // anything.
1504 if (*ElementsBegin != dwarf::DW_OP_LLVM_arg)
1505 return Expr;
1506
1507 SmallVector<uint64_t> NonVariadicOps(
1508 make_range(ElementsBegin + 2, Expr->elements_end()));
1509 return DIExpression::get(Expr->getContext(), NonVariadicOps);
1510}
1511
1513 const DIExpression *Expr,
1514 bool IsIndirect) {
1515 // If Expr is not already variadic, insert the implied `DW_OP_LLVM_arg 0`
1516 // to the existing expression ops.
1517 if (none_of(Expr->expr_ops(), [](auto ExprOp) {
1518 return ExprOp.getOp() == dwarf::DW_OP_LLVM_arg;
1519 }))
1520 Ops.append({dwarf::DW_OP_LLVM_arg, 0});
1521 // If Expr is not indirect, we only need to insert the expression elements and
1522 // we're done.
1523 if (!IsIndirect) {
1524 Ops.append(Expr->elements_begin(), Expr->elements_end());
1525 return;
1526 }
1527 // If Expr is indirect, insert the implied DW_OP_deref at the end of the
1528 // expression but before DW_OP_{stack_value, LLVM_fragment} if they are
1529 // present.
1530 for (auto Op : Expr->expr_ops()) {
1531 if (Op.getOp() == dwarf::DW_OP_stack_value ||
1532 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1533 Ops.push_back(dwarf::DW_OP_deref);
1534 IsIndirect = false;
1535 }
1536 Op.appendToVector(Ops);
1537 }
1538 if (IsIndirect)
1539 Ops.push_back(dwarf::DW_OP_deref);
1540}
1541
1543 bool FirstIndirect,
1544 const DIExpression *SecondExpr,
1545 bool SecondIndirect) {
1546 SmallVector<uint64_t> FirstOps;
1547 DIExpression::canonicalizeExpressionOps(FirstOps, FirstExpr, FirstIndirect);
1548 SmallVector<uint64_t> SecondOps;
1549 DIExpression::canonicalizeExpressionOps(SecondOps, SecondExpr,
1550 SecondIndirect);
1551 return FirstOps == SecondOps;
1552}
1553
1554std::optional<DIExpression::FragmentInfo>
1556 for (auto I = Start; I != End; ++I)
1557 if (I->getOp() == dwarf::DW_OP_LLVM_fragment) {
1558 DIExpression::FragmentInfo Info = {I->getArg(1), I->getArg(0)};
1559 return Info;
1560 }
1561 return std::nullopt;
1562}
1563
1565 int64_t Offset) {
1566 if (Offset > 0) {
1567 Ops.push_back(dwarf::DW_OP_plus_uconst);
1568 Ops.push_back(Offset);
1569 } else if (Offset < 0) {
1570 Ops.push_back(dwarf::DW_OP_constu);
1571 // Avoid UB when encountering LLONG_MIN, because in 2's complement
1572 // abs(LLONG_MIN) is LLONG_MAX+1.
1573 uint64_t AbsMinusOne = -(Offset+1);
1574 Ops.push_back(AbsMinusOne + 1);
1575 Ops.push_back(dwarf::DW_OP_minus);
1576 }
1577}
1578
1580 if (getNumElements() == 0) {
1581 Offset = 0;
1582 return true;
1583 }
1584
1585 if (getNumElements() == 2 && Elements[0] == dwarf::DW_OP_plus_uconst) {
1586 Offset = Elements[1];
1587 return true;
1588 }
1589
1590 if (getNumElements() == 3 && Elements[0] == dwarf::DW_OP_constu) {
1591 if (Elements[2] == dwarf::DW_OP_plus) {
1592 Offset = Elements[1];
1593 return true;
1594 }
1595 if (Elements[2] == dwarf::DW_OP_minus) {
1596 Offset = -Elements[1];
1597 return true;
1598 }
1599 }
1600
1601 return false;
1602}
1603
1606 for (auto ExprOp : expr_ops())
1607 if (ExprOp.getOp() == dwarf::DW_OP_LLVM_arg)
1608 SeenOps.insert(ExprOp.getArg(0));
1609 for (uint64_t Idx = 0; Idx < N; ++Idx)
1610 if (!is_contained(SeenOps, Idx))
1611 return false;
1612 return true;
1613}
1614
1616 unsigned &AddrClass) {
1617 // FIXME: This seems fragile. Nothing that verifies that these elements
1618 // actually map to ops and not operands.
1619 const unsigned PatternSize = 4;
1620 if (Expr->Elements.size() >= PatternSize &&
1621 Expr->Elements[PatternSize - 4] == dwarf::DW_OP_constu &&
1622 Expr->Elements[PatternSize - 2] == dwarf::DW_OP_swap &&
1623 Expr->Elements[PatternSize - 1] == dwarf::DW_OP_xderef) {
1624 AddrClass = Expr->Elements[PatternSize - 3];
1625
1626 if (Expr->Elements.size() == PatternSize)
1627 return nullptr;
1628 return DIExpression::get(Expr->getContext(),
1629 ArrayRef(&*Expr->Elements.begin(),
1630 Expr->Elements.size() - PatternSize));
1631 }
1632 return Expr;
1633}
1634
1636 int64_t Offset) {
1638 if (Flags & DIExpression::DerefBefore)
1639 Ops.push_back(dwarf::DW_OP_deref);
1640
1641 appendOffset(Ops, Offset);
1642 if (Flags & DIExpression::DerefAfter)
1643 Ops.push_back(dwarf::DW_OP_deref);
1644
1645 bool StackValue = Flags & DIExpression::StackValue;
1646 bool EntryValue = Flags & DIExpression::EntryValue;
1647
1648 return prependOpcodes(Expr, Ops, StackValue, EntryValue);
1649}
1650
1653 unsigned ArgNo, bool StackValue) {
1654 assert(Expr && "Can't add ops to this expression");
1655
1656 // Handle non-variadic intrinsics by prepending the opcodes.
1657 if (!any_of(Expr->expr_ops(),
1658 [](auto Op) { return Op.getOp() == dwarf::DW_OP_LLVM_arg; })) {
1659 assert(ArgNo == 0 &&
1660 "Location Index must be 0 for a non-variadic expression.");
1661 SmallVector<uint64_t, 8> NewOps(Ops.begin(), Ops.end());
1662 return DIExpression::prependOpcodes(Expr, NewOps, StackValue);
1663 }
1664
1666 for (auto Op : Expr->expr_ops()) {
1667 // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
1668 if (StackValue) {
1669 if (Op.getOp() == dwarf::DW_OP_stack_value)
1670 StackValue = false;
1671 else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1672 NewOps.push_back(dwarf::DW_OP_stack_value);
1673 StackValue = false;
1674 }
1675 }
1676 Op.appendToVector(NewOps);
1677 if (Op.getOp() == dwarf::DW_OP_LLVM_arg && Op.getArg(0) == ArgNo)
1678 NewOps.insert(NewOps.end(), Ops.begin(), Ops.end());
1679 }
1680 if (StackValue)
1681 NewOps.push_back(dwarf::DW_OP_stack_value);
1682
1683 return DIExpression::get(Expr->getContext(), NewOps);
1684}
1685
1687 uint64_t OldArg, uint64_t NewArg) {
1688 assert(Expr && "Can't replace args in this expression");
1689
1691
1692 for (auto Op : Expr->expr_ops()) {
1693 if (Op.getOp() != dwarf::DW_OP_LLVM_arg || Op.getArg(0) < OldArg) {
1694 Op.appendToVector(NewOps);
1695 continue;
1696 }
1698 uint64_t Arg = Op.getArg(0) == OldArg ? NewArg : Op.getArg(0);
1699 // OldArg has been deleted from the Op list, so decrement all indices
1700 // greater than it.
1701 if (Arg > OldArg)
1702 --Arg;
1703 NewOps.push_back(Arg);
1704 }
1705 return DIExpression::get(Expr->getContext(), NewOps);
1706}
1707
1710 bool StackValue, bool EntryValue) {
1711 assert(Expr && "Can't prepend ops to this expression");
1712
1713 if (EntryValue) {
1715 // Use a block size of 1 for the target register operand. The
1716 // DWARF backend currently cannot emit entry values with a block
1717 // size > 1.
1718 Ops.push_back(1);
1719 }
1720
1721 // If there are no ops to prepend, do not even add the DW_OP_stack_value.
1722 if (Ops.empty())
1723 StackValue = false;
1724 for (auto Op : Expr->expr_ops()) {
1725 // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
1726 if (StackValue) {
1727 if (Op.getOp() == dwarf::DW_OP_stack_value)
1728 StackValue = false;
1729 else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1730 Ops.push_back(dwarf::DW_OP_stack_value);
1731 StackValue = false;
1732 }
1733 }
1734 Op.appendToVector(Ops);
1735 }
1736 if (StackValue)
1737 Ops.push_back(dwarf::DW_OP_stack_value);
1738 return DIExpression::get(Expr->getContext(), Ops);
1739}
1740
1742 ArrayRef<uint64_t> Ops) {
1743 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
1744
1745 // Copy Expr's current op list.
1747 for (auto Op : Expr->expr_ops()) {
1748 // Append new opcodes before DW_OP_{stack_value, LLVM_fragment}.
1749 if (Op.getOp() == dwarf::DW_OP_stack_value ||
1750 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1751 NewOps.append(Ops.begin(), Ops.end());
1752
1753 // Ensure that the new opcodes are only appended once.
1754 Ops = std::nullopt;
1755 }
1756 Op.appendToVector(NewOps);
1757 }
1758
1759 NewOps.append(Ops.begin(), Ops.end());
1760 auto *result = DIExpression::get(Expr->getContext(), NewOps);
1761 assert(result->isValid() && "concatenated expression is not valid");
1762 return result;
1763}
1764
1766 ArrayRef<uint64_t> Ops) {
1767 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
1768 assert(none_of(Ops,
1769 [](uint64_t Op) {
1770 return Op == dwarf::DW_OP_stack_value ||
1772 }) &&
1773 "Can't append this op");
1774
1775 // Append a DW_OP_deref after Expr's current op list if it's non-empty and
1776 // has no DW_OP_stack_value.
1777 //
1778 // Match .* DW_OP_stack_value (DW_OP_LLVM_fragment A B)?.
1779 std::optional<FragmentInfo> FI = Expr->getFragmentInfo();
1780 unsigned DropUntilStackValue = FI ? 3 : 0;
1781 ArrayRef<uint64_t> ExprOpsBeforeFragment =
1782 Expr->getElements().drop_back(DropUntilStackValue);
1783 bool NeedsDeref = (Expr->getNumElements() > DropUntilStackValue) &&
1784 (ExprOpsBeforeFragment.back() != dwarf::DW_OP_stack_value);
1785 bool NeedsStackValue = NeedsDeref || ExprOpsBeforeFragment.empty();
1786
1787 // Append a DW_OP_deref after Expr's current op list if needed, then append
1788 // the new ops, and finally ensure that a single DW_OP_stack_value is present.
1790 if (NeedsDeref)
1791 NewOps.push_back(dwarf::DW_OP_deref);
1792 NewOps.append(Ops.begin(), Ops.end());
1793 if (NeedsStackValue)
1794 NewOps.push_back(dwarf::DW_OP_stack_value);
1795 return DIExpression::append(Expr, NewOps);
1796}
1797
1798std::optional<DIExpression *> DIExpression::createFragmentExpression(
1799 const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits) {
1801 // Track whether it's safe to split the value at the top of the DWARF stack,
1802 // assuming that it'll be used as an implicit location value.
1803 bool CanSplitValue = true;
1804 // Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment.
1805 if (Expr) {
1806 for (auto Op : Expr->expr_ops()) {
1807 switch (Op.getOp()) {
1808 default:
1809 break;
1810 case dwarf::DW_OP_shr:
1811 case dwarf::DW_OP_shra:
1812 case dwarf::DW_OP_shl:
1813 case dwarf::DW_OP_plus:
1814 case dwarf::DW_OP_plus_uconst:
1815 case dwarf::DW_OP_minus:
1816 // We can't safely split arithmetic or shift operations into multiple
1817 // fragments because we can't express carry-over between fragments.
1818 //
1819 // FIXME: We *could* preserve the lowest fragment of a constant offset
1820 // operation if the offset fits into SizeInBits.
1821 CanSplitValue = false;
1822 break;
1823 case dwarf::DW_OP_deref:
1824 case dwarf::DW_OP_deref_size:
1825 case dwarf::DW_OP_deref_type:
1826 case dwarf::DW_OP_xderef:
1827 case dwarf::DW_OP_xderef_size:
1828 case dwarf::DW_OP_xderef_type:
1829 // Preceeding arithmetic operations have been applied to compute an
1830 // address. It's okay to split the value loaded from that address.
1831 CanSplitValue = true;
1832 break;
1833 case dwarf::DW_OP_stack_value:
1834 // Bail if this expression computes a value that cannot be split.
1835 if (!CanSplitValue)
1836 return std::nullopt;
1837 break;
1839 // Make the new offset point into the existing fragment.
1840 uint64_t FragmentOffsetInBits = Op.getArg(0);
1841 uint64_t FragmentSizeInBits = Op.getArg(1);
1842 (void)FragmentSizeInBits;
1843 assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&
1844 "new fragment outside of original fragment");
1845 OffsetInBits += FragmentOffsetInBits;
1846 continue;
1847 }
1848 }
1849 Op.appendToVector(Ops);
1850 }
1851 }
1852 assert((!Expr->isImplicit() || CanSplitValue) && "Expr can't be split");
1853 assert(Expr && "Unknown DIExpression");
1855 Ops.push_back(OffsetInBits);
1856 Ops.push_back(SizeInBits);
1857 return DIExpression::get(Expr->getContext(), Ops);
1858}
1859
1860std::pair<DIExpression *, const ConstantInt *>
1862 // Copy the APInt so we can modify it.
1863 APInt NewInt = CI->getValue();
1865
1866 // Fold operators only at the beginning of the expression.
1867 bool First = true;
1868 bool Changed = false;
1869 for (auto Op : expr_ops()) {
1870 switch (Op.getOp()) {
1871 default:
1872 // We fold only the leading part of the expression; if we get to a part
1873 // that we're going to copy unchanged, and haven't done any folding,
1874 // then the entire expression is unchanged and we can return early.
1875 if (!Changed)
1876 return {this, CI};
1877 First = false;
1878 break;
1880 if (!First)
1881 break;
1882 Changed = true;
1883 if (Op.getArg(1) == dwarf::DW_ATE_signed)
1884 NewInt = NewInt.sextOrTrunc(Op.getArg(0));
1885 else {
1886 assert(Op.getArg(1) == dwarf::DW_ATE_unsigned && "Unexpected operand");
1887 NewInt = NewInt.zextOrTrunc(Op.getArg(0));
1888 }
1889 continue;
1890 }
1891 Op.appendToVector(Ops);
1892 }
1893 if (!Changed)
1894 return {this, CI};
1895 return {DIExpression::get(getContext(), Ops),
1896 ConstantInt::get(getContext(), NewInt)};
1897}
1898
1900 uint64_t Result = 0;
1901 for (auto ExprOp : expr_ops())
1902 if (ExprOp.getOp() == dwarf::DW_OP_LLVM_arg)
1903 Result = std::max(Result, ExprOp.getArg(0) + 1);
1904 assert(hasAllLocationOps(Result) &&
1905 "Expression is missing one or more location operands.");
1906 return Result;
1907}
1908
1909std::optional<DIExpression::SignedOrUnsignedConstant>
1911
1912 // Recognize signed and unsigned constants.
1913 // An signed constants can be represented as DW_OP_consts C DW_OP_stack_value
1914 // (DW_OP_LLVM_fragment of Len).
1915 // An unsigned constant can be represented as
1916 // DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment of Len).
1917
1918 if ((getNumElements() != 2 && getNumElements() != 3 &&
1919 getNumElements() != 6) ||
1920 (getElement(0) != dwarf::DW_OP_consts &&
1921 getElement(0) != dwarf::DW_OP_constu))
1922 return std::nullopt;
1923
1924 if (getNumElements() == 2 && getElement(0) == dwarf::DW_OP_consts)
1926
1927 if ((getNumElements() == 3 && getElement(2) != dwarf::DW_OP_stack_value) ||
1928 (getNumElements() == 6 && (getElement(2) != dwarf::DW_OP_stack_value ||
1930 return std::nullopt;
1931 return getElement(0) == dwarf::DW_OP_constu
1934}
1935
1936DIExpression::ExtOps DIExpression::getExtOps(unsigned FromSize, unsigned ToSize,
1937 bool Signed) {
1938 dwarf::TypeKind TK = Signed ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned;
1940 dwarf::DW_OP_LLVM_convert, ToSize, TK}};
1941 return Ops;
1942}
1943
1945 unsigned FromSize, unsigned ToSize,
1946 bool Signed) {
1947 return appendToStack(Expr, getExtOps(FromSize, ToSize, Signed));
1948}
1949
1951DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable,
1953 bool ShouldCreate) {
1955 Metadata *Ops[] = {Variable, Expression};
1957}
1958DIObjCProperty::DIObjCProperty(LLVMContext &C, StorageType Storage,
1959 unsigned Line, unsigned Attributes,
1961 : DINode(C, DIObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property, Ops),
1963
1964DIObjCProperty *DIObjCProperty::getImpl(
1965 LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
1966 MDString *GetterName, MDString *SetterName, unsigned Attributes,
1967 Metadata *Type, StorageType Storage, bool ShouldCreate) {
1968 assert(isCanonical(Name) && "Expected canonical MDString");
1969 assert(isCanonical(GetterName) && "Expected canonical MDString");
1970 assert(isCanonical(SetterName) && "Expected canonical MDString");
1972 SetterName, Attributes, Type));
1973 Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
1974 DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops);
1975}
1976
1977DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
1978 Metadata *Scope, Metadata *Entity,
1979 Metadata *File, unsigned Line,
1980 MDString *Name, Metadata *Elements,
1981 StorageType Storage,
1982 bool ShouldCreate) {
1983 assert(isCanonical(Name) && "Expected canonical MDString");
1985 (Tag, Scope, Entity, File, Line, Name, Elements));
1986 Metadata *Ops[] = {Scope, Entity, Name, File, Elements};
1988}
1989
1990DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
1991 MDString *Name, MDString *Value, StorageType Storage,
1992 bool ShouldCreate) {
1993 assert(isCanonical(Name) && "Expected canonical MDString");
1995 Metadata *Ops[] = {Name, Value};
1996 DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops);
1997}
1998
1999DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
2000 unsigned Line, Metadata *File,
2001 Metadata *Elements, StorageType Storage,
2002 bool ShouldCreate) {
2004 Metadata *Ops[] = {File, Elements};
2006}
2007
2008DIArgList *DIArgList::getImpl(LLVMContext &Context,
2010 StorageType Storage, bool ShouldCreate) {
2013}
2014
2016 ValueAsMetadata **OldVMPtr = static_cast<ValueAsMetadata **>(Ref);
2017 assert((!New || isa<ValueAsMetadata>(New)) &&
2018 "DIArgList must be passed a ValueAsMetadata");
2019 untrack();
2020 bool Uniq = isUniqued();
2021 if (Uniq) {
2022 // We need to update the uniqueness once the Args are updated since they
2023 // form the key to the DIArgLists store.
2024 eraseFromStore();
2025 }
2026 ValueAsMetadata *NewVM = cast_or_null<ValueAsMetadata>(New);
2027 for (ValueAsMetadata *&VM : Args) {
2028 if (&VM == OldVMPtr) {
2029 if (NewVM)
2030 VM = NewVM;
2031 else
2032 VM = ValueAsMetadata::get(UndefValue::get(VM->getValue()->getType()));
2033 }
2034 }
2035 if (Uniq) {
2036 if (uniquify() != this)
2038 }
2039 track();
2040}
2041void DIArgList::track() {
2042 for (ValueAsMetadata *&VAM : Args)
2043 if (VAM)
2044 MetadataTracking::track(&VAM, *VAM, *this);
2045}
2046void DIArgList::untrack() {
2047 for (ValueAsMetadata *&VAM : Args)
2048 if (VAM)
2049 MetadataTracking::untrack(&VAM, *VAM);
2050}
2051void DIArgList::dropAllReferences() {
2052 untrack();
2053 Args.clear();
2055}
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
AMDGPU Kernel Attributes
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< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
static const char * ChecksumKindName[DIFile::CSK_Last]
#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS)
static void adjustColumn(unsigned &Column)
#define DEFINE_GETIMPL_STORE_N(CLASS, ARGS, OPS, NUM_OPS)
static bool isCanonical(const MDString *S)
#define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS)
#define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS)
#define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS)
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
static unsigned encodingBits(unsigned C)
Definition: Discriminator.h:49
static unsigned encodeComponent(unsigned C)
Definition: Discriminator.h:45
static unsigned getNextComponentInDiscriminator(unsigned D)
Returns the next component stored in discriminator.
Definition: Discriminator.h:38
static unsigned getUnsignedFromPrefixEncoding(unsigned U)
Reverse transformation as getPrefixEncodingFromUnsigned.
Definition: Discriminator.h:30
This file contains constants used for implementing Dwarf debug support.
std::string Name
uint64_t Size
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
LLVMContext & Context
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallSet class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Class for arbitrary precision integers.
Definition: APInt.h:75
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
Definition: APInt.cpp:994
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
Definition: APInt.cpp:1002
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
const T & back() const
back - Get the last element.
Definition: ArrayRef.h:172
iterator end() const
Definition: ArrayRef.h:152
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:163
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
Definition: ArrayRef.h:208
iterator begin() const
Definition: ArrayRef.h:151
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:158
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:419
This is the shared class of boolean and integer constants.
Definition: Constants.h:78
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:887
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
Definition: Constants.cpp:901
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:132
This is an important base class in LLVM.
Definition: Constant.h:41
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
void handleChangedOperand(void *Ref, Metadata *New)
Assignment ID.
Basic type, like 'int' or 'float'.
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags
unsigned StringRef uint64_t SizeInBits
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 Name
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t AlignInBits
Metadata Metadata * Decl
Metadata Metadata MDString * Name
Metadata Metadata MDString Metadata * File
static const char * nameTableKindString(DebugNameTableKind PK)
static const char * emissionKindString(DebugEmissionKind EK)
DebugEmissionKind getEmissionKind() const
unsigned Metadata * File
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata * Macros
unsigned Metadata MDString bool MDString * Flags
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata * EnumTypes
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata * RetainedTypes
DebugNameTableKind getNameTableKind() const
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata * GlobalVariables
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString MDString * SDK
unsigned Metadata MDString * Producer
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString * SysRoot
unsigned Metadata MDString bool MDString unsigned MDString * SplitDebugFilename
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata * ImportedEntities
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t AlignInBits
unsigned MDString Metadata unsigned Line
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 Metadata Metadata * TemplateParams
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata * Rank
static DICompositeType * getODRTypeIfExists(LLVMContext &Context, MDString &Identifier)
unsigned MDString * Name
static DICompositeType * buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator, Metadata *DataLocation, Metadata *Associated, Metadata *Allocated, Metadata *Rank, Metadata *Annotations)
Build a DICompositeType with the given ODR identifier.
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t OffsetInBits
unsigned MDString Metadata unsigned Metadata * Scope
unsigned MDString Metadata * File
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned Metadata Metadata MDString Metadata Metadata Metadata Metadata * Allocated
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 Metadata Metadata MDString Metadata * Discriminator
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned Metadata Metadata MDString Metadata Metadata * DataLocation
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned Metadata Metadata MDString * Identifier
unsigned MDString Metadata unsigned Metadata Metadata uint64_t SizeInBits
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned Metadata Metadata MDString Metadata Metadata Metadata * Associated
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned Metadata * VTableHolder
unsigned StringRef DIFile unsigned DIScope DIType * BaseType
unsigned StringRef DIFile unsigned DIScope DIType uint64_t SizeInBits
unsigned StringRef DIFile * File
unsigned StringRef DIFile unsigned DIScope DIType uint64_t uint32_t uint64_t std::optional< unsigned > DIFlags Flags
unsigned StringRef DIFile unsigned DIScope DIType uint64_t uint32_t uint64_t OffsetInBits
unsigned StringRef DIFile unsigned DIScope DIType uint64_t uint32_t AlignInBits
unsigned StringRef DIFile unsigned DIScope * Scope
Constant * getConstant() const
Constant * getStorageOffsetInBits() const
Constant * getDiscriminantValue() const
unsigned StringRef Name
uint32_t getVBPtrOffset() const
unsigned StringRef DIFile unsigned DIScope DIType uint64_t uint32_t uint64_t std::optional< unsigned > DIFlags Metadata * ExtraData
unsigned StringRef DIFile unsigned Line
Enumeration value.
int64_t bool MDString * Name
unsigned getSize() const
Return the size of the operand.
uint64_t getOp() const
Get the operand code.
An iterator for expression operands.
DWARF expression.
element_iterator elements_end() const
bool isEntryValue() const
Check if the expression consists of exactly one entry value operand.
iterator_range< expr_op_iterator > expr_ops() const
static DIExpression * append(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Append the opcodes Ops to DIExpr.
std::array< uint64_t, 6 > ExtOps
unsigned getNumElements() const
static 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.
bool extractIfOffset(int64_t &Offset) const
If this is a constant offset, extract it.
static void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
bool startsWithDeref() const
Return whether the first element a DW_OP_deref.
static 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
bool isImplicit() const
Return whether this is an implicit location description.
element_iterator elements_begin() const
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 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...
bool isComplex() const
Return whether the location is computed on the expression stack, meaning it cannot be a simple regist...
static std::optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
static std::optional< const DIExpression * > convertToNonVariadicExpression(const DIExpression *Expr)
If Expr is a valid single-location expression, i.e.
std::pair< DIExpression *, const ConstantInt * > constantFold(const ConstantInt *CI)
Try to shorten an expression with an initial constant operand.
bool isDeref() const
Return whether there is exactly one operator and it is a DW_OP_deref;.
static const DIExpression * convertToVariadicExpression(const DIExpression *Expr)
If Expr is a non-variadic expression (i.e.
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 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 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 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 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 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 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 DIExpression * appendExt(const DIExpression *Expr, unsigned FromSize, unsigned ToSize, bool Signed)
Append a zero- or sign-extension to Expr.
bool isSingleLocationExpression() const
Return whether the evaluated expression makes use of a single location at the start of the expression...
std::optional< SignedOrUnsignedConstant > isConstant() const
Determine whether this represents a constant value, if so.
static const DIExpression * extractAddressClass(const DIExpression *Expr, unsigned &AddrClass)
Checks if the last 4 elements of the expression are DW_OP_constu <DWARF Address Space> DW_OP_swap DW_...
static 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.
MDString MDString * Directory
MDString * Filename
static std::optional< ChecksumKind > getChecksumKind(StringRef CSKindStr)
MDString MDString std::optional< ChecksumInfo< MDString * > > CS
Metadata * getRawLowerBound() const
Metadata * getRawCountNode() const
Metadata * getRawStride() const
BoundType getLowerBound() const
Metadata * getRawUpperBound() const
BoundType getUpperBound() const
PointerUnion< DIVariable *, DIExpression * > BoundType
A pair of DIGlobalVariable and DIExpression.
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata Metadata * TemplateParams
Metadata MDString MDString Metadata unsigned Line
Metadata MDString MDString Metadata unsigned Metadata * Type
Metadata MDString * Name
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata * StaticDataMemberDeclaration
Metadata MDString MDString * LinkageName
Metadata MDString MDString Metadata * File
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
unsigned Metadata Metadata Metadata unsigned MDString * Name
unsigned Metadata Metadata Metadata * File
unsigned Metadata * Scope
Metadata MDString * Name
Metadata MDString Metadata * File
DILexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage, ArrayRef< Metadata * > Ops)
Metadata Metadata * File
Metadata Metadata * File
A scope for locals.
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
DILocalScope * getNonLexicalBlockFileScope() const
Get the first non DILexicalBlockFile scope of this scope.
static 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
Metadata MDString * Name
Metadata MDString Metadata unsigned Line
Metadata MDString Metadata unsigned Metadata unsigned DIFlags uint32_t AlignInBits
Debug location.
unsigned unsigned DILocalScope * Scope
static const DILocation * getMergedLocations(ArrayRef< const DILocation * > Locs)
Try to combine the vector of locations passed as input in a single one.
static std::optional< unsigned > encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI)
Raw encoding of the discriminator.
unsigned unsigned DILocalScope DILocation bool ImplicitCode
static void decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF, unsigned &CI)
Raw decoder for values in an encoded discriminator D.
unsigned unsigned Column
unsigned unsigned DILocalScope DILocation * InlinedAt
static const DILocation * getMergedLocation(const DILocation *LocA, const DILocation *LocB)
When two instructions are combined into a single instruction we also need to combine the original loc...
unsigned unsigned Metadata * File
unsigned unsigned Metadata Metadata * Elements
unsigned unsigned MDString * Name
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
Metadata MDString * Name
Tagged DWARF-like metadata node.
dwarf::Tag getTag() const
static DIFlags getFlag(StringRef Flag)
static DIFlags splitFlags(DIFlags Flags, SmallVectorImpl< DIFlags > &SplitFlags)
Split up a flags bitfield.
static StringRef getFlagString(DIFlags Flag)
DIFlags
Debug info flags.
MDString Metadata * File
MDString Metadata unsigned MDString * GetterName
MDString Metadata unsigned MDString MDString * SetterName
Base class for scope-like contexts.
StringRef getName() const
DIScope * getScope() const
String type, Fortran CHARACTER(n)
unsigned MDString * Name
unsigned MDString Metadata Metadata Metadata uint64_t SizeInBits
unsigned MDString Metadata Metadata Metadata uint64_t uint32_t AlignInBits
unsigned MDString Metadata Metadata Metadata * StringLocationExp
unsigned MDString Metadata Metadata * StringLengthExp
unsigned MDString Metadata * StringLength
Subprogram description.
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 * Annotations
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 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
static DISPFlags getFlag(StringRef Flag)
Metadata MDString MDString Metadata * File
static DISPFlags splitFlags(DISPFlags Flags, SmallVectorImpl< DISPFlags > &SplitFlags)
Split up a flags bitfield for easier printing.
Metadata MDString MDString * LinkageName
static 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.
Array subrange.
BoundType getUpperBound() const
BoundType getStride() const
BoundType getLowerBound() const
BoundType getCount() const
Type array for a subprogram.
DIFlags uint8_t Metadata * TypeArray
Base class for template parameters.
unsigned MDString Metadata * Type
Base class for types.
bool isBitField() const
bool isStaticMember() const
std::optional< uint64_t > getSizeInBits() const
Determines the size of the variable's type.
Metadata * getRawType() const
DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, signed Line, ArrayRef< Metadata * > Ops, uint32_t AlignInBits=0)
This is the common base class for debug info intrinsics for variables.
DebugVariable(const DbgVariableIntrinsic *DII)
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:150
iterator end()
Definition: DenseMap.h:84
Class representing an expression and its matching format.
Generic tagged DWARF-like metadata node.
dwarf::Tag getTag() const
unsigned MDString * Header
unsigned MDString ArrayRef< Metadata * > DwarfOps
std::optional< DenseMap< const MDString *, DICompositeType * > > DITypeMap
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
bool isODRUniquingDebugTypes() const
Whether there is a string map for uniquing debug info identifiers across the context.
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:69
Metadata node.
Definition: Metadata.h:943
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1407
void storeDistinctInContext()
Definition: Metadata.cpp:946
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1399
bool isUniqued() const
Definition: Metadata.h:1125
TempMDNode clone() const
Create a (temporary) clone of this.
Definition: Metadata.cpp:558
static T * storeImpl(T *N, StorageType Storage, StoreT &Store)
Definition: MetadataImpl.h:42
LLVMContext & getContext() const
Definition: Metadata.h:1107
void dropAllReferences()
Definition: Metadata.cpp:798
static std::enable_if_t< std::is_base_of< MDNode, T >::value, T * > replaceWithUniqued(std::unique_ptr< T, TempMDNodeDeleter > N)
Replace a temporary node with a uniqued one.
Definition: Metadata.h:1167
A single uniqued string.
Definition: Metadata.h:611
StringRef getString() const
Definition: Metadata.cpp:507
static void untrack(Metadata *&MD)
Stop tracking a reference to metadata.
Definition: Metadata.h:247
static bool track(Metadata *&MD)
Track the reference to metadata.
Definition: Metadata.h:222
Root of the metadata hierarchy.
Definition: Metadata.h:61
StorageType
Active type of storage.
Definition: Metadata.h:69
unsigned short SubclassData16
Definition: Metadata.h:75
unsigned SubclassData32
Definition: Metadata.h:76
unsigned char Storage
Storage flag for non-uniqued, otherwise unowned, metadata.
Definition: Metadata.h:72
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:118
Implements a dense probed hash-table based set with some number of buckets stored inline.
Definition: DenseSet.h:290
bool empty() const
Definition: SmallVector.h:94
size_t size() const
Definition: SmallVector.h:91
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
void reserve(size_type N)
Definition: SmallVector.h:667
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:687
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:809
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static IntegerType * getInt64Ty(LLVMContext &C)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1740
Value wrapper in the Metadata hierarchy.
Definition: Metadata.h:344
static ValueAsMetadata * get(Value *V)
Definition: Metadata.cpp:392
LLVM Value Representation.
Definition: Value.h:74
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ DW_OP_LLVM_entry_value
Only used in LLVM metadata.
Definition: Dwarf.h:144
@ DW_OP_LLVM_implicit_pointer
Only used in LLVM metadata.
Definition: Dwarf.h:145
@ DW_OP_LLVM_tag_offset
Only used in LLVM metadata.
Definition: Dwarf.h:143
@ DW_OP_LLVM_fragment
Only used in LLVM metadata.
Definition: Dwarf.h:141
@ DW_OP_LLVM_arg
Only used in LLVM metadata.
Definition: Dwarf.h:146
@ DW_OP_LLVM_convert
Only used in LLVM metadata.
Definition: Dwarf.h:142
SourceLanguage
Definition: Dwarf.h:199
@ DW_VIRTUALITY_max
Definition: Dwarf.h:190
@ NameTableKind
Definition: LLToken.h:451
@ EmissionKind
Definition: LLToken.h:450
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition: STLExtras.h:386
@ Offset
Definition: DWP.cpp:406
static T * getUniqued(DenseSet< T *, InfoT > &Store, const typename InfoT::KeyTy &Key)
Definition: MetadataImpl.h:22
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
cl::opt< bool > EnableFSDiscriminator
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1742
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:484
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1749
@ Ref
The access may reference the value stored in memory.
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:1869
#define N
Holds the characteristics of one fragment of a larger variable.
A single checksum, represented by a Kind and a Value (a string).