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 "));
123 cl::desc(
"Preserve use-list order when writing LLVM bitcode."));
138 VST_BBENTRY_6_ABBREV,
142 CONSTANTS_INTEGER_ABBREV,
143 CONSTANTS_CE_CAST_Abbrev,
144 CONSTANTS_NULL_Abbrev,
148 FUNCTION_INST_STORE_ABBREV,
149 FUNCTION_INST_UNOP_ABBREV,
150 FUNCTION_INST_UNOP_FLAGS_ABBREV,
151 FUNCTION_INST_BINOP_ABBREV,
152 FUNCTION_INST_BINOP_FLAGS_ABBREV,
153 FUNCTION_INST_CAST_ABBREV,
154 FUNCTION_INST_CAST_FLAGS_ABBREV,
155 FUNCTION_INST_RET_VOID_ABBREV,
156 FUNCTION_INST_RET_VAL_ABBREV,
157 FUNCTION_INST_BR_UNCOND_ABBREV,
158 FUNCTION_INST_BR_COND_ABBREV,
159 FUNCTION_INST_UNREACHABLE_ABBREV,
160 FUNCTION_INST_GEP_ABBREV,
161 FUNCTION_INST_CMP_ABBREV,
162 FUNCTION_INST_CMP_FLAGS_ABBREV,
163 FUNCTION_DEBUG_RECORD_VALUE_ABBREV,
164 FUNCTION_DEBUG_LOC_ABBREV,
169class BitcodeWriterBase {
172 BitstreamWriter &Stream;
174 StringTableBuilder &StrtabBuilder;
179 BitcodeWriterBase(BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder)
180 : Stream(Stream), StrtabBuilder(StrtabBuilder) {}
183 void writeModuleVersion();
186void BitcodeWriterBase::writeModuleVersion() {
193class ModuleBitcodeWriterBase :
public BitcodeWriterBase {
202 const ModuleSummaryIndex *Index;
207 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
210 unsigned GlobalValueId;
214 uint64_t VSTOffsetPlaceholder = 0;
219 ModuleBitcodeWriterBase(
const Module &M, StringTableBuilder &StrtabBuilder,
220 BitstreamWriter &Stream,
221 bool ShouldPreserveUseListOrder,
222 const ModuleSummaryIndex *Index)
223 : BitcodeWriterBase(Stream, StrtabBuilder),
M(
M),
226 : ShouldPreserveUseListOrder),
236 for (
const auto &GUIDSummaryLists : *Index)
238 for (
auto &Summary : GUIDSummaryLists.second.getSummaryList())
244 for (auto &CallEdge : FS->calls())
245 if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
246 assignValueId(CallEdge.first.getGUID());
252 for (auto &RefEdge : FS->refs())
253 if (!RefEdge.haveGVs() || !RefEdge.getValue())
254 assignValueId(RefEdge.getGUID());
259 void writePerModuleGlobalValueSummary();
262 void writePerModuleFunctionSummaryRecord(
263 SmallVector<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
264 unsigned ValueID,
unsigned FSCallsAbbrev,
unsigned FSCallsProfileAbbrev,
265 unsigned CallsiteAbbrev,
unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
266 const Function &
F, DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
268 void writeModuleLevelReferences(
const GlobalVariable &V,
269 SmallVector<uint64_t, 64> &NameVals,
270 unsigned FSModRefsAbbrev,
271 unsigned FSModVTableRefsAbbrev);
274 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
278 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
281 assert(VMI != GUIDToValueIdMap.end() &&
282 "GUID does not have assigned value Id");
287 unsigned getValueId(ValueInfo VI) {
288 if (!
VI.haveGVs() || !
VI.getValue())
289 return getValueId(
VI.getGUID());
293 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
297class ModuleBitcodeWriter :
public ModuleBitcodeWriterBase {
308 uint64_t BitcodeStartBit;
313 ModuleBitcodeWriter(
const Module &M, StringTableBuilder &StrtabBuilder,
314 BitstreamWriter &Stream,
bool ShouldPreserveUseListOrder,
315 const ModuleSummaryIndex *Index,
bool GenerateHash,
317 : ModuleBitcodeWriterBase(
M, StrtabBuilder, Stream,
318 ShouldPreserveUseListOrder,
Index),
319 GenerateHash(GenerateHash), ModHash(ModHash),
320 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
326 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
328 size_t addToStrtab(StringRef Str);
330 void writeAttributeGroupTable();
331 void writeAttributeTable();
332 void writeTypeTable();
334 void writeValueSymbolTableForwardDecl();
335 void writeModuleInfo();
336 void writeValueAsMetadata(
const ValueAsMetadata *MD,
337 SmallVectorImpl<uint64_t> &Record);
338 void writeMDTuple(
const MDTuple *
N, SmallVectorImpl<uint64_t> &Record,
340 unsigned createDILocationAbbrev();
341 void writeDILocation(
const DILocation *
N, SmallVectorImpl<uint64_t> &Record,
343 unsigned createGenericDINodeAbbrev();
345 SmallVectorImpl<uint64_t> &Record,
unsigned &Abbrev);
346 void writeDISubrange(
const DISubrange *
N, SmallVectorImpl<uint64_t> &Record,
349 SmallVectorImpl<uint64_t> &Record,
352 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
356 SmallVectorImpl<uint64_t> &Record,
359 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
361 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
363 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
365 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
367 SmallVectorImpl<uint64_t> &Record,
369 void writeDIFile(
const DIFile *
N, SmallVectorImpl<uint64_t> &Record,
372 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
374 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
376 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
378 SmallVectorImpl<uint64_t> &Record,
381 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
384 void writeDIMacro(
const DIMacro *
N, SmallVectorImpl<uint64_t> &Record,
388 void writeDIArgList(
const DIArgList *
N, SmallVectorImpl<uint64_t> &Record);
389 void writeDIModule(
const DIModule *
N, SmallVectorImpl<uint64_t> &Record,
391 void writeDIAssignID(
const DIAssignID *
N, SmallVectorImpl<uint64_t> &Record,
394 SmallVectorImpl<uint64_t> &Record,
397 SmallVectorImpl<uint64_t> &Record,
400 SmallVectorImpl<uint64_t> &Record,
403 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
405 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
407 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
409 SmallVectorImpl<uint64_t> &Record,
412 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
414 SmallVectorImpl<uint64_t> &Record,
416 unsigned createNamedMetadataAbbrev();
417 void writeNamedMetadata(SmallVectorImpl<uint64_t> &Record);
418 unsigned createMetadataStringsAbbrev();
420 SmallVectorImpl<uint64_t> &Record);
422 SmallVectorImpl<uint64_t> &Record,
423 std::vector<unsigned> *MDAbbrevs =
nullptr,
424 std::vector<uint64_t> *IndexPos =
nullptr);
425 void writeModuleMetadata();
426 void writeFunctionMetadata(
const Function &
F);
427 void writeFunctionMetadataAttachment(
const Function &
F);
428 void pushGlobalMetadataAttachment(SmallVectorImpl<uint64_t> &Record,
429 const GlobalObject &GO);
430 void writeModuleMetadataKinds();
431 void writeOperandBundleTags();
432 void writeSyncScopeNames();
433 void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
434 void writeModuleConstants();
435 bool pushValueAndType(
const Value *V,
unsigned InstID,
436 SmallVectorImpl<unsigned> &Vals);
437 bool pushValueOrMetadata(
const Value *V,
unsigned InstID,
438 SmallVectorImpl<unsigned> &Vals);
439 void writeOperandBundles(
const CallBase &CB,
unsigned InstID);
440 void pushValue(
const Value *V,
unsigned InstID,
441 SmallVectorImpl<unsigned> &Vals);
442 void pushValueSigned(
const Value *V,
unsigned InstID,
443 SmallVectorImpl<uint64_t> &Vals);
444 void writeInstruction(
const Instruction &
I,
unsigned InstID,
445 SmallVectorImpl<unsigned> &Vals);
446 void writeFunctionLevelValueSymbolTable(
const ValueSymbolTable &VST);
447 void writeGlobalValueSymbolTable(
448 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
449 void writeUseList(UseListOrder &&Order);
450 void writeUseListBlock(
const Function *
F);
452 writeFunction(
const Function &
F,
453 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
454 void writeBlockInfo();
455 void writeModuleHash(StringRef View);
458 return unsigned(SSID);
461 unsigned getEncodedAlign(MaybeAlign Alignment) {
return encode(Alignment); }
465class IndexBitcodeWriter :
public BitcodeWriterBase {
467 const ModuleSummaryIndex &
Index;
480 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
484 std::vector<uint64_t> StackIds;
489 DenseMap<unsigned, unsigned> StackIdIndicesToIndex;
492 unsigned GlobalValueId = 0;
496 DenseMap<StringRef, uint64_t> ModuleIdMap;
506 BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder,
507 const ModuleSummaryIndex &Index,
510 : BitcodeWriterBase(Stream, StrtabBuilder),
Index(
Index),
511 DecSummaries(DecSummaries),
512 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
516 auto RecordStackIdReference = [&](
unsigned StackIdIndex) {
521 StackIdIndicesToIndex.
insert({StackIdIndex, StackIds.size()});
523 StackIds.push_back(
Index.getStackIdAtIndex(StackIdIndex));
530 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
531 GUIDToValueIdMap[
I.first] = ++GlobalValueId;
543 for (
auto &CI :
FS->callsites()) {
554 if (CI.StackIdIndices.empty()) {
555 GUIDToValueIdMap[CI.Callee.getGUID()] = ++GlobalValueId;
558 for (
auto Idx : CI.StackIdIndices)
559 RecordStackIdReference(Idx);
562 for (
auto &AI :
FS->allocs())
563 for (
auto &MIB : AI.MIBs)
564 for (
auto Idx : MIB.StackIdIndices)
565 RecordStackIdReference(Idx);
571 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
576 template<
typename Functor>
577 void forEachSummary(Functor Callback) {
578 if (ModuleToSummariesForIndex) {
579 for (
auto &M : *ModuleToSummariesForIndex)
580 for (
auto &Summary :
M.second) {
586 Callback({AS->getAliaseeGUID(), &AS->getAliasee()},
true);
589 for (
auto &Summaries : Index)
590 for (
auto &Summary : Summaries.second.getSummaryList())
599 template <
typename Functor>
void forEachModule(Functor Callback) {
600 if (ModuleToSummariesForIndex) {
601 for (
const auto &M : *ModuleToSummariesForIndex) {
602 const auto &MPI =
Index.modulePaths().find(
M.first);
603 if (MPI ==
Index.modulePaths().end()) {
607 assert(ModuleToSummariesForIndex->size() == 1);
617 std::vector<StringRef> ModulePaths;
618 for (
auto &[ModPath,
_] :
Index.modulePaths())
619 ModulePaths.push_back(ModPath);
621 for (
auto &ModPath : ModulePaths)
630 void writeModStrings();
631 void writeCombinedGlobalValueSummary();
634 auto VMI = GUIDToValueIdMap.find(ValGUID);
635 if (VMI == GUIDToValueIdMap.end())
640 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
675 case Instruction::Add:
677 case Instruction::Sub:
679 case Instruction::Mul:
682 case Instruction::FDiv:
685 case Instruction::FRem:
759 case Attribute::Alignment:
761 case Attribute::AllocAlign:
763 case Attribute::AllocSize:
765 case Attribute::AlwaysInline:
767 case Attribute::Builtin:
769 case Attribute::ByVal:
771 case Attribute::Convergent:
773 case Attribute::InAlloca:
775 case Attribute::Cold:
777 case Attribute::DisableSanitizerInstrumentation:
779 case Attribute::FnRetThunkExtern:
783 case Attribute::ElementType:
785 case Attribute::HybridPatchable:
787 case Attribute::InlineHint:
789 case Attribute::InReg:
791 case Attribute::JumpTable:
793 case Attribute::MinSize:
795 case Attribute::AllocatedPointer:
797 case Attribute::AllocKind:
799 case Attribute::Memory:
801 case Attribute::NoFPClass:
803 case Attribute::Naked:
805 case Attribute::Nest:
807 case Attribute::NoAlias:
809 case Attribute::NoBuiltin:
811 case Attribute::NoCallback:
813 case Attribute::NoDivergenceSource:
815 case Attribute::NoDuplicate:
817 case Attribute::NoFree:
819 case Attribute::NoImplicitFloat:
821 case Attribute::NoInline:
823 case Attribute::NoRecurse:
825 case Attribute::NoMerge:
827 case Attribute::NonLazyBind:
829 case Attribute::NonNull:
831 case Attribute::Dereferenceable:
833 case Attribute::DereferenceableOrNull:
835 case Attribute::NoRedZone:
837 case Attribute::NoReturn:
839 case Attribute::NoSync:
841 case Attribute::NoCfCheck:
843 case Attribute::NoProfile:
845 case Attribute::SkipProfile:
847 case Attribute::NoUnwind:
849 case Attribute::NoSanitizeBounds:
851 case Attribute::NoSanitizeCoverage:
853 case Attribute::NullPointerIsValid:
855 case Attribute::OptimizeForDebugging:
857 case Attribute::OptForFuzzing:
859 case Attribute::OptimizeForSize:
861 case Attribute::OptimizeNone:
863 case Attribute::ReadNone:
865 case Attribute::ReadOnly:
867 case Attribute::Returned:
869 case Attribute::ReturnsTwice:
871 case Attribute::SExt:
873 case Attribute::Speculatable:
875 case Attribute::StackAlignment:
877 case Attribute::StackProtect:
879 case Attribute::StackProtectReq:
881 case Attribute::StackProtectStrong:
883 case Attribute::SafeStack:
885 case Attribute::ShadowCallStack:
887 case Attribute::StrictFP:
889 case Attribute::StructRet:
891 case Attribute::SanitizeAddress:
893 case Attribute::SanitizeAllocToken:
895 case Attribute::SanitizeHWAddress:
897 case Attribute::SanitizeThread:
899 case Attribute::SanitizeType:
901 case Attribute::SanitizeMemory:
903 case Attribute::SanitizeNumericalStability:
905 case Attribute::SanitizeRealtime:
907 case Attribute::SanitizeRealtimeBlocking:
909 case Attribute::SpeculativeLoadHardening:
911 case Attribute::SwiftError:
913 case Attribute::SwiftSelf:
915 case Attribute::SwiftAsync:
917 case Attribute::UWTable:
919 case Attribute::VScaleRange:
921 case Attribute::WillReturn:
923 case Attribute::WriteOnly:
925 case Attribute::ZExt:
927 case Attribute::ImmArg:
929 case Attribute::SanitizeMemTag:
931 case Attribute::Preallocated:
933 case Attribute::NoUndef:
935 case Attribute::ByRef:
937 case Attribute::MustProgress:
939 case Attribute::PresplitCoroutine:
941 case Attribute::Writable:
943 case Attribute::CoroDestroyOnlyWhenComplete:
945 case Attribute::CoroElideSafe:
947 case Attribute::DeadOnUnwind:
949 case Attribute::Range:
951 case Attribute::Initializes:
953 case Attribute::NoExt:
955 case Attribute::Captures:
957 case Attribute::DeadOnReturn:
983 unsigned NumWords =
A.getActiveWords();
984 const uint64_t *RawData =
A.getRawData();
985 for (
unsigned i = 0; i < NumWords; i++)
1005void ModuleBitcodeWriter::writeAttributeGroupTable() {
1006 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
1008 if (AttrGrps.empty())
return;
1012 SmallVector<uint64_t, 64> Record;
1014 unsigned AttrListIndex = Pair.first;
1015 AttributeSet AS = Pair.second;
1020 if (Attr.isEnumAttribute()) {
1023 }
else if (Attr.isIntAttribute()) {
1025 Attribute::AttrKind
Kind = Attr.getKindAsEnum();
1027 if (Kind == Attribute::Memory) {
1034 }
else if (Attr.isStringAttribute()) {
1035 StringRef
Kind = Attr.getKindAsString();
1036 StringRef Val = Attr.getValueAsString();
1045 }
else if (Attr.isTypeAttribute()) {
1046 Type *Ty = Attr.getValueAsType();
1051 }
else if (Attr.isConstantRangeAttribute()) {
1057 assert(Attr.isConstantRangeListAttribute());
1063 for (
auto &CR : Val)
1075void ModuleBitcodeWriter::writeAttributeTable() {
1077 if (
Attrs.empty())
return;
1081 SmallVector<uint64_t, 64> Record;
1082 for (
const AttributeList &AL : Attrs) {
1083 for (
unsigned i :
AL.indexes()) {
1084 AttributeSet AS =
AL.getAttributes(i);
1097void ModuleBitcodeWriter::writeTypeTable() {
1101 SmallVector<uint64_t, 64> TypeVals;
1106 auto Abbv = std::make_shared<BitCodeAbbrev>();
1108 Abbv->Add(BitCodeAbbrevOp(0));
1109 unsigned OpaquePtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1112 Abbv = std::make_shared<BitCodeAbbrev>();
1117 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1120 Abbv = std::make_shared<BitCodeAbbrev>();
1125 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1128 Abbv = std::make_shared<BitCodeAbbrev>();
1132 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1135 Abbv = std::make_shared<BitCodeAbbrev>();
1140 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1143 Abbv = std::make_shared<BitCodeAbbrev>();
1147 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1155 for (
Type *
T : TypeList) {
1156 int AbbrevToUse = 0;
1159 switch (
T->getTypeID()) {
1169 case Type::MetadataTyID:
1174 case Type::IntegerTyID:
1179 case Type::PointerTyID: {
1186 AbbrevToUse = OpaquePtrAbbrev;
1189 case Type::FunctionTyID: {
1195 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1197 AbbrevToUse = FunctionAbbrev;
1200 case Type::StructTyID: {
1205 for (
Type *ET :
ST->elements())
1208 if (
ST->isLiteral()) {
1210 AbbrevToUse = StructAnonAbbrev;
1212 if (
ST->isOpaque()) {
1216 AbbrevToUse = StructNamedAbbrev;
1220 if (!
ST->getName().empty())
1226 case Type::ArrayTyID: {
1230 TypeVals.
push_back(AT->getNumElements());
1232 AbbrevToUse = ArrayAbbrev;
1235 case Type::FixedVectorTyID:
1236 case Type::ScalableVectorTyID: {
1241 TypeVals.
push_back(VT->getElementCount().getKnownMinValue());
1247 case Type::TargetExtTyID: {
1253 for (
Type *InnerTy :
TET->type_params())
1258 case Type::TypedPointerTyID:
1263 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
1304 RawFlags |= Flags.ReadNone;
1305 RawFlags |= (Flags.ReadOnly << 1);
1306 RawFlags |= (Flags.NoRecurse << 2);
1307 RawFlags |= (Flags.ReturnDoesNotAlias << 3);
1308 RawFlags |= (Flags.NoInline << 4);
1309 RawFlags |= (Flags.AlwaysInline << 5);
1310 RawFlags |= (Flags.NoUnwind << 6);
1311 RawFlags |= (Flags.MayThrow << 7);
1312 RawFlags |= (Flags.HasUnknownCall << 8);
1313 RawFlags |= (Flags.MustBeUnreachable << 9);
1320 bool ImportAsDecl =
false) {
1323 RawFlags |= Flags.NotEligibleToImport;
1324 RawFlags |= (Flags.Live << 1);
1325 RawFlags |= (Flags.DSOLocal << 2);
1326 RawFlags |= (Flags.CanAutoHide << 3);
1331 RawFlags = (RawFlags << 4) | Flags.Linkage;
1333 RawFlags |= (Flags.Visibility << 8);
1335 unsigned ImportType = Flags.ImportType | ImportAsDecl;
1336 RawFlags |= (ImportType << 10);
1342 uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1343 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1395 switch (
C.getSelectionKind()) {
1419size_t ModuleBitcodeWriter::addToStrtab(StringRef Str) {
1422 return StrtabBuilder.
add(Str);
1425void ModuleBitcodeWriter::writeComdats() {
1440void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1445 auto Abbv = std::make_shared<BitCodeAbbrev>();
1451 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1467 bool isChar6 =
true;
1468 for (
char C : Str) {
1471 if ((
unsigned char)
C & 128)
1480static_assert(
sizeof(GlobalValue::SanitizerMetadata) <=
sizeof(unsigned),
1481 "Sanitizer Metadata is too large for naive serialization.");
1484 return Meta.NoAddress | (
Meta.NoHWAddress << 1) |
1485 (
Meta.Memtag << 2) | (
Meta.IsDynInit << 3);
1491void ModuleBitcodeWriter::writeModuleInfo() {
1493 if (!
M.getTargetTriple().empty())
1495 M.getTargetTriple().str(), 0 );
1496 const std::string &
DL =
M.getDataLayoutStr();
1499 if (!
M.getModuleInlineAsm().empty())
1505 std::map<std::string, unsigned> SectionMap;
1506 std::map<std::string, unsigned> GCMap;
1507 MaybeAlign MaxGVarAlignment;
1508 unsigned MaxGlobalType = 0;
1509 for (
const GlobalVariable &GV :
M.globals()) {
1510 if (MaybeAlign
A = GV.getAlign())
1511 MaxGVarAlignment = !MaxGVarAlignment ? *
A : std::max(*MaxGVarAlignment, *
A);
1512 MaxGlobalType = std::max(MaxGlobalType, VE.
getTypeID(GV.getValueType()));
1513 if (GV.hasSection()) {
1515 unsigned &
Entry = SectionMap[std::string(GV.getSection())];
1519 Entry = SectionMap.size();
1523 for (
const Function &
F : M) {
1524 if (
F.hasSection()) {
1526 unsigned &
Entry = SectionMap[std::string(
F.getSection())];
1530 Entry = SectionMap.size();
1535 unsigned &
Entry = GCMap[
F.getGC()];
1539 Entry = GCMap.size();
1545 unsigned SimpleGVarAbbrev = 0;
1546 if (!
M.global_empty()) {
1548 auto Abbv = std::make_shared<BitCodeAbbrev>();
1559 if (!MaxGVarAlignment)
1560 Abbv->Add(BitCodeAbbrevOp(0));
1562 unsigned MaxEncAlignment = getEncodedAlign(MaxGVarAlignment);
1566 if (SectionMap.empty())
1567 Abbv->Add(BitCodeAbbrevOp(0));
1572 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1586 auto Abbv = std::make_shared<BitCodeAbbrev>();
1589 Abbv->Add(AbbrevOpToUse);
1590 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1592 for (
const auto P :
M.getSourceFileName())
1601 for (
const GlobalVariable &GV :
M.globals()) {
1602 unsigned AbbrevToUse = 0;
1608 Vals.
push_back(addToStrtab(GV.getName()));
1611 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1615 Vals.
push_back(getEncodedAlign(GV.getAlign()));
1616 Vals.
push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1618 if (GV.isThreadLocal() ||
1620 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1621 GV.isExternallyInitialized() ||
1623 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1624 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1628 Vals.
push_back(GV.isExternallyInitialized());
1632 auto AL = GV.getAttributesAsList(AttributeList::FunctionIndex);
1636 Vals.
push_back(addToStrtab(GV.getPartition()));
1637 Vals.
push_back(GV.getPartition().size());
1640 GV.getSanitizerMetadata())
1644 AbbrevToUse = SimpleGVarAbbrev;
1652 for (
const Function &
F : M) {
1664 Vals.
push_back(getEncodedAlign(
F.getAlign()));
1665 Vals.
push_back(
F.hasSection() ? SectionMap[std::string(
F.getSection())]
1677 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1681 Vals.
push_back(addToStrtab(
F.getPartition()));
1684 unsigned AbbrevToUse = 0;
1690 for (
const GlobalAlias &
A :
M.aliases()) {
1697 Vals.
push_back(
A.getType()->getAddressSpace());
1705 Vals.
push_back(addToStrtab(
A.getPartition()));
1708 unsigned AbbrevToUse = 0;
1714 for (
const GlobalIFunc &
I :
M.ifuncs()) {
1720 Vals.
push_back(
I.getType()->getAddressSpace());
1725 Vals.
push_back(addToStrtab(
I.getPartition()));
1731 writeValueSymbolTableForwardDecl();
1738 if (OBO->hasNoSignedWrap())
1740 if (OBO->hasNoUnsignedWrap())
1746 if (PDI->isDisjoint())
1749 if (FPMO->hasAllowReassoc())
1751 if (FPMO->hasNoNaNs())
1753 if (FPMO->hasNoInfs())
1755 if (FPMO->hasNoSignedZeros())
1757 if (FPMO->hasAllowReciprocal())
1759 if (FPMO->hasAllowContract())
1761 if (FPMO->hasApproxFunc())
1764 if (NNI->hasNonNeg())
1767 if (TI->hasNoSignedWrap())
1769 if (TI->hasNoUnsignedWrap())
1772 if (
GEP->isInBounds())
1774 if (
GEP->hasNoUnsignedSignedWrap())
1776 if (
GEP->hasNoUnsignedWrap())
1779 if (ICmp->hasSameSign())
1786void ModuleBitcodeWriter::writeValueAsMetadata(
1787 const ValueAsMetadata *MD, SmallVectorImpl<uint64_t> &Record) {
1796void ModuleBitcodeWriter::writeMDTuple(
const MDTuple *
N,
1797 SmallVectorImpl<uint64_t> &Record,
1799 for (
const MDOperand &MDO :
N->operands()) {
1802 "Unexpected function-local metadata");
1811unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1814 auto Abbv = std::make_shared<BitCodeAbbrev>();
1827void ModuleBitcodeWriter::writeDILocation(
const DILocation *
N,
1828 SmallVectorImpl<uint64_t> &Record,
1831 Abbrev = createDILocationAbbrev();
1845unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1848 auto Abbv = std::make_shared<BitCodeAbbrev>();
1859void ModuleBitcodeWriter::writeGenericDINode(
const GenericDINode *
N,
1860 SmallVectorImpl<uint64_t> &Record,
1863 Abbrev = createGenericDINodeAbbrev();
1869 for (
auto &
I :
N->operands())
1876void ModuleBitcodeWriter::writeDISubrange(
const DISubrange *
N,
1877 SmallVectorImpl<uint64_t> &Record,
1879 const uint64_t
Version = 2 << 1;
1890void ModuleBitcodeWriter::writeDIGenericSubrange(
1891 const DIGenericSubrange *
N, SmallVectorImpl<uint64_t> &Record,
1903void ModuleBitcodeWriter::writeDIEnumerator(
const DIEnumerator *
N,
1904 SmallVectorImpl<uint64_t> &Record,
1906 const uint64_t IsBigInt = 1 << 2;
1907 Record.
push_back(IsBigInt | (
N->isUnsigned() << 1) |
N->isDistinct());
1908 Record.
push_back(
N->getValue().getBitWidth());
1916void ModuleBitcodeWriter::writeDIBasicType(
const DIBasicType *
N,
1917 SmallVectorImpl<uint64_t> &Record,
1919 const unsigned SizeIsMetadata = 0x2;
1920 Record.
push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1927 Record.
push_back(
N->getNumExtraInhabitants());
1934void ModuleBitcodeWriter::writeDIFixedPointType(
1935 const DIFixedPointType *
N, SmallVectorImpl<uint64_t> &Record,
1937 const unsigned SizeIsMetadata = 0x2;
1938 Record.
push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1948 auto WriteWideInt = [&](
const APInt &
Value) {
1951 uint64_t NumWords =
Value.getActiveWords();
1952 uint64_t
Encoded = (NumWords << 32) |
Value.getBitWidth();
1957 WriteWideInt(
N->getNumeratorRaw());
1958 WriteWideInt(
N->getDenominatorRaw());
1964void ModuleBitcodeWriter::writeDIStringType(
const DIStringType *
N,
1965 SmallVectorImpl<uint64_t> &Record,
1967 const unsigned SizeIsMetadata = 0x2;
1968 Record.
push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1982void ModuleBitcodeWriter::writeDIDerivedType(
const DIDerivedType *
N,
1983 SmallVectorImpl<uint64_t> &Record,
1985 const unsigned SizeIsMetadata = 0x2;
1986 Record.
push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2001 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
2002 Record.
push_back(*DWARFAddressSpace + 1);
2008 if (
auto PtrAuthData =
N->getPtrAuthData())
2017void ModuleBitcodeWriter::writeDISubrangeType(
const DISubrangeType *
N,
2018 SmallVectorImpl<uint64_t> &Record,
2020 const unsigned SizeIsMetadata = 0x2;
2021 Record.
push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2039void ModuleBitcodeWriter::writeDICompositeType(
2040 const DICompositeType *
N, SmallVectorImpl<uint64_t> &Record,
2042 const unsigned IsNotUsedInOldTypeRef = 0x2;
2043 const unsigned SizeIsMetadata = 0x4;
2044 Record.
push_back(SizeIsMetadata | IsNotUsedInOldTypeRef |
2045 (
unsigned)
N->isDistinct());
2067 Record.
push_back(
N->getNumExtraInhabitants());
2077void ModuleBitcodeWriter::writeDISubroutineType(
2078 const DISubroutineType *
N, SmallVectorImpl<uint64_t> &Record,
2080 const unsigned HasNoOldTypeRefs = 0x2;
2081 Record.
push_back(HasNoOldTypeRefs | (
unsigned)
N->isDistinct());
2090void ModuleBitcodeWriter::writeDIFile(
const DIFile *
N,
2091 SmallVectorImpl<uint64_t> &Record,
2096 if (
N->getRawChecksum()) {
2105 auto Source =
N->getRawSource();
2113void ModuleBitcodeWriter::writeDICompileUnit(
const DICompileUnit *
N,
2114 SmallVectorImpl<uint64_t> &Record,
2116 assert(
N->isDistinct() &&
"Expected distinct compile units");
2119 auto Lang =
N->getSourceLanguage();
2123 if (Lang.hasVersionedName())
2124 Record.
back() ^= (uint64_t(1) << 63);
2140 Record.
push_back(
N->getSplitDebugInlining());
2141 Record.
push_back(
N->getDebugInfoForProfiling());
2142 Record.
push_back((
unsigned)
N->getNameTableKind());
2146 Record.
push_back(Lang.hasVersionedName() ? Lang.getVersion() : 0);
2152void ModuleBitcodeWriter::writeDISubprogram(
const DISubprogram *
N,
2153 SmallVectorImpl<uint64_t> &Record,
2155 const uint64_t HasUnitFlag = 1 << 1;
2156 const uint64_t HasSPFlagsFlag = 1 << 2;
2157 Record.
push_back(uint64_t(
N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
2177 Record.
push_back(
N->getKeyInstructionsEnabled());
2183void ModuleBitcodeWriter::writeDILexicalBlock(
const DILexicalBlock *
N,
2184 SmallVectorImpl<uint64_t> &Record,
2196void ModuleBitcodeWriter::writeDILexicalBlockFile(
2197 const DILexicalBlockFile *
N, SmallVectorImpl<uint64_t> &Record,
2208void ModuleBitcodeWriter::writeDICommonBlock(
const DICommonBlock *
N,
2209 SmallVectorImpl<uint64_t> &Record,
2222void ModuleBitcodeWriter::writeDINamespace(
const DINamespace *
N,
2223 SmallVectorImpl<uint64_t> &Record,
2225 Record.
push_back(
N->isDistinct() |
N->getExportSymbols() << 1);
2233void ModuleBitcodeWriter::writeDIMacro(
const DIMacro *
N,
2234 SmallVectorImpl<uint64_t> &Record,
2246void ModuleBitcodeWriter::writeDIMacroFile(
const DIMacroFile *
N,
2247 SmallVectorImpl<uint64_t> &Record,
2259void ModuleBitcodeWriter::writeDIArgList(
const DIArgList *
N,
2260 SmallVectorImpl<uint64_t> &Record) {
2261 Record.
reserve(
N->getArgs().size());
2262 for (ValueAsMetadata *MD :
N->getArgs())
2269void ModuleBitcodeWriter::writeDIModule(
const DIModule *
N,
2270 SmallVectorImpl<uint64_t> &Record,
2273 for (
auto &
I :
N->operands())
2282void ModuleBitcodeWriter::writeDIAssignID(
const DIAssignID *
N,
2283 SmallVectorImpl<uint64_t> &Record,
2291void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2292 const DITemplateTypeParameter *
N, SmallVectorImpl<uint64_t> &Record,
2303void ModuleBitcodeWriter::writeDITemplateValueParameter(
2304 const DITemplateValueParameter *
N, SmallVectorImpl<uint64_t> &Record,
2317void ModuleBitcodeWriter::writeDIGlobalVariable(
2318 const DIGlobalVariable *
N, SmallVectorImpl<uint64_t> &Record,
2320 const uint64_t
Version = 2 << 1;
2339void ModuleBitcodeWriter::writeDILocalVariable(
2340 const DILocalVariable *
N, SmallVectorImpl<uint64_t> &Record,
2355 const uint64_t HasAlignmentFlag = 1 << 1;
2356 Record.
push_back((uint64_t)
N->isDistinct() | HasAlignmentFlag);
2371void ModuleBitcodeWriter::writeDILabel(
2372 const DILabel *
N, SmallVectorImpl<uint64_t> &Record,
2374 uint64_t IsArtificialFlag = uint64_t(
N->isArtificial()) << 1;
2375 Record.
push_back((uint64_t)
N->isDistinct() | IsArtificialFlag);
2381 Record.
push_back(
N->getCoroSuspendIdx().has_value()
2382 ? (uint64_t)
N->getCoroSuspendIdx().value()
2383 : std::numeric_limits<uint64_t>::max());
2389void ModuleBitcodeWriter::writeDIExpression(
const DIExpression *
N,
2390 SmallVectorImpl<uint64_t> &Record,
2392 Record.
reserve(
N->getElements().size() + 1);
2393 const uint64_t
Version = 3 << 1;
2395 Record.
append(
N->elements_begin(),
N->elements_end());
2401void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2402 const DIGlobalVariableExpression *
N, SmallVectorImpl<uint64_t> &Record,
2412void ModuleBitcodeWriter::writeDIObjCProperty(
const DIObjCProperty *
N,
2413 SmallVectorImpl<uint64_t> &Record,
2428void ModuleBitcodeWriter::writeDIImportedEntity(
2429 const DIImportedEntity *
N, SmallVectorImpl<uint64_t> &Record,
2444unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2445 auto Abbv = std::make_shared<BitCodeAbbrev>();
2452void ModuleBitcodeWriter::writeNamedMetadata(
2453 SmallVectorImpl<uint64_t> &Record) {
2454 if (
M.named_metadata_empty())
2457 unsigned Abbrev = createNamedMetadataAbbrev();
2458 for (
const NamedMDNode &NMD :
M.named_metadata()) {
2460 StringRef Str = NMD.getName();
2461 Record.
append(Str.bytes_begin(), Str.bytes_end());
2466 for (
const MDNode *
N : NMD.operands())
2473unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2474 auto Abbv = std::make_shared<BitCodeAbbrev>();
2486void ModuleBitcodeWriter::writeMetadataStrings(
2488 if (Strings.
empty())
2496 SmallString<256> Blob;
2498 BitstreamWriter
W(Blob);
2518#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
2519#include "llvm/IR/Metadata.def"
2523void ModuleBitcodeWriter::writeMetadataRecords(
2525 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2530#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
2531#include "llvm/IR/Metadata.def"
2537 assert(
N->isResolved() &&
"Expected forward references to be resolved");
2539 switch (
N->getMetadataID()) {
2542#define HANDLE_MDNODE_LEAF(CLASS) \
2543 case Metadata::CLASS##Kind: \
2545 write##CLASS(cast<CLASS>(N), Record, \
2546 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
2548 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
2550#include "llvm/IR/Metadata.def"
2561void ModuleBitcodeWriter::writeModuleMetadata() {
2562 if (!VE.
hasMDs() &&
M.named_metadata_empty())
2566 SmallVector<uint64_t, 64> Record;
2570 std::vector<unsigned> MDAbbrevs;
2573 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2574 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2575 createGenericDINodeAbbrev();
2577 auto Abbv = std::make_shared<BitCodeAbbrev>();
2581 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2583 Abbv = std::make_shared<BitCodeAbbrev>();
2587 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2599 uint64_t Vals[] = {0, 0};
2609 std::vector<uint64_t> IndexPos;
2613 writeMetadataRecords(VE.
getNonMDStrings(), Record, &MDAbbrevs, &IndexPos);
2624 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2625 for (
auto &Elt : IndexPos) {
2626 auto EltDelta = Elt - PreviousValue;
2627 PreviousValue = Elt;
2636 writeNamedMetadata(Record);
2638 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2639 SmallVector<uint64_t, 4> Record;
2641 pushGlobalMetadataAttachment(Record, GO);
2644 for (
const Function &
F : M)
2645 if (
F.isDeclaration() &&
F.hasMetadata())
2646 AddDeclAttachedMetadata(
F);
2647 for (
const GlobalIFunc &GI :
M.ifuncs())
2648 if (GI.hasMetadata())
2649 AddDeclAttachedMetadata(GI);
2652 for (
const GlobalVariable &GV :
M.globals())
2653 if (GV.hasMetadata())
2654 AddDeclAttachedMetadata(GV);
2659void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2664 SmallVector<uint64_t, 64> Record;
2670void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2671 SmallVectorImpl<uint64_t> &Record,
const GlobalObject &GO) {
2675 for (
const auto &
I : MDs) {
2681void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &
F) {
2684 SmallVector<uint64_t, 64> Record;
2686 if (
F.hasMetadata()) {
2687 pushGlobalMetadataAttachment(Record,
F);
2695 for (
const BasicBlock &BB :
F)
2696 for (
const Instruction &
I : BB) {
2698 I.getAllMetadataOtherThanDebugLoc(MDs);
2701 if (MDs.
empty())
continue;
2705 for (
const auto &[
ID, MD] : MDs) {
2716void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2717 SmallVector<uint64_t, 64> Record;
2722 M.getMDKindNames(Names);
2724 if (Names.
empty())
return;
2728 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2730 StringRef KName = Names[MDKindID];
2740void ModuleBitcodeWriter::writeOperandBundleTags() {
2748 M.getOperandBundleTags(Tags);
2755 SmallVector<uint64_t, 64> Record;
2757 for (
auto Tag : Tags) {
2767void ModuleBitcodeWriter::writeSyncScopeNames() {
2769 M.getContext().getSyncScopeNames(SSNs);
2775 SmallVector<uint64_t, 64> Record;
2776 for (
auto SSN : SSNs) {
2777 Record.
append(SSN.begin(), SSN.end());
2785void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2787 if (FirstVal == LastVal)
return;
2791 unsigned AggregateAbbrev = 0;
2792 unsigned String8Abbrev = 0;
2793 unsigned CString7Abbrev = 0;
2794 unsigned CString6Abbrev = 0;
2798 auto Abbv = std::make_shared<BitCodeAbbrev>();
2802 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2805 Abbv = std::make_shared<BitCodeAbbrev>();
2809 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2811 Abbv = std::make_shared<BitCodeAbbrev>();
2815 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2817 Abbv = std::make_shared<BitCodeAbbrev>();
2821 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2824 SmallVector<uint64_t, 64> Record;
2827 Type *LastTy =
nullptr;
2828 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2829 const Value *
V = Vals[i].first;
2831 if (
V->getType() != LastTy) {
2832 LastTy =
V->getType();
2835 CONSTANTS_SETTYPE_ABBREV);
2842 unsigned(
IA->hasSideEffects()) |
unsigned(
IA->isAlignStack()) << 1 |
2843 unsigned(
IA->getDialect() & 1) << 2 |
unsigned(
IA->canThrow()) << 3);
2846 StringRef AsmStr =
IA->getAsmString();
2851 StringRef ConstraintStr =
IA->getConstraintString();
2859 unsigned Code = -1U;
2860 unsigned AbbrevToUse = 0;
2861 if (
C->isNullValue()) {
2868 if (
IV->getBitWidth() <= 64) {
2869 uint64_t
V =
IV->getSExtValue();
2872 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2882 Record.
push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2886 APInt api = CFP->getValueAPF().bitcastToAPInt();
2888 Record.
push_back((p[1] << 48) | (p[0] >> 16));
2891 APInt api = CFP->getValueAPF().bitcastToAPInt();
2896 assert(0 &&
"Unknown FP type!");
2902 uint64_t NumElts = Str->getNumElements();
2904 if (Str->isCString()) {
2909 AbbrevToUse = String8Abbrev;
2913 for (uint64_t i = 0; i != NumElts; ++i) {
2914 unsigned char V = Str->getElementAsInteger(i);
2916 isCStr7 &= (
V & 128) == 0;
2922 AbbrevToUse = CString6Abbrev;
2924 AbbrevToUse = CString7Abbrev;
2925 }
else if (
const ConstantDataSequential *CDS =
2928 Type *EltTy = CDS->getElementType();
2930 for (uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
2931 Record.
push_back(CDS->getElementAsInteger(i));
2933 for (uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
2935 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2939 for (
const Value *
Op :
C->operands())
2941 AbbrevToUse = AggregateAbbrev;
2943 switch (
CE->getOpcode()) {
2950 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2952 assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2962 case Instruction::FNeg: {
2963 assert(
CE->getNumOperands() == 1 &&
"Unknown constant expr!");
2972 case Instruction::GetElementPtr: {
2977 if (std::optional<ConstantRange>
Range = GO->getInRange()) {
2981 for (
const Value *
Op :
CE->operands()) {
2987 case Instruction::ExtractElement:
2994 case Instruction::InsertElement:
3001 case Instruction::ShuffleVector:
3006 if (
C->getType() ==
C->getOperand(0)->getType()) {
3042 Stream.
EmitRecord(Code, Record, AbbrevToUse);
3049void ModuleBitcodeWriter::writeModuleConstants() {
3054 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
3056 writeConstants(i, Vals.size(),
true);
3070bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
3071 SmallVectorImpl<unsigned> &Vals) {
3075 if (ValID >= InstID) {
3082bool ModuleBitcodeWriter::pushValueOrMetadata(
const Value *V,
unsigned InstID,
3083 SmallVectorImpl<unsigned> &Vals) {
3084 bool IsMetadata =
V->getType()->isMetadataTy();
3092 return pushValueAndType(V, InstID, Vals);
3095void ModuleBitcodeWriter::writeOperandBundles(
const CallBase &CS,
3102 Record.
push_back(
C.getOperandBundleTagID(Bundle.getTagName()));
3104 for (
auto &Input : Bundle.Inputs)
3105 pushValueOrMetadata(Input, InstID, Record);
3114void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
3115 SmallVectorImpl<unsigned> &Vals) {
3120void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
3121 SmallVectorImpl<uint64_t> &Vals) {
3123 int64_t diff = ((int32_t)InstID - (int32_t)ValID);
3128void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
3130 SmallVectorImpl<unsigned> &Vals) {
3132 unsigned AbbrevToUse = 0;
3134 switch (
I.getOpcode()) {
3138 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3139 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
3144 if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
3145 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
3151 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3152 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
3153 pushValue(
I.getOperand(1), InstID, Vals);
3157 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
3158 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
3163 case Instruction::FNeg: {
3165 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3166 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
3170 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
3171 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
3176 case Instruction::GetElementPtr: {
3178 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
3182 for (
const Value *
Op :
I.operands())
3183 pushValueAndType(
Op, InstID, Vals);
3186 case Instruction::ExtractValue: {
3188 pushValueAndType(
I.getOperand(0), InstID, Vals);
3193 case Instruction::InsertValue: {
3195 pushValueAndType(
I.getOperand(0), InstID, Vals);
3196 pushValueAndType(
I.getOperand(1), InstID, Vals);
3201 case Instruction::Select: {
3203 pushValueAndType(
I.getOperand(1), InstID, Vals);
3204 pushValue(
I.getOperand(2), InstID, Vals);
3205 pushValueAndType(
I.getOperand(0), InstID, Vals);
3211 case Instruction::ExtractElement:
3213 pushValueAndType(
I.getOperand(0), InstID, Vals);
3214 pushValueAndType(
I.getOperand(1), InstID, Vals);
3216 case Instruction::InsertElement:
3218 pushValueAndType(
I.getOperand(0), InstID, Vals);
3219 pushValue(
I.getOperand(1), InstID, Vals);
3220 pushValueAndType(
I.getOperand(2), InstID, Vals);
3222 case Instruction::ShuffleVector:
3224 pushValueAndType(
I.getOperand(0), InstID, Vals);
3225 pushValue(
I.getOperand(1), InstID, Vals);
3229 case Instruction::ICmp:
3230 case Instruction::FCmp: {
3233 AbbrevToUse = FUNCTION_INST_CMP_ABBREV;
3234 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3236 pushValue(
I.getOperand(1), InstID, Vals);
3242 AbbrevToUse = FUNCTION_INST_CMP_FLAGS_ABBREV;
3247 case Instruction::Ret:
3250 unsigned NumOperands =
I.getNumOperands();
3251 if (NumOperands == 0)
3252 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
3253 else if (NumOperands == 1) {
3254 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3255 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
3257 for (
const Value *
Op :
I.operands())
3258 pushValueAndType(
Op, InstID, Vals);
3262 case Instruction::Br:
3265 AbbrevToUse = FUNCTION_INST_BR_UNCOND_ABBREV;
3268 if (
II.isConditional()) {
3270 pushValue(
II.getCondition(), InstID, Vals);
3271 AbbrevToUse = FUNCTION_INST_BR_COND_ABBREV;
3275 case Instruction::Switch:
3280 pushValue(
SI.getCondition(), InstID, Vals);
3282 for (
auto Case :
SI.cases()) {
3288 case Instruction::IndirectBr:
3292 pushValue(
I.getOperand(0), InstID, Vals);
3297 case Instruction::Invoke: {
3300 FunctionType *FTy =
II->getFunctionType();
3302 if (
II->hasOperandBundles())
3303 writeOperandBundles(*
II, InstID);
3312 pushValueAndType(Callee, InstID, Vals);
3315 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3316 pushValue(
I.getOperand(i), InstID, Vals);
3319 if (FTy->isVarArg()) {
3320 for (
unsigned i = FTy->getNumParams(), e =
II->arg_size(); i != e; ++i)
3321 pushValueAndType(
I.getOperand(i), InstID, Vals);
3325 case Instruction::Resume:
3327 pushValueAndType(
I.getOperand(0), InstID, Vals);
3329 case Instruction::CleanupRet: {
3332 pushValue(CRI.getCleanupPad(), InstID, Vals);
3333 if (CRI.hasUnwindDest())
3337 case Instruction::CatchRet: {
3340 pushValue(CRI.getCatchPad(), InstID, Vals);
3344 case Instruction::CleanupPad:
3345 case Instruction::CatchPad: {
3349 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3351 unsigned NumArgOperands = FuncletPad.arg_size();
3353 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
3354 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
3357 case Instruction::CatchSwitch: {
3361 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3363 unsigned NumHandlers = CatchSwitch.getNumHandlers();
3365 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
3368 if (CatchSwitch.hasUnwindDest())
3372 case Instruction::CallBr: {
3378 writeOperandBundles(*CBI, InstID);
3393 pushValueAndType(Callee, InstID, Vals);
3396 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3397 pushValue(
I.getOperand(i), InstID, Vals);
3400 if (FTy->isVarArg()) {
3401 for (
unsigned i = FTy->getNumParams(), e = CBI->
arg_size(); i != e; ++i)
3402 pushValueAndType(
I.getOperand(i), InstID, Vals);
3406 case Instruction::Unreachable:
3408 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3411 case Instruction::PHI: {
3429 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
3434 case Instruction::LandingPad: {
3445 pushValueAndType(LP.
getClause(
I), InstID, Vals);
3450 case Instruction::Alloca: {
3456 using APV = AllocaPackedValues;
3457 unsigned Record = 0;
3458 unsigned EncodedAlign = getEncodedAlign(AI.
getAlign());
3460 Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3462 EncodedAlign >> APV::AlignLower::Bits);
3469 if (AS !=
M.getDataLayout().getAllocaAddrSpace())
3474 case Instruction::Load:
3477 pushValueAndType(
I.getOperand(0), InstID, Vals);
3480 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3481 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3491 case Instruction::Store:
3496 AbbrevToUse = FUNCTION_INST_STORE_ABBREV;
3498 if (pushValueAndType(
I.getOperand(1), InstID, Vals))
3500 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3510 case Instruction::AtomicCmpXchg:
3512 pushValueAndType(
I.getOperand(0), InstID, Vals);
3513 pushValueAndType(
I.getOperand(1), InstID, Vals);
3514 pushValue(
I.getOperand(2), InstID, Vals);
3525 case Instruction::AtomicRMW:
3527 pushValueAndType(
I.getOperand(0), InstID, Vals);
3528 pushValueAndType(
I.getOperand(1), InstID, Vals);
3537 case Instruction::Fence:
3542 case Instruction::Call: {
3547 writeOperandBundles(CI, InstID);
3567 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3571 if (FTy->isVarArg()) {
3572 for (
unsigned i = FTy->getNumParams(), e = CI.
arg_size(); i != e; ++i)
3577 case Instruction::VAArg:
3580 pushValue(
I.getOperand(0), InstID, Vals);
3583 case Instruction::Freeze:
3585 pushValueAndType(
I.getOperand(0), InstID, Vals);
3595void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3596 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3601 VSTOffset -= bitcodeStartBit();
3602 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
3606 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3610 auto Abbv = std::make_shared<BitCodeAbbrev>();
3614 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3616 for (
const Function &
F : M) {
3619 if (
F.isDeclaration())
3626 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
3627 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
3631 Record[1] = BitcodeIndex / 32 + 1;
3640void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3641 const ValueSymbolTable &VST) {
3649 SmallVector<uint64_t, 64> NameVals;
3655 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3664 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3668 AbbrevToUse = VST_ENTRY_6_ABBREV;
3670 AbbrevToUse = VST_ENTRY_7_ABBREV;
3673 for (
const auto P :
Name.getKey())
3677 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3684void ModuleBitcodeWriter::writeUseList(UseListOrder &&Order) {
3685 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3692 SmallVector<uint64_t, 64> Record(Order.Shuffle.begin(), Order.Shuffle.end());
3697void ModuleBitcodeWriter::writeUseListBlock(
const Function *
F) {
3699 "Expected to be preserving use-list order");
3701 auto hasMore = [&]() {
3717void ModuleBitcodeWriter::writeFunction(
3719 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3736 unsigned CstStart, CstEnd;
3738 writeConstants(CstStart, CstEnd,
false);
3741 writeFunctionMetadata(
F);
3744 unsigned InstID = CstEnd;
3746 bool NeedsMetadataAttachment =
F.hasMetadata();
3748 DILocation *LastDL =
nullptr;
3749 SmallSetVector<Function *, 4> BlockAddressUsers;
3752 for (
const BasicBlock &BB :
F) {
3753 for (
const Instruction &
I : BB) {
3754 writeInstruction(
I, InstID, Vals);
3756 if (!
I.getType()->isVoidTy())
3760 NeedsMetadataAttachment |=
I.hasMetadataOtherThanDebugLoc();
3763 if (DILocation *
DL =
I.getDebugLoc()) {
3776 FUNCTION_DEBUG_LOC_ABBREV);
3786 if (
I.hasDbgRecords()) {
3790 auto PushValueOrMetadata = [&Vals, InstID,
3793 "RawLocation unexpectedly null in DbgVariableRecord");
3795 SmallVector<unsigned, 2> ValAndType;
3799 if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
3813 for (DbgRecord &DR :
I.DebugMarker->getDbgRecordRange()) {
3839 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3860 SmallPtrSet<Value *, 8> Visited{BA};
3861 while (!Worklist.
empty()) {
3863 for (User *U :
V->users()) {
3869 Visited.
insert(U).second)
3876 if (!BlockAddressUsers.
empty()) {
3885 if (
auto *Symtab =
F.getValueSymbolTable())
3886 writeFunctionLevelValueSymbolTable(*Symtab);
3888 if (NeedsMetadataAttachment)
3889 writeFunctionMetadataAttachment(
F);
3891 writeUseListBlock(&
F);
3897void ModuleBitcodeWriter::writeBlockInfo() {
3910 auto Abbv = std::make_shared<BitCodeAbbrev>();
3921 auto Abbv = std::make_shared<BitCodeAbbrev>();
3931 auto Abbv = std::make_shared<BitCodeAbbrev>();
3941 auto Abbv = std::make_shared<BitCodeAbbrev>();
3947 VST_BBENTRY_6_ABBREV)
3952 auto Abbv = std::make_shared<BitCodeAbbrev>();
3954 Abbv->Add(TypeAbbrevOp);
3956 CONSTANTS_SETTYPE_ABBREV)
3961 auto Abbv = std::make_shared<BitCodeAbbrev>();
3965 CONSTANTS_INTEGER_ABBREV)
3970 auto Abbv = std::make_shared<BitCodeAbbrev>();
3978 CONSTANTS_CE_CAST_Abbrev)
3982 auto Abbv = std::make_shared<BitCodeAbbrev>();
3985 CONSTANTS_NULL_Abbrev)
3992 auto Abbv = std::make_shared<BitCodeAbbrev>();
3994 Abbv->Add(ValAbbrevOp);
3995 Abbv->Add(TypeAbbrevOp);
3999 FUNCTION_INST_LOAD_ABBREV)
4003 auto Abbv = std::make_shared<BitCodeAbbrev>();
4005 Abbv->Add(ValAbbrevOp);
4006 Abbv->Add(ValAbbrevOp);
4010 FUNCTION_INST_STORE_ABBREV)
4014 auto Abbv = std::make_shared<BitCodeAbbrev>();
4016 Abbv->Add(ValAbbrevOp);
4019 FUNCTION_INST_UNOP_ABBREV)
4023 auto Abbv = std::make_shared<BitCodeAbbrev>();
4025 Abbv->Add(ValAbbrevOp);
4029 FUNCTION_INST_UNOP_FLAGS_ABBREV)
4033 auto Abbv = std::make_shared<BitCodeAbbrev>();
4035 Abbv->Add(ValAbbrevOp);
4036 Abbv->Add(ValAbbrevOp);
4039 FUNCTION_INST_BINOP_ABBREV)
4043 auto Abbv = std::make_shared<BitCodeAbbrev>();
4045 Abbv->Add(ValAbbrevOp);
4046 Abbv->Add(ValAbbrevOp);
4050 FUNCTION_INST_BINOP_FLAGS_ABBREV)
4054 auto Abbv = std::make_shared<BitCodeAbbrev>();
4056 Abbv->Add(ValAbbrevOp);
4057 Abbv->Add(TypeAbbrevOp);
4060 FUNCTION_INST_CAST_ABBREV)
4064 auto Abbv = std::make_shared<BitCodeAbbrev>();
4066 Abbv->Add(ValAbbrevOp);
4067 Abbv->Add(TypeAbbrevOp);
4071 FUNCTION_INST_CAST_FLAGS_ABBREV)
4076 auto Abbv = std::make_shared<BitCodeAbbrev>();
4079 FUNCTION_INST_RET_VOID_ABBREV)
4083 auto Abbv = std::make_shared<BitCodeAbbrev>();
4085 Abbv->Add(ValAbbrevOp);
4087 FUNCTION_INST_RET_VAL_ABBREV)
4091 auto Abbv = std::make_shared<BitCodeAbbrev>();
4094 Abbv->Add(ValAbbrevOp);
4096 FUNCTION_INST_BR_UNCOND_ABBREV)
4100 auto Abbv = std::make_shared<BitCodeAbbrev>();
4103 Abbv->Add(ValAbbrevOp);
4104 Abbv->Add(ValAbbrevOp);
4105 Abbv->Add(ValAbbrevOp);
4107 FUNCTION_INST_BR_COND_ABBREV)
4111 auto Abbv = std::make_shared<BitCodeAbbrev>();
4114 FUNCTION_INST_UNREACHABLE_ABBREV)
4118 auto Abbv = std::make_shared<BitCodeAbbrev>();
4121 Abbv->Add(TypeAbbrevOp);
4123 Abbv->Add(ValAbbrevOp);
4125 FUNCTION_INST_GEP_ABBREV)
4129 auto Abbv = std::make_shared<BitCodeAbbrev>();
4131 Abbv->Add(ValAbbrevOp);
4132 Abbv->Add(ValAbbrevOp);
4135 FUNCTION_INST_CMP_ABBREV)
4139 auto Abbv = std::make_shared<BitCodeAbbrev>();
4141 Abbv->Add(ValAbbrevOp);
4142 Abbv->Add(ValAbbrevOp);
4146 FUNCTION_INST_CMP_FLAGS_ABBREV)
4150 auto Abbv = std::make_shared<BitCodeAbbrev>();
4155 Abbv->Add(ValAbbrevOp);
4157 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
4161 auto Abbv = std::make_shared<BitCodeAbbrev>();
4172 FUNCTION_DEBUG_LOC_ABBREV)
4180void IndexBitcodeWriter::writeModStrings() {
4186 auto Abbv = std::make_shared<BitCodeAbbrev>();
4191 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
4194 Abbv = std::make_shared<BitCodeAbbrev>();
4199 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
4202 Abbv = std::make_shared<BitCodeAbbrev>();
4207 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
4210 Abbv = std::make_shared<BitCodeAbbrev>();
4217 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
4220 forEachModule([&](
const StringMapEntry<ModuleHash> &MPSE) {
4222 const auto &Hash = MPSE.
getValue();
4224 unsigned AbbrevToUse = Abbrev8Bit;
4226 AbbrevToUse = Abbrev6Bit;
4228 AbbrevToUse = Abbrev7Bit;
4230 auto ModuleId = ModuleIdMap.
size();
4231 ModuleIdMap[
Key] = ModuleId;
4240 Vals.
assign(Hash.begin(), Hash.end());
4252template <
typename Fn>
4256 if (!FS->type_tests().empty())
4261 auto WriteVFuncIdVec = [&](
uint64_t Ty,
4266 for (
auto &VF : VFs) {
4267 Record.push_back(VF.GUID);
4268 Record.push_back(VF.Offset);
4274 FS->type_test_assume_vcalls());
4276 FS->type_checked_load_vcalls());
4278 auto WriteConstVCallVec = [&](
uint64_t Ty,
4280 for (
auto &VC : VCs) {
4282 Record.push_back(VC.VFunc.GUID);
4283 Record.push_back(VC.VFunc.Offset);
4290 FS->type_test_assume_const_vcalls());
4292 FS->type_checked_load_const_vcalls());
4302 if (!FS->paramAccesses().empty()) {
4304 for (
auto &Arg : FS->paramAccesses()) {
4305 size_t UndoSize =
Record.size();
4306 Record.push_back(Arg.ParamNo);
4307 WriteRange(Arg.Use);
4308 Record.push_back(Arg.Calls.size());
4309 for (
auto &
Call : Arg.Calls) {
4311 std::optional<unsigned> ValueID = GetValueID(
Call.Callee);
4318 Record.push_back(*ValueID);
4319 WriteRange(
Call.Offsets);
4330 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
4331 if (!FS->type_tests().empty())
4332 for (
auto &TT : FS->type_tests())
4333 ReferencedTypeIds.insert(TT);
4335 auto GetReferencedTypesFromVFuncIdVec =
4337 for (
auto &VF : VFs)
4338 ReferencedTypeIds.insert(VF.GUID);
4341 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4342 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4344 auto GetReferencedTypesFromConstVCallVec =
4346 for (
auto &VC : VCs)
4347 ReferencedTypeIds.insert(VC.VFunc.GUID);
4350 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4351 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
4387 NameVals.
push_back(Summary.TTRes.TheKind);
4388 NameVals.
push_back(Summary.TTRes.SizeM1BitWidth);
4389 NameVals.
push_back(Summary.TTRes.AlignLog2);
4390 NameVals.
push_back(Summary.TTRes.SizeM1);
4391 NameVals.
push_back(Summary.TTRes.BitMask);
4392 NameVals.
push_back(Summary.TTRes.InlineBits);
4394 for (
auto &W : Summary.WPDRes)
4406 for (
auto &
P : Summary) {
4408 NameVals.
push_back(
VE.getValueID(
P.VTableVI.getValue()));
4422 static_assert(std::is_same_v<LinearFrameId, unsigned>);
4423 for (
auto &AI : FS->allocs()) {
4424 for (
auto &MIB : AI.MIBs) {
4426 StackIdIndices.
reserve(MIB.StackIdIndices.size());
4427 for (
auto Id : MIB.StackIdIndices)
4428 StackIdIndices.
push_back(GetStackIndex(Id));
4430 CallStacks.insert({CallStacks.size(), StackIdIndices});
4443 assert(!CallStacks.empty());
4449 Builder.
build(std::move(CallStacks),
nullptr,
4453 return Builder.takeCallStackPos();
4458 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
bool PerModule,
4459 std::function<
unsigned(
const ValueInfo &VI)> GetValueID,
4460 std::function<
unsigned(
unsigned)> GetStackIndex,
4461 bool WriteContextSizeInfoIndex,
4466 for (
auto &CI : FS->callsites()) {
4470 assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4471 Record.push_back(GetValueID(CI.Callee));
4473 Record.push_back(CI.StackIdIndices.size());
4474 Record.push_back(CI.Clones.size());
4476 for (
auto Id : CI.StackIdIndices)
4477 Record.push_back(GetStackIndex(Id));
4485 for (
auto &AI : FS->allocs()) {
4489 assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4490 Record.push_back(AI.MIBs.size());
4492 Record.push_back(AI.Versions.size());
4493 for (
auto &MIB : AI.MIBs) {
4500 assert(CallStackCount <= CallStackPos.
size());
4501 Record.push_back(CallStackPos[CallStackCount++]);
4506 assert(AI.ContextSizeInfos.empty() ||
4507 AI.ContextSizeInfos.size() == AI.MIBs.size());
4509 if (WriteContextSizeInfoIndex && !AI.ContextSizeInfos.empty()) {
4517 ContextIds.
reserve(AI.ContextSizeInfos.size() * 2);
4518 for (
auto &Infos : AI.ContextSizeInfos) {
4519 Record.push_back(Infos.size());
4520 for (
auto [FullStackId, TotalSize] : Infos) {
4527 Record.push_back(TotalSize);
4545void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4546 SmallVector<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
4547 unsigned ValueID,
unsigned FSCallsRelBFAbbrev,
4548 unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
4549 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
const Function &
F,
4550 DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
4557 Stream, FS, [&](
const ValueInfo &VI) -> std::optional<unsigned> {
4562 Stream, FS, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
4564 [&](
const ValueInfo &VI) {
return getValueId(VI); },
4565 [&](
unsigned I) {
return I; },
4566 true, CallStackPos, CallStackCount);
4568 auto SpecialRefCnts =
FS->specialRefCounts();
4573 NameVals.
push_back(SpecialRefCnts.first);
4574 NameVals.
push_back(SpecialRefCnts.second);
4576 for (
auto &RI :
FS->refs())
4579 const bool UseRelBFRecord =
4582 for (
auto &ECI :
FS->calls()) {
4583 NameVals.
push_back(getValueId(ECI.first));
4591 (UseRelBFRecord ? FSCallsRelBFAbbrev : FSCallsProfileAbbrev);
4602void ModuleBitcodeWriterBase::writeModuleLevelReferences(
4603 const GlobalVariable &V, SmallVector<uint64_t, 64> &NameVals,
4604 unsigned FSModRefsAbbrev,
unsigned FSModVTableRefsAbbrev) {
4605 auto VI =
Index->getValueInfo(
V.getGUID());
4606 if (!VI ||
VI.getSummaryList().empty()) {
4612 auto *
Summary =
VI.getSummaryList()[0].get();
4618 auto VTableFuncs =
VS->vTableFuncs();
4619 if (!VTableFuncs.empty())
4622 unsigned SizeBeforeRefs = NameVals.
size();
4623 for (
auto &RI :
VS->refs())
4629 if (VTableFuncs.empty())
4634 for (
auto &
P : VTableFuncs) {
4640 FSModVTableRefsAbbrev);
4647void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
4650 bool IsThinLTO =
true;
4653 IsThinLTO = MD->getZExtValue();
4665 if (
Index->enableSplitLTOUnit())
4667 if (
Index->hasUnifiedLTO())
4677 auto Abbv = std::make_shared<BitCodeAbbrev>();
4683 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4685 for (
const auto &GVI : valueIds()) {
4687 ArrayRef<uint32_t>{GVI.second,
4688 static_cast<uint32_t
>(GVI.first >> 32),
4689 static_cast<uint32_t
>(GVI.first)},
4693 if (!
Index->stackIds().empty()) {
4694 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4701 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4702 SmallVector<uint32_t> Vals;
4704 for (
auto Id :
Index->stackIds()) {
4705 Vals.
push_back(
static_cast<uint32_t
>(Id >> 32));
4706 Vals.
push_back(
static_cast<uint32_t
>(Id));
4711 unsigned ContextIdAbbvId = 0;
4714 auto ContextIdAbbv = std::make_shared<BitCodeAbbrev>();
4726 ContextIdAbbvId = Stream.
EmitAbbrev(std::move(ContextIdAbbv));
4730 Abbv = std::make_shared<BitCodeAbbrev>();
4742 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4745 Abbv = std::make_shared<BitCodeAbbrev>();
4757 unsigned FSCallsRelBFAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4760 Abbv = std::make_shared<BitCodeAbbrev>();
4766 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4769 Abbv = std::make_shared<BitCodeAbbrev>();
4777 unsigned FSModVTableRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4780 Abbv = std::make_shared<BitCodeAbbrev>();
4785 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4788 Abbv = std::make_shared<BitCodeAbbrev>();
4795 unsigned TypeIdCompatibleVtableAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4797 Abbv = std::make_shared<BitCodeAbbrev>();
4803 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4805 Abbv = std::make_shared<BitCodeAbbrev>();
4812 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4814 Abbv = std::make_shared<BitCodeAbbrev>();
4819 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4826 MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
4827 for (
const Function &
F : M) {
4833 ValueInfo
VI =
Index->getValueInfo(
F.getGUID());
4834 if (!VI ||
VI.getSummaryList().empty()) {
4840 auto *
Summary =
VI.getSummaryList()[0].get();
4843 FS, [](
unsigned I) {
return I; }, CallStacks);
4847 DenseMap<CallStackId, LinearCallStackId> CallStackPos;
4848 if (!CallStacks.
empty()) {
4856 SmallVector<uint64_t, 64> NameVals;
4859 for (
const Function &
F : M) {
4865 ValueInfo
VI =
Index->getValueInfo(
F.getGUID());
4866 if (!VI ||
VI.getSummaryList().empty()) {
4872 auto *
Summary =
VI.getSummaryList()[0].get();
4873 writePerModuleFunctionSummaryRecord(
4874 NameVals, Summary, VE.
getValueID(&
F), FSCallsRelBFAbbrev,
4875 FSCallsProfileAbbrev, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
F,
4876 CallStackPos, CallStackCount);
4881 for (
const GlobalVariable &
G :
M.globals())
4882 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev,
4883 FSModVTableRefsAbbrev);
4885 for (
const GlobalAlias &
A :
M.aliases()) {
4886 auto *Aliasee =
A.getAliaseeObject();
4902 for (
auto &S :
Index->typeIdCompatibleVtableMap()) {
4906 TypeIdCompatibleVtableAbbrev);
4910 if (
Index->getBlockCount())
4912 ArrayRef<uint64_t>{
Index->getBlockCount()});
4918void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4927 auto Abbv = std::make_shared<BitCodeAbbrev>();
4933 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4935 for (
const auto &GVI : valueIds()) {
4937 ArrayRef<uint32_t>{GVI.second,
4938 static_cast<uint32_t
>(GVI.first >> 32),
4939 static_cast<uint32_t
>(GVI.first)},
4945 if (!StackIds.empty()) {
4946 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4953 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4954 SmallVector<uint32_t> Vals;
4955 Vals.
reserve(StackIds.size() * 2);
4956 for (
auto Id : StackIds) {
4957 Vals.
push_back(
static_cast<uint32_t
>(Id >> 32));
4958 Vals.
push_back(
static_cast<uint32_t
>(Id));
4964 Abbv = std::make_shared<BitCodeAbbrev>();
4978 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4981 Abbv = std::make_shared<BitCodeAbbrev>();
4988 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4991 Abbv = std::make_shared<BitCodeAbbrev>();
4997 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4999 Abbv = std::make_shared<BitCodeAbbrev>();
5007 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5009 Abbv = std::make_shared<BitCodeAbbrev>();
5020 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5022 auto shouldImportValueAsDecl = [&](GlobalValueSummary *GVS) ->
bool {
5023 if (DecSummaries ==
nullptr)
5025 return DecSummaries->count(GVS);
5033 DenseMap<const GlobalValueSummary *, unsigned> SummaryToValueIdMap;
5035 SmallVector<uint64_t, 64> NameVals;
5039 std::set<GlobalValue::GUID> ReferencedTypeIds;
5043 auto MaybeEmitOriginalName = [&](GlobalValueSummary &S) {
5053 NameVals.
push_back(S.getOriginalName());
5058 DenseMap<CallStackId, LinearCallStackId> CallStackPos;
5060 Abbv = std::make_shared<BitCodeAbbrev>();
5065 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5072 MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
5073 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5079 GlobalValueSummary *S =
I.second;
5092 return StackIdIndicesToIndex[
I];
5098 if (!CallStacks.
empty()) {
5108 DenseSet<GlobalValue::GUID> DefOrUseGUIDs;
5109 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5110 GlobalValueSummary *S =
I.second;
5112 DefOrUseGUIDs.
insert(
I.first);
5113 for (
const ValueInfo &VI : S->
refs())
5114 DefOrUseGUIDs.
insert(
VI.getGUID());
5116 auto ValueId = getValueId(
I.first);
5118 SummaryToValueIdMap[S] = *ValueId;
5136 NameVals.
push_back(ModuleIdMap[
VS->modulePath()]);
5140 for (
auto &RI :
VS->refs()) {
5141 auto RefValueId = getValueId(RI.getGUID());
5151 MaybeEmitOriginalName(*S);
5155 auto GetValueId = [&](
const ValueInfo &
VI) -> std::optional<unsigned> {
5157 return std::nullopt;
5158 return getValueId(
VI.getGUID());
5166 Stream, FS, CallsiteAbbrev, AllocAbbrev, 0,
5169 [&](
const ValueInfo &VI) ->
unsigned {
5170 std::optional<unsigned> ValueID = GetValueId(VI);
5185 return StackIdIndicesToIndex[
I];
5187 false, CallStackPos, CallStackCount);
5191 NameVals.
push_back(ModuleIdMap[
FS->modulePath()]);
5204 unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
5205 for (
auto &RI :
FS->refs()) {
5206 auto RefValueId = getValueId(RI.getGUID());
5210 if (RI.isReadOnly())
5212 else if (RI.isWriteOnly())
5216 NameVals[6] =
Count;
5217 NameVals[7] = RORefCnt;
5218 NameVals[8] = WORefCnt;
5220 for (
auto &EI :
FS->calls()) {
5223 std::optional<unsigned> CallValueId = GetValueId(EI.first);
5232 FSCallsProfileAbbrev);
5234 MaybeEmitOriginalName(*S);
5237 for (
auto *AS : Aliases) {
5238 auto AliasValueId = SummaryToValueIdMap[AS];
5245 auto AliaseeValueId = SummaryToValueIdMap[&AS->
getAliasee()];
5252 MaybeEmitOriginalName(*AS);
5259 auto EmitCfiFunctions = [&](
const CfiFunctionIndex &CfiIndex,
5261 if (CfiIndex.
empty())
5264 auto Defs = CfiIndex.
forGuid(GUID);
5267 if (Functions.
empty())
5270 for (
const auto &S : Functions) {
5284 for (
auto &
T : ReferencedTypeIds) {
5285 auto TidIter =
Index.typeIds().equal_range(
T);
5286 for (
const auto &[GUID, TypeIdPair] :
make_range(TidIter)) {
5294 if (
Index.getBlockCount())
5296 ArrayRef<uint64_t>{
Index.getBlockCount()});
5307 auto Abbv = std::make_shared<BitCodeAbbrev>();
5311 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5313 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
5316 Abbv = std::make_shared<BitCodeAbbrev>();
5319 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5325void ModuleBitcodeWriter::writeModuleHash(StringRef View) {
5330 Hasher.
update(ArrayRef<uint8_t>(
5331 reinterpret_cast<const uint8_t *
>(
View.data()),
View.size()));
5332 std::array<uint8_t, 20> Hash = Hasher.
result();
5333 for (
int Pos = 0; Pos < 20; Pos += 4) {
5346void ModuleBitcodeWriter::write() {
5354 writeModuleVersion();
5363 writeAttributeGroupTable();
5366 writeAttributeTable();
5375 writeModuleConstants();
5378 writeModuleMetadataKinds();
5381 writeModuleMetadata();
5385 writeUseListBlock(
nullptr);
5387 writeOperandBundleTags();
5388 writeSyncScopeNames();
5391 DenseMap<const Function *, uint64_t> FunctionToBitcodeIndex;
5392 for (
const Function &
F : M)
5393 if (!
F.isDeclaration())
5394 writeFunction(
F, FunctionToBitcodeIndex);
5399 writePerModuleGlobalValueSummary();
5401 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
5429 unsigned CPUType = ~0U;
5436 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
5437 DARWIN_CPU_TYPE_X86 = 7,
5438 DARWIN_CPU_TYPE_ARM = 12,
5439 DARWIN_CPU_TYPE_POWERPC = 18
5444 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
5446 CPUType = DARWIN_CPU_TYPE_X86;
5448 CPUType = DARWIN_CPU_TYPE_POWERPC;
5450 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
5452 CPUType = DARWIN_CPU_TYPE_ARM;
5456 "Expected header size to be reserved");
5461 unsigned Position = 0;
5469 while (Buffer.
size() & 15)
5476 Stream.
Emit((
unsigned)
'B', 8);
5477 Stream.
Emit((
unsigned)
'C', 8);
5478 Stream.
Emit(0x0, 4);
5479 Stream.
Emit(0xC, 4);
5480 Stream.
Emit(0xE, 4);
5481 Stream.
Emit(0xD, 4);
5499 auto Abbv = std::make_shared<BitCodeAbbrev>();
5502 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
5510 assert(!WroteStrtab && !WroteSymtab);
5516 if (M->getModuleInlineAsm().empty())
5520 const Triple TT(M->getTargetTriple());
5522 if (!
T || !
T->hasMCAsmParser())
5544 std::vector<char> Strtab;
5545 StrtabBuilder.finalizeInOrder();
5546 Strtab.resize(StrtabBuilder.getSize());
5547 StrtabBuilder.write((
uint8_t *)Strtab.data());
5550 {Strtab.data(), Strtab.size()});
5561 bool ShouldPreserveUseListOrder,
5570 assert(M.isMaterialized());
5571 Mods.push_back(
const_cast<Module *
>(&M));
5573 ModuleBitcodeWriter ModuleWriter(M, StrtabBuilder, *Stream,
5574 ShouldPreserveUseListOrder, Index,
5575 GenerateHash, ModHash);
5576 ModuleWriter.write();
5583 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, DecSummaries,
5584 ModuleToSummariesForIndex);
5585 IndexWriter.write();
5590 bool ShouldPreserveUseListOrder,
5594 Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
5596 Writer.writeSymtab();
5597 Writer.writeStrtab();
5599 Triple TT(M.getTargetTriple());
5600 if (TT.isOSDarwin() || TT.isOSBinFormatMachO()) {
5618void IndexBitcodeWriter::write() {
5621 writeModuleVersion();
5627 writeCombinedGlobalValueSummary();
5644 Writer.
writeIndex(&Index, ModuleToSummariesForIndex, DecSummaries);
5653class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
5663 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5665 ModHash(&ModHash) {}
5670 void writeSimplifiedModuleInfo();
5680void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5692 auto Abbv = std::make_shared<BitCodeAbbrev>();
5695 Abbv->Add(AbbrevOpToUse);
5696 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5698 for (
const auto P :
M.getSourceFileName())
5762void ThinLinkBitcodeWriter::write() {
5765 writeModuleVersion();
5767 writeSimplifiedModuleInfo();
5769 writePerModuleGlobalValueSummary();
5786 assert(M.isMaterialized());
5787 Mods.push_back(
const_cast<Module *
>(&M));
5789 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream, Index,
5791 ThinLinkWriter.write();
5812 switch (
T.getObjectFormat()) {
5814 return "__LLVM,__bitcode";
5839 switch (
T.getObjectFormat()) {
5841 return "__LLVM,__cmdline";
5867 const std::vector<uint8_t> &CmdArgs) {
5872 Type *UsedElementType = Used ? Used->getValueType()->getArrayElementType()
5874 for (
auto *GV : UsedGlobals) {
5875 if (GV->getName() !=
"llvm.embedded.module" &&
5876 GV->getName() !=
"llvm.cmdline")
5881 Used->eraseFromParent();
5886 Triple T(M.getTargetTriple());
5915 M.getGlobalVariable(
"llvm.embedded.module",
true)) {
5916 assert(Old->hasZeroLiveUses() &&
5917 "llvm.embedded.module can only be used once in llvm.compiler.used");
5919 Old->eraseFromParent();
5921 GV->
setName(
"llvm.embedded.module");
5939 assert(Old->hasZeroLiveUses() &&
5940 "llvm.cmdline can only be used once in llvm.compiler.used");
5942 Old->eraseFromParent();
5948 if (UsedArray.
empty())
5956 NewUsed->setSection(
"llvm.metadata");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void writeDIMacro(raw_ostream &Out, const DIMacro *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, AsmWriterContext &WriterCtx)
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, AsmWriterContext &WriterCtx)
static void writeDIFixedPointType(raw_ostream &Out, const DIFixedPointType *N, AsmWriterContext &WriterCtx)
static void writeDISubrangeType(raw_ostream &Out, const DISubrangeType *N, AsmWriterContext &WriterCtx)
static void writeDIStringType(raw_ostream &Out, const DIStringType *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, AsmWriterContext &WriterCtx)
static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, AsmWriterContext &WriterCtx)
static void writeDIModule(raw_ostream &Out, const DIModule *N, AsmWriterContext &WriterCtx)
static void writeDIFile(raw_ostream &Out, const DIFile *N, AsmWriterContext &)
static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, AsmWriterContext &WriterCtx)
static void writeDILabel(raw_ostream &Out, const DILabel *N, AsmWriterContext &WriterCtx)
static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, AsmWriterContext &WriterCtx)
static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, AsmWriterContext &WriterCtx)
static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, AsmWriterContext &WriterCtx)
static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, AsmWriterContext &WriterCtx)
static void writeDILocation(raw_ostream &Out, const DILocation *DL, AsmWriterContext &WriterCtx)
static void writeDINamespace(raw_ostream &Out, const DINamespace *N, AsmWriterContext &WriterCtx)
static void writeDICommonBlock(raw_ostream &Out, const DICommonBlock *N, AsmWriterContext &WriterCtx)
static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, AsmWriterContext &WriterCtx)
static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, AsmWriterContext &WriterCtx)
static void writeDITemplateTypeParameter(raw_ostream &Out, const DITemplateTypeParameter *N, AsmWriterContext &WriterCtx)
static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, AsmWriterContext &WriterCtx)
static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N, AsmWriterContext &WriterCtx)
static void writeDISubrange(raw_ostream &Out, const DISubrange *N, AsmWriterContext &WriterCtx)
static void writeDILexicalBlockFile(raw_ostream &Out, const DILexicalBlockFile *N, AsmWriterContext &WriterCtx)
static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, AsmWriterContext &)
static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, AsmWriterContext &WriterCtx)
static void writeDIExpression(raw_ostream &Out, const DIExpression *N, AsmWriterContext &WriterCtx)
static void writeDIAssignID(raw_ostream &Out, const DIAssignID *DL, AsmWriterContext &WriterCtx)
static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, AsmWriterContext &WriterCtx)
static void writeDIArgList(raw_ostream &Out, const DIArgList *N, AsmWriterContext &WriterCtx, bool FromValue=false)
static void writeDITemplateValueParameter(raw_ostream &Out, const DITemplateValueParameter *N, AsmWriterContext &WriterCtx)
static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, AsmWriterContext &WriterCtx)
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static void writeFunctionHeapProfileRecords(BitstreamWriter &Stream, FunctionSummary *FS, unsigned CallsiteAbbrev, unsigned AllocAbbrev, unsigned ContextIdAbbvId, bool PerModule, std::function< unsigned(const ValueInfo &VI)> GetValueID, std::function< unsigned(unsigned)> GetStackIndex, bool WriteContextSizeInfoIndex, DenseMap< CallStackId, LinearCallStackId > &CallStackPos, CallStackId &CallStackCount)
static unsigned serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta)
static void writeTypeIdCompatibleVtableSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdCompatibleVtableInfo &Summary, ValueEnumerator &VE)
static void getReferencedTypeIds(FunctionSummary *FS, std::set< GlobalValue::GUID > &ReferencedTypeIds)
Collect type IDs from type tests used by function.
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
static void collectMemProfCallStacks(FunctionSummary *FS, std::function< LinearFrameId(unsigned)> GetStackIndex, MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &CallStacks)
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
static unsigned getEncodedVisibility(const GlobalValue &GV)
static uint64_t getOptimizationFlags(const Value *V)
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
static cl::opt< bool > PreserveBitcodeUseListOrder("preserve-bc-uselistorder", cl::Hidden, cl::init(true), cl::desc("Preserve use-list order when writing LLVM bitcode."))
static unsigned 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_SANITIZE_ALLOC_TOKEN
@ 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