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