33#include "llvm/Config/llvm-config.h"
95 cl::desc(
"Number of metadatas above which we emit an index "
96 "to enable lazy-loading"));
99 cl::desc(
"The threshold (unit M) for flushing LLVM bitcode."));
103 cl::desc(
"Write relative block frequency to function summary "));
134 VST_BBENTRY_6_ABBREV,
138 CONSTANTS_INTEGER_ABBREV,
139 CONSTANTS_CE_CAST_Abbrev,
140 CONSTANTS_NULL_Abbrev,
144 FUNCTION_INST_STORE_ABBREV,
145 FUNCTION_INST_UNOP_ABBREV,
146 FUNCTION_INST_UNOP_FLAGS_ABBREV,
147 FUNCTION_INST_BINOP_ABBREV,
148 FUNCTION_INST_BINOP_FLAGS_ABBREV,
149 FUNCTION_INST_CAST_ABBREV,
150 FUNCTION_INST_CAST_FLAGS_ABBREV,
151 FUNCTION_INST_RET_VOID_ABBREV,
152 FUNCTION_INST_RET_VAL_ABBREV,
153 FUNCTION_INST_BR_UNCOND_ABBREV,
154 FUNCTION_INST_BR_COND_ABBREV,
155 FUNCTION_INST_UNREACHABLE_ABBREV,
156 FUNCTION_INST_GEP_ABBREV,
157 FUNCTION_INST_CMP_ABBREV,
158 FUNCTION_INST_CMP_FLAGS_ABBREV,
159 FUNCTION_DEBUG_RECORD_VALUE_ABBREV,
160 FUNCTION_DEBUG_LOC_ABBREV,
165class BitcodeWriterBase {
168 BitstreamWriter &Stream;
170 StringTableBuilder &StrtabBuilder;
175 BitcodeWriterBase(BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder)
176 : Stream(Stream), StrtabBuilder(StrtabBuilder) {}
179 void writeModuleVersion();
182void BitcodeWriterBase::writeModuleVersion() {
189class ModuleBitcodeWriterBase :
public BitcodeWriterBase {
198 const ModuleSummaryIndex *Index;
203 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
206 unsigned GlobalValueId;
210 uint64_t VSTOffsetPlaceholder = 0;
215 ModuleBitcodeWriterBase(
const Module &M, StringTableBuilder &StrtabBuilder,
216 BitstreamWriter &Stream,
217 bool ShouldPreserveUseListOrder,
218 const ModuleSummaryIndex *Index)
219 : BitcodeWriterBase(Stream, StrtabBuilder),
M(
M),
229 for (
const auto &GUIDSummaryLists : *Index)
231 for (
auto &Summary : GUIDSummaryLists.second.SummaryList)
237 for (auto &CallEdge : FS->calls())
238 if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
239 assignValueId(CallEdge.first.getGUID());
245 for (auto &RefEdge : FS->refs())
246 if (!RefEdge.haveGVs() || !RefEdge.getValue())
247 assignValueId(RefEdge.getGUID());
252 void writePerModuleGlobalValueSummary();
255 void writePerModuleFunctionSummaryRecord(
256 SmallVector<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
257 unsigned ValueID,
unsigned FSCallsAbbrev,
unsigned FSCallsProfileAbbrev,
258 unsigned CallsiteAbbrev,
unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
259 const Function &
F, DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
261 void writeModuleLevelReferences(
const GlobalVariable &V,
262 SmallVector<uint64_t, 64> &NameVals,
263 unsigned FSModRefsAbbrev,
264 unsigned FSModVTableRefsAbbrev);
267 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
271 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
274 assert(VMI != GUIDToValueIdMap.end() &&
275 "GUID does not have assigned value Id");
280 unsigned getValueId(ValueInfo VI) {
281 if (!
VI.haveGVs() || !
VI.getValue())
282 return getValueId(
VI.getGUID());
286 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
290class ModuleBitcodeWriter :
public ModuleBitcodeWriterBase {
301 uint64_t BitcodeStartBit;
306 ModuleBitcodeWriter(
const Module &M, StringTableBuilder &StrtabBuilder,
307 BitstreamWriter &Stream,
bool ShouldPreserveUseListOrder,
308 const ModuleSummaryIndex *Index,
bool GenerateHash,
310 : ModuleBitcodeWriterBase(
M, StrtabBuilder, Stream,
311 ShouldPreserveUseListOrder,
Index),
312 GenerateHash(GenerateHash), ModHash(ModHash),
313 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
319 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
321 size_t addToStrtab(StringRef Str);
323 void writeAttributeGroupTable();
324 void writeAttributeTable();
325 void writeTypeTable();
327 void writeValueSymbolTableForwardDecl();
328 void writeModuleInfo();
329 void writeValueAsMetadata(
const ValueAsMetadata *MD,
330 SmallVectorImpl<uint64_t> &Record);
331 void writeMDTuple(
const MDTuple *
N, SmallVectorImpl<uint64_t> &Record,
333 unsigned createDILocationAbbrev();
334 void writeDILocation(
const DILocation *
N, SmallVectorImpl<uint64_t> &Record,
336 unsigned createGenericDINodeAbbrev();
338 SmallVectorImpl<uint64_t> &Record,
unsigned &Abbrev);
339 void writeDISubrange(
const DISubrange *
N, SmallVectorImpl<uint64_t> &Record,
342 SmallVectorImpl<uint64_t> &Record,
345 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
349 SmallVectorImpl<uint64_t> &Record,
352 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
354 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
356 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
358 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
360 SmallVectorImpl<uint64_t> &Record,
362 void writeDIFile(
const DIFile *
N, SmallVectorImpl<uint64_t> &Record,
365 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
367 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
369 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
371 SmallVectorImpl<uint64_t> &Record,
374 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
377 void writeDIMacro(
const DIMacro *
N, SmallVectorImpl<uint64_t> &Record,
381 void writeDIArgList(
const DIArgList *
N, SmallVectorImpl<uint64_t> &Record);
382 void writeDIModule(
const DIModule *
N, SmallVectorImpl<uint64_t> &Record,
384 void writeDIAssignID(
const DIAssignID *
N, SmallVectorImpl<uint64_t> &Record,
387 SmallVectorImpl<uint64_t> &Record,
390 SmallVectorImpl<uint64_t> &Record,
393 SmallVectorImpl<uint64_t> &Record,
396 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
398 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
400 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
402 SmallVectorImpl<uint64_t> &Record,
405 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
407 SmallVectorImpl<uint64_t> &Record,
409 unsigned createNamedMetadataAbbrev();
410 void writeNamedMetadata(SmallVectorImpl<uint64_t> &Record);
411 unsigned createMetadataStringsAbbrev();
413 SmallVectorImpl<uint64_t> &Record);
415 SmallVectorImpl<uint64_t> &Record,
416 std::vector<unsigned> *MDAbbrevs =
nullptr,
417 std::vector<uint64_t> *IndexPos =
nullptr);
418 void writeModuleMetadata();
419 void writeFunctionMetadata(
const Function &
F);
420 void writeFunctionMetadataAttachment(
const Function &
F);
421 void pushGlobalMetadataAttachment(SmallVectorImpl<uint64_t> &Record,
422 const GlobalObject &GO);
423 void writeModuleMetadataKinds();
424 void writeOperandBundleTags();
425 void writeSyncScopeNames();
426 void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
427 void writeModuleConstants();
428 bool pushValueAndType(
const Value *V,
unsigned InstID,
429 SmallVectorImpl<unsigned> &Vals);
430 bool pushValueOrMetadata(
const Value *V,
unsigned InstID,
431 SmallVectorImpl<unsigned> &Vals);
432 void writeOperandBundles(
const CallBase &CB,
unsigned InstID);
433 void pushValue(
const Value *V,
unsigned InstID,
434 SmallVectorImpl<unsigned> &Vals);
435 void pushValueSigned(
const Value *V,
unsigned InstID,
436 SmallVectorImpl<uint64_t> &Vals);
437 void writeInstruction(
const Instruction &
I,
unsigned InstID,
438 SmallVectorImpl<unsigned> &Vals);
439 void writeFunctionLevelValueSymbolTable(
const ValueSymbolTable &VST);
440 void writeGlobalValueSymbolTable(
441 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
442 void writeUseList(UseListOrder &&Order);
443 void writeUseListBlock(
const Function *
F);
445 writeFunction(
const Function &
F,
446 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
447 void writeBlockInfo();
448 void writeModuleHash(StringRef View);
451 return unsigned(SSID);
454 unsigned getEncodedAlign(MaybeAlign Alignment) {
return encode(Alignment); }
458class IndexBitcodeWriter :
public BitcodeWriterBase {
460 const ModuleSummaryIndex &
Index;
473 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
477 std::vector<uint64_t> StackIds;
482 DenseMap<unsigned, unsigned> StackIdIndicesToIndex;
485 unsigned GlobalValueId = 0;
489 DenseMap<StringRef, uint64_t> ModuleIdMap;
499 BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder,
500 const ModuleSummaryIndex &Index,
503 : BitcodeWriterBase(Stream, StrtabBuilder),
Index(
Index),
504 DecSummaries(DecSummaries),
505 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
509 auto RecordStackIdReference = [&](
unsigned StackIdIndex) {
514 StackIdIndicesToIndex.
insert({StackIdIndex, StackIds.size()});
516 StackIds.push_back(
Index.getStackIdAtIndex(StackIdIndex));
523 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
524 GUIDToValueIdMap[
I.first] = ++GlobalValueId;
536 for (
auto &CI :
FS->callsites()) {
547 if (CI.StackIdIndices.empty()) {
548 GUIDToValueIdMap[CI.Callee.getGUID()] = ++GlobalValueId;
551 for (
auto Idx : CI.StackIdIndices)
552 RecordStackIdReference(Idx);
555 for (
auto &AI :
FS->allocs())
556 for (
auto &MIB : AI.MIBs)
557 for (
auto Idx : MIB.StackIdIndices)
558 RecordStackIdReference(Idx);
564 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
569 template<
typename Functor>
570 void forEachSummary(Functor Callback) {
571 if (ModuleToSummariesForIndex) {
572 for (
auto &M : *ModuleToSummariesForIndex)
573 for (
auto &Summary :
M.second) {
579 Callback({AS->getAliaseeGUID(), &AS->getAliasee()},
true);
582 for (
auto &Summaries : Index)
583 for (
auto &Summary : Summaries.second.SummaryList)
592 template <
typename Functor>
void forEachModule(Functor Callback) {
593 if (ModuleToSummariesForIndex) {
594 for (
const auto &M : *ModuleToSummariesForIndex) {
595 const auto &MPI =
Index.modulePaths().find(
M.first);
596 if (MPI ==
Index.modulePaths().end()) {
600 assert(ModuleToSummariesForIndex->size() == 1);
610 std::vector<StringRef> ModulePaths;
611 for (
auto &[ModPath,
_] :
Index.modulePaths())
612 ModulePaths.push_back(ModPath);
614 for (
auto &ModPath : ModulePaths)
623 void writeModStrings();
624 void writeCombinedGlobalValueSummary();
627 auto VMI = GUIDToValueIdMap.find(ValGUID);
628 if (VMI == GUIDToValueIdMap.end())
633 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
668 case Instruction::Add:
670 case Instruction::Sub:
672 case Instruction::Mul:
675 case Instruction::FDiv:
678 case Instruction::FRem:
752 case Attribute::Alignment:
754 case Attribute::AllocAlign:
756 case Attribute::AllocSize:
758 case Attribute::AlwaysInline:
760 case Attribute::Builtin:
762 case Attribute::ByVal:
764 case Attribute::Convergent:
766 case Attribute::InAlloca:
768 case Attribute::Cold:
770 case Attribute::DisableSanitizerInstrumentation:
772 case Attribute::FnRetThunkExtern:
776 case Attribute::ElementType:
778 case Attribute::HybridPatchable:
780 case Attribute::InlineHint:
782 case Attribute::InReg:
784 case Attribute::JumpTable:
786 case Attribute::MinSize:
788 case Attribute::AllocatedPointer:
790 case Attribute::AllocKind:
792 case Attribute::Memory:
794 case Attribute::NoFPClass:
796 case Attribute::Naked:
798 case Attribute::Nest:
800 case Attribute::NoAlias:
802 case Attribute::NoBuiltin:
804 case Attribute::NoCallback:
806 case Attribute::NoDivergenceSource:
808 case Attribute::NoDuplicate:
810 case Attribute::NoFree:
812 case Attribute::NoImplicitFloat:
814 case Attribute::NoInline:
816 case Attribute::NoRecurse:
818 case Attribute::NoMerge:
820 case Attribute::NonLazyBind:
822 case Attribute::NonNull:
824 case Attribute::Dereferenceable:
826 case Attribute::DereferenceableOrNull:
828 case Attribute::NoRedZone:
830 case Attribute::NoReturn:
832 case Attribute::NoSync:
834 case Attribute::NoCfCheck:
836 case Attribute::NoProfile:
838 case Attribute::SkipProfile:
840 case Attribute::NoUnwind:
842 case Attribute::NoSanitizeBounds:
844 case Attribute::NoSanitizeCoverage:
846 case Attribute::NullPointerIsValid:
848 case Attribute::OptimizeForDebugging:
850 case Attribute::OptForFuzzing:
852 case Attribute::OptimizeForSize:
854 case Attribute::OptimizeNone:
856 case Attribute::ReadNone:
858 case Attribute::ReadOnly:
860 case Attribute::Returned:
862 case Attribute::ReturnsTwice:
864 case Attribute::SExt:
866 case Attribute::Speculatable:
868 case Attribute::StackAlignment:
870 case Attribute::StackProtect:
872 case Attribute::StackProtectReq:
874 case Attribute::StackProtectStrong:
876 case Attribute::SafeStack:
878 case Attribute::ShadowCallStack:
880 case Attribute::StrictFP:
882 case Attribute::StructRet:
884 case Attribute::SanitizeAddress:
886 case Attribute::SanitizeAllocToken:
888 case Attribute::SanitizeHWAddress:
890 case Attribute::SanitizeThread:
892 case Attribute::SanitizeType:
894 case Attribute::SanitizeMemory:
896 case Attribute::SanitizeNumericalStability:
898 case Attribute::SanitizeRealtime:
900 case Attribute::SanitizeRealtimeBlocking:
902 case Attribute::SpeculativeLoadHardening:
904 case Attribute::SwiftError:
906 case Attribute::SwiftSelf:
908 case Attribute::SwiftAsync:
910 case Attribute::UWTable:
912 case Attribute::VScaleRange:
914 case Attribute::WillReturn:
916 case Attribute::WriteOnly:
918 case Attribute::ZExt:
920 case Attribute::ImmArg:
922 case Attribute::SanitizeMemTag:
924 case Attribute::Preallocated:
926 case Attribute::NoUndef:
928 case Attribute::ByRef:
930 case Attribute::MustProgress:
932 case Attribute::PresplitCoroutine:
934 case Attribute::Writable:
936 case Attribute::CoroDestroyOnlyWhenComplete:
938 case Attribute::CoroElideSafe:
940 case Attribute::DeadOnUnwind:
942 case Attribute::Range:
944 case Attribute::Initializes:
946 case Attribute::NoExt:
948 case Attribute::Captures:
950 case Attribute::DeadOnReturn:
976 unsigned NumWords =
A.getActiveWords();
977 const uint64_t *RawData =
A.getRawData();
978 for (
unsigned i = 0; i < NumWords; i++)
998void ModuleBitcodeWriter::writeAttributeGroupTable() {
999 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
1001 if (AttrGrps.empty())
return;
1005 SmallVector<uint64_t, 64> Record;
1007 unsigned AttrListIndex = Pair.first;
1008 AttributeSet AS = Pair.second;
1013 if (Attr.isEnumAttribute()) {
1016 }
else if (Attr.isIntAttribute()) {
1018 Attribute::AttrKind
Kind = Attr.getKindAsEnum();
1020 if (Kind == Attribute::Memory) {
1027 }
else if (Attr.isStringAttribute()) {
1028 StringRef
Kind = Attr.getKindAsString();
1029 StringRef Val = Attr.getValueAsString();
1038 }
else if (Attr.isTypeAttribute()) {
1039 Type *Ty = Attr.getValueAsType();
1044 }
else if (Attr.isConstantRangeAttribute()) {
1050 assert(Attr.isConstantRangeListAttribute());
1056 for (
auto &CR : Val)
1068void ModuleBitcodeWriter::writeAttributeTable() {
1070 if (
Attrs.empty())
return;
1074 SmallVector<uint64_t, 64> Record;
1075 for (
const AttributeList &AL : Attrs) {
1076 for (
unsigned i :
AL.indexes()) {
1077 AttributeSet AS =
AL.getAttributes(i);
1090void ModuleBitcodeWriter::writeTypeTable() {
1094 SmallVector<uint64_t, 64> TypeVals;
1099 auto Abbv = std::make_shared<BitCodeAbbrev>();
1101 Abbv->Add(BitCodeAbbrevOp(0));
1102 unsigned OpaquePtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1105 Abbv = std::make_shared<BitCodeAbbrev>();
1110 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1113 Abbv = std::make_shared<BitCodeAbbrev>();
1118 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1121 Abbv = std::make_shared<BitCodeAbbrev>();
1125 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1128 Abbv = std::make_shared<BitCodeAbbrev>();
1133 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1136 Abbv = std::make_shared<BitCodeAbbrev>();
1140 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1148 for (
Type *
T : TypeList) {
1149 int AbbrevToUse = 0;
1152 switch (
T->getTypeID()) {
1162 case Type::MetadataTyID:
1167 case Type::IntegerTyID:
1172 case Type::PointerTyID: {
1179 AbbrevToUse = OpaquePtrAbbrev;
1182 case Type::FunctionTyID: {
1188 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1190 AbbrevToUse = FunctionAbbrev;
1193 case Type::StructTyID: {
1198 for (
Type *ET :
ST->elements())
1201 if (
ST->isLiteral()) {
1203 AbbrevToUse = StructAnonAbbrev;
1205 if (
ST->isOpaque()) {
1209 AbbrevToUse = StructNamedAbbrev;
1213 if (!
ST->getName().empty())
1219 case Type::ArrayTyID: {
1223 TypeVals.
push_back(AT->getNumElements());
1225 AbbrevToUse = ArrayAbbrev;
1228 case Type::FixedVectorTyID:
1229 case Type::ScalableVectorTyID: {
1234 TypeVals.
push_back(VT->getElementCount().getKnownMinValue());
1240 case Type::TargetExtTyID: {
1246 for (
Type *InnerTy :
TET->type_params())
1251 case Type::TypedPointerTyID:
1256 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
1297 RawFlags |= Flags.ReadNone;
1298 RawFlags |= (Flags.ReadOnly << 1);
1299 RawFlags |= (Flags.NoRecurse << 2);
1300 RawFlags |= (Flags.ReturnDoesNotAlias << 3);
1301 RawFlags |= (Flags.NoInline << 4);
1302 RawFlags |= (Flags.AlwaysInline << 5);
1303 RawFlags |= (Flags.NoUnwind << 6);
1304 RawFlags |= (Flags.MayThrow << 7);
1305 RawFlags |= (Flags.HasUnknownCall << 8);
1306 RawFlags |= (Flags.MustBeUnreachable << 9);
1313 bool ImportAsDecl =
false) {
1316 RawFlags |= Flags.NotEligibleToImport;
1317 RawFlags |= (Flags.Live << 1);
1318 RawFlags |= (Flags.DSOLocal << 2);
1319 RawFlags |= (Flags.CanAutoHide << 3);
1324 RawFlags = (RawFlags << 4) | Flags.Linkage;
1326 RawFlags |= (Flags.Visibility << 8);
1328 unsigned ImportType = Flags.ImportType | ImportAsDecl;
1329 RawFlags |= (ImportType << 10);
1335 uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1336 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1388 switch (
C.getSelectionKind()) {
1412size_t ModuleBitcodeWriter::addToStrtab(StringRef Str) {
1415 return StrtabBuilder.
add(Str);
1418void ModuleBitcodeWriter::writeComdats() {
1433void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1438 auto Abbv = std::make_shared<BitCodeAbbrev>();
1444 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1460 bool isChar6 =
true;
1461 for (
char C : Str) {
1464 if ((
unsigned char)
C & 128)
1473static_assert(
sizeof(GlobalValue::SanitizerMetadata) <=
sizeof(unsigned),
1474 "Sanitizer Metadata is too large for naive serialization.");
1477 return Meta.NoAddress | (
Meta.NoHWAddress << 1) |
1478 (
Meta.Memtag << 2) | (
Meta.IsDynInit << 3);
1484void ModuleBitcodeWriter::writeModuleInfo() {
1486 if (!
M.getTargetTriple().empty())
1488 M.getTargetTriple().str(), 0 );
1489 const std::string &
DL =
M.getDataLayoutStr();
1492 if (!
M.getModuleInlineAsm().empty())
1498 std::map<std::string, unsigned> SectionMap;
1499 std::map<std::string, unsigned> GCMap;
1500 MaybeAlign MaxGVarAlignment;
1501 unsigned MaxGlobalType = 0;
1502 for (
const GlobalVariable &GV :
M.globals()) {
1503 if (MaybeAlign
A = GV.getAlign())
1504 MaxGVarAlignment = !MaxGVarAlignment ? *
A : std::max(*MaxGVarAlignment, *
A);
1505 MaxGlobalType = std::max(MaxGlobalType, VE.
getTypeID(GV.getValueType()));
1506 if (GV.hasSection()) {
1508 unsigned &
Entry = SectionMap[std::string(GV.getSection())];
1512 Entry = SectionMap.size();
1516 for (
const Function &
F : M) {
1517 if (
F.hasSection()) {
1519 unsigned &
Entry = SectionMap[std::string(
F.getSection())];
1523 Entry = SectionMap.size();
1528 unsigned &
Entry = GCMap[
F.getGC()];
1532 Entry = GCMap.size();
1538 unsigned SimpleGVarAbbrev = 0;
1539 if (!
M.global_empty()) {
1541 auto Abbv = std::make_shared<BitCodeAbbrev>();
1552 if (!MaxGVarAlignment)
1553 Abbv->Add(BitCodeAbbrevOp(0));
1555 unsigned MaxEncAlignment = getEncodedAlign(MaxGVarAlignment);
1559 if (SectionMap.empty())
1560 Abbv->Add(BitCodeAbbrevOp(0));
1565 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1579 auto Abbv = std::make_shared<BitCodeAbbrev>();
1582 Abbv->Add(AbbrevOpToUse);
1583 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1585 for (
const auto P :
M.getSourceFileName())
1594 for (
const GlobalVariable &GV :
M.globals()) {
1595 unsigned AbbrevToUse = 0;
1601 Vals.
push_back(addToStrtab(GV.getName()));
1604 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1608 Vals.
push_back(getEncodedAlign(GV.getAlign()));
1609 Vals.
push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1611 if (GV.isThreadLocal() ||
1613 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1614 GV.isExternallyInitialized() ||
1616 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1617 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1621 Vals.
push_back(GV.isExternallyInitialized());
1625 auto AL = GV.getAttributesAsList(AttributeList::FunctionIndex);
1629 Vals.
push_back(addToStrtab(GV.getPartition()));
1630 Vals.
push_back(GV.getPartition().size());
1633 GV.getSanitizerMetadata())
1637 AbbrevToUse = SimpleGVarAbbrev;
1645 for (
const Function &
F : M) {
1657 Vals.
push_back(getEncodedAlign(
F.getAlign()));
1658 Vals.
push_back(
F.hasSection() ? SectionMap[std::string(
F.getSection())]
1670 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1674 Vals.
push_back(addToStrtab(
F.getPartition()));
1677 unsigned AbbrevToUse = 0;
1683 for (
const GlobalAlias &
A :
M.aliases()) {
1690 Vals.
push_back(
A.getType()->getAddressSpace());
1698 Vals.
push_back(addToStrtab(
A.getPartition()));
1701 unsigned AbbrevToUse = 0;
1707 for (
const GlobalIFunc &
I :
M.ifuncs()) {
1713 Vals.
push_back(
I.getType()->getAddressSpace());
1718 Vals.
push_back(addToStrtab(
I.getPartition()));
1724 writeValueSymbolTableForwardDecl();
1731 if (OBO->hasNoSignedWrap())
1733 if (OBO->hasNoUnsignedWrap())
1739 if (PDI->isDisjoint())
1742 if (FPMO->hasAllowReassoc())
1744 if (FPMO->hasNoNaNs())
1746 if (FPMO->hasNoInfs())
1748 if (FPMO->hasNoSignedZeros())
1750 if (FPMO->hasAllowReciprocal())
1752 if (FPMO->hasAllowContract())
1754 if (FPMO->hasApproxFunc())
1757 if (NNI->hasNonNeg())
1760 if (TI->hasNoSignedWrap())
1762 if (TI->hasNoUnsignedWrap())
1765 if (
GEP->isInBounds())
1767 if (
GEP->hasNoUnsignedSignedWrap())
1769 if (
GEP->hasNoUnsignedWrap())
1772 if (ICmp->hasSameSign())
1779void ModuleBitcodeWriter::writeValueAsMetadata(
1780 const ValueAsMetadata *MD, SmallVectorImpl<uint64_t> &Record) {
1789void ModuleBitcodeWriter::writeMDTuple(
const MDTuple *
N,
1790 SmallVectorImpl<uint64_t> &Record,
1792 for (
const MDOperand &MDO :
N->operands()) {
1795 "Unexpected function-local metadata");
1804unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1807 auto Abbv = std::make_shared<BitCodeAbbrev>();
1820void ModuleBitcodeWriter::writeDILocation(
const DILocation *
N,
1821 SmallVectorImpl<uint64_t> &Record,
1824 Abbrev = createDILocationAbbrev();
1838unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1841 auto Abbv = std::make_shared<BitCodeAbbrev>();
1852void ModuleBitcodeWriter::writeGenericDINode(
const GenericDINode *
N,
1853 SmallVectorImpl<uint64_t> &Record,
1856 Abbrev = createGenericDINodeAbbrev();
1862 for (
auto &
I :
N->operands())
1869void ModuleBitcodeWriter::writeDISubrange(
const DISubrange *
N,
1870 SmallVectorImpl<uint64_t> &Record,
1872 const uint64_t
Version = 2 << 1;
1883void ModuleBitcodeWriter::writeDIGenericSubrange(
1884 const DIGenericSubrange *
N, SmallVectorImpl<uint64_t> &Record,
1896void ModuleBitcodeWriter::writeDIEnumerator(
const DIEnumerator *
N,
1897 SmallVectorImpl<uint64_t> &Record,
1899 const uint64_t IsBigInt = 1 << 2;
1900 Record.
push_back(IsBigInt | (
N->isUnsigned() << 1) |
N->isDistinct());
1901 Record.
push_back(
N->getValue().getBitWidth());
1909void ModuleBitcodeWriter::writeDIBasicType(
const DIBasicType *
N,
1910 SmallVectorImpl<uint64_t> &Record,
1912 const unsigned SizeIsMetadata = 0x2;
1913 Record.
push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1920 Record.
push_back(
N->getNumExtraInhabitants());
1926void ModuleBitcodeWriter::writeDIFixedPointType(
1927 const DIFixedPointType *
N, SmallVectorImpl<uint64_t> &Record,
1929 const unsigned SizeIsMetadata = 0x2;
1930 Record.
push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1940 auto WriteWideInt = [&](
const APInt &
Value) {
1943 uint64_t NumWords =
Value.getActiveWords();
1944 uint64_t
Encoded = (NumWords << 32) |
Value.getBitWidth();
1949 WriteWideInt(
N->getNumeratorRaw());
1950 WriteWideInt(
N->getDenominatorRaw());
1956void ModuleBitcodeWriter::writeDIStringType(
const DIStringType *
N,
1957 SmallVectorImpl<uint64_t> &Record,
1959 const unsigned SizeIsMetadata = 0x2;
1960 Record.
push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1974void ModuleBitcodeWriter::writeDIDerivedType(
const DIDerivedType *
N,
1975 SmallVectorImpl<uint64_t> &Record,
1977 const unsigned SizeIsMetadata = 0x2;
1978 Record.
push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1993 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
1994 Record.
push_back(*DWARFAddressSpace + 1);
2000 if (
auto PtrAuthData =
N->getPtrAuthData())
2009void ModuleBitcodeWriter::writeDISubrangeType(
const DISubrangeType *
N,
2010 SmallVectorImpl<uint64_t> &Record,
2012 const unsigned SizeIsMetadata = 0x2;
2013 Record.
push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2031void ModuleBitcodeWriter::writeDICompositeType(
2032 const DICompositeType *
N, SmallVectorImpl<uint64_t> &Record,
2034 const unsigned IsNotUsedInOldTypeRef = 0x2;
2035 const unsigned SizeIsMetadata = 0x4;
2036 Record.
push_back(SizeIsMetadata | IsNotUsedInOldTypeRef |
2037 (
unsigned)
N->isDistinct());
2059 Record.
push_back(
N->getNumExtraInhabitants());
2069void ModuleBitcodeWriter::writeDISubroutineType(
2070 const DISubroutineType *
N, SmallVectorImpl<uint64_t> &Record,
2072 const unsigned HasNoOldTypeRefs = 0x2;
2073 Record.
push_back(HasNoOldTypeRefs | (
unsigned)
N->isDistinct());
2082void ModuleBitcodeWriter::writeDIFile(
const DIFile *
N,
2083 SmallVectorImpl<uint64_t> &Record,
2088 if (
N->getRawChecksum()) {
2097 auto Source =
N->getRawSource();
2105void ModuleBitcodeWriter::writeDICompileUnit(
const DICompileUnit *
N,
2106 SmallVectorImpl<uint64_t> &Record,
2108 assert(
N->isDistinct() &&
"Expected distinct compile units");
2125 Record.
push_back(
N->getSplitDebugInlining());
2126 Record.
push_back(
N->getDebugInfoForProfiling());
2127 Record.
push_back((
unsigned)
N->getNameTableKind());
2136void ModuleBitcodeWriter::writeDISubprogram(
const DISubprogram *
N,
2137 SmallVectorImpl<uint64_t> &Record,
2139 const uint64_t HasUnitFlag = 1 << 1;
2140 const uint64_t HasSPFlagsFlag = 1 << 2;
2141 Record.
push_back(uint64_t(
N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
2161 Record.
push_back(
N->getKeyInstructionsEnabled());
2167void ModuleBitcodeWriter::writeDILexicalBlock(
const DILexicalBlock *
N,
2168 SmallVectorImpl<uint64_t> &Record,
2180void ModuleBitcodeWriter::writeDILexicalBlockFile(
2181 const DILexicalBlockFile *
N, SmallVectorImpl<uint64_t> &Record,
2192void ModuleBitcodeWriter::writeDICommonBlock(
const DICommonBlock *
N,
2193 SmallVectorImpl<uint64_t> &Record,
2206void ModuleBitcodeWriter::writeDINamespace(
const DINamespace *
N,
2207 SmallVectorImpl<uint64_t> &Record,
2209 Record.
push_back(
N->isDistinct() |
N->getExportSymbols() << 1);
2217void ModuleBitcodeWriter::writeDIMacro(
const DIMacro *
N,
2218 SmallVectorImpl<uint64_t> &Record,
2230void ModuleBitcodeWriter::writeDIMacroFile(
const DIMacroFile *
N,
2231 SmallVectorImpl<uint64_t> &Record,
2243void ModuleBitcodeWriter::writeDIArgList(
const DIArgList *
N,
2244 SmallVectorImpl<uint64_t> &Record) {
2245 Record.
reserve(
N->getArgs().size());
2246 for (ValueAsMetadata *MD :
N->getArgs())
2253void ModuleBitcodeWriter::writeDIModule(
const DIModule *
N,
2254 SmallVectorImpl<uint64_t> &Record,
2257 for (
auto &
I :
N->operands())
2266void ModuleBitcodeWriter::writeDIAssignID(
const DIAssignID *
N,
2267 SmallVectorImpl<uint64_t> &Record,
2275void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2276 const DITemplateTypeParameter *
N, SmallVectorImpl<uint64_t> &Record,
2287void ModuleBitcodeWriter::writeDITemplateValueParameter(
2288 const DITemplateValueParameter *
N, SmallVectorImpl<uint64_t> &Record,
2301void ModuleBitcodeWriter::writeDIGlobalVariable(
2302 const DIGlobalVariable *
N, SmallVectorImpl<uint64_t> &Record,
2304 const uint64_t
Version = 2 << 1;
2323void ModuleBitcodeWriter::writeDILocalVariable(
2324 const DILocalVariable *
N, SmallVectorImpl<uint64_t> &Record,
2339 const uint64_t HasAlignmentFlag = 1 << 1;
2340 Record.
push_back((uint64_t)
N->isDistinct() | HasAlignmentFlag);
2355void ModuleBitcodeWriter::writeDILabel(
2356 const DILabel *
N, SmallVectorImpl<uint64_t> &Record,
2358 uint64_t IsArtificialFlag = uint64_t(
N->isArtificial()) << 1;
2359 Record.
push_back((uint64_t)
N->isDistinct() | IsArtificialFlag);
2365 Record.
push_back(
N->getCoroSuspendIdx().has_value()
2366 ? (uint64_t)
N->getCoroSuspendIdx().value()
2367 : std::numeric_limits<uint64_t>::max());
2373void ModuleBitcodeWriter::writeDIExpression(
const DIExpression *
N,
2374 SmallVectorImpl<uint64_t> &Record,
2376 Record.
reserve(
N->getElements().size() + 1);
2377 const uint64_t
Version = 3 << 1;
2379 Record.
append(
N->elements_begin(),
N->elements_end());
2385void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2386 const DIGlobalVariableExpression *
N, SmallVectorImpl<uint64_t> &Record,
2396void ModuleBitcodeWriter::writeDIObjCProperty(
const DIObjCProperty *
N,
2397 SmallVectorImpl<uint64_t> &Record,
2412void ModuleBitcodeWriter::writeDIImportedEntity(
2413 const DIImportedEntity *
N, SmallVectorImpl<uint64_t> &Record,
2428unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2429 auto Abbv = std::make_shared<BitCodeAbbrev>();
2436void ModuleBitcodeWriter::writeNamedMetadata(
2437 SmallVectorImpl<uint64_t> &Record) {
2438 if (
M.named_metadata_empty())
2441 unsigned Abbrev = createNamedMetadataAbbrev();
2442 for (
const NamedMDNode &NMD :
M.named_metadata()) {
2444 StringRef Str = NMD.getName();
2445 Record.
append(Str.bytes_begin(), Str.bytes_end());
2450 for (
const MDNode *
N : NMD.operands())
2457unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2458 auto Abbv = std::make_shared<BitCodeAbbrev>();
2470void ModuleBitcodeWriter::writeMetadataStrings(
2472 if (Strings.
empty())
2480 SmallString<256> Blob;
2482 BitstreamWriter
W(Blob);
2502#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
2503#include "llvm/IR/Metadata.def"
2507void ModuleBitcodeWriter::writeMetadataRecords(
2509 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2514#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
2515#include "llvm/IR/Metadata.def"
2521 assert(
N->isResolved() &&
"Expected forward references to be resolved");
2523 switch (
N->getMetadataID()) {
2526#define HANDLE_MDNODE_LEAF(CLASS) \
2527 case Metadata::CLASS##Kind: \
2529 write##CLASS(cast<CLASS>(N), Record, \
2530 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
2532 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
2534#include "llvm/IR/Metadata.def"
2545void ModuleBitcodeWriter::writeModuleMetadata() {
2546 if (!VE.
hasMDs() &&
M.named_metadata_empty())
2550 SmallVector<uint64_t, 64> Record;
2554 std::vector<unsigned> MDAbbrevs;
2557 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2558 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2559 createGenericDINodeAbbrev();
2561 auto Abbv = std::make_shared<BitCodeAbbrev>();
2565 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2567 Abbv = std::make_shared<BitCodeAbbrev>();
2571 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2583 uint64_t Vals[] = {0, 0};
2593 std::vector<uint64_t> IndexPos;
2597 writeMetadataRecords(VE.
getNonMDStrings(), Record, &MDAbbrevs, &IndexPos);
2608 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2609 for (
auto &Elt : IndexPos) {
2610 auto EltDelta = Elt - PreviousValue;
2611 PreviousValue = Elt;
2620 writeNamedMetadata(Record);
2622 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2623 SmallVector<uint64_t, 4> Record;
2625 pushGlobalMetadataAttachment(Record, GO);
2628 for (
const Function &
F : M)
2629 if (
F.isDeclaration() &&
F.hasMetadata())
2630 AddDeclAttachedMetadata(
F);
2631 for (
const GlobalIFunc &GI :
M.ifuncs())
2632 if (GI.hasMetadata())
2633 AddDeclAttachedMetadata(GI);
2636 for (
const GlobalVariable &GV :
M.globals())
2637 if (GV.hasMetadata())
2638 AddDeclAttachedMetadata(GV);
2643void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2648 SmallVector<uint64_t, 64> Record;
2654void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2655 SmallVectorImpl<uint64_t> &Record,
const GlobalObject &GO) {
2659 for (
const auto &
I : MDs) {
2665void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &
F) {
2668 SmallVector<uint64_t, 64> Record;
2670 if (
F.hasMetadata()) {
2671 pushGlobalMetadataAttachment(Record,
F);
2679 for (
const BasicBlock &BB :
F)
2680 for (
const Instruction &
I : BB) {
2682 I.getAllMetadataOtherThanDebugLoc(MDs);
2685 if (MDs.
empty())
continue;
2689 for (
const auto &[
ID, MD] : MDs) {
2700void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2701 SmallVector<uint64_t, 64> Record;
2706 M.getMDKindNames(Names);
2708 if (Names.
empty())
return;
2712 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2714 StringRef KName = Names[MDKindID];
2724void ModuleBitcodeWriter::writeOperandBundleTags() {
2732 M.getOperandBundleTags(Tags);
2739 SmallVector<uint64_t, 64> Record;
2741 for (
auto Tag : Tags) {
2751void ModuleBitcodeWriter::writeSyncScopeNames() {
2753 M.getContext().getSyncScopeNames(SSNs);
2759 SmallVector<uint64_t, 64> Record;
2760 for (
auto SSN : SSNs) {
2761 Record.
append(SSN.begin(), SSN.end());
2769void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2771 if (FirstVal == LastVal)
return;
2775 unsigned AggregateAbbrev = 0;
2776 unsigned String8Abbrev = 0;
2777 unsigned CString7Abbrev = 0;
2778 unsigned CString6Abbrev = 0;
2782 auto Abbv = std::make_shared<BitCodeAbbrev>();
2786 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2789 Abbv = std::make_shared<BitCodeAbbrev>();
2793 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2795 Abbv = std::make_shared<BitCodeAbbrev>();
2799 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2801 Abbv = std::make_shared<BitCodeAbbrev>();
2805 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2808 SmallVector<uint64_t, 64> Record;
2811 Type *LastTy =
nullptr;
2812 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2813 const Value *
V = Vals[i].first;
2815 if (
V->getType() != LastTy) {
2816 LastTy =
V->getType();
2819 CONSTANTS_SETTYPE_ABBREV);
2826 unsigned(
IA->hasSideEffects()) |
unsigned(
IA->isAlignStack()) << 1 |
2827 unsigned(
IA->getDialect() & 1) << 2 |
unsigned(
IA->canThrow()) << 3);
2830 StringRef AsmStr =
IA->getAsmString();
2835 StringRef ConstraintStr =
IA->getConstraintString();
2843 unsigned Code = -1U;
2844 unsigned AbbrevToUse = 0;
2845 if (
C->isNullValue()) {
2852 if (
IV->getBitWidth() <= 64) {
2853 uint64_t
V =
IV->getSExtValue();
2856 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2866 Record.
push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2870 APInt api = CFP->getValueAPF().bitcastToAPInt();
2872 Record.
push_back((p[1] << 48) | (p[0] >> 16));
2875 APInt api = CFP->getValueAPF().bitcastToAPInt();
2880 assert(0 &&
"Unknown FP type!");
2886 uint64_t NumElts = Str->getNumElements();
2888 if (Str->isCString()) {
2893 AbbrevToUse = String8Abbrev;
2897 for (uint64_t i = 0; i != NumElts; ++i) {
2898 unsigned char V = Str->getElementAsInteger(i);
2900 isCStr7 &= (
V & 128) == 0;
2906 AbbrevToUse = CString6Abbrev;
2908 AbbrevToUse = CString7Abbrev;
2909 }
else if (
const ConstantDataSequential *CDS =
2912 Type *EltTy = CDS->getElementType();
2914 for (uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
2915 Record.
push_back(CDS->getElementAsInteger(i));
2917 for (uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
2919 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2923 for (
const Value *
Op :
C->operands())
2925 AbbrevToUse = AggregateAbbrev;
2927 switch (
CE->getOpcode()) {
2934 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2936 assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2946 case Instruction::FNeg: {
2947 assert(
CE->getNumOperands() == 1 &&
"Unknown constant expr!");
2956 case Instruction::GetElementPtr: {
2961 if (std::optional<ConstantRange>
Range = GO->getInRange()) {
2965 for (
const Value *
Op :
CE->operands()) {
2971 case Instruction::ExtractElement:
2978 case Instruction::InsertElement:
2985 case Instruction::ShuffleVector:
2990 if (
C->getType() ==
C->getOperand(0)->getType()) {
3026 Stream.
EmitRecord(Code, Record, AbbrevToUse);
3033void ModuleBitcodeWriter::writeModuleConstants() {
3038 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
3040 writeConstants(i, Vals.size(),
true);
3054bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
3055 SmallVectorImpl<unsigned> &Vals) {
3059 if (ValID >= InstID) {
3066bool ModuleBitcodeWriter::pushValueOrMetadata(
const Value *V,
unsigned InstID,
3067 SmallVectorImpl<unsigned> &Vals) {
3068 bool IsMetadata =
V->getType()->isMetadataTy();
3076 return pushValueAndType(V, InstID, Vals);
3079void ModuleBitcodeWriter::writeOperandBundles(
const CallBase &CS,
3086 Record.
push_back(
C.getOperandBundleTagID(Bundle.getTagName()));
3088 for (
auto &Input : Bundle.Inputs)
3089 pushValueOrMetadata(Input, InstID, Record);
3098void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
3099 SmallVectorImpl<unsigned> &Vals) {
3104void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
3105 SmallVectorImpl<uint64_t> &Vals) {
3107 int64_t diff = ((int32_t)InstID - (int32_t)ValID);
3112void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
3114 SmallVectorImpl<unsigned> &Vals) {
3116 unsigned AbbrevToUse = 0;
3118 switch (
I.getOpcode()) {
3122 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3123 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
3128 if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
3129 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
3135 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3136 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
3137 pushValue(
I.getOperand(1), InstID, Vals);
3141 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
3142 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
3147 case Instruction::FNeg: {
3149 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3150 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
3154 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
3155 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
3160 case Instruction::GetElementPtr: {
3162 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
3166 for (
const Value *
Op :
I.operands())
3167 pushValueAndType(
Op, InstID, Vals);
3170 case Instruction::ExtractValue: {
3172 pushValueAndType(
I.getOperand(0), InstID, Vals);
3177 case Instruction::InsertValue: {
3179 pushValueAndType(
I.getOperand(0), InstID, Vals);
3180 pushValueAndType(
I.getOperand(1), InstID, Vals);
3185 case Instruction::Select: {
3187 pushValueAndType(
I.getOperand(1), InstID, Vals);
3188 pushValue(
I.getOperand(2), InstID, Vals);
3189 pushValueAndType(
I.getOperand(0), InstID, Vals);
3195 case Instruction::ExtractElement:
3197 pushValueAndType(
I.getOperand(0), InstID, Vals);
3198 pushValueAndType(
I.getOperand(1), InstID, Vals);
3200 case Instruction::InsertElement:
3202 pushValueAndType(
I.getOperand(0), InstID, Vals);
3203 pushValue(
I.getOperand(1), InstID, Vals);
3204 pushValueAndType(
I.getOperand(2), InstID, Vals);
3206 case Instruction::ShuffleVector:
3208 pushValueAndType(
I.getOperand(0), InstID, Vals);
3209 pushValue(
I.getOperand(1), InstID, Vals);
3213 case Instruction::ICmp:
3214 case Instruction::FCmp: {
3217 AbbrevToUse = FUNCTION_INST_CMP_ABBREV;
3218 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3220 pushValue(
I.getOperand(1), InstID, Vals);
3226 AbbrevToUse = FUNCTION_INST_CMP_FLAGS_ABBREV;
3231 case Instruction::Ret:
3234 unsigned NumOperands =
I.getNumOperands();
3235 if (NumOperands == 0)
3236 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
3237 else if (NumOperands == 1) {
3238 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3239 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
3241 for (
const Value *
Op :
I.operands())
3242 pushValueAndType(
Op, InstID, Vals);
3246 case Instruction::Br:
3249 AbbrevToUse = FUNCTION_INST_BR_UNCOND_ABBREV;
3252 if (
II.isConditional()) {
3254 pushValue(
II.getCondition(), InstID, Vals);
3255 AbbrevToUse = FUNCTION_INST_BR_COND_ABBREV;
3259 case Instruction::Switch:
3264 pushValue(
SI.getCondition(), InstID, Vals);
3266 for (
auto Case :
SI.cases()) {
3272 case Instruction::IndirectBr:
3276 pushValue(
I.getOperand(0), InstID, Vals);
3281 case Instruction::Invoke: {
3284 FunctionType *FTy =
II->getFunctionType();
3286 if (
II->hasOperandBundles())
3287 writeOperandBundles(*
II, InstID);
3296 pushValueAndType(Callee, InstID, Vals);
3299 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3300 pushValue(
I.getOperand(i), InstID, Vals);
3303 if (FTy->isVarArg()) {
3304 for (
unsigned i = FTy->getNumParams(), e =
II->arg_size(); i != e; ++i)
3305 pushValueAndType(
I.getOperand(i), InstID, Vals);
3309 case Instruction::Resume:
3311 pushValueAndType(
I.getOperand(0), InstID, Vals);
3313 case Instruction::CleanupRet: {
3316 pushValue(CRI.getCleanupPad(), InstID, Vals);
3317 if (CRI.hasUnwindDest())
3321 case Instruction::CatchRet: {
3324 pushValue(CRI.getCatchPad(), InstID, Vals);
3328 case Instruction::CleanupPad:
3329 case Instruction::CatchPad: {
3333 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3335 unsigned NumArgOperands = FuncletPad.arg_size();
3337 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
3338 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
3341 case Instruction::CatchSwitch: {
3345 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3347 unsigned NumHandlers = CatchSwitch.getNumHandlers();
3349 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
3352 if (CatchSwitch.hasUnwindDest())
3356 case Instruction::CallBr: {
3362 writeOperandBundles(*CBI, InstID);
3377 pushValueAndType(Callee, InstID, Vals);
3380 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3381 pushValue(
I.getOperand(i), InstID, Vals);
3384 if (FTy->isVarArg()) {
3385 for (
unsigned i = FTy->getNumParams(), e = CBI->
arg_size(); i != e; ++i)
3386 pushValueAndType(
I.getOperand(i), InstID, Vals);
3390 case Instruction::Unreachable:
3392 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3395 case Instruction::PHI: {
3413 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
3418 case Instruction::LandingPad: {
3429 pushValueAndType(LP.
getClause(
I), InstID, Vals);
3434 case Instruction::Alloca: {
3440 using APV = AllocaPackedValues;
3441 unsigned Record = 0;
3442 unsigned EncodedAlign = getEncodedAlign(AI.
getAlign());
3444 Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3446 EncodedAlign >> APV::AlignLower::Bits);
3453 if (AS !=
M.getDataLayout().getAllocaAddrSpace())
3458 case Instruction::Load:
3461 pushValueAndType(
I.getOperand(0), InstID, Vals);
3464 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3465 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3475 case Instruction::Store:
3480 AbbrevToUse = FUNCTION_INST_STORE_ABBREV;
3482 if (pushValueAndType(
I.getOperand(1), InstID, Vals))
3484 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3494 case Instruction::AtomicCmpXchg:
3496 pushValueAndType(
I.getOperand(0), InstID, Vals);
3497 pushValueAndType(
I.getOperand(1), InstID, Vals);
3498 pushValue(
I.getOperand(2), InstID, Vals);
3509 case Instruction::AtomicRMW:
3511 pushValueAndType(
I.getOperand(0), InstID, Vals);
3512 pushValueAndType(
I.getOperand(1), InstID, Vals);
3521 case Instruction::Fence:
3526 case Instruction::Call: {
3531 writeOperandBundles(CI, InstID);
3551 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3555 if (FTy->isVarArg()) {
3556 for (
unsigned i = FTy->getNumParams(), e = CI.
arg_size(); i != e; ++i)
3561 case Instruction::VAArg:
3564 pushValue(
I.getOperand(0), InstID, Vals);
3567 case Instruction::Freeze:
3569 pushValueAndType(
I.getOperand(0), InstID, Vals);
3579void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3580 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3585 VSTOffset -= bitcodeStartBit();
3586 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
3590 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3594 auto Abbv = std::make_shared<BitCodeAbbrev>();
3598 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3600 for (
const Function &
F : M) {
3603 if (
F.isDeclaration())
3610 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
3611 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
3615 Record[1] = BitcodeIndex / 32 + 1;
3624void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3625 const ValueSymbolTable &VST) {
3633 SmallVector<uint64_t, 64> NameVals;
3639 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3648 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3652 AbbrevToUse = VST_ENTRY_6_ABBREV;
3654 AbbrevToUse = VST_ENTRY_7_ABBREV;
3657 for (
const auto P :
Name.getKey())
3661 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3668void ModuleBitcodeWriter::writeUseList(UseListOrder &&Order) {
3669 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3676 SmallVector<uint64_t, 64> Record(Order.Shuffle.begin(), Order.Shuffle.end());
3681void ModuleBitcodeWriter::writeUseListBlock(
const Function *
F) {
3683 "Expected to be preserving use-list order");
3685 auto hasMore = [&]() {
3701void ModuleBitcodeWriter::writeFunction(
3703 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3720 unsigned CstStart, CstEnd;
3722 writeConstants(CstStart, CstEnd,
false);
3725 writeFunctionMetadata(
F);
3728 unsigned InstID = CstEnd;
3730 bool NeedsMetadataAttachment =
F.hasMetadata();
3732 DILocation *LastDL =
nullptr;
3733 SmallSetVector<Function *, 4> BlockAddressUsers;
3736 for (
const BasicBlock &BB :
F) {
3737 for (
const Instruction &
I : BB) {
3738 writeInstruction(
I, InstID, Vals);
3740 if (!
I.getType()->isVoidTy())
3744 NeedsMetadataAttachment |=
I.hasMetadataOtherThanDebugLoc();
3747 if (DILocation *
DL =
I.getDebugLoc()) {
3760 FUNCTION_DEBUG_LOC_ABBREV);
3770 if (
I.hasDbgRecords()) {
3774 auto PushValueOrMetadata = [&Vals, InstID,
3777 "RawLocation unexpectedly null in DbgVariableRecord");
3779 SmallVector<unsigned, 2> ValAndType;
3783 if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
3797 for (DbgRecord &DR :
I.DebugMarker->getDbgRecordRange()) {
3823 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3844 SmallPtrSet<Value *, 8> Visited{BA};
3845 while (!Worklist.
empty()) {
3847 for (User *U :
V->users()) {
3853 Visited.
insert(U).second)
3860 if (!BlockAddressUsers.
empty()) {
3869 if (
auto *Symtab =
F.getValueSymbolTable())
3870 writeFunctionLevelValueSymbolTable(*Symtab);
3872 if (NeedsMetadataAttachment)
3873 writeFunctionMetadataAttachment(
F);
3875 writeUseListBlock(&
F);
3881void ModuleBitcodeWriter::writeBlockInfo() {
3894 auto Abbv = std::make_shared<BitCodeAbbrev>();
3905 auto Abbv = std::make_shared<BitCodeAbbrev>();
3915 auto Abbv = std::make_shared<BitCodeAbbrev>();
3925 auto Abbv = std::make_shared<BitCodeAbbrev>();
3931 VST_BBENTRY_6_ABBREV)
3936 auto Abbv = std::make_shared<BitCodeAbbrev>();
3938 Abbv->Add(TypeAbbrevOp);
3940 CONSTANTS_SETTYPE_ABBREV)
3945 auto Abbv = std::make_shared<BitCodeAbbrev>();
3949 CONSTANTS_INTEGER_ABBREV)
3954 auto Abbv = std::make_shared<BitCodeAbbrev>();
3962 CONSTANTS_CE_CAST_Abbrev)
3966 auto Abbv = std::make_shared<BitCodeAbbrev>();
3969 CONSTANTS_NULL_Abbrev)
3976 auto Abbv = std::make_shared<BitCodeAbbrev>();
3978 Abbv->Add(ValAbbrevOp);
3979 Abbv->Add(TypeAbbrevOp);
3983 FUNCTION_INST_LOAD_ABBREV)
3987 auto Abbv = std::make_shared<BitCodeAbbrev>();
3989 Abbv->Add(ValAbbrevOp);
3990 Abbv->Add(ValAbbrevOp);
3994 FUNCTION_INST_STORE_ABBREV)
3998 auto Abbv = std::make_shared<BitCodeAbbrev>();
4000 Abbv->Add(ValAbbrevOp);
4003 FUNCTION_INST_UNOP_ABBREV)
4007 auto Abbv = std::make_shared<BitCodeAbbrev>();
4009 Abbv->Add(ValAbbrevOp);
4013 FUNCTION_INST_UNOP_FLAGS_ABBREV)
4017 auto Abbv = std::make_shared<BitCodeAbbrev>();
4019 Abbv->Add(ValAbbrevOp);
4020 Abbv->Add(ValAbbrevOp);
4023 FUNCTION_INST_BINOP_ABBREV)
4027 auto Abbv = std::make_shared<BitCodeAbbrev>();
4029 Abbv->Add(ValAbbrevOp);
4030 Abbv->Add(ValAbbrevOp);
4034 FUNCTION_INST_BINOP_FLAGS_ABBREV)
4038 auto Abbv = std::make_shared<BitCodeAbbrev>();
4040 Abbv->Add(ValAbbrevOp);
4041 Abbv->Add(TypeAbbrevOp);
4044 FUNCTION_INST_CAST_ABBREV)
4048 auto Abbv = std::make_shared<BitCodeAbbrev>();
4050 Abbv->Add(ValAbbrevOp);
4051 Abbv->Add(TypeAbbrevOp);
4055 FUNCTION_INST_CAST_FLAGS_ABBREV)
4060 auto Abbv = std::make_shared<BitCodeAbbrev>();
4063 FUNCTION_INST_RET_VOID_ABBREV)
4067 auto Abbv = std::make_shared<BitCodeAbbrev>();
4069 Abbv->Add(ValAbbrevOp);
4071 FUNCTION_INST_RET_VAL_ABBREV)
4075 auto Abbv = std::make_shared<BitCodeAbbrev>();
4078 Abbv->Add(ValAbbrevOp);
4080 FUNCTION_INST_BR_UNCOND_ABBREV)
4084 auto Abbv = std::make_shared<BitCodeAbbrev>();
4087 Abbv->Add(ValAbbrevOp);
4088 Abbv->Add(ValAbbrevOp);
4089 Abbv->Add(ValAbbrevOp);
4091 FUNCTION_INST_BR_COND_ABBREV)
4095 auto Abbv = std::make_shared<BitCodeAbbrev>();
4098 FUNCTION_INST_UNREACHABLE_ABBREV)
4102 auto Abbv = std::make_shared<BitCodeAbbrev>();
4105 Abbv->Add(TypeAbbrevOp);
4107 Abbv->Add(ValAbbrevOp);
4109 FUNCTION_INST_GEP_ABBREV)
4113 auto Abbv = std::make_shared<BitCodeAbbrev>();
4115 Abbv->Add(ValAbbrevOp);
4116 Abbv->Add(ValAbbrevOp);
4119 FUNCTION_INST_CMP_ABBREV)
4123 auto Abbv = std::make_shared<BitCodeAbbrev>();
4125 Abbv->Add(ValAbbrevOp);
4126 Abbv->Add(ValAbbrevOp);
4130 FUNCTION_INST_CMP_FLAGS_ABBREV)
4134 auto Abbv = std::make_shared<BitCodeAbbrev>();
4139 Abbv->Add(ValAbbrevOp);
4141 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
4145 auto Abbv = std::make_shared<BitCodeAbbrev>();
4156 FUNCTION_DEBUG_LOC_ABBREV)
4164void IndexBitcodeWriter::writeModStrings() {
4170 auto Abbv = std::make_shared<BitCodeAbbrev>();
4175 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
4178 Abbv = std::make_shared<BitCodeAbbrev>();
4183 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
4186 Abbv = std::make_shared<BitCodeAbbrev>();
4191 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
4194 Abbv = std::make_shared<BitCodeAbbrev>();
4201 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
4204 forEachModule([&](
const StringMapEntry<ModuleHash> &MPSE) {
4206 const auto &Hash = MPSE.
getValue();
4208 unsigned AbbrevToUse = Abbrev8Bit;
4210 AbbrevToUse = Abbrev6Bit;
4212 AbbrevToUse = Abbrev7Bit;
4214 auto ModuleId = ModuleIdMap.
size();
4215 ModuleIdMap[
Key] = ModuleId;
4224 Vals.
assign(Hash.begin(), Hash.end());
4236template <
typename Fn>
4240 if (!FS->type_tests().empty())
4245 auto WriteVFuncIdVec = [&](
uint64_t Ty,
4250 for (
auto &VF : VFs) {
4251 Record.push_back(VF.GUID);
4252 Record.push_back(VF.Offset);
4258 FS->type_test_assume_vcalls());
4260 FS->type_checked_load_vcalls());
4262 auto WriteConstVCallVec = [&](
uint64_t Ty,
4264 for (
auto &VC : VCs) {
4266 Record.push_back(VC.VFunc.GUID);
4267 Record.push_back(VC.VFunc.Offset);
4274 FS->type_test_assume_const_vcalls());
4276 FS->type_checked_load_const_vcalls());
4286 if (!FS->paramAccesses().empty()) {
4288 for (
auto &Arg : FS->paramAccesses()) {
4289 size_t UndoSize =
Record.size();
4290 Record.push_back(Arg.ParamNo);
4291 WriteRange(Arg.Use);
4292 Record.push_back(Arg.Calls.size());
4293 for (
auto &
Call : Arg.Calls) {
4295 std::optional<unsigned> ValueID = GetValueID(
Call.Callee);
4302 Record.push_back(*ValueID);
4303 WriteRange(
Call.Offsets);
4314 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
4315 if (!FS->type_tests().empty())
4316 for (
auto &TT : FS->type_tests())
4317 ReferencedTypeIds.insert(TT);
4319 auto GetReferencedTypesFromVFuncIdVec =
4321 for (
auto &VF : VFs)
4322 ReferencedTypeIds.insert(VF.GUID);
4325 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4326 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4328 auto GetReferencedTypesFromConstVCallVec =
4330 for (
auto &VC : VCs)
4331 ReferencedTypeIds.insert(VC.VFunc.GUID);
4334 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4335 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
4371 NameVals.
push_back(Summary.TTRes.TheKind);
4372 NameVals.
push_back(Summary.TTRes.SizeM1BitWidth);
4373 NameVals.
push_back(Summary.TTRes.AlignLog2);
4374 NameVals.
push_back(Summary.TTRes.SizeM1);
4375 NameVals.
push_back(Summary.TTRes.BitMask);
4376 NameVals.
push_back(Summary.TTRes.InlineBits);
4378 for (
auto &W : Summary.WPDRes)
4390 for (
auto &
P : Summary) {
4392 NameVals.
push_back(
VE.getValueID(
P.VTableVI.getValue()));
4406 static_assert(std::is_same_v<LinearFrameId, unsigned>);
4407 for (
auto &AI : FS->allocs()) {
4408 for (
auto &MIB : AI.MIBs) {
4410 StackIdIndices.
reserve(MIB.StackIdIndices.size());
4411 for (
auto Id : MIB.StackIdIndices)
4412 StackIdIndices.
push_back(GetStackIndex(Id));
4414 CallStacks.insert({CallStacks.size(), StackIdIndices});
4427 assert(!CallStacks.empty());
4433 Builder.
build(std::move(CallStacks),
nullptr,
4437 return Builder.takeCallStackPos();
4442 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
bool PerModule,
4443 std::function<
unsigned(
const ValueInfo &VI)> GetValueID,
4444 std::function<
unsigned(
unsigned)> GetStackIndex,
4445 bool WriteContextSizeInfoIndex,
4450 for (
auto &CI : FS->callsites()) {
4454 assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4455 Record.push_back(GetValueID(CI.Callee));
4457 Record.push_back(CI.StackIdIndices.size());
4458 Record.push_back(CI.Clones.size());
4460 for (
auto Id : CI.StackIdIndices)
4461 Record.push_back(GetStackIndex(Id));
4469 for (
auto &AI : FS->allocs()) {
4473 assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4474 Record.push_back(AI.MIBs.size());
4476 Record.push_back(AI.Versions.size());
4477 for (
auto &MIB : AI.MIBs) {
4484 assert(CallStackCount <= CallStackPos.
size());
4485 Record.push_back(CallStackPos[CallStackCount++]);
4490 assert(AI.ContextSizeInfos.empty() ||
4491 AI.ContextSizeInfos.size() == AI.MIBs.size());
4493 if (WriteContextSizeInfoIndex && !AI.ContextSizeInfos.empty()) {
4501 ContextIds.
reserve(AI.ContextSizeInfos.size() * 2);
4502 for (
auto &Infos : AI.ContextSizeInfos) {
4503 Record.push_back(Infos.size());
4504 for (
auto [FullStackId, TotalSize] : Infos) {
4511 Record.push_back(TotalSize);
4529void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4530 SmallVector<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
4531 unsigned ValueID,
unsigned FSCallsRelBFAbbrev,
4532 unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
4533 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
const Function &
F,
4534 DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
4541 Stream, FS, [&](
const ValueInfo &VI) -> std::optional<unsigned> {
4546 Stream, FS, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
4548 [&](
const ValueInfo &VI) {
return getValueId(VI); },
4549 [&](
unsigned I) {
return I; },
4550 true, CallStackPos, CallStackCount);
4552 auto SpecialRefCnts =
FS->specialRefCounts();
4557 NameVals.
push_back(SpecialRefCnts.first);
4558 NameVals.
push_back(SpecialRefCnts.second);
4560 for (
auto &RI :
FS->refs())
4563 const bool UseRelBFRecord =
4566 for (
auto &ECI :
FS->calls()) {
4567 NameVals.
push_back(getValueId(ECI.first));
4575 (UseRelBFRecord ? FSCallsRelBFAbbrev : FSCallsProfileAbbrev);
4586void ModuleBitcodeWriterBase::writeModuleLevelReferences(
4587 const GlobalVariable &V, SmallVector<uint64_t, 64> &NameVals,
4588 unsigned FSModRefsAbbrev,
unsigned FSModVTableRefsAbbrev) {
4589 auto VI =
Index->getValueInfo(
V.getGUID());
4590 if (!VI ||
VI.getSummaryList().empty()) {
4596 auto *
Summary =
VI.getSummaryList()[0].get();
4602 auto VTableFuncs =
VS->vTableFuncs();
4603 if (!VTableFuncs.empty())
4606 unsigned SizeBeforeRefs = NameVals.
size();
4607 for (
auto &RI :
VS->refs())
4613 if (VTableFuncs.empty())
4618 for (
auto &
P : VTableFuncs) {
4624 FSModVTableRefsAbbrev);
4631void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
4634 bool IsThinLTO =
true;
4637 IsThinLTO = MD->getZExtValue();
4649 if (
Index->enableSplitLTOUnit())
4651 if (
Index->hasUnifiedLTO())
4661 auto Abbv = std::make_shared<BitCodeAbbrev>();
4667 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4669 for (
const auto &GVI : valueIds()) {
4671 ArrayRef<uint32_t>{GVI.second,
4672 static_cast<uint32_t
>(GVI.first >> 32),
4673 static_cast<uint32_t
>(GVI.first)},
4677 if (!
Index->stackIds().empty()) {
4678 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4685 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4686 SmallVector<uint32_t> Vals;
4688 for (
auto Id :
Index->stackIds()) {
4689 Vals.
push_back(
static_cast<uint32_t
>(Id >> 32));
4690 Vals.
push_back(
static_cast<uint32_t
>(Id));
4695 unsigned ContextIdAbbvId = 0;
4698 auto ContextIdAbbv = std::make_shared<BitCodeAbbrev>();
4710 ContextIdAbbvId = Stream.
EmitAbbrev(std::move(ContextIdAbbv));
4714 Abbv = std::make_shared<BitCodeAbbrev>();
4726 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4729 Abbv = std::make_shared<BitCodeAbbrev>();
4741 unsigned FSCallsRelBFAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4744 Abbv = std::make_shared<BitCodeAbbrev>();
4750 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4753 Abbv = std::make_shared<BitCodeAbbrev>();
4761 unsigned FSModVTableRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4764 Abbv = std::make_shared<BitCodeAbbrev>();
4769 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4772 Abbv = std::make_shared<BitCodeAbbrev>();
4779 unsigned TypeIdCompatibleVtableAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4781 Abbv = std::make_shared<BitCodeAbbrev>();
4787 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4789 Abbv = std::make_shared<BitCodeAbbrev>();
4796 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4798 Abbv = std::make_shared<BitCodeAbbrev>();
4803 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4810 MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
4811 for (
const Function &
F : M) {
4817 ValueInfo
VI =
Index->getValueInfo(
F.getGUID());
4818 if (!VI ||
VI.getSummaryList().empty()) {
4824 auto *
Summary =
VI.getSummaryList()[0].get();
4827 FS, [](
unsigned I) {
return I; }, CallStacks);
4831 DenseMap<CallStackId, LinearCallStackId> CallStackPos;
4832 if (!CallStacks.
empty()) {
4840 SmallVector<uint64_t, 64> NameVals;
4843 for (
const Function &
F : M) {
4849 ValueInfo
VI =
Index->getValueInfo(
F.getGUID());
4850 if (!VI ||
VI.getSummaryList().empty()) {
4856 auto *
Summary =
VI.getSummaryList()[0].get();
4857 writePerModuleFunctionSummaryRecord(
4858 NameVals, Summary, VE.
getValueID(&
F), FSCallsRelBFAbbrev,
4859 FSCallsProfileAbbrev, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
F,
4860 CallStackPos, CallStackCount);
4865 for (
const GlobalVariable &
G :
M.globals())
4866 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev,
4867 FSModVTableRefsAbbrev);
4869 for (
const GlobalAlias &
A :
M.aliases()) {
4870 auto *Aliasee =
A.getAliaseeObject();
4886 for (
auto &S :
Index->typeIdCompatibleVtableMap()) {
4890 TypeIdCompatibleVtableAbbrev);
4894 if (
Index->getBlockCount())
4896 ArrayRef<uint64_t>{
Index->getBlockCount()});
4902void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4911 auto Abbv = std::make_shared<BitCodeAbbrev>();
4917 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4919 for (
const auto &GVI : valueIds()) {
4921 ArrayRef<uint32_t>{GVI.second,
4922 static_cast<uint32_t
>(GVI.first >> 32),
4923 static_cast<uint32_t
>(GVI.first)},
4929 if (!StackIds.empty()) {
4930 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4937 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4938 SmallVector<uint32_t> Vals;
4939 Vals.
reserve(StackIds.size() * 2);
4940 for (
auto Id : StackIds) {
4941 Vals.
push_back(
static_cast<uint32_t
>(Id >> 32));
4942 Vals.
push_back(
static_cast<uint32_t
>(Id));
4948 Abbv = std::make_shared<BitCodeAbbrev>();
4962 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4965 Abbv = std::make_shared<BitCodeAbbrev>();
4972 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4975 Abbv = std::make_shared<BitCodeAbbrev>();
4981 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4983 Abbv = std::make_shared<BitCodeAbbrev>();
4991 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4993 Abbv = std::make_shared<BitCodeAbbrev>();
5004 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5006 auto shouldImportValueAsDecl = [&](GlobalValueSummary *GVS) ->
bool {
5007 if (DecSummaries ==
nullptr)
5009 return DecSummaries->count(GVS);
5017 DenseMap<const GlobalValueSummary *, unsigned> SummaryToValueIdMap;
5019 SmallVector<uint64_t, 64> NameVals;
5023 std::set<GlobalValue::GUID> ReferencedTypeIds;
5027 auto MaybeEmitOriginalName = [&](GlobalValueSummary &S) {
5037 NameVals.
push_back(S.getOriginalName());
5042 DenseMap<CallStackId, LinearCallStackId> CallStackPos;
5044 Abbv = std::make_shared<BitCodeAbbrev>();
5049 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5056 MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
5057 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5063 GlobalValueSummary *S =
I.second;
5076 return StackIdIndicesToIndex[
I];
5082 if (!CallStacks.
empty()) {
5092 DenseSet<GlobalValue::GUID> DefOrUseGUIDs;
5093 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5094 GlobalValueSummary *S =
I.second;
5096 DefOrUseGUIDs.
insert(
I.first);
5097 for (
const ValueInfo &VI : S->
refs())
5098 DefOrUseGUIDs.
insert(
VI.getGUID());
5100 auto ValueId = getValueId(
I.first);
5102 SummaryToValueIdMap[S] = *ValueId;
5120 NameVals.
push_back(ModuleIdMap[
VS->modulePath()]);
5124 for (
auto &RI :
VS->refs()) {
5125 auto RefValueId = getValueId(RI.getGUID());
5135 MaybeEmitOriginalName(*S);
5139 auto GetValueId = [&](
const ValueInfo &
VI) -> std::optional<unsigned> {
5141 return std::nullopt;
5142 return getValueId(
VI.getGUID());
5150 Stream, FS, CallsiteAbbrev, AllocAbbrev, 0,
5153 [&](
const ValueInfo &VI) ->
unsigned {
5154 std::optional<unsigned> ValueID = GetValueId(VI);
5169 return StackIdIndicesToIndex[
I];
5171 false, CallStackPos, CallStackCount);
5175 NameVals.
push_back(ModuleIdMap[
FS->modulePath()]);
5188 unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
5189 for (
auto &RI :
FS->refs()) {
5190 auto RefValueId = getValueId(RI.getGUID());
5194 if (RI.isReadOnly())
5196 else if (RI.isWriteOnly())
5200 NameVals[6] =
Count;
5201 NameVals[7] = RORefCnt;
5202 NameVals[8] = WORefCnt;
5204 for (
auto &EI :
FS->calls()) {
5207 std::optional<unsigned> CallValueId = GetValueId(EI.first);
5216 FSCallsProfileAbbrev);
5218 MaybeEmitOriginalName(*S);
5221 for (
auto *AS : Aliases) {
5222 auto AliasValueId = SummaryToValueIdMap[AS];
5229 auto AliaseeValueId = SummaryToValueIdMap[&AS->
getAliasee()];
5236 MaybeEmitOriginalName(*AS);
5243 auto EmitCfiFunctions = [&](
const CfiFunctionIndex &CfiIndex,
5245 if (CfiIndex.
empty())
5248 auto Defs = CfiIndex.
forGuid(GUID);
5251 if (Functions.
empty())
5254 for (
const auto &S : Functions) {
5268 for (
auto &
T : ReferencedTypeIds) {
5269 auto TidIter =
Index.typeIds().equal_range(
T);
5270 for (
const auto &[GUID, TypeIdPair] :
make_range(TidIter)) {
5278 if (
Index.getBlockCount())
5280 ArrayRef<uint64_t>{
Index.getBlockCount()});
5291 auto Abbv = std::make_shared<BitCodeAbbrev>();
5295 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5297 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
5300 Abbv = std::make_shared<BitCodeAbbrev>();
5303 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5309void ModuleBitcodeWriter::writeModuleHash(StringRef View) {
5314 Hasher.
update(ArrayRef<uint8_t>(
5315 reinterpret_cast<const uint8_t *
>(
View.data()),
View.size()));
5316 std::array<uint8_t, 20> Hash = Hasher.
result();
5317 for (
int Pos = 0; Pos < 20; Pos += 4) {
5330void ModuleBitcodeWriter::write() {
5338 writeModuleVersion();
5347 writeAttributeGroupTable();
5350 writeAttributeTable();
5359 writeModuleConstants();
5362 writeModuleMetadataKinds();
5365 writeModuleMetadata();
5369 writeUseListBlock(
nullptr);
5371 writeOperandBundleTags();
5372 writeSyncScopeNames();
5375 DenseMap<const Function *, uint64_t> FunctionToBitcodeIndex;
5376 for (
const Function &
F : M)
5377 if (!
F.isDeclaration())
5378 writeFunction(
F, FunctionToBitcodeIndex);
5383 writePerModuleGlobalValueSummary();
5385 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
5413 unsigned CPUType = ~0U;
5420 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
5421 DARWIN_CPU_TYPE_X86 = 7,
5422 DARWIN_CPU_TYPE_ARM = 12,
5423 DARWIN_CPU_TYPE_POWERPC = 18
5428 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
5430 CPUType = DARWIN_CPU_TYPE_X86;
5432 CPUType = DARWIN_CPU_TYPE_POWERPC;
5434 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
5436 CPUType = DARWIN_CPU_TYPE_ARM;
5440 "Expected header size to be reserved");
5445 unsigned Position = 0;
5453 while (Buffer.
size() & 15)
5460 Stream.
Emit((
unsigned)
'B', 8);
5461 Stream.
Emit((
unsigned)
'C', 8);
5462 Stream.
Emit(0x0, 4);
5463 Stream.
Emit(0xC, 4);
5464 Stream.
Emit(0xE, 4);
5465 Stream.
Emit(0xD, 4);
5483 auto Abbv = std::make_shared<BitCodeAbbrev>();
5486 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
5494 assert(!WroteStrtab && !WroteSymtab);
5500 if (M->getModuleInlineAsm().empty())
5504 const Triple TT(M->getTargetTriple());
5506 if (!
T || !
T->hasMCAsmParser())
5528 std::vector<char> Strtab;
5529 StrtabBuilder.finalizeInOrder();
5530 Strtab.resize(StrtabBuilder.getSize());
5531 StrtabBuilder.write((
uint8_t *)Strtab.data());
5534 {Strtab.data(), Strtab.size()});
5545 bool ShouldPreserveUseListOrder,
5554 assert(M.isMaterialized());
5555 Mods.push_back(
const_cast<Module *
>(&M));
5557 ModuleBitcodeWriter ModuleWriter(M, StrtabBuilder, *Stream,
5558 ShouldPreserveUseListOrder, Index,
5559 GenerateHash, ModHash);
5560 ModuleWriter.write();
5567 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, DecSummaries,
5568 ModuleToSummariesForIndex);
5569 IndexWriter.write();
5574 bool ShouldPreserveUseListOrder,
5578 Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
5580 Writer.writeSymtab();
5581 Writer.writeStrtab();
5583 Triple TT(M.getTargetTriple());
5584 if (TT.isOSDarwin() || TT.isOSBinFormatMachO()) {
5602void IndexBitcodeWriter::write() {
5605 writeModuleVersion();
5611 writeCombinedGlobalValueSummary();
5628 Writer.
writeIndex(&Index, ModuleToSummariesForIndex, DecSummaries);
5637class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
5647 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5649 ModHash(&ModHash) {}
5654 void writeSimplifiedModuleInfo();
5664void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5676 auto Abbv = std::make_shared<BitCodeAbbrev>();
5679 Abbv->Add(AbbrevOpToUse);
5680 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5682 for (
const auto P :
M.getSourceFileName())
5746void ThinLinkBitcodeWriter::write() {
5749 writeModuleVersion();
5751 writeSimplifiedModuleInfo();
5753 writePerModuleGlobalValueSummary();
5770 assert(M.isMaterialized());
5771 Mods.push_back(
const_cast<Module *
>(&M));
5773 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream, Index,
5775 ThinLinkWriter.write();
5796 switch (
T.getObjectFormat()) {
5798 return "__LLVM,__bitcode";
5823 switch (
T.getObjectFormat()) {
5825 return "__LLVM,__cmdline";
5851 const std::vector<uint8_t> &CmdArgs) {
5856 Type *UsedElementType = Used ? Used->getValueType()->getArrayElementType()
5858 for (
auto *GV : UsedGlobals) {
5859 if (GV->getName() !=
"llvm.embedded.module" &&
5860 GV->getName() !=
"llvm.cmdline")
5865 Used->eraseFromParent();
5870 Triple T(M.getTargetTriple());
5899 M.getGlobalVariable(
"llvm.embedded.module",
true)) {
5900 assert(Old->hasZeroLiveUses() &&
5901 "llvm.embedded.module can only be used once in llvm.compiler.used");
5903 Old->eraseFromParent();
5905 GV->
setName(
"llvm.embedded.module");
5923 assert(Old->hasZeroLiveUses() &&
5924 "llvm.cmdline can only be used once in llvm.compiler.used");
5926 Old->eraseFromParent();
5932 if (UsedArray.
empty())
5940 NewUsed->setSection(
"llvm.metadata");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void writeDIMacro(raw_ostream &Out, const DIMacro *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, AsmWriterContext &WriterCtx)
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, AsmWriterContext &WriterCtx)
static void writeDIFixedPointType(raw_ostream &Out, const DIFixedPointType *N, AsmWriterContext &WriterCtx)
static void writeDISubrangeType(raw_ostream &Out, const DISubrangeType *N, AsmWriterContext &WriterCtx)
static void writeDIStringType(raw_ostream &Out, const DIStringType *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, AsmWriterContext &WriterCtx)
static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, AsmWriterContext &WriterCtx)
static void writeDIModule(raw_ostream &Out, const DIModule *N, AsmWriterContext &WriterCtx)
static void writeDIFile(raw_ostream &Out, const DIFile *N, AsmWriterContext &)
static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, AsmWriterContext &WriterCtx)
static void writeDILabel(raw_ostream &Out, const DILabel *N, AsmWriterContext &WriterCtx)
static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, AsmWriterContext &WriterCtx)
static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, AsmWriterContext &WriterCtx)
static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, AsmWriterContext &WriterCtx)
static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, AsmWriterContext &WriterCtx)
static void writeDILocation(raw_ostream &Out, const DILocation *DL, AsmWriterContext &WriterCtx)
static void writeDINamespace(raw_ostream &Out, const DINamespace *N, AsmWriterContext &WriterCtx)
static void writeDICommonBlock(raw_ostream &Out, const DICommonBlock *N, AsmWriterContext &WriterCtx)
static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, AsmWriterContext &WriterCtx)
static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, AsmWriterContext &WriterCtx)
static void writeDITemplateTypeParameter(raw_ostream &Out, const DITemplateTypeParameter *N, AsmWriterContext &WriterCtx)
static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, AsmWriterContext &WriterCtx)
static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N, AsmWriterContext &WriterCtx)
static void writeDISubrange(raw_ostream &Out, const DISubrange *N, AsmWriterContext &WriterCtx)
static void writeDILexicalBlockFile(raw_ostream &Out, const DILexicalBlockFile *N, AsmWriterContext &WriterCtx)
static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, AsmWriterContext &)
static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, AsmWriterContext &WriterCtx)
static void writeDIExpression(raw_ostream &Out, const DIExpression *N, AsmWriterContext &WriterCtx)
static void writeDIAssignID(raw_ostream &Out, const DIAssignID *DL, AsmWriterContext &WriterCtx)
static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, AsmWriterContext &WriterCtx)
static void writeDIArgList(raw_ostream &Out, const DIArgList *N, AsmWriterContext &WriterCtx, bool FromValue=false)
static void writeDITemplateValueParameter(raw_ostream &Out, const DITemplateValueParameter *N, AsmWriterContext &WriterCtx)
static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, AsmWriterContext &WriterCtx)
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static void writeFunctionHeapProfileRecords(BitstreamWriter &Stream, FunctionSummary *FS, unsigned CallsiteAbbrev, unsigned AllocAbbrev, unsigned ContextIdAbbvId, bool PerModule, std::function< unsigned(const ValueInfo &VI)> GetValueID, std::function< unsigned(unsigned)> GetStackIndex, bool WriteContextSizeInfoIndex, DenseMap< CallStackId, LinearCallStackId > &CallStackPos, CallStackId &CallStackCount)
static unsigned serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta)
static void writeTypeIdCompatibleVtableSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdCompatibleVtableInfo &Summary, ValueEnumerator &VE)
static void getReferencedTypeIds(FunctionSummary *FS, std::set< GlobalValue::GUID > &ReferencedTypeIds)
Collect type IDs from type tests used by function.
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
static void collectMemProfCallStacks(FunctionSummary *FS, std::function< LinearFrameId(unsigned)> GetStackIndex, MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &CallStacks)
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
static unsigned getEncodedVisibility(const GlobalValue &GV)
static uint64_t getOptimizationFlags(const Value *V)
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
static unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
static DenseMap< CallStackId, LinearCallStackId > writeMemoryProfileRadixTree(MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &&CallStacks, BitstreamWriter &Stream, unsigned RadixAbbrev)
static void writeIdentificationBlock(BitstreamWriter &Stream)
Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version,...
static unsigned getEncodedCastOpcode(unsigned Opcode)
static cl::opt< bool > WriteRelBFToSummary("write-relbf-to-summary", cl::Hidden, cl::init(false), cl::desc("Write relative block frequency to function summary "))
static cl::opt< uint32_t > FlushThreshold("bitcode-flush-threshold", cl::Hidden, cl::init(512), cl::desc("The threshold (unit M) for flushing LLVM bitcode."))
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
static unsigned getEncodedUnnamedAddr(const GlobalValue &GV)
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags, bool ImportAsDecl=false)
static void emitDarwinBCHeaderAndTrailer(SmallVectorImpl< char > &Buffer, const Triple &TT)
If generating a bc file on darwin, we have to emit a header and trailer to make it compatible with th...
static void writeBitcodeHeader(BitstreamWriter &Stream)
Helper to write the header common to all bitcode files.
static uint64_t getEncodedRelBFCallEdgeInfo(const CalleeInfo &CI)
static void writeWholeProgramDevirtResolutionByArg(SmallVector< uint64_t, 64 > &NameVals, const std::vector< uint64_t > &args, const WholeProgramDevirtResolution::ByArg &ByArg)
static void emitConstantRange(SmallVectorImpl< uint64_t > &Record, const ConstantRange &CR, bool EmitBitWidth)
static StringEncoding getStringEncoding(StringRef Str)
Determine the encoding to use for the given string name and length.
static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags)
static const char * getSectionNameForCommandline(const Triple &T)
static cl::opt< unsigned > IndexThreshold("bitcode-mdindex-threshold", cl::Hidden, cl::init(25), cl::desc("Number of metadatas above which we emit an index " "to enable lazy-loading"))
static void writeTypeIdSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdSummary &Summary)
static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, FunctionSummary *FS, Fn GetValueID)
Write the function type metadata related records that need to appear before a function summary entry ...
static uint64_t getEncodedHotnessCallEdgeInfo(const CalleeInfo &CI)
static void emitWideAPInt(SmallVectorImpl< uint64_t > &Vals, const APInt &A)
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
static void writeWholeProgramDevirtResolution(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, uint64_t Id, const WholeProgramDevirtResolution &Wpd)
static unsigned getEncodedDLLStorageClass(const GlobalValue &GV)
static void writeInt32ToBuffer(uint32_t Value, SmallVectorImpl< char > &Buffer, uint32_t &Position)
static const char * getSectionNameForBitcode(const Triple &T)
static cl::opt< bool > CombinedIndexMemProfContext("combined-index-memprof-context", cl::Hidden, cl::init(true), cl::desc(""))
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
This file contains constants used for implementing Dwarf debug support.
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
static MaybeAlign getAlign(Value *Ptr)
Module.h This file contains the declarations for the Module class.
static cl::opt< LTOBitcodeEmbedding > EmbedBitcode("lto-embed-bitcode", cl::init(LTOBitcodeEmbedding::DoNotEmbed), cl::values(clEnumValN(LTOBitcodeEmbedding::DoNotEmbed, "none", "Do not embed"), clEnumValN(LTOBitcodeEmbedding::EmbedOptimized, "optimized", "Embed after all optimization passes"), clEnumValN(LTOBitcodeEmbedding::EmbedPostMergePreOptimized, "post-merge-pre-opt", "Embed post merge, but before optimizations")), cl::desc("Embed LLVM bitcode in object files produced by LTO"))
Machine Check Debug Module
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static const uint32_t IV[8]
Class for arbitrary precision integers.
unsigned getActiveWords() const
Compute the number of active words in the value of this APInt.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
int64_t getSExtValue() const
Get sign extended value.
const GlobalValueSummary & getAliasee() const
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
unsigned getAddressSpace() const
Return the address space for the allocation.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
Class to represent array types.
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ USubCond
Subtract only if no unsigned overflow.
@ FMinimum
*p = minimum(old, v) minimum matches the behavior of llvm.minimum.
@ Min
*p = old <signed v ? old : v
@ USubSat
*p = usub.sat(old, v) usub.sat matches the behavior of llvm.usub.sat.
@ FMaximum
*p = maximum(old, v) maximum matches the behavior of llvm.maximum.
@ UIncWrap
Increment one up to a maximum value.
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ UMax
*p = old >unsigned v ? old : v
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
bool hasAttributes() const
Return true if attributes exists in this set.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
@ None
No attributes have been set.
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
@ EndAttrKinds
Sentinel value useful for loops.
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
LLVM_ABI void writeThinLinkBitcode(const Module &M, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the buffer specified...
LLVM_ABI void writeIndex(const ModuleSummaryIndex *Index, const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex, const GVSummaryPtrSet *DecSummaries)
LLVM_ABI void copyStrtab(StringRef Strtab)
Copy the string table for another module into this bitcode file.
LLVM_ABI void writeStrtab()
Write the bitcode file's string table.
LLVM_ABI ~BitcodeWriter()
LLVM_ABI void writeSymtab()
Attempt to write a symbol table to the bitcode file.
LLVM_ABI void writeModule(const Module &M, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the buffer specified at construction time.
LLVM_ABI BitcodeWriter(SmallVectorImpl< char > &Buffer)
Create a BitcodeWriter that writes to Buffer.
unsigned EmitAbbrev(std::shared_ptr< BitCodeAbbrev > Abbv)
Emits the abbreviation Abbv to the stream.
void markAndBlockFlushing()
For scenarios where the user wants to access a section of the stream to (for example) compute some ch...
StringRef getMarkedBufferAndResumeFlushing()
resumes flushing, but does not flush, and returns the section in the internal buffer starting from th...
void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev=0)
EmitRecord - Emit the specified record to the stream, using an abbrev if we have one to compress the ...
void Emit(uint32_t Val, unsigned NumBits)
void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals, StringRef Blob)
EmitRecordWithBlob - Emit the specified record to the stream, using an abbrev that includes a blob at...
unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr< BitCodeAbbrev > Abbv)
EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified BlockID.
void EnterBlockInfoBlock()
EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
void BackpatchWord(uint64_t BitNo, unsigned Val)
void BackpatchWord64(uint64_t BitNo, uint64_t Val)
void EnterSubblock(unsigned BlockID, unsigned CodeLen)
uint64_t GetCurrentBitNo() const
Retrieve the current position in the stream, in bits.
void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals)
EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
static LLVM_ABI BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
CallingConv::ID getCallingConv() const
Value * getCalledOperand() const
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
bool hasOperandBundles() const
Return true if this User has any operand bundles.
BasicBlock * getIndirectDest(unsigned i) const
BasicBlock * getDefaultDest() const
unsigned getNumIndirectDests() const
Return the number of callbr indirect dest labels.
bool isNoTailCall() const
bool isMustTailCall() const
iterator_range< NestedIterator > forGuid(GlobalValue::GUID GUID) const
@ Largest
The linker will choose the largest COMDAT.
@ SameSize
The data referenced by the COMDAT must be the same size.
@ Any
The linker may choose any COMDAT.
@ NoDeduplicate
No deduplication is performed.
@ ExactMatch
The data referenced by the COMDAT must be the same.
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
static LLVM_ABI Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
This class represents a range of values.
const APInt & getLower() const
Return the lower value for this range.
const APInt & getUpper() const
Return the upper value for this range.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
This is an important base class in LLVM.
DebugLoc getDebugLoc() const
LLVM_ABI DIAssignID * getAssignID() const
DIExpression * getExpression() const
DILocalVariable * getVariable() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
bool isDbgDeclare() const
Metadata * getRawAddress() const
DIExpression * getAddressExpression() const
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Lightweight error class with error context and mandatory checking.
Function summary information to aid decisions and implementation of importing.
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
LLVM_ABI void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
LLVM_ABI void setSection(StringRef S)
Change the section for this global.
GVFlags flags() const
Get the flags for this GlobalValue (see struct GVFlags).
StringRef modulePath() const
Get the path to the module containing this function.
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
VisibilityTypes getVisibility() const
static bool isLocalLinkage(LinkageTypes Linkage)
LinkageTypes getLinkage() const
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
ThreadLocalMode getThreadLocalMode() const
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ProtectedVisibility
The GV is protected.
UnnamedAddr getUnnamedAddr() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
DLLStorageClassTypes getDLLStorageClass() const
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalVariable.
idx_iterator idx_end() const
idx_iterator idx_begin() const
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
This class implements a map that also provides access to all stored values in a deterministic order.
size_t getBufferSize() const
const char * getBufferStart() const
const char * getBufferEnd() const
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static constexpr uint64_t BitcodeSummaryVersion
A Module instance is used to store all the information related to an LLVM module.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Digest more data.
LLVM_ABI std::array< uint8_t, 20 > result()
Return the current raw 160-bits SHA1 for the digested data since the last call to init().
size_type size() const
Determine the number of elements in the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void append(StringRef RHS)
Append from a StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
const ValueTy & getValue() const
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
Utility for building string tables with deduplicated suffixes.
LLVM_ABI size_t add(CachedHashStringRef S, uint8_t Priority=0)
Add a string to the builder.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isX86_FP80Ty() const
Return true if this is x86 long double.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
bool isFP128Ty() const
Return true if this is 'fp128'.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
std::vector< std::pair< const Value *, unsigned > > ValueList
unsigned getTypeID(Type *T) const
unsigned getMetadataID(const Metadata *MD) const
UseListOrderStack UseListOrders
ArrayRef< const Metadata * > getNonMDStrings() const
Get the non-MDString metadata for this block.
unsigned getInstructionID(const Instruction *I) const
unsigned getAttributeListID(AttributeList PAL) const
void incorporateFunction(const Function &F)
incorporateFunction/purgeFunction - If you'd like to deal with a function, use these two methods to g...
void getFunctionConstantRange(unsigned &Start, unsigned &End) const
getFunctionConstantRange - Return the range of values that corresponds to function-local constants.
unsigned getAttributeGroupID(IndexAndAttrSet Group) const
bool hasMDs() const
Check whether the current block has any metadata to emit.
unsigned getComdatID(const Comdat *C) const
uint64_t computeBitsRequiredForTypeIndices() const
unsigned getValueID(const Value *V) const
unsigned getMetadataOrNullID(const Metadata *MD) const
const std::vector< IndexAndAttrSet > & getAttributeGroups() const
const ValueList & getValues() const
unsigned getGlobalBasicBlockID(const BasicBlock *BB) const
getGlobalBasicBlockID - This returns the function-specific ID for the specified basic block.
void setInstructionID(const Instruction *I)
const std::vector< const BasicBlock * > & getBasicBlocks() const
const std::vector< AttributeList > & getAttributeLists() const
bool shouldPreserveUseListOrder() const
const ComdatSetType & getComdats() const
std::vector< Type * > TypeList
ArrayRef< const Metadata * > getMDStrings() const
Get the MDString metadata for this block.
std::pair< unsigned, AttributeSet > IndexAndAttrSet
Attribute groups as encoded in bitcode are almost AttributeSets, but they include the AttributeList i...
const TypeList & getTypes() const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
std::pair< iterator, bool > insert(const ValueT &V)
void build(llvm::MapVector< CallStackId, llvm::SmallVector< FrameIdTy > > &&MemProfCallStackData, const llvm::DenseMap< FrameIdTy, LinearFrameId > *MemProfFrameIndexes, llvm::DenseMap< FrameIdTy, FrameStat > &FrameHistogram)
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an std::string.
std::string & str()
Returns the string's reference.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
@ CE
Windows NT (Windows on ARM)
@ TYPE_CODE_OPAQUE_POINTER
@ METADATA_TEMPLATE_VALUE
@ METADATA_LEXICAL_BLOCK_FILE
@ METADATA_SUBROUTINE_TYPE
@ METADATA_GLOBAL_DECL_ATTACHMENT
@ METADATA_IMPORTED_ENTITY
@ METADATA_GENERIC_SUBRANGE
@ METADATA_COMPOSITE_TYPE
@ METADATA_FIXED_POINT_TYPE
@ METADATA_GLOBAL_VAR_EXPR
GlobalValueSummarySymtabCodes
@ FS_CONTEXT_RADIX_TREE_ARRAY
@ FS_COMBINED_GLOBALVAR_INIT_REFS
@ FS_TYPE_CHECKED_LOAD_VCALLS
@ FS_COMBINED_ORIGINAL_NAME
@ FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_CONST_VCALL
@ FS_PERMODULE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_VCALLS
@ FS_COMBINED_ALLOC_INFO_NO_CONTEXT
@ FS_COMBINED_CALLSITE_INFO
@ FS_PERMODULE_CALLSITE_INFO
@ FS_PERMODULE_ALLOC_INFO
@ FS_TYPE_CHECKED_LOAD_CONST_VCALL
@ IDENTIFICATION_CODE_EPOCH
@ IDENTIFICATION_CODE_STRING
@ CST_CODE_DSO_LOCAL_EQUIVALENT
@ CST_CODE_CE_GEP_WITH_INRANGE
@ COMDAT_SELECTION_KIND_LARGEST
@ COMDAT_SELECTION_KIND_ANY
@ COMDAT_SELECTION_KIND_SAME_SIZE
@ COMDAT_SELECTION_KIND_EXACT_MATCH
@ COMDAT_SELECTION_KIND_NO_DUPLICATES
@ ATTR_KIND_STACK_PROTECT
@ ATTR_KIND_STACK_PROTECT_STRONG
@ ATTR_KIND_SANITIZE_MEMORY
@ ATTR_KIND_OPTIMIZE_FOR_SIZE
@ ATTR_KIND_FNRETTHUNK_EXTERN
@ ATTR_KIND_NO_DIVERGENCE_SOURCE
@ ATTR_KIND_SANITIZE_ADDRESS
@ ATTR_KIND_NO_IMPLICIT_FLOAT
@ ATTR_KIND_DEAD_ON_UNWIND
@ ATTR_KIND_STACK_ALIGNMENT
@ ATTR_KIND_STACK_PROTECT_REQ
@ ATTR_KIND_NULL_POINTER_IS_VALID
@ ATTR_KIND_SANITIZE_HWADDRESS
@ ATTR_KIND_RETURNS_TWICE
@ ATTR_KIND_SHADOWCALLSTACK
@ ATTR_KIND_OPT_FOR_FUZZING
@ ATTR_KIND_SANITIZE_NUMERICAL_STABILITY
@ ATTR_KIND_ALLOCATED_POINTER
@ ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION
@ ATTR_KIND_CORO_ELIDE_SAFE
@ ATTR_KIND_NON_LAZY_BIND
@ ATTR_KIND_DEREFERENCEABLE
@ ATTR_KIND_OPTIMIZE_NONE
@ ATTR_KIND_HYBRID_PATCHABLE
@ ATTR_KIND_DEREFERENCEABLE_OR_NULL
@ ATTR_KIND_SANITIZE_REALTIME
@ ATTR_KIND_SPECULATIVE_LOAD_HARDENING
@ ATTR_KIND_ALWAYS_INLINE
@ ATTR_KIND_SANITIZE_TYPE
@ ATTR_KIND_PRESPLIT_COROUTINE
@ ATTR_KIND_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