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:
1011 case Attribute::NoIPA:
1026 if ((int64_t)V >= 0)
1037 unsigned NumWords =
A.getActiveWords();
1038 const uint64_t *RawData =
A.getRawData();
1039 for (
unsigned i = 0; i < NumWords; i++)
1059void ModuleBitcodeWriter::writeAttributeGroupTable() {
1060 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
1062 if (AttrGrps.empty())
return;
1066 SmallVector<uint64_t, 64>
Record;
1068 unsigned AttrListIndex = Pair.first;
1069 AttributeSet AS = Pair.second;
1071 Record.push_back(AttrListIndex);
1074 if (Attr.isEnumAttribute()) {
1077 }
else if (Attr.isIntAttribute()) {
1079 Attribute::AttrKind
Kind = Attr.getKindAsEnum();
1081 if (Kind == Attribute::Memory) {
1086 Record.push_back(Attr.getValueAsInt());
1088 }
else if (Attr.isStringAttribute()) {
1089 StringRef
Kind = Attr.getKindAsString();
1090 StringRef Val = Attr.getValueAsString();
1099 }
else if (Attr.isTypeAttribute()) {
1100 Type *Ty = Attr.getValueAsType();
1101 Record.push_back(Ty ? 6 : 5);
1105 }
else if (Attr.isConstantRangeAttribute()) {
1111 assert(Attr.isConstantRangeListAttribute());
1117 for (
auto &CR : Val)
1129void ModuleBitcodeWriter::writeAttributeTable() {
1131 if (
Attrs.empty())
return;
1135 SmallVector<uint64_t, 64>
Record;
1136 for (
const AttributeList &AL : Attrs) {
1137 for (
unsigned i :
AL.indexes()) {
1138 AttributeSet AS =
AL.getAttributes(i);
1151void ModuleBitcodeWriter::writeTypeTable() {
1155 SmallVector<uint64_t, 64> TypeVals;
1160 auto Abbv = std::make_shared<BitCodeAbbrev>();
1162 Abbv->Add(BitCodeAbbrevOp(0));
1163 unsigned OpaquePtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1166 Abbv = std::make_shared<BitCodeAbbrev>();
1171 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1174 Abbv = std::make_shared<BitCodeAbbrev>();
1179 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1182 Abbv = std::make_shared<BitCodeAbbrev>();
1186 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1189 Abbv = std::make_shared<BitCodeAbbrev>();
1194 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1197 Abbv = std::make_shared<BitCodeAbbrev>();
1201 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1209 for (
Type *
T : TypeList) {
1210 int AbbrevToUse = 0;
1213 switch (
T->getTypeID()) {
1223 case Type::MetadataTyID:
1228 case Type::ByteTyID:
1233 case Type::IntegerTyID:
1238 case Type::PointerTyID: {
1245 AbbrevToUse = OpaquePtrAbbrev;
1248 case Type::FunctionTyID: {
1254 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1256 AbbrevToUse = FunctionAbbrev;
1259 case Type::StructTyID: {
1264 for (
Type *ET :
ST->elements())
1267 if (
ST->isLiteral()) {
1269 AbbrevToUse = StructAnonAbbrev;
1271 if (
ST->isOpaque()) {
1275 AbbrevToUse = StructNamedAbbrev;
1279 if (!
ST->getName().empty())
1285 case Type::ArrayTyID: {
1289 TypeVals.
push_back(AT->getNumElements());
1291 AbbrevToUse = ArrayAbbrev;
1294 case Type::FixedVectorTyID:
1295 case Type::ScalableVectorTyID: {
1300 TypeVals.
push_back(VT->getElementCount().getKnownMinValue());
1306 case Type::TargetExtTyID: {
1312 for (
Type *InnerTy :
TET->type_params())
1317 case Type::TypedPointerTyID:
1322 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
1363 RawFlags |= Flags.ReadNone;
1364 RawFlags |= (Flags.ReadOnly << 1);
1365 RawFlags |= (Flags.NoRecurse << 2);
1366 RawFlags |= (Flags.ReturnDoesNotAlias << 3);
1367 RawFlags |= (Flags.NoInline << 4);
1368 RawFlags |= (Flags.AlwaysInline << 5);
1369 RawFlags |= (Flags.NoUnwind << 6);
1370 RawFlags |= (Flags.MayThrow << 7);
1371 RawFlags |= (Flags.HasUnknownCall << 8);
1372 RawFlags |= (Flags.MustBeUnreachable << 9);
1379 bool ImportAsDecl =
false) {
1382 RawFlags |= Flags.NotEligibleToImport;
1383 RawFlags |= (Flags.Live << 1);
1384 RawFlags |= (Flags.DSOLocal << 2);
1385 RawFlags |= (Flags.CanAutoHide << 3);
1390 RawFlags = (RawFlags << 4) | Flags.Linkage;
1392 RawFlags |= (Flags.Visibility << 8);
1394 unsigned ImportType = Flags.ImportType | ImportAsDecl;
1395 RawFlags |= (ImportType << 10);
1397 RawFlags |= (Flags.NoRenameOnPromotion << 11);
1403 uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1404 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1447 switch (
C.getSelectionKind()) {
1471size_t ModuleBitcodeWriter::addToStrtab(StringRef Str) {
1474 return StrtabBuilder.
add(Str);
1477void ModuleBitcodeWriter::writeComdats() {
1492void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1497 auto Abbv = std::make_shared<BitCodeAbbrev>();
1503 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1519 bool isChar6 =
true;
1520 for (
char C : Str) {
1523 if ((
unsigned char)
C & 128)
1532static_assert(
sizeof(GlobalValue::SanitizerMetadata) <=
sizeof(unsigned),
1533 "Sanitizer Metadata is too large for naive serialization.");
1536 return Meta.NoAddress | (
Meta.NoHWAddress << 1) |
1537 (
Meta.Memtag << 2) | (
Meta.IsDynInit << 3);
1543void ModuleBitcodeWriter::writeModuleInfo() {
1545 if (!
M.getTargetTriple().empty())
1547 M.getTargetTriple().str(), 0 );
1548 const std::string &
DL =
M.getDataLayoutStr();
1551 if (!
M.getModuleInlineAsm().empty())
1557 std::map<std::string, unsigned> SectionMap;
1558 std::map<std::string, unsigned> GCMap;
1559 MaybeAlign MaxGVarAlignment;
1560 unsigned MaxGlobalType = 0;
1561 for (
const GlobalVariable &GV :
M.globals()) {
1562 if (MaybeAlign
A = GV.getAlign())
1563 MaxGVarAlignment = !MaxGVarAlignment ? *
A : std::max(*MaxGVarAlignment, *
A);
1564 MaxGlobalType = std::max(MaxGlobalType, VE.
getTypeID(GV.getValueType()));
1565 if (GV.hasSection()) {
1567 unsigned &
Entry = SectionMap[std::string(GV.getSection())];
1571 Entry = SectionMap.size();
1575 for (
const Function &
F : M) {
1576 if (
F.hasSection()) {
1578 unsigned &
Entry = SectionMap[std::string(
F.getSection())];
1582 Entry = SectionMap.size();
1587 unsigned &
Entry = GCMap[
F.getGC()];
1591 Entry = GCMap.size();
1597 unsigned SimpleGVarAbbrev = 0;
1598 if (!
M.global_empty()) {
1600 auto Abbv = std::make_shared<BitCodeAbbrev>();
1611 if (!MaxGVarAlignment)
1612 Abbv->Add(BitCodeAbbrevOp(0));
1614 unsigned MaxEncAlignment = getEncodedAlign(MaxGVarAlignment);
1618 if (SectionMap.empty())
1619 Abbv->Add(BitCodeAbbrevOp(0));
1624 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1638 auto Abbv = std::make_shared<BitCodeAbbrev>();
1641 Abbv->Add(AbbrevOpToUse);
1642 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1644 for (
const auto P :
M.getSourceFileName())
1653 for (
const GlobalVariable &GV :
M.globals()) {
1654 unsigned AbbrevToUse = 0;
1660 Vals.
push_back(addToStrtab(GV.getName()));
1663 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1667 Vals.
push_back(getEncodedAlign(GV.getAlign()));
1668 Vals.
push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1670 if (GV.isThreadLocal() ||
1672 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1673 GV.isExternallyInitialized() ||
1675 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1676 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1680 Vals.
push_back(GV.isExternallyInitialized());
1684 auto AL = GV.getAttributesAsList(AttributeList::FunctionIndex);
1688 Vals.
push_back(addToStrtab(GV.getPartition()));
1689 Vals.
push_back(GV.getPartition().size());
1692 GV.getSanitizerMetadata())
1696 AbbrevToUse = SimpleGVarAbbrev;
1704 for (
const Function &
F : M) {
1717 Vals.
push_back(getEncodedAlign(
F.getAlign()));
1718 Vals.
push_back(
F.hasSection() ? SectionMap[std::string(
F.getSection())]
1730 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1734 Vals.
push_back(addToStrtab(
F.getPartition()));
1736 Vals.
push_back(getEncodedAlign(
F.getPreferredAlignment()));
1738 unsigned AbbrevToUse = 0;
1744 for (
const GlobalAlias &
A :
M.aliases()) {
1751 Vals.
push_back(
A.getType()->getAddressSpace());
1759 Vals.
push_back(addToStrtab(
A.getPartition()));
1762 unsigned AbbrevToUse = 0;
1768 for (
const GlobalIFunc &
I :
M.ifuncs()) {
1774 Vals.
push_back(
I.getType()->getAddressSpace());
1779 Vals.
push_back(addToStrtab(
I.getPartition()));
1785 writeValueSymbolTableForwardDecl();
1792 if (OBO->hasNoSignedWrap())
1794 if (OBO->hasNoUnsignedWrap())
1800 if (PDI->isDisjoint())
1803 if (FPMO->hasAllowReassoc())
1805 if (FPMO->hasNoNaNs())
1807 if (FPMO->hasNoInfs())
1809 if (FPMO->hasNoSignedZeros())
1811 if (FPMO->hasAllowReciprocal())
1813 if (FPMO->hasAllowContract())
1815 if (FPMO->hasApproxFunc())
1821 if (NNI->hasNonNeg())
1825 if (NNI->hasNonNeg())
1828 if (TI->hasNoSignedWrap())
1830 if (TI->hasNoUnsignedWrap())
1833 if (
GEP->isInBounds())
1835 if (
GEP->hasNoUnsignedSignedWrap())
1837 if (
GEP->hasNoUnsignedWrap())
1840 if (ICmp->hasSameSign())
1847void ModuleBitcodeWriter::writeValueAsMetadata(
1848 const ValueAsMetadata *MD, SmallVectorImpl<uint64_t> &Record) {
1857void ModuleBitcodeWriter::writeMDTuple(
const MDTuple *
N,
1858 SmallVectorImpl<uint64_t> &Record,
1860 for (
const MDOperand &MDO :
N->operands()) {
1863 "Unexpected function-local metadata");
1872unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1875 auto Abbv = std::make_shared<BitCodeAbbrev>();
1888void ModuleBitcodeWriter::writeDILocation(
const DILocation *
N,
1889 SmallVectorImpl<uint64_t> &Record,
1892 Abbrev = createDILocationAbbrev();
1894 Record.push_back(
N->isDistinct());
1895 Record.push_back(
N->getLine());
1896 Record.push_back(
N->getColumn());
1899 Record.push_back(
N->isImplicitCode());
1900 Record.push_back(
N->getAtomGroup());
1901 Record.push_back(
N->getAtomRank());
1906unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1909 auto Abbv = std::make_shared<BitCodeAbbrev>();
1920void ModuleBitcodeWriter::writeGenericDINode(
const GenericDINode *
N,
1921 SmallVectorImpl<uint64_t> &Record,
1924 Abbrev = createGenericDINodeAbbrev();
1926 Record.push_back(
N->isDistinct());
1927 Record.push_back(
N->getTag());
1930 for (
auto &
I :
N->operands())
1937void ModuleBitcodeWriter::writeDISubrange(
const DISubrange *
N,
1938 SmallVectorImpl<uint64_t> &Record,
1940 const uint64_t
Version = 2 << 1;
1951void ModuleBitcodeWriter::writeDIGenericSubrange(
1952 const DIGenericSubrange *
N, SmallVectorImpl<uint64_t> &Record,
1954 Record.push_back((uint64_t)
N->isDistinct());
1964void ModuleBitcodeWriter::writeDIEnumerator(
const DIEnumerator *
N,
1965 SmallVectorImpl<uint64_t> &Record,
1967 const uint64_t IsBigInt = 1 << 2;
1968 Record.push_back(IsBigInt | (
N->isUnsigned() << 1) |
N->isDistinct());
1969 Record.push_back(
N->getValue().getBitWidth());
1977void ModuleBitcodeWriter::writeDIBasicType(
const DIBasicType *
N,
1978 SmallVectorImpl<uint64_t> &Record,
1980 const unsigned SizeIsMetadata = 0x2;
1981 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1982 Record.push_back(
N->getTag());
1985 Record.push_back(
N->getAlignInBits());
1986 Record.push_back(
N->getEncoding());
1987 Record.push_back(
N->getFlags());
1988 Record.push_back(
N->getNumExtraInhabitants());
1989 Record.push_back(
N->getDataSizeInBits());
1991 Record.push_back(
N->getLine());
1998void ModuleBitcodeWriter::writeDIFixedPointType(
1999 const DIFixedPointType *
N, SmallVectorImpl<uint64_t> &Record,
2001 const unsigned SizeIsMetadata = 0x2;
2002 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2003 Record.push_back(
N->getTag());
2006 Record.push_back(
N->getAlignInBits());
2007 Record.push_back(
N->getEncoding());
2008 Record.push_back(
N->getFlags());
2009 Record.push_back(
N->getKind());
2010 Record.push_back(
N->getFactorRaw());
2012 auto WriteWideInt = [&](
const APInt &
Value) {
2015 uint64_t NumWords =
Value.getActiveWords();
2016 uint64_t
Encoded = (NumWords << 32) |
Value.getBitWidth();
2017 Record.push_back(Encoded);
2021 WriteWideInt(
N->getNumeratorRaw());
2022 WriteWideInt(
N->getDenominatorRaw());
2025 Record.push_back(
N->getLine());
2032void ModuleBitcodeWriter::writeDIStringType(
const DIStringType *
N,
2033 SmallVectorImpl<uint64_t> &Record,
2035 const unsigned SizeIsMetadata = 0x2;
2036 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2037 Record.push_back(
N->getTag());
2043 Record.push_back(
N->getAlignInBits());
2044 Record.push_back(
N->getEncoding());
2050void ModuleBitcodeWriter::writeDIDerivedType(
const DIDerivedType *
N,
2051 SmallVectorImpl<uint64_t> &Record,
2053 const unsigned SizeIsMetadata = 0x2;
2054 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2055 Record.push_back(
N->getTag());
2058 Record.push_back(
N->getLine());
2062 Record.push_back(
N->getAlignInBits());
2064 Record.push_back(
N->getFlags());
2069 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
2070 Record.push_back(*DWARFAddressSpace + 1);
2076 if (
auto PtrAuthData =
N->getPtrAuthData())
2077 Record.push_back(PtrAuthData->RawData);
2085void ModuleBitcodeWriter::writeDISubrangeType(
const DISubrangeType *
N,
2086 SmallVectorImpl<uint64_t> &Record,
2088 const unsigned SizeIsMetadata = 0x2;
2089 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2092 Record.push_back(
N->getLine());
2095 Record.push_back(
N->getAlignInBits());
2096 Record.push_back(
N->getFlags());
2107void ModuleBitcodeWriter::writeDICompositeType(
2108 const DICompositeType *
N, SmallVectorImpl<uint64_t> &Record,
2110 const unsigned IsNotUsedInOldTypeRef = 0x2;
2111 const unsigned SizeIsMetadata = 0x4;
2112 Record.push_back(SizeIsMetadata | IsNotUsedInOldTypeRef |
2113 (
unsigned)
N->isDistinct());
2114 Record.push_back(
N->getTag());
2117 Record.push_back(
N->getLine());
2121 Record.push_back(
N->getAlignInBits());
2123 Record.push_back(
N->getFlags());
2125 Record.push_back(
N->getRuntimeLang());
2135 Record.push_back(
N->getNumExtraInhabitants());
2145void ModuleBitcodeWriter::writeDISubroutineType(
2146 const DISubroutineType *
N, SmallVectorImpl<uint64_t> &Record,
2148 const unsigned HasNoOldTypeRefs = 0x2;
2149 Record.push_back(HasNoOldTypeRefs | (
unsigned)
N->isDistinct());
2150 Record.push_back(
N->getFlags());
2158void ModuleBitcodeWriter::writeDIFile(
const DIFile *
N,
2159 SmallVectorImpl<uint64_t> &Record,
2161 Record.push_back(
N->isDistinct());
2164 if (
N->getRawChecksum()) {
2165 Record.push_back(
N->getRawChecksum()->Kind);
2173 auto Source =
N->getRawSource();
2181void ModuleBitcodeWriter::writeDICompileUnit(
const DICompileUnit *
N,
2182 SmallVectorImpl<uint64_t> &Record,
2184 assert(
N->isDistinct() &&
"Expected distinct compile units");
2187 auto Lang =
N->getSourceLanguage();
2188 Record.push_back(Lang.getName());
2191 if (Lang.hasVersionedName())
2192 Record.back() ^= (uint64_t(1) << 63);
2196 Record.push_back(
N->isOptimized());
2198 Record.push_back(
N->getRuntimeVersion());
2200 Record.push_back(
N->getEmissionKind());
2206 Record.push_back(
N->getDWOId());
2208 Record.push_back(
N->getSplitDebugInlining());
2209 Record.push_back(
N->getDebugInfoForProfiling());
2210 Record.push_back((
unsigned)
N->getNameTableKind());
2211 Record.push_back(
N->getRangesBaseAddress());
2214 Record.push_back(Lang.hasVersionedName() ? Lang.getVersion() : 0);
2215 Record.push_back(Lang.getDialect());
2221void ModuleBitcodeWriter::writeDISubprogram(
const DISubprogram *
N,
2222 SmallVectorImpl<uint64_t> &Record,
2224 const uint64_t HasUnitFlag = 1 << 1;
2225 const uint64_t HasSPFlagsFlag = 1 << 2;
2226 Record.push_back(uint64_t(
N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
2231 Record.push_back(
N->getLine());
2233 Record.push_back(
N->getScopeLine());
2235 Record.push_back(
N->getSPFlags());
2236 Record.push_back(
N->getVirtualIndex());
2237 Record.push_back(
N->getFlags());
2242 Record.push_back(
N->getThisAdjustment());
2246 Record.push_back(
N->getKeyInstructionsEnabled());
2252void ModuleBitcodeWriter::writeDILexicalBlock(
const DILexicalBlock *
N,
2253 SmallVectorImpl<uint64_t> &Record,
2255 Record.push_back(
N->isDistinct());
2258 Record.push_back(
N->getLine());
2259 Record.push_back(
N->getColumn());
2265void ModuleBitcodeWriter::writeDILexicalBlockFile(
2266 const DILexicalBlockFile *
N, SmallVectorImpl<uint64_t> &Record,
2268 Record.push_back(
N->isDistinct());
2271 Record.push_back(
N->getDiscriminator());
2277void ModuleBitcodeWriter::writeDICommonBlock(
const DICommonBlock *
N,
2278 SmallVectorImpl<uint64_t> &Record,
2280 Record.push_back(
N->isDistinct());
2285 Record.push_back(
N->getLineNo());
2291void ModuleBitcodeWriter::writeDINamespace(
const DINamespace *
N,
2292 SmallVectorImpl<uint64_t> &Record,
2294 Record.push_back(
N->isDistinct() |
N->getExportSymbols() << 1);
2302void ModuleBitcodeWriter::writeDIMacro(
const DIMacro *
N,
2303 SmallVectorImpl<uint64_t> &Record,
2305 Record.push_back(
N->isDistinct());
2306 Record.push_back(
N->getMacinfoType());
2307 Record.push_back(
N->getLine());
2315void ModuleBitcodeWriter::writeDIMacroFile(
const DIMacroFile *
N,
2316 SmallVectorImpl<uint64_t> &Record,
2318 Record.push_back(
N->isDistinct());
2319 Record.push_back(
N->getMacinfoType());
2320 Record.push_back(
N->getLine());
2328void ModuleBitcodeWriter::writeDIArgList(
const DIArgList *
N,
2329 SmallVectorImpl<uint64_t> &Record) {
2330 Record.reserve(
N->getArgs().size());
2331 for (ValueAsMetadata *MD :
N->getArgs())
2338void ModuleBitcodeWriter::writeDIModule(
const DIModule *
N,
2339 SmallVectorImpl<uint64_t> &Record,
2341 Record.push_back(
N->isDistinct());
2342 for (
auto &
I :
N->operands())
2344 Record.push_back(
N->getLineNo());
2345 Record.push_back(
N->getIsDecl());
2351void ModuleBitcodeWriter::writeDIAssignID(
const DIAssignID *
N,
2352 SmallVectorImpl<uint64_t> &Record,
2355 Record.push_back(
N->isDistinct());
2360void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2361 const DITemplateTypeParameter *
N, SmallVectorImpl<uint64_t> &Record,
2363 Record.push_back(
N->isDistinct());
2366 Record.push_back(
N->isDefault());
2372void ModuleBitcodeWriter::writeDITemplateValueParameter(
2373 const DITemplateValueParameter *
N, SmallVectorImpl<uint64_t> &Record,
2375 Record.push_back(
N->isDistinct());
2376 Record.push_back(
N->getTag());
2379 Record.push_back(
N->isDefault());
2386void ModuleBitcodeWriter::writeDIGlobalVariable(
2387 const DIGlobalVariable *
N, SmallVectorImpl<uint64_t> &Record,
2389 const uint64_t
Version = 2 << 1;
2395 Record.push_back(
N->getLine());
2397 Record.push_back(
N->isLocalToUnit());
2398 Record.push_back(
N->isDefinition());
2401 Record.push_back(
N->getAlignInBits());
2408void ModuleBitcodeWriter::writeDILocalVariable(
2409 const DILocalVariable *
N, SmallVectorImpl<uint64_t> &Record,
2424 const uint64_t HasAlignmentFlag = 1 << 1;
2425 Record.push_back((uint64_t)
N->isDistinct() | HasAlignmentFlag);
2429 Record.push_back(
N->getLine());
2431 Record.push_back(
N->getArg());
2432 Record.push_back(
N->getFlags());
2433 Record.push_back(
N->getAlignInBits());
2440void ModuleBitcodeWriter::writeDILabel(
2441 const DILabel *
N, SmallVectorImpl<uint64_t> &Record,
2443 uint64_t IsArtificialFlag = uint64_t(
N->isArtificial()) << 1;
2444 Record.push_back((uint64_t)
N->isDistinct() | IsArtificialFlag);
2448 Record.push_back(
N->getLine());
2449 Record.push_back(
N->getColumn());
2450 Record.push_back(
N->getCoroSuspendIdx().has_value()
2451 ? (uint64_t)
N->getCoroSuspendIdx().value()
2452 : std::numeric_limits<uint64_t>::max());
2458void ModuleBitcodeWriter::writeDIExpression(
const DIExpression *
N,
2459 SmallVectorImpl<uint64_t> &Record,
2461 Record.reserve(
N->getElements().size() + 1);
2462 const uint64_t
Version = 3 << 1;
2464 Record.append(
N->elements_begin(),
N->elements_end());
2470void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2471 const DIGlobalVariableExpression *
N, SmallVectorImpl<uint64_t> &Record,
2473 Record.push_back(
N->isDistinct());
2481void ModuleBitcodeWriter::writeDIObjCProperty(
const DIObjCProperty *
N,
2482 SmallVectorImpl<uint64_t> &Record,
2484 Record.push_back(
N->isDistinct());
2487 Record.push_back(
N->getLine());
2490 Record.push_back(
N->getAttributes());
2497void ModuleBitcodeWriter::writeDIImportedEntity(
2498 const DIImportedEntity *
N, SmallVectorImpl<uint64_t> &Record,
2500 Record.push_back(
N->isDistinct());
2501 Record.push_back(
N->getTag());
2504 Record.push_back(
N->getLine());
2513unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2514 auto Abbv = std::make_shared<BitCodeAbbrev>();
2521void ModuleBitcodeWriter::writeNamedMetadata(
2522 SmallVectorImpl<uint64_t> &Record) {
2523 if (
M.named_metadata_empty())
2526 unsigned Abbrev = createNamedMetadataAbbrev();
2527 for (
const NamedMDNode &NMD :
M.named_metadata()) {
2529 StringRef Str = NMD.getName();
2530 Record.append(Str.bytes_begin(), Str.bytes_end());
2535 for (
const MDNode *
N : NMD.operands())
2542unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2543 auto Abbv = std::make_shared<BitCodeAbbrev>();
2555void ModuleBitcodeWriter::writeMetadataStrings(
2557 if (Strings.
empty())
2565 SmallString<256> Blob;
2567 BitstreamWriter
W(Blob);
2587#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
2588#include "llvm/IR/Metadata.def"
2592void ModuleBitcodeWriter::writeMetadataRecords(
2594 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2599#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
2600#include "llvm/IR/Metadata.def"
2606 assert(
N->isResolved() &&
"Expected forward references to be resolved");
2608 switch (
N->getMetadataID()) {
2611#define HANDLE_MDNODE_LEAF(CLASS) \
2612 case Metadata::CLASS##Kind: \
2614 write##CLASS(cast<CLASS>(N), Record, \
2615 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
2617 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
2619#include "llvm/IR/Metadata.def"
2630void ModuleBitcodeWriter::writeModuleMetadata() {
2631 if (!VE.
hasMDs() &&
M.named_metadata_empty())
2635 SmallVector<uint64_t, 64>
Record;
2639 std::vector<unsigned> MDAbbrevs;
2642 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2643 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2644 createGenericDINodeAbbrev();
2646 auto Abbv = std::make_shared<BitCodeAbbrev>();
2650 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2652 Abbv = std::make_shared<BitCodeAbbrev>();
2656 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2668 uint64_t Vals[] = {0, 0};
2678 std::vector<uint64_t> IndexPos;
2682 writeMetadataRecords(VE.
getNonMDStrings(), Record, &MDAbbrevs, &IndexPos);
2693 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2694 for (
auto &Elt : IndexPos) {
2695 auto EltDelta = Elt - PreviousValue;
2696 PreviousValue = Elt;
2705 writeNamedMetadata(Record);
2707 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2708 SmallVector<uint64_t, 4>
Record;
2710 pushGlobalMetadataAttachment(Record, GO);
2713 for (
const Function &
F : M)
2714 if (
F.isDeclaration() &&
F.hasMetadata())
2715 AddDeclAttachedMetadata(
F);
2716 for (
const GlobalIFunc &GI :
M.ifuncs())
2717 if (GI.hasMetadata())
2718 AddDeclAttachedMetadata(GI);
2721 for (
const GlobalVariable &GV :
M.globals())
2722 if (GV.hasMetadata())
2723 AddDeclAttachedMetadata(GV);
2728void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2733 SmallVector<uint64_t, 64>
Record;
2739void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2740 SmallVectorImpl<uint64_t> &Record,
const GlobalObject &GO) {
2744 for (
const auto &
I : MDs) {
2750void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &
F) {
2753 SmallVector<uint64_t, 64>
Record;
2755 if (
F.hasMetadata()) {
2756 pushGlobalMetadataAttachment(Record,
F);
2764 for (
const BasicBlock &BB :
F)
2765 for (
const Instruction &
I : BB) {
2767 I.getAllMetadataOtherThanDebugLoc(MDs);
2770 if (MDs.
empty())
continue;
2774 for (
const auto &[
ID, MD] : MDs) {
2785void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2786 SmallVector<uint64_t, 64>
Record;
2791 M.getMDKindNames(Names);
2793 if (Names.
empty())
return;
2797 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2798 Record.push_back(MDKindID);
2799 StringRef KName = Names[MDKindID];
2809void ModuleBitcodeWriter::writeOperandBundleTags() {
2817 M.getOperandBundleTags(Tags);
2824 SmallVector<uint64_t, 64>
Record;
2826 for (
auto Tag : Tags) {
2836void ModuleBitcodeWriter::writeSyncScopeNames() {
2838 M.getContext().getSyncScopeNames(SSNs);
2844 SmallVector<uint64_t, 64>
Record;
2845 for (
auto SSN : SSNs) {
2846 Record.append(SSN.begin(), SSN.end());
2854void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2856 if (FirstVal == LastVal)
return;
2860 unsigned AggregateAbbrev = 0;
2861 unsigned String8Abbrev = 0;
2862 unsigned CString7Abbrev = 0;
2863 unsigned CString6Abbrev = 0;
2867 auto Abbv = std::make_shared<BitCodeAbbrev>();
2871 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2874 Abbv = std::make_shared<BitCodeAbbrev>();
2878 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2880 Abbv = std::make_shared<BitCodeAbbrev>();
2884 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2886 Abbv = std::make_shared<BitCodeAbbrev>();
2890 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2893 SmallVector<uint64_t, 64>
Record;
2896 Type *LastTy =
nullptr;
2897 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2898 const Value *
V = Vals[i].first;
2900 if (
V->getType() != LastTy) {
2901 LastTy =
V->getType();
2904 CONSTANTS_SETTYPE_ABBREV);
2911 unsigned(
IA->hasSideEffects()) |
unsigned(
IA->isAlignStack()) << 1 |
2912 unsigned(
IA->getDialect() & 1) << 2 |
unsigned(
IA->canThrow()) << 3);
2915 StringRef AsmStr =
IA->getAsmString();
2920 StringRef ConstraintStr =
IA->getConstraintString();
2928 unsigned Code = -1U;
2929 unsigned AbbrevToUse = 0;
2930 if (
C->isNullValue()) {
2937 if (
IV->getBitWidth() <= 64) {
2938 uint64_t
V =
IV->getSExtValue();
2941 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2947 if (BV->getBitWidth() <= 64) {
2948 uint64_t
V = BV->getSExtValue();
2951 AbbrevToUse = CONSTANTS_BYTE_ABBREV;
2961 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2965 APInt api = CFP->getValueAPF().bitcastToAPInt();
2967 Record.push_back((p[1] << 48) | (p[0] >> 16));
2968 Record.push_back(p[0] & 0xffffLL);
2970 APInt api = CFP->getValueAPF().bitcastToAPInt();
2975 assert(0 &&
"Unknown FP type!");
2981 uint64_t NumElts = Str->getNumElements();
2983 if (Str->isCString()) {
2988 AbbrevToUse = String8Abbrev;
2992 for (uint64_t i = 0; i != NumElts; ++i) {
2993 unsigned char V = Str->getElementAsInteger(i);
2995 isCStr7 &= (
V & 128) == 0;
3001 AbbrevToUse = CString6Abbrev;
3003 AbbrevToUse = CString7Abbrev;
3004 }
else if (
const ConstantDataSequential *CDS =
3007 Type *EltTy = CDS->getElementType();
3009 for (uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
3010 Record.push_back(CDS->getElementAsInteger(i));
3012 for (uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
3014 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
3018 for (
const Value *
Op :
C->operands())
3020 AbbrevToUse = AggregateAbbrev;
3022 switch (
CE->getOpcode()) {
3029 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
3031 assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
3041 case Instruction::FNeg: {
3042 assert(
CE->getNumOperands() == 1 &&
"Unknown constant expr!");
3051 case Instruction::GetElementPtr: {
3056 if (std::optional<ConstantRange>
Range = GO->getInRange()) {
3060 for (
const Value *
Op :
CE->operands()) {
3066 case Instruction::ExtractElement:
3073 case Instruction::InsertElement:
3080 case Instruction::ShuffleVector:
3085 if (
C->getType() ==
C->getOperand(0)->getType()) {
3122 Stream.
EmitRecord(Code, Record, AbbrevToUse);
3129void ModuleBitcodeWriter::writeModuleConstants() {
3134 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
3136 writeConstants(i, Vals.size(),
true);
3150bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
3151 SmallVectorImpl<unsigned> &Vals) {
3155 if (ValID >= InstID) {
3162bool ModuleBitcodeWriter::pushValueOrMetadata(
const Value *V,
unsigned InstID,
3163 SmallVectorImpl<unsigned> &Vals) {
3164 bool IsMetadata =
V->getType()->isMetadataTy();
3172 return pushValueAndType(V, InstID, Vals);
3175void ModuleBitcodeWriter::writeOperandBundles(
const CallBase &CS,
3182 Record.push_back(
C.getOperandBundleTagID(Bundle.getTagName()));
3184 for (
auto &Input : Bundle.Inputs)
3185 pushValueOrMetadata(Input, InstID, Record);
3194void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
3195 SmallVectorImpl<unsigned> &Vals) {
3200void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
3201 SmallVectorImpl<uint64_t> &Vals) {
3203 int64_t diff = ((int32_t)InstID - (int32_t)ValID);
3208void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
3210 SmallVectorImpl<unsigned> &Vals) {
3212 unsigned AbbrevToUse = 0;
3214 switch (
I.getOpcode()) {
3218 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3219 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
3224 if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
3225 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
3231 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3232 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
3233 pushValue(
I.getOperand(1), InstID, Vals);
3237 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
3238 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
3243 case Instruction::FNeg: {
3245 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3246 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
3250 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
3251 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
3256 case Instruction::GetElementPtr: {
3258 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
3262 for (
const Value *
Op :
I.operands())
3263 pushValueAndType(
Op, InstID, Vals);
3266 case Instruction::ExtractValue: {
3268 pushValueAndType(
I.getOperand(0), InstID, Vals);
3273 case Instruction::InsertValue: {
3275 pushValueAndType(
I.getOperand(0), InstID, Vals);
3276 pushValueAndType(
I.getOperand(1), InstID, Vals);
3281 case Instruction::Select: {
3283 pushValueAndType(
I.getOperand(1), InstID, Vals);
3284 pushValue(
I.getOperand(2), InstID, Vals);
3285 pushValueAndType(
I.getOperand(0), InstID, Vals);
3291 case Instruction::ExtractElement:
3293 pushValueAndType(
I.getOperand(0), InstID, Vals);
3294 pushValueAndType(
I.getOperand(1), InstID, Vals);
3296 case Instruction::InsertElement:
3298 pushValueAndType(
I.getOperand(0), InstID, Vals);
3299 pushValue(
I.getOperand(1), InstID, Vals);
3300 pushValueAndType(
I.getOperand(2), InstID, Vals);
3302 case Instruction::ShuffleVector:
3304 pushValueAndType(
I.getOperand(0), InstID, Vals);
3305 pushValue(
I.getOperand(1), InstID, Vals);
3309 case Instruction::ICmp:
3310 case Instruction::FCmp: {
3313 AbbrevToUse = FUNCTION_INST_CMP_ABBREV;
3314 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3316 pushValue(
I.getOperand(1), InstID, Vals);
3322 AbbrevToUse = FUNCTION_INST_CMP_FLAGS_ABBREV;
3327 case Instruction::Ret:
3330 unsigned NumOperands =
I.getNumOperands();
3331 if (NumOperands == 0)
3332 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
3333 else if (NumOperands == 1) {
3334 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3335 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
3337 for (
const Value *
Op :
I.operands())
3338 pushValueAndType(
Op, InstID, Vals);
3342 case Instruction::UncondBr: {
3344 AbbrevToUse = FUNCTION_INST_BR_UNCOND_ABBREV;
3348 case Instruction::CondBr: {
3350 AbbrevToUse = FUNCTION_INST_BR_COND_ABBREV;
3354 pushValue(
II.getCondition(), InstID, Vals);
3356 case Instruction::Switch:
3361 pushValue(
SI.getCondition(), InstID, Vals);
3363 for (
auto Case :
SI.cases()) {
3369 case Instruction::IndirectBr:
3373 pushValue(
I.getOperand(0), InstID, Vals);
3378 case Instruction::Invoke: {
3381 FunctionType *FTy =
II->getFunctionType();
3383 if (
II->hasOperandBundles())
3384 writeOperandBundles(*
II, InstID);
3393 pushValueAndType(Callee, InstID, Vals);
3396 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3397 pushValue(
I.getOperand(i), InstID, Vals);
3400 if (FTy->isVarArg()) {
3401 for (
unsigned i = FTy->getNumParams(), e =
II->arg_size(); i != e; ++i)
3402 pushValueAndType(
I.getOperand(i), InstID, Vals);
3406 case Instruction::Resume:
3408 pushValueAndType(
I.getOperand(0), InstID, Vals);
3410 case Instruction::CleanupRet: {
3413 pushValue(CRI.getCleanupPad(), InstID, Vals);
3414 if (CRI.hasUnwindDest())
3418 case Instruction::CatchRet: {
3421 pushValue(CRI.getCatchPad(), InstID, Vals);
3425 case Instruction::CleanupPad:
3426 case Instruction::CatchPad: {
3430 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3432 unsigned NumArgOperands = FuncletPad.arg_size();
3434 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
3435 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
3438 case Instruction::CatchSwitch: {
3442 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3444 unsigned NumHandlers = CatchSwitch.getNumHandlers();
3446 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
3449 if (CatchSwitch.hasUnwindDest())
3453 case Instruction::CallBr: {
3459 writeOperandBundles(*CBI, InstID);
3474 pushValueAndType(Callee, InstID, Vals);
3477 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3478 pushValue(
I.getOperand(i), InstID, Vals);
3481 if (FTy->isVarArg()) {
3482 for (
unsigned i = FTy->getNumParams(), e = CBI->
arg_size(); i != e; ++i)
3483 pushValueAndType(
I.getOperand(i), InstID, Vals);
3487 case Instruction::Unreachable:
3489 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3492 case Instruction::PHI: {
3510 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
3515 case Instruction::LandingPad: {
3526 pushValueAndType(LP.
getClause(
I), InstID, Vals);
3531 case Instruction::Alloca: {
3537 using APV = AllocaPackedValues;
3539 unsigned EncodedAlign = getEncodedAlign(AI.
getAlign());
3541 Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3543 EncodedAlign >> APV::AlignLower::Bits);
3550 if (AS !=
M.getDataLayout().getAllocaAddrSpace())
3555 case Instruction::Load:
3558 pushValueAndType(
I.getOperand(0), InstID, Vals);
3561 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3562 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3572 case Instruction::Store:
3577 AbbrevToUse = FUNCTION_INST_STORE_ABBREV;
3579 if (pushValueAndType(
I.getOperand(1), InstID, Vals))
3581 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3591 case Instruction::AtomicCmpXchg:
3593 pushValueAndType(
I.getOperand(0), InstID, Vals);
3594 pushValueAndType(
I.getOperand(1), InstID, Vals);
3595 pushValue(
I.getOperand(2), InstID, Vals);
3606 case Instruction::AtomicRMW:
3608 pushValueAndType(
I.getOperand(0), InstID, Vals);
3609 pushValueAndType(
I.getOperand(1), InstID, Vals);
3617 case Instruction::Fence:
3622 case Instruction::Call: {
3627 writeOperandBundles(CI, InstID);
3647 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3651 if (FTy->isVarArg()) {
3652 for (
unsigned i = FTy->getNumParams(), e = CI.
arg_size(); i != e; ++i)
3657 case Instruction::VAArg:
3660 pushValue(
I.getOperand(0), InstID, Vals);
3663 case Instruction::Freeze:
3665 pushValueAndType(
I.getOperand(0), InstID, Vals);
3675void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3676 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3681 VSTOffset -= bitcodeStartBit();
3682 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
3686 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3690 auto Abbv = std::make_shared<BitCodeAbbrev>();
3694 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3696 for (
const Function &
F : M) {
3699 if (
F.isDeclaration())
3706 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
3707 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
3711 Record[1] = BitcodeIndex / 32 + 1;
3720void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3721 const ValueSymbolTable &VST) {
3729 SmallVector<uint64_t, 64> NameVals;
3735 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3744 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3748 AbbrevToUse = VST_ENTRY_6_ABBREV;
3750 AbbrevToUse = VST_ENTRY_7_ABBREV;
3753 for (
const auto P :
Name.getKey())
3757 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3764void ModuleBitcodeWriter::writeUseList(UseListOrder &&Order) {
3765 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3772 SmallVector<uint64_t, 64>
Record(Order.Shuffle.begin(), Order.Shuffle.end());
3777void ModuleBitcodeWriter::writeUseListBlock(
const Function *
F) {
3779 "Expected to be preserving use-list order");
3781 auto hasMore = [&]() {
3797void ModuleBitcodeWriter::writeFunction(
3799 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3816 unsigned CstStart, CstEnd;
3818 writeConstants(CstStart, CstEnd,
false);
3821 writeFunctionMetadata(
F);
3824 unsigned InstID = CstEnd;
3826 bool NeedsMetadataAttachment =
F.hasMetadata();
3828 DILocation *LastDL =
nullptr;
3829 SmallSetVector<Function *, 4> BlockAddressUsers;
3832 for (
const BasicBlock &BB :
F) {
3833 for (
const Instruction &
I : BB) {
3834 writeInstruction(
I, InstID, Vals);
3836 if (!
I.getType()->isVoidTy())
3840 NeedsMetadataAttachment |=
I.hasMetadataOtherThanDebugLoc();
3843 if (DILocation *
DL =
I.getDebugLoc()) {
3856 FUNCTION_DEBUG_LOC_ABBREV);
3866 if (
I.hasDbgRecords()) {
3870 auto PushValueOrMetadata = [&Vals, InstID,
3873 "RawLocation unexpectedly null in DbgVariableRecord");
3875 SmallVector<unsigned, 2> ValAndType;
3879 if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
3893 for (DbgRecord &DR :
I.DebugMarker->getDbgRecordRange()) {
3919 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3943 SmallPtrSet<Value *, 8> Visited{BA};
3944 while (!Worklist.
empty()) {
3946 for (User *U :
V->users()) {
3952 Visited.
insert(U).second)
3959 if (!BlockAddressUsers.
empty()) {
3968 if (
auto *Symtab =
F.getValueSymbolTable())
3969 writeFunctionLevelValueSymbolTable(*Symtab);
3971 if (NeedsMetadataAttachment)
3972 writeFunctionMetadataAttachment(
F);
3974 writeUseListBlock(&
F);
3980void ModuleBitcodeWriter::writeBlockInfo() {
3993 auto Abbv = std::make_shared<BitCodeAbbrev>();
4004 auto Abbv = std::make_shared<BitCodeAbbrev>();
4014 auto Abbv = std::make_shared<BitCodeAbbrev>();
4024 auto Abbv = std::make_shared<BitCodeAbbrev>();
4030 VST_BBENTRY_6_ABBREV)
4035 auto Abbv = std::make_shared<BitCodeAbbrev>();
4037 Abbv->Add(TypeAbbrevOp);
4039 CONSTANTS_SETTYPE_ABBREV)
4044 auto Abbv = std::make_shared<BitCodeAbbrev>();
4048 CONSTANTS_INTEGER_ABBREV)
4053 auto Abbv = std::make_shared<BitCodeAbbrev>();
4057 CONSTANTS_BYTE_ABBREV)
4062 auto Abbv = std::make_shared<BitCodeAbbrev>();
4070 CONSTANTS_CE_CAST_Abbrev)
4074 auto Abbv = std::make_shared<BitCodeAbbrev>();
4077 CONSTANTS_NULL_Abbrev)
4084 auto Abbv = std::make_shared<BitCodeAbbrev>();
4086 Abbv->Add(ValAbbrevOp);
4087 Abbv->Add(TypeAbbrevOp);
4091 FUNCTION_INST_LOAD_ABBREV)
4095 auto Abbv = std::make_shared<BitCodeAbbrev>();
4097 Abbv->Add(ValAbbrevOp);
4098 Abbv->Add(ValAbbrevOp);
4102 FUNCTION_INST_STORE_ABBREV)
4106 auto Abbv = std::make_shared<BitCodeAbbrev>();
4108 Abbv->Add(ValAbbrevOp);
4111 FUNCTION_INST_UNOP_ABBREV)
4115 auto Abbv = std::make_shared<BitCodeAbbrev>();
4117 Abbv->Add(ValAbbrevOp);
4121 FUNCTION_INST_UNOP_FLAGS_ABBREV)
4125 auto Abbv = std::make_shared<BitCodeAbbrev>();
4127 Abbv->Add(ValAbbrevOp);
4128 Abbv->Add(ValAbbrevOp);
4131 FUNCTION_INST_BINOP_ABBREV)
4135 auto Abbv = std::make_shared<BitCodeAbbrev>();
4137 Abbv->Add(ValAbbrevOp);
4138 Abbv->Add(ValAbbrevOp);
4142 FUNCTION_INST_BINOP_FLAGS_ABBREV)
4146 auto Abbv = std::make_shared<BitCodeAbbrev>();
4148 Abbv->Add(ValAbbrevOp);
4149 Abbv->Add(TypeAbbrevOp);
4152 FUNCTION_INST_CAST_ABBREV)
4156 auto Abbv = std::make_shared<BitCodeAbbrev>();
4158 Abbv->Add(ValAbbrevOp);
4159 Abbv->Add(TypeAbbrevOp);
4163 FUNCTION_INST_CAST_FLAGS_ABBREV)
4168 auto Abbv = std::make_shared<BitCodeAbbrev>();
4171 FUNCTION_INST_RET_VOID_ABBREV)
4175 auto Abbv = std::make_shared<BitCodeAbbrev>();
4177 Abbv->Add(ValAbbrevOp);
4179 FUNCTION_INST_RET_VAL_ABBREV)
4183 auto Abbv = std::make_shared<BitCodeAbbrev>();
4186 Abbv->Add(ValAbbrevOp);
4188 FUNCTION_INST_BR_UNCOND_ABBREV)
4192 auto Abbv = std::make_shared<BitCodeAbbrev>();
4195 Abbv->Add(ValAbbrevOp);
4196 Abbv->Add(ValAbbrevOp);
4197 Abbv->Add(ValAbbrevOp);
4199 FUNCTION_INST_BR_COND_ABBREV)
4203 auto Abbv = std::make_shared<BitCodeAbbrev>();
4206 FUNCTION_INST_UNREACHABLE_ABBREV)
4210 auto Abbv = std::make_shared<BitCodeAbbrev>();
4213 Abbv->Add(TypeAbbrevOp);
4215 Abbv->Add(ValAbbrevOp);
4217 FUNCTION_INST_GEP_ABBREV)
4221 auto Abbv = std::make_shared<BitCodeAbbrev>();
4223 Abbv->Add(ValAbbrevOp);
4224 Abbv->Add(ValAbbrevOp);
4227 FUNCTION_INST_CMP_ABBREV)
4231 auto Abbv = std::make_shared<BitCodeAbbrev>();
4233 Abbv->Add(ValAbbrevOp);
4234 Abbv->Add(ValAbbrevOp);
4238 FUNCTION_INST_CMP_FLAGS_ABBREV)
4242 auto Abbv = std::make_shared<BitCodeAbbrev>();
4247 Abbv->Add(ValAbbrevOp);
4249 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
4253 auto Abbv = std::make_shared<BitCodeAbbrev>();
4264 FUNCTION_DEBUG_LOC_ABBREV)
4272void IndexBitcodeWriter::writeModStrings() {
4278 auto Abbv = std::make_shared<BitCodeAbbrev>();
4283 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
4286 Abbv = std::make_shared<BitCodeAbbrev>();
4291 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
4294 Abbv = std::make_shared<BitCodeAbbrev>();
4299 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
4302 Abbv = std::make_shared<BitCodeAbbrev>();
4309 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
4312 forEachModule([&](
const StringMapEntry<ModuleHash> &MPSE) {
4314 const auto &Hash = MPSE.
getValue();
4316 unsigned AbbrevToUse = Abbrev8Bit;
4318 AbbrevToUse = Abbrev6Bit;
4320 AbbrevToUse = Abbrev7Bit;
4322 auto ModuleId = ModuleIdMap.
size();
4323 ModuleIdMap[
Key] = ModuleId;
4333 Vals.
assign(Hash.begin(), Hash.end());
4345template <
typename Fn>
4349 if (!FS->type_tests().empty())
4354 auto WriteVFuncIdVec = [&](
uint64_t Ty,
4359 for (
auto &VF : VFs) {
4360 Record.push_back(VF.GUID);
4361 Record.push_back(VF.Offset);
4367 FS->type_test_assume_vcalls());
4369 FS->type_checked_load_vcalls());
4371 auto WriteConstVCallVec = [&](
uint64_t Ty,
4373 for (
auto &VC : VCs) {
4375 Record.push_back(VC.VFunc.GUID);
4376 Record.push_back(VC.VFunc.Offset);
4383 FS->type_test_assume_const_vcalls());
4385 FS->type_checked_load_const_vcalls());
4395 if (!FS->paramAccesses().empty()) {
4397 for (
auto &Arg : FS->paramAccesses()) {
4398 size_t UndoSize =
Record.size();
4399 Record.push_back(Arg.ParamNo);
4400 WriteRange(Arg.Use);
4401 Record.push_back(Arg.Calls.size());
4402 for (
auto &
Call : Arg.Calls) {
4404 std::optional<unsigned> ValueID = GetValueID(
Call.Callee);
4411 Record.push_back(*ValueID);
4412 WriteRange(
Call.Offsets);
4423 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
4424 if (!FS->type_tests().empty())
4425 for (
auto &TT : FS->type_tests())
4426 ReferencedTypeIds.insert(TT);
4428 auto GetReferencedTypesFromVFuncIdVec =
4430 for (
auto &VF : VFs)
4431 ReferencedTypeIds.insert(VF.GUID);
4434 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4435 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4437 auto GetReferencedTypesFromConstVCallVec =
4439 for (
auto &VC : VCs)
4440 ReferencedTypeIds.insert(VC.VFunc.GUID);
4443 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4444 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
4480 NameVals.
push_back(Summary.TTRes.TheKind);
4481 NameVals.
push_back(Summary.TTRes.SizeM1BitWidth);
4482 NameVals.
push_back(Summary.TTRes.AlignLog2);
4483 NameVals.
push_back(Summary.TTRes.SizeM1);
4484 NameVals.
push_back(Summary.TTRes.BitMask);
4485 NameVals.
push_back(Summary.TTRes.InlineBits);
4487 for (
auto &W : Summary.WPDRes)
4499 for (
auto &
P : Summary) {
4501 NameVals.
push_back(
VE.getValueID(
P.VTableVI.getValue()));
4515 static_assert(std::is_same_v<LinearFrameId, unsigned>);
4516 for (
auto &AI : FS->allocs()) {
4517 for (
auto &MIB : AI.MIBs) {
4519 StackIdIndices.
reserve(MIB.StackIdIndices.size());
4520 for (
auto Id : MIB.StackIdIndices)
4521 StackIdIndices.
push_back(GetStackIndex(Id));
4523 CallStacks.insert({CallStacks.size(), StackIdIndices});
4536 assert(!CallStacks.empty());
4542 Builder.
build(std::move(CallStacks),
nullptr,
4546 return Builder.takeCallStackPos();
4551 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
bool PerModule,
4552 std::function<
unsigned(
const ValueInfo &VI)> GetValueID,
4553 std::function<
unsigned(
unsigned)> GetStackIndex,
4554 bool WriteContextSizeInfoIndex,
4559 for (
auto &CI : FS->callsites()) {
4563 assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4564 Record.push_back(GetValueID(CI.Callee));
4566 Record.push_back(CI.StackIdIndices.size());
4567 Record.push_back(CI.Clones.size());
4569 for (
auto Id : CI.StackIdIndices)
4570 Record.push_back(GetStackIndex(Id));
4578 for (
auto &AI : FS->allocs()) {
4582 assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4583 Record.push_back(AI.MIBs.size());
4585 Record.push_back(AI.Versions.size());
4586 for (
auto &MIB : AI.MIBs) {
4593 assert(CallStackCount <= CallStackPos.
size());
4594 Record.push_back(CallStackPos[CallStackCount++]);
4599 assert(AI.ContextSizeInfos.empty() ||
4600 AI.ContextSizeInfos.size() == AI.MIBs.size());
4602 if (WriteContextSizeInfoIndex && !AI.ContextSizeInfos.empty()) {
4610 ContextIds.
reserve(AI.ContextSizeInfos.size() * 2);
4611 for (
auto &Infos : AI.ContextSizeInfos) {
4612 Record.push_back(Infos.size());
4613 for (
auto [FullStackId, TotalSize] : Infos) {
4620 Record.push_back(TotalSize);
4638void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4639 SmallVector<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
4640 unsigned ValueID,
unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
4641 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
const Function &
F,
4642 DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
4649 Stream, FS, [&](
const ValueInfo &VI) -> std::optional<unsigned> {
4653 auto SpecialRefCnts =
FS->specialRefCounts();
4658 NameVals.
push_back(SpecialRefCnts.first);
4659 NameVals.
push_back(SpecialRefCnts.second);
4661 for (
auto &RI :
FS->refs())
4664 for (
auto &ECI :
FS->calls()) {
4665 NameVals.
push_back(getValueId(ECI.first));
4674 Stream, FS, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
4676 [&](
const ValueInfo &VI) {
return getValueId(VI); },
4677 [&](
unsigned I) {
return I; },
4678 true, CallStackPos, CallStackCount);
4683void ModuleBitcodeWriterBase::writeModuleLevelReferences(
4684 const GlobalVariable &V, SmallVector<uint64_t, 64> &NameVals,
4685 unsigned FSModRefsAbbrev,
unsigned FSModVTableRefsAbbrev) {
4686 auto VI =
Index->getValueInfo(
V.getGUID());
4687 if (!VI ||
VI.getSummaryList().empty()) {
4693 auto *
Summary =
VI.getSummaryList()[0].get();
4699 auto VTableFuncs =
VS->vTableFuncs();
4700 if (!VTableFuncs.empty())
4703 unsigned SizeBeforeRefs = NameVals.
size();
4704 for (
auto &RI :
VS->refs())
4710 if (VTableFuncs.empty())
4715 for (
auto &
P : VTableFuncs) {
4721 FSModVTableRefsAbbrev);
4728void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
4731 bool IsThinLTO =
true;
4734 IsThinLTO = MD->getZExtValue();
4746 if (
Index->enableSplitLTOUnit())
4748 if (
Index->hasUnifiedLTO())
4758 auto Abbv = std::make_shared<BitCodeAbbrev>();
4764 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4766 for (
const auto &GVI : valueIds()) {
4768 ArrayRef<uint32_t>{GVI.second,
4769 static_cast<uint32_t
>(GVI.first >> 32),
4770 static_cast<uint32_t
>(GVI.first)},
4774 if (!
Index->stackIds().empty()) {
4775 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4782 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4783 SmallVector<uint32_t> Vals;
4785 for (
auto Id :
Index->stackIds()) {
4786 Vals.
push_back(
static_cast<uint32_t
>(Id >> 32));
4787 Vals.
push_back(
static_cast<uint32_t
>(Id));
4792 unsigned ContextIdAbbvId = 0;
4795 auto ContextIdAbbv = std::make_shared<BitCodeAbbrev>();
4807 ContextIdAbbvId = Stream.
EmitAbbrev(std::move(ContextIdAbbv));
4811 Abbv = std::make_shared<BitCodeAbbrev>();
4823 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4826 Abbv = std::make_shared<BitCodeAbbrev>();
4832 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4835 Abbv = std::make_shared<BitCodeAbbrev>();
4843 unsigned FSModVTableRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4846 Abbv = std::make_shared<BitCodeAbbrev>();
4851 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4854 Abbv = std::make_shared<BitCodeAbbrev>();
4861 unsigned TypeIdCompatibleVtableAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4863 Abbv = std::make_shared<BitCodeAbbrev>();
4869 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4871 Abbv = std::make_shared<BitCodeAbbrev>();
4878 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4880 Abbv = std::make_shared<BitCodeAbbrev>();
4885 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4892 MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
4893 for (
const Function &
F : M) {
4899 ValueInfo
VI =
Index->getValueInfo(
F.getGUID());
4900 if (!VI ||
VI.getSummaryList().empty()) {
4906 auto *
Summary =
VI.getSummaryList()[0].get();
4909 FS, [](
unsigned I) {
return I; }, CallStacks);
4913 DenseMap<CallStackId, LinearCallStackId> CallStackPos;
4914 if (!CallStacks.
empty()) {
4922 SmallVector<uint64_t, 64> NameVals;
4925 for (
const Function &
F : M) {
4931 ValueInfo
VI =
Index->getValueInfo(
F.getGUID());
4932 if (!VI ||
VI.getSummaryList().empty()) {
4938 auto *
Summary =
VI.getSummaryList()[0].get();
4939 writePerModuleFunctionSummaryRecord(NameVals, Summary, VE.
getValueID(&
F),
4940 FSCallsProfileAbbrev, CallsiteAbbrev,
4941 AllocAbbrev, ContextIdAbbvId,
F,
4942 CallStackPos, CallStackCount);
4947 for (
const GlobalVariable &
G :
M.globals())
4948 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev,
4949 FSModVTableRefsAbbrev);
4951 for (
const GlobalAlias &
A :
M.aliases()) {
4952 auto *Aliasee =
A.getAliaseeObject();
4968 for (
auto &S :
Index->typeIdCompatibleVtableMap()) {
4972 TypeIdCompatibleVtableAbbrev);
4976 if (
Index->getBlockCount())
4978 ArrayRef<uint64_t>{
Index->getBlockCount()});
4984void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4993 auto Abbv = std::make_shared<BitCodeAbbrev>();
4999 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5001 for (
const auto &GVI : valueIds()) {
5003 ArrayRef<uint32_t>{GVI.second,
5004 static_cast<uint32_t
>(GVI.first >> 32),
5005 static_cast<uint32_t
>(GVI.first)},
5011 if (!StackIds.empty()) {
5012 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
5019 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
5020 SmallVector<uint32_t> Vals;
5021 Vals.
reserve(StackIds.size() * 2);
5022 for (
auto Id : StackIds) {
5023 Vals.
push_back(
static_cast<uint32_t
>(Id >> 32));
5024 Vals.
push_back(
static_cast<uint32_t
>(Id));
5030 Abbv = std::make_shared<BitCodeAbbrev>();
5044 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5047 Abbv = std::make_shared<BitCodeAbbrev>();
5054 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5057 Abbv = std::make_shared<BitCodeAbbrev>();
5063 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5065 Abbv = std::make_shared<BitCodeAbbrev>();
5073 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5075 Abbv = std::make_shared<BitCodeAbbrev>();
5086 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5088 auto shouldImportValueAsDecl = [&](GlobalValueSummary *GVS) ->
bool {
5089 if (DecSummaries ==
nullptr)
5091 return DecSummaries->
count(GVS);
5099 DenseMap<const GlobalValueSummary *, unsigned> SummaryToValueIdMap;
5101 SmallVector<uint64_t, 64> NameVals;
5105 std::set<GlobalValue::GUID> ReferencedTypeIds;
5109 auto MaybeEmitOriginalName = [&](GlobalValueSummary &S) {
5119 NameVals.
push_back(S.getOriginalName());
5124 DenseMap<CallStackId, LinearCallStackId> CallStackPos;
5126 Abbv = std::make_shared<BitCodeAbbrev>();
5131 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5138 MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
5139 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5145 GlobalValueSummary *S =
I.second;
5158 return StackIdIndicesToIndex[
I];
5164 if (!CallStacks.
empty()) {
5174 DenseSet<GlobalValue::GUID> DefOrUseGUIDs;
5175 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5176 GlobalValueSummary *S =
I.second;
5178 DefOrUseGUIDs.
insert(
I.first);
5179 for (
const ValueInfo &VI : S->
refs())
5180 DefOrUseGUIDs.
insert(
VI.getGUID());
5182 auto ValueId = getValueId(
I.first);
5184 SummaryToValueIdMap[S] = *ValueId;
5202 NameVals.
push_back(ModuleIdMap[
VS->modulePath()]);
5206 for (
auto &RI :
VS->refs()) {
5207 auto RefValueId = getValueId(RI.getGUID());
5217 MaybeEmitOriginalName(*S);
5221 auto GetValueId = [&](
const ValueInfo &
VI) -> std::optional<unsigned> {
5223 return std::nullopt;
5224 return getValueId(
VI.getGUID());
5233 NameVals.
push_back(ModuleIdMap[
FS->modulePath()]);
5246 unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
5247 for (
auto &RI :
FS->refs()) {
5248 auto RefValueId = getValueId(RI.getGUID());
5252 if (RI.isReadOnly())
5254 else if (RI.isWriteOnly())
5258 NameVals[6] =
Count;
5259 NameVals[7] = RORefCnt;
5260 NameVals[8] = WORefCnt;
5262 for (
auto &EI :
FS->calls()) {
5265 std::optional<unsigned> CallValueId = GetValueId(EI.first);
5274 FSCallsProfileAbbrev);
5278 Stream, FS, CallsiteAbbrev, AllocAbbrev, 0,
5281 [&](
const ValueInfo &VI) ->
unsigned {
5282 std::optional<unsigned> ValueID = GetValueId(VI);
5297 return StackIdIndicesToIndex[
I];
5299 false, CallStackPos, CallStackCount);
5301 MaybeEmitOriginalName(*S);
5304 for (
auto *AS : Aliases) {
5305 auto AliasValueId = SummaryToValueIdMap[AS];
5314 auto AliaseeValueId =
5321 MaybeEmitOriginalName(*AS);
5329 auto EmitCfiFunctions = [&](
const CfiFunctionIndex &CfiIndex,
5331 if (CfiIndex.
empty())
5335 for (StringRef Name : Names)
5338 if (Functions.
empty())
5341 for (
const auto &Record : Functions) {
5356 for (
auto &
T : ReferencedTypeIds) {
5357 auto TidIter =
Index.typeIds().equal_range(
T);
5358 for (
const auto &[GUID, TypeIdPair] :
make_range(TidIter)) {
5366 if (
Index.getBlockCount())
5368 ArrayRef<uint64_t>{
Index.getBlockCount()});
5379 auto Abbv = std::make_shared<BitCodeAbbrev>();
5383 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5385 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
5388 Abbv = std::make_shared<BitCodeAbbrev>();
5391 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5397void ModuleBitcodeWriter::writeModuleHash(StringRef View) {
5402 Hasher.
update(ArrayRef<uint8_t>(
5403 reinterpret_cast<const uint8_t *
>(
View.data()),
View.size()));
5404 std::array<uint8_t, 20> Hash = Hasher.
result();
5405 for (
int Pos = 0; Pos < 20; Pos += 4) {
5418void ModuleBitcodeWriter::write() {
5426 writeModuleVersion();
5435 writeAttributeGroupTable();
5438 writeAttributeTable();
5447 writeModuleConstants();
5450 writeModuleMetadataKinds();
5453 writeModuleMetadata();
5457 writeUseListBlock(
nullptr);
5459 writeOperandBundleTags();
5460 writeSyncScopeNames();
5463 DenseMap<const Function *, uint64_t> FunctionToBitcodeIndex;
5464 for (
const Function &
F : M)
5465 if (!
F.isDeclaration())
5466 writeFunction(
F, FunctionToBitcodeIndex);
5471 writePerModuleGlobalValueSummary();
5473 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
5501 unsigned CPUType = ~0U;
5508 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
5509 DARWIN_CPU_TYPE_X86 = 7,
5510 DARWIN_CPU_TYPE_ARM = 12,
5511 DARWIN_CPU_TYPE_POWERPC = 18
5516 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
5518 CPUType = DARWIN_CPU_TYPE_X86;
5520 CPUType = DARWIN_CPU_TYPE_POWERPC;
5522 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
5524 CPUType = DARWIN_CPU_TYPE_ARM;
5528 "Expected header size to be reserved");
5533 unsigned Position = 0;
5541 while (Buffer.
size() & 15)
5548 Stream.
Emit((
unsigned)
'B', 8);
5549 Stream.
Emit((
unsigned)
'C', 8);
5550 Stream.
Emit(0x0, 4);
5551 Stream.
Emit(0xC, 4);
5552 Stream.
Emit(0xE, 4);
5553 Stream.
Emit(0xD, 4);
5571 auto Abbv = std::make_shared<BitCodeAbbrev>();
5574 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
5582 assert(!WroteStrtab && !WroteSymtab);
5588 if (M->getModuleInlineAsm().empty())
5592 const Triple TT(M->getTargetTriple());
5594 if (!
T || !
T->hasMCAsmParser())
5616 std::vector<char> Strtab;
5617 StrtabBuilder.finalizeInOrder();
5618 Strtab.resize(StrtabBuilder.getSize());
5619 StrtabBuilder.write((
uint8_t *)Strtab.data());
5622 {Strtab.data(), Strtab.size()});
5633 bool ShouldPreserveUseListOrder,
5642 assert(M.isMaterialized());
5643 Mods.push_back(
const_cast<Module *
>(&M));
5645 ModuleBitcodeWriter ModuleWriter(M, StrtabBuilder, *Stream,
5646 ShouldPreserveUseListOrder, Index,
5647 GenerateHash, ModHash);
5648 ModuleWriter.write();
5655 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, DecSummaries,
5656 ModuleToSummariesForIndex);
5657 IndexWriter.write();
5662 bool ShouldPreserveUseListOrder,
5666 Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
5668 Writer.writeSymtab();
5669 Writer.writeStrtab();
5671 Triple TT(M.getTargetTriple());
5672 if (TT.isOSDarwin() || TT.isOSBinFormatMachO()) {
5690void IndexBitcodeWriter::write() {
5693 writeModuleVersion();
5699 writeCombinedGlobalValueSummary();
5716 Writer.
writeIndex(&Index, ModuleToSummariesForIndex, DecSummaries);
5725class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
5735 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5737 ModHash(&ModHash) {}
5742 void writeSimplifiedModuleInfo();
5752void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5764 auto Abbv = std::make_shared<BitCodeAbbrev>();
5767 Abbv->Add(AbbrevOpToUse);
5768 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5770 for (
const auto P :
M.getSourceFileName())
5834void ThinLinkBitcodeWriter::write() {
5837 writeModuleVersion();
5839 writeSimplifiedModuleInfo();
5841 writePerModuleGlobalValueSummary();
5858 assert(M.isMaterialized());
5859 Mods.push_back(
const_cast<Module *
>(&M));
5861 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream, Index,
5863 ThinLinkWriter.write();
5884 switch (
T.getObjectFormat()) {
5886 return "__LLVM,__bitcode";
5911 switch (
T.getObjectFormat()) {
5913 return "__LLVM,__cmdline";
5939 const std::vector<uint8_t> &CmdArgs) {
5944 Type *UsedElementType = Used ? Used->getValueType()->getArrayElementType()
5946 for (
auto *GV : UsedGlobals) {
5947 if (GV->getName() !=
"llvm.embedded.module" &&
5948 GV->getName() !=
"llvm.cmdline")
5953 Used->eraseFromParent();
5958 Triple T(M.getTargetTriple());
5987 M.getGlobalVariable(
"llvm.embedded.module",
true)) {
5988 assert(Old->hasZeroLiveUses() &&
5989 "llvm.embedded.module can only be used once in llvm.compiler.used");
5991 Old->eraseFromParent();
5993 GV->
setName(
"llvm.embedded.module");
6011 assert(Old->hasZeroLiveUses() &&
6012 "llvm.cmdline can only be used once in llvm.compiler.used");
6014 Old->eraseFromParent();
6020 if (UsedArray.
empty())
6028 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
auto getNamesForGUID(GlobalValue::GUID GUID) const
get the name(s) associated with a given ThinLTO GUID.
@ 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.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
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.
constexpr bool isAtomic(const T &...O)
@ 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.
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.
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.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
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.
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
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.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
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,...
SmallPtrSet< GlobalValueSummary *, 0 > GVSummaryPtrSet
A set of global value summary pointers.
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