LLVM: lib/Bitcode/Reader/MetadataLoader.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
11
48
49#include
50#include
51#include
52#include
53#include
54#include
55#include
56#include
57#include
58#include
59#include
60#include
61#include
62
63using namespace llvm;
64
65#define DEBUG_TYPE "bitcode-reader"
66
67STATISTIC(NumMDStringLoaded, "Number of MDStrings loaded");
68STATISTIC(NumMDNodeTemporary, "Number of MDNode::Temporary created");
69STATISTIC(NumMDRecordLoaded, "Number of Metadata records loaded");
70
71
72
75 cl::desc("Import full type definitions for ThinLTO."));
76
79 cl::desc("Force disable the lazy-loading on-demand of metadata when "
80 "loading bitcode for importing."));
81
82namespace {
83
84class BitcodeReaderMetadataList {
85
86
87
88
90
91
92
94
95
96
98
99
100 struct {
105 } OldTypeRefs;
106
107 LLVMContext &Context;
108
109
110
111 unsigned RefsUpperBound;
112
113public:
114 BitcodeReaderMetadataList(LLVMContext &C, size_t RefsUpperBound)
115 : Context(C),
116 RefsUpperBound(std::min((size_t)std::numeric_limits::max(),
117 RefsUpperBound)) {}
118
119
120 unsigned size() const { return MetadataPtrs.size(); }
121 void resize(unsigned N) { MetadataPtrs.resize(N); }
122 void push_back(Metadata *MD) { MetadataPtrs.emplace_back(MD); }
123 void clear() { MetadataPtrs.clear(); }
124 Metadata *back() const { return MetadataPtrs.back(); }
125 void pop_back() { MetadataPtrs.pop_back(); }
126 bool empty() const { return MetadataPtrs.empty(); }
127
128 Metadata *operator[](unsigned i) const { return MetadataPtrs[i]; }
129
131 if (I < MetadataPtrs.size())
132 return MetadataPtrs[I];
133 return nullptr;
134 }
135
136 void shrinkTo(unsigned N) {
137 assert(N <= size() && "Invalid shrinkTo request!");
138 assert(ForwardReference.empty() && "Unexpected forward refs");
139 assert(UnresolvedNodes.empty() && "Unexpected unresolved node");
140 MetadataPtrs.resize(N);
141 }
142
143
144
145 Metadata *getMetadataFwdRef(unsigned Idx);
146
147
148
149
150
151 Metadata *getMetadataIfResolved(unsigned Idx);
152
153 MDNode *getMDNodeFwdRefOrNull(unsigned Idx);
154 void assignValue(Metadata *MD, unsigned Idx);
155 void tryToResolveCycles();
156 bool hasFwdRefs() const { return !ForwardReference.empty(); }
157 int getNextFwdRef() {
158 assert(hasFwdRefs());
159 return *ForwardReference.begin();
160 }
161
162
163 void addTypeRef(MDString &UUID, DICompositeType &CT);
164
165
167
168
170
171private:
173};
174}
175
177
178void BitcodeReaderMetadataList::assignValue(Metadata *MD, unsigned Idx) {
180 if (!MDN->isResolved())
181 UnresolvedNodes.insert(Idx);
182
183 if (Idx == size()) {
184 push_back(MD);
185 return;
186 }
187
188 if (Idx >= size())
189 resize(Idx + 1);
190
191 TrackingMDRef &OldMD = MetadataPtrs[Idx];
192 if (!OldMD) {
194 return;
195 }
196
197
199 PrevMD->replaceAllUsesWith(MD);
201}
202
203Metadata *BitcodeReaderMetadataList::getMetadataFwdRef(unsigned Idx) {
204
205 if (Idx >= RefsUpperBound)
206 return nullptr;
207
208 if (Idx >= size())
209 resize(Idx + 1);
210
211 if (Metadata *MD = MetadataPtrs[Idx])
212 return MD;
213
214
216
217
218 ++NumMDNodeTemporary;
220 MetadataPtrs[Idx].reset(MD);
221 return MD;
222}
223
224Metadata *BitcodeReaderMetadataList::getMetadataIfResolved(unsigned Idx) {
227 if (->isResolved())
228 return nullptr;
229 return MD;
230}
231
232MDNode *BitcodeReaderMetadataList::getMDNodeFwdRefOrNull(unsigned Idx) {
234}
235
236void BitcodeReaderMetadataList::tryToResolveCycles() {
238
239 return;
240
241
242 for (const auto &Ref : OldTypeRefs.FwdDecls)
243 OldTypeRefs.Final.insert(Ref);
244 OldTypeRefs.FwdDecls.clear();
245
246
247
248 for (const auto &Array : OldTypeRefs.Arrays)
249 Array.second->replaceAllUsesWith(resolveTypeRefArray(Array.first.get()));
250 OldTypeRefs.Arrays.clear();
251
252
253
254
255 for (const auto &Ref : OldTypeRefs.Unknown) {
256 if (DICompositeType *CT = OldTypeRefs.Final.lookup(Ref.first))
257 Ref.second->replaceAllUsesWith(CT);
258 else
259 Ref.second->replaceAllUsesWith(Ref.first);
260 }
261 OldTypeRefs.Unknown.clear();
262
263 if (UnresolvedNodes.empty())
264
265 return;
266
267
268 for (unsigned I : UnresolvedNodes) {
269 auto &MD = MetadataPtrs[I];
271 if ()
272 continue;
273
274 assert(->isTemporary() && "Unexpected forward reference");
275 N->resolveCycles();
276 }
277
278
279 UnresolvedNodes.clear();
280}
281
282void BitcodeReaderMetadataList::addTypeRef(MDString &UUID,
283 DICompositeType &CT) {
286 OldTypeRefs.FwdDecls.insert(std::make_pair(&UUID, &CT));
287 else
288 OldTypeRefs.Final.insert(std::make_pair(&UUID, &CT));
289}
290
291Metadata *BitcodeReaderMetadataList::upgradeTypeRef(Metadata *MaybeUUID) {
294 return MaybeUUID;
295
296 if (auto *CT = OldTypeRefs.Final.lookup(UUID))
297 return CT;
298
299 auto &Ref = OldTypeRefs.Unknown[UUID];
300 if ()
302 return Ref.get();
303}
304
305Metadata *BitcodeReaderMetadataList::upgradeTypeRefArray(Metadata *MaybeTuple) {
307 if (!Tuple || Tuple->isDistinct())
308 return MaybeTuple;
309
310
311 if (!Tuple->isTemporary())
312 return resolveTypeRefArray(Tuple);
313
314
315
316 OldTypeRefs.Arrays.emplace_back(
317 std::piecewise_construct, std::forward_as_tuple(Tuple),
319 return OldTypeRefs.Arrays.back().second.get();
320}
321
322Metadata *BitcodeReaderMetadataList::resolveTypeRefArray(Metadata *MaybeTuple) {
324 if (!Tuple || Tuple->isDistinct())
325 return MaybeTuple;
326
327
329 Ops.reserve(Tuple->getNumOperands());
330 for (Metadata *MD : Tuple->operands())
331 Ops.push_back(upgradeTypeRef(MD));
332
334}
335
336namespace {
337
338class PlaceholderQueue {
339
340
341 std::deque PHs;
342
343public:
344 ~PlaceholderQueue() {
346 "PlaceholderQueue hasn't been flushed before being destroyed");
347 }
348 bool empty() const { return PHs.empty(); }
349 DistinctMDOperandPlaceholder &getPlaceholderOp(unsigned ID);
350 void flush(BitcodeReaderMetadataList &MetadataList);
351
352
353
354 void getTemporaries(BitcodeReaderMetadataList &MetadataList,
355 DenseSet &Temporaries) {
356 for (auto &PH : PHs) {
357 auto ID = PH.getID();
358 auto *MD = MetadataList.lookup(ID);
359 if (!MD) {
361 continue;
362 }
364 if (N && N->isTemporary())
366 }
367 }
368};
369
370}
371
372DistinctMDOperandPlaceholder &PlaceholderQueue::getPlaceholderOp(unsigned ID) {
373 PHs.emplace_back(ID);
374 return PHs.back();
375}
376
377void PlaceholderQueue::flush(BitcodeReaderMetadataList &MetadataList) {
378 while (!PHs.empty()) {
379 auto *MD = MetadataList.lookup(PHs.front().getID());
380 assert(MD && "Flushing placeholder on unassigned MD");
381#ifndef NDEBUG
383 assert(MDN->isResolved() &&
384 "Flushing Placeholder while cycles aren't resolved");
385#endif
386 PHs.front().replaceUseWith(MD);
387 PHs.pop_front();
388 }
389}
390
395
397 BitcodeReaderMetadataList MetadataList;
403
404
405
406
408
409
410 std::vector MDStringRef;
411
412
413
414 MDString *lazyLoadOneMDString(unsigned Idx);
415
416
417 std::vector<uint64_t> GlobalMetadataBitPosIndex;
418
419
420
421
422 uint64_t GlobalDeclAttachmentPos = 0;
423
424#ifndef NDEBUG
425
426
427 unsigned NumGlobalDeclAttachSkipped = 0;
428 unsigned NumGlobalDeclAttachParsed = 0;
429#endif
430
431
433
434
435
436
438
439
440
441 void lazyLoadOneMetadata(unsigned Idx, PlaceholderQueue &Placeholders);
442
443
444
445 std::vector<std::pair<DICompileUnit *, Metadata *>> CUSubprograms;
446
447
448
450
451
453
454 bool StripTBAA = false;
455 bool HasSeenOldLoopTags = false;
456 bool NeedUpgradeToDIGlobalVariableExpression = false;
457 bool NeedDeclareExpressionUpgrade = false;
458
459
461
462
463 bool IsImporting = false;
464
466 PlaceholderQueue &Placeholders, StringRef Blob,
467 unsigned &NextMetadataNo);
473
474 void resolveForwardRefsAndPlaceholders(PlaceholderQueue &Placeholders);
475
476
477 void upgradeCUSubprograms() {
478 for (auto CU_SP : CUSubprograms)
480 for (auto &Op : SPs->operands())
482 SP->replaceUnit(CU_SP.first);
483 CUSubprograms.clear();
484 }
485
486
487 void upgradeCUVariables() {
488 if (!NeedUpgradeToDIGlobalVariableExpression)
489 return;
490
491
492 if (NamedMDNode *CUNodes = TheModule.getNamedMetadata("llvm.dbg.cu"))
493 for (unsigned I = 0, E = CUNodes->getNumOperands(); I != E; ++I) {
496 for (unsigned I = 0; I < GVs->getNumOperands(); I++)
497 if (auto *GV =
501 GVs->replaceOperandWith(I, DGVE);
502 }
503 }
504
505
506 for (auto &GV : TheModule.globals()) {
508 GV.getMetadata(LLVMContext::MD_dbg, MDs);
509 GV.eraseMetadata(LLVMContext::MD_dbg);
510 for (auto *MD : MDs)
514 GV.addMetadata(LLVMContext::MD_dbg, *DGVE);
515 } else
516 GV.addMetadata(LLVMContext::MD_dbg, *MD);
517 }
518 }
519
521 if (!S)
522 return nullptr;
523 if (auto *SP = ParentSubprogram[S]) {
524 return SP;
525 }
526
531 if (!Visited.insert(S).second)
532 break;
533 }
534
535 return ParentSubprogram[InitialScope] =
537 }
538
539
540
541 void upgradeCULocals() {
542 if (NamedMDNode *CUNodes = TheModule.getNamedMetadata("llvm.dbg.cu")) {
543 for (MDNode *N : CUNodes->operands()) {
545 if ()
546 continue;
547
548 if (CU->getRawImportedEntities()) {
549
551 for (Metadata *Op : CU->getImportedEntities()->operands()) {
554 EntitiesToRemove.insert(IE);
555 }
556 }
557
558 if (!EntitiesToRemove.empty()) {
559
561 for (Metadata *Op : CU->getImportedEntities()->operands()) {
564 }
565 }
566
567
568 std::map<DISubprogram *, SmallVector<Metadata *>> SPToEntities;
569 for (auto *I : EntitiesToRemove) {
571 if (auto *SP = findEnclosingSubprogram(
573 SPToEntities[SP].push_back(Entity);
574 }
575 }
576
577
578 for (auto I = SPToEntities.begin(); I != SPToEntities.end(); ++I) {
579 auto *SP = I->first;
580 auto RetainedNodes = SP->getRetainedNodes();
582 RetainedNodes.end());
584 SP->replaceRetainedNodes(MDNode::get(Context, MDs));
585 }
586
587
588 CU->replaceImportedEntities(MDTuple::get(Context, NewImports));
589 }
590 }
591 }
592 }
593
594 ParentSubprogram.clear();
595 }
596
597
598
599 void upgradeDeclareExpressions(Function &F) {
600 if (!NeedDeclareExpressionUpgrade)
601 return;
602
603 auto UpdateDeclareIfNeeded = [&](auto *Declare) {
604 auto *DIExpr = Declare->getExpression();
605 if (!DIExpr || !DIExpr->startsWithDeref() ||
607 return;
609 Ops.append(std::next(DIExpr->elements_begin()), DIExpr->elements_end());
611 };
612
613 for (auto &BB : F)
614 for (auto &I : BB) {
616 if (DVR.isDbgDeclare())
617 UpdateDeclareIfNeeded(&DVR);
618 }
620 UpdateDeclareIfNeeded(DDI);
621 }
622 }
623
624
629 switch (FromVersion) {
630 default:
631 return error("Invalid record");
632 case 0:
633 if (N >= 3 && Expr[N - 3] == dwarf::DW_OP_bit_piece)
635 [[fallthrough]];
636 case 1:
637
638 if (N && Expr[0] == dwarf::DW_OP_deref) {
639 auto End = Expr.end();
640 if (Expr.size() >= 3 &&
642 End = std::prev(End, 3);
643 std::move(std::next(Expr.begin()), End, Expr.begin());
644 *std::prev(End) = dwarf::DW_OP_deref;
645 }
646 NeedDeclareExpressionUpgrade = true;
647 [[fallthrough]];
648 case 2: {
649
650
652 while (!SubExpr.empty()) {
653
654
655
656 size_t HistoricSize;
657 switch (SubExpr.front()) {
658 default:
659 HistoricSize = 1;
660 break;
661 case dwarf::DW_OP_constu:
662 case dwarf::DW_OP_minus:
663 case dwarf::DW_OP_plus:
664 HistoricSize = 2;
665 break;
667 HistoricSize = 3;
668 break;
669 }
670
671
672
673 HistoricSize = std::min(SubExpr.size(), HistoricSize);
675
676 switch (SubExpr.front()) {
677 case dwarf::DW_OP_plus:
678 Buffer.push_back(dwarf::DW_OP_plus_uconst);
679 Buffer.append(Args.begin(), Args.end());
680 break;
681 case dwarf::DW_OP_minus:
682 Buffer.push_back(dwarf::DW_OP_constu);
683 Buffer.append(Args.begin(), Args.end());
684 Buffer.push_back(dwarf::DW_OP_minus);
685 break;
686 default:
687 Buffer.push_back(*SubExpr.begin());
688 Buffer.append(Args.begin(), Args.end());
689 break;
690 }
691
692
693 SubExpr = SubExpr.slice(HistoricSize);
694 }
696 [[fallthrough]];
697 }
698 case 3:
699
700 break;
701 }
702
704 }
705
706 void upgradeDebugInfo(bool ModuleLevel) {
707 upgradeCUSubprograms();
708 upgradeCUVariables();
709 if (ModuleLevel)
710 upgradeCULocals();
711 }
712
713 void callMDTypeCallback(Metadata **Val, unsigned TypeID);
714
715public:
719 : MetadataList(TheModule.getContext(), Stream.SizeInBytes()),
720 ValueList(ValueList), Stream(Stream), Context(TheModule.getContext()),
721 TheModule(TheModule), Callbacks(std::move(Callbacks)),
722 IsImporting(IsImporting) {}
723
725
726 bool hasFwdRefs() const { return MetadataList.hasFwdRefs(); }
727
729 if (ID < MDStringRef.size())
730 return lazyLoadOneMDString(ID);
731 if (auto *MD = MetadataList.lookup(ID))
732 return MD;
733
734
735 if (ID < (MDStringRef.size() + GlobalMetadataBitPosIndex.size())) {
736 PlaceholderQueue Placeholders;
737 lazyLoadOneMetadata(ID, Placeholders);
738 resolveForwardRefsAndPlaceholders(Placeholders);
739 return MetadataList.lookup(ID);
740 }
741 return MetadataList.getMetadataFwdRef(ID);
742 }
743
745 return FunctionsWithSPs.lookup(F);
746 }
747
749
752
754
757
758 unsigned size() const { return MetadataList.size(); }
759 void shrinkTo(unsigned N) { MetadataList.shrinkTo(N); }
761};
762
764MetadataLoader::MetadataLoaderImpl::lazyLoadModuleMetadataBlock() {
765 IndexCursor = Stream;
767 GlobalDeclAttachmentPos = 0;
768
769 while (true) {
770 uint64_t SavedPos = IndexCursor.GetCurrentBitNo();
773 IndexCursor
775 .moveInto(Entry))
776 return std::move(E);
777
778 switch (Entry.Kind) {
781 return error("Malformed block");
783 return true;
784 }
786
787 ++NumMDRecordLoaded;
788 uint64_t CurrentPos = IndexCursor.GetCurrentBitNo();
789 unsigned Code;
790 if (Error E = IndexCursor.skipRecord(Entry.ID).moveInto(Code))
791 return std::move(E);
792 switch (Code) {
794
795 if (Error Err = IndexCursor.JumpToBit(CurrentPos))
796 return std::move(Err);
800 IndexCursor.readRecord(Entry.ID, Record, &Blob))
801 ;
802 else
803 return MaybeRecord.takeError();
804 unsigned NumStrings = Record[0];
805 MDStringRef.reserve(NumStrings);
806 auto IndexNextMDString = [&](StringRef Str) {
807 MDStringRef.push_back(Str);
808 };
809 if (auto Err = parseMetadataStrings(Record, Blob, IndexNextMDString))
810 return std::move(Err);
811 break;
812 }
814
815
816 if (Error Err = IndexCursor.JumpToBit(CurrentPos))
817 return std::move(Err);
819 if (Expected MaybeRecord =
820 IndexCursor.readRecord(Entry.ID, Record))
821 ;
822 else
823 return MaybeRecord.takeError();
824 if (Record.size() != 2)
825 return error("Invalid record");
826 auto Offset = Record[0] + (Record[1] << 32);
827 auto BeginPos = IndexCursor.GetCurrentBitNo();
828 if (Error Err = IndexCursor.JumpToBit(BeginPos + Offset))
829 return std::move(Err);
830 Expected MaybeEntry =
831 IndexCursor.advanceSkippingSubblocks(
833 if (!MaybeEntry)
837 "Corrupted bitcode: Expected `Record` when trying to find the "
838 "Metadata index");
840 if (Expected MaybeCode =
841 IndexCursor.readRecord(Entry.ID, Record))
843 "Corrupted bitcode: Expected `METADATA_INDEX` when trying to "
844 "find the Metadata index");
845 else
846 return MaybeCode.takeError();
847
848 auto CurrentValue = BeginPos;
849 GlobalMetadataBitPosIndex.reserve(Record.size());
850 for (auto &Elt : Record) {
851 CurrentValue += Elt;
852 GlobalMetadataBitPosIndex.push_back(CurrentValue);
853 }
854 break;
855 }
857
858
859 return error("Corrupted Metadata block");
861
862 if (Error Err = IndexCursor.JumpToBit(CurrentPos))
863 return std::move(Err);
864 Record.clear();
865
866 unsigned Code;
867 if (Expected MaybeCode =
868 IndexCursor.readRecord(Entry.ID, Record)) {
869 Code = MaybeCode.get();
871 } else
872 return MaybeCode.takeError();
873
874
875 SmallString<8> Name(Record.begin(), Record.end());
876 if (Expected MaybeCode = IndexCursor.ReadCode())
877 Code = MaybeCode.get();
878 else
879 return MaybeCode.takeError();
880
881
882
883 Record.clear();
884 if (Expected MaybeNextBitCode =
885 IndexCursor.readRecord(Code, Record))
887 else
888 return MaybeNextBitCode.takeError();
889
890
891 unsigned Size = Record.size();
892 NamedMDNode *NMD = TheModule.getOrInsertNamedMetadata(Name);
893 for (unsigned i = 0; i != Size; ++i) {
894
895
896
897
898 MDNode *MD = MetadataList.getMDNodeFwdRefOrNull(Record[i]);
899 assert(MD && "Invalid metadata: expect fwd ref to MDNode");
901 }
902 break;
903 }
905 if (!GlobalDeclAttachmentPos)
906 GlobalDeclAttachmentPos = SavedPos;
907#ifndef NDEBUG
908 NumGlobalDeclAttachSkipped++;
909#endif
910 break;
911 }
949
950
951 MDStringRef.clear();
952 GlobalMetadataBitPosIndex.clear();
953 return false;
954 }
955 break;
956 }
957 }
958 }
959}
960
961
962
963
964
965
966Expected MetadataLoader::MetadataLoaderImpl::loadGlobalDeclAttachments() {
967
968 if (!GlobalDeclAttachmentPos)
969 return true;
970
971
972 BitstreamCursor TempCursor = Stream;
973 SmallVector<uint64_t, 64> Record;
974
975
976 if (Error Err = TempCursor.JumpToBit(GlobalDeclAttachmentPos))
977 return std::move(Err);
978 while (true) {
979 BitstreamEntry Entry;
981 TempCursor
983 .moveInto(Entry))
984 return std::move(E);
985
986 switch (Entry.Kind) {
989 return error("Malformed block");
991
992 assert(NumGlobalDeclAttachSkipped == NumGlobalDeclAttachParsed);
993 return true;
995 break;
996 }
998 Expected MaybeCode = TempCursor.skipRecord(Entry.ID);
999 if (!MaybeCode)
1002
1003
1004 assert(NumGlobalDeclAttachSkipped == NumGlobalDeclAttachParsed);
1005 return true;
1006 }
1007#ifndef NDEBUG
1008 NumGlobalDeclAttachParsed++;
1009#endif
1010
1011
1013 return std::move(Err);
1015 if (Expected MaybeRecord =
1017 ;
1018 else
1019 return MaybeRecord.takeError();
1020 if (Record.size() % 2 == 0)
1021 return error("Invalid record");
1022 unsigned ValueID = Record[0];
1023 if (ValueID >= ValueList.size())
1024 return error("Invalid record");
1026
1027
1028
1030 if (Error Err = parseGlobalObjectAttachment(
1031 *GO, ArrayRef<uint64_t>(Record).slice(1)))
1032 return std::move(Err);
1034 return std::move(Err);
1035 }
1036 }
1037}
1038
1039void MetadataLoader::MetadataLoaderImpl::callMDTypeCallback(Metadata **Val,
1041 if (Callbacks.MDType) {
1042 (*Callbacks.MDType)(Val, TypeID, Callbacks.GetTypeByID,
1043 Callbacks.GetContainedTypeID);
1044 }
1045}
1046
1047
1048
1051 if (!ModuleLevel && MetadataList.hasFwdRefs())
1052 return error("Invalid metadata: fwd refs into function blocks");
1053
1054
1055
1056 auto EntryPos = Stream.GetCurrentBitNo();
1057
1059 return Err;
1060
1062 PlaceholderQueue Placeholders;
1063
1064
1065
1066 if (ModuleLevel && IsImporting && MetadataList.empty() &&
1068 auto SuccessOrErr = lazyLoadModuleMetadataBlock();
1069 if (!SuccessOrErr)
1070 return SuccessOrErr.takeError();
1071 if (SuccessOrErr.get()) {
1072
1073
1074 MetadataList.resize(MDStringRef.size() +
1075 GlobalMetadataBitPosIndex.size());
1076
1077
1078
1079
1080 SuccessOrErr = loadGlobalDeclAttachments();
1081 if (!SuccessOrErr)
1082 return SuccessOrErr.takeError();
1083 assert(SuccessOrErr.get());
1084
1085
1086
1087 resolveForwardRefsAndPlaceholders(Placeholders);
1088 upgradeDebugInfo(ModuleLevel);
1089
1090
1091 Stream.ReadBlockEnd();
1092 if (Error Err = IndexCursor.JumpToBit(EntryPos))
1093 return Err;
1094 if (Error Err = Stream.SkipBlock()) {
1095
1096
1099 }
1101 }
1102
1103 }
1104
1105 unsigned NextMetadataNo = MetadataList.size();
1106
1107
1108 while (true) {
1110 if (Error E = Stream.advanceSkippingSubblocks().moveInto(Entry))
1111 return E;
1112
1113 switch (Entry.Kind) {
1116 return error("Malformed block");
1118 resolveForwardRefsAndPlaceholders(Placeholders);
1119 upgradeDebugInfo(ModuleLevel);
1122
1123 break;
1124 }
1125
1126
1129 ++NumMDRecordLoaded;
1131 Stream.readRecord(Entry.ID, Record, &Blob)) {
1132 if (Error Err = parseOneMetadata(Record, MaybeCode.get(), Placeholders,
1133 Blob, NextMetadataNo))
1134 return Err;
1135 } else
1137 }
1138}
1139
1140MDString *MetadataLoader::MetadataLoaderImpl::lazyLoadOneMDString(unsigned ID) {
1141 ++NumMDStringLoaded;
1142 if (Metadata *MD = MetadataList.lookup(ID))
1145 MetadataList.assignValue(MDS, ID);
1146 return MDS;
1147}
1148
1149void MetadataLoader::MetadataLoaderImpl::lazyLoadOneMetadata(
1150 unsigned ID, PlaceholderQueue &Placeholders) {
1151 assert(ID < (MDStringRef.size()) + GlobalMetadataBitPosIndex.size());
1152 assert(ID >= MDStringRef.size() && "Unexpected lazy-loading of MDString");
1153
1154 if (auto *MD = MetadataList.lookup(ID)) {
1156
1157
1158 if ( ||
->isTemporary())
1159 return;
1160 }
1163 if (Error Err = IndexCursor.JumpToBit(
1164 GlobalMetadataBitPosIndex[ID - MDStringRef.size()]))
1168 if (Error E = IndexCursor.advanceSkippingSubblocks().moveInto(Entry))
1169
1170 report_fatal_error("lazyLoadOneMetadata failed advanceSkippingSubblocks: " +
1172 ++NumMDRecordLoaded;
1174 IndexCursor.readRecord(Entry.ID, Record, &Blob)) {
1176 parseOneMetadata(Record, MaybeCode.get(), Placeholders, Blob, ID))
1179 } else
1182}
1183
1184
1185
1186void MetadataLoader::MetadataLoaderImpl::resolveForwardRefsAndPlaceholders(
1187 PlaceholderQueue &Placeholders) {
1188 DenseSet Temporaries;
1189 while (true) {
1190
1191 Placeholders.getTemporaries(MetadataList, Temporaries);
1192
1193
1194 if (Temporaries.empty() && !MetadataList.hasFwdRefs())
1195 break;
1196
1197
1198
1199 for (auto ID : Temporaries)
1200 lazyLoadOneMetadata(ID, Placeholders);
1201 Temporaries.clear();
1202
1203
1204
1205 while (MetadataList.hasFwdRefs())
1206 lazyLoadOneMetadata(MetadataList.getNextFwdRef(), Placeholders);
1207 }
1208
1209
1210
1211 MetadataList.tryToResolveCycles();
1212
1213
1214
1215 Placeholders.flush(MetadataList);
1216}
1217
1219 Type *Ty, unsigned TyID) {
1221 nullptr);
1222 if (V)
1223 return V;
1224
1225
1226
1227
1228
1229
1230
1231 if (Idx < ValueList.size() && ValueList[Idx] &&
1232 ValueList[Idx]->getType() == Ty)
1234
1235 return nullptr;
1236}
1237
1238Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
1239 SmallVectorImpl<uint64_t> &Record, unsigned Code,
1240 PlaceholderQueue &Placeholders, StringRef Blob, unsigned &NextMetadataNo) {
1241
1242 bool IsDistinct = false;
1243 auto getMD = [&](unsigned ID) -> Metadata * {
1244 if (ID < MDStringRef.size())
1245 return lazyLoadOneMDString(ID);
1246 if (!IsDistinct) {
1247 if (auto *MD = MetadataList.lookup(ID))
1248 return MD;
1249
1250
1251 if (ID < (MDStringRef.size() + GlobalMetadataBitPosIndex.size())) {
1252
1253
1254
1255 MetadataList.getMetadataFwdRef(NextMetadataNo);
1256 lazyLoadOneMetadata(ID, Placeholders);
1257 return MetadataList.lookup(ID);
1258 }
1259
1260 return MetadataList.getMetadataFwdRef(ID);
1261 }
1262 if (auto *MD = MetadataList.getMetadataIfResolved(ID))
1263 return MD;
1264 return &Placeholders.getPlaceholderOp(ID);
1265 };
1266 auto getMDOrNull = [&](unsigned ID) -> Metadata * {
1267 if (ID)
1268 return getMD(ID - 1);
1269 return nullptr;
1270 };
1271 auto getMDOrNullWithoutPlaceholders = [&](unsigned ID) -> Metadata * {
1272 if (ID)
1273 return MetadataList.getMetadataFwdRef(ID - 1);
1274 return nullptr;
1275 };
1276 auto getMDString = [&](unsigned ID) -> MDString * {
1277
1278
1279 auto MDS = getMDOrNull(ID);
1281 };
1282
1283
1284 auto getDITypeRefOrNull = [&](unsigned ID) {
1285 return MetadataList.upgradeTypeRef(getMDOrNull(ID));
1286 };
1287
1288 auto getMetadataOrConstant = [&](bool IsMetadata,
1290 if (IsMetadata)
1291 return getMDOrNull(Entry);
1293 ConstantInt::get(Type::getInt64Ty(Context), Entry));
1294 };
1295
1296#define GET_OR_DISTINCT(CLASS, ARGS) \
1297 (IsDistinct ? CLASS::getDistinct ARGS : CLASS::get ARGS)
1298
1299 switch (Code) {
1300 default:
1301 break;
1303
1304 SmallString<8> Name(Record.begin(), Record.end());
1306 if (Error E = Stream.ReadCode().moveInto(Code))
1307 return E;
1308
1309 ++NumMDRecordLoaded;
1310 if (Expected MaybeNextBitCode = Stream.readRecord(Code, Record)) {
1312 return error("METADATA_NAME not followed by METADATA_NAMED_NODE");
1313 } else
1314 return MaybeNextBitCode.takeError();
1315
1316
1317 unsigned Size = Record.size();
1318 NamedMDNode *NMD = TheModule.getOrInsertNamedMetadata(Name);
1319 for (unsigned i = 0; i != Size; ++i) {
1320 MDNode *MD = MetadataList.getMDNodeFwdRefOrNull(Record[i]);
1321 if (!MD)
1322 return error("Invalid named metadata: expect fwd ref to MDNode");
1324 }
1325 break;
1326 }
1328
1329
1330
1331 if (Record.size() % 2 == 1)
1332 return error("Invalid record");
1333
1334
1335
1336 auto dropRecord = [&] {
1338 NextMetadataNo++;
1339 };
1340 if (Record.size() != 2) {
1341 dropRecord();
1342 break;
1343 }
1344
1345 unsigned TyID = Record[0];
1346 Type *Ty = Callbacks.GetTypeByID(TyID);
1348 dropRecord();
1349 break;
1350 }
1351
1352 Value *V = ValueList.getValueFwdRef(Record[1], Ty, TyID,
1353 nullptr);
1354 if (!V)
1355 return error("Invalid value reference from old fn metadata");
1356
1358 NextMetadataNo++;
1359 break;
1360 }
1362
1363 if (Record.size() % 2 == 1)
1364 return error("Invalid record");
1365
1366 unsigned Size = Record.size();
1368 for (unsigned i = 0; i != Size; i += 2) {
1369 unsigned TyID = Record[i];
1370 Type *Ty = Callbacks.GetTypeByID(TyID);
1371 if (!Ty)
1372 return error("Invalid record");
1374 Elts.push_back(getMD(Record[i + 1]));
1377 if (!V)
1378 return error("Invalid value reference from old metadata");
1381 "Expected non-function-local metadata");
1382 callMDTypeCallback(&MD, TyID);
1384 } else
1386 }
1387 MetadataList.assignValue(MDNode::get(Context, Elts), NextMetadataNo);
1388 NextMetadataNo++;
1389 break;
1390 }
1392 if (Record.size() != 2)
1393 return error("Invalid record");
1394
1395 unsigned TyID = Record[0];
1396 Type *Ty = Callbacks.GetTypeByID(TyID);
1398 return error("Invalid record");
1399
1401 if (!V)
1402 return error("Invalid value reference from metadata");
1403
1405 callMDTypeCallback(&MD, TyID);
1406 MetadataList.assignValue(MD, NextMetadataNo);
1407 NextMetadataNo++;
1408 break;
1409 }
1411 IsDistinct = true;
1412 [[fallthrough]];
1416 for (unsigned ID : Record)
1420 NextMetadataNo);
1421 NextMetadataNo++;
1422 break;
1423 }
1425
1426 if (Record.size() != 5 && Record.size() != 6 && Record.size() != 8)
1427 return error("Invalid record");
1428
1429 IsDistinct = Record[0];
1430 unsigned Line = Record[1];
1431 unsigned Column = Record[2];
1433 Metadata *InlinedAt = getMDOrNull(Record[4]);
1434 bool ImplicitCode = Record.size() >= 6 && Record[5];
1435 uint64_t AtomGroup = Record.size() == 8 ? Record[6] : 0;
1436 uint8_t AtomRank = Record.size() == 8 ? Record[7] : 0;
1437 MetadataList.assignValue(
1439 ImplicitCode, AtomGroup, AtomRank)),
1440 NextMetadataNo);
1441 NextMetadataNo++;
1442 break;
1443 }
1445 if (Record.size() < 4)
1446 return error("Invalid record");
1447
1448 IsDistinct = Record[0];
1449 unsigned Tag = Record[1];
1450 unsigned Version = Record[2];
1451
1452 if (Tag >= 1u << 16 || Version != 0)
1453 return error("Invalid record");
1454
1455 auto *Header = getMDString(Record[3]);
1457 for (unsigned I = 4, E = Record.size(); I != E; ++I)
1458 DwarfOps.push_back(getMDOrNull(Record[I]));
1459 MetadataList.assignValue(
1461 NextMetadataNo);
1462 NextMetadataNo++;
1463 break;
1464 }
1467
1468
1469
1470
1471
1472
1473
1474
1475 switch (Record[0] >> 1) {
1476 case 0:
1479 break;
1480 case 1:
1483 break;
1484 case 2:
1486 DISubrange, (Context, getMDOrNull(Record[1]), getMDOrNull(Record[2]),
1487 getMDOrNull(Record[3]), getMDOrNull(Record[4])));
1488 break;
1489 default:
1490 return error("Invalid record: Unsupported version of DISubrange");
1491 }
1492
1493 MetadataList.assignValue(Val, NextMetadataNo);
1494 IsDistinct = Record[0] & 1;
1495 NextMetadataNo++;
1496 break;
1497 }
1501 (Context, getMDOrNull(Record[1]),
1502 getMDOrNull(Record[2]), getMDOrNull(Record[3]),
1503 getMDOrNull(Record[4])));
1504
1505 MetadataList.assignValue(Val, NextMetadataNo);
1506 IsDistinct = Record[0] & 1;
1507 NextMetadataNo++;
1508 break;
1509 }
1511 if (Record.size() < 3)
1512 return error("Invalid record");
1513
1514 IsDistinct = Record[0] & 1;
1515 bool IsUnsigned = Record[0] & 2;
1516 bool IsBigInt = Record[0] & 4;
1518
1519 if (IsBigInt) {
1520 const uint64_t BitWidth = Record[1];
1521 const size_t NumWords = Record.size() - 3;
1523 } else
1525
1526 MetadataList.assignValue(
1528 (Context, Value, IsUnsigned, getMDString(Record[2]))),
1529 NextMetadataNo);
1530 NextMetadataNo++;
1531 break;
1532 }
1534 if (Record.size() < 6 || Record.size() > 9)
1535 return error("Invalid record");
1536
1537 IsDistinct = Record[0] & 1;
1538 bool SizeIsMetadata = Record[0] & 2;
1541 : DINode::FlagZero;
1542 uint32_t NumExtraInhabitants = (Record.size() > 7) ? Record[7] : 0;
1543 uint32_t DataSizeInBits = (Record.size() > 8) ? Record[8] : 0;
1544 Metadata *SizeInBits = getMetadataOrConstant(SizeIsMetadata, Record[3]);
1545 MetadataList.assignValue(
1547 (Context, Record[1], getMDString(Record[2]), SizeInBits,
1548 Record[4], Record[5], NumExtraInhabitants,
1549 DataSizeInBits, Flags)),
1550 NextMetadataNo);
1551 NextMetadataNo++;
1552 break;
1553 }
1555 if (Record.size() < 11)
1556 return error("Invalid record");
1557
1558 IsDistinct = Record[0] & 1;
1559 bool SizeIsMetadata = Record[0] & 2;
1561
1562 Metadata *SizeInBits = getMetadataOrConstant(SizeIsMetadata, Record[3]);
1563
1565
1566 auto ReadWideInt = [&]() {
1568 unsigned NumWords = Encoded >> 32;
1573 };
1574
1575 APInt Numerator = ReadWideInt();
1576 APInt Denominator = ReadWideInt();
1577
1578 if (Offset != Record.size())
1579 return error("Invalid record");
1580
1581 MetadataList.assignValue(
1583 (Context, Record[1], getMDString(Record[2]), SizeInBits,
1584 Record[4], Record[5], Flags, Record[7], Record[8],
1585 Numerator, Denominator)),
1586 NextMetadataNo);
1587 NextMetadataNo++;
1588 break;
1589 }
1591 if (Record.size() > 9 || Record.size() < 8)
1592 return error("Invalid record");
1593
1594 IsDistinct = Record[0] & 1;
1595 bool SizeIsMetadata = Record[0] & 2;
1596 bool SizeIs8 = Record.size() == 8;
1597
1598
1599 Metadata *StringLocationExp = SizeIs8 ? nullptr : getMDOrNull(Record[5]);
1600 unsigned Offset = SizeIs8 ? 5 : 6;
1602 getMetadataOrConstant(SizeIsMetadata, Record[Offset]);
1603
1604 MetadataList.assignValue(
1606 (Context, Record[1], getMDString(Record[2]),
1607 getMDOrNull(Record[3]), getMDOrNull(Record[4]),
1608 StringLocationExp, SizeInBits, Record[Offset + 1],
1609 Record[Offset + 2])),
1610 NextMetadataNo);
1611 NextMetadataNo++;
1612 break;
1613 }
1615 if (Record.size() < 12 || Record.size() > 15)
1616 return error("Invalid record");
1617
1618
1619
1620 std::optional DWARFAddressSpace;
1621 if (Record.size() > 12 && Record[12])
1622 DWARFAddressSpace = Record[12] - 1;
1623
1624 Metadata *Annotations = nullptr;
1625 std::optionalDIDerivedType::PtrAuthData PtrAuthData;
1626
1627
1628
1629
1630 if (Record.size() > 14) {
1631 if (Record[13])
1632 Annotations = getMDOrNull(Record[13]);
1633 if (Record[14])
1634 PtrAuthData.emplace(Record[14]);
1635 }
1636
1637 IsDistinct = Record[0] & 1;
1638 bool SizeIsMetadata = Record[0] & 2;
1640
1641 Metadata *SizeInBits = getMetadataOrConstant(SizeIsMetadata, Record[7]);
1642 Metadata *OffsetInBits = getMetadataOrConstant(SizeIsMetadata, Record[9]);
1643
1644 MetadataList.assignValue(
1646 (Context, Record[1], getMDString(Record[2]),
1647 getMDOrNull(Record[3]), Record[4],
1648 getDITypeRefOrNull(Record[5]),
1649 getDITypeRefOrNull(Record[6]), SizeInBits, Record[8],
1650 OffsetInBits, DWARFAddressSpace, PtrAuthData, Flags,
1651 getDITypeRefOrNull(Record[11]), Annotations)),
1652 NextMetadataNo);
1653 NextMetadataNo++;
1654 break;
1655 }
1657 if (Record.size() != 13)
1658 return error("Invalid record");
1659
1660 IsDistinct = Record[0] & 1;
1661 bool SizeIsMetadata = Record[0] & 2;
1663
1664 Metadata *SizeInBits = getMetadataOrConstant(SizeIsMetadata, Record[5]);
1665
1666 MetadataList.assignValue(
1668 (Context, getMDString(Record[1]),
1669 getMDOrNull(Record[2]), Record[3],
1670 getMDOrNull(Record[4]), SizeInBits, Record[6], Flags,
1671 getDITypeRefOrNull(Record[8]), getMDOrNull(Record[9]),
1672 getMDOrNull(Record[10]), getMDOrNull(Record[11]),
1673 getMDOrNull(Record[12]))),
1674 NextMetadataNo);
1675 NextMetadataNo++;
1676 break;
1677 }
1679 if (Record.size() < 16 || Record.size() > 26)
1680 return error("Invalid record");
1681
1682
1683
1684 IsDistinct = Record[0] & 0x1;
1685 bool IsNotUsedInTypeRef = Record[0] & 2;
1686 bool SizeIsMetadata = Record[0] & 4;
1687 unsigned Tag = Record[1];
1688 MDString *Name = getMDString(Record[2]);
1690 unsigned Line = Record[4];
1691 Metadata *Scope = getDITypeRefOrNull(Record[5]);
1693 if (Record[8] > (uint64_t)std::numeric_limits<uint32_t>::max())
1694 return error("Alignment value is too large");
1695 uint32_t AlignInBits = Record[8];
1696 Metadata *OffsetInBits = nullptr;
1697 uint32_t NumExtraInhabitants = (Record.size() > 22) ? Record[22] : 0;
1700 unsigned RuntimeLang = Record[12];
1701 std::optional<uint32_t> EnumKind;
1702
1703 Metadata *VTableHolder = nullptr;
1704 Metadata *TemplateParams = nullptr;
1706 Metadata *DataLocation = nullptr;
1707 Metadata *Associated = nullptr;
1708 Metadata *Allocated = nullptr;
1710 Metadata *Annotations = nullptr;
1711 Metadata *Specification = nullptr;
1712 Metadata *BitStride = nullptr;
1713 auto *Identifier = getMDString(Record[15]);
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1729 (Tag == dwarf::DW_TAG_enumeration_type ||
1730 Tag == dwarf::DW_TAG_class_type ||
1731 Tag == dwarf::DW_TAG_structure_type ||
1732 Tag == dwarf::DW_TAG_union_type)) {
1733 Flags = Flags | DINode::FlagFwdDecl;
1734
1735
1736
1737
1738 StringRef NameStr = Name->getString();
1740 TemplateParams = getMDOrNull(Record[14]);
1741 } else {
1742 BaseType = getDITypeRefOrNull(Record[6]);
1743
1744 OffsetInBits = getMetadataOrConstant(SizeIsMetadata, Record[9]);
1745
1746 Elements = getMDOrNull(Record[11]);
1747 VTableHolder = getDITypeRefOrNull(Record[13]);
1748 TemplateParams = getMDOrNull(Record[14]);
1749 if (Record.size() > 16)
1751 if (Record.size() > 17)
1752 DataLocation = getMDOrNull(Record[17]);
1753 if (Record.size() > 19) {
1754 Associated = getMDOrNull(Record[18]);
1755 Allocated = getMDOrNull(Record[19]);
1756 }
1757 if (Record.size() > 20) {
1758 Rank = getMDOrNull(Record[20]);
1759 }
1760 if (Record.size() > 21) {
1761 Annotations = getMDOrNull(Record[21]);
1762 }
1763 if (Record.size() > 23) {
1764 Specification = getMDOrNull(Record[23]);
1765 }
1766 if (Record.size() > 25)
1767 BitStride = getMDOrNull(Record[25]);
1768 }
1769
1771 EnumKind = Record[24];
1772
1773 Metadata *SizeInBits = getMetadataOrConstant(SizeIsMetadata, Record[7]);
1774
1775 DICompositeType *CT = nullptr;
1776 if (Identifier)
1779 SizeInBits, AlignInBits, OffsetInBits, Specification,
1780 NumExtraInhabitants, Flags, Elements, RuntimeLang, EnumKind,
1781 VTableHolder, TemplateParams, Discriminator, DataLocation, Associated,
1782 Allocated, Rank, Annotations, BitStride);
1783
1784
1785 if (!CT)
1787 DICompositeType,
1789 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, EnumKind,
1790 VTableHolder, TemplateParams, Identifier, Discriminator,
1791 DataLocation, Associated, Allocated, Rank, Annotations,
1792 Specification, NumExtraInhabitants, BitStride));
1793 if (!IsNotUsedInTypeRef && Identifier)
1795
1796 MetadataList.assignValue(CT, NextMetadataNo);
1797 NextMetadataNo++;
1798 break;
1799 }
1801 if (Record.size() < 3 || Record.size() > 4)
1802 return error("Invalid record");
1803 bool IsOldTypeRefArray = Record[0] < 2;
1804 unsigned CC = (Record.size() > 3) ? Record[3] : 0;
1805
1806 IsDistinct = Record[0] & 0x1;
1810 Types = MetadataList.upgradeTypeRefArray(Types);
1811
1812 MetadataList.assignValue(
1814 NextMetadataNo);
1815 NextMetadataNo++;
1816 break;
1817 }
1818
1820 if (Record.size() < 5 || Record.size() > 9)
1821 return error("Invalid record");
1822
1823 unsigned Offset = Record.size() >= 8 ? 2 : 1;
1824 IsDistinct = Record[0];
1825 MetadataList.assignValue(
1827 DIModule,
1828 (Context, Record.size() >= 8 ? getMDOrNull(Record[1]) : nullptr,
1829 getMDOrNull(Record[0 + Offset]), getMDString(Record[1 + Offset]),
1830 getMDString(Record[2 + Offset]), getMDString(Record[3 + Offset]),
1831 getMDString(Record[4 + Offset]),
1832 Record.size() <= 7 ? 0 : Record[7],
1833 Record.size() <= 8 ? false : Record[8])),
1834 NextMetadataNo);
1835 NextMetadataNo++;
1836 break;
1837 }
1838
1840 if (Record.size() != 3 && Record.size() != 5 && Record.size() != 6)
1841 return error("Invalid record");
1842
1843 IsDistinct = Record[0];
1844 std::optional<DIFile::ChecksumInfo<MDString *>> Checksum;
1845
1846
1847
1848
1849
1850 if (Record.size() > 4 && Record[3] && Record[4])
1852 getMDString(Record[4]));
1853 MetadataList.assignValue(
1855 (Context, getMDString(Record[1]),
1856 getMDString(Record[2]), Checksum,
1857 Record.size() > 5 ? getMDString(Record[5]) : nullptr)),
1858 NextMetadataNo);
1859 NextMetadataNo++;
1860 break;
1861 }
1863 if (Record.size() < 14 || Record.size() > 23)
1864 return error("Invalid record");
1865
1866
1867
1868 IsDistinct = true;
1869
1870 const auto LangVersionMask = (uint64_t(1) << 63);
1871 const bool HasVersionedLanguage = Record[1] & LangVersionMask;
1872 const uint32_t LanguageVersion = Record.size() > 22 ? Record[22] : 0;
1873
1874 auto *CU = DICompileUnit::getDistinct(
1876 HasVersionedLanguage
1877 ? DISourceLanguageName(Record[1] & ~LangVersionMask,
1878 LanguageVersion)
1879 : DISourceLanguageName(Record[1]),
1880 getMDOrNull(Record[2]), getMDString(Record[3]), Record[4],
1881 getMDString(Record[5]), Record[6], getMDString(Record[7]), Record[8],
1882 getMDOrNull(Record[9]), getMDOrNull(Record[10]),
1883 getMDOrNull(Record[12]), getMDOrNull(Record[13]),
1884 Record.size() <= 15 ? nullptr : getMDOrNull(Record[15]),
1885 Record.size() <= 14 ? 0 : Record[14],
1886 Record.size() <= 16 ? true : Record[16],
1887 Record.size() <= 17 ? false : Record[17],
1888 Record.size() <= 18 ? 0 : Record[18],
1889 Record.size() <= 19 ? false : Record[19],
1890 Record.size() <= 20 ? nullptr : getMDString(Record[20]),
1891 Record.size() <= 21 ? nullptr : getMDString(Record[21]));
1892
1893 MetadataList.assignValue(CU, NextMetadataNo);
1894 NextMetadataNo++;
1895
1896
1897 if (Metadata *SPs = getMDOrNullWithoutPlaceholders(Record[11]))
1898 CUSubprograms.push_back({CU, SPs});
1899 break;
1900 }
1902 if (Record.size() < 18 || Record.size() > 22)
1903 return error("Invalid record");
1904
1905 bool HasSPFlags = Record[0] & 4;
1906
1909 if (!HasSPFlags)
1911 else {
1914 }
1915
1916
1917
1918 const unsigned DIFlagMainSubprogram = 1 << 21;
1919 bool HasOldMainSubprogramFlag = Flags & DIFlagMainSubprogram;
1920 if (HasOldMainSubprogramFlag)
1921
1922
1923
1924 Flags &= ~static_castDINode::DIFlags(DIFlagMainSubprogram);
1925
1926 if (HasOldMainSubprogramFlag && HasSPFlags)
1927 SPFlags |= DISubprogram::SPFlagMainSubprogram;
1928 else if (!HasSPFlags)
1930 Record[7], Record[8],
1931 Record[14], Record[11],
1932 HasOldMainSubprogramFlag);
1933
1934
1935 IsDistinct = (Record[0] & 1) || (SPFlags & DISubprogram::SPFlagDefinition);
1936
1937
1938
1939
1940
1941 bool HasUnit = Record[0] & 2;
1942 if (!HasSPFlags && HasUnit && Record.size() < 19)
1943 return error("Invalid record");
1944 if (HasSPFlags && !HasUnit)
1945 return error("Invalid record");
1946
1947 bool HasFn = false;
1948 bool HasThisAdj = true;
1949 bool HasThrownTypes = true;
1950 bool HasAnnotations = false;
1951 bool HasTargetFuncName = false;
1952 unsigned OffsetA = 0;
1953 unsigned OffsetB = 0;
1954
1955
1956 bool UsesKeyInstructions = false;
1957 if (!HasSPFlags) {
1958 OffsetA = 2;
1959 OffsetB = 2;
1960 if (Record.size() >= 19) {
1961 HasFn = !HasUnit;
1962 OffsetB++;
1963 }
1964 HasThisAdj = Record.size() >= 20;
1965 HasThrownTypes = Record.size() >= 21;
1966 } else {
1967 HasAnnotations = Record.size() >= 19;
1968 HasTargetFuncName = Record.size() >= 20;
1969 UsesKeyInstructions = Record.size() >= 21 ? Record[20] : 0;
1970 }
1971
1972 Metadata *CUorFn = getMDOrNull(Record[12 + OffsetB]);
1974 DISubprogram,
1976 getDITypeRefOrNull(Record[1]),
1977 getMDString(Record[2]),
1978 getMDString(Record[3]),
1979 getMDOrNull(Record[4]),
1980 Record[5],
1981 getMDOrNull(Record[6]),
1982 Record[7 + OffsetA],
1983 getDITypeRefOrNull(Record[8 + OffsetA]),
1984 Record[10 + OffsetA],
1985 HasThisAdj ? Record[16 + OffsetB] : 0,
1986 Flags,
1987 SPFlags,
1988 HasUnit ? CUorFn : nullptr,
1989 getMDOrNull(Record[13 + OffsetB]),
1990 getMDOrNull(Record[14 + OffsetB]),
1991 getMDOrNull(Record[15 + OffsetB]),
1992 HasThrownTypes ? getMDOrNull(Record[17 + OffsetB])
1993 : nullptr,
1994 HasAnnotations ? getMDOrNull(Record[18 + OffsetB])
1995 : nullptr,
1996 HasTargetFuncName ? getMDString(Record[19 + OffsetB])
1997 : nullptr,
1998 UsesKeyInstructions));
1999 MetadataList.assignValue(SP, NextMetadataNo);
2000 NextMetadataNo++;
2001
2002
2003 if (HasFn) {
2006 if (F->isMaterializable())
2007
2008
2009 FunctionsWithSPs[F] = SP;
2010 else if (->empty())
2011 F->setSubprogram(SP);
2012 }
2013 }
2014 break;
2015 }
2017 if (Record.size() != 5)
2018 return error("Invalid record");
2019
2020 IsDistinct = Record[0];
2021 MetadataList.assignValue(
2023 (Context, getMDOrNull(Record[1]),
2024 getMDOrNull(Record[2]), Record[3], Record[4])),
2025 NextMetadataNo);
2026 NextMetadataNo++;
2027 break;
2028 }
2030 if (Record.size() != 4)
2031 return error("Invalid record");
2032
2033 IsDistinct = Record[0];
2034 MetadataList.assignValue(
2036 (Context, getMDOrNull(Record[1]),
2037 getMDOrNull(Record[2]), Record[3])),
2038 NextMetadataNo);
2039 NextMetadataNo++;
2040 break;
2041 }
2043 IsDistinct = Record[0] & 1;
2044 MetadataList.assignValue(
2046 (Context, getMDOrNull(Record[1]),
2047 getMDOrNull(Record[2]), getMDString(Record[3]),
2048 getMDOrNull(Record[4]), Record[5])),
2049 NextMetadataNo);
2050 NextMetadataNo++;
2051 break;
2052 }
2054
2055 MDString *Name;
2056 if (Record.size() == 3)
2057 Name = getMDString(Record[2]);
2058 else if (Record.size() == 5)
2059 Name = getMDString(Record[3]);
2060 else
2061 return error("Invalid record");
2062
2063 IsDistinct = Record[0] & 1;
2064 bool ExportSymbols = Record[0] & 2;
2065 MetadataList.assignValue(
2067 (Context, getMDOrNull(Record[1]), Name, ExportSymbols)),
2068 NextMetadataNo);
2069 NextMetadataNo++;
2070 break;
2071 }
2073 if (Record.size() != 5)
2074 return error("Invalid record");
2075
2076 IsDistinct = Record[0];
2077 MetadataList.assignValue(
2079 (Context, Record[1], Record[2], getMDString(Record[3]),
2080 getMDString(Record[4]))),
2081 NextMetadataNo);
2082 NextMetadataNo++;
2083 break;
2084 }
2086 if (Record.size() != 5)
2087 return error("Invalid record");
2088
2089 IsDistinct = Record[0];
2090 MetadataList.assignValue(
2092 (Context, Record[1], Record[2], getMDOrNull(Record[3]),
2093 getMDOrNull(Record[4]))),
2094 NextMetadataNo);
2095 NextMetadataNo++;
2096 break;
2097 }
2099 if (Record.size() < 3 || Record.size() > 4)
2100 return error("Invalid record");
2101
2102 IsDistinct = Record[0];
2103 MetadataList.assignValue(
2105 (Context, getMDString(Record[1]),
2106 getDITypeRefOrNull(Record[2]),
2107 (Record.size() == 4) ? getMDOrNull(Record[3])
2108 : getMDOrNull(false))),
2109 NextMetadataNo);
2110 NextMetadataNo++;
2111 break;
2112 }
2114 if (Record.size() < 5 || Record.size() > 6)
2115 return error("Invalid record");
2116
2117 IsDistinct = Record[0];
2118
2119 MetadataList.assignValue(
2121 DITemplateValueParameter,
2122 (Context, Record[1], getMDString(Record[2]),
2123 getDITypeRefOrNull(Record[3]),
2124 (Record.size() == 6) ? getMDOrNull(Record[4]) : getMDOrNull(false),
2125 (Record.size() == 6) ? getMDOrNull(Record[5])
2126 : getMDOrNull(Record[4]))),
2127 NextMetadataNo);
2128 NextMetadataNo++;
2129 break;
2130 }
2132 if (Record.size() < 11 || Record.size() > 13)
2133 return error("Invalid record");
2134
2135 IsDistinct = Record[0] & 1;
2136 unsigned Version = Record[0] >> 1;
2137
2139 Metadata *Annotations = nullptr;
2140 if (Record.size() > 12)
2141 Annotations = getMDOrNull(Record[12]);
2142
2143 MetadataList.assignValue(
2145 (Context, getMDOrNull(Record[1]),
2146 getMDString(Record[2]), getMDString(Record[3]),
2147 getMDOrNull(Record[4]), Record[5],
2148 getDITypeRefOrNull(Record[6]), Record[7], Record[8],
2149 getMDOrNull(Record[9]), getMDOrNull(Record[10]),
2150 Record[11], Annotations)),
2151 NextMetadataNo);
2152
2153 NextMetadataNo++;
2154 } else if (Version == 1) {
2155
2156
2157 MetadataList.assignValue(
2159 DIGlobalVariable,
2160 (Context, getMDOrNull(Record[1]), getMDString(Record[2]),
2161 getMDString(Record[3]), getMDOrNull(Record[4]), Record[5],
2162 getDITypeRefOrNull(Record[6]), Record[7], Record[8],
2163 getMDOrNull(Record[10]), nullptr, Record[11], nullptr)),
2164 NextMetadataNo);
2165
2166 NextMetadataNo++;
2167 } else if (Version == 0) {
2168
2169
2170 NeedUpgradeToDIGlobalVariableExpression = true;
2171 Metadata *Expr = getMDOrNull(Record[9]);
2172 uint32_t AlignInBits = 0;
2173 if (Record.size() > 11) {
2174 if (Record[11] > (uint64_t)std::numeric_limits<uint32_t>::max())
2175 return error("Alignment value is too large");
2176 AlignInBits = Record[11];
2177 }
2178 GlobalVariable *Attach = nullptr;
2181 Attach = GV;
2182 Expr = nullptr;
2184 Expr = DIExpression::get(Context,
2185 {dwarf::DW_OP_constu, CI->getZExtValue(),
2186 dwarf::DW_OP_stack_value});
2187 } else {
2188 Expr = nullptr;
2189 }
2190 }
2192 DIGlobalVariable,
2193 (Context, getMDOrNull(Record[1]), getMDString(Record[2]),
2194 getMDString(Record[3]), getMDOrNull(Record[4]), Record[5],
2195 getDITypeRefOrNull(Record[6]), Record[7], Record[8],
2196 getMDOrNull(Record[10]), nullptr, AlignInBits, nullptr));
2197
2198 DIGlobalVariableExpression *DGVE = nullptr;
2199 if (Attach || Expr)
2200 DGVE = DIGlobalVariableExpression::getDistinct(
2201 Context, DGV, Expr ? Expr : DIExpression::get(Context, {}));
2202 if (Attach)
2204
2206 MetadataList.assignValue(MDNode, NextMetadataNo);
2207 NextMetadataNo++;
2208 } else
2209 return error("Invalid record");
2210
2211 break;
2212 }
2214 if (Record.size() != 1)
2215 return error("Invalid DIAssignID record.");
2216
2217 IsDistinct = Record[0] & 1;
2218 if (!IsDistinct)
2219 return error("Invalid DIAssignID record. Must be distinct");
2220
2222 NextMetadataNo++;
2223 break;
2224 }
2226
2227 if (Record.size() < 8 || Record.size() > 10)
2228 return error("Invalid record");
2229
2230 IsDistinct = Record[0] & 1;
2231 bool HasAlignment = Record[0] & 2;
2232
2233
2234
2235 bool HasTag = !HasAlignment && Record.size() > 8;
2237 uint32_t AlignInBits = 0;
2238 Metadata *Annotations = nullptr;
2239 if (HasAlignment) {
2240 if (Record[8] > (uint64_t)std::numeric_limits<uint32_t>::max())
2241 return error("Alignment value is too large");
2242 AlignInBits = Record[8];
2243 if (Record.size() > 9)
2244 Annotations = getMDOrNull(Record[9]);
2245 }
2246
2247 MetadataList.assignValue(
2249 (Context, getMDOrNull(Record[1 + HasTag]),
2250 getMDString(Record[2 + HasTag]),
2251 getMDOrNull(Record[3 + HasTag]), Record[4 + HasTag],
2252 getDITypeRefOrNull(Record[5 + HasTag]),
2253 Record[6 + HasTag], Flags, AlignInBits, Annotations)),
2254 NextMetadataNo);
2255 NextMetadataNo++;
2256 break;
2257 }
2259 if (Record.size() < 5 || Record.size() > 7)
2260 return error("Invalid record");
2261
2262 IsDistinct = Record[0] & 1;
2263 uint64_t Line = Record[4];
2264 uint64_t Column = Record.size() > 5 ? Record[5] : 0;
2265 bool IsArtificial = Record[0] & 2;
2266 std::optional CoroSuspendIdx;
2267 if (Record.size() > 6) {
2268 uint64_t RawSuspendIdx = Record[6];
2269 if (RawSuspendIdx != std::numeric_limits<uint64_t>::max()) {
2270 if (RawSuspendIdx > (uint64_t)std::numeric_limits::max())
2271 return error("CoroSuspendIdx value is too large");
2272 CoroSuspendIdx = RawSuspendIdx;
2273 }
2274 }
2275
2276 MetadataList.assignValue(
2278 (Context, getMDOrNull(Record[1]),
2279 getMDString(Record[2]), getMDOrNull(Record[3]), Line,
2280 Column, IsArtificial, CoroSuspendIdx)),
2281 NextMetadataNo);
2282 NextMetadataNo++;
2283 break;
2284 }
2286 if (Record.size() < 1)
2287 return error("Invalid record");
2288
2289 IsDistinct = Record[0] & 1;
2290 uint64_t Version = Record[0] >> 1;
2291 auto Elts = MutableArrayRef<uint64_t>(Record).slice(1);
2292
2294 if (Error Err = upgradeDIExpression(Version, Elts, Buffer))
2295 return Err;
2296
2298 NextMetadataNo);
2299 NextMetadataNo++;
2300 break;
2301 }
2303 if (Record.size() != 3)
2304 return error("Invalid record");
2305
2306 IsDistinct = Record[0];
2307 Metadata *Expr = getMDOrNull(Record[2]);
2308 if (!Expr)
2309 Expr = DIExpression::get(Context, {});
2310 MetadataList.assignValue(
2312 (Context, getMDOrNull(Record[1]), Expr)),
2313 NextMetadataNo);
2314 NextMetadataNo++;
2315 break;
2316 }
2318 if (Record.size() != 8)
2319 return error("Invalid record");
2320
2321 IsDistinct = Record[0];
2322 MetadataList.assignValue(
2324 (Context, getMDString(Record[1]),
2325 getMDOrNull(Record[2]), Record[3],
2326 getMDString(Record[5]),
2327 getMDString(Record[4]), Record[6],
2328 getDITypeRefOrNull(Record[7]))),
2329 NextMetadataNo);
2330 NextMetadataNo++;
2331 break;
2332 }
2334 if (Record.size() < 6 || Record.size() > 8)
2335 return error("Invalid DIImportedEntity record");
2336
2337 IsDistinct = Record[0];
2338 bool HasFile = (Record.size() >= 7);
2339 bool HasElements = (Record.size() >= 8);
2340 MetadataList.assignValue(
2342 (Context, Record[1], getMDOrNull(Record[2]),
2343 getDITypeRefOrNull(Record[3]),
2344 HasFile ? getMDOrNull(Record[6]) : nullptr,
2345 HasFile ? Record[4] : 0, getMDString(Record[5]),
2346 HasElements ? getMDOrNull(Record[7]) : nullptr)),
2347 NextMetadataNo);
2348 NextMetadataNo++;
2349 break;
2350 }
2352 std::string String(Record.begin(), Record.end());
2353
2354
2356 ++NumMDStringLoaded;
2358 MetadataList.assignValue(MD, NextMetadataNo);
2359 NextMetadataNo++;
2360 break;
2361 }
2363 auto CreateNextMDString = [&](StringRef Str) {
2364 ++NumMDStringLoaded;
2366 NextMetadataNo++;
2367 };
2368 if (Error Err = parseMetadataStrings(Record, Blob, CreateNextMDString))
2369 return Err;
2370 break;
2371 }
2373 if (Record.size() % 2 == 0)
2374 return error("Invalid record");
2375 unsigned ValueID = Record[0];
2376 if (ValueID >= ValueList.size())
2377 return error("Invalid record");
2379 if (Error Err = parseGlobalObjectAttachment(
2380 *GO, ArrayRef<uint64_t>(Record).slice(1)))
2381 return Err;
2382 break;
2383 }
2385
2386
2387 if (Error Err = parseMetadataKindRecord(Record))
2388 return Err;
2389 break;
2390 }
2393 Elts.reserve(Record.size());
2394 for (uint64_t Elt : Record) {
2398 "Invalid record: DIArgList should not contain forward refs");
2400 return error("Invalid record");
2402 }
2403
2405 NextMetadataNo++;
2406 break;
2407 }
2408 }
2410#undef GET_OR_DISTINCT
2411}
2412
2413Error MetadataLoader::MetadataLoaderImpl::parseMetadataStrings(
2414 ArrayRef<uint64_t> Record, StringRef Blob,
2415 function_ref<void(StringRef)> CallBack) {
2416
2417
2418
2419 if (Record.size() != 2)
2420 return error("Invalid record: metadata strings layout");
2421
2422 unsigned NumStrings = Record[0];
2423 unsigned StringsOffset = Record[1];
2424 if (!NumStrings)
2425 return error("Invalid record: metadata strings with no strings");
2426 if (StringsOffset > Blob.size())
2427 return error("Invalid record: metadata strings corrupt offset");
2428
2429 StringRef Lengths = Blob.slice(0, StringsOffset);
2430 SimpleBitstreamCursor R(Lengths);
2431
2432 StringRef Strings = Blob.drop_front(StringsOffset);
2433 do {
2434 if (R.AtEndOfStream())
2435 return error("Invalid record: metadata strings bad length");
2436
2437 uint32_t Size;
2438 if (Error E = R.ReadVBR(6).moveInto(Size))
2439 return E;
2441 return error("Invalid record: metadata strings truncated chars");
2442
2443 CallBack(Strings.slice(0, Size));
2445 } while (--NumStrings);
2446
2448}
2449
2450Error MetadataLoader::MetadataLoaderImpl::parseGlobalObjectAttachment(
2451 GlobalObject &GO, ArrayRef<uint64_t> Record) {
2453 for (unsigned I = 0, E = Record.size(); I != E; I += 2) {
2454 auto K = MDKindMap.find(Record[I]);
2455 if (K == MDKindMap.end())
2456 return error("Invalid ID");
2457 MDNode *MD =
2459 if (!MD)
2460 return error("Invalid metadata attachment: expect fwd ref to MDNode");
2462 }
2464}
2465
2466
2470 return Err;
2471
2473 PlaceholderQueue Placeholders;
2474
2475 while (true) {
2477 if (Error E = Stream.advanceSkippingSubblocks().moveInto(Entry))
2478 return E;
2479
2480 switch (Entry.Kind) {
2483 return error("Malformed block");
2485 resolveForwardRefsAndPlaceholders(Placeholders);
2488
2489 break;
2490 }
2491
2492
2494 ++NumMDRecordLoaded;
2496 if (!MaybeRecord)
2498 switch (MaybeRecord.get()) {
2499 default:
2500 break;
2502 unsigned RecordLength = Record.size();
2504 return error("Invalid record");
2505 if (RecordLength % 2 == 0) {
2506
2507 if (Error Err = parseGlobalObjectAttachment(F, Record))
2508 return Err;
2509 continue;
2510 }
2511
2512
2514 for (unsigned i = 1; i != RecordLength; i = i + 2) {
2515 unsigned Kind = Record[i];
2517 if (I == MDKindMap.end())
2518 return error("Invalid ID");
2519 if (I->second == LLVMContext::MD_tbaa && StripTBAA)
2520 continue;
2521
2522 auto Idx = Record[i + 1];
2523 if (Idx < (MDStringRef.size() + GlobalMetadataBitPosIndex.size()) &&
2524 !MetadataList.lookup(Idx)) {
2525
2526
2527 lazyLoadOneMetadata(Idx, Placeholders);
2528 resolveForwardRefsAndPlaceholders(Placeholders);
2529 }
2530
2531 Metadata *Node = MetadataList.getMetadataFwdRef(Idx);
2533
2534
2535 break;
2537 if (!MD)
2538 return error("Invalid metadata attachment");
2539
2540 if (HasSeenOldLoopTags && I->second == LLVMContext::MD_loop)
2542
2543 if (I->second == LLVMContext::MD_tbaa) {
2544 assert(!MD->isTemporary() && "should load MDs before attachments");
2546 }
2548 }
2549 break;
2550 }
2551 }
2552 }
2553}
2554
2555
2556Error MetadataLoader::MetadataLoaderImpl::parseMetadataKindRecord(
2558 if (Record.size() < 2)
2559 return error("Invalid record");
2560
2561 unsigned Kind = Record[0];
2563
2564 unsigned NewKind = TheModule.getMDKindID(Name.str());
2565 if (!MDKindMap.insert(std::make_pair(Kind, NewKind)).second)
2566 return error("Conflicting METADATA_KIND records");
2568}
2569
2570
2573 return Err;
2574
2576
2577
2578 while (true) {
2580 if (Error E = Stream.advanceSkippingSubblocks().moveInto(Entry))
2581 return E;
2582
2583 switch (Entry.Kind) {
2586 return error("Malformed block");
2590
2591 break;
2592 }
2593
2594
2596 ++NumMDRecordLoaded;
2598 if (!MaybeCode)
2600 switch (MaybeCode.get()) {
2601 default:
2602 break;
2604 if (Error Err = parseMetadataKindRecord(Record))
2605 return Err;
2606 break;
2607 }
2608 }
2609 }
2610}
2611
2613 Pimpl = std::move(RHS.Pimpl);
2614 return *this;
2615}
2617 : Pimpl(std::move(RHS.Pimpl)) {}
2618
2622 bool IsImporting,
2625 Stream, TheModule, ValueList, std::move(Callbacks), IsImporting)) {}
2626
2627Error MetadataLoader::parseMetadata(bool ModuleLevel) {
2628 return Pimpl->parseMetadata(ModuleLevel);
2629}
2630
2632
2633
2634
2636 return Pimpl->getMetadataFwdRefOrLoad(Idx);
2637}
2638
2640 return Pimpl->lookupSubprogramForFunction(F);
2641}
2642
2645 return Pimpl->parseMetadataAttachment(F, InstructionList);
2646}
2647
2649 return Pimpl->parseMetadataKinds();
2650}
2651
2653 return Pimpl->setStripTBAA(StripTBAA);
2654}
2655
2657
2660
2662 return Pimpl->upgradeDebugIntrinsics(F);
2663}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_UNLIKELY(EXPR)
#define LLVM_LIKELY(EXPR)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
This file contains constants used for implementing Dwarf debug support.
Module.h This file contains the declarations for the Module class.
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.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define GET_OR_DISTINCT(CLASS, ARGS)
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
static bool parseMetadata(const StringRef &Input, uint64_t &FunctionHash, uint32_t &Attributes)
Parse Input that contains metadata.
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallString class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
std::pair< llvm::MachO::Target, std::string > UUID
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
Value * getValueFwdRef(unsigned Idx, Type *Ty, unsigned TyID, BasicBlock *ConstExprInsertBB)
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
Error JumpToBit(uint64_t BitNo)
Reset the stream to the specified bit number.
uint64_t GetCurrentBitNo() const
Return the bit # of the bit we are reading.
LLVM_ABI Expected< unsigned > readRecord(unsigned AbbrevID, SmallVectorImpl< uint64_t > &Vals, StringRef *Blob=nullptr)
LLVM_ABI Expected< unsigned > skipRecord(unsigned AbbrevID)
Read the current record and discard it, returning the code for the record.
@ AF_DontPopBlockAtEnd
If this flag is used, the advance() method does not automatically pop the block scope when the end of...
static LLVM_ABI DIArgList * get(LLVMContext &Context, ArrayRef< ValueAsMetadata * > Args)
static DIAssignID * getDistinct(LLVMContext &Context)
static LLVM_ABI DICompositeType * buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, Metadata *SizeInBits, uint32_t AlignInBits, Metadata *OffsetInBits, Metadata *Specification, uint32_t NumExtraInhabitants, DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, std::optional< uint32_t > EnumKind, Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator, Metadata *DataLocation, Metadata *Associated, Metadata *Allocated, Metadata *Rank, Metadata *Annotations, Metadata *BitStride)
Build a DICompositeType with the given ODR identifier.
MDString * getRawIdentifier() const
ChecksumKind
Which algorithm (e.g.
LLVM_ABI DIScope * getScope() const
Subprogram description. Uses SubclassData1.
static LLVM_ABI DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized, unsigned Virtuality=SPFlagNonvirtual, bool IsMainSubprogram=false)
DISPFlags
Debug info subprogram flags.
bool isForwardDecl() const
Record of a variable value-assignment, aka a non instruction representation of the dbg....
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
Implements a dense probed hash-table based set.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
LLVM_ABI void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
LLVM_ABI void addDebugInfo(DIGlobalVariableExpression *GV)
Attach a DIGlobalVariableExpression.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
This is an important class for using LLVM in a threaded context.
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a temporary node.
A Module instance is used to store all the information related to an LLVM module.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
LLVM_ABI void addOperand(MDNode *M)
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
A vector that has set insertion semantics.
bool contains(const_arg_type key) const
Check if the SetVector contains the given key.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
Implements a dense probed hash-table based set with some number of buckets stored inline.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
constexpr size_t size() const
size - Get the string size.
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVoidTy() const
Return true if this is 'void'.
bool isMetadataTy() const
Return true if this is 'metadata'.
LLVM Value Representation.
std::pair< iterator, bool > insert(const ValueT &V)
An efficient, type-erasing, non-owning reference to a callable.
constexpr char LanguageVersion[]
Key for Kernel::Metadata::mLanguageVersion.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
@ METADATA_TEMPLATE_VALUE
@ METADATA_LEXICAL_BLOCK_FILE
@ METADATA_SUBROUTINE_TYPE
@ METADATA_GLOBAL_DECL_ATTACHMENT
@ METADATA_IMPORTED_ENTITY
@ METADATA_GENERIC_SUBRANGE
@ METADATA_COMPOSITE_TYPE
@ METADATA_FIXED_POINT_TYPE
@ METADATA_GLOBAL_VAR_EXPR
initializer< Ty > init(const Ty &Val)
@ DW_OP_LLVM_fragment
Only used in LLVM metadata.
@ DW_APPLE_ENUM_KIND_invalid
Enum kind for invalid results.
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
NodeAddr< CodeNode * > Code
LLVM_ABI Instruction & back() const
This is an optimization pass for GlobalISel generic memory operations.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
FunctionAddr VTableAddr Value
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.
std::error_code make_error_code(BitcodeError E)
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
LLVM_ABI MDNode * upgradeInstructionLoopAttachment(MDNode &N)
Upgrade the loop attachment metadata node.
auto cast_or_null(const Y &Val)
bool isa_and_nonnull(const Y &Val)
auto dyn_cast_or_null(const Y &Val)
FunctionAddr VTableAddr uintptr_t uintptr_t Version
bool mayBeOldLoopAttachmentTag(StringRef Name)
Check whether a string looks like an old loop attachment tag.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
@ Ref
The access may reference the value stored in memory.
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
constexpr unsigned BitWidth
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
LLVM_ABI APInt readWideAPInt(ArrayRef< uint64_t > Vals, unsigned TypeBits)
LLVM_ABI MDNode * UpgradeTBAANode(MDNode &TBAANode)
If the given TBAA tag uses the scalar TBAA format, create a new node corresponding to the upgrade to ...
static auto filterDbgVars(iterator_range< simple_ilist< DbgRecord >::iterator > R)
Filter the DbgRecord range to DbgVariableRecord types only and downcast.
void consumeError(Error Err)
Consume a Error without doing anything.
Implement std::hash so that hash_code can be used in STL containers.
When advancing through a bitstream cursor, each advance can discover a few different kinds of entries...