33#include "llvm/Config/llvm-config.h"
95 cl::desc(
"Number of metadatas above which we emit an index "
96 "to enable lazy-loading"));
99 cl::desc(
"The threshold (unit M) for flushing LLVM bitcode."));
119 cl::desc(
"Preserve use-list order when writing LLVM bitcode."));
134 VST_BBENTRY_6_ABBREV,
138 CONSTANTS_INTEGER_ABBREV,
139 CONSTANTS_BYTE_ABBREV,
140 CONSTANTS_CE_CAST_Abbrev,
141 CONSTANTS_NULL_Abbrev,
145 FUNCTION_INST_STORE_ABBREV,
146 FUNCTION_INST_UNOP_ABBREV,
147 FUNCTION_INST_UNOP_FLAGS_ABBREV,
148 FUNCTION_INST_BINOP_ABBREV,
149 FUNCTION_INST_BINOP_FLAGS_ABBREV,
150 FUNCTION_INST_CAST_ABBREV,
151 FUNCTION_INST_CAST_FLAGS_ABBREV,
152 FUNCTION_INST_RET_VOID_ABBREV,
153 FUNCTION_INST_RET_VAL_ABBREV,
154 FUNCTION_INST_BR_UNCOND_ABBREV,
155 FUNCTION_INST_BR_COND_ABBREV,
156 FUNCTION_INST_UNREACHABLE_ABBREV,
157 FUNCTION_INST_GEP_ABBREV,
158 FUNCTION_INST_CMP_ABBREV,
159 FUNCTION_INST_CMP_FLAGS_ABBREV,
160 FUNCTION_DEBUG_RECORD_VALUE_ABBREV,
161 FUNCTION_DEBUG_LOC_ABBREV,
166class BitcodeWriterBase {
169 BitstreamWriter &Stream;
171 StringTableBuilder &StrtabBuilder;
176 BitcodeWriterBase(BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder)
177 : Stream(Stream), StrtabBuilder(StrtabBuilder) {}
180 void writeModuleVersion();
183void BitcodeWriterBase::writeModuleVersion() {
190class ModuleBitcodeWriterBase :
public BitcodeWriterBase {
199 const ModuleSummaryIndex *Index;
204 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
207 unsigned GlobalValueId;
211 uint64_t VSTOffsetPlaceholder = 0;
216 ModuleBitcodeWriterBase(
const Module &M, StringTableBuilder &StrtabBuilder,
217 BitstreamWriter &Stream,
218 bool ShouldPreserveUseListOrder,
219 const ModuleSummaryIndex *Index)
220 : BitcodeWriterBase(Stream, StrtabBuilder),
M(
M),
223 : ShouldPreserveUseListOrder),
233 for (
const auto &GUIDSummaryLists : *Index)
235 for (
auto &Summary : GUIDSummaryLists.second.getSummaryList())
241 for (auto &CallEdge : FS->calls())
242 if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
243 assignValueId(CallEdge.first.getGUID());
249 for (auto &RefEdge : FS->refs())
250 if (!RefEdge.haveGVs() || !RefEdge.getValue())
251 assignValueId(RefEdge.getGUID());
256 void writePerModuleGlobalValueSummary();
259 void writePerModuleFunctionSummaryRecord(
260 SmallVector<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
261 unsigned ValueID,
unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
262 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
const Function &
F,
263 DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
265 void writeModuleLevelReferences(
const GlobalVariable &V,
266 SmallVector<uint64_t, 64> &NameVals,
267 unsigned FSModRefsAbbrev,
268 unsigned FSModVTableRefsAbbrev);
271 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
275 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
278 assert(VMI != GUIDToValueIdMap.end() &&
279 "GUID does not have assigned value Id");
284 unsigned getValueId(ValueInfo VI) {
285 if (!
VI.haveGVs() || !
VI.getValue())
286 return getValueId(
VI.getGUID());
290 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
294class ModuleBitcodeWriter :
public ModuleBitcodeWriterBase {
305 uint64_t BitcodeStartBit;
310 ModuleBitcodeWriter(
const Module &M, StringTableBuilder &StrtabBuilder,
311 BitstreamWriter &Stream,
bool ShouldPreserveUseListOrder,
312 const ModuleSummaryIndex *Index,
bool GenerateHash,
314 : ModuleBitcodeWriterBase(
M, StrtabBuilder, Stream,
315 ShouldPreserveUseListOrder,
Index),
316 GenerateHash(GenerateHash), ModHash(ModHash),
317 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
323 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
325 size_t addToStrtab(StringRef Str);
327 void writeAttributeGroupTable();
328 void writeAttributeTable();
329 void writeTypeTable();
331 void writeValueSymbolTableForwardDecl();
332 void writeModuleInfo();
333 void writeValueAsMetadata(
const ValueAsMetadata *MD,
334 SmallVectorImpl<uint64_t> &Record);
335 void writeMDTuple(
const MDTuple *
N, SmallVectorImpl<uint64_t> &Record,
337 unsigned createDILocationAbbrev();
338 void writeDILocation(
const DILocation *
N, SmallVectorImpl<uint64_t> &Record,
340 unsigned createGenericDINodeAbbrev();
342 SmallVectorImpl<uint64_t> &Record,
unsigned &Abbrev);
343 void writeDISubrange(
const DISubrange *
N, SmallVectorImpl<uint64_t> &Record,
346 SmallVectorImpl<uint64_t> &Record,
349 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
353 SmallVectorImpl<uint64_t> &Record,
356 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
358 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
360 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
362 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
364 SmallVectorImpl<uint64_t> &Record,
366 void writeDIFile(
const DIFile *
N, SmallVectorImpl<uint64_t> &Record,
369 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
371 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
373 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
375 SmallVectorImpl<uint64_t> &Record,
378 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
381 void writeDIMacro(
const DIMacro *
N, SmallVectorImpl<uint64_t> &Record,
385 void writeDIArgList(
const DIArgList *
N, SmallVectorImpl<uint64_t> &Record);
386 void writeDIModule(
const DIModule *
N, SmallVectorImpl<uint64_t> &Record,
388 void writeDIAssignID(
const DIAssignID *
N, SmallVectorImpl<uint64_t> &Record,
391 SmallVectorImpl<uint64_t> &Record,
394 SmallVectorImpl<uint64_t> &Record,
397 SmallVectorImpl<uint64_t> &Record,
400 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
402 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
404 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
406 SmallVectorImpl<uint64_t> &Record,
409 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
411 SmallVectorImpl<uint64_t> &Record,
413 unsigned createNamedMetadataAbbrev();
414 void writeNamedMetadata(SmallVectorImpl<uint64_t> &Record);
415 unsigned createMetadataStringsAbbrev();
417 SmallVectorImpl<uint64_t> &Record);
419 SmallVectorImpl<uint64_t> &Record,
420 std::vector<unsigned> *MDAbbrevs =
nullptr,
421 std::vector<uint64_t> *IndexPos =
nullptr);
422 void writeModuleMetadata();
423 void writeFunctionMetadata(
const Function &
F);
424 void writeFunctionMetadataAttachment(
const Function &
F);
425 void pushGlobalMetadataAttachment(SmallVectorImpl<uint64_t> &Record,
426 const GlobalObject &GO);
427 void writeModuleMetadataKinds();
428 void writeOperandBundleTags();
429 void writeSyncScopeNames();
430 void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
431 void writeModuleConstants();
432 bool pushValueAndType(
const Value *V,
unsigned InstID,
433 SmallVectorImpl<unsigned> &Vals);
434 bool pushValueOrMetadata(
const Value *V,
unsigned InstID,
435 SmallVectorImpl<unsigned> &Vals);
436 void writeOperandBundles(
const CallBase &CB,
unsigned InstID);
437 void pushValue(
const Value *V,
unsigned InstID,
438 SmallVectorImpl<unsigned> &Vals);
439 void pushValueSigned(
const Value *V,
unsigned InstID,
440 SmallVectorImpl<uint64_t> &Vals);
441 void writeInstruction(
const Instruction &
I,
unsigned InstID,
442 SmallVectorImpl<unsigned> &Vals);
443 void writeFunctionLevelValueSymbolTable(
const ValueSymbolTable &VST);
444 void writeGlobalValueSymbolTable(
445 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
446 void writeUseList(UseListOrder &&Order);
447 void writeUseListBlock(
const Function *
F);
449 writeFunction(
const Function &
F,
450 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
451 void writeBlockInfo();
452 void writeModuleHash(StringRef View);
455 return unsigned(SSID);
458 unsigned getEncodedAlign(MaybeAlign Alignment) {
return encode(Alignment); }
462class IndexBitcodeWriter :
public BitcodeWriterBase {
464 const ModuleSummaryIndex &
Index;
477 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
481 std::vector<uint64_t> StackIds;
486 DenseMap<unsigned, unsigned> StackIdIndicesToIndex;
489 unsigned GlobalValueId = 0;
493 DenseMap<StringRef, uint64_t> ModuleIdMap;
503 BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder,
504 const ModuleSummaryIndex &Index,
507 : BitcodeWriterBase(Stream, StrtabBuilder),
Index(
Index),
508 DecSummaries(DecSummaries),
509 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
513 auto RecordStackIdReference = [&](
unsigned StackIdIndex) {
518 StackIdIndicesToIndex.
insert({StackIdIndex, StackIds.size()});
520 StackIds.push_back(
Index.getStackIdAtIndex(StackIdIndex));
527 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
528 GUIDToValueIdMap[
I.first] = ++GlobalValueId;
540 for (
auto &CI :
FS->callsites()) {
551 if (CI.StackIdIndices.empty()) {
552 GUIDToValueIdMap[CI.Callee.getGUID()] = ++GlobalValueId;
555 for (
auto Idx : CI.StackIdIndices)
556 RecordStackIdReference(Idx);
559 for (
auto &AI :
FS->allocs())
560 for (
auto &MIB : AI.MIBs)
561 for (
auto Idx : MIB.StackIdIndices)
562 RecordStackIdReference(Idx);
568 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
573 template<
typename Functor>
574 void forEachSummary(Functor Callback) {
575 if (ModuleToSummariesForIndex) {
576 for (
auto &M : *ModuleToSummariesForIndex)
577 for (
auto &Summary :
M.second) {
583 Callback({AS->getAliaseeGUID(), &AS->getAliasee()},
true);
586 for (
auto &Summaries : Index)
587 for (
auto &Summary : Summaries.second.getSummaryList())
596 template <
typename Functor>
void forEachModule(Functor Callback) {
597 if (ModuleToSummariesForIndex) {
598 for (
const auto &M : *ModuleToSummariesForIndex) {
599 const auto &MPI =
Index.modulePaths().find(
M.first);
600 if (MPI ==
Index.modulePaths().end()) {
604 assert(ModuleToSummariesForIndex->size() == 1);
614 std::vector<StringRef> ModulePaths;
615 for (
auto &[ModPath,
_] :
Index.modulePaths())
616 ModulePaths.push_back(ModPath);
618 for (
auto &ModPath : ModulePaths)
627 void writeModStrings();
628 void writeCombinedGlobalValueSummary();
631 auto VMI = GUIDToValueIdMap.find(ValGUID);
632 if (VMI == GUIDToValueIdMap.end())
637 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
672 case Instruction::Add:
674 case Instruction::Sub:
676 case Instruction::Mul:
679 case Instruction::FDiv:
682 case Instruction::FRem:
694 unsigned Encoding = 0;
695 switch (
I.getOperation()) {
768 if (
I.isElementwise())
803 case Attribute::Alignment:
805 case Attribute::AllocAlign:
807 case Attribute::AllocSize:
809 case Attribute::AlwaysInline:
811 case Attribute::Builtin:
813 case Attribute::ByVal:
815 case Attribute::Convergent:
817 case Attribute::InAlloca:
819 case Attribute::Cold:
821 case Attribute::DisableSanitizerInstrumentation:
823 case Attribute::FnRetThunkExtern:
825 case Attribute::Flatten:
829 case Attribute::ElementType:
831 case Attribute::HybridPatchable:
833 case Attribute::InlineHint:
835 case Attribute::InReg:
837 case Attribute::JumpTable:
839 case Attribute::MinSize:
841 case Attribute::AllocatedPointer:
843 case Attribute::AllocKind:
845 case Attribute::Memory:
847 case Attribute::NoFPClass:
849 case Attribute::Naked:
851 case Attribute::Nest:
853 case Attribute::NoAlias:
855 case Attribute::NoBuiltin:
857 case Attribute::NoCallback:
859 case Attribute::NoDivergenceSource:
861 case Attribute::NoDuplicate:
863 case Attribute::NoFree:
865 case Attribute::NoImplicitFloat:
867 case Attribute::NoInline:
869 case Attribute::NoRecurse:
871 case Attribute::NoMerge:
873 case Attribute::NonLazyBind:
875 case Attribute::NonNull:
877 case Attribute::Dereferenceable:
879 case Attribute::DereferenceableOrNull:
881 case Attribute::NoRedZone:
883 case Attribute::NoReturn:
885 case Attribute::NoSync:
887 case Attribute::NoCfCheck:
889 case Attribute::NoProfile:
891 case Attribute::SkipProfile:
893 case Attribute::NoUnwind:
895 case Attribute::NoSanitizeBounds:
897 case Attribute::NoSanitizeCoverage:
899 case Attribute::NullPointerIsValid:
901 case Attribute::OptimizeForDebugging:
903 case Attribute::OptForFuzzing:
905 case Attribute::OptimizeForSize:
907 case Attribute::OptimizeNone:
909 case Attribute::ReadNone:
911 case Attribute::ReadOnly:
913 case Attribute::Returned:
915 case Attribute::ReturnsTwice:
917 case Attribute::SExt:
919 case Attribute::Speculatable:
921 case Attribute::StackAlignment:
923 case Attribute::StackProtect:
925 case Attribute::StackProtectReq:
927 case Attribute::StackProtectStrong:
929 case Attribute::SafeStack:
931 case Attribute::ShadowCallStack:
933 case Attribute::StrictFP:
935 case Attribute::StructRet:
937 case Attribute::SanitizeAddress:
939 case Attribute::SanitizeAllocToken:
941 case Attribute::SanitizeHWAddress:
943 case Attribute::SanitizeThread:
945 case Attribute::SanitizeType:
947 case Attribute::SanitizeMemory:
949 case Attribute::SanitizeNumericalStability:
951 case Attribute::SanitizeRealtime:
953 case Attribute::SanitizeRealtimeBlocking:
955 case Attribute::SpeculativeLoadHardening:
957 case Attribute::SwiftError:
959 case Attribute::SwiftSelf:
961 case Attribute::SwiftAsync:
963 case Attribute::UWTable:
965 case Attribute::VScaleRange:
967 case Attribute::WillReturn:
969 case Attribute::WriteOnly:
971 case Attribute::ZExt:
973 case Attribute::ImmArg:
975 case Attribute::SanitizeMemTag:
977 case Attribute::Preallocated:
979 case Attribute::NoUndef:
981 case Attribute::ByRef:
983 case Attribute::MustProgress:
985 case Attribute::PresplitCoroutine:
987 case Attribute::Writable:
989 case Attribute::CoroDestroyOnlyWhenComplete:
991 case Attribute::CoroElideSafe:
993 case Attribute::DeadOnUnwind:
995 case Attribute::Range:
997 case Attribute::Initializes:
999 case Attribute::NoExt:
1001 case Attribute::Captures:
1003 case Attribute::DeadOnReturn:
1005 case Attribute::NoCreateUndefOrPoison:
1007 case Attribute::DenormalFPEnv:
1009 case Attribute::NoOutline:
1024 if ((int64_t)V >= 0)
1035 unsigned NumWords =
A.getActiveWords();
1036 const uint64_t *RawData =
A.getRawData();
1037 for (
unsigned i = 0; i < NumWords; i++)
1057void ModuleBitcodeWriter::writeAttributeGroupTable() {
1058 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
1060 if (AttrGrps.empty())
return;
1064 SmallVector<uint64_t, 64>
Record;
1066 unsigned AttrListIndex = Pair.first;
1067 AttributeSet AS = Pair.second;
1069 Record.push_back(AttrListIndex);
1072 if (Attr.isEnumAttribute()) {
1075 }
else if (Attr.isIntAttribute()) {
1077 Attribute::AttrKind
Kind = Attr.getKindAsEnum();
1079 if (Kind == Attribute::Memory) {
1084 Record.push_back(Attr.getValueAsInt());
1086 }
else if (Attr.isStringAttribute()) {
1087 StringRef
Kind = Attr.getKindAsString();
1088 StringRef Val = Attr.getValueAsString();
1097 }
else if (Attr.isTypeAttribute()) {
1098 Type *Ty = Attr.getValueAsType();
1099 Record.push_back(Ty ? 6 : 5);
1103 }
else if (Attr.isConstantRangeAttribute()) {
1109 assert(Attr.isConstantRangeListAttribute());
1115 for (
auto &CR : Val)
1127void ModuleBitcodeWriter::writeAttributeTable() {
1129 if (
Attrs.empty())
return;
1133 SmallVector<uint64_t, 64>
Record;
1134 for (
const AttributeList &AL : Attrs) {
1135 for (
unsigned i :
AL.indexes()) {
1136 AttributeSet AS =
AL.getAttributes(i);
1149void ModuleBitcodeWriter::writeTypeTable() {
1153 SmallVector<uint64_t, 64> TypeVals;
1158 auto Abbv = std::make_shared<BitCodeAbbrev>();
1160 Abbv->Add(BitCodeAbbrevOp(0));
1161 unsigned OpaquePtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1164 Abbv = std::make_shared<BitCodeAbbrev>();
1169 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1172 Abbv = std::make_shared<BitCodeAbbrev>();
1177 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1180 Abbv = std::make_shared<BitCodeAbbrev>();
1184 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1187 Abbv = std::make_shared<BitCodeAbbrev>();
1192 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1195 Abbv = std::make_shared<BitCodeAbbrev>();
1199 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1207 for (
Type *
T : TypeList) {
1208 int AbbrevToUse = 0;
1211 switch (
T->getTypeID()) {
1221 case Type::MetadataTyID:
1226 case Type::ByteTyID:
1231 case Type::IntegerTyID:
1236 case Type::PointerTyID: {
1243 AbbrevToUse = OpaquePtrAbbrev;
1246 case Type::FunctionTyID: {
1252 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1254 AbbrevToUse = FunctionAbbrev;
1257 case Type::StructTyID: {
1262 for (
Type *ET :
ST->elements())
1265 if (
ST->isLiteral()) {
1267 AbbrevToUse = StructAnonAbbrev;
1269 if (
ST->isOpaque()) {
1273 AbbrevToUse = StructNamedAbbrev;
1277 if (!
ST->getName().empty())
1283 case Type::ArrayTyID: {
1287 TypeVals.
push_back(AT->getNumElements());
1289 AbbrevToUse = ArrayAbbrev;
1292 case Type::FixedVectorTyID:
1293 case Type::ScalableVectorTyID: {
1298 TypeVals.
push_back(VT->getElementCount().getKnownMinValue());
1304 case Type::TargetExtTyID: {
1310 for (
Type *InnerTy :
TET->type_params())
1315 case Type::TypedPointerTyID:
1320 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
1361 RawFlags |= Flags.ReadNone;
1362 RawFlags |= (Flags.ReadOnly << 1);
1363 RawFlags |= (Flags.NoRecurse << 2);
1364 RawFlags |= (Flags.ReturnDoesNotAlias << 3);
1365 RawFlags |= (Flags.NoInline << 4);
1366 RawFlags |= (Flags.AlwaysInline << 5);
1367 RawFlags |= (Flags.NoUnwind << 6);
1368 RawFlags |= (Flags.MayThrow << 7);
1369 RawFlags |= (Flags.HasUnknownCall << 8);
1370 RawFlags |= (Flags.MustBeUnreachable << 9);
1377 bool ImportAsDecl =
false) {
1380 RawFlags |= Flags.NotEligibleToImport;
1381 RawFlags |= (Flags.Live << 1);
1382 RawFlags |= (Flags.DSOLocal << 2);
1383 RawFlags |= (Flags.CanAutoHide << 3);
1388 RawFlags = (RawFlags << 4) | Flags.Linkage;
1390 RawFlags |= (Flags.Visibility << 8);
1392 unsigned ImportType = Flags.ImportType | ImportAsDecl;
1393 RawFlags |= (ImportType << 10);
1395 RawFlags |= (Flags.NoRenameOnPromotion << 11);
1401 uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1402 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1445 switch (
C.getSelectionKind()) {
1469size_t ModuleBitcodeWriter::addToStrtab(StringRef Str) {
1472 return StrtabBuilder.
add(Str);
1475void ModuleBitcodeWriter::writeComdats() {
1490void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1495 auto Abbv = std::make_shared<BitCodeAbbrev>();
1501 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1517 bool isChar6 =
true;
1518 for (
char C : Str) {
1521 if ((
unsigned char)
C & 128)
1530static_assert(
sizeof(GlobalValue::SanitizerMetadata) <=
sizeof(unsigned),
1531 "Sanitizer Metadata is too large for naive serialization.");
1534 return Meta.NoAddress | (
Meta.NoHWAddress << 1) |
1535 (
Meta.Memtag << 2) | (
Meta.IsDynInit << 3);
1541void ModuleBitcodeWriter::writeModuleInfo() {
1543 if (!
M.getTargetTriple().empty())
1545 M.getTargetTriple().str(), 0 );
1546 const std::string &
DL =
M.getDataLayoutStr();
1549 if (!
M.getModuleInlineAsm().empty())
1555 std::map<std::string, unsigned> SectionMap;
1556 std::map<std::string, unsigned> GCMap;
1557 MaybeAlign MaxGVarAlignment;
1558 unsigned MaxGlobalType = 0;
1559 for (
const GlobalVariable &GV :
M.globals()) {
1560 if (MaybeAlign
A = GV.getAlign())
1561 MaxGVarAlignment = !MaxGVarAlignment ? *
A : std::max(*MaxGVarAlignment, *
A);
1562 MaxGlobalType = std::max(MaxGlobalType, VE.
getTypeID(GV.getValueType()));
1563 if (GV.hasSection()) {
1565 unsigned &
Entry = SectionMap[std::string(GV.getSection())];
1569 Entry = SectionMap.size();
1573 for (
const Function &
F : M) {
1574 if (
F.hasSection()) {
1576 unsigned &
Entry = SectionMap[std::string(
F.getSection())];
1580 Entry = SectionMap.size();
1585 unsigned &
Entry = GCMap[
F.getGC()];
1589 Entry = GCMap.size();
1595 unsigned SimpleGVarAbbrev = 0;
1596 if (!
M.global_empty()) {
1598 auto Abbv = std::make_shared<BitCodeAbbrev>();
1609 if (!MaxGVarAlignment)
1610 Abbv->Add(BitCodeAbbrevOp(0));
1612 unsigned MaxEncAlignment = getEncodedAlign(MaxGVarAlignment);
1616 if (SectionMap.empty())
1617 Abbv->Add(BitCodeAbbrevOp(0));
1622 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1636 auto Abbv = std::make_shared<BitCodeAbbrev>();
1639 Abbv->Add(AbbrevOpToUse);
1640 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1642 for (
const auto P :
M.getSourceFileName())
1651 for (
const GlobalVariable &GV :
M.globals()) {
1652 unsigned AbbrevToUse = 0;
1658 Vals.
push_back(addToStrtab(GV.getName()));
1661 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1665 Vals.
push_back(getEncodedAlign(GV.getAlign()));
1666 Vals.
push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1668 if (GV.isThreadLocal() ||
1670 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1671 GV.isExternallyInitialized() ||
1673 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1674 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1678 Vals.
push_back(GV.isExternallyInitialized());
1682 auto AL = GV.getAttributesAsList(AttributeList::FunctionIndex);
1686 Vals.
push_back(addToStrtab(GV.getPartition()));
1687 Vals.
push_back(GV.getPartition().size());
1690 GV.getSanitizerMetadata())
1694 AbbrevToUse = SimpleGVarAbbrev;
1702 for (
const Function &
F : M) {
1715 Vals.
push_back(getEncodedAlign(
F.getAlign()));
1716 Vals.
push_back(
F.hasSection() ? SectionMap[std::string(
F.getSection())]
1728 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1732 Vals.
push_back(addToStrtab(
F.getPartition()));
1734 Vals.
push_back(getEncodedAlign(
F.getPreferredAlignment()));
1736 unsigned AbbrevToUse = 0;
1742 for (
const GlobalAlias &
A :
M.aliases()) {
1749 Vals.
push_back(
A.getType()->getAddressSpace());
1757 Vals.
push_back(addToStrtab(
A.getPartition()));
1760 unsigned AbbrevToUse = 0;
1766 for (
const GlobalIFunc &
I :
M.ifuncs()) {
1772 Vals.
push_back(
I.getType()->getAddressSpace());
1777 Vals.
push_back(addToStrtab(
I.getPartition()));
1783 writeValueSymbolTableForwardDecl();
1790 if (OBO->hasNoSignedWrap())
1792 if (OBO->hasNoUnsignedWrap())
1798 if (PDI->isDisjoint())
1801 if (FPMO->hasAllowReassoc())
1803 if (FPMO->hasNoNaNs())
1805 if (FPMO->hasNoInfs())
1807 if (FPMO->hasNoSignedZeros())
1809 if (FPMO->hasAllowReciprocal())
1811 if (FPMO->hasAllowContract())
1813 if (FPMO->hasApproxFunc())
1816 if (NNI->hasNonNeg())
1819 if (TI->hasNoSignedWrap())
1821 if (TI->hasNoUnsignedWrap())
1824 if (
GEP->isInBounds())
1826 if (
GEP->hasNoUnsignedSignedWrap())
1828 if (
GEP->hasNoUnsignedWrap())
1831 if (ICmp->hasSameSign())
1838void ModuleBitcodeWriter::writeValueAsMetadata(
1839 const ValueAsMetadata *MD, SmallVectorImpl<uint64_t> &Record) {
1848void ModuleBitcodeWriter::writeMDTuple(
const MDTuple *
N,
1849 SmallVectorImpl<uint64_t> &Record,
1851 for (
const MDOperand &MDO :
N->operands()) {
1854 "Unexpected function-local metadata");
1863unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1866 auto Abbv = std::make_shared<BitCodeAbbrev>();
1879void ModuleBitcodeWriter::writeDILocation(
const DILocation *
N,
1880 SmallVectorImpl<uint64_t> &Record,
1883 Abbrev = createDILocationAbbrev();
1885 Record.push_back(
N->isDistinct());
1886 Record.push_back(
N->getLine());
1887 Record.push_back(
N->getColumn());
1890 Record.push_back(
N->isImplicitCode());
1891 Record.push_back(
N->getAtomGroup());
1892 Record.push_back(
N->getAtomRank());
1897unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1900 auto Abbv = std::make_shared<BitCodeAbbrev>();
1911void ModuleBitcodeWriter::writeGenericDINode(
const GenericDINode *
N,
1912 SmallVectorImpl<uint64_t> &Record,
1915 Abbrev = createGenericDINodeAbbrev();
1917 Record.push_back(
N->isDistinct());
1918 Record.push_back(
N->getTag());
1921 for (
auto &
I :
N->operands())
1928void ModuleBitcodeWriter::writeDISubrange(
const DISubrange *
N,
1929 SmallVectorImpl<uint64_t> &Record,
1931 const uint64_t
Version = 2 << 1;
1942void ModuleBitcodeWriter::writeDIGenericSubrange(
1943 const DIGenericSubrange *
N, SmallVectorImpl<uint64_t> &Record,
1945 Record.push_back((uint64_t)
N->isDistinct());
1955void ModuleBitcodeWriter::writeDIEnumerator(
const DIEnumerator *
N,
1956 SmallVectorImpl<uint64_t> &Record,
1958 const uint64_t IsBigInt = 1 << 2;
1959 Record.push_back(IsBigInt | (
N->isUnsigned() << 1) |
N->isDistinct());
1960 Record.push_back(
N->getValue().getBitWidth());
1968void ModuleBitcodeWriter::writeDIBasicType(
const DIBasicType *
N,
1969 SmallVectorImpl<uint64_t> &Record,
1971 const unsigned SizeIsMetadata = 0x2;
1972 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1973 Record.push_back(
N->getTag());
1976 Record.push_back(
N->getAlignInBits());
1977 Record.push_back(
N->getEncoding());
1978 Record.push_back(
N->getFlags());
1979 Record.push_back(
N->getNumExtraInhabitants());
1980 Record.push_back(
N->getDataSizeInBits());
1982 Record.push_back(
N->getLine());
1989void ModuleBitcodeWriter::writeDIFixedPointType(
1990 const DIFixedPointType *
N, SmallVectorImpl<uint64_t> &Record,
1992 const unsigned SizeIsMetadata = 0x2;
1993 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1994 Record.push_back(
N->getTag());
1997 Record.push_back(
N->getAlignInBits());
1998 Record.push_back(
N->getEncoding());
1999 Record.push_back(
N->getFlags());
2000 Record.push_back(
N->getKind());
2001 Record.push_back(
N->getFactorRaw());
2003 auto WriteWideInt = [&](
const APInt &
Value) {
2006 uint64_t NumWords =
Value.getActiveWords();
2007 uint64_t
Encoded = (NumWords << 32) |
Value.getBitWidth();
2008 Record.push_back(Encoded);
2012 WriteWideInt(
N->getNumeratorRaw());
2013 WriteWideInt(
N->getDenominatorRaw());
2016 Record.push_back(
N->getLine());
2023void ModuleBitcodeWriter::writeDIStringType(
const DIStringType *
N,
2024 SmallVectorImpl<uint64_t> &Record,
2026 const unsigned SizeIsMetadata = 0x2;
2027 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2028 Record.push_back(
N->getTag());
2034 Record.push_back(
N->getAlignInBits());
2035 Record.push_back(
N->getEncoding());
2041void ModuleBitcodeWriter::writeDIDerivedType(
const DIDerivedType *
N,
2042 SmallVectorImpl<uint64_t> &Record,
2044 const unsigned SizeIsMetadata = 0x2;
2045 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2046 Record.push_back(
N->getTag());
2049 Record.push_back(
N->getLine());
2053 Record.push_back(
N->getAlignInBits());
2055 Record.push_back(
N->getFlags());
2060 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
2061 Record.push_back(*DWARFAddressSpace + 1);
2067 if (
auto PtrAuthData =
N->getPtrAuthData())
2068 Record.push_back(PtrAuthData->RawData);
2076void ModuleBitcodeWriter::writeDISubrangeType(
const DISubrangeType *
N,
2077 SmallVectorImpl<uint64_t> &Record,
2079 const unsigned SizeIsMetadata = 0x2;
2080 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2083 Record.push_back(
N->getLine());
2086 Record.push_back(
N->getAlignInBits());
2087 Record.push_back(
N->getFlags());
2098void ModuleBitcodeWriter::writeDICompositeType(
2099 const DICompositeType *
N, SmallVectorImpl<uint64_t> &Record,
2101 const unsigned IsNotUsedInOldTypeRef = 0x2;
2102 const unsigned SizeIsMetadata = 0x4;
2103 Record.push_back(SizeIsMetadata | IsNotUsedInOldTypeRef |
2104 (
unsigned)
N->isDistinct());
2105 Record.push_back(
N->getTag());
2108 Record.push_back(
N->getLine());
2112 Record.push_back(
N->getAlignInBits());
2114 Record.push_back(
N->getFlags());
2116 Record.push_back(
N->getRuntimeLang());
2126 Record.push_back(
N->getNumExtraInhabitants());
2136void ModuleBitcodeWriter::writeDISubroutineType(
2137 const DISubroutineType *
N, SmallVectorImpl<uint64_t> &Record,
2139 const unsigned HasNoOldTypeRefs = 0x2;
2140 Record.push_back(HasNoOldTypeRefs | (
unsigned)
N->isDistinct());
2141 Record.push_back(
N->getFlags());
2149void ModuleBitcodeWriter::writeDIFile(
const DIFile *
N,
2150 SmallVectorImpl<uint64_t> &Record,
2152 Record.push_back(
N->isDistinct());
2155 if (
N->getRawChecksum()) {
2156 Record.push_back(
N->getRawChecksum()->Kind);
2164 auto Source =
N->getRawSource();
2172void ModuleBitcodeWriter::writeDICompileUnit(
const DICompileUnit *
N,
2173 SmallVectorImpl<uint64_t> &Record,
2175 assert(
N->isDistinct() &&
"Expected distinct compile units");
2178 auto Lang =
N->getSourceLanguage();
2179 Record.push_back(Lang.getName());
2182 if (Lang.hasVersionedName())
2183 Record.back() ^= (uint64_t(1) << 63);
2187 Record.push_back(
N->isOptimized());
2189 Record.push_back(
N->getRuntimeVersion());
2191 Record.push_back(
N->getEmissionKind());
2197 Record.push_back(
N->getDWOId());
2199 Record.push_back(
N->getSplitDebugInlining());
2200 Record.push_back(
N->getDebugInfoForProfiling());
2201 Record.push_back((
unsigned)
N->getNameTableKind());
2202 Record.push_back(
N->getRangesBaseAddress());
2205 Record.push_back(Lang.hasVersionedName() ? Lang.getVersion() : 0);
2206 Record.push_back(Lang.getDialect());
2212void ModuleBitcodeWriter::writeDISubprogram(
const DISubprogram *
N,
2213 SmallVectorImpl<uint64_t> &Record,
2215 const uint64_t HasUnitFlag = 1 << 1;
2216 const uint64_t HasSPFlagsFlag = 1 << 2;
2217 Record.push_back(uint64_t(
N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
2222 Record.push_back(
N->getLine());
2224 Record.push_back(
N->getScopeLine());
2226 Record.push_back(
N->getSPFlags());
2227 Record.push_back(
N->getVirtualIndex());
2228 Record.push_back(
N->getFlags());
2233 Record.push_back(
N->getThisAdjustment());
2237 Record.push_back(
N->getKeyInstructionsEnabled());
2243void ModuleBitcodeWriter::writeDILexicalBlock(
const DILexicalBlock *
N,
2244 SmallVectorImpl<uint64_t> &Record,
2246 Record.push_back(
N->isDistinct());
2249 Record.push_back(
N->getLine());
2250 Record.push_back(
N->getColumn());
2256void ModuleBitcodeWriter::writeDILexicalBlockFile(
2257 const DILexicalBlockFile *
N, SmallVectorImpl<uint64_t> &Record,
2259 Record.push_back(
N->isDistinct());
2262 Record.push_back(
N->getDiscriminator());
2268void ModuleBitcodeWriter::writeDICommonBlock(
const DICommonBlock *
N,
2269 SmallVectorImpl<uint64_t> &Record,
2271 Record.push_back(
N->isDistinct());
2276 Record.push_back(
N->getLineNo());
2282void ModuleBitcodeWriter::writeDINamespace(
const DINamespace *
N,
2283 SmallVectorImpl<uint64_t> &Record,
2285 Record.push_back(
N->isDistinct() |
N->getExportSymbols() << 1);
2293void ModuleBitcodeWriter::writeDIMacro(
const DIMacro *
N,
2294 SmallVectorImpl<uint64_t> &Record,
2296 Record.push_back(
N->isDistinct());
2297 Record.push_back(
N->getMacinfoType());
2298 Record.push_back(
N->getLine());
2306void ModuleBitcodeWriter::writeDIMacroFile(
const DIMacroFile *
N,
2307 SmallVectorImpl<uint64_t> &Record,
2309 Record.push_back(
N->isDistinct());
2310 Record.push_back(
N->getMacinfoType());
2311 Record.push_back(
N->getLine());
2319void ModuleBitcodeWriter::writeDIArgList(
const DIArgList *
N,
2320 SmallVectorImpl<uint64_t> &Record) {
2321 Record.reserve(
N->getArgs().size());
2322 for (ValueAsMetadata *MD :
N->getArgs())
2329void ModuleBitcodeWriter::writeDIModule(
const DIModule *
N,
2330 SmallVectorImpl<uint64_t> &Record,
2332 Record.push_back(
N->isDistinct());
2333 for (
auto &
I :
N->operands())
2335 Record.push_back(
N->getLineNo());
2336 Record.push_back(
N->getIsDecl());
2342void ModuleBitcodeWriter::writeDIAssignID(
const DIAssignID *
N,
2343 SmallVectorImpl<uint64_t> &Record,
2346 Record.push_back(
N->isDistinct());
2351void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2352 const DITemplateTypeParameter *
N, SmallVectorImpl<uint64_t> &Record,
2354 Record.push_back(
N->isDistinct());
2357 Record.push_back(
N->isDefault());
2363void ModuleBitcodeWriter::writeDITemplateValueParameter(
2364 const DITemplateValueParameter *
N, SmallVectorImpl<uint64_t> &Record,
2366 Record.push_back(
N->isDistinct());
2367 Record.push_back(
N->getTag());
2370 Record.push_back(
N->isDefault());
2377void ModuleBitcodeWriter::writeDIGlobalVariable(
2378 const DIGlobalVariable *
N, SmallVectorImpl<uint64_t> &Record,
2380 const uint64_t
Version = 2 << 1;
2386 Record.push_back(
N->getLine());
2388 Record.push_back(
N->isLocalToUnit());
2389 Record.push_back(
N->isDefinition());
2392 Record.push_back(
N->getAlignInBits());
2399void ModuleBitcodeWriter::writeDILocalVariable(
2400 const DILocalVariable *
N, SmallVectorImpl<uint64_t> &Record,
2415 const uint64_t HasAlignmentFlag = 1 << 1;
2416 Record.push_back((uint64_t)
N->isDistinct() | HasAlignmentFlag);
2420 Record.push_back(
N->getLine());
2422 Record.push_back(
N->getArg());
2423 Record.push_back(
N->getFlags());
2424 Record.push_back(
N->getAlignInBits());
2431void ModuleBitcodeWriter::writeDILabel(
2432 const DILabel *
N, SmallVectorImpl<uint64_t> &Record,
2434 uint64_t IsArtificialFlag = uint64_t(
N->isArtificial()) << 1;
2435 Record.push_back((uint64_t)
N->isDistinct() | IsArtificialFlag);
2439 Record.push_back(
N->getLine());
2440 Record.push_back(
N->getColumn());
2441 Record.push_back(
N->getCoroSuspendIdx().has_value()
2442 ? (uint64_t)
N->getCoroSuspendIdx().value()
2443 : std::numeric_limits<uint64_t>::max());
2449void ModuleBitcodeWriter::writeDIExpression(
const DIExpression *
N,
2450 SmallVectorImpl<uint64_t> &Record,
2452 Record.reserve(
N->getElements().size() + 1);
2453 const uint64_t
Version = 3 << 1;
2455 Record.append(
N->elements_begin(),
N->elements_end());
2461void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2462 const DIGlobalVariableExpression *
N, SmallVectorImpl<uint64_t> &Record,
2464 Record.push_back(
N->isDistinct());
2472void ModuleBitcodeWriter::writeDIObjCProperty(
const DIObjCProperty *
N,
2473 SmallVectorImpl<uint64_t> &Record,
2475 Record.push_back(
N->isDistinct());
2478 Record.push_back(
N->getLine());
2481 Record.push_back(
N->getAttributes());
2488void ModuleBitcodeWriter::writeDIImportedEntity(
2489 const DIImportedEntity *
N, SmallVectorImpl<uint64_t> &Record,
2491 Record.push_back(
N->isDistinct());
2492 Record.push_back(
N->getTag());
2495 Record.push_back(
N->getLine());
2504unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2505 auto Abbv = std::make_shared<BitCodeAbbrev>();
2512void ModuleBitcodeWriter::writeNamedMetadata(
2513 SmallVectorImpl<uint64_t> &Record) {
2514 if (
M.named_metadata_empty())
2517 unsigned Abbrev = createNamedMetadataAbbrev();
2518 for (
const NamedMDNode &NMD :
M.named_metadata()) {
2520 StringRef Str = NMD.getName();
2521 Record.append(Str.bytes_begin(), Str.bytes_end());
2526 for (
const MDNode *
N : NMD.operands())
2533unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2534 auto Abbv = std::make_shared<BitCodeAbbrev>();
2546void ModuleBitcodeWriter::writeMetadataStrings(
2548 if (Strings.
empty())
2556 SmallString<256> Blob;
2558 BitstreamWriter
W(Blob);
2578#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
2579#include "llvm/IR/Metadata.def"
2583void ModuleBitcodeWriter::writeMetadataRecords(
2585 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2590#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
2591#include "llvm/IR/Metadata.def"
2597 assert(
N->isResolved() &&
"Expected forward references to be resolved");
2599 switch (
N->getMetadataID()) {
2602#define HANDLE_MDNODE_LEAF(CLASS) \
2603 case Metadata::CLASS##Kind: \
2605 write##CLASS(cast<CLASS>(N), Record, \
2606 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
2608 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
2610#include "llvm/IR/Metadata.def"
2621void ModuleBitcodeWriter::writeModuleMetadata() {
2622 if (!VE.
hasMDs() &&
M.named_metadata_empty())
2626 SmallVector<uint64_t, 64>
Record;
2630 std::vector<unsigned> MDAbbrevs;
2633 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2634 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2635 createGenericDINodeAbbrev();
2637 auto Abbv = std::make_shared<BitCodeAbbrev>();
2641 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2643 Abbv = std::make_shared<BitCodeAbbrev>();
2647 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2659 uint64_t Vals[] = {0, 0};
2669 std::vector<uint64_t> IndexPos;
2673 writeMetadataRecords(VE.
getNonMDStrings(), Record, &MDAbbrevs, &IndexPos);
2684 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2685 for (
auto &Elt : IndexPos) {
2686 auto EltDelta = Elt - PreviousValue;
2687 PreviousValue = Elt;
2696 writeNamedMetadata(Record);
2698 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2699 SmallVector<uint64_t, 4>
Record;
2701 pushGlobalMetadataAttachment(Record, GO);
2704 for (
const Function &
F : M)
2705 if (
F.isDeclaration() &&
F.hasMetadata())
2706 AddDeclAttachedMetadata(
F);
2707 for (
const GlobalIFunc &GI :
M.ifuncs())
2708 if (GI.hasMetadata())
2709 AddDeclAttachedMetadata(GI);
2712 for (
const GlobalVariable &GV :
M.globals())
2713 if (GV.hasMetadata())
2714 AddDeclAttachedMetadata(GV);
2719void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2724 SmallVector<uint64_t, 64>
Record;
2730void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2731 SmallVectorImpl<uint64_t> &Record,
const GlobalObject &GO) {
2735 for (
const auto &
I : MDs) {
2741void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &
F) {
2744 SmallVector<uint64_t, 64>
Record;
2746 if (
F.hasMetadata()) {
2747 pushGlobalMetadataAttachment(Record,
F);
2755 for (
const BasicBlock &BB :
F)
2756 for (
const Instruction &
I : BB) {
2758 I.getAllMetadataOtherThanDebugLoc(MDs);
2761 if (MDs.
empty())
continue;
2765 for (
const auto &[
ID, MD] : MDs) {
2776void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2777 SmallVector<uint64_t, 64>
Record;
2782 M.getMDKindNames(Names);
2784 if (Names.
empty())
return;
2788 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2789 Record.push_back(MDKindID);
2790 StringRef KName = Names[MDKindID];
2800void ModuleBitcodeWriter::writeOperandBundleTags() {
2808 M.getOperandBundleTags(Tags);
2815 SmallVector<uint64_t, 64>
Record;
2817 for (
auto Tag : Tags) {
2827void ModuleBitcodeWriter::writeSyncScopeNames() {
2829 M.getContext().getSyncScopeNames(SSNs);
2835 SmallVector<uint64_t, 64>
Record;
2836 for (
auto SSN : SSNs) {
2837 Record.append(SSN.begin(), SSN.end());
2845void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2847 if (FirstVal == LastVal)
return;
2851 unsigned AggregateAbbrev = 0;
2852 unsigned String8Abbrev = 0;
2853 unsigned CString7Abbrev = 0;
2854 unsigned CString6Abbrev = 0;
2858 auto Abbv = std::make_shared<BitCodeAbbrev>();
2862 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2865 Abbv = std::make_shared<BitCodeAbbrev>();
2869 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2871 Abbv = std::make_shared<BitCodeAbbrev>();
2875 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2877 Abbv = std::make_shared<BitCodeAbbrev>();
2881 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2884 SmallVector<uint64_t, 64>
Record;
2887 Type *LastTy =
nullptr;
2888 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2889 const Value *
V = Vals[i].first;
2891 if (
V->getType() != LastTy) {
2892 LastTy =
V->getType();
2895 CONSTANTS_SETTYPE_ABBREV);
2902 unsigned(
IA->hasSideEffects()) |
unsigned(
IA->isAlignStack()) << 1 |
2903 unsigned(
IA->getDialect() & 1) << 2 |
unsigned(
IA->canThrow()) << 3);
2906 StringRef AsmStr =
IA->getAsmString();
2911 StringRef ConstraintStr =
IA->getConstraintString();
2919 unsigned Code = -1U;
2920 unsigned AbbrevToUse = 0;
2921 if (
C->isNullValue()) {
2928 if (
IV->getBitWidth() <= 64) {
2929 uint64_t
V =
IV->getSExtValue();
2932 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2938 if (BV->getBitWidth() <= 64) {
2939 uint64_t
V = BV->getSExtValue();
2942 AbbrevToUse = CONSTANTS_BYTE_ABBREV;
2952 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2956 APInt api = CFP->getValueAPF().bitcastToAPInt();
2958 Record.push_back((p[1] << 48) | (p[0] >> 16));
2959 Record.push_back(p[0] & 0xffffLL);
2961 APInt api = CFP->getValueAPF().bitcastToAPInt();
2966 assert(0 &&
"Unknown FP type!");
2972 uint64_t NumElts = Str->getNumElements();
2974 if (Str->isCString()) {
2979 AbbrevToUse = String8Abbrev;
2983 for (uint64_t i = 0; i != NumElts; ++i) {
2984 unsigned char V = Str->getElementAsInteger(i);
2986 isCStr7 &= (
V & 128) == 0;
2992 AbbrevToUse = CString6Abbrev;
2994 AbbrevToUse = CString7Abbrev;
2995 }
else if (
const ConstantDataSequential *CDS =
2998 Type *EltTy = CDS->getElementType();
3000 for (uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
3001 Record.push_back(CDS->getElementAsInteger(i));
3003 for (uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
3005 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
3009 for (
const Value *
Op :
C->operands())
3011 AbbrevToUse = AggregateAbbrev;
3013 switch (
CE->getOpcode()) {
3020 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
3022 assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
3032 case Instruction::FNeg: {
3033 assert(
CE->getNumOperands() == 1 &&
"Unknown constant expr!");
3042 case Instruction::GetElementPtr: {
3047 if (std::optional<ConstantRange>
Range = GO->getInRange()) {
3051 for (
const Value *
Op :
CE->operands()) {
3057 case Instruction::ExtractElement:
3064 case Instruction::InsertElement:
3071 case Instruction::ShuffleVector:
3076 if (
C->getType() ==
C->getOperand(0)->getType()) {
3113 Stream.
EmitRecord(Code, Record, AbbrevToUse);
3120void ModuleBitcodeWriter::writeModuleConstants() {
3125 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
3127 writeConstants(i, Vals.size(),
true);
3141bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
3142 SmallVectorImpl<unsigned> &Vals) {
3146 if (ValID >= InstID) {
3153bool ModuleBitcodeWriter::pushValueOrMetadata(
const Value *V,
unsigned InstID,
3154 SmallVectorImpl<unsigned> &Vals) {
3155 bool IsMetadata =
V->getType()->isMetadataTy();
3163 return pushValueAndType(V, InstID, Vals);
3166void ModuleBitcodeWriter::writeOperandBundles(
const CallBase &CS,
3173 Record.push_back(
C.getOperandBundleTagID(Bundle.getTagName()));
3175 for (
auto &Input : Bundle.Inputs)
3176 pushValueOrMetadata(Input, InstID, Record);
3185void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
3186 SmallVectorImpl<unsigned> &Vals) {
3191void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
3192 SmallVectorImpl<uint64_t> &Vals) {
3194 int64_t diff = ((int32_t)InstID - (int32_t)ValID);
3199void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
3201 SmallVectorImpl<unsigned> &Vals) {
3203 unsigned AbbrevToUse = 0;
3205 switch (
I.getOpcode()) {
3209 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3210 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
3215 if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
3216 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
3222 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3223 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
3224 pushValue(
I.getOperand(1), InstID, Vals);
3228 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
3229 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
3234 case Instruction::FNeg: {
3236 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3237 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
3241 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
3242 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
3247 case Instruction::GetElementPtr: {
3249 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
3253 for (
const Value *
Op :
I.operands())
3254 pushValueAndType(
Op, InstID, Vals);
3257 case Instruction::ExtractValue: {
3259 pushValueAndType(
I.getOperand(0), InstID, Vals);
3264 case Instruction::InsertValue: {
3266 pushValueAndType(
I.getOperand(0), InstID, Vals);
3267 pushValueAndType(
I.getOperand(1), InstID, Vals);
3272 case Instruction::Select: {
3274 pushValueAndType(
I.getOperand(1), InstID, Vals);
3275 pushValue(
I.getOperand(2), InstID, Vals);
3276 pushValueAndType(
I.getOperand(0), InstID, Vals);
3282 case Instruction::ExtractElement:
3284 pushValueAndType(
I.getOperand(0), InstID, Vals);
3285 pushValueAndType(
I.getOperand(1), InstID, Vals);
3287 case Instruction::InsertElement:
3289 pushValueAndType(
I.getOperand(0), InstID, Vals);
3290 pushValue(
I.getOperand(1), InstID, Vals);
3291 pushValueAndType(
I.getOperand(2), InstID, Vals);
3293 case Instruction::ShuffleVector:
3295 pushValueAndType(
I.getOperand(0), InstID, Vals);
3296 pushValue(
I.getOperand(1), InstID, Vals);
3300 case Instruction::ICmp:
3301 case Instruction::FCmp: {
3304 AbbrevToUse = FUNCTION_INST_CMP_ABBREV;
3305 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3307 pushValue(
I.getOperand(1), InstID, Vals);
3313 AbbrevToUse = FUNCTION_INST_CMP_FLAGS_ABBREV;
3318 case Instruction::Ret:
3321 unsigned NumOperands =
I.getNumOperands();
3322 if (NumOperands == 0)
3323 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
3324 else if (NumOperands == 1) {
3325 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3326 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
3328 for (
const Value *
Op :
I.operands())
3329 pushValueAndType(
Op, InstID, Vals);
3333 case Instruction::UncondBr: {
3335 AbbrevToUse = FUNCTION_INST_BR_UNCOND_ABBREV;
3339 case Instruction::CondBr: {
3341 AbbrevToUse = FUNCTION_INST_BR_COND_ABBREV;
3345 pushValue(
II.getCondition(), InstID, Vals);
3347 case Instruction::Switch:
3352 pushValue(
SI.getCondition(), InstID, Vals);
3354 for (
auto Case :
SI.cases()) {
3360 case Instruction::IndirectBr:
3364 pushValue(
I.getOperand(0), InstID, Vals);
3369 case Instruction::Invoke: {
3372 FunctionType *FTy =
II->getFunctionType();
3374 if (
II->hasOperandBundles())
3375 writeOperandBundles(*
II, InstID);
3384 pushValueAndType(Callee, InstID, Vals);
3387 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3388 pushValue(
I.getOperand(i), InstID, Vals);
3391 if (FTy->isVarArg()) {
3392 for (
unsigned i = FTy->getNumParams(), e =
II->arg_size(); i != e; ++i)
3393 pushValueAndType(
I.getOperand(i), InstID, Vals);
3397 case Instruction::Resume:
3399 pushValueAndType(
I.getOperand(0), InstID, Vals);
3401 case Instruction::CleanupRet: {
3404 pushValue(CRI.getCleanupPad(), InstID, Vals);
3405 if (CRI.hasUnwindDest())
3409 case Instruction::CatchRet: {
3412 pushValue(CRI.getCatchPad(), InstID, Vals);
3416 case Instruction::CleanupPad:
3417 case Instruction::CatchPad: {
3421 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3423 unsigned NumArgOperands = FuncletPad.arg_size();
3425 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
3426 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
3429 case Instruction::CatchSwitch: {
3433 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3435 unsigned NumHandlers = CatchSwitch.getNumHandlers();
3437 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
3440 if (CatchSwitch.hasUnwindDest())
3444 case Instruction::CallBr: {
3450 writeOperandBundles(*CBI, InstID);
3465 pushValueAndType(Callee, InstID, Vals);
3468 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3469 pushValue(
I.getOperand(i), InstID, Vals);
3472 if (FTy->isVarArg()) {
3473 for (
unsigned i = FTy->getNumParams(), e = CBI->
arg_size(); i != e; ++i)
3474 pushValueAndType(
I.getOperand(i), InstID, Vals);
3478 case Instruction::Unreachable:
3480 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3483 case Instruction::PHI: {
3501 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
3506 case Instruction::LandingPad: {
3517 pushValueAndType(LP.
getClause(
I), InstID, Vals);
3522 case Instruction::Alloca: {
3528 using APV = AllocaPackedValues;
3530 unsigned EncodedAlign = getEncodedAlign(AI.
getAlign());
3532 Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3534 EncodedAlign >> APV::AlignLower::Bits);
3541 if (AS !=
M.getDataLayout().getAllocaAddrSpace())
3546 case Instruction::Load:
3549 pushValueAndType(
I.getOperand(0), InstID, Vals);
3552 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3553 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3563 case Instruction::Store:
3568 AbbrevToUse = FUNCTION_INST_STORE_ABBREV;
3570 if (pushValueAndType(
I.getOperand(1), InstID, Vals))
3572 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3582 case Instruction::AtomicCmpXchg:
3584 pushValueAndType(
I.getOperand(0), InstID, Vals);
3585 pushValueAndType(
I.getOperand(1), InstID, Vals);
3586 pushValue(
I.getOperand(2), InstID, Vals);
3597 case Instruction::AtomicRMW:
3599 pushValueAndType(
I.getOperand(0), InstID, Vals);
3600 pushValueAndType(
I.getOperand(1), InstID, Vals);
3608 case Instruction::Fence:
3613 case Instruction::Call: {
3618 writeOperandBundles(CI, InstID);
3638 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3642 if (FTy->isVarArg()) {
3643 for (
unsigned i = FTy->getNumParams(), e = CI.
arg_size(); i != e; ++i)
3648 case Instruction::VAArg:
3651 pushValue(
I.getOperand(0), InstID, Vals);
3654 case Instruction::Freeze:
3656 pushValueAndType(
I.getOperand(0), InstID, Vals);
3666void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3667 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3672 VSTOffset -= bitcodeStartBit();
3673 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
3677 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3681 auto Abbv = std::make_shared<BitCodeAbbrev>();
3685 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3687 for (
const Function &
F : M) {
3690 if (
F.isDeclaration())
3697 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
3698 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
3702 Record[1] = BitcodeIndex / 32 + 1;
3711void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3712 const ValueSymbolTable &VST) {
3720 SmallVector<uint64_t, 64> NameVals;
3726 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3735 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3739 AbbrevToUse = VST_ENTRY_6_ABBREV;
3741 AbbrevToUse = VST_ENTRY_7_ABBREV;
3744 for (
const auto P :
Name.getKey())
3748 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3755void ModuleBitcodeWriter::writeUseList(UseListOrder &&Order) {
3756 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3763 SmallVector<uint64_t, 64>
Record(Order.Shuffle.begin(), Order.Shuffle.end());
3768void ModuleBitcodeWriter::writeUseListBlock(
const Function *
F) {
3770 "Expected to be preserving use-list order");
3772 auto hasMore = [&]() {
3788void ModuleBitcodeWriter::writeFunction(
3790 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3807 unsigned CstStart, CstEnd;
3809 writeConstants(CstStart, CstEnd,
false);
3812 writeFunctionMetadata(
F);
3815 unsigned InstID = CstEnd;
3817 bool NeedsMetadataAttachment =
F.hasMetadata();
3819 DILocation *LastDL =
nullptr;
3820 SmallSetVector<Function *, 4> BlockAddressUsers;
3823 for (
const BasicBlock &BB :
F) {
3824 for (
const Instruction &
I : BB) {
3825 writeInstruction(
I, InstID, Vals);
3827 if (!
I.getType()->isVoidTy())
3831 NeedsMetadataAttachment |=
I.hasMetadataOtherThanDebugLoc();
3834 if (DILocation *
DL =
I.getDebugLoc()) {
3847 FUNCTION_DEBUG_LOC_ABBREV);
3857 if (
I.hasDbgRecords()) {
3861 auto PushValueOrMetadata = [&Vals, InstID,
3864 "RawLocation unexpectedly null in DbgVariableRecord");
3866 SmallVector<unsigned, 2> ValAndType;
3870 if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
3884 for (DbgRecord &DR :
I.DebugMarker->getDbgRecordRange()) {
3910 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3934 SmallPtrSet<Value *, 8> Visited{BA};
3935 while (!Worklist.
empty()) {
3937 for (User *U :
V->users()) {
3943 Visited.
insert(U).second)
3950 if (!BlockAddressUsers.
empty()) {
3959 if (
auto *Symtab =
F.getValueSymbolTable())
3960 writeFunctionLevelValueSymbolTable(*Symtab);
3962 if (NeedsMetadataAttachment)
3963 writeFunctionMetadataAttachment(
F);
3965 writeUseListBlock(&
F);
3971void ModuleBitcodeWriter::writeBlockInfo() {
3984 auto Abbv = std::make_shared<BitCodeAbbrev>();
3995 auto Abbv = std::make_shared<BitCodeAbbrev>();
4005 auto Abbv = std::make_shared<BitCodeAbbrev>();
4015 auto Abbv = std::make_shared<BitCodeAbbrev>();
4021 VST_BBENTRY_6_ABBREV)
4026 auto Abbv = std::make_shared<BitCodeAbbrev>();
4028 Abbv->Add(TypeAbbrevOp);
4030 CONSTANTS_SETTYPE_ABBREV)
4035 auto Abbv = std::make_shared<BitCodeAbbrev>();
4039 CONSTANTS_INTEGER_ABBREV)
4044 auto Abbv = std::make_shared<BitCodeAbbrev>();
4048 CONSTANTS_BYTE_ABBREV)
4053 auto Abbv = std::make_shared<BitCodeAbbrev>();
4061 CONSTANTS_CE_CAST_Abbrev)
4065 auto Abbv = std::make_shared<BitCodeAbbrev>();
4068 CONSTANTS_NULL_Abbrev)
4075 auto Abbv = std::make_shared<BitCodeAbbrev>();
4077 Abbv->Add(ValAbbrevOp);
4078 Abbv->Add(TypeAbbrevOp);
4082 FUNCTION_INST_LOAD_ABBREV)
4086 auto Abbv = std::make_shared<BitCodeAbbrev>();
4088 Abbv->Add(ValAbbrevOp);
4089 Abbv->Add(ValAbbrevOp);
4093 FUNCTION_INST_STORE_ABBREV)
4097 auto Abbv = std::make_shared<BitCodeAbbrev>();
4099 Abbv->Add(ValAbbrevOp);
4102 FUNCTION_INST_UNOP_ABBREV)
4106 auto Abbv = std::make_shared<BitCodeAbbrev>();
4108 Abbv->Add(ValAbbrevOp);
4112 FUNCTION_INST_UNOP_FLAGS_ABBREV)
4116 auto Abbv = std::make_shared<BitCodeAbbrev>();
4118 Abbv->Add(ValAbbrevOp);
4119 Abbv->Add(ValAbbrevOp);
4122 FUNCTION_INST_BINOP_ABBREV)
4126 auto Abbv = std::make_shared<BitCodeAbbrev>();
4128 Abbv->Add(ValAbbrevOp);
4129 Abbv->Add(ValAbbrevOp);
4133 FUNCTION_INST_BINOP_FLAGS_ABBREV)
4137 auto Abbv = std::make_shared<BitCodeAbbrev>();
4139 Abbv->Add(ValAbbrevOp);
4140 Abbv->Add(TypeAbbrevOp);
4143 FUNCTION_INST_CAST_ABBREV)
4147 auto Abbv = std::make_shared<BitCodeAbbrev>();
4149 Abbv->Add(ValAbbrevOp);
4150 Abbv->Add(TypeAbbrevOp);
4154 FUNCTION_INST_CAST_FLAGS_ABBREV)
4159 auto Abbv = std::make_shared<BitCodeAbbrev>();
4162 FUNCTION_INST_RET_VOID_ABBREV)
4166 auto Abbv = std::make_shared<BitCodeAbbrev>();
4168 Abbv->Add(ValAbbrevOp);
4170 FUNCTION_INST_RET_VAL_ABBREV)
4174 auto Abbv = std::make_shared<BitCodeAbbrev>();
4177 Abbv->Add(ValAbbrevOp);
4179 FUNCTION_INST_BR_UNCOND_ABBREV)
4183 auto Abbv = std::make_shared<BitCodeAbbrev>();
4186 Abbv->Add(ValAbbrevOp);
4187 Abbv->Add(ValAbbrevOp);
4188 Abbv->Add(ValAbbrevOp);
4190 FUNCTION_INST_BR_COND_ABBREV)
4194 auto Abbv = std::make_shared<BitCodeAbbrev>();
4197 FUNCTION_INST_UNREACHABLE_ABBREV)
4201 auto Abbv = std::make_shared<BitCodeAbbrev>();
4204 Abbv->Add(TypeAbbrevOp);
4206 Abbv->Add(ValAbbrevOp);
4208 FUNCTION_INST_GEP_ABBREV)
4212 auto Abbv = std::make_shared<BitCodeAbbrev>();
4214 Abbv->Add(ValAbbrevOp);
4215 Abbv->Add(ValAbbrevOp);
4218 FUNCTION_INST_CMP_ABBREV)
4222 auto Abbv = std::make_shared<BitCodeAbbrev>();
4224 Abbv->Add(ValAbbrevOp);
4225 Abbv->Add(ValAbbrevOp);
4229 FUNCTION_INST_CMP_FLAGS_ABBREV)
4233 auto Abbv = std::make_shared<BitCodeAbbrev>();
4238 Abbv->Add(ValAbbrevOp);
4240 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
4244 auto Abbv = std::make_shared<BitCodeAbbrev>();
4255 FUNCTION_DEBUG_LOC_ABBREV)
4263void IndexBitcodeWriter::writeModStrings() {
4269 auto Abbv = std::make_shared<BitCodeAbbrev>();
4274 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
4277 Abbv = std::make_shared<BitCodeAbbrev>();
4282 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
4285 Abbv = std::make_shared<BitCodeAbbrev>();
4290 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
4293 Abbv = std::make_shared<BitCodeAbbrev>();
4300 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
4303 forEachModule([&](
const StringMapEntry<ModuleHash> &MPSE) {
4305 const auto &Hash = MPSE.
getValue();
4307 unsigned AbbrevToUse = Abbrev8Bit;
4309 AbbrevToUse = Abbrev6Bit;
4311 AbbrevToUse = Abbrev7Bit;
4313 auto ModuleId = ModuleIdMap.
size();
4314 ModuleIdMap[
Key] = ModuleId;
4324 Vals.
assign(Hash.begin(), Hash.end());
4336template <
typename Fn>
4340 if (!FS->type_tests().empty())
4345 auto WriteVFuncIdVec = [&](
uint64_t Ty,
4350 for (
auto &VF : VFs) {
4351 Record.push_back(VF.GUID);
4352 Record.push_back(VF.Offset);
4358 FS->type_test_assume_vcalls());
4360 FS->type_checked_load_vcalls());
4362 auto WriteConstVCallVec = [&](
uint64_t Ty,
4364 for (
auto &VC : VCs) {
4366 Record.push_back(VC.VFunc.GUID);
4367 Record.push_back(VC.VFunc.Offset);
4374 FS->type_test_assume_const_vcalls());
4376 FS->type_checked_load_const_vcalls());
4386 if (!FS->paramAccesses().empty()) {
4388 for (
auto &Arg : FS->paramAccesses()) {
4389 size_t UndoSize =
Record.size();
4390 Record.push_back(Arg.ParamNo);
4391 WriteRange(Arg.Use);
4392 Record.push_back(Arg.Calls.size());
4393 for (
auto &
Call : Arg.Calls) {
4395 std::optional<unsigned> ValueID = GetValueID(
Call.Callee);
4402 Record.push_back(*ValueID);
4403 WriteRange(
Call.Offsets);
4414 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
4415 if (!FS->type_tests().empty())
4416 for (
auto &TT : FS->type_tests())
4417 ReferencedTypeIds.insert(TT);
4419 auto GetReferencedTypesFromVFuncIdVec =
4421 for (
auto &VF : VFs)
4422 ReferencedTypeIds.insert(VF.GUID);
4425 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4426 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4428 auto GetReferencedTypesFromConstVCallVec =
4430 for (
auto &VC : VCs)
4431 ReferencedTypeIds.insert(VC.VFunc.GUID);
4434 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4435 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
4471 NameVals.
push_back(Summary.TTRes.TheKind);
4472 NameVals.
push_back(Summary.TTRes.SizeM1BitWidth);
4473 NameVals.
push_back(Summary.TTRes.AlignLog2);
4474 NameVals.
push_back(Summary.TTRes.SizeM1);
4475 NameVals.
push_back(Summary.TTRes.BitMask);
4476 NameVals.
push_back(Summary.TTRes.InlineBits);
4478 for (
auto &W : Summary.WPDRes)
4490 for (
auto &
P : Summary) {
4492 NameVals.
push_back(
VE.getValueID(
P.VTableVI.getValue()));
4506 static_assert(std::is_same_v<LinearFrameId, unsigned>);
4507 for (
auto &AI : FS->allocs()) {
4508 for (
auto &MIB : AI.MIBs) {
4510 StackIdIndices.
reserve(MIB.StackIdIndices.size());
4511 for (
auto Id : MIB.StackIdIndices)
4512 StackIdIndices.
push_back(GetStackIndex(Id));
4514 CallStacks.insert({CallStacks.size(), StackIdIndices});
4527 assert(!CallStacks.empty());
4533 Builder.
build(std::move(CallStacks),
nullptr,
4537 return Builder.takeCallStackPos();
4542 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
bool PerModule,
4543 std::function<
unsigned(
const ValueInfo &VI)> GetValueID,
4544 std::function<
unsigned(
unsigned)> GetStackIndex,
4545 bool WriteContextSizeInfoIndex,
4550 for (
auto &CI : FS->callsites()) {
4554 assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4555 Record.push_back(GetValueID(CI.Callee));
4557 Record.push_back(CI.StackIdIndices.size());
4558 Record.push_back(CI.Clones.size());
4560 for (
auto Id : CI.StackIdIndices)
4561 Record.push_back(GetStackIndex(Id));
4569 for (
auto &AI : FS->allocs()) {
4573 assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4574 Record.push_back(AI.MIBs.size());
4576 Record.push_back(AI.Versions.size());
4577 for (
auto &MIB : AI.MIBs) {
4584 assert(CallStackCount <= CallStackPos.
size());
4585 Record.push_back(CallStackPos[CallStackCount++]);
4590 assert(AI.ContextSizeInfos.empty() ||
4591 AI.ContextSizeInfos.size() == AI.MIBs.size());
4593 if (WriteContextSizeInfoIndex && !AI.ContextSizeInfos.empty()) {
4601 ContextIds.
reserve(AI.ContextSizeInfos.size() * 2);
4602 for (
auto &Infos : AI.ContextSizeInfos) {
4603 Record.push_back(Infos.size());
4604 for (
auto [FullStackId, TotalSize] : Infos) {
4611 Record.push_back(TotalSize);
4629void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4630 SmallVector<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
4631 unsigned ValueID,
unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
4632 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
const Function &
F,
4633 DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
4640 Stream, FS, [&](
const ValueInfo &VI) -> std::optional<unsigned> {
4644 auto SpecialRefCnts =
FS->specialRefCounts();
4649 NameVals.
push_back(SpecialRefCnts.first);
4650 NameVals.
push_back(SpecialRefCnts.second);
4652 for (
auto &RI :
FS->refs())
4655 for (
auto &ECI :
FS->calls()) {
4656 NameVals.
push_back(getValueId(ECI.first));
4665 Stream, FS, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
4667 [&](
const ValueInfo &VI) {
return getValueId(VI); },
4668 [&](
unsigned I) {
return I; },
4669 true, CallStackPos, CallStackCount);
4674void ModuleBitcodeWriterBase::writeModuleLevelReferences(
4675 const GlobalVariable &V, SmallVector<uint64_t, 64> &NameVals,
4676 unsigned FSModRefsAbbrev,
unsigned FSModVTableRefsAbbrev) {
4677 auto VI =
Index->getValueInfo(
V.getGUID());
4678 if (!VI ||
VI.getSummaryList().empty()) {
4684 auto *
Summary =
VI.getSummaryList()[0].get();
4690 auto VTableFuncs =
VS->vTableFuncs();
4691 if (!VTableFuncs.empty())
4694 unsigned SizeBeforeRefs = NameVals.
size();
4695 for (
auto &RI :
VS->refs())
4701 if (VTableFuncs.empty())
4706 for (
auto &
P : VTableFuncs) {
4712 FSModVTableRefsAbbrev);
4719void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
4722 bool IsThinLTO =
true;
4725 IsThinLTO = MD->getZExtValue();
4737 if (
Index->enableSplitLTOUnit())
4739 if (
Index->hasUnifiedLTO())
4749 auto Abbv = std::make_shared<BitCodeAbbrev>();
4755 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4757 for (
const auto &GVI : valueIds()) {
4759 ArrayRef<uint32_t>{GVI.second,
4760 static_cast<uint32_t
>(GVI.first >> 32),
4761 static_cast<uint32_t
>(GVI.first)},
4765 if (!
Index->stackIds().empty()) {
4766 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4773 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4774 SmallVector<uint32_t> Vals;
4776 for (
auto Id :
Index->stackIds()) {
4777 Vals.
push_back(
static_cast<uint32_t
>(Id >> 32));
4778 Vals.
push_back(
static_cast<uint32_t
>(Id));
4783 unsigned ContextIdAbbvId = 0;
4786 auto ContextIdAbbv = std::make_shared<BitCodeAbbrev>();
4798 ContextIdAbbvId = Stream.
EmitAbbrev(std::move(ContextIdAbbv));
4802 Abbv = std::make_shared<BitCodeAbbrev>();
4814 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4817 Abbv = std::make_shared<BitCodeAbbrev>();
4823 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4826 Abbv = std::make_shared<BitCodeAbbrev>();
4834 unsigned FSModVTableRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4837 Abbv = std::make_shared<BitCodeAbbrev>();
4842 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4845 Abbv = std::make_shared<BitCodeAbbrev>();
4852 unsigned TypeIdCompatibleVtableAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4854 Abbv = std::make_shared<BitCodeAbbrev>();
4860 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4862 Abbv = std::make_shared<BitCodeAbbrev>();
4869 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4871 Abbv = std::make_shared<BitCodeAbbrev>();
4876 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4883 MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
4884 for (
const Function &
F : M) {
4890 ValueInfo
VI =
Index->getValueInfo(
F.getGUID());
4891 if (!VI ||
VI.getSummaryList().empty()) {
4897 auto *
Summary =
VI.getSummaryList()[0].get();
4900 FS, [](
unsigned I) {
return I; }, CallStacks);
4904 DenseMap<CallStackId, LinearCallStackId> CallStackPos;
4905 if (!CallStacks.
empty()) {
4913 SmallVector<uint64_t, 64> NameVals;
4916 for (
const Function &
F : M) {
4922 ValueInfo
VI =
Index->getValueInfo(
F.getGUID());
4923 if (!VI ||
VI.getSummaryList().empty()) {
4929 auto *
Summary =
VI.getSummaryList()[0].get();
4930 writePerModuleFunctionSummaryRecord(NameVals, Summary, VE.
getValueID(&
F),
4931 FSCallsProfileAbbrev, CallsiteAbbrev,
4932 AllocAbbrev, ContextIdAbbvId,
F,
4933 CallStackPos, CallStackCount);
4938 for (
const GlobalVariable &
G :
M.globals())
4939 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev,
4940 FSModVTableRefsAbbrev);
4942 for (
const GlobalAlias &
A :
M.aliases()) {
4943 auto *Aliasee =
A.getAliaseeObject();
4959 for (
auto &S :
Index->typeIdCompatibleVtableMap()) {
4963 TypeIdCompatibleVtableAbbrev);
4967 if (
Index->getBlockCount())
4969 ArrayRef<uint64_t>{
Index->getBlockCount()});
4975void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4984 auto Abbv = std::make_shared<BitCodeAbbrev>();
4990 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4992 for (
const auto &GVI : valueIds()) {
4994 ArrayRef<uint32_t>{GVI.second,
4995 static_cast<uint32_t
>(GVI.first >> 32),
4996 static_cast<uint32_t
>(GVI.first)},
5002 if (!StackIds.empty()) {
5003 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
5010 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
5011 SmallVector<uint32_t> Vals;
5012 Vals.
reserve(StackIds.size() * 2);
5013 for (
auto Id : StackIds) {
5014 Vals.
push_back(
static_cast<uint32_t
>(Id >> 32));
5015 Vals.
push_back(
static_cast<uint32_t
>(Id));
5021 Abbv = std::make_shared<BitCodeAbbrev>();
5035 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5038 Abbv = std::make_shared<BitCodeAbbrev>();
5045 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5048 Abbv = std::make_shared<BitCodeAbbrev>();
5054 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5056 Abbv = std::make_shared<BitCodeAbbrev>();
5064 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5066 Abbv = std::make_shared<BitCodeAbbrev>();
5077 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5079 auto shouldImportValueAsDecl = [&](GlobalValueSummary *GVS) ->
bool {
5080 if (DecSummaries ==
nullptr)
5082 return DecSummaries->count(GVS);
5090 DenseMap<const GlobalValueSummary *, unsigned> SummaryToValueIdMap;
5092 SmallVector<uint64_t, 64> NameVals;
5096 std::set<GlobalValue::GUID> ReferencedTypeIds;
5100 auto MaybeEmitOriginalName = [&](GlobalValueSummary &S) {
5110 NameVals.
push_back(S.getOriginalName());
5115 DenseMap<CallStackId, LinearCallStackId> CallStackPos;
5117 Abbv = std::make_shared<BitCodeAbbrev>();
5122 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5129 MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
5130 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5136 GlobalValueSummary *S =
I.second;
5149 return StackIdIndicesToIndex[
I];
5155 if (!CallStacks.
empty()) {
5165 DenseSet<GlobalValue::GUID> DefOrUseGUIDs;
5166 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5167 GlobalValueSummary *S =
I.second;
5169 DefOrUseGUIDs.
insert(
I.first);
5170 for (
const ValueInfo &VI : S->
refs())
5171 DefOrUseGUIDs.
insert(
VI.getGUID());
5173 auto ValueId = getValueId(
I.first);
5175 SummaryToValueIdMap[S] = *ValueId;
5193 NameVals.
push_back(ModuleIdMap[
VS->modulePath()]);
5197 for (
auto &RI :
VS->refs()) {
5198 auto RefValueId = getValueId(RI.getGUID());
5208 MaybeEmitOriginalName(*S);
5212 auto GetValueId = [&](
const ValueInfo &
VI) -> std::optional<unsigned> {
5214 return std::nullopt;
5215 return getValueId(
VI.getGUID());
5224 NameVals.
push_back(ModuleIdMap[
FS->modulePath()]);
5237 unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
5238 for (
auto &RI :
FS->refs()) {
5239 auto RefValueId = getValueId(RI.getGUID());
5243 if (RI.isReadOnly())
5245 else if (RI.isWriteOnly())
5249 NameVals[6] =
Count;
5250 NameVals[7] = RORefCnt;
5251 NameVals[8] = WORefCnt;
5253 for (
auto &EI :
FS->calls()) {
5256 std::optional<unsigned> CallValueId = GetValueId(EI.first);
5265 FSCallsProfileAbbrev);
5269 Stream, FS, CallsiteAbbrev, AllocAbbrev, 0,
5272 [&](
const ValueInfo &VI) ->
unsigned {
5273 std::optional<unsigned> ValueID = GetValueId(VI);
5288 return StackIdIndicesToIndex[
I];
5290 false, CallStackPos, CallStackCount);
5292 MaybeEmitOriginalName(*S);
5295 for (
auto *AS : Aliases) {
5296 auto AliasValueId = SummaryToValueIdMap[AS];
5305 auto AliaseeValueId =
5312 MaybeEmitOriginalName(*AS);
5320 auto EmitCfiFunctions = [&](
const CfiFunctionIndex &CfiIndex,
5322 if (CfiIndex.
empty())
5325 auto Defs = CfiIndex.
forGuid(GUID);
5328 if (Functions.
empty())
5331 for (
const auto &S : Functions) {
5345 for (
auto &
T : ReferencedTypeIds) {
5346 auto TidIter =
Index.typeIds().equal_range(
T);
5347 for (
const auto &[GUID, TypeIdPair] :
make_range(TidIter)) {
5355 if (
Index.getBlockCount())
5357 ArrayRef<uint64_t>{
Index.getBlockCount()});
5368 auto Abbv = std::make_shared<BitCodeAbbrev>();
5372 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5374 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
5377 Abbv = std::make_shared<BitCodeAbbrev>();
5380 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5386void ModuleBitcodeWriter::writeModuleHash(StringRef View) {
5391 Hasher.
update(ArrayRef<uint8_t>(
5392 reinterpret_cast<const uint8_t *
>(
View.data()),
View.size()));
5393 std::array<uint8_t, 20> Hash = Hasher.
result();
5394 for (
int Pos = 0; Pos < 20; Pos += 4) {
5407void ModuleBitcodeWriter::write() {
5415 writeModuleVersion();
5424 writeAttributeGroupTable();
5427 writeAttributeTable();
5436 writeModuleConstants();
5439 writeModuleMetadataKinds();
5442 writeModuleMetadata();
5446 writeUseListBlock(
nullptr);
5448 writeOperandBundleTags();
5449 writeSyncScopeNames();
5452 DenseMap<const Function *, uint64_t> FunctionToBitcodeIndex;
5453 for (
const Function &
F : M)
5454 if (!
F.isDeclaration())
5455 writeFunction(
F, FunctionToBitcodeIndex);
5460 writePerModuleGlobalValueSummary();
5462 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
5490 unsigned CPUType = ~0U;
5497 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
5498 DARWIN_CPU_TYPE_X86 = 7,
5499 DARWIN_CPU_TYPE_ARM = 12,
5500 DARWIN_CPU_TYPE_POWERPC = 18
5505 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
5507 CPUType = DARWIN_CPU_TYPE_X86;
5509 CPUType = DARWIN_CPU_TYPE_POWERPC;
5511 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
5513 CPUType = DARWIN_CPU_TYPE_ARM;
5517 "Expected header size to be reserved");
5522 unsigned Position = 0;
5530 while (Buffer.
size() & 15)
5537 Stream.
Emit((
unsigned)
'B', 8);
5538 Stream.
Emit((
unsigned)
'C', 8);
5539 Stream.
Emit(0x0, 4);
5540 Stream.
Emit(0xC, 4);
5541 Stream.
Emit(0xE, 4);
5542 Stream.
Emit(0xD, 4);
5560 auto Abbv = std::make_shared<BitCodeAbbrev>();
5563 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
5571 assert(!WroteStrtab && !WroteSymtab);
5577 if (M->getModuleInlineAsm().empty())
5581 const Triple TT(M->getTargetTriple());
5583 if (!
T || !
T->hasMCAsmParser())
5605 std::vector<char> Strtab;
5606 StrtabBuilder.finalizeInOrder();
5607 Strtab.resize(StrtabBuilder.getSize());
5608 StrtabBuilder.write((
uint8_t *)Strtab.data());
5611 {Strtab.data(), Strtab.size()});
5622 bool ShouldPreserveUseListOrder,
5631 assert(M.isMaterialized());
5632 Mods.push_back(
const_cast<Module *
>(&M));
5634 ModuleBitcodeWriter ModuleWriter(M, StrtabBuilder, *Stream,
5635 ShouldPreserveUseListOrder, Index,
5636 GenerateHash, ModHash);
5637 ModuleWriter.write();
5644 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, DecSummaries,
5645 ModuleToSummariesForIndex);
5646 IndexWriter.write();
5651 bool ShouldPreserveUseListOrder,
5655 Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
5657 Writer.writeSymtab();
5658 Writer.writeStrtab();
5660 Triple TT(M.getTargetTriple());
5661 if (TT.isOSDarwin() || TT.isOSBinFormatMachO()) {
5679void IndexBitcodeWriter::write() {
5682 writeModuleVersion();
5688 writeCombinedGlobalValueSummary();
5705 Writer.
writeIndex(&Index, ModuleToSummariesForIndex, DecSummaries);
5714class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
5724 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5726 ModHash(&ModHash) {}
5731 void writeSimplifiedModuleInfo();
5741void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5753 auto Abbv = std::make_shared<BitCodeAbbrev>();
5756 Abbv->Add(AbbrevOpToUse);
5757 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5759 for (
const auto P :
M.getSourceFileName())
5823void ThinLinkBitcodeWriter::write() {
5826 writeModuleVersion();
5828 writeSimplifiedModuleInfo();
5830 writePerModuleGlobalValueSummary();
5847 assert(M.isMaterialized());
5848 Mods.push_back(
const_cast<Module *
>(&M));
5850 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream, Index,
5852 ThinLinkWriter.write();
5873 switch (
T.getObjectFormat()) {
5875 return "__LLVM,__bitcode";
5900 switch (
T.getObjectFormat()) {
5902 return "__LLVM,__cmdline";
5928 const std::vector<uint8_t> &CmdArgs) {
5933 Type *UsedElementType = Used ? Used->getValueType()->getArrayElementType()
5935 for (
auto *GV : UsedGlobals) {
5936 if (GV->getName() !=
"llvm.embedded.module" &&
5937 GV->getName() !=
"llvm.cmdline")
5942 Used->eraseFromParent();
5947 Triple T(M.getTargetTriple());
5976 M.getGlobalVariable(
"llvm.embedded.module",
true)) {
5977 assert(Old->hasZeroLiveUses() &&
5978 "llvm.embedded.module can only be used once in llvm.compiler.used");
5980 Old->eraseFromParent();
5982 GV->
setName(
"llvm.embedded.module");
6000 assert(Old->hasZeroLiveUses() &&
6001 "llvm.cmdline can only be used once in llvm.compiler.used");
6003 Old->eraseFromParent();
6009 if (UsedArray.
empty())
6017 NewUsed->setSection(
"llvm.metadata");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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 writeDIFixedPointType(raw_ostream &Out, const DIFixedPointType *N, AsmWriterContext &WriterCtx)
static void writeDISubrangeType(raw_ostream &Out, const DISubrangeType *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 writeDIBasicType(raw_ostream &Out, const DIBasicType *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 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 cl::opt< bool > PreserveBitcodeUseListOrder("preserve-bc-uselistorder", cl::Hidden, cl::init(true), cl::desc("Preserve use-list order when writing LLVM bitcode."))
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< 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)
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.
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 unsigned getEncodedRMWOperation(const AtomicRMWInst &I)
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 cl::opt< bool > CombinedIndexMemProfContext("combined-index-memprof-context", cl::Hidden, cl::init(true), cl::desc(""))
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
This file contains constants used for implementing Dwarf debug support.
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"))
Machine Check Debug Module
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
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 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.
const GlobalValueSummary & getAliasee() const
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.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
bool empty() const
Check if the array is empty.
Class to represent array types.
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
an instruction that atomically reads a memory location, combines it with another value,...
@ USubCond
Subtract only if no unsigned overflow.
@ FMinimum
*p = minimum(old, v) minimum matches the behavior of llvm.minimum.
@ Min
*p = old <signed v ? old : v
@ USubSat
*p = usub.sat(old, v) usub.sat matches the behavior of llvm.usub.sat.
@ FMaximum
*p = maximum(old, v) maximum matches the behavior of llvm.maximum.
@ 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
@ FMaximumNum
*p = maximumnum(old, v) maximumnum matches the behavior of llvm.maximumnum.
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
@ FMinimumNum
*p = minimumnum(old, v) minimumnum matches the behavior of llvm.minimumnum.
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.
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.
LLVM_ABI 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...
LLVM_ABI void writeIndex(const ModuleSummaryIndex *Index, const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex, const GVSummaryPtrSet *DecSummaries)
LLVM_ABI void copyStrtab(StringRef Strtab)
Copy the string table for another module into this bitcode file.
LLVM_ABI void writeStrtab()
Write the bitcode file's string table.
LLVM_ABI ~BitcodeWriter()
LLVM_ABI void writeSymtab()
Attempt to write a symbol table to the bitcode file.
LLVM_ABI 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.
LLVM_ABI 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.
static LLVM_ABI BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
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.
BasicBlock * getIndirectDest(unsigned i) const
BasicBlock * getDefaultDest() const
unsigned getNumIndirectDests() const
Return the number of callbr indirect dest labels.
bool isNoTailCall() const
bool isMustTailCall() const
iterator_range< NestedIterator > forGuid(GlobalValue::GUID GUID) 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 LLVM_ABI 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...
static LLVM_ABI Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
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.
This is an important base class in LLVM.
DebugLoc getDebugLoc() const
LLVM_ABI DIAssignID * getAssignID() const
DIExpression * getExpression() const
DILocalVariable * getVariable() const
bool isDbgDeclareValue() 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)
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.
LLVM_ABI void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
LLVM_ABI void setSection(StringRef S)
Change the section for this global.
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
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
ThreadLocalMode getThreadLocalMode() const
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
@ 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
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalVariable.
idx_iterator idx_end() const
idx_iterator idx_begin() const
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.
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...
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Digest more data.
LLVM_ABI std::array< uint8_t, 20 > result()
Return the current raw 160-bits SHA1 for the digested data since the last call to init().
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.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
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
Represent a constant reference to a string, i.e.
constexpr bool empty() const
Check if the string is empty.
constexpr size_t size() const
Get the string size.
Utility for building string tables with deduplicated suffixes.
LLVM_ABI size_t add(CachedHashStringRef S, uint8_t Priority=0)
Add a string to the builder.
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.
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
bool isFP128Ty() const
Return true if this is 'fp128'.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
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.
std::vector< std::pair< const Value *, unsigned > > ValueList
unsigned getTypeID(Type *T) const
unsigned getMetadataID(const Metadata *MD) const
UseListOrderStack UseListOrders
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
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
std::pair< iterator, bool > insert(const ValueT &V)
void build(llvm::MapVector< CallStackId, llvm::SmallVector< FrameIdTy > > &&MemProfCallStackData, const llvm::DenseMap< FrameIdTy, LinearFrameId > *MemProfFrameIndexes, llvm::DenseMap< FrameIdTy, FrameStat > &FrameHistogram)
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.
std::string & str()
Returns the string's reference.
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ 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_FIXED_POINT_TYPE
@ METADATA_GLOBAL_VAR_EXPR
GlobalValueSummarySymtabCodes
@ 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_ALLOC_INFO_NO_CONTEXT
@ 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_DENORMAL_FPENV
@ 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_SANITIZE_ALLOC_TOKEN
@ ATTR_KIND_NO_SANITIZE_COVERAGE
@ ATTR_KIND_NO_CREATE_UNDEF_OR_POISON
@ ATTR_KIND_DEAD_ON_RETURN
@ 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_RECORD_DECLARE_VALUE
@ 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)
@ DW_APPLE_ENUM_KIND_invalid
Enum kind for invalid results.
LLVM_ABI 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.
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract_or_null(Y &&MD)
Extract a Value from Metadata, allowing null.
LLVM_ABI bool metadataIncludesAllContextSizeInfo()
Whether the alloc memeprof metadata will include context size info for all MIBs.
template LLVM_ABI llvm::DenseMap< LinearFrameId, FrameStat > computeFrameHistogram< LinearFrameId >(llvm::MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &MemProfCallStackData)
LLVM_ABI bool metadataMayIncludeContextSizeInfo()
Whether the alloc memprof metadata may include context size info for some MIBs (but possibly not all)...
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.
FunctionAddr VTableAddr Value
StringMapEntry< Value * > ValueName
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
std::unordered_set< GlobalValueSummary * > GVSummaryPtrSet
A set of global value summary pointers.
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
LLVM_ABI 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,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
LLVM_ABI 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.
LLVM_ABI 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 ...
LLVM_ABI 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.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
FunctionAddr VTableAddr Count
std::map< std::string, GVSummaryMapTy, std::less<> > ModuleToSummariesForIndexTy
Map of a module name to the GUIDs and summaries we will import from that module.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
AtomicOrdering
Atomic ordering for LLVM's memory model.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt copy(R &&Range, OutputIt Out)
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
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,...
void consumeError(Error Err)
Consume a Error without doing anything.
LLVM_ABI Error write(DWPWriter &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue, Dwarf64StrOffsetsPromotion StrOffsetsOptValue, raw_pwrite_stream *OS=nullptr)
LLVM_ABI 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.
static void set(StorageType &Packed, typename Bitfield::Type Value)
Sets the typed value in the provided Packed value.
Class to accumulate and hold information about a callee.
Flags specific to function summaries.
static constexpr uint32_t RangeWidth
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
static LLVM_ABI const Target * lookupTarget(const Triple &TheTriple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
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