LLVM 17.0.0git
DebugInfoMetadata.cpp
Go to the documentation of this file.
1//===- DebugInfoMetadata.cpp - Implement debug info metadata --------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the debug info Metadata classes.
10//
11//===----------------------------------------------------------------------===//
12
14#include "LLVMContextImpl.h"
15#include "MetadataImpl.h"
17#include "llvm/ADT/SmallSet.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 : DebugVariable(DVI->getVariable(), std::nullopt,
47 DVI->getDebugLoc()->getInlinedAt()) {}
48
49DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
50 unsigned Column, ArrayRef<Metadata *> MDs,
51 bool ImplicitCode)
52 : MDNode(C, DILocationKind, Storage, MDs) {
53 assert((MDs.size() == 1 || MDs.size() == 2) &&
54 "Expected a scope and optional inlined-at");
55
56 // Set line and column.
57 assert(Column < (1u << 16) && "Expected 16-bit column");
58
59 SubclassData32 = Line;
60 SubclassData16 = Column;
61
62 setImplicitCode(ImplicitCode);
63}
64
65static void adjustColumn(unsigned &Column) {
66 // Set to unknown on overflow. We only have 16 bits to play with here.
67 if (Column >= (1u << 16))
68 Column = 0;
69}
70
71DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
72 unsigned Column, Metadata *Scope,
73 Metadata *InlinedAt, bool ImplicitCode,
74 StorageType Storage, bool ShouldCreate) {
75 // Fixup column.
77
78 if (Storage == Uniqued) {
79 if (auto *N = getUniqued(Context.pImpl->DILocations,
80 DILocationInfo::KeyTy(Line, Column, Scope,
82 return N;
83 if (!ShouldCreate)
84 return nullptr;
85 } else {
86 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
87 }
88
90 Ops.push_back(Scope);
91 if (InlinedAt)
93 return storeImpl(new (Ops.size(), Storage) DILocation(
94 Context, Storage, Line, Column, Ops, ImplicitCode),
95 Storage, Context.pImpl->DILocations);
96}
97
99 if (Locs.empty())
100 return nullptr;
101 if (Locs.size() == 1)
102 return Locs[0];
103 auto *Merged = Locs[0];
104 for (DILocation *L : llvm::drop_begin(Locs)) {
105 Merged = getMergedLocation(Merged, L);
106 if (Merged == nullptr)
107 break;
108 }
109 return Merged;
110}
111
113 if (!LocA || !LocB)
114 return nullptr;
115
116 if (LocA == LocB)
117 return LocA;
118
119 LLVMContext &C = LocA->getContext();
120
121 using LocVec = SmallVector<const DILocation *>;
122 LocVec ALocs;
123 LocVec BLocs;
125 4>
126 ALookup;
127
128 // Walk through LocA and its inlined-at locations, populate them in ALocs and
129 // save the index for the subprogram and inlined-at pair, which we use to find
130 // a matching starting location in LocB's chain.
131 for (auto [L, I] = std::make_pair(LocA, 0U); L; L = L->getInlinedAt(), I++) {
132 ALocs.push_back(L);
133 auto Res = ALookup.try_emplace(
134 {L->getScope()->getSubprogram(), L->getInlinedAt()}, I);
135 assert(Res.second && "Multiple <SP, InlinedAt> pairs in a location chain?");
136 (void)Res;
137 }
138
139 LocVec::reverse_iterator ARIt = ALocs.rend();
140 LocVec::reverse_iterator BRIt = BLocs.rend();
141
142 // Populate BLocs and look for a matching starting location, the first
143 // location with the same subprogram and inlined-at location as in LocA's
144 // chain. Since the two locations have the same inlined-at location we do
145 // not need to look at those parts of the chains.
146 for (auto [L, I] = std::make_pair(LocB, 0U); L; L = L->getInlinedAt(), I++) {
147 BLocs.push_back(L);
148
149 if (ARIt != ALocs.rend())
150 // We have already found a matching starting location.
151 continue;
152
153 auto IT = ALookup.find({L->getScope()->getSubprogram(), L->getInlinedAt()});
154 if (IT == ALookup.end())
155 continue;
156
157 // The + 1 is to account for the &*rev_it = &(it - 1) relationship.
158 ARIt = LocVec::reverse_iterator(ALocs.begin() + IT->second + 1);
159 BRIt = LocVec::reverse_iterator(BLocs.begin() + I + 1);
160
161 // If we have found a matching starting location we do not need to add more
162 // locations to BLocs, since we will only look at location pairs preceding
163 // the matching starting location, and adding more elements to BLocs could
164 // invalidate the iterator that we initialized here.
165 break;
166 }
167
168 // Merge the two locations if possible, using the supplied
169 // inlined-at location for the created location.
170 auto MergeLocPair = [&C](const DILocation *L1, const DILocation *L2,
172 if (L1 == L2)
173 return DILocation::get(C, L1->getLine(), L1->getColumn(), L1->getScope(),
174 InlinedAt);
175
176 // If the locations originate from different subprograms we can't produce
177 // a common location.
178 if (L1->getScope()->getSubprogram() != L2->getScope()->getSubprogram())
179 return nullptr;
180
181 // Return the nearest common scope inside a subprogram.
182 auto GetNearestCommonScope = [](DIScope *S1, DIScope *S2) -> DIScope * {
184 for (; S1; S1 = S1->getScope()) {
185 Scopes.insert(S1);
186 if (isa<DISubprogram>(S1))
187 break;
188 }
189
190 for (; S2; S2 = S2->getScope()) {
191 if (Scopes.count(S2))
192 return S2;
193 if (isa<DISubprogram>(S2))
194 break;
195 }
196
197 return nullptr;
198 };
199
200 auto Scope = GetNearestCommonScope(L1->getScope(), L2->getScope());
201 assert(Scope && "No common scope in the same subprogram?");
202
203 bool SameLine = L1->getLine() == L2->getLine();
204 bool SameCol = L1->getColumn() == L2->getColumn();
205 unsigned Line = SameLine ? L1->getLine() : 0;
206 unsigned Col = SameLine && SameCol ? L1->getColumn() : 0;
207
208 return DILocation::get(C, Line, Col, Scope, InlinedAt);
209 };
210
211 DILocation *Result = ARIt != ALocs.rend() ? (*ARIt)->getInlinedAt() : nullptr;
212
213 // If we have found a common starting location, walk up the inlined-at chains
214 // and try to produce common locations.
215 for (; ARIt != ALocs.rend() && BRIt != BLocs.rend(); ++ARIt, ++BRIt) {
216 DILocation *Tmp = MergeLocPair(*ARIt, *BRIt, Result);
217
218 if (!Tmp)
219 // We have walked up to a point in the chains where the two locations
220 // are irreconsilable. At this point Result contains the nearest common
221 // location in the inlined-at chains of LocA and LocB, so we break here.
222 break;
223
224 Result = Tmp;
225 }
226
227 if (Result)
228 return Result;
229
230 // We ended up with LocA and LocB as irreconsilable locations. Produce a
231 // location at 0:0 with one of the locations' scope. The function has
232 // historically picked A's scope, and a nullptr inlined-at location, so that
233 // behavior is mimicked here but I am not sure if this is always the correct
234 // way to handle this.
235 return DILocation::get(C, 0, 0, LocA->getScope(), nullptr);
236}
237
238std::optional<unsigned>
239DILocation::encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI) {
240 std::array<unsigned, 3> Components = {BD, DF, CI};
241 uint64_t RemainingWork = 0U;
242 // We use RemainingWork to figure out if we have no remaining components to
243 // encode. For example: if BD != 0 but DF == 0 && CI == 0, we don't need to
244 // encode anything for the latter 2.
245 // Since any of the input components is at most 32 bits, their sum will be
246 // less than 34 bits, and thus RemainingWork won't overflow.
247 RemainingWork =
248 std::accumulate(Components.begin(), Components.end(), RemainingWork);
249
250 int I = 0;
251 unsigned Ret = 0;
252 unsigned NextBitInsertionIndex = 0;
253 while (RemainingWork > 0) {
254 unsigned C = Components[I++];
255 RemainingWork -= C;
256 unsigned EC = encodeComponent(C);
257 Ret |= (EC << NextBitInsertionIndex);
258 NextBitInsertionIndex += encodingBits(C);
259 }
260
261 // Encoding may be unsuccessful because of overflow. We determine success by
262 // checking equivalence of components before & after encoding. Alternatively,
263 // we could determine Success during encoding, but the current alternative is
264 // simpler.
265 unsigned TBD, TDF, TCI = 0;
266 decodeDiscriminator(Ret, TBD, TDF, TCI);
267 if (TBD == BD && TDF == DF && TCI == CI)
268 return Ret;
269 return std::nullopt;
270}
271
272void DILocation::decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF,
273 unsigned &CI) {
278}
280
282 return StringSwitch<DIFlags>(Flag)
283#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
284#include "llvm/IR/DebugInfoFlags.def"
285 .Default(DINode::FlagZero);
286}
287
289 switch (Flag) {
290#define HANDLE_DI_FLAG(ID, NAME) \
291 case Flag##NAME: \
292 return "DIFlag" #NAME;
293#include "llvm/IR/DebugInfoFlags.def"
294 }
295 return "";
296}
297
299 SmallVectorImpl<DIFlags> &SplitFlags) {
300 // Flags that are packed together need to be specially handled, so
301 // that, for example, we emit "DIFlagPublic" and not
302 // "DIFlagPrivate | DIFlagProtected".
304 if (A == FlagPrivate)
305 SplitFlags.push_back(FlagPrivate);
306 else if (A == FlagProtected)
307 SplitFlags.push_back(FlagProtected);
308 else
309 SplitFlags.push_back(FlagPublic);
310 Flags &= ~A;
311 }
312 if (DIFlags R = Flags & FlagPtrToMemberRep) {
313 if (R == FlagSingleInheritance)
314 SplitFlags.push_back(FlagSingleInheritance);
315 else if (R == FlagMultipleInheritance)
316 SplitFlags.push_back(FlagMultipleInheritance);
317 else
318 SplitFlags.push_back(FlagVirtualInheritance);
319 Flags &= ~R;
320 }
321 if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) {
322 Flags &= ~FlagIndirectVirtualBase;
323 SplitFlags.push_back(FlagIndirectVirtualBase);
324 }
325
326#define HANDLE_DI_FLAG(ID, NAME) \
327 if (DIFlags Bit = Flags & Flag##NAME) { \
328 SplitFlags.push_back(Bit); \
329 Flags &= ~Bit; \
330 }
331#include "llvm/IR/DebugInfoFlags.def"
332 return Flags;
333}
334
336 if (auto *T = dyn_cast<DIType>(this))
337 return T->getScope();
338
339 if (auto *SP = dyn_cast<DISubprogram>(this))
340 return SP->getScope();
341
342 if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
343 return LB->getScope();
344
345 if (auto *NS = dyn_cast<DINamespace>(this))
346 return NS->getScope();
347
348 if (auto *CB = dyn_cast<DICommonBlock>(this))
349 return CB->getScope();
350
351 if (auto *M = dyn_cast<DIModule>(this))
352 return M->getScope();
353
354 assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&
355 "Unhandled type of scope.");
356 return nullptr;
357}
358
360 if (auto *T = dyn_cast<DIType>(this))
361 return T->getName();
362 if (auto *SP = dyn_cast<DISubprogram>(this))
363 return SP->getName();
364 if (auto *NS = dyn_cast<DINamespace>(this))
365 return NS->getName();
366 if (auto *CB = dyn_cast<DICommonBlock>(this))
367 return CB->getName();
368 if (auto *M = dyn_cast<DIModule>(this))
369 return M->getName();
370 assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||
371 isa<DICompileUnit>(this)) &&
372 "Unhandled type of scope.");
373 return "";
374}
375
376#ifndef NDEBUG
377static bool isCanonical(const MDString *S) {
378 return !S || !S->getString().empty();
379}
380#endif
381
383GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
384 MDString *Header,
385 ArrayRef<Metadata *> DwarfOps,
386 StorageType Storage, bool ShouldCreate) {
387 unsigned Hash = 0;
388 if (Storage == Uniqued) {
389 GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps);
390 if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
391 return N;
392 if (!ShouldCreate)
393 return nullptr;
394 Hash = Key.getHash();
395 } else {
396 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
397 }
398
399 // Use a nullptr for empty headers.
400 assert(isCanonical(Header) && "Expected canonical MDString");
401 Metadata *PreOps[] = {Header};
402 return storeImpl(new (DwarfOps.size() + 1, Storage) GenericDINode(
403 Context, Storage, Hash, Tag, PreOps, DwarfOps),
404 Storage, Context.pImpl->GenericDINodes);
405}
406
407void GenericDINode::recalculateHash() {
408 setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
409}
410
411#define UNWRAP_ARGS_IMPL(...) __VA_ARGS__
412#define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS
413#define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS) \
414 do { \
415 if (Storage == Uniqued) { \
416 if (auto *N = getUniqued(Context.pImpl->CLASS##s, \
417 CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS)))) \
418 return N; \
419 if (!ShouldCreate) \
420 return nullptr; \
421 } else { \
422 assert(ShouldCreate && \
423 "Expected non-uniqued nodes to always be created"); \
424 } \
425 } while (false)
426#define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS) \
427 return storeImpl(new (std::size(OPS), Storage) \
428 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
429 Storage, Context.pImpl->CLASS##s)
430#define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS) \
431 return storeImpl(new (0u, Storage) \
432 CLASS(Context, Storage, UNWRAP_ARGS(ARGS)), \
433 Storage, Context.pImpl->CLASS##s)
434#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS) \
435 return storeImpl(new (std::size(OPS), Storage) CLASS(Context, Storage, OPS), \
436 Storage, Context.pImpl->CLASS##s)
437#define DEFINE_GETIMPL_STORE_N(CLASS, ARGS, OPS, NUM_OPS) \
438 return storeImpl(new (NUM_OPS, Storage) \
439 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
440 Storage, Context.pImpl->CLASS##s)
441
442DISubrange::DISubrange(LLVMContext &C, StorageType Storage,
444 : DINode(C, DISubrangeKind, Storage, dwarf::DW_TAG_subrange_type, Ops) {}
445DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
446 StorageType Storage, bool ShouldCreate) {
449 auto *LB = ConstantAsMetadata::get(
451 return getImpl(Context, CountNode, LB, nullptr, nullptr, Storage,
452 ShouldCreate);
453}
454
455DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
456 int64_t Lo, StorageType Storage,
457 bool ShouldCreate) {
458 auto *LB = ConstantAsMetadata::get(
460 return getImpl(Context, CountNode, LB, nullptr, nullptr, Storage,
461 ShouldCreate);
462}
463
464DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
465 Metadata *LB, Metadata *UB, Metadata *Stride,
466 StorageType Storage, bool ShouldCreate) {
467 DEFINE_GETIMPL_LOOKUP(DISubrange, (CountNode, LB, UB, Stride));
468 Metadata *Ops[] = {CountNode, LB, UB, Stride};
470}
471
472DISubrange::BoundType DISubrange::getCount() const {
473 Metadata *CB = getRawCountNode();
474 if (!CB)
475 return BoundType();
476
477 assert((isa<ConstantAsMetadata>(CB) || isa<DIVariable>(CB) ||
478 isa<DIExpression>(CB)) &&
479 "Count must be signed constant or DIVariable or DIExpression");
480
481 if (auto *MD = dyn_cast<ConstantAsMetadata>(CB))
482 return BoundType(cast<ConstantInt>(MD->getValue()));
483
484 if (auto *MD = dyn_cast<DIVariable>(CB))
485 return BoundType(MD);
486
487 if (auto *MD = dyn_cast<DIExpression>(CB))
488 return BoundType(MD);
489
490 return BoundType();
491}
492
493DISubrange::BoundType DISubrange::getLowerBound() const {
494 Metadata *LB = getRawLowerBound();
495 if (!LB)
496 return BoundType();
497
498 assert((isa<ConstantAsMetadata>(LB) || isa<DIVariable>(LB) ||
499 isa<DIExpression>(LB)) &&
500 "LowerBound must be signed constant or DIVariable or DIExpression");
501
502 if (auto *MD = dyn_cast<ConstantAsMetadata>(LB))
503 return BoundType(cast<ConstantInt>(MD->getValue()));
504
505 if (auto *MD = dyn_cast<DIVariable>(LB))
506 return BoundType(MD);
507
508 if (auto *MD = dyn_cast<DIExpression>(LB))
509 return BoundType(MD);
510
511 return BoundType();
512}
513
514DISubrange::BoundType DISubrange::getUpperBound() const {
515 Metadata *UB = getRawUpperBound();
516 if (!UB)
517 return BoundType();
518
519 assert((isa<ConstantAsMetadata>(UB) || isa<DIVariable>(UB) ||
520 isa<DIExpression>(UB)) &&
521 "UpperBound must be signed constant or DIVariable or DIExpression");
522
523 if (auto *MD = dyn_cast<ConstantAsMetadata>(UB))
524 return BoundType(cast<ConstantInt>(MD->getValue()));
525
526 if (auto *MD = dyn_cast<DIVariable>(UB))
527 return BoundType(MD);
528
529 if (auto *MD = dyn_cast<DIExpression>(UB))
530 return BoundType(MD);
531
532 return BoundType();
533}
534
535DISubrange::BoundType DISubrange::getStride() const {
536 Metadata *ST = getRawStride();
537 if (!ST)
538 return BoundType();
539
540 assert((isa<ConstantAsMetadata>(ST) || isa<DIVariable>(ST) ||
541 isa<DIExpression>(ST)) &&
542 "Stride must be signed constant or DIVariable or DIExpression");
543
544 if (auto *MD = dyn_cast<ConstantAsMetadata>(ST))
545 return BoundType(cast<ConstantInt>(MD->getValue()));
546
547 if (auto *MD = dyn_cast<DIVariable>(ST))
548 return BoundType(MD);
549
550 if (auto *MD = dyn_cast<DIExpression>(ST))
551 return BoundType(MD);
552
553 return BoundType();
554}
555DIGenericSubrange::DIGenericSubrange(LLVMContext &C, StorageType Storage,
557 : DINode(C, DIGenericSubrangeKind, Storage, dwarf::DW_TAG_generic_subrange,
558 Ops) {}
559
560DIGenericSubrange *DIGenericSubrange::getImpl(LLVMContext &Context,
561 Metadata *CountNode, Metadata *LB,
562 Metadata *UB, Metadata *Stride,
563 StorageType Storage,
564 bool ShouldCreate) {
565 DEFINE_GETIMPL_LOOKUP(DIGenericSubrange, (CountNode, LB, UB, Stride));
566 Metadata *Ops[] = {CountNode, LB, UB, Stride};
568}
569
572 if (!CB)
573 return BoundType();
574
575 assert((isa<DIVariable>(CB) || isa<DIExpression>(CB)) &&
576 "Count must be signed constant or DIVariable or DIExpression");
577
578 if (auto *MD = dyn_cast<DIVariable>(CB))
579 return BoundType(MD);
580
581 if (auto *MD = dyn_cast<DIExpression>(CB))
582 return BoundType(MD);
583
584 return BoundType();
585}
586
589 if (!LB)
590 return BoundType();
591
592 assert((isa<DIVariable>(LB) || isa<DIExpression>(LB)) &&
593 "LowerBound must be signed constant or DIVariable or DIExpression");
594
595 if (auto *MD = dyn_cast<DIVariable>(LB))
596 return BoundType(MD);
597
598 if (auto *MD = dyn_cast<DIExpression>(LB))
599 return BoundType(MD);
600
601 return BoundType();
602}
603
606 if (!UB)
607 return BoundType();
608
609 assert((isa<DIVariable>(UB) || isa<DIExpression>(UB)) &&
610 "UpperBound must be signed constant or DIVariable or DIExpression");
611
612 if (auto *MD = dyn_cast<DIVariable>(UB))
613 return BoundType(MD);
614
615 if (auto *MD = dyn_cast<DIExpression>(UB))
616 return BoundType(MD);
617
618 return BoundType();
619}
620
622 Metadata *ST = getRawStride();
623 if (!ST)
624 return BoundType();
625
626 assert((isa<DIVariable>(ST) || isa<DIExpression>(ST)) &&
627 "Stride must be signed constant or DIVariable or DIExpression");
628
629 if (auto *MD = dyn_cast<DIVariable>(ST))
630 return BoundType(MD);
631
632 if (auto *MD = dyn_cast<DIExpression>(ST))
633 return BoundType(MD);
634
635 return BoundType();
636}
637
638DIEnumerator::DIEnumerator(LLVMContext &C, StorageType Storage,
639 const APInt &Value, bool IsUnsigned,
641 : DINode(C, DIEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
642 Value(Value) {
643 SubclassData32 = IsUnsigned;
644}
645DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, const APInt &Value,
646 bool IsUnsigned, MDString *Name,
647 StorageType Storage, bool ShouldCreate) {
648 assert(isCanonical(Name) && "Expected canonical MDString");
650 Metadata *Ops[] = {Name};
652}
653
654DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
655 MDString *Name, uint64_t SizeInBits,
656 uint32_t AlignInBits, unsigned Encoding,
657 DIFlags Flags, StorageType Storage,
658 bool ShouldCreate) {
659 assert(isCanonical(Name) && "Expected canonical MDString");
661 (Tag, Name, SizeInBits, AlignInBits, Encoding, Flags));
662 Metadata *Ops[] = {nullptr, nullptr, Name};
664 (Tag, SizeInBits, AlignInBits, Encoding, Flags), Ops);
665}
666
667std::optional<DIBasicType::Signedness> DIBasicType::getSignedness() const {
668 switch (getEncoding()) {
669 case dwarf::DW_ATE_signed:
670 case dwarf::DW_ATE_signed_char:
671 return Signedness::Signed;
672 case dwarf::DW_ATE_unsigned:
673 case dwarf::DW_ATE_unsigned_char:
675 default:
676 return std::nullopt;
677 }
678}
679
680DIStringType *DIStringType::getImpl(LLVMContext &Context, unsigned Tag,
681 MDString *Name, Metadata *StringLength,
682 Metadata *StringLengthExp,
683 Metadata *StringLocationExp,
684 uint64_t SizeInBits, uint32_t AlignInBits,
685 unsigned Encoding, StorageType Storage,
686 bool ShouldCreate) {
687 assert(isCanonical(Name) && "Expected canonical MDString");
691 Metadata *Ops[] = {nullptr, nullptr, Name,
694 Ops);
695}
696DIType *DIDerivedType::getClassType() const {
697 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
698 return cast_or_null<DIType>(getExtraData());
699}
701 assert(getTag() == dwarf::DW_TAG_inheritance);
702 if (auto *CM = cast_or_null<ConstantAsMetadata>(getExtraData()))
703 if (auto *CI = dyn_cast_or_null<ConstantInt>(CM->getValue()))
704 return static_cast<uint32_t>(CI->getZExtValue());
705 return 0;
706}
708 assert(getTag() == dwarf::DW_TAG_member && isBitField());
709 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
710 return C->getValue();
711 return nullptr;
712}
713
715 assert(getTag() == dwarf::DW_TAG_member && isStaticMember());
716 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
717 return C->getValue();
718 return nullptr;
719}
721 assert(getTag() == dwarf::DW_TAG_member && !isStaticMember());
722 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
723 return C->getValue();
724 return nullptr;
725}
726
728DIDerivedType::getImpl(LLVMContext &Context, unsigned Tag, MDString *Name,
729 Metadata *File, unsigned Line, Metadata *Scope,
730 Metadata *BaseType, uint64_t SizeInBits,
731 uint32_t AlignInBits, uint64_t OffsetInBits,
732 std::optional<unsigned> DWARFAddressSpace, DIFlags Flags,
733 Metadata *ExtraData, Metadata *Annotations,
734 StorageType Storage, bool ShouldCreate) {
735 assert(isCanonical(Name) && "Expected canonical MDString");
738 AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
743 DWARFAddressSpace, Flags),
744 Ops);
745}
746
747DICompositeType *DICompositeType::getImpl(
748 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
749 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
750 uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
751 Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
752 Metadata *TemplateParams, MDString *Identifier, Metadata *Discriminator,
753 Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
754 Metadata *Rank, Metadata *Annotations, StorageType Storage,
755 bool ShouldCreate) {
756 assert(isCanonical(Name) && "Expected canonical MDString");
757
758 // Keep this in sync with buildODRType.
764 Rank, Annotations));
765 Metadata *Ops[] = {File, Scope, Name, BaseType,
771 (Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits, Flags),
772 Ops);
773}
774
776 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
777 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
778 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
779 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
780 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
781 Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
782 Metadata *Rank, Metadata *Annotations) {
783 assert(!Identifier.getString().empty() && "Expected valid identifier");
785 return nullptr;
786 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
787 if (!CT)
790 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
793
794 if (CT->getTag() != Tag)
795 return nullptr;
796
797 // Only mutate CT if it's a forward declaration and the new operands aren't.
798 assert(CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?");
799 if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl))
800 return CT;
801
802 // Mutate CT in place. Keep this in sync with getImpl.
803 CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
804 Flags);
805 Metadata *Ops[] = {File, Scope, Name, BaseType,
809 assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&
810 "Mismatched number of operands");
811 for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I)
812 if (Ops[I] != CT->getOperand(I))
813 CT->setOperand(I, Ops[I]);
814 return CT;
815}
816
817DICompositeType *DICompositeType::getODRType(
818 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
819 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
820 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
821 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
822 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
823 Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
824 Metadata *Rank, Metadata *Annotations) {
825 assert(!Identifier.getString().empty() && "Expected valid identifier");
827 return nullptr;
828 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
829 if (!CT) {
831 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
835 } else {
836 if (CT->getTag() != Tag)
837 return nullptr;
838 }
839 return CT;
840}
841
843 MDString &Identifier) {
844 assert(!Identifier.getString().empty() && "Expected valid identifier");
846 return nullptr;
847 return Context.pImpl->DITypeMap->lookup(&Identifier);
848}
849DISubroutineType::DISubroutineType(LLVMContext &C, StorageType Storage,
850 DIFlags Flags, uint8_t CC,
852 : DIType(C, DISubroutineTypeKind, Storage, dwarf::DW_TAG_subroutine_type, 0,
853 0, 0, 0, Flags, Ops),
854 CC(CC) {}
855
856DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags,
857 uint8_t CC, Metadata *TypeArray,
858 StorageType Storage,
859 bool ShouldCreate) {
861 Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
863}
864
865DIFile::DIFile(LLVMContext &C, StorageType Storage,
866 std::optional<ChecksumInfo<MDString *>> CS, MDString *Src,
868 : DIScope(C, DIFileKind, Storage, dwarf::DW_TAG_file_type, Ops),
869 Checksum(CS), Source(Src) {}
870
871// FIXME: Implement this string-enum correspondence with a .def file and macros,
872// so that the association is explicit rather than implied.
873static const char *ChecksumKindName[DIFile::CSK_Last] = {
874 "CSK_MD5",
875 "CSK_SHA1",
876 "CSK_SHA256",
877};
878
879StringRef DIFile::getChecksumKindAsString(ChecksumKind CSKind) {
880 assert(CSKind <= DIFile::CSK_Last && "Invalid checksum kind");
881 // The first space was originally the CSK_None variant, which is now
882 // obsolete, but the space is still reserved in ChecksumKind, so we account
883 // for it here.
884 return ChecksumKindName[CSKind - 1];
885}
886
887std::optional<DIFile::ChecksumKind>
890 .Case("CSK_MD5", DIFile::CSK_MD5)
891 .Case("CSK_SHA1", DIFile::CSK_SHA1)
892 .Case("CSK_SHA256", DIFile::CSK_SHA256)
893 .Default(std::nullopt);
894}
895
896DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
897 MDString *Directory,
898 std::optional<DIFile::ChecksumInfo<MDString *>> CS,
899 MDString *Source, StorageType Storage,
900 bool ShouldCreate) {
901 assert(isCanonical(Filename) && "Expected canonical MDString");
902 assert(isCanonical(Directory) && "Expected canonical MDString");
903 assert((!CS || isCanonical(CS->Value)) && "Expected canonical MDString");
904 // We do *NOT* expect Source to be a canonical MDString because nullptr
905 // means none, so we need something to represent the empty file.
907 Metadata *Ops[] = {Filename, Directory, CS ? CS->Value : nullptr, Source};
908 DEFINE_GETIMPL_STORE(DIFile, (CS, Source), Ops);
909}
910DICompileUnit::DICompileUnit(LLVMContext &C, StorageType Storage,
911 unsigned SourceLanguage, bool IsOptimized,
912 unsigned RuntimeVersion, unsigned EmissionKind,
913 uint64_t DWOId, bool SplitDebugInlining,
914 bool DebugInfoForProfiling, unsigned NameTableKind,
915 bool RangesBaseAddress, ArrayRef<Metadata *> Ops)
916 : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
917 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
918 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind), DWOId(DWOId),
919 SplitDebugInlining(SplitDebugInlining),
920 DebugInfoForProfiling(DebugInfoForProfiling),
921 NameTableKind(NameTableKind), RangesBaseAddress(RangesBaseAddress) {
923}
924
925DICompileUnit *DICompileUnit::getImpl(
926 LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
927 MDString *Producer, bool IsOptimized, MDString *Flags,
928 unsigned RuntimeVersion, MDString *SplitDebugFilename,
929 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
930 Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
931 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
932 unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
933 MDString *SDK, StorageType Storage, bool ShouldCreate) {
934 assert(Storage != Uniqued && "Cannot unique DICompileUnit");
935 assert(isCanonical(Producer) && "Expected canonical MDString");
936 assert(isCanonical(Flags) && "Expected canonical MDString");
937 assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
938
939 Metadata *Ops[] = {File,
940 Producer,
941 Flags,
943 EnumTypes,
947 Macros,
948 SysRoot,
949 SDK};
950 return storeImpl(new (std::size(Ops), Storage) DICompileUnit(
951 Context, Storage, SourceLanguage, IsOptimized,
952 RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
953 DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
954 Ops),
955 Storage);
956}
957
958std::optional<DICompileUnit::DebugEmissionKind>
961 .Case("NoDebug", NoDebug)
962 .Case("FullDebug", FullDebug)
963 .Case("LineTablesOnly", LineTablesOnly)
964 .Case("DebugDirectivesOnly", DebugDirectivesOnly)
965 .Default(std::nullopt);
966}
967
968std::optional<DICompileUnit::DebugNameTableKind>
971 .Case("Default", DebugNameTableKind::Default)
974 .Default(std::nullopt);
975}
976
978 switch (EK) {
979 case NoDebug:
980 return "NoDebug";
981 case FullDebug:
982 return "FullDebug";
983 case LineTablesOnly:
984 return "LineTablesOnly";
986 return "DebugDirectivesOnly";
987 }
988 return nullptr;
989}
990
992 switch (NTK) {
994 return nullptr;
996 return "GNU";
998 return "None";
999 }
1000 return nullptr;
1001}
1002DISubprogram::DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1003 unsigned ScopeLine, unsigned VirtualIndex,
1004 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags,
1006 : DILocalScope(C, DISubprogramKind, Storage, dwarf::DW_TAG_subprogram, Ops),
1007 Line(Line), ScopeLine(ScopeLine), VirtualIndex(VirtualIndex),
1008 ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags) {
1009 static_assert(dwarf::DW_VIRTUALITY_max < 4, "Virtuality out of range");
1010}
1012DISubprogram::toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized,
1013 unsigned Virtuality, bool IsMainSubprogram) {
1014 // We're assuming virtuality is the low-order field.
1015 static_assert(int(SPFlagVirtual) == int(dwarf::DW_VIRTUALITY_virtual) &&
1016 int(SPFlagPureVirtual) ==
1017 int(dwarf::DW_VIRTUALITY_pure_virtual),
1018 "Virtuality constant mismatch");
1019 return static_cast<DISPFlags>(
1020 (Virtuality & SPFlagVirtuality) |
1021 (IsLocalToUnit ? SPFlagLocalToUnit : SPFlagZero) |
1022 (IsDefinition ? SPFlagDefinition : SPFlagZero) |
1023 (IsOptimized ? SPFlagOptimized : SPFlagZero) |
1024 (IsMainSubprogram ? SPFlagMainSubprogram : SPFlagZero));
1025}
1026
1028 if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
1029 return Block->getScope()->getSubprogram();
1030 return const_cast<DISubprogram *>(cast<DISubprogram>(this));
1031}
1032
1034 if (auto *File = dyn_cast<DILexicalBlockFile>(this))
1035 return File->getScope()->getNonLexicalBlockFileScope();
1036 return const_cast<DILocalScope *>(this);
1037}
1038
1040 DILocalScope &RootScope, DISubprogram &NewSP, LLVMContext &Ctx,
1042 SmallVector<DIScope *> ScopeChain;
1043 DIScope *CachedResult = nullptr;
1044
1045 for (DIScope *Scope = &RootScope; !isa<DISubprogram>(Scope);
1046 Scope = Scope->getScope()) {
1047 if (auto It = Cache.find(Scope); It != Cache.end()) {
1048 CachedResult = cast<DIScope>(It->second);
1049 break;
1050 }
1051 ScopeChain.push_back(Scope);
1052 }
1053
1054 // Recreate the scope chain, bottom-up, starting at the new subprogram (or a
1055 // cached result).
1056 DIScope *UpdatedScope = CachedResult ? CachedResult : &NewSP;
1057 for (DIScope *ScopeToUpdate : reverse(ScopeChain)) {
1058 TempMDNode ClonedScope = ScopeToUpdate->clone();
1059 cast<DILexicalBlockBase>(*ClonedScope).replaceScope(UpdatedScope);
1060 UpdatedScope =
1061 cast<DIScope>(MDNode::replaceWithUniqued(std::move(ClonedScope)));
1062 Cache[ScopeToUpdate] = UpdatedScope;
1063 }
1064
1065 return cast<DILocalScope>(UpdatedScope);
1066}
1067
1069 return StringSwitch<DISPFlags>(Flag)
1070#define HANDLE_DISP_FLAG(ID, NAME) .Case("DISPFlag" #NAME, SPFlag##NAME)
1071#include "llvm/IR/DebugInfoFlags.def"
1072 .Default(SPFlagZero);
1073}
1074
1076 switch (Flag) {
1077 // Appease a warning.
1078 case SPFlagVirtuality:
1079 return "";
1080#define HANDLE_DISP_FLAG(ID, NAME) \
1081 case SPFlag##NAME: \
1082 return "DISPFlag" #NAME;
1083#include "llvm/IR/DebugInfoFlags.def"
1084 }
1085 return "";
1086}
1087
1090 SmallVectorImpl<DISPFlags> &SplitFlags) {
1091 // Multi-bit fields can require special handling. In our case, however, the
1092 // only multi-bit field is virtuality, and all its values happen to be
1093 // single-bit values, so the right behavior just falls out.
1094#define HANDLE_DISP_FLAG(ID, NAME) \
1095 if (DISPFlags Bit = Flags & SPFlag##NAME) { \
1096 SplitFlags.push_back(Bit); \
1097 Flags &= ~Bit; \
1098 }
1099#include "llvm/IR/DebugInfoFlags.def"
1100 return Flags;
1101}
1102
1103DISubprogram *DISubprogram::getImpl(
1104 LLVMContext &Context, Metadata *Scope, MDString *Name,
1105 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1106 unsigned ScopeLine, Metadata *ContainingType, unsigned VirtualIndex,
1107 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
1108 Metadata *TemplateParams, Metadata *Declaration, Metadata *RetainedNodes,
1109 Metadata *ThrownTypes, Metadata *Annotations, MDString *TargetFuncName,
1110 StorageType Storage, bool ShouldCreate) {
1111 assert(isCanonical(Name) && "Expected canonical MDString");
1112 assert(isCanonical(LinkageName) && "Expected canonical MDString");
1113 assert(isCanonical(TargetFuncName) && "Expected canonical MDString");
1115 (Scope, Name, LinkageName, File, Line, Type, ScopeLine,
1116 ContainingType, VirtualIndex, ThisAdjustment, Flags,
1117 SPFlags, Unit, TemplateParams, Declaration,
1125 if (!TargetFuncName) {
1126 Ops.pop_back();
1127 if (!Annotations) {
1128 Ops.pop_back();
1129 if (!ThrownTypes) {
1130 Ops.pop_back();
1131 if (!TemplateParams) {
1132 Ops.pop_back();
1133 if (!ContainingType)
1134 Ops.pop_back();
1135 }
1136 }
1137 }
1138 }
1141 (Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags, SPFlags), Ops,
1142 Ops.size());
1143}
1144
1145bool DISubprogram::describes(const Function *F) const {
1146 assert(F && "Invalid function");
1147 return F->getSubprogram() == this;
1148}
1150 StorageType Storage,
1152 : DILocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1153
1154DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
1155 Metadata *File, unsigned Line,
1156 unsigned Column, StorageType Storage,
1157 bool ShouldCreate) {
1158 // Fixup column.
1159 adjustColumn(Column);
1160
1161 assert(Scope && "Expected scope");
1163 Metadata *Ops[] = {File, Scope};
1164 DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops);
1165}
1166
1167DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
1168 Metadata *Scope, Metadata *File,
1169 unsigned Discriminator,
1170 StorageType Storage,
1171 bool ShouldCreate) {
1172 assert(Scope && "Expected scope");
1174 Metadata *Ops[] = {File, Scope};
1175 DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops);
1176}
1177
1178DINamespace::DINamespace(LLVMContext &Context, StorageType Storage,
1179 bool ExportSymbols, ArrayRef<Metadata *> Ops)
1180 : DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace, Ops),
1181 ExportSymbols(ExportSymbols) {}
1182DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
1183 MDString *Name, bool ExportSymbols,
1184 StorageType Storage, bool ShouldCreate) {
1185 assert(isCanonical(Name) && "Expected canonical MDString");
1186 DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, Name, ExportSymbols));
1187 // The nullptr is for DIScope's File operand. This should be refactored.
1188 Metadata *Ops[] = {nullptr, Scope, Name};
1189 DEFINE_GETIMPL_STORE(DINamespace, (ExportSymbols), Ops);
1190}
1191
1192DICommonBlock::DICommonBlock(LLVMContext &Context, StorageType Storage,
1193 unsigned LineNo, ArrayRef<Metadata *> Ops)
1194 : DIScope(Context, DICommonBlockKind, Storage, dwarf::DW_TAG_common_block,
1195 Ops),
1196 LineNo(LineNo) {}
1197DICommonBlock *DICommonBlock::getImpl(LLVMContext &Context, Metadata *Scope,
1198 Metadata *Decl, MDString *Name,
1199 Metadata *File, unsigned LineNo,
1200 StorageType Storage, bool ShouldCreate) {
1201 assert(isCanonical(Name) && "Expected canonical MDString");
1203 // The nullptr is for DIScope's File operand. This should be refactored.
1204 Metadata *Ops[] = {Scope, Decl, Name, File};
1205 DEFINE_GETIMPL_STORE(DICommonBlock, (LineNo), Ops);
1206}
1207
1208DIModule::DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo,
1209 bool IsDecl, ArrayRef<Metadata *> Ops)
1210 : DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops),
1211 LineNo(LineNo), IsDecl(IsDecl) {}
1212DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *File,
1213 Metadata *Scope, MDString *Name,
1214 MDString *ConfigurationMacros,
1215 MDString *IncludePath, MDString *APINotesFile,
1216 unsigned LineNo, bool IsDecl, StorageType Storage,
1217 bool ShouldCreate) {
1218 assert(isCanonical(Name) && "Expected canonical MDString");
1220 IncludePath, APINotesFile, LineNo, IsDecl));
1223 DEFINE_GETIMPL_STORE(DIModule, (LineNo, IsDecl), Ops);
1224}
1225DITemplateTypeParameter::DITemplateTypeParameter(LLVMContext &Context,
1226 StorageType Storage,
1227 bool IsDefault,
1229 : DITemplateParameter(Context, DITemplateTypeParameterKind, Storage,
1230 dwarf::DW_TAG_template_type_parameter, IsDefault,
1231 Ops) {}
1232
1234DITemplateTypeParameter::getImpl(LLVMContext &Context, MDString *Name,
1235 Metadata *Type, bool isDefault,
1236 StorageType Storage, bool ShouldCreate) {
1237 assert(isCanonical(Name) && "Expected canonical MDString");
1239 Metadata *Ops[] = {Name, Type};
1241}
1242
1243DITemplateValueParameter *DITemplateValueParameter::getImpl(
1244 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
1245 bool isDefault, Metadata *Value, StorageType Storage, bool ShouldCreate) {
1246 assert(isCanonical(Name) && "Expected canonical MDString");
1248 (Tag, Name, Type, isDefault, Value));
1249 Metadata *Ops[] = {Name, Type, Value};
1251}
1252
1254DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1255 MDString *LinkageName, Metadata *File, unsigned Line,
1256 Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1257 Metadata *StaticDataMemberDeclaration,
1258 Metadata *TemplateParams, uint32_t AlignInBits,
1259 Metadata *Annotations, StorageType Storage,
1260 bool ShouldCreate) {
1261 assert(isCanonical(Name) && "Expected canonical MDString");
1262 assert(isCanonical(LinkageName) && "Expected canonical MDString");
1265 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1267 Metadata *Ops[] = {Scope,
1268 Name,
1269 File,
1270 Type,
1271 Name,
1275 Annotations};
1277 (Line, IsLocalToUnit, IsDefinition, AlignInBits), Ops);
1278}
1279
1281DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1282 Metadata *File, unsigned Line, Metadata *Type,
1283 unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
1284 Metadata *Annotations, StorageType Storage,
1285 bool ShouldCreate) {
1286 // 64K ought to be enough for any frontend.
1287 assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");
1288
1289 assert(Scope && "Expected scope");
1290 assert(isCanonical(Name) && "Expected canonical MDString");
1292 Flags, AlignInBits, Annotations));
1293 Metadata *Ops[] = {Scope, Name, File, Type, Annotations};
1295}
1296
1298 signed Line, ArrayRef<Metadata *> Ops,
1299 uint32_t AlignInBits)
1300 : DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line),
1301 AlignInBits(AlignInBits) {}
1302std::optional<uint64_t> DIVariable::getSizeInBits() const {
1303 // This is used by the Verifier so be mindful of broken types.
1304 const Metadata *RawType = getRawType();
1305 while (RawType) {
1306 // Try to get the size directly.
1307 if (auto *T = dyn_cast<DIType>(RawType))
1308 if (uint64_t Size = T->getSizeInBits())
1309 return Size;
1310
1311 if (auto *DT = dyn_cast<DIDerivedType>(RawType)) {
1312 // Look at the base type.
1313 RawType = DT->getRawBaseType();
1314 continue;
1315 }
1316
1317 // Missing type or size.
1318 break;
1319 }
1320
1321 // Fail gracefully.
1322 return std::nullopt;
1323}
1324
1325DILabel::DILabel(LLVMContext &C, StorageType Storage, unsigned Line,
1327 : DINode(C, DILabelKind, Storage, dwarf::DW_TAG_label, Ops), Line(Line) {}
1328DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1329 Metadata *File, unsigned Line, StorageType Storage,
1330 bool ShouldCreate) {
1331 assert(Scope && "Expected scope");
1332 assert(isCanonical(Name) && "Expected canonical MDString");
1334 Metadata *Ops[] = {Scope, Name, File};
1335 DEFINE_GETIMPL_STORE(DILabel, (Line), Ops);
1336}
1337
1338DIExpression *DIExpression::getImpl(LLVMContext &Context,
1339 ArrayRef<uint64_t> Elements,
1340 StorageType Storage, bool ShouldCreate) {
1343}
1346}
1348 return getNumElements() > 0 && getElement(0) == dwarf::DW_OP_deref;
1349}
1351 return getNumElements() == 1 && startsWithDeref();
1352}
1353
1354DIAssignID *DIAssignID::getImpl(LLVMContext &Context, StorageType Storage,
1355 bool ShouldCreate) {
1356 // Uniqued DIAssignID are not supported as the instance address *is* the ID.
1357 assert(Storage != StorageType::Uniqued && "uniqued DIAssignID unsupported");
1358 return storeImpl(new (0u, Storage) DIAssignID(Context, Storage), Storage);
1359}
1360
1362 uint64_t Op = getOp();
1363
1364 if (Op >= dwarf::DW_OP_breg0 && Op <= dwarf::DW_OP_breg31)
1365 return 2;
1366
1367 switch (Op) {
1370 case dwarf::DW_OP_bregx:
1371 return 3;
1372 case dwarf::DW_OP_constu:
1373 case dwarf::DW_OP_consts:
1374 case dwarf::DW_OP_deref_size:
1375 case dwarf::DW_OP_plus_uconst:
1379 case dwarf::DW_OP_regx:
1380 return 2;
1381 default:
1382 return 1;
1383 }
1384}
1385
1387 for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
1388 // Check that there's space for the operand.
1389 if (I->get() + I->getSize() > E->get())
1390 return false;
1391
1392 uint64_t Op = I->getOp();
1393 if ((Op >= dwarf::DW_OP_reg0 && Op <= dwarf::DW_OP_reg31) ||
1394 (Op >= dwarf::DW_OP_breg0 && Op <= dwarf::DW_OP_breg31))
1395 return true;
1396
1397 // Check that the operand is valid.
1398 switch (Op) {
1399 default:
1400 return false;
1402 // A fragment operator must appear at the end.
1403 return I->get() + I->getSize() == E->get();
1404 case dwarf::DW_OP_stack_value: {
1405 // Must be the last one or followed by a DW_OP_LLVM_fragment.
1406 if (I->get() + I->getSize() == E->get())
1407 break;
1408 auto J = I;
1409 if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment)
1410 return false;
1411 break;
1412 }
1413 case dwarf::DW_OP_swap: {
1414 // Must be more than one implicit element on the stack.
1415
1416 // FIXME: A better way to implement this would be to add a local variable
1417 // that keeps track of the stack depth and introduce something like a
1418 // DW_LLVM_OP_implicit_location as a placeholder for the location this
1419 // DIExpression is attached to, or else pass the number of implicit stack
1420 // elements into isValid.
1421 if (getNumElements() == 1)
1422 return false;
1423 break;
1424 }
1426 // An entry value operator must appear at the beginning or immediately
1427 // following `DW_OP_LLVM_arg 0`, and the number of operations it cover can
1428 // currently only be 1, because we support only entry values of a simple
1429 // register location. One reason for this is that we currently can't
1430 // calculate the size of the resulting DWARF block for other expressions.
1431 auto FirstOp = expr_op_begin();
1432 if (FirstOp->getOp() == dwarf::DW_OP_LLVM_arg && FirstOp->getArg(0) == 0)
1433 ++FirstOp;
1434 return I->get() == FirstOp->get() && I->getArg(0) == 1;
1435 }
1440 case dwarf::DW_OP_constu:
1441 case dwarf::DW_OP_plus_uconst:
1442 case dwarf::DW_OP_plus:
1443 case dwarf::DW_OP_minus:
1444 case dwarf::DW_OP_mul:
1445 case dwarf::DW_OP_div:
1446 case dwarf::DW_OP_mod:
1447 case dwarf::DW_OP_or:
1448 case dwarf::DW_OP_and:
1449 case dwarf::DW_OP_xor:
1450 case dwarf::DW_OP_shl:
1451 case dwarf::DW_OP_shr:
1452 case dwarf::DW_OP_shra:
1453 case dwarf::DW_OP_deref:
1454 case dwarf::DW_OP_deref_size:
1455 case dwarf::DW_OP_xderef:
1456 case dwarf::DW_OP_lit0:
1457 case dwarf::DW_OP_not:
1458 case dwarf::DW_OP_dup:
1459 case dwarf::DW_OP_regx:
1460 case dwarf::DW_OP_bregx:
1461 case dwarf::DW_OP_push_object_address:
1462 case dwarf::DW_OP_over:
1463 case dwarf::DW_OP_consts:
1464 case dwarf::DW_OP_eq:
1465 case dwarf::DW_OP_ne:
1466 case dwarf::DW_OP_gt:
1467 case dwarf::DW_OP_ge:
1468 case dwarf::DW_OP_lt:
1469 case dwarf::DW_OP_le:
1470 break;
1471 }
1472 }
1473 return true;
1474}
1475
1477 if (!isValid())
1478 return false;
1479
1480 if (getNumElements() == 0)
1481 return false;
1482
1483 for (const auto &It : expr_ops()) {
1484 switch (It.getOp()) {
1485 default:
1486 break;
1487 case dwarf::DW_OP_stack_value:
1489 return true;
1490 }
1491 }
1492
1493 return false;
1494}
1495
1497 if (!isValid())
1498 return false;
1499
1500 if (getNumElements() == 0)
1501 return false;
1502
1503 // If there are any elements other than fragment or tag_offset, then some
1504 // kind of complex computation occurs.
1505 for (const auto &It : expr_ops()) {
1506 switch (It.getOp()) {
1510 continue;
1511 default:
1512 return true;
1513 }
1514 }
1515
1516 return false;
1517}
1518
1520 if (!isValid())
1521 return false;
1522
1523 if (getNumElements() == 0)
1524 return true;
1525
1526 auto ExprOpBegin = expr_ops().begin();
1527 auto ExprOpEnd = expr_ops().end();
1528 if (ExprOpBegin->getOp() == dwarf::DW_OP_LLVM_arg)
1529 ++ExprOpBegin;
1530
1531 return !std::any_of(ExprOpBegin, ExprOpEnd, [](auto Op) {
1532 return Op.getOp() == dwarf::DW_OP_LLVM_arg;
1533 });
1534}
1535
1536const DIExpression *
1538 SmallVector<uint64_t, 3> UndefOps;
1539 if (auto FragmentInfo = Expr->getFragmentInfo()) {
1542 }
1543 return DIExpression::get(Expr->getContext(), UndefOps);
1544}
1545
1546const DIExpression *
1548 if (any_of(Expr->expr_ops(), [](auto ExprOp) {
1549 return ExprOp.getOp() == dwarf::DW_OP_LLVM_arg;
1550 }))
1551 return Expr;
1552 SmallVector<uint64_t> NewOps;
1553 NewOps.reserve(Expr->getNumElements() + 2);
1554 NewOps.append({dwarf::DW_OP_LLVM_arg, 0});
1555 NewOps.append(Expr->elements_begin(), Expr->elements_end());
1556 return DIExpression::get(Expr->getContext(), NewOps);
1557}
1558
1559std::optional<const DIExpression *>
1561 // Check for `isValid` covered by `isSingleLocationExpression`.
1562 if (!Expr->isSingleLocationExpression())
1563 return std::nullopt;
1564
1565 // An empty expression is already non-variadic.
1566 if (!Expr->getNumElements())
1567 return Expr;
1568
1569 auto ElementsBegin = Expr->elements_begin();
1570 // If Expr does not have a leading DW_OP_LLVM_arg then we don't need to do
1571 // anything.
1572 if (*ElementsBegin != dwarf::DW_OP_LLVM_arg)
1573 return Expr;
1574
1575 SmallVector<uint64_t> NonVariadicOps(
1576 make_range(ElementsBegin + 2, Expr->elements_end()));
1577 return DIExpression::get(Expr->getContext(), NonVariadicOps);
1578}
1579
1581 const DIExpression *Expr,
1582 bool IsIndirect) {
1583 // If Expr is not already variadic, insert the implied `DW_OP_LLVM_arg 0`
1584 // to the existing expression ops.
1585 if (none_of(Expr->expr_ops(), [](auto ExprOp) {
1586 return ExprOp.getOp() == dwarf::DW_OP_LLVM_arg;
1587 }))
1588 Ops.append({dwarf::DW_OP_LLVM_arg, 0});
1589 // If Expr is not indirect, we only need to insert the expression elements and
1590 // we're done.
1591 if (!IsIndirect) {
1592 Ops.append(Expr->elements_begin(), Expr->elements_end());
1593 return;
1594 }
1595 // If Expr is indirect, insert the implied DW_OP_deref at the end of the
1596 // expression but before DW_OP_{stack_value, LLVM_fragment} if they are
1597 // present.
1598 for (auto Op : Expr->expr_ops()) {
1599 if (Op.getOp() == dwarf::DW_OP_stack_value ||
1600 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1601 Ops.push_back(dwarf::DW_OP_deref);
1602 IsIndirect = false;
1603 }
1604 Op.appendToVector(Ops);
1605 }
1606 if (IsIndirect)
1607 Ops.push_back(dwarf::DW_OP_deref);
1608}
1609
1611 bool FirstIndirect,
1612 const DIExpression *SecondExpr,
1613 bool SecondIndirect) {
1614 SmallVector<uint64_t> FirstOps;
1615 DIExpression::canonicalizeExpressionOps(FirstOps, FirstExpr, FirstIndirect);
1616 SmallVector<uint64_t> SecondOps;
1617 DIExpression::canonicalizeExpressionOps(SecondOps, SecondExpr,
1618 SecondIndirect);
1619 return FirstOps == SecondOps;
1620}
1621
1622std::optional<DIExpression::FragmentInfo>
1624 for (auto I = Start; I != End; ++I)
1625 if (I->getOp() == dwarf::DW_OP_LLVM_fragment) {
1626 DIExpression::FragmentInfo Info = {I->getArg(1), I->getArg(0)};
1627 return Info;
1628 }
1629 return std::nullopt;
1630}
1631
1633 int64_t Offset) {
1634 if (Offset > 0) {
1635 Ops.push_back(dwarf::DW_OP_plus_uconst);
1636 Ops.push_back(Offset);
1637 } else if (Offset < 0) {
1638 Ops.push_back(dwarf::DW_OP_constu);
1639 // Avoid UB when encountering LLONG_MIN, because in 2's complement
1640 // abs(LLONG_MIN) is LLONG_MAX+1.
1641 uint64_t AbsMinusOne = -(Offset+1);
1642 Ops.push_back(AbsMinusOne + 1);
1643 Ops.push_back(dwarf::DW_OP_minus);
1644 }
1645}
1646
1648 if (getNumElements() == 0) {
1649 Offset = 0;
1650 return true;
1651 }
1652
1653 if (getNumElements() == 2 && Elements[0] == dwarf::DW_OP_plus_uconst) {
1654 Offset = Elements[1];
1655 return true;
1656 }
1657
1658 if (getNumElements() == 3 && Elements[0] == dwarf::DW_OP_constu) {
1659 if (Elements[2] == dwarf::DW_OP_plus) {
1660 Offset = Elements[1];
1661 return true;
1662 }
1663 if (Elements[2] == dwarf::DW_OP_minus) {
1664 Offset = -Elements[1];
1665 return true;
1666 }
1667 }
1668
1669 return false;
1670}
1671
1674 for (auto ExprOp : expr_ops())
1675 if (ExprOp.getOp() == dwarf::DW_OP_LLVM_arg)
1676 SeenOps.insert(ExprOp.getArg(0));
1677 for (uint64_t Idx = 0; Idx < N; ++Idx)
1678 if (!SeenOps.contains(Idx))
1679 return false;
1680 return true;
1681}
1682
1684 unsigned &AddrClass) {
1685 // FIXME: This seems fragile. Nothing that verifies that these elements
1686 // actually map to ops and not operands.
1687 const unsigned PatternSize = 4;
1688 if (Expr->Elements.size() >= PatternSize &&
1689 Expr->Elements[PatternSize - 4] == dwarf::DW_OP_constu &&
1690 Expr->Elements[PatternSize - 2] == dwarf::DW_OP_swap &&
1691 Expr->Elements[PatternSize - 1] == dwarf::DW_OP_xderef) {
1692 AddrClass = Expr->Elements[PatternSize - 3];
1693
1694 if (Expr->Elements.size() == PatternSize)
1695 return nullptr;
1696 return DIExpression::get(Expr->getContext(),
1697 ArrayRef(&*Expr->Elements.begin(),
1698 Expr->Elements.size() - PatternSize));
1699 }
1700 return Expr;
1701}
1702
1704 int64_t Offset) {
1707 Ops.push_back(dwarf::DW_OP_deref);
1708
1709 appendOffset(Ops, Offset);
1711 Ops.push_back(dwarf::DW_OP_deref);
1712
1715
1716 return prependOpcodes(Expr, Ops, StackValue, EntryValue);
1717}
1718
1721 unsigned ArgNo, bool StackValue) {
1722 assert(Expr && "Can't add ops to this expression");
1723
1724 // Handle non-variadic intrinsics by prepending the opcodes.
1725 if (!any_of(Expr->expr_ops(),
1726 [](auto Op) { return Op.getOp() == dwarf::DW_OP_LLVM_arg; })) {
1727 assert(ArgNo == 0 &&
1728 "Location Index must be 0 for a non-variadic expression.");
1729 SmallVector<uint64_t, 8> NewOps(Ops.begin(), Ops.end());
1730 return DIExpression::prependOpcodes(Expr, NewOps, StackValue);
1731 }
1732
1734 for (auto Op : Expr->expr_ops()) {
1735 // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
1736 if (StackValue) {
1737 if (Op.getOp() == dwarf::DW_OP_stack_value)
1738 StackValue = false;
1739 else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1740 NewOps.push_back(dwarf::DW_OP_stack_value);
1741 StackValue = false;
1742 }
1743 }
1744 Op.appendToVector(NewOps);
1745 if (Op.getOp() == dwarf::DW_OP_LLVM_arg && Op.getArg(0) == ArgNo)
1746 NewOps.insert(NewOps.end(), Ops.begin(), Ops.end());
1747 }
1748 if (StackValue)
1749 NewOps.push_back(dwarf::DW_OP_stack_value);
1750
1751 return DIExpression::get(Expr->getContext(), NewOps);
1752}
1753
1755 uint64_t OldArg, uint64_t NewArg) {
1756 assert(Expr && "Can't replace args in this expression");
1757
1759
1760 for (auto Op : Expr->expr_ops()) {
1761 if (Op.getOp() != dwarf::DW_OP_LLVM_arg || Op.getArg(0) < OldArg) {
1762 Op.appendToVector(NewOps);
1763 continue;
1764 }
1766 uint64_t Arg = Op.getArg(0) == OldArg ? NewArg : Op.getArg(0);
1767 // OldArg has been deleted from the Op list, so decrement all indices
1768 // greater than it.
1769 if (Arg > OldArg)
1770 --Arg;
1771 NewOps.push_back(Arg);
1772 }
1773 return DIExpression::get(Expr->getContext(), NewOps);
1774}
1775
1778 bool StackValue, bool EntryValue) {
1779 assert(Expr && "Can't prepend ops to this expression");
1780
1781 if (EntryValue) {
1783 // Use a block size of 1 for the target register operand. The
1784 // DWARF backend currently cannot emit entry values with a block
1785 // size > 1.
1786 Ops.push_back(1);
1787 }
1788
1789 // If there are no ops to prepend, do not even add the DW_OP_stack_value.
1790 if (Ops.empty())
1791 StackValue = false;
1792 for (auto Op : Expr->expr_ops()) {
1793 // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
1794 if (StackValue) {
1795 if (Op.getOp() == dwarf::DW_OP_stack_value)
1796 StackValue = false;
1797 else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1798 Ops.push_back(dwarf::DW_OP_stack_value);
1799 StackValue = false;
1800 }
1801 }
1802 Op.appendToVector(Ops);
1803 }
1804 if (StackValue)
1805 Ops.push_back(dwarf::DW_OP_stack_value);
1806 return DIExpression::get(Expr->getContext(), Ops);
1807}
1808
1810 ArrayRef<uint64_t> Ops) {
1811 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
1812
1813 // Copy Expr's current op list.
1815 for (auto Op : Expr->expr_ops()) {
1816 // Append new opcodes before DW_OP_{stack_value, LLVM_fragment}.
1817 if (Op.getOp() == dwarf::DW_OP_stack_value ||
1818 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1819 NewOps.append(Ops.begin(), Ops.end());
1820
1821 // Ensure that the new opcodes are only appended once.
1822 Ops = std::nullopt;
1823 }
1824 Op.appendToVector(NewOps);
1825 }
1826
1827 NewOps.append(Ops.begin(), Ops.end());
1828 auto *result = DIExpression::get(Expr->getContext(), NewOps);
1829 assert(result->isValid() && "concatenated expression is not valid");
1830 return result;
1831}
1832
1834 ArrayRef<uint64_t> Ops) {
1835 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
1836 assert(none_of(Ops,
1837 [](uint64_t Op) {
1838 return Op == dwarf::DW_OP_stack_value ||
1840 }) &&
1841 "Can't append this op");
1842
1843 // Append a DW_OP_deref after Expr's current op list if it's non-empty and
1844 // has no DW_OP_stack_value.
1845 //
1846 // Match .* DW_OP_stack_value (DW_OP_LLVM_fragment A B)?.
1847 std::optional<FragmentInfo> FI = Expr->getFragmentInfo();
1848 unsigned DropUntilStackValue = FI ? 3 : 0;
1849 ArrayRef<uint64_t> ExprOpsBeforeFragment =
1850 Expr->getElements().drop_back(DropUntilStackValue);
1851 bool NeedsDeref = (Expr->getNumElements() > DropUntilStackValue) &&
1852 (ExprOpsBeforeFragment.back() != dwarf::DW_OP_stack_value);
1853 bool NeedsStackValue = NeedsDeref || ExprOpsBeforeFragment.empty();
1854
1855 // Append a DW_OP_deref after Expr's current op list if needed, then append
1856 // the new ops, and finally ensure that a single DW_OP_stack_value is present.
1858 if (NeedsDeref)
1859 NewOps.push_back(dwarf::DW_OP_deref);
1860 NewOps.append(Ops.begin(), Ops.end());
1861 if (NeedsStackValue)
1862 NewOps.push_back(dwarf::DW_OP_stack_value);
1863 return DIExpression::append(Expr, NewOps);
1864}
1865
1866std::optional<DIExpression *> DIExpression::createFragmentExpression(
1867 const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits) {
1869 // Track whether it's safe to split the value at the top of the DWARF stack,
1870 // assuming that it'll be used as an implicit location value.
1871 bool CanSplitValue = true;
1872 // Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment.
1873 if (Expr) {
1874 for (auto Op : Expr->expr_ops()) {
1875 switch (Op.getOp()) {
1876 default:
1877 break;
1878 case dwarf::DW_OP_shr:
1879 case dwarf::DW_OP_shra:
1880 case dwarf::DW_OP_shl:
1881 case dwarf::DW_OP_plus:
1882 case dwarf::DW_OP_plus_uconst:
1883 case dwarf::DW_OP_minus:
1884 // We can't safely split arithmetic or shift operations into multiple
1885 // fragments because we can't express carry-over between fragments.
1886 //
1887 // FIXME: We *could* preserve the lowest fragment of a constant offset
1888 // operation if the offset fits into SizeInBits.
1889 CanSplitValue = false;
1890 break;
1891 case dwarf::DW_OP_deref:
1892 case dwarf::DW_OP_deref_size:
1893 case dwarf::DW_OP_deref_type:
1894 case dwarf::DW_OP_xderef:
1895 case dwarf::DW_OP_xderef_size:
1896 case dwarf::DW_OP_xderef_type:
1897 // Preceeding arithmetic operations have been applied to compute an
1898 // address. It's okay to split the value loaded from that address.
1899 CanSplitValue = true;
1900 break;
1901 case dwarf::DW_OP_stack_value:
1902 // Bail if this expression computes a value that cannot be split.
1903 if (!CanSplitValue)
1904 return std::nullopt;
1905 break;
1907 // Make the new offset point into the existing fragment.
1908 uint64_t FragmentOffsetInBits = Op.getArg(0);
1909 uint64_t FragmentSizeInBits = Op.getArg(1);
1910 (void)FragmentSizeInBits;
1911 assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&
1912 "new fragment outside of original fragment");
1913 OffsetInBits += FragmentOffsetInBits;
1914 continue;
1915 }
1916 }
1917 Op.appendToVector(Ops);
1918 }
1919 }
1920 assert((!Expr->isImplicit() || CanSplitValue) && "Expr can't be split");
1921 assert(Expr && "Unknown DIExpression");
1923 Ops.push_back(OffsetInBits);
1924 Ops.push_back(SizeInBits);
1925 return DIExpression::get(Expr->getContext(), Ops);
1926}
1927
1928std::pair<DIExpression *, const ConstantInt *>
1930 // Copy the APInt so we can modify it.
1931 APInt NewInt = CI->getValue();
1933
1934 // Fold operators only at the beginning of the expression.
1935 bool First = true;
1936 bool Changed = false;
1937 for (auto Op : expr_ops()) {
1938 switch (Op.getOp()) {
1939 default:
1940 // We fold only the leading part of the expression; if we get to a part
1941 // that we're going to copy unchanged, and haven't done any folding,
1942 // then the entire expression is unchanged and we can return early.
1943 if (!Changed)
1944 return {this, CI};
1945 First = false;
1946 break;
1948 if (!First)
1949 break;
1950 Changed = true;
1951 if (Op.getArg(1) == dwarf::DW_ATE_signed)
1952 NewInt = NewInt.sextOrTrunc(Op.getArg(0));
1953 else {
1954 assert(Op.getArg(1) == dwarf::DW_ATE_unsigned && "Unexpected operand");
1955 NewInt = NewInt.zextOrTrunc(Op.getArg(0));
1956 }
1957 continue;
1958 }
1959 Op.appendToVector(Ops);
1960 }
1961 if (!Changed)
1962 return {this, CI};
1963 return {DIExpression::get(getContext(), Ops),
1964 ConstantInt::get(getContext(), NewInt)};
1965}
1966
1968 uint64_t Result = 0;
1969 for (auto ExprOp : expr_ops())
1970 if (ExprOp.getOp() == dwarf::DW_OP_LLVM_arg)
1971 Result = std::max(Result, ExprOp.getArg(0) + 1);
1972 assert(hasAllLocationOps(Result) &&
1973 "Expression is missing one or more location operands.");
1974 return Result;
1975}
1976
1977std::optional<DIExpression::SignedOrUnsignedConstant>
1979
1980 // Recognize signed and unsigned constants.
1981 // An signed constants can be represented as DW_OP_consts C DW_OP_stack_value
1982 // (DW_OP_LLVM_fragment of Len).
1983 // An unsigned constant can be represented as
1984 // DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment of Len).
1985
1986 if ((getNumElements() != 2 && getNumElements() != 3 &&
1987 getNumElements() != 6) ||
1988 (getElement(0) != dwarf::DW_OP_consts &&
1989 getElement(0) != dwarf::DW_OP_constu))
1990 return std::nullopt;
1991
1992 if (getNumElements() == 2 && getElement(0) == dwarf::DW_OP_consts)
1994
1995 if ((getNumElements() == 3 && getElement(2) != dwarf::DW_OP_stack_value) ||
1996 (getNumElements() == 6 && (getElement(2) != dwarf::DW_OP_stack_value ||
1998 return std::nullopt;
1999 return getElement(0) == dwarf::DW_OP_constu
2002}
2003
2004DIExpression::ExtOps DIExpression::getExtOps(unsigned FromSize, unsigned ToSize,
2005 bool Signed) {
2006 dwarf::TypeKind TK = Signed ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned;
2008 dwarf::DW_OP_LLVM_convert, ToSize, TK}};
2009 return Ops;
2010}
2011
2013 unsigned FromSize, unsigned ToSize,
2014 bool Signed) {
2015 return appendToStack(Expr, getExtOps(FromSize, ToSize, Signed));
2016}
2017
2019DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable,
2021 bool ShouldCreate) {
2023 Metadata *Ops[] = {Variable, Expression};
2025}
2026DIObjCProperty::DIObjCProperty(LLVMContext &C, StorageType Storage,
2027 unsigned Line, unsigned Attributes,
2029 : DINode(C, DIObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property, Ops),
2031
2032DIObjCProperty *DIObjCProperty::getImpl(
2033 LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
2034 MDString *GetterName, MDString *SetterName, unsigned Attributes,
2035 Metadata *Type, StorageType Storage, bool ShouldCreate) {
2036 assert(isCanonical(Name) && "Expected canonical MDString");
2037 assert(isCanonical(GetterName) && "Expected canonical MDString");
2038 assert(isCanonical(SetterName) && "Expected canonical MDString");
2040 SetterName, Attributes, Type));
2041 Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
2042 DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops);
2043}
2044
2045DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
2046 Metadata *Scope, Metadata *Entity,
2047 Metadata *File, unsigned Line,
2048 MDString *Name, Metadata *Elements,
2049 StorageType Storage,
2050 bool ShouldCreate) {
2051 assert(isCanonical(Name) && "Expected canonical MDString");
2053 (Tag, Scope, Entity, File, Line, Name, Elements));
2054 Metadata *Ops[] = {Scope, Entity, Name, File, Elements};
2056}
2057
2058DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
2059 MDString *Name, MDString *Value, StorageType Storage,
2060 bool ShouldCreate) {
2061 assert(isCanonical(Name) && "Expected canonical MDString");
2063 Metadata *Ops[] = {Name, Value};
2064 DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops);
2065}
2066
2067DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
2068 unsigned Line, Metadata *File,
2069 Metadata *Elements, StorageType Storage,
2070 bool ShouldCreate) {
2072 Metadata *Ops[] = {File, Elements};
2074}
2075
2076DIArgList *DIArgList::getImpl(LLVMContext &Context,
2078 StorageType Storage, bool ShouldCreate) {
2081}
2082
2084 ValueAsMetadata **OldVMPtr = static_cast<ValueAsMetadata **>(Ref);
2085 assert((!New || isa<ValueAsMetadata>(New)) &&
2086 "DIArgList must be passed a ValueAsMetadata");
2087 untrack();
2088 bool Uniq = isUniqued();
2089 if (Uniq) {
2090 // We need to update the uniqueness once the Args are updated since they
2091 // form the key to the DIArgLists store.
2092 eraseFromStore();
2093 }
2094 ValueAsMetadata *NewVM = cast_or_null<ValueAsMetadata>(New);
2095 for (ValueAsMetadata *&VM : Args) {
2096 if (&VM == OldVMPtr) {
2097 if (NewVM)
2098 VM = NewVM;
2099 else
2100 VM = ValueAsMetadata::get(PoisonValue::get(VM->getValue()->getType()));
2101 }
2102 }
2103 if (Uniq) {
2104 if (uniquify() != this)
2106 }
2107 track();
2108}
2109void DIArgList::track() {
2110 for (ValueAsMetadata *&VAM : Args)
2111 if (VAM)
2112 MetadataTracking::track(&VAM, *VAM, *this);
2113}
2114void DIArgList::untrack() {
2115 for (ValueAsMetadata *&VAM : Args)
2116 if (VAM)
2117 MetadataTracking::untrack(&VAM, *VAM);
2118}
2119void DIArgList::dropAllReferences() {
2120 untrack();
2121 Args.clear();
2123}
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
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:836
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:464
#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 defines the SmallSet class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
@ Flags
Definition: TextStubV5.cpp:93
Class for arbitrary precision integers.
Definition: APInt.h:75
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
Definition: APInt.cpp:994
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
Definition: APInt.cpp:1002
Annotations lets you mark points and ranges inside source code, for tests:
Definition: Annotations.h:53
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
const T & back() const
back - Get the last element.
Definition: ArrayRef.h:172
iterator end() const
Definition: ArrayRef.h:152
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:163
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
Definition: ArrayRef.h:208
iterator begin() const
Definition: ArrayRef.h:151
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:158
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:419
This is the shared class of boolean and integer constants.
Definition: Constants.h:78
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:888
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
Definition: Constants.h:114
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:136
This is an important base class in LLVM.
Definition: Constant.h:41
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
void handleChangedOperand(void *Ref, Metadata *New)
Assignment ID.
Basic type, like 'int' or 'float'.
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags
unsigned StringRef uint64_t SizeInBits
std::optional< Signedness > getSignedness() const
Return the signedness of this type, or std::nullopt if this type is neither signed nor unsigned.
unsigned getEncoding() const
unsigned StringRef Name
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t AlignInBits
Metadata Metadata * Decl
Metadata Metadata MDString * Name
Metadata Metadata MDString Metadata * File
static const char * nameTableKindString(DebugNameTableKind PK)
static const char * emissionKindString(DebugEmissionKind EK)
DebugEmissionKind getEmissionKind() const
unsigned Metadata * File
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata * Macros
unsigned Metadata MDString bool MDString * Flags
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata * EnumTypes
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata * RetainedTypes
DebugNameTableKind getNameTableKind() const
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata * GlobalVariables
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString MDString * SDK
unsigned Metadata MDString * Producer
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString * SysRoot
unsigned Metadata MDString bool MDString unsigned MDString * SplitDebugFilename
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata * ImportedEntities
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t AlignInBits
unsigned MDString Metadata unsigned Line
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata * Elements
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned Metadata Metadata * TemplateParams
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata * Rank
static DICompositeType * getODRTypeIfExists(LLVMContext &Context, MDString &Identifier)
unsigned MDString * Name
static DICompositeType * buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator, Metadata *DataLocation, Metadata *Associated, Metadata *Allocated, Metadata *Rank, Metadata *Annotations)
Build a DICompositeType with the given ODR identifier.
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t OffsetInBits
unsigned MDString Metadata unsigned Metadata * Scope
unsigned MDString Metadata * File
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned Metadata Metadata MDString Metadata Metadata Metadata Metadata * Allocated
unsigned MDString Metadata unsigned Metadata Metadata * BaseType
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Flags
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned Metadata Metadata MDString Metadata * Discriminator
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned Metadata Metadata MDString Metadata Metadata * DataLocation
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned Metadata Metadata MDString * Identifier
unsigned MDString Metadata unsigned Metadata Metadata uint64_t SizeInBits
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned Metadata Metadata MDString Metadata Metadata Metadata * Associated
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned Metadata * VTableHolder
unsigned StringRef DIFile unsigned DIScope DIType * BaseType
unsigned StringRef DIFile unsigned DIScope DIType uint64_t SizeInBits
unsigned StringRef DIFile * File
unsigned StringRef DIFile unsigned DIScope DIType uint64_t uint32_t uint64_t std::optional< unsigned > DIFlags Flags
unsigned StringRef DIFile unsigned DIScope DIType uint64_t uint32_t uint64_t OffsetInBits
unsigned StringRef DIFile unsigned DIScope DIType uint64_t uint32_t AlignInBits
unsigned StringRef DIFile unsigned DIScope * Scope
Constant * getConstant() const
Constant * getStorageOffsetInBits() const
Constant * getDiscriminantValue() const
unsigned StringRef Name
uint32_t getVBPtrOffset() const
unsigned StringRef DIFile unsigned DIScope DIType uint64_t uint32_t uint64_t std::optional< unsigned > DIFlags Metadata * ExtraData
unsigned StringRef DIFile unsigned Line
Enumeration value.
int64_t bool MDString * Name
unsigned getSize() const
Return the size of the operand.
uint64_t getOp() const
Get the operand code.
An iterator for expression operands.
DWARF expression.
element_iterator elements_end() const
bool isEntryValue() const
Check if the expression consists of exactly one entry value operand.
iterator_range< expr_op_iterator > expr_ops() const
static DIExpression * append(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Append the opcodes Ops to DIExpr.
std::array< uint64_t, 6 > ExtOps
unsigned getNumElements() const
static ExtOps getExtOps(unsigned FromSize, unsigned ToSize, bool Signed)
Returns the ops for a zero- or sign-extension in a DIExpression.
expr_op_iterator expr_op_begin() const
Visit the elements via ExprOperand wrappers.
bool extractIfOffset(int64_t &Offset) const
If this is a constant offset, extract it.
static void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
bool startsWithDeref() const
Return whether the first element a DW_OP_deref.
static bool isEqualExpression(const DIExpression *FirstExpr, bool FirstIndirect, const DIExpression *SecondExpr, bool SecondIndirect)
Determines whether two debug values should produce equivalent DWARF expressions, using their DIExpres...
expr_op_iterator expr_op_end() const
bool isImplicit() const
Return whether this is an implicit location description.
element_iterator elements_begin() const
bool hasAllLocationOps(unsigned N) const
Returns true iff this DIExpression contains at least one instance of DW_OP_LLVM_arg,...
std::optional< FragmentInfo > getFragmentInfo() const
Retrieve the details of this fragment expression.
static DIExpression * appendOpsToArg(const DIExpression *Expr, ArrayRef< uint64_t > Ops, unsigned ArgNo, bool StackValue=false)
Create a copy of Expr by appending the given list of Ops to each instance of the operand DW_OP_LLVM_a...
bool isComplex() const
Return whether the location is computed on the expression stack, meaning it cannot be a simple regist...
static std::optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
static std::optional< const DIExpression * > convertToNonVariadicExpression(const DIExpression *Expr)
If Expr is a valid single-location expression, i.e.
std::pair< DIExpression *, const ConstantInt * > constantFold(const ConstantInt *CI)
Try to shorten an expression with an initial constant operand.
bool isDeref() const
Return whether there is exactly one operator and it is a DW_OP_deref;.
static const DIExpression * convertToVariadicExpression(const DIExpression *Expr)
If Expr is a non-variadic expression (i.e.
uint64_t getNumLocationOperands() const
Return the number of unique location operands referred to (via DW_OP_LLVM_arg) in this expression; th...
ArrayRef< uint64_t > getElements() const
static DIExpression * replaceArg(const DIExpression *Expr, uint64_t OldArg, uint64_t NewArg)
Create a copy of Expr with each instance of DW_OP_LLVM_arg, \p OldArg replaced with DW_OP_LLVM_arg,...
static void canonicalizeExpressionOps(SmallVectorImpl< uint64_t > &Ops, const DIExpression *Expr, bool IsIndirect)
Inserts the elements of Expr into Ops modified to a canonical form, which uses DW_OP_LLVM_arg (i....
uint64_t getElement(unsigned I) const
static std::optional< DIExpression * > createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits)
Create a DIExpression to describe one part of an aggregate variable that is fragmented across multipl...
static const DIExpression * convertToUndefExpression(const DIExpression *Expr)
Removes all elements from Expr that do not apply to an undef debug value, which includes every operat...
static DIExpression * prepend(const DIExpression *Expr, uint8_t Flags, int64_t Offset=0)
Prepend DIExpr with a deref and offset operation and optionally turn it into a stack value or/and an ...
static DIExpression * appendToStack(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Convert DIExpr into a stack value if it isn't one already by appending DW_OP_deref if needed,...
static DIExpression * appendExt(const DIExpression *Expr, unsigned FromSize, unsigned ToSize, bool Signed)
Append a zero- or sign-extension to Expr.
bool isSingleLocationExpression() const
Return whether the evaluated expression makes use of a single location at the start of the expression...
std::optional< SignedOrUnsignedConstant > isConstant() const
Determine whether this represents a constant value, if so.
static const DIExpression * extractAddressClass(const DIExpression *Expr, unsigned &AddrClass)
Checks if the last 4 elements of the expression are DW_OP_constu <DWARF Address Space> DW_OP_swap DW_...
static DIExpression * prependOpcodes(const DIExpression *Expr, SmallVectorImpl< uint64_t > &Ops, bool StackValue=false, bool EntryValue=false)
Prepend DIExpr with the given opcodes and optionally turn it into a stack value.
MDString MDString * Directory
MDString * Filename
static std::optional< ChecksumKind > getChecksumKind(StringRef CSKindStr)
MDString MDString std::optional< ChecksumInfo< MDString * > > CS
Metadata * getRawLowerBound() const
Metadata * getRawCountNode() const
Metadata * getRawStride() const
BoundType getLowerBound() const
Metadata * getRawUpperBound() const
BoundType getUpperBound() const
PointerUnion< DIVariable *, DIExpression * > BoundType
A pair of DIGlobalVariable and DIExpression.
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata Metadata * TemplateParams
Metadata MDString MDString Metadata unsigned Line
Metadata MDString MDString Metadata unsigned Metadata * Type
Metadata MDString * Name
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata * StaticDataMemberDeclaration
Metadata MDString MDString * LinkageName
Metadata MDString MDString Metadata * File
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata Metadata uint32_t AlignInBits
An imported module (C++ using directive or similar).
unsigned Metadata Metadata * Entity
unsigned Metadata Metadata Metadata unsigned MDString * Name
unsigned Metadata Metadata Metadata * File
unsigned Metadata * Scope
Metadata MDString * Name
Metadata MDString Metadata * File
DILexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage, ArrayRef< Metadata * > Ops)
Metadata Metadata * File
Metadata Metadata * File
A scope for locals.
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
DILocalScope * getNonLexicalBlockFileScope() const
Get the first non DILexicalBlockFile scope of this scope.
static DILocalScope * cloneScopeForSubprogram(DILocalScope &RootScope, DISubprogram &NewSP, LLVMContext &Ctx, DenseMap< const MDNode *, MDNode * > &Cache)
Traverses the scope chain rooted at RootScope until it hits a Subprogram, recreating the chain with "...
Metadata MDString Metadata unsigned Metadata * Type
Metadata MDString Metadata * File
Metadata MDString * Name
Metadata MDString Metadata unsigned Line
Metadata MDString Metadata unsigned Metadata unsigned DIFlags uint32_t AlignInBits
Debug location.
unsigned unsigned DILocalScope * Scope
static 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 Metadata Metadata * Elements
unsigned unsigned MDString * Name
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
Metadata Metadata * Scope
Metadata Metadata MDString * Name
Metadata Metadata MDString MDString MDString MDString * APINotesFile
Metadata Metadata MDString MDString MDString * IncludePath
Metadata Metadata MDString MDString * ConfigurationMacros
Metadata MDString * Name
Tagged DWARF-like metadata node.
dwarf::Tag getTag() const
static DIFlags getFlag(StringRef Flag)
static DIFlags splitFlags(DIFlags Flags, SmallVectorImpl< DIFlags > &SplitFlags)
Split up a flags bitfield.
static StringRef getFlagString(DIFlags Flag)
DIFlags
Debug info flags.
MDString Metadata * File
MDString Metadata unsigned MDString * GetterName
MDString Metadata unsigned MDString MDString * SetterName
Base class for scope-like contexts.
StringRef getName() const
DIScope * getScope() const
String type, Fortran CHARACTER(n)
unsigned MDString * Name
unsigned MDString Metadata Metadata Metadata uint64_t SizeInBits
unsigned MDString Metadata Metadata Metadata uint64_t uint32_t AlignInBits
unsigned MDString Metadata Metadata Metadata * StringLocationExp
unsigned MDString Metadata Metadata * StringLengthExp
unsigned MDString Metadata * StringLength
Subprogram description.
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata * Unit
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata Metadata * Annotations
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata * ContainingType
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata * TemplateParams
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata * Declaration
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata Metadata MDString * TargetFuncName
static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized, unsigned Virtuality=SPFlagNonvirtual, bool IsMainSubprogram=false)
Metadata MDString * Name
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata * ThrownTypes
static DISPFlags getFlag(StringRef Flag)
Metadata MDString MDString Metadata * File
static DISPFlags splitFlags(DISPFlags Flags, SmallVectorImpl< DISPFlags > &SplitFlags)
Split up a flags bitfield for easier printing.
Metadata MDString MDString * LinkageName
static StringRef getFlagString(DISPFlags Flag)
Metadata MDString MDString Metadata unsigned Metadata * Type
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata * RetainedNodes
DISPFlags
Debug info subprogram flags.
Array subrange.
BoundType getUpperBound() const
BoundType getStride() const
BoundType getLowerBound() const
BoundType getCount() const
Type array for a subprogram.
DIFlags uint8_t Metadata * TypeArray
Base class for template parameters.
unsigned MDString Metadata * Type
Base class for types.
bool isBitField() const
bool isStaticMember() const
std::optional< uint64_t > getSizeInBits() const
Determines the size of the variable's type.
Metadata * getRawType() const
DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, signed Line, ArrayRef< Metadata * > Ops, uint32_t AlignInBits=0)
This is the common base class for debug info intrinsics for variables.
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
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:950
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1424
void storeDistinctInContext()
Definition: Metadata.cpp:948
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1416
bool isUniqued() const
Definition: Metadata.h:1132
TempMDNode clone() const
Create a (temporary) clone of this.
Definition: Metadata.cpp:560
static T * storeImpl(T *N, StorageType Storage, StoreT &Store)
Definition: MetadataImpl.h:42
LLVMContext & getContext() const
Definition: Metadata.h:1114
void dropAllReferences()
Definition: Metadata.cpp:800
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:1174
A single uniqued string.
Definition: Metadata.h:611
StringRef getString() const
Definition: Metadata.cpp:509
static void untrack(Metadata *&MD)
Stop tracking a reference to metadata.
Definition: Metadata.h:247
static bool track(Metadata *&MD)
Track the reference to metadata.
Definition: Metadata.h:222
Root of the metadata hierarchy.
Definition: Metadata.h:61
StorageType
Active type of storage.
Definition: Metadata.h:69
unsigned short SubclassData16
Definition: Metadata.h:75
unsigned SubclassData32
Definition: Metadata.h:76
unsigned char Storage
Storage flag for non-uniqued, otherwise unowned, metadata.
Definition: Metadata.h:72
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:118
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1743
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:450
bool empty() const
Definition: SmallVector.h:94
size_t size() const
Definition: SmallVector.h:91
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
void reserve(size_type N)
Definition: SmallVector.h:667
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:687
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:809
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static IntegerType * getInt64Ty(LLVMContext &C)
Value wrapper in the Metadata hierarchy.
Definition: Metadata.h:344
static ValueAsMetadata * get(Value *V)
Definition: Metadata.cpp:394
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:199
@ DW_VIRTUALITY_max
Definition: Dwarf.h:190
@ NameTableKind
Definition: LLToken.h:468
@ EmissionKind
Definition: LLToken.h:467
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:413
@ Offset
Definition: DWP.cpp:406
static T * getUniqued(DenseSet< T *, InfoT > &Store, const typename InfoT::KeyTy &Key)
Definition: MetadataImpl.h:22
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
cl::opt< bool > EnableFSDiscriminator
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1826
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:511
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:1833
@ Ref
The access may reference the value stored in memory.
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).