LLVM 24.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 "IROptions.h"
15#include "LLVMContextImpl.h"
16#include "MetadataImpl.h"
17#include "llvm/ADT/DenseSet.h"
18#include "llvm/ADT/SetVector.h"
22#include "llvm/IR/Function.h"
24#include "llvm/IR/Type.h"
25#include "llvm/IR/Value.h"
27
28#include <numeric>
29#include <optional>
30#include <tuple>
31
32using namespace llvm;
33
34namespace llvm {
35// Use FS-AFDO discriminator.
37 "enable-fs-discriminator", cl::Hidden,
38 cl::desc("Enable adding flow sensitive discriminators"));
39} // namespace llvm
40
42 return (getTag() == dwarf::DW_TAG_LLVM_ptrauth_type ? 0 : SubclassData32);
43}
44
45const DIExpression::FragmentInfo DebugVariable::DefaultFragment = {
46 std::numeric_limits<uint64_t>::max(), std::numeric_limits<uint64_t>::min()};
47
49 : Variable(DVR->getVariable()),
50 Fragment(DVR->getExpression()->getFragmentInfo()),
51 InlinedAt(DVR->getDebugLoc().getInlinedAt()) {}
52
56
57DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
58 unsigned Column, uint64_t AtomGroup, uint8_t AtomRank,
59 bool HasIRLayers, ArrayRef<Metadata *> MDs,
60 bool ImplicitCode)
61 : MDNode(C, DILocationKind, Storage, MDs), AtomGroup(AtomGroup),
62 AtomRank(AtomRank), HasIRLayers(HasIRLayers) {
63 assert(AtomRank <= 7 && "AtomRank number should fit in 3 bits");
64 assert(AtomGroup < (1ULL << 60) && "AtomGroup number should fit in 60 bits");
65 if (AtomGroup)
66 C.updateDILocationAtomGroupWaterline(AtomGroup + 1);
67
68 assert(MDs.size() >= 1 && MDs.size() <= 3 &&
69 "Expected a scope and optional inlined-at + irlayers");
70 // Set line and column.
71 assert(Column < (1u << 16) && "Expected 16-bit column");
72
73 SubclassData32 = Line;
74 SubclassData16 = Column;
75
76 setImplicitCode(ImplicitCode);
77}
78
79static void adjustColumn(unsigned &Column) {
80 // Set to unknown on overflow. We only have 16 bits to play with here.
81 if (Column >= (1u << 16))
82 Column = 0;
83}
84
85DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
86 unsigned Column, Metadata *Scope,
87 Metadata *InlinedAt, bool ImplicitCode,
88 uint64_t AtomGroup, uint8_t AtomRank,
89 Metadata *IRLayers, StorageType Storage,
90 bool ShouldCreate) {
91 // Fixup column.
93
94 // Clamp rather than truncate, which would wrap into a different valid group.
95 if (AtomGroup >= (1ULL << 60))
96 AtomGroup = 0;
97
98 if (Storage == Uniqued) {
99 if (auto *N = getUniqued(
100 Context.pImpl->DILocations,
101 DILocationInfo::KeyTy(Line, Column, Scope, InlinedAt, ImplicitCode,
102 AtomGroup, AtomRank, IRLayers)))
103 return N;
104 if (!ShouldCreate)
105 return nullptr;
106 } else {
107 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
108 }
109
111 Ops.push_back(Scope);
112 if (InlinedAt)
113 Ops.push_back(InlinedAt);
114 if (IRLayers)
115 Ops.push_back(IRLayers);
116 return storeImpl(new (Ops.size(), Storage) DILocation(
117 Context, Storage, Line, Column, AtomGroup, AtomRank,
118 /*HasIRLayers=*/IRLayers != nullptr, Ops, ImplicitCode),
119 Storage, Context.pImpl->DILocations);
120}
121
122DILayerLoc *DILayerLoc::getImpl(LLVMContext &Context, MDString *Kind,
123 Metadata *File, unsigned Line, unsigned Column,
124 StorageType Storage, bool ShouldCreate) {
125 // Clamp an out-of-range column to 0 (the 16-bit SubclassData limit), as
126 // DILocation::getImpl does; the ctor otherwise asserts and release builds
127 // truncate.
128 adjustColumn(Column);
129 if (Storage == Uniqued) {
130 if (auto *N = getUniqued(Context.pImpl->DILayerLocs,
131 DILayerLocInfo::KeyTy(Kind, File, Line, Column)))
132 return N;
133 if (!ShouldCreate)
134 return nullptr;
135 }
136 Metadata *Ops[] = {Kind, File};
137 return storeImpl(new (std::size(Ops), Storage)
138 DILayerLoc(Context, Storage, Line, Column, Ops),
139 Storage, Context.pImpl->DILayerLocs);
140}
141
142DILayerLocList *DILayerLocList::getImpl(LLVMContext &Context,
144 StorageType Storage,
145 bool ShouldCreate) {
146 unsigned Hash = 0;
147 if (Storage == Uniqued) {
148 DILayerLocListInfo::KeyTy Key(Layers);
149 if (auto *N = getUniqued(Context.pImpl->DILayerLocLists, Key))
150 return N;
151 if (!ShouldCreate)
152 return nullptr;
153 Hash = Key.getHash();
154 } else {
155 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
156 }
157 return storeImpl(new (Layers.size(), Storage)
158 DILayerLocList(Context, Storage, Hash, Layers),
159 Storage, Context.pImpl->DILayerLocLists);
160}
161
162void DILayerLocList::recalculateHash() {
163 setHash(DILayerLocListInfo::KeyTy::calculateHash(this));
164}
165
167 if (Locs.empty())
168 return nullptr;
169 if (Locs.size() == 1)
170 return Locs[0];
171 auto *Merged = Locs[0];
172 for (DILocation *L : llvm::drop_begin(Locs)) {
173 Merged = getMergedLocation(Merged, L);
174 if (Merged == nullptr)
175 break;
176 }
177 return Merged;
178}
179
181 DIScope *NewParent) {
182 TempMDNode ClonedScope = LBB->clone();
183 cast<DILexicalBlockBase>(*ClonedScope).replaceScope(NewParent);
185 MDNode::replaceWithUniqued(std::move(ClonedScope)));
186}
187
188using LineColumn = std::pair<unsigned /* Line */, unsigned /* Column */>;
189
190/// Returns the location of DILocalScope, if present, or a default value.
192 assert(isa<DILocalScope>(S) && "Expected DILocalScope.");
193
195 return Default;
196 if (auto *LB = dyn_cast<DILexicalBlock>(S))
197 return {LB->getLine(), LB->getColumn()};
198 if (auto *SP = dyn_cast<DISubprogram>(S))
199 return {SP->getLine(), 0u};
200
201 llvm_unreachable("Unhandled type of DILocalScope.");
202}
203
204// Returns the nearest matching scope inside a subprogram.
205template <typename MatcherT>
206static std::pair<DIScope *, LineColumn>
208 MatcherT Matcher;
209
210 DIScope *S1 = L1->getScope();
211 DIScope *S2 = L2->getScope();
212
213 LineColumn Loc1(L1->getLine(), L1->getColumn());
214 for (; S1; S1 = S1->getScope()) {
215 Loc1 = getLocalScopeLocationOr(S1, Loc1);
216 Matcher.insert(S1, Loc1);
218 break;
219 }
220
221 LineColumn Loc2(L2->getLine(), L2->getColumn());
222 for (; S2; S2 = S2->getScope()) {
223 Loc2 = getLocalScopeLocationOr(S2, Loc2);
224
225 if (DIScope *S = Matcher.match(S2, Loc2))
226 return std::make_pair(S, Loc2);
227
228 if (isa<DISubprogram>(S2))
229 break;
230 }
231 return std::make_pair(nullptr, LineColumn(L2->getLine(), L2->getColumn()));
232}
233
234// Matches equal scopes.
237
238 void insert(DIScope *S, LineColumn Loc) { Scopes.insert(S); }
239
241 return Scopes.contains(S) ? S : nullptr;
242 }
243};
244
245// Matches scopes with the same location.
248 8>
250
252 Scopes[{S->getFile(), Loc}].insert(S);
253 }
254
256 auto ScopesAtLoc = Scopes.find({S->getFile(), Loc});
257 // No scope found with the given location.
258 if (ScopesAtLoc == Scopes.end())
259 return nullptr;
260
261 // Prefer S over other scopes with the same location.
262 if (ScopesAtLoc->second.contains(S))
263 return S;
264
265 if (!ScopesAtLoc->second.empty())
266 return *ScopesAtLoc->second.begin();
267
268 llvm_unreachable("Scopes must not have empty entries.");
269 }
270};
271
272// Returns a uniqued DILayerLocList holding the intersection of LocA's and
273// LocB's layer sets, or null if either has no layers or they share none.
274// Entries keep LocA's relative order: LLVM assigns no meaning to layer order,
275// but it is part of a list's identity and visible to consumers, so preserve
276// rather than sort.
278 const DILocation *LocB) {
279 DILayerLocList *LA = LocA->getIRLayers();
280 DILayerLocList *LB = LocB->getIRLayers();
281 if (!LA || !LB)
282 return nullptr;
283 // Entries match on their fields rather than by pointer: DILayerLocs are
284 // uniqued, but `distinct` ones are legal and must not look disjoint. Keying
285 // on the fields also keeps the intersection linear in the two list lengths.
286 using LayerKey = std::tuple<Metadata *, Metadata *, unsigned, unsigned>;
287 auto keyOf = [](const DILayerLoc *L) {
288 return LayerKey(L->getRawKind(), L->getRawFile(), L->getLine(),
289 L->getColumn());
290 };
292 for (const MDOperand &Op : LB->layers())
293 BLayers.insert(keyOf(cast<DILayerLoc>(Op.get())));
295 for (const MDOperand &Op : LA->layers()) {
296 auto *L = cast<DILayerLoc>(Op.get());
297 if (BLayers.contains(keyOf(L)))
298 Keep.push_back(L);
299 }
300 if (Keep.empty())
301 return nullptr;
302 return DILayerLocList::get(C, Keep);
303}
304
305DILocation *DILocation::getMergedLocation(DILocation *LocA, DILocation *LocB) {
306 if (LocA == LocB)
307 return LocA;
308
309 // For some use cases (SamplePGO), it is important to retain distinct source
310 // locations. When this flag is set, we choose arbitrarily between A and B,
311 // rather than computing a merged location using line 0, which is typically
312 // not useful for PGO. If one of them is null, then try to return one which is
313 // valid.
314 DILocation *Loc = LocA ? LocA : LocB;
315 if (getIROptions(Loc->getContext()).pick_merged_source_locations) {
316 if (!LocA || !LocB)
317 return Loc;
318
319 auto A = std::make_tuple(LocA->getLine(), LocA->getColumn(),
320 LocA->getDiscriminator(), LocA->getFilename(),
321 LocA->getDirectory());
322 auto B = std::make_tuple(LocB->getLine(), LocB->getColumn(),
323 LocB->getDiscriminator(), LocB->getFilename(),
324 LocB->getDirectory());
325 return A < B ? LocA : LocB;
326 }
327
328 if (!LocA || !LocB)
329 return nullptr;
330
331 LLVMContext &C = LocA->getContext();
332
333 using LocVec = SmallVector<const DILocation *>;
334 LocVec ALocs;
335 LocVec BLocs;
337 4>
338 ALookup;
339
340 // Walk through LocA and its inlined-at locations, populate them in ALocs and
341 // save the index for the subprogram and inlined-at pair, which we use to find
342 // a matching starting location in LocB's chain.
343 for (auto [L, I] = std::make_pair(LocA, 0U); L; L = L->getInlinedAt(), I++) {
344 ALocs.push_back(L);
345 auto Res = ALookup.try_emplace(
346 {L->getScope()->getSubprogram(), L->getInlinedAt()}, I);
347 assert(Res.second && "Multiple <SP, InlinedAt> pairs in a location chain?");
348 (void)Res;
349 }
350
351 LocVec::reverse_iterator ARIt = ALocs.rend();
352 LocVec::reverse_iterator BRIt = BLocs.rend();
353
354 // Populate BLocs and look for a matching starting location, the first
355 // location with the same subprogram and inlined-at location as in LocA's
356 // chain. Since the two locations have the same inlined-at location we do
357 // not need to look at those parts of the chains.
358 for (auto [L, I] = std::make_pair(LocB, 0U); L; L = L->getInlinedAt(), I++) {
359 BLocs.push_back(L);
360
361 if (ARIt != ALocs.rend())
362 // We have already found a matching starting location.
363 continue;
364
365 auto IT = ALookup.find({L->getScope()->getSubprogram(), L->getInlinedAt()});
366 if (IT == ALookup.end())
367 continue;
368
369 // The + 1 is to account for the &*rev_it = &(it - 1) relationship.
370 ARIt = LocVec::reverse_iterator(ALocs.begin() + IT->second + 1);
371 BRIt = LocVec::reverse_iterator(BLocs.begin() + I + 1);
372
373 // If we have found a matching starting location we do not need to add more
374 // locations to BLocs, since we will only look at location pairs preceding
375 // the matching starting location, and adding more elements to BLocs could
376 // invalidate the iterator that we initialized here.
377 break;
378 }
379
380 // Merge the two locations if possible, using the supplied
381 // inlined-at location for the created location.
382 auto *LocAIA = LocA->getInlinedAt();
383 auto *LocBIA = LocB->getInlinedAt();
384 auto MergeLocPair = [&C, LocAIA,
385 LocBIA](const DILocation *L1, const DILocation *L2,
386 DILocation *InlinedAt) -> DILocation * {
387 if (L1 == L2)
388 return DILocation::get(C, L1->getLine(), L1->getColumn(), L1->getScope(),
389 InlinedAt, L1->isImplicitCode(),
390 L1->getAtomGroup(), L1->getAtomRank(),
391 L1->getRawIRLayers());
392
393 // If the locations originate from different subprograms we can't produce
394 // a common location.
395 if (L1->getScope()->getSubprogram() != L2->getScope()->getSubprogram())
396 return nullptr;
397
398 // Each merged location keeps the intersection of the two inputs'
399 // intermediate-IR layer sets, so a layer common to both survives.
400 Metadata *MergedLayers = mergeIRLayers(C, L1, L2);
401
402 // Find nearest common scope inside subprogram.
404 assert(Scope && "No common scope in the same subprogram?");
405
406 // Try using the nearest scope with common location if files are different.
407 if (Scope->getFile() != L1->getFile() || L1->getFile() != L2->getFile()) {
408 auto [CommonLocScope, CommonLoc] =
410
411 // If CommonLocScope is a DILexicalBlockBase, clone it and locate
412 // a new scope inside the nearest common scope to preserve
413 // lexical blocks structure.
414 if (auto *LBB = dyn_cast<DILexicalBlockBase>(CommonLocScope);
415 LBB && LBB != Scope)
416 CommonLocScope = cloneAndReplaceParentScope(LBB, Scope);
417
418 Scope = CommonLocScope;
419
420 // If files are still different, assume that L1 and L2 were "included"
421 // from CommonLoc. Use it as merged location.
422 if (Scope->getFile() != L1->getFile() || L1->getFile() != L2->getFile())
423 return DILocation::get(C, CommonLoc.first, CommonLoc.second,
424 CommonLocScope, InlinedAt,
425 /*ImplicitCode=*/false, /*AtomGroup=*/0,
426 /*AtomRank=*/0, MergedLayers);
427 }
428
429 bool SameLine = L1->getLine() == L2->getLine();
430 bool SameCol = L1->getColumn() == L2->getColumn();
431 unsigned Line = SameLine ? L1->getLine() : 0;
432 unsigned Col = SameLine && SameCol ? L1->getColumn() : 0;
433 bool IsImplicitCode = L1->isImplicitCode() && L2->isImplicitCode();
434
435 // Discard source location atom if the line becomes 0. And there's nothing
436 // further to do if neither location has an atom number.
437 if (!SameLine || !(L1->getAtomGroup() || L2->getAtomGroup()))
438 return DILocation::get(C, Line, Col, Scope, InlinedAt, IsImplicitCode,
439 /*AtomGroup*/ 0, /*AtomRank*/ 0, MergedLayers);
440
441 uint64_t Group = 0;
442 uint64_t Rank = 0;
443 // If we're preserving the same matching inlined-at field we can
444 // preserve the atom.
445 if (LocBIA == LocAIA && InlinedAt == LocBIA) {
446 // Deterministically keep the lowest non-zero ranking atom group
447 // number.
448 // FIXME: It would be nice if we could track that an instruction
449 // belongs to two source atoms.
450 bool UseL1Atom = [L1, L2]() {
451 if (L1->getAtomRank() == L2->getAtomRank()) {
452 // Arbitrarily choose the lowest non-zero group number.
453 if (!L1->getAtomGroup() || !L2->getAtomGroup())
454 return !L2->getAtomGroup();
455 return L1->getAtomGroup() < L2->getAtomGroup();
456 }
457 // Choose the lowest non-zero rank.
458 if (!L1->getAtomRank() || !L2->getAtomRank())
459 return !L2->getAtomRank();
460 return L1->getAtomRank() < L2->getAtomRank();
461 }();
462 Group = UseL1Atom ? L1->getAtomGroup() : L2->getAtomGroup();
463 Rank = UseL1Atom ? L1->getAtomRank() : L2->getAtomRank();
464 } else {
465 // If either instruction is part of a source atom, reassign it a new
466 // atom group. This essentially regresses to non-key-instructions
467 // behaviour (now that it's the only instruction in its group it'll
468 // probably get is_stmt applied).
469 Group = C.incNextDILocationAtomGroup();
470 Rank = 1;
471 }
472 return DILocation::get(C, Line, Col, Scope, InlinedAt, IsImplicitCode,
473 Group, Rank, MergedLayers);
474 };
475
476 DILocation *Result = ARIt != ALocs.rend() ? (*ARIt)->getInlinedAt() : nullptr;
477
478 // If we have found a common starting location, walk up the inlined-at chains
479 // and try to produce common locations.
480 for (; ARIt != ALocs.rend() && BRIt != BLocs.rend(); ++ARIt, ++BRIt) {
481 DILocation *Tmp = MergeLocPair(*ARIt, *BRIt, Result);
482
483 if (!Tmp)
484 // We have walked up to a point in the chains where the two locations
485 // are irreconsilable. At this point Result contains the nearest common
486 // location in the inlined-at chains of LocA and LocB, so we break here.
487 break;
488
489 Result = Tmp;
490 }
491
492 if (Result)
493 return Result;
494
495 // We ended up with LocA and LocB as irreconsilable locations. Produce a
496 // location at 0:0 with one of the locations' scope. The function has
497 // historically picked A's scope, and a nullptr inlined-at location, so that
498 // behavior is mimicked here but I am not sure if this is always the correct
499 // way to handle this.
500 // Key Instructions: it's fine to drop atom group and rank here, as line 0
501 // is a nonsensical is_stmt location.
502 return DILocation::get(C, 0, 0, LocA->getScope(), nullptr, false,
503 /*AtomGroup*/ 0, /*AtomRank*/ 0);
504}
505
506std::optional<unsigned>
507DILocation::encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI) {
508 std::array<unsigned, 3> Components = {BD, DF, CI};
509 uint64_t RemainingWork = 0U;
510 // We use RemainingWork to figure out if we have no remaining components to
511 // encode. For example: if BD != 0 but DF == 0 && CI == 0, we don't need to
512 // encode anything for the latter 2.
513 // Since any of the input components is at most 32 bits, their sum will be
514 // less than 34 bits, and thus RemainingWork won't overflow.
515 RemainingWork =
516 std::accumulate(Components.begin(), Components.end(), RemainingWork);
517
518 int I = 0;
519 unsigned Ret = 0;
520 unsigned NextBitInsertionIndex = 0;
521 while (RemainingWork > 0) {
522 unsigned C = Components[I++];
523 RemainingWork -= C;
524 unsigned EC = encodeComponent(C);
525 Ret |= (EC << NextBitInsertionIndex);
526 NextBitInsertionIndex += encodingBits(C);
527 }
528
529 // Encoding may be unsuccessful because of overflow. We determine success by
530 // checking equivalence of components before & after encoding. Alternatively,
531 // we could determine Success during encoding, but the current alternative is
532 // simpler.
533 unsigned TBD, TDF, TCI = 0;
534 decodeDiscriminator(Ret, TBD, TDF, TCI);
535 if (TBD == BD && TDF == DF && TCI == CI)
536 return Ret;
537 return std::nullopt;
538}
539
548
550 return StringSwitch<DIFlags>(Flag)
551#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
552#include "llvm/IR/DebugInfoFlags.def"
553 .Default(DINode::FlagZero);
554}
555
557 switch (Flag) {
558#define HANDLE_DI_FLAG(ID, NAME) \
559 case Flag##NAME: \
560 return "DIFlag" #NAME;
561#include "llvm/IR/DebugInfoFlags.def"
562 }
563 return "";
564}
565
567 SmallVectorImpl<DIFlags> &SplitFlags) {
568 // Flags that are packed together need to be specially handled, so
569 // that, for example, we emit "DIFlagPublic" and not
570 // "DIFlagPrivate | DIFlagProtected".
571 if (DIFlags A = Flags & FlagAccessibility) {
572 if (A == FlagPrivate)
573 SplitFlags.push_back(FlagPrivate);
574 else if (A == FlagProtected)
575 SplitFlags.push_back(FlagProtected);
576 else
577 SplitFlags.push_back(FlagPublic);
578 Flags &= ~A;
579 }
580 if (DIFlags R = Flags & FlagPtrToMemberRep) {
581 if (R == FlagSingleInheritance)
582 SplitFlags.push_back(FlagSingleInheritance);
583 else if (R == FlagMultipleInheritance)
584 SplitFlags.push_back(FlagMultipleInheritance);
585 else
586 SplitFlags.push_back(FlagVirtualInheritance);
587 Flags &= ~R;
588 }
589 if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) {
590 Flags &= ~FlagIndirectVirtualBase;
591 SplitFlags.push_back(FlagIndirectVirtualBase);
592 }
593
594#define HANDLE_DI_FLAG(ID, NAME) \
595 if (DIFlags Bit = Flags & Flag##NAME) { \
596 SplitFlags.push_back(Bit); \
597 Flags &= ~Bit; \
598 }
599#include "llvm/IR/DebugInfoFlags.def"
600 return Flags;
601}
602
604 if (auto *T = dyn_cast<DIType>(this))
605 return T->getScope();
606
607 if (auto *SP = dyn_cast<DISubprogram>(this))
608 return SP->getScope();
609
610 if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
611 return LB->getScope();
612
613 if (auto *NS = dyn_cast<DINamespace>(this))
614 return NS->getScope();
615
616 if (auto *CB = dyn_cast<DICommonBlock>(this))
617 return CB->getScope();
618
619 if (auto *M = dyn_cast<DIModule>(this))
620 return M->getScope();
621
622 assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&
623 "Unhandled type of scope.");
624 return nullptr;
625}
626
628 if (auto *T = dyn_cast<DIType>(this))
629 return T->getName();
630 if (auto *SP = dyn_cast<DISubprogram>(this))
631 return SP->getName();
632 if (auto *NS = dyn_cast<DINamespace>(this))
633 return NS->getName();
634 if (auto *CB = dyn_cast<DICommonBlock>(this))
635 return CB->getName();
636 if (auto *M = dyn_cast<DIModule>(this))
637 return M->getName();
639 isa<DICompileUnit>(this)) &&
640 "Unhandled type of scope.");
641 return "";
642}
643
644#ifndef NDEBUG
645static bool isCanonical(const MDString *S) {
646 return !S || !S->getString().empty();
647}
648#endif
649
651GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
652 MDString *Header,
653 ArrayRef<Metadata *> DwarfOps,
654 StorageType Storage, bool ShouldCreate) {
655 unsigned Hash = 0;
656 if (Storage == Uniqued) {
657 GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps);
658 if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
659 return N;
660 if (!ShouldCreate)
661 return nullptr;
662 Hash = Key.getHash();
663 } else {
664 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
665 }
666
667 // Use a nullptr for empty headers.
668 assert(isCanonical(Header) && "Expected canonical MDString");
669 Metadata *PreOps[] = {Header};
670 return storeImpl(new (DwarfOps.size() + 1, Storage) GenericDINode(
671 Context, Storage, Hash, Tag, PreOps, DwarfOps),
672 Storage, Context.pImpl->GenericDINodes);
673}
674
675void GenericDINode::recalculateHash() {
676 setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
677}
678
679#define UNWRAP_ARGS_IMPL(...) __VA_ARGS__
680#define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS
681#define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS) \
682 do { \
683 if (Storage == Uniqued) { \
684 if (auto *N = getUniqued(Context.pImpl->CLASS##s, \
685 CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS)))) \
686 return N; \
687 if (!ShouldCreate) \
688 return nullptr; \
689 } else { \
690 assert(ShouldCreate && \
691 "Expected non-uniqued nodes to always be created"); \
692 } \
693 } while (false)
694#define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS) \
695 return storeImpl(new (std::size(OPS), Storage) \
696 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
697 Storage, Context.pImpl->CLASS##s)
698#define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS) \
699 return storeImpl(new (0u, Storage) \
700 CLASS(Context, Storage, UNWRAP_ARGS(ARGS)), \
701 Storage, Context.pImpl->CLASS##s)
702#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS) \
703 return storeImpl(new (std::size(OPS), Storage) CLASS(Context, Storage, OPS), \
704 Storage, Context.pImpl->CLASS##s)
705#define DEFINE_GETIMPL_STORE_N(CLASS, ARGS, OPS, NUM_OPS) \
706 return storeImpl(new (NUM_OPS, Storage) \
707 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
708 Storage, Context.pImpl->CLASS##s)
709
710DISubrange::DISubrange(LLVMContext &C, StorageType Storage,
712 : DINode(C, DISubrangeKind, Storage, dwarf::DW_TAG_subrange_type, Ops) {}
713DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
714 StorageType Storage, bool ShouldCreate) {
717 auto *LB = ConstantAsMetadata::get(
719 return getImpl(Context, CountNode, LB, nullptr, nullptr, Storage,
720 ShouldCreate);
721}
722
723DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
724 int64_t Lo, StorageType Storage,
725 bool ShouldCreate) {
726 auto *LB = ConstantAsMetadata::get(
728 return getImpl(Context, CountNode, LB, nullptr, nullptr, Storage,
729 ShouldCreate);
730}
731
732DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
733 Metadata *LB, Metadata *UB, Metadata *Stride,
734 StorageType Storage, bool ShouldCreate) {
735 DEFINE_GETIMPL_LOOKUP(DISubrange, (CountNode, LB, UB, Stride));
736 Metadata *Ops[] = {CountNode, LB, UB, Stride};
738}
739
740DISubrange::BoundType DISubrange::getCount() const {
741 Metadata *CB = getRawCountNode();
742 if (!CB)
743 return BoundType();
744
746 isa<DIExpression>(CB)) &&
747 "Count must be signed constant or DIVariable or DIExpression");
748
749 if (auto *MD = dyn_cast<ConstantAsMetadata>(CB))
750 return BoundType(cast<ConstantInt>(MD->getValue()));
751
752 if (auto *MD = dyn_cast<DIVariable>(CB))
753 return BoundType(MD);
754
755 if (auto *MD = dyn_cast<DIExpression>(CB))
756 return BoundType(MD);
757
758 return BoundType();
759}
760
761DISubrange::BoundType DISubrange::getLowerBound() const {
762 Metadata *LB = getRawLowerBound();
763 if (!LB)
764 return BoundType();
765
767 isa<DIExpression>(LB)) &&
768 "LowerBound must be signed constant or DIVariable or DIExpression");
769
770 if (auto *MD = dyn_cast<ConstantAsMetadata>(LB))
771 return BoundType(cast<ConstantInt>(MD->getValue()));
772
773 if (auto *MD = dyn_cast<DIVariable>(LB))
774 return BoundType(MD);
775
776 if (auto *MD = dyn_cast<DIExpression>(LB))
777 return BoundType(MD);
778
779 return BoundType();
780}
781
782DISubrange::BoundType DISubrange::getUpperBound() const {
783 Metadata *UB = getRawUpperBound();
784 if (!UB)
785 return BoundType();
786
788 isa<DIExpression>(UB)) &&
789 "UpperBound must be signed constant or DIVariable or DIExpression");
790
791 if (auto *MD = dyn_cast<ConstantAsMetadata>(UB))
792 return BoundType(cast<ConstantInt>(MD->getValue()));
793
794 if (auto *MD = dyn_cast<DIVariable>(UB))
795 return BoundType(MD);
796
797 if (auto *MD = dyn_cast<DIExpression>(UB))
798 return BoundType(MD);
799
800 return BoundType();
801}
802
803DISubrange::BoundType DISubrange::getStride() const {
804 Metadata *ST = getRawStride();
805 if (!ST)
806 return BoundType();
807
809 isa<DIExpression>(ST)) &&
810 "Stride must be signed constant or DIVariable or DIExpression");
811
812 if (auto *MD = dyn_cast<ConstantAsMetadata>(ST))
813 return BoundType(cast<ConstantInt>(MD->getValue()));
814
815 if (auto *MD = dyn_cast<DIVariable>(ST))
816 return BoundType(MD);
817
818 if (auto *MD = dyn_cast<DIExpression>(ST))
819 return BoundType(MD);
820
821 return BoundType();
822}
823DIGenericSubrange::DIGenericSubrange(LLVMContext &C, StorageType Storage,
825 : DINode(C, DIGenericSubrangeKind, Storage, dwarf::DW_TAG_generic_subrange,
826 Ops) {}
827
828DIGenericSubrange *DIGenericSubrange::getImpl(LLVMContext &Context,
829 Metadata *CountNode, Metadata *LB,
830 Metadata *UB, Metadata *Stride,
831 StorageType Storage,
832 bool ShouldCreate) {
833 DEFINE_GETIMPL_LOOKUP(DIGenericSubrange, (CountNode, LB, UB, Stride));
834 Metadata *Ops[] = {CountNode, LB, UB, Stride};
836}
837
840 if (!CB)
841 return BoundType();
842
844 "Count must be signed constant or DIVariable or DIExpression");
845
846 if (auto *MD = dyn_cast<DIVariable>(CB))
847 return BoundType(MD);
848
849 if (auto *MD = dyn_cast<DIExpression>(CB))
850 return BoundType(MD);
851
852 return BoundType();
853}
854
857 if (!LB)
858 return BoundType();
859
861 "LowerBound must be signed constant or DIVariable or DIExpression");
862
863 if (auto *MD = dyn_cast<DIVariable>(LB))
864 return BoundType(MD);
865
866 if (auto *MD = dyn_cast<DIExpression>(LB))
867 return BoundType(MD);
868
869 return BoundType();
870}
871
874 if (!UB)
875 return BoundType();
876
878 "UpperBound must be signed constant or DIVariable or DIExpression");
879
880 if (auto *MD = dyn_cast<DIVariable>(UB))
881 return BoundType(MD);
882
883 if (auto *MD = dyn_cast<DIExpression>(UB))
884 return BoundType(MD);
885
886 return BoundType();
887}
888
890 Metadata *ST = getRawStride();
891 if (!ST)
892 return BoundType();
893
895 "Stride must be signed constant or DIVariable or DIExpression");
896
897 if (auto *MD = dyn_cast<DIVariable>(ST))
898 return BoundType(MD);
899
900 if (auto *MD = dyn_cast<DIExpression>(ST))
901 return BoundType(MD);
902
903 return BoundType();
904}
905
906DISubrangeType::DISubrangeType(LLVMContext &C, StorageType Storage,
907 unsigned Line, uint32_t AlignInBits,
908 DIFlags Flags, ArrayRef<Metadata *> Ops)
909 : DIType(C, DISubrangeTypeKind, Storage, dwarf::DW_TAG_subrange_type, Line,
910 AlignInBits, 0, Flags, Ops) {}
911
912DISubrangeType *DISubrangeType::getImpl(
913 LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
914 Metadata *Scope, Metadata *SizeInBits, uint32_t AlignInBits, DIFlags Flags,
915 Metadata *BaseType, Metadata *LowerBound, Metadata *UpperBound,
916 Metadata *Stride, Metadata *Bias, StorageType Storage, bool ShouldCreate) {
917 assert(isCanonical(Name) && "Expected canonical MDString");
919 AlignInBits, Flags, BaseType,
921 Metadata *Ops[] = {File, Scope, Name, SizeInBits, nullptr,
923 DEFINE_GETIMPL_STORE(DISubrangeType, (Line, AlignInBits, Flags), Ops);
924}
925
927DISubrangeType::convertRawToBound(Metadata *IN) const {
928 if (!IN)
929 return BoundType();
930
933
934 if (auto *MD = dyn_cast<ConstantAsMetadata>(IN))
935 return BoundType(cast<ConstantInt>(MD->getValue()));
936
937 if (auto *MD = dyn_cast<DIVariable>(IN))
938 return BoundType(MD);
939
940 if (auto *MD = dyn_cast<DIExpression>(IN))
941 return BoundType(MD);
942
943 if (auto *DT = dyn_cast<DIDerivedType>(IN))
944 return BoundType(DT);
945
946 return BoundType();
947}
948
949DIEnumerator::DIEnumerator(LLVMContext &C, StorageType Storage,
950 const APInt &Value, bool IsUnsigned,
952 : DINode(C, DIEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
953 Value(Value) {
954 SubclassData32 = IsUnsigned;
955}
956DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, const APInt &Value,
957 bool IsUnsigned, MDString *Name,
958 StorageType Storage, bool ShouldCreate) {
959 assert(isCanonical(Name) && "Expected canonical MDString");
960 DEFINE_GETIMPL_LOOKUP(DIEnumerator, (Value, IsUnsigned, Name));
961 Metadata *Ops[] = {Name};
962 DEFINE_GETIMPL_STORE(DIEnumerator, (Value, IsUnsigned), Ops);
963}
964
967 unsigned LineNo, Metadata *Scope,
969 unsigned Encoding,
971 uint32_t DataSizeInBits, DIFlags Flags,
972 StorageType Storage, bool ShouldCreate) {
973 assert(isCanonical(Name) && "Expected canonical MDString");
976 Encoding, NumExtraInhabitants, DataSizeInBits, Flags));
977 Metadata *Ops[] = {File, Scope, Name, SizeInBits, nullptr};
980 DataSizeInBits, Flags),
981 Ops);
982}
983
984std::optional<DIBasicType::Signedness> DIBasicType::getSignedness() const {
985 switch (getEncoding()) {
986 case dwarf::DW_ATE_signed:
987 case dwarf::DW_ATE_signed_char:
988 case dwarf::DW_ATE_signed_fixed:
989 return Signedness::Signed;
990 case dwarf::DW_ATE_unsigned:
991 case dwarf::DW_ATE_unsigned_char:
992 case dwarf::DW_ATE_unsigned_fixed:
994 default:
995 return std::nullopt;
996 }
997}
998
1000DIFixedPointType::getImpl(LLVMContext &Context, unsigned Tag, MDString *Name,
1001 Metadata *File, unsigned LineNo, Metadata *Scope,
1002 Metadata *SizeInBits, uint32_t AlignInBits,
1003 unsigned Encoding, DIFlags Flags, unsigned Kind,
1004 int Factor, APInt Numerator, APInt Denominator,
1005 StorageType Storage, bool ShouldCreate) {
1007 (Tag, Name, File, LineNo, Scope, SizeInBits,
1008 AlignInBits, Encoding, Flags, Kind, Factor, Numerator,
1009 Denominator));
1010 Metadata *Ops[] = {File, Scope, Name, SizeInBits, nullptr};
1012 (Tag, LineNo, AlignInBits, Encoding, Flags, Kind, Factor,
1014 Ops);
1015}
1016
1018 return getEncoding() == dwarf::DW_ATE_signed_fixed;
1019}
1020
1021std::optional<DIFixedPointType::FixedPointKind>
1024 .Case("Binary", FixedPointBinary)
1025 .Case("Decimal", FixedPointDecimal)
1026 .Case("Rational", FixedPointRational)
1027 .Default(std::nullopt);
1028}
1029
1031 switch (V) {
1032 case FixedPointBinary:
1033 return "Binary";
1034 case FixedPointDecimal:
1035 return "Decimal";
1036 case FixedPointRational:
1037 return "Rational";
1038 }
1039 return nullptr;
1040}
1041
1042DIStringType *DIStringType::getImpl(LLVMContext &Context, unsigned Tag,
1043 MDString *Name, Metadata *StringLength,
1044 Metadata *StringLengthExp,
1045 Metadata *StringLocationExp,
1046 Metadata *SizeInBits, uint32_t AlignInBits,
1047 unsigned Encoding, Metadata *CharType,
1048 StorageType Storage, bool ShouldCreate) {
1049 assert(isCanonical(Name) && "Expected canonical MDString");
1052 AlignInBits, Encoding, CharType));
1053 Metadata *Ops[] = {nullptr, nullptr, Name,
1054 SizeInBits, nullptr, StringLength,
1057}
1059 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
1061}
1062
1063// Helper function to extract ConstantAsMetadata from ExtraData,
1064// handling extra data MDTuple unwrapping if needed.
1066 Metadata *ED = ExtraData;
1067 if (auto *Tuple = dyn_cast_or_null<MDTuple>(ED)) {
1068 if (Tuple->getNumOperands() != 1)
1069 return nullptr;
1070 ED = Tuple->getOperand(0);
1071 }
1073}
1074
1076 assert(getTag() == dwarf::DW_TAG_inheritance);
1077 if (auto *CM = extractConstantMetadata(getExtraData()))
1078 if (auto *CI = dyn_cast_or_null<ConstantInt>(CM->getValue()))
1079 return static_cast<uint32_t>(CI->getZExtValue());
1080 return 0;
1081}
1083 assert(getTag() == dwarf::DW_TAG_member && isBitField());
1084 if (auto *C = extractConstantMetadata(getExtraData()))
1085 return C->getValue();
1086 return nullptr;
1087}
1088
1090 assert((getTag() == dwarf::DW_TAG_member ||
1091 getTag() == dwarf::DW_TAG_variable) &&
1092 isStaticMember());
1093 if (auto *C = extractConstantMetadata(getExtraData()))
1094 return C->getValue();
1095 return nullptr;
1096}
1098 assert(getTag() == dwarf::DW_TAG_member && !isStaticMember());
1099 if (auto *C = extractConstantMetadata(getExtraData()))
1100 return C->getValue();
1101 return nullptr;
1102}
1103
1104DIDerivedType *DIDerivedType::getImpl(
1105 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1106 unsigned Line, Metadata *Scope, Metadata *BaseType, Metadata *SizeInBits,
1107 uint32_t AlignInBits, Metadata *OffsetInBits,
1108 std::optional<unsigned> DWARFAddressSpace,
1109 std::optional<PtrAuthData> PtrAuthData, DIFlags Flags, Metadata *ExtraData,
1110 Metadata *Annotations, StorageType Storage, bool ShouldCreate) {
1111 assert(isCanonical(Name) && "Expected canonical MDString");
1113 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
1115 PtrAuthData, Flags, ExtraData, Annotations));
1116 Metadata *Ops[] = {File, Scope, Name, SizeInBits,
1117 OffsetInBits, BaseType, ExtraData, Annotations};
1120 (Tag, Line, AlignInBits, DWARFAddressSpace, PtrAuthData, Flags), Ops);
1121}
1122
1123std::optional<DIDerivedType::PtrAuthData>
1124DIDerivedType::getPtrAuthData() const {
1125 return getTag() == dwarf::DW_TAG_LLVM_ptrauth_type
1126 ? std::make_optional<PtrAuthData>(SubclassData32)
1127 : std::nullopt;
1128}
1129
1130DICompositeType *DICompositeType::getImpl(
1131 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
1132 unsigned Line, Metadata *Scope, Metadata *BaseType, Metadata *SizeInBits,
1133 uint32_t AlignInBits, Metadata *OffsetInBits, DIFlags Flags,
1134 Metadata *Elements, unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1135 Metadata *VTableHolder, Metadata *TemplateParams, MDString *Identifier,
1136 Metadata *Discriminator, Metadata *DataLocation, Metadata *Associated,
1137 Metadata *Allocated, Metadata *Rank, Metadata *Annotations,
1138 Metadata *Specification, uint32_t NumExtraInhabitants, Metadata *BitStride,
1139 StorageType Storage, bool ShouldCreate) {
1140 assert(isCanonical(Name) && "Expected canonical MDString");
1141
1142 // Keep this in sync with buildODRType.
1144 DICompositeType,
1154 DEFINE_GETIMPL_STORE(DICompositeType,
1155 (Tag, Line, RuntimeLang, AlignInBits,
1156 NumExtraInhabitants, EnumKind, Flags),
1157 Ops);
1158}
1159
1161 Metadata *SizeInBits) {
1162 Metadata *ExistingSize = CT->getRawSizeInBits();
1163 if (!ExistingSize || !SizeInBits || ExistingSize == SizeInBits)
1164 return false;
1165 auto *ExistingCI = mdconst::dyn_extract<ConstantInt>(ExistingSize);
1166 auto *IncomingCI = mdconst::dyn_extract<ConstantInt>(SizeInBits);
1167 // Forward declarations commonly encode an unspecified size as ConstantInt(0)
1168 // rather than nullptr; treat 0 as unspecified so they still unique/mutate.
1169 if ((ExistingCI && ExistingCI->isZero()) ||
1170 (IncomingCI && IncomingCI->isZero()))
1171 return false;
1172 if (ExistingCI && IncomingCI)
1173 return ExistingCI->getZExtValue() != IncomingCI->getZExtValue();
1174 return true;
1175}
1176
1182 Metadata *Elements, unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1186 assert(!Identifier.getString().empty() && "Expected valid identifier");
1187 if (!Context.isODRUniquingDebugTypes())
1188 return nullptr;
1189 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
1190 if (!CT)
1191 return CT = DICompositeType::getDistinct(
1193 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
1197 if (CT->getTag() != Tag || hasConflictingSize(CT, SizeInBits))
1198 return nullptr;
1199
1200 // Only mutate CT if it's a forward declaration and the new operands aren't.
1201 assert(CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?");
1202 if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl))
1203 return CT;
1204
1205 // Mutate CT in place. Keep this in sync with getImpl.
1206 CT->mutate(Tag, Line, RuntimeLang, AlignInBits, NumExtraInhabitants, EnumKind,
1207 Flags);
1213 assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&
1214 "Mismatched number of operands");
1215 for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I)
1216 if (Ops[I] != CT->getOperand(I))
1217 CT->setOperand(I, Ops[I]);
1218 return CT;
1219}
1220
1221DICompositeType *DICompositeType::getODRType(
1222 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
1223 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
1224 Metadata *SizeInBits, uint32_t AlignInBits, Metadata *OffsetInBits,
1225 Metadata *Specification, uint32_t NumExtraInhabitants, DIFlags Flags,
1226 Metadata *Elements, unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
1227 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
1228 Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
1229 Metadata *Rank, Metadata *Annotations, Metadata *BitStride) {
1230 assert(!Identifier.getString().empty() && "Expected valid identifier");
1231 if (!Context.isODRUniquingDebugTypes())
1232 return nullptr;
1233 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
1234 if (!CT) {
1236 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
1241 } else {
1242 if (CT->getTag() != Tag || hasConflictingSize(CT, SizeInBits))
1243 return nullptr;
1244 }
1245 return CT;
1246}
1247
1250 assert(!Identifier.getString().empty() && "Expected valid identifier");
1251 if (!Context.isODRUniquingDebugTypes())
1252 return nullptr;
1253 return Context.pImpl->DITypeMap->lookup(&Identifier);
1254}
1255DISubroutineType::DISubroutineType(LLVMContext &C, StorageType Storage,
1256 DIFlags Flags, uint8_t CC,
1258 : DIType(C, DISubroutineTypeKind, Storage, dwarf::DW_TAG_subroutine_type, 0,
1259 0, 0, Flags, Ops),
1260 CC(CC) {}
1261
1262DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags,
1263 uint8_t CC, Metadata *TypeArray,
1264 StorageType Storage,
1265 bool ShouldCreate) {
1267 Metadata *Ops[] = {nullptr, nullptr, nullptr, nullptr, nullptr, TypeArray};
1268 DEFINE_GETIMPL_STORE(DISubroutineType, (Flags, CC), Ops);
1269}
1270
1271DIFile::DIFile(LLVMContext &C, StorageType Storage,
1272 std::optional<ChecksumInfo<MDString *>> CS, MDString *Src,
1274 : DIScope(C, DIFileKind, Storage, dwarf::DW_TAG_file_type, Ops),
1275 Checksum(CS), Source(Src) {}
1276
1277// FIXME: Implement this string-enum correspondence with a .def file and macros,
1278// so that the association is explicit rather than implied.
1279static const char *ChecksumKindName[DIFile::CSK_Last] = {
1280 "CSK_MD5",
1281 "CSK_SHA1",
1282 "CSK_SHA256",
1283};
1284
1285StringRef DIFile::getChecksumKindAsString(ChecksumKind CSKind) {
1286 assert(CSKind <= DIFile::CSK_Last && "Invalid checksum kind");
1287 // The first space was originally the CSK_None variant, which is now
1288 // obsolete, but the space is still reserved in ChecksumKind, so we account
1289 // for it here.
1290 return ChecksumKindName[CSKind - 1];
1291}
1292
1293std::optional<DIFile::ChecksumKind>
1296 .Case("CSK_MD5", DIFile::CSK_MD5)
1297 .Case("CSK_SHA1", DIFile::CSK_SHA1)
1298 .Case("CSK_SHA256", DIFile::CSK_SHA256)
1299 .Default(std::nullopt);
1300}
1301
1302DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
1303 MDString *Directory,
1304 std::optional<DIFile::ChecksumInfo<MDString *>> CS,
1305 MDString *Source, StorageType Storage,
1306 bool ShouldCreate) {
1307 assert(isCanonical(Filename) && "Expected canonical MDString");
1308 assert(isCanonical(Directory) && "Expected canonical MDString");
1309 assert((!CS || isCanonical(CS->Value)) && "Expected canonical MDString");
1310 // We do *NOT* expect Source to be a canonical MDString because nullptr
1311 // means none, so we need something to represent the empty file.
1313 Metadata *Ops[] = {Filename, Directory, CS ? CS->Value : nullptr, Source};
1315}
1316DICompileUnit::DICompileUnit(LLVMContext &C, StorageType Storage,
1317 DISourceLanguageName SourceLanguage,
1318 bool IsOptimized, unsigned RuntimeVersion,
1319 unsigned EmissionKind, uint64_t DWOId,
1320 bool SplitDebugInlining,
1321 bool DebugInfoForProfiling, unsigned NameTableKind,
1322 bool RangesBaseAddress, ArrayRef<Metadata *> Ops)
1323 : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
1324 SourceLanguage(SourceLanguage), RuntimeVersion(RuntimeVersion),
1326 IsOptimized(IsOptimized), SplitDebugInlining(SplitDebugInlining),
1327 DebugInfoForProfiling(DebugInfoForProfiling),
1328 RangesBaseAddress(RangesBaseAddress) {
1330}
1331
1332DICompileUnit *DICompileUnit::getImpl(
1333 LLVMContext &Context, DISourceLanguageName SourceLanguage, Metadata *File,
1334 MDString *Producer, bool IsOptimized, MDString *Flags,
1335 unsigned RuntimeVersion, MDString *SplitDebugFilename,
1336 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
1337 Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
1338 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
1339 unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
1340 MDString *SDK, StorageType Storage, bool ShouldCreate) {
1341 assert(Storage != Uniqued && "Cannot unique DICompileUnit");
1342 assert(isCanonical(Producer) && "Expected canonical MDString");
1343 assert(isCanonical(Flags) && "Expected canonical MDString");
1344 assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
1345
1346 Metadata *Ops[] = {File,
1347 Producer,
1348 Flags,
1350 EnumTypes,
1354 Macros,
1355 SysRoot,
1356 SDK};
1357 return storeImpl(new (std::size(Ops), Storage) DICompileUnit(
1358 Context, Storage, SourceLanguage, IsOptimized,
1359 RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
1360 DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
1361 Ops),
1362 Storage);
1363}
1364
1365std::optional<DICompileUnit::DebugEmissionKind>
1368 .Case("NoDebug", NoDebug)
1369 .Case("FullDebug", FullDebug)
1370 .Case("LineTablesOnly", LineTablesOnly)
1371 .Case("DebugDirectivesOnly", DebugDirectivesOnly)
1372 .Default(std::nullopt);
1373}
1374
1375std::optional<DICompileUnit::DebugNameTableKind>
1384
1386 switch (EK) {
1387 case NoDebug:
1388 return "NoDebug";
1389 case FullDebug:
1390 return "FullDebug";
1391 case LineTablesOnly:
1392 return "LineTablesOnly";
1394 return "DebugDirectivesOnly";
1395 }
1396 return nullptr;
1397}
1398
1400 switch (NTK) {
1402 return nullptr;
1404 return "GNU";
1406 return "Apple";
1408 return "None";
1409 }
1410 return nullptr;
1411}
1412DISubprogram::DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1413 unsigned ScopeLine, unsigned VirtualIndex,
1414 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags,
1415 bool UsesKeyInstructions, ArrayRef<Metadata *> Ops)
1416 : DILocalScope(C, DISubprogramKind, Storage, dwarf::DW_TAG_subprogram, Ops),
1417 Line(Line), ScopeLine(ScopeLine), VirtualIndex(VirtualIndex),
1418 ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags) {
1419 static_assert(dwarf::DW_VIRTUALITY_max < 4, "Virtuality out of range");
1420 SubclassData1 = UsesKeyInstructions;
1421}
1423DISubprogram::toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized,
1424 unsigned Virtuality, bool IsMainSubprogram) {
1425 // We're assuming virtuality is the low-order field.
1426 static_assert(int(SPFlagVirtual) == int(dwarf::DW_VIRTUALITY_virtual) &&
1427 int(SPFlagPureVirtual) ==
1428 int(dwarf::DW_VIRTUALITY_pure_virtual),
1429 "Virtuality constant mismatch");
1430 return static_cast<DISPFlags>(
1431 (Virtuality & SPFlagVirtuality) |
1432 (IsLocalToUnit ? SPFlagLocalToUnit : SPFlagZero) |
1433 (IsDefinition ? SPFlagDefinition : SPFlagZero) |
1434 (IsOptimized ? SPFlagOptimized : SPFlagZero) |
1435 (IsMainSubprogram ? SPFlagMainSubprogram : SPFlagZero));
1436}
1437
1439 if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
1440 return Block->getScope()->getSubprogram();
1441 return const_cast<DISubprogram *>(cast<DISubprogram>(this));
1442}
1443
1445 if (auto *File = dyn_cast<DILexicalBlockFile>(this))
1446 return File->getScope()->getNonLexicalBlockFileScope();
1447 return const_cast<DILocalScope *>(this);
1448}
1449
1451 DILocalScope &RootScope, DISubprogram &NewSP, LLVMContext &Ctx,
1453 SmallVector<DIScope *> ScopeChain;
1454 DIScope *CachedResult = nullptr;
1455
1456 for (DIScope *Scope = &RootScope; !isa<DISubprogram>(Scope);
1457 Scope = Scope->getScope()) {
1458 if (auto It = Cache.find(Scope); It != Cache.end()) {
1459 CachedResult = cast<DIScope>(It->second);
1460 break;
1461 }
1462 ScopeChain.push_back(Scope);
1463 }
1464
1465 // Recreate the scope chain, bottom-up, starting at the new subprogram (or a
1466 // cached result).
1467 DIScope *UpdatedScope = CachedResult ? CachedResult : &NewSP;
1468 for (DIScope *ScopeToUpdate : reverse(ScopeChain)) {
1469 UpdatedScope = cloneAndReplaceParentScope(
1470 cast<DILexicalBlockBase>(ScopeToUpdate), UpdatedScope);
1471 Cache[ScopeToUpdate] = UpdatedScope;
1472 }
1473
1474 return cast<DILocalScope>(UpdatedScope);
1475}
1476
1478 return StringSwitch<DISPFlags>(Flag)
1479#define HANDLE_DISP_FLAG(ID, NAME) .Case("DISPFlag" #NAME, SPFlag##NAME)
1480#include "llvm/IR/DebugInfoFlags.def"
1481 .Default(SPFlagZero);
1482}
1483
1485 switch (Flag) {
1486 // Appease a warning.
1487 case SPFlagVirtuality:
1488 return "";
1489#define HANDLE_DISP_FLAG(ID, NAME) \
1490 case SPFlag##NAME: \
1491 return "DISPFlag" #NAME;
1492#include "llvm/IR/DebugInfoFlags.def"
1493 }
1494 return "";
1495}
1496
1499 SmallVectorImpl<DISPFlags> &SplitFlags) {
1500 // Multi-bit fields can require special handling. In our case, however, the
1501 // only multi-bit field is virtuality, and all its values happen to be
1502 // single-bit values, so the right behavior just falls out.
1503#define HANDLE_DISP_FLAG(ID, NAME) \
1504 if (DISPFlags Bit = Flags & SPFlag##NAME) { \
1505 SplitFlags.push_back(Bit); \
1506 Flags &= ~Bit; \
1507 }
1508#include "llvm/IR/DebugInfoFlags.def"
1509 return Flags;
1510}
1511
1512DISubprogram *DISubprogram::getImpl(
1513 LLVMContext &Context, Metadata *Scope, MDString *Name,
1514 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
1515 unsigned ScopeLine, Metadata *ContainingType, unsigned VirtualIndex,
1516 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
1517 Metadata *TemplateParams, Metadata *Declaration, Metadata *RetainedNodes,
1518 Metadata *ThrownTypes, Metadata *Annotations, MDString *TargetFuncName,
1519 bool UsesKeyInstructions, StorageType Storage, bool ShouldCreate) {
1520 assert(isCanonical(Name) && "Expected canonical MDString");
1521 assert(isCanonical(LinkageName) && "Expected canonical MDString");
1522 assert(isCanonical(TargetFuncName) && "Expected canonical MDString");
1524 (Scope, Name, LinkageName, File, Line, Type, ScopeLine,
1526 SPFlags, Unit, TemplateParams, Declaration,
1530 File, Scope, Name, LinkageName,
1531 Type, Unit, Declaration, RetainedNodes,
1534 if (!TargetFuncName) {
1535 Ops.pop_back();
1536 if (!Annotations) {
1537 Ops.pop_back();
1538 if (!ThrownTypes) {
1539 Ops.pop_back();
1540 if (!TemplateParams) {
1541 Ops.pop_back();
1542 if (!ContainingType)
1543 Ops.pop_back();
1544 }
1545 }
1546 }
1547 }
1548 DEFINE_GETIMPL_STORE_N(DISubprogram,
1549 (Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags,
1550 SPFlags, UsesKeyInstructions),
1551 Ops, Ops.size());
1552}
1553
1555 assert(F && "Invalid function");
1556 return F->getSubprogram() == this;
1557}
1558
1559template <typename ScopeT, typename NodeT>
1560static ScopeT getRawRetainedNodeScopeInternal(NodeT *N) {
1561 auto getScopeLambda = [](auto *N) { return getScope(N); };
1562 return DISubprogram::visitRetainedNode<ScopeT>(
1563 N, getScopeLambda, getScopeLambda, getScopeLambda, getScopeLambda,
1564 getScopeLambda, [](auto *N) { return nullptr; });
1565}
1566
1570
1574
1578
1581}
1582
1584 // Checks if a metadata node from retainedTypes is a type belonging to
1585 // this subprogram.
1586 auto IsTypeInSP = [this](Metadata *N) {
1587 auto *T = dyn_cast_or_null<DIType>(N);
1588 if (!T)
1589 return true;
1590
1591 DISubprogram *TypeSP = nullptr;
1592 // The type might have been global in the previously loaded IR modules.
1593 if (auto *LS = dyn_cast_or_null<DILocalScope>(T->getScope()))
1594 TypeSP = LS->getSubprogram();
1595
1596 return this == TypeSP;
1597 };
1598
1599 cleanupRetainedNodesIf(IsTypeInSP);
1600}
1601
1606
1607DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
1608 Metadata *File, unsigned Line,
1609 unsigned Column, StorageType Storage,
1610 bool ShouldCreate) {
1611 // Fixup column.
1613
1614 assert(Scope && "Expected scope");
1616 Metadata *Ops[] = {File, Scope};
1618}
1619
1620DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
1621 Metadata *Scope, Metadata *File,
1622 unsigned Discriminator,
1623 StorageType Storage,
1624 bool ShouldCreate) {
1625 assert(Scope && "Expected scope");
1626 DEFINE_GETIMPL_LOOKUP(DILexicalBlockFile, (Scope, File, Discriminator));
1627 Metadata *Ops[] = {File, Scope};
1628 DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops);
1629}
1630
1631DINamespace::DINamespace(LLVMContext &Context, StorageType Storage,
1632 bool ExportSymbols, ArrayRef<Metadata *> Ops)
1633 : DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace, Ops) {
1634 SubclassData1 = ExportSymbols;
1635}
1636DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
1637 MDString *Name, bool ExportSymbols,
1638 StorageType Storage, bool ShouldCreate) {
1639 assert(isCanonical(Name) && "Expected canonical MDString");
1641 // The nullptr is for DIScope's File operand. This should be refactored.
1642 Metadata *Ops[] = {nullptr, Scope, Name};
1643 DEFINE_GETIMPL_STORE(DINamespace, (ExportSymbols), Ops);
1644}
1645
1646DICommonBlock::DICommonBlock(LLVMContext &Context, StorageType Storage,
1647 unsigned LineNo, ArrayRef<Metadata *> Ops)
1648 : DIScope(Context, DICommonBlockKind, Storage, dwarf::DW_TAG_common_block,
1649 Ops) {
1650 SubclassData32 = LineNo;
1651}
1652DICommonBlock *DICommonBlock::getImpl(LLVMContext &Context, Metadata *Scope,
1653 Metadata *Decl, MDString *Name,
1654 Metadata *File, unsigned LineNo,
1655 StorageType Storage, bool ShouldCreate) {
1656 assert(isCanonical(Name) && "Expected canonical MDString");
1657 DEFINE_GETIMPL_LOOKUP(DICommonBlock, (Scope, Decl, Name, File, LineNo));
1658 // The nullptr is for DIScope's File operand. This should be refactored.
1659 Metadata *Ops[] = {Scope, Decl, Name, File};
1660 DEFINE_GETIMPL_STORE(DICommonBlock, (LineNo), Ops);
1661}
1662
1663DIModule::DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo,
1664 bool IsDecl, ArrayRef<Metadata *> Ops)
1665 : DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops) {
1666 SubclassData1 = IsDecl;
1667 SubclassData32 = LineNo;
1668}
1669DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *File,
1670 Metadata *Scope, MDString *Name,
1671 MDString *ConfigurationMacros,
1672 MDString *IncludePath, MDString *APINotesFile,
1673 unsigned LineNo, bool IsDecl, StorageType Storage,
1674 bool ShouldCreate) {
1675 assert(isCanonical(Name) && "Expected canonical MDString");
1677 IncludePath, APINotesFile, LineNo, IsDecl));
1680 DEFINE_GETIMPL_STORE(DIModule, (LineNo, IsDecl), Ops);
1681}
1682DITemplateTypeParameter::DITemplateTypeParameter(LLVMContext &Context,
1683 StorageType Storage,
1684 bool IsDefault,
1686 : DITemplateParameter(Context, DITemplateTypeParameterKind, Storage,
1687 dwarf::DW_TAG_template_type_parameter, IsDefault,
1688 Ops) {}
1689
1691DITemplateTypeParameter::getImpl(LLVMContext &Context, MDString *Name,
1692 Metadata *Type, bool isDefault,
1693 StorageType Storage, bool ShouldCreate) {
1694 assert(isCanonical(Name) && "Expected canonical MDString");
1695 DEFINE_GETIMPL_LOOKUP(DITemplateTypeParameter, (Name, Type, isDefault));
1696 Metadata *Ops[] = {Name, Type};
1697 DEFINE_GETIMPL_STORE(DITemplateTypeParameter, (isDefault), Ops);
1698}
1699
1700DITemplateValueParameter *DITemplateValueParameter::getImpl(
1701 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
1702 bool isDefault, Metadata *Value, StorageType Storage, bool ShouldCreate) {
1703 assert(isCanonical(Name) && "Expected canonical MDString");
1704 DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter,
1705 (Tag, Name, Type, isDefault, Value));
1706 Metadata *Ops[] = {Name, Type, Value};
1707 DEFINE_GETIMPL_STORE(DITemplateValueParameter, (Tag, isDefault), Ops);
1708}
1709
1711DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1712 MDString *LinkageName, Metadata *File, unsigned Line,
1713 Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
1714 Metadata *StaticDataMemberDeclaration,
1715 Metadata *TemplateParams, uint32_t AlignInBits,
1716 Metadata *Annotations, StorageType Storage,
1717 bool ShouldCreate) {
1718 assert(isCanonical(Name) && "Expected canonical MDString");
1719 assert(isCanonical(LinkageName) && "Expected canonical MDString");
1721 DIGlobalVariable,
1722 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
1724 Metadata *Ops[] = {Scope,
1725 Name,
1726 File,
1727 Type,
1728 Name,
1732 Annotations};
1733 DEFINE_GETIMPL_STORE(DIGlobalVariable,
1734 (Line, IsLocalToUnit, IsDefinition, AlignInBits), Ops);
1735}
1736
1738DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1739 Metadata *File, unsigned Line, Metadata *Type,
1740 unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
1741 Metadata *Annotations, StorageType Storage,
1742 bool ShouldCreate) {
1743 // 64K ought to be enough for any frontend.
1744 assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");
1745
1746 assert(Scope && "Expected scope");
1747 assert(isCanonical(Name) && "Expected canonical MDString");
1748 DEFINE_GETIMPL_LOOKUP(DILocalVariable, (Scope, Name, File, Line, Type, Arg,
1749 Flags, AlignInBits, Annotations));
1751 DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops);
1752}
1753
1755 signed Line, ArrayRef<Metadata *> Ops,
1756 uint32_t AlignInBits)
1757 : DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line) {
1758 SubclassData32 = AlignInBits;
1759}
1760std::optional<uint64_t> DIVariable::getSizeInBits() const {
1761 // This is used by the Verifier so be mindful of broken types.
1762 const Metadata *RawType = getRawType();
1763 while (RawType) {
1764 // Try to get the size directly.
1765 if (auto *T = dyn_cast<DIType>(RawType))
1766 if (uint64_t Size = T->getSizeInBits())
1767 return Size;
1768
1769 if (auto *DT = dyn_cast<DIDerivedType>(RawType)) {
1770 // Look at the base type.
1771 RawType = DT->getRawBaseType();
1772 continue;
1773 }
1774
1775 // Missing type or size.
1776 break;
1777 }
1778
1779 // Fail gracefully.
1780 return std::nullopt;
1781}
1782
1783DILabel::DILabel(LLVMContext &C, StorageType Storage, unsigned Line,
1784 unsigned Column, bool IsArtificial,
1785 std::optional<unsigned> CoroSuspendIdx,
1787 : DINode(C, DILabelKind, Storage, dwarf::DW_TAG_label, Ops) {
1788 this->SubclassData32 = Line;
1789 this->Column = Column;
1790 this->IsArtificial = IsArtificial;
1791 this->CoroSuspendIdx = CoroSuspendIdx;
1792}
1793DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
1794 Metadata *File, unsigned Line, unsigned Column,
1795 bool IsArtificial,
1796 std::optional<unsigned> CoroSuspendIdx,
1797 StorageType Storage, bool ShouldCreate) {
1798 assert(Scope && "Expected scope");
1799 assert(isCanonical(Name) && "Expected canonical MDString");
1801 DILabel, (Scope, Name, File, Line, Column, IsArtificial, CoroSuspendIdx));
1802 Metadata *Ops[] = {Scope, Name, File};
1803 DEFINE_GETIMPL_STORE(DILabel, (Line, Column, IsArtificial, CoroSuspendIdx),
1804 Ops);
1805}
1806
1807DIExpression *DIExpression::getImpl(LLVMContext &Context,
1808 ArrayRef<uint64_t> Elements,
1809 StorageType Storage, bool ShouldCreate) {
1810 DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements));
1811 DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements));
1812}
1814 if (auto singleLocElts = getSingleLocationExpressionElements()) {
1815 return singleLocElts->size() > 0 &&
1816 (*singleLocElts)[0] == dwarf::DW_OP_LLVM_entry_value;
1817 }
1818 return false;
1819}
1821 if (auto singleLocElts = getSingleLocationExpressionElements())
1822 return singleLocElts->size() > 0 &&
1823 (*singleLocElts)[0] == dwarf::DW_OP_deref;
1824 return false;
1825}
1827 if (auto singleLocElts = getSingleLocationExpressionElements())
1828 return singleLocElts->size() == 1 &&
1829 (*singleLocElts)[0] == dwarf::DW_OP_deref;
1830 return false;
1831}
1832
1833DIAssignID *DIAssignID::getImpl(LLVMContext &Context, StorageType Storage,
1834 bool ShouldCreate) {
1835 // Uniqued DIAssignID are not supported as the instance address *is* the ID.
1836 assert(Storage != StorageType::Uniqued && "uniqued DIAssignID unsupported");
1837 return storeImpl(new (0u, Storage) DIAssignID(Context, Storage), Storage);
1838}
1839
1841 uint64_t Op = getOp();
1842
1843 if (Op >= dwarf::DW_OP_breg0 && Op <= dwarf::DW_OP_breg31)
1844 return 2;
1845
1846 switch (Op) {
1851 case dwarf::DW_OP_bregx:
1852 return 3;
1853 case dwarf::DW_OP_constu:
1854 case dwarf::DW_OP_consts:
1855 case dwarf::DW_OP_deref_size:
1856 case dwarf::DW_OP_xderef_size:
1857 case dwarf::DW_OP_plus_uconst:
1861 case dwarf::DW_OP_regx:
1862 return 2;
1863 default:
1864 return 1;
1865 }
1866}
1867
1871
1873 return Op->is(dwarf::DW_OP_LLVM_arg);
1874}
1875
1879
1884
1888
1892
1896
1900
1902 return Op->is(dwarf::DW_OP_constu);
1903}
1904
1906 return Op->is(dwarf::DW_OP_plus_uconst);
1907}
1908
1910 return Op >= dwarf::DW_OP_lit0 && Op <= dwarf::DW_OP_lit31;
1911}
1912
1914 for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
1915 // Check that there's space for the operand.
1916 if (I->getSize() > static_cast<uint64_t>(E->get() - I->get()))
1917 return false;
1918
1919 uint64_t Op = I->getOp();
1920 if ((Op >= dwarf::DW_OP_reg0 && Op <= dwarf::DW_OP_reg31) ||
1921 (Op >= dwarf::DW_OP_breg0 && Op <= dwarf::DW_OP_breg31) || isLitOp(Op))
1922 continue;
1923
1924 // Check that the operand is valid.
1925 switch (Op) {
1926 default:
1927 return false;
1929 // A fragment operator must appear at the end.
1930 return I->get() + I->getSize() == E->get();
1931 case dwarf::DW_OP_stack_value: {
1932 // Must be the last one or followed by a DW_OP_LLVM_fragment.
1933 if (I->get() + I->getSize() == E->get())
1934 break;
1935 auto J = I;
1936 if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment)
1937 return false;
1938 break;
1939 }
1940 case dwarf::DW_OP_swap: {
1941 // Must be more than one implicit element on the stack.
1942
1943 // FIXME: A better way to implement this would be to add a local variable
1944 // that keeps track of the stack depth and introduce something like a
1945 // DW_LLVM_OP_implicit_location as a placeholder for the location this
1946 // DIExpression is attached to, or else pass the number of implicit stack
1947 // elements into isValid.
1948 if (getNumElements() == 1)
1949 return false;
1950 break;
1951 }
1953 // An entry value operator must appear at the beginning or immediately
1954 // following `DW_OP_LLVM_arg 0`, and the number of operations it cover can
1955 // currently only be 1, because we support only entry values of a simple
1956 // register location. One reason for this is that we currently can't
1957 // calculate the size of the resulting DWARF block for other expressions.
1958 auto FirstOp = expr_op_begin();
1959 if (auto Arg = dyn_cast<ArgOp>(*FirstOp); Arg && Arg.getIndex() == 0)
1960 ++FirstOp;
1961 if (I->get() != FirstOp->get() ||
1962 cast<EntryValueOp>(*I).getNumOperations() != 1)
1963 return false;
1964 break;
1965 }
1966 case dwarf::DW_OP_deref_size:
1967 case dwarf::DW_OP_xderef_size:
1968 // The size operand is encoded as a single byte.
1969 if (!isUInt<8>(I->getArg(0)))
1970 return false;
1971 break;
1978 case dwarf::DW_OP_constu:
1979 case dwarf::DW_OP_plus_uconst:
1980 case dwarf::DW_OP_plus:
1981 case dwarf::DW_OP_minus:
1982 case dwarf::DW_OP_mul:
1983 case dwarf::DW_OP_div:
1984 case dwarf::DW_OP_mod:
1985 case dwarf::DW_OP_or:
1986 case dwarf::DW_OP_and:
1987 case dwarf::DW_OP_xor:
1988 case dwarf::DW_OP_shl:
1989 case dwarf::DW_OP_shr:
1990 case dwarf::DW_OP_shra:
1991 case dwarf::DW_OP_deref:
1992 case dwarf::DW_OP_xderef:
1993 case dwarf::DW_OP_not:
1994 case dwarf::DW_OP_dup:
1995 case dwarf::DW_OP_regx:
1996 case dwarf::DW_OP_bregx:
1997 case dwarf::DW_OP_push_object_address:
1998 case dwarf::DW_OP_over:
1999 case dwarf::DW_OP_rot:
2000 case dwarf::DW_OP_consts:
2001 case dwarf::DW_OP_eq:
2002 case dwarf::DW_OP_ne:
2003 case dwarf::DW_OP_gt:
2004 case dwarf::DW_OP_ge:
2005 case dwarf::DW_OP_lt:
2006 case dwarf::DW_OP_le:
2007 case dwarf::DW_OP_neg:
2008 case dwarf::DW_OP_abs:
2009 break;
2010 }
2011 }
2012 return true;
2013}
2014
2016 if (!isValid())
2017 return false;
2018
2019 if (getNumElements() == 0)
2020 return false;
2021
2022 for (const auto &It : expr_ops()) {
2023 switch (It.getOp()) {
2024 default:
2025 break;
2026 case dwarf::DW_OP_stack_value:
2027 return true;
2028 }
2029 }
2030
2031 return false;
2032}
2033
2035 if (!isValid())
2036 return false;
2037
2038 if (getNumElements() == 0)
2039 return false;
2040
2041 // Tag offsets are non-emitting. They, fragments, and location operands don't
2042 // perform a computation by themselves.
2043 for (const auto &It : expr_ops()) {
2044 if (It.isNonEmitting())
2045 continue;
2046 switch (It.getOp()) {
2049 continue;
2050 default:
2051 return true;
2052 }
2053 }
2054
2055 return false;
2056}
2057
2059 if (!isValid())
2060 return false;
2061
2062 if (getNumElements() == 0)
2063 return true;
2064
2065 auto ExprOpBegin = expr_ops().begin();
2066 auto ExprOpEnd = expr_ops().end();
2067 if (auto Arg = dyn_cast<ArgOp>(*ExprOpBegin)) {
2068 if (Arg.getIndex() != 0)
2069 return false;
2070 ++ExprOpBegin;
2071 }
2072
2073 return !std::any_of(ExprOpBegin, ExprOpEnd,
2074 [](auto Op) { return Op.is(dwarf::DW_OP_LLVM_arg); });
2075}
2076
2077std::optional<ArrayRef<uint64_t>>
2079 // Check for `isValid` covered by `isSingleLocationExpression`.
2081 return std::nullopt;
2082
2083 // An empty expression is already non-variadic.
2084 if (!getNumElements())
2085 return ArrayRef<uint64_t>();
2086
2087 // If Expr does not have a leading DW_OP_LLVM_arg then we don't need to do
2088 // anything.
2090 return getElements().drop_front(2);
2091 return getElements();
2092}
2093
2094const DIExpression *
2096 SmallVector<uint64_t, 3> UndefOps;
2097 if (auto FragmentInfo = Expr->getFragmentInfo()) {
2098 UndefOps.append({dwarf::DW_OP_LLVM_fragment, FragmentInfo->OffsetInBits,
2099 FragmentInfo->SizeInBits});
2100 }
2101 return DIExpression::get(Expr->getContext(), UndefOps);
2102}
2103
2104const DIExpression *
2106 if (any_of(Expr->expr_ops(), [](auto ExprOp) {
2107 return ExprOp.getOp() == dwarf::DW_OP_LLVM_arg;
2108 }))
2109 return Expr;
2110 SmallVector<uint64_t> NewOps;
2111 NewOps.reserve(Expr->getNumElements() + 2);
2112 NewOps.append({dwarf::DW_OP_LLVM_arg, 0});
2113 NewOps.append(Expr->elements_begin(), Expr->elements_end());
2114 return DIExpression::get(Expr->getContext(), NewOps);
2115}
2116
2117std::optional<const DIExpression *>
2119 if (!Expr)
2120 return std::nullopt;
2121
2122 if (auto Elts = Expr->getSingleLocationExpressionElements())
2123 return DIExpression::get(Expr->getContext(), *Elts);
2124
2125 return std::nullopt;
2126}
2127
2129 const DIExpression *Expr,
2130 bool IsIndirect) {
2131 // If Expr is not already variadic, insert the implied `DW_OP_LLVM_arg 0`
2132 // to the existing expression ops.
2133 if (none_of(Expr->expr_ops(), [](auto ExprOp) {
2134 return ExprOp.getOp() == dwarf::DW_OP_LLVM_arg;
2135 }))
2136 Ops.append({dwarf::DW_OP_LLVM_arg, 0});
2137 // If Expr is not indirect, we only need to insert the expression elements and
2138 // we're done.
2139 if (!IsIndirect) {
2140 Ops.append(Expr->elements_begin(), Expr->elements_end());
2141 return;
2142 }
2143 // If Expr is indirect, insert the implied DW_OP_deref at the end of the
2144 // expression but before DW_OP_{stack_value, LLVM_fragment} if they are
2145 // present.
2146 for (auto Op : Expr->expr_ops()) {
2147 if (Op.getOp() == dwarf::DW_OP_stack_value ||
2148 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
2149 Ops.push_back(dwarf::DW_OP_deref);
2150 IsIndirect = false;
2151 }
2152 Op.appendToVector(Ops);
2153 }
2154 if (IsIndirect)
2155 Ops.push_back(dwarf::DW_OP_deref);
2156}
2157
2158bool DIExpression::isEqualExpression(const DIExpression *FirstExpr,
2159 bool FirstIndirect,
2160 const DIExpression *SecondExpr,
2161 bool SecondIndirect) {
2162 SmallVector<uint64_t> FirstOps;
2163 DIExpression::canonicalizeExpressionOps(FirstOps, FirstExpr, FirstIndirect);
2164 SmallVector<uint64_t> SecondOps;
2165 DIExpression::canonicalizeExpressionOps(SecondOps, SecondExpr,
2166 SecondIndirect);
2167 return FirstOps == SecondOps;
2168}
2169
2170std::optional<DIExpression::FragmentInfo>
2172 for (auto I = Start; I != End; ++I)
2173 if (auto Fragment = dyn_cast<FragmentOp>(*I))
2174 return FragmentInfo{Fragment.getSizeInBits(), Fragment.getOffsetInBits()};
2175 return std::nullopt;
2176}
2177
2178std::optional<uint64_t> DIExpression::getActiveBits(DIVariable *Var) {
2179 std::optional<uint64_t> InitialActiveBits = Var->getSizeInBits();
2180 std::optional<uint64_t> ActiveBits = InitialActiveBits;
2181 auto NarrowActiveBits = [&](uint64_t SizeInBits) {
2182 ActiveBits = ActiveBits ? std::min(*ActiveBits, SizeInBits) : SizeInBits;
2183 };
2184
2185 for (auto Op : expr_ops()) {
2186 switch (Op.getOp()) {
2187 default:
2188 // We assume the worst case for anything we don't currently handle and
2189 // revert to the initial active bits.
2190 ActiveBits = InitialActiveBits;
2191 break;
2194 auto Extract = cast<ExtractBitsOp>(Op);
2195 // We can't handle an extract whose sign doesn't match that of the
2196 // variable.
2197 std::optional<DIBasicType::Signedness> VarSign = Var->getSignedness();
2198 bool VarSigned = (VarSign == DIBasicType::Signedness::Signed);
2199 if (!VarSign || VarSigned != Extract.isSigned()) {
2200 ActiveBits = InitialActiveBits;
2201 break;
2202 }
2203 NarrowActiveBits(Extract.getSizeInBits());
2204 break;
2205 }
2207 NarrowActiveBits(cast<FragmentOp>(Op).getSizeInBits());
2208 break;
2209 }
2210 }
2211 return ActiveBits;
2212}
2213
2215 int64_t Offset) {
2216 if (Offset > 0) {
2217 Ops.push_back(dwarf::DW_OP_plus_uconst);
2218 Ops.push_back(Offset);
2219 } else if (Offset < 0) {
2220 Ops.push_back(dwarf::DW_OP_constu);
2221 // Avoid UB when encountering LLONG_MIN, because in 2's complement
2222 // abs(LLONG_MIN) is LLONG_MAX+1.
2223 uint64_t AbsMinusOne = -(Offset+1);
2224 Ops.push_back(AbsMinusOne + 1);
2225 Ops.push_back(dwarf::DW_OP_minus);
2226 }
2227}
2228
2230 auto SingleLocEltsOpt = getSingleLocationExpressionElements();
2231 if (!SingleLocEltsOpt)
2232 return false;
2233 auto SingleLocElts = *SingleLocEltsOpt;
2234
2235 if (SingleLocElts.size() == 0) {
2236 Offset = 0;
2237 return true;
2238 }
2239
2240 if (SingleLocElts.size() == 2 &&
2241 SingleLocElts[0] == dwarf::DW_OP_plus_uconst) {
2242 Offset = SingleLocElts[1];
2243 return true;
2244 }
2245
2246 if (SingleLocElts.size() == 3 && SingleLocElts[0] == dwarf::DW_OP_constu) {
2247 if (SingleLocElts[2] == dwarf::DW_OP_plus) {
2248 Offset = SingleLocElts[1];
2249 return true;
2250 }
2251 if (SingleLocElts[2] == dwarf::DW_OP_minus) {
2252 Offset = -SingleLocElts[1];
2253 return true;
2254 }
2255 }
2256
2257 return false;
2258}
2259
2261 ArrayRef<uint64_t> Ops, int64_t &OffsetInBytes,
2262 SmallVectorImpl<uint64_t> &RemainingOps) {
2263 OffsetInBytes = 0;
2264 RemainingOps.clear();
2265
2266 auto ExprOpEnd = expr_op_iterator(Ops.end());
2267 auto ExprOpIt = expr_op_iterator(Ops.begin());
2268 while (ExprOpIt != ExprOpEnd) {
2269 uint64_t Op = ExprOpIt->getOp();
2270 if (Op == dwarf::DW_OP_deref || Op == dwarf::DW_OP_deref_size ||
2271 Op == dwarf::DW_OP_deref_type || Op == dwarf::DW_OP_LLVM_fragment ||
2274 break;
2275 } else if (auto PlusUconst = dyn_cast<PlusUconstOp>(*ExprOpIt)) {
2276 OffsetInBytes += PlusUconst.getOffset();
2277 } else if (auto Constant = dyn_cast<ConstuOp>(*ExprOpIt)) {
2278 uint64_t Value = Constant.getValue();
2279 ++ExprOpIt;
2280 if (ExprOpIt->getOp() == dwarf::DW_OP_plus)
2281 OffsetInBytes += Value;
2282 else if (ExprOpIt->getOp() == dwarf::DW_OP_minus)
2283 OffsetInBytes -= Value;
2284 else
2285 return false;
2286 } else {
2287 // Not a const plus/minus operation or deref.
2288 return false;
2289 }
2290 ++ExprOpIt;
2291 }
2292 RemainingOps.append(ExprOpIt.getBase(), ExprOpEnd.getBase());
2293 return true;
2294}
2295
2297 int64_t &OffsetInBytes, SmallVectorImpl<uint64_t> &RemainingOps) const {
2298 auto SingleLocEltsOpt = getSingleLocationExpressionElements();
2299 if (!SingleLocEltsOpt) {
2300 OffsetInBytes = 0;
2301 RemainingOps.clear();
2302 return false;
2303 }
2304
2305 return extractLeadingOffset(*SingleLocEltsOpt, OffsetInBytes, RemainingOps);
2306}
2307
2310 for (auto ExprOp : expr_ops())
2311 if (auto Arg = dyn_cast<ArgOp>(ExprOp))
2312 SeenOps.insert(Arg.getIndex());
2313 for (uint64_t Idx = 0; Idx < N; ++Idx)
2314 if (!SeenOps.contains(Idx))
2315 return false;
2316 return true;
2317}
2318
2319const DIExpression *DIExpression::extractAddressClass(const DIExpression *Expr,
2320 unsigned &AddrClass) {
2321 if (!Expr->isValid())
2322 return Expr;
2323 auto SingleLocEltsOpt = Expr->getSingleLocationExpressionElements();
2324 if (!SingleLocEltsOpt)
2325 return Expr;
2326 ArrayRef<uint64_t> SingleLocElts = *SingleLocEltsOpt;
2327
2328 // Walk the operations, rather than the raw elements, so that operands are
2329 // never mistaken for opcodes.
2331 expr_op_iterator(SingleLocElts.end()));
2332 if (Ops.size() < 3)
2333 return Expr;
2334 const ExprOperand &AddrSpaceOp = Ops[Ops.size() - 3];
2335 const ExprOperand &SwapOp = Ops[Ops.size() - 2];
2336 const ExprOperand &XDerefOp = Ops[Ops.size() - 1];
2337 if (!SwapOp.is(dwarf::DW_OP_swap) || !(XDerefOp.is(dwarf::DW_OP_xderef) ||
2338 XDerefOp.is(dwarf::DW_OP_xderef_size)))
2339 return Expr;
2340
2341 uint64_t Op = AddrSpaceOp.getOp();
2342 if (Op == dwarf::DW_OP_constu)
2343 AddrClass = AddrSpaceOp.getArg(0);
2344 else if (isLitOp(Op))
2345 AddrClass = Op - dwarf::DW_OP_lit0;
2346 else
2347 return Expr;
2348
2349 if (AddrSpaceOp.get() == SingleLocElts.begin())
2350 return nullptr;
2351 return DIExpression::get(Expr->getContext(),
2352 ArrayRef(SingleLocElts.begin(), AddrSpaceOp.get()));
2353}
2354
2355DIExpression *DIExpression::prepend(const DIExpression *Expr, uint8_t Flags,
2356 int64_t Offset) {
2358 if (Flags & DIExpression::DerefBefore)
2359 Ops.push_back(dwarf::DW_OP_deref);
2360
2362 if (Flags & DIExpression::DerefAfter)
2363 Ops.push_back(dwarf::DW_OP_deref);
2364
2365 bool StackValue = Flags & DIExpression::StackValue;
2366 bool EntryValue = Flags & DIExpression::EntryValue;
2367
2368 return prependOpcodes(Expr, Ops, StackValue, EntryValue);
2369}
2370
2371DIExpression *DIExpression::appendOpsToArg(const DIExpression *Expr,
2373 unsigned ArgNo, bool StackValue) {
2374 assert(Expr && "Can't add ops to this expression");
2375
2376 // Handle non-variadic intrinsics by prepending the opcodes.
2377 if (!any_of(Expr->expr_ops(),
2378 [](auto Op) { return Op.is(dwarf::DW_OP_LLVM_arg); })) {
2379 assert(ArgNo == 0 &&
2380 "Location Index must be 0 for a non-variadic expression.");
2382 return DIExpression::prependOpcodes(Expr, NewOps, StackValue);
2383 }
2384
2386 for (auto Op : Expr->expr_ops()) {
2387 // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
2388 if (StackValue) {
2389 if (Op.getOp() == dwarf::DW_OP_stack_value)
2390 StackValue = false;
2391 else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
2392 NewOps.push_back(dwarf::DW_OP_stack_value);
2393 StackValue = false;
2394 }
2395 }
2396 Op.appendToVector(NewOps);
2397 if (auto Arg = dyn_cast<ArgOp>(Op); Arg && Arg.getIndex() == ArgNo)
2398 llvm::append_range(NewOps, Ops);
2399 }
2400 if (StackValue)
2401 NewOps.push_back(dwarf::DW_OP_stack_value);
2402
2403 return DIExpression::get(Expr->getContext(), NewOps);
2404}
2405
2406DIExpression *DIExpression::replaceArg(const DIExpression *Expr,
2407 uint64_t OldArg, uint64_t NewArg) {
2408 assert(Expr && "Can't replace args in this expression");
2409
2411
2412 for (auto Op : Expr->expr_ops()) {
2413 auto Arg = dyn_cast<ArgOp>(Op);
2414 if (!Arg || Arg.getIndex() < OldArg) {
2415 Op.appendToVector(NewOps);
2416 continue;
2417 }
2419 uint64_t ArgIndex = Arg.getIndex() == OldArg ? NewArg : Arg.getIndex();
2420 // OldArg has been deleted from the Op list, so decrement all indices
2421 // greater than it.
2422 if (ArgIndex > OldArg)
2423 --ArgIndex;
2424 NewOps.push_back(ArgIndex);
2425 }
2426 return DIExpression::get(Expr->getContext(), NewOps);
2427}
2428
2429DIExpression *DIExpression::prependOpcodes(const DIExpression *Expr,
2431 bool StackValue, bool EntryValue) {
2432 assert(Expr && "Can't prepend ops to this expression");
2433
2434 if (EntryValue) {
2436 // Use a block size of 1 for the target register operand. The
2437 // DWARF backend currently cannot emit entry values with a block
2438 // size > 1.
2439 Ops.push_back(1);
2440 }
2441
2442 // If there are no ops to prepend, do not even add the DW_OP_stack_value.
2443 if (Ops.empty())
2444 StackValue = false;
2445 for (auto Op : Expr->expr_ops()) {
2446 // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
2447 if (StackValue) {
2448 if (Op.getOp() == dwarf::DW_OP_stack_value)
2449 StackValue = false;
2450 else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
2451 Ops.push_back(dwarf::DW_OP_stack_value);
2452 StackValue = false;
2453 }
2454 }
2455 Op.appendToVector(Ops);
2456 }
2457 if (StackValue)
2458 Ops.push_back(dwarf::DW_OP_stack_value);
2459 return DIExpression::get(Expr->getContext(), Ops);
2460}
2461
2462DIExpression *DIExpression::append(const DIExpression *Expr,
2464 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
2465
2466 // Copy Expr's current op list.
2468 for (auto Op : Expr->expr_ops()) {
2469 // Append new opcodes before DW_OP_{stack_value, LLVM_fragment}.
2470 if (Op.getOp() == dwarf::DW_OP_stack_value ||
2471 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
2472 NewOps.append(Ops.begin(), Ops.end());
2473
2474 // Ensure that the new opcodes are only appended once.
2475 Ops = {};
2476 }
2477 Op.appendToVector(NewOps);
2478 }
2479 NewOps.append(Ops.begin(), Ops.end());
2480 auto *result =
2481 DIExpression::get(Expr->getContext(), NewOps)->foldConstantMath();
2482 assert(result->isValid() && "concatenated expression is not valid");
2483 return result;
2484}
2485
2486DIExpression *DIExpression::appendToStack(const DIExpression *Expr,
2488 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
2489 assert(std::none_of(expr_op_iterator(Ops.begin()),
2490 expr_op_iterator(Ops.end()),
2491 [](auto Op) {
2492 return Op.getOp() == dwarf::DW_OP_stack_value ||
2493 Op.getOp() == dwarf::DW_OP_LLVM_fragment;
2494 }) &&
2495 "Can't append this op");
2496
2497 // DIExpression stores opcodes and their arguments in a flat array. Walk the
2498 // parsed operations to find the last opcode that determines whether the
2499 // expression already ends in DW_OP_stack_value.
2500 std::optional<uint64_t> LastValueOp;
2501 for (auto Op : Expr->expr_ops()) {
2502 if (Op.isNonEmitting() || Op.getOp() == dwarf::DW_OP_LLVM_fragment)
2503 continue;
2504 LastValueOp = Op.getOp();
2505 }
2506 bool NeedsDeref = LastValueOp && *LastValueOp != dwarf::DW_OP_stack_value;
2507 bool NeedsStackValue = NeedsDeref || !LastValueOp;
2508
2509 // Append a DW_OP_deref after Expr's current op list if needed, then append
2510 // the new ops, and finally ensure that a single DW_OP_stack_value is present.
2512 if (NeedsDeref)
2513 NewOps.push_back(dwarf::DW_OP_deref);
2514 NewOps.append(Ops.begin(), Ops.end());
2515 if (NeedsStackValue)
2516 NewOps.push_back(dwarf::DW_OP_stack_value);
2517 return DIExpression::append(Expr, NewOps);
2518}
2519
2520std::optional<DIExpression *> DIExpression::createFragmentExpression(
2521 const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits) {
2523 // Track whether it's safe to split the value at the top of the DWARF stack,
2524 // assuming that it'll be used as an implicit location value.
2525 bool CanSplitValue = true;
2526 // Track whether we need to add a fragment expression to the end of Expr.
2527 bool EmitFragment = true;
2528 // Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment.
2529 if (Expr) {
2530 for (auto Op : Expr->expr_ops()) {
2531 switch (Op.getOp()) {
2532 default:
2533 break;
2534 case dwarf::DW_OP_shr:
2535 case dwarf::DW_OP_shra:
2536 case dwarf::DW_OP_shl:
2537 case dwarf::DW_OP_plus:
2538 case dwarf::DW_OP_plus_uconst:
2539 case dwarf::DW_OP_minus:
2540 // We can't safely split arithmetic or shift operations into multiple
2541 // fragments because we can't express carry-over between fragments.
2542 //
2543 // FIXME: We *could* preserve the lowest fragment of a constant offset
2544 // operation if the offset fits into SizeInBits.
2545 CanSplitValue = false;
2546 break;
2547 case dwarf::DW_OP_deref:
2548 case dwarf::DW_OP_deref_size:
2549 case dwarf::DW_OP_deref_type:
2550 case dwarf::DW_OP_xderef:
2551 case dwarf::DW_OP_xderef_size:
2552 case dwarf::DW_OP_xderef_type:
2553 // Preceeding arithmetic operations have been applied to compute an
2554 // address. It's okay to split the value loaded from that address.
2555 CanSplitValue = true;
2556 break;
2557 case dwarf::DW_OP_stack_value:
2558 // Bail if this expression computes a value that cannot be split.
2559 if (!CanSplitValue)
2560 return std::nullopt;
2561 break;
2564 // If we've decided we don't need a fragment then give up if we see that
2565 // there's already a fragment expression.
2566 // FIXME: We could probably do better here
2567 if (!EmitFragment)
2568 return std::nullopt;
2569 // Make the new offset point into the existing fragment.
2570 uint64_t FragmentOffsetInBits = Fragment.getOffsetInBits();
2571 uint64_t FragmentSizeInBits = Fragment.getSizeInBits();
2572 (void)FragmentSizeInBits;
2573 assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&
2574 "new fragment outside of original fragment");
2575 OffsetInBits += FragmentOffsetInBits;
2576 continue;
2577 }
2580 auto Extract = cast<ExtractBitsOp>(Op);
2581 // If we're extracting bits from inside of the fragment that we're
2582 // creating then we don't have a fragment after all, and just need to
2583 // adjust the offset that we're extracting from.
2584 uint64_t ExtractOffsetInBits = Extract.getOffsetInBits();
2585 uint64_t ExtractSizeInBits = Extract.getSizeInBits();
2586 if (ExtractOffsetInBits >= OffsetInBits &&
2587 ExtractOffsetInBits + ExtractSizeInBits <=
2588 OffsetInBits + SizeInBits) {
2589 Ops.push_back(Op.getOp());
2590 Ops.push_back(ExtractOffsetInBits - OffsetInBits);
2591 Ops.push_back(ExtractSizeInBits);
2592 EmitFragment = false;
2593 continue;
2594 }
2595 // If the extracted bits aren't fully contained within the fragment then
2596 // give up.
2597 // FIXME: We could probably do better here
2598 return std::nullopt;
2599 }
2600 }
2601 Op.appendToVector(Ops);
2602 }
2603 }
2604 assert((!Expr->isImplicit() || CanSplitValue) && "Expr can't be split");
2605 assert(Expr && "Unknown DIExpression");
2606 if (EmitFragment) {
2608 Ops.push_back(OffsetInBits);
2609 Ops.push_back(SizeInBits);
2610 }
2611 return DIExpression::get(Expr->getContext(), Ops);
2612}
2613
2614/// See declaration for more info.
2616 const DataLayout &DL, const Value *SliceStart, uint64_t SliceOffsetInBits,
2617 uint64_t SliceSizeInBits, const Value *DbgPtr, int64_t DbgPtrOffsetInBits,
2618 int64_t DbgExtractOffsetInBits, DIExpression::FragmentInfo VarFrag,
2619 std::optional<DIExpression::FragmentInfo> &Result,
2620 int64_t &OffsetFromLocationInBits) {
2621
2622 if (VarFrag.SizeInBits == 0)
2623 return false; // Variable size is unknown.
2624
2625 // Difference between mem slice start and the dbg location start.
2626 // 0 4 8 12 16 ...
2627 // | |
2628 // dbg location start
2629 // |
2630 // mem slice start
2631 // Here MemStartRelToDbgStartInBits is 8. Note this can be negative.
2632 int64_t MemStartRelToDbgStartInBits;
2633 {
2634 auto MemOffsetFromDbgInBytes = SliceStart->getPointerOffsetFrom(DbgPtr, DL);
2635 if (!MemOffsetFromDbgInBytes)
2636 return false; // Can't calculate difference in addresses.
2637 // Difference between the pointers.
2638 MemStartRelToDbgStartInBits = *MemOffsetFromDbgInBytes * 8;
2639 // Add the difference of the offsets.
2640 MemStartRelToDbgStartInBits +=
2641 SliceOffsetInBits - (DbgPtrOffsetInBits + DbgExtractOffsetInBits);
2642 }
2643
2644 // Out-param. Invert offset to get offset from debug location.
2645 OffsetFromLocationInBits = -MemStartRelToDbgStartInBits;
2646
2647 // Check if the variable fragment sits outside (before) this memory slice.
2648 int64_t MemEndRelToDbgStart = MemStartRelToDbgStartInBits + SliceSizeInBits;
2649 if (MemEndRelToDbgStart < 0) {
2650 Result = {0, 0}; // Out-param.
2651 return true;
2652 }
2653
2654 // Work towards creating SliceOfVariable which is the bits of the variable
2655 // that the memory region covers.
2656 // 0 4 8 12 16 ...
2657 // | |
2658 // dbg location start with VarFrag offset=32
2659 // |
2660 // mem slice start: SliceOfVariable offset=40
2661 int64_t MemStartRelToVarInBits =
2662 MemStartRelToDbgStartInBits + VarFrag.OffsetInBits;
2663 int64_t MemEndRelToVarInBits = MemStartRelToVarInBits + SliceSizeInBits;
2664 // If the memory region starts before the debug location the fragment
2665 // offset would be negative, which we can't encode. Limit those to 0. This
2666 // is fine because those bits necessarily don't overlap with the existing
2667 // variable fragment.
2668 int64_t MemFragStart = std::max<int64_t>(0, MemStartRelToVarInBits);
2669 int64_t MemFragSize =
2670 std::max<int64_t>(0, MemEndRelToVarInBits - MemFragStart);
2671 DIExpression::FragmentInfo SliceOfVariable(MemFragSize, MemFragStart);
2672
2673 // Intersect the memory region fragment with the variable location fragment.
2674 DIExpression::FragmentInfo TrimmedSliceOfVariable =
2675 DIExpression::FragmentInfo::intersect(SliceOfVariable, VarFrag);
2676 if (TrimmedSliceOfVariable == VarFrag)
2677 Result = std::nullopt; // Out-param.
2678 else
2679 Result = TrimmedSliceOfVariable; // Out-param.
2680 return true;
2681}
2682
2683std::pair<DIExpression *, const ConstantInt *>
2685 // Copy the APInt so we can modify it.
2686 APInt NewInt = CI->getValue();
2688
2689 // Fold operators only at the beginning of the expression.
2690 bool First = true;
2691 bool Changed = false;
2692 for (auto Op : expr_ops()) {
2693 switch (Op.getOp()) {
2694 default:
2695 // We fold only the leading part of the expression; if we get to a part
2696 // that we're going to copy unchanged, and haven't done any folding,
2697 // then the entire expression is unchanged and we can return early.
2698 if (!Changed)
2699 return {this, CI};
2700 First = false;
2701 break;
2703 if (!First)
2704 break;
2705 Changed = true;
2706 auto Convert = cast<ConvertOp>(Op);
2707 if (Convert.getEncoding() == dwarf::DW_ATE_signed)
2708 NewInt = NewInt.sextOrTrunc(Convert.getBitSize());
2709 else {
2710 assert(Convert.getEncoding() == dwarf::DW_ATE_unsigned &&
2711 "Unexpected operand");
2712 NewInt = NewInt.zextOrTrunc(Convert.getBitSize());
2713 }
2714 continue;
2715 }
2716 }
2717 Op.appendToVector(Ops);
2718 }
2719 if (!Changed)
2720 return {this, CI};
2721 return {DIExpression::get(getContext(), Ops),
2722 ConstantInt::get(getContext(), NewInt)};
2723}
2724
2726 uint64_t Result = 0;
2727 for (auto ExprOp : expr_ops())
2728 if (auto Arg = dyn_cast<ArgOp>(ExprOp))
2729 Result = std::max(Result, Arg.getIndex() + 1);
2730 assert(hasAllLocationOps(Result) &&
2731 "Expression is missing one or more location operands.");
2732 return Result;
2733}
2734
2735std::optional<DIExpression::SignedOrUnsignedConstant>
2737
2738 // Recognize signed and unsigned constants.
2739 // An signed constants can be represented as DW_OP_consts C DW_OP_stack_value
2740 // (DW_OP_LLVM_fragment of Len).
2741 // An unsigned constant can be represented as
2742 // DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment of Len), or as
2743 // DW_OP_lit<C> DW_OP_stack_value (DW_OP_LLVM_fragment of Len).
2744
2745 if (getNumElements() == 0)
2746 return std::nullopt;
2747 uint64_t Op = getElement(0);
2748 if (Op != dwarf::DW_OP_consts && Op != dwarf::DW_OP_constu && !isLitOp(Op))
2749 return std::nullopt;
2750
2751 // The number of elements used by the constant: DW_OP_lit<C> encodes its
2752 // value in the opcode, while DW_OP_constu/DW_OP_consts take an operand.
2753 unsigned ConstSize = expr_op_begin()->getSize();
2754 unsigned NumElements = getNumElements();
2755 // The constant may be followed by DW_OP_stack_value (1 element), and then
2756 // by DW_OP_LLVM_fragment, offset, size (3 more elements).
2757 if (NumElements != ConstSize && NumElements != ConstSize + 1 &&
2758 NumElements != ConstSize + 4)
2759 return std::nullopt;
2760
2761 if (NumElements == ConstSize && Op == dwarf::DW_OP_consts)
2763
2764 if ((NumElements == ConstSize + 1 &&
2765 getElement(ConstSize) != dwarf::DW_OP_stack_value) ||
2766 (NumElements == ConstSize + 4 &&
2767 (getElement(ConstSize) != dwarf::DW_OP_stack_value ||
2768 getElement(ConstSize + 1) != dwarf::DW_OP_LLVM_fragment)))
2769 return std::nullopt;
2770 return Op == dwarf::DW_OP_consts ? SignedOrUnsignedConstant::SignedConstant
2772}
2773
2775 assert(isConstant() && "Expression is not a constant");
2776 uint64_t Op = getElement(0);
2777 if (isLitOp(Op))
2778 return Op - dwarf::DW_OP_lit0;
2779 return getElement(1);
2780}
2781
2782DIExpression::ExtOps DIExpression::getExtOps(unsigned FromSize, unsigned ToSize,
2783 bool Signed) {
2784 dwarf::TypeKind TK = Signed ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned;
2786 dwarf::DW_OP_LLVM_convert, ToSize, TK}};
2787 return Ops;
2788}
2789
2790DIExpression *DIExpression::appendExt(const DIExpression *Expr,
2791 unsigned FromSize, unsigned ToSize,
2792 bool Signed) {
2793 return appendToStack(Expr, getExtOps(FromSize, ToSize, Signed));
2794}
2795
2797DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable,
2799 bool ShouldCreate) {
2801 Metadata *Ops[] = {Variable, Expression};
2803}
2804DIObjCProperty::DIObjCProperty(LLVMContext &C, StorageType Storage,
2805 unsigned Line, unsigned Attributes,
2807 : DINode(C, DIObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property, Ops),
2809
2810DIObjCProperty *DIObjCProperty::getImpl(
2811 LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
2812 MDString *GetterName, MDString *SetterName, unsigned Attributes,
2813 Metadata *Type, StorageType Storage, bool ShouldCreate) {
2814 assert(isCanonical(Name) && "Expected canonical MDString");
2815 assert(isCanonical(GetterName) && "Expected canonical MDString");
2816 assert(isCanonical(SetterName) && "Expected canonical MDString");
2817 DEFINE_GETIMPL_LOOKUP(DIObjCProperty, (Name, File, Line, GetterName,
2818 SetterName, Attributes, Type));
2820 DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops);
2821}
2822
2823DIProperty::DIProperty(LLVMContext &C, StorageType Storage, unsigned Line,
2825 : DINode(C, DIPropertyKind, Storage, dwarf::DW_TAG_property, Ops),
2826 Line(Line) {}
2827
2828DIProperty *DIProperty::getImpl(LLVMContext &Context, MDString *Name,
2829 Metadata *File, unsigned Line, Metadata *Type,
2830 Metadata *BackingStorage, StorageType Storage,
2831 bool ShouldCreate) {
2832 assert(isCanonical(Name) && "Expected canonical MDString");
2833 DEFINE_GETIMPL_LOOKUP(DIProperty, (Name, File, Line, Type, BackingStorage));
2835 DEFINE_GETIMPL_STORE(DIProperty, (Line), Ops);
2836}
2837
2838DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
2839 Metadata *Scope, Metadata *Entity,
2840 Metadata *File, unsigned Line,
2841 MDString *Name, Metadata *Elements,
2842 StorageType Storage,
2843 bool ShouldCreate) {
2844 assert(isCanonical(Name) && "Expected canonical MDString");
2845 DEFINE_GETIMPL_LOOKUP(DIImportedEntity,
2846 (Tag, Scope, Entity, File, Line, Name, Elements));
2848 DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops);
2849}
2850
2851DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
2852 MDString *Name, MDString *Value, StorageType Storage,
2853 bool ShouldCreate) {
2854 assert(isCanonical(Name) && "Expected canonical MDString");
2856 Metadata *Ops[] = {Name, Value};
2857 DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops);
2858}
2859
2860DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
2861 unsigned Line, Metadata *File,
2862 Metadata *Elements, StorageType Storage,
2863 bool ShouldCreate) {
2864 DEFINE_GETIMPL_LOOKUP(DIMacroFile, (MIType, Line, File, Elements));
2865 Metadata *Ops[] = {File, Elements};
2866 DEFINE_GETIMPL_STORE(DIMacroFile, (MIType, Line), Ops);
2867}
2868
2869DIArgList *DIArgList::get(LLVMContext &Context,
2871 auto ExistingIt = Context.pImpl->DIArgLists.find_as(DIArgListKeyInfo(Args));
2872 if (ExistingIt != Context.pImpl->DIArgLists.end())
2873 return *ExistingIt;
2874 DIArgList *NewArgList = new DIArgList(Context, Args);
2875 Context.pImpl->DIArgLists.insert(NewArgList);
2876 return NewArgList;
2877}
2878
2880 ValueAsMetadata **OldVMPtr = static_cast<ValueAsMetadata **>(Ref);
2881 assert((!New || isa<ValueAsMetadata>(New)) &&
2882 "DIArgList must be passed a ValueAsMetadata");
2883 untrack();
2884 // We need to update the set storage once the Args are updated since they
2885 // form the key to the DIArgLists store.
2886 getContext().pImpl->DIArgLists.erase(this);
2888 for (ValueAsMetadata *&VM : Args) {
2889 if (&VM == OldVMPtr) {
2890 if (NewVM)
2891 VM = NewVM;
2892 else
2893 VM = ValueAsMetadata::get(PoisonValue::get(VM->getValue()->getType()));
2894 }
2895 }
2896 // We've changed the contents of this DIArgList, and the set storage may
2897 // already contain a DIArgList with our new set of args; if it does, then we
2898 // must RAUW this with the existing DIArgList, otherwise we simply insert this
2899 // back into the set storage.
2900 DIArgList *ExistingArgList = getUniqued(getContext().pImpl->DIArgLists, this);
2901 if (ExistingArgList) {
2902 replaceAllUsesWith(ExistingArgList);
2903 // Clear this here so we don't try to untrack in the destructor.
2904 Args.clear();
2905 delete this;
2906 return;
2907 }
2908 getContext().pImpl->DIArgLists.insert(this);
2909 track();
2910}
2911void DIArgList::track() {
2912 for (ValueAsMetadata *&VAM : Args)
2913 if (VAM)
2914 MetadataTracking::track(&VAM, *VAM, *this);
2915}
2916void DIArgList::untrack() {
2917 for (ValueAsMetadata *&VAM : Args)
2918 if (VAM)
2919 MetadataTracking::untrack(&VAM, *VAM);
2920}
2921void DIArgList::dropAllReferences(bool Untrack) {
2922 if (Untrack)
2923 untrack();
2924 Args.clear();
2925 ReplaceableUses::resolveAllUses(/* ResolveUsers */ false);
2926}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
constexpr LLT S1
AMDGPU Kernel Attributes
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static Metadata * mergeIRLayers(LLVMContext &C, const DILocation *LocA, const DILocation *LocB)
static ConstantAsMetadata * extractConstantMetadata(Metadata *ExtraData)
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 std::pair< DIScope *, LineColumn > getNearestMatchingScope(const DILocation *L1, const DILocation *L2)
static LineColumn getLocalScopeLocationOr(DIScope *S, LineColumn Default)
Returns the location of DILocalScope, if present, or a default value.
std::pair< unsigned, unsigned > LineColumn
static bool hasConflictingSize(const DICompositeType *CT, Metadata *SizeInBits)
static ScopeT getRawRetainedNodeScopeInternal(NodeT *N)
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 DILexicalBlockBase * cloneAndReplaceParentScope(DILexicalBlockBase *LBB, DIScope *NewParent)
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
This file defines the DenseSet and SmallDenseSet classes.
static unsigned encodingBits(unsigned C)
static unsigned encodeComponent(unsigned C)
static unsigned getNextComponentInDiscriminator(unsigned D)
Returns the next component stored in discriminator.
static unsigned getUnsignedFromPrefixEncoding(unsigned U)
Reverse transformation as getPrefixEncodingFromUnsigned.
@ Default
This file contains constants used for implementing Dwarf debug support.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first DebugLoc that has line number information, given a range of instructions.
#define T
static constexpr StringLiteral Filename
RISCVCC::CondCode CC
MachineInstr *& Lo
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
This file implements a set that has insertion order iteration characteristics.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Class for arbitrary precision integers.
Definition APInt.h:78
LLVM_ABI APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
Definition APInt.cpp:1078
LLVM_ABI APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
Definition APInt.cpp:1086
Annotations lets you mark points and ranges inside source code, for tests:
Definition Annotations.h:67
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition ArrayRef.h:194
iterator end() const
Definition ArrayRef.h:130
size_t size() const
Get the array size.
Definition ArrayRef.h:141
iterator begin() const
Definition ArrayRef.h:129
bool empty() const
Check if the array is empty.
Definition ArrayRef.h:136
static ConstantAsMetadata * get(Constant *C)
Definition Metadata.h:549
This is the shared class of boolean and integer constants.
Definition Constants.h:87
static ConstantInt * getSigned(IntegerType *Ty, int64_t V, bool ImplicitTrunc=false)
Return a ConstantInt with the specified value for the specified type.
Definition Constants.h:135
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition Constants.h:159
This is an important base class in LLVM.
Definition Constant.h:44
LLVM_ABI void handleChangedOperand(void *Ref, Metadata *New)
static LLVM_ABI DIArgList * get(LLVMContext &Context, ArrayRef< ValueAsMetadata * > Args)
DIBasicType(LLVMContext &C, StorageType Storage, unsigned Tag, unsigned LineNo, uint32_t AlignInBits, unsigned Encoding, uint32_t NumExtraInhabitants, uint32_t DataSizeInBits, DIFlags Flags, ArrayRef< Metadata * > Ops)
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags unsigned StringRef uint64_t uint32_t unsigned uint32_t DIFlags Flags unsigned StringRef DIFile * File
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags unsigned StringRef uint64_t uint32_t unsigned uint32_t DIFlags Flags unsigned StringRef DIFile unsigned DIScope * Scope
unsigned StringRef uint64_t SizeInBits
LLVM_ABI std::optional< Signedness > getSignedness() const
Return the signedness of this type, or std::nullopt if this type is neither signed nor unsigned.
unsigned getEncoding() const
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags unsigned StringRef uint64_t uint32_t unsigned uint32_t NumExtraInhabitants
static DIBasicType * getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, DIFile *File, unsigned LineNo, DIScope *Scope, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, uint32_t NumExtraInhabitants, uint32_t DataSizeInBits, DIFlags Flags, StorageType Storage, bool ShouldCreate=true)
unsigned StringRef Name
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t AlignInBits
unsigned StringRef uint64_t FlagZero unsigned StringRef uint64_t uint32_t unsigned DIFlags Flags unsigned StringRef uint64_t uint32_t unsigned uint32_t DIFlags Flags unsigned StringRef DIFile unsigned LineNo
Debug common block.
Metadata Metadata * Decl
Metadata Metadata MDString Metadata unsigned LineNo
Metadata Metadata MDString * Name
Metadata Metadata MDString Metadata * File
static LLVM_ABI const char * nameTableKindString(DebugNameTableKind PK)
static LLVM_ABI const char * emissionKindString(DebugEmissionKind EK)
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString * SysRoot
DISourceLanguageName Metadata MDString bool MDString * Flags
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata uint64_t bool bool unsigned bool MDString MDString * SDK
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata * GlobalVariables
DebugEmissionKind getEmissionKind() const
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata * EnumTypes
DISourceLanguageName Metadata MDString * Producer
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata * RetainedTypes
DISourceLanguageName Metadata MDString bool MDString unsigned MDString * SplitDebugFilename
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata * ImportedEntities
DISourceLanguageName Metadata MDString bool MDString unsigned MDString unsigned Metadata Metadata Metadata Metadata Metadata * Macros
DebugNameTableKind getNameTableKind() const
DISourceLanguageName Metadata * File
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t AlignInBits
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > EnumKind
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata * DataLocation
static LLVM_ABI DICompositeType * buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, Metadata *SizeInBits, uint32_t AlignInBits, Metadata *OffsetInBits, Metadata *Specification, uint32_t NumExtraInhabitants, DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, std::optional< uint32_t > EnumKind, Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator, Metadata *DataLocation, Metadata *Associated, Metadata *Allocated, Metadata *Rank, Metadata *Annotations, Metadata *BitStride)
Build a DICompositeType with the given ODR identifier.
unsigned MDString Metadata unsigned Line
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata * Elements
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned RuntimeLang
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata * Annotations
unsigned MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString * Identifier
static LLVM_ABI 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 MDString Metadata unsigned Metadata Metadata uint64_t uint32_t uint64_t DIFlags Metadata unsigned std::optional< uint32_t > Metadata Metadata MDString Metadata Metadata Metadata Metadata Metadata Metadata Metadata uint32_t Metadata * BitStride
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata * OffsetInBits
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t AlignInBits
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > std::optional< PtrAuthData > PtrAuthData
Metadata * getExtraData() const
Get extra data associated with this derived type.
unsigned StringRef DIFile * File
unsigned StringRef DIFile unsigned DIScope DIType Metadata uint32_t Metadata std::optional< unsigned > DWARFAddressSpace
LLVM_ABI DIType * getClassType() const
Get casted version of extra data.
LLVM_ABI Constant * getConstant() const
unsigned StringRef DIFile unsigned DIScope DIType Metadata * SizeInBits
LLVM_ABI Constant * getStorageOffsetInBits() const
LLVM_ABI Constant * getDiscriminantValue() const
unsigned StringRef Name
LLVM_ABI uint32_t getVBPtrOffset() const
Enumeration value.
int64_t bool MDString * Name
static LLVM_ABI bool classof(const ExprOperand *Op)
static LLVM_ABI bool classof(const ExprOperand *Op)
static LLVM_ABI bool classof(const ExprOperand *Op)
static LLVM_ABI bool classof(const ExprOperand *Op)
A lightweight wrapper around an expression operand.
LLVM_ABI bool isNonEmitting() const
Return true if CodeGen handles this operand without adding bytes to the DWARF expression.
LLVM_ABI unsigned getSize() const
Return the size of the operand.
uint64_t getArg(unsigned I) const
Get an argument to the operand.
bool is(uint64_t Opcode) const
Return true if this is Opcode.
uint64_t getOp() const
Get the operand code.
static LLVM_ABI bool classof(const ExprOperand *Op)
LLVM_ABI bool isSigned() const
Return whether the extracted value is sign-extended.
static LLVM_ABI bool classof(const ExprOperand *Op)
static LLVM_ABI bool classof(const ExprOperand *Op)
static LLVM_ABI bool classof(const ExprOperand *Op)
An iterator for expression operands.
DWARF expression.
element_iterator elements_end() const
LLVM_ABI bool isEntryValue() const
Check if the expression consists of exactly one entry value operand.
iterator_range< expr_op_iterator > expr_ops() const
static LLVM_ABI DIExpression * append(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Append the opcodes Ops to DIExpr.
std::array< uint64_t, 6 > ExtOps
unsigned getNumElements() const
static LLVM_ABI bool isLitOp(uint64_t Op)
Return true if Op is one of DW_OP_lit0 through DW_OP_lit31.
static LLVM_ABI ExtOps getExtOps(unsigned FromSize, unsigned ToSize, bool Signed)
Returns the ops for a zero- or sign-extension in a DIExpression.
expr_op_iterator expr_op_begin() const
Visit the elements via ExprOperand wrappers.
LLVM_ABI bool extractIfOffset(int64_t &Offset) const
If this is a constant offset, extract it.
static LLVM_ABI void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
DbgVariableFragmentInfo FragmentInfo
LLVM_ABI bool startsWithDeref() const
Return whether the first element a DW_OP_deref.
static LLVM_ABI bool isEqualExpression(const DIExpression *FirstExpr, bool FirstIndirect, const DIExpression *SecondExpr, bool SecondIndirect)
Determines whether two debug values should produce equivalent DWARF expressions, using their DIExpres...
expr_op_iterator expr_op_end() const
LLVM_ABI bool isImplicit() const
Return whether this is an implicit location description.
static LLVM_ABI bool calculateFragmentIntersect(const DataLayout &DL, const Value *SliceStart, uint64_t SliceOffsetInBits, uint64_t SliceSizeInBits, const Value *DbgPtr, int64_t DbgPtrOffsetInBits, int64_t DbgExtractOffsetInBits, DIExpression::FragmentInfo VarFrag, std::optional< DIExpression::FragmentInfo > &Result, int64_t &OffsetFromLocationInBits)
Computes a fragment, bit-extract operation if needed, and new constant offset to describe a part of a...
element_iterator elements_begin() const
LLVM_ABI bool hasAllLocationOps(unsigned N) const
Returns true iff this DIExpression contains at least one instance of DW_OP_LLVM_arg,...
std::optional< FragmentInfo > getFragmentInfo() const
Retrieve the details of this fragment expression.
static LLVM_ABI DIExpression * appendOpsToArg(const DIExpression *Expr, ArrayRef< uint64_t > Ops, unsigned ArgNo, bool StackValue=false)
Create a copy of Expr by appending the given list of Ops to each instance of the operand DW_OP_LLVM_a...
LLVM_ABI uint64_t getConstantValue() const
Return the value of a constant expression, as recognized by isConstant().
LLVM_ABI bool isComplex() const
Return whether the location is computed on the expression stack, meaning it cannot be a simple regist...
static LLVM_ABI std::optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
static LLVM_ABI std::optional< const DIExpression * > convertToNonVariadicExpression(const DIExpression *Expr)
If Expr is a valid single-location expression, i.e.
LLVM_ABI std::pair< DIExpression *, const ConstantInt * > constantFold(const ConstantInt *CI)
Try to shorten an expression with an initial constant operand.
LLVM_ABI bool isDeref() const
Return whether there is exactly one operator and it is a DW_OP_deref;.
static LLVM_ABI const DIExpression * convertToVariadicExpression(const DIExpression *Expr)
If Expr is a non-variadic expression (i.e.
LLVM_ABI uint64_t getNumLocationOperands() const
Return the number of unique location operands referred to (via DW_OP_LLVM_arg) in this expression; th...
ArrayRef< uint64_t > getElements() const
static LLVM_ABI DIExpression * replaceArg(const DIExpression *Expr, uint64_t OldArg, uint64_t NewArg)
Create a copy of Expr with each instance of DW_OP_LLVM_arg, \p OldArg replaced with DW_OP_LLVM_arg,...
LLVM_ABI std::optional< uint64_t > getActiveBits(DIVariable *Var)
Return the number of bits that have an active value, i.e.
static LLVM_ABI void canonicalizeExpressionOps(SmallVectorImpl< uint64_t > &Ops, const DIExpression *Expr, bool IsIndirect)
Inserts the elements of Expr into Ops modified to a canonical form, which uses DW_OP_LLVM_arg (i....
uint64_t getElement(unsigned I) const
static LLVM_ABI bool extractLeadingOffset(ArrayRef< uint64_t > Ops, int64_t &OffsetInBytes, SmallVectorImpl< uint64_t > &RemainingOps)
static LLVM_ABI std::optional< DIExpression * > createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits)
Create a DIExpression to describe one part of an aggregate variable that is fragmented across multipl...
static LLVM_ABI const DIExpression * convertToUndefExpression(const DIExpression *Expr)
Removes all elements from Expr that do not apply to an undef debug value, which includes every operat...
static LLVM_ABI DIExpression * prepend(const DIExpression *Expr, uint8_t Flags, int64_t Offset=0)
Prepend DIExpr with a deref and offset operation and optionally turn it into a stack value or/and an ...
static LLVM_ABI DIExpression * appendToStack(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Convert DIExpr into a stack value if it isn't one already by appending DW_OP_deref if needed,...
static LLVM_ABI DIExpression * appendExt(const DIExpression *Expr, unsigned FromSize, unsigned ToSize, bool Signed)
Append a zero- or sign-extension to Expr.
LLVM_ABI std::optional< ArrayRef< uint64_t > > getSingleLocationExpressionElements() const
Returns a reference to the elements contained in this expression, skipping past the leading DW_OP_LLV...
LLVM_ABI bool isSingleLocationExpression() const
Return whether the evaluated expression makes use of a single location at the start of the expression...
LLVM_ABI std::optional< SignedOrUnsignedConstant > isConstant() const
Determine whether this represents a constant value, if so.
LLVM_ABI bool isValid() const
static LLVM_ABI const DIExpression * extractAddressClass(const DIExpression *Expr, unsigned &AddrClass)
Checks if the expression ends with <DWARF Address Space> DW_OP_swap DW_OP_xderef[_size],...
static LLVM_ABI DIExpression * prependOpcodes(const DIExpression *Expr, SmallVectorImpl< uint64_t > &Ops, bool StackValue=false, bool EntryValue=false)
Prepend DIExpr with the given opcodes and optionally turn it into a stack value.
MDString MDString * Directory
MDString MDString std::optional< ChecksumInfo< MDString * > > MDString * Source
static LLVM_ABI std::optional< ChecksumKind > getChecksumKind(StringRef CSKindStr)
MDString MDString std::optional< ChecksumInfo< MDString * > > CS
static LLVM_ABI std::optional< FixedPointKind > getFixedPointKind(StringRef Str)
static LLVM_ABI const char * fixedPointKindString(FixedPointKind)
unsigned StringRef DIFile unsigned DIScope uint64_t uint32_t unsigned DIFlags unsigned int APInt Numerator
unsigned StringRef DIFile unsigned LineNo
unsigned StringRef DIFile unsigned DIScope uint64_t uint32_t unsigned Encoding
unsigned StringRef DIFile unsigned DIScope uint64_t uint32_t unsigned DIFlags unsigned int APInt APInt Denominator
unsigned StringRef DIFile unsigned DIScope uint64_t SizeInBits
unsigned StringRef DIFile unsigned DIScope uint64_t uint32_t AlignInBits
LLVM_ABI bool isSigned() const
unsigned StringRef DIFile unsigned DIScope uint64_t uint32_t unsigned DIFlags unsigned int Factor
@ FixedPointBinary
Scale factor 2^Factor.
@ FixedPointDecimal
Scale factor 10^Factor.
@ FixedPointRational
Arbitrary rational scale factor.
unsigned StringRef DIFile * File
Metadata * getRawLowerBound() const
Metadata * getRawCountNode() const
Metadata * getRawStride() const
LLVM_ABI BoundType getLowerBound() const
Metadata * getRawUpperBound() const
LLVM_ABI BoundType getCount() const
LLVM_ABI BoundType getUpperBound() const
PointerUnion< DIVariable *, DIExpression * > BoundType
LLVM_ABI BoundType getStride() const
A pair of DIGlobalVariable and DIExpression.
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 MDString Metadata unsigned Metadata bool bool Metadata Metadata uint32_t Metadata * Annotations
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 unsigned bool std::optional< unsigned > CoroSuspendIdx
Metadata MDString Metadata unsigned unsigned Column
Metadata MDString Metadata unsigned unsigned bool IsArtificial
Metadata MDString Metadata unsigned Line
Metadata MDString * Name
Metadata MDString Metadata * File
A sequence of DILayerLoc entries.
iterator_range< layer_iterator > layers() const
A single intermediate-IR layer location.
LLVM_ABI DILexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage, ArrayRef< Metadata * > Ops)
Metadata Metadata unsigned Discriminator
Debug lexical block.
Metadata Metadata unsigned unsigned Column
Metadata Metadata * File
A scope for locals.
LLVM_ABI DISubprogram * getSubprogram() const
Get the subprogram for this scope.
LLVM_ABI DILocalScope * getNonLexicalBlockFileScope() const
Get the first non DILexicalBlockFile scope of this scope.
DILocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, ArrayRef< Metadata * > Ops)
static LLVM_ABI DILocalScope * cloneScopeForSubprogram(DILocalScope &RootScope, DISubprogram &NewSP, LLVMContext &Ctx, DenseMap< const MDNode *, MDNode * > &Cache)
Traverses the scope chain rooted at RootScope until it hits a Subprogram, recreating the chain with "...
Metadata MDString Metadata unsigned Metadata * Type
Metadata MDString Metadata * File
Metadata MDString * Name
Metadata MDString Metadata unsigned Line
Metadata MDString Metadata unsigned Metadata unsigned DIFlags uint32_t Metadata * Annotations
Metadata MDString Metadata unsigned Metadata unsigned DIFlags uint32_t AlignInBits
unsigned unsigned DILocalScope * Scope
static LLVM_ABI DILocation * getMergedLocations(ArrayRef< DILocation * > Locs)
Try to combine the vector of locations passed as input in a single one.
DILayerLocList * getIRLayers() const
unsigned unsigned DILocalScope DILocation bool uint64_t uint8_t Metadata * IRLayers
static LLVM_ABI std::optional< unsigned > encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI)
Raw encoding of the discriminator.
unsigned unsigned DILocalScope DILocation bool ImplicitCode
static LLVM_ABI void decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF, unsigned &CI)
Raw decoder for values in an encoded discriminator D.
static LLVM_ABI DILocation * getMergedLocation(DILocation *LocA, DILocation *LocB)
Attempts to merge LocA and LocB into a single location; see DebugLoc::getMergedLocation for more deta...
unsigned unsigned Column
unsigned unsigned DILocalScope DILocation * InlinedAt
unsigned unsigned Metadata * File
unsigned unsigned Line
unsigned unsigned Metadata Metadata * Elements
unsigned unsigned MDString MDString * Value
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.
LLVM_ABI dwarf::Tag getTag() const
static LLVM_ABI DIFlags getFlag(StringRef Flag)
static LLVM_ABI DIFlags splitFlags(DIFlags Flags, SmallVectorImpl< DIFlags > &SplitFlags)
Split up a flags bitfield.
DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, ArrayRef< Metadata * > Ops1, ArrayRef< Metadata * > Ops2={})
static LLVM_ABI StringRef getFlagString(DIFlags Flag)
DIFlags
Debug info flags.
MDString Metadata * File
MDString Metadata unsigned MDString MDString unsigned Metadata * Type
MDString Metadata unsigned MDString * GetterName
MDString Metadata unsigned MDString MDString * SetterName
A property of a class or structure.
MDString Metadata unsigned Metadata * Type
MDString Metadata unsigned Metadata Metadata * BackingStorage
MDString Metadata * File
Base class for scope-like contexts.
LLVM_ABI StringRef getName() const
DIFile * getFile() const
LLVM_ABI DIScope * getScope() const
DIScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, ArrayRef< Metadata * > Ops)
Wrapper structure that holds source language identity metadata that includes language name,...
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 Metadata Metadata uint64_t uint32_t unsigned Encoding
unsigned MDString Metadata * StringLength
Subprogram description. Uses SubclassData1.
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata Metadata MDString bool UsesKeyInstructions
LLVM_ABI void cleanupRetainedNodes()
When IR modules are merged, typically during LTO, the merged module may contain several types having ...
Metadata MDString MDString Metadata unsigned Metadata unsigned ScopeLine
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags SPFlags
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata * ContainingType
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata * TemplateParams
static LLVM_ABI DILocalScope * getRetainedNodeScope(MDNode *N)
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata Metadata MDString * TargetFuncName
static LLVM_ABI DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized, unsigned Virtuality=SPFlagNonvirtual, bool IsMainSubprogram=false)
static LLVM_ABI const DIScope * getRawRetainedNodeScope(const MDNode *N)
void cleanupRetainedNodesIf(T &&Pred)
Metadata MDString * Name
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata Metadata * ThrownTypes
static LLVM_ABI DISPFlags getFlag(StringRef Flag)
Metadata MDString MDString Metadata * File
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned VirtualIndex
static LLVM_ABI DISPFlags splitFlags(DISPFlags Flags, SmallVectorImpl< DISPFlags > &SplitFlags)
Split up a flags bitfield for easier printing.
static LLVM_ABI StringRef getFlagString(DISPFlags Flag)
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int DIFlags DISPFlags Metadata Metadata Metadata Metadata * RetainedNodes
DISPFlags
Debug info subprogram flags.
Metadata MDString MDString Metadata unsigned Metadata unsigned Metadata unsigned int ThisAdjustment
LLVM_ABI bool describes(const Function *F) const
Check if this subprogram describes the given function.
StringRef DIFile unsigned Line
StringRef DIFile unsigned DIScope uint64_t uint32_t DIFlags DIType Metadata Metadata * UpperBound
StringRef DIFile unsigned DIScope uint64_t uint32_t DIFlags DIType Metadata Metadata Metadata Metadata * Bias
StringRef DIFile unsigned DIScope uint64_t uint32_t DIFlags DIType Metadata Metadata Metadata * Stride
StringRef DIFile unsigned DIScope uint64_t SizeInBits
StringRef DIFile * File
PointerUnion< ConstantInt *, DIVariable *, DIExpression *, DIDerivedType * > BoundType
StringRef DIFile unsigned DIScope uint64_t uint32_t AlignInBits
StringRef DIFile unsigned DIScope uint64_t uint32_t DIFlags DIType Metadata * LowerBound
StringRef DIFile unsigned DIScope uint64_t uint32_t DIFlags Flags
Array subrange.
LLVM_ABI BoundType getUpperBound() const
LLVM_ABI BoundType getStride() const
LLVM_ABI BoundType getLowerBound() const
LLVM_ABI BoundType getCount() const
Type array for a subprogram.
DIFlags uint8_t Metadata * TypeArray
Base class for template parameters.
unsigned MDString Metadata * Type
unsigned MDString Metadata bool Metadata * Value
Base class for types.
bool isBitField() const
bool isStaticMember() const
DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, unsigned Line, uint32_t AlignInBits, uint32_t NumExtraInhabitants, DIFlags Flags, ArrayRef< Metadata * > Ops)
LLVM_ABI uint32_t getAlignInBits() const
Metadata * getRawSizeInBits() 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...
LLVM_ABI std::optional< uint64_t > getSizeInBits() const
Determines the size of the variable's type.
Metadata * getRawType() const
LLVM_ABI DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, signed Line, ArrayRef< Metadata * > Ops, uint32_t AlignInBits=0)
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:63
Record of a variable value-assignment, aka a non instruction representation of the dbg....
LLVM_ABI DebugVariableAggregate(const DbgVariableRecord *DVR)
const DILocation * getInlinedAt() const
const DILocalVariable * getVariable() const
LLVM_ABI DebugVariable(const DbgVariableRecord *DVR)
iterator find(const_arg_type_t< KeyT > Val)
Definition DenseMap.h:766
iterator end()
Definition DenseMap.h:686
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Definition DenseMap.h:856
Class representing an expression and its matching format.
Generic tagged DWARF-like metadata node.
LLVM_ABI dwarf::Tag getTag() const
unsigned MDString * Header
unsigned MDString ArrayRef< Metadata * > DwarfOps
DenseSet< DIArgList *, DIArgListInfo > DIArgLists
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
LLVMContextImpl *const pImpl
Definition LLVMContext.h:78
Metadata node.
Definition Metadata.h:1087
friend class DIAssignID
Definition Metadata.h:1090
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1596
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1588
LLVM_ABI TempMDNode clone() const
Create a (temporary) clone of this.
Definition Metadata.cpp:668
static T * storeImpl(T *N, StorageType Storage, StoreT &Store)
LLVMContext & getContext() const
Definition Metadata.h:1251
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:1318
Tracking metadata reference owned by Metadata.
Definition Metadata.h:908
A single uniqued string.
Definition Metadata.h:734
LLVM_ABI StringRef getString() const
Definition Metadata.cpp:613
static void untrack(Metadata *&MD)
Stop tracking a reference to metadata.
Definition Metadata.h:361
static bool track(Metadata *&MD)
Track the reference to metadata.
Definition Metadata.h:327
Root of the metadata hierarchy.
Definition Metadata.h:65
StorageType
Active type of storage.
Definition Metadata.h:73
unsigned short SubclassData16
Definition Metadata.h:79
unsigned SubclassData32
Definition Metadata.h:80
unsigned char Storage
Storage flag for non-uniqued, otherwise unowned, metadata.
Definition Metadata.h:76
unsigned char SubclassData1
Definition Metadata.h:78
Metadata(unsigned ID, StorageType Storage)
Definition Metadata.h:89
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
LLVMContext & getContext() const
Definition Metadata.h:461
LLVM_ABI void resolveAllUses(bool ResolveUsers=true)
Resolve all uses of this.
Definition Metadata.cpp:428
LLVM_ABI void replaceAllUsesWith(Metadata *MD)
Replace all uses of this with MD.
Definition Metadata.cpp:375
Implements a dense probed hash-table based set with some number of buckets stored inline.
Definition DenseSet.h:295
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
Definition SetVector.h:346
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:295
Value wrapper in the Metadata hierarchy.
Definition Metadata.h:472
static LLVM_ABI ValueAsMetadata * get(Value *V)
Definition Metadata.cpp:512
LLVM Value Representation.
Definition Value.h:75
LLVM_ABI 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:1078
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:210
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
Definition DenseSet.h:183
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Calculates the starting offsets for various sections within the .debug_names section.
Definition Dwarf.h:35
@ DW_OP_LLVM_entry_value
Only used in LLVM metadata.
Definition Dwarf.h:147
@ DW_OP_LLVM_implicit_pointer
Only used in LLVM metadata.
Definition Dwarf.h:148
@ DW_OP_LLVM_extract_bits_zext
Only used in LLVM metadata.
Definition Dwarf.h:151
@ DW_OP_LLVM_tag_offset
Only used in LLVM metadata.
Definition Dwarf.h:146
@ DW_OP_LLVM_fragment
Only used in LLVM metadata.
Definition Dwarf.h:144
@ DW_OP_LLVM_arg
Only used in LLVM metadata.
Definition Dwarf.h:149
@ DW_OP_LLVM_convert
Only used in LLVM metadata.
Definition Dwarf.h:145
@ DW_OP_LLVM_extract_bits_sext
Only used in LLVM metadata.
Definition Dwarf.h:150
@ DW_VIRTUALITY_max
Definition Dwarf.h:200
@ NameTableKind
Definition LLToken.h:529
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract(Y &&MD)
Extract a Value from Metadata, if any.
Definition Metadata.h:708
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition STLExtras.h:316
@ Offset
Definition DWP.cpp:577
static T * getUniqued(DenseSet< T *, InfoT > &Store, const typename InfoT::KeyTy &Key)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI cl::opt< bool > EnableFSDiscriminator
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2229
auto cast_or_null(const Y &Val)
Definition Casting.h:714
static const DIScope * getScope(const NodeT *N)
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
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:1762
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
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:1769
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
@ Ref
The access may reference the value stored in memory.
Definition ModRef.h:32
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
const IROptions & getIROptions(const LLVMContext &C)
Definition IROptions.h:27
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:320
@ Keep
No function return thunk.
Definition CodeGen.h:370
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879
#define N
SmallPtrSet< DIScope *, 8 > Scopes
void insert(DIScope *S, LineColumn Loc)
DIScope * match(DIScope *S, LineColumn Loc)
void insert(DIScope *S, LineColumn Loc)
DIScope * match(DIScope *S, LineColumn Loc)
SmallMapVector< std::pair< DIFile *, LineColumn >, SmallSetVector< DIScope *, 8 >, 8 > Scopes
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.
A MapVector that performs no allocations if smaller than a certain size.
Definition MapVector.h:344