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