LLVM  15.0.0git
MetadataLoader.cpp
Go to the documentation of this file.
1 //===- MetadataLoader.cpp - Internal BitcodeReader implementation ---------===//
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 #include "MetadataLoader.h"
10 #include "ValueList.h"
11 
12 #include "llvm/ADT/APInt.h"
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/BitmaskEnum.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/ADT/DenseSet.h"
17 #include "llvm/ADT/None.h"
18 #include "llvm/ADT/Optional.h"
20 #include "llvm/ADT/SmallString.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/Statistic.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/ADT/Twine.h"
31 #include "llvm/IR/AutoUpgrade.h"
32 #include "llvm/IR/BasicBlock.h"
33 #include "llvm/IR/Constants.h"
35 #include "llvm/IR/Function.h"
36 #include "llvm/IR/GlobalObject.h"
37 #include "llvm/IR/GlobalVariable.h"
38 #include "llvm/IR/Instruction.h"
39 #include "llvm/IR/IntrinsicInst.h"
40 #include "llvm/IR/LLVMContext.h"
41 #include "llvm/IR/Metadata.h"
42 #include "llvm/IR/Module.h"
43 #include "llvm/IR/TrackingMDRef.h"
44 #include "llvm/IR/Type.h"
45 #include "llvm/Support/Casting.h"
47 #include "llvm/Support/Compiler.h"
50 
51 #include <algorithm>
52 #include <cassert>
53 #include <cstddef>
54 #include <cstdint>
55 #include <deque>
56 #include <iterator>
57 #include <limits>
58 #include <string>
59 #include <tuple>
60 #include <type_traits>
61 #include <utility>
62 #include <vector>
63 namespace llvm {
64 class Argument;
65 }
66 
67 using namespace llvm;
68 
69 #define DEBUG_TYPE "bitcode-reader"
70 
71 STATISTIC(NumMDStringLoaded, "Number of MDStrings loaded");
72 STATISTIC(NumMDNodeTemporary, "Number of MDNode::Temporary created");
73 STATISTIC(NumMDRecordLoaded, "Number of Metadata records loaded");
74 
75 /// Flag whether we need to import full type definitions for ThinLTO.
76 /// Currently needed for Darwin and LLDB.
78  "import-full-type-definitions", cl::init(false), cl::Hidden,
79  cl::desc("Import full type definitions for ThinLTO."));
80 
82  "disable-ondemand-mds-loading", cl::init(false), cl::Hidden,
83  cl::desc("Force disable the lazy-loading on-demand of metadata when "
84  "loading bitcode for importing."));
85 
86 namespace {
87 
88 static int64_t unrotateSign(uint64_t U) { return (U & 1) ? ~(U >> 1) : U >> 1; }
89 
90 class BitcodeReaderMetadataList {
91  /// Array of metadata references.
92  ///
93  /// Don't use std::vector here. Some versions of libc++ copy (instead of
94  /// move) on resize, and TrackingMDRef is very expensive to copy.
95  SmallVector<TrackingMDRef, 1> MetadataPtrs;
96 
97  /// The set of indices in MetadataPtrs above of forward references that were
98  /// generated.
100 
101  /// The set of indices in MetadataPtrs above of Metadata that need to be
102  /// resolved.
103  SmallDenseSet<unsigned, 1> UnresolvedNodes;
104 
105  /// Structures for resolving old type refs.
106  struct {
111  } OldTypeRefs;
112 
114 
115  /// Maximum number of valid references. Forward references exceeding the
116  /// maximum must be invalid.
117  unsigned RefsUpperBound;
118 
119 public:
120  BitcodeReaderMetadataList(LLVMContext &C, size_t RefsUpperBound)
121  : Context(C),
122  RefsUpperBound(std::min((size_t)std::numeric_limits<unsigned>::max(),
123  RefsUpperBound)) {}
124 
125  // vector compatibility methods
126  unsigned size() const { return MetadataPtrs.size(); }
127  void resize(unsigned N) { MetadataPtrs.resize(N); }
128  void push_back(Metadata *MD) { MetadataPtrs.emplace_back(MD); }
129  void clear() { MetadataPtrs.clear(); }
130  Metadata *back() const { return MetadataPtrs.back(); }
131  void pop_back() { MetadataPtrs.pop_back(); }
132  bool empty() const { return MetadataPtrs.empty(); }
133 
134  Metadata *operator[](unsigned i) const {
135  assert(i < MetadataPtrs.size());
136  return MetadataPtrs[i];
137  }
138 
139  Metadata *lookup(unsigned I) const {
140  if (I < MetadataPtrs.size())
141  return MetadataPtrs[I];
142  return nullptr;
143  }
144 
145  void shrinkTo(unsigned N) {
146  assert(N <= size() && "Invalid shrinkTo request!");
147  assert(ForwardReference.empty() && "Unexpected forward refs");
148  assert(UnresolvedNodes.empty() && "Unexpected unresolved node");
149  MetadataPtrs.resize(N);
150  }
151 
152  /// Return the given metadata, creating a replaceable forward reference if
153  /// necessary.
154  Metadata *getMetadataFwdRef(unsigned Idx);
155 
156  /// Return the given metadata only if it is fully resolved.
157  ///
158  /// Gives the same result as \a lookup(), unless \a MDNode::isResolved()
159  /// would give \c false.
160  Metadata *getMetadataIfResolved(unsigned Idx);
161 
162  MDNode *getMDNodeFwdRefOrNull(unsigned Idx);
163  void assignValue(Metadata *MD, unsigned Idx);
164  void tryToResolveCycles();
165  bool hasFwdRefs() const { return !ForwardReference.empty(); }
166  int getNextFwdRef() {
167  assert(hasFwdRefs());
168  return *ForwardReference.begin();
169  }
170 
171  /// Upgrade a type that had an MDString reference.
172  void addTypeRef(MDString &UUID, DICompositeType &CT);
173 
174  /// Upgrade a type that had an MDString reference.
175  Metadata *upgradeTypeRef(Metadata *MaybeUUID);
176 
177  /// Upgrade a type ref array that may have MDString references.
178  Metadata *upgradeTypeRefArray(Metadata *MaybeTuple);
179 
180 private:
181  Metadata *resolveTypeRefArray(Metadata *MaybeTuple);
182 };
183 
184 void BitcodeReaderMetadataList::assignValue(Metadata *MD, unsigned Idx) {
185  if (auto *MDN = dyn_cast<MDNode>(MD))
186  if (!MDN->isResolved())
187  UnresolvedNodes.insert(Idx);
188 
189  if (Idx == size()) {
190  push_back(MD);
191  return;
192  }
193 
194  if (Idx >= size())
195  resize(Idx + 1);
196 
197  TrackingMDRef &OldMD = MetadataPtrs[Idx];
198  if (!OldMD) {
199  OldMD.reset(MD);
200  return;
201  }
202 
203  // If there was a forward reference to this value, replace it.
204  TempMDTuple PrevMD(cast<MDTuple>(OldMD.get()));
205  PrevMD->replaceAllUsesWith(MD);
206  ForwardReference.erase(Idx);
207 }
208 
209 Metadata *BitcodeReaderMetadataList::getMetadataFwdRef(unsigned Idx) {
210  // Bail out for a clearly invalid value.
211  if (Idx >= RefsUpperBound)
212  return nullptr;
213 
214  if (Idx >= size())
215  resize(Idx + 1);
216 
217  if (Metadata *MD = MetadataPtrs[Idx])
218  return MD;
219 
220  // Track forward refs to be resolved later.
221  ForwardReference.insert(Idx);
222 
223  // Create and return a placeholder, which will later be RAUW'd.
224  ++NumMDNodeTemporary;
225  Metadata *MD = MDNode::getTemporary(Context, None).release();
226  MetadataPtrs[Idx].reset(MD);
227  return MD;
228 }
229 
230 Metadata *BitcodeReaderMetadataList::getMetadataIfResolved(unsigned Idx) {
231  Metadata *MD = lookup(Idx);
232  if (auto *N = dyn_cast_or_null<MDNode>(MD))
233  if (!N->isResolved())
234  return nullptr;
235  return MD;
236 }
237 
238 MDNode *BitcodeReaderMetadataList::getMDNodeFwdRefOrNull(unsigned Idx) {
239  return dyn_cast_or_null<MDNode>(getMetadataFwdRef(Idx));
240 }
241 
242 void BitcodeReaderMetadataList::tryToResolveCycles() {
243  if (!ForwardReference.empty())
244  // Still forward references... can't resolve cycles.
245  return;
246 
247  // Give up on finding a full definition for any forward decls that remain.
248  for (const auto &Ref : OldTypeRefs.FwdDecls)
249  OldTypeRefs.Final.insert(Ref);
250  OldTypeRefs.FwdDecls.clear();
251 
252  // Upgrade from old type ref arrays. In strange cases, this could add to
253  // OldTypeRefs.Unknown.
254  for (const auto &Array : OldTypeRefs.Arrays)
255  Array.second->replaceAllUsesWith(resolveTypeRefArray(Array.first.get()));
256  OldTypeRefs.Arrays.clear();
257 
258  // Replace old string-based type refs with the resolved node, if possible.
259  // If we haven't seen the node, leave it to the verifier to complain about
260  // the invalid string reference.
261  for (const auto &Ref : OldTypeRefs.Unknown) {
262  if (DICompositeType *CT = OldTypeRefs.Final.lookup(Ref.first))
263  Ref.second->replaceAllUsesWith(CT);
264  else
265  Ref.second->replaceAllUsesWith(Ref.first);
266  }
267  OldTypeRefs.Unknown.clear();
268 
269  if (UnresolvedNodes.empty())
270  // Nothing to do.
271  return;
272 
273  // Resolve any cycles.
274  for (unsigned I : UnresolvedNodes) {
275  auto &MD = MetadataPtrs[I];
276  auto *N = dyn_cast_or_null<MDNode>(MD);
277  if (!N)
278  continue;
279 
280  assert(!N->isTemporary() && "Unexpected forward reference");
281  N->resolveCycles();
282  }
283 
284  // Make sure we return early again until there's another unresolved ref.
285  UnresolvedNodes.clear();
286 }
287 
288 void BitcodeReaderMetadataList::addTypeRef(MDString &UUID,
289  DICompositeType &CT) {
290  assert(CT.getRawIdentifier() == &UUID && "Mismatched UUID");
291  if (CT.isForwardDecl())
292  OldTypeRefs.FwdDecls.insert(std::make_pair(&UUID, &CT));
293  else
294  OldTypeRefs.Final.insert(std::make_pair(&UUID, &CT));
295 }
296 
297 Metadata *BitcodeReaderMetadataList::upgradeTypeRef(Metadata *MaybeUUID) {
298  auto *UUID = dyn_cast_or_null<MDString>(MaybeUUID);
299  if (LLVM_LIKELY(!UUID))
300  return MaybeUUID;
301 
302  if (auto *CT = OldTypeRefs.Final.lookup(UUID))
303  return CT;
304 
305  auto &Ref = OldTypeRefs.Unknown[UUID];
306  if (!Ref)
308  return Ref.get();
309 }
310 
311 Metadata *BitcodeReaderMetadataList::upgradeTypeRefArray(Metadata *MaybeTuple) {
312  auto *Tuple = dyn_cast_or_null<MDTuple>(MaybeTuple);
313  if (!Tuple || Tuple->isDistinct())
314  return MaybeTuple;
315 
316  // Look through the array immediately if possible.
317  if (!Tuple->isTemporary())
318  return resolveTypeRefArray(Tuple);
319 
320  // Create and return a placeholder to use for now. Eventually
321  // resolveTypeRefArrays() will be resolve this forward reference.
322  OldTypeRefs.Arrays.emplace_back(
323  std::piecewise_construct, std::forward_as_tuple(Tuple),
324  std::forward_as_tuple(MDTuple::getTemporary(Context, None)));
325  return OldTypeRefs.Arrays.back().second.get();
326 }
327 
328 Metadata *BitcodeReaderMetadataList::resolveTypeRefArray(Metadata *MaybeTuple) {
329  auto *Tuple = dyn_cast_or_null<MDTuple>(MaybeTuple);
330  if (!Tuple || Tuple->isDistinct())
331  return MaybeTuple;
332 
333  // Look through the DITypeRefArray, upgrading each DIType *.
335  Ops.reserve(Tuple->getNumOperands());
336  for (Metadata *MD : Tuple->operands())
337  Ops.push_back(upgradeTypeRef(MD));
338 
339  return MDTuple::get(Context, Ops);
340 }
341 
342 namespace {
343 
344 class PlaceholderQueue {
345  // Placeholders would thrash around when moved, so store in a std::deque
346  // instead of some sort of vector.
347  std::deque<DistinctMDOperandPlaceholder> PHs;
348 
349 public:
350  ~PlaceholderQueue() {
351  assert(empty() &&
352  "PlaceholderQueue hasn't been flushed before being destroyed");
353  }
354  bool empty() const { return PHs.empty(); }
355  DistinctMDOperandPlaceholder &getPlaceholderOp(unsigned ID);
356  void flush(BitcodeReaderMetadataList &MetadataList);
357 
358  /// Return the list of temporaries nodes in the queue, these need to be
359  /// loaded before we can flush the queue.
360  void getTemporaries(BitcodeReaderMetadataList &MetadataList,
361  DenseSet<unsigned> &Temporaries) {
362  for (auto &PH : PHs) {
363  auto ID = PH.getID();
364  auto *MD = MetadataList.lookup(ID);
365  if (!MD) {
366  Temporaries.insert(ID);
367  continue;
368  }
369  auto *N = dyn_cast_or_null<MDNode>(MD);
370  if (N && N->isTemporary())
371  Temporaries.insert(ID);
372  }
373  }
374 };
375 
376 } // end anonymous namespace
377 
378 DistinctMDOperandPlaceholder &PlaceholderQueue::getPlaceholderOp(unsigned ID) {
379  PHs.emplace_back(ID);
380  return PHs.back();
381 }
382 
383 void PlaceholderQueue::flush(BitcodeReaderMetadataList &MetadataList) {
384  while (!PHs.empty()) {
385  auto *MD = MetadataList.lookup(PHs.front().getID());
386  assert(MD && "Flushing placeholder on unassigned MD");
387 #ifndef NDEBUG
388  if (auto *MDN = dyn_cast<MDNode>(MD))
389  assert(MDN->isResolved() &&
390  "Flushing Placeholder while cycles aren't resolved");
391 #endif
392  PHs.front().replaceUseWith(MD);
393  PHs.pop_front();
394  }
395 }
396 
397 } // anonymous namespace
398 
399 static Error error(const Twine &Message) {
400  return make_error<StringError>(
402 }
403 
405  BitcodeReaderMetadataList MetadataList;
406  BitcodeReaderValueList &ValueList;
407  BitstreamCursor &Stream;
409  Module &TheModule;
410  std::function<Type *(unsigned)> getTypeByID;
411 
412  /// Cursor associated with the lazy-loading of Metadata. This is the easy way
413  /// to keep around the right "context" (Abbrev list) to be able to jump in
414  /// the middle of the metadata block and load any record.
415  BitstreamCursor IndexCursor;
416 
417  /// Index that keeps track of MDString values.
418  std::vector<StringRef> MDStringRef;
419 
420  /// On-demand loading of a single MDString. Requires the index above to be
421  /// populated.
422  MDString *lazyLoadOneMDString(unsigned Idx);
423 
424  /// Index that keeps track of where to find a metadata record in the stream.
425  std::vector<uint64_t> GlobalMetadataBitPosIndex;
426 
427  /// Cursor position of the start of the global decl attachments, to enable
428  /// loading using the index built for lazy loading, instead of forward
429  /// references.
430  uint64_t GlobalDeclAttachmentPos = 0;
431 
432 #ifndef NDEBUG
433  /// Baisic correctness check that we end up parsing all of the global decl
434  /// attachments.
435  unsigned NumGlobalDeclAttachSkipped = 0;
436  unsigned NumGlobalDeclAttachParsed = 0;
437 #endif
438 
439  /// Load the global decl attachments, using the index built for lazy loading.
440  Expected<bool> loadGlobalDeclAttachments();
441 
442  /// Populate the index above to enable lazily loading of metadata, and load
443  /// the named metadata as well as the transitively referenced global
444  /// Metadata.
445  Expected<bool> lazyLoadModuleMetadataBlock();
446 
447  /// On-demand loading of a single metadata. Requires the index above to be
448  /// populated.
449  void lazyLoadOneMetadata(unsigned Idx, PlaceholderQueue &Placeholders);
450 
451  // Keep mapping of seens pair of old-style CU <-> SP, and update pointers to
452  // point from SP to CU after a block is completly parsed.
453  std::vector<std::pair<DICompileUnit *, Metadata *>> CUSubprograms;
454 
455  /// Functions that need to be matched with subprograms when upgrading old
456  /// metadata.
458 
459  // Map the bitcode's custom MDKind ID to the Module's MDKind ID.
461 
462  bool StripTBAA = false;
463  bool HasSeenOldLoopTags = false;
464  bool NeedUpgradeToDIGlobalVariableExpression = false;
465  bool NeedDeclareExpressionUpgrade = false;
466 
467  /// True if metadata is being parsed for a module being ThinLTO imported.
468  bool IsImporting = false;
469 
470  Error parseOneMetadata(SmallVectorImpl<uint64_t> &Record, unsigned Code,
471  PlaceholderQueue &Placeholders, StringRef Blob,
472  unsigned &NextMetadataNo);
473  Error parseMetadataStrings(ArrayRef<uint64_t> Record, StringRef Blob,
474  function_ref<void(StringRef)> CallBack);
475  Error parseGlobalObjectAttachment(GlobalObject &GO,
477  Error parseMetadataKindRecord(SmallVectorImpl<uint64_t> &Record);
478 
479  void resolveForwardRefsAndPlaceholders(PlaceholderQueue &Placeholders);
480 
481  /// Upgrade old-style CU <-> SP pointers to point from SP to CU.
482  void upgradeCUSubprograms() {
483  for (auto CU_SP : CUSubprograms)
484  if (auto *SPs = dyn_cast_or_null<MDTuple>(CU_SP.second))
485  for (auto &Op : SPs->operands())
486  if (auto *SP = dyn_cast_or_null<DISubprogram>(Op))
487  SP->replaceUnit(CU_SP.first);
488  CUSubprograms.clear();
489  }
490 
491  /// Upgrade old-style bare DIGlobalVariables to DIGlobalVariableExpressions.
492  void upgradeCUVariables() {
493  if (!NeedUpgradeToDIGlobalVariableExpression)
494  return;
495 
496  // Upgrade list of variables attached to the CUs.
497  if (NamedMDNode *CUNodes = TheModule.getNamedMetadata("llvm.dbg.cu"))
498  for (unsigned I = 0, E = CUNodes->getNumOperands(); I != E; ++I) {
499  auto *CU = cast<DICompileUnit>(CUNodes->getOperand(I));
500  if (auto *GVs = dyn_cast_or_null<MDTuple>(CU->getRawGlobalVariables()))
501  for (unsigned I = 0; I < GVs->getNumOperands(); I++)
502  if (auto *GV =
503  dyn_cast_or_null<DIGlobalVariable>(GVs->getOperand(I))) {
505  Context, GV, DIExpression::get(Context, {}));
506  GVs->replaceOperandWith(I, DGVE);
507  }
508  }
509 
510  // Upgrade variables attached to globals.
511  for (auto &GV : TheModule.globals()) {
513  GV.getMetadata(LLVMContext::MD_dbg, MDs);
514  GV.eraseMetadata(LLVMContext::MD_dbg);
515  for (auto *MD : MDs)
516  if (auto *DGV = dyn_cast<DIGlobalVariable>(MD)) {
518  Context, DGV, DIExpression::get(Context, {}));
519  GV.addMetadata(LLVMContext::MD_dbg, *DGVE);
520  } else
521  GV.addMetadata(LLVMContext::MD_dbg, *MD);
522  }
523  }
524 
525  /// Remove a leading DW_OP_deref from DIExpressions in a dbg.declare that
526  /// describes a function argument.
527  void upgradeDeclareExpressions(Function &F) {
528  if (!NeedDeclareExpressionUpgrade)
529  return;
530 
531  for (auto &BB : F)
532  for (auto &I : BB)
533  if (auto *DDI = dyn_cast<DbgDeclareInst>(&I))
534  if (auto *DIExpr = DDI->getExpression())
535  if (DIExpr->startsWithDeref() &&
536  isa_and_nonnull<Argument>(DDI->getAddress())) {
538  Ops.append(std::next(DIExpr->elements_begin()),
539  DIExpr->elements_end());
540  DDI->setExpression(DIExpression::get(Context, Ops));
541  }
542  }
543 
544  /// Upgrade the expression from previous versions.
545  Error upgradeDIExpression(uint64_t FromVersion,
547  SmallVectorImpl<uint64_t> &Buffer) {
548  auto N = Expr.size();
549  switch (FromVersion) {
550  default:
551  return error("Invalid record");
552  case 0:
553  if (N >= 3 && Expr[N - 3] == dwarf::DW_OP_bit_piece)
554  Expr[N - 3] = dwarf::DW_OP_LLVM_fragment;
556  case 1:
557  // Move DW_OP_deref to the end.
558  if (N && Expr[0] == dwarf::DW_OP_deref) {
559  auto End = Expr.end();
560  if (Expr.size() >= 3 &&
561  *std::prev(End, 3) == dwarf::DW_OP_LLVM_fragment)
562  End = std::prev(End, 3);
563  std::move(std::next(Expr.begin()), End, Expr.begin());
564  *std::prev(End) = dwarf::DW_OP_deref;
565  }
566  NeedDeclareExpressionUpgrade = true;
568  case 2: {
569  // Change DW_OP_plus to DW_OP_plus_uconst.
570  // Change DW_OP_minus to DW_OP_uconst, DW_OP_minus
571  auto SubExpr = ArrayRef<uint64_t>(Expr);
572  while (!SubExpr.empty()) {
573  // Skip past other operators with their operands
574  // for this version of the IR, obtained from
575  // from historic DIExpression::ExprOperand::getSize().
576  size_t HistoricSize;
577  switch (SubExpr.front()) {
578  default:
579  HistoricSize = 1;
580  break;
581  case dwarf::DW_OP_constu:
582  case dwarf::DW_OP_minus:
583  case dwarf::DW_OP_plus:
584  HistoricSize = 2;
585  break;
587  HistoricSize = 3;
588  break;
589  }
590 
591  // If the expression is malformed, make sure we don't
592  // copy more elements than we should.
593  HistoricSize = std::min(SubExpr.size(), HistoricSize);
594  ArrayRef<uint64_t> Args = SubExpr.slice(1, HistoricSize - 1);
595 
596  switch (SubExpr.front()) {
597  case dwarf::DW_OP_plus:
598  Buffer.push_back(dwarf::DW_OP_plus_uconst);
599  Buffer.append(Args.begin(), Args.end());
600  break;
601  case dwarf::DW_OP_minus:
602  Buffer.push_back(dwarf::DW_OP_constu);
603  Buffer.append(Args.begin(), Args.end());
604  Buffer.push_back(dwarf::DW_OP_minus);
605  break;
606  default:
607  Buffer.push_back(*SubExpr.begin());
608  Buffer.append(Args.begin(), Args.end());
609  break;
610  }
611 
612  // Continue with remaining elements.
613  SubExpr = SubExpr.slice(HistoricSize);
614  }
615  Expr = MutableArrayRef<uint64_t>(Buffer);
617  }
618  case 3:
619  // Up-to-date!
620  break;
621  }
622 
623  return Error::success();
624  }
625 
626  void upgradeDebugInfo() {
627  upgradeCUSubprograms();
628  upgradeCUVariables();
629  }
630 
631 public:
633  BitcodeReaderValueList &ValueList,
634  std::function<Type *(unsigned)> getTypeByID,
635  bool IsImporting)
636  : MetadataList(TheModule.getContext(), Stream.SizeInBytes()),
637  ValueList(ValueList), Stream(Stream), Context(TheModule.getContext()),
638  TheModule(TheModule), getTypeByID(std::move(getTypeByID)),
639  IsImporting(IsImporting) {}
640 
641  Error parseMetadata(bool ModuleLevel);
642 
643  bool hasFwdRefs() const { return MetadataList.hasFwdRefs(); }
644 
646  if (ID < MDStringRef.size())
647  return lazyLoadOneMDString(ID);
648  if (auto *MD = MetadataList.lookup(ID))
649  return MD;
650  // If lazy-loading is enabled, we try recursively to load the operand
651  // instead of creating a temporary.
652  if (ID < (MDStringRef.size() + GlobalMetadataBitPosIndex.size())) {
653  PlaceholderQueue Placeholders;
654  lazyLoadOneMetadata(ID, Placeholders);
655  resolveForwardRefsAndPlaceholders(Placeholders);
656  return MetadataList.lookup(ID);
657  }
658  return MetadataList.getMetadataFwdRef(ID);
659  }
660 
662  return FunctionsWithSPs.lookup(F);
663  }
664 
665  bool hasSeenOldLoopTags() const { return HasSeenOldLoopTags; }
666 
668  ArrayRef<Instruction *> InstructionList);
669 
671 
672  void setStripTBAA(bool Value) { StripTBAA = Value; }
673  bool isStrippingTBAA() const { return StripTBAA; }
674 
675  unsigned size() const { return MetadataList.size(); }
676  void shrinkTo(unsigned N) { MetadataList.shrinkTo(N); }
677  void upgradeDebugIntrinsics(Function &F) { upgradeDeclareExpressions(F); }
678 };
679 
681 MetadataLoader::MetadataLoaderImpl::lazyLoadModuleMetadataBlock() {
682  IndexCursor = Stream;
684  GlobalDeclAttachmentPos = 0;
685  // Get the abbrevs, and preload record positions to make them lazy-loadable.
686  while (true) {
687  uint64_t SavedPos = IndexCursor.GetCurrentBitNo();
688  BitstreamEntry Entry;
689  if (Error E =
690  IndexCursor
691  .advanceSkippingSubblocks(BitstreamCursor::AF_DontPopBlockAtEnd)
692  .moveInto(Entry))
693  return std::move(E);
694 
695  switch (Entry.Kind) {
696  case BitstreamEntry::SubBlock: // Handled for us already.
698  return error("Malformed block");
699  case BitstreamEntry::EndBlock: {
700  return true;
701  }
702  case BitstreamEntry::Record: {
703  // The interesting case.
704  ++NumMDRecordLoaded;
705  uint64_t CurrentPos = IndexCursor.GetCurrentBitNo();
706  unsigned Code;
707  if (Error E = IndexCursor.skipRecord(Entry.ID).moveInto(Code))
708  return std::move(E);
709  switch (Code) {
710  case bitc::METADATA_STRINGS: {
711  // Rewind and parse the strings.
712  if (Error Err = IndexCursor.JumpToBit(CurrentPos))
713  return std::move(Err);
714  StringRef Blob;
715  Record.clear();
716  if (Expected<unsigned> MaybeRecord =
717  IndexCursor.readRecord(Entry.ID, Record, &Blob))
718  ;
719  else
720  return MaybeRecord.takeError();
721  unsigned NumStrings = Record[0];
722  MDStringRef.reserve(NumStrings);
723  auto IndexNextMDString = [&](StringRef Str) {
724  MDStringRef.push_back(Str);
725  };
726  if (auto Err = parseMetadataStrings(Record, Blob, IndexNextMDString))
727  return std::move(Err);
728  break;
729  }
731  // This is the offset to the index, when we see this we skip all the
732  // records and load only an index to these.
733  if (Error Err = IndexCursor.JumpToBit(CurrentPos))
734  return std::move(Err);
735  Record.clear();
736  if (Expected<unsigned> MaybeRecord =
737  IndexCursor.readRecord(Entry.ID, Record))
738  ;
739  else
740  return MaybeRecord.takeError();
741  if (Record.size() != 2)
742  return error("Invalid record");
743  auto Offset = Record[0] + (Record[1] << 32);
744  auto BeginPos = IndexCursor.GetCurrentBitNo();
745  if (Error Err = IndexCursor.JumpToBit(BeginPos + Offset))
746  return std::move(Err);
747  Expected<BitstreamEntry> MaybeEntry =
748  IndexCursor.advanceSkippingSubblocks(
749  BitstreamCursor::AF_DontPopBlockAtEnd);
750  if (!MaybeEntry)
751  return MaybeEntry.takeError();
752  Entry = MaybeEntry.get();
753  assert(Entry.Kind == BitstreamEntry::Record &&
754  "Corrupted bitcode: Expected `Record` when trying to find the "
755  "Metadata index");
756  Record.clear();
757  if (Expected<unsigned> MaybeCode =
758  IndexCursor.readRecord(Entry.ID, Record))
759  assert(MaybeCode.get() == bitc::METADATA_INDEX &&
760  "Corrupted bitcode: Expected `METADATA_INDEX` when trying to "
761  "find the Metadata index");
762  else
763  return MaybeCode.takeError();
764  // Delta unpack
765  auto CurrentValue = BeginPos;
766  GlobalMetadataBitPosIndex.reserve(Record.size());
767  for (auto &Elt : Record) {
768  CurrentValue += Elt;
769  GlobalMetadataBitPosIndex.push_back(CurrentValue);
770  }
771  break;
772  }
774  // We don't expect to get there, the Index is loaded when we encounter
775  // the offset.
776  return error("Corrupted Metadata block");
777  case bitc::METADATA_NAME: {
778  // Named metadata need to be materialized now and aren't deferred.
779  if (Error Err = IndexCursor.JumpToBit(CurrentPos))
780  return std::move(Err);
781  Record.clear();
782 
783  unsigned Code;
784  if (Expected<unsigned> MaybeCode =
785  IndexCursor.readRecord(Entry.ID, Record)) {
786  Code = MaybeCode.get();
788  } else
789  return MaybeCode.takeError();
790 
791  // Read name of the named metadata.
792  SmallString<8> Name(Record.begin(), Record.end());
793  if (Expected<unsigned> MaybeCode = IndexCursor.ReadCode())
794  Code = MaybeCode.get();
795  else
796  return MaybeCode.takeError();
797 
798  // Named Metadata comes in two parts, we expect the name to be followed
799  // by the node
800  Record.clear();
801  if (Expected<unsigned> MaybeNextBitCode =
802  IndexCursor.readRecord(Code, Record))
803  assert(MaybeNextBitCode.get() == bitc::METADATA_NAMED_NODE);
804  else
805  return MaybeNextBitCode.takeError();
806 
807  // Read named metadata elements.
808  unsigned Size = Record.size();
809  NamedMDNode *NMD = TheModule.getOrInsertNamedMetadata(Name);
810  for (unsigned i = 0; i != Size; ++i) {
811  // FIXME: We could use a placeholder here, however NamedMDNode are
812  // taking MDNode as operand and not using the Metadata infrastructure.
813  // It is acknowledged by 'TODO: Inherit from Metadata' in the
814  // NamedMDNode class definition.
815  MDNode *MD = MetadataList.getMDNodeFwdRefOrNull(Record[i]);
816  assert(MD && "Invalid metadata: expect fwd ref to MDNode");
817  NMD->addOperand(MD);
818  }
819  break;
820  }
822  if (!GlobalDeclAttachmentPos)
823  GlobalDeclAttachmentPos = SavedPos;
824 #ifndef NDEBUG
825  NumGlobalDeclAttachSkipped++;
826 #endif
827  break;
828  }
829  case bitc::METADATA_KIND:
835  case bitc::METADATA_NODE:
846  case bitc::METADATA_FILE:
865  // We don't expect to see any of these, if we see one, give up on
866  // lazy-loading and fallback.
867  MDStringRef.clear();
868  GlobalMetadataBitPosIndex.clear();
869  return false;
870  }
871  break;
872  }
873  }
874  }
875 }
876 
877 // Load the global decl attachments after building the lazy loading index.
878 // We don't load them "lazily" - all global decl attachments must be
879 // parsed since they aren't materialized on demand. However, by delaying
880 // their parsing until after the index is created, we can use the index
881 // instead of creating temporaries.
882 Expected<bool> MetadataLoader::MetadataLoaderImpl::loadGlobalDeclAttachments() {
883  // Nothing to do if we didn't find any of these metadata records.
884  if (!GlobalDeclAttachmentPos)
885  return true;
886  // Use a temporary cursor so that we don't mess up the main Stream cursor or
887  // the lazy loading IndexCursor (which holds the necessary abbrev ids).
888  BitstreamCursor TempCursor = Stream;
890  // Jump to the position before the first global decl attachment, so we can
891  // scan for the first BitstreamEntry record.
892  if (Error Err = TempCursor.JumpToBit(GlobalDeclAttachmentPos))
893  return std::move(Err);
894  while (true) {
895  BitstreamEntry Entry;
896  if (Error E =
897  TempCursor
898  .advanceSkippingSubblocks(BitstreamCursor::AF_DontPopBlockAtEnd)
899  .moveInto(Entry))
900  return std::move(E);
901 
902  switch (Entry.Kind) {
903  case BitstreamEntry::SubBlock: // Handled for us already.
905  return error("Malformed block");
906  case BitstreamEntry::EndBlock:
907  // Check that we parsed them all.
908  assert(NumGlobalDeclAttachSkipped == NumGlobalDeclAttachParsed);
909  return true;
910  case BitstreamEntry::Record:
911  break;
912  }
913  uint64_t CurrentPos = TempCursor.GetCurrentBitNo();
914  Expected<unsigned> MaybeCode = TempCursor.skipRecord(Entry.ID);
915  if (!MaybeCode)
916  return MaybeCode.takeError();
917  if (MaybeCode.get() != bitc::METADATA_GLOBAL_DECL_ATTACHMENT) {
918  // Anything other than a global decl attachment signals the end of
919  // these records. Check that we parsed them all.
920  assert(NumGlobalDeclAttachSkipped == NumGlobalDeclAttachParsed);
921  return true;
922  }
923 #ifndef NDEBUG
924  NumGlobalDeclAttachParsed++;
925 #endif
926  // FIXME: we need to do this early because we don't materialize global
927  // value explicitly.
928  if (Error Err = TempCursor.JumpToBit(CurrentPos))
929  return std::move(Err);
930  Record.clear();
931  if (Expected<unsigned> MaybeRecord =
932  TempCursor.readRecord(Entry.ID, Record))
933  ;
934  else
935  return MaybeRecord.takeError();
936  if (Record.size() % 2 == 0)
937  return error("Invalid record");
938  unsigned ValueID = Record[0];
939  if (ValueID >= ValueList.size())
940  return error("Invalid record");
941  if (auto *GO = dyn_cast<GlobalObject>(ValueList[ValueID])) {
942  // Need to save and restore the current position since
943  // parseGlobalObjectAttachment will resolve all forward references which
944  // would require parsing from locations stored in the index.
945  CurrentPos = TempCursor.GetCurrentBitNo();
946  if (Error Err = parseGlobalObjectAttachment(
947  *GO, ArrayRef<uint64_t>(Record).slice(1)))
948  return std::move(Err);
949  if (Error Err = TempCursor.JumpToBit(CurrentPos))
950  return std::move(Err);
951  }
952  }
953 }
954 
955 /// Parse a METADATA_BLOCK. If ModuleLevel is true then we are parsing
956 /// module level metadata.
958  if (!ModuleLevel && MetadataList.hasFwdRefs())
959  return error("Invalid metadata: fwd refs into function blocks");
960 
961  // Record the entry position so that we can jump back here and efficiently
962  // skip the whole block in case we lazy-load.
963  auto EntryPos = Stream.GetCurrentBitNo();
964 
965  if (Error Err = Stream.EnterSubBlock(bitc::METADATA_BLOCK_ID))
966  return Err;
967 
969  PlaceholderQueue Placeholders;
970 
971  // We lazy-load module-level metadata: we build an index for each record, and
972  // then load individual record as needed, starting with the named metadata.
973  if (ModuleLevel && IsImporting && MetadataList.empty() &&
975  auto SuccessOrErr = lazyLoadModuleMetadataBlock();
976  if (!SuccessOrErr)
977  return SuccessOrErr.takeError();
978  if (SuccessOrErr.get()) {
979  // An index was successfully created and we will be able to load metadata
980  // on-demand.
981  MetadataList.resize(MDStringRef.size() +
982  GlobalMetadataBitPosIndex.size());
983 
984  // Now that we have built the index, load the global decl attachments
985  // that were deferred during that process. This avoids creating
986  // temporaries.
987  SuccessOrErr = loadGlobalDeclAttachments();
988  if (!SuccessOrErr)
989  return SuccessOrErr.takeError();
990  assert(SuccessOrErr.get());
991 
992  // Reading the named metadata created forward references and/or
993  // placeholders, that we flush here.
994  resolveForwardRefsAndPlaceholders(Placeholders);
995  upgradeDebugInfo();
996  // Return at the beginning of the block, since it is easy to skip it
997  // entirely from there.
998  Stream.ReadBlockEnd(); // Pop the abbrev block context.
999  if (Error Err = IndexCursor.JumpToBit(EntryPos))
1000  return Err;
1001  if (Error Err = Stream.SkipBlock()) {
1002  // FIXME this drops the error on the floor, which
1003  // ThinLTO/X86/debuginfo-cu-import.ll relies on.
1004  consumeError(std::move(Err));
1005  return Error::success();
1006  }
1007  return Error::success();
1008  }
1009  // Couldn't load an index, fallback to loading all the block "old-style".
1010  }
1011 
1012  unsigned NextMetadataNo = MetadataList.size();
1013 
1014  // Read all the records.
1015  while (true) {
1016  BitstreamEntry Entry;
1017  if (Error E = Stream.advanceSkippingSubblocks().moveInto(Entry))
1018  return E;
1019 
1020  switch (Entry.Kind) {
1021  case BitstreamEntry::SubBlock: // Handled for us already.
1022  case BitstreamEntry::Error:
1023  return error("Malformed block");
1024  case BitstreamEntry::EndBlock:
1025  resolveForwardRefsAndPlaceholders(Placeholders);
1026  upgradeDebugInfo();
1027  return Error::success();
1028  case BitstreamEntry::Record:
1029  // The interesting case.
1030  break;
1031  }
1032 
1033  // Read a record.
1034  Record.clear();
1035  StringRef Blob;
1036  ++NumMDRecordLoaded;
1037  if (Expected<unsigned> MaybeCode =
1038  Stream.readRecord(Entry.ID, Record, &Blob)) {
1039  if (Error Err = parseOneMetadata(Record, MaybeCode.get(), Placeholders,
1040  Blob, NextMetadataNo))
1041  return Err;
1042  } else
1043  return MaybeCode.takeError();
1044  }
1045 }
1046 
1047 MDString *MetadataLoader::MetadataLoaderImpl::lazyLoadOneMDString(unsigned ID) {
1048  ++NumMDStringLoaded;
1049  if (Metadata *MD = MetadataList.lookup(ID))
1050  return cast<MDString>(MD);
1051  auto MDS = MDString::get(Context, MDStringRef[ID]);
1052  MetadataList.assignValue(MDS, ID);
1053  return MDS;
1054 }
1055 
1056 void MetadataLoader::MetadataLoaderImpl::lazyLoadOneMetadata(
1057  unsigned ID, PlaceholderQueue &Placeholders) {
1058  assert(ID < (MDStringRef.size()) + GlobalMetadataBitPosIndex.size());
1059  assert(ID >= MDStringRef.size() && "Unexpected lazy-loading of MDString");
1060  // Lookup first if the metadata hasn't already been loaded.
1061  if (auto *MD = MetadataList.lookup(ID)) {
1062  auto *N = cast<MDNode>(MD);
1063  if (!N->isTemporary())
1064  return;
1065  }
1067  StringRef Blob;
1068  if (Error Err = IndexCursor.JumpToBit(
1069  GlobalMetadataBitPosIndex[ID - MDStringRef.size()]))
1070  report_fatal_error("lazyLoadOneMetadata failed jumping: " +
1071  Twine(toString(std::move(Err))));
1072  BitstreamEntry Entry;
1073  if (Error E = IndexCursor.advanceSkippingSubblocks().moveInto(Entry))
1074  // FIXME this drops the error on the floor.
1075  report_fatal_error("lazyLoadOneMetadata failed advanceSkippingSubblocks: " +
1076  Twine(toString(std::move(E))));
1077  ++NumMDRecordLoaded;
1078  if (Expected<unsigned> MaybeCode =
1079  IndexCursor.readRecord(Entry.ID, Record, &Blob)) {
1080  if (Error Err =
1081  parseOneMetadata(Record, MaybeCode.get(), Placeholders, Blob, ID))
1082  report_fatal_error("Can't lazyload MD, parseOneMetadata: " +
1083  Twine(toString(std::move(Err))));
1084  } else
1085  report_fatal_error("Can't lazyload MD: " +
1086  Twine(toString(MaybeCode.takeError())));
1087 }
1088 
1089 /// Ensure that all forward-references and placeholders are resolved.
1090 /// Iteratively lazy-loading metadata on-demand if needed.
1091 void MetadataLoader::MetadataLoaderImpl::resolveForwardRefsAndPlaceholders(
1092  PlaceholderQueue &Placeholders) {
1093  DenseSet<unsigned> Temporaries;
1094  while (true) {
1095  // Populate Temporaries with the placeholders that haven't been loaded yet.
1096  Placeholders.getTemporaries(MetadataList, Temporaries);
1097 
1098  // If we don't have any temporary, or FwdReference, we're done!
1099  if (Temporaries.empty() && !MetadataList.hasFwdRefs())
1100  break;
1101 
1102  // First, load all the temporaries. This can add new placeholders or
1103  // forward references.
1104  for (auto ID : Temporaries)
1105  lazyLoadOneMetadata(ID, Placeholders);
1106  Temporaries.clear();
1107 
1108  // Second, load the forward-references. This can also add new placeholders
1109  // or forward references.
1110  while (MetadataList.hasFwdRefs())
1111  lazyLoadOneMetadata(MetadataList.getNextFwdRef(), Placeholders);
1112  }
1113  // At this point we don't have any forward reference remaining, or temporary
1114  // that haven't been loaded. We can safely drop RAUW support and mark cycles
1115  // as resolved.
1116  MetadataList.tryToResolveCycles();
1117 
1118  // Finally, everything is in place, we can replace the placeholders operands
1119  // with the final node they refer to.
1120  Placeholders.flush(MetadataList);
1121 }
1122 
1123 Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
1125  PlaceholderQueue &Placeholders, StringRef Blob, unsigned &NextMetadataNo) {
1126 
1127  bool IsDistinct = false;
1128  auto getMD = [&](unsigned ID) -> Metadata * {
1129  if (ID < MDStringRef.size())
1130  return lazyLoadOneMDString(ID);
1131  if (!IsDistinct) {
1132  if (auto *MD = MetadataList.lookup(ID))
1133  return MD;
1134  // If lazy-loading is enabled, we try recursively to load the operand
1135  // instead of creating a temporary.
1136  if (ID < (MDStringRef.size() + GlobalMetadataBitPosIndex.size())) {
1137  // Create a temporary for the node that is referencing the operand we
1138  // will lazy-load. It is needed before recursing in case there are
1139  // uniquing cycles.
1140  MetadataList.getMetadataFwdRef(NextMetadataNo);
1141  lazyLoadOneMetadata(ID, Placeholders);
1142  return MetadataList.lookup(ID);
1143  }
1144  // Return a temporary.
1145  return MetadataList.getMetadataFwdRef(ID);
1146  }
1147  if (auto *MD = MetadataList.getMetadataIfResolved(ID))
1148  return MD;
1149  return &Placeholders.getPlaceholderOp(ID);
1150  };
1151  auto getMDOrNull = [&](unsigned ID) -> Metadata * {
1152  if (ID)
1153  return getMD(ID - 1);
1154  return nullptr;
1155  };
1156  auto getMDOrNullWithoutPlaceholders = [&](unsigned ID) -> Metadata * {
1157  if (ID)
1158  return MetadataList.getMetadataFwdRef(ID - 1);
1159  return nullptr;
1160  };
1161  auto getMDString = [&](unsigned ID) -> MDString * {
1162  // This requires that the ID is not really a forward reference. In
1163  // particular, the MDString must already have been resolved.
1164  auto MDS = getMDOrNull(ID);
1165  return cast_or_null<MDString>(MDS);
1166  };
1167 
1168  // Support for old type refs.
1169  auto getDITypeRefOrNull = [&](unsigned ID) {
1170  return MetadataList.upgradeTypeRef(getMDOrNull(ID));
1171  };
1172 
1173 #define GET_OR_DISTINCT(CLASS, ARGS) \
1174  (IsDistinct ? CLASS::getDistinct ARGS : CLASS::get ARGS)
1175 
1176  switch (Code) {
1177  default: // Default behavior: ignore.
1178  break;
1179  case bitc::METADATA_NAME: {
1180  // Read name of the named metadata.
1181  SmallString<8> Name(Record.begin(), Record.end());
1182  Record.clear();
1183  if (Error E = Stream.ReadCode().moveInto(Code))
1184  return E;
1185 
1186  ++NumMDRecordLoaded;
1187  if (Expected<unsigned> MaybeNextBitCode = Stream.readRecord(Code, Record)) {
1188  if (MaybeNextBitCode.get() != bitc::METADATA_NAMED_NODE)
1189  return error("METADATA_NAME not followed by METADATA_NAMED_NODE");
1190  } else
1191  return MaybeNextBitCode.takeError();
1192 
1193  // Read named metadata elements.
1194  unsigned Size = Record.size();
1195  NamedMDNode *NMD = TheModule.getOrInsertNamedMetadata(Name);
1196  for (unsigned i = 0; i != Size; ++i) {
1197  MDNode *MD = MetadataList.getMDNodeFwdRefOrNull(Record[i]);
1198  if (!MD)
1199  return error("Invalid named metadata: expect fwd ref to MDNode");
1200  NMD->addOperand(MD);
1201  }
1202  break;
1203  }
1205  // Deprecated, but still needed to read old bitcode files.
1206  // This is a LocalAsMetadata record, the only type of function-local
1207  // metadata.
1208  if (Record.size() % 2 == 1)
1209  return error("Invalid record");
1210 
1211  // If this isn't a LocalAsMetadata record, we're dropping it. This used
1212  // to be legal, but there's no upgrade path.
1213  auto dropRecord = [&] {
1214  MetadataList.assignValue(MDNode::get(Context, None), NextMetadataNo);
1215  NextMetadataNo++;
1216  };
1217  if (Record.size() != 2) {
1218  dropRecord();
1219  break;
1220  }
1221 
1222  unsigned TyID = Record[0];
1223  Type *Ty = getTypeByID(TyID);
1224  if (Ty->isMetadataTy() || Ty->isVoidTy()) {
1225  dropRecord();
1226  break;
1227  }
1228 
1229  MetadataList.assignValue(
1230  LocalAsMetadata::get(ValueList.getValueFwdRef(Record[1], Ty, TyID)),
1231  NextMetadataNo);
1232  NextMetadataNo++;
1233  break;
1234  }
1235  case bitc::METADATA_OLD_NODE: {
1236  // Deprecated, but still needed to read old bitcode files.
1237  if (Record.size() % 2 == 1)
1238  return error("Invalid record");
1239 
1240  unsigned Size = Record.size();
1242  for (unsigned i = 0; i != Size; i += 2) {
1243  unsigned TyID = Record[i];
1244  Type *Ty = getTypeByID(TyID);
1245  if (!Ty)
1246  return error("Invalid record");
1247  if (Ty->isMetadataTy())
1248  Elts.push_back(getMD(Record[i + 1]));
1249  else if (!Ty->isVoidTy()) {
1250  auto *MD = ValueAsMetadata::get(
1251  ValueList.getValueFwdRef(Record[i + 1], Ty, TyID));
1252  assert(isa<ConstantAsMetadata>(MD) &&
1253  "Expected non-function-local metadata");
1254  Elts.push_back(MD);
1255  } else
1256  Elts.push_back(nullptr);
1257  }
1258  MetadataList.assignValue(MDNode::get(Context, Elts), NextMetadataNo);
1259  NextMetadataNo++;
1260  break;
1261  }
1262  case bitc::METADATA_VALUE: {
1263  if (Record.size() != 2)
1264  return error("Invalid record");
1265 
1266  unsigned TyID = Record[0];
1267  Type *Ty = getTypeByID(TyID);
1268  if (Ty->isMetadataTy() || Ty->isVoidTy())
1269  return error("Invalid record");
1270 
1271  MetadataList.assignValue(
1272  ValueAsMetadata::get(ValueList.getValueFwdRef(Record[1], Ty, TyID)),
1273  NextMetadataNo);
1274  NextMetadataNo++;
1275  break;
1276  }
1278  IsDistinct = true;
1280  case bitc::METADATA_NODE: {
1282  Elts.reserve(Record.size());
1283  for (unsigned ID : Record)
1284  Elts.push_back(getMDOrNull(ID));
1285  MetadataList.assignValue(IsDistinct ? MDNode::getDistinct(Context, Elts)
1286  : MDNode::get(Context, Elts),
1287  NextMetadataNo);
1288  NextMetadataNo++;
1289  break;
1290  }
1291  case bitc::METADATA_LOCATION: {
1292  if (Record.size() != 5 && Record.size() != 6)
1293  return error("Invalid record");
1294 
1295  IsDistinct = Record[0];
1296  unsigned Line = Record[1];
1297  unsigned Column = Record[2];
1298  Metadata *Scope = getMD(Record[3]);
1299  Metadata *InlinedAt = getMDOrNull(Record[4]);
1300  bool ImplicitCode = Record.size() == 6 && Record[5];
1301  MetadataList.assignValue(
1302  GET_OR_DISTINCT(DILocation, (Context, Line, Column, Scope, InlinedAt,
1303  ImplicitCode)),
1304  NextMetadataNo);
1305  NextMetadataNo++;
1306  break;
1307  }
1309  if (Record.size() < 4)
1310  return error("Invalid record");
1311 
1312  IsDistinct = Record[0];
1313  unsigned Tag = Record[1];
1314  unsigned Version = Record[2];
1315 
1316  if (Tag >= 1u << 16 || Version != 0)
1317  return error("Invalid record");
1318 
1319  auto *Header = getMDString(Record[3]);
1320  SmallVector<Metadata *, 8> DwarfOps;
1321  for (unsigned I = 4, E = Record.size(); I != E; ++I)
1322  DwarfOps.push_back(getMDOrNull(Record[I]));
1323  MetadataList.assignValue(
1324  GET_OR_DISTINCT(GenericDINode, (Context, Tag, Header, DwarfOps)),
1325  NextMetadataNo);
1326  NextMetadataNo++;
1327  break;
1328  }
1329  case bitc::METADATA_SUBRANGE: {
1330  Metadata *Val = nullptr;
1331  // Operand 'count' is interpreted as:
1332  // - Signed integer (version 0)
1333  // - Metadata node (version 1)
1334  // Operand 'lowerBound' is interpreted as:
1335  // - Signed integer (version 0 and 1)
1336  // - Metadata node (version 2)
1337  // Operands 'upperBound' and 'stride' are interpreted as:
1338  // - Metadata node (version 2)
1339  switch (Record[0] >> 1) {
1340  case 0:
1342  (Context, Record[1], unrotateSign(Record[2])));
1343  break;
1344  case 1:
1345  Val = GET_OR_DISTINCT(DISubrange, (Context, getMDOrNull(Record[1]),
1346  unrotateSign(Record[2])));
1347  break;
1348  case 2:
1349  Val = GET_OR_DISTINCT(
1350  DISubrange, (Context, getMDOrNull(Record[1]), getMDOrNull(Record[2]),
1351  getMDOrNull(Record[3]), getMDOrNull(Record[4])));
1352  break;
1353  default:
1354  return error("Invalid record: Unsupported version of DISubrange");
1355  }
1356 
1357  MetadataList.assignValue(Val, NextMetadataNo);
1358  IsDistinct = Record[0] & 1;
1359  NextMetadataNo++;
1360  break;
1361  }
1363  Metadata *Val = nullptr;
1365  (Context, getMDOrNull(Record[1]),
1366  getMDOrNull(Record[2]), getMDOrNull(Record[3]),
1367  getMDOrNull(Record[4])));
1368 
1369  MetadataList.assignValue(Val, NextMetadataNo);
1370  IsDistinct = Record[0] & 1;
1371  NextMetadataNo++;
1372  break;
1373  }
1375  if (Record.size() < 3)
1376  return error("Invalid record");
1377 
1378  IsDistinct = Record[0] & 1;
1379  bool IsUnsigned = Record[0] & 2;
1380  bool IsBigInt = Record[0] & 4;
1381  APInt Value;
1382 
1383  if (IsBigInt) {
1384  const uint64_t BitWidth = Record[1];
1385  const size_t NumWords = Record.size() - 3;
1386  Value = readWideAPInt(makeArrayRef(&Record[3], NumWords), BitWidth);
1387  } else
1388  Value = APInt(64, unrotateSign(Record[1]), !IsUnsigned);
1389 
1390  MetadataList.assignValue(
1392  (Context, Value, IsUnsigned, getMDString(Record[2]))),
1393  NextMetadataNo);
1394  NextMetadataNo++;
1395  break;
1396  }
1398  if (Record.size() < 6 || Record.size() > 7)
1399  return error("Invalid record");
1400 
1401  IsDistinct = Record[0];
1402  DINode::DIFlags Flags = (Record.size() > 6)
1403  ? static_cast<DINode::DIFlags>(Record[6])
1404  : DINode::FlagZero;
1405 
1406  MetadataList.assignValue(
1408  (Context, Record[1], getMDString(Record[2]), Record[3],
1409  Record[4], Record[5], Flags)),
1410  NextMetadataNo);
1411  NextMetadataNo++;
1412  break;
1413  }
1415  if (Record.size() > 9 || Record.size() < 8)
1416  return error("Invalid record");
1417 
1418  IsDistinct = Record[0];
1419  bool SizeIs8 = Record.size() == 8;
1420  // StringLocationExp (i.e. Record[5]) is added at a later time
1421  // than the other fields. The code here enables backward compatibility.
1422  Metadata *StringLocationExp = SizeIs8 ? nullptr : getMDOrNull(Record[5]);
1423  unsigned Offset = SizeIs8 ? 5 : 6;
1424  MetadataList.assignValue(
1426  (Context, Record[1], getMDString(Record[2]),
1427  getMDOrNull(Record[3]), getMDOrNull(Record[4]),
1428  StringLocationExp, Record[Offset], Record[Offset + 1],
1429  Record[Offset + 2])),
1430  NextMetadataNo);
1431  NextMetadataNo++;
1432  break;
1433  }
1435  if (Record.size() < 12 || Record.size() > 14)
1436  return error("Invalid record");
1437 
1438  // DWARF address space is encoded as N->getDWARFAddressSpace() + 1. 0 means
1439  // that there is no DWARF address space associated with DIDerivedType.
1440  Optional<unsigned> DWARFAddressSpace;
1441  if (Record.size() > 12 && Record[12])
1442  DWARFAddressSpace = Record[12] - 1;
1443 
1444  Metadata *Annotations = nullptr;
1445  if (Record.size() > 13 && Record[13])
1446  Annotations = getMDOrNull(Record[13]);
1447 
1448  IsDistinct = Record[0];
1449  DINode::DIFlags Flags = static_cast<DINode::DIFlags>(Record[10]);
1450  MetadataList.assignValue(
1452  (Context, Record[1], getMDString(Record[2]),
1453  getMDOrNull(Record[3]), Record[4],
1454  getDITypeRefOrNull(Record[5]),
1455  getDITypeRefOrNull(Record[6]), Record[7], Record[8],
1456  Record[9], DWARFAddressSpace, Flags,
1457  getDITypeRefOrNull(Record[11]), Annotations)),
1458  NextMetadataNo);
1459  NextMetadataNo++;
1460  break;
1461  }
1463  if (Record.size() < 16 || Record.size() > 22)
1464  return error("Invalid record");
1465 
1466  // If we have a UUID and this is not a forward declaration, lookup the
1467  // mapping.
1468  IsDistinct = Record[0] & 0x1;
1469  bool IsNotUsedInTypeRef = Record[0] >= 2;
1470  unsigned Tag = Record[1];
1471  MDString *Name = getMDString(Record[2]);
1472  Metadata *File = getMDOrNull(Record[3]);
1473  unsigned Line = Record[4];
1474  Metadata *Scope = getDITypeRefOrNull(Record[5]);
1475  Metadata *BaseType = nullptr;
1476  uint64_t SizeInBits = Record[7];
1478  return error("Alignment value is too large");
1479  uint32_t AlignInBits = Record[8];
1480  uint64_t OffsetInBits = 0;
1481  DINode::DIFlags Flags = static_cast<DINode::DIFlags>(Record[10]);
1482  Metadata *Elements = nullptr;
1483  unsigned RuntimeLang = Record[12];
1484  Metadata *VTableHolder = nullptr;
1485  Metadata *TemplateParams = nullptr;
1486  Metadata *Discriminator = nullptr;
1487  Metadata *DataLocation = nullptr;
1488  Metadata *Associated = nullptr;
1489  Metadata *Allocated = nullptr;
1490  Metadata *Rank = nullptr;
1491  Metadata *Annotations = nullptr;
1492  auto *Identifier = getMDString(Record[15]);
1493  // If this module is being parsed so that it can be ThinLTO imported
1494  // into another module, composite types only need to be imported
1495  // as type declarations (unless full type definitions requested).
1496  // Create type declarations up front to save memory. Also, buildODRType
1497  // handles the case where this is type ODRed with a definition needed
1498  // by the importing module, in which case the existing definition is
1499  // used.
1500  if (IsImporting && !ImportFullTypeDefinitions && Identifier &&
1501  (Tag == dwarf::DW_TAG_enumeration_type ||
1502  Tag == dwarf::DW_TAG_class_type ||
1503  Tag == dwarf::DW_TAG_structure_type ||
1504  Tag == dwarf::DW_TAG_union_type)) {
1505  Flags = Flags | DINode::FlagFwdDecl;
1506  if (Name) {
1507  // This is a hack around preserving template parameters for simplified
1508  // template names - it should probably be replaced with a
1509  // DICompositeType flag specifying whether template parameters are
1510  // required on declarations of this type.
1511  StringRef NameStr = Name->getString();
1512  if (!NameStr.contains('<') || NameStr.startswith("_STN|"))
1513  TemplateParams = getMDOrNull(Record[14]);
1514  }
1515  } else {
1516  BaseType = getDITypeRefOrNull(Record[6]);
1517  OffsetInBits = Record[9];
1518  Elements = getMDOrNull(Record[11]);
1519  VTableHolder = getDITypeRefOrNull(Record[13]);
1520  TemplateParams = getMDOrNull(Record[14]);
1521  if (Record.size() > 16)
1522  Discriminator = getMDOrNull(Record[16]);
1523  if (Record.size() > 17)
1524  DataLocation = getMDOrNull(Record[17]);
1525  if (Record.size() > 19) {
1526  Associated = getMDOrNull(Record[18]);
1527  Allocated = getMDOrNull(Record[19]);
1528  }
1529  if (Record.size() > 20) {
1530  Rank = getMDOrNull(Record[20]);
1531  }
1532  if (Record.size() > 21) {
1533  Annotations = getMDOrNull(Record[21]);
1534  }
1535  }
1536  DICompositeType *CT = nullptr;
1537  if (Identifier)
1538  CT = DICompositeType::buildODRType(
1539  Context, *Identifier, Tag, Name, File, Line, Scope, BaseType,
1540  SizeInBits, AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
1541  VTableHolder, TemplateParams, Discriminator, DataLocation, Associated,
1542  Allocated, Rank, Annotations);
1543 
1544  // Create a node if we didn't get a lazy ODR type.
1545  if (!CT)
1547  (Context, Tag, Name, File, Line, Scope, BaseType,
1548  SizeInBits, AlignInBits, OffsetInBits, Flags,
1549  Elements, RuntimeLang, VTableHolder, TemplateParams,
1550  Identifier, Discriminator, DataLocation, Associated,
1551  Allocated, Rank, Annotations));
1552  if (!IsNotUsedInTypeRef && Identifier)
1553  MetadataList.addTypeRef(*Identifier, *cast<DICompositeType>(CT));
1554 
1555  MetadataList.assignValue(CT, NextMetadataNo);
1556  NextMetadataNo++;
1557  break;
1558  }
1560  if (Record.size() < 3 || Record.size() > 4)
1561  return error("Invalid record");
1562  bool IsOldTypeRefArray = Record[0] < 2;
1563  unsigned CC = (Record.size() > 3) ? Record[3] : 0;
1564 
1565  IsDistinct = Record[0] & 0x1;
1566  DINode::DIFlags Flags = static_cast<DINode::DIFlags>(Record[1]);
1567  Metadata *Types = getMDOrNull(Record[2]);
1568  if (LLVM_UNLIKELY(IsOldTypeRefArray))
1569  Types = MetadataList.upgradeTypeRefArray(Types);
1570 
1571  MetadataList.assignValue(
1572  GET_OR_DISTINCT(DISubroutineType, (Context, Flags, CC, Types)),
1573  NextMetadataNo);
1574  NextMetadataNo++;
1575  break;
1576  }
1577 
1578  case bitc::METADATA_MODULE: {
1579  if (Record.size() < 5 || Record.size() > 9)
1580  return error("Invalid record");
1581 
1582  unsigned Offset = Record.size() >= 8 ? 2 : 1;
1583  IsDistinct = Record[0];
1584  MetadataList.assignValue(
1586  DIModule,
1587  (Context, Record.size() >= 8 ? getMDOrNull(Record[1]) : nullptr,
1588  getMDOrNull(Record[0 + Offset]), getMDString(Record[1 + Offset]),
1589  getMDString(Record[2 + Offset]), getMDString(Record[3 + Offset]),
1590  getMDString(Record[4 + Offset]),
1591  Record.size() <= 7 ? 0 : Record[7],
1592  Record.size() <= 8 ? false : Record[8])),
1593  NextMetadataNo);
1594  NextMetadataNo++;
1595  break;
1596  }
1597 
1598  case bitc::METADATA_FILE: {
1599  if (Record.size() != 3 && Record.size() != 5 && Record.size() != 6)
1600  return error("Invalid record");
1601 
1602  IsDistinct = Record[0];
1604  // The BitcodeWriter writes null bytes into Record[3:4] when the Checksum
1605  // is not present. This matches up with the old internal representation,
1606  // and the old encoding for CSK_None in the ChecksumKind. The new
1607  // representation reserves the value 0 in the ChecksumKind to continue to
1608  // encode None in a backwards-compatible way.
1609  if (Record.size() > 4 && Record[3] && Record[4])
1610  Checksum.emplace(static_cast<DIFile::ChecksumKind>(Record[3]),
1611  getMDString(Record[4]));
1612  MetadataList.assignValue(
1614  DIFile,
1615  (Context, getMDString(Record[1]), getMDString(Record[2]), Checksum,
1616  Record.size() > 5 ? Optional<MDString *>(getMDString(Record[5]))
1617  : None)),
1618  NextMetadataNo);
1619  NextMetadataNo++;
1620  break;
1621  }
1623  if (Record.size() < 14 || Record.size() > 22)
1624  return error("Invalid record");
1625 
1626  // Ignore Record[0], which indicates whether this compile unit is
1627  // distinct. It's always distinct.
1628  IsDistinct = true;
1629  auto *CU = DICompileUnit::getDistinct(
1630  Context, Record[1], getMDOrNull(Record[2]), getMDString(Record[3]),
1631  Record[4], getMDString(Record[5]), Record[6], getMDString(Record[7]),
1632  Record[8], getMDOrNull(Record[9]), getMDOrNull(Record[10]),
1633  getMDOrNull(Record[12]), getMDOrNull(Record[13]),
1634  Record.size() <= 15 ? nullptr : getMDOrNull(Record[15]),
1635  Record.size() <= 14 ? 0 : Record[14],
1636  Record.size() <= 16 ? true : Record[16],
1637  Record.size() <= 17 ? false : Record[17],
1638  Record.size() <= 18 ? 0 : Record[18],
1639  Record.size() <= 19 ? false : Record[19],
1640  Record.size() <= 20 ? nullptr : getMDString(Record[20]),
1641  Record.size() <= 21 ? nullptr : getMDString(Record[21]));
1642 
1643  MetadataList.assignValue(CU, NextMetadataNo);
1644  NextMetadataNo++;
1645 
1646  // Move the Upgrade the list of subprograms.
1647  if (Metadata *SPs = getMDOrNullWithoutPlaceholders(Record[11]))
1648  CUSubprograms.push_back({CU, SPs});
1649  break;
1650  }
1652  if (Record.size() < 18 || Record.size() > 21)
1653  return error("Invalid record");
1654 
1655  bool HasSPFlags = Record[0] & 4;
1656 
1657  DINode::DIFlags Flags;
1658  DISubprogram::DISPFlags SPFlags;
1659  if (!HasSPFlags)
1660  Flags = static_cast<DINode::DIFlags>(Record[11 + 2]);
1661  else {
1662  Flags = static_cast<DINode::DIFlags>(Record[11]);
1663  SPFlags = static_cast<DISubprogram::DISPFlags>(Record[9]);
1664  }
1665 
1666  // Support for old metadata when
1667  // subprogram specific flags are placed in DIFlags.
1668  const unsigned DIFlagMainSubprogram = 1 << 21;
1669  bool HasOldMainSubprogramFlag = Flags & DIFlagMainSubprogram;
1670  if (HasOldMainSubprogramFlag)
1671  // Remove old DIFlagMainSubprogram from DIFlags.
1672  // Note: This assumes that any future use of bit 21 defaults to it
1673  // being 0.
1674  Flags &= ~static_cast<DINode::DIFlags>(DIFlagMainSubprogram);
1675 
1676  if (HasOldMainSubprogramFlag && HasSPFlags)
1677  SPFlags |= DISubprogram::SPFlagMainSubprogram;
1678  else if (!HasSPFlags)
1679  SPFlags = DISubprogram::toSPFlags(
1680  /*IsLocalToUnit=*/Record[7], /*IsDefinition=*/Record[8],
1681  /*IsOptimized=*/Record[14], /*Virtuality=*/Record[11],
1682  /*IsMainSubprogram=*/HasOldMainSubprogramFlag);
1683 
1684  // All definitions should be distinct.
1685  IsDistinct = (Record[0] & 1) || (SPFlags & DISubprogram::SPFlagDefinition);
1686  // Version 1 has a Function as Record[15].
1687  // Version 2 has removed Record[15].
1688  // Version 3 has the Unit as Record[15].
1689  // Version 4 added thisAdjustment.
1690  // Version 5 repacked flags into DISPFlags, changing many element numbers.
1691  bool HasUnit = Record[0] & 2;
1692  if (!HasSPFlags && HasUnit && Record.size() < 19)
1693  return error("Invalid record");
1694  if (HasSPFlags && !HasUnit)
1695  return error("Invalid record");
1696  // Accommodate older formats.
1697  bool HasFn = false;
1698  bool HasThisAdj = true;
1699  bool HasThrownTypes = true;
1700  bool HasAnnotations = false;
1701  bool HasTargetFuncName = false;
1702  unsigned OffsetA = 0;
1703  unsigned OffsetB = 0;
1704  if (!HasSPFlags) {
1705  OffsetA = 2;
1706  OffsetB = 2;
1707  if (Record.size() >= 19) {
1708  HasFn = !HasUnit;
1709  OffsetB++;
1710  }
1711  HasThisAdj = Record.size() >= 20;
1712  HasThrownTypes = Record.size() >= 21;
1713  } else {
1714  HasAnnotations = Record.size() >= 19;
1715  HasTargetFuncName = Record.size() >= 20;
1716  }
1717  Metadata *CUorFn = getMDOrNull(Record[12 + OffsetB]);
1719  DISubprogram,
1720  (Context,
1721  getDITypeRefOrNull(Record[1]), // scope
1722  getMDString(Record[2]), // name
1723  getMDString(Record[3]), // linkageName
1724  getMDOrNull(Record[4]), // file
1725  Record[5], // line
1726  getMDOrNull(Record[6]), // type
1727  Record[7 + OffsetA], // scopeLine
1728  getDITypeRefOrNull(Record[8 + OffsetA]), // containingType
1729  Record[10 + OffsetA], // virtualIndex
1730  HasThisAdj ? Record[16 + OffsetB] : 0, // thisAdjustment
1731  Flags, // flags
1732  SPFlags, // SPFlags
1733  HasUnit ? CUorFn : nullptr, // unit
1734  getMDOrNull(Record[13 + OffsetB]), // templateParams
1735  getMDOrNull(Record[14 + OffsetB]), // declaration
1736  getMDOrNull(Record[15 + OffsetB]), // retainedNodes
1737  HasThrownTypes ? getMDOrNull(Record[17 + OffsetB])
1738  : nullptr, // thrownTypes
1739  HasAnnotations ? getMDOrNull(Record[18 + OffsetB])
1740  : nullptr, // annotations
1741  HasTargetFuncName ? getMDString(Record[19 + OffsetB])
1742  : nullptr // targetFuncName
1743  ));
1744  MetadataList.assignValue(SP, NextMetadataNo);
1745  NextMetadataNo++;
1746 
1747  // Upgrade sp->function mapping to function->sp mapping.
1748  if (HasFn) {
1749  if (auto *CMD = dyn_cast_or_null<ConstantAsMetadata>(CUorFn))
1750  if (auto *F = dyn_cast<Function>(CMD->getValue())) {
1751  if (F->isMaterializable())
1752  // Defer until materialized; unmaterialized functions may not have
1753  // metadata.
1754  FunctionsWithSPs[F] = SP;
1755  else if (!F->empty())
1756  F->setSubprogram(SP);
1757  }
1758  }
1759  break;
1760  }
1762  if (Record.size() != 5)
1763  return error("Invalid record");
1764 
1765  IsDistinct = Record[0];
1766  MetadataList.assignValue(
1768  (Context, getMDOrNull(Record[1]),
1769  getMDOrNull(Record[2]), Record[3], Record[4])),
1770  NextMetadataNo);
1771  NextMetadataNo++;
1772  break;
1773  }
1775  if (Record.size() != 4)
1776  return error("Invalid record");
1777 
1778  IsDistinct = Record[0];
1779  MetadataList.assignValue(
1781  (Context, getMDOrNull(Record[1]),
1782  getMDOrNull(Record[2]), Record[3])),
1783  NextMetadataNo);
1784  NextMetadataNo++;
1785  break;
1786  }
1788  IsDistinct = Record[0] & 1;
1789  MetadataList.assignValue(
1791  (Context, getMDOrNull(Record[1]),
1792  getMDOrNull(Record[2]), getMDString(Record[3]),
1793  getMDOrNull(Record[4]), Record[5])),
1794  NextMetadataNo);
1795  NextMetadataNo++;
1796  break;
1797  }
1798  case bitc::METADATA_NAMESPACE: {
1799  // Newer versions of DINamespace dropped file and line.
1800  MDString *Name;
1801  if (Record.size() == 3)
1802  Name = getMDString(Record[2]);
1803  else if (Record.size() == 5)
1804  Name = getMDString(Record[3]);
1805  else
1806  return error("Invalid record");
1807 
1808  IsDistinct = Record[0] & 1;
1809  bool ExportSymbols = Record[0] & 2;
1810  MetadataList.assignValue(
1812  (Context, getMDOrNull(Record[1]), Name, ExportSymbols)),
1813  NextMetadataNo);
1814  NextMetadataNo++;
1815  break;
1816  }
1817  case bitc::METADATA_MACRO: {
1818  if (Record.size() != 5)
1819  return error("Invalid record");
1820 
1821  IsDistinct = Record[0];
1822  MetadataList.assignValue(
1824  (Context, Record[1], Record[2], getMDString(Record[3]),
1825  getMDString(Record[4]))),
1826  NextMetadataNo);
1827  NextMetadataNo++;
1828  break;
1829  }
1831  if (Record.size() != 5)
1832  return error("Invalid record");
1833 
1834  IsDistinct = Record[0];
1835  MetadataList.assignValue(
1837  (Context, Record[1], Record[2], getMDOrNull(Record[3]),
1838  getMDOrNull(Record[4]))),
1839  NextMetadataNo);
1840  NextMetadataNo++;
1841  break;
1842  }
1844  if (Record.size() < 3 || Record.size() > 4)
1845  return error("Invalid record");
1846 
1847  IsDistinct = Record[0];
1848  MetadataList.assignValue(
1850  (Context, getMDString(Record[1]),
1851  getDITypeRefOrNull(Record[2]),
1852  (Record.size() == 4) ? getMDOrNull(Record[3])
1853  : getMDOrNull(false))),
1854  NextMetadataNo);
1855  NextMetadataNo++;
1856  break;
1857  }
1859  if (Record.size() < 5 || Record.size() > 6)
1860  return error("Invalid record");
1861 
1862  IsDistinct = Record[0];
1863 
1864  MetadataList.assignValue(
1867  (Context, Record[1], getMDString(Record[2]),
1868  getDITypeRefOrNull(Record[3]),
1869  (Record.size() == 6) ? getMDOrNull(Record[4]) : getMDOrNull(false),
1870  (Record.size() == 6) ? getMDOrNull(Record[5])
1871  : getMDOrNull(Record[4]))),
1872  NextMetadataNo);
1873  NextMetadataNo++;
1874  break;
1875  }
1877  if (Record.size() < 11 || Record.size() > 13)
1878  return error("Invalid record");
1879 
1880  IsDistinct = Record[0] & 1;
1881  unsigned Version = Record[0] >> 1;
1882 
1883  if (Version == 2) {
1884  Metadata *Annotations = nullptr;
1885  if (Record.size() > 12)
1886  Annotations = getMDOrNull(Record[12]);
1887 
1888  MetadataList.assignValue(
1890  (Context, getMDOrNull(Record[1]),
1891  getMDString(Record[2]), getMDString(Record[3]),
1892  getMDOrNull(Record[4]), Record[5],
1893  getDITypeRefOrNull(Record[6]), Record[7], Record[8],
1894  getMDOrNull(Record[9]), getMDOrNull(Record[10]),
1895  Record[11], Annotations)),
1896  NextMetadataNo);
1897 
1898  NextMetadataNo++;
1899  } else if (Version == 1) {
1900  // No upgrade necessary. A null field will be introduced to indicate
1901  // that no parameter information is available.
1902  MetadataList.assignValue(
1905  (Context, getMDOrNull(Record[1]), getMDString(Record[2]),
1906  getMDString(Record[3]), getMDOrNull(Record[4]), Record[5],
1907  getDITypeRefOrNull(Record[6]), Record[7], Record[8],
1908  getMDOrNull(Record[10]), nullptr, Record[11], nullptr)),
1909  NextMetadataNo);
1910 
1911  NextMetadataNo++;
1912  } else if (Version == 0) {
1913  // Upgrade old metadata, which stored a global variable reference or a
1914  // ConstantInt here.
1915  NeedUpgradeToDIGlobalVariableExpression = true;
1916  Metadata *Expr = getMDOrNull(Record[9]);
1917  uint32_t AlignInBits = 0;
1918  if (Record.size() > 11) {
1920  return error("Alignment value is too large");
1921  AlignInBits = Record[11];
1922  }
1923  GlobalVariable *Attach = nullptr;
1924  if (auto *CMD = dyn_cast_or_null<ConstantAsMetadata>(Expr)) {
1925  if (auto *GV = dyn_cast<GlobalVariable>(CMD->getValue())) {
1926  Attach = GV;
1927  Expr = nullptr;
1928  } else if (auto *CI = dyn_cast<ConstantInt>(CMD->getValue())) {
1929  Expr = DIExpression::get(Context,
1930  {dwarf::DW_OP_constu, CI->getZExtValue(),
1931  dwarf::DW_OP_stack_value});
1932  } else {
1933  Expr = nullptr;
1934  }
1935  }
1938  (Context, getMDOrNull(Record[1]), getMDString(Record[2]),
1939  getMDString(Record[3]), getMDOrNull(Record[4]), Record[5],
1940  getDITypeRefOrNull(Record[6]), Record[7], Record[8],
1941  getMDOrNull(Record[10]), nullptr, AlignInBits, nullptr));
1942 
1943  DIGlobalVariableExpression *DGVE = nullptr;
1944  if (Attach || Expr)
1945  DGVE = DIGlobalVariableExpression::getDistinct(
1946  Context, DGV, Expr ? Expr : DIExpression::get(Context, {}));
1947  if (Attach)
1948  Attach->addDebugInfo(DGVE);
1949 
1950  auto *MDNode = Expr ? cast<Metadata>(DGVE) : cast<Metadata>(DGV);
1951  MetadataList.assignValue(MDNode, NextMetadataNo);
1952  NextMetadataNo++;
1953  } else
1954  return error("Invalid record");
1955 
1956  break;
1957  }
1958  case bitc::METADATA_LOCAL_VAR: {
1959  // 10th field is for the obseleted 'inlinedAt:' field.
1960  if (Record.size() < 8 || Record.size() > 10)
1961  return error("Invalid record");
1962 
1963  IsDistinct = Record[0] & 1;
1964  bool HasAlignment = Record[0] & 2;
1965  // 2nd field used to be an artificial tag, either DW_TAG_auto_variable or
1966  // DW_TAG_arg_variable, if we have alignment flag encoded it means, that
1967  // this is newer version of record which doesn't have artificial tag.
1968  bool HasTag = !HasAlignment && Record.size() > 8;
1969  DINode::DIFlags Flags = static_cast<DINode::DIFlags>(Record[7 + HasTag]);
1970  uint32_t AlignInBits = 0;
1971  Metadata *Annotations = nullptr;
1972  if (HasAlignment) {
1974  return error("Alignment value is too large");
1975  AlignInBits = Record[8];
1976  if (Record.size() > 9)
1977  Annotations = getMDOrNull(Record[9]);
1978  }
1979 
1980  MetadataList.assignValue(
1982  (Context, getMDOrNull(Record[1 + HasTag]),
1983  getMDString(Record[2 + HasTag]),
1984  getMDOrNull(Record[3 + HasTag]), Record[4 + HasTag],
1985  getDITypeRefOrNull(Record[5 + HasTag]),
1986  Record[6 + HasTag], Flags, AlignInBits, Annotations)),
1987  NextMetadataNo);
1988  NextMetadataNo++;
1989  break;
1990  }
1991  case bitc::METADATA_LABEL: {
1992  if (Record.size() != 5)
1993  return error("Invalid record");
1994 
1995  IsDistinct = Record[0] & 1;
1996  MetadataList.assignValue(
1997  GET_OR_DISTINCT(DILabel, (Context, getMDOrNull(Record[1]),
1998  getMDString(Record[2]),
1999  getMDOrNull(Record[3]), Record[4])),
2000  NextMetadataNo);
2001  NextMetadataNo++;
2002  break;
2003  }
2005  if (Record.size() < 1)
2006  return error("Invalid record");
2007 
2008  IsDistinct = Record[0] & 1;
2009  uint64_t Version = Record[0] >> 1;
2010  auto Elts = MutableArrayRef<uint64_t>(Record).slice(1);
2011 
2012  SmallVector<uint64_t, 6> Buffer;
2013  if (Error Err = upgradeDIExpression(Version, Elts, Buffer))
2014  return Err;
2015 
2016  MetadataList.assignValue(GET_OR_DISTINCT(DIExpression, (Context, Elts)),
2017  NextMetadataNo);
2018  NextMetadataNo++;
2019  break;
2020  }
2022  if (Record.size() != 3)
2023  return error("Invalid record");
2024 
2025  IsDistinct = Record[0];
2026  Metadata *Expr = getMDOrNull(Record[2]);
2027  if (!Expr)
2028  Expr = DIExpression::get(Context, {});
2029  MetadataList.assignValue(
2031  (Context, getMDOrNull(Record[1]), Expr)),
2032  NextMetadataNo);
2033  NextMetadataNo++;
2034  break;
2035  }
2037  if (Record.size() != 8)
2038  return error("Invalid record");
2039 
2040  IsDistinct = Record[0];
2041  MetadataList.assignValue(
2043  (Context, getMDString(Record[1]),
2044  getMDOrNull(Record[2]), Record[3],
2045  getMDString(Record[4]), getMDString(Record[5]),
2046  Record[6], getDITypeRefOrNull(Record[7]))),
2047  NextMetadataNo);
2048  NextMetadataNo++;
2049  break;
2050  }
2052  if (Record.size() < 6 || Record.size() > 8)
2053  return error("Invalid DIImportedEntity record");
2054 
2055  IsDistinct = Record[0];
2056  bool HasFile = (Record.size() >= 7);
2057  bool HasElements = (Record.size() >= 8);
2058  MetadataList.assignValue(
2060  (Context, Record[1], getMDOrNull(Record[2]),
2061  getDITypeRefOrNull(Record[3]),
2062  HasFile ? getMDOrNull(Record[6]) : nullptr,
2063  HasFile ? Record[4] : 0, getMDString(Record[5]),
2064  HasElements ? getMDOrNull(Record[7]) : nullptr)),
2065  NextMetadataNo);
2066  NextMetadataNo++;
2067  break;
2068  }
2070  std::string String(Record.begin(), Record.end());
2071 
2072  // Test for upgrading !llvm.loop.
2073  HasSeenOldLoopTags |= mayBeOldLoopAttachmentTag(String);
2074  ++NumMDStringLoaded;
2076  MetadataList.assignValue(MD, NextMetadataNo);
2077  NextMetadataNo++;
2078  break;
2079  }
2080  case bitc::METADATA_STRINGS: {
2081  auto CreateNextMDString = [&](StringRef Str) {
2082  ++NumMDStringLoaded;
2083  MetadataList.assignValue(MDString::get(Context, Str), NextMetadataNo);
2084  NextMetadataNo++;
2085  };
2086  if (Error Err = parseMetadataStrings(Record, Blob, CreateNextMDString))
2087  return Err;
2088  break;
2089  }
2091  if (Record.size() % 2 == 0)
2092  return error("Invalid record");
2093  unsigned ValueID = Record[0];
2094  if (ValueID >= ValueList.size())
2095  return error("Invalid record");
2096  if (auto *GO = dyn_cast<GlobalObject>(ValueList[ValueID]))
2097  if (Error Err = parseGlobalObjectAttachment(
2098  *GO, ArrayRef<uint64_t>(Record).slice(1)))
2099  return Err;
2100  break;
2101  }
2102  case bitc::METADATA_KIND: {
2103  // Support older bitcode files that had METADATA_KIND records in a
2104  // block with METADATA_BLOCK_ID.
2105  if (Error Err = parseMetadataKindRecord(Record))
2106  return Err;
2107  break;
2108  }
2109  case bitc::METADATA_ARG_LIST: {
2111  Elts.reserve(Record.size());
2112  for (uint64_t Elt : Record) {
2113  Metadata *MD = getMD(Elt);
2114  if (isa<MDNode>(MD) && cast<MDNode>(MD)->isTemporary())
2115  return error(
2116  "Invalid record: DIArgList should not contain forward refs");
2117  if (!isa<ValueAsMetadata>(MD))
2118  return error("Invalid record");
2119  Elts.push_back(cast<ValueAsMetadata>(MD));
2120  }
2121 
2122  MetadataList.assignValue(DIArgList::get(Context, Elts), NextMetadataNo);
2123  NextMetadataNo++;
2124  break;
2125  }
2126  }
2127  return Error::success();
2128 #undef GET_OR_DISTINCT
2129 }
2130 
2131 Error MetadataLoader::MetadataLoaderImpl::parseMetadataStrings(
2133  function_ref<void(StringRef)> CallBack) {
2134  // All the MDStrings in the block are emitted together in a single
2135  // record. The strings are concatenated and stored in a blob along with
2136  // their sizes.
2137  if (Record.size() != 2)
2138  return error("Invalid record: metadata strings layout");
2139 
2140  unsigned NumStrings = Record[0];
2141  unsigned StringsOffset = Record[1];
2142  if (!NumStrings)
2143  return error("Invalid record: metadata strings with no strings");
2144  if (StringsOffset > Blob.size())
2145  return error("Invalid record: metadata strings corrupt offset");
2146 
2147  StringRef Lengths = Blob.slice(0, StringsOffset);
2148  SimpleBitstreamCursor R(Lengths);
2149 
2150  StringRef Strings = Blob.drop_front(StringsOffset);
2151  do {
2152  if (R.AtEndOfStream())
2153  return error("Invalid record: metadata strings bad length");
2154 
2155  uint32_t Size;
2156  if (Error E = R.ReadVBR(6).moveInto(Size))
2157  return E;
2158  if (Strings.size() < Size)
2159  return error("Invalid record: metadata strings truncated chars");
2160 
2161  CallBack(Strings.slice(0, Size));
2162  Strings = Strings.drop_front(Size);
2163  } while (--NumStrings);
2164 
2165  return Error::success();
2166 }
2167 
2168 Error MetadataLoader::MetadataLoaderImpl::parseGlobalObjectAttachment(
2170  assert(Record.size() % 2 == 0);
2171  for (unsigned I = 0, E = Record.size(); I != E; I += 2) {
2172  auto K = MDKindMap.find(Record[I]);
2173  if (K == MDKindMap.end())
2174  return error("Invalid ID");
2175  MDNode *MD =
2176  dyn_cast_or_null<MDNode>(getMetadataFwdRefOrLoad(Record[I + 1]));
2177  if (!MD)
2178  return error("Invalid metadata attachment: expect fwd ref to MDNode");
2179  GO.addMetadata(K->second, *MD);
2180  }
2181  return Error::success();
2182 }
2183 
2184 /// Parse metadata attachments.
2186  Function &F, ArrayRef<Instruction *> InstructionList) {
2187  if (Error Err = Stream.EnterSubBlock(bitc::METADATA_ATTACHMENT_ID))
2188  return Err;
2189 
2191  PlaceholderQueue Placeholders;
2192 
2193  while (true) {
2194  BitstreamEntry Entry;
2195  if (Error E = Stream.advanceSkippingSubblocks().moveInto(Entry))
2196  return E;
2197 
2198  switch (Entry.Kind) {
2199  case BitstreamEntry::SubBlock: // Handled for us already.
2200  case BitstreamEntry::Error:
2201  return error("Malformed block");
2202  case BitstreamEntry::EndBlock:
2203  resolveForwardRefsAndPlaceholders(Placeholders);
2204  return Error::success();
2205  case BitstreamEntry::Record:
2206  // The interesting case.
2207  break;
2208  }
2209 
2210  // Read a metadata attachment record.
2211  Record.clear();
2212  ++NumMDRecordLoaded;
2213  Expected<unsigned> MaybeRecord = Stream.readRecord(Entry.ID, Record);
2214  if (!MaybeRecord)
2215  return MaybeRecord.takeError();
2216  switch (MaybeRecord.get()) {
2217  default: // Default behavior: ignore.
2218  break;
2220  unsigned RecordLength = Record.size();
2221  if (Record.empty())
2222  return error("Invalid record");
2223  if (RecordLength % 2 == 0) {
2224  // A function attachment.
2225  if (Error Err = parseGlobalObjectAttachment(F, Record))
2226  return Err;
2227  continue;
2228  }
2229 
2230  // An instruction attachment.
2231  Instruction *Inst = InstructionList[Record[0]];
2232  for (unsigned i = 1; i != RecordLength; i = i + 2) {
2233  unsigned Kind = Record[i];
2235  if (I == MDKindMap.end())
2236  return error("Invalid ID");
2237  if (I->second == LLVMContext::MD_tbaa && StripTBAA)
2238  continue;
2239 
2240  auto Idx = Record[i + 1];
2241  if (Idx < (MDStringRef.size() + GlobalMetadataBitPosIndex.size()) &&
2242  !MetadataList.lookup(Idx)) {
2243  // Load the attachment if it is in the lazy-loadable range and hasn't
2244  // been loaded yet.
2245  lazyLoadOneMetadata(Idx, Placeholders);
2246  resolveForwardRefsAndPlaceholders(Placeholders);
2247  }
2248 
2249  Metadata *Node = MetadataList.getMetadataFwdRef(Idx);
2250  if (isa<LocalAsMetadata>(Node))
2251  // Drop the attachment. This used to be legal, but there's no
2252  // upgrade path.
2253  break;
2254  MDNode *MD = dyn_cast_or_null<MDNode>(Node);
2255  if (!MD)
2256  return error("Invalid metadata attachment");
2257 
2258  if (HasSeenOldLoopTags && I->second == LLVMContext::MD_loop)
2260 
2261  if (I->second == LLVMContext::MD_tbaa) {
2262  assert(!MD->isTemporary() && "should load MDs before attachments");
2263  MD = UpgradeTBAANode(*MD);
2264  }
2265  Inst->setMetadata(I->second, MD);
2266  }
2267  break;
2268  }
2269  }
2270  }
2271 }
2272 
2273 /// Parse a single METADATA_KIND record, inserting result in MDKindMap.
2274 Error MetadataLoader::MetadataLoaderImpl::parseMetadataKindRecord(
2276  if (Record.size() < 2)
2277  return error("Invalid record");
2278 
2279  unsigned Kind = Record[0];
2280  SmallString<8> Name(Record.begin() + 1, Record.end());
2281 
2282  unsigned NewKind = TheModule.getMDKindID(Name.str());
2283  if (!MDKindMap.insert(std::make_pair(Kind, NewKind)).second)
2284  return error("Conflicting METADATA_KIND records");
2285  return Error::success();
2286 }
2287 
2288 /// Parse the metadata kinds out of the METADATA_KIND_BLOCK.
2290  if (Error Err = Stream.EnterSubBlock(bitc::METADATA_KIND_BLOCK_ID))
2291  return Err;
2292 
2294 
2295  // Read all the records.
2296  while (true) {
2297  BitstreamEntry Entry;
2298  if (Error E = Stream.advanceSkippingSubblocks().moveInto(Entry))
2299  return E;
2300 
2301  switch (Entry.Kind) {
2302  case BitstreamEntry::SubBlock: // Handled for us already.
2303  case BitstreamEntry::Error:
2304  return error("Malformed block");
2305  case BitstreamEntry::EndBlock:
2306  return Error::success();
2307  case BitstreamEntry::Record:
2308  // The interesting case.
2309  break;
2310  }
2311 
2312  // Read a record.
2313  Record.clear();
2314  ++NumMDRecordLoaded;
2315  Expected<unsigned> MaybeCode = Stream.readRecord(Entry.ID, Record);
2316  if (!MaybeCode)
2317  return MaybeCode.takeError();
2318  switch (MaybeCode.get()) {
2319  default: // Default behavior: ignore.
2320  break;
2321  case bitc::METADATA_KIND: {
2322  if (Error Err = parseMetadataKindRecord(Record))
2323  return Err;
2324  break;
2325  }
2326  }
2327  }
2328 }
2329 
2330 MetadataLoader &MetadataLoader::operator=(MetadataLoader &&RHS) {
2331  Pimpl = std::move(RHS.Pimpl);
2332  return *this;
2333 }
2334 MetadataLoader::MetadataLoader(MetadataLoader &&RHS)
2335  : Pimpl(std::move(RHS.Pimpl)) {}
2336 
2339  BitcodeReaderValueList &ValueList,
2340  bool IsImporting,
2341  std::function<Type *(unsigned)> getTypeByID)
2342  : Pimpl(std::make_unique<MetadataLoaderImpl>(
2343  Stream, TheModule, ValueList, std::move(getTypeByID), IsImporting)) {}
2344 
2345 Error MetadataLoader::parseMetadata(bool ModuleLevel) {
2346  return Pimpl->parseMetadata(ModuleLevel);
2347 }
2348 
2349 bool MetadataLoader::hasFwdRefs() const { return Pimpl->hasFwdRefs(); }
2350 
2351 /// Return the given metadata, creating a replaceable forward reference if
2352 /// necessary.
2354  return Pimpl->getMetadataFwdRefOrLoad(Idx);
2355 }
2356 
2358  return Pimpl->lookupSubprogramForFunction(F);
2359 }
2360 
2362  Function &F, ArrayRef<Instruction *> InstructionList) {
2363  return Pimpl->parseMetadataAttachment(F, InstructionList);
2364 }
2365 
2367  return Pimpl->parseMetadataKinds();
2368 }
2369 
2370 void MetadataLoader::setStripTBAA(bool StripTBAA) {
2371  return Pimpl->setStripTBAA(StripTBAA);
2372 }
2373 
2374 bool MetadataLoader::isStrippingTBAA() { return Pimpl->isStrippingTBAA(); }
2375 
2376 unsigned MetadataLoader::size() const { return Pimpl->size(); }
2377 void MetadataLoader::shrinkTo(unsigned N) { return Pimpl->shrinkTo(N); }
2378 
2380  return Pimpl->upgradeDebugIntrinsics(F);
2381 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:77
i
i
Definition: README.txt:29
llvm::upgradeInstructionLoopAttachment
MDNode * upgradeInstructionLoopAttachment(MDNode &N)
Upgrade the loop attachment metadata node.
Definition: AutoUpgrade.cpp:4601
llvm::codeview::ClassOptions::ForwardReference
@ ForwardReference
llvm::Argument
This class represents an incoming formal argument to a Function.
Definition: Argument.h:28
llvm::StringRef::startswith
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:290
llvm::BitcodeError::CorruptedBitcode
@ CorruptedBitcode
llvm::MetadataLoader::lookupSubprogramForFunction
DISubprogram * lookupSubprogramForFunction(Function *F)
Return the DISubprogram metadata for a Function if any, null otherwise.
Definition: MetadataLoader.cpp:2357
llvm::MetadataLoader::MetadataLoaderImpl
Definition: MetadataLoader.cpp:404
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::bitc::METADATA_LABEL
@ METADATA_LABEL
Definition: LLVMBitCodes.h:346
llvm::NamedMDNode
A tuple of MDNodes.
Definition: Metadata.h:1488
llvm::lltok::Error
@ Error
Definition: LLToken.h:21
Optional.h
Metadata.h
ValueList.h
IntrinsicInst.h
DebugInfoMetadata.h
llvm::DIGenericSubrange
Definition: DebugInfoMetadata.h:363
llvm::bitc::METADATA_DISTINCT_NODE
@ METADATA_DISTINCT_NODE
Definition: LLVMBitCodes.h:311
llvm::Function
Definition: Function.h:60
llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, 4, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::lookup
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:199
StringRef.h
llvm::MetadataLoader::parseMetadataKinds
Error parseMetadataKinds()
Parse a METADATA_KIND block for the current module.
Definition: MetadataLoader.cpp:2366
llvm::DILexicalBlockFile
Definition: DebugInfoMetadata.h:2140
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
Statistic.h
llvm::tgtok::Code
@ Code
Definition: TGLexer.h:50
llvm::bitc::METADATA_SUBRANGE
@ METADATA_SUBRANGE
Definition: LLVMBitCodes.h:319
llvm::DIStringType
String type, Fortran CHARACTER(n)
Definition: DebugInfoMetadata.h:832
ErrorHandling.h
ImportFullTypeDefinitions
static cl::opt< bool > ImportFullTypeDefinitions("import-full-type-definitions", cl::init(false), cl::Hidden, cl::desc("Import full type definitions for ThinLTO."))
Flag whether we need to import full type definitions for ThinLTO.
llvm::SmallDenseSet
Implements a dense probed hash-table based set with some number of buckets stored inline.
Definition: DenseSet.h:286
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
llvm::MetadataLoader::parseMetadataAttachment
Error parseMetadataAttachment(Function &F, ArrayRef< Instruction * > InstructionList)
Parse a METADATA_ATTACHMENT block for a function.
Definition: MetadataLoader.cpp:2361
llvm::GlobalVariable
Definition: GlobalVariable.h:39
llvm::SmallDenseMap
Definition: DenseMap.h:882
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:139
APInt.h
llvm::bitc::METADATA_BASIC_TYPE
@ METADATA_BASIC_TYPE
Definition: LLVMBitCodes.h:321
llvm::DILocation
Debug location.
Definition: DebugInfoMetadata.h:1557
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
DenseMap.h
llvm::bitc::METADATA_GLOBAL_VAR_EXPR
@ METADATA_GLOBAL_VAR_EXPR
Definition: LLVMBitCodes.h:343
Module.h
llvm::BitstreamCursor
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
Definition: BitstreamReader.h:358
llvm::bitc::METADATA_ARG_LIST
@ METADATA_ARG_LIST
Definition: LLVMBitCodes.h:352
llvm::readWideAPInt
APInt readWideAPInt(ArrayRef< uint64_t > Vals, unsigned TypeBits)
Definition: BitcodeReader.cpp:2463
llvm::Optional< unsigned >
llvm::MetadataLoader::MetadataLoaderImpl::MetadataLoaderImpl
MetadataLoaderImpl(BitstreamCursor &Stream, Module &TheModule, BitcodeReaderValueList &ValueList, std::function< Type *(unsigned)> getTypeByID, bool IsImporting)
Definition: MetadataLoader.cpp:632
GlobalObject.h
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:79
llvm::bitc::METADATA_INDEX_OFFSET
@ METADATA_INDEX_OFFSET
Definition: LLVMBitCodes.h:344
llvm::BitstreamCursor::JumpToBit
Error JumpToBit(uint64_t BitNo)
Reset the stream to the specified bit number.
Definition: BitstreamReader.h:127
llvm::msgpack::Type::Array
@ Array
llvm::max
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:337
llvm::bitc::METADATA_EXPRESSION
@ METADATA_EXPRESSION
Definition: LLVMBitCodes.h:335
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::MetadataLoader::shrinkTo
void shrinkTo(unsigned N)
Definition: MetadataLoader.cpp:2377
llvm::DIExpression
DWARF expression.
Definition: DebugInfoMetadata.h:2558
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::StringRef::slice
LLVM_NODISCARD StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
Definition: StringRef.h:736
llvm::dwarf::Tag
Tag
Definition: Dwarf.h:105
BaseType
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::bitc::METADATA_OLD_NODE
@ METADATA_OLD_NODE
Definition: LLVMBitCodes.h:314
llvm::wasm::toString
llvm::StringRef toString(WasmSymbolType type)
Definition: Wasm.cpp:11
llvm::Type::isMetadataTy
bool isMetadataTy() const
Return true if this is 'metadata'.
Definition: Type.h:185
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1043
llvm::mayBeOldLoopAttachmentTag
bool mayBeOldLoopAttachmentTag(StringRef Name)
Check whether a string looks like an old loop attachment tag.
Definition: AutoUpgrade.h:92
llvm::DINamespace
Definition: DebugInfoMetadata.h:2258
llvm::MetadataLoader::MetadataLoaderImpl::setStripTBAA
void setStripTBAA(bool Value)
Definition: MetadataLoader.cpp:672
llvm::MetadataLoader::MetadataLoaderImpl::size
unsigned size() const
Definition: MetadataLoader.cpp:675
llvm::DILexicalBlock
Definition: DebugInfoMetadata.h:2087
llvm::MDNode::get
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1300
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::RISCVFenceField::R
@ R
Definition: RISCVBaseInfo.h:240
llvm::bitc::METADATA_FILE
@ METADATA_FILE
Definition: LLVMBitCodes.h:322
llvm::Instruction::setMetadata
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1366
llvm::Annotations
Annotations lets you mark points and ranges inside source code, for tests:
Definition: Annotations.h:48
llvm::bitc::METADATA_NAMESPACE
@ METADATA_NAMESPACE
Definition: LLVMBitCodes.h:330
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::MetadataLoader::hasFwdRefs
bool hasFwdRefs() const
Definition: MetadataLoader.cpp:2349
clear
static void clear(coro::Shape &Shape)
Definition: Coroutines.cpp:149
Instruction.h
llvm::NamedMDNode::addOperand
void addOperand(MDNode *M)
Definition: Metadata.cpp:1160
CommandLine.h
llvm::TrackingMDRef::reset
void reset()
Definition: TrackingMDRef.h:62
llvm::DIObjCProperty
Definition: DebugInfoMetadata.h:3213
llvm::bitc::METADATA_INDEX
@ METADATA_INDEX
Definition: LLVMBitCodes.h:345
llvm::MutableArrayRef::end
iterator end() const
Definition: ArrayRef.h:356
llvm::MutableArrayRef
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:306
llvm::ModRefInfo::Ref
@ Ref
The access may reference the value stored in memory.
llvm::bitc::METADATA_KIND_BLOCK_ID
@ METADATA_KIND_BLOCK_ID
Definition: LLVMBitCodes.h:57
Constants.h
llvm::Module::globals
iterator_range< global_iterator > globals()
Definition: Module.h:614
llvm::MetadataLoader::MetadataLoaderImpl::parseMetadataAttachment
Error parseMetadataAttachment(Function &F, ArrayRef< Instruction * > InstructionList)
Parse metadata attachments.
Definition: MetadataLoader.cpp:2185
SmallString.h
llvm::DILocalVariable
Local variable.
Definition: DebugInfoMetadata.h:3058
llvm::DIMacro
Definition: DebugInfoMetadata.h:3448
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::SmallVectorImpl::append
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:667
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
Twine.h
llvm::GlobalObject
Definition: GlobalObject.h:27
llvm::bitc::METADATA_COMPILE_UNIT
@ METADATA_COMPILE_UNIT
Definition: LLVMBitCodes.h:326
llvm::DISubprogram::DISPFlags
DISPFlags
Debug info subprogram flags.
Definition: DebugInfoMetadata.h:1818
llvm::DISubrange
Array subrange.
Definition: DebugInfoMetadata.h:300
llvm::bitc::METADATA_ENUMERATOR
@ METADATA_ENUMERATOR
Definition: LLVMBitCodes.h:320
DenseSet.h
llvm::MetadataLoader::MetadataLoaderImpl::lookupSubprogramForFunction
DISubprogram * lookupSubprogramForFunction(Function *F)
Definition: MetadataLoader.cpp:661
llvm::DITemplateTypeParameter
Definition: DebugInfoMetadata.h:2403
llvm::UpgradeTBAANode
MDNode * UpgradeTBAANode(MDNode &TBAANode)
If the given TBAA tag uses the scalar TBAA format, create a new node corresponding to the upgrade to ...
Definition: AutoUpgrade.cpp:4121
llvm::bitc::METADATA_LEXICAL_BLOCK
@ METADATA_LEXICAL_BLOCK
Definition: LLVMBitCodes.h:328
llvm::bitc::METADATA_MODULE
@ METADATA_MODULE
Definition: LLVMBitCodes.h:338
llvm::Instruction
Definition: Instruction.h:42
llvm::StringRef::contains
LLVM_NODISCARD bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Definition: StringRef.h:466
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:143
llvm::bitc::METADATA_GENERIC_SUBRANGE
@ METADATA_GENERIC_SUBRANGE
Definition: LLVMBitCodes.h:351
llvm::STATISTIC
STATISTIC(NumFunctions, "Total number of functions")
llvm::GlobalObject::addMetadata
void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
Definition: Metadata.cpp:1298
llvm::MDNode::getTemporary
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1312
llvm::MetadataLoader::size
unsigned size() const
Definition: MetadataLoader.cpp:2376
llvm::SmallVectorImpl::resize
void resize(size_type N)
Definition: SmallVector.h:619
llvm::bitc::METADATA_LOCATION
@ METADATA_LOCATION
Definition: LLVMBitCodes.h:313
llvm::IndexedInstrProf::Version
const uint64_t Version
Definition: InstrProf.h:1027
llvm::bitc::METADATA_NAME
@ METADATA_NAME
Definition: LLVMBitCodes.h:310
STLFunctionalExtras.h
DebugLocVerifyLevel::None
@ None
llvm::Metadata
Root of the metadata hierarchy.
Definition: Metadata.h:62
llvm::bitc::METADATA_COMPOSITE_TYPE
@ METADATA_COMPOSITE_TYPE
Definition: LLVMBitCodes.h:324
llvm::None
const NoneType None
Definition: None.h:24
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
DisableLazyLoading
static cl::opt< bool > DisableLazyLoading("disable-ondemand-mds-loading", cl::init(false), cl::Hidden, cl::desc("Force disable the lazy-loading on-demand of metadata when " "loading bitcode for importing."))
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
Type.h
llvm::SmallString< 8 >
BitstreamReader.h
llvm::MetadataLoader
Helper class that handles loading Metadatas and keeping them available.
Definition: MetadataLoader.h:33
llvm::DICommonBlock
Definition: DebugInfoMetadata.h:2999
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
llvm::MetadataLoader::MetadataLoader
MetadataLoader(BitstreamCursor &Stream, Module &TheModule, BitcodeReaderValueList &ValueList, bool IsImporting, std::function< Type *(unsigned)> getTypeByID)
Definition: MetadataLoader.cpp:2338
llvm::GlobalVariable::addDebugInfo
void addDebugInfo(DIGlobalVariableExpression *GV)
Attach a DIGlobalVariableExpression.
Definition: Metadata.cpp:1584
llvm::SimpleBitstreamCursor
This represents a position within a bitstream.
Definition: BitstreamReader.h:79
llvm::DenseSet< unsigned >
llvm::bitc::METADATA_KIND
@ METADATA_KIND
Definition: LLVMBitCodes.h:312
llvm::MutableArrayRef::slice
MutableArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Definition: ArrayRef.h:375
BasicBlock.h
llvm::cl::opt< bool >
llvm::BitcodeReaderValueList
Definition: ValueList.h:29
llvm::BitstreamCursor::GetCurrentBitNo
uint64_t GetCurrentBitNo() const
Return the bit # of the bit we are reading.
Definition: BitstreamReader.h:117
llvm::MetadataLoader::MetadataLoaderImpl::getMetadataFwdRefOrLoad
Metadata * getMetadataFwdRefOrLoad(unsigned ID)
Definition: MetadataLoader.cpp:645
llvm::DIEnumerator
Enumeration value.
Definition: DebugInfoMetadata.h:411
uint64_t
llvm::pdb::Unknown
@ Unknown
Definition: PDBTypes.h:396
llvm::bitc::METADATA_COMMON_BLOCK
@ METADATA_COMMON_BLOCK
Definition: LLVMBitCodes.h:350
llvm::bitc::METADATA_DERIVED_TYPE
@ METADATA_DERIVED_TYPE
Definition: LLVMBitCodes.h:323
llvm::TrackingMDRef::get
Metadata * get() const
Definition: TrackingMDRef.h:57
llvm::Optional::emplace
void emplace(ArgTypes &&... Args)
Create a new object by constructing it in place with the given arguments.
Definition: Optional.h:287
llvm::DIGlobalVariable
Global variables.
Definition: DebugInfoMetadata.h:2914
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::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::DenseMap< unsigned, unsigned >
llvm::DistinctMDOperandPlaceholder
Placeholder metadata for operands of distinct MDNodes.
Definition: Metadata.h:1443
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::MetadataLoader::~MetadataLoader
~MetadataLoader()
llvm::detail::DenseSetImpl< ValueT, SmallDenseMap< ValueT, detail::DenseSetEmpty, 4, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::empty
bool empty() const
Definition: DenseSet.h:80
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:432
llvm::bitc::METADATA_STRING_OLD
@ METADATA_STRING_OLD
Definition: LLVMBitCodes.h:307
llvm::DIImportedEntity
An imported module (C++ using directive or similar).
Definition: DebugInfoMetadata.h:3293
ArrayRef.h
llvm::bitc::METADATA_NAMED_NODE
@ METADATA_NAMED_NODE
Definition: LLVMBitCodes.h:316
llvm::bitc::METADATA_STRING_TYPE
@ METADATA_STRING_TYPE
Definition: LLVMBitCodes.h:347
llvm::MetadataLoader::MetadataLoaderImpl::parseMetadataKinds
Error parseMetadataKinds()
Parse the metadata kinds out of the METADATA_KIND_BLOCK.
Definition: MetadataLoader.cpp:2289
llvm::bitc::METADATA_SUBROUTINE_TYPE
@ METADATA_SUBROUTINE_TYPE
Definition: LLVMBitCodes.h:325
llvm::DenseMapBase::find
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:152
llvm::DIMacroFile
Definition: DebugInfoMetadata.h:3499
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1675
llvm::bitc::METADATA_NODE
@ METADATA_NODE
Definition: LLVMBitCodes.h:309
llvm::SPIRV::Decoration::Stream
@ Stream
cast
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte * cast({ double, int } *%C.0.904 to sbyte *)
iterator_range.h
llvm::MDTuple::get
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1267
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::Type::isVoidTy
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:139
UUID
std::pair< llvm::MachO::Target, std::string > UUID
Definition: TextStubCommon.h:23
llvm::MutableArrayRef::begin
iterator begin() const
Definition: ArrayRef.h:355
llvm::Record
Definition: Record.h:1543
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::MDNode
Metadata node.
Definition: Metadata.h:937
llvm::MetadataLoader::isStrippingTBAA
bool isStrippingTBAA()
Return true if the Loader is stripping TBAA metadata.
Definition: MetadataLoader.cpp:2374
llvm::BitcodeReaderValueList::size
unsigned size() const
Definition: ValueList.h:59
llvm::BitstreamCursor::readRecord
Expected< unsigned > readRecord(unsigned AbbrevID, SmallVectorImpl< uint64_t > &Vals, StringRef *Blob=nullptr)
Definition: BitstreamReader.cpp:213
llvm::DIBasicType
Basic type, like 'int' or 'float'.
Definition: DebugInfoMetadata.h:764
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
llvm::BitcodeReaderValueList::getValueFwdRef
Value * getValueFwdRef(unsigned Idx, Type *Ty, unsigned TyID)
Definition: ValueList.cpp:121
llvm::size
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1598
llvm::DISubroutineType
Type array for a subprogram.
Definition: DebugInfoMetadata.h:1265
llvm::DICompositeType
Composite types.
Definition: DebugInfoMetadata.h:1042
llvm::bitc::METADATA_TEMPLATE_VALUE
@ METADATA_TEMPLATE_VALUE
Definition: LLVMBitCodes.h:332
llvm::dwarf::DW_OP_LLVM_fragment
@ DW_OP_LLVM_fragment
Only used in LLVM metadata.
Definition: Dwarf.h:143
llvm::ArrayRef< uint64_t >
None.h
llvm::min
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:357
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
Dwarf.h
llvm::bitc::METADATA_LEXICAL_BLOCK_FILE
@ METADATA_LEXICAL_BLOCK_FILE
Definition: LLVMBitCodes.h:329
llvm::MetadataLoader::MetadataLoaderImpl::isStrippingTBAA
bool isStrippingTBAA() const
Definition: MetadataLoader.cpp:673
llvm::MetadataLoader::MetadataLoaderImpl::upgradeDebugIntrinsics
void upgradeDebugIntrinsics(Function &F)
Definition: MetadataLoader.cpp:677
BitmaskEnum.h
llvm::Expected::get
reference get()
Returns a reference to the stored T value.
Definition: Error.h:567
uint32_t
Compiler.h
llvm::GenericDINode
Generic tagged DWARF-like metadata node.
Definition: DebugInfoMetadata.h:227
llvm::MetadataLoader::MetadataLoaderImpl::parseMetadata
Error parseMetadata(bool ModuleLevel)
Parse a METADATA_BLOCK.
Definition: MetadataLoader.cpp:957
llvm::MDTuple::getTemporary
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a temporary node.
Definition: Metadata.h:1287
llvm::MDNode::getDistinct
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1308
LLVM_FALLTHROUGH
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:280
llvm::DenseMapBase::insert
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:209
llvm::bitc::METADATA_MACRO
@ METADATA_MACRO
Definition: LLVMBitCodes.h:339
llvm::make_error_code
std::error_code make_error_code(BitcodeError E)
Definition: BitcodeReader.h:271
llvm::DIType::isForwardDecl
bool isForwardDecl() const
Definition: DebugInfoMetadata.h:725
llvm::StringRef::size
constexpr LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:157
LLVMBitCodes.h
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::empty
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
Definition: STLExtras.h:268
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
std
Definition: BitVector.h:851
llvm::StringRef::drop_front
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition: StringRef.h:657
llvm::Module::getMDKindID
unsigned getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
Definition: Module.cpp:120
llvm::BitstreamEntry
When advancing through a bitstream cursor, each advance can discover a few different kinds of entries...
Definition: BitstreamReader.h:325
type_traits.h
get
Should compile to something r4 addze r3 instead we get
Definition: README.txt:24
llvm::DenseMapBase::end
iterator end()
Definition: DenseMap.h:84
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:345
llvm::bitc::METADATA_STRINGS
@ METADATA_STRINGS
Definition: LLVMBitCodes.h:341
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
GlobalVariable.h
Casting.h
Function.h
llvm::BitWidth
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:147
llvm::bitc::METADATA_GLOBAL_DECL_ATTACHMENT
@ METADATA_GLOBAL_DECL_ATTACHMENT
Definition: LLVMBitCodes.h:342
TrackingMDRef.h
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::Module::getOrInsertNamedMetadata
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
Definition: Module.cpp:260
llvm::bitc::METADATA_ATTACHMENT_ID
@ METADATA_ATTACHMENT_ID
Definition: LLVMBitCodes.h:46
llvm::object::Identifier
@ Identifier
Definition: COFFModuleDefinition.cpp:34
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:591
llvm::bitc::METADATA_OLD_FN_NODE
@ METADATA_OLD_FN_NODE
Definition: LLVMBitCodes.h:315
llvm::bitc::METADATA_ATTACHMENT
@ METADATA_ATTACHMENT
Definition: LLVMBitCodes.h:317
llvm::bitc::METADATA_MACRO_FILE
@ METADATA_MACRO_FILE
Definition: LLVMBitCodes.h:340
llvm::DIDerivedType
Derived types.
Definition: DebugInfoMetadata.h:924
llvm::DIGlobalVariableExpression
A pair of DIGlobalVariable and DIExpression.
Definition: DebugInfoMetadata.h:3358
llvm::MetadataLoader::MetadataLoaderImpl::hasFwdRefs
bool hasFwdRefs() const
Definition: MetadataLoader.cpp:643
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:475
llvm::MetadataLoader::setStripTBAA
void setStripTBAA(bool StripTBAA=true)
Set the mode to strip TBAA metadata on load.
Definition: MetadataLoader.cpp:2370
llvm::TrackingMDRef
Tracking metadata reference.
Definition: TrackingMDRef.h:25
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:597
llvm::DIFile::ChecksumKind
ChecksumKind
Which algorithm (e.g.
Definition: DebugInfoMetadata.h:534
llvm::DITemplateValueParameter
Definition: DebugInfoMetadata.h:2442
llvm::bitc::METADATA_GLOBAL_VAR
@ METADATA_GLOBAL_VAR
Definition: LLVMBitCodes.h:333
llvm::bitc::METADATA_BLOCK_ID
@ METADATA_BLOCK_ID
Definition: LLVMBitCodes.h:45
llvm::MDNode::isTemporary
bool isTemporary() const
Definition: Metadata.h:1051
llvm::bitc::METADATA_LOCAL_VAR
@ METADATA_LOCAL_VAR
Definition: LLVMBitCodes.h:334
MetadataLoader.h
SmallVector.h
llvm::DINode::DIFlags
DIFlags
Debug info flags.
Definition: DebugInfoMetadata.h:168
lookup
static bool lookup(const GsymReader &GR, DataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr, uint64_t Addr, SourceLocations &SrcLocs, llvm::Error &Err)
A Lookup helper functions.
Definition: InlineInfo.cpp:108
llvm::MetadataLoader::upgradeDebugIntrinsics
void upgradeDebugIntrinsics(Function &F)
Perform bitcode upgrades on llvm.dbg.* calls.
Definition: MetadataLoader.cpp:2379
N
#define N
llvm::bitc::METADATA_VALUE
@ METADATA_VALUE
Definition: LLVMBitCodes.h:308
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:164
llvm::Module::getNamedMetadata
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
Definition: Module.cpp:251
LLVM_LIKELY
#define LLVM_LIKELY(EXPR)
Definition: Compiler.h:219
AutoUpgrade.h
llvm::DISubprogram
Subprogram description.
Definition: DebugInfoMetadata.h:1803
llvm::SmallVectorImpl< uint64_t >
llvm::BitstreamCursor::skipRecord
Expected< unsigned > skipRecord(unsigned AbbrevID)
Read the current record and discard it, returning the code for the record.
Definition: BitstreamReader.cpp:95
error
static Error error(const Twine &Message)
Definition: MetadataLoader.cpp:399
llvm::DIModule
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
Definition: DebugInfoMetadata.h:2307
llvm::bitc::METADATA_SUBPROGRAM
@ METADATA_SUBPROGRAM
Definition: LLVMBitCodes.h:327
GET_OR_DISTINCT
#define GET_OR_DISTINCT(CLASS, ARGS)
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::bitc::METADATA_GENERIC_DEBUG
@ METADATA_GENERIC_DEBUG
Definition: LLVMBitCodes.h:318
llvm::DILabel
Label.
Definition: DebugInfoMetadata.h:3148
LLVMContext.h
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:394
llvm::cl::desc
Definition: CommandLine.h:405
BitcodeReader.h
llvm::MetadataLoader::getMetadataFwdRefOrLoad
Metadata * getMetadataFwdRefOrLoad(unsigned Idx)
Return the given metadata, creating a replaceable forward reference if necessary.
Definition: MetadataLoader.cpp:2353
llvm::pdb::String
@ String
Definition: PDBTypes.h:408
LLVM_UNLIKELY
#define LLVM_UNLIKELY(EXPR)
Definition: Compiler.h:220
llvm::bitc::METADATA_TEMPLATE_TYPE
@ METADATA_TEMPLATE_TYPE
Definition: LLVMBitCodes.h:331
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition: SmallVector.h:644
llvm::MDString
A single uniqued string.
Definition: Metadata.h:612
llvm::bitc::METADATA_OBJC_PROPERTY
@ METADATA_OBJC_PROPERTY
Definition: LLVMBitCodes.h:336
CU
Definition: AArch64AsmBackend.cpp:504
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
File
Instrumentation for Order File
Definition: InstrOrderFile.cpp:198
llvm::MetadataLoader::MetadataLoaderImpl::hasSeenOldLoopTags
bool hasSeenOldLoopTags() const
Definition: MetadataLoader.cpp:665
ilist_iterator.h
llvm::DICompositeType::getRawIdentifier
MDString * getRawIdentifier() const
Definition: DebugInfoMetadata.h:1192
llvm::DIFile
File.
Definition: DebugInfoMetadata.h:525
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:927
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38
llvm::MetadataLoader::MetadataLoaderImpl::shrinkTo
void shrinkTo(unsigned N)
Definition: MetadataLoader.cpp:676
llvm::bitc::METADATA_IMPORTED_ENTITY
@ METADATA_IMPORTED_ENTITY
Definition: LLVMBitCodes.h:337