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."));
103 cl::desc(
"Write relative block frequency to function summary "));
134 VST_BBENTRY_6_ABBREV,
138 CONSTANTS_INTEGER_ABBREV,
139 CONSTANTS_CE_CAST_Abbrev,
140 CONSTANTS_NULL_Abbrev,
144 FUNCTION_INST_STORE_ABBREV,
145 FUNCTION_INST_UNOP_ABBREV,
146 FUNCTION_INST_UNOP_FLAGS_ABBREV,
147 FUNCTION_INST_BINOP_ABBREV,
148 FUNCTION_INST_BINOP_FLAGS_ABBREV,
149 FUNCTION_INST_CAST_ABBREV,
150 FUNCTION_INST_CAST_FLAGS_ABBREV,
151 FUNCTION_INST_RET_VOID_ABBREV,
152 FUNCTION_INST_RET_VAL_ABBREV,
153 FUNCTION_INST_BR_UNCOND_ABBREV,
154 FUNCTION_INST_BR_COND_ABBREV,
155 FUNCTION_INST_UNREACHABLE_ABBREV,
156 FUNCTION_INST_GEP_ABBREV,
157 FUNCTION_INST_CMP_ABBREV,
158 FUNCTION_INST_CMP_FLAGS_ABBREV,
159 FUNCTION_DEBUG_RECORD_VALUE_ABBREV,
160 FUNCTION_DEBUG_LOC_ABBREV,
165class BitcodeWriterBase {
168 BitstreamWriter &Stream;
170 StringTableBuilder &StrtabBuilder;
175 BitcodeWriterBase(BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder)
176 : Stream(Stream), StrtabBuilder(StrtabBuilder) {}
179 void writeModuleVersion();
182void BitcodeWriterBase::writeModuleVersion() {
189class ModuleBitcodeWriterBase :
public BitcodeWriterBase {
198 const ModuleSummaryIndex *Index;
203 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
206 unsigned GlobalValueId;
210 uint64_t VSTOffsetPlaceholder = 0;
215 ModuleBitcodeWriterBase(
const Module &M, StringTableBuilder &StrtabBuilder,
216 BitstreamWriter &Stream,
217 bool ShouldPreserveUseListOrder,
218 const ModuleSummaryIndex *Index)
219 : BitcodeWriterBase(Stream, StrtabBuilder),
M(
M),
229 for (
const auto &GUIDSummaryLists : *Index)
231 for (
auto &Summary : GUIDSummaryLists.second.SummaryList)
237 for (auto &CallEdge : FS->calls())
238 if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
239 assignValueId(CallEdge.first.getGUID());
245 for (auto &RefEdge : FS->refs())
246 if (!RefEdge.haveGVs() || !RefEdge.getValue())
247 assignValueId(RefEdge.getGUID());
252 void writePerModuleGlobalValueSummary();
255 void writePerModuleFunctionSummaryRecord(
256 SmallVector<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
257 unsigned ValueID,
unsigned FSCallsAbbrev,
unsigned FSCallsProfileAbbrev,
258 unsigned CallsiteAbbrev,
unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
259 const Function &
F, DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
261 void writeModuleLevelReferences(
const GlobalVariable &V,
262 SmallVector<uint64_t, 64> &NameVals,
263 unsigned FSModRefsAbbrev,
264 unsigned FSModVTableRefsAbbrev);
267 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
271 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
274 assert(VMI != GUIDToValueIdMap.end() &&
275 "GUID does not have assigned value Id");
280 unsigned getValueId(ValueInfo VI) {
281 if (!
VI.haveGVs() || !
VI.getValue())
282 return getValueId(
VI.getGUID());
286 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
290class ModuleBitcodeWriter :
public ModuleBitcodeWriterBase {
301 uint64_t BitcodeStartBit;
306 ModuleBitcodeWriter(
const Module &M, StringTableBuilder &StrtabBuilder,
307 BitstreamWriter &Stream,
bool ShouldPreserveUseListOrder,
308 const ModuleSummaryIndex *Index,
bool GenerateHash,
310 : ModuleBitcodeWriterBase(
M, StrtabBuilder, Stream,
311 ShouldPreserveUseListOrder,
Index),
312 GenerateHash(GenerateHash), ModHash(ModHash),
313 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
319 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
321 size_t addToStrtab(StringRef Str);
323 void writeAttributeGroupTable();
324 void writeAttributeTable();
325 void writeTypeTable();
327 void writeValueSymbolTableForwardDecl();
328 void writeModuleInfo();
329 void writeValueAsMetadata(
const ValueAsMetadata *MD,
330 SmallVectorImpl<uint64_t> &Record);
331 void writeMDTuple(
const MDTuple *
N, SmallVectorImpl<uint64_t> &Record,
333 unsigned createDILocationAbbrev();
334 void writeDILocation(
const DILocation *
N, SmallVectorImpl<uint64_t> &Record,
336 unsigned createGenericDINodeAbbrev();
338 SmallVectorImpl<uint64_t> &Record,
unsigned &Abbrev);
339 void writeDISubrange(
const DISubrange *
N, SmallVectorImpl<uint64_t> &Record,
342 SmallVectorImpl<uint64_t> &Record,
345 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
349 SmallVectorImpl<uint64_t> &Record,
352 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
354 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
356 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
358 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
360 SmallVectorImpl<uint64_t> &Record,
362 void writeDIFile(
const DIFile *
N, SmallVectorImpl<uint64_t> &Record,
365 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
367 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
369 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
371 SmallVectorImpl<uint64_t> &Record,
374 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
377 void writeDIMacro(
const DIMacro *
N, SmallVectorImpl<uint64_t> &Record,
381 void writeDIArgList(
const DIArgList *
N, SmallVectorImpl<uint64_t> &Record);
382 void writeDIModule(
const DIModule *
N, SmallVectorImpl<uint64_t> &Record,
384 void writeDIAssignID(
const DIAssignID *
N, SmallVectorImpl<uint64_t> &Record,
387 SmallVectorImpl<uint64_t> &Record,
390 SmallVectorImpl<uint64_t> &Record,
393 SmallVectorImpl<uint64_t> &Record,
396 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
398 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
400 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
402 SmallVectorImpl<uint64_t> &Record,
405 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
407 SmallVectorImpl<uint64_t> &Record,
409 unsigned createNamedMetadataAbbrev();
410 void writeNamedMetadata(SmallVectorImpl<uint64_t> &Record);
411 unsigned createMetadataStringsAbbrev();
413 SmallVectorImpl<uint64_t> &Record);
415 SmallVectorImpl<uint64_t> &Record,
416 std::vector<unsigned> *MDAbbrevs =
nullptr,
417 std::vector<uint64_t> *IndexPos =
nullptr);
418 void writeModuleMetadata();
419 void writeFunctionMetadata(
const Function &
F);
420 void writeFunctionMetadataAttachment(
const Function &
F);
421 void pushGlobalMetadataAttachment(SmallVectorImpl<uint64_t> &Record,
422 const GlobalObject &GO);
423 void writeModuleMetadataKinds();
424 void writeOperandBundleTags();
425 void writeSyncScopeNames();
426 void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
427 void writeModuleConstants();
428 bool pushValueAndType(
const Value *V,
unsigned InstID,
429 SmallVectorImpl<unsigned> &Vals);
430 bool pushValueOrMetadata(
const Value *V,
unsigned InstID,
431 SmallVectorImpl<unsigned> &Vals);
432 void writeOperandBundles(
const CallBase &CB,
unsigned InstID);
433 void pushValue(
const Value *V,
unsigned InstID,
434 SmallVectorImpl<unsigned> &Vals);
435 void pushValueSigned(
const Value *V,
unsigned InstID,
436 SmallVectorImpl<uint64_t> &Vals);
437 void writeInstruction(
const Instruction &
I,
unsigned InstID,
438 SmallVectorImpl<unsigned> &Vals);
439 void writeFunctionLevelValueSymbolTable(
const ValueSymbolTable &VST);
440 void writeGlobalValueSymbolTable(
441 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
442 void writeUseList(UseListOrder &&Order);
443 void writeUseListBlock(
const Function *
F);
445 writeFunction(
const Function &
F,
446 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
447 void writeBlockInfo();
448 void writeModuleHash(StringRef View);
451 return unsigned(SSID);
454 unsigned getEncodedAlign(MaybeAlign Alignment) {
return encode(Alignment); }
458class IndexBitcodeWriter :
public BitcodeWriterBase {
460 const ModuleSummaryIndex &
Index;
473 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
477 std::vector<uint64_t> StackIds;
482 DenseMap<unsigned, unsigned> StackIdIndicesToIndex;
485 unsigned GlobalValueId = 0;
489 DenseMap<StringRef, uint64_t> ModuleIdMap;
499 BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder,
500 const ModuleSummaryIndex &Index,
503 : BitcodeWriterBase(Stream, StrtabBuilder),
Index(
Index),
504 DecSummaries(DecSummaries),
505 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
509 auto RecordStackIdReference = [&](
unsigned StackIdIndex) {
514 StackIdIndicesToIndex.
insert({StackIdIndex, StackIds.size()});
516 StackIds.push_back(
Index.getStackIdAtIndex(StackIdIndex));
523 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
524 GUIDToValueIdMap[
I.first] = ++GlobalValueId;
536 for (
auto &CI :
FS->callsites()) {
547 if (CI.StackIdIndices.empty()) {
548 GUIDToValueIdMap[CI.Callee.getGUID()] = ++GlobalValueId;
551 for (
auto Idx : CI.StackIdIndices)
552 RecordStackIdReference(Idx);
555 for (
auto &AI :
FS->allocs())
556 for (
auto &MIB : AI.MIBs)
557 for (
auto Idx : MIB.StackIdIndices)
558 RecordStackIdReference(Idx);
564 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
569 template<
typename Functor>
570 void forEachSummary(Functor Callback) {
571 if (ModuleToSummariesForIndex) {
572 for (
auto &M : *ModuleToSummariesForIndex)
573 for (
auto &Summary :
M.second) {
579 Callback({AS->getAliaseeGUID(), &AS->getAliasee()},
true);
582 for (
auto &Summaries : Index)
583 for (
auto &Summary : Summaries.second.SummaryList)
592 template <
typename Functor>
void forEachModule(Functor Callback) {
593 if (ModuleToSummariesForIndex) {
594 for (
const auto &M : *ModuleToSummariesForIndex) {
595 const auto &MPI =
Index.modulePaths().find(
M.first);
596 if (MPI ==
Index.modulePaths().end()) {
600 assert(ModuleToSummariesForIndex->size() == 1);
610 std::vector<StringRef> ModulePaths;
611 for (
auto &[ModPath,
_] :
Index.modulePaths())
612 ModulePaths.push_back(ModPath);
614 for (
auto &ModPath : ModulePaths)
623 void writeModStrings();
624 void writeCombinedGlobalValueSummary();
627 auto VMI = GUIDToValueIdMap.find(ValGUID);
628 if (VMI == GUIDToValueIdMap.end())
633 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
668 case Instruction::Add:
670 case Instruction::Sub:
672 case Instruction::Mul:
675 case Instruction::FDiv:
678 case Instruction::FRem:
752 case Attribute::Alignment:
754 case Attribute::AllocAlign:
756 case Attribute::AllocSize:
758 case Attribute::AlwaysInline:
760 case Attribute::Builtin:
762 case Attribute::ByVal:
764 case Attribute::Convergent:
766 case Attribute::InAlloca:
768 case Attribute::Cold:
770 case Attribute::DisableSanitizerInstrumentation:
772 case Attribute::FnRetThunkExtern:
776 case Attribute::ElementType:
778 case Attribute::HybridPatchable:
780 case Attribute::InlineHint:
782 case Attribute::InReg:
784 case Attribute::JumpTable:
786 case Attribute::MinSize:
788 case Attribute::AllocatedPointer:
790 case Attribute::AllocKind:
792 case Attribute::Memory:
794 case Attribute::NoFPClass:
796 case Attribute::Naked:
798 case Attribute::Nest:
800 case Attribute::NoAlias:
802 case Attribute::NoBuiltin:
804 case Attribute::NoCallback:
806 case Attribute::NoDivergenceSource:
808 case Attribute::NoDuplicate:
810 case Attribute::NoFree:
812 case Attribute::NoImplicitFloat:
814 case Attribute::NoInline:
816 case Attribute::NoRecurse:
818 case Attribute::NoMerge:
820 case Attribute::NonLazyBind:
822 case Attribute::NonNull:
824 case Attribute::Dereferenceable:
826 case Attribute::DereferenceableOrNull:
828 case Attribute::NoRedZone:
830 case Attribute::NoReturn:
832 case Attribute::NoSync:
834 case Attribute::NoCfCheck:
836 case Attribute::NoProfile:
838 case Attribute::SkipProfile:
840 case Attribute::NoUnwind:
842 case Attribute::NoSanitizeBounds:
844 case Attribute::NoSanitizeCoverage:
846 case Attribute::NullPointerIsValid:
848 case Attribute::OptimizeForDebugging:
850 case Attribute::OptForFuzzing:
852 case Attribute::OptimizeForSize:
854 case Attribute::OptimizeNone:
856 case Attribute::ReadNone:
858 case Attribute::ReadOnly:
860 case Attribute::Returned:
862 case Attribute::ReturnsTwice:
864 case Attribute::SExt:
866 case Attribute::Speculatable:
868 case Attribute::StackAlignment:
870 case Attribute::StackProtect:
872 case Attribute::StackProtectReq:
874 case Attribute::StackProtectStrong:
876 case Attribute::SafeStack:
878 case Attribute::ShadowCallStack:
880 case Attribute::StrictFP:
882 case Attribute::StructRet:
884 case Attribute::SanitizeAddress:
886 case Attribute::SanitizeHWAddress:
888 case Attribute::SanitizeThread:
890 case Attribute::SanitizeType:
892 case Attribute::SanitizeMemory:
894 case Attribute::SanitizeNumericalStability:
896 case Attribute::SanitizeRealtime:
898 case Attribute::SanitizeRealtimeBlocking:
900 case Attribute::SpeculativeLoadHardening:
902 case Attribute::SwiftError:
904 case Attribute::SwiftSelf:
906 case Attribute::SwiftAsync:
908 case Attribute::UWTable:
910 case Attribute::VScaleRange:
912 case Attribute::WillReturn:
914 case Attribute::WriteOnly:
916 case Attribute::ZExt:
918 case Attribute::ImmArg:
920 case Attribute::SanitizeMemTag:
922 case Attribute::Preallocated:
924 case Attribute::NoUndef:
926 case Attribute::ByRef:
928 case Attribute::MustProgress:
930 case Attribute::PresplitCoroutine:
932 case Attribute::Writable:
934 case Attribute::CoroDestroyOnlyWhenComplete:
936 case Attribute::CoroElideSafe:
938 case Attribute::DeadOnUnwind:
940 case Attribute::Range:
942 case Attribute::Initializes:
944 case Attribute::NoExt:
946 case Attribute::Captures:
948 case Attribute::DeadOnReturn:
974 unsigned NumWords =
A.getActiveWords();
975 const uint64_t *RawData =
A.getRawData();
976 for (
unsigned i = 0; i < NumWords; i++)
996void ModuleBitcodeWriter::writeAttributeGroupTable() {
997 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
999 if (AttrGrps.empty())
return;
1003 SmallVector<uint64_t, 64> Record;
1005 unsigned AttrListIndex = Pair.first;
1006 AttributeSet AS = Pair.second;
1011 if (Attr.isEnumAttribute()) {
1014 }
else if (Attr.isIntAttribute()) {
1016 Attribute::AttrKind
Kind = Attr.getKindAsEnum();
1018 if (Kind == Attribute::Memory) {
1025 }
else if (Attr.isStringAttribute()) {
1026 StringRef
Kind = Attr.getKindAsString();
1027 StringRef Val = Attr.getValueAsString();
1036 }
else if (Attr.isTypeAttribute()) {
1037 Type *Ty = Attr.getValueAsType();
1042 }
else if (Attr.isConstantRangeAttribute()) {
1048 assert(Attr.isConstantRangeListAttribute());
1054 for (
auto &CR : Val)
1066void ModuleBitcodeWriter::writeAttributeTable() {
1068 if (
Attrs.empty())
return;
1072 SmallVector<uint64_t, 64> Record;
1073 for (
const AttributeList &AL : Attrs) {
1074 for (
unsigned i :
AL.indexes()) {
1075 AttributeSet AS =
AL.getAttributes(i);
1088void ModuleBitcodeWriter::writeTypeTable() {
1092 SmallVector<uint64_t, 64> TypeVals;
1097 auto Abbv = std::make_shared<BitCodeAbbrev>();
1099 Abbv->Add(BitCodeAbbrevOp(0));
1100 unsigned OpaquePtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1103 Abbv = std::make_shared<BitCodeAbbrev>();
1108 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1111 Abbv = std::make_shared<BitCodeAbbrev>();
1116 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1119 Abbv = std::make_shared<BitCodeAbbrev>();
1123 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1126 Abbv = std::make_shared<BitCodeAbbrev>();
1131 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1134 Abbv = std::make_shared<BitCodeAbbrev>();
1138 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1146 for (
Type *
T : TypeList) {
1147 int AbbrevToUse = 0;
1150 switch (
T->getTypeID()) {
1160 case Type::MetadataTyID:
1165 case Type::IntegerTyID:
1170 case Type::PointerTyID: {
1177 AbbrevToUse = OpaquePtrAbbrev;
1180 case Type::FunctionTyID: {
1186 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1188 AbbrevToUse = FunctionAbbrev;
1191 case Type::StructTyID: {
1196 for (
Type *ET :
ST->elements())
1199 if (
ST->isLiteral()) {
1201 AbbrevToUse = StructAnonAbbrev;
1203 if (
ST->isOpaque()) {
1207 AbbrevToUse = StructNamedAbbrev;
1211 if (!
ST->getName().empty())
1217 case Type::ArrayTyID: {
1221 TypeVals.
push_back(AT->getNumElements());
1223 AbbrevToUse = ArrayAbbrev;
1226 case Type::FixedVectorTyID:
1227 case Type::ScalableVectorTyID: {
1232 TypeVals.
push_back(VT->getElementCount().getKnownMinValue());
1238 case Type::TargetExtTyID: {
1244 for (
Type *InnerTy :
TET->type_params())
1249 case Type::TypedPointerTyID:
1254 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
1295 RawFlags |= Flags.ReadNone;
1296 RawFlags |= (Flags.ReadOnly << 1);
1297 RawFlags |= (Flags.NoRecurse << 2);
1298 RawFlags |= (Flags.ReturnDoesNotAlias << 3);
1299 RawFlags |= (Flags.NoInline << 4);
1300 RawFlags |= (Flags.AlwaysInline << 5);
1301 RawFlags |= (Flags.NoUnwind << 6);
1302 RawFlags |= (Flags.MayThrow << 7);
1303 RawFlags |= (Flags.HasUnknownCall << 8);
1304 RawFlags |= (Flags.MustBeUnreachable << 9);
1311 bool ImportAsDecl =
false) {
1314 RawFlags |= Flags.NotEligibleToImport;
1315 RawFlags |= (Flags.Live << 1);
1316 RawFlags |= (Flags.DSOLocal << 2);
1317 RawFlags |= (Flags.CanAutoHide << 3);
1322 RawFlags = (RawFlags << 4) | Flags.Linkage;
1324 RawFlags |= (Flags.Visibility << 8);
1326 unsigned ImportType = Flags.ImportType | ImportAsDecl;
1327 RawFlags |= (ImportType << 10);
1333 uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1334 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1386 switch (
C.getSelectionKind()) {
1410size_t ModuleBitcodeWriter::addToStrtab(StringRef Str) {
1413 return StrtabBuilder.
add(Str);
1416void ModuleBitcodeWriter::writeComdats() {
1431void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1436 auto Abbv = std::make_shared<BitCodeAbbrev>();
1442 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1458 bool isChar6 =
true;
1459 for (
char C : Str) {
1462 if ((
unsigned char)
C & 128)
1471static_assert(
sizeof(GlobalValue::SanitizerMetadata) <=
sizeof(unsigned),
1472 "Sanitizer Metadata is too large for naive serialization.");
1475 return Meta.NoAddress | (
Meta.NoHWAddress << 1) |
1476 (
Meta.Memtag << 2) | (
Meta.IsDynInit << 3);
1482void ModuleBitcodeWriter::writeModuleInfo() {
1484 if (!
M.getTargetTriple().empty())
1486 M.getTargetTriple().str(), 0 );
1487 const std::string &
DL =
M.getDataLayoutStr();
1490 if (!
M.getModuleInlineAsm().empty())
1496 std::map<std::string, unsigned> SectionMap;
1497 std::map<std::string, unsigned> GCMap;
1498 MaybeAlign MaxGVarAlignment;
1499 unsigned MaxGlobalType = 0;
1500 for (
const GlobalVariable &GV :
M.globals()) {
1501 if (MaybeAlign
A = GV.getAlign())
1502 MaxGVarAlignment = !MaxGVarAlignment ? *
A : std::max(*MaxGVarAlignment, *
A);
1503 MaxGlobalType = std::max(MaxGlobalType, VE.
getTypeID(GV.getValueType()));
1504 if (GV.hasSection()) {
1506 unsigned &
Entry = SectionMap[std::string(GV.getSection())];
1510 Entry = SectionMap.size();
1514 for (
const Function &
F : M) {
1515 if (
F.hasSection()) {
1517 unsigned &
Entry = SectionMap[std::string(
F.getSection())];
1521 Entry = SectionMap.size();
1526 unsigned &
Entry = GCMap[
F.getGC()];
1530 Entry = GCMap.size();
1536 unsigned SimpleGVarAbbrev = 0;
1537 if (!
M.global_empty()) {
1539 auto Abbv = std::make_shared<BitCodeAbbrev>();
1550 if (!MaxGVarAlignment)
1551 Abbv->Add(BitCodeAbbrevOp(0));
1553 unsigned MaxEncAlignment = getEncodedAlign(MaxGVarAlignment);
1557 if (SectionMap.empty())
1558 Abbv->Add(BitCodeAbbrevOp(0));
1563 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1577 auto Abbv = std::make_shared<BitCodeAbbrev>();
1580 Abbv->Add(AbbrevOpToUse);
1581 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1583 for (
const auto P :
M.getSourceFileName())
1592 for (
const GlobalVariable &GV :
M.globals()) {
1593 unsigned AbbrevToUse = 0;
1599 Vals.
push_back(addToStrtab(GV.getName()));
1602 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1606 Vals.
push_back(getEncodedAlign(GV.getAlign()));
1607 Vals.
push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1609 if (GV.isThreadLocal() ||
1611 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1612 GV.isExternallyInitialized() ||
1614 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1615 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1619 Vals.
push_back(GV.isExternallyInitialized());
1623 auto AL = GV.getAttributesAsList(AttributeList::FunctionIndex);
1627 Vals.
push_back(addToStrtab(GV.getPartition()));
1628 Vals.
push_back(GV.getPartition().size());
1631 GV.getSanitizerMetadata())
1635 AbbrevToUse = SimpleGVarAbbrev;
1643 for (
const Function &
F : M) {
1655 Vals.
push_back(getEncodedAlign(
F.getAlign()));
1656 Vals.
push_back(
F.hasSection() ? SectionMap[std::string(
F.getSection())]
1668 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1672 Vals.
push_back(addToStrtab(
F.getPartition()));
1675 unsigned AbbrevToUse = 0;
1681 for (
const GlobalAlias &
A :
M.aliases()) {
1688 Vals.
push_back(
A.getType()->getAddressSpace());
1696 Vals.
push_back(addToStrtab(
A.getPartition()));
1699 unsigned AbbrevToUse = 0;
1705 for (
const GlobalIFunc &
I :
M.ifuncs()) {
1711 Vals.
push_back(
I.getType()->getAddressSpace());
1716 Vals.
push_back(addToStrtab(
I.getPartition()));
1722 writeValueSymbolTableForwardDecl();
1729 if (OBO->hasNoSignedWrap())
1731 if (OBO->hasNoUnsignedWrap())
1737 if (PDI->isDisjoint())
1740 if (FPMO->hasAllowReassoc())
1742 if (FPMO->hasNoNaNs())
1744 if (FPMO->hasNoInfs())
1746 if (FPMO->hasNoSignedZeros())
1748 if (FPMO->hasAllowReciprocal())
1750 if (FPMO->hasAllowContract())
1752 if (FPMO->hasApproxFunc())
1755 if (NNI->hasNonNeg())
1758 if (TI->hasNoSignedWrap())
1760 if (TI->hasNoUnsignedWrap())
1763 if (
GEP->isInBounds())
1765 if (
GEP->hasNoUnsignedSignedWrap())
1767 if (
GEP->hasNoUnsignedWrap())
1770 if (ICmp->hasSameSign())
1777void ModuleBitcodeWriter::writeValueAsMetadata(
1778 const ValueAsMetadata *MD, SmallVectorImpl<uint64_t> &Record) {
1787void ModuleBitcodeWriter::writeMDTuple(
const MDTuple *
N,
1788 SmallVectorImpl<uint64_t> &Record,
1790 for (
const MDOperand &MDO :
N->operands()) {
1793 "Unexpected function-local metadata");
1802unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1805 auto Abbv = std::make_shared<BitCodeAbbrev>();
1818void ModuleBitcodeWriter::writeDILocation(
const DILocation *
N,
1819 SmallVectorImpl<uint64_t> &Record,
1822 Abbrev = createDILocationAbbrev();
1836unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1839 auto Abbv = std::make_shared<BitCodeAbbrev>();
1850void ModuleBitcodeWriter::writeGenericDINode(
const GenericDINode *
N,
1851 SmallVectorImpl<uint64_t> &Record,
1854 Abbrev = createGenericDINodeAbbrev();
1860 for (
auto &
I :
N->operands())
1867void ModuleBitcodeWriter::writeDISubrange(
const DISubrange *
N,
1868 SmallVectorImpl<uint64_t> &Record,
1870 const uint64_t
Version = 2 << 1;
1881void ModuleBitcodeWriter::writeDIGenericSubrange(
1882 const DIGenericSubrange *
N, SmallVectorImpl<uint64_t> &Record,
1894void ModuleBitcodeWriter::writeDIEnumerator(
const DIEnumerator *
N,
1895 SmallVectorImpl<uint64_t> &Record,
1897 const uint64_t IsBigInt = 1 << 2;
1898 Record.
push_back(IsBigInt | (
N->isUnsigned() << 1) |
N->isDistinct());
1899 Record.
push_back(
N->getValue().getBitWidth());
1907void ModuleBitcodeWriter::writeDIBasicType(
const DIBasicType *
N,
1908 SmallVectorImpl<uint64_t> &Record,
1910 const unsigned SizeIsMetadata = 0x2;
1911 Record.
push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1918 Record.
push_back(
N->getNumExtraInhabitants());
1924void ModuleBitcodeWriter::writeDIFixedPointType(
1925 const DIFixedPointType *
N, SmallVectorImpl<uint64_t> &Record,
1927 const unsigned SizeIsMetadata = 0x2;
1928 Record.
push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1938 auto WriteWideInt = [&](
const APInt &
Value) {
1941 uint64_t NumWords =
Value.getActiveWords();
1942 uint64_t
Encoded = (NumWords << 32) |
Value.getBitWidth();
1947 WriteWideInt(
N->getNumeratorRaw());
1948 WriteWideInt(
N->getDenominatorRaw());
1954void ModuleBitcodeWriter::writeDIStringType(
const DIStringType *
N,
1955 SmallVectorImpl<uint64_t> &Record,
1957 const unsigned SizeIsMetadata = 0x2;
1958 Record.
push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1972void ModuleBitcodeWriter::writeDIDerivedType(
const DIDerivedType *
N,
1973 SmallVectorImpl<uint64_t> &Record,
1975 const unsigned SizeIsMetadata = 0x2;
1976 Record.
push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1991 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
1992 Record.
push_back(*DWARFAddressSpace + 1);
1998 if (
auto PtrAuthData =
N->getPtrAuthData())
2007void ModuleBitcodeWriter::writeDISubrangeType(
const DISubrangeType *
N,
2008 SmallVectorImpl<uint64_t> &Record,
2010 const unsigned SizeIsMetadata = 0x2;
2011 Record.
push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2029void ModuleBitcodeWriter::writeDICompositeType(
2030 const DICompositeType *
N, SmallVectorImpl<uint64_t> &Record,
2032 const unsigned IsNotUsedInOldTypeRef = 0x2;
2033 const unsigned SizeIsMetadata = 0x4;
2034 Record.
push_back(SizeIsMetadata | IsNotUsedInOldTypeRef |
2035 (
unsigned)
N->isDistinct());
2057 Record.
push_back(
N->getNumExtraInhabitants());
2067void ModuleBitcodeWriter::writeDISubroutineType(
2068 const DISubroutineType *
N, SmallVectorImpl<uint64_t> &Record,
2070 const unsigned HasNoOldTypeRefs = 0x2;
2071 Record.
push_back(HasNoOldTypeRefs | (
unsigned)
N->isDistinct());
2080void ModuleBitcodeWriter::writeDIFile(
const DIFile *
N,
2081 SmallVectorImpl<uint64_t> &Record,
2086 if (
N->getRawChecksum()) {
2095 auto Source =
N->getRawSource();
2103void ModuleBitcodeWriter::writeDICompileUnit(
const DICompileUnit *
N,
2104 SmallVectorImpl<uint64_t> &Record,
2106 assert(
N->isDistinct() &&
"Expected distinct compile units");
2123 Record.
push_back(
N->getSplitDebugInlining());
2124 Record.
push_back(
N->getDebugInfoForProfiling());
2125 Record.
push_back((
unsigned)
N->getNameTableKind());
2134void ModuleBitcodeWriter::writeDISubprogram(
const DISubprogram *
N,
2135 SmallVectorImpl<uint64_t> &Record,
2137 const uint64_t HasUnitFlag = 1 << 1;
2138 const uint64_t HasSPFlagsFlag = 1 << 2;
2139 Record.
push_back(uint64_t(
N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
2159 Record.
push_back(
N->getKeyInstructionsEnabled());
2165void ModuleBitcodeWriter::writeDILexicalBlock(
const DILexicalBlock *
N,
2166 SmallVectorImpl<uint64_t> &Record,
2178void ModuleBitcodeWriter::writeDILexicalBlockFile(
2179 const DILexicalBlockFile *
N, SmallVectorImpl<uint64_t> &Record,
2190void ModuleBitcodeWriter::writeDICommonBlock(
const DICommonBlock *
N,
2191 SmallVectorImpl<uint64_t> &Record,
2204void ModuleBitcodeWriter::writeDINamespace(
const DINamespace *
N,
2205 SmallVectorImpl<uint64_t> &Record,
2207 Record.
push_back(
N->isDistinct() |
N->getExportSymbols() << 1);
2215void ModuleBitcodeWriter::writeDIMacro(
const DIMacro *
N,
2216 SmallVectorImpl<uint64_t> &Record,
2228void ModuleBitcodeWriter::writeDIMacroFile(
const DIMacroFile *
N,
2229 SmallVectorImpl<uint64_t> &Record,
2241void ModuleBitcodeWriter::writeDIArgList(
const DIArgList *
N,
2242 SmallVectorImpl<uint64_t> &Record) {
2243 Record.
reserve(
N->getArgs().size());
2244 for (ValueAsMetadata *MD :
N->getArgs())
2251void ModuleBitcodeWriter::writeDIModule(
const DIModule *
N,
2252 SmallVectorImpl<uint64_t> &Record,
2255 for (
auto &
I :
N->operands())
2264void ModuleBitcodeWriter::writeDIAssignID(
const DIAssignID *
N,
2265 SmallVectorImpl<uint64_t> &Record,
2273void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2274 const DITemplateTypeParameter *
N, SmallVectorImpl<uint64_t> &Record,
2285void ModuleBitcodeWriter::writeDITemplateValueParameter(
2286 const DITemplateValueParameter *
N, SmallVectorImpl<uint64_t> &Record,
2299void ModuleBitcodeWriter::writeDIGlobalVariable(
2300 const DIGlobalVariable *
N, SmallVectorImpl<uint64_t> &Record,
2302 const uint64_t
Version = 2 << 1;
2321void ModuleBitcodeWriter::writeDILocalVariable(
2322 const DILocalVariable *
N, SmallVectorImpl<uint64_t> &Record,
2337 const uint64_t HasAlignmentFlag = 1 << 1;
2338 Record.
push_back((uint64_t)
N->isDistinct() | HasAlignmentFlag);
2353void ModuleBitcodeWriter::writeDILabel(
2354 const DILabel *
N, SmallVectorImpl<uint64_t> &Record,
2356 uint64_t IsArtificialFlag = uint64_t(
N->isArtificial()) << 1;
2357 Record.
push_back((uint64_t)
N->isDistinct() | IsArtificialFlag);
2363 Record.
push_back(
N->getCoroSuspendIdx().has_value()
2364 ? (uint64_t)
N->getCoroSuspendIdx().value()
2365 : std::numeric_limits<uint64_t>::max());
2371void ModuleBitcodeWriter::writeDIExpression(
const DIExpression *
N,
2372 SmallVectorImpl<uint64_t> &Record,
2374 Record.
reserve(
N->getElements().size() + 1);
2375 const uint64_t
Version = 3 << 1;
2377 Record.
append(
N->elements_begin(),
N->elements_end());
2383void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2384 const DIGlobalVariableExpression *
N, SmallVectorImpl<uint64_t> &Record,
2394void ModuleBitcodeWriter::writeDIObjCProperty(
const DIObjCProperty *
N,
2395 SmallVectorImpl<uint64_t> &Record,
2410void ModuleBitcodeWriter::writeDIImportedEntity(
2411 const DIImportedEntity *
N, SmallVectorImpl<uint64_t> &Record,
2426unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2427 auto Abbv = std::make_shared<BitCodeAbbrev>();
2434void ModuleBitcodeWriter::writeNamedMetadata(
2435 SmallVectorImpl<uint64_t> &Record) {
2436 if (
M.named_metadata_empty())
2439 unsigned Abbrev = createNamedMetadataAbbrev();
2440 for (
const NamedMDNode &NMD :
M.named_metadata()) {
2442 StringRef Str = NMD.getName();
2443 Record.
append(Str.bytes_begin(), Str.bytes_end());
2448 for (
const MDNode *
N : NMD.operands())
2455unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2456 auto Abbv = std::make_shared<BitCodeAbbrev>();
2468void ModuleBitcodeWriter::writeMetadataStrings(
2470 if (Strings.
empty())
2478 SmallString<256> Blob;
2480 BitstreamWriter
W(Blob);
2500#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
2501#include "llvm/IR/Metadata.def"
2505void ModuleBitcodeWriter::writeMetadataRecords(
2507 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2512#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
2513#include "llvm/IR/Metadata.def"
2519 assert(
N->isResolved() &&
"Expected forward references to be resolved");
2521 switch (
N->getMetadataID()) {
2524#define HANDLE_MDNODE_LEAF(CLASS) \
2525 case Metadata::CLASS##Kind: \
2527 write##CLASS(cast<CLASS>(N), Record, \
2528 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
2530 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
2532#include "llvm/IR/Metadata.def"
2543void ModuleBitcodeWriter::writeModuleMetadata() {
2544 if (!VE.
hasMDs() &&
M.named_metadata_empty())
2548 SmallVector<uint64_t, 64> Record;
2552 std::vector<unsigned> MDAbbrevs;
2555 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2556 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2557 createGenericDINodeAbbrev();
2559 auto Abbv = std::make_shared<BitCodeAbbrev>();
2563 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2565 Abbv = std::make_shared<BitCodeAbbrev>();
2569 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2581 uint64_t Vals[] = {0, 0};
2591 std::vector<uint64_t> IndexPos;
2595 writeMetadataRecords(VE.
getNonMDStrings(), Record, &MDAbbrevs, &IndexPos);
2606 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2607 for (
auto &Elt : IndexPos) {
2608 auto EltDelta = Elt - PreviousValue;
2609 PreviousValue = Elt;
2618 writeNamedMetadata(Record);
2620 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2621 SmallVector<uint64_t, 4> Record;
2623 pushGlobalMetadataAttachment(Record, GO);
2626 for (
const Function &
F : M)
2627 if (
F.isDeclaration() &&
F.hasMetadata())
2628 AddDeclAttachedMetadata(
F);
2629 for (
const GlobalIFunc &GI :
M.ifuncs())
2630 if (GI.hasMetadata())
2631 AddDeclAttachedMetadata(GI);
2634 for (
const GlobalVariable &GV :
M.globals())
2635 if (GV.hasMetadata())
2636 AddDeclAttachedMetadata(GV);
2641void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2646 SmallVector<uint64_t, 64> Record;
2652void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2653 SmallVectorImpl<uint64_t> &Record,
const GlobalObject &GO) {
2657 for (
const auto &
I : MDs) {
2663void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &
F) {
2666 SmallVector<uint64_t, 64> Record;
2668 if (
F.hasMetadata()) {
2669 pushGlobalMetadataAttachment(Record,
F);
2677 for (
const BasicBlock &BB :
F)
2678 for (
const Instruction &
I : BB) {
2680 I.getAllMetadataOtherThanDebugLoc(MDs);
2683 if (MDs.
empty())
continue;
2687 for (
const auto &[
ID, MD] : MDs) {
2698void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2699 SmallVector<uint64_t, 64> Record;
2704 M.getMDKindNames(Names);
2706 if (Names.
empty())
return;
2710 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2712 StringRef KName = Names[MDKindID];
2722void ModuleBitcodeWriter::writeOperandBundleTags() {
2730 M.getOperandBundleTags(Tags);
2737 SmallVector<uint64_t, 64> Record;
2739 for (
auto Tag : Tags) {
2749void ModuleBitcodeWriter::writeSyncScopeNames() {
2751 M.getContext().getSyncScopeNames(SSNs);
2757 SmallVector<uint64_t, 64> Record;
2758 for (
auto SSN : SSNs) {
2759 Record.
append(SSN.begin(), SSN.end());
2767void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2769 if (FirstVal == LastVal)
return;
2773 unsigned AggregateAbbrev = 0;
2774 unsigned String8Abbrev = 0;
2775 unsigned CString7Abbrev = 0;
2776 unsigned CString6Abbrev = 0;
2780 auto Abbv = std::make_shared<BitCodeAbbrev>();
2784 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2787 Abbv = std::make_shared<BitCodeAbbrev>();
2791 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2793 Abbv = std::make_shared<BitCodeAbbrev>();
2797 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2799 Abbv = std::make_shared<BitCodeAbbrev>();
2803 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2806 SmallVector<uint64_t, 64> Record;
2809 Type *LastTy =
nullptr;
2810 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2811 const Value *
V = Vals[i].first;
2813 if (
V->getType() != LastTy) {
2814 LastTy =
V->getType();
2817 CONSTANTS_SETTYPE_ABBREV);
2824 unsigned(
IA->hasSideEffects()) |
unsigned(
IA->isAlignStack()) << 1 |
2825 unsigned(
IA->getDialect() & 1) << 2 |
unsigned(
IA->canThrow()) << 3);
2828 StringRef AsmStr =
IA->getAsmString();
2833 StringRef ConstraintStr =
IA->getConstraintString();
2841 unsigned Code = -1U;
2842 unsigned AbbrevToUse = 0;
2843 if (
C->isNullValue()) {
2850 if (
IV->getBitWidth() <= 64) {
2851 uint64_t
V =
IV->getSExtValue();
2854 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2864 Record.
push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2868 APInt api = CFP->getValueAPF().bitcastToAPInt();
2870 Record.
push_back((p[1] << 48) | (p[0] >> 16));
2873 APInt api = CFP->getValueAPF().bitcastToAPInt();
2878 assert(0 &&
"Unknown FP type!");
2884 uint64_t NumElts = Str->getNumElements();
2886 if (Str->isCString()) {
2891 AbbrevToUse = String8Abbrev;
2895 for (uint64_t i = 0; i != NumElts; ++i) {
2896 unsigned char V = Str->getElementAsInteger(i);
2898 isCStr7 &= (
V & 128) == 0;
2904 AbbrevToUse = CString6Abbrev;
2906 AbbrevToUse = CString7Abbrev;
2907 }
else if (
const ConstantDataSequential *CDS =
2910 Type *EltTy = CDS->getElementType();
2912 for (uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
2913 Record.
push_back(CDS->getElementAsInteger(i));
2915 for (uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
2917 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2921 for (
const Value *
Op :
C->operands())
2923 AbbrevToUse = AggregateAbbrev;
2925 switch (
CE->getOpcode()) {
2932 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2934 assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2944 case Instruction::FNeg: {
2945 assert(
CE->getNumOperands() == 1 &&
"Unknown constant expr!");
2954 case Instruction::GetElementPtr: {
2959 if (std::optional<ConstantRange>
Range = GO->getInRange()) {
2963 for (
const Value *
Op :
CE->operands()) {
2969 case Instruction::ExtractElement:
2976 case Instruction::InsertElement:
2983 case Instruction::ShuffleVector:
2988 if (
C->getType() ==
C->getOperand(0)->getType()) {
3024 Stream.
EmitRecord(Code, Record, AbbrevToUse);
3031void ModuleBitcodeWriter::writeModuleConstants() {
3036 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
3038 writeConstants(i, Vals.size(),
true);
3052bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
3053 SmallVectorImpl<unsigned> &Vals) {
3057 if (ValID >= InstID) {
3064bool ModuleBitcodeWriter::pushValueOrMetadata(
const Value *V,
unsigned InstID,
3065 SmallVectorImpl<unsigned> &Vals) {
3066 bool IsMetadata =
V->getType()->isMetadataTy();
3074 return pushValueAndType(V, InstID, Vals);
3077void ModuleBitcodeWriter::writeOperandBundles(
const CallBase &CS,
3084 Record.
push_back(
C.getOperandBundleTagID(Bundle.getTagName()));
3086 for (
auto &Input : Bundle.Inputs)
3087 pushValueOrMetadata(Input, InstID, Record);
3096void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
3097 SmallVectorImpl<unsigned> &Vals) {
3102void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
3103 SmallVectorImpl<uint64_t> &Vals) {
3105 int64_t diff = ((int32_t)InstID - (int32_t)ValID);
3110void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
3112 SmallVectorImpl<unsigned> &Vals) {
3114 unsigned AbbrevToUse = 0;
3116 switch (
I.getOpcode()) {
3120 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3121 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
3126 if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
3127 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
3133 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3134 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
3135 pushValue(
I.getOperand(1), InstID, Vals);
3139 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
3140 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
3145 case Instruction::FNeg: {
3147 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3148 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
3152 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
3153 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
3158 case Instruction::GetElementPtr: {
3160 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
3164 for (
const Value *
Op :
I.operands())
3165 pushValueAndType(
Op, InstID, Vals);
3168 case Instruction::ExtractValue: {
3170 pushValueAndType(
I.getOperand(0), InstID, Vals);
3175 case Instruction::InsertValue: {
3177 pushValueAndType(
I.getOperand(0), InstID, Vals);
3178 pushValueAndType(
I.getOperand(1), InstID, Vals);
3183 case Instruction::Select: {
3185 pushValueAndType(
I.getOperand(1), InstID, Vals);
3186 pushValue(
I.getOperand(2), InstID, Vals);
3187 pushValueAndType(
I.getOperand(0), InstID, Vals);
3193 case Instruction::ExtractElement:
3195 pushValueAndType(
I.getOperand(0), InstID, Vals);
3196 pushValueAndType(
I.getOperand(1), InstID, Vals);
3198 case Instruction::InsertElement:
3200 pushValueAndType(
I.getOperand(0), InstID, Vals);
3201 pushValue(
I.getOperand(1), InstID, Vals);
3202 pushValueAndType(
I.getOperand(2), InstID, Vals);
3204 case Instruction::ShuffleVector:
3206 pushValueAndType(
I.getOperand(0), InstID, Vals);
3207 pushValue(
I.getOperand(1), InstID, Vals);
3211 case Instruction::ICmp:
3212 case Instruction::FCmp: {
3215 AbbrevToUse = FUNCTION_INST_CMP_ABBREV;
3216 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3218 pushValue(
I.getOperand(1), InstID, Vals);
3224 AbbrevToUse = FUNCTION_INST_CMP_FLAGS_ABBREV;
3229 case Instruction::Ret:
3232 unsigned NumOperands =
I.getNumOperands();
3233 if (NumOperands == 0)
3234 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
3235 else if (NumOperands == 1) {
3236 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3237 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
3239 for (
const Value *
Op :
I.operands())
3240 pushValueAndType(
Op, InstID, Vals);
3244 case Instruction::Br:
3247 AbbrevToUse = FUNCTION_INST_BR_UNCOND_ABBREV;
3250 if (
II.isConditional()) {
3252 pushValue(
II.getCondition(), InstID, Vals);
3253 AbbrevToUse = FUNCTION_INST_BR_COND_ABBREV;
3257 case Instruction::Switch:
3262 pushValue(
SI.getCondition(), InstID, Vals);
3264 for (
auto Case :
SI.cases()) {
3270 case Instruction::IndirectBr:
3274 pushValue(
I.getOperand(0), InstID, Vals);
3279 case Instruction::Invoke: {
3282 FunctionType *FTy =
II->getFunctionType();
3284 if (
II->hasOperandBundles())
3285 writeOperandBundles(*
II, InstID);
3294 pushValueAndType(Callee, InstID, Vals);
3297 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3298 pushValue(
I.getOperand(i), InstID, Vals);
3301 if (FTy->isVarArg()) {
3302 for (
unsigned i = FTy->getNumParams(), e =
II->arg_size(); i != e; ++i)
3303 pushValueAndType(
I.getOperand(i), InstID, Vals);
3307 case Instruction::Resume:
3309 pushValueAndType(
I.getOperand(0), InstID, Vals);
3311 case Instruction::CleanupRet: {
3314 pushValue(CRI.getCleanupPad(), InstID, Vals);
3315 if (CRI.hasUnwindDest())
3319 case Instruction::CatchRet: {
3322 pushValue(CRI.getCatchPad(), InstID, Vals);
3326 case Instruction::CleanupPad:
3327 case Instruction::CatchPad: {
3331 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3333 unsigned NumArgOperands = FuncletPad.arg_size();
3335 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
3336 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
3339 case Instruction::CatchSwitch: {
3343 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3345 unsigned NumHandlers = CatchSwitch.getNumHandlers();
3347 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
3350 if (CatchSwitch.hasUnwindDest())
3354 case Instruction::CallBr: {
3360 writeOperandBundles(*CBI, InstID);
3375 pushValueAndType(Callee, InstID, Vals);
3378 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3379 pushValue(
I.getOperand(i), InstID, Vals);
3382 if (FTy->isVarArg()) {
3383 for (
unsigned i = FTy->getNumParams(), e = CBI->
arg_size(); i != e; ++i)
3384 pushValueAndType(
I.getOperand(i), InstID, Vals);
3388 case Instruction::Unreachable:
3390 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3393 case Instruction::PHI: {
3411 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
3416 case Instruction::LandingPad: {
3427 pushValueAndType(LP.
getClause(
I), InstID, Vals);
3432 case Instruction::Alloca: {
3438 using APV = AllocaPackedValues;
3439 unsigned Record = 0;
3440 unsigned EncodedAlign = getEncodedAlign(AI.
getAlign());
3442 Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3444 EncodedAlign >> APV::AlignLower::Bits);
3451 if (AS !=
M.getDataLayout().getAllocaAddrSpace())
3456 case Instruction::Load:
3459 pushValueAndType(
I.getOperand(0), InstID, Vals);
3462 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3463 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3473 case Instruction::Store:
3478 AbbrevToUse = FUNCTION_INST_STORE_ABBREV;
3480 if (pushValueAndType(
I.getOperand(1), InstID, Vals))
3482 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3492 case Instruction::AtomicCmpXchg:
3494 pushValueAndType(
I.getOperand(0), InstID, Vals);
3495 pushValueAndType(
I.getOperand(1), InstID, Vals);
3496 pushValue(
I.getOperand(2), InstID, Vals);
3507 case Instruction::AtomicRMW:
3509 pushValueAndType(
I.getOperand(0), InstID, Vals);
3510 pushValueAndType(
I.getOperand(1), InstID, Vals);
3519 case Instruction::Fence:
3524 case Instruction::Call: {
3529 writeOperandBundles(CI, InstID);
3549 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3553 if (FTy->isVarArg()) {
3554 for (
unsigned i = FTy->getNumParams(), e = CI.
arg_size(); i != e; ++i)
3559 case Instruction::VAArg:
3562 pushValue(
I.getOperand(0), InstID, Vals);
3565 case Instruction::Freeze:
3567 pushValueAndType(
I.getOperand(0), InstID, Vals);
3577void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3578 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3583 VSTOffset -= bitcodeStartBit();
3584 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
3588 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3592 auto Abbv = std::make_shared<BitCodeAbbrev>();
3596 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3598 for (
const Function &
F : M) {
3601 if (
F.isDeclaration())
3608 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
3609 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
3613 Record[1] = BitcodeIndex / 32 + 1;
3622void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3623 const ValueSymbolTable &VST) {
3631 SmallVector<uint64_t, 64> NameVals;
3637 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3646 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3650 AbbrevToUse = VST_ENTRY_6_ABBREV;
3652 AbbrevToUse = VST_ENTRY_7_ABBREV;
3655 for (
const auto P :
Name.getKey())
3659 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3666void ModuleBitcodeWriter::writeUseList(UseListOrder &&Order) {
3667 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3674 SmallVector<uint64_t, 64> Record(Order.Shuffle.begin(), Order.Shuffle.end());
3679void ModuleBitcodeWriter::writeUseListBlock(
const Function *
F) {
3681 "Expected to be preserving use-list order");
3683 auto hasMore = [&]() {
3699void ModuleBitcodeWriter::writeFunction(
3701 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3718 unsigned CstStart, CstEnd;
3720 writeConstants(CstStart, CstEnd,
false);
3723 writeFunctionMetadata(
F);
3726 unsigned InstID = CstEnd;
3728 bool NeedsMetadataAttachment =
F.hasMetadata();
3730 DILocation *LastDL =
nullptr;
3731 SmallSetVector<Function *, 4> BlockAddressUsers;
3734 for (
const BasicBlock &BB :
F) {
3735 for (
const Instruction &
I : BB) {
3736 writeInstruction(
I, InstID, Vals);
3738 if (!
I.getType()->isVoidTy())
3742 NeedsMetadataAttachment |=
I.hasMetadataOtherThanDebugLoc();
3745 if (DILocation *
DL =
I.getDebugLoc()) {
3758 FUNCTION_DEBUG_LOC_ABBREV);
3768 if (
I.hasDbgRecords()) {
3772 auto PushValueOrMetadata = [&Vals, InstID,
3775 "RawLocation unexpectedly null in DbgVariableRecord");
3777 SmallVector<unsigned, 2> ValAndType;
3781 if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
3795 for (DbgRecord &DR :
I.DebugMarker->getDbgRecordRange()) {
3821 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3842 SmallPtrSet<Value *, 8> Visited{BA};
3843 while (!Worklist.
empty()) {
3845 for (User *U :
V->users()) {
3851 Visited.
insert(U).second)
3858 if (!BlockAddressUsers.
empty()) {
3867 if (
auto *Symtab =
F.getValueSymbolTable())
3868 writeFunctionLevelValueSymbolTable(*Symtab);
3870 if (NeedsMetadataAttachment)
3871 writeFunctionMetadataAttachment(
F);
3873 writeUseListBlock(&
F);
3879void ModuleBitcodeWriter::writeBlockInfo() {
3892 auto Abbv = std::make_shared<BitCodeAbbrev>();
3903 auto Abbv = std::make_shared<BitCodeAbbrev>();
3913 auto Abbv = std::make_shared<BitCodeAbbrev>();
3923 auto Abbv = std::make_shared<BitCodeAbbrev>();
3929 VST_BBENTRY_6_ABBREV)
3934 auto Abbv = std::make_shared<BitCodeAbbrev>();
3936 Abbv->Add(TypeAbbrevOp);
3938 CONSTANTS_SETTYPE_ABBREV)
3943 auto Abbv = std::make_shared<BitCodeAbbrev>();
3947 CONSTANTS_INTEGER_ABBREV)
3952 auto Abbv = std::make_shared<BitCodeAbbrev>();
3960 CONSTANTS_CE_CAST_Abbrev)
3964 auto Abbv = std::make_shared<BitCodeAbbrev>();
3967 CONSTANTS_NULL_Abbrev)
3974 auto Abbv = std::make_shared<BitCodeAbbrev>();
3976 Abbv->Add(ValAbbrevOp);
3977 Abbv->Add(TypeAbbrevOp);
3981 FUNCTION_INST_LOAD_ABBREV)
3985 auto Abbv = std::make_shared<BitCodeAbbrev>();
3987 Abbv->Add(ValAbbrevOp);
3988 Abbv->Add(ValAbbrevOp);
3992 FUNCTION_INST_STORE_ABBREV)
3996 auto Abbv = std::make_shared<BitCodeAbbrev>();
3998 Abbv->Add(ValAbbrevOp);
4001 FUNCTION_INST_UNOP_ABBREV)
4005 auto Abbv = std::make_shared<BitCodeAbbrev>();
4007 Abbv->Add(ValAbbrevOp);
4011 FUNCTION_INST_UNOP_FLAGS_ABBREV)
4015 auto Abbv = std::make_shared<BitCodeAbbrev>();
4017 Abbv->Add(ValAbbrevOp);
4018 Abbv->Add(ValAbbrevOp);
4021 FUNCTION_INST_BINOP_ABBREV)
4025 auto Abbv = std::make_shared<BitCodeAbbrev>();
4027 Abbv->Add(ValAbbrevOp);
4028 Abbv->Add(ValAbbrevOp);
4032 FUNCTION_INST_BINOP_FLAGS_ABBREV)
4036 auto Abbv = std::make_shared<BitCodeAbbrev>();
4038 Abbv->Add(ValAbbrevOp);
4039 Abbv->Add(TypeAbbrevOp);
4042 FUNCTION_INST_CAST_ABBREV)
4046 auto Abbv = std::make_shared<BitCodeAbbrev>();
4048 Abbv->Add(ValAbbrevOp);
4049 Abbv->Add(TypeAbbrevOp);
4053 FUNCTION_INST_CAST_FLAGS_ABBREV)
4058 auto Abbv = std::make_shared<BitCodeAbbrev>();
4061 FUNCTION_INST_RET_VOID_ABBREV)
4065 auto Abbv = std::make_shared<BitCodeAbbrev>();
4067 Abbv->Add(ValAbbrevOp);
4069 FUNCTION_INST_RET_VAL_ABBREV)
4073 auto Abbv = std::make_shared<BitCodeAbbrev>();
4076 Abbv->Add(ValAbbrevOp);
4078 FUNCTION_INST_BR_UNCOND_ABBREV)
4082 auto Abbv = std::make_shared<BitCodeAbbrev>();
4085 Abbv->Add(ValAbbrevOp);
4086 Abbv->Add(ValAbbrevOp);
4087 Abbv->Add(ValAbbrevOp);
4089 FUNCTION_INST_BR_COND_ABBREV)
4093 auto Abbv = std::make_shared<BitCodeAbbrev>();
4096 FUNCTION_INST_UNREACHABLE_ABBREV)
4100 auto Abbv = std::make_shared<BitCodeAbbrev>();
4103 Abbv->Add(TypeAbbrevOp);
4105 Abbv->Add(ValAbbrevOp);
4107 FUNCTION_INST_GEP_ABBREV)
4111 auto Abbv = std::make_shared<BitCodeAbbrev>();
4113 Abbv->Add(ValAbbrevOp);
4114 Abbv->Add(ValAbbrevOp);
4117 FUNCTION_INST_CMP_ABBREV)
4121 auto Abbv = std::make_shared<BitCodeAbbrev>();
4123 Abbv->Add(ValAbbrevOp);
4124 Abbv->Add(ValAbbrevOp);
4128 FUNCTION_INST_CMP_FLAGS_ABBREV)
4132 auto Abbv = std::make_shared<BitCodeAbbrev>();
4137 Abbv->Add(ValAbbrevOp);
4139 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
4143 auto Abbv = std::make_shared<BitCodeAbbrev>();
4154 FUNCTION_DEBUG_LOC_ABBREV)
4162void IndexBitcodeWriter::writeModStrings() {
4168 auto Abbv = std::make_shared<BitCodeAbbrev>();
4173 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
4176 Abbv = std::make_shared<BitCodeAbbrev>();
4181 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
4184 Abbv = std::make_shared<BitCodeAbbrev>();
4189 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
4192 Abbv = std::make_shared<BitCodeAbbrev>();
4199 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
4202 forEachModule([&](
const StringMapEntry<ModuleHash> &MPSE) {
4204 const auto &Hash = MPSE.
getValue();
4206 unsigned AbbrevToUse = Abbrev8Bit;
4208 AbbrevToUse = Abbrev6Bit;
4210 AbbrevToUse = Abbrev7Bit;
4212 auto ModuleId = ModuleIdMap.
size();
4213 ModuleIdMap[
Key] = ModuleId;
4222 Vals.
assign(Hash.begin(), Hash.end());
4234template <
typename Fn>
4238 if (!FS->type_tests().empty())
4243 auto WriteVFuncIdVec = [&](
uint64_t Ty,
4248 for (
auto &VF : VFs) {
4249 Record.push_back(VF.GUID);
4250 Record.push_back(VF.Offset);
4256 FS->type_test_assume_vcalls());
4258 FS->type_checked_load_vcalls());
4260 auto WriteConstVCallVec = [&](
uint64_t Ty,
4262 for (
auto &VC : VCs) {
4264 Record.push_back(VC.VFunc.GUID);
4265 Record.push_back(VC.VFunc.Offset);
4272 FS->type_test_assume_const_vcalls());
4274 FS->type_checked_load_const_vcalls());
4284 if (!FS->paramAccesses().empty()) {
4286 for (
auto &Arg : FS->paramAccesses()) {
4287 size_t UndoSize =
Record.size();
4288 Record.push_back(Arg.ParamNo);
4289 WriteRange(Arg.Use);
4290 Record.push_back(Arg.Calls.size());
4291 for (
auto &
Call : Arg.Calls) {
4293 std::optional<unsigned> ValueID = GetValueID(
Call.Callee);
4300 Record.push_back(*ValueID);
4301 WriteRange(
Call.Offsets);
4312 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
4313 if (!FS->type_tests().empty())
4314 for (
auto &TT : FS->type_tests())
4315 ReferencedTypeIds.insert(TT);
4317 auto GetReferencedTypesFromVFuncIdVec =
4319 for (
auto &VF : VFs)
4320 ReferencedTypeIds.insert(VF.GUID);
4323 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4324 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4326 auto GetReferencedTypesFromConstVCallVec =
4328 for (
auto &VC : VCs)
4329 ReferencedTypeIds.insert(VC.VFunc.GUID);
4332 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4333 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
4369 NameVals.
push_back(Summary.TTRes.TheKind);
4370 NameVals.
push_back(Summary.TTRes.SizeM1BitWidth);
4371 NameVals.
push_back(Summary.TTRes.AlignLog2);
4372 NameVals.
push_back(Summary.TTRes.SizeM1);
4373 NameVals.
push_back(Summary.TTRes.BitMask);
4374 NameVals.
push_back(Summary.TTRes.InlineBits);
4376 for (
auto &W : Summary.WPDRes)
4388 for (
auto &
P : Summary) {
4390 NameVals.
push_back(
VE.getValueID(
P.VTableVI.getValue()));
4404 static_assert(std::is_same_v<LinearFrameId, unsigned>);
4405 for (
auto &AI : FS->allocs()) {
4406 for (
auto &MIB : AI.MIBs) {
4408 StackIdIndices.
reserve(MIB.StackIdIndices.size());
4409 for (
auto Id : MIB.StackIdIndices)
4410 StackIdIndices.
push_back(GetStackIndex(Id));
4412 CallStacks.insert({CallStacks.size(), StackIdIndices});
4425 assert(!CallStacks.empty());
4431 Builder.
build(std::move(CallStacks),
nullptr,
4435 return Builder.takeCallStackPos();
4440 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
bool PerModule,
4441 std::function<
unsigned(
const ValueInfo &VI)> GetValueID,
4442 std::function<
unsigned(
unsigned)> GetStackIndex,
4443 bool WriteContextSizeInfoIndex,
4448 for (
auto &CI : FS->callsites()) {
4452 assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4453 Record.push_back(GetValueID(CI.Callee));
4455 Record.push_back(CI.StackIdIndices.size());
4456 Record.push_back(CI.Clones.size());
4458 for (
auto Id : CI.StackIdIndices)
4459 Record.push_back(GetStackIndex(Id));
4467 for (
auto &AI : FS->allocs()) {
4471 assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4472 Record.push_back(AI.MIBs.size());
4474 Record.push_back(AI.Versions.size());
4475 for (
auto &MIB : AI.MIBs) {
4482 assert(CallStackCount <= CallStackPos.
size());
4483 Record.push_back(CallStackPos[CallStackCount++]);
4488 assert(AI.ContextSizeInfos.empty() ||
4489 AI.ContextSizeInfos.size() == AI.MIBs.size());
4491 if (WriteContextSizeInfoIndex && !AI.ContextSizeInfos.empty()) {
4499 ContextIds.
reserve(AI.ContextSizeInfos.size() * 2);
4500 for (
auto &Infos : AI.ContextSizeInfos) {
4501 Record.push_back(Infos.size());
4502 for (
auto [FullStackId, TotalSize] : Infos) {
4509 Record.push_back(TotalSize);
4527void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4528 SmallVector<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
4529 unsigned ValueID,
unsigned FSCallsRelBFAbbrev,
4530 unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
4531 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
const Function &
F,
4532 DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
4539 Stream, FS, [&](
const ValueInfo &VI) -> std::optional<unsigned> {
4544 Stream, FS, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
4546 [&](
const ValueInfo &VI) {
return getValueId(VI); },
4547 [&](
unsigned I) {
return I; },
4548 true, CallStackPos, CallStackCount);
4550 auto SpecialRefCnts =
FS->specialRefCounts();
4555 NameVals.
push_back(SpecialRefCnts.first);
4556 NameVals.
push_back(SpecialRefCnts.second);
4558 for (
auto &RI :
FS->refs())
4561 const bool UseRelBFRecord =
4564 for (
auto &ECI :
FS->calls()) {
4565 NameVals.
push_back(getValueId(ECI.first));
4573 (UseRelBFRecord ? FSCallsRelBFAbbrev : FSCallsProfileAbbrev);
4584void ModuleBitcodeWriterBase::writeModuleLevelReferences(
4585 const GlobalVariable &V, SmallVector<uint64_t, 64> &NameVals,
4586 unsigned FSModRefsAbbrev,
unsigned FSModVTableRefsAbbrev) {
4587 auto VI =
Index->getValueInfo(
V.getGUID());
4588 if (!VI ||
VI.getSummaryList().empty()) {
4594 auto *
Summary =
VI.getSummaryList()[0].get();
4600 auto VTableFuncs =
VS->vTableFuncs();
4601 if (!VTableFuncs.empty())
4604 unsigned SizeBeforeRefs = NameVals.
size();
4605 for (
auto &RI :
VS->refs())
4611 if (VTableFuncs.empty())
4616 for (
auto &
P : VTableFuncs) {
4622 FSModVTableRefsAbbrev);
4629void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
4632 bool IsThinLTO =
true;
4635 IsThinLTO = MD->getZExtValue();
4647 if (
Index->enableSplitLTOUnit())
4649 if (
Index->hasUnifiedLTO())
4659 auto Abbv = std::make_shared<BitCodeAbbrev>();
4665 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4667 for (
const auto &GVI : valueIds()) {
4669 ArrayRef<uint32_t>{GVI.second,
4670 static_cast<uint32_t
>(GVI.first >> 32),
4671 static_cast<uint32_t
>(GVI.first)},
4675 if (!
Index->stackIds().empty()) {
4676 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4683 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4684 SmallVector<uint32_t> Vals;
4686 for (
auto Id :
Index->stackIds()) {
4687 Vals.
push_back(
static_cast<uint32_t
>(Id >> 32));
4688 Vals.
push_back(
static_cast<uint32_t
>(Id));
4693 unsigned ContextIdAbbvId = 0;
4696 auto ContextIdAbbv = std::make_shared<BitCodeAbbrev>();
4708 ContextIdAbbvId = Stream.
EmitAbbrev(std::move(ContextIdAbbv));
4712 Abbv = std::make_shared<BitCodeAbbrev>();
4724 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4727 Abbv = std::make_shared<BitCodeAbbrev>();
4739 unsigned FSCallsRelBFAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4742 Abbv = std::make_shared<BitCodeAbbrev>();
4748 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4751 Abbv = std::make_shared<BitCodeAbbrev>();
4759 unsigned FSModVTableRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4762 Abbv = std::make_shared<BitCodeAbbrev>();
4767 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4770 Abbv = std::make_shared<BitCodeAbbrev>();
4777 unsigned TypeIdCompatibleVtableAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4779 Abbv = std::make_shared<BitCodeAbbrev>();
4785 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4787 Abbv = std::make_shared<BitCodeAbbrev>();
4794 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4796 Abbv = std::make_shared<BitCodeAbbrev>();
4801 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4808 MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
4809 for (
const Function &
F : M) {
4815 ValueInfo
VI =
Index->getValueInfo(
F.getGUID());
4816 if (!VI ||
VI.getSummaryList().empty()) {
4822 auto *
Summary =
VI.getSummaryList()[0].get();
4825 FS, [](
unsigned I) {
return I; }, CallStacks);
4829 DenseMap<CallStackId, LinearCallStackId> CallStackPos;
4830 if (!CallStacks.
empty()) {
4838 SmallVector<uint64_t, 64> NameVals;
4841 for (
const Function &
F : M) {
4847 ValueInfo
VI =
Index->getValueInfo(
F.getGUID());
4848 if (!VI ||
VI.getSummaryList().empty()) {
4854 auto *
Summary =
VI.getSummaryList()[0].get();
4855 writePerModuleFunctionSummaryRecord(
4856 NameVals, Summary, VE.
getValueID(&
F), FSCallsRelBFAbbrev,
4857 FSCallsProfileAbbrev, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
F,
4858 CallStackPos, CallStackCount);
4863 for (
const GlobalVariable &
G :
M.globals())
4864 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev,
4865 FSModVTableRefsAbbrev);
4867 for (
const GlobalAlias &
A :
M.aliases()) {
4868 auto *Aliasee =
A.getAliaseeObject();
4884 for (
auto &S :
Index->typeIdCompatibleVtableMap()) {
4888 TypeIdCompatibleVtableAbbrev);
4892 if (
Index->getBlockCount())
4894 ArrayRef<uint64_t>{
Index->getBlockCount()});
4900void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4909 auto Abbv = std::make_shared<BitCodeAbbrev>();
4915 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4917 for (
const auto &GVI : valueIds()) {
4919 ArrayRef<uint32_t>{GVI.second,
4920 static_cast<uint32_t
>(GVI.first >> 32),
4921 static_cast<uint32_t
>(GVI.first)},
4927 if (!StackIds.empty()) {
4928 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4935 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4936 SmallVector<uint32_t> Vals;
4937 Vals.
reserve(StackIds.size() * 2);
4938 for (
auto Id : StackIds) {
4939 Vals.
push_back(
static_cast<uint32_t
>(Id >> 32));
4940 Vals.
push_back(
static_cast<uint32_t
>(Id));
4946 Abbv = std::make_shared<BitCodeAbbrev>();
4960 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4963 Abbv = std::make_shared<BitCodeAbbrev>();
4970 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4973 Abbv = std::make_shared<BitCodeAbbrev>();
4979 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4981 Abbv = std::make_shared<BitCodeAbbrev>();
4989 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4991 Abbv = std::make_shared<BitCodeAbbrev>();
5002 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5004 auto shouldImportValueAsDecl = [&](GlobalValueSummary *GVS) ->
bool {
5005 if (DecSummaries ==
nullptr)
5007 return DecSummaries->count(GVS);
5015 DenseMap<const GlobalValueSummary *, unsigned> SummaryToValueIdMap;
5017 SmallVector<uint64_t, 64> NameVals;
5021 std::set<GlobalValue::GUID> ReferencedTypeIds;
5025 auto MaybeEmitOriginalName = [&](GlobalValueSummary &S) {
5035 NameVals.
push_back(S.getOriginalName());
5040 DenseMap<CallStackId, LinearCallStackId> CallStackPos;
5042 Abbv = std::make_shared<BitCodeAbbrev>();
5047 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5054 MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
5055 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5061 GlobalValueSummary *S =
I.second;
5074 return StackIdIndicesToIndex[
I];
5080 if (!CallStacks.
empty()) {
5090 DenseSet<GlobalValue::GUID> DefOrUseGUIDs;
5091 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5092 GlobalValueSummary *S =
I.second;
5094 DefOrUseGUIDs.
insert(
I.first);
5095 for (
const ValueInfo &VI : S->
refs())
5096 DefOrUseGUIDs.
insert(
VI.getGUID());
5098 auto ValueId = getValueId(
I.first);
5100 SummaryToValueIdMap[S] = *ValueId;
5118 NameVals.
push_back(ModuleIdMap[
VS->modulePath()]);
5122 for (
auto &RI :
VS->refs()) {
5123 auto RefValueId = getValueId(RI.getGUID());
5133 MaybeEmitOriginalName(*S);
5137 auto GetValueId = [&](
const ValueInfo &
VI) -> std::optional<unsigned> {
5139 return std::nullopt;
5140 return getValueId(
VI.getGUID());
5148 Stream, FS, CallsiteAbbrev, AllocAbbrev, 0,
5151 [&](
const ValueInfo &VI) ->
unsigned {
5152 std::optional<unsigned> ValueID = GetValueId(VI);
5167 return StackIdIndicesToIndex[
I];
5169 false, CallStackPos, CallStackCount);
5173 NameVals.
push_back(ModuleIdMap[
FS->modulePath()]);
5186 unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
5187 for (
auto &RI :
FS->refs()) {
5188 auto RefValueId = getValueId(RI.getGUID());
5192 if (RI.isReadOnly())
5194 else if (RI.isWriteOnly())
5198 NameVals[6] =
Count;
5199 NameVals[7] = RORefCnt;
5200 NameVals[8] = WORefCnt;
5202 for (
auto &EI :
FS->calls()) {
5205 std::optional<unsigned> CallValueId = GetValueId(EI.first);
5214 FSCallsProfileAbbrev);
5216 MaybeEmitOriginalName(*S);
5219 for (
auto *AS : Aliases) {
5220 auto AliasValueId = SummaryToValueIdMap[AS];
5227 auto AliaseeValueId = SummaryToValueIdMap[&AS->
getAliasee()];
5234 MaybeEmitOriginalName(*AS);
5241 auto EmitCfiFunctions = [&](
const CfiFunctionIndex &CfiIndex,
5243 if (CfiIndex.
empty())
5246 auto Defs = CfiIndex.
forGuid(GUID);
5249 if (Functions.
empty())
5252 for (
const auto &S : Functions) {
5266 for (
auto &
T : ReferencedTypeIds) {
5267 auto TidIter =
Index.typeIds().equal_range(
T);
5268 for (
const auto &[GUID, TypeIdPair] :
make_range(TidIter)) {
5276 if (
Index.getBlockCount())
5278 ArrayRef<uint64_t>{
Index.getBlockCount()});
5289 auto Abbv = std::make_shared<BitCodeAbbrev>();
5293 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5295 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
5298 Abbv = std::make_shared<BitCodeAbbrev>();
5301 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5307void ModuleBitcodeWriter::writeModuleHash(StringRef View) {
5312 Hasher.
update(ArrayRef<uint8_t>(
5313 reinterpret_cast<const uint8_t *
>(
View.data()),
View.size()));
5314 std::array<uint8_t, 20> Hash = Hasher.
result();
5315 for (
int Pos = 0; Pos < 20; Pos += 4) {
5328void ModuleBitcodeWriter::write() {
5336 writeModuleVersion();
5345 writeAttributeGroupTable();
5348 writeAttributeTable();
5357 writeModuleConstants();
5360 writeModuleMetadataKinds();
5363 writeModuleMetadata();
5367 writeUseListBlock(
nullptr);
5369 writeOperandBundleTags();
5370 writeSyncScopeNames();
5373 DenseMap<const Function *, uint64_t> FunctionToBitcodeIndex;
5374 for (
const Function &
F : M)
5375 if (!
F.isDeclaration())
5376 writeFunction(
F, FunctionToBitcodeIndex);
5381 writePerModuleGlobalValueSummary();
5383 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
5411 unsigned CPUType = ~0U;
5418 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
5419 DARWIN_CPU_TYPE_X86 = 7,
5420 DARWIN_CPU_TYPE_ARM = 12,
5421 DARWIN_CPU_TYPE_POWERPC = 18
5426 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
5428 CPUType = DARWIN_CPU_TYPE_X86;
5430 CPUType = DARWIN_CPU_TYPE_POWERPC;
5432 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
5434 CPUType = DARWIN_CPU_TYPE_ARM;
5438 "Expected header size to be reserved");
5443 unsigned Position = 0;
5451 while (Buffer.
size() & 15)
5458 Stream.
Emit((
unsigned)
'B', 8);
5459 Stream.
Emit((
unsigned)
'C', 8);
5460 Stream.
Emit(0x0, 4);
5461 Stream.
Emit(0xC, 4);
5462 Stream.
Emit(0xE, 4);
5463 Stream.
Emit(0xD, 4);
5481 auto Abbv = std::make_shared<BitCodeAbbrev>();
5484 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
5492 assert(!WroteStrtab && !WroteSymtab);
5498 if (M->getModuleInlineAsm().empty())
5502 const Triple TT(M->getTargetTriple());
5504 if (!
T || !
T->hasMCAsmParser())
5526 std::vector<char> Strtab;
5527 StrtabBuilder.finalizeInOrder();
5528 Strtab.resize(StrtabBuilder.getSize());
5529 StrtabBuilder.write((
uint8_t *)Strtab.data());
5532 {Strtab.data(), Strtab.size()});
5543 bool ShouldPreserveUseListOrder,
5552 assert(M.isMaterialized());
5553 Mods.push_back(
const_cast<Module *
>(&M));
5555 ModuleBitcodeWriter ModuleWriter(M, StrtabBuilder, *Stream,
5556 ShouldPreserveUseListOrder, Index,
5557 GenerateHash, ModHash);
5558 ModuleWriter.write();
5565 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, DecSummaries,
5566 ModuleToSummariesForIndex);
5567 IndexWriter.write();
5572 bool ShouldPreserveUseListOrder,
5576 Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
5578 Writer.writeSymtab();
5579 Writer.writeStrtab();
5581 Triple TT(M.getTargetTriple());
5582 if (TT.isOSDarwin() || TT.isOSBinFormatMachO()) {
5600void IndexBitcodeWriter::write() {
5603 writeModuleVersion();
5609 writeCombinedGlobalValueSummary();
5626 Writer.
writeIndex(&Index, ModuleToSummariesForIndex, DecSummaries);
5635class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
5645 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5647 ModHash(&ModHash) {}
5652 void writeSimplifiedModuleInfo();
5662void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5674 auto Abbv = std::make_shared<BitCodeAbbrev>();
5677 Abbv->Add(AbbrevOpToUse);
5678 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5680 for (
const auto P :
M.getSourceFileName())
5744void ThinLinkBitcodeWriter::write() {
5747 writeModuleVersion();
5749 writeSimplifiedModuleInfo();
5751 writePerModuleGlobalValueSummary();
5768 assert(M.isMaterialized());
5769 Mods.push_back(
const_cast<Module *
>(&M));
5771 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream, Index,
5773 ThinLinkWriter.write();
5794 switch (
T.getObjectFormat()) {
5796 return "__LLVM,__bitcode";
5821 switch (
T.getObjectFormat()) {
5823 return "__LLVM,__cmdline";
5849 const std::vector<uint8_t> &CmdArgs) {
5854 Type *UsedElementType = Used ? Used->getValueType()->getArrayElementType()
5856 for (
auto *GV : UsedGlobals) {
5857 if (GV->getName() !=
"llvm.embedded.module" &&
5858 GV->getName() !=
"llvm.cmdline")
5863 Used->eraseFromParent();
5868 Triple T(M.getTargetTriple());
5897 M.getGlobalVariable(
"llvm.embedded.module",
true)) {
5898 assert(Old->hasZeroLiveUses() &&
5899 "llvm.embedded.module can only be used once in llvm.compiler.used");
5901 Old->eraseFromParent();
5903 GV->
setName(
"llvm.embedded.module");
5921 assert(Old->hasZeroLiveUses() &&
5922 "llvm.cmdline can only be used once in llvm.compiler.used");
5924 Old->eraseFromParent();
5930 if (UsedArray.
empty())
5938 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 unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
static DenseMap< CallStackId, LinearCallStackId > writeMemoryProfileRadixTree(MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &&CallStacks, BitstreamWriter &Stream, unsigned RadixAbbrev)
static void writeIdentificationBlock(BitstreamWriter &Stream)
Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version,...
static unsigned getEncodedCastOpcode(unsigned Opcode)
static cl::opt< bool > WriteRelBFToSummary("write-relbf-to-summary", cl::Hidden, cl::init(false), cl::desc("Write relative block frequency to function summary "))
static cl::opt< uint32_t > FlushThreshold("bitcode-flush-threshold", cl::Hidden, cl::init(512), cl::desc("The threshold (unit M) for flushing LLVM bitcode."))
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
static unsigned getEncodedUnnamedAddr(const GlobalValue &GV)
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 uint64_t getEncodedRelBFCallEdgeInfo(const CalleeInfo &CI)
static void writeWholeProgramDevirtResolutionByArg(SmallVector< uint64_t, 64 > &NameVals, const std::vector< uint64_t > &args, const WholeProgramDevirtResolution::ByArg &ByArg)
static void emitConstantRange(SmallVectorImpl< uint64_t > &Record, const ConstantRange &CR, bool EmitBitWidth)
static StringEncoding getStringEncoding(StringRef Str)
Determine the encoding to use for the given string name and length.
static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags)
static const char * getSectionNameForCommandline(const Triple &T)
static cl::opt< unsigned > IndexThreshold("bitcode-mdindex-threshold", cl::Hidden, cl::init(25), cl::desc("Number of metadatas above which we emit an index " "to enable lazy-loading"))
static void writeTypeIdSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdSummary &Summary)
static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, FunctionSummary *FS, Fn GetValueID)
Write the function type metadata related records that need to appear before a function summary entry ...
static uint64_t getEncodedHotnessCallEdgeInfo(const CalleeInfo &CI)
static void emitWideAPInt(SmallVectorImpl< uint64_t > &Vals, const APInt &A)
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
static void writeWholeProgramDevirtResolution(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, uint64_t Id, const WholeProgramDevirtResolution &Wpd)
static unsigned getEncodedDLLStorageClass(const GlobalValue &GV)
static void writeInt32ToBuffer(uint32_t Value, SmallVectorImpl< char > &Buffer, uint32_t &Position)
static const char * getSectionNameForBitcode(const Triple &T)
static 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.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
Class to represent array types.
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ USubCond
Subtract only if no unsigned overflow.
@ 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
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
bool hasAttributes() const
Return true if attributes exists in this set.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
@ None
No attributes have been set.
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
@ EndAttrKinds
Sentinel value useful for loops.
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
LLVM_ABI void writeThinLinkBitcode(const Module &M, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the buffer specified...
LLVM_ABI void writeIndex(const ModuleSummaryIndex *Index, const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex, const GVSummaryPtrSet *DecSummaries)
LLVM_ABI void copyStrtab(StringRef Strtab)
Copy the string table for another module into this bitcode file.
LLVM_ABI void writeStrtab()
Write the bitcode file's string table.
LLVM_ABI ~BitcodeWriter()
LLVM_ABI void writeSymtab()
Attempt to write a symbol table to the bitcode file.
LLVM_ABI void writeModule(const Module &M, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the buffer specified at construction time.
LLVM_ABI BitcodeWriter(SmallVectorImpl< char > &Buffer)
Create a BitcodeWriter that writes to Buffer.
unsigned EmitAbbrev(std::shared_ptr< BitCodeAbbrev > Abbv)
Emits the abbreviation Abbv to the stream.
void markAndBlockFlushing()
For scenarios where the user wants to access a section of the stream to (for example) compute some ch...
StringRef getMarkedBufferAndResumeFlushing()
resumes flushing, but does not flush, and returns the section in the internal buffer starting from th...
void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev=0)
EmitRecord - Emit the specified record to the stream, using an abbrev if we have one to compress the ...
void Emit(uint32_t Val, unsigned NumBits)
void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals, StringRef Blob)
EmitRecordWithBlob - Emit the specified record to the stream, using an abbrev that includes a blob at...
unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr< BitCodeAbbrev > Abbv)
EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified BlockID.
void EnterBlockInfoBlock()
EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
void BackpatchWord(uint64_t BitNo, unsigned Val)
void BackpatchWord64(uint64_t BitNo, uint64_t Val)
void EnterSubblock(unsigned BlockID, unsigned CodeLen)
uint64_t GetCurrentBitNo() const
Retrieve the current position in the stream, in bits.
void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals)
EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
static LLVM_ABI BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
CallingConv::ID getCallingConv() const
Value * getCalledOperand() const
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
bool hasOperandBundles() const
Return true if this User has any operand bundles.
BasicBlock * getIndirectDest(unsigned i) const
BasicBlock * getDefaultDest() const
unsigned getNumIndirectDests() const
Return the number of callbr indirect dest labels.
bool isNoTailCall() const
bool isMustTailCall() const
iterator_range< NestedIterator > forGuid(GlobalValue::GUID GUID) const
@ Largest
The linker will choose the largest COMDAT.
@ SameSize
The data referenced by the COMDAT must be the same size.
@ Any
The linker may choose any COMDAT.
@ NoDeduplicate
No deduplication is performed.
@ ExactMatch
The data referenced by the COMDAT must be the same.
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
static LLVM_ABI Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
This class represents a range of values.
const APInt & getLower() const
Return the lower value for this range.
const APInt & getUpper() const
Return the upper value for this range.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
This is an important base class in LLVM.
DebugLoc getDebugLoc() const
LLVM_ABI DIAssignID * getAssignID() const
DIExpression * getExpression() const
DILocalVariable * getVariable() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
bool isDbgDeclare() const
Metadata * getRawAddress() const
DIExpression * getAddressExpression() const
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Lightweight error class with error context and mandatory checking.
Function summary information to aid decisions and implementation of importing.
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
LLVM_ABI void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
LLVM_ABI void setSection(StringRef S)
Change the section for this global.
GVFlags flags() const
Get the flags for this GlobalValue (see struct GVFlags).
StringRef modulePath() const
Get the path to the module containing this function.
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
VisibilityTypes getVisibility() const
static bool isLocalLinkage(LinkageTypes Linkage)
LinkageTypes getLinkage() const
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
ThreadLocalMode getThreadLocalMode() const
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ProtectedVisibility
The GV is protected.
UnnamedAddr getUnnamedAddr() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
DLLStorageClassTypes getDLLStorageClass() const
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalVariable.
idx_iterator idx_end() const
idx_iterator idx_begin() const
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
This class implements a map that also provides access to all stored values in a deterministic order.
size_t getBufferSize() const
const char * getBufferStart() const
const char * getBufferEnd() const
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static constexpr uint64_t BitcodeSummaryVersion
A Module instance is used to store all the information related to an LLVM module.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Digest more data.
LLVM_ABI std::array< uint8_t, 20 > result()
Return the current raw 160-bits SHA1 for the digested data since the last call to init().
size_type size() const
Determine the number of elements in the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void append(StringRef RHS)
Append from a StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
const ValueTy & getValue() const
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - 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.
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
std::pair< iterator, bool > insert(const ValueT &V)
void build(llvm::MapVector< CallStackId, llvm::SmallVector< FrameIdTy > > &&MemProfCallStackData, const llvm::DenseMap< FrameIdTy, LinearFrameId > *MemProfFrameIndexes, llvm::DenseMap< FrameIdTy, FrameStat > &FrameHistogram)
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an std::string.
std::string & str()
Returns the string's reference.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
@ CE
Windows NT (Windows on ARM)
@ TYPE_CODE_OPAQUE_POINTER
@ METADATA_TEMPLATE_VALUE
@ METADATA_LEXICAL_BLOCK_FILE
@ METADATA_SUBROUTINE_TYPE
@ METADATA_GLOBAL_DECL_ATTACHMENT
@ METADATA_IMPORTED_ENTITY
@ METADATA_GENERIC_SUBRANGE
@ METADATA_COMPOSITE_TYPE
@ METADATA_FIXED_POINT_TYPE
@ METADATA_GLOBAL_VAR_EXPR
GlobalValueSummarySymtabCodes
@ FS_CONTEXT_RADIX_TREE_ARRAY
@ FS_COMBINED_GLOBALVAR_INIT_REFS
@ FS_TYPE_CHECKED_LOAD_VCALLS
@ FS_COMBINED_ORIGINAL_NAME
@ FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_CONST_VCALL
@ FS_PERMODULE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_VCALLS
@ FS_COMBINED_ALLOC_INFO_NO_CONTEXT
@ FS_COMBINED_CALLSITE_INFO
@ FS_PERMODULE_CALLSITE_INFO
@ FS_PERMODULE_ALLOC_INFO
@ FS_TYPE_CHECKED_LOAD_CONST_VCALL
@ IDENTIFICATION_CODE_EPOCH
@ IDENTIFICATION_CODE_STRING
@ CST_CODE_DSO_LOCAL_EQUIVALENT
@ CST_CODE_CE_GEP_WITH_INRANGE
@ COMDAT_SELECTION_KIND_LARGEST
@ COMDAT_SELECTION_KIND_ANY
@ COMDAT_SELECTION_KIND_SAME_SIZE
@ COMDAT_SELECTION_KIND_EXACT_MATCH
@ COMDAT_SELECTION_KIND_NO_DUPLICATES
@ ATTR_KIND_STACK_PROTECT
@ ATTR_KIND_STACK_PROTECT_STRONG
@ ATTR_KIND_SANITIZE_MEMORY
@ ATTR_KIND_OPTIMIZE_FOR_SIZE
@ ATTR_KIND_FNRETTHUNK_EXTERN
@ ATTR_KIND_NO_DIVERGENCE_SOURCE
@ ATTR_KIND_SANITIZE_ADDRESS
@ ATTR_KIND_NO_IMPLICIT_FLOAT
@ ATTR_KIND_DEAD_ON_UNWIND
@ ATTR_KIND_STACK_ALIGNMENT
@ ATTR_KIND_STACK_PROTECT_REQ
@ ATTR_KIND_NULL_POINTER_IS_VALID
@ ATTR_KIND_SANITIZE_HWADDRESS
@ ATTR_KIND_RETURNS_TWICE
@ ATTR_KIND_SHADOWCALLSTACK
@ ATTR_KIND_OPT_FOR_FUZZING
@ ATTR_KIND_SANITIZE_NUMERICAL_STABILITY
@ ATTR_KIND_ALLOCATED_POINTER
@ ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION
@ ATTR_KIND_CORO_ELIDE_SAFE
@ ATTR_KIND_NON_LAZY_BIND
@ ATTR_KIND_DEREFERENCEABLE
@ ATTR_KIND_OPTIMIZE_NONE
@ ATTR_KIND_HYBRID_PATCHABLE
@ ATTR_KIND_DEREFERENCEABLE_OR_NULL
@ ATTR_KIND_SANITIZE_REALTIME
@ ATTR_KIND_SPECULATIVE_LOAD_HARDENING
@ ATTR_KIND_ALWAYS_INLINE
@ ATTR_KIND_SANITIZE_TYPE
@ ATTR_KIND_PRESPLIT_COROUTINE
@ ATTR_KIND_NO_SANITIZE_COVERAGE
@ ATTR_KIND_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_LOC_AGAIN
@ FUNC_CODE_INST_EXTRACTELT
@ FUNC_CODE_INST_INDIRECTBR
@ FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE
@ FUNC_CODE_INST_INSERTVAL
@ FUNC_CODE_DECLAREBLOCKS
@ FUNC_CODE_DEBUG_RECORD_LABEL
@ FUNC_CODE_INST_INSERTELT
@ FUNC_CODE_BLOCKADDR_USERS
@ FUNC_CODE_INST_CLEANUPPAD
@ FUNC_CODE_INST_SHUFFLEVEC
@ FUNC_CODE_INST_UNREACHABLE
@ FUNC_CODE_DEBUG_RECORD_DECLARE
@ FUNC_CODE_OPERAND_BUNDLE
@ FIRST_APPLICATION_ABBREV
@ PARAMATTR_GRP_CODE_ENTRY
initializer< Ty > init(const Ty &Val)
@ DW_APPLE_ENUM_KIND_invalid
Enum kind for invalid results.
LLVM_ABI Error build(ArrayRef< Module * > Mods, SmallVector< char, 0 > &Symtab, StringTableBuilder &StrtabBuilder, BumpPtrAllocator &Alloc)
Fills in Symtab and StrtabBuilder with a valid symbol and string table for Mods.
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract_or_null(Y &&MD)
Extract a Value from Metadata, allowing null.
LLVM_ABI bool metadataIncludesAllContextSizeInfo()
Whether the alloc memeprof metadata will include context size info for all MIBs.
template LLVM_ABI llvm::DenseMap< LinearFrameId, FrameStat > computeFrameHistogram< LinearFrameId >(llvm::MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &MemProfCallStackData)
LLVM_ABI bool metadataMayIncludeContextSizeInfo()
Whether the alloc memprof metadata may include context size info for some MIBs (but possibly not all)...
NodeAddr< CodeNode * > Code
void write32le(void *P, uint32_t V)
uint32_t read32be(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
FunctionAddr VTableAddr Value
StringMapEntry< Value * > ValueName
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
std::unordered_set< GlobalValueSummary * > GVSummaryPtrSet
A set of global value summary pointers.
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
LLVM_ABI void WriteBitcodeToFile(const Module &M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the specified raw output stream.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
LLVM_ABI void writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the given raw output...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
LLVM_ABI void writeIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out, const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex=nullptr, const GVSummaryPtrSet *DecSummaries=nullptr)
Write the specified module summary index to the given raw output stream, where it will be written in ...
LLVM_ABI void embedBitcodeInModule(Module &M, MemoryBufferRef Buf, bool EmbedBitcode, bool EmbedCmdline, const std::vector< uint8_t > &CmdArgs)
If EmbedBitcode is set, save a copy of the llvm IR as data in the __LLVM,__bitcode section (....
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
LLVM_ABI Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
FunctionAddr VTableAddr Count
std::map< std::string, GVSummaryMapTy, std::less<> > ModuleToSummariesForIndexTy
Map of a module name to the GUIDs and summaries we will import from that module.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
AtomicOrdering
Atomic ordering for LLVM's memory model.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt copy(R &&Range, OutputIt Out)
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
bool isBitcode(const unsigned char *BufPtr, const unsigned char *BufEnd)
isBitcode - Return true if the given bytes are the magic bytes for LLVM IR bitcode,...
void consumeError(Error Err)
Consume a Error without doing anything.
LLVM_ABI 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.
static constexpr unsigned RelBlockFreqBits
The value stored in RelBlockFreq has to be interpreted as the digits of a scaled number with a scale ...
Flags specific to function summaries.
static constexpr uint32_t RangeWidth
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
static const Target * lookupTarget(StringRef TripleStr, 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