LLVM 19.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"
20#include "llvm/IR/Function.h"
22#include "llvm/IR/Type.h"
23#include "llvm/IR/Value.h"
24
25#include <numeric>
26#include <optional>
27
28using namespace llvm;
29
30namespace llvm {
31// Use FS-AFDO discriminator.
33 "enable-fs-discriminator", cl::Hidden,
34 cl::desc("Enable adding flow sensitive discriminators"));
35} // namespace llvm
36
37const DIExpression::FragmentInfo DebugVariable::DefaultFragment = {
38 std::numeric_limits<uint64_t>::max(), std::numeric_limits<uint64_t>::min()};
39
41 : Variable(DII->getVariable()),
42 Fragment(DII->getExpression()->getFragmentInfo()),
43 InlinedAt(DII->getDebugLoc().getInlinedAt()) {}
44
46 : Variable(DPV->getVariable()),
47 Fragment(DPV->getExpression()->getFragmentInfo()),
48 InlinedAt(DPV->getDebugLoc().getInlinedAt()) {}
49
51 : DebugVariable(DVI->getVariable(), std::nullopt,
52 DVI->getDebugLoc()->getInlinedAt()) {}
53
54DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
55 unsigned Column, ArrayRef<Metadata *> MDs,
56 bool ImplicitCode)
57 : MDNode(C, DILocationKind, Storage, MDs) {
58 assert((MDs.size() == 1 || MDs.size() == 2) &&
59 "Expected a scope and optional inlined-at");
60
61 // Set line and column.
62 assert(Column < (1u << 16) && "Expected 16-bit column");
63
64 SubclassData32 = Line;
65 SubclassData16 = Column;
66
67 setImplicitCode(ImplicitCode);
68}
69
70static void adjustColumn(unsigned &Column) {
71 // Set to unknown on overflow. We only have 16 bits to play with here.
72 if (Column >= (1u << 16))
73 Column = 0;
74}
75
76DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
77 unsigned Column, Metadata *Scope,
78 Metadata *InlinedAt, bool ImplicitCode,
79 StorageType Storage, bool ShouldCreate) {
80 // Fixup column.
82
83 if (Storage == Uniqued) {
84 if (auto *N = getUniqued(Context.pImpl->DILocations,
85 DILocationInfo::KeyTy(Line, Column, Scope,
87 return N;
88 if (!ShouldCreate)
89 return nullptr;
90 } else {
91 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
92 }
93
95 Ops.push_back(Scope);
96 if (InlinedAt)
98 return storeImpl(new (Ops.size(), Storage) DILocation(
99 Context, Storage, Line, Column, Ops, ImplicitCode),
100 Storage, Context.pImpl->DILocations);
101}
102
104 if (Locs.empty())
105 return nullptr;
106 if (Locs.size() == 1)
107 return Locs[0];
108 auto *Merged = Locs[0];
109 for (DILocation *L : llvm::drop_begin(Locs)) {
110 Merged = getMergedLocation(Merged, L);
111 if (Merged == nullptr)
112 break;
113 }
114 return Merged;
115}
116
118 if (!LocA || !LocB)
119 return nullptr;
120
121 if (LocA == LocB)
122 return LocA;
123
124 LLVMContext &C = LocA->getContext();
125
126 using LocVec = SmallVector<const DILocation *>;
127 LocVec ALocs;
128 LocVec BLocs;
130 4>
131 ALookup;
132
133 // Walk through LocA and its inlined-at locations, populate them in ALocs and
134 // save the index for the subprogram and inlined-at pair, which we use to find
135 // a matching starting location in LocB's chain.
136 for (auto [L, I] = std::make_pair(LocA, 0U); L; L = L->getInlinedAt(), I++) {
137 ALocs.push_back(L);
138 auto Res = ALookup.try_emplace(
139 {L->getScope()->getSubprogram(), L->getInlinedAt()}, I);
140 assert(Res.second && "Multiple <SP, InlinedAt> pairs in a location chain?");
141 (void)Res;
142 }
143
144 LocVec::reverse_iterator ARIt = ALocs.rend();
145 LocVec::reverse_iterator BRIt = BLocs.rend();
146
147 // Populate BLocs and look for a matching starting location, the first
148 // location with the same subprogram and inlined-at location as in LocA's
149 // chain. Since the two locations have the same inlined-at location we do
150 // not need to look at those parts of the chains.
151 for (auto [L, I] = std::make_pair(LocB, 0U); L; L = L->getInlinedAt(), I++) {
152 BLocs.push_back(L);
153
154 if (ARIt != ALocs.rend())
155 // We have already found a matching starting location.
156 continue;
157
158 auto IT = ALookup.find({L->getScope()->getSubprogram(), L->getInlinedAt()});
159 if (IT == ALookup.end())
160 continue;
161
162 // The + 1 is to account for the &*rev_it = &(it - 1) relationship.
163 ARIt = LocVec::reverse_iterator(ALocs.begin() + IT->second + 1);
164 BRIt = LocVec::reverse_iterator(BLocs.begin() + I + 1);
165
166 // If we have found a matching starting location we do not need to add more
167 // locations to BLocs, since we will only look at location pairs preceding
168 // the matching starting location, and adding more elements to BLocs could
169 // invalidate the iterator that we initialized here.
170 break;
171 }
172
173 // Merge the two locations if possible, using the supplied
174 // inlined-at location for the created location.
175 auto MergeLocPair = [&C](const DILocation *L1, const DILocation *L2,
177 if (L1 == L2)
178 return DILocation::get(C, L1->getLine(), L1->getColumn(), L1->getScope(),
179 InlinedAt);
180
181 // If the locations originate from different subprograms we can't produce
182 // a common location.
183 if (L1->getScope()->getSubprogram() != L2->getScope()->getSubprogram())
184 return nullptr;
185
186 // Return the nearest common scope inside a subprogram.
187 auto GetNearestCommonScope = [](DIScope *S1, DIScope *S2) -> DIScope * {
189 for (; S1; S1 = S1->getScope()) {
190 Scopes.insert(S1);
191 if (isa<DISubprogram>(S1))
192 break;
193 }
194
195 for (; S2; S2 = S2->getScope()) {
196 if (Scopes.count(S2))
197 return S2;
198 if (isa<DISubprogram>(S2))
199 break;
200 }
201
202 return nullptr;
203 };
204
205 auto Scope = GetNearestCommonScope(L1->getScope(), L2->getScope());
206 assert(Scope && "No common scope in the same subprogram?");
207
208 bool SameLine = L1->getLine() == L2->getLine();
209 bool SameCol = L1->getColumn() == L2->getColumn();
210 unsigned Line = SameLine ? L1->getLine() : 0;
211 unsigned Col = SameLine && SameCol ? L1->getColumn() : 0;
212
213 return DILocation::get(C, Line, Col, Scope, InlinedAt);
214 };
215
216 DILocation *Result = ARIt != ALocs.rend() ? (*ARIt)->getInlinedAt() : nullptr;
217
218 // If we have found a common starting location, walk up the inlined-at chains
219 // and try to produce common locations.
220 for (; ARIt != ALocs.rend() && BRIt != BLocs.rend(); ++ARIt, ++BRIt) {
221 DILocation *Tmp = MergeLocPair(*ARIt, *BRIt, Result);
222
223 if (!Tmp)
224 // We have walked up to a point in the chains where the two locations
225 // are irreconsilable. At this point Result contains the nearest common
226 // location in the inlined-at chains of LocA and LocB, so we break here.
227 break;
228
229 Result = Tmp;
230 }
231
232 if (Result)
233 return Result;
234
235 // We ended up with LocA and LocB as irreconsilable locations. Produce a
236 // location at 0:0 with one of the locations' scope. The function has
237 // historically picked A's scope, and a nullptr inlined-at location, so that
238 // behavior is mimicked here but I am not sure if this is always the correct
239 // way to handle this.
240 return DILocation::get(C, 0, 0, LocA->getScope(), nullptr);
241}
242
243std::optional<unsigned>
244DILocation::encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI) {
245 std::array<unsigned, 3> Components = {BD, DF, CI};
246 uint64_t RemainingWork = 0U;
247 // We use RemainingWork to figure out if we have no remaining components to
248 // encode. For example: if BD != 0 but DF == 0 && CI == 0, we don't need to
249 // encode anything for the latter 2.
250 // Since any of the input components is at most 32 bits, their sum will be
251 // less than 34 bits, and thus RemainingWork won't overflow.
252 RemainingWork =
253 std::accumulate(Components.begin(), Components.end(), RemainingWork);
254
255 int I = 0;
256 unsigned Ret = 0;
257 unsigned NextBitInsertionIndex = 0;
258 while (RemainingWork > 0) {
259 unsigned C = Components[I++];
260 RemainingWork -= C;
261 unsigned EC = encodeComponent(C);
262 Ret |= (EC << NextBitInsertionIndex);
263 NextBitInsertionIndex += encodingBits(C);
264 }
265
266 // Encoding may be unsuccessful because of overflow. We determine success by
267 // checking equivalence of components before & after encoding. Alternatively,
268 // we could determine Success during encoding, but the current alternative is
269 // simpler.
270 unsigned TBD, TDF, TCI = 0;
271 decodeDiscriminator(Ret, TBD, TDF, TCI);
272 if (TBD == BD && TDF == DF && TCI == CI)
273 return Ret;
274 return std::nullopt;
275}
276
277void DILocation::decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF,
278 unsigned &CI) {
283}
285
287 return StringSwitch<DIFlags>(Flag)
288#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
289#include "llvm/IR/DebugInfoFlags.def"
290 .Default(DINode::FlagZero);
291}
292
294 switch (Flag) {
295#define HANDLE_DI_FLAG(ID, NAME) \
296 case Flag##NAME: \
297 return "DIFlag" #NAME;
298#include "llvm/IR/DebugInfoFlags.def"
299 }
300 return "";
301}
302
304 SmallVectorImpl<DIFlags> &SplitFlags) {
305 // Flags that are packed together need to be specially handled, so
306 // that, for example, we emit "DIFlagPublic" and not
307 // "DIFlagPrivate | DIFlagProtected".
308 if (DIFlags A = Flags & FlagAccessibility) {
309 if (A == FlagPrivate)
310 SplitFlags.push_back(FlagPrivate);
311 else if (A == FlagProtected)
312 SplitFlags.push_back(FlagProtected);
313 else
314 SplitFlags.push_back(FlagPublic);
315 Flags &= ~A;
316 }
317 if (DIFlags R = Flags & FlagPtrToMemberRep) {
318 if (R == FlagSingleInheritance)
319 SplitFlags.push_back(FlagSingleInheritance);
320 else if (R == FlagMultipleInheritance)
321 SplitFlags.push_back(FlagMultipleInheritance);
322 else
323 SplitFlags.push_back(FlagVirtualInheritance);
324 Flags &= ~R;
325 }
326 if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) {
327 Flags &= ~FlagIndirectVirtualBase;
328 SplitFlags.push_back(FlagIndirectVirtualBase);
329 }
330
331#define HANDLE_DI_FLAG(ID, NAME) \
332 if (DIFlags Bit = Flags & Flag##NAME) { \
333 SplitFlags.push_back(Bit); \
334 Flags &= ~Bit; \
335 }
336#include "llvm/IR/DebugInfoFlags.def"
337 return Flags;
338}
339
341 if (auto *T = dyn_cast<DIType>(this))
342 return T->getScope();
343
344 if (auto *SP = dyn_cast<DISubprogram>(this))
345 return SP->getScope();
346
347 if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
348 return LB->getScope();
349
350 if (auto *NS = dyn_cast<DINamespace>(this))
351 return NS->getScope();
352
353 if (auto *CB = dyn_cast<DICommonBlock>(this))
354 return CB->getScope();
355
356 if (auto *M = dyn_cast<DIModule>(this))
357 return M->getScope();
358
359 assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&
360 "Unhandled type of scope.");
361 return nullptr;
362}
363
365 if (auto *T = dyn_cast<DIType>(this))
366 return T->getName();
367 if (auto *SP = dyn_cast<DISubprogram>(this))
368 return SP->getName();
369 if (auto *NS = dyn_cast<DINamespace>(this))
370 return NS->getName();
371 if (auto *CB = dyn_cast<DICommonBlock>(this))
372 return CB->getName();
373 if (auto *M = dyn_cast<DIModule>(this))
374 return M->getName();
375 assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||
376 isa<DICompileUnit>(this)) &&
377 "Unhandled type of scope.");
378 return "";
379}
380
381#ifndef NDEBUG
382static bool isCanonical(const MDString *S) {
383 return !S || !S->getString().empty();
384}
385#endif
386
388GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
389 MDString *Header,
390 ArrayRef<Metadata *> DwarfOps,
391 StorageType Storage, bool ShouldCreate) {
392 unsigned Hash = 0;
393 if (Storage == Uniqued) {
394 GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps);
395 if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
396 return N;
397 if (!ShouldCreate)
398 return nullptr;
399 Hash = Key.getHash();
400 } else {
401 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
402 }
403
404 // Use a nullptr for empty headers.
405 assert(isCanonical(Header) && "Expected canonical MDString");
406 Metadata *PreOps[] = {Header};
407 return storeImpl(new (DwarfOps.size() + 1, Storage) GenericDINode(
408 Context, Storage, Hash, Tag, PreOps, DwarfOps),
409 Storage, Context.pImpl->GenericDINodes);
410}
411
412void GenericDINode::recalculateHash() {
413 setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
414}
415
416#define UNWRAP_ARGS_IMPL(...) __VA_ARGS__
417#define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS
418#define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS) \
419 do { \
420 if (Storage == Uniqued) { \
421 if (auto *N = getUniqued(Context.pImpl->CLASS##s, \
422 CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS)))) \
423 return N; \
424 if (!ShouldCreate) \
425 return nullptr; \
426 } else { \
427 assert(ShouldCreate && \
428 "Expected non-uniqued nodes to always be created"); \
429 } \
430 } while (false)
431#define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS) \
432 return storeImpl(new (std::size(OPS), Storage) \
433 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
434 Storage, Context.pImpl->CLASS##s)
435#define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS) \
436 return storeImpl(new (0u, Storage) \
437 CLASS(Context, Storage, UNWRAP_ARGS(ARGS)), \
438 Storage, Context.pImpl->CLASS##s)
439#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS) \
440 return storeImpl(new (std::size(OPS), Storage) CLASS(Context, Storage, OPS), \
441 Storage, Context.pImpl->CLASS##s)
442#define DEFINE_GETIMPL_STORE_N(CLASS, ARGS, OPS, NUM_OPS) \
443 return storeImpl(new (NUM_OPS, Storage) \
444 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
445 Storage, Context.pImpl->CLASS##s)
446
447DISubrange::DISubrange(LLVMContext &C, StorageType Storage,
449 : DINode(C, DISubrangeKind, Storage, dwarf::DW_TAG_subrange_type, Ops) {}
450DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
451 StorageType Storage, bool ShouldCreate) {
454 auto *LB = ConstantAsMetadata::get(
456 return getImpl(Context, CountNode, LB, nullptr, nullptr, Storage,
457 ShouldCreate);
458}
459
460DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
461 int64_t Lo, StorageType Storage,
462 bool ShouldCreate) {
463 auto *LB = ConstantAsMetadata::get(
465 return getImpl(Context, CountNode, LB, nullptr, nullptr, Storage,
466 ShouldCreate);
467}
468
469DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
470 Metadata *LB, Metadata *UB, Metadata *Stride,
471 StorageType Storage, bool ShouldCreate) {
472 DEFINE_GETIMPL_LOOKUP(DISubrange, (CountNode, LB, UB, Stride));
473 Metadata *Ops[] = {CountNode, LB, UB, Stride};
475}
476
477DISubrange::BoundType DISubrange::getCount() const {
478 Metadata *CB = getRawCountNode();
479 if (!CB)
480 return BoundType();
481
482 assert((isa<ConstantAsMetadata>(CB) || isa<DIVariable>(CB) ||
483 isa<DIExpression>(CB)) &&
484 "Count must be signed constant or DIVariable or DIExpression");
485
486 if (auto *MD = dyn_cast<ConstantAsMetadata>(CB))
487 return BoundType(cast<ConstantInt>(MD->getValue()));
488
489 if (auto *MD = dyn_cast<DIVariable>(CB))
490 return BoundType(MD);
491
492 if (auto *MD = dyn_cast<DIExpression>(CB))
493 return BoundType(MD);
494
495 return BoundType();
496}
497
498DISubrange::BoundType DISubrange::getLowerBound() const {
499 Metadata *LB = getRawLowerBound();
500 if (!LB)
501 return BoundType();
502
503 assert((isa<ConstantAsMetadata>(LB) || isa<DIVariable>(LB) ||
504 isa<DIExpression>(LB)) &&
505 "LowerBound must be signed constant or DIVariable or DIExpression");
506
507 if (auto *MD = dyn_cast<ConstantAsMetadata>(LB))
508 return BoundType(cast<ConstantInt>(MD->getValue()));
509
510 if (auto *MD = dyn_cast<DIVariable>(LB))
511 return BoundType(MD);
512
513 if (auto *MD = dyn_cast<DIExpression>(LB))
514 return BoundType(MD);
515
516 return BoundType();
517}
518
519DISubrange::BoundType DISubrange::getUpperBound() const {
520 Metadata *UB = getRawUpperBound();
521 if (!UB)
522 return BoundType();
523
524 assert((isa<ConstantAsMetadata>(UB) || isa<DIVariable>(UB) ||
525 isa<DIExpression>(UB)) &&
526 "UpperBound must be signed constant or DIVariable or DIExpression");
527
528 if (auto *MD = dyn_cast<ConstantAsMetadata>(UB))
529 return BoundType(cast<ConstantInt>(MD->getValue()));
530
531 if (auto *MD = dyn_cast<DIVariable>(UB))
532 return BoundType(MD);
533
534 if (auto *MD = dyn_cast<DIExpression>(UB))
535 return BoundType(MD);
536
537 return BoundType();
538}
539
540DISubrange::BoundType DISubrange::getStride() const {
541 Metadata *ST = getRawStride();
542 if (!ST)
543 return BoundType();
544
545 assert((isa<ConstantAsMetadata>(ST) || isa<DIVariable>(ST) ||
546 isa<DIExpression>(ST)) &&
547 "Stride must be signed constant or DIVariable or DIExpression");
548
549 if (auto *MD = dyn_cast<ConstantAsMetadata>(ST))
550 return BoundType(cast<ConstantInt>(MD->getValue()));
551
552 if (auto *MD = dyn_cast<DIVariable>(ST))
553 return BoundType(MD);
554
555 if (auto *MD = dyn_cast<DIExpression>(ST))
556 return BoundType(MD);
557
558 return BoundType();
559}
560DIGenericSubrange::DIGenericSubrange(LLVMContext &C, StorageType Storage,
562 : DINode(C, DIGenericSubrangeKind, Storage, dwarf::DW_TAG_generic_subrange,
563 Ops) {}
564
565DIGenericSubrange *DIGenericSubrange::getImpl(LLVMContext &Context,
566 Metadata *CountNode, Metadata *LB,
567 Metadata *UB, Metadata *Stride,
568 StorageType Storage,
569 bool ShouldCreate) {
570 DEFINE_GETIMPL_LOOKUP(DIGenericSubrange, (CountNode, LB, UB, Stride));
571 Metadata *Ops[] = {CountNode, LB, UB, Stride};
573}
574
577 if (!CB)
578 return BoundType();
579
580 assert((isa<DIVariable>(CB) || isa<DIExpression>(CB)) &&
581 "Count must be signed constant or DIVariable or DIExpression");
582
583 if (auto *MD = dyn_cast<DIVariable>(CB))
584 return BoundType(MD);
585
586 if (auto *MD = dyn_cast<DIExpression>(CB))
587 return BoundType(MD);
588
589 return BoundType();
590}
591
594 if (!LB)
595 return BoundType();
596
597 assert((isa<DIVariable>(LB) || isa<DIExpression>(LB)) &&
598 "LowerBound must be signed constant or DIVariable or DIExpression");
599
600 if (auto *MD = dyn_cast<DIVariable>(LB))
601 return BoundType(MD);
602
603 if (auto *MD = dyn_cast<DIExpression>(LB))
604 return BoundType(MD);
605
606 return BoundType();
607}
608
611 if (!UB)
612 return BoundType();
613
614 assert((isa<DIVariable>(UB) || isa<DIExpression>(UB)) &&
615 "UpperBound must be signed constant or DIVariable or DIExpression");
616
617 if (auto *MD = dyn_cast<DIVariable>(UB))
618 return BoundType(MD);
619
620 if (auto *MD = dyn_cast<DIExpression>(UB))
621 return BoundType(MD);
622
623 return BoundType();
624}
625
627 Metadata *ST = getRawStride();
628 if (!ST)
629 return BoundType();
630
631 assert((isa<DIVariable>(ST) || isa<DIExpression>(ST)) &&
632 "Stride must be signed constant or DIVariable or DIExpression");
633
634 if (auto *MD = dyn_cast<DIVariable>(ST))
635 return BoundType(MD);
636
637 if (auto *MD = dyn_cast<DIExpression>(ST))
638 return BoundType(MD);
639
640 return BoundType();
641}
642
643DIEnumerator::DIEnumerator(LLVMContext &C, StorageType Storage,
644 const APInt &Value, bool IsUnsigned,
646 : DINode(C, DIEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
647 Value(Value) {
648 SubclassData32 = IsUnsigned;
649}
650DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, const APInt &Value,
651 bool IsUnsigned, MDString *Name,
652 StorageType Storage, bool ShouldCreate) {
653 assert(isCanonical(Name) && "Expected canonical MDString");
655 Metadata *Ops[] = {Name};
657}
658
659DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
660 MDString *Name, uint64_t SizeInBits,
661 uint32_t AlignInBits, unsigned Encoding,
662 DIFlags Flags, StorageType Storage,
663 bool ShouldCreate) {
664 assert(isCanonical(Name) && "Expected canonical MDString");
666 (Tag, Name, SizeInBits, AlignInBits, Encoding, Flags));
667 Metadata *Ops[] = {nullptr, nullptr, Name};
669 (Tag, SizeInBits, AlignInBits, Encoding, Flags), Ops);
670}
671
672std::optional<DIBasicType::Signedness> DIBasicType::getSignedness() const {
673 switch (getEncoding()) {
674 case dwarf::DW_ATE_signed:
675 case dwarf::DW_ATE_signed_char:
676 return Signedness::Signed;
677 case dwarf::DW_ATE_unsigned:
678 case dwarf::DW_ATE_unsigned_char:
680 default:
681 return std::nullopt;
682 }
683}
684
685DIStringType *DIStringType::getImpl(LLVMContext &Context, unsigned Tag,
686 MDString *Name, Metadata *StringLength,
687 Metadata *StringLengthExp,
688 Metadata *StringLocationExp,
689 uint64_t SizeInBits, uint32_t AlignInBits,
690 unsigned Encoding, StorageType Storage,
691 bool ShouldCreate) {
692 assert(isCanonical(Name) && "Expected canonical MDString");
696 Metadata *Ops[] = {nullptr, nullptr, Name,
699 Ops);
700}
701DIType *DIDerivedType::getClassType() const {
702 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
703 return cast_or_null<DIType>(getExtraData());
704}
706 assert(getTag() == dwarf::DW_TAG_inheritance);
707 if (auto *CM = cast_or_null<ConstantAsMetadata>(getExtraData()))
708 if (auto *CI = dyn_cast_or_null<ConstantInt>(CM->getValue()))
709 return static_cast<uint32_t>(CI->getZExtValue());
710 return 0;
711}
713 assert(getTag() == dwarf::DW_TAG_member && isBitField());
714 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
715 return C->getValue();
716 return nullptr;
717}
718
720 assert((getTag() == dwarf::DW_TAG_member ||
721 getTag() == dwarf::DW_TAG_variable) &&
723 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
724 return C->getValue();
725 return nullptr;
726}
728 assert(getTag() == dwarf::DW_TAG_member && !isStaticMember());
729 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
730 return C->getValue();
731 return nullptr;
732}
733
735DIDerivedType::getImpl(LLVMContext &Context, unsigned Tag, MDString *Name,
736 Metadata *File, unsigned Line, Metadata *Scope,
737 Metadata *BaseType, uint64_t SizeInBits,
738 uint32_t AlignInBits, uint64_t OffsetInBits,
739 std::optional<unsigned> DWARFAddressSpace, DIFlags Flags,
740 Metadata *ExtraData, Metadata *Annotations,
741 StorageType Storage, bool ShouldCreate) {
742 assert(isCanonical(Name) && "Expected canonical MDString");
745 AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
750 DWARFAddressSpace, Flags),
751 Ops);
752}
753
754DICompositeType *DICompositeType::getImpl(
755 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
756 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
757 uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
758 Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
759 Metadata *TemplateParams, MDString *Identifier, Metadata *Discriminator,
760 Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
761 Metadata *Rank, Metadata *Annotations, StorageType Storage,
762 bool ShouldCreate) {
763 assert(isCanonical(Name) && "Expected canonical MDString");
764
765 // Keep this in sync with buildODRType.
771 Rank, Annotations));
772 Metadata *Ops[] = {File, Scope, Name, BaseType,
778 (Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits, Flags),
779 Ops);
780}
781
783 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
784 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
785 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
786 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
787 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
788 Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
789 Metadata *Rank, Metadata *Annotations) {
790 assert(!Identifier.getString().empty() && "Expected valid identifier");
792 return nullptr;
793 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
794 if (!CT)
797 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
800
801 if (CT->getTag() != Tag)
802 return nullptr;
803
804 // Only mutate CT if it's a forward declaration and the new operands aren't.
805 assert(CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?");
806 if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl))
807 return CT;
808
809 // Mutate CT in place. Keep this in sync with getImpl.
810 CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
811 Flags);
812 Metadata *Ops[] = {File, Scope, Name, BaseType,
816 assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&
817 "Mismatched number of operands");
818 for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I)
819 if (Ops[I] != CT->getOperand(I))
820 CT->setOperand(I, Ops[I]);
821 return CT;
822}
823
824DICompositeType *DICompositeType::getODRType(
825 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
826 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
827 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
828 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
829 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
830 Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
831 Metadata *Rank, Metadata *Annotations) {
832 assert(!Identifier.getString().empty() && "Expected valid identifier");
834 return nullptr;
835 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
836 if (!CT) {
838 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
842 } else {
843 if (CT->getTag() != Tag)
844 return nullptr;
845 }
846 return CT;
847}
848
850 MDString &Identifier) {
851 assert(!Identifier.getString().empty() && "Expected valid identifier");
853 return nullptr;
854 return Context.pImpl->DITypeMap->lookup(&Identifier);
855}
856DISubroutineType::DISubroutineType(LLVMContext &C, StorageType Storage,
857 DIFlags Flags, uint8_t CC,
859 : DIType(C, DISubroutineTypeKind, Storage, dwarf::DW_TAG_subroutine_type, 0,
860 0, 0, 0, Flags, Ops),
861 CC(CC) {}
862
863DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags,
864 uint8_t CC, Metadata *TypeArray,
865 StorageType Storage,
866 bool ShouldCreate) {
868 Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
870}
871
872DIFile::DIFile(LLVMContext &C, StorageType Storage,
873 std::optional<ChecksumInfo<MDString *>> CS, MDString *Src,
875 : DIScope(C, DIFileKind, Storage, dwarf::DW_TAG_file_type, Ops),
876 Checksum(CS), Source(Src) {}
877
878// FIXME: Implement this string-enum correspondence with a .def file and macros,
879// so that the association is explicit rather than implied.
880static const char *ChecksumKindName[DIFile::CSK_Last] = {
881 "CSK_MD5",
882 "CSK_SHA1",
883 "CSK_SHA256",
884};
885
886StringRef DIFile::getChecksumKindAsString(ChecksumKind CSKind) {
887 assert(CSKind <= DIFile::CSK_Last && "Invalid checksum kind");
888 // The first space was originally the CSK_None variant, which is now
889 // obsolete, but the space is still reserved in ChecksumKind, so we account
890 // for it here.
891 return ChecksumKindName[CSKind - 1];
892}
893
894std::optional<DIFile::ChecksumKind>
897 .Case("CSK_MD5", DIFile::CSK_MD5)
898 .Case("CSK_SHA1", DIFile::CSK_SHA1)
899 .Case("CSK_SHA256", DIFile::CSK_SHA256)
900 .Default(std::nullopt);
901}
902
903DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
904 MDString *Directory,
905 std::optional<DIFile::ChecksumInfo<MDString *>> CS,
906 MDString *Source, StorageType Storage,
907 bool ShouldCreate) {
908 assert(isCanonical(Filename) && "Expected canonical MDString");
909 assert(isCanonical(Directory) && "Expected canonical MDString");
910 assert((!CS || isCanonical(CS->Value)) && "Expected canonical MDString");
911 // We do *NOT* expect Source to be a canonical MDString because nullptr
912 // means none, so we need something to represent the empty file.
914 Metadata *Ops[] = {Filename, Directory, CS ? CS->Value : nullptr, Source};
915 DEFINE_GETIMPL_STORE(DIFile, (CS, Source), Ops);
916}
917DICompileUnit::DICompileUnit(LLVMContext &C, StorageType Storage,
918 unsigned SourceLanguage, bool IsOptimized,
919 unsigned RuntimeVersion, unsigned EmissionKind,
920 uint64_t DWOId, bool SplitDebugInlining,
921 bool DebugInfoForProfiling, unsigned NameTableKind,
922 bool RangesBaseAddress, ArrayRef<Metadata *> Ops)
923 : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
924 SourceLanguage(SourceLanguage), RuntimeVersion(RuntimeVersion),
926 IsOptimized(IsOptimized), SplitDebugInlining(SplitDebugInlining),
927 DebugInfoForProfiling(DebugInfoForProfiling),
928 RangesBaseAddress(RangesBaseAddress) {
930}
931
932DICompileUnit *DICompileUnit::getImpl(
933 LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
934 MDString *Producer, bool IsOptimized, MDString *Flags,
935 unsigned RuntimeVersion, MDString *SplitDebugFilename,
936 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
937 Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
938 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
939 unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
940 MDString *SDK, StorageType Storage, bool ShouldCreate) {
941 assert(Storage != Uniqued && "Cannot unique DICompileUnit");
942 assert(isCanonical(Producer) && "Expected canonical MDString");
943 assert(isCanonical(Flags) && "Expected canonical MDString");
944 assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
945
946 Metadata *Ops[] = {File,
947 Producer,
948 Flags,
950 EnumTypes,
954 Macros,
955 SysRoot,
956 SDK};
957 return storeImpl(new (std::size(Ops), Storage) DICompileUnit(
958 Context, Storage, SourceLanguage, IsOptimized,
959 RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
960 DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
961 Ops),
962 Storage);
963}
964
965std::optional<DICompileUnit::DebugEmissionKind>
968 .Case("NoDebug", NoDebug)
969 .Case("FullDebug", FullDebug)
970 .Case("LineTablesOnly", LineTablesOnly)
971 .Case("DebugDirectivesOnly", DebugDirectivesOnly)
972 .Default(std::nullopt);
973}
974
975std::optional<DICompileUnit::DebugNameTableKind>
978 .Case("Default", DebugNameTableKind::Default)
982 .Default(std::nullopt);
983}
984
986 switch (EK) {
987 case NoDebug:
988 return "NoDebug";
989 case FullDebug:
990 return "FullDebug";
991 case LineTablesOnly:
992 return "LineTablesOnly";
994 return "DebugDirectivesOnly";
995 }
996 return nullptr;
997}
998
1000 switch (NTK) {
1002 return nullptr;
1004 return "GNU";
1006 return "Apple";
1008 return "None";
1009 }
1010 return nullptr;
1011}
1012DISubprogram::DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1013 unsigned ScopeLine, unsigned VirtualIndex,
1014 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags,
1016 : DILocalScope(C, DISubprogramKind, Storage, dwarf::DW_TAG_subprogram, Ops),
1017 Line(Line), ScopeLine(ScopeLine), VirtualIndex(VirtualIndex),
1018 ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags) {
1019 static_assert(dwarf::DW_VIRTUALITY_max < 4, "Virtuality out of range");
1020}
1022DISubprogram::toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized,
1023 unsigned Virtuality, bool IsMainSubprogram) {
1024 // We're assuming virtuality is the low-order field.
1025 static_assert(int(SPFlagVirtual) == int(dwarf::DW_VIRTUALITY_virtual) &&
1026 int(SPFlagPureVirtual) ==
1027 int(dwarf::DW_VIRTUALITY_pure_virtual),
1028 "Virtuality constant mismatch");
1029 return static_cast<DISPFlags>(
1030 (Virtuality & SPFlagVirtuality) |
1031 (IsLocalToUnit ? SPFlagLocalToUnit : SPFlagZero) |
1032 (IsDefinition ? SPFlagDefinition : SPFlagZero) |
1033 (IsOptimized ? SPFlagOptimized : SPFlagZero) |
1034 (IsMainSubprogram ? SPFlagMainSubprogram : SPFlagZero));
1035}
1036
1038 if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
1039 return Block->getScope()->getSubprogram();
1040 return const_cast<DISubprogram *>(cast<DISubprogram>(this));
1041}
1042
1044 if (auto *File = dyn_cast<DILexicalBlockFile>(this))
1045 return File->getScope()->getNonLexicalBlockFileScope();
1046 return const_cast<DILocalScope *>(this);
1047}
1048
1050 DILocalScope &RootScope, DISubprogram &NewSP, LLVMContext &Ctx,
1052 SmallVector<DIScope *> ScopeChain;
1053 DIScope *CachedResult = nullptr;
1054
1055 for (DIScope *Scope = &RootScope; !isa<DISubprogram>(Scope);
1056 Scope = Scope->getScope()) {
1057 if (auto It = Cache.find(Scope); It != Cache.end()) {
1058 CachedResult = cast<DIScope>(It->second);
1059 break;
1060 }
1061 ScopeChain.push_back(Scope);
1062 }
1063
1064 // Recreate the scope chain, bottom-up, starting at the new subprogram (or a
1065 // cached result).
1066 DIScope *UpdatedScope = CachedResult ? CachedResult : &NewSP;
1067 for (DIScope *ScopeToUpdate : reverse(ScopeChain)) {
1068 TempMDNode ClonedScope = ScopeToUpdate->clone();
1069 cast<DILexicalBlockBase>(*ClonedScope).replaceScope(UpdatedScope);
1070 UpdatedScope =
1071 cast<DIScope>(MDNode::replaceWithUniqued(std::move(ClonedScope)));
1072 Cache[ScopeToUpdate] = UpdatedScope;
1073 }
1074
1075 return cast<DILocalScope>(UpdatedScope);
1076}
1077
1079 return StringSwitch<DISPFlags>(Flag)
1080#define HANDLE_DISP_FLAG(ID, NAME) .Case("DISPFlag" #NAME, SPFlag##NAME)
1081#include "llvm/IR/DebugInfoFlags.def"
1082 .Default(SPFlagZero);
1083}
1084
1086 switch (Flag) {
1087 // Appease a warning.
1088 case SPFlagVirtuality:
1089 return "";
1090#define HANDLE_DISP_FLAG(ID, NAME) \
1091 case SPFlag##NAME: \
1092 return "DISPFlag" #NAME;
1093#include "llvm/IR/DebugInfoFlags.def"
1094 }
1095 return "";
1096}
1097
1100 SmallVectorImpl<DISPFlags> &SplitFlags) {
1101 // Multi-bit fields can require special handling. In our case, however, the
1102 // only multi-bit field is virtuality, and all its values happen to be
1103 // single-bit values, so the right behavior just falls out.
1104#define HANDLE_DISP_FLAG(ID, NAME) \
1105 if (DISPFlags Bit = Flags & SPFlag##NAME) { \
1106 SplitFlags.push_back(Bit); \
1107 Flags &= ~Bit; \
1108 }
1109#include "llvm/IR/DebugInfoFlags.def"
1110 return Flags;
1111}
1112
1113DISubprogram *DISubprogram::getImpl(
1114 LLVMContext &Context, Metadata *Scope, MDString *Name,
1115 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1116 unsigned ScopeLine, Metadata *ContainingType, unsigned VirtualIndex,
1117 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
1118 Metadata *TemplateParams, Metadata *Declaration, Metadata *RetainedNodes,
1119 Metadata *ThrownTypes, Metadata *Annotations, MDString *TargetFuncName,
1120 StorageType Storage, bool ShouldCreate) {
1121 assert(isCanonical(Name) && "Expected canonical MDString");
1122 assert(isCanonical(LinkageName) && "Expected canonical MDString");
1123 assert(isCanonical(TargetFuncName) && "Expected canonical MDString");
1125 (Scope, Name, LinkageName, File, Line, Type, ScopeLine,
1126 ContainingType, VirtualIndex, ThisAdjustment, Flags,
1127 SPFlags, Unit, TemplateParams, Declaration,
1135 if (!TargetFuncName) {
1136 Ops.pop_back();
1137 if (!Annotations) {
1138 Ops.pop_back();
1139 if (!ThrownTypes) {
1140 Ops.pop_back();
1141 if (!TemplateParams) {
1142 Ops.pop_back();
1143 if (!ContainingType)
1144 Ops.pop_back();
1145 }
1146 }
1147 }
1148 }
1151 (Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags, SPFlags), Ops,
1152 Ops.size());
1153}
1154
1155bool DISubprogram::describes(const Function *F) const {
1156 assert(F && "Invalid function");
1157 return F->getSubprogram() == this;
1158}
1160 StorageType Storage,
1162 : DILocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1163
1164DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
1165 Metadata *File, unsigned Line,
1166 unsigned Column, StorageType Storage,
1167 bool ShouldCreate) {
1168 // Fixup column.
1169 adjustColumn(Column);
1170
1171 assert(Scope && "Expected scope");
1173 Metadata *Ops[] = {File, Scope};
1174 DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops);
1175}
1176
1177DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
1178 Metadata *Scope, Metadata *File,
1179 unsigned Discriminator,
1180 StorageType Storage,
1181 bool ShouldCreate) {
1182 assert(Scope && "Expected scope");
1184 Metadata *Ops[] = {File, Scope};
1186}
1187
1188DINamespace::DINamespace(LLVMContext &Context, StorageType Storage,
1189 bool ExportSymbols, ArrayRef<Metadata *> Ops)
1190 : DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace, Ops) {
1191 SubclassData1 = ExportSymbols;
1192}
1193DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
1194 MDString *Name, bool ExportSymbols,
1195 StorageType Storage, bool ShouldCreate) {
1196 assert(isCanonical(Name) && "Expected canonical MDString");
1198 // The nullptr is for DIScope's File operand. This should be refactored.
1199 Metadata *Ops[] = {nullptr, Scope, Name};
1201}
1202
1203DICommonBlock::DICommonBlock(LLVMContext &Context, StorageType Storage,
1204 unsigned LineNo, ArrayRef<Metadata *> Ops)
1205 : DIScope(Context, DICommonBlockKind, Storage, dwarf::DW_TAG_common_block,
1206 Ops) {
1207 SubclassData32 = LineNo;
1208}
1209DICommonBlock *DICommonBlock::getImpl(LLVMContext &Context, Metadata *Scope,
1210 Metadata *Decl, MDString *Name,
1211 Metadata *File, unsigned LineNo,
1212 StorageType Storage, bool ShouldCreate) {
1213 assert(isCanonical(Name) && "Expected canonical MDString");
1215 // The nullptr is for DIScope's File operand. This should be refactored.
1216 Metadata *Ops[] = {Scope, Decl, Name, File};
1218}
1219
1220DIModule::DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo,
1221 bool IsDecl, ArrayRef<Metadata *> Ops)
1222 : DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops) {
1223 SubclassData1 = IsDecl;
1224 SubclassData32 = LineNo;
1225}
1226DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *File,
1227 Metadata *Scope, MDString *Name,
1228 MDString *ConfigurationMacros,
1229 MDString *IncludePath, MDString *APINotesFile,
1230 unsigned LineNo, bool IsDecl, StorageType Storage,
1231 bool ShouldCreate) {
1232 assert(isCanonical(Name) && "Expected canonical MDString");
1234 IncludePath, APINotesFile, LineNo, IsDecl));
1237 DEFINE_GETIMPL_STORE(DIModule, (LineNo, IsDecl), Ops);
1238}
1239DITemplateTypeParameter::DITemplateTypeParameter(LLVMContext &Context,
1240 StorageType Storage,
1241 bool IsDefault,
1243 : DITemplateParameter(Context, DITemplateTypeParameterKind, Storage,
1244 dwarf::DW_TAG_template_type_parameter, IsDefault,
1245 Ops) {}
1246
1248DITemplateTypeParameter::getImpl(LLVMContext &Context, MDString *Name,
1249 Metadata *Type, bool isDefault,
1250 StorageType Storage, bool ShouldCreate) {
1251 assert(isCanonical(Name) && "Expected canonical MDString");
1253 Metadata *Ops[] = {Name, Type};
1255}
1256
1257DITemplateValueParameter *DITemplateValueParameter::getImpl(
1258 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
1259 bool isDefault, Metadata *Value, StorageType Storage, bool ShouldCreate) {
1260 assert(isCanonical(Name) && "Expected canonical MDString");
1262 (Tag, Name, Type, isDefault, Value));
1263 Metadata *Ops[] = {Name, Type, Value};
1265}
1266
1268DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1269 MDString *LinkageName, Metadata *File, unsigned Line,
1270 Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1271 Metadata *StaticDataMemberDeclaration,
1272 Metadata *TemplateParams, uint32_t AlignInBits,
1273 Metadata *Annotations, StorageType Storage,
1274 bool ShouldCreate) {
1275 assert(isCanonical(Name) && "Expected canonical MDString");
1276 assert(isCanonical(LinkageName) && "Expected canonical MDString");
1279 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1281 Metadata *Ops[] = {Scope,
1282 Name,
1283 File,
1284 Type,
1285 Name,
1289 Annotations};
1291 (Line, IsLocalToUnit, IsDefinition, AlignInBits), Ops);
1292}
1293
1295DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1296 Metadata *File, unsigned Line, Metadata *Type,
1297 unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
1298 Metadata *Annotations, StorageType Storage,
1299 bool ShouldCreate) {
1300 // 64K ought to be enough for any frontend.
1301 assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");
1302
1303 assert(Scope && "Expected scope");
1304 assert(isCanonical(Name) && "Expected canonical MDString");
1306 Flags, AlignInBits, Annotations));
1307 Metadata *Ops[] = {Scope, Name, File, Type, Annotations};
1309}
1310
1312 signed Line, ArrayRef<Metadata *> Ops,
1313 uint32_t AlignInBits)
1314 : DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line) {
1315 SubclassData32 = AlignInBits;
1316}
1317std::optional<uint64_t> DIVariable::getSizeInBits() const {
1318 // This is used by the Verifier so be mindful of broken types.
1319 const Metadata *RawType = getRawType();
1320 while (RawType) {
1321 // Try to get the size directly.
1322 if (auto *T = dyn_cast<DIType>(RawType))
1323 if (uint64_t Size = T->getSizeInBits())
1324 return Size;
1325
1326 if (auto *DT = dyn_cast<DIDerivedType>(RawType)) {
1327 // Look at the base type.
1328 RawType = DT->getRawBaseType();
1329 continue;
1330 }
1331
1332 // Missing type or size.
1333 break;
1334 }
1335
1336 // Fail gracefully.
1337 return std::nullopt;
1338}
1339
1340DILabel::DILabel(LLVMContext &C, StorageType Storage, unsigned Line,
1342 : DINode(C, DILabelKind, Storage, dwarf::DW_TAG_label, Ops) {
1343 SubclassData32 = Line;
1344}
1345DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1346 Metadata *File, unsigned Line, StorageType Storage,
1347 bool ShouldCreate) {
1348 assert(Scope && "Expected scope");
1349 assert(isCanonical(Name) && "Expected canonical MDString");
1351 Metadata *Ops[] = {Scope, Name, File};
1353}
1354
1355DIExpression *DIExpression::getImpl(LLVMContext &Context,
1356 ArrayRef<uint64_t> Elements,
1357 StorageType Storage, bool ShouldCreate) {
1360}
1362 if (auto singleLocElts = getSingleLocationExpressionElements()) {
1363 return singleLocElts->size() > 0 &&
1364 (*singleLocElts)[0] == dwarf::DW_OP_LLVM_entry_value;
1365 }
1366 return false;
1367}
1369 if (auto singleLocElts = getSingleLocationExpressionElements())
1370 return singleLocElts->size() > 0 &&
1371 (*singleLocElts)[0] == dwarf::DW_OP_deref;
1372 return false;
1373}
1375 if (auto singleLocElts = getSingleLocationExpressionElements())
1376 return singleLocElts->size() == 1 &&
1377 (*singleLocElts)[0] == dwarf::DW_OP_deref;
1378 return false;
1379}
1380
1381DIAssignID *DIAssignID::getImpl(LLVMContext &Context, StorageType Storage,
1382 bool ShouldCreate) {
1383 // Uniqued DIAssignID are not supported as the instance address *is* the ID.
1384 assert(Storage != StorageType::Uniqued && "uniqued DIAssignID unsupported");
1385 return storeImpl(new (0u, Storage) DIAssignID(Context, Storage), Storage);
1386}
1387
1389 uint64_t Op = getOp();
1390
1391 if (Op >= dwarf::DW_OP_breg0 && Op <= dwarf::DW_OP_breg31)
1392 return 2;
1393
1394 switch (Op) {
1397 case dwarf::DW_OP_bregx:
1398 return 3;
1399 case dwarf::DW_OP_constu:
1400 case dwarf::DW_OP_consts:
1401 case dwarf::DW_OP_deref_size:
1402 case dwarf::DW_OP_plus_uconst:
1406 case dwarf::DW_OP_regx:
1407 return 2;
1408 default:
1409 return 1;
1410 }
1411}
1412
1414 for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
1415 // Check that there's space for the operand.
1416 if (I->get() + I->getSize() > E->get())
1417 return false;
1418
1419 uint64_t Op = I->getOp();
1420 if ((Op >= dwarf::DW_OP_reg0 && Op <= dwarf::DW_OP_reg31) ||
1421 (Op >= dwarf::DW_OP_breg0 && Op <= dwarf::DW_OP_breg31))
1422 return true;
1423
1424 // Check that the operand is valid.
1425 switch (Op) {
1426 default:
1427 return false;
1429 // A fragment operator must appear at the end.
1430 return I->get() + I->getSize() == E->get();
1431 case dwarf::DW_OP_stack_value: {
1432 // Must be the last one or followed by a DW_OP_LLVM_fragment.
1433 if (I->get() + I->getSize() == E->get())
1434 break;
1435 auto J = I;
1436 if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment)
1437 return false;
1438 break;
1439 }
1440 case dwarf::DW_OP_swap: {
1441 // Must be more than one implicit element on the stack.
1442
1443 // FIXME: A better way to implement this would be to add a local variable
1444 // that keeps track of the stack depth and introduce something like a
1445 // DW_LLVM_OP_implicit_location as a placeholder for the location this
1446 // DIExpression is attached to, or else pass the number of implicit stack
1447 // elements into isValid.
1448 if (getNumElements() == 1)
1449 return false;
1450 break;
1451 }
1453 // An entry value operator must appear at the beginning or immediately
1454 // following `DW_OP_LLVM_arg 0`, and the number of operations it cover can
1455 // currently only be 1, because we support only entry values of a simple
1456 // register location. One reason for this is that we currently can't
1457 // calculate the size of the resulting DWARF block for other expressions.
1458 auto FirstOp = expr_op_begin();
1459 if (FirstOp->getOp() == dwarf::DW_OP_LLVM_arg && FirstOp->getArg(0) == 0)
1460 ++FirstOp;
1461 return I->get() == FirstOp->get() && I->getArg(0) == 1;
1462 }
1467 case dwarf::DW_OP_constu:
1468 case dwarf::DW_OP_plus_uconst:
1469 case dwarf::DW_OP_plus:
1470 case dwarf::DW_OP_minus:
1471 case dwarf::DW_OP_mul:
1472 case dwarf::DW_OP_div:
1473 case dwarf::DW_OP_mod:
1474 case dwarf::DW_OP_or:
1475 case dwarf::DW_OP_and:
1476 case dwarf::DW_OP_xor:
1477 case dwarf::DW_OP_shl:
1478 case dwarf::DW_OP_shr:
1479 case dwarf::DW_OP_shra:
1480 case dwarf::DW_OP_deref:
1481 case dwarf::DW_OP_deref_size:
1482 case dwarf::DW_OP_xderef:
1483 case dwarf::DW_OP_lit0:
1484 case dwarf::DW_OP_not:
1485 case dwarf::DW_OP_dup:
1486 case dwarf::DW_OP_regx:
1487 case dwarf::DW_OP_bregx:
1488 case dwarf::DW_OP_push_object_address:
1489 case dwarf::DW_OP_over:
1490 case dwarf::DW_OP_consts:
1491 case dwarf::DW_OP_eq:
1492 case dwarf::DW_OP_ne:
1493 case dwarf::DW_OP_gt:
1494 case dwarf::DW_OP_ge:
1495 case dwarf::DW_OP_lt:
1496 case dwarf::DW_OP_le:
1497 break;
1498 }
1499 }
1500 return true;
1501}
1502
1504 if (!isValid())
1505 return false;
1506
1507 if (getNumElements() == 0)
1508 return false;
1509
1510 for (const auto &It : expr_ops()) {
1511 switch (It.getOp()) {
1512 default:
1513 break;
1514 case dwarf::DW_OP_stack_value:
1515 return true;
1516 }
1517 }
1518
1519 return false;
1520}
1521
1523 if (!isValid())
1524 return false;
1525
1526 if (getNumElements() == 0)
1527 return false;
1528
1529 // If there are any elements other than fragment or tag_offset, then some
1530 // kind of complex computation occurs.
1531 for (const auto &It : expr_ops()) {
1532 switch (It.getOp()) {
1536 continue;
1537 default:
1538 return true;
1539 }
1540 }
1541
1542 return false;
1543}
1544
1546 if (!isValid())
1547 return false;
1548
1549 if (getNumElements() == 0)
1550 return true;
1551
1552 auto ExprOpBegin = expr_ops().begin();
1553 auto ExprOpEnd = expr_ops().end();
1554 if (ExprOpBegin->getOp() == dwarf::DW_OP_LLVM_arg) {
1555 if (ExprOpBegin->getArg(0) != 0)
1556 return false;
1557 ++ExprOpBegin;
1558 }
1559
1560 return !std::any_of(ExprOpBegin, ExprOpEnd, [](auto Op) {
1561 return Op.getOp() == dwarf::DW_OP_LLVM_arg;
1562 });
1563}
1564
1565std::optional<ArrayRef<uint64_t>>
1567 // Check for `isValid` covered by `isSingleLocationExpression`.
1569 return std::nullopt;
1570
1571 // An empty expression is already non-variadic.
1572 if (!getNumElements())
1573 return ArrayRef<uint64_t>();
1574
1575 // If Expr does not have a leading DW_OP_LLVM_arg then we don't need to do
1576 // anything.
1578 return getElements().drop_front(2);
1579 return getElements();
1580}
1581
1582const DIExpression *
1584 SmallVector<uint64_t, 3> UndefOps;
1585 if (auto FragmentInfo = Expr->getFragmentInfo()) {
1588 }
1589 return DIExpression::get(Expr->getContext(), UndefOps);
1590}
1591
1592const DIExpression *
1594 if (any_of(Expr->expr_ops(), [](auto ExprOp) {
1595 return ExprOp.getOp() == dwarf::DW_OP_LLVM_arg;
1596 }))
1597 return Expr;
1598 SmallVector<uint64_t> NewOps;
1599 NewOps.reserve(Expr->getNumElements() + 2);
1600 NewOps.append({dwarf::DW_OP_LLVM_arg, 0});
1601 NewOps.append(Expr->elements_begin(), Expr->elements_end());
1602 return DIExpression::get(Expr->getContext(), NewOps);
1603}
1604
1605std::optional<const DIExpression *>
1607 if (!Expr)
1608 return std::nullopt;
1609
1610 if (auto Elts = Expr->getSingleLocationExpressionElements())
1611 return DIExpression::get(Expr->getContext(), *Elts);
1612
1613 return std::nullopt;
1614}
1615
1617 const DIExpression *Expr,
1618 bool IsIndirect) {
1619 // If Expr is not already variadic, insert the implied `DW_OP_LLVM_arg 0`
1620 // to the existing expression ops.
1621 if (none_of(Expr->expr_ops(), [](auto ExprOp) {
1622 return ExprOp.getOp() == dwarf::DW_OP_LLVM_arg;
1623 }))
1624 Ops.append({dwarf::DW_OP_LLVM_arg, 0});
1625 // If Expr is not indirect, we only need to insert the expression elements and
1626 // we're done.
1627 if (!IsIndirect) {
1628 Ops.append(Expr->elements_begin(), Expr->elements_end());
1629 return;
1630 }
1631 // If Expr is indirect, insert the implied DW_OP_deref at the end of the
1632 // expression but before DW_OP_{stack_value, LLVM_fragment} if they are
1633 // present.
1634 for (auto Op : Expr->expr_ops()) {
1635 if (Op.getOp() == dwarf::DW_OP_stack_value ||
1636 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1637 Ops.push_back(dwarf::DW_OP_deref);
1638 IsIndirect = false;
1639 }
1640 Op.appendToVector(Ops);
1641 }
1642 if (IsIndirect)
1643 Ops.push_back(dwarf::DW_OP_deref);
1644}
1645
1647 bool FirstIndirect,
1648 const DIExpression *SecondExpr,
1649 bool SecondIndirect) {
1650 SmallVector<uint64_t> FirstOps;
1651 DIExpression::canonicalizeExpressionOps(FirstOps, FirstExpr, FirstIndirect);
1652 SmallVector<uint64_t> SecondOps;
1653 DIExpression::canonicalizeExpressionOps(SecondOps, SecondExpr,
1654 SecondIndirect);
1655 return FirstOps == SecondOps;
1656}
1657
1658std::optional<DIExpression::FragmentInfo>
1660 for (auto I = Start; I != End; ++I)
1661 if (I->getOp() == dwarf::DW_OP_LLVM_fragment) {
1662 DIExpression::FragmentInfo Info = {I->getArg(1), I->getArg(0)};
1663 return Info;
1664 }
1665 return std::nullopt;
1666}
1667
1669 int64_t Offset) {
1670 if (Offset > 0) {
1671 Ops.push_back(dwarf::DW_OP_plus_uconst);
1672 Ops.push_back(Offset);
1673 } else if (Offset < 0) {
1674 Ops.push_back(dwarf::DW_OP_constu);
1675 // Avoid UB when encountering LLONG_MIN, because in 2's complement
1676 // abs(LLONG_MIN) is LLONG_MAX+1.
1677 uint64_t AbsMinusOne = -(Offset+1);
1678 Ops.push_back(AbsMinusOne + 1);
1679 Ops.push_back(dwarf::DW_OP_minus);
1680 }
1681}
1682
1684 auto SingleLocEltsOpt = getSingleLocationExpressionElements();
1685 if (!SingleLocEltsOpt)
1686 return false;
1687 auto SingleLocElts = *SingleLocEltsOpt;
1688
1689 if (SingleLocElts.size() == 0) {
1690 Offset = 0;
1691 return true;
1692 }
1693
1694 if (SingleLocElts.size() == 2 &&
1695 SingleLocElts[0] == dwarf::DW_OP_plus_uconst) {
1696 Offset = SingleLocElts[1];
1697 return true;
1698 }
1699
1700 if (SingleLocElts.size() == 3 && SingleLocElts[0] == dwarf::DW_OP_constu) {
1701 if (SingleLocElts[2] == dwarf::DW_OP_plus) {
1702 Offset = SingleLocElts[1];
1703 return true;
1704 }
1705 if (SingleLocElts[2] == dwarf::DW_OP_minus) {
1706 Offset = -SingleLocElts[1];
1707 return true;
1708 }
1709 }
1710
1711 return false;
1712}
1713
1716 for (auto ExprOp : expr_ops())
1717 if (ExprOp.getOp() == dwarf::DW_OP_LLVM_arg)
1718 SeenOps.insert(ExprOp.getArg(0));
1719 for (uint64_t Idx = 0; Idx < N; ++Idx)
1720 if (!SeenOps.contains(Idx))
1721 return false;
1722 return true;
1723}
1724
1726 unsigned &AddrClass) {
1727 // FIXME: This seems fragile. Nothing that verifies that these elements
1728 // actually map to ops and not operands.
1729 auto SingleLocEltsOpt = Expr->getSingleLocationExpressionElements();
1730 if (!SingleLocEltsOpt)
1731 return nullptr;
1732 auto SingleLocElts = *SingleLocEltsOpt;
1733
1734 const unsigned PatternSize = 4;
1735 if (SingleLocElts.size() >= PatternSize &&
1736 SingleLocElts[PatternSize - 4] == dwarf::DW_OP_constu &&
1737 SingleLocElts[PatternSize - 2] == dwarf::DW_OP_swap &&
1738 SingleLocElts[PatternSize - 1] == dwarf::DW_OP_xderef) {
1739 AddrClass = SingleLocElts[PatternSize - 3];
1740
1741 if (SingleLocElts.size() == PatternSize)
1742 return nullptr;
1743 return DIExpression::get(
1744 Expr->getContext(),
1745 ArrayRef(&*SingleLocElts.begin(), SingleLocElts.size() - PatternSize));
1746 }
1747 return Expr;
1748}
1749
1751 int64_t Offset) {
1753 if (Flags & DIExpression::DerefBefore)
1754 Ops.push_back(dwarf::DW_OP_deref);
1755
1756 appendOffset(Ops, Offset);
1757 if (Flags & DIExpression::DerefAfter)
1758 Ops.push_back(dwarf::DW_OP_deref);
1759
1760 bool StackValue = Flags & DIExpression::StackValue;
1761 bool EntryValue = Flags & DIExpression::EntryValue;
1762
1763 return prependOpcodes(Expr, Ops, StackValue, EntryValue);
1764}
1765
1768 unsigned ArgNo, bool StackValue) {
1769 assert(Expr && "Can't add ops to this expression");
1770
1771 // Handle non-variadic intrinsics by prepending the opcodes.
1772 if (!any_of(Expr->expr_ops(),
1773 [](auto Op) { return Op.getOp() == dwarf::DW_OP_LLVM_arg; })) {
1774 assert(ArgNo == 0 &&
1775 "Location Index must be 0 for a non-variadic expression.");
1776 SmallVector<uint64_t, 8> NewOps(Ops.begin(), Ops.end());
1777 return DIExpression::prependOpcodes(Expr, NewOps, StackValue);
1778 }
1779
1781 for (auto Op : Expr->expr_ops()) {
1782 // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
1783 if (StackValue) {
1784 if (Op.getOp() == dwarf::DW_OP_stack_value)
1785 StackValue = false;
1786 else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1787 NewOps.push_back(dwarf::DW_OP_stack_value);
1788 StackValue = false;
1789 }
1790 }
1791 Op.appendToVector(NewOps);
1792 if (Op.getOp() == dwarf::DW_OP_LLVM_arg && Op.getArg(0) == ArgNo)
1793 NewOps.insert(NewOps.end(), Ops.begin(), Ops.end());
1794 }
1795 if (StackValue)
1796 NewOps.push_back(dwarf::DW_OP_stack_value);
1797
1798 return DIExpression::get(Expr->getContext(), NewOps);
1799}
1800
1802 uint64_t OldArg, uint64_t NewArg) {
1803 assert(Expr && "Can't replace args in this expression");
1804
1806
1807 for (auto Op : Expr->expr_ops()) {
1808 if (Op.getOp() != dwarf::DW_OP_LLVM_arg || Op.getArg(0) < OldArg) {
1809 Op.appendToVector(NewOps);
1810 continue;
1811 }
1813 uint64_t Arg = Op.getArg(0) == OldArg ? NewArg : Op.getArg(0);
1814 // OldArg has been deleted from the Op list, so decrement all indices
1815 // greater than it.
1816 if (Arg > OldArg)
1817 --Arg;
1818 NewOps.push_back(Arg);
1819 }
1820 return DIExpression::get(Expr->getContext(), NewOps);
1821}
1822
1825 bool StackValue, bool EntryValue) {
1826 assert(Expr && "Can't prepend ops to this expression");
1827
1828 if (EntryValue) {
1830 // Use a block size of 1 for the target register operand. The
1831 // DWARF backend currently cannot emit entry values with a block
1832 // size > 1.
1833 Ops.push_back(1);
1834 }
1835
1836 // If there are no ops to prepend, do not even add the DW_OP_stack_value.
1837 if (Ops.empty())
1838 StackValue = false;
1839 for (auto Op : Expr->expr_ops()) {
1840 // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
1841 if (StackValue) {
1842 if (Op.getOp() == dwarf::DW_OP_stack_value)
1843 StackValue = false;
1844 else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1845 Ops.push_back(dwarf::DW_OP_stack_value);
1846 StackValue = false;
1847 }
1848 }
1849 Op.appendToVector(Ops);
1850 }
1851 if (StackValue)
1852 Ops.push_back(dwarf::DW_OP_stack_value);
1853 return DIExpression::get(Expr->getContext(), Ops);
1854}
1855
1857 ArrayRef<uint64_t> Ops) {
1858 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
1859
1860 // Copy Expr's current op list.
1862 for (auto Op : Expr->expr_ops()) {
1863 // Append new opcodes before DW_OP_{stack_value, LLVM_fragment}.
1864 if (Op.getOp() == dwarf::DW_OP_stack_value ||
1865 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1866 NewOps.append(Ops.begin(), Ops.end());
1867
1868 // Ensure that the new opcodes are only appended once.
1869 Ops = std::nullopt;
1870 }
1871 Op.appendToVector(NewOps);
1872 }
1873
1874 NewOps.append(Ops.begin(), Ops.end());
1875 auto *result = DIExpression::get(Expr->getContext(), NewOps);
1876 assert(result->isValid() && "concatenated expression is not valid");
1877 return result;
1878}
1879
1881 ArrayRef<uint64_t> Ops) {
1882 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
1883 assert(std::none_of(expr_op_iterator(Ops.begin()),
1884 expr_op_iterator(Ops.end()),
1885 [](auto Op) {
1886 return Op.getOp() == dwarf::DW_OP_stack_value ||
1887 Op.getOp() == dwarf::DW_OP_LLVM_fragment;
1888 }) &&
1889 "Can't append this op");
1890
1891 // Append a DW_OP_deref after Expr's current op list if it's non-empty and
1892 // has no DW_OP_stack_value.
1893 //
1894 // Match .* DW_OP_stack_value (DW_OP_LLVM_fragment A B)?.
1895 std::optional<FragmentInfo> FI = Expr->getFragmentInfo();
1896 unsigned DropUntilStackValue = FI ? 3 : 0;
1897 ArrayRef<uint64_t> ExprOpsBeforeFragment =
1898 Expr->getElements().drop_back(DropUntilStackValue);
1899 bool NeedsDeref = (Expr->getNumElements() > DropUntilStackValue) &&
1900 (ExprOpsBeforeFragment.back() != dwarf::DW_OP_stack_value);
1901 bool NeedsStackValue = NeedsDeref || ExprOpsBeforeFragment.empty();
1902
1903 // Append a DW_OP_deref after Expr's current op list if needed, then append
1904 // the new ops, and finally ensure that a single DW_OP_stack_value is present.
1906 if (NeedsDeref)
1907 NewOps.push_back(dwarf::DW_OP_deref);
1908 NewOps.append(Ops.begin(), Ops.end());
1909 if (NeedsStackValue)
1910 NewOps.push_back(dwarf::DW_OP_stack_value);
1911 return DIExpression::append(Expr, NewOps);
1912}
1913
1914std::optional<DIExpression *> DIExpression::createFragmentExpression(
1915 const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits) {
1917 // Track whether it's safe to split the value at the top of the DWARF stack,
1918 // assuming that it'll be used as an implicit location value.
1919 bool CanSplitValue = true;
1920 // Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment.
1921 if (Expr) {
1922 for (auto Op : Expr->expr_ops()) {
1923 switch (Op.getOp()) {
1924 default:
1925 break;
1926 case dwarf::DW_OP_shr:
1927 case dwarf::DW_OP_shra:
1928 case dwarf::DW_OP_shl:
1929 case dwarf::DW_OP_plus:
1930 case dwarf::DW_OP_plus_uconst:
1931 case dwarf::DW_OP_minus:
1932 // We can't safely split arithmetic or shift operations into multiple
1933 // fragments because we can't express carry-over between fragments.
1934 //
1935 // FIXME: We *could* preserve the lowest fragment of a constant offset
1936 // operation if the offset fits into SizeInBits.
1937 CanSplitValue = false;
1938 break;
1939 case dwarf::DW_OP_deref:
1940 case dwarf::DW_OP_deref_size:
1941 case dwarf::DW_OP_deref_type:
1942 case dwarf::DW_OP_xderef:
1943 case dwarf::DW_OP_xderef_size:
1944 case dwarf::DW_OP_xderef_type:
1945 // Preceeding arithmetic operations have been applied to compute an
1946 // address. It's okay to split the value loaded from that address.
1947 CanSplitValue = true;
1948 break;
1949 case dwarf::DW_OP_stack_value:
1950 // Bail if this expression computes a value that cannot be split.
1951 if (!CanSplitValue)
1952 return std::nullopt;
1953 break;
1955 // Make the new offset point into the existing fragment.
1956 uint64_t FragmentOffsetInBits = Op.getArg(0);
1957 uint64_t FragmentSizeInBits = Op.getArg(1);
1958 (void)FragmentSizeInBits;
1959 assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&
1960 "new fragment outside of original fragment");
1961 OffsetInBits += FragmentOffsetInBits;
1962 continue;
1963 }
1964 }
1965 Op.appendToVector(Ops);
1966 }
1967 }
1968 assert((!Expr->isImplicit() || CanSplitValue) && "Expr can't be split");
1969 assert(Expr && "Unknown DIExpression");
1971 Ops.push_back(OffsetInBits);
1972 Ops.push_back(SizeInBits);
1973 return DIExpression::get(Expr->getContext(), Ops);
1974}
1975
1976std::pair<DIExpression *, const ConstantInt *>
1978 // Copy the APInt so we can modify it.
1979 APInt NewInt = CI->getValue();
1981
1982 // Fold operators only at the beginning of the expression.
1983 bool First = true;
1984 bool Changed = false;
1985 for (auto Op : expr_ops()) {
1986 switch (Op.getOp()) {
1987 default:
1988 // We fold only the leading part of the expression; if we get to a part
1989 // that we're going to copy unchanged, and haven't done any folding,
1990 // then the entire expression is unchanged and we can return early.
1991 if (!Changed)
1992 return {this, CI};
1993 First = false;
1994 break;
1996 if (!First)
1997 break;
1998 Changed = true;
1999 if (Op.getArg(1) == dwarf::DW_ATE_signed)
2000 NewInt = NewInt.sextOrTrunc(Op.getArg(0));
2001 else {
2002 assert(Op.getArg(1) == dwarf::DW_ATE_unsigned && "Unexpected operand");
2003 NewInt = NewInt.zextOrTrunc(Op.getArg(0));
2004 }
2005 continue;
2006 }
2007 Op.appendToVector(Ops);
2008 }
2009 if (!Changed)
2010 return {this, CI};
2011 return {DIExpression::get(getContext(), Ops),
2012 ConstantInt::get(getContext(), NewInt)};
2013}
2014
2016 uint64_t Result = 0;
2017 for (auto ExprOp : expr_ops())
2018 if (ExprOp.getOp() == dwarf::DW_OP_LLVM_arg)
2019 Result = std::max(Result, ExprOp.getArg(0) + 1);
2020 assert(hasAllLocationOps(Result) &&
2021 "Expression is missing one or more location operands.");
2022 return Result;
2023}
2024
2025std::optional<DIExpression::SignedOrUnsignedConstant>
2027
2028 // Recognize signed and unsigned constants.
2029 // An signed constants can be represented as DW_OP_consts C DW_OP_stack_value
2030 // (DW_OP_LLVM_fragment of Len).
2031 // An unsigned constant can be represented as
2032 // DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment of Len).
2033
2034 if ((getNumElements() != 2 && getNumElements() != 3 &&
2035 getNumElements() != 6) ||
2036 (getElement(0) != dwarf::DW_OP_consts &&
2037 getElement(0) != dwarf::DW_OP_constu))
2038 return std::nullopt;
2039
2040 if (getNumElements() == 2 && getElement(0) == dwarf::DW_OP_consts)
2042
2043 if ((getNumElements() == 3 && getElement(2) != dwarf::DW_OP_stack_value) ||
2044 (getNumElements() == 6 && (getElement(2) != dwarf::DW_OP_stack_value ||
2046 return std::nullopt;
2047 return getElement(0) == dwarf::DW_OP_constu
2050}
2051
2052DIExpression::ExtOps DIExpression::getExtOps(unsigned FromSize, unsigned ToSize,
2053 bool Signed) {
2054 dwarf::TypeKind TK = Signed ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned;
2056 dwarf::DW_OP_LLVM_convert, ToSize, TK}};
2057 return Ops;
2058}
2059
2061 unsigned FromSize, unsigned ToSize,
2062 bool Signed) {
2063 return appendToStack(Expr, getExtOps(FromSize, ToSize, Signed));
2064}
2065
2067DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable,
2069 bool ShouldCreate) {
2071 Metadata *Ops[] = {Variable, Expression};
2073}
2074DIObjCProperty::DIObjCProperty(LLVMContext &C, StorageType Storage,
2075 unsigned Line, unsigned Attributes,
2077 : DINode(C, DIObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property, Ops),
2079
2080DIObjCProperty *DIObjCProperty::getImpl(
2081 LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
2082 MDString *GetterName, MDString *SetterName, unsigned Attributes,
2083 Metadata *Type, StorageType Storage, bool ShouldCreate) {
2084 assert(isCanonical(Name) && "Expected canonical MDString");
2085 assert(isCanonical(GetterName) && "Expected canonical MDString");
2086 assert(isCanonical(SetterName) && "Expected canonical MDString");
2088 SetterName, Attributes, Type));
2089 Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
2090 DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops);
2091}
2092
2093DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
2094 Metadata *Scope, Metadata *Entity,
2095 Metadata *File, unsigned Line,
2096 MDString *Name, Metadata *Elements,
2097 StorageType Storage,
2098 bool ShouldCreate) {
2099 assert(isCanonical(Name) && "Expected canonical MDString");
2101 (Tag, Scope, Entity, File, Line, Name, Elements));
2102 Metadata *Ops[] = {Scope, Entity, Name, File, Elements};
2104}
2105
2106DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
2107 MDString *Name, MDString *Value, StorageType Storage,
2108 bool ShouldCreate) {
2109 assert(isCanonical(Name) && "Expected canonical MDString");
2111 Metadata *Ops[] = {Name, Value};
2113}
2114
2115DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
2116 unsigned Line, Metadata *File,
2117 Metadata *Elements, StorageType Storage,
2118 bool ShouldCreate) {
2120 Metadata *Ops[] = {File, Elements};
2122}
2123
2126 auto ExistingIt = Context.pImpl->DIArgLists.find_as(DIArgListKeyInfo(Args));
2127 if (ExistingIt != Context.pImpl->DIArgLists.end())
2128 return *ExistingIt;
2129 DIArgList *NewArgList = new DIArgList(Context, Args);
2130 Context.pImpl->DIArgLists.insert(NewArgList);
2131 return NewArgList;
2132}
2133
2135 ValueAsMetadata **OldVMPtr = static_cast<ValueAsMetadata **>(Ref);
2136 assert((!New || isa<ValueAsMetadata>(New)) &&
2137 "DIArgList must be passed a ValueAsMetadata");
2138 untrack();
2139 // We need to update the set storage once the Args are updated since they
2140 // form the key to the DIArgLists store.
2141 getContext().pImpl->DIArgLists.erase(this);
2142 ValueAsMetadata *NewVM = cast_or_null<ValueAsMetadata>(New);
2143 for (ValueAsMetadata *&VM : Args) {
2144 if (&VM == OldVMPtr) {
2145 if (NewVM)
2146 VM = NewVM;
2147 else
2148 VM = ValueAsMetadata::get(PoisonValue::get(VM->getValue()->getType()));
2149 }
2150 }
2151 // We've changed the contents of this DIArgList, and the set storage may
2152 // already contain a DIArgList with our new set of args; if it does, then we
2153 // must RAUW this with the existing DIArgList, otherwise we simply insert this
2154 // back into the set storage.
2155 DIArgList *ExistingArgList = getUniqued(getContext().pImpl->DIArgLists, this);
2156 if (ExistingArgList) {
2157 replaceAllUsesWith(ExistingArgList);
2158 // Clear this here so we don't try to untrack in the destructor.
2159 Args.clear();
2160 delete this;
2161 return;
2162 }
2163 getContext().pImpl->DIArgLists.insert(this);
2164 track();
2165}
2166void DIArgList::track() {
2167 for (ValueAsMetadata *&VAM : Args)
2168 if (VAM)
2169 MetadataTracking::track(&VAM, *VAM, *this);
2170}
2171void DIArgList::untrack() {
2172 for (ValueAsMetadata *&VAM : Args)
2173 if (VAM)
2174 MetadataTracking::untrack(&VAM, *VAM);
2175}
2176void DIArgList::dropAllReferences(bool Untrack) {
2177 if (Untrack)
2178 untrack();
2179 Args.clear();
2180 ReplaceableMetadataImpl::resolveAllUses(/* ResolveUsers */ false);
2181}
static const LLT S1
AMDGPU Kernel Attributes
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate any type of IT block"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow complex IT blocks")))
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
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&...Args)
Definition: DIBuilder.cpp:822
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
bool End
Definition: ELF_riscv.cpp:480
#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 SmallPtrSet class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
support::ulittle16_t & Lo
Definition: aarch32.cpp:206
Class for arbitrary precision integers.
Definition: APInt.h:76
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
Definition: APInt.cpp:1002
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
Definition: APInt.cpp:1010
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:174
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition: ArrayRef.h:204
iterator end() const
Definition: ArrayRef.h:154
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
Definition: ArrayRef.h:210
iterator begin() const
Definition: ArrayRef.h:153
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:160
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:528
This is the shared class of boolean and integer constants.
Definition: Constants.h:79
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
Definition: Constants.h:122
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:144
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)
static DIArgList * get(LLVMContext &Context, ArrayRef< ValueAsMetadata * > Args)
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
Debug common block.
Metadata Metadata * Decl
Metadata Metadata MDString Metadata unsigned LineNo
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.
std::optional< ArrayRef< uint64_t > > getSingleLocationExpressionElements() const
Returns a reference to the elements contained in this expression, skipping past the leading DW_OP_LLV...
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 Line
unsigned Metadata Metadata Metadata unsigned MDString * Name
unsigned Metadata Metadata Metadata * File
unsigned Metadata * Scope
Metadata MDString Metadata unsigned Line
Metadata MDString * Name
Metadata MDString Metadata * File
DILexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage, ArrayRef< Metadata * > Ops)
Metadata Metadata unsigned Discriminator
Metadata Metadata * File
Debug lexical block.
Metadata Metadata unsigned Line
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 DILocation * getMergedLocations(ArrayRef< 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.
static DILocation * getMergedLocation(DILocation *LocA, DILocation *LocB)
When two instructions are combined into a single instruction we also need to combine the original loc...
unsigned unsigned Column
unsigned unsigned DILocalScope DILocation * InlinedAt
unsigned unsigned Metadata * File
unsigned unsigned Line
unsigned unsigned Metadata Metadata * Elements
unsigned unsigned MDString * Name
unsigned unsigned Line
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 Metadata MDString MDString MDString MDString unsigned LineNo
Debug lexical block.
Metadata MDString bool ExportSymbols
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)
Record of a variable value-assignment, aka a non instruction representation of the dbg....
This class represents an Operation in the Expression.
This is the common base class for debug info intrinsics for variables.
DebugVariableAggregate(const DbgVariableIntrinsic *DVI)
Identifies a unique instance of a variable.
DebugVariable(const DbgVariableIntrinsic *DII)
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:155
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&... Args)
Definition: DenseMap.h:235
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
DenseSet< DIArgList *, DIArgListInfo > DIArgLists
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:1067
friend class DIAssignID
Definition: Metadata.h:1070
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1549
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1541
TempMDNode clone() const
Create a (temporary) clone of this.
Definition: Metadata.cpp:658
static T * storeImpl(T *N, StorageType Storage, StoreT &Store)
Definition: MetadataImpl.h:42
LLVMContext & getContext() const
Definition: Metadata.h:1231
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:1299
A single uniqued string.
Definition: Metadata.h:720
StringRef getString() const
Definition: Metadata.cpp:607
static void untrack(Metadata *&MD)
Stop tracking a reference to metadata.
Definition: Metadata.h:349
static bool track(Metadata *&MD)
Track the reference to metadata.
Definition: Metadata.h:315
Root of the metadata hierarchy.
Definition: Metadata.h:62
StorageType
Active type of storage.
Definition: Metadata.h:70
unsigned short SubclassData16
Definition: Metadata.h:76
unsigned SubclassData32
Definition: Metadata.h:77
unsigned char Storage
Storage flag for non-uniqued, otherwise unowned, metadata.
Definition: Metadata.h:73
unsigned char SubclassData1
Definition: Metadata.h:75
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:118
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1827
void replaceAllUsesWith(Metadata *MD)
Replace all uses of this with MD.
Definition: Metadata.cpp:358
LLVMContext & getContext() const
Definition: Metadata.h:400
void resolveAllUses(bool ResolveUsers=true)
Resolve all uses of this.
Definition: Metadata.cpp:411
Implements a dense probed hash-table based set with some number of buckets stored inline.
Definition: DenseSet.h:290
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:427
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:586
void reserve(size_type N)
Definition: SmallVector.h:676
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:696
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:818
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
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)
Value wrapper in the Metadata hierarchy.
Definition: Metadata.h:450
static ValueAsMetadata * get(Value *V)
Definition: Metadata.cpp:492
LLVM Value Representation.
Definition: Value.h:74
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
Definition: DenseSet.h:185
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:204
@ DW_VIRTUALITY_max
Definition: Dwarf.h:195
@ NameTableKind
Definition: LLToken.h:477
@ EmissionKind
Definition: LLToken.h:476
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:329
@ Offset
Definition: DWP.cpp:456
static T * getUniqued(DenseSet< T *, InfoT > &Store, const typename InfoT::KeyTy &Key)
Definition: MetadataImpl.h:22
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:1738
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:428
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:1745
@ Ref
The access may reference the value stored in memory.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
#define N
Holds the characteristics of one fragment of a larger variable.
A single checksum, represented by a Kind and a Value (a string).