LLVM 21.0.0git
DebugInfoMetadata.cpp
Go to the documentation of this file.
1//===- DebugInfoMetadata.cpp - Implement debug info metadata --------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the debug info Metadata classes.
10//
11//===----------------------------------------------------------------------===//
12
14#include "LLVMContextImpl.h"
15#include "MetadataImpl.h"
20#include "llvm/IR/Function.h"
22#include "llvm/IR/Type.h"
23#include "llvm/IR/Value.h"
24
25#include <numeric>
26#include <optional>
27
28using namespace llvm;
29
30namespace llvm {
31// Use FS-AFDO discriminator.
33 "enable-fs-discriminator", cl::Hidden,
34 cl::desc("Enable adding flow sensitive discriminators"));
35} // namespace llvm
36
38 return (getTag() == dwarf::DW_TAG_LLVM_ptrauth_type ? 0 : SubclassData32);
39}
40
41const DIExpression::FragmentInfo DebugVariable::DefaultFragment = {
42 std::numeric_limits<uint64_t>::max(), std::numeric_limits<uint64_t>::min()};
43
45 : Variable(DII->getVariable()),
46 Fragment(DII->getExpression()->getFragmentInfo()),
47 InlinedAt(DII->getDebugLoc().getInlinedAt()) {}
48
50 : Variable(DVR->getVariable()),
51 Fragment(DVR->getExpression()->getFragmentInfo()),
52 InlinedAt(DVR->getDebugLoc().getInlinedAt()) {}
53
55 : DebugVariable(DVI->getVariable(), std::nullopt,
56 DVI->getDebugLoc()->getInlinedAt()) {}
57
58DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
59 unsigned Column, ArrayRef<Metadata *> MDs,
60 bool ImplicitCode)
61 : MDNode(C, DILocationKind, Storage, MDs) {
62 assert((MDs.size() == 1 || MDs.size() == 2) &&
63 "Expected a scope and optional inlined-at");
64
65 // Set line and column.
66 assert(Column < (1u << 16) && "Expected 16-bit column");
67
68 SubclassData32 = Line;
69 SubclassData16 = Column;
70
71 setImplicitCode(ImplicitCode);
72}
73
74static void adjustColumn(unsigned &Column) {
75 // Set to unknown on overflow. We only have 16 bits to play with here.
76 if (Column >= (1u << 16))
77 Column = 0;
78}
79
80DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
81 unsigned Column, Metadata *Scope,
82 Metadata *InlinedAt, bool ImplicitCode,
83 StorageType Storage, bool ShouldCreate) {
84 // Fixup column.
86
87 if (Storage == Uniqued) {
88 if (auto *N = getUniqued(Context.pImpl->DILocations,
89 DILocationInfo::KeyTy(Line, Column, Scope,
91 return N;
92 if (!ShouldCreate)
93 return nullptr;
94 } else {
95 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
96 }
97
99 Ops.push_back(Scope);
100 if (InlinedAt)
101 Ops.push_back(InlinedAt);
102 return storeImpl(new (Ops.size(), Storage) DILocation(
103 Context, Storage, Line, Column, Ops, ImplicitCode),
104 Storage, Context.pImpl->DILocations);
105}
106
108 if (Locs.empty())
109 return nullptr;
110 if (Locs.size() == 1)
111 return Locs[0];
112 auto *Merged = Locs[0];
113 for (DILocation *L : llvm::drop_begin(Locs)) {
114 Merged = getMergedLocation(Merged, L);
115 if (Merged == nullptr)
116 break;
117 }
118 return Merged;
119}
120
122 if (!LocA || !LocB)
123 return nullptr;
124
125 if (LocA == LocB)
126 return LocA;
127
128 LLVMContext &C = LocA->getContext();
129
130 using LocVec = SmallVector<const DILocation *>;
131 LocVec ALocs;
132 LocVec BLocs;
134 4>
135 ALookup;
136
137 // Walk through LocA and its inlined-at locations, populate them in ALocs and
138 // save the index for the subprogram and inlined-at pair, which we use to find
139 // a matching starting location in LocB's chain.
140 for (auto [L, I] = std::make_pair(LocA, 0U); L; L = L->getInlinedAt(), I++) {
141 ALocs.push_back(L);
142 auto Res = ALookup.try_emplace(
143 {L->getScope()->getSubprogram(), L->getInlinedAt()}, I);
144 assert(Res.second && "Multiple <SP, InlinedAt> pairs in a location chain?");
145 (void)Res;
146 }
147
148 LocVec::reverse_iterator ARIt = ALocs.rend();
149 LocVec::reverse_iterator BRIt = BLocs.rend();
150
151 // Populate BLocs and look for a matching starting location, the first
152 // location with the same subprogram and inlined-at location as in LocA's
153 // chain. Since the two locations have the same inlined-at location we do
154 // not need to look at those parts of the chains.
155 for (auto [L, I] = std::make_pair(LocB, 0U); L; L = L->getInlinedAt(), I++) {
156 BLocs.push_back(L);
157
158 if (ARIt != ALocs.rend())
159 // We have already found a matching starting location.
160 continue;
161
162 auto IT = ALookup.find({L->getScope()->getSubprogram(), L->getInlinedAt()});
163 if (IT == ALookup.end())
164 continue;
165
166 // The + 1 is to account for the &*rev_it = &(it - 1) relationship.
167 ARIt = LocVec::reverse_iterator(ALocs.begin() + IT->second + 1);
168 BRIt = LocVec::reverse_iterator(BLocs.begin() + I + 1);
169
170 // If we have found a matching starting location we do not need to add more
171 // locations to BLocs, since we will only look at location pairs preceding
172 // the matching starting location, and adding more elements to BLocs could
173 // invalidate the iterator that we initialized here.
174 break;
175 }
176
177 // Merge the two locations if possible, using the supplied
178 // inlined-at location for the created location.
179 auto MergeLocPair = [&C](const DILocation *L1, const DILocation *L2,
181 if (L1 == L2)
182 return DILocation::get(C, L1->getLine(), L1->getColumn(), L1->getScope(),
183 InlinedAt);
184
185 // If the locations originate from different subprograms we can't produce
186 // a common location.
187 if (L1->getScope()->getSubprogram() != L2->getScope()->getSubprogram())
188 return nullptr;
189
190 // Return the nearest common scope inside a subprogram.
191 auto GetNearestCommonScope = [](DIScope *S1, DIScope *S2) -> DIScope * {
193 for (; S1; S1 = S1->getScope()) {
194 Scopes.insert(S1);
195 if (isa<DISubprogram>(S1))
196 break;
197 }
198
199 for (; S2; S2 = S2->getScope()) {
200 if (Scopes.count(S2))
201 return S2;
202 if (isa<DISubprogram>(S2))
203 break;
204 }
205
206 return nullptr;
207 };
208
209 auto Scope = GetNearestCommonScope(L1->getScope(), L2->getScope());
210 assert(Scope && "No common scope in the same subprogram?");
211
212 bool SameLine = L1->getLine() == L2->getLine();
213 bool SameCol = L1->getColumn() == L2->getColumn();
214 unsigned Line = SameLine ? L1->getLine() : 0;
215 unsigned Col = SameLine && SameCol ? L1->getColumn() : 0;
216
217 return DILocation::get(C, Line, Col, Scope, InlinedAt);
218 };
219
220 DILocation *Result = ARIt != ALocs.rend() ? (*ARIt)->getInlinedAt() : nullptr;
221
222 // If we have found a common starting location, walk up the inlined-at chains
223 // and try to produce common locations.
224 for (; ARIt != ALocs.rend() && BRIt != BLocs.rend(); ++ARIt, ++BRIt) {
225 DILocation *Tmp = MergeLocPair(*ARIt, *BRIt, Result);
226
227 if (!Tmp)
228 // We have walked up to a point in the chains where the two locations
229 // are irreconsilable. At this point Result contains the nearest common
230 // location in the inlined-at chains of LocA and LocB, so we break here.
231 break;
232
233 Result = Tmp;
234 }
235
236 if (Result)
237 return Result;
238
239 // We ended up with LocA and LocB as irreconsilable locations. Produce a
240 // location at 0:0 with one of the locations' scope. The function has
241 // historically picked A's scope, and a nullptr inlined-at location, so that
242 // behavior is mimicked here but I am not sure if this is always the correct
243 // way to handle this.
244 return DILocation::get(C, 0, 0, LocA->getScope(), nullptr);
245}
246
247std::optional<unsigned>
248DILocation::encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI) {
249 std::array<unsigned, 3> Components = {BD, DF, CI};
250 uint64_t RemainingWork = 0U;
251 // We use RemainingWork to figure out if we have no remaining components to
252 // encode. For example: if BD != 0 but DF == 0 && CI == 0, we don't need to
253 // encode anything for the latter 2.
254 // Since any of the input components is at most 32 bits, their sum will be
255 // less than 34 bits, and thus RemainingWork won't overflow.
256 RemainingWork =
257 std::accumulate(Components.begin(), Components.end(), RemainingWork);
258
259 int I = 0;
260 unsigned Ret = 0;
261 unsigned NextBitInsertionIndex = 0;
262 while (RemainingWork > 0) {
263 unsigned C = Components[I++];
264 RemainingWork -= C;
265 unsigned EC = encodeComponent(C);
266 Ret |= (EC << NextBitInsertionIndex);
267 NextBitInsertionIndex += encodingBits(C);
268 }
269
270 // Encoding may be unsuccessful because of overflow. We determine success by
271 // checking equivalence of components before & after encoding. Alternatively,
272 // we could determine Success during encoding, but the current alternative is
273 // simpler.
274 unsigned TBD, TDF, TCI = 0;
275 decodeDiscriminator(Ret, TBD, TDF, TCI);
276 if (TBD == BD && TDF == DF && TCI == CI)
277 return Ret;
278 return std::nullopt;
279}
280
281void DILocation::decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF,
282 unsigned &CI) {
287}
289
291 return StringSwitch<DIFlags>(Flag)
292#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
293#include "llvm/IR/DebugInfoFlags.def"
294 .Default(DINode::FlagZero);
295}
296
298 switch (Flag) {
299#define HANDLE_DI_FLAG(ID, NAME) \
300 case Flag##NAME: \
301 return "DIFlag" #NAME;
302#include "llvm/IR/DebugInfoFlags.def"
303 }
304 return "";
305}
306
308 SmallVectorImpl<DIFlags> &SplitFlags) {
309 // Flags that are packed together need to be specially handled, so
310 // that, for example, we emit "DIFlagPublic" and not
311 // "DIFlagPrivate | DIFlagProtected".
312 if (DIFlags A = Flags & FlagAccessibility) {
313 if (A == FlagPrivate)
314 SplitFlags.push_back(FlagPrivate);
315 else if (A == FlagProtected)
316 SplitFlags.push_back(FlagProtected);
317 else
318 SplitFlags.push_back(FlagPublic);
319 Flags &= ~A;
320 }
321 if (DIFlags R = Flags & FlagPtrToMemberRep) {
322 if (R == FlagSingleInheritance)
323 SplitFlags.push_back(FlagSingleInheritance);
324 else if (R == FlagMultipleInheritance)
325 SplitFlags.push_back(FlagMultipleInheritance);
326 else
327 SplitFlags.push_back(FlagVirtualInheritance);
328 Flags &= ~R;
329 }
330 if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) {
331 Flags &= ~FlagIndirectVirtualBase;
332 SplitFlags.push_back(FlagIndirectVirtualBase);
333 }
334
335#define HANDLE_DI_FLAG(ID, NAME) \
336 if (DIFlags Bit = Flags & Flag##NAME) { \
337 SplitFlags.push_back(Bit); \
338 Flags &= ~Bit; \
339 }
340#include "llvm/IR/DebugInfoFlags.def"
341 return Flags;
342}
343
345 if (auto *T = dyn_cast<DIType>(this))
346 return T->getScope();
347
348 if (auto *SP = dyn_cast<DISubprogram>(this))
349 return SP->getScope();
350
351 if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
352 return LB->getScope();
353
354 if (auto *NS = dyn_cast<DINamespace>(this))
355 return NS->getScope();
356
357 if (auto *CB = dyn_cast<DICommonBlock>(this))
358 return CB->getScope();
359
360 if (auto *M = dyn_cast<DIModule>(this))
361 return M->getScope();
362
363 assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&
364 "Unhandled type of scope.");
365 return nullptr;
366}
367
369 if (auto *T = dyn_cast<DIType>(this))
370 return T->getName();
371 if (auto *SP = dyn_cast<DISubprogram>(this))
372 return SP->getName();
373 if (auto *NS = dyn_cast<DINamespace>(this))
374 return NS->getName();
375 if (auto *CB = dyn_cast<DICommonBlock>(this))
376 return CB->getName();
377 if (auto *M = dyn_cast<DIModule>(this))
378 return M->getName();
379 assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||
380 isa<DICompileUnit>(this)) &&
381 "Unhandled type of scope.");
382 return "";
383}
384
385#ifndef NDEBUG
386static bool isCanonical(const MDString *S) {
387 return !S || !S->getString().empty();
388}
389#endif
390
392GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
393 MDString *Header,
394 ArrayRef<Metadata *> DwarfOps,
395 StorageType Storage, bool ShouldCreate) {
396 unsigned Hash = 0;
397 if (Storage == Uniqued) {
398 GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps);
399 if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
400 return N;
401 if (!ShouldCreate)
402 return nullptr;
403 Hash = Key.getHash();
404 } else {
405 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
406 }
407
408 // Use a nullptr for empty headers.
409 assert(isCanonical(Header) && "Expected canonical MDString");
410 Metadata *PreOps[] = {Header};
411 return storeImpl(new (DwarfOps.size() + 1, Storage) GenericDINode(
412 Context, Storage, Hash, Tag, PreOps, DwarfOps),
413 Storage, Context.pImpl->GenericDINodes);
414}
415
416void GenericDINode::recalculateHash() {
417 setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
418}
419
420#define UNWRAP_ARGS_IMPL(...) __VA_ARGS__
421#define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS
422#define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS) \
423 do { \
424 if (Storage == Uniqued) { \
425 if (auto *N = getUniqued(Context.pImpl->CLASS##s, \
426 CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS)))) \
427 return N; \
428 if (!ShouldCreate) \
429 return nullptr; \
430 } else { \
431 assert(ShouldCreate && \
432 "Expected non-uniqued nodes to always be created"); \
433 } \
434 } while (false)
435#define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS) \
436 return storeImpl(new (std::size(OPS), Storage) \
437 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
438 Storage, Context.pImpl->CLASS##s)
439#define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS) \
440 return storeImpl(new (0u, Storage) \
441 CLASS(Context, Storage, UNWRAP_ARGS(ARGS)), \
442 Storage, Context.pImpl->CLASS##s)
443#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS) \
444 return storeImpl(new (std::size(OPS), Storage) CLASS(Context, Storage, OPS), \
445 Storage, Context.pImpl->CLASS##s)
446#define DEFINE_GETIMPL_STORE_N(CLASS, ARGS, OPS, NUM_OPS) \
447 return storeImpl(new (NUM_OPS, Storage) \
448 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
449 Storage, Context.pImpl->CLASS##s)
450
451DISubrange::DISubrange(LLVMContext &C, StorageType Storage,
453 : DINode(C, DISubrangeKind, Storage, dwarf::DW_TAG_subrange_type, Ops) {}
454DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
455 StorageType Storage, 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 int64_t Lo, StorageType Storage,
466 bool ShouldCreate) {
467 auto *LB = ConstantAsMetadata::get(
469 return getImpl(Context, CountNode, LB, nullptr, nullptr, Storage,
470 ShouldCreate);
471}
472
473DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
474 Metadata *LB, Metadata *UB, Metadata *Stride,
475 StorageType Storage, bool ShouldCreate) {
476 DEFINE_GETIMPL_LOOKUP(DISubrange, (CountNode, LB, UB, Stride));
477 Metadata *Ops[] = {CountNode, LB, UB, Stride};
479}
480
481DISubrange::BoundType DISubrange::getCount() const {
482 Metadata *CB = getRawCountNode();
483 if (!CB)
484 return BoundType();
485
486 assert((isa<ConstantAsMetadata>(CB) || isa<DIVariable>(CB) ||
487 isa<DIExpression>(CB)) &&
488 "Count must be signed constant or DIVariable or DIExpression");
489
490 if (auto *MD = dyn_cast<ConstantAsMetadata>(CB))
491 return BoundType(cast<ConstantInt>(MD->getValue()));
492
493 if (auto *MD = dyn_cast<DIVariable>(CB))
494 return BoundType(MD);
495
496 if (auto *MD = dyn_cast<DIExpression>(CB))
497 return BoundType(MD);
498
499 return BoundType();
500}
501
502DISubrange::BoundType DISubrange::getLowerBound() const {
503 Metadata *LB = getRawLowerBound();
504 if (!LB)
505 return BoundType();
506
507 assert((isa<ConstantAsMetadata>(LB) || isa<DIVariable>(LB) ||
508 isa<DIExpression>(LB)) &&
509 "LowerBound must be signed constant or DIVariable or DIExpression");
510
511 if (auto *MD = dyn_cast<ConstantAsMetadata>(LB))
512 return BoundType(cast<ConstantInt>(MD->getValue()));
513
514 if (auto *MD = dyn_cast<DIVariable>(LB))
515 return BoundType(MD);
516
517 if (auto *MD = dyn_cast<DIExpression>(LB))
518 return BoundType(MD);
519
520 return BoundType();
521}
522
523DISubrange::BoundType DISubrange::getUpperBound() const {
524 Metadata *UB = getRawUpperBound();
525 if (!UB)
526 return BoundType();
527
528 assert((isa<ConstantAsMetadata>(UB) || isa<DIVariable>(UB) ||
529 isa<DIExpression>(UB)) &&
530 "UpperBound must be signed constant or DIVariable or DIExpression");
531
532 if (auto *MD = dyn_cast<ConstantAsMetadata>(UB))
533 return BoundType(cast<ConstantInt>(MD->getValue()));
534
535 if (auto *MD = dyn_cast<DIVariable>(UB))
536 return BoundType(MD);
537
538 if (auto *MD = dyn_cast<DIExpression>(UB))
539 return BoundType(MD);
540
541 return BoundType();
542}
543
544DISubrange::BoundType DISubrange::getStride() const {
545 Metadata *ST = getRawStride();
546 if (!ST)
547 return BoundType();
548
549 assert((isa<ConstantAsMetadata>(ST) || isa<DIVariable>(ST) ||
550 isa<DIExpression>(ST)) &&
551 "Stride must be signed constant or DIVariable or DIExpression");
552
553 if (auto *MD = dyn_cast<ConstantAsMetadata>(ST))
554 return BoundType(cast<ConstantInt>(MD->getValue()));
555
556 if (auto *MD = dyn_cast<DIVariable>(ST))
557 return BoundType(MD);
558
559 if (auto *MD = dyn_cast<DIExpression>(ST))
560 return BoundType(MD);
561
562 return BoundType();
563}
564DIGenericSubrange::DIGenericSubrange(LLVMContext &C, StorageType Storage,
566 : DINode(C, DIGenericSubrangeKind, Storage, dwarf::DW_TAG_generic_subrange,
567 Ops) {}
568
569DIGenericSubrange *DIGenericSubrange::getImpl(LLVMContext &Context,
570 Metadata *CountNode, Metadata *LB,
571 Metadata *UB, Metadata *Stride,
572 StorageType Storage,
573 bool ShouldCreate) {
574 DEFINE_GETIMPL_LOOKUP(DIGenericSubrange, (CountNode, LB, UB, Stride));
575 Metadata *Ops[] = {CountNode, LB, UB, Stride};
577}
578
581 if (!CB)
582 return BoundType();
583
584 assert((isa<DIVariable>(CB) || isa<DIExpression>(CB)) &&
585 "Count must be signed constant or DIVariable or DIExpression");
586
587 if (auto *MD = dyn_cast<DIVariable>(CB))
588 return BoundType(MD);
589
590 if (auto *MD = dyn_cast<DIExpression>(CB))
591 return BoundType(MD);
592
593 return BoundType();
594}
595
598 if (!LB)
599 return BoundType();
600
601 assert((isa<DIVariable>(LB) || isa<DIExpression>(LB)) &&
602 "LowerBound must be signed constant or DIVariable or DIExpression");
603
604 if (auto *MD = dyn_cast<DIVariable>(LB))
605 return BoundType(MD);
606
607 if (auto *MD = dyn_cast<DIExpression>(LB))
608 return BoundType(MD);
609
610 return BoundType();
611}
612
615 if (!UB)
616 return BoundType();
617
618 assert((isa<DIVariable>(UB) || isa<DIExpression>(UB)) &&
619 "UpperBound must be signed constant or DIVariable or DIExpression");
620
621 if (auto *MD = dyn_cast<DIVariable>(UB))
622 return BoundType(MD);
623
624 if (auto *MD = dyn_cast<DIExpression>(UB))
625 return BoundType(MD);
626
627 return BoundType();
628}
629
631 Metadata *ST = getRawStride();
632 if (!ST)
633 return BoundType();
634
635 assert((isa<DIVariable>(ST) || isa<DIExpression>(ST)) &&
636 "Stride must be signed constant or DIVariable or DIExpression");
637
638 if (auto *MD = dyn_cast<DIVariable>(ST))
639 return BoundType(MD);
640
641 if (auto *MD = dyn_cast<DIExpression>(ST))
642 return BoundType(MD);
643
644 return BoundType();
645}
646
647DIEnumerator::DIEnumerator(LLVMContext &C, StorageType Storage,
648 const APInt &Value, bool IsUnsigned,
650 : DINode(C, DIEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
651 Value(Value) {
652 SubclassData32 = IsUnsigned;
653}
654DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, const APInt &Value,
655 bool IsUnsigned, MDString *Name,
656 StorageType Storage, bool ShouldCreate) {
657 assert(isCanonical(Name) && "Expected canonical MDString");
659 Metadata *Ops[] = {Name};
661}
662
663DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
664 MDString *Name, uint64_t SizeInBits,
665 uint32_t AlignInBits, unsigned Encoding,
666 uint32_t NumExtraInhabitants, DIFlags Flags,
667 StorageType Storage, bool ShouldCreate) {
668 assert(isCanonical(Name) && "Expected canonical MDString");
670 Encoding, NumExtraInhabitants, Flags));
671 Metadata *Ops[] = {nullptr, nullptr, Name};
675 Ops);
676}
677
678std::optional<DIBasicType::Signedness> DIBasicType::getSignedness() const {
679 switch (getEncoding()) {
680 case dwarf::DW_ATE_signed:
681 case dwarf::DW_ATE_signed_char:
682 return Signedness::Signed;
683 case dwarf::DW_ATE_unsigned:
684 case dwarf::DW_ATE_unsigned_char:
686 default:
687 return std::nullopt;
688 }
689}
690
691DIStringType *DIStringType::getImpl(LLVMContext &Context, unsigned Tag,
692 MDString *Name, Metadata *StringLength,
693 Metadata *StringLengthExp,
694 Metadata *StringLocationExp,
695 uint64_t SizeInBits, uint32_t AlignInBits,
696 unsigned Encoding, StorageType Storage,
697 bool ShouldCreate) {
698 assert(isCanonical(Name) && "Expected canonical MDString");
702 Metadata *Ops[] = {nullptr, nullptr, Name,
705 Ops);
706}
708 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
709 return cast_or_null<DIType>(getExtraData());
710}
712 assert(getTag() == dwarf::DW_TAG_inheritance);
713 if (auto *CM = cast_or_null<ConstantAsMetadata>(getExtraData()))
714 if (auto *CI = dyn_cast_or_null<ConstantInt>(CM->getValue()))
715 return static_cast<uint32_t>(CI->getZExtValue());
716 return 0;
717}
719 assert(getTag() == dwarf::DW_TAG_member && isBitField());
720 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
721 return C->getValue();
722 return nullptr;
723}
724
726 assert((getTag() == dwarf::DW_TAG_member ||
727 getTag() == dwarf::DW_TAG_variable) &&
729 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
730 return C->getValue();
731 return nullptr;
732}
734 assert(getTag() == dwarf::DW_TAG_member && !isStaticMember());
735 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
736 return C->getValue();
737 return nullptr;
738}
739
740DIDerivedType *DIDerivedType::getImpl(
741 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
742 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
743 uint32_t AlignInBits, uint64_t OffsetInBits,
744 std::optional<unsigned> DWARFAddressSpace,
745 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags, Metadata *ExtraData,
746 Metadata *Annotations, StorageType Storage, bool ShouldCreate) {
747 assert(isCanonical(Name) && "Expected canonical MDString");
750 AlignInBits, OffsetInBits, DWARFAddressSpace,
751 PtrAuthData, Flags, ExtraData, Annotations));
755 DWARFAddressSpace, PtrAuthData, Flags),
756 Ops);
757}
758
759std::optional<DIDerivedType::PtrAuthData>
760DIDerivedType::getPtrAuthData() const {
761 return getTag() == dwarf::DW_TAG_LLVM_ptrauth_type
762 ? std::optional<PtrAuthData>(PtrAuthData(SubclassData32))
763 : std::nullopt;
764}
765
766DICompositeType *DICompositeType::getImpl(
767 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
768 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
769 uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
770 Metadata *Elements, unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
771 Metadata *VTableHolder, Metadata *TemplateParams, MDString *Identifier,
772 Metadata *Discriminator, Metadata *DataLocation, Metadata *Associated,
773 Metadata *Allocated, Metadata *Rank, Metadata *Annotations,
774 Metadata *Specification, uint32_t NumExtraInhabitants, StorageType Storage,
775 bool ShouldCreate) {
776 assert(isCanonical(Name) && "Expected canonical MDString");
777
778 // Keep this in sync with buildODRType.
785 Metadata *Ops[] = {File, Scope, Name, BaseType,
790 (Tag, Line, RuntimeLang, SizeInBits, AlignInBits,
792 Ops);
793}
794
796 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
797 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
798 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
799 Metadata *Specification, uint32_t NumExtraInhabitants, DIFlags Flags,
800 Metadata *Elements, unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
801 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
802 Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
803 Metadata *Rank, Metadata *Annotations) {
804 assert(!Identifier.getString().empty() && "Expected valid identifier");
805 if (!Context.isODRUniquingDebugTypes())
806 return nullptr;
807 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
808 if (!CT)
810 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
811 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
815 if (CT->getTag() != Tag)
816 return nullptr;
817
818 // Only mutate CT if it's a forward declaration and the new operands aren't.
819 assert(CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?");
820 if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl))
821 return CT;
822
823 // Mutate CT in place. Keep this in sync with getImpl.
824 CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
825 NumExtraInhabitants, EnumKind, Flags);
826 Metadata *Ops[] = {File, Scope, Name, BaseType,
830 assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&
831 "Mismatched number of operands");
832 for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I)
833 if (Ops[I] != CT->getOperand(I))
834 CT->setOperand(I, Ops[I]);
835 return CT;
836}
837
838DICompositeType *DICompositeType::getODRType(
839 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
840 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
841 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
842 Metadata *Specification, uint32_t NumExtraInhabitants, DIFlags Flags,
843 Metadata *Elements, unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
844 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
845 Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
846 Metadata *Rank, Metadata *Annotations) {
847 assert(!Identifier.getString().empty() && "Expected valid identifier");
848 if (!Context.isODRUniquingDebugTypes())
849 return nullptr;
850 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
851 if (!CT) {
853 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
854 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, EnumKind,
858 } else {
859 if (CT->getTag() != Tag)
860 return nullptr;
861 }
862 return CT;
863}
864
866 MDString &Identifier) {
867 assert(!Identifier.getString().empty() && "Expected valid identifier");
868 if (!Context.isODRUniquingDebugTypes())
869 return nullptr;
870 return Context.pImpl->DITypeMap->lookup(&Identifier);
871}
872DISubroutineType::DISubroutineType(LLVMContext &C, StorageType Storage,
873 DIFlags Flags, uint8_t CC,
875 : DIType(C, DISubroutineTypeKind, Storage, dwarf::DW_TAG_subroutine_type, 0,
876 0, 0, 0, 0, Flags, Ops),
877 CC(CC) {}
878
879DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags,
880 uint8_t CC, Metadata *TypeArray,
881 StorageType Storage,
882 bool ShouldCreate) {
884 Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
886}
887
888DIFile::DIFile(LLVMContext &C, StorageType Storage,
889 std::optional<ChecksumInfo<MDString *>> CS, MDString *Src,
891 : DIScope(C, DIFileKind, Storage, dwarf::DW_TAG_file_type, Ops),
892 Checksum(CS), Source(Src) {}
893
894// FIXME: Implement this string-enum correspondence with a .def file and macros,
895// so that the association is explicit rather than implied.
896static const char *ChecksumKindName[DIFile::CSK_Last] = {
897 "CSK_MD5",
898 "CSK_SHA1",
899 "CSK_SHA256",
900};
901
902StringRef DIFile::getChecksumKindAsString(ChecksumKind CSKind) {
903 assert(CSKind <= DIFile::CSK_Last && "Invalid checksum kind");
904 // The first space was originally the CSK_None variant, which is now
905 // obsolete, but the space is still reserved in ChecksumKind, so we account
906 // for it here.
907 return ChecksumKindName[CSKind - 1];
908}
909
910std::optional<DIFile::ChecksumKind>
913 .Case("CSK_MD5", DIFile::CSK_MD5)
914 .Case("CSK_SHA1", DIFile::CSK_SHA1)
915 .Case("CSK_SHA256", DIFile::CSK_SHA256)
916 .Default(std::nullopt);
917}
918
919DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
920 MDString *Directory,
921 std::optional<DIFile::ChecksumInfo<MDString *>> CS,
922 MDString *Source, StorageType Storage,
923 bool ShouldCreate) {
924 assert(isCanonical(Filename) && "Expected canonical MDString");
925 assert(isCanonical(Directory) && "Expected canonical MDString");
926 assert((!CS || isCanonical(CS->Value)) && "Expected canonical MDString");
927 // We do *NOT* expect Source to be a canonical MDString because nullptr
928 // means none, so we need something to represent the empty file.
930 Metadata *Ops[] = {Filename, Directory, CS ? CS->Value : nullptr, Source};
931 DEFINE_GETIMPL_STORE(DIFile, (CS, Source), Ops);
932}
933DICompileUnit::DICompileUnit(LLVMContext &C, StorageType Storage,
934 unsigned SourceLanguage, bool IsOptimized,
935 unsigned RuntimeVersion, unsigned EmissionKind,
936 uint64_t DWOId, bool SplitDebugInlining,
937 bool DebugInfoForProfiling, unsigned NameTableKind,
938 bool RangesBaseAddress, ArrayRef<Metadata *> Ops)
939 : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
940 SourceLanguage(SourceLanguage), RuntimeVersion(RuntimeVersion),
942 IsOptimized(IsOptimized), SplitDebugInlining(SplitDebugInlining),
943 DebugInfoForProfiling(DebugInfoForProfiling),
944 RangesBaseAddress(RangesBaseAddress) {
946}
947
948DICompileUnit *DICompileUnit::getImpl(
949 LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
950 MDString *Producer, bool IsOptimized, MDString *Flags,
951 unsigned RuntimeVersion, MDString *SplitDebugFilename,
952 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
953 Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
954 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
955 unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
956 MDString *SDK, StorageType Storage, bool ShouldCreate) {
957 assert(Storage != Uniqued && "Cannot unique DICompileUnit");
958 assert(isCanonical(Producer) && "Expected canonical MDString");
959 assert(isCanonical(Flags) && "Expected canonical MDString");
960 assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
961
962 Metadata *Ops[] = {File,
963 Producer,
964 Flags,
966 EnumTypes,
970 Macros,
971 SysRoot,
972 SDK};
973 return storeImpl(new (std::size(Ops), Storage) DICompileUnit(
974 Context, Storage, SourceLanguage, IsOptimized,
975 RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
976 DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
977 Ops),
978 Storage);
979}
980
981std::optional<DICompileUnit::DebugEmissionKind>
984 .Case("NoDebug", NoDebug)
985 .Case("FullDebug", FullDebug)
986 .Case("LineTablesOnly", LineTablesOnly)
987 .Case("DebugDirectivesOnly", DebugDirectivesOnly)
988 .Default(std::nullopt);
989}
990
991std::optional<DICompileUnit::DebugNameTableKind>
994 .Case("Default", DebugNameTableKind::Default)
998 .Default(std::nullopt);
999}
1000
1002 switch (EK) {
1003 case NoDebug:
1004 return "NoDebug";
1005 case FullDebug:
1006 return "FullDebug";
1007 case LineTablesOnly:
1008 return "LineTablesOnly";
1010 return "DebugDirectivesOnly";
1011 }
1012 return nullptr;
1013}
1014
1016 switch (NTK) {
1018 return nullptr;
1020 return "GNU";
1022 return "Apple";
1024 return "None";
1025 }
1026 return nullptr;
1027}
1028DISubprogram::DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1029 unsigned ScopeLine, unsigned VirtualIndex,
1030 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags,
1032 : DILocalScope(C, DISubprogramKind, Storage, dwarf::DW_TAG_subprogram, Ops),
1033 Line(Line), ScopeLine(ScopeLine), VirtualIndex(VirtualIndex),
1034 ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags) {
1035 static_assert(dwarf::DW_VIRTUALITY_max < 4, "Virtuality out of range");
1036}
1038DISubprogram::toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized,
1039 unsigned Virtuality, bool IsMainSubprogram) {
1040 // We're assuming virtuality is the low-order field.
1041 static_assert(int(SPFlagVirtual) == int(dwarf::DW_VIRTUALITY_virtual) &&
1042 int(SPFlagPureVirtual) ==
1043 int(dwarf::DW_VIRTUALITY_pure_virtual),
1044 "Virtuality constant mismatch");
1045 return static_cast<DISPFlags>(
1046 (Virtuality & SPFlagVirtuality) |
1047 (IsLocalToUnit ? SPFlagLocalToUnit : SPFlagZero) |
1048 (IsDefinition ? SPFlagDefinition : SPFlagZero) |
1049 (IsOptimized ? SPFlagOptimized : SPFlagZero) |
1050 (IsMainSubprogram ? SPFlagMainSubprogram : SPFlagZero));
1051}
1052
1054 if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
1055 return Block->getScope()->getSubprogram();
1056 return const_cast<DISubprogram *>(cast<DISubprogram>(this));
1057}
1058
1060 if (auto *File = dyn_cast<DILexicalBlockFile>(this))
1061 return File->getScope()->getNonLexicalBlockFileScope();
1062 return const_cast<DILocalScope *>(this);
1063}
1064
1066 DILocalScope &RootScope, DISubprogram &NewSP, LLVMContext &Ctx,
1068 SmallVector<DIScope *> ScopeChain;
1069 DIScope *CachedResult = nullptr;
1070
1071 for (DIScope *Scope = &RootScope; !isa<DISubprogram>(Scope);
1072 Scope = Scope->getScope()) {
1073 if (auto It = Cache.find(Scope); It != Cache.end()) {
1074 CachedResult = cast<DIScope>(It->second);
1075 break;
1076 }
1077 ScopeChain.push_back(Scope);
1078 }
1079
1080 // Recreate the scope chain, bottom-up, starting at the new subprogram (or a
1081 // cached result).
1082 DIScope *UpdatedScope = CachedResult ? CachedResult : &NewSP;
1083 for (DIScope *ScopeToUpdate : reverse(ScopeChain)) {
1084 TempMDNode ClonedScope = ScopeToUpdate->clone();
1085 cast<DILexicalBlockBase>(*ClonedScope).replaceScope(UpdatedScope);
1086 UpdatedScope =
1087 cast<DIScope>(MDNode::replaceWithUniqued(std::move(ClonedScope)));
1088 Cache[ScopeToUpdate] = UpdatedScope;
1089 }
1090
1091 return cast<DILocalScope>(UpdatedScope);
1092}
1093
1095 return StringSwitch<DISPFlags>(Flag)
1096#define HANDLE_DISP_FLAG(ID, NAME) .Case("DISPFlag" #NAME, SPFlag##NAME)
1097#include "llvm/IR/DebugInfoFlags.def"
1098 .Default(SPFlagZero);
1099}
1100
1102 switch (Flag) {
1103 // Appease a warning.
1104 case SPFlagVirtuality:
1105 return "";
1106#define HANDLE_DISP_FLAG(ID, NAME) \
1107 case SPFlag##NAME: \
1108 return "DISPFlag" #NAME;
1109#include "llvm/IR/DebugInfoFlags.def"
1110 }
1111 return "";
1112}
1113
1116 SmallVectorImpl<DISPFlags> &SplitFlags) {
1117 // Multi-bit fields can require special handling. In our case, however, the
1118 // only multi-bit field is virtuality, and all its values happen to be
1119 // single-bit values, so the right behavior just falls out.
1120#define HANDLE_DISP_FLAG(ID, NAME) \
1121 if (DISPFlags Bit = Flags & SPFlag##NAME) { \
1122 SplitFlags.push_back(Bit); \
1123 Flags &= ~Bit; \
1124 }
1125#include "llvm/IR/DebugInfoFlags.def"
1126 return Flags;
1127}
1128
1129DISubprogram *DISubprogram::getImpl(
1130 LLVMContext &Context, Metadata *Scope, MDString *Name,
1131 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1132 unsigned ScopeLine, Metadata *ContainingType, unsigned VirtualIndex,
1133 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
1134 Metadata *TemplateParams, Metadata *Declaration, Metadata *RetainedNodes,
1135 Metadata *ThrownTypes, Metadata *Annotations, MDString *TargetFuncName,
1136 StorageType Storage, bool ShouldCreate) {
1137 assert(isCanonical(Name) && "Expected canonical MDString");
1138 assert(isCanonical(LinkageName) && "Expected canonical MDString");
1139 assert(isCanonical(TargetFuncName) && "Expected canonical MDString");
1141 (Scope, Name, LinkageName, File, Line, Type, ScopeLine,
1142 ContainingType, VirtualIndex, ThisAdjustment, Flags,
1143 SPFlags, Unit, TemplateParams, Declaration,
1151 if (!TargetFuncName) {
1152 Ops.pop_back();
1153 if (!Annotations) {
1154 Ops.pop_back();
1155 if (!ThrownTypes) {
1156 Ops.pop_back();
1157 if (!TemplateParams) {
1158 Ops.pop_back();
1159 if (!ContainingType)
1160 Ops.pop_back();
1161 }
1162 }
1163 }
1164 }
1167 (Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags, SPFlags), Ops,
1168 Ops.size());
1169}
1170
1171bool DISubprogram::describes(const Function *F) const {
1172 assert(F && "Invalid function");
1173 return F->getSubprogram() == this;
1174}
1176 StorageType Storage,
1178 : DILocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1179
1180DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
1181 Metadata *File, unsigned Line,
1182 unsigned Column, StorageType Storage,
1183 bool ShouldCreate) {
1184 // Fixup column.
1185 adjustColumn(Column);
1186
1187 assert(Scope && "Expected scope");
1189 Metadata *Ops[] = {File, Scope};
1190 DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops);
1191}
1192
1193DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
1194 Metadata *Scope, Metadata *File,
1195 unsigned Discriminator,
1196 StorageType Storage,
1197 bool ShouldCreate) {
1198 assert(Scope && "Expected scope");
1200 Metadata *Ops[] = {File, Scope};
1202}
1203
1204DINamespace::DINamespace(LLVMContext &Context, StorageType Storage,
1205 bool ExportSymbols, ArrayRef<Metadata *> Ops)
1206 : DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace, Ops) {
1207 SubclassData1 = ExportSymbols;
1208}
1209DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
1210 MDString *Name, bool ExportSymbols,
1211 StorageType Storage, bool ShouldCreate) {
1212 assert(isCanonical(Name) && "Expected canonical MDString");
1214 // The nullptr is for DIScope's File operand. This should be refactored.
1215 Metadata *Ops[] = {nullptr, Scope, Name};
1217}
1218
1219DICommonBlock::DICommonBlock(LLVMContext &Context, StorageType Storage,
1220 unsigned LineNo, ArrayRef<Metadata *> Ops)
1221 : DIScope(Context, DICommonBlockKind, Storage, dwarf::DW_TAG_common_block,
1222 Ops) {
1223 SubclassData32 = LineNo;
1224}
1225DICommonBlock *DICommonBlock::getImpl(LLVMContext &Context, Metadata *Scope,
1226 Metadata *Decl, MDString *Name,
1227 Metadata *File, unsigned LineNo,
1228 StorageType Storage, bool ShouldCreate) {
1229 assert(isCanonical(Name) && "Expected canonical MDString");
1231 // The nullptr is for DIScope's File operand. This should be refactored.
1232 Metadata *Ops[] = {Scope, Decl, Name, File};
1234}
1235
1236DIModule::DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo,
1237 bool IsDecl, ArrayRef<Metadata *> Ops)
1238 : DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops) {
1239 SubclassData1 = IsDecl;
1240 SubclassData32 = LineNo;
1241}
1242DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *File,
1243 Metadata *Scope, MDString *Name,
1244 MDString *ConfigurationMacros,
1245 MDString *IncludePath, MDString *APINotesFile,
1246 unsigned LineNo, bool IsDecl, StorageType Storage,
1247 bool ShouldCreate) {
1248 assert(isCanonical(Name) && "Expected canonical MDString");
1250 IncludePath, APINotesFile, LineNo, IsDecl));
1253 DEFINE_GETIMPL_STORE(DIModule, (LineNo, IsDecl), Ops);
1254}
1255DITemplateTypeParameter::DITemplateTypeParameter(LLVMContext &Context,
1256 StorageType Storage,
1257 bool IsDefault,
1259 : DITemplateParameter(Context, DITemplateTypeParameterKind, Storage,
1260 dwarf::DW_TAG_template_type_parameter, IsDefault,
1261 Ops) {}
1262
1264DITemplateTypeParameter::getImpl(LLVMContext &Context, MDString *Name,
1265 Metadata *Type, bool isDefault,
1266 StorageType Storage, bool ShouldCreate) {
1267 assert(isCanonical(Name) && "Expected canonical MDString");
1269 Metadata *Ops[] = {Name, Type};
1271}
1272
1273DITemplateValueParameter *DITemplateValueParameter::getImpl(
1274 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
1275 bool isDefault, Metadata *Value, StorageType Storage, bool ShouldCreate) {
1276 assert(isCanonical(Name) && "Expected canonical MDString");
1278 (Tag, Name, Type, isDefault, Value));
1279 Metadata *Ops[] = {Name, Type, Value};
1281}
1282
1284DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1285 MDString *LinkageName, Metadata *File, unsigned Line,
1286 Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1287 Metadata *StaticDataMemberDeclaration,
1288 Metadata *TemplateParams, uint32_t AlignInBits,
1289 Metadata *Annotations, StorageType Storage,
1290 bool ShouldCreate) {
1291 assert(isCanonical(Name) && "Expected canonical MDString");
1292 assert(isCanonical(LinkageName) && "Expected canonical MDString");
1295 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1297 Metadata *Ops[] = {Scope,
1298 Name,
1299 File,
1300 Type,
1301 Name,
1305 Annotations};
1307 (Line, IsLocalToUnit, IsDefinition, AlignInBits), Ops);
1308}
1309
1311DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1312 Metadata *File, unsigned Line, Metadata *Type,
1313 unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
1314 Metadata *Annotations, StorageType Storage,
1315 bool ShouldCreate) {
1316 // 64K ought to be enough for any frontend.
1317 assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");
1318
1319 assert(Scope && "Expected scope");
1320 assert(isCanonical(Name) && "Expected canonical MDString");
1322 Flags, AlignInBits, Annotations));
1323 Metadata *Ops[] = {Scope, Name, File, Type, Annotations};
1325}
1326
1328 signed Line, ArrayRef<Metadata *> Ops,
1329 uint32_t AlignInBits)
1330 : DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line) {
1331 SubclassData32 = AlignInBits;
1332}
1333std::optional<uint64_t> DIVariable::getSizeInBits() const {
1334 // This is used by the Verifier so be mindful of broken types.
1335 const Metadata *RawType = getRawType();
1336 while (RawType) {
1337 // Try to get the size directly.
1338 if (auto *T = dyn_cast<DIType>(RawType))
1339 if (uint64_t Size = T->getSizeInBits())
1340 return Size;
1341
1342 if (auto *DT = dyn_cast<DIDerivedType>(RawType)) {
1343 // Look at the base type.
1344 RawType = DT->getRawBaseType();
1345 continue;
1346 }
1347
1348 // Missing type or size.
1349 break;
1350 }
1351
1352 // Fail gracefully.
1353 return std::nullopt;
1354}
1355
1356DILabel::DILabel(LLVMContext &C, StorageType Storage, unsigned Line,
1358 : DINode(C, DILabelKind, Storage, dwarf::DW_TAG_label, Ops) {
1359 SubclassData32 = Line;
1360}
1361DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1362 Metadata *File, unsigned Line, StorageType Storage,
1363 bool ShouldCreate) {
1364 assert(Scope && "Expected scope");
1365 assert(isCanonical(Name) && "Expected canonical MDString");
1367 Metadata *Ops[] = {Scope, Name, File};
1369}
1370
1371DIExpression *DIExpression::getImpl(LLVMContext &Context,
1372 ArrayRef<uint64_t> Elements,
1373 StorageType Storage, bool ShouldCreate) {
1376}
1378 if (auto singleLocElts = getSingleLocationExpressionElements()) {
1379 return singleLocElts->size() > 0 &&
1380 (*singleLocElts)[0] == dwarf::DW_OP_LLVM_entry_value;
1381 }
1382 return false;
1383}
1385 if (auto singleLocElts = getSingleLocationExpressionElements())
1386 return singleLocElts->size() > 0 &&
1387 (*singleLocElts)[0] == dwarf::DW_OP_deref;
1388 return false;
1389}
1391 if (auto singleLocElts = getSingleLocationExpressionElements())
1392 return singleLocElts->size() == 1 &&
1393 (*singleLocElts)[0] == dwarf::DW_OP_deref;
1394 return false;
1395}
1396
1397DIAssignID *DIAssignID::getImpl(LLVMContext &Context, StorageType Storage,
1398 bool ShouldCreate) {
1399 // Uniqued DIAssignID are not supported as the instance address *is* the ID.
1400 assert(Storage != StorageType::Uniqued && "uniqued DIAssignID unsupported");
1401 return storeImpl(new (0u, Storage) DIAssignID(Context, Storage), Storage);
1402}
1403
1405 uint64_t Op = getOp();
1406
1407 if (Op >= dwarf::DW_OP_breg0 && Op <= dwarf::DW_OP_breg31)
1408 return 2;
1409
1410 switch (Op) {
1415 case dwarf::DW_OP_bregx:
1416 return 3;
1417 case dwarf::DW_OP_constu:
1418 case dwarf::DW_OP_consts:
1419 case dwarf::DW_OP_deref_size:
1420 case dwarf::DW_OP_plus_uconst:
1424 case dwarf::DW_OP_regx:
1425 return 2;
1426 default:
1427 return 1;
1428 }
1429}
1430
1432 for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
1433 // Check that there's space for the operand.
1434 if (I->get() + I->getSize() > E->get())
1435 return false;
1436
1437 uint64_t Op = I->getOp();
1438 if ((Op >= dwarf::DW_OP_reg0 && Op <= dwarf::DW_OP_reg31) ||
1439 (Op >= dwarf::DW_OP_breg0 && Op <= dwarf::DW_OP_breg31))
1440 return true;
1441
1442 // Check that the operand is valid.
1443 switch (Op) {
1444 default:
1445 return false;
1447 // A fragment operator must appear at the end.
1448 return I->get() + I->getSize() == E->get();
1449 case dwarf::DW_OP_stack_value: {
1450 // Must be the last one or followed by a DW_OP_LLVM_fragment.
1451 if (I->get() + I->getSize() == E->get())
1452 break;
1453 auto J = I;
1454 if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment)
1455 return false;
1456 break;
1457 }
1458 case dwarf::DW_OP_swap: {
1459 // Must be more than one implicit element on the stack.
1460
1461 // FIXME: A better way to implement this would be to add a local variable
1462 // that keeps track of the stack depth and introduce something like a
1463 // DW_LLVM_OP_implicit_location as a placeholder for the location this
1464 // DIExpression is attached to, or else pass the number of implicit stack
1465 // elements into isValid.
1466 if (getNumElements() == 1)
1467 return false;
1468 break;
1469 }
1471 // An entry value operator must appear at the beginning or immediately
1472 // following `DW_OP_LLVM_arg 0`, and the number of operations it cover can
1473 // currently only be 1, because we support only entry values of a simple
1474 // register location. One reason for this is that we currently can't
1475 // calculate the size of the resulting DWARF block for other expressions.
1476 auto FirstOp = expr_op_begin();
1477 if (FirstOp->getOp() == dwarf::DW_OP_LLVM_arg && FirstOp->getArg(0) == 0)
1478 ++FirstOp;
1479 return I->get() == FirstOp->get() && I->getArg(0) == 1;
1480 }
1487 case dwarf::DW_OP_constu:
1488 case dwarf::DW_OP_plus_uconst:
1489 case dwarf::DW_OP_plus:
1490 case dwarf::DW_OP_minus:
1491 case dwarf::DW_OP_mul:
1492 case dwarf::DW_OP_div:
1493 case dwarf::DW_OP_mod:
1494 case dwarf::DW_OP_or:
1495 case dwarf::DW_OP_and:
1496 case dwarf::DW_OP_xor:
1497 case dwarf::DW_OP_shl:
1498 case dwarf::DW_OP_shr:
1499 case dwarf::DW_OP_shra:
1500 case dwarf::DW_OP_deref:
1501 case dwarf::DW_OP_deref_size:
1502 case dwarf::DW_OP_xderef:
1503 case dwarf::DW_OP_lit0:
1504 case dwarf::DW_OP_not:
1505 case dwarf::DW_OP_dup:
1506 case dwarf::DW_OP_regx:
1507 case dwarf::DW_OP_bregx:
1508 case dwarf::DW_OP_push_object_address:
1509 case dwarf::DW_OP_over:
1510 case dwarf::DW_OP_consts:
1511 case dwarf::DW_OP_eq:
1512 case dwarf::DW_OP_ne:
1513 case dwarf::DW_OP_gt:
1514 case dwarf::DW_OP_ge:
1515 case dwarf::DW_OP_lt:
1516 case dwarf::DW_OP_le:
1517 break;
1518 }
1519 }
1520 return true;
1521}
1522
1524 if (!isValid())
1525 return false;
1526
1527 if (getNumElements() == 0)
1528 return false;
1529
1530 for (const auto &It : expr_ops()) {
1531 switch (It.getOp()) {
1532 default:
1533 break;
1534 case dwarf::DW_OP_stack_value:
1535 return true;
1536 }
1537 }
1538
1539 return false;
1540}
1541
1543 if (!isValid())
1544 return false;
1545
1546 if (getNumElements() == 0)
1547 return false;
1548
1549 // If there are any elements other than fragment or tag_offset, then some
1550 // kind of complex computation occurs.
1551 for (const auto &It : expr_ops()) {
1552 switch (It.getOp()) {
1556 continue;
1557 default:
1558 return true;
1559 }
1560 }
1561
1562 return false;
1563}
1564
1566 if (!isValid())
1567 return false;
1568
1569 if (getNumElements() == 0)
1570 return true;
1571
1572 auto ExprOpBegin = expr_ops().begin();
1573 auto ExprOpEnd = expr_ops().end();
1574 if (ExprOpBegin->getOp() == dwarf::DW_OP_LLVM_arg) {
1575 if (ExprOpBegin->getArg(0) != 0)
1576 return false;
1577 ++ExprOpBegin;
1578 }
1579
1580 return !std::any_of(ExprOpBegin, ExprOpEnd, [](auto Op) {
1581 return Op.getOp() == dwarf::DW_OP_LLVM_arg;
1582 });
1583}
1584
1585std::optional<ArrayRef<uint64_t>>
1587 // Check for `isValid` covered by `isSingleLocationExpression`.
1589 return std::nullopt;
1590
1591 // An empty expression is already non-variadic.
1592 if (!getNumElements())
1593 return ArrayRef<uint64_t>();
1594
1595 // If Expr does not have a leading DW_OP_LLVM_arg then we don't need to do
1596 // anything.
1598 return getElements().drop_front(2);
1599 return getElements();
1600}
1601
1602const DIExpression *
1604 SmallVector<uint64_t, 3> UndefOps;
1605 if (auto FragmentInfo = Expr->getFragmentInfo()) {
1608 }
1609 return DIExpression::get(Expr->getContext(), UndefOps);
1610}
1611
1612const DIExpression *
1614 if (any_of(Expr->expr_ops(), [](auto ExprOp) {
1615 return ExprOp.getOp() == dwarf::DW_OP_LLVM_arg;
1616 }))
1617 return Expr;
1618 SmallVector<uint64_t> NewOps;
1619 NewOps.reserve(Expr->getNumElements() + 2);
1620 NewOps.append({dwarf::DW_OP_LLVM_arg, 0});
1621 NewOps.append(Expr->elements_begin(), Expr->elements_end());
1622 return DIExpression::get(Expr->getContext(), NewOps);
1623}
1624
1625std::optional<const DIExpression *>
1627 if (!Expr)
1628 return std::nullopt;
1629
1630 if (auto Elts = Expr->getSingleLocationExpressionElements())
1631 return DIExpression::get(Expr->getContext(), *Elts);
1632
1633 return std::nullopt;
1634}
1635
1637 const DIExpression *Expr,
1638 bool IsIndirect) {
1639 // If Expr is not already variadic, insert the implied `DW_OP_LLVM_arg 0`
1640 // to the existing expression ops.
1641 if (none_of(Expr->expr_ops(), [](auto ExprOp) {
1642 return ExprOp.getOp() == dwarf::DW_OP_LLVM_arg;
1643 }))
1644 Ops.append({dwarf::DW_OP_LLVM_arg, 0});
1645 // If Expr is not indirect, we only need to insert the expression elements and
1646 // we're done.
1647 if (!IsIndirect) {
1648 Ops.append(Expr->elements_begin(), Expr->elements_end());
1649 return;
1650 }
1651 // If Expr is indirect, insert the implied DW_OP_deref at the end of the
1652 // expression but before DW_OP_{stack_value, LLVM_fragment} if they are
1653 // present.
1654 for (auto Op : Expr->expr_ops()) {
1655 if (Op.getOp() == dwarf::DW_OP_stack_value ||
1656 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1657 Ops.push_back(dwarf::DW_OP_deref);
1658 IsIndirect = false;
1659 }
1660 Op.appendToVector(Ops);
1661 }
1662 if (IsIndirect)
1663 Ops.push_back(dwarf::DW_OP_deref);
1664}
1665
1667 bool FirstIndirect,
1668 const DIExpression *SecondExpr,
1669 bool SecondIndirect) {
1670 SmallVector<uint64_t> FirstOps;
1671 DIExpression::canonicalizeExpressionOps(FirstOps, FirstExpr, FirstIndirect);
1672 SmallVector<uint64_t> SecondOps;
1673 DIExpression::canonicalizeExpressionOps(SecondOps, SecondExpr,
1674 SecondIndirect);
1675 return FirstOps == SecondOps;
1676}
1677
1678std::optional<DIExpression::FragmentInfo>
1680 for (auto I = Start; I != End; ++I)
1681 if (I->getOp() == dwarf::DW_OP_LLVM_fragment) {
1682 DIExpression::FragmentInfo Info = {I->getArg(1), I->getArg(0)};
1683 return Info;
1684 }
1685 return std::nullopt;
1686}
1687
1688std::optional<uint64_t> DIExpression::getActiveBits(DIVariable *Var) {
1689 std::optional<uint64_t> InitialActiveBits = Var->getSizeInBits();
1690 std::optional<uint64_t> ActiveBits = InitialActiveBits;
1691 for (auto Op : expr_ops()) {
1692 switch (Op.getOp()) {
1693 default:
1694 // We assume the worst case for anything we don't currently handle and
1695 // revert to the initial active bits.
1696 ActiveBits = InitialActiveBits;
1697 break;
1700 // We can't handle an extract whose sign doesn't match that of the
1701 // variable.
1702 std::optional<DIBasicType::Signedness> VarSign = Var->getSignedness();
1703 bool VarSigned = (VarSign == DIBasicType::Signedness::Signed);
1704 bool OpSigned = (Op.getOp() == dwarf::DW_OP_LLVM_extract_bits_sext);
1705 if (!VarSign || VarSigned != OpSigned) {
1706 ActiveBits = InitialActiveBits;
1707 break;
1708 }
1709 [[fallthrough]];
1710 }
1712 // Extract or fragment narrows the active bits
1713 if (ActiveBits)
1714 ActiveBits = std::min(*ActiveBits, Op.getArg(1));
1715 else
1716 ActiveBits = Op.getArg(1);
1717 break;
1718 }
1719 }
1720 return ActiveBits;
1721}
1722
1724 int64_t Offset) {
1725 if (Offset > 0) {
1726 Ops.push_back(dwarf::DW_OP_plus_uconst);
1727 Ops.push_back(Offset);
1728 } else if (Offset < 0) {
1729 Ops.push_back(dwarf::DW_OP_constu);
1730 // Avoid UB when encountering LLONG_MIN, because in 2's complement
1731 // abs(LLONG_MIN) is LLONG_MAX+1.
1732 uint64_t AbsMinusOne = -(Offset+1);
1733 Ops.push_back(AbsMinusOne + 1);
1734 Ops.push_back(dwarf::DW_OP_minus);
1735 }
1736}
1737
1739 auto SingleLocEltsOpt = getSingleLocationExpressionElements();
1740 if (!SingleLocEltsOpt)
1741 return false;
1742 auto SingleLocElts = *SingleLocEltsOpt;
1743
1744 if (SingleLocElts.size() == 0) {
1745 Offset = 0;
1746 return true;
1747 }
1748
1749 if (SingleLocElts.size() == 2 &&
1750 SingleLocElts[0] == dwarf::DW_OP_plus_uconst) {
1751 Offset = SingleLocElts[1];
1752 return true;
1753 }
1754
1755 if (SingleLocElts.size() == 3 && SingleLocElts[0] == dwarf::DW_OP_constu) {
1756 if (SingleLocElts[2] == dwarf::DW_OP_plus) {
1757 Offset = SingleLocElts[1];
1758 return true;
1759 }
1760 if (SingleLocElts[2] == dwarf::DW_OP_minus) {
1761 Offset = -SingleLocElts[1];
1762 return true;
1763 }
1764 }
1765
1766 return false;
1767}
1768
1770 int64_t &OffsetInBytes, SmallVectorImpl<uint64_t> &RemainingOps) const {
1771 OffsetInBytes = 0;
1772 RemainingOps.clear();
1773
1774 auto SingleLocEltsOpt = getSingleLocationExpressionElements();
1775 if (!SingleLocEltsOpt)
1776 return false;
1777
1778 auto ExprOpEnd = expr_op_iterator(SingleLocEltsOpt->end());
1779 auto ExprOpIt = expr_op_iterator(SingleLocEltsOpt->begin());
1780 while (ExprOpIt != ExprOpEnd) {
1781 uint64_t Op = ExprOpIt->getOp();
1782 if (Op == dwarf::DW_OP_deref || Op == dwarf::DW_OP_deref_size ||
1783 Op == dwarf::DW_OP_deref_type || Op == dwarf::DW_OP_LLVM_fragment ||
1786 break;
1787 } else if (Op == dwarf::DW_OP_plus_uconst) {
1788 OffsetInBytes += ExprOpIt->getArg(0);
1789 } else if (Op == dwarf::DW_OP_constu) {
1790 uint64_t Value = ExprOpIt->getArg(0);
1791 ++ExprOpIt;
1792 if (ExprOpIt->getOp() == dwarf::DW_OP_plus)
1793 OffsetInBytes += Value;
1794 else if (ExprOpIt->getOp() == dwarf::DW_OP_minus)
1795 OffsetInBytes -= Value;
1796 else
1797 return false;
1798 } else {
1799 // Not a const plus/minus operation or deref.
1800 return false;
1801 }
1802 ++ExprOpIt;
1803 }
1804 RemainingOps.append(ExprOpIt.getBase(), ExprOpEnd.getBase());
1805 return true;
1806}
1807
1810 for (auto ExprOp : expr_ops())
1811 if (ExprOp.getOp() == dwarf::DW_OP_LLVM_arg)
1812 SeenOps.insert(ExprOp.getArg(0));
1813 for (uint64_t Idx = 0; Idx < N; ++Idx)
1814 if (!SeenOps.contains(Idx))
1815 return false;
1816 return true;
1817}
1818
1820 unsigned &AddrClass) {
1821 // FIXME: This seems fragile. Nothing that verifies that these elements
1822 // actually map to ops and not operands.
1823 auto SingleLocEltsOpt = Expr->getSingleLocationExpressionElements();
1824 if (!SingleLocEltsOpt)
1825 return nullptr;
1826 auto SingleLocElts = *SingleLocEltsOpt;
1827
1828 const unsigned PatternSize = 4;
1829 if (SingleLocElts.size() >= PatternSize &&
1830 SingleLocElts[PatternSize - 4] == dwarf::DW_OP_constu &&
1831 SingleLocElts[PatternSize - 2] == dwarf::DW_OP_swap &&
1832 SingleLocElts[PatternSize - 1] == dwarf::DW_OP_xderef) {
1833 AddrClass = SingleLocElts[PatternSize - 3];
1834
1835 if (SingleLocElts.size() == PatternSize)
1836 return nullptr;
1837 return DIExpression::get(
1838 Expr->getContext(),
1839 ArrayRef(&*SingleLocElts.begin(), SingleLocElts.size() - PatternSize));
1840 }
1841 return Expr;
1842}
1843
1845 int64_t Offset) {
1847 if (Flags & DIExpression::DerefBefore)
1848 Ops.push_back(dwarf::DW_OP_deref);
1849
1850 appendOffset(Ops, Offset);
1851 if (Flags & DIExpression::DerefAfter)
1852 Ops.push_back(dwarf::DW_OP_deref);
1853
1854 bool StackValue = Flags & DIExpression::StackValue;
1855 bool EntryValue = Flags & DIExpression::EntryValue;
1856
1857 return prependOpcodes(Expr, Ops, StackValue, EntryValue);
1858}
1859
1862 unsigned ArgNo, bool StackValue) {
1863 assert(Expr && "Can't add ops to this expression");
1864
1865 // Handle non-variadic intrinsics by prepending the opcodes.
1866 if (!any_of(Expr->expr_ops(),
1867 [](auto Op) { return Op.getOp() == dwarf::DW_OP_LLVM_arg; })) {
1868 assert(ArgNo == 0 &&
1869 "Location Index must be 0 for a non-variadic expression.");
1870 SmallVector<uint64_t, 8> NewOps(Ops);
1871 return DIExpression::prependOpcodes(Expr, NewOps, StackValue);
1872 }
1873
1875 for (auto Op : Expr->expr_ops()) {
1876 // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
1877 if (StackValue) {
1878 if (Op.getOp() == dwarf::DW_OP_stack_value)
1879 StackValue = false;
1880 else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1881 NewOps.push_back(dwarf::DW_OP_stack_value);
1882 StackValue = false;
1883 }
1884 }
1885 Op.appendToVector(NewOps);
1886 if (Op.getOp() == dwarf::DW_OP_LLVM_arg && Op.getArg(0) == ArgNo)
1887 NewOps.insert(NewOps.end(), Ops.begin(), Ops.end());
1888 }
1889 if (StackValue)
1890 NewOps.push_back(dwarf::DW_OP_stack_value);
1891
1892 return DIExpression::get(Expr->getContext(), NewOps);
1893}
1894
1896 uint64_t OldArg, uint64_t NewArg) {
1897 assert(Expr && "Can't replace args in this expression");
1898
1900
1901 for (auto Op : Expr->expr_ops()) {
1902 if (Op.getOp() != dwarf::DW_OP_LLVM_arg || Op.getArg(0) < OldArg) {
1903 Op.appendToVector(NewOps);
1904 continue;
1905 }
1907 uint64_t Arg = Op.getArg(0) == OldArg ? NewArg : Op.getArg(0);
1908 // OldArg has been deleted from the Op list, so decrement all indices
1909 // greater than it.
1910 if (Arg > OldArg)
1911 --Arg;
1912 NewOps.push_back(Arg);
1913 }
1914 return DIExpression::get(Expr->getContext(), NewOps);
1915}
1916
1919 bool StackValue, bool EntryValue) {
1920 assert(Expr && "Can't prepend ops to this expression");
1921
1922 if (EntryValue) {
1924 // Use a block size of 1 for the target register operand. The
1925 // DWARF backend currently cannot emit entry values with a block
1926 // size > 1.
1927 Ops.push_back(1);
1928 }
1929
1930 // If there are no ops to prepend, do not even add the DW_OP_stack_value.
1931 if (Ops.empty())
1932 StackValue = false;
1933 for (auto Op : Expr->expr_ops()) {
1934 // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
1935 if (StackValue) {
1936 if (Op.getOp() == dwarf::DW_OP_stack_value)
1937 StackValue = false;
1938 else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1939 Ops.push_back(dwarf::DW_OP_stack_value);
1940 StackValue = false;
1941 }
1942 }
1943 Op.appendToVector(Ops);
1944 }
1945 if (StackValue)
1946 Ops.push_back(dwarf::DW_OP_stack_value);
1947 return DIExpression::get(Expr->getContext(), Ops);
1948}
1949
1951 ArrayRef<uint64_t> Ops) {
1952 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
1953
1954 // Copy Expr's current op list.
1956 for (auto Op : Expr->expr_ops()) {
1957 // Append new opcodes before DW_OP_{stack_value, LLVM_fragment}.
1958 if (Op.getOp() == dwarf::DW_OP_stack_value ||
1959 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
1960 NewOps.append(Ops.begin(), Ops.end());
1961
1962 // Ensure that the new opcodes are only appended once.
1963 Ops = {};
1964 }
1965 Op.appendToVector(NewOps);
1966 }
1967 NewOps.append(Ops.begin(), Ops.end());
1968 auto *result =
1969 DIExpression::get(Expr->getContext(), NewOps)->foldConstantMath();
1970 assert(result->isValid() && "concatenated expression is not valid");
1971 return result;
1972}
1973
1975 ArrayRef<uint64_t> Ops) {
1976 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
1977 assert(std::none_of(expr_op_iterator(Ops.begin()),
1978 expr_op_iterator(Ops.end()),
1979 [](auto Op) {
1980 return Op.getOp() == dwarf::DW_OP_stack_value ||
1981 Op.getOp() == dwarf::DW_OP_LLVM_fragment;
1982 }) &&
1983 "Can't append this op");
1984
1985 // Append a DW_OP_deref after Expr's current op list if it's non-empty and
1986 // has no DW_OP_stack_value.
1987 //
1988 // Match .* DW_OP_stack_value (DW_OP_LLVM_fragment A B)?.
1989 std::optional<FragmentInfo> FI = Expr->getFragmentInfo();
1990 unsigned DropUntilStackValue = FI ? 3 : 0;
1991 ArrayRef<uint64_t> ExprOpsBeforeFragment =
1992 Expr->getElements().drop_back(DropUntilStackValue);
1993 bool NeedsDeref = (Expr->getNumElements() > DropUntilStackValue) &&
1994 (ExprOpsBeforeFragment.back() != dwarf::DW_OP_stack_value);
1995 bool NeedsStackValue = NeedsDeref || ExprOpsBeforeFragment.empty();
1996
1997 // Append a DW_OP_deref after Expr's current op list if needed, then append
1998 // the new ops, and finally ensure that a single DW_OP_stack_value is present.
2000 if (NeedsDeref)
2001 NewOps.push_back(dwarf::DW_OP_deref);
2002 NewOps.append(Ops.begin(), Ops.end());
2003 if (NeedsStackValue)
2004 NewOps.push_back(dwarf::DW_OP_stack_value);
2005 return DIExpression::append(Expr, NewOps);
2006}
2007
2008std::optional<DIExpression *> DIExpression::createFragmentExpression(
2009 const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits) {
2011 // Track whether it's safe to split the value at the top of the DWARF stack,
2012 // assuming that it'll be used as an implicit location value.
2013 bool CanSplitValue = true;
2014 // Track whether we need to add a fragment expression to the end of Expr.
2015 bool EmitFragment = true;
2016 // Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment.
2017 if (Expr) {
2018 for (auto Op : Expr->expr_ops()) {
2019 switch (Op.getOp()) {
2020 default:
2021 break;
2022 case dwarf::DW_OP_shr:
2023 case dwarf::DW_OP_shra:
2024 case dwarf::DW_OP_shl:
2025 case dwarf::DW_OP_plus:
2026 case dwarf::DW_OP_plus_uconst:
2027 case dwarf::DW_OP_minus:
2028 // We can't safely split arithmetic or shift operations into multiple
2029 // fragments because we can't express carry-over between fragments.
2030 //
2031 // FIXME: We *could* preserve the lowest fragment of a constant offset
2032 // operation if the offset fits into SizeInBits.
2033 CanSplitValue = false;
2034 break;
2035 case dwarf::DW_OP_deref:
2036 case dwarf::DW_OP_deref_size:
2037 case dwarf::DW_OP_deref_type:
2038 case dwarf::DW_OP_xderef:
2039 case dwarf::DW_OP_xderef_size:
2040 case dwarf::DW_OP_xderef_type:
2041 // Preceeding arithmetic operations have been applied to compute an
2042 // address. It's okay to split the value loaded from that address.
2043 CanSplitValue = true;
2044 break;
2045 case dwarf::DW_OP_stack_value:
2046 // Bail if this expression computes a value that cannot be split.
2047 if (!CanSplitValue)
2048 return std::nullopt;
2049 break;
2051 // If we've decided we don't need a fragment then give up if we see that
2052 // there's already a fragment expression.
2053 // FIXME: We could probably do better here
2054 if (!EmitFragment)
2055 return std::nullopt;
2056 // Make the new offset point into the existing fragment.
2057 uint64_t FragmentOffsetInBits = Op.getArg(0);
2058 uint64_t FragmentSizeInBits = Op.getArg(1);
2059 (void)FragmentSizeInBits;
2060 assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&
2061 "new fragment outside of original fragment");
2062 OffsetInBits += FragmentOffsetInBits;
2063 continue;
2064 }
2067 // If we're extracting bits from inside of the fragment that we're
2068 // creating then we don't have a fragment after all, and just need to
2069 // adjust the offset that we're extracting from.
2070 uint64_t ExtractOffsetInBits = Op.getArg(0);
2071 uint64_t ExtractSizeInBits = Op.getArg(1);
2072 if (ExtractOffsetInBits >= OffsetInBits &&
2073 ExtractOffsetInBits + ExtractSizeInBits <=
2074 OffsetInBits + SizeInBits) {
2075 Ops.push_back(Op.getOp());
2076 Ops.push_back(ExtractOffsetInBits - OffsetInBits);
2077 Ops.push_back(ExtractSizeInBits);
2078 EmitFragment = false;
2079 continue;
2080 }
2081 // If the extracted bits aren't fully contained within the fragment then
2082 // give up.
2083 // FIXME: We could probably do better here
2084 return std::nullopt;
2085 }
2086 }
2087 Op.appendToVector(Ops);
2088 }
2089 }
2090 assert((!Expr->isImplicit() || CanSplitValue) && "Expr can't be split");
2091 assert(Expr && "Unknown DIExpression");
2092 if (EmitFragment) {
2094 Ops.push_back(OffsetInBits);
2095 Ops.push_back(SizeInBits);
2096 }
2097 return DIExpression::get(Expr->getContext(), Ops);
2098}
2099
2100/// See declaration for more info.
2102 const DataLayout &DL, const Value *SliceStart, uint64_t SliceOffsetInBits,
2103 uint64_t SliceSizeInBits, const Value *DbgPtr, int64_t DbgPtrOffsetInBits,
2104 int64_t DbgExtractOffsetInBits, DIExpression::FragmentInfo VarFrag,
2105 std::optional<DIExpression::FragmentInfo> &Result,
2106 int64_t &OffsetFromLocationInBits) {
2107
2108 if (VarFrag.SizeInBits == 0)
2109 return false; // Variable size is unknown.
2110
2111 // Difference between mem slice start and the dbg location start.
2112 // 0 4 8 12 16 ...
2113 // | |
2114 // dbg location start
2115 // |
2116 // mem slice start
2117 // Here MemStartRelToDbgStartInBits is 8. Note this can be negative.
2118 int64_t MemStartRelToDbgStartInBits;
2119 {
2120 auto MemOffsetFromDbgInBytes = SliceStart->getPointerOffsetFrom(DbgPtr, DL);
2121 if (!MemOffsetFromDbgInBytes)
2122 return false; // Can't calculate difference in addresses.
2123 // Difference between the pointers.
2124 MemStartRelToDbgStartInBits = *MemOffsetFromDbgInBytes * 8;
2125 // Add the difference of the offsets.
2126 MemStartRelToDbgStartInBits +=
2127 SliceOffsetInBits - (DbgPtrOffsetInBits + DbgExtractOffsetInBits);
2128 }
2129
2130 // Out-param. Invert offset to get offset from debug location.
2131 OffsetFromLocationInBits = -MemStartRelToDbgStartInBits;
2132
2133 // Check if the variable fragment sits outside (before) this memory slice.
2134 int64_t MemEndRelToDbgStart = MemStartRelToDbgStartInBits + SliceSizeInBits;
2135 if (MemEndRelToDbgStart < 0) {
2136 Result = {0, 0}; // Out-param.
2137 return true;
2138 }
2139
2140 // Work towards creating SliceOfVariable which is the bits of the variable
2141 // that the memory region covers.
2142 // 0 4 8 12 16 ...
2143 // | |
2144 // dbg location start with VarFrag offset=32
2145 // |
2146 // mem slice start: SliceOfVariable offset=40
2147 int64_t MemStartRelToVarInBits =
2148 MemStartRelToDbgStartInBits + VarFrag.OffsetInBits;
2149 int64_t MemEndRelToVarInBits = MemStartRelToVarInBits + SliceSizeInBits;
2150 // If the memory region starts before the debug location the fragment
2151 // offset would be negative, which we can't encode. Limit those to 0. This
2152 // is fine because those bits necessarily don't overlap with the existing
2153 // variable fragment.
2154 int64_t MemFragStart = std::max<int64_t>(0, MemStartRelToVarInBits);
2155 int64_t MemFragSize =
2156 std::max<int64_t>(0, MemEndRelToVarInBits - MemFragStart);
2157 DIExpression::FragmentInfo SliceOfVariable(MemFragSize, MemFragStart);
2158
2159 // Intersect the memory region fragment with the variable location fragment.
2160 DIExpression::FragmentInfo TrimmedSliceOfVariable =
2161 DIExpression::FragmentInfo::intersect(SliceOfVariable, VarFrag);
2162 if (TrimmedSliceOfVariable == VarFrag)
2163 Result = std::nullopt; // Out-param.
2164 else
2165 Result = TrimmedSliceOfVariable; // Out-param.
2166 return true;
2167}
2168
2169std::pair<DIExpression *, const ConstantInt *>
2171 // Copy the APInt so we can modify it.
2172 APInt NewInt = CI->getValue();
2174
2175 // Fold operators only at the beginning of the expression.
2176 bool First = true;
2177 bool Changed = false;
2178 for (auto Op : expr_ops()) {
2179 switch (Op.getOp()) {
2180 default:
2181 // We fold only the leading part of the expression; if we get to a part
2182 // that we're going to copy unchanged, and haven't done any folding,
2183 // then the entire expression is unchanged and we can return early.
2184 if (!Changed)
2185 return {this, CI};
2186 First = false;
2187 break;
2189 if (!First)
2190 break;
2191 Changed = true;
2192 if (Op.getArg(1) == dwarf::DW_ATE_signed)
2193 NewInt = NewInt.sextOrTrunc(Op.getArg(0));
2194 else {
2195 assert(Op.getArg(1) == dwarf::DW_ATE_unsigned && "Unexpected operand");
2196 NewInt = NewInt.zextOrTrunc(Op.getArg(0));
2197 }
2198 continue;
2199 }
2200 Op.appendToVector(Ops);
2201 }
2202 if (!Changed)
2203 return {this, CI};
2204 return {DIExpression::get(getContext(), Ops),
2205 ConstantInt::get(getContext(), NewInt)};
2206}
2207
2209 uint64_t Result = 0;
2210 for (auto ExprOp : expr_ops())
2211 if (ExprOp.getOp() == dwarf::DW_OP_LLVM_arg)
2212 Result = std::max(Result, ExprOp.getArg(0) + 1);
2213 assert(hasAllLocationOps(Result) &&
2214 "Expression is missing one or more location operands.");
2215 return Result;
2216}
2217
2218std::optional<DIExpression::SignedOrUnsignedConstant>
2220
2221 // Recognize signed and unsigned constants.
2222 // An signed constants can be represented as DW_OP_consts C DW_OP_stack_value
2223 // (DW_OP_LLVM_fragment of Len).
2224 // An unsigned constant can be represented as
2225 // DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment of Len).
2226
2227 if ((getNumElements() != 2 && getNumElements() != 3 &&
2228 getNumElements() != 6) ||
2229 (getElement(0) != dwarf::DW_OP_consts &&
2230 getElement(0) != dwarf::DW_OP_constu))
2231 return std::nullopt;
2232
2233 if (getNumElements() == 2 && getElement(0) == dwarf::DW_OP_consts)
2235
2236 if ((getNumElements() == 3 && getElement(2) != dwarf::DW_OP_stack_value) ||
2237 (getNumElements() == 6 && (getElement(2) != dwarf::DW_OP_stack_value ||
2239 return std::nullopt;
2240 return getElement(0) == dwarf::DW_OP_constu
2243}
2244
2245DIExpression::ExtOps DIExpression::getExtOps(unsigned FromSize, unsigned ToSize,
2246 bool Signed) {
2247 dwarf::TypeKind TK = Signed ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned;
2249 dwarf::DW_OP_LLVM_convert, ToSize, TK}};
2250 return Ops;
2251}
2252
2254 unsigned FromSize, unsigned ToSize,
2255 bool Signed) {
2256 return appendToStack(Expr, getExtOps(FromSize, ToSize, Signed));
2257}
2258
2260DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable,
2262 bool ShouldCreate) {
2264 Metadata *Ops[] = {Variable, Expression};
2266}
2267DIObjCProperty::DIObjCProperty(LLVMContext &C, StorageType Storage,
2268 unsigned Line, unsigned Attributes,
2270 : DINode(C, DIObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property, Ops),
2272
2273DIObjCProperty *DIObjCProperty::getImpl(
2274 LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
2275 MDString *GetterName, MDString *SetterName, unsigned Attributes,
2276 Metadata *Type, StorageType Storage, bool ShouldCreate) {
2277 assert(isCanonical(Name) && "Expected canonical MDString");
2278 assert(isCanonical(GetterName) && "Expected canonical MDString");
2279 assert(isCanonical(SetterName) && "Expected canonical MDString");
2281 SetterName, Attributes, Type));
2282 Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
2283 DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops);
2284}
2285
2286DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
2287 Metadata *Scope, Metadata *Entity,
2288 Metadata *File, unsigned Line,
2289 MDString *Name, Metadata *Elements,
2290 StorageType Storage,
2291 bool ShouldCreate) {
2292 assert(isCanonical(Name) && "Expected canonical MDString");
2294 (Tag, Scope, Entity, File, Line, Name, Elements));
2295 Metadata *Ops[] = {Scope, Entity, Name, File, Elements};
2297}
2298
2299DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
2300 MDString *Name, MDString *Value, StorageType Storage,
2301 bool ShouldCreate) {
2302 assert(isCanonical(Name) && "Expected canonical MDString");
2304 Metadata *Ops[] = {Name, Value};
2306}
2307
2308DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
2309 unsigned Line, Metadata *File,
2310 Metadata *Elements, StorageType Storage,
2311 bool ShouldCreate) {
2313 Metadata *Ops[] = {File, Elements};
2315}
2316
2319 auto ExistingIt = Context.pImpl->DIArgLists.find_as(DIArgListKeyInfo(Args));
2320 if (ExistingIt != Context.pImpl->DIArgLists.end())
2321 return *ExistingIt;
2322 DIArgList *NewArgList = new DIArgList(Context, Args);
2323 Context.pImpl->DIArgLists.insert(NewArgList);
2324 return NewArgList;
2325}
2326
2328 ValueAsMetadata **OldVMPtr = static_cast<ValueAsMetadata **>(Ref);
2329 assert((!New || isa<ValueAsMetadata>(New)) &&
2330 "DIArgList must be passed a ValueAsMetadata");
2331 untrack();
2332 // We need to update the set storage once the Args are updated since they
2333 // form the key to the DIArgLists store.
2334 getContext().pImpl->DIArgLists.erase(this);
2335 ValueAsMetadata *NewVM = cast_or_null<ValueAsMetadata>(New);
2336 for (ValueAsMetadata *&VM : Args) {
2337 if (&VM == OldVMPtr) {
2338 if (NewVM)
2339 VM = NewVM;
2340 else
2341 VM = ValueAsMetadata::get(PoisonValue::get(VM->getValue()->getType()));
2342 }
2343 }
2344 // We've changed the contents of this DIArgList, and the set storage may
2345 // already contain a DIArgList with our new set of args; if it does, then we
2346 // must RAUW this with the existing DIArgList, otherwise we simply insert this
2347 // back into the set storage.
2348 DIArgList *ExistingArgList = getUniqued(getContext().pImpl->DIArgLists, this);
2349 if (ExistingArgList) {
2350 replaceAllUsesWith(ExistingArgList);
2351 // Clear this here so we don't try to untrack in the destructor.
2352 Args.clear();
2353 delete this;
2354 return;
2355 }
2356 getContext().pImpl->DIArgLists.insert(this);
2357 track();
2358}
2359void DIArgList::track() {
2360 for (ValueAsMetadata *&VAM : Args)
2361 if (VAM)
2362 MetadataTracking::track(&VAM, *VAM, *this);
2363}
2364void DIArgList::untrack() {
2365 for (ValueAsMetadata *&VAM : Args)
2366 if (VAM)
2367 MetadataTracking::untrack(&VAM, *VAM);
2368}
2369void DIArgList::dropAllReferences(bool Untrack) {
2370 if (Untrack)
2371 untrack();
2372 Args.clear();
2373 ReplaceableMetadataImpl::resolveAllUses(/* ResolveUsers */ false);
2374}
static const LLT S1
AMDGPU Kernel Attributes
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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")
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&...Args)
Definition: DIBuilder.cpp:857
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
static const char * ChecksumKindName[DIFile::CSK_Last]
#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS)
static void adjustColumn(unsigned &Column)
#define DEFINE_GETIMPL_STORE_N(CLASS, ARGS, OPS, NUM_OPS)
static bool isCanonical(const MDString *S)
#define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS)
#define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS)
#define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS)
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
static unsigned encodingBits(unsigned C)
Definition: Discriminator.h:49
static unsigned encodeComponent(unsigned C)
Definition: Discriminator.h:45
static unsigned getNextComponentInDiscriminator(unsigned D)
Returns the next component stored in discriminator.
Definition: Discriminator.h:38
static unsigned getUnsignedFromPrefixEncoding(unsigned U)
Reverse transformation as getPrefixEncodingFromUnsigned.
Definition: Discriminator.h:30
This file contains constants used for implementing Dwarf debug support.
std::string Name
uint64_t Size
bool End
Definition: ELF_riscv.cpp:480
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallPtrSet class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
support::ulittle16_t & Lo
Definition: aarch32.cpp:204
Class for arbitrary precision integers.
Definition: APInt.h:78
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
Definition: APInt.cpp:1007
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
Definition: APInt.cpp:1015
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:177
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition: ArrayRef.h:207
iterator end() const
Definition: ArrayRef.h:157
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:168
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
Definition: ArrayRef.h:213
iterator begin() const
Definition: ArrayRef.h:156
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:163
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:532
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
Definition: Constants.h:126
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:148
This is an important base class in LLVM.
Definition: Constant.h:42
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
void handleChangedOperand(void *Ref, Metadata *New)
static DIArgList * get(LLVMContext &Context, ArrayRef< ValueAsMetadata * > Args)
Assignment ID.
Basic type, like 'int' or 'float'.
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags
unsigned StringRef uint64_t SizeInBits
std::optional< Signedness > getSignedness() const
Return the signedness of this type, or std::nullopt if this type is neither signed nor unsigned.
unsigned getEncoding() const
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags unsigned StringRef uint64_t uint32_t unsigned uint32_t NumExtraInhabitants
unsigned StringRef Name
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t AlignInBits
Debug common block.
Metadata Metadata * Decl
Metadata Metadata MDString Metadata unsigned LineNo
Metadata Metadata MDString * Name
Metadata Metadata MDString Metadata * File
static const char * nameTableKindString(DebugNameTableKind PK)
static const char * emissionKindString(DebugEmissionKind EK)
DebugEmissionKind getEmissionKind() const
unsigned Metadata * File
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata * Macros
unsigned Metadata MDString bool MDString * Flags
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata * EnumTypes
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata * RetainedTypes
DebugNameTableKind getNameTableKind() const
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata * GlobalVariables
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString MDString * SDK
unsigned Metadata MDString * Producer
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString * SysRoot
unsigned Metadata MDString bool MDString unsigned MDString * SplitDebugFilename
unsigned Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata * ImportedEntities
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t AlignInBits
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, Metadata *Specification, uint32_t NumExtraInhabitants, DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, std::optional< uint32_t > EnumKind, Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator, Metadata *DataLocation, Metadata *Associated, Metadata *Allocated, Metadata *Rank, Metadata *Annotations)
Build a DICompositeType with the given ODR identifier.
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata * DataLocation
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 std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata * Annotations
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString * Identifier
static DICompositeType * getODRTypeIfExists(LLVMContext &Context, MDString &Identifier)
unsigned MDString * Name
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata * Discriminator
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata * TemplateParams
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 * BaseType
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Flags
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata * Allocated
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata Metadata * Specification
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata * VTableHolder
unsigned MDString Metadata unsigned Metadata Metadata uint64_t SizeInBits
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata * Associated
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata Metadata uint32_t NumExtraInhabitants
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata * Rank
unsigned StringRef DIFile unsigned DIScope DIType * BaseType
unsigned StringRef DIFile unsigned DIScope DIType uint64_t uint32_t uint64_t std::optional< unsigned > std::optional< PtrAuthData > DIFlags Metadata * ExtraData
unsigned StringRef DIFile unsigned DIScope DIType uint64_t SizeInBits
Metadata * getExtraData() const
Get extra data associated with this derived type.
unsigned StringRef DIFile * File
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
DIType * getClassType() const
Get casted version of extra data.
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 > std::optional< PtrAuthData > DIFlags Flags
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.
static bool calculateFragmentIntersect(const DataLayout &DL, const Value *SliceStart, uint64_t SliceOffsetInBits, uint64_t SliceSizeInBits, const Value *DbgPtr, int64_t DbgPtrOffsetInBits, int64_t DbgExtractOffsetInBits, DIExpression::FragmentInfo VarFrag, std::optional< DIExpression::FragmentInfo > &Result, int64_t &OffsetFromLocationInBits)
Computes a fragment, bit-extract operation if needed, and new constant offset to describe a part of a...
element_iterator elements_begin() const
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,...
std::optional< uint64_t > getActiveBits(DIVariable *Var)
Return the number of bits that have an active value, i.e.
static void canonicalizeExpressionOps(SmallVectorImpl< uint64_t > &Ops, const DIExpression *Expr, bool IsIndirect)
Inserts the elements of Expr into Ops modified to a canonical form, which uses DW_OP_LLVM_arg (i....
uint64_t getElement(unsigned I) const
static std::optional< DIExpression * > createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits)
Create a DIExpression to describe one part of an aggregate variable that is fragmented across multipl...
static const DIExpression * convertToUndefExpression(const DIExpression *Expr)
Removes all elements from Expr that do not apply to an undef debug value, which includes every operat...
static DIExpression * prepend(const DIExpression *Expr, uint8_t Flags, int64_t Offset=0)
Prepend DIExpr with a deref and offset operation and optionally turn it into a stack value or/and an ...
static DIExpression * appendToStack(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Convert DIExpr into a stack value if it isn't one already by appending DW_OP_deref if needed,...
static DIExpression * appendExt(const DIExpression *Expr, unsigned FromSize, unsigned ToSize, bool Signed)
Append a zero- or sign-extension to Expr.
std::optional< ArrayRef< uint64_t > > getSingleLocationExpressionElements() const
Returns a reference to the elements contained in this expression, skipping past the leading DW_OP_LLV...
bool isSingleLocationExpression() const
Return whether the evaluated expression makes use of a single location at the start of the expression...
bool extractLeadingOffset(int64_t &OffsetInBytes, SmallVectorImpl< uint64_t > &RemainingOps) const
Assuming that the expression operates on an address, extract a constant offset and the successive ops...
std::optional< SignedOrUnsignedConstant > isConstant() const
Determine whether this represents a constant value, if so.
static const DIExpression * extractAddressClass(const DIExpression *Expr, unsigned &AddrClass)
Checks if the last 4 elements of the expression are DW_OP_constu <DWARF Address Space> DW_OP_swap DW_...
static DIExpression * prependOpcodes(const DIExpression *Expr, SmallVectorImpl< uint64_t > &Ops, bool StackValue=false, bool EntryValue=false)
Prepend DIExpr with the given opcodes and optionally turn it into a stack value.
MDString MDString * Directory
MDString * Filename
static std::optional< ChecksumKind > getChecksumKind(StringRef CSKindStr)
MDString MDString std::optional< ChecksumInfo< MDString * > > CS
Metadata * getRawLowerBound() const
Metadata * getRawCountNode() const
Metadata * getRawStride() const
BoundType getLowerBound() const
Metadata * getRawUpperBound() const
BoundType getUpperBound() const
PointerUnion< DIVariable *, DIExpression * > BoundType
A pair of DIGlobalVariable and DIExpression.
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata Metadata * TemplateParams
Metadata MDString MDString Metadata unsigned Line
Metadata MDString MDString Metadata unsigned Metadata * Type
Metadata MDString * Name
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata * StaticDataMemberDeclaration
Metadata MDString MDString * LinkageName
Metadata MDString MDString Metadata * File
Metadata MDString MDString Metadata unsigned Metadata bool bool Metadata Metadata uint32_t AlignInBits
An imported module (C++ using directive or similar).
unsigned Metadata Metadata * Entity
unsigned Metadata Metadata Metadata unsigned Line
unsigned Metadata Metadata Metadata unsigned MDString * Name
unsigned Metadata Metadata Metadata * File
unsigned Metadata * Scope
Metadata MDString Metadata unsigned Line
Metadata MDString * Name
Metadata MDString Metadata * File
DILexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage, ArrayRef< Metadata * > Ops)
Metadata Metadata unsigned Discriminator
Metadata Metadata * File
Debug lexical block.
Metadata Metadata unsigned Line
Metadata Metadata * File
A scope for locals.
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
DILocalScope * getNonLexicalBlockFileScope() const
Get the first non DILexicalBlockFile scope of this scope.
static DILocalScope * cloneScopeForSubprogram(DILocalScope &RootScope, DISubprogram &NewSP, LLVMContext &Ctx, DenseMap< const MDNode *, MDNode * > &Cache)
Traverses the scope chain rooted at RootScope until it hits a Subprogram, recreating the chain with "...
Metadata MDString Metadata unsigned Metadata * Type
Metadata MDString Metadata * File
Metadata MDString * Name
Metadata MDString Metadata unsigned Line
Metadata MDString Metadata unsigned Metadata unsigned DIFlags uint32_t AlignInBits
Debug location.
unsigned unsigned DILocalScope * Scope
static DILocation * getMergedLocations(ArrayRef< DILocation * > Locs)
Try to combine the vector of locations passed as input in a single one.
static std::optional< unsigned > encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI)
Raw encoding of the discriminator.
unsigned unsigned DILocalScope DILocation bool ImplicitCode
static void decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF, unsigned &CI)
Raw decoder for values in an encoded discriminator D.
static DILocation * getMergedLocation(DILocation *LocA, DILocation *LocB)
When two instructions are combined into a single instruction we also need to combine the original loc...
unsigned unsigned Column
unsigned unsigned DILocalScope DILocation * InlinedAt
unsigned unsigned Metadata * File
unsigned unsigned Line
unsigned unsigned Metadata Metadata * Elements
unsigned unsigned MDString * Name
unsigned unsigned Line
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
Metadata Metadata * Scope
Metadata Metadata MDString * Name
Metadata Metadata MDString MDString MDString MDString * APINotesFile
Metadata Metadata MDString MDString MDString * IncludePath
Metadata Metadata MDString MDString * ConfigurationMacros
Metadata Metadata MDString MDString MDString MDString unsigned LineNo
Debug lexical block.
Metadata MDString bool ExportSymbols
Metadata MDString * Name
Tagged DWARF-like metadata node.
dwarf::Tag getTag() const
static DIFlags getFlag(StringRef Flag)
static DIFlags splitFlags(DIFlags Flags, SmallVectorImpl< DIFlags > &SplitFlags)
Split up a flags bitfield.
static StringRef getFlagString(DIFlags Flag)
DIFlags
Debug info flags.
MDString Metadata * File
MDString Metadata unsigned MDString * GetterName
MDString Metadata unsigned MDString MDString * SetterName
Base class for scope-like contexts.
StringRef getName() const
DIScope * getScope() const
String type, Fortran CHARACTER(n)
unsigned MDString * Name
unsigned MDString Metadata Metadata Metadata uint64_t SizeInBits
unsigned MDString Metadata Metadata Metadata uint64_t uint32_t AlignInBits
unsigned MDString Metadata Metadata Metadata * StringLocationExp
unsigned MDString Metadata Metadata * StringLengthExp
unsigned MDString Metadata * StringLength
Subprogram description.
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata * Unit
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata Metadata * Annotations
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata * ContainingType
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata * TemplateParams
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata * Declaration
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata Metadata MDString * TargetFuncName
static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized, unsigned Virtuality=SPFlagNonvirtual, bool IsMainSubprogram=false)
Metadata MDString * Name
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata * ThrownTypes
static DISPFlags getFlag(StringRef Flag)
Metadata MDString MDString Metadata * File
static DISPFlags splitFlags(DISPFlags Flags, SmallVectorImpl< DISPFlags > &SplitFlags)
Split up a flags bitfield for easier printing.
Metadata MDString MDString * LinkageName
static StringRef getFlagString(DISPFlags Flag)
Metadata MDString MDString Metadata unsigned Metadata * Type
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata * RetainedNodes
DISPFlags
Debug info subprogram flags.
Array subrange.
BoundType getUpperBound() const
BoundType getStride() const
BoundType getLowerBound() const
BoundType getCount() const
Type array for a subprogram.
DIFlags uint8_t Metadata * TypeArray
Base class for template parameters.
unsigned MDString Metadata * Type
Base class for types.
bool isBitField() const
bool isStaticMember() const
uint32_t getAlignInBits() const
Base class for variables.
std::optional< DIBasicType::Signedness > getSignedness() const
Return the signedness of this variable's type, or std::nullopt if this type is neither signed nor uns...
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 class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
This is the common base class for debug info intrinsics for variables.
Record of a variable value-assignment, aka a non instruction representation of the dbg....
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:156
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Definition: DenseMap.h:226
iterator end()
Definition: DenseMap.h:84
Class representing an expression and its matching format.
Generic tagged DWARF-like metadata node.
dwarf::Tag getTag() const
unsigned MDString * Header
unsigned MDString ArrayRef< Metadata * > DwarfOps
DenseSet< DIArgList *, DIArgListInfo > DIArgLists
std::optional< DenseMap< const MDString *, DICompositeType * > > DITypeMap
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
bool isODRUniquingDebugTypes() const
Whether there is a string map for uniquing debug info identifiers across the context.
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:69
Metadata node.
Definition: Metadata.h:1073
friend class DIAssignID
Definition: Metadata.h:1076
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1557
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1549
TempMDNode clone() const
Create a (temporary) clone of this.
Definition: Metadata.cpp:667
static T * storeImpl(T *N, StorageType Storage, StoreT &Store)
Definition: MetadataImpl.h:42
LLVMContext & getContext() const
Definition: Metadata.h:1237
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:1305
A single uniqued string.
Definition: Metadata.h:724
StringRef getString() const
Definition: Metadata.cpp:616
static void untrack(Metadata *&MD)
Stop tracking a reference to metadata.
Definition: Metadata.h:353
static bool track(Metadata *&MD)
Track the reference to metadata.
Definition: Metadata.h:319
Root of the metadata hierarchy.
Definition: Metadata.h:62
StorageType
Active type of storage.
Definition: Metadata.h:70
unsigned short SubclassData16
Definition: Metadata.h:76
unsigned SubclassData32
Definition: Metadata.h:77
unsigned char Storage
Storage flag for non-uniqued, otherwise unowned, metadata.
Definition: Metadata.h:73
unsigned char SubclassData1
Definition: Metadata.h:75
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:118
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1878
void replaceAllUsesWith(Metadata *MD)
Replace all uses of this with MD.
Definition: Metadata.cpp:367
LLVMContext & getContext() const
Definition: Metadata.h:404
void resolveAllUses(bool ResolveUsers=true)
Resolve all uses of this.
Definition: Metadata.cpp:420
Implements a dense probed hash-table based set with some number of buckets stored inline.
Definition: DenseSet.h:298
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:519
bool empty() const
Definition: SmallVector.h:81
size_t size() const
Definition: SmallVector.h:78
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
void reserve(size_type N)
Definition: SmallVector.h:663
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:683
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:805
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:43
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:68
R Default(T Value)
Definition: StringSwitch.h:177
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:454
static ValueAsMetadata * get(Value *V)
Definition: Metadata.cpp:501
LLVM Value Representation.
Definition: Value.h:74
std::optional< int64_t > getPointerOffsetFrom(const Value *Other, const DataLayout &DL) const
If this ptr is provably equal to Other plus a constant offset, return that offset in bytes.
Definition: Value.cpp:1047
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:213
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
Definition: DenseSet.h:193
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:146
@ DW_OP_LLVM_implicit_pointer
Only used in LLVM metadata.
Definition: Dwarf.h:147
@ DW_OP_LLVM_extract_bits_zext
Only used in LLVM metadata.
Definition: Dwarf.h:150
@ DW_OP_LLVM_tag_offset
Only used in LLVM metadata.
Definition: Dwarf.h:145
@ DW_OP_LLVM_fragment
Only used in LLVM metadata.
Definition: Dwarf.h:143
@ DW_OP_LLVM_arg
Only used in LLVM metadata.
Definition: Dwarf.h:148
@ DW_OP_LLVM_convert
Only used in LLVM metadata.
Definition: Dwarf.h:144
@ DW_OP_LLVM_extract_bits_sext
Only used in LLVM metadata.
Definition: Dwarf.h:149
@ DW_VIRTUALITY_max
Definition: Dwarf.h:199
@ NameTableKind
Definition: LLToken.h:494
@ EmissionKind
Definition: LLToken.h:493
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition: STLExtras.h:329
@ Offset
Definition: DWP.cpp:480
static T * getUniqued(DenseSet< T *, InfoT > &Store, const typename InfoT::KeyTy &Key)
Definition: MetadataImpl.h:22
cl::opt< bool > EnableFSDiscriminator
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1746
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:420
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:1753
@ Ref
The access may reference the value stored in memory.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
#define N
A single checksum, represented by a Kind and a Value (a string).
static DbgVariableFragmentInfo intersect(DbgVariableFragmentInfo A, DbgVariableFragmentInfo B)
Returns a zero-sized fragment if A and B don't intersect.