LLVM: lib/Bitcode/Writer/BitcodeWriter.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
31#include "llvm/Config/llvm-config.h"
74#include
75#include
76#include
77#include
78#include
79#include
80#include
81#include
82#include
83#include
84#include
85
86using namespace llvm;
88
91 cl::desc("Number of metadatas above which we emit an index "
92 "to enable lazy-loading"));
95 cl::desc("The threshold (unit M) for flushing LLVM bitcode."));
96
99 cl::desc("Write relative block frequency to function summary "));
100
101namespace llvm {
103}
104
107
108namespace {
109
110
111
112enum {
113
115 VST_ENTRY_7_ABBREV,
116 VST_ENTRY_6_ABBREV,
117 VST_BBENTRY_6_ABBREV,
118
119
121 CONSTANTS_INTEGER_ABBREV,
122 CONSTANTS_CE_CAST_Abbrev,
123 CONSTANTS_NULL_Abbrev,
124
125
127 FUNCTION_INST_UNOP_ABBREV,
128 FUNCTION_INST_UNOP_FLAGS_ABBREV,
129 FUNCTION_INST_BINOP_ABBREV,
130 FUNCTION_INST_BINOP_FLAGS_ABBREV,
131 FUNCTION_INST_CAST_ABBREV,
132 FUNCTION_INST_CAST_FLAGS_ABBREV,
133 FUNCTION_INST_RET_VOID_ABBREV,
134 FUNCTION_INST_RET_VAL_ABBREV,
135 FUNCTION_INST_UNREACHABLE_ABBREV,
136 FUNCTION_INST_GEP_ABBREV,
137 FUNCTION_DEBUG_RECORD_VALUE_ABBREV,
138};
139
140
141
142class BitcodeWriterBase {
143protected:
144
146
148
149public:
150
151
153 : Stream(Stream), StrtabBuilder(StrtabBuilder) {}
154
155protected:
156 void writeModuleVersion();
157};
158
159void BitcodeWriterBase::writeModuleVersion() {
160
162}
163
164
165
166class ModuleBitcodeWriterBase : public BitcodeWriterBase {
167protected:
168
170
171
173
174
176
177
178
179
180 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
181
182
183 unsigned GlobalValueId;
184
185
186
187 uint64_t VSTOffsetPlaceholder = 0;
188
189public:
190
191
194 bool ShouldPreserveUseListOrder,
196 : BitcodeWriterBase(Stream, StrtabBuilder), M(M),
197 VE(M, ShouldPreserveUseListOrder), Index(Index) {
198
199
200
201
202
203 GlobalValueId = VE.getValues().size();
204 if (!Index)
205 return;
206 for (const auto &GUIDSummaryLists : *Index)
207
208 for (auto &Summary : GUIDSummaryLists.second.SummaryList)
209 if (auto FS = dyn_cast(Summary.get())) {
210
211
212
213
214 for (auto &CallEdge : FS->calls())
215 if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
216 assignValueId(CallEdge.first.getGUID());
217
218
219
220
221
222 for (auto &RefEdge : FS->refs())
223 if (!RefEdge.haveGVs() || !RefEdge.getValue())
224 assignValueId(RefEdge.getGUID());
225 }
226 }
227
228protected:
229 void writePerModuleGlobalValueSummary();
230
231private:
232 void writePerModuleFunctionSummaryRecord(
234 unsigned ValueID, unsigned FSCallsAbbrev, unsigned FSCallsProfileAbbrev,
235 unsigned CallsiteAbbrev, unsigned AllocAbbrev, unsigned ContextIdAbbvId,
238 void writeModuleLevelReferences(const GlobalVariable &V,
240 unsigned FSModRefsAbbrev,
241 unsigned FSModVTableRefsAbbrev);
242
244 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
245 }
246
248 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
249
250
251 assert(VMI != GUIDToValueIdMap.end() &&
252 "GUID does not have assigned value Id");
253 return VMI->second;
254 }
255
256
257 unsigned getValueId(ValueInfo VI) {
258 if (.haveGVs() ||
.getValue())
259 return getValueId(VI.getGUID());
261 }
262
263 std::map<GlobalValue::GUID, unsigned> &valueIds() { return GUIDToValueIdMap; }
264};
265
266
267class ModuleBitcodeWriter : public ModuleBitcodeWriterBase {
268
269 bool GenerateHash;
270
271
272
274
276
277
279
280public:
281
282
284 BitstreamWriter &Stream, bool ShouldPreserveUseListOrder,
287 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
288 ShouldPreserveUseListOrder, Index),
289 GenerateHash(GenerateHash), ModHash(ModHash),
290 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
291
292
294
295private:
296 uint64_t bitcodeStartBit() { return BitcodeStartBit; }
297
298 size_t addToStrtab(StringRef Str);
299
300 void writeAttributeGroupTable();
301 void writeAttributeTable();
302 void writeTypeTable();
303 void writeComdats();
304 void writeValueSymbolTableForwardDecl();
305 void writeModuleInfo();
309 unsigned Abbrev);
310 unsigned createDILocationAbbrev();
312 unsigned &Abbrev);
313 unsigned createGenericDINodeAbbrev();
317 unsigned Abbrev);
320 unsigned Abbrev);
324 unsigned Abbrev);
333 unsigned Abbrev);
335 unsigned Abbrev);
344 unsigned Abbrev);
348 unsigned Abbrev);
350 unsigned Abbrev);
352 unsigned Abbrev);
355 unsigned Abbrev);
357 unsigned Abbrev);
360 unsigned Abbrev);
363 unsigned Abbrev);
366 unsigned Abbrev);
375 unsigned Abbrev);
380 unsigned Abbrev);
381 unsigned createNamedMetadataAbbrev();
383 unsigned createMetadataStringsAbbrev();
388 std::vector *MDAbbrevs = nullptr,
389 std::vector<uint64_t> *IndexPos = nullptr);
390 void writeModuleMetadata();
391 void writeFunctionMetadata(const Function &F);
392 void writeFunctionMetadataAttachment(const Function &F);
395 void writeModuleMetadataKinds();
396 void writeOperandBundleTags();
397 void writeSyncScopeNames();
398 void writeConstants(unsigned FirstVal, unsigned LastVal, bool isGlobal);
399 void writeModuleConstants();
400 bool pushValueAndType(const Value *V, unsigned InstID,
402 bool pushValueOrMetadata(const Value *V, unsigned InstID,
404 void writeOperandBundles(const CallBase &CB, unsigned InstID);
405 void pushValue(const Value *V, unsigned InstID,
407 void pushValueSigned(const Value *V, unsigned InstID,
409 void writeInstruction(const Instruction &I, unsigned InstID,
411 void writeFunctionLevelValueSymbolTable(const ValueSymbolTable &VST);
412 void writeGlobalValueSymbolTable(
415 void writeUseListBlock(const Function *F);
416 void
419 void writeBlockInfo();
420 void writeModuleHash(StringRef View);
421
422 unsigned getEncodedSyncScopeID(SyncScope::ID SSID) {
424 }
425
426 unsigned getEncodedAlign(MaybeAlign Alignment) { return encode(Alignment); }
427};
428
429
430class IndexBitcodeWriter : public BitcodeWriterBase {
431
433
434
435
436
438
439
440
442
443
444
445 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
446
447
448
449 std::vector<uint64_t> StackIds;
450
451
452
453
455
456
457 unsigned GlobalValueId = 0;
458
459
460
462
463public:
464
465
466
467
468
469
470 IndexBitcodeWriter(
475 : BitcodeWriterBase(Stream, StrtabBuilder), Index(Index),
476 DecSummaries(DecSummaries),
477 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
478
479
480
481 auto RecordStackIdReference = [&](unsigned StackIdIndex) {
482
483
484
486 StackIdIndicesToIndex.insert({StackIdIndex, StackIds.size()});
488 StackIds.push_back(Index.getStackIdAtIndex(StackIdIndex));
489 };
490
491
492
493
494
495 forEachSummary([&](GVInfo I, bool IsAliasee) {
496 GUIDToValueIdMap[I.first] = ++GlobalValueId;
497
498
499
500 if (IsAliasee)
501 return;
502 auto *FS = dyn_cast(I.second);
503 if (!FS)
504 return;
505
506
507
508 for (auto &CI : FS->callsites()) {
509
510
511
512
513
514
515
516
517
518
519 if (CI.StackIdIndices.empty()) {
520 GUIDToValueIdMap[CI.Callee.getGUID()] = ++GlobalValueId;
521 continue;
522 }
523 for (auto Idx : CI.StackIdIndices)
524 RecordStackIdReference(Idx);
525 }
526 for (auto &AI : FS->allocs())
527 for (auto &MIB : AI.MIBs)
528 for (auto Idx : MIB.StackIdIndices)
529 RecordStackIdReference(Idx);
530 });
531 }
532
533
534 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
535
536
537
538
539 template
540 void forEachSummary(Functor Callback) {
541 if (ModuleToSummariesForIndex) {
542 for (auto &M : *ModuleToSummariesForIndex)
543 for (auto &Summary : M.second) {
544 Callback(Summary, false);
545
546
547
548 if (auto *AS = dyn_cast(Summary.getSecond()))
549 Callback({AS->getAliaseeGUID(), &AS->getAliasee()}, true);
550 }
551 } else {
552 for (auto &Summaries : Index)
553 for (auto &Summary : Summaries.second.SummaryList)
554 Callback({Summaries.first, Summary.get()}, false);
555 }
556 }
557
558
559
560
561
562 template void forEachModule(Functor Callback) {
563 if (ModuleToSummariesForIndex) {
564 for (const auto &M : *ModuleToSummariesForIndex) {
565 const auto &MPI = Index.modulePaths().find(M.first);
566 if (MPI == Index.modulePaths().end()) {
567
568
569
570 assert(ModuleToSummariesForIndex->size() == 1);
571 continue;
572 }
573 Callback(*MPI);
574 }
575 } else {
576
577
578
579
580 std::vector ModulePaths;
581 for (auto &[ModPath, _] : Index.modulePaths())
582 ModulePaths.push_back(ModPath);
583 llvm::sort(ModulePaths.begin(), ModulePaths.end());
584 for (auto &ModPath : ModulePaths)
585 Callback(*Index.modulePaths().find(ModPath));
586 }
587 }
588
589
591
592private:
593 void writeModStrings();
594 void writeCombinedGlobalValueSummary();
595
597 auto VMI = GUIDToValueIdMap.find(ValGUID);
598 if (VMI == GUIDToValueIdMap.end())
599 return std::nullopt;
600 return VMI->second;
601 }
602
603 std::map<GlobalValue::GUID, unsigned> &valueIds() { return GUIDToValueIdMap; }
604};
605
606}
607
609 switch (Opcode) {
624 }
625}
626
628 switch (Opcode) {
631 }
632}
633
635 switch (Opcode) {
637 case Instruction::Add:
639 case Instruction::Sub:
641 case Instruction::Mul:
644 case Instruction::FDiv:
647 case Instruction::FRem:
655 }
656}
657
659 switch (Op) {
684 }
685}
686
688 switch (Ordering) {
696 }
698}
699
701 StringRef Str, unsigned AbbrevToUse) {
703
704
705 for (char C : Str) {
707 AbbrevToUse = 0;
709 }
710
711
712 Stream.EmitRecord(Code, Vals, AbbrevToUse);
713}
714
716 switch (Kind) {
717 case Attribute::Alignment:
719 case Attribute::AllocAlign:
721 case Attribute::AllocSize:
723 case Attribute::AlwaysInline:
725 case Attribute::Builtin:
727 case Attribute::ByVal:
729 case Attribute::Convergent:
731 case Attribute::InAlloca:
733 case Attribute::Cold:
735 case Attribute::DisableSanitizerInstrumentation:
737 case Attribute::FnRetThunkExtern:
739 case Attribute::Hot:
741 case Attribute::ElementType:
743 case Attribute::HybridPatchable:
745 case Attribute::InlineHint:
747 case Attribute::InReg:
749 case Attribute::JumpTable:
751 case Attribute::MinSize:
753 case Attribute::AllocatedPointer:
755 case Attribute::AllocKind:
757 case Attribute::Memory:
759 case Attribute::NoFPClass:
761 case Attribute::Naked:
763 case Attribute::Nest:
765 case Attribute::NoAlias:
767 case Attribute::NoBuiltin:
769 case Attribute::NoCallback:
771 case Attribute::NoCapture:
773 case Attribute::NoDivergenceSource:
775 case Attribute::NoDuplicate:
777 case Attribute::NoFree:
779 case Attribute::NoImplicitFloat:
781 case Attribute::NoInline:
783 case Attribute::NoRecurse:
785 case Attribute::NoMerge:
787 case Attribute::NonLazyBind:
789 case Attribute::NonNull:
791 case Attribute::Dereferenceable:
793 case Attribute::DereferenceableOrNull:
795 case Attribute::NoRedZone:
797 case Attribute::NoReturn:
799 case Attribute::NoSync:
801 case Attribute::NoCfCheck:
803 case Attribute::NoProfile:
805 case Attribute::SkipProfile:
807 case Attribute::NoUnwind:
809 case Attribute::NoSanitizeBounds:
811 case Attribute::NoSanitizeCoverage:
813 case Attribute::NullPointerIsValid:
815 case Attribute::OptimizeForDebugging:
817 case Attribute::OptForFuzzing:
819 case Attribute::OptimizeForSize:
821 case Attribute::OptimizeNone:
823 case Attribute::ReadNone:
825 case Attribute::ReadOnly:
827 case Attribute::Returned:
829 case Attribute::ReturnsTwice:
831 case Attribute::SExt:
833 case Attribute::Speculatable:
835 case Attribute::StackAlignment:
837 case Attribute::StackProtect:
839 case Attribute::StackProtectReq:
841 case Attribute::StackProtectStrong:
843 case Attribute::SafeStack:
845 case Attribute::ShadowCallStack:
847 case Attribute::StrictFP:
849 case Attribute::StructRet:
851 case Attribute::SanitizeAddress:
853 case Attribute::SanitizeHWAddress:
855 case Attribute::SanitizeThread:
857 case Attribute::SanitizeType:
859 case Attribute::SanitizeMemory:
861 case Attribute::SanitizeNumericalStability:
863 case Attribute::SanitizeRealtime:
865 case Attribute::SanitizeRealtimeBlocking:
867 case Attribute::SpeculativeLoadHardening:
869 case Attribute::SwiftError:
871 case Attribute::SwiftSelf:
873 case Attribute::SwiftAsync:
875 case Attribute::UWTable:
877 case Attribute::VScaleRange:
879 case Attribute::WillReturn:
881 case Attribute::WriteOnly:
883 case Attribute::ZExt:
885 case Attribute::ImmArg:
887 case Attribute::SanitizeMemTag:
889 case Attribute::Preallocated:
891 case Attribute::NoUndef:
893 case Attribute::ByRef:
895 case Attribute::MustProgress:
897 case Attribute::PresplitCoroutine:
899 case Attribute::Writable:
901 case Attribute::CoroDestroyOnlyWhenComplete:
903 case Attribute::CoroElideSafe:
905 case Attribute::DeadOnUnwind:
907 case Attribute::Range:
909 case Attribute::Initializes:
911 case Attribute::NoExt:
913 case Attribute::Captures:
916 llvm_unreachable("Can not encode end-attribute kinds marker.");
922 }
923
925}
926
928 if ((int64_t)V >= 0)
930 else
932}
933
935
936
937
938
939 unsigned NumWords = A.getActiveWords();
940 const uint64_t *RawData = A.getRawData();
941 for (unsigned i = 0; i < NumWords; i++)
943}
944
948 if (EmitBitWidth)
955 } else {
958 }
959}
960
961void ModuleBitcodeWriter::writeAttributeGroupTable() {
962 const std::vectorValueEnumerator::IndexAndAttrSet &AttrGrps =
964 if (AttrGrps.empty()) return;
965
967
970 unsigned AttrListIndex = Pair.first;
973 Record.push_back(AttrListIndex);
974
976 if (Attr.isEnumAttribute()) {
979 } else if (Attr.isIntAttribute()) {
982 Record.push_back(Attr.getValueAsInt());
983 } else if (Attr.isStringAttribute()) {
985 StringRef Val = Attr.getValueAsString();
986
990 if (!Val.empty()) {
993 }
994 } else if (Attr.isTypeAttribute()) {
995 Type *Ty = Attr.getValueAsType();
996 Record.push_back(Ty ? 6 : 5);
998 if (Ty)
1000 } else if (Attr.isConstantRangeAttribute()) {
1001 Record.push_back(7);
1004 true);
1005 } else {
1006 assert(Attr.isConstantRangeListAttribute());
1007 Record.push_back(8);
1012 for (auto &CR : Val)
1014 }
1015 }
1016
1019 }
1020
1022}
1023
1024void ModuleBitcodeWriter::writeAttributeTable() {
1026 if (Attrs.empty()) return;
1027
1029
1032 for (unsigned i : AL.indexes()) {
1036 }
1037
1040 }
1041
1043}
1044
1045
1046void ModuleBitcodeWriter::writeTypeTable() {
1048
1051
1053
1054
1055 auto Abbv = std::make_shared();
1058 unsigned OpaquePtrAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1059
1060
1061 Abbv = std::make_shared();
1066 unsigned FunctionAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1067
1068
1069 Abbv = std::make_shared();
1074 unsigned StructAnonAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1075
1076
1077 Abbv = std::make_shared();
1081 unsigned StructNameAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1082
1083
1084 Abbv = std::make_shared();
1089 unsigned StructNamedAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1090
1091
1092 Abbv = std::make_shared();
1096 unsigned ArrayAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1097
1098
1099 TypeVals.push_back(TypeList.size());
1101 TypeVals.clear();
1102
1103
1104 for (Type *T : TypeList) {
1105 int AbbrevToUse = 0;
1106 unsigned Code = 0;
1107
1108 switch (T->getTypeID()) {
1120 break;
1124
1127 break;
1130 unsigned AddressSpace = PTy->getAddressSpace();
1131
1135 AbbrevToUse = OpaquePtrAbbrev;
1136 break;
1137 }
1140
1142 TypeVals.push_back(FT->isVarArg());
1144 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1146 AbbrevToUse = FunctionAbbrev;
1147 break;
1148 }
1151
1153
1154 for (Type *ET : ST->elements())
1156
1157 if (ST->isLiteral()) {
1159 AbbrevToUse = StructAnonAbbrev;
1160 } else {
1161 if (ST->isOpaque()) {
1163 } else {
1165 AbbrevToUse = StructNamedAbbrev;
1166 }
1167
1168
1169 if (->getName().empty())
1171 StructNameAbbrev);
1172 }
1173 break;
1174 }
1177
1179 TypeVals.push_back(AT->getNumElements());
1181 AbbrevToUse = ArrayAbbrev;
1182 break;
1183 }
1187
1188
1190 TypeVals.push_back(VT->getElementCount().getKnownMinValue());
1192 if (isa(VT))
1194 break;
1195 }
1200 StructNameAbbrev);
1201 TypeVals.push_back(TET->getNumTypeParameters());
1202 for (Type *InnerTy : TET->type_params())
1204 for (unsigned IntParam : TET->int_params())
1206 break;
1207 }
1209 llvm_unreachable("Typed pointers cannot be added to IR modules");
1210 }
1211
1212
1213 Stream.EmitRecord(Code, TypeVals, AbbrevToUse);
1214 TypeVals.clear();
1215 }
1216
1218}
1219
1221 switch (Linkage) {
1223 return 0;
1225 return 16;
1227 return 2;
1229 return 3;
1231 return 18;
1233 return 7;
1235 return 8;
1237 return 9;
1239 return 17;
1241 return 19;
1243 return 12;
1244 }
1246}
1247
1250}
1251
1254 RawFlags |= Flags.ReadNone;
1255 RawFlags |= (Flags.ReadOnly << 1);
1256 RawFlags |= (Flags.NoRecurse << 2);
1257 RawFlags |= (Flags.ReturnDoesNotAlias << 3);
1258 RawFlags |= (Flags.NoInline << 4);
1259 RawFlags |= (Flags.AlwaysInline << 5);
1260 RawFlags |= (Flags.NoUnwind << 6);
1261 RawFlags |= (Flags.MayThrow << 7);
1262 RawFlags |= (Flags.HasUnknownCall << 8);
1263 RawFlags |= (Flags.MustBeUnreachable << 9);
1264 return RawFlags;
1265}
1266
1267
1268
1270 bool ImportAsDecl = false) {
1272
1273 RawFlags |= Flags.NotEligibleToImport;
1274 RawFlags |= (Flags.Live << 1);
1275 RawFlags |= (Flags.DSOLocal << 2);
1276 RawFlags |= (Flags.CanAutoHide << 3);
1277
1278
1279
1280
1281 RawFlags = (RawFlags << 4) | Flags.Linkage;
1282
1283 RawFlags |= (Flags.Visibility << 8);
1284
1285 unsigned ImportType = Flags.ImportType | ImportAsDecl;
1286 RawFlags |= (ImportType << 10);
1287
1288 return RawFlags;
1289}
1290
1292 uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1293 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1294 return RawFlags;
1295}
1296
1299
1300 RawFlags |= CI.Hotness;
1301 RawFlags |= (CI.HasTailCall << 3);
1302
1303 return RawFlags;
1304}
1305
1308
1309 RawFlags |= CI.RelBlockFreq;
1311
1312 return RawFlags;
1313}
1314
1320 }
1322}
1323
1329 }
1331}
1332
1335 case GlobalVariable::NotThreadLocal: return 0;
1336 case GlobalVariable::GeneralDynamicTLSModel: return 1;
1337 case GlobalVariable::LocalDynamicTLSModel: return 2;
1338 case GlobalVariable::InitialExecTLSModel: return 3;
1339 case GlobalVariable::LocalExecTLSModel: return 4;
1340 }
1342}
1343
1345 switch (C.getSelectionKind()) {
1356 }
1358}
1359
1362 case GlobalValue::UnnamedAddr::None: return 0;
1363 case GlobalValue::UnnamedAddr::Local: return 2;
1364 case GlobalValue::UnnamedAddr::Global: return 1;
1365 }
1367}
1368
1369size_t ModuleBitcodeWriter::addToStrtab(StringRef Str) {
1370 if (GenerateHash)
1371 Hasher.update(Str);
1372 return StrtabBuilder.add(Str);
1373}
1374
1375void ModuleBitcodeWriter::writeComdats() {
1378
1379 Vals.push_back(addToStrtab(C->getName()));
1380 Vals.push_back(C->getName().size());
1384 }
1385}
1386
1387
1388
1389
1390void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1391
1392
1393
1394
1395 auto Abbv = std::make_shared();
1397
1398
1399
1401 unsigned VSTOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1402
1403
1406
1407
1408
1409
1411}
1412
1414
1415
1417 bool isChar6 = true;
1418 for (char C : Str) {
1419 if (isChar6)
1421 if ((unsigned char)C & 128)
1422
1424 }
1425 if (isChar6)
1428}
1429
1431 "Sanitizer Metadata is too large for naive serialization.");
1432static unsigned
1434 return Meta.NoAddress | (Meta.NoHWAddress << 1) |
1435 (Meta.Memtag << 2) | (Meta.IsDynInit << 3);
1436}
1437
1438
1439
1440
1441void ModuleBitcodeWriter::writeModuleInfo() {
1442
1443 if (.getTargetTriple().empty())
1445 0 );
1446 const std::string &DL = M.getDataLayoutStr();
1449 if (.getModuleInlineAsm().empty())
1451 0 );
1452
1453
1454
1455 std::map<std::string, unsigned> SectionMap;
1456 std::map<std::string, unsigned> GCMap;
1458 unsigned MaxGlobalType = 0;
1459 const auto UpdateMaxAlignment = [&MaxAlignment](const MaybeAlign A) {
1460 if (A)
1461 MaxAlignment = !MaxAlignment ? *A : std::max(*MaxAlignment, *A);
1462 };
1464 UpdateMaxAlignment(GV.getAlign());
1465 MaxGlobalType = std::max(MaxGlobalType, VE.getTypeID(GV.getValueType()));
1466 if (GV.hasSection()) {
1467
1468 unsigned &Entry = SectionMap[std::string(GV.getSection())];
1469 if (!Entry) {
1471 0 );
1472 Entry = SectionMap.size();
1473 }
1474 }
1475 }
1477 UpdateMaxAlignment(F.getAlign());
1478 if (F.hasSection()) {
1479
1480 unsigned &Entry = SectionMap[std::string(F.getSection())];
1481 if (!Entry) {
1483 0 );
1484 Entry = SectionMap.size();
1485 }
1486 }
1487 if (F.hasGC()) {
1488
1489 unsigned &Entry = GCMap[F.getGC()];
1490 if (!Entry) {
1492 0 );
1493 Entry = GCMap.size();
1494 }
1495 }
1496 }
1497
1498
1499 unsigned SimpleGVarAbbrev = 0;
1500 if (.global_empty()) {
1501
1502 auto Abbv = std::make_shared();
1509
1510
1513 if (!MaxAlignment)
1515 else {
1516 unsigned MaxEncAlignment = getEncodedAlign(MaxAlignment);
1519 }
1520 if (SectionMap.empty())
1522 else
1525
1526 SimpleGVarAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1527 }
1528
1530
1531 {
1538
1539
1540 auto Abbv = std::make_shared();
1543 Abbv->Add(AbbrevOpToUse);
1544 unsigned FilenameAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1545
1546 for (const auto P : M.getSourceFileName())
1548
1549
1552 }
1553
1554
1556 unsigned AbbrevToUse = 0;
1557
1558
1559
1560
1561
1562 Vals.push_back(addToStrtab(GV.getName()));
1563 Vals.push_back(GV.getName().size());
1565 Vals.push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1566 Vals.push_back(GV.isDeclaration() ? 0 :
1567 (VE.getValueID(GV.getInitializer()) + 1));
1569 Vals.push_back(getEncodedAlign(GV.getAlign()));
1570 Vals.push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1571 : 0);
1572 if (GV.isThreadLocal() ||
1574 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1575 GV.isExternallyInitialized() ||
1577 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1578 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1582 Vals.push_back(GV.isExternallyInitialized());
1585
1588
1589 Vals.push_back(GV.isDSOLocal());
1590 Vals.push_back(addToStrtab(GV.getPartition()));
1591 Vals.push_back(GV.getPartition().size());
1592
1594 GV.getSanitizerMetadata())
1595 : 0));
1596 Vals.push_back(GV.getCodeModelRaw());
1597 } else {
1598 AbbrevToUse = SimpleGVarAbbrev;
1599 }
1600
1603 }
1604
1605
1607
1608
1609
1610
1611 Vals.push_back(addToStrtab(F.getName()));
1618 Vals.push_back(getEncodedAlign(F.getAlign()));
1619 Vals.push_back(F.hasSection() ? SectionMap[std::string(F.getSection())]
1620 : 0);
1622 Vals.push_back(F.hasGC() ? GCMap[F.getGC()] : 0);
1625 : 0);
1629 : 0);
1631 F.hasPersonalityFn() ? (VE.getValueID(F.getPersonalityFn()) + 1) : 0);
1632
1634 Vals.push_back(F.getAddressSpace());
1635 Vals.push_back(addToStrtab(F.getPartition()));
1636 Vals.push_back(F.getPartition().size());
1637
1638 unsigned AbbrevToUse = 0;
1641 }
1642
1643
1645
1646
1647
1648 Vals.push_back(addToStrtab(A.getName()));
1651 Vals.push_back(A.getType()->getAddressSpace());
1659 Vals.push_back(addToStrtab(A.getPartition()));
1660 Vals.push_back(A.getPartition().size());
1661
1662 unsigned AbbrevToUse = 0;
1665 }
1666
1667
1669
1670
1671 Vals.push_back(addToStrtab(I.getName()));
1674 Vals.push_back(I.getType()->getAddressSpace());
1679 Vals.push_back(addToStrtab(I.getPartition()));
1680 Vals.push_back(I.getPartition().size());
1683 }
1684
1685 writeValueSymbolTableForwardDecl();
1686}
1687
1690
1691 if (const auto *OBO = dyn_cast(V)) {
1692 if (OBO->hasNoSignedWrap())
1694 if (OBO->hasNoUnsignedWrap())
1696 } else if (const auto *PEO = dyn_cast(V)) {
1697 if (PEO->isExact())
1699 } else if (const auto *PDI = dyn_cast(V)) {
1700 if (PDI->isDisjoint())
1702 } else if (const auto *FPMO = dyn_cast(V)) {
1703 if (FPMO->hasAllowReassoc())
1705 if (FPMO->hasNoNaNs())
1707 if (FPMO->hasNoInfs())
1709 if (FPMO->hasNoSignedZeros())
1711 if (FPMO->hasAllowReciprocal())
1713 if (FPMO->hasAllowContract())
1715 if (FPMO->hasApproxFunc())
1717 } else if (const auto *NNI = dyn_cast(V)) {
1718 if (NNI->hasNonNeg())
1720 } else if (const auto *TI = dyn_cast(V)) {
1721 if (TI->hasNoSignedWrap())
1723 if (TI->hasNoUnsignedWrap())
1725 } else if (const auto *GEP = dyn_cast(V)) {
1726 if (GEP->isInBounds())
1728 if (GEP->hasNoUnsignedSignedWrap())
1730 if (GEP->hasNoUnsignedWrap())
1732 } else if (const auto *ICmp = dyn_cast(V)) {
1733 if (ICmp->hasSameSign())
1735 }
1736
1737 return Flags;
1738}
1739
1740void ModuleBitcodeWriter::writeValueAsMetadata(
1742
1748}
1749
1750void ModuleBitcodeWriter::writeMDTuple(const MDTuple *N,
1752 unsigned Abbrev) {
1753 for (const MDOperand &MDO : N->operands()) {
1755 assert(!(MD && isa(MD)) &&
1756 "Unexpected function-local metadata");
1758 }
1763}
1764
1765unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1766
1767
1768 auto Abbv = std::make_shared();
1776 return Stream.EmitAbbrev(std::move(Abbv));
1777}
1778
1779void ModuleBitcodeWriter::writeDILocation(const DILocation *N,
1781 unsigned &Abbrev) {
1782 if (!Abbrev)
1783 Abbrev = createDILocationAbbrev();
1784
1785 Record.push_back(N->isDistinct());
1786 Record.push_back(N->getLine());
1787 Record.push_back(N->getColumn());
1790 Record.push_back(N->isImplicitCode());
1791
1794}
1795
1796unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1797
1798
1799 auto Abbv = std::make_shared();
1807 return Stream.EmitAbbrev(std::move(Abbv));
1808}
1809
1810void ModuleBitcodeWriter::writeGenericDINode(const GenericDINode *N,
1812 unsigned &Abbrev) {
1813 if (!Abbrev)
1814 Abbrev = createGenericDINodeAbbrev();
1815
1816 Record.push_back(N->isDistinct());
1817 Record.push_back(N->getTag());
1818 Record.push_back(0);
1819
1820 for (auto &I : N->operands())
1822
1825}
1826
1827void ModuleBitcodeWriter::writeDISubrange(const DISubrange *N,
1829 unsigned Abbrev) {
1836
1839}
1840
1841void ModuleBitcodeWriter::writeDIGenericSubrange(
1843 unsigned Abbrev) {
1849
1852}
1853
1854void ModuleBitcodeWriter::writeDIEnumerator(const DIEnumerator *N,
1856 unsigned Abbrev) {
1857 const uint64_t IsBigInt = 1 << 2;
1858 Record.push_back(IsBigInt | (N->isUnsigned() << 1) | N->isDistinct());
1859 Record.push_back(N->getValue().getBitWidth());
1862
1865}
1866
1867void ModuleBitcodeWriter::writeDIBasicType(const DIBasicType *N,
1869 unsigned Abbrev) {
1870 Record.push_back(N->isDistinct());
1871 Record.push_back(N->getTag());
1873 Record.push_back(N->getSizeInBits());
1874 Record.push_back(N->getAlignInBits());
1875 Record.push_back(N->getEncoding());
1876 Record.push_back(N->getFlags());
1877 Record.push_back(N->getNumExtraInhabitants());
1878
1881}
1882
1883void ModuleBitcodeWriter::writeDIStringType(const DIStringType *N,
1885 unsigned Abbrev) {
1886 Record.push_back(N->isDistinct());
1887 Record.push_back(N->getTag());
1892 Record.push_back(N->getSizeInBits());
1893 Record.push_back(N->getAlignInBits());
1894 Record.push_back(N->getEncoding());
1895
1898}
1899
1900void ModuleBitcodeWriter::writeDIDerivedType(const DIDerivedType *N,
1902 unsigned Abbrev) {
1903 Record.push_back(N->isDistinct());
1904 Record.push_back(N->getTag());
1907 Record.push_back(N->getLine());
1910 Record.push_back(N->getSizeInBits());
1911 Record.push_back(N->getAlignInBits());
1912 Record.push_back(N->getOffsetInBits());
1913 Record.push_back(N->getFlags());
1915
1916
1917
1918 if (const auto &DWARFAddressSpace = N->getDWARFAddressSpace())
1919 Record.push_back(*DWARFAddressSpace + 1);
1920 else
1921 Record.push_back(0);
1922
1924
1925 if (auto PtrAuthData = N->getPtrAuthData())
1926 Record.push_back(PtrAuthData->RawData);
1927 else
1928 Record.push_back(0);
1929
1932}
1933
1934void ModuleBitcodeWriter::writeDICompositeType(
1936 unsigned Abbrev) {
1937 const unsigned IsNotUsedInOldTypeRef = 0x2;
1938 Record.push_back(IsNotUsedInOldTypeRef | (unsigned)N->isDistinct());
1939 Record.push_back(N->getTag());
1942 Record.push_back(N->getLine());
1945 Record.push_back(N->getSizeInBits());
1946 Record.push_back(N->getAlignInBits());
1947 Record.push_back(N->getOffsetInBits());
1948 Record.push_back(N->getFlags());
1950 Record.push_back(N->getRuntimeLang());
1960 Record.push_back(N->getNumExtraInhabitants());
1962
1965}
1966
1967void ModuleBitcodeWriter::writeDISubroutineType(
1969 unsigned Abbrev) {
1970 const unsigned HasNoOldTypeRefs = 0x2;
1971 Record.push_back(HasNoOldTypeRefs | (unsigned)N->isDistinct());
1972 Record.push_back(N->getFlags());
1974 Record.push_back(N->getCC());
1975
1978}
1979
1980void ModuleBitcodeWriter::writeDIFile(const DIFile *N,
1982 unsigned Abbrev) {
1983 Record.push_back(N->isDistinct());
1986 if (N->getRawChecksum()) {
1987 Record.push_back(N->getRawChecksum()->Kind);
1989 } else {
1990
1991
1992 Record.push_back(0);
1994 }
1995 auto Source = N->getRawSource();
1996 if (Source)
1998
2001}
2002
2003void ModuleBitcodeWriter::writeDICompileUnit(const DICompileUnit *N,
2005 unsigned Abbrev) {
2006 assert(N->isDistinct() && "Expected distinct compile units");
2007 Record.push_back( true);
2008 Record.push_back(N->getSourceLanguage());
2011 Record.push_back(N->isOptimized());
2013 Record.push_back(N->getRuntimeVersion());
2015 Record.push_back(N->getEmissionKind());
2018 Record.push_back( 0);
2021 Record.push_back(N->getDWOId());
2023 Record.push_back(N->getSplitDebugInlining());
2024 Record.push_back(N->getDebugInfoForProfiling());
2025 Record.push_back((unsigned)N->getNameTableKind());
2026 Record.push_back(N->getRangesBaseAddress());
2029
2032}
2033
2034void ModuleBitcodeWriter::writeDISubprogram(const DISubprogram *N,
2036 unsigned Abbrev) {
2037 const uint64_t HasUnitFlag = 1 << 1;
2038 const uint64_t HasSPFlagsFlag = 1 << 2;
2039 Record.push_back(uint64_t(N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
2044 Record.push_back(N->getLine());
2046 Record.push_back(N->getScopeLine());
2048 Record.push_back(N->getSPFlags());
2049 Record.push_back(N->getVirtualIndex());
2050 Record.push_back(N->getFlags());
2055 Record.push_back(N->getThisAdjustment());
2059
2062}
2063
2064void ModuleBitcodeWriter::writeDILexicalBlock(const DILexicalBlock *N,
2066 unsigned Abbrev) {
2067 Record.push_back(N->isDistinct());
2070 Record.push_back(N->getLine());
2071 Record.push_back(N->getColumn());
2072
2075}
2076
2077void ModuleBitcodeWriter::writeDILexicalBlockFile(
2079 unsigned Abbrev) {
2080 Record.push_back(N->isDistinct());
2083 Record.push_back(N->getDiscriminator());
2084
2087}
2088
2089void ModuleBitcodeWriter::writeDICommonBlock(const DICommonBlock *N,
2091 unsigned Abbrev) {
2092 Record.push_back(N->isDistinct());
2097 Record.push_back(N->getLineNo());
2098
2101}
2102
2103void ModuleBitcodeWriter::writeDINamespace(const DINamespace *N,
2105 unsigned Abbrev) {
2106 Record.push_back(N->isDistinct() | N->getExportSymbols() << 1);
2109
2112}
2113
2114void ModuleBitcodeWriter::writeDIMacro(const DIMacro *N,
2116 unsigned Abbrev) {
2117 Record.push_back(N->isDistinct());
2118 Record.push_back(N->getMacinfoType());
2119 Record.push_back(N->getLine());
2122
2125}
2126
2127void ModuleBitcodeWriter::writeDIMacroFile(const DIMacroFile *N,
2129 unsigned Abbrev) {
2130 Record.push_back(N->isDistinct());
2131 Record.push_back(N->getMacinfoType());
2132 Record.push_back(N->getLine());
2135
2138}
2139
2140void ModuleBitcodeWriter::writeDIArgList(const DIArgList *N,
2142 Record.reserve(N->getArgs().size());
2145
2148}
2149
2150void ModuleBitcodeWriter::writeDIModule(const DIModule *N,
2152 unsigned Abbrev) {
2153 Record.push_back(N->isDistinct());
2154 for (auto &I : N->operands())
2156 Record.push_back(N->getLineNo());
2157 Record.push_back(N->getIsDecl());
2158
2161}
2162
2163void ModuleBitcodeWriter::writeDIAssignID(const DIAssignID *N,
2165 unsigned Abbrev) {
2166
2167 Record.push_back(N->isDistinct());
2170}
2171
2172void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2174 unsigned Abbrev) {
2175 Record.push_back(N->isDistinct());
2178 Record.push_back(N->isDefault());
2179
2182}
2183
2184void ModuleBitcodeWriter::writeDITemplateValueParameter(
2186 unsigned Abbrev) {
2187 Record.push_back(N->isDistinct());
2188 Record.push_back(N->getTag());
2191 Record.push_back(N->isDefault());
2193
2196}
2197
2198void ModuleBitcodeWriter::writeDIGlobalVariable(
2200 unsigned Abbrev) {
2207 Record.push_back(N->getLine());
2209 Record.push_back(N->isLocalToUnit());
2210 Record.push_back(N->isDefinition());
2213 Record.push_back(N->getAlignInBits());
2215
2218}
2219
2220void ModuleBitcodeWriter::writeDILocalVariable(
2222 unsigned Abbrev) {
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236 const uint64_t HasAlignmentFlag = 1 << 1;
2237 Record.push_back((uint64_t)N->isDistinct() | HasAlignmentFlag);
2241 Record.push_back(N->getLine());
2243 Record.push_back(N->getArg());
2244 Record.push_back(N->getFlags());
2245 Record.push_back(N->getAlignInBits());
2247
2250}
2251
2252void ModuleBitcodeWriter::writeDILabel(
2254 unsigned Abbrev) {
2259 Record.push_back(N->getLine());
2260
2263}
2264
2265void ModuleBitcodeWriter::writeDIExpression(const DIExpression *N,
2267 unsigned Abbrev) {
2268 Record.reserve(N->getElements().size() + 1);
2271 Record.append(N->elements_begin(), N->elements_end());
2272
2275}
2276
2277void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2279 unsigned Abbrev) {
2280 Record.push_back(N->isDistinct());
2283
2286}
2287
2288void ModuleBitcodeWriter::writeDIObjCProperty(const DIObjCProperty *N,
2290 unsigned Abbrev) {
2291 Record.push_back(N->isDistinct());
2294 Record.push_back(N->getLine());
2297 Record.push_back(N->getAttributes());
2299
2302}
2303
2304void ModuleBitcodeWriter::writeDIImportedEntity(
2306 unsigned Abbrev) {
2307 Record.push_back(N->isDistinct());
2308 Record.push_back(N->getTag());
2311 Record.push_back(N->getLine());
2315
2318}
2319
2320unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2321 auto Abbv = std::make_shared();
2325 return Stream.EmitAbbrev(std::move(Abbv));
2326}
2327
2328void ModuleBitcodeWriter::writeNamedMetadata(
2330 if (M.named_metadata_empty())
2331 return;
2332
2333 unsigned Abbrev = createNamedMetadataAbbrev();
2334 for (const NamedMDNode &NMD : M.named_metadata()) {
2335
2337 Record.append(Str.bytes_begin(), Str.bytes_end());
2340
2341
2342 for (const MDNode *N : NMD.operands())
2346 }
2347}
2348
2349unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2350 auto Abbv = std::make_shared();
2355 return Stream.EmitAbbrev(std::move(Abbv));
2356}
2357
2358
2359
2360
2361
2362void ModuleBitcodeWriter::writeMetadataStrings(
2364 if (Strings.empty())
2365 return;
2366
2367
2369 Record.push_back(Strings.size());
2370
2371
2373 {
2375 for (const Metadata *MD : Strings)
2376 W.EmitVBR(cast(MD)->getLength(), 6);
2377 W.FlushToWord();
2378 }
2379
2380
2382
2383
2384 for (const Metadata *MD : Strings)
2385 Blob.append(cast(MD)->getString());
2386
2387
2390}
2391
2392
2394#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
2395#include "llvm/IR/Metadata.def"
2398
2399void ModuleBitcodeWriter::writeMetadataRecords(
2401 std::vector *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2402 if (MDs.empty())
2403 return;
2404
2405
2406#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
2407#include "llvm/IR/Metadata.def"
2408
2409 for (const Metadata *MD : MDs) {
2410 if (IndexPos)
2412 if (const MDNode *N = dyn_cast(MD)) {
2413 assert(N->isResolved() && "Expected forward references to be resolved");
2414
2415 switch (N->getMetadataID()) {
2416 default:
2418#define HANDLE_MDNODE_LEAF(CLASS) \
2419 case Metadata::CLASS##Kind: \
2420 if (MDAbbrevs) \
2421 write##CLASS(cast(N), Record, \
2422 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
2423 else \
2424 write##CLASS(cast(N), Record, CLASS##Abbrev); \
2425 continue;
2426#include "llvm/IR/Metadata.def"
2427 }
2428 }
2429 if (auto *AL = dyn_cast(MD)) {
2431 continue;
2432 }
2433 writeValueAsMetadata(cast(MD), Record);
2434 }
2435}
2436
2437void ModuleBitcodeWriter::writeModuleMetadata() {
2438 if (!VE.hasMDs() && M.named_metadata_empty())
2439 return;
2440
2443
2444
2445
2446 std::vector MDAbbrevs;
2447
2449 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2450 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2451 createGenericDINodeAbbrev();
2452
2453 auto Abbv = std::make_shared();
2457 unsigned OffsetAbbrev = Stream.EmitAbbrev(std::move(Abbv));
2458
2459 Abbv = std::make_shared();
2463 unsigned IndexAbbrev = Stream.EmitAbbrev(std::move(Abbv));
2464
2465
2467
2468
2469
2471
2472
2473
2474
2477 }
2478
2479
2480
2481
2483
2484
2485 std::vector<uint64_t> IndexPos;
2487
2488
2490
2492
2493
2494
2495
2498
2499
2500 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2501 for (auto &Elt : IndexPos) {
2502 auto EltDelta = Elt - PreviousValue;
2503 PreviousValue = Elt;
2504 Elt = EltDelta;
2505 }
2506
2508 IndexPos.clear();
2509 }
2510
2511
2512 writeNamedMetadata(Record);
2513
2514 auto AddDeclAttachedMetadata = [&](const GlobalObject &GO) {
2517 pushGlobalMetadataAttachment(Record, GO);
2519 };
2521 if (F.isDeclaration() && F.hasMetadata())
2522 AddDeclAttachedMetadata(F);
2523
2524
2526 if (GV.hasMetadata())
2527 AddDeclAttachedMetadata(GV);
2528
2530}
2531
2532void ModuleBitcodeWriter::writeFunctionMetadata(const Function &F) {
2534 return;
2535
2541}
2542
2543void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2545
2548 for (const auto &I : MDs) {
2549 Record.push_back(I.first);
2551 }
2552}
2553
2554void ModuleBitcodeWriter::writeFunctionMetadataAttachment(const Function &F) {
2556
2558
2559 if (F.hasMetadata()) {
2560 pushGlobalMetadataAttachment(Record, F);
2563 }
2564
2565
2566
2571 I.getAllMetadataOtherThanDebugLoc(MDs);
2572
2573
2574 if (MDs.empty()) continue;
2575
2577
2578 for (unsigned i = 0, e = MDs.size(); i != e; ++i) {
2579 Record.push_back(MDs[i].first);
2581 }
2584 }
2585
2587}
2588
2589void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2591
2592
2593
2595 M.getMDKindNames(Names);
2596
2597 if (Names.empty()) return;
2598
2600
2601 for (unsigned MDKindID = 0, e = Names.size(); MDKindID != e; ++MDKindID) {
2602 Record.push_back(MDKindID);
2603 StringRef KName = Names[MDKindID];
2605
2608 }
2609
2611}
2612
2613void ModuleBitcodeWriter::writeOperandBundleTags() {
2614
2615
2616
2617
2618
2619
2621 M.getOperandBundleTags(Tags);
2622
2623 if (Tags.empty())
2624 return;
2625
2627
2629
2630 for (auto Tag : Tags) {
2632
2635 }
2636
2638}
2639
2640void ModuleBitcodeWriter::writeSyncScopeNames() {
2642 M.getContext().getSyncScopeNames(SSNs);
2643 if (SSNs.empty())
2644 return;
2645
2647
2649 for (auto SSN : SSNs) {
2650 Record.append(SSN.begin(), SSN.end());
2653 }
2654
2656}
2657
2658void ModuleBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
2659 bool isGlobal) {
2660 if (FirstVal == LastVal) return;
2661
2663
2664 unsigned AggregateAbbrev = 0;
2665 unsigned String8Abbrev = 0;
2666 unsigned CString7Abbrev = 0;
2667 unsigned CString6Abbrev = 0;
2668
2669 if (isGlobal) {
2670
2671 auto Abbv = std::make_shared();
2675 AggregateAbbrev = Stream.EmitAbbrev(std::move(Abbv));
2676
2677
2678 Abbv = std::make_shared();
2682 String8Abbrev = Stream.EmitAbbrev(std::move(Abbv));
2683
2684 Abbv = std::make_shared();
2688 CString7Abbrev = Stream.EmitAbbrev(std::move(Abbv));
2689
2690 Abbv = std::make_shared();
2694 CString6Abbrev = Stream.EmitAbbrev(std::move(Abbv));
2695 }
2696
2698
2700 Type *LastTy = nullptr;
2701 for (unsigned i = FirstVal; i != LastVal; ++i) {
2702 const Value *V = Vals[i].first;
2703
2704 if (V->getType() != LastTy) {
2705 LastTy = V->getType();
2708 CONSTANTS_SETTYPE_ABBREV);
2710 }
2711
2712 if (const InlineAsm *IA = dyn_cast(V)) {
2715 unsigned(IA->hasSideEffects()) | unsigned(IA->isAlignStack()) << 1 |
2716 unsigned(IA->getDialect() & 1) << 2 | unsigned(IA->canThrow()) << 3);
2717
2718
2719 const std::string &AsmStr = IA->getAsmString();
2720 Record.push_back(AsmStr.size());
2721 Record.append(AsmStr.begin(), AsmStr.end());
2722
2723
2724 const std::string &ConstraintStr = IA->getConstraintString();
2725 Record.push_back(ConstraintStr.size());
2726 Record.append(ConstraintStr.begin(), ConstraintStr.end());
2729 continue;
2730 }
2731 const Constant *C = cast(V);
2732 unsigned Code = -1U;
2733 unsigned AbbrevToUse = 0;
2734 if (C->isNullValue()) {
2736 } else if (isa(C)) {
2738 } else if (isa(C)) {
2740 } else if (const ConstantInt *IV = dyn_cast(C)) {
2741 if (IV->getBitWidth() <= 64) {
2745 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2746 } else {
2749 }
2750 } else if (const ConstantFP *CFP = dyn_cast(C)) {
2755 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2757
2758
2759 APInt api = CFP->getValueAPF().bitcastToAPInt();
2761 Record.push_back((p[1] << 48) | (p[0] >> 16));
2762 Record.push_back(p[0] & 0xffffLL);
2764 APInt api = CFP->getValueAPF().bitcastToAPInt();
2766 Record.push_back(p[0]);
2767 Record.push_back(p[1]);
2768 } else {
2769 assert(0 && "Unknown FP type!");
2770 }
2771 } else if (isa(C) &&
2772 cast(C)->isString()) {
2774
2775 unsigned NumElts = Str->getNumElements();
2776
2777 if (Str->isCString()) {
2779 --NumElts;
2780 } else {
2782 AbbrevToUse = String8Abbrev;
2783 }
2786 for (unsigned i = 0; i != NumElts; ++i) {
2787 unsigned char V = Str->getElementAsInteger(i);
2788 Record.push_back(V);
2789 isCStr7 &= (V & 128) == 0;
2790 if (isCStrChar6)
2792 }
2793
2794 if (isCStrChar6)
2795 AbbrevToUse = CString6Abbrev;
2796 else if (isCStr7)
2797 AbbrevToUse = CString7Abbrev;
2799 dyn_cast(C)) {
2801 Type *EltTy = CDS->getElementType();
2802 if (isa(EltTy)) {
2803 for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2804 Record.push_back(CDS->getElementAsInteger(i));
2805 } else {
2806 for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2808 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2809 }
2810 } else if (isa(C)) {
2812 for (const Value *Op : C->operands())
2814 AbbrevToUse = AggregateAbbrev;
2815 } else if (const ConstantExpr *CE = dyn_cast(C)) {
2816 switch (CE->getOpcode()) {
2817 default:
2821 Record.push_back(VE.getTypeID(C->getOperand(0)->getType()));
2823 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2824 } else {
2825 assert(CE->getNumOperands() == 2 && "Unknown constant expr!");
2831 if (Flags != 0)
2832 Record.push_back(Flags);
2833 }
2834 break;
2835 case Instruction::FNeg: {
2836 assert(CE->getNumOperands() == 1 && "Unknown constant expr!");
2841 if (Flags != 0)
2842 Record.push_back(Flags);
2843 break;
2844 }
2845 case Instruction::GetElementPtr: {
2847 const auto *GO = cast(C);
2848 Record.push_back(VE.getTypeID(GO->getSourceElementType()));
2850 if (std::optional Range = GO->getInRange()) {
2853 }
2854 for (const Value *Op : CE->operands()) {
2857 }
2858 break;
2859 }
2860 case Instruction::ExtractElement:
2862 Record.push_back(VE.getTypeID(C->getOperand(0)->getType()));
2864 Record.push_back(VE.getTypeID(C->getOperand(1)->getType()));
2866 break;
2867 case Instruction::InsertElement:
2871 Record.push_back(VE.getTypeID(C->getOperand(2)->getType()));
2873 break;
2874 case Instruction::ShuffleVector:
2875
2876
2877
2878
2879 if (C->getType() == C->getOperand(0)->getType()) {
2881 } else {
2883 Record.push_back(VE.getTypeID(C->getOperand(0)->getType()));
2884 }
2888 break;
2889 }
2890 } else if (const BlockAddress *BA = dyn_cast(C)) {
2892 Record.push_back(VE.getTypeID(BA->getFunction()->getType()));
2895 } else if (const auto *Equiv = dyn_cast(C)) {
2897 Record.push_back(VE.getTypeID(Equiv->getGlobalValue()->getType()));
2899 } else if (const auto *NC = dyn_cast(C)) {
2901 Record.push_back(VE.getTypeID(NC->getGlobalValue()->getType()));
2903 } else if (const auto *CPA = dyn_cast(C)) {
2908 Record.push_back(VE.getValueID(CPA->getAddrDiscriminator()));
2909 } else {
2910#ifndef NDEBUG
2911 C->dump();
2912#endif
2914 }
2917 }
2918
2920}
2921
2922void ModuleBitcodeWriter::writeModuleConstants() {
2924
2925
2926
2927 for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
2928 if (!isa(Vals[i].first)) {
2929 writeConstants(i, Vals.size(), true);
2930 return;
2931 }
2932 }
2933}
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943bool ModuleBitcodeWriter::pushValueAndType(const Value *V, unsigned InstID,
2946
2948 if (ValID >= InstID) {
2950 return true;
2951 }
2952 return false;
2953}
2954
2955bool ModuleBitcodeWriter::pushValueOrMetadata(const Value *V, unsigned InstID,
2957 bool IsMetadata = V->getType()->isMetadataTy();
2958 if (IsMetadata) {
2960 Metadata *MD = cast(V)->getMetadata();
2963 return false;
2964 }
2965 return pushValueAndType(V, InstID, Vals);
2966}
2967
2968void ModuleBitcodeWriter::writeOperandBundles(const CallBase &CS,
2969 unsigned InstID) {
2972
2975 Record.push_back(C.getOperandBundleTagID(Bundle.getTagName()));
2976
2977 for (auto &Input : Bundle.Inputs)
2978 pushValueOrMetadata(Input, InstID, Record);
2979
2982 }
2983}
2984
2985
2986
2987void ModuleBitcodeWriter::pushValue(const Value *V, unsigned InstID,
2991}
2992
2993void ModuleBitcodeWriter::pushValueSigned(const Value *V, unsigned InstID,
2996 int64_t diff = ((int32_t)InstID - (int32_t)ValID);
2998}
2999
3000
3001void ModuleBitcodeWriter::writeInstruction(const Instruction &I,
3002 unsigned InstID,
3004 unsigned Code = 0;
3005 unsigned AbbrevToUse = 0;
3007 switch (I.getOpcode()) {
3008 default:
3011 if (!pushValueAndType(I.getOperand(0), InstID, Vals))
3012 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
3016 if (Flags != 0) {
3017 if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
3018 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
3020 }
3021 } else {
3022 assert(isa(I) && "Unknown instruction!");
3024 if (!pushValueAndType(I.getOperand(0), InstID, Vals))
3025 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
3026 pushValue(I.getOperand(1), InstID, Vals);
3029 if (Flags != 0) {
3030 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
3031 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
3033 }
3034 }
3035 break;
3036 case Instruction::FNeg: {
3038 if (!pushValueAndType(I.getOperand(0), InstID, Vals))
3039 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
3042 if (Flags != 0) {
3043 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
3044 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
3046 }
3047 break;
3048 }
3049 case Instruction::GetElementPtr: {
3051 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
3052 auto &GEPInst = cast(I);
3055 for (const Value *Op : I.operands())
3056 pushValueAndType(Op, InstID, Vals);
3057 break;
3058 }
3059 case Instruction::ExtractValue: {
3061 pushValueAndType(I.getOperand(0), InstID, Vals);
3064 break;
3065 }
3066 case Instruction::InsertValue: {
3068 pushValueAndType(I.getOperand(0), InstID, Vals);
3069 pushValueAndType(I.getOperand(1), InstID, Vals);
3072 break;
3073 }
3074 case Instruction::Select: {
3076 pushValueAndType(I.getOperand(1), InstID, Vals);
3077 pushValue(I.getOperand(2), InstID, Vals);
3078 pushValueAndType(I.getOperand(0), InstID, Vals);
3080 if (Flags != 0)
3082 break;
3083 }
3084 case Instruction::ExtractElement:
3086 pushValueAndType(I.getOperand(0), InstID, Vals);
3087 pushValueAndType(I.getOperand(1), InstID, Vals);
3088 break;
3089 case Instruction::InsertElement:
3091 pushValueAndType(I.getOperand(0), InstID, Vals);
3092 pushValue(I.getOperand(1), InstID, Vals);
3093 pushValueAndType(I.getOperand(2), InstID, Vals);
3094 break;
3095 case Instruction::ShuffleVector:
3097 pushValueAndType(I.getOperand(0), InstID, Vals);
3098 pushValue(I.getOperand(1), InstID, Vals);
3099 pushValue(cast(I).getShuffleMaskForBitcode(), InstID,
3100 Vals);
3101 break;
3102 case Instruction::ICmp:
3103 case Instruction::FCmp: {
3104
3106 pushValueAndType(I.getOperand(0), InstID, Vals);
3107 pushValue(I.getOperand(1), InstID, Vals);
3110 if (Flags != 0)
3112 break;
3113 }
3114
3115 case Instruction::Ret:
3116 {
3118 unsigned NumOperands = I.getNumOperands();
3119 if (NumOperands == 0)
3120 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
3121 else if (NumOperands == 1) {
3122 if (!pushValueAndType(I.getOperand(0), InstID, Vals))
3123 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
3124 } else {
3125 for (const Value *Op : I.operands())
3126 pushValueAndType(Op, InstID, Vals);
3127 }
3128 }
3129 break;
3130 case Instruction::Br:
3131 {
3135 if (II.isConditional()) {
3137 pushValue(II.getCondition(), InstID, Vals);
3138 }
3139 }
3140 break;
3141 case Instruction::Switch:
3142 {
3146 pushValue(SI.getCondition(), InstID, Vals);
3148 for (auto Case : SI.cases()) {
3151 }
3152 }
3153 break;
3154 case Instruction::IndirectBr:
3157
3158 pushValue(I.getOperand(0), InstID, Vals);
3161 break;
3162
3163 case Instruction::Invoke: {
3167
3168 if (II->hasOperandBundles())
3169 writeOperandBundles(*II, InstID);
3170
3172
3174 Vals.push_back(II->getCallingConv() | 1 << 13);
3178 pushValueAndType(Callee, InstID, Vals);
3179
3180
3181 for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3182 pushValue(I.getOperand(i), InstID, Vals);
3183
3184
3185 if (FTy->isVarArg()) {
3186 for (unsigned i = FTy->getNumParams(), e = II->arg_size(); i != e; ++i)
3187 pushValueAndType(I.getOperand(i), InstID, Vals);
3188 }
3189 break;
3190 }
3191 case Instruction::Resume:
3193 pushValueAndType(I.getOperand(0), InstID, Vals);
3194 break;
3195 case Instruction::CleanupRet: {
3197 const auto &CRI = cast(I);
3198 pushValue(CRI.getCleanupPad(), InstID, Vals);
3199 if (CRI.hasUnwindDest())
3201 break;
3202 }
3203 case Instruction::CatchRet: {
3205 const auto &CRI = cast(I);
3206 pushValue(CRI.getCatchPad(), InstID, Vals);
3208 break;
3209 }
3210 case Instruction::CleanupPad:
3211 case Instruction::CatchPad: {
3212 const auto &FuncletPad = cast(I);
3215 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3216
3217 unsigned NumArgOperands = FuncletPad.arg_size();
3219 for (unsigned Op = 0; Op != NumArgOperands; ++Op)
3220 pushValueAndType(FuncletPad.getArgOperand(Op), InstID, Vals);
3221 break;
3222 }
3223 case Instruction::CatchSwitch: {
3225 const auto &CatchSwitch = cast(I);
3226
3227 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3228
3229 unsigned NumHandlers = CatchSwitch.getNumHandlers();
3231 for (const BasicBlock *CatchPadBB : CatchSwitch.handlers())
3233
3234 if (CatchSwitch.hasUnwindDest())
3236 break;
3237 }
3238 case Instruction::CallBr: {
3239 const CallBrInst *CBI = cast(&I);
3242
3244 writeOperandBundles(*CBI, InstID);
3245
3247
3249
3252
3257
3259 pushValueAndType(Callee, InstID, Vals);
3260
3261
3262 for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3263 pushValue(I.getOperand(i), InstID, Vals);
3264
3265
3266 if (FTy->isVarArg()) {
3267 for (unsigned i = FTy->getNumParams(), e = CBI->arg_size(); i != e; ++i)
3268 pushValueAndType(I.getOperand(i), InstID, Vals);
3269 }
3270 break;
3271 }
3272 case Instruction::Unreachable:
3274 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3275 break;
3276
3277 case Instruction::PHI: {
3278 const PHINode &PN = cast(I);
3280
3281
3282
3288 }
3289
3291 if (Flags != 0)
3293
3294
3295 Stream.EmitRecord(Code, Vals64, AbbrevToUse);
3297 return;
3298 }
3299
3300 case Instruction::LandingPad: {
3309 else
3311 pushValueAndType(LP.getClause(I), InstID, Vals);
3312 }
3313 break;
3314 }
3315
3316 case Instruction::Alloca: {
3318 const AllocaInst &AI = cast(I);
3323 unsigned Record = 0;
3324 unsigned EncodedAlign = getEncodedAlign(AI.getAlign());
3325 Bitfield::setAPV::AlignLower(
3326 Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3327 Bitfield::setAPV::AlignUpper(Record,
3328 EncodedAlign >> APV::AlignLower::Bits);
3330 Bitfield::setAPV::ExplicitType(Record, true);
3333
3335 if (AS != M.getDataLayout().getAllocaAddrSpace())
3337 break;
3338 }
3339
3340 case Instruction::Load:
3341 if (cast(I).isAtomic()) {
3343 pushValueAndType(I.getOperand(0), InstID, Vals);
3344 } else {
3346 if (!pushValueAndType(I.getOperand(0), InstID, Vals))
3347 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3348 }
3351 Vals.push_back(cast(I).isVolatile());
3352 if (cast(I).isAtomic()) {
3354 Vals.push_back(getEncodedSyncScopeID(cast(I).getSyncScopeID()));
3355 }
3356 break;
3357 case Instruction::Store:
3358 if (cast(I).isAtomic())
3360 else
3362 pushValueAndType(I.getOperand(1), InstID, Vals);
3363 pushValueAndType(I.getOperand(0), InstID, Vals);
3365 Vals.push_back(cast(I).isVolatile());
3366 if (cast(I).isAtomic()) {
3369 getEncodedSyncScopeID(cast(I).getSyncScopeID()));
3370 }
3371 break;
3372 case Instruction::AtomicCmpXchg:
3374 pushValueAndType(I.getOperand(0), InstID, Vals);
3375 pushValueAndType(I.getOperand(1), InstID, Vals);
3376 pushValue(I.getOperand(2), InstID, Vals);
3377 Vals.push_back(cast(I).isVolatile());
3381 getEncodedSyncScopeID(cast(I).getSyncScopeID()));
3384 Vals.push_back(cast(I).isWeak());
3385 Vals.push_back(getEncodedAlign(cast(I).getAlign()));
3386 break;
3387 case Instruction::AtomicRMW:
3389 pushValueAndType(I.getOperand(0), InstID, Vals);
3390 pushValueAndType(I.getOperand(1), InstID, Vals);
3393 Vals.push_back(cast(I).isVolatile());
3396 getEncodedSyncScopeID(cast(I).getSyncScopeID()));
3398 break;
3399 case Instruction::Fence:
3402 Vals.push_back(getEncodedSyncScopeID(cast(I).getSyncScopeID()));
3403 break;
3404 case Instruction::Call: {
3405 const CallInst &CI = cast(I);
3407
3409 writeOperandBundles(CI, InstID);
3410
3412
3414
3422 if (Flags != 0)
3424
3426 pushValueAndType(CI.getCalledOperand(), InstID, Vals);
3427
3428
3429 for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3430
3431 if (FTy->getParamType(i)->isLabelTy())
3433 else
3434 pushValue(CI.getArgOperand(i), InstID, Vals);
3435 }
3436
3437
3438 if (FTy->isVarArg()) {
3439 for (unsigned i = FTy->getNumParams(), e = CI.arg_size(); i != e; ++i)
3440 pushValueAndType(CI.getArgOperand(i), InstID, Vals);
3441 }
3442 break;
3443 }
3444 case Instruction::VAArg:
3447 pushValue(I.getOperand(0), InstID, Vals);
3449 break;
3450 case Instruction::Freeze:
3452 pushValueAndType(I.getOperand(0), InstID, Vals);
3453 break;
3454 }
3455
3456 Stream.EmitRecord(Code, Vals, AbbrevToUse);
3458}
3459
3460
3461
3462void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3464
3465
3467
3468 VSTOffset -= bitcodeStartBit();
3469 assert((VSTOffset & 31) == 0 && "VST block not 32-bit aligned");
3470
3471
3472
3473 Stream.BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3474
3476
3477 auto Abbv = std::make_shared();
3481 unsigned FnEntryAbbrev = Stream.EmitAbbrev(std::move(Abbv));
3482
3485
3486 if (F.isDeclaration())
3487 continue;
3488
3490
3491
3492
3493 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&F] - bitcodeStartBit();
3494 assert((BitcodeIndex & 31) == 0 && "function block not 32-bit aligned");
3495
3496
3497
3498 Record[1] = BitcodeIndex / 32 + 1;
3499
3501 }
3502
3504}
3505
3506
3507void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3509 if (VST.empty())
3510 return;
3511
3513
3514
3515
3517
3519
3521
3522 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3524
3525
3526
3527 unsigned Code;
3528 if (isa(Name.getValue())) {
3531 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3532 } else {
3535 AbbrevToUse = VST_ENTRY_6_ABBREV;
3537 AbbrevToUse = VST_ENTRY_7_ABBREV;
3538 }
3539
3540 for (const auto P : Name.getKey())
3541 NameVals.push_back((unsigned char)P);
3542
3543
3544 Stream.EmitRecord(Code, NameVals, AbbrevToUse);
3545 NameVals.clear();
3546 }
3547
3549}
3550
3551void ModuleBitcodeWriter::writeUseList(UseListOrder &&Order) {
3552 assert(Order.Shuffle.size() >= 2 && "Shuffle too small");
3553 unsigned Code;
3554 if (isa(Order.V))
3556 else
3558
3562}
3563
3564void ModuleBitcodeWriter::writeUseListBlock(const Function *F) {
3566 "Expected to be preserving use-list order");
3567
3568 auto hasMore = [&]() {
3570 };
3571 if (!hasMore())
3572
3573 return;
3574
3576 while (hasMore()) {
3577 writeUseList(std::move(VE.UseListOrders.back()));
3579 }
3581}
3582
3583
3584void ModuleBitcodeWriter::writeFunction(
3587
3588
3590
3593
3595
3596
3597
3601
3602
3603 unsigned CstStart, CstEnd;
3605 writeConstants(CstStart, CstEnd, false);
3606
3607
3608 writeFunctionMetadata(F);
3609
3610
3611 unsigned InstID = CstEnd;
3612
3613 bool NeedsMetadataAttachment = F.hasMetadata();
3614
3617
3618
3621 writeInstruction(I, InstID, Vals);
3622
3623 if (.getType()->isVoidTy())
3624 ++InstID;
3625
3626
3627 NeedsMetadataAttachment |= I.hasMetadataOtherThanDebugLoc();
3628
3629
3631 if (DL == LastDL) {
3632
3634 } else {
3642 LastDL = DL;
3643 }
3644 }
3645
3646
3647
3648
3649
3651
3652
3653
3654 auto PushValueOrMetadata = [&Vals, InstID,
3655 this](Metadata *RawLocation) {
3656 assert(RawLocation &&
3657 "RawLocation unexpectedly null in DbgVariableRecord");
3658 if (ValueAsMetadata *VAM = dyn_cast(RawLocation)) {
3660
3661
3662
3663 if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
3665 return true;
3666 }
3667 }
3668
3669
3671 return false;
3672 };
3673
3674
3675
3676
3677 for (DbgRecord &DR : I.DebugMarker->getDbgRecordRange()) {
3678 if (DbgLabelRecord *DLR = dyn_cast(&DR)) {
3683 continue;
3684 }
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3703 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3704 else
3709 } else {
3716 }
3718 }
3719 }
3720 }
3721
3725 while (!Worklist.empty()) {
3726 Value *V = Worklist.pop_back_val();
3727 for (User *U : V->users()) {
3728 if (auto *I = dyn_cast(U)) {
3731 BlockAddressUsers.insert(P);
3732 } else if (isa(U) && !isa(U) &&
3733 Visited.insert(U).second)
3734 Worklist.push_back(U);
3735 }
3736 }
3737 }
3738 }
3739
3740 if (!BlockAddressUsers.empty()) {
3741 Vals.resize(BlockAddressUsers.size());
3746 }
3747
3748
3749 if (auto *Symtab = F.getValueSymbolTable())
3750 writeFunctionLevelValueSymbolTable(*Symtab);
3751
3752 if (NeedsMetadataAttachment)
3753 writeFunctionMetadataAttachment(F);
3755 writeUseListBlock(&F);
3758}
3759
3760
3761void ModuleBitcodeWriter::writeBlockInfo() {
3762
3763
3764
3766
3767 {
3768 auto Abbv = std::make_shared();
3774 VST_ENTRY_8_ABBREV)
3776 }
3777
3778 {
3779 auto Abbv = std::make_shared();
3785 VST_ENTRY_7_ABBREV)
3787 }
3788 {
3789 auto Abbv = std::make_shared();
3795 VST_ENTRY_6_ABBREV)
3797 }
3798 {
3799 auto Abbv = std::make_shared();
3805 VST_BBENTRY_6_ABBREV)
3807 }
3808
3809 {
3810 auto Abbv = std::make_shared();
3815 CONSTANTS_SETTYPE_ABBREV)
3817 }
3818
3819 {
3820 auto Abbv = std::make_shared();
3824 CONSTANTS_INTEGER_ABBREV)
3826 }
3827
3828 {
3829 auto Abbv = std::make_shared();
3835
3837 CONSTANTS_CE_CAST_Abbrev)
3839 }
3840 {
3841 auto Abbv = std::make_shared();
3844 CONSTANTS_NULL_Abbrev)
3846 }
3847
3848
3849
3850 {
3851 auto Abbv = std::make_shared();
3859 FUNCTION_INST_LOAD_ABBREV)
3861 }
3862 {
3863 auto Abbv = std::make_shared();
3868 FUNCTION_INST_UNOP_ABBREV)
3870 }
3871 {
3872 auto Abbv = std::make_shared();
3878 FUNCTION_INST_UNOP_FLAGS_ABBREV)
3880 }
3881 {
3882 auto Abbv = std::make_shared();
3888 FUNCTION_INST_BINOP_ABBREV)
3890 }
3891 {
3892 auto Abbv = std::make_shared();
3899 FUNCTION_INST_BINOP_FLAGS_ABBREV)
3901 }
3902 {
3903 auto Abbv = std::make_shared();
3910 FUNCTION_INST_CAST_ABBREV)
3912 }
3913 {
3914 auto Abbv = std::make_shared();
3922 FUNCTION_INST_CAST_FLAGS_ABBREV)
3924 }
3925
3926 {
3927 auto Abbv = std::make_shared();
3930 FUNCTION_INST_RET_VOID_ABBREV)
3932 }
3933 {
3934 auto Abbv = std::make_shared();
3938 FUNCTION_INST_RET_VAL_ABBREV)
3940 }
3941 {
3942 auto Abbv = std::make_shared();
3945 FUNCTION_INST_UNREACHABLE_ABBREV)
3947 }
3948 {
3949 auto Abbv = std::make_shared();
3957 FUNCTION_INST_GEP_ABBREV)
3959 }
3960 {
3961 auto Abbv = std::make_shared();
3968 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
3970 }
3972}
3973
3974
3975
3976void IndexBitcodeWriter::writeModStrings() {
3978
3979
3980
3981
3982 auto Abbv = std::make_shared();
3987 unsigned Abbrev8Bit = Stream.EmitAbbrev(std::move(Abbv));
3988
3989
3990 Abbv = std::make_shared();
3995 unsigned Abbrev7Bit = Stream.EmitAbbrev(std::move(Abbv));
3996
3997
3998 Abbv = std::make_shared();
4003 unsigned Abbrev6Bit = Stream.EmitAbbrev(std::move(Abbv));
4004
4005
4006 Abbv = std::make_shared();
4013 unsigned AbbrevHash = Stream.EmitAbbrev(std::move(Abbv));
4014
4018 const auto &Hash = MPSE.getValue();
4020 unsigned AbbrevToUse = Abbrev8Bit;
4022 AbbrevToUse = Abbrev6Bit;
4024 AbbrevToUse = Abbrev7Bit;
4025
4026 auto ModuleId = ModuleIdMap.size();
4027 ModuleIdMap[Key] = ModuleId;
4030
4031
4033
4034
4036 Vals.assign(Hash.begin(), Hash.end());
4037
4039 }
4040
4042 });
4044}
4045
4046
4047
4048template
4051 Fn GetValueID) {
4052 if (!FS->type_tests().empty())
4054
4056
4057 auto WriteVFuncIdVec = [&](uint64_t Ty,
4059 if (VFs.empty())
4060 return;
4062 for (auto &VF : VFs) {
4063 Record.push_back(VF.GUID);
4064 Record.push_back(VF.Offset);
4065 }
4067 };
4068
4070 FS->type_test_assume_vcalls());
4072 FS->type_checked_load_vcalls());
4073
4074 auto WriteConstVCallVec = [&](uint64_t Ty,
4076 for (auto &VC : VCs) {
4078 Record.push_back(VC.VFunc.GUID);
4079 Record.push_back(VC.VFunc.Offset);
4082 }
4083 };
4084
4086 FS->type_test_assume_const_vcalls());
4088 FS->type_checked_load_const_vcalls());
4089
4096 };
4097
4098 if (!FS->paramAccesses().empty()) {
4100 for (auto &Arg : FS->paramAccesses()) {
4101 size_t UndoSize = Record.size();
4102 Record.push_back(Arg.ParamNo);
4103 WriteRange(Arg.Use);
4104 Record.push_back(Arg.Calls.size());
4105 for (auto &Call : Arg.Calls) {
4106 Record.push_back(Call.ParamNo);
4107 std::optional ValueID = GetValueID(Call.Callee);
4108 if (!ValueID) {
4109
4110
4111 Record.resize(UndoSize);
4112 break;
4113 }
4114 Record.push_back(*ValueID);
4115 WriteRange(Call.Offsets);
4116 }
4117 }
4118 if (.empty())
4120 }
4121}
4122
4123
4124static void
4126 std::setGlobalValue::GUID &ReferencedTypeIds) {
4127 if (!FS->type_tests().empty())
4128 for (auto &TT : FS->type_tests())
4129 ReferencedTypeIds.insert(TT);
4130
4131 auto GetReferencedTypesFromVFuncIdVec =
4133 for (auto &VF : VFs)
4134 ReferencedTypeIds.insert(VF.GUID);
4135 };
4136
4137 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4138 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4139
4140 auto GetReferencedTypesFromConstVCallVec =
4142 for (auto &VC : VCs)
4143 ReferencedTypeIds.insert(VC.VFunc.GUID);
4144 };
4145
4146 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4147 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
4148}
4149
4155
4160}
4161
4166
4170
4174}
4175
4182
4183 NameVals.push_back(Summary.TTRes.TheKind);
4184 NameVals.push_back(Summary.TTRes.SizeM1BitWidth);
4185 NameVals.push_back(Summary.TTRes.AlignLog2);
4186 NameVals.push_back(Summary.TTRes.SizeM1);
4187 NameVals.push_back(Summary.TTRes.BitMask);
4188 NameVals.push_back(Summary.TTRes.InlineBits);
4189
4190 for (auto &W : Summary.WPDRes)
4192 W.second);
4193}
4194
4201
4202 for (auto &P : Summary) {
4203 NameVals.push_back(P.AddressPointOffset);
4205 }
4206}
4207
4208
4209
4210
4211
4215
4216
4217
4218 static_assert(std::is_same_v<LinearFrameId, unsigned>);
4219 for (auto &AI : FS->allocs()) {
4220 for (auto &MIB : AI.MIBs) {
4222 StackIdIndices.reserve(MIB.StackIdIndices.size());
4223 for (auto Id : MIB.StackIdIndices)
4224 StackIdIndices.push_back(GetStackIndex(Id));
4225
4226 CallStacks.insert({CallStacks.size(), StackIdIndices});
4227 }
4228 }
4229}
4230
4231
4232
4233
4234
4235
4239 assert(!CallStacks.empty());
4243
4244
4245 Builder.build(std::move(CallStacks), nullptr,
4246 FrameHistogram);
4248 RadixAbbrev);
4250}
4251
4254 unsigned AllocAbbrev, unsigned ContextIdAbbvId, bool PerModule,
4255 std::function<unsigned(const ValueInfo &VI)> GetValueID,
4256 std::function<unsigned(unsigned)> GetStackIndex,
4257 bool WriteContextSizeInfoIndex,
4261
4262 for (auto &CI : FS->callsites()) {
4264
4265
4266 assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4267 Record.push_back(GetValueID(CI.Callee));
4268 if (!PerModule) {
4269 Record.push_back(CI.StackIdIndices.size());
4270 Record.push_back(CI.Clones.size());
4271 }
4272 for (auto Id : CI.StackIdIndices)
4273 Record.push_back(GetStackIndex(Id));
4274 if (!PerModule) {
4275 for (auto V : CI.Clones)
4276 Record.push_back(V);
4277 }
4280 Record, CallsiteAbbrev);
4281 }
4282
4283 for (auto &AI : FS->allocs()) {
4285
4286
4287 assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4288 Record.push_back(AI.MIBs.size());
4289 if (!PerModule)
4290 Record.push_back(AI.Versions.size());
4291 for (auto &MIB : AI.MIBs) {
4293
4294 assert(CallStackCount <= CallStackPos.size());
4295 Record.push_back(CallStackPos[CallStackCount++]);
4296 }
4297 if (!PerModule) {
4298 for (auto V : AI.Versions)
4299 Record.push_back(V);
4300 }
4301 assert(AI.ContextSizeInfos.empty() ||
4302 AI.ContextSizeInfos.size() == AI.MIBs.size());
4303
4304 if (WriteContextSizeInfoIndex && !AI.ContextSizeInfos.empty()) {
4305
4306
4307
4308 assert(ContextIdAbbvId);
4310
4311
4312 ContextIds.reserve(AI.ContextSizeInfos.size() * 2);
4313 for (auto &Infos : AI.ContextSizeInfos) {
4314 Record.push_back(Infos.size());
4315 for (auto [FullStackId, TotalSize] : Infos) {
4316
4317
4318
4319
4322 Record.push_back(TotalSize);
4323 }
4324 }
4325
4326
4328 ContextIdAbbvId);
4329 }
4332 Record, AllocAbbrev);
4333 }
4334}
4335
4336
4337void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4339 unsigned ValueID, unsigned FSCallsRelBFAbbrev,
4340 unsigned FSCallsProfileAbbrev, unsigned CallsiteAbbrev,
4341 unsigned AllocAbbrev, unsigned ContextIdAbbvId, const Function &F,
4345
4347
4349 Stream, FS, [&](const ValueInfo &VI) -> std::optional {
4351 });
4352
4354 Stream, FS, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
4355 true,
4356 [&](const ValueInfo &VI) { return getValueId(VI); },
4357 [&](unsigned I) { return I; },
4358 true, CallStackPos, CallStackCount);
4359
4360 auto SpecialRefCnts = FS->specialRefCounts();
4365 NameVals.push_back(SpecialRefCnts.first);
4366 NameVals.push_back(SpecialRefCnts.second);
4367
4368 for (auto &RI : FS->refs())
4369 NameVals.push_back(getValueId(RI));
4370
4371 const bool UseRelBFRecord =
4374 for (auto &ECI : FS->calls()) {
4375 NameVals.push_back(getValueId(ECI.first));
4376 if (UseRelBFRecord)
4378 else
4380 }
4381
4382 unsigned FSAbbrev =
4383 (UseRelBFRecord ? FSCallsRelBFAbbrev : FSCallsProfileAbbrev);
4384 unsigned Code =
4386
4387
4388 Stream.EmitRecord(Code, NameVals, FSAbbrev);
4389 NameVals.clear();
4390}
4391
4392
4393
4394void ModuleBitcodeWriterBase::writeModuleLevelReferences(
4396 unsigned FSModRefsAbbrev, unsigned FSModVTableRefsAbbrev) {
4397 auto VI = Index->getValueInfo(V.getGUID());
4398 if (!VI || VI.getSummaryList().empty()) {
4399
4400
4401 assert(V.isDeclaration());
4402 return;
4403 }
4404 auto *Summary = VI.getSummaryList()[0].get();
4409
4410 auto VTableFuncs = VS->vTableFuncs();
4411 if (!VTableFuncs.empty())
4413
4414 unsigned SizeBeforeRefs = NameVals.size();
4415 for (auto &RI : VS->refs())
4417
4418
4420
4421 if (VTableFuncs.empty())
4423 FSModRefsAbbrev);
4424 else {
4425
4426 for (auto &P : VTableFuncs) {
4429 }
4430
4432 FSModVTableRefsAbbrev);
4433 }
4434 NameVals.clear();
4435}
4436
4437
4438
4439void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
4440
4441
4442 bool IsThinLTO = true;
4443 if (auto *MD =
4444 mdconst::extract_or_null(M.getModuleFlag("ThinLTO")))
4445 IsThinLTO = MD->getZExtValue();
4448 4);
4449
4453
4454
4456
4457 if (Index->enableSplitLTOUnit())
4459 if (Index->hasUnifiedLTO())
4461
4463
4464 if (Index->begin() == Index->end()) {
4466 return;
4467 }
4468
4469 auto Abbv = std::make_shared();
4472
4475 unsigned ValueGuidAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4476
4477 for (const auto &GVI : valueIds()) {
4480 static_cast<uint32_t>(GVI.first >> 32),
4481 static_cast<uint32_t>(GVI.first)},
4482 ValueGuidAbbrev);
4483 }
4484
4485 if (->stackIds().empty()) {
4486 auto StackIdAbbv = std::make_shared();
4488
4490
4491
4493 unsigned StackIdAbbvId = Stream.EmitAbbrev(std::move(StackIdAbbv));
4496 for (auto Id : Index->stackIds()) {
4499 }
4501 }
4502
4503
4504 auto ContextIdAbbv = std::make_shared();
4507
4508
4510 unsigned ContextIdAbbvId = Stream.EmitAbbrev(std::move(ContextIdAbbv));
4511
4512
4513 Abbv = std::make_shared();
4522
4525 unsigned FSCallsProfileAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4526
4527
4528 Abbv = std::make_shared();
4537
4540 unsigned FSCallsRelBFAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4541
4542
4543 Abbv = std::make_shared();
4549 unsigned FSModRefsAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4550
4551
4552 Abbv = std::make_shared();
4557
4560 unsigned FSModVTableRefsAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4561
4562
4563 Abbv = std::make_shared();
4568 unsigned FSAliasAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4569
4570
4571 Abbv = std::make_shared();
4575
4578 unsigned TypeIdCompatibleVtableAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4579
4580 Abbv = std::make_shared();
4583
4586 unsigned CallsiteAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4587
4588 Abbv = std::make_shared();
4591
4592
4595 unsigned AllocAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4596
4597 Abbv = std::make_shared();
4599
4602 unsigned RadixAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4603
4604
4605
4606
4607
4608
4611
4612
4613 if (.hasName())
4614 report_fatal_error("Unexpected anonymous function when writing summary");
4615
4617 if (!VI || VI.getSummaryList().empty()) {
4618
4619
4620 assert(F.isDeclaration());
4621 continue;
4622 }
4623 auto *Summary = VI.getSummaryList()[0].get();
4626 FS, [](unsigned I) { return I; }, CallStacks);
4627 }
4628
4629
4631 if (!CallStacks.empty()) {
4632 CallStackPos =
4634 }
4635
4636
4638
4640
4641
4643
4644
4645 if (.hasName())
4646 report_fatal_error("Unexpected anonymous function when writing summary");
4647
4649 if (!VI || VI.getSummaryList().empty()) {
4650
4651
4652 assert(F.isDeclaration());
4653 continue;
4654 }
4655 auto *Summary = VI.getSummaryList()[0].get();
4656 writePerModuleFunctionSummaryRecord(
4657 NameVals, Summary, VE.getValueID(&F), FSCallsRelBFAbbrev,
4658 FSCallsProfileAbbrev, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId, F,
4659 CallStackPos, CallStackCount);
4660 }
4661
4662
4663
4665 writeModuleLevelReferences(G, NameVals, FSModRefsAbbrev,
4666 FSModVTableRefsAbbrev);
4667
4669 auto *Aliasee = A.getAliaseeObject();
4670
4671
4672 if (!Aliasee->hasName() || isa(Aliasee))
4673 continue;
4675 auto AliaseeId = VE.getValueID(Aliasee);
4677 auto *Summary = Index->getGlobalValueSummary(A);
4678 AliasSummary *AS = cast(Summary);
4682 NameVals.clear();
4683 }
4684
4685 for (auto &S : Index->typeIdCompatibleVtableMap()) {
4687 S.second, VE);
4689 TypeIdCompatibleVtableAbbrev);
4690 NameVals.clear();
4691 }
4692
4693 if (Index->getBlockCount())
4696
4698}
4699
4700
4701void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4706
4707
4709
4710 auto Abbv = std::make_shared();
4713
4716 unsigned ValueGuidAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4717
4718 for (const auto &GVI : valueIds()) {
4721 static_cast<uint32_t>(GVI.first >> 32),
4722 static_cast<uint32_t>(GVI.first)},
4723 ValueGuidAbbrev);
4724 }
4725
4726
4727
4728 if (!StackIds.empty()) {
4729 auto StackIdAbbv = std::make_shared();
4731
4733
4734
4736 unsigned StackIdAbbvId = Stream.EmitAbbrev(std::move(StackIdAbbv));
4738 Vals.reserve(StackIds.size() * 2);
4739 for (auto Id : StackIds) {
4742 }
4744 }
4745
4746
4747 Abbv = std::make_shared();
4758
4761 unsigned FSCallsProfileAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4762
4763
4764 Abbv = std::make_shared();
4771 unsigned FSModRefsAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4772
4773
4774 Abbv = std::make_shared();
4780 unsigned FSAliasAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4781
4782 Abbv = std::make_shared();
4787
4790 unsigned CallsiteAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4791
4792 Abbv = std::make_shared();
4796
4797
4798
4801 unsigned AllocAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4802
4803 Abbv = std::make_shared();
4805
4808 unsigned RadixAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4809
4810 auto shouldImportValueAsDecl = [&](GlobalValueSummary *GVS) -> bool {
4811 if (DecSummaries == nullptr)
4812 return false;
4813 return DecSummaries->count(GVS);
4814 };
4815
4816
4817
4819
4820
4822
4824
4825
4826
4827 std::setGlobalValue::GUID ReferencedTypeIds;
4828
4829
4830
4832
4833
4834
4835
4836
4837
4838
4840 return;
4841 NameVals.push_back(S.getOriginalName());
4843 NameVals.clear();
4844 };
4845
4846
4847
4848
4849
4850
4852 forEachSummary([&](GVInfo I, bool IsAliasee) {
4853
4854
4855
4856 if (IsAliasee)
4857 return;
4860 auto *FS = dyn_cast(S);
4861 if (!FS)
4862 return;
4864 FS,
4865
4866 [&](unsigned I) {
4867
4868
4869
4871 return StackIdIndicesToIndex[I];
4872 },
4873 CallStacks);
4874 });
4875
4876
4878 if (!CallStacks.empty()) {
4879 CallStackPos =
4881 }
4882
4883
4885
4887 forEachSummary([&](GVInfo I, bool IsAliasee) {
4890 DefOrUseGUIDs.insert(I.first);
4892 DefOrUseGUIDs.insert(VI.getGUID());
4893
4894 auto ValueId = getValueId(I.first);
4896 SummaryToValueIdMap[S] = *ValueId;
4897
4898
4899
4900
4901 if (IsAliasee)
4902 return;
4903
4904 if (auto *AS = dyn_cast(S)) {
4905
4906
4908 return;
4909 }
4910
4911 if (auto *VS = dyn_cast(S)) {
4914 NameVals.push_back(ModuleIdMap[VS->modulePath()]);
4918 for (auto &RI : VS->refs()) {
4919 auto RefValueId = getValueId(RI.getGUID());
4920 if (!RefValueId)
4921 continue;
4922 NameVals.push_back(*RefValueId);
4923 }
4924
4925
4927 FSModRefsAbbrev);
4928 NameVals.clear();
4929 MaybeEmitOriginalName(*S);
4930 return;
4931 }
4932
4933 auto GetValueId = [&](const ValueInfo &VI) -> std::optional {
4934 if (!VI)
4935 return std::nullopt;
4936 return getValueId(VI.getGUID());
4937 };
4938
4939 auto *FS = cast(S);
4942
4944 Stream, FS, CallsiteAbbrev, AllocAbbrev, 0,
4945 false,
4946
4947 [&](const ValueInfo &VI) -> unsigned {
4948 std::optional ValueID = GetValueId(VI);
4949
4950
4951
4952
4953 if (!ValueID)
4954 return 0;
4955 return *ValueID;
4956 },
4957
4958 [&](unsigned I) {
4959
4960
4961
4963 return StackIdIndicesToIndex[I];
4964 },
4965 false, CallStackPos, CallStackCount);
4966
4969 NameVals.push_back(ModuleIdMap[FS->modulePath()]);
4974
4975 NameVals.push_back(0 );
4976
4977
4978 NameVals.push_back(0);
4979 NameVals.push_back(0);
4980 NameVals.push_back(0);
4981
4982 unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
4983 for (auto &RI : FS->refs()) {
4984 auto RefValueId = getValueId(RI.getGUID());
4985 if (!RefValueId)
4986 continue;
4987 NameVals.push_back(*RefValueId);
4988 if (RI.isReadOnly())
4989 RORefCnt++;
4990 else if (RI.isWriteOnly())
4991 WORefCnt++;
4992 Count++;
4993 }
4994 NameVals[6] = Count;
4995 NameVals[7] = RORefCnt;
4996 NameVals[8] = WORefCnt;
4997
4998 for (auto &EI : FS->calls()) {
4999
5000
5001 std::optional CallValueId = GetValueId(EI.first);
5002 if (!CallValueId)
5003 continue;
5004 NameVals.push_back(*CallValueId);
5006 }
5007
5008
5010 FSCallsProfileAbbrev);
5011 NameVals.clear();
5012 MaybeEmitOriginalName(*S);
5013 });
5014
5015 for (auto *AS : Aliases) {
5016 auto AliasValueId = SummaryToValueIdMap[AS];
5017 assert(AliasValueId);
5018 NameVals.push_back(AliasValueId);
5023 auto AliaseeValueId = SummaryToValueIdMap[&AS->getAliasee()];
5024 assert(AliaseeValueId);
5025 NameVals.push_back(AliaseeValueId);
5026
5027
5029 NameVals.clear();
5030 MaybeEmitOriginalName(*AS);
5031
5032 if (auto *FS = dyn_cast(&AS->getAliasee()))
5034 }
5035
5036 if (.cfiFunctionDefs().empty()) {
5037 for (auto &S : Index.cfiFunctionDefs()) {
5042 }
5043 }
5044 if (!NameVals.empty()) {
5046 NameVals.clear();
5047 }
5048 }
5049
5050 if (.cfiFunctionDecls().empty()) {
5051 for (auto &S : Index.cfiFunctionDecls()) {
5056 }
5057 }
5058 if (!NameVals.empty()) {
5060 NameVals.clear();
5061 }
5062 }
5063
5064
5065
5066 for (auto &T : ReferencedTypeIds) {
5067 auto TidIter = Index.typeIds().equal_range(T);
5068 for (const auto &[GUID, TypeIdPair] : make_range(TidIter)) {
5070 TypeIdPair.second);
5072 NameVals.clear();
5073 }
5074 }
5075
5076 if (Index.getBlockCount())
5079
5081}
5082
5083
5084
5087
5088
5089 auto Abbv = std::make_shared();
5093 auto StringAbbrev = Stream.EmitAbbrev(std::move(Abbv));
5095 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
5096
5097
5098 Abbv = std::make_shared();
5101 auto EpochAbbrev = Stream.EmitAbbrev(std::move(Abbv));
5105}
5106
5107void ModuleBitcodeWriter::writeModuleHash(StringRef View) {
5108
5109
5110 if (GenerateHash) {
5113 reinterpret_cast<const uint8_t *>(View.data()), View.size()));
5114 std::array<uint8_t, 20> Hash = Hasher.result();
5115 for (int Pos = 0; Pos < 20; Pos += 4) {
5117 }
5118
5119
5121
5122 if (ModHash)
5123
5124 llvm::copy(Vals, std::begin(*ModHash));
5125 }
5126}
5127
5128void ModuleBitcodeWriter::write() {
5130
5132
5133
5135
5136 writeModuleVersion();
5137
5138
5139 writeBlockInfo();
5140
5141
5142 writeTypeTable();
5143
5144
5145 writeAttributeGroupTable();
5146
5147
5148 writeAttributeTable();
5149
5150 writeComdats();
5151
5152
5153
5154 writeModuleInfo();
5155
5156
5157 writeModuleConstants();
5158
5159
5160 writeModuleMetadataKinds();
5161
5162
5163 writeModuleMetadata();
5164
5165
5167 writeUseListBlock(nullptr);
5168
5169 writeOperandBundleTags();
5170 writeSyncScopeNames();
5171
5172
5175 if (.isDeclaration())
5176 writeFunction(F, FunctionToBitcodeIndex);
5177
5178
5179
5180 if (Index)
5181 writePerModuleGlobalValueSummary();
5182
5183 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
5184
5186
5188}
5189
5193 Position += 4;
5194}
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5211 unsigned CPUType = ~0U;
5212
5213
5214
5215
5216
5217 enum {
5218 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
5219 DARWIN_CPU_TYPE_X86 = 7,
5220 DARWIN_CPU_TYPE_ARM = 12,
5221 DARWIN_CPU_TYPE_POWERPC = 18
5222 };
5223
5226 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
5228 CPUType = DARWIN_CPU_TYPE_X86;
5230 CPUType = DARWIN_CPU_TYPE_POWERPC;
5232 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
5234 CPUType = DARWIN_CPU_TYPE_ARM;
5235
5236
5238 "Expected header size to be reserved");
5241
5242
5243 unsigned Position = 0;
5249
5250
5251 while (Buffer.size() & 15)
5253}
5254
5255
5257
5258 Stream.Emit((unsigned)'B', 8);
5259 Stream.Emit((unsigned)'C', 8);
5260 Stream.Emit(0x0, 4);
5261 Stream.Emit(0xC, 4);
5262 Stream.Emit(0xE, 4);
5263 Stream.Emit(0xD, 4);
5264}
5265
5269}
5270
5274}
5275
5277
5278void BitcodeWriter::writeBlob(unsigned Block, unsigned Record, StringRef Blob) {
5280
5281 auto Abbv = std::make_shared();
5284 auto AbbrevNo = Stream->EmitAbbrev(std::move(Abbv));
5285
5287
5289}
5290
5292 assert(!WroteStrtab && !WroteSymtab);
5293
5294
5295
5296
5297 for (Module *M : Mods) {
5298 if (M->getModuleInlineAsm().empty())
5299 continue;
5300
5301 std::string Err;
5302 const Triple TT(M->getTargetTriple());
5304 if ( ||
->hasMCAsmParser())
5305 return;
5306 }
5307
5308 WroteSymtab = true;
5310
5311
5312
5313
5316 return;
5317 }
5318
5320 {Symtab.data(), Symtab.size()});
5321}
5322
5324 assert(!WroteStrtab);
5325
5326 std::vector Strtab;
5328 Strtab.resize(StrtabBuilder.getSize());
5329 StrtabBuilder.write((uint8_t *)Strtab.data());
5330
5332 {Strtab.data(), Strtab.size()});
5333
5334 WroteStrtab = true;
5335}
5336
5339 WroteStrtab = true;
5340}
5341
5343 bool ShouldPreserveUseListOrder,
5345 bool GenerateHash, ModuleHash *ModHash) {
5346 assert(!WroteStrtab);
5347
5348
5349
5350
5351
5352 assert(M.isMaterialized());
5353 Mods.push_back(const_cast<Module *>(&M));
5354
5355 ModuleBitcodeWriter ModuleWriter(M, StrtabBuilder, *Stream,
5356 ShouldPreserveUseListOrder, Index,
5357 GenerateHash, ModHash);
5358 ModuleWriter.write();
5359}
5360
5365 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, DecSummaries,
5366 ModuleToSummariesForIndex);
5367 IndexWriter.write();
5368}
5369
5370
5372 bool ShouldPreserveUseListOrder,
5374 bool GenerateHash, ModuleHash *ModHash) {
5376 Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
5377 ModHash);
5378 Writer.writeSymtab();
5379 Writer.writeStrtab();
5380 };
5381 Triple TT(M.getTargetTriple());
5382 if (TT.isOSDarwin() || TT.isOSBinFormatMachO()) {
5383
5384
5385
5386
5388 Buffer.reserve(256 * 1024);
5394 } else {
5397 }
5398}
5399
5400void IndexBitcodeWriter::write() {
5402
5403 writeModuleVersion();
5404
5405
5406 writeModStrings();
5407
5408
5409 writeCombinedGlobalValueSummary();
5410
5412}
5413
5414
5415
5416
5417
5423 Buffer.reserve(256 * 1024);
5424
5426 Writer.writeIndex(&Index, ModuleToSummariesForIndex, DecSummaries);
5428
5430}
5431
5432namespace {
5433
5434
5435class ThinLinkBitcodeWriter : public ModuleBitcodeWriterBase {
5436
5437
5439
5440public:
5445 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5447 ModHash(&ModHash) {}
5448
5450
5451private:
5452 void writeSimplifiedModuleInfo();
5453};
5454
5455}
5456
5457
5458
5459
5460
5461
5462void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5464
5465 {
5472
5473
5474 auto Abbv = std::make_shared();
5477 Abbv->Add(AbbrevOpToUse);
5478 unsigned FilenameAbbrev = Stream.EmitAbbrev(std::move(Abbv));
5479
5480 for (const auto P : M.getSourceFileName())
5482
5485 }
5486
5487
5489
5490 Vals.push_back(StrtabBuilder.add(GV.getName()));
5491 Vals.push_back(GV.getName().size());
5496
5499 }
5500
5501
5503
5510
5513 }
5514
5515
5517
5524
5527 }
5528
5529
5531
5538
5541 }
5542}
5543
5544void ThinLinkBitcodeWriter::write() {
5546
5547 writeModuleVersion();
5548
5549 writeSimplifiedModuleInfo();
5550
5551 writePerModuleGlobalValueSummary();
5552
5553
5555
5557}
5558
5562 assert(!WroteStrtab);
5563
5564
5565
5566
5567
5568 assert(M.isMaterialized());
5569 Mods.push_back(const_cast<Module *>(&M));
5570
5571 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream, Index,
5572 ModHash);
5573 ThinLinkWriter.write();
5574}
5575
5576
5577
5578
5583 Buffer.reserve(256 * 1024);
5584
5589
5591}
5592
5594 switch (T.getObjectFormat()) {
5596 return "__LLVM,__bitcode";
5601 return ".llvmbc";
5604 break;
5607 return ".llvmbc";
5609 break;
5612 break;
5615 break;
5616 }
5618}
5619
5621 switch (T.getObjectFormat()) {
5623 return "__LLVM,__cmdline";
5628 return ".llvmcmd";
5631 break;
5634 return ".llvmcmd";
5636 break;
5639 break;
5642 break;
5643 }
5645}
5646
5649 const std::vector<uint8_t> &CmdArgs) {
5650
5654 Type *UsedElementType = Used ? Used->getValueType()->getArrayElementType()
5656 for (auto *GV : UsedGlobals) {
5657 if (GV->getName() != "llvm.embedded.module" &&
5658 GV->getName() != "llvm.cmdline")
5661 }
5662 if (Used)
5663 Used->eraseFromParent();
5664
5665
5666 std::string Data;
5668 Triple T(M.getTargetTriple());
5669
5673 (const unsigned char *)Buf.getBufferEnd())) {
5674
5675
5678 ModuleData =
5680 } else
5681
5684 }
5689 ModuleConstant);
5691
5692
5697 M.getGlobalVariable("llvm.embedded.module", true)) {
5698 assert(Old->hasZeroLiveUses() &&
5699 "llvm.embedded.module can only be used once in llvm.compiler.used");
5701 Old->eraseFromParent();
5702 } else {
5703 GV->setName("llvm.embedded.module");
5704 }
5705
5706
5707 if (EmbedCmdline) {
5708
5710 CmdArgs.size());
5715 CmdConstant);
5720 if (llvm::GlobalVariable *Old = M.getGlobalVariable("llvm.cmdline", true)) {
5721 assert(Old->hasZeroLiveUses() &&
5722 "llvm.cmdline can only be used once in llvm.compiler.used");
5724 Old->eraseFromParent();
5725 } else {
5726 GV->setName("llvm.cmdline");
5727 }
5728 }
5729
5730 if (UsedArray.empty())
5731 return;
5732
5733
5738 NewUsed->setSection("llvm.metadata");
5739}
This file defines the StringMap class.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void writeDIMacro(raw_ostream &Out, const DIMacro *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, AsmWriterContext &WriterCtx)
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, AsmWriterContext &WriterCtx)
static void writeDIStringType(raw_ostream &Out, const DIStringType *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, AsmWriterContext &WriterCtx)
static void writeDIModule(raw_ostream &Out, const DIModule *N, AsmWriterContext &WriterCtx)
static void writeDIFile(raw_ostream &Out, const DIFile *N, AsmWriterContext &)
static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, AsmWriterContext &WriterCtx)
static void writeDILabel(raw_ostream &Out, const DILabel *N, AsmWriterContext &WriterCtx)
static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, AsmWriterContext &WriterCtx)
static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, AsmWriterContext &WriterCtx)
static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, AsmWriterContext &WriterCtx)
static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, AsmWriterContext &WriterCtx)
static void writeDILocation(raw_ostream &Out, const DILocation *DL, AsmWriterContext &WriterCtx)
static void writeDINamespace(raw_ostream &Out, const DINamespace *N, AsmWriterContext &WriterCtx)
static void writeDICommonBlock(raw_ostream &Out, const DICommonBlock *N, AsmWriterContext &WriterCtx)
static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, AsmWriterContext &)
static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, AsmWriterContext &WriterCtx)
static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, AsmWriterContext &WriterCtx)
static void writeDITemplateTypeParameter(raw_ostream &Out, const DITemplateTypeParameter *N, AsmWriterContext &WriterCtx)
static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, AsmWriterContext &WriterCtx)
static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N, AsmWriterContext &WriterCtx)
static void writeDISubrange(raw_ostream &Out, const DISubrange *N, AsmWriterContext &WriterCtx)
static void writeDILexicalBlockFile(raw_ostream &Out, const DILexicalBlockFile *N, AsmWriterContext &WriterCtx)
static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, AsmWriterContext &)
static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, AsmWriterContext &WriterCtx)
static void writeDIExpression(raw_ostream &Out, const DIExpression *N, AsmWriterContext &WriterCtx)
static void writeDIAssignID(raw_ostream &Out, const DIAssignID *DL, AsmWriterContext &WriterCtx)
static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, AsmWriterContext &WriterCtx)
static void writeDIArgList(raw_ostream &Out, const DIArgList *N, AsmWriterContext &WriterCtx, bool FromValue=false)
static void writeDITemplateValueParameter(raw_ostream &Out, const DITemplateValueParameter *N, AsmWriterContext &WriterCtx)
static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, AsmWriterContext &WriterCtx)
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static void writeFunctionHeapProfileRecords(BitstreamWriter &Stream, FunctionSummary *FS, unsigned CallsiteAbbrev, unsigned AllocAbbrev, unsigned ContextIdAbbvId, bool PerModule, std::function< unsigned(const ValueInfo &VI)> GetValueID, std::function< unsigned(unsigned)> GetStackIndex, bool WriteContextSizeInfoIndex, DenseMap< CallStackId, LinearCallStackId > &CallStackPos, CallStackId &CallStackCount)
static unsigned serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta)
static void writeTypeIdCompatibleVtableSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdCompatibleVtableInfo &Summary, ValueEnumerator &VE)
static void getReferencedTypeIds(FunctionSummary *FS, std::set< GlobalValue::GUID > &ReferencedTypeIds)
Collect type IDs from type tests used by function.
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
static void collectMemProfCallStacks(FunctionSummary *FS, std::function< LinearFrameId(unsigned)> GetStackIndex, MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &CallStacks)
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
static unsigned getEncodedVisibility(const GlobalValue &GV)
static uint64_t getOptimizationFlags(const Value *V)
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
static unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
static DenseMap< CallStackId, LinearCallStackId > writeMemoryProfileRadixTree(MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &&CallStacks, BitstreamWriter &Stream, unsigned RadixAbbrev)
static void writeIdentificationBlock(BitstreamWriter &Stream)
Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version,...
static unsigned getEncodedCastOpcode(unsigned Opcode)
static cl::opt< bool > WriteRelBFToSummary("write-relbf-to-summary", cl::Hidden, cl::init(false), cl::desc("Write relative block frequency to function summary "))
static cl::opt< uint32_t > FlushThreshold("bitcode-flush-threshold", cl::Hidden, cl::init(512), cl::desc("The threshold (unit M) for flushing LLVM bitcode."))
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
static unsigned getEncodedUnnamedAddr(const GlobalValue &GV)
bool WriteNewDbgInfoFormatToBitcode
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags, bool ImportAsDecl=false)
static void emitDarwinBCHeaderAndTrailer(SmallVectorImpl< char > &Buffer, const Triple &TT)
If generating a bc file on darwin, we have to emit a header and trailer to make it compatible with th...
static void writeBitcodeHeader(BitstreamWriter &Stream)
Helper to write the header common to all bitcode files.
llvm:🆑:opt< bool > UseNewDbgInfoFormat
static uint64_t getEncodedRelBFCallEdgeInfo(const CalleeInfo &CI)
static void writeWholeProgramDevirtResolutionByArg(SmallVector< uint64_t, 64 > &NameVals, const std::vector< uint64_t > &args, const WholeProgramDevirtResolution::ByArg &ByArg)
static void emitConstantRange(SmallVectorImpl< uint64_t > &Record, const ConstantRange &CR, bool EmitBitWidth)
static StringEncoding getStringEncoding(StringRef Str)
Determine the encoding to use for the given string name and length.
static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags)
static const char * getSectionNameForCommandline(const Triple &T)
static cl::opt< unsigned > IndexThreshold("bitcode-mdindex-threshold", cl::Hidden, cl::init(25), cl::desc("Number of metadatas above which we emit an index " "to enable lazy-loading"))
static void writeTypeIdSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdSummary &Summary)
static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, FunctionSummary *FS, Fn GetValueID)
Write the function type metadata related records that need to appear before a function summary entry ...
static uint64_t getEncodedHotnessCallEdgeInfo(const CalleeInfo &CI)
static void emitWideAPInt(SmallVectorImpl< uint64_t > &Vals, const APInt &A)
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
static void writeWholeProgramDevirtResolution(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, uint64_t Id, const WholeProgramDevirtResolution &Wpd)
static unsigned getEncodedDLLStorageClass(const GlobalValue &GV)
static void writeInt32ToBuffer(uint32_t Value, SmallVectorImpl< char > &Buffer, uint32_t &Position)
static const char * getSectionNameForBitcode(const Triple &T)
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseMap class.
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
static MaybeAlign getAlign(Value *Ptr)
Module.h This file contains the declarations for the Module class.
static cl::opt< LTOBitcodeEmbedding > EmbedBitcode("lto-embed-bitcode", cl::init(LTOBitcodeEmbedding::DoNotEmbed), cl::values(clEnumValN(LTOBitcodeEmbedding::DoNotEmbed, "none", "Do not embed"), clEnumValN(LTOBitcodeEmbedding::EmbedOptimized, "optimized", "Embed after all optimization passes"), clEnumValN(LTOBitcodeEmbedding::EmbedPostMergePreOptimized, "post-merge-pre-opt", "Embed post merge, but before optimizations")), cl::desc("Embed LLVM bitcode in object files produced by LTO"))
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static const uint32_t IV[8]
Class for arbitrary precision integers.
unsigned getNumWords() const
Get the number of words.
unsigned getActiveWords() const
Compute the number of active words in the value of this APInt.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
int64_t getSExtValue() const
Get sign extended value.
Alias summary information.
const GlobalValueSummary & getAliasee() const
an instruction to allocate memory on the stack
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
unsigned getAddressSpace() const
Return the address space for the allocation.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
Class to represent array types.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ USubCond
Subtract only if no unsigned overflow.
@ Min
*p = old <signed v ? old : v
@ USubSat
*p = usub.sat(old, v) usub.sat matches the behavior of llvm.usub.sat.
@ UIncWrap
Increment one up to a maximum value.
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ UMax
*p = old >unsigned v ? old : v
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
bool hasAttributes() const
Return true if attributes exists in this set.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
@ None
No attributes have been set.
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
@ EndAttrKinds
Sentinel value useful for loops.
LLVM Basic Block Representation.
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
void writeThinLinkBitcode(const Module &M, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the buffer specified...
void writeIndex(const ModuleSummaryIndex *Index, const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex, const GVSummaryPtrSet *DecSummaries)
void copyStrtab(StringRef Strtab)
Copy the string table for another module into this bitcode file.
void writeStrtab()
Write the bitcode file's string table.
void writeSymtab()
Attempt to write a symbol table to the bitcode file.
void writeModule(const Module &M, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the buffer specified at construction time.
BitcodeWriter(SmallVectorImpl< char > &Buffer)
Create a BitcodeWriter that writes to Buffer.
unsigned EmitAbbrev(std::shared_ptr< BitCodeAbbrev > Abbv)
Emits the abbreviation Abbv to the stream.
void markAndBlockFlushing()
For scenarios where the user wants to access a section of the stream to (for example) compute some ch...
StringRef getMarkedBufferAndResumeFlushing()
resumes flushing, but does not flush, and returns the section in the internal buffer starting from th...
void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev=0)
EmitRecord - Emit the specified record to the stream, using an abbrev if we have one to compress the ...
void Emit(uint32_t Val, unsigned NumBits)
void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals, StringRef Blob)
EmitRecordWithBlob - Emit the specified record to the stream, using an abbrev that includes a blob at...
unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr< BitCodeAbbrev > Abbv)
EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified BlockID.
void EnterBlockInfoBlock()
EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
void BackpatchWord(uint64_t BitNo, unsigned Val)
void BackpatchWord64(uint64_t BitNo, uint64_t Val)
void EnterSubblock(unsigned BlockID, unsigned CodeLen)
uint64_t GetCurrentBitNo() const
Retrieve the current position in the stream, in bits.
void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals)
EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
The address of a basic block.
static BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
Conditional or Unconditional Branch instruction.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
CallingConv::ID getCallingConv() const
Value * getCalledOperand() const
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
bool hasOperandBundles() const
Return true if this User has any operand bundles.
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
BasicBlock * getIndirectDest(unsigned i) const
BasicBlock * getDefaultDest() const
unsigned getNumIndirectDests() const
Return the number of callbr indirect dest labels.
This class represents a function call, abstracting a target machine's calling convention.
bool isNoTailCall() const
bool isMustTailCall() const
@ Largest
The linker will choose the largest COMDAT.
@ SameSize
The data referenced by the COMDAT must be the same size.
@ Any
The linker may choose any COMDAT.
@ NoDeduplicate
No deduplication is performed.
@ ExactMatch
The data referenced by the COMDAT must be the same.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
A constant value that is initialized with an expression using other constant values.
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
ConstantFP - Floating Point Values [float, double].
This is the shared class of boolean and integer constants.
This class represents a range of values.
const APInt & getLower() const
Return the lower value for this range.
const APInt & getUpper() const
Return the upper value for this range.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
ConstantRange sextOrTrunc(uint32_t BitWidth) const
Make this range have the bit width given by BitWidth.
This is an important base class in LLVM.
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
Basic type, like 'int' or 'float'.
A pair of DIGlobalVariable and DIExpression.
An imported module (C++ using directive or similar).
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
String type, Fortran CHARACTER(n)
Type array for a subprogram.
This class represents an Operation in the Expression.
Records a position in IR for a source label (DILabel).
Base class for non-instruction debug metadata records that have positions within IR.
DebugLoc getDebugLoc() const
Record of a variable value-assignment, aka a non instruction representation of the dbg....
DIAssignID * getAssignID() const
DIExpression * getExpression() const
DILocalVariable * getVariable() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
bool isDbgDeclare() const
Metadata * getRawAddress() const
DIExpression * getAddressExpression() const
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
Lightweight error class with error context and mandatory checking.
Function summary information to aid decisions and implementation of importing.
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
Generic tagged DWARF-like metadata node.
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
void setSection(StringRef S)
Change the section for this global.
Function and variable summary information to aid decisions and implementation of importing.
GVFlags flags() const
Get the flags for this GlobalValue (see struct GVFlags).
StringRef modulePath() const
Get the path to the module containing this function.
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
VisibilityTypes getVisibility() const
static bool isLocalLinkage(LinkageTypes Linkage)
LinkageTypes getLinkage() const
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
ThreadLocalMode getThreadLocalMode() const
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ProtectedVisibility
The GV is protected.
UnnamedAddr getUnnamedAddr() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
DLLStorageClassTypes getDLLStorageClass() const
Global variable summary information to aid decisions and implementation of importing.
This instruction inserts a struct field of array element value into an aggregate value.
idx_iterator idx_end() const
idx_iterator idx_begin() const
This is an important class for using LLVM in a threaded context.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
Tracking metadata reference owned by Metadata.
This class implements a map that also provides access to all stored values in a deterministic order.
size_t getBufferSize() const
const char * getBufferStart() const
const char * getBufferEnd() const
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static constexpr uint64_t BitcodeSummaryVersion
A Module instance is used to store all the information related to an LLVM module.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
A class that wrap the SHA1 algorithm.
size_type size() const
Determine the number of elements in the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void append(StringRef RHS)
Append from a StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
const ValueTy & getValue() const
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
Utility for building string tables with deduplicated suffixes.
void finalizeInOrder()
Finalize the string table without reording it.
void write(raw_ostream &OS) const
size_t add(CachedHashStringRef S)
Add a string to the builder.
Class to represent struct types.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isX86_FP80Ty() const
Return true if this is x86 long double.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
@ TypedPointerTyID
Typed pointer used by some GPU targets.
@ HalfTyID
16-bit floating point type
@ TargetExtTyID
Target extension type.
@ VoidTyID
type with no size
@ ScalableVectorTyID
Scalable SIMD vector type.
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ FixedVectorTyID
Fixed width SIMD vector type.
@ BFloatTyID
16-bit floating point type (7-bit significand)
@ DoubleTyID
64-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
@ FP128TyID
128-bit floating point type (112-bit significand)
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
bool isFP128Ty() const
Return true if this is 'fp128'.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
unsigned getTypeID(Type *T) const
unsigned getMetadataID(const Metadata *MD) const
UseListOrderStack UseListOrders
std::vector< std::pair< const Value *, unsigned > > ValueList
ArrayRef< const Metadata * > getNonMDStrings() const
Get the non-MDString metadata for this block.
unsigned getInstructionID(const Instruction *I) const
unsigned getAttributeListID(AttributeList PAL) const
void incorporateFunction(const Function &F)
incorporateFunction/purgeFunction - If you'd like to deal with a function, use these two methods to g...
void getFunctionConstantRange(unsigned &Start, unsigned &End) const
getFunctionConstantRange - Return the range of values that corresponds to function-local constants.
unsigned getAttributeGroupID(IndexAndAttrSet Group) const
bool hasMDs() const
Check whether the current block has any metadata to emit.
unsigned getComdatID(const Comdat *C) const
uint64_t computeBitsRequiredForTypeIndices() const
unsigned getValueID(const Value *V) const
unsigned getMetadataOrNullID(const Metadata *MD) const
const std::vector< IndexAndAttrSet > & getAttributeGroups() const
const ValueList & getValues() const
unsigned getGlobalBasicBlockID(const BasicBlock *BB) const
getGlobalBasicBlockID - This returns the function-specific ID for the specified basic block.
void setInstructionID(const Instruction *I)
const std::vector< const BasicBlock * > & getBasicBlocks() const
const std::vector< AttributeList > & getAttributeLists() const
bool shouldPreserveUseListOrder() const
const ComdatSetType & getComdats() const
std::vector< Type * > TypeList
ArrayRef< const Metadata * > getMDStrings() const
Get the MDString metadata for this block.
std::pair< unsigned, AttributeSet > IndexAndAttrSet
Attribute groups as encoded in bitcode are almost AttributeSets, but they include the AttributeList i...
const TypeList & getTypes() const
This class provides a symbol table of name/value pairs.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void setName(const Twine &Name)
Change the name of the value.
LLVMContext & getContext() const
All values hold a context through their type.
void takeName(Value *V)
Transfer the name from V to this value.
std::pair< iterator, bool > insert(const ValueT &V)
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
void build(llvm::MapVector< CallStackId, llvm::SmallVector< FrameIdTy > > &&MemProfCallStackData, const llvm::DenseMap< FrameIdTy, LinearFrameId > *MemProfFrameIndexes, llvm::DenseMap< FrameIdTy, FrameStat > &FrameHistogram)
ArrayRef< LinearFrameId > getRadixArray() const
llvm::DenseMap< CallStackId, LinearCallStackId > takeCallStackPos()
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an std::string.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
@ C
The default llvm calling convention, compatible with C.
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
@ CE
Windows NT (Windows on ARM)
@ TYPE_CODE_OPAQUE_POINTER
@ METADATA_TEMPLATE_VALUE
@ METADATA_LEXICAL_BLOCK_FILE
@ METADATA_SUBROUTINE_TYPE
@ METADATA_GLOBAL_DECL_ATTACHMENT
@ METADATA_IMPORTED_ENTITY
@ METADATA_GENERIC_SUBRANGE
@ METADATA_COMPOSITE_TYPE
@ METADATA_GLOBAL_VAR_EXPR
@ FS_CONTEXT_RADIX_TREE_ARRAY
@ FS_COMBINED_GLOBALVAR_INIT_REFS
@ FS_TYPE_CHECKED_LOAD_VCALLS
@ FS_COMBINED_ORIGINAL_NAME
@ FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_CONST_VCALL
@ FS_PERMODULE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_VCALLS
@ FS_COMBINED_CALLSITE_INFO
@ FS_PERMODULE_CALLSITE_INFO
@ FS_PERMODULE_ALLOC_INFO
@ FS_TYPE_CHECKED_LOAD_CONST_VCALL
@ IDENTIFICATION_CODE_EPOCH
@ IDENTIFICATION_CODE_STRING
@ CST_CODE_DSO_LOCAL_EQUIVALENT
@ CST_CODE_CE_GEP_WITH_INRANGE
@ COMDAT_SELECTION_KIND_LARGEST
@ COMDAT_SELECTION_KIND_ANY
@ COMDAT_SELECTION_KIND_SAME_SIZE
@ COMDAT_SELECTION_KIND_EXACT_MATCH
@ COMDAT_SELECTION_KIND_NO_DUPLICATES
@ ATTR_KIND_STACK_PROTECT
@ ATTR_KIND_STACK_PROTECT_STRONG
@ ATTR_KIND_SANITIZE_MEMORY
@ ATTR_KIND_OPTIMIZE_FOR_SIZE
@ ATTR_KIND_FNRETTHUNK_EXTERN
@ ATTR_KIND_NO_DIVERGENCE_SOURCE
@ ATTR_KIND_SANITIZE_ADDRESS
@ ATTR_KIND_NO_IMPLICIT_FLOAT
@ ATTR_KIND_DEAD_ON_UNWIND
@ ATTR_KIND_STACK_ALIGNMENT
@ ATTR_KIND_STACK_PROTECT_REQ
@ ATTR_KIND_NULL_POINTER_IS_VALID
@ ATTR_KIND_SANITIZE_HWADDRESS
@ ATTR_KIND_RETURNS_TWICE
@ ATTR_KIND_SHADOWCALLSTACK
@ ATTR_KIND_OPT_FOR_FUZZING
@ ATTR_KIND_SANITIZE_NUMERICAL_STABILITY
@ ATTR_KIND_ALLOCATED_POINTER
@ ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION
@ ATTR_KIND_CORO_ELIDE_SAFE
@ ATTR_KIND_NON_LAZY_BIND
@ ATTR_KIND_DEREFERENCEABLE
@ ATTR_KIND_OPTIMIZE_NONE
@ ATTR_KIND_HYBRID_PATCHABLE
@ ATTR_KIND_DEREFERENCEABLE_OR_NULL
@ ATTR_KIND_SANITIZE_REALTIME
@ ATTR_KIND_SPECULATIVE_LOAD_HARDENING
@ ATTR_KIND_ALWAYS_INLINE
@ ATTR_KIND_SANITIZE_TYPE
@ ATTR_KIND_PRESPLIT_COROUTINE
@ ATTR_KIND_NO_SANITIZE_COVERAGE
@ ATTR_KIND_SANITIZE_REALTIME_BLOCKING
@ ATTR_KIND_NO_SANITIZE_BOUNDS
@ ATTR_KIND_SANITIZE_MEMTAG
@ ATTR_KIND_CORO_ONLY_DESTROY_WHEN_COMPLETE
@ ATTR_KIND_SANITIZE_THREAD
@ ATTR_KIND_OPTIMIZE_FOR_DEBUGGING
@ SYNC_SCOPE_NAMES_BLOCK_ID
@ PARAMATTR_GROUP_BLOCK_ID
@ IDENTIFICATION_BLOCK_ID
@ GLOBALVAL_SUMMARY_BLOCK_ID
@ FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID
@ OPERAND_BUNDLE_TAGS_BLOCK_ID
@ MODULE_CODE_SOURCE_FILENAME
@ MODULE_CODE_SECTIONNAME
@ FUNC_CODE_INST_CATCHRET
@ FUNC_CODE_INST_LANDINGPAD
@ FUNC_CODE_INST_EXTRACTVAL
@ FUNC_CODE_INST_CATCHPAD
@ FUNC_CODE_INST_CATCHSWITCH
@ FUNC_CODE_INST_CLEANUPRET
@ FUNC_CODE_DEBUG_RECORD_VALUE
@ FUNC_CODE_INST_LOADATOMIC
@ FUNC_CODE_DEBUG_RECORD_ASSIGN
@ FUNC_CODE_INST_STOREATOMIC
@ FUNC_CODE_INST_ATOMICRMW
@ FUNC_CODE_DEBUG_LOC_AGAIN
@ FUNC_CODE_INST_EXTRACTELT
@ FUNC_CODE_INST_INDIRECTBR
@ FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE
@ FUNC_CODE_INST_INSERTVAL
@ FUNC_CODE_DECLAREBLOCKS
@ FUNC_CODE_DEBUG_RECORD_LABEL
@ FUNC_CODE_INST_INSERTELT
@ FUNC_CODE_BLOCKADDR_USERS
@ FUNC_CODE_INST_CLEANUPPAD
@ FUNC_CODE_INST_SHUFFLEVEC
@ FUNC_CODE_INST_UNREACHABLE
@ FUNC_CODE_DEBUG_RECORD_DECLARE
@ FUNC_CODE_OPERAND_BUNDLE
@ FIRST_APPLICATION_ABBREV
@ PARAMATTR_GRP_CODE_ENTRY
initializer< Ty > init(const Ty &Val)
Error build(ArrayRef< Module * > Mods, SmallVector< char, 0 > &Symtab, StringTableBuilder &StrtabBuilder, BumpPtrAllocator &Alloc)
Fills in Symtab and StrtabBuilder with a valid symbol and string table for Mods.
template llvm::DenseMap< LinearFrameId, FrameStat > computeFrameHistogram< LinearFrameId >(llvm::MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &MemProfCallStackData)
NodeAddr< CodeNode * > Code
void write32le(void *P, uint32_t V)
uint32_t read32be(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
void WriteBitcodeToFile(const Module &M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the specified raw output stream.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
void writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the given raw output...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
void writeIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out, const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex=nullptr, const GVSummaryPtrSet *DecSummaries=nullptr)
Write the specified module summary index to the given raw output stream, where it will be written in ...
void embedBitcodeInModule(Module &M, MemoryBufferRef Buf, bool EmbedBitcode, bool EmbedCmdline, const std::vector< uint8_t > &CmdArgs)
If EmbedBitcode is set, save a copy of the llvm IR as data in the __LLVM,__bitcode section (....
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue)
void sort(IteratorTy Start, IteratorTy End)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
AtomicOrdering
Atomic ordering for LLVM's memory model.
std::unordered_set< GlobalValueSummary * > GVSummaryPtrSet
A set of global value summary pointers.
DWARFExpression::Operation Op
std::map< std::string, GVSummaryMapTy, std::less<> > ModuleToSummariesForIndexTy
Map of a module name to the GUIDs and summaries we will import from that module.
OutputIt copy(R &&Range, OutputIt Out)
constexpr unsigned BitWidth
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
bool isBitcode(const unsigned char *BufPtr, const unsigned char *BufEnd)
isBitcode - Return true if the given bytes are the magic bytes for LLVM IR bitcode,...
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
void consumeError(Error Err)
Consume a Error without doing anything.
GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallVectorImpl< GlobalValue * > &Vec, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
This struct is a compact representation of a valid (non-zero power of two) alignment.
Class to accumulate and hold information about a callee.
static constexpr unsigned RelBlockFreqBits
The value stored in RelBlockFreq has to be interpreted as the digits of a scaled number with a scale ...
Flags specific to function summaries.
static constexpr uint32_t RangeWidth
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
static const Target * lookupTarget(StringRef Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
Structure to hold a use-list order.
ValID - Represents a reference of a definition of some sort with no type.
Struct that holds a reference to a particular GUID in a global value summary.
uint64_t Info
Additional information for the resolution:
enum llvm::WholeProgramDevirtResolution::ByArg::Kind TheKind
enum llvm::WholeProgramDevirtResolution::Kind TheKind
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument,...
std::string SingleImplName