33#include "llvm/Config/llvm-config.h"
95 cl::desc(
"Number of metadatas above which we emit an index "
96 "to enable lazy-loading"));
99 cl::desc(
"The threshold (unit M) for flushing LLVM bitcode."));
119 cl::desc(
"Preserve use-list order when writing LLVM bitcode."));
134 VST_BBENTRY_6_ABBREV,
138 CONSTANTS_INTEGER_ABBREV,
139 CONSTANTS_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),
222 : ShouldPreserveUseListOrder),
232 for (
const auto &GUIDSummaryLists : *Index)
234 for (
auto &Summary : GUIDSummaryLists.second.getSummaryList())
240 for (auto &CallEdge : FS->calls())
241 if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
242 assignValueId(CallEdge.first.getGUID());
248 for (auto &RefEdge : FS->refs())
249 if (!RefEdge.haveGVs() || !RefEdge.getValue())
250 assignValueId(RefEdge.getGUID());
255 void writePerModuleGlobalValueSummary();
258 void writePerModuleFunctionSummaryRecord(
259 SmallVector<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
260 unsigned ValueID,
unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
261 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
const Function &
F,
262 DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
264 void writeModuleLevelReferences(
const GlobalVariable &V,
265 SmallVector<uint64_t, 64> &NameVals,
266 unsigned FSModRefsAbbrev,
267 unsigned FSModVTableRefsAbbrev);
270 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
274 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
277 assert(VMI != GUIDToValueIdMap.end() &&
278 "GUID does not have assigned value Id");
283 unsigned getValueId(ValueInfo VI) {
284 if (!
VI.haveGVs() || !
VI.getValue())
285 return getValueId(
VI.getGUID());
289 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
293class ModuleBitcodeWriter :
public ModuleBitcodeWriterBase {
304 uint64_t BitcodeStartBit;
309 ModuleBitcodeWriter(
const Module &M, StringTableBuilder &StrtabBuilder,
310 BitstreamWriter &Stream,
bool ShouldPreserveUseListOrder,
311 const ModuleSummaryIndex *Index,
bool GenerateHash,
313 : ModuleBitcodeWriterBase(
M, StrtabBuilder, Stream,
314 ShouldPreserveUseListOrder,
Index),
315 GenerateHash(GenerateHash), ModHash(ModHash),
316 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
322 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
324 size_t addToStrtab(StringRef Str);
326 void writeAttributeGroupTable();
327 void writeAttributeTable();
328 void writeTypeTable();
330 void writeValueSymbolTableForwardDecl();
331 void writeModuleInfo();
332 void writeValueAsMetadata(
const ValueAsMetadata *MD,
333 SmallVectorImpl<uint64_t> &Record);
334 void writeMDTuple(
const MDTuple *
N, SmallVectorImpl<uint64_t> &Record,
336 unsigned createDILocationAbbrev();
337 void writeDILocation(
const DILocation *
N, SmallVectorImpl<uint64_t> &Record,
339 unsigned createGenericDINodeAbbrev();
341 SmallVectorImpl<uint64_t> &Record,
unsigned &Abbrev);
342 void writeDISubrange(
const DISubrange *
N, SmallVectorImpl<uint64_t> &Record,
345 SmallVectorImpl<uint64_t> &Record,
348 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
352 SmallVectorImpl<uint64_t> &Record,
355 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
357 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
359 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
361 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
363 SmallVectorImpl<uint64_t> &Record,
365 void writeDIFile(
const DIFile *
N, SmallVectorImpl<uint64_t> &Record,
368 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
370 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
372 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
374 SmallVectorImpl<uint64_t> &Record,
377 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
380 void writeDIMacro(
const DIMacro *
N, SmallVectorImpl<uint64_t> &Record,
384 void writeDIArgList(
const DIArgList *
N, SmallVectorImpl<uint64_t> &Record);
385 void writeDIModule(
const DIModule *
N, SmallVectorImpl<uint64_t> &Record,
387 void writeDIAssignID(
const DIAssignID *
N, SmallVectorImpl<uint64_t> &Record,
390 SmallVectorImpl<uint64_t> &Record,
393 SmallVectorImpl<uint64_t> &Record,
396 SmallVectorImpl<uint64_t> &Record,
399 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
401 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
403 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
405 SmallVectorImpl<uint64_t> &Record,
408 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
410 SmallVectorImpl<uint64_t> &Record,
412 unsigned createNamedMetadataAbbrev();
413 void writeNamedMetadata(SmallVectorImpl<uint64_t> &Record);
414 unsigned createMetadataStringsAbbrev();
416 SmallVectorImpl<uint64_t> &Record);
418 SmallVectorImpl<uint64_t> &Record,
419 std::vector<unsigned> *MDAbbrevs =
nullptr,
420 std::vector<uint64_t> *IndexPos =
nullptr);
421 void writeModuleMetadata();
422 void writeFunctionMetadata(
const Function &
F);
423 void writeFunctionMetadataAttachment(
const Function &
F);
424 void pushGlobalMetadataAttachment(SmallVectorImpl<uint64_t> &Record,
425 const GlobalObject &GO);
426 void writeModuleMetadataKinds();
427 void writeOperandBundleTags();
428 void writeSyncScopeNames();
429 void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
430 void writeModuleConstants();
431 bool pushValueAndType(
const Value *V,
unsigned InstID,
432 SmallVectorImpl<unsigned> &Vals);
433 bool pushValueOrMetadata(
const Value *V,
unsigned InstID,
434 SmallVectorImpl<unsigned> &Vals);
435 void writeOperandBundles(
const CallBase &CB,
unsigned InstID);
436 void pushValue(
const Value *V,
unsigned InstID,
437 SmallVectorImpl<unsigned> &Vals);
438 void pushValueSigned(
const Value *V,
unsigned InstID,
439 SmallVectorImpl<uint64_t> &Vals);
440 void writeInstruction(
const Instruction &
I,
unsigned InstID,
441 SmallVectorImpl<unsigned> &Vals);
442 void writeFunctionLevelValueSymbolTable(
const ValueSymbolTable &VST);
443 void writeGlobalValueSymbolTable(
444 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
445 void writeUseList(UseListOrder &&Order);
446 void writeUseListBlock(
const Function *
F);
448 writeFunction(
const Function &
F,
449 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
450 void writeBlockInfo();
451 void writeModuleHash(StringRef View);
454 return unsigned(SSID);
457 unsigned getEncodedAlign(MaybeAlign Alignment) {
return encode(Alignment); }
461class IndexBitcodeWriter :
public BitcodeWriterBase {
463 const ModuleSummaryIndex &
Index;
476 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
480 std::vector<uint64_t> StackIds;
485 DenseMap<unsigned, unsigned> StackIdIndicesToIndex;
488 unsigned GlobalValueId = 0;
492 DenseMap<StringRef, uint64_t> ModuleIdMap;
502 BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder,
503 const ModuleSummaryIndex &Index,
506 : BitcodeWriterBase(Stream, StrtabBuilder),
Index(
Index),
507 DecSummaries(DecSummaries),
508 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
512 auto RecordStackIdReference = [&](
unsigned StackIdIndex) {
517 StackIdIndicesToIndex.
insert({StackIdIndex, StackIds.size()});
519 StackIds.push_back(
Index.getStackIdAtIndex(StackIdIndex));
526 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
527 GUIDToValueIdMap[
I.first] = ++GlobalValueId;
539 for (
auto &CI :
FS->callsites()) {
550 if (CI.StackIdIndices.empty()) {
551 GUIDToValueIdMap[CI.Callee.getGUID()] = ++GlobalValueId;
554 for (
auto Idx : CI.StackIdIndices)
555 RecordStackIdReference(Idx);
558 for (
auto &AI :
FS->allocs())
559 for (
auto &MIB : AI.MIBs)
560 for (
auto Idx : MIB.StackIdIndices)
561 RecordStackIdReference(Idx);
567 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
572 template<
typename Functor>
573 void forEachSummary(Functor Callback) {
574 if (ModuleToSummariesForIndex) {
575 for (
auto &M : *ModuleToSummariesForIndex)
576 for (
auto &Summary :
M.second) {
582 Callback({AS->getAliaseeGUID(), &AS->getAliasee()},
true);
585 for (
auto &Summaries : Index)
586 for (
auto &Summary : Summaries.second.getSummaryList())
595 template <
typename Functor>
void forEachModule(Functor Callback) {
596 if (ModuleToSummariesForIndex) {
597 for (
const auto &M : *ModuleToSummariesForIndex) {
598 const auto &MPI =
Index.modulePaths().find(
M.first);
599 if (MPI ==
Index.modulePaths().end()) {
603 assert(ModuleToSummariesForIndex->size() == 1);
613 std::vector<StringRef> ModulePaths;
614 for (
auto &[ModPath,
_] :
Index.modulePaths())
615 ModulePaths.push_back(ModPath);
617 for (
auto &ModPath : ModulePaths)
626 void writeModStrings();
627 void writeCombinedGlobalValueSummary();
630 auto VMI = GUIDToValueIdMap.find(ValGUID);
631 if (VMI == GUIDToValueIdMap.end())
636 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
671 case Instruction::Add:
673 case Instruction::Sub:
675 case Instruction::Mul:
678 case Instruction::FDiv:
681 case Instruction::FRem:
755 case Attribute::Alignment:
757 case Attribute::AllocAlign:
759 case Attribute::AllocSize:
761 case Attribute::AlwaysInline:
763 case Attribute::Builtin:
765 case Attribute::ByVal:
767 case Attribute::Convergent:
769 case Attribute::InAlloca:
771 case Attribute::Cold:
773 case Attribute::DisableSanitizerInstrumentation:
775 case Attribute::FnRetThunkExtern:
779 case Attribute::ElementType:
781 case Attribute::HybridPatchable:
783 case Attribute::InlineHint:
785 case Attribute::InReg:
787 case Attribute::JumpTable:
789 case Attribute::MinSize:
791 case Attribute::AllocatedPointer:
793 case Attribute::AllocKind:
795 case Attribute::Memory:
797 case Attribute::NoFPClass:
799 case Attribute::Naked:
801 case Attribute::Nest:
803 case Attribute::NoAlias:
805 case Attribute::NoBuiltin:
807 case Attribute::NoCallback:
809 case Attribute::NoDivergenceSource:
811 case Attribute::NoDuplicate:
813 case Attribute::NoFree:
815 case Attribute::NoImplicitFloat:
817 case Attribute::NoInline:
819 case Attribute::NoRecurse:
821 case Attribute::NoMerge:
823 case Attribute::NonLazyBind:
825 case Attribute::NonNull:
827 case Attribute::Dereferenceable:
829 case Attribute::DereferenceableOrNull:
831 case Attribute::NoRedZone:
833 case Attribute::NoReturn:
835 case Attribute::NoSync:
837 case Attribute::NoCfCheck:
839 case Attribute::NoProfile:
841 case Attribute::SkipProfile:
843 case Attribute::NoUnwind:
845 case Attribute::NoSanitizeBounds:
847 case Attribute::NoSanitizeCoverage:
849 case Attribute::NullPointerIsValid:
851 case Attribute::OptimizeForDebugging:
853 case Attribute::OptForFuzzing:
855 case Attribute::OptimizeForSize:
857 case Attribute::OptimizeNone:
859 case Attribute::ReadNone:
861 case Attribute::ReadOnly:
863 case Attribute::Returned:
865 case Attribute::ReturnsTwice:
867 case Attribute::SExt:
869 case Attribute::Speculatable:
871 case Attribute::StackAlignment:
873 case Attribute::StackProtect:
875 case Attribute::StackProtectReq:
877 case Attribute::StackProtectStrong:
879 case Attribute::SafeStack:
881 case Attribute::ShadowCallStack:
883 case Attribute::StrictFP:
885 case Attribute::StructRet:
887 case Attribute::SanitizeAddress:
889 case Attribute::SanitizeAllocToken:
891 case Attribute::SanitizeHWAddress:
893 case Attribute::SanitizeThread:
895 case Attribute::SanitizeType:
897 case Attribute::SanitizeMemory:
899 case Attribute::SanitizeNumericalStability:
901 case Attribute::SanitizeRealtime:
903 case Attribute::SanitizeRealtimeBlocking:
905 case Attribute::SpeculativeLoadHardening:
907 case Attribute::SwiftError:
909 case Attribute::SwiftSelf:
911 case Attribute::SwiftAsync:
913 case Attribute::UWTable:
915 case Attribute::VScaleRange:
917 case Attribute::WillReturn:
919 case Attribute::WriteOnly:
921 case Attribute::ZExt:
923 case Attribute::ImmArg:
925 case Attribute::SanitizeMemTag:
927 case Attribute::Preallocated:
929 case Attribute::NoUndef:
931 case Attribute::ByRef:
933 case Attribute::MustProgress:
935 case Attribute::PresplitCoroutine:
937 case Attribute::Writable:
939 case Attribute::CoroDestroyOnlyWhenComplete:
941 case Attribute::CoroElideSafe:
943 case Attribute::DeadOnUnwind:
945 case Attribute::Range:
947 case Attribute::Initializes:
949 case Attribute::NoExt:
951 case Attribute::Captures:
953 case Attribute::DeadOnReturn:
955 case Attribute::NoCreateUndefOrPoison:
957 case Attribute::DenormalFPEnv:
959 case Attribute::NoOutline:
985 unsigned NumWords =
A.getActiveWords();
986 const uint64_t *RawData =
A.getRawData();
987 for (
unsigned i = 0; i < NumWords; i++)
1007void ModuleBitcodeWriter::writeAttributeGroupTable() {
1008 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
1010 if (AttrGrps.empty())
return;
1014 SmallVector<uint64_t, 64>
Record;
1016 unsigned AttrListIndex = Pair.first;
1017 AttributeSet AS = Pair.second;
1019 Record.push_back(AttrListIndex);
1022 if (Attr.isEnumAttribute()) {
1025 }
else if (Attr.isIntAttribute()) {
1027 Attribute::AttrKind
Kind = Attr.getKindAsEnum();
1029 if (Kind == Attribute::Memory) {
1034 Record.push_back(Attr.getValueAsInt());
1036 }
else if (Attr.isStringAttribute()) {
1037 StringRef
Kind = Attr.getKindAsString();
1038 StringRef Val = Attr.getValueAsString();
1047 }
else if (Attr.isTypeAttribute()) {
1048 Type *Ty = Attr.getValueAsType();
1049 Record.push_back(Ty ? 6 : 5);
1053 }
else if (Attr.isConstantRangeAttribute()) {
1059 assert(Attr.isConstantRangeListAttribute());
1065 for (
auto &CR : Val)
1077void ModuleBitcodeWriter::writeAttributeTable() {
1079 if (
Attrs.empty())
return;
1083 SmallVector<uint64_t, 64>
Record;
1084 for (
const AttributeList &AL : Attrs) {
1085 for (
unsigned i :
AL.indexes()) {
1086 AttributeSet AS =
AL.getAttributes(i);
1099void ModuleBitcodeWriter::writeTypeTable() {
1103 SmallVector<uint64_t, 64> TypeVals;
1108 auto Abbv = std::make_shared<BitCodeAbbrev>();
1110 Abbv->Add(BitCodeAbbrevOp(0));
1111 unsigned OpaquePtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1114 Abbv = std::make_shared<BitCodeAbbrev>();
1119 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1122 Abbv = std::make_shared<BitCodeAbbrev>();
1127 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1130 Abbv = std::make_shared<BitCodeAbbrev>();
1134 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1137 Abbv = std::make_shared<BitCodeAbbrev>();
1142 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1145 Abbv = std::make_shared<BitCodeAbbrev>();
1149 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1157 for (
Type *
T : TypeList) {
1158 int AbbrevToUse = 0;
1161 switch (
T->getTypeID()) {
1171 case Type::MetadataTyID:
1176 case Type::IntegerTyID:
1181 case Type::PointerTyID: {
1188 AbbrevToUse = OpaquePtrAbbrev;
1191 case Type::FunctionTyID: {
1197 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1199 AbbrevToUse = FunctionAbbrev;
1202 case Type::StructTyID: {
1207 for (
Type *ET :
ST->elements())
1210 if (
ST->isLiteral()) {
1212 AbbrevToUse = StructAnonAbbrev;
1214 if (
ST->isOpaque()) {
1218 AbbrevToUse = StructNamedAbbrev;
1222 if (!
ST->getName().empty())
1228 case Type::ArrayTyID: {
1232 TypeVals.
push_back(AT->getNumElements());
1234 AbbrevToUse = ArrayAbbrev;
1237 case Type::FixedVectorTyID:
1238 case Type::ScalableVectorTyID: {
1243 TypeVals.
push_back(VT->getElementCount().getKnownMinValue());
1249 case Type::TargetExtTyID: {
1255 for (
Type *InnerTy :
TET->type_params())
1260 case Type::TypedPointerTyID:
1265 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
1306 RawFlags |= Flags.ReadNone;
1307 RawFlags |= (Flags.ReadOnly << 1);
1308 RawFlags |= (Flags.NoRecurse << 2);
1309 RawFlags |= (Flags.ReturnDoesNotAlias << 3);
1310 RawFlags |= (Flags.NoInline << 4);
1311 RawFlags |= (Flags.AlwaysInline << 5);
1312 RawFlags |= (Flags.NoUnwind << 6);
1313 RawFlags |= (Flags.MayThrow << 7);
1314 RawFlags |= (Flags.HasUnknownCall << 8);
1315 RawFlags |= (Flags.MustBeUnreachable << 9);
1322 bool ImportAsDecl =
false) {
1325 RawFlags |= Flags.NotEligibleToImport;
1326 RawFlags |= (Flags.Live << 1);
1327 RawFlags |= (Flags.DSOLocal << 2);
1328 RawFlags |= (Flags.CanAutoHide << 3);
1333 RawFlags = (RawFlags << 4) | Flags.Linkage;
1335 RawFlags |= (Flags.Visibility << 8);
1337 unsigned ImportType = Flags.ImportType | ImportAsDecl;
1338 RawFlags |= (ImportType << 10);
1340 RawFlags |= (Flags.NoRenameOnPromotion << 11);
1346 uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1347 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1390 switch (
C.getSelectionKind()) {
1414size_t ModuleBitcodeWriter::addToStrtab(StringRef Str) {
1417 return StrtabBuilder.
add(Str);
1420void ModuleBitcodeWriter::writeComdats() {
1435void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1440 auto Abbv = std::make_shared<BitCodeAbbrev>();
1446 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1462 bool isChar6 =
true;
1463 for (
char C : Str) {
1466 if ((
unsigned char)
C & 128)
1475static_assert(
sizeof(GlobalValue::SanitizerMetadata) <=
sizeof(unsigned),
1476 "Sanitizer Metadata is too large for naive serialization.");
1479 return Meta.NoAddress | (
Meta.NoHWAddress << 1) |
1480 (
Meta.Memtag << 2) | (
Meta.IsDynInit << 3);
1486void ModuleBitcodeWriter::writeModuleInfo() {
1488 if (!
M.getTargetTriple().empty())
1490 M.getTargetTriple().str(), 0 );
1491 const std::string &
DL =
M.getDataLayoutStr();
1494 if (!
M.getModuleInlineAsm().empty())
1500 std::map<std::string, unsigned> SectionMap;
1501 std::map<std::string, unsigned> GCMap;
1502 MaybeAlign MaxGVarAlignment;
1503 unsigned MaxGlobalType = 0;
1504 for (
const GlobalVariable &GV :
M.globals()) {
1505 if (MaybeAlign
A = GV.getAlign())
1506 MaxGVarAlignment = !MaxGVarAlignment ? *
A : std::max(*MaxGVarAlignment, *
A);
1507 MaxGlobalType = std::max(MaxGlobalType, VE.
getTypeID(GV.getValueType()));
1508 if (GV.hasSection()) {
1510 unsigned &
Entry = SectionMap[std::string(GV.getSection())];
1514 Entry = SectionMap.size();
1518 for (
const Function &
F : M) {
1519 if (
F.hasSection()) {
1521 unsigned &
Entry = SectionMap[std::string(
F.getSection())];
1525 Entry = SectionMap.size();
1530 unsigned &
Entry = GCMap[
F.getGC()];
1534 Entry = GCMap.size();
1540 unsigned SimpleGVarAbbrev = 0;
1541 if (!
M.global_empty()) {
1543 auto Abbv = std::make_shared<BitCodeAbbrev>();
1554 if (!MaxGVarAlignment)
1555 Abbv->Add(BitCodeAbbrevOp(0));
1557 unsigned MaxEncAlignment = getEncodedAlign(MaxGVarAlignment);
1561 if (SectionMap.empty())
1562 Abbv->Add(BitCodeAbbrevOp(0));
1567 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1581 auto Abbv = std::make_shared<BitCodeAbbrev>();
1584 Abbv->Add(AbbrevOpToUse);
1585 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1587 for (
const auto P :
M.getSourceFileName())
1596 for (
const GlobalVariable &GV :
M.globals()) {
1597 unsigned AbbrevToUse = 0;
1603 Vals.
push_back(addToStrtab(GV.getName()));
1606 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1610 Vals.
push_back(getEncodedAlign(GV.getAlign()));
1611 Vals.
push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1613 if (GV.isThreadLocal() ||
1615 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1616 GV.isExternallyInitialized() ||
1618 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1619 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1623 Vals.
push_back(GV.isExternallyInitialized());
1627 auto AL = GV.getAttributesAsList(AttributeList::FunctionIndex);
1631 Vals.
push_back(addToStrtab(GV.getPartition()));
1632 Vals.
push_back(GV.getPartition().size());
1635 GV.getSanitizerMetadata())
1639 AbbrevToUse = SimpleGVarAbbrev;
1647 for (
const Function &
F : M) {
1660 Vals.
push_back(getEncodedAlign(
F.getAlign()));
1661 Vals.
push_back(
F.hasSection() ? SectionMap[std::string(
F.getSection())]
1673 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1677 Vals.
push_back(addToStrtab(
F.getPartition()));
1679 Vals.
push_back(getEncodedAlign(
F.getPreferredAlignment()));
1681 unsigned AbbrevToUse = 0;
1687 for (
const GlobalAlias &
A :
M.aliases()) {
1694 Vals.
push_back(
A.getType()->getAddressSpace());
1702 Vals.
push_back(addToStrtab(
A.getPartition()));
1705 unsigned AbbrevToUse = 0;
1711 for (
const GlobalIFunc &
I :
M.ifuncs()) {
1717 Vals.
push_back(
I.getType()->getAddressSpace());
1722 Vals.
push_back(addToStrtab(
I.getPartition()));
1728 writeValueSymbolTableForwardDecl();
1735 if (OBO->hasNoSignedWrap())
1737 if (OBO->hasNoUnsignedWrap())
1743 if (PDI->isDisjoint())
1746 if (FPMO->hasAllowReassoc())
1748 if (FPMO->hasNoNaNs())
1750 if (FPMO->hasNoInfs())
1752 if (FPMO->hasNoSignedZeros())
1754 if (FPMO->hasAllowReciprocal())
1756 if (FPMO->hasAllowContract())
1758 if (FPMO->hasApproxFunc())
1761 if (NNI->hasNonNeg())
1764 if (TI->hasNoSignedWrap())
1766 if (TI->hasNoUnsignedWrap())
1769 if (
GEP->isInBounds())
1771 if (
GEP->hasNoUnsignedSignedWrap())
1773 if (
GEP->hasNoUnsignedWrap())
1776 if (ICmp->hasSameSign())
1783void ModuleBitcodeWriter::writeValueAsMetadata(
1784 const ValueAsMetadata *MD, SmallVectorImpl<uint64_t> &Record) {
1793void ModuleBitcodeWriter::writeMDTuple(
const MDTuple *
N,
1794 SmallVectorImpl<uint64_t> &Record,
1796 for (
const MDOperand &MDO :
N->operands()) {
1799 "Unexpected function-local metadata");
1808unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1811 auto Abbv = std::make_shared<BitCodeAbbrev>();
1824void ModuleBitcodeWriter::writeDILocation(
const DILocation *
N,
1825 SmallVectorImpl<uint64_t> &Record,
1828 Abbrev = createDILocationAbbrev();
1830 Record.push_back(
N->isDistinct());
1831 Record.push_back(
N->getLine());
1832 Record.push_back(
N->getColumn());
1835 Record.push_back(
N->isImplicitCode());
1836 Record.push_back(
N->getAtomGroup());
1837 Record.push_back(
N->getAtomRank());
1842unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1845 auto Abbv = std::make_shared<BitCodeAbbrev>();
1856void ModuleBitcodeWriter::writeGenericDINode(
const GenericDINode *
N,
1857 SmallVectorImpl<uint64_t> &Record,
1860 Abbrev = createGenericDINodeAbbrev();
1862 Record.push_back(
N->isDistinct());
1863 Record.push_back(
N->getTag());
1866 for (
auto &
I :
N->operands())
1873void ModuleBitcodeWriter::writeDISubrange(
const DISubrange *
N,
1874 SmallVectorImpl<uint64_t> &Record,
1876 const uint64_t
Version = 2 << 1;
1887void ModuleBitcodeWriter::writeDIGenericSubrange(
1888 const DIGenericSubrange *
N, SmallVectorImpl<uint64_t> &Record,
1890 Record.push_back((uint64_t)
N->isDistinct());
1900void ModuleBitcodeWriter::writeDIEnumerator(
const DIEnumerator *
N,
1901 SmallVectorImpl<uint64_t> &Record,
1903 const uint64_t IsBigInt = 1 << 2;
1904 Record.push_back(IsBigInt | (
N->isUnsigned() << 1) |
N->isDistinct());
1905 Record.push_back(
N->getValue().getBitWidth());
1913void ModuleBitcodeWriter::writeDIBasicType(
const DIBasicType *
N,
1914 SmallVectorImpl<uint64_t> &Record,
1916 const unsigned SizeIsMetadata = 0x2;
1917 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1918 Record.push_back(
N->getTag());
1921 Record.push_back(
N->getAlignInBits());
1922 Record.push_back(
N->getEncoding());
1923 Record.push_back(
N->getFlags());
1924 Record.push_back(
N->getNumExtraInhabitants());
1925 Record.push_back(
N->getDataSizeInBits());
1931void ModuleBitcodeWriter::writeDIFixedPointType(
1932 const DIFixedPointType *
N, SmallVectorImpl<uint64_t> &Record,
1934 const unsigned SizeIsMetadata = 0x2;
1935 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1936 Record.push_back(
N->getTag());
1939 Record.push_back(
N->getAlignInBits());
1940 Record.push_back(
N->getEncoding());
1941 Record.push_back(
N->getFlags());
1942 Record.push_back(
N->getKind());
1943 Record.push_back(
N->getFactorRaw());
1945 auto WriteWideInt = [&](
const APInt &
Value) {
1948 uint64_t NumWords =
Value.getActiveWords();
1949 uint64_t
Encoded = (NumWords << 32) |
Value.getBitWidth();
1950 Record.push_back(Encoded);
1954 WriteWideInt(
N->getNumeratorRaw());
1955 WriteWideInt(
N->getDenominatorRaw());
1961void ModuleBitcodeWriter::writeDIStringType(
const DIStringType *
N,
1962 SmallVectorImpl<uint64_t> &Record,
1964 const unsigned SizeIsMetadata = 0x2;
1965 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1966 Record.push_back(
N->getTag());
1972 Record.push_back(
N->getAlignInBits());
1973 Record.push_back(
N->getEncoding());
1979void ModuleBitcodeWriter::writeDIDerivedType(
const DIDerivedType *
N,
1980 SmallVectorImpl<uint64_t> &Record,
1982 const unsigned SizeIsMetadata = 0x2;
1983 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1984 Record.push_back(
N->getTag());
1987 Record.push_back(
N->getLine());
1991 Record.push_back(
N->getAlignInBits());
1993 Record.push_back(
N->getFlags());
1998 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
1999 Record.push_back(*DWARFAddressSpace + 1);
2005 if (
auto PtrAuthData =
N->getPtrAuthData())
2006 Record.push_back(PtrAuthData->RawData);
2014void ModuleBitcodeWriter::writeDISubrangeType(
const DISubrangeType *
N,
2015 SmallVectorImpl<uint64_t> &Record,
2017 const unsigned SizeIsMetadata = 0x2;
2018 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2021 Record.push_back(
N->getLine());
2024 Record.push_back(
N->getAlignInBits());
2025 Record.push_back(
N->getFlags());
2036void ModuleBitcodeWriter::writeDICompositeType(
2037 const DICompositeType *
N, SmallVectorImpl<uint64_t> &Record,
2039 const unsigned IsNotUsedInOldTypeRef = 0x2;
2040 const unsigned SizeIsMetadata = 0x4;
2041 Record.push_back(SizeIsMetadata | IsNotUsedInOldTypeRef |
2042 (
unsigned)
N->isDistinct());
2043 Record.push_back(
N->getTag());
2046 Record.push_back(
N->getLine());
2050 Record.push_back(
N->getAlignInBits());
2052 Record.push_back(
N->getFlags());
2054 Record.push_back(
N->getRuntimeLang());
2064 Record.push_back(
N->getNumExtraInhabitants());
2074void ModuleBitcodeWriter::writeDISubroutineType(
2075 const DISubroutineType *
N, SmallVectorImpl<uint64_t> &Record,
2077 const unsigned HasNoOldTypeRefs = 0x2;
2078 Record.push_back(HasNoOldTypeRefs | (
unsigned)
N->isDistinct());
2079 Record.push_back(
N->getFlags());
2087void ModuleBitcodeWriter::writeDIFile(
const DIFile *
N,
2088 SmallVectorImpl<uint64_t> &Record,
2090 Record.push_back(
N->isDistinct());
2093 if (
N->getRawChecksum()) {
2094 Record.push_back(
N->getRawChecksum()->Kind);
2102 auto Source =
N->getRawSource();
2110void ModuleBitcodeWriter::writeDICompileUnit(
const DICompileUnit *
N,
2111 SmallVectorImpl<uint64_t> &Record,
2113 assert(
N->isDistinct() &&
"Expected distinct compile units");
2116 auto Lang =
N->getSourceLanguage();
2117 Record.push_back(Lang.getName());
2120 if (Lang.hasVersionedName())
2121 Record.back() ^= (uint64_t(1) << 63);
2125 Record.push_back(
N->isOptimized());
2127 Record.push_back(
N->getRuntimeVersion());
2129 Record.push_back(
N->getEmissionKind());
2135 Record.push_back(
N->getDWOId());
2137 Record.push_back(
N->getSplitDebugInlining());
2138 Record.push_back(
N->getDebugInfoForProfiling());
2139 Record.push_back((
unsigned)
N->getNameTableKind());
2140 Record.push_back(
N->getRangesBaseAddress());
2143 Record.push_back(Lang.hasVersionedName() ? Lang.getVersion() : 0);
2149void ModuleBitcodeWriter::writeDISubprogram(
const DISubprogram *
N,
2150 SmallVectorImpl<uint64_t> &Record,
2152 const uint64_t HasUnitFlag = 1 << 1;
2153 const uint64_t HasSPFlagsFlag = 1 << 2;
2154 Record.push_back(uint64_t(
N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
2159 Record.push_back(
N->getLine());
2161 Record.push_back(
N->getScopeLine());
2163 Record.push_back(
N->getSPFlags());
2164 Record.push_back(
N->getVirtualIndex());
2165 Record.push_back(
N->getFlags());
2170 Record.push_back(
N->getThisAdjustment());
2174 Record.push_back(
N->getKeyInstructionsEnabled());
2180void ModuleBitcodeWriter::writeDILexicalBlock(
const DILexicalBlock *
N,
2181 SmallVectorImpl<uint64_t> &Record,
2183 Record.push_back(
N->isDistinct());
2186 Record.push_back(
N->getLine());
2187 Record.push_back(
N->getColumn());
2193void ModuleBitcodeWriter::writeDILexicalBlockFile(
2194 const DILexicalBlockFile *
N, SmallVectorImpl<uint64_t> &Record,
2196 Record.push_back(
N->isDistinct());
2199 Record.push_back(
N->getDiscriminator());
2205void ModuleBitcodeWriter::writeDICommonBlock(
const DICommonBlock *
N,
2206 SmallVectorImpl<uint64_t> &Record,
2208 Record.push_back(
N->isDistinct());
2213 Record.push_back(
N->getLineNo());
2219void ModuleBitcodeWriter::writeDINamespace(
const DINamespace *
N,
2220 SmallVectorImpl<uint64_t> &Record,
2222 Record.push_back(
N->isDistinct() |
N->getExportSymbols() << 1);
2230void ModuleBitcodeWriter::writeDIMacro(
const DIMacro *
N,
2231 SmallVectorImpl<uint64_t> &Record,
2233 Record.push_back(
N->isDistinct());
2234 Record.push_back(
N->getMacinfoType());
2235 Record.push_back(
N->getLine());
2243void ModuleBitcodeWriter::writeDIMacroFile(
const DIMacroFile *
N,
2244 SmallVectorImpl<uint64_t> &Record,
2246 Record.push_back(
N->isDistinct());
2247 Record.push_back(
N->getMacinfoType());
2248 Record.push_back(
N->getLine());
2256void ModuleBitcodeWriter::writeDIArgList(
const DIArgList *
N,
2257 SmallVectorImpl<uint64_t> &Record) {
2258 Record.reserve(
N->getArgs().size());
2259 for (ValueAsMetadata *MD :
N->getArgs())
2266void ModuleBitcodeWriter::writeDIModule(
const DIModule *
N,
2267 SmallVectorImpl<uint64_t> &Record,
2269 Record.push_back(
N->isDistinct());
2270 for (
auto &
I :
N->operands())
2272 Record.push_back(
N->getLineNo());
2273 Record.push_back(
N->getIsDecl());
2279void ModuleBitcodeWriter::writeDIAssignID(
const DIAssignID *
N,
2280 SmallVectorImpl<uint64_t> &Record,
2283 Record.push_back(
N->isDistinct());
2288void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2289 const DITemplateTypeParameter *
N, SmallVectorImpl<uint64_t> &Record,
2291 Record.push_back(
N->isDistinct());
2294 Record.push_back(
N->isDefault());
2300void ModuleBitcodeWriter::writeDITemplateValueParameter(
2301 const DITemplateValueParameter *
N, SmallVectorImpl<uint64_t> &Record,
2303 Record.push_back(
N->isDistinct());
2304 Record.push_back(
N->getTag());
2307 Record.push_back(
N->isDefault());
2314void ModuleBitcodeWriter::writeDIGlobalVariable(
2315 const DIGlobalVariable *
N, SmallVectorImpl<uint64_t> &Record,
2317 const uint64_t
Version = 2 << 1;
2323 Record.push_back(
N->getLine());
2325 Record.push_back(
N->isLocalToUnit());
2326 Record.push_back(
N->isDefinition());
2329 Record.push_back(
N->getAlignInBits());
2336void ModuleBitcodeWriter::writeDILocalVariable(
2337 const DILocalVariable *
N, SmallVectorImpl<uint64_t> &Record,
2352 const uint64_t HasAlignmentFlag = 1 << 1;
2353 Record.push_back((uint64_t)
N->isDistinct() | HasAlignmentFlag);
2357 Record.push_back(
N->getLine());
2359 Record.push_back(
N->getArg());
2360 Record.push_back(
N->getFlags());
2361 Record.push_back(
N->getAlignInBits());
2368void ModuleBitcodeWriter::writeDILabel(
2369 const DILabel *
N, SmallVectorImpl<uint64_t> &Record,
2371 uint64_t IsArtificialFlag = uint64_t(
N->isArtificial()) << 1;
2372 Record.push_back((uint64_t)
N->isDistinct() | IsArtificialFlag);
2376 Record.push_back(
N->getLine());
2377 Record.push_back(
N->getColumn());
2378 Record.push_back(
N->getCoroSuspendIdx().has_value()
2379 ? (uint64_t)
N->getCoroSuspendIdx().value()
2380 : std::numeric_limits<uint64_t>::max());
2386void ModuleBitcodeWriter::writeDIExpression(
const DIExpression *
N,
2387 SmallVectorImpl<uint64_t> &Record,
2389 Record.reserve(
N->getElements().size() + 1);
2390 const uint64_t
Version = 3 << 1;
2392 Record.append(
N->elements_begin(),
N->elements_end());
2398void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2399 const DIGlobalVariableExpression *
N, SmallVectorImpl<uint64_t> &Record,
2401 Record.push_back(
N->isDistinct());
2409void ModuleBitcodeWriter::writeDIObjCProperty(
const DIObjCProperty *
N,
2410 SmallVectorImpl<uint64_t> &Record,
2412 Record.push_back(
N->isDistinct());
2415 Record.push_back(
N->getLine());
2418 Record.push_back(
N->getAttributes());
2425void ModuleBitcodeWriter::writeDIImportedEntity(
2426 const DIImportedEntity *
N, SmallVectorImpl<uint64_t> &Record,
2428 Record.push_back(
N->isDistinct());
2429 Record.push_back(
N->getTag());
2432 Record.push_back(
N->getLine());
2441unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2442 auto Abbv = std::make_shared<BitCodeAbbrev>();
2449void ModuleBitcodeWriter::writeNamedMetadata(
2450 SmallVectorImpl<uint64_t> &Record) {
2451 if (
M.named_metadata_empty())
2454 unsigned Abbrev = createNamedMetadataAbbrev();
2455 for (
const NamedMDNode &NMD :
M.named_metadata()) {
2457 StringRef Str = NMD.getName();
2458 Record.append(Str.bytes_begin(), Str.bytes_end());
2463 for (
const MDNode *
N : NMD.operands())
2470unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2471 auto Abbv = std::make_shared<BitCodeAbbrev>();
2483void ModuleBitcodeWriter::writeMetadataStrings(
2485 if (Strings.
empty())
2493 SmallString<256> Blob;
2495 BitstreamWriter
W(Blob);
2515#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
2516#include "llvm/IR/Metadata.def"
2520void ModuleBitcodeWriter::writeMetadataRecords(
2522 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2527#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
2528#include "llvm/IR/Metadata.def"
2534 assert(
N->isResolved() &&
"Expected forward references to be resolved");
2536 switch (
N->getMetadataID()) {
2539#define HANDLE_MDNODE_LEAF(CLASS) \
2540 case Metadata::CLASS##Kind: \
2542 write##CLASS(cast<CLASS>(N), Record, \
2543 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
2545 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
2547#include "llvm/IR/Metadata.def"
2558void ModuleBitcodeWriter::writeModuleMetadata() {
2559 if (!VE.
hasMDs() &&
M.named_metadata_empty())
2563 SmallVector<uint64_t, 64>
Record;
2567 std::vector<unsigned> MDAbbrevs;
2570 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2571 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2572 createGenericDINodeAbbrev();
2574 auto Abbv = std::make_shared<BitCodeAbbrev>();
2578 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2580 Abbv = std::make_shared<BitCodeAbbrev>();
2584 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2596 uint64_t Vals[] = {0, 0};
2606 std::vector<uint64_t> IndexPos;
2610 writeMetadataRecords(VE.
getNonMDStrings(), Record, &MDAbbrevs, &IndexPos);
2621 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2622 for (
auto &Elt : IndexPos) {
2623 auto EltDelta = Elt - PreviousValue;
2624 PreviousValue = Elt;
2633 writeNamedMetadata(Record);
2635 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2636 SmallVector<uint64_t, 4>
Record;
2638 pushGlobalMetadataAttachment(Record, GO);
2641 for (
const Function &
F : M)
2642 if (
F.isDeclaration() &&
F.hasMetadata())
2643 AddDeclAttachedMetadata(
F);
2644 for (
const GlobalIFunc &GI :
M.ifuncs())
2645 if (GI.hasMetadata())
2646 AddDeclAttachedMetadata(GI);
2649 for (
const GlobalVariable &GV :
M.globals())
2650 if (GV.hasMetadata())
2651 AddDeclAttachedMetadata(GV);
2656void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2661 SmallVector<uint64_t, 64>
Record;
2667void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2668 SmallVectorImpl<uint64_t> &Record,
const GlobalObject &GO) {
2672 for (
const auto &
I : MDs) {
2678void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &
F) {
2681 SmallVector<uint64_t, 64>
Record;
2683 if (
F.hasMetadata()) {
2684 pushGlobalMetadataAttachment(Record,
F);
2692 for (
const BasicBlock &BB :
F)
2693 for (
const Instruction &
I : BB) {
2695 I.getAllMetadataOtherThanDebugLoc(MDs);
2698 if (MDs.
empty())
continue;
2702 for (
const auto &[
ID, MD] : MDs) {
2713void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2714 SmallVector<uint64_t, 64>
Record;
2719 M.getMDKindNames(Names);
2721 if (Names.
empty())
return;
2725 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2726 Record.push_back(MDKindID);
2727 StringRef KName = Names[MDKindID];
2737void ModuleBitcodeWriter::writeOperandBundleTags() {
2745 M.getOperandBundleTags(Tags);
2752 SmallVector<uint64_t, 64>
Record;
2754 for (
auto Tag : Tags) {
2764void ModuleBitcodeWriter::writeSyncScopeNames() {
2766 M.getContext().getSyncScopeNames(SSNs);
2772 SmallVector<uint64_t, 64>
Record;
2773 for (
auto SSN : SSNs) {
2774 Record.append(SSN.begin(), SSN.end());
2782void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2784 if (FirstVal == LastVal)
return;
2788 unsigned AggregateAbbrev = 0;
2789 unsigned String8Abbrev = 0;
2790 unsigned CString7Abbrev = 0;
2791 unsigned CString6Abbrev = 0;
2795 auto Abbv = std::make_shared<BitCodeAbbrev>();
2799 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2802 Abbv = std::make_shared<BitCodeAbbrev>();
2806 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2808 Abbv = std::make_shared<BitCodeAbbrev>();
2812 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2814 Abbv = std::make_shared<BitCodeAbbrev>();
2818 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2821 SmallVector<uint64_t, 64>
Record;
2824 Type *LastTy =
nullptr;
2825 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2826 const Value *
V = Vals[i].first;
2828 if (
V->getType() != LastTy) {
2829 LastTy =
V->getType();
2832 CONSTANTS_SETTYPE_ABBREV);
2839 unsigned(
IA->hasSideEffects()) |
unsigned(
IA->isAlignStack()) << 1 |
2840 unsigned(
IA->getDialect() & 1) << 2 |
unsigned(
IA->canThrow()) << 3);
2843 StringRef AsmStr =
IA->getAsmString();
2848 StringRef ConstraintStr =
IA->getConstraintString();
2856 unsigned Code = -1U;
2857 unsigned AbbrevToUse = 0;
2858 if (
C->isNullValue()) {
2865 if (
IV->getBitWidth() <= 64) {
2866 uint64_t
V =
IV->getSExtValue();
2869 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2879 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2883 APInt api = CFP->getValueAPF().bitcastToAPInt();
2885 Record.push_back((p[1] << 48) | (p[0] >> 16));
2886 Record.push_back(p[0] & 0xffffLL);
2888 APInt api = CFP->getValueAPF().bitcastToAPInt();
2893 assert(0 &&
"Unknown FP type!");
2899 uint64_t NumElts = Str->getNumElements();
2901 if (Str->isCString()) {
2906 AbbrevToUse = String8Abbrev;
2910 for (uint64_t i = 0; i != NumElts; ++i) {
2911 unsigned char V = Str->getElementAsInteger(i);
2913 isCStr7 &= (
V & 128) == 0;
2919 AbbrevToUse = CString6Abbrev;
2921 AbbrevToUse = CString7Abbrev;
2922 }
else if (
const ConstantDataSequential *CDS =
2925 Type *EltTy = CDS->getElementType();
2927 for (uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
2928 Record.push_back(CDS->getElementAsInteger(i));
2930 for (uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
2932 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2936 for (
const Value *
Op :
C->operands())
2938 AbbrevToUse = AggregateAbbrev;
2940 switch (
CE->getOpcode()) {
2947 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2949 assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2959 case Instruction::FNeg: {
2960 assert(
CE->getNumOperands() == 1 &&
"Unknown constant expr!");
2969 case Instruction::GetElementPtr: {
2974 if (std::optional<ConstantRange>
Range = GO->getInRange()) {
2978 for (
const Value *
Op :
CE->operands()) {
2984 case Instruction::ExtractElement:
2991 case Instruction::InsertElement:
2998 case Instruction::ShuffleVector:
3003 if (
C->getType() ==
C->getOperand(0)->getType()) {
3040 Stream.
EmitRecord(Code, Record, AbbrevToUse);
3047void ModuleBitcodeWriter::writeModuleConstants() {
3052 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
3054 writeConstants(i, Vals.size(),
true);
3068bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
3069 SmallVectorImpl<unsigned> &Vals) {
3073 if (ValID >= InstID) {
3080bool ModuleBitcodeWriter::pushValueOrMetadata(
const Value *V,
unsigned InstID,
3081 SmallVectorImpl<unsigned> &Vals) {
3082 bool IsMetadata =
V->getType()->isMetadataTy();
3090 return pushValueAndType(V, InstID, Vals);
3093void ModuleBitcodeWriter::writeOperandBundles(
const CallBase &CS,
3100 Record.push_back(
C.getOperandBundleTagID(Bundle.getTagName()));
3102 for (
auto &Input : Bundle.Inputs)
3103 pushValueOrMetadata(Input, InstID, Record);
3112void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
3113 SmallVectorImpl<unsigned> &Vals) {
3118void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
3119 SmallVectorImpl<uint64_t> &Vals) {
3121 int64_t diff = ((int32_t)InstID - (int32_t)ValID);
3126void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
3128 SmallVectorImpl<unsigned> &Vals) {
3130 unsigned AbbrevToUse = 0;
3132 switch (
I.getOpcode()) {
3136 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3137 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
3142 if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
3143 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
3149 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3150 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
3151 pushValue(
I.getOperand(1), InstID, Vals);
3155 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
3156 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
3161 case Instruction::FNeg: {
3163 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3164 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
3168 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
3169 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
3174 case Instruction::GetElementPtr: {
3176 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
3180 for (
const Value *
Op :
I.operands())
3181 pushValueAndType(
Op, InstID, Vals);
3184 case Instruction::ExtractValue: {
3186 pushValueAndType(
I.getOperand(0), InstID, Vals);
3191 case Instruction::InsertValue: {
3193 pushValueAndType(
I.getOperand(0), InstID, Vals);
3194 pushValueAndType(
I.getOperand(1), InstID, Vals);
3199 case Instruction::Select: {
3201 pushValueAndType(
I.getOperand(1), InstID, Vals);
3202 pushValue(
I.getOperand(2), InstID, Vals);
3203 pushValueAndType(
I.getOperand(0), InstID, Vals);
3209 case Instruction::ExtractElement:
3211 pushValueAndType(
I.getOperand(0), InstID, Vals);
3212 pushValueAndType(
I.getOperand(1), InstID, Vals);
3214 case Instruction::InsertElement:
3216 pushValueAndType(
I.getOperand(0), InstID, Vals);
3217 pushValue(
I.getOperand(1), InstID, Vals);
3218 pushValueAndType(
I.getOperand(2), InstID, Vals);
3220 case Instruction::ShuffleVector:
3222 pushValueAndType(
I.getOperand(0), InstID, Vals);
3223 pushValue(
I.getOperand(1), InstID, Vals);
3227 case Instruction::ICmp:
3228 case Instruction::FCmp: {
3231 AbbrevToUse = FUNCTION_INST_CMP_ABBREV;
3232 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3234 pushValue(
I.getOperand(1), InstID, Vals);
3240 AbbrevToUse = FUNCTION_INST_CMP_FLAGS_ABBREV;
3245 case Instruction::Ret:
3248 unsigned NumOperands =
I.getNumOperands();
3249 if (NumOperands == 0)
3250 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
3251 else if (NumOperands == 1) {
3252 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3253 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
3255 for (
const Value *
Op :
I.operands())
3256 pushValueAndType(
Op, InstID, Vals);
3260 case Instruction::Br:
3263 AbbrevToUse = FUNCTION_INST_BR_UNCOND_ABBREV;
3266 if (
II.isConditional()) {
3268 pushValue(
II.getCondition(), InstID, Vals);
3269 AbbrevToUse = FUNCTION_INST_BR_COND_ABBREV;
3273 case Instruction::Switch:
3278 pushValue(
SI.getCondition(), InstID, Vals);
3280 for (
auto Case :
SI.cases()) {
3286 case Instruction::IndirectBr:
3290 pushValue(
I.getOperand(0), InstID, Vals);
3295 case Instruction::Invoke: {
3298 FunctionType *FTy =
II->getFunctionType();
3300 if (
II->hasOperandBundles())
3301 writeOperandBundles(*
II, InstID);
3310 pushValueAndType(Callee, InstID, Vals);
3313 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3314 pushValue(
I.getOperand(i), InstID, Vals);
3317 if (FTy->isVarArg()) {
3318 for (
unsigned i = FTy->getNumParams(), e =
II->arg_size(); i != e; ++i)
3319 pushValueAndType(
I.getOperand(i), InstID, Vals);
3323 case Instruction::Resume:
3325 pushValueAndType(
I.getOperand(0), InstID, Vals);
3327 case Instruction::CleanupRet: {
3330 pushValue(CRI.getCleanupPad(), InstID, Vals);
3331 if (CRI.hasUnwindDest())
3335 case Instruction::CatchRet: {
3338 pushValue(CRI.getCatchPad(), InstID, Vals);
3342 case Instruction::CleanupPad:
3343 case Instruction::CatchPad: {
3347 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3349 unsigned NumArgOperands = FuncletPad.arg_size();
3351 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
3352 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
3355 case Instruction::CatchSwitch: {
3359 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3361 unsigned NumHandlers = CatchSwitch.getNumHandlers();
3363 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
3366 if (CatchSwitch.hasUnwindDest())
3370 case Instruction::CallBr: {
3376 writeOperandBundles(*CBI, InstID);
3391 pushValueAndType(Callee, InstID, Vals);
3394 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3395 pushValue(
I.getOperand(i), InstID, Vals);
3398 if (FTy->isVarArg()) {
3399 for (
unsigned i = FTy->getNumParams(), e = CBI->
arg_size(); i != e; ++i)
3400 pushValueAndType(
I.getOperand(i), InstID, Vals);
3404 case Instruction::Unreachable:
3406 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3409 case Instruction::PHI: {
3427 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
3432 case Instruction::LandingPad: {
3443 pushValueAndType(LP.
getClause(
I), InstID, Vals);
3448 case Instruction::Alloca: {
3454 using APV = AllocaPackedValues;
3456 unsigned EncodedAlign = getEncodedAlign(AI.
getAlign());
3458 Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3460 EncodedAlign >> APV::AlignLower::Bits);
3467 if (AS !=
M.getDataLayout().getAllocaAddrSpace())
3472 case Instruction::Load:
3475 pushValueAndType(
I.getOperand(0), InstID, Vals);
3478 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3479 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3489 case Instruction::Store:
3494 AbbrevToUse = FUNCTION_INST_STORE_ABBREV;
3496 if (pushValueAndType(
I.getOperand(1), InstID, Vals))
3498 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3508 case Instruction::AtomicCmpXchg:
3510 pushValueAndType(
I.getOperand(0), InstID, Vals);
3511 pushValueAndType(
I.getOperand(1), InstID, Vals);
3512 pushValue(
I.getOperand(2), InstID, Vals);
3523 case Instruction::AtomicRMW:
3525 pushValueAndType(
I.getOperand(0), InstID, Vals);
3526 pushValueAndType(
I.getOperand(1), InstID, Vals);
3535 case Instruction::Fence:
3540 case Instruction::Call: {
3545 writeOperandBundles(CI, InstID);
3565 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3569 if (FTy->isVarArg()) {
3570 for (
unsigned i = FTy->getNumParams(), e = CI.
arg_size(); i != e; ++i)
3575 case Instruction::VAArg:
3578 pushValue(
I.getOperand(0), InstID, Vals);
3581 case Instruction::Freeze:
3583 pushValueAndType(
I.getOperand(0), InstID, Vals);
3593void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3594 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3599 VSTOffset -= bitcodeStartBit();
3600 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
3604 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3608 auto Abbv = std::make_shared<BitCodeAbbrev>();
3612 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3614 for (
const Function &
F : M) {
3617 if (
F.isDeclaration())
3624 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
3625 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
3629 Record[1] = BitcodeIndex / 32 + 1;
3638void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3639 const ValueSymbolTable &VST) {
3647 SmallVector<uint64_t, 64> NameVals;
3653 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3662 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3666 AbbrevToUse = VST_ENTRY_6_ABBREV;
3668 AbbrevToUse = VST_ENTRY_7_ABBREV;
3671 for (
const auto P :
Name.getKey())
3675 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3682void ModuleBitcodeWriter::writeUseList(UseListOrder &&Order) {
3683 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3690 SmallVector<uint64_t, 64>
Record(Order.Shuffle.begin(), Order.Shuffle.end());
3695void ModuleBitcodeWriter::writeUseListBlock(
const Function *
F) {
3697 "Expected to be preserving use-list order");
3699 auto hasMore = [&]() {
3715void ModuleBitcodeWriter::writeFunction(
3717 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3734 unsigned CstStart, CstEnd;
3736 writeConstants(CstStart, CstEnd,
false);
3739 writeFunctionMetadata(
F);
3742 unsigned InstID = CstEnd;
3744 bool NeedsMetadataAttachment =
F.hasMetadata();
3746 DILocation *LastDL =
nullptr;
3747 SmallSetVector<Function *, 4> BlockAddressUsers;
3750 for (
const BasicBlock &BB :
F) {
3751 for (
const Instruction &
I : BB) {
3752 writeInstruction(
I, InstID, Vals);
3754 if (!
I.getType()->isVoidTy())
3758 NeedsMetadataAttachment |=
I.hasMetadataOtherThanDebugLoc();
3761 if (DILocation *
DL =
I.getDebugLoc()) {
3774 FUNCTION_DEBUG_LOC_ABBREV);
3784 if (
I.hasDbgRecords()) {
3788 auto PushValueOrMetadata = [&Vals, InstID,
3791 "RawLocation unexpectedly null in DbgVariableRecord");
3793 SmallVector<unsigned, 2> ValAndType;
3797 if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
3811 for (DbgRecord &DR :
I.DebugMarker->getDbgRecordRange()) {
3837 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3861 SmallPtrSet<Value *, 8> Visited{BA};
3862 while (!Worklist.
empty()) {
3864 for (User *U :
V->users()) {
3870 Visited.
insert(U).second)
3877 if (!BlockAddressUsers.
empty()) {
3886 if (
auto *Symtab =
F.getValueSymbolTable())
3887 writeFunctionLevelValueSymbolTable(*Symtab);
3889 if (NeedsMetadataAttachment)
3890 writeFunctionMetadataAttachment(
F);
3892 writeUseListBlock(&
F);
3898void ModuleBitcodeWriter::writeBlockInfo() {
3911 auto Abbv = std::make_shared<BitCodeAbbrev>();
3922 auto Abbv = std::make_shared<BitCodeAbbrev>();
3932 auto Abbv = std::make_shared<BitCodeAbbrev>();
3942 auto Abbv = std::make_shared<BitCodeAbbrev>();
3948 VST_BBENTRY_6_ABBREV)
3953 auto Abbv = std::make_shared<BitCodeAbbrev>();
3955 Abbv->Add(TypeAbbrevOp);
3957 CONSTANTS_SETTYPE_ABBREV)
3962 auto Abbv = std::make_shared<BitCodeAbbrev>();
3966 CONSTANTS_INTEGER_ABBREV)
3971 auto Abbv = std::make_shared<BitCodeAbbrev>();
3979 CONSTANTS_CE_CAST_Abbrev)
3983 auto Abbv = std::make_shared<BitCodeAbbrev>();
3986 CONSTANTS_NULL_Abbrev)
3993 auto Abbv = std::make_shared<BitCodeAbbrev>();
3995 Abbv->Add(ValAbbrevOp);
3996 Abbv->Add(TypeAbbrevOp);
4000 FUNCTION_INST_LOAD_ABBREV)
4004 auto Abbv = std::make_shared<BitCodeAbbrev>();
4006 Abbv->Add(ValAbbrevOp);
4007 Abbv->Add(ValAbbrevOp);
4011 FUNCTION_INST_STORE_ABBREV)
4015 auto Abbv = std::make_shared<BitCodeAbbrev>();
4017 Abbv->Add(ValAbbrevOp);
4020 FUNCTION_INST_UNOP_ABBREV)
4024 auto Abbv = std::make_shared<BitCodeAbbrev>();
4026 Abbv->Add(ValAbbrevOp);
4030 FUNCTION_INST_UNOP_FLAGS_ABBREV)
4034 auto Abbv = std::make_shared<BitCodeAbbrev>();
4036 Abbv->Add(ValAbbrevOp);
4037 Abbv->Add(ValAbbrevOp);
4040 FUNCTION_INST_BINOP_ABBREV)
4044 auto Abbv = std::make_shared<BitCodeAbbrev>();
4046 Abbv->Add(ValAbbrevOp);
4047 Abbv->Add(ValAbbrevOp);
4051 FUNCTION_INST_BINOP_FLAGS_ABBREV)
4055 auto Abbv = std::make_shared<BitCodeAbbrev>();
4057 Abbv->Add(ValAbbrevOp);
4058 Abbv->Add(TypeAbbrevOp);
4061 FUNCTION_INST_CAST_ABBREV)
4065 auto Abbv = std::make_shared<BitCodeAbbrev>();
4067 Abbv->Add(ValAbbrevOp);
4068 Abbv->Add(TypeAbbrevOp);
4072 FUNCTION_INST_CAST_FLAGS_ABBREV)
4077 auto Abbv = std::make_shared<BitCodeAbbrev>();
4080 FUNCTION_INST_RET_VOID_ABBREV)
4084 auto Abbv = std::make_shared<BitCodeAbbrev>();
4086 Abbv->Add(ValAbbrevOp);
4088 FUNCTION_INST_RET_VAL_ABBREV)
4092 auto Abbv = std::make_shared<BitCodeAbbrev>();
4095 Abbv->Add(ValAbbrevOp);
4097 FUNCTION_INST_BR_UNCOND_ABBREV)
4101 auto Abbv = std::make_shared<BitCodeAbbrev>();
4104 Abbv->Add(ValAbbrevOp);
4105 Abbv->Add(ValAbbrevOp);
4106 Abbv->Add(ValAbbrevOp);
4108 FUNCTION_INST_BR_COND_ABBREV)
4112 auto Abbv = std::make_shared<BitCodeAbbrev>();
4115 FUNCTION_INST_UNREACHABLE_ABBREV)
4119 auto Abbv = std::make_shared<BitCodeAbbrev>();
4122 Abbv->Add(TypeAbbrevOp);
4124 Abbv->Add(ValAbbrevOp);
4126 FUNCTION_INST_GEP_ABBREV)
4130 auto Abbv = std::make_shared<BitCodeAbbrev>();
4132 Abbv->Add(ValAbbrevOp);
4133 Abbv->Add(ValAbbrevOp);
4136 FUNCTION_INST_CMP_ABBREV)
4140 auto Abbv = std::make_shared<BitCodeAbbrev>();
4142 Abbv->Add(ValAbbrevOp);
4143 Abbv->Add(ValAbbrevOp);
4147 FUNCTION_INST_CMP_FLAGS_ABBREV)
4151 auto Abbv = std::make_shared<BitCodeAbbrev>();
4156 Abbv->Add(ValAbbrevOp);
4158 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
4162 auto Abbv = std::make_shared<BitCodeAbbrev>();
4173 FUNCTION_DEBUG_LOC_ABBREV)
4181void IndexBitcodeWriter::writeModStrings() {
4187 auto Abbv = std::make_shared<BitCodeAbbrev>();
4192 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
4195 Abbv = std::make_shared<BitCodeAbbrev>();
4200 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
4203 Abbv = std::make_shared<BitCodeAbbrev>();
4208 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
4211 Abbv = std::make_shared<BitCodeAbbrev>();
4218 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
4221 forEachModule([&](
const StringMapEntry<ModuleHash> &MPSE) {
4223 const auto &Hash = MPSE.
getValue();
4225 unsigned AbbrevToUse = Abbrev8Bit;
4227 AbbrevToUse = Abbrev6Bit;
4229 AbbrevToUse = Abbrev7Bit;
4231 auto ModuleId = ModuleIdMap.
size();
4232 ModuleIdMap[
Key] = ModuleId;
4241 Vals.
assign(Hash.begin(), Hash.end());
4253template <
typename Fn>
4257 if (!FS->type_tests().empty())
4262 auto WriteVFuncIdVec = [&](
uint64_t Ty,
4267 for (
auto &VF : VFs) {
4268 Record.push_back(VF.GUID);
4269 Record.push_back(VF.Offset);
4275 FS->type_test_assume_vcalls());
4277 FS->type_checked_load_vcalls());
4279 auto WriteConstVCallVec = [&](
uint64_t Ty,
4281 for (
auto &VC : VCs) {
4283 Record.push_back(VC.VFunc.GUID);
4284 Record.push_back(VC.VFunc.Offset);
4291 FS->type_test_assume_const_vcalls());
4293 FS->type_checked_load_const_vcalls());
4303 if (!FS->paramAccesses().empty()) {
4305 for (
auto &Arg : FS->paramAccesses()) {
4306 size_t UndoSize =
Record.size();
4307 Record.push_back(Arg.ParamNo);
4308 WriteRange(Arg.Use);
4309 Record.push_back(Arg.Calls.size());
4310 for (
auto &
Call : Arg.Calls) {
4312 std::optional<unsigned> ValueID = GetValueID(
Call.Callee);
4319 Record.push_back(*ValueID);
4320 WriteRange(
Call.Offsets);
4331 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
4332 if (!FS->type_tests().empty())
4333 for (
auto &TT : FS->type_tests())
4334 ReferencedTypeIds.insert(TT);
4336 auto GetReferencedTypesFromVFuncIdVec =
4338 for (
auto &VF : VFs)
4339 ReferencedTypeIds.insert(VF.GUID);
4342 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4343 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4345 auto GetReferencedTypesFromConstVCallVec =
4347 for (
auto &VC : VCs)
4348 ReferencedTypeIds.insert(VC.VFunc.GUID);
4351 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4352 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
4388 NameVals.
push_back(Summary.TTRes.TheKind);
4389 NameVals.
push_back(Summary.TTRes.SizeM1BitWidth);
4390 NameVals.
push_back(Summary.TTRes.AlignLog2);
4391 NameVals.
push_back(Summary.TTRes.SizeM1);
4392 NameVals.
push_back(Summary.TTRes.BitMask);
4393 NameVals.
push_back(Summary.TTRes.InlineBits);
4395 for (
auto &W : Summary.WPDRes)
4407 for (
auto &
P : Summary) {
4409 NameVals.
push_back(
VE.getValueID(
P.VTableVI.getValue()));
4423 static_assert(std::is_same_v<LinearFrameId, unsigned>);
4424 for (
auto &AI : FS->allocs()) {
4425 for (
auto &MIB : AI.MIBs) {
4427 StackIdIndices.
reserve(MIB.StackIdIndices.size());
4428 for (
auto Id : MIB.StackIdIndices)
4429 StackIdIndices.
push_back(GetStackIndex(Id));
4431 CallStacks.insert({CallStacks.size(), StackIdIndices});
4444 assert(!CallStacks.empty());
4450 Builder.
build(std::move(CallStacks),
nullptr,
4454 return Builder.takeCallStackPos();
4459 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
bool PerModule,
4460 std::function<
unsigned(
const ValueInfo &VI)> GetValueID,
4461 std::function<
unsigned(
unsigned)> GetStackIndex,
4462 bool WriteContextSizeInfoIndex,
4467 for (
auto &CI : FS->callsites()) {
4471 assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4472 Record.push_back(GetValueID(CI.Callee));
4474 Record.push_back(CI.StackIdIndices.size());
4475 Record.push_back(CI.Clones.size());
4477 for (
auto Id : CI.StackIdIndices)
4478 Record.push_back(GetStackIndex(Id));
4486 for (
auto &AI : FS->allocs()) {
4490 assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4491 Record.push_back(AI.MIBs.size());
4493 Record.push_back(AI.Versions.size());
4494 for (
auto &MIB : AI.MIBs) {
4501 assert(CallStackCount <= CallStackPos.
size());
4502 Record.push_back(CallStackPos[CallStackCount++]);
4507 assert(AI.ContextSizeInfos.empty() ||
4508 AI.ContextSizeInfos.size() == AI.MIBs.size());
4510 if (WriteContextSizeInfoIndex && !AI.ContextSizeInfos.empty()) {
4518 ContextIds.
reserve(AI.ContextSizeInfos.size() * 2);
4519 for (
auto &Infos : AI.ContextSizeInfos) {
4520 Record.push_back(Infos.size());
4521 for (
auto [FullStackId, TotalSize] : Infos) {
4528 Record.push_back(TotalSize);
4546void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4547 SmallVector<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
4548 unsigned ValueID,
unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
4549 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
const Function &
F,
4550 DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
4557 Stream, FS, [&](
const ValueInfo &VI) -> std::optional<unsigned> {
4562 Stream, FS, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
4564 [&](
const ValueInfo &VI) {
return getValueId(VI); },
4565 [&](
unsigned I) {
return I; },
4566 true, CallStackPos, CallStackCount);
4568 auto SpecialRefCnts =
FS->specialRefCounts();
4573 NameVals.
push_back(SpecialRefCnts.first);
4574 NameVals.
push_back(SpecialRefCnts.second);
4576 for (
auto &RI :
FS->refs())
4579 for (
auto &ECI :
FS->calls()) {
4580 NameVals.
push_back(getValueId(ECI.first));
4591void ModuleBitcodeWriterBase::writeModuleLevelReferences(
4592 const GlobalVariable &V, SmallVector<uint64_t, 64> &NameVals,
4593 unsigned FSModRefsAbbrev,
unsigned FSModVTableRefsAbbrev) {
4594 auto VI =
Index->getValueInfo(
V.getGUID());
4595 if (!VI ||
VI.getSummaryList().empty()) {
4601 auto *
Summary =
VI.getSummaryList()[0].get();
4607 auto VTableFuncs =
VS->vTableFuncs();
4608 if (!VTableFuncs.empty())
4611 unsigned SizeBeforeRefs = NameVals.
size();
4612 for (
auto &RI :
VS->refs())
4618 if (VTableFuncs.empty())
4623 for (
auto &
P : VTableFuncs) {
4629 FSModVTableRefsAbbrev);
4636void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
4639 bool IsThinLTO =
true;
4642 IsThinLTO = MD->getZExtValue();
4654 if (
Index->enableSplitLTOUnit())
4656 if (
Index->hasUnifiedLTO())
4666 auto Abbv = std::make_shared<BitCodeAbbrev>();
4672 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4674 for (
const auto &GVI : valueIds()) {
4676 ArrayRef<uint32_t>{GVI.second,
4677 static_cast<uint32_t
>(GVI.first >> 32),
4678 static_cast<uint32_t
>(GVI.first)},
4682 if (!
Index->stackIds().empty()) {
4683 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4690 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4691 SmallVector<uint32_t> Vals;
4693 for (
auto Id :
Index->stackIds()) {
4694 Vals.
push_back(
static_cast<uint32_t
>(Id >> 32));
4695 Vals.
push_back(
static_cast<uint32_t
>(Id));
4700 unsigned ContextIdAbbvId = 0;
4703 auto ContextIdAbbv = std::make_shared<BitCodeAbbrev>();
4715 ContextIdAbbvId = Stream.
EmitAbbrev(std::move(ContextIdAbbv));
4719 Abbv = std::make_shared<BitCodeAbbrev>();
4731 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4734 Abbv = std::make_shared<BitCodeAbbrev>();
4740 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4743 Abbv = std::make_shared<BitCodeAbbrev>();
4751 unsigned FSModVTableRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4754 Abbv = std::make_shared<BitCodeAbbrev>();
4759 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4762 Abbv = std::make_shared<BitCodeAbbrev>();
4769 unsigned TypeIdCompatibleVtableAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4771 Abbv = std::make_shared<BitCodeAbbrev>();
4777 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4779 Abbv = std::make_shared<BitCodeAbbrev>();
4786 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4788 Abbv = std::make_shared<BitCodeAbbrev>();
4793 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4800 MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
4801 for (
const Function &
F : M) {
4807 ValueInfo
VI =
Index->getValueInfo(
F.getGUID());
4808 if (!VI ||
VI.getSummaryList().empty()) {
4814 auto *
Summary =
VI.getSummaryList()[0].get();
4817 FS, [](
unsigned I) {
return I; }, CallStacks);
4821 DenseMap<CallStackId, LinearCallStackId> CallStackPos;
4822 if (!CallStacks.
empty()) {
4830 SmallVector<uint64_t, 64> NameVals;
4833 for (
const Function &
F : M) {
4839 ValueInfo
VI =
Index->getValueInfo(
F.getGUID());
4840 if (!VI ||
VI.getSummaryList().empty()) {
4846 auto *
Summary =
VI.getSummaryList()[0].get();
4847 writePerModuleFunctionSummaryRecord(NameVals, Summary, VE.
getValueID(&
F),
4848 FSCallsProfileAbbrev, CallsiteAbbrev,
4849 AllocAbbrev, ContextIdAbbvId,
F,
4850 CallStackPos, CallStackCount);
4855 for (
const GlobalVariable &
G :
M.globals())
4856 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev,
4857 FSModVTableRefsAbbrev);
4859 for (
const GlobalAlias &
A :
M.aliases()) {
4860 auto *Aliasee =
A.getAliaseeObject();
4876 for (
auto &S :
Index->typeIdCompatibleVtableMap()) {
4880 TypeIdCompatibleVtableAbbrev);
4884 if (
Index->getBlockCount())
4886 ArrayRef<uint64_t>{
Index->getBlockCount()});
4892void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4901 auto Abbv = std::make_shared<BitCodeAbbrev>();
4907 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4909 for (
const auto &GVI : valueIds()) {
4911 ArrayRef<uint32_t>{GVI.second,
4912 static_cast<uint32_t
>(GVI.first >> 32),
4913 static_cast<uint32_t
>(GVI.first)},
4919 if (!StackIds.empty()) {
4920 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4927 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4928 SmallVector<uint32_t> Vals;
4929 Vals.
reserve(StackIds.size() * 2);
4930 for (
auto Id : StackIds) {
4931 Vals.
push_back(
static_cast<uint32_t
>(Id >> 32));
4932 Vals.
push_back(
static_cast<uint32_t
>(Id));
4938 Abbv = std::make_shared<BitCodeAbbrev>();
4952 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4955 Abbv = std::make_shared<BitCodeAbbrev>();
4962 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4965 Abbv = std::make_shared<BitCodeAbbrev>();
4971 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4973 Abbv = std::make_shared<BitCodeAbbrev>();
4981 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4983 Abbv = std::make_shared<BitCodeAbbrev>();
4994 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4996 auto shouldImportValueAsDecl = [&](GlobalValueSummary *GVS) ->
bool {
4997 if (DecSummaries ==
nullptr)
4999 return DecSummaries->count(GVS);
5007 DenseMap<const GlobalValueSummary *, unsigned> SummaryToValueIdMap;
5009 SmallVector<uint64_t, 64> NameVals;
5013 std::set<GlobalValue::GUID> ReferencedTypeIds;
5017 auto MaybeEmitOriginalName = [&](GlobalValueSummary &S) {
5027 NameVals.
push_back(S.getOriginalName());
5032 DenseMap<CallStackId, LinearCallStackId> CallStackPos;
5034 Abbv = std::make_shared<BitCodeAbbrev>();
5039 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5046 MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
5047 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5053 GlobalValueSummary *S =
I.second;
5066 return StackIdIndicesToIndex[
I];
5072 if (!CallStacks.
empty()) {
5082 DenseSet<GlobalValue::GUID> DefOrUseGUIDs;
5083 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5084 GlobalValueSummary *S =
I.second;
5086 DefOrUseGUIDs.
insert(
I.first);
5087 for (
const ValueInfo &VI : S->
refs())
5088 DefOrUseGUIDs.
insert(
VI.getGUID());
5090 auto ValueId = getValueId(
I.first);
5092 SummaryToValueIdMap[S] = *ValueId;
5110 NameVals.
push_back(ModuleIdMap[
VS->modulePath()]);
5114 for (
auto &RI :
VS->refs()) {
5115 auto RefValueId = getValueId(RI.getGUID());
5125 MaybeEmitOriginalName(*S);
5129 auto GetValueId = [&](
const ValueInfo &
VI) -> std::optional<unsigned> {
5131 return std::nullopt;
5132 return getValueId(
VI.getGUID());
5140 Stream, FS, CallsiteAbbrev, AllocAbbrev, 0,
5143 [&](
const ValueInfo &VI) ->
unsigned {
5144 std::optional<unsigned> ValueID = GetValueId(VI);
5159 return StackIdIndicesToIndex[
I];
5161 false, CallStackPos, CallStackCount);
5165 NameVals.
push_back(ModuleIdMap[
FS->modulePath()]);
5178 unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
5179 for (
auto &RI :
FS->refs()) {
5180 auto RefValueId = getValueId(RI.getGUID());
5184 if (RI.isReadOnly())
5186 else if (RI.isWriteOnly())
5190 NameVals[6] =
Count;
5191 NameVals[7] = RORefCnt;
5192 NameVals[8] = WORefCnt;
5194 for (
auto &EI :
FS->calls()) {
5197 std::optional<unsigned> CallValueId = GetValueId(EI.first);
5206 FSCallsProfileAbbrev);
5208 MaybeEmitOriginalName(*S);
5211 for (
auto *AS : Aliases) {
5212 auto AliasValueId = SummaryToValueIdMap[AS];
5221 auto AliaseeValueId =
5228 MaybeEmitOriginalName(*AS);
5236 auto EmitCfiFunctions = [&](
const CfiFunctionIndex &CfiIndex,
5238 if (CfiIndex.
empty())
5241 auto Defs = CfiIndex.
forGuid(GUID);
5244 if (Functions.
empty())
5247 for (
const auto &S : Functions) {
5261 for (
auto &
T : ReferencedTypeIds) {
5262 auto TidIter =
Index.typeIds().equal_range(
T);
5263 for (
const auto &[GUID, TypeIdPair] :
make_range(TidIter)) {
5271 if (
Index.getBlockCount())
5273 ArrayRef<uint64_t>{
Index.getBlockCount()});
5284 auto Abbv = std::make_shared<BitCodeAbbrev>();
5288 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5290 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
5293 Abbv = std::make_shared<BitCodeAbbrev>();
5296 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5302void ModuleBitcodeWriter::writeModuleHash(StringRef View) {
5307 Hasher.
update(ArrayRef<uint8_t>(
5308 reinterpret_cast<const uint8_t *
>(
View.data()),
View.size()));
5309 std::array<uint8_t, 20> Hash = Hasher.
result();
5310 for (
int Pos = 0; Pos < 20; Pos += 4) {
5323void ModuleBitcodeWriter::write() {
5331 writeModuleVersion();
5340 writeAttributeGroupTable();
5343 writeAttributeTable();
5352 writeModuleConstants();
5355 writeModuleMetadataKinds();
5358 writeModuleMetadata();
5362 writeUseListBlock(
nullptr);
5364 writeOperandBundleTags();
5365 writeSyncScopeNames();
5368 DenseMap<const Function *, uint64_t> FunctionToBitcodeIndex;
5369 for (
const Function &
F : M)
5370 if (!
F.isDeclaration())
5371 writeFunction(
F, FunctionToBitcodeIndex);
5376 writePerModuleGlobalValueSummary();
5378 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
5406 unsigned CPUType = ~0U;
5413 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
5414 DARWIN_CPU_TYPE_X86 = 7,
5415 DARWIN_CPU_TYPE_ARM = 12,
5416 DARWIN_CPU_TYPE_POWERPC = 18
5421 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
5423 CPUType = DARWIN_CPU_TYPE_X86;
5425 CPUType = DARWIN_CPU_TYPE_POWERPC;
5427 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
5429 CPUType = DARWIN_CPU_TYPE_ARM;
5433 "Expected header size to be reserved");
5438 unsigned Position = 0;
5446 while (Buffer.
size() & 15)
5453 Stream.
Emit((
unsigned)
'B', 8);
5454 Stream.
Emit((
unsigned)
'C', 8);
5455 Stream.
Emit(0x0, 4);
5456 Stream.
Emit(0xC, 4);
5457 Stream.
Emit(0xE, 4);
5458 Stream.
Emit(0xD, 4);
5476 auto Abbv = std::make_shared<BitCodeAbbrev>();
5479 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
5487 assert(!WroteStrtab && !WroteSymtab);
5493 if (M->getModuleInlineAsm().empty())
5497 const Triple TT(M->getTargetTriple());
5499 if (!
T || !
T->hasMCAsmParser())
5521 std::vector<char> Strtab;
5522 StrtabBuilder.finalizeInOrder();
5523 Strtab.resize(StrtabBuilder.getSize());
5524 StrtabBuilder.write((
uint8_t *)Strtab.data());
5527 {Strtab.data(), Strtab.size()});
5538 bool ShouldPreserveUseListOrder,
5547 assert(M.isMaterialized());
5548 Mods.push_back(
const_cast<Module *
>(&M));
5550 ModuleBitcodeWriter ModuleWriter(M, StrtabBuilder, *Stream,
5551 ShouldPreserveUseListOrder, Index,
5552 GenerateHash, ModHash);
5553 ModuleWriter.write();
5560 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, DecSummaries,
5561 ModuleToSummariesForIndex);
5562 IndexWriter.write();
5567 bool ShouldPreserveUseListOrder,
5571 Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
5573 Writer.writeSymtab();
5574 Writer.writeStrtab();
5576 Triple TT(M.getTargetTriple());
5577 if (TT.isOSDarwin() || TT.isOSBinFormatMachO()) {
5595void IndexBitcodeWriter::write() {
5598 writeModuleVersion();
5604 writeCombinedGlobalValueSummary();
5621 Writer.
writeIndex(&Index, ModuleToSummariesForIndex, DecSummaries);
5630class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
5640 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5642 ModHash(&ModHash) {}
5647 void writeSimplifiedModuleInfo();
5657void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5669 auto Abbv = std::make_shared<BitCodeAbbrev>();
5672 Abbv->Add(AbbrevOpToUse);
5673 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5675 for (
const auto P :
M.getSourceFileName())
5739void ThinLinkBitcodeWriter::write() {
5742 writeModuleVersion();
5744 writeSimplifiedModuleInfo();
5746 writePerModuleGlobalValueSummary();
5763 assert(M.isMaterialized());
5764 Mods.push_back(
const_cast<Module *
>(&M));
5766 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream, Index,
5768 ThinLinkWriter.write();
5789 switch (
T.getObjectFormat()) {
5791 return "__LLVM,__bitcode";
5816 switch (
T.getObjectFormat()) {
5818 return "__LLVM,__cmdline";
5844 const std::vector<uint8_t> &CmdArgs) {
5849 Type *UsedElementType = Used ? Used->getValueType()->getArrayElementType()
5851 for (
auto *GV : UsedGlobals) {
5852 if (GV->getName() !=
"llvm.embedded.module" &&
5853 GV->getName() !=
"llvm.cmdline")
5858 Used->eraseFromParent();
5863 Triple T(M.getTargetTriple());
5892 M.getGlobalVariable(
"llvm.embedded.module",
true)) {
5893 assert(Old->hasZeroLiveUses() &&
5894 "llvm.embedded.module can only be used once in llvm.compiler.used");
5896 Old->eraseFromParent();
5898 GV->
setName(
"llvm.embedded.module");
5916 assert(Old->hasZeroLiveUses() &&
5917 "llvm.cmdline can only be used once in llvm.compiler.used");
5919 Old->eraseFromParent();
5925 if (UsedArray.
empty())
5933 NewUsed->setSection(
"llvm.metadata");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void writeDIMacro(raw_ostream &Out, const DIMacro *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, AsmWriterContext &WriterCtx)
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, AsmWriterContext &WriterCtx)
static void writeDIFixedPointType(raw_ostream &Out, const DIFixedPointType *N, AsmWriterContext &WriterCtx)
static void writeDISubrangeType(raw_ostream &Out, const DISubrangeType *N, AsmWriterContext &WriterCtx)
static void writeDIStringType(raw_ostream &Out, const DIStringType *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, AsmWriterContext &WriterCtx)
static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, AsmWriterContext &WriterCtx)
static void writeDIModule(raw_ostream &Out, const DIModule *N, AsmWriterContext &WriterCtx)
static void writeDIFile(raw_ostream &Out, const DIFile *N, AsmWriterContext &)
static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, AsmWriterContext &WriterCtx)
static void writeDILabel(raw_ostream &Out, const DILabel *N, AsmWriterContext &WriterCtx)
static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, AsmWriterContext &WriterCtx)
static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, AsmWriterContext &WriterCtx)
static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, AsmWriterContext &WriterCtx)
static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, AsmWriterContext &WriterCtx)
static void writeDILocation(raw_ostream &Out, const DILocation *DL, AsmWriterContext &WriterCtx)
static void writeDINamespace(raw_ostream &Out, const DINamespace *N, AsmWriterContext &WriterCtx)
static void writeDICommonBlock(raw_ostream &Out, const DICommonBlock *N, AsmWriterContext &WriterCtx)
static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, AsmWriterContext &WriterCtx)
static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, AsmWriterContext &WriterCtx)
static void writeDITemplateTypeParameter(raw_ostream &Out, const DITemplateTypeParameter *N, AsmWriterContext &WriterCtx)
static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, AsmWriterContext &WriterCtx)
static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N, AsmWriterContext &WriterCtx)
static void writeDISubrange(raw_ostream &Out, const DISubrange *N, AsmWriterContext &WriterCtx)
static void writeDILexicalBlockFile(raw_ostream &Out, const DILexicalBlockFile *N, AsmWriterContext &WriterCtx)
static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, AsmWriterContext &)
static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, AsmWriterContext &WriterCtx)
static void writeDIExpression(raw_ostream &Out, const DIExpression *N, AsmWriterContext &WriterCtx)
static void writeDIAssignID(raw_ostream &Out, const DIAssignID *DL, AsmWriterContext &WriterCtx)
static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, AsmWriterContext &WriterCtx)
static void writeDIArgList(raw_ostream &Out, const DIArgList *N, AsmWriterContext &WriterCtx, bool FromValue=false)
static void writeDITemplateValueParameter(raw_ostream &Out, const DITemplateValueParameter *N, AsmWriterContext &WriterCtx)
static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, AsmWriterContext &WriterCtx)
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static void writeFunctionHeapProfileRecords(BitstreamWriter &Stream, FunctionSummary *FS, unsigned CallsiteAbbrev, unsigned AllocAbbrev, unsigned ContextIdAbbvId, bool PerModule, std::function< unsigned(const ValueInfo &VI)> GetValueID, std::function< unsigned(unsigned)> GetStackIndex, bool WriteContextSizeInfoIndex, DenseMap< CallStackId, LinearCallStackId > &CallStackPos, CallStackId &CallStackCount)
static unsigned serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta)
static void writeTypeIdCompatibleVtableSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdCompatibleVtableInfo &Summary, ValueEnumerator &VE)
static void getReferencedTypeIds(FunctionSummary *FS, std::set< GlobalValue::GUID > &ReferencedTypeIds)
Collect type IDs from type tests used by function.
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
static void collectMemProfCallStacks(FunctionSummary *FS, std::function< LinearFrameId(unsigned)> GetStackIndex, MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &CallStacks)
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
static unsigned getEncodedVisibility(const GlobalValue &GV)
static uint64_t getOptimizationFlags(const Value *V)
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
static cl::opt< bool > PreserveBitcodeUseListOrder("preserve-bc-uselistorder", cl::Hidden, cl::init(true), cl::desc("Preserve use-list order when writing LLVM bitcode."))
static unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
static DenseMap< CallStackId, LinearCallStackId > writeMemoryProfileRadixTree(MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &&CallStacks, BitstreamWriter &Stream, unsigned RadixAbbrev)
static void writeIdentificationBlock(BitstreamWriter &Stream)
Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version,...
static unsigned getEncodedCastOpcode(unsigned Opcode)
static cl::opt< uint32_t > FlushThreshold("bitcode-flush-threshold", cl::Hidden, cl::init(512), cl::desc("The threshold (unit M) for flushing LLVM bitcode."))
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
static unsigned getEncodedUnnamedAddr(const GlobalValue &GV)
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags, bool ImportAsDecl=false)
static void emitDarwinBCHeaderAndTrailer(SmallVectorImpl< char > &Buffer, const Triple &TT)
If generating a bc file on darwin, we have to emit a header and trailer to make it compatible with th...
static void writeBitcodeHeader(BitstreamWriter &Stream)
Helper to write the header common to all bitcode files.
static void writeWholeProgramDevirtResolutionByArg(SmallVector< uint64_t, 64 > &NameVals, const std::vector< uint64_t > &args, const WholeProgramDevirtResolution::ByArg &ByArg)
static void emitConstantRange(SmallVectorImpl< uint64_t > &Record, const ConstantRange &CR, bool EmitBitWidth)
static StringEncoding getStringEncoding(StringRef Str)
Determine the encoding to use for the given string name and length.
static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags)
static const char * getSectionNameForCommandline(const Triple &T)
static cl::opt< unsigned > IndexThreshold("bitcode-mdindex-threshold", cl::Hidden, cl::init(25), cl::desc("Number of metadatas above which we emit an index " "to enable lazy-loading"))
static void writeTypeIdSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdSummary &Summary)
static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, FunctionSummary *FS, Fn GetValueID)
Write the function type metadata related records that need to appear before a function summary entry ...
static uint64_t getEncodedHotnessCallEdgeInfo(const CalleeInfo &CI)
static void emitWideAPInt(SmallVectorImpl< uint64_t > &Vals, const APInt &A)
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
static 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
bool isDbgDeclareValue() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
bool isDbgDeclare() const
Metadata * getRawAddress() const
DIExpression * getAddressExpression() const
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Lightweight error class with error context and mandatory checking.
Function summary information to aid decisions and implementation of importing.
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
LLVM_ABI void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
LLVM_ABI void setSection(StringRef S)
Change the section for this global.
GVFlags flags() const
Get the flags for this GlobalValue (see struct GVFlags).
StringRef modulePath() const
Get the path to the module containing this function.
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
VisibilityTypes getVisibility() const
static bool isLocalLinkage(LinkageTypes Linkage)
LinkageTypes getLinkage() const
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
ThreadLocalMode getThreadLocalMode() const
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ProtectedVisibility
The GV is protected.
UnnamedAddr getUnnamedAddr() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
DLLStorageClassTypes getDLLStorageClass() const
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalVariable.
idx_iterator idx_end() const
idx_iterator idx_begin() const
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
This class implements a map that also provides access to all stored values in a deterministic order.
size_t getBufferSize() const
const char * getBufferStart() const
const char * getBufferEnd() const
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static constexpr uint64_t BitcodeSummaryVersion
A Module instance is used to store all the information related to an LLVM module.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Digest more data.
LLVM_ABI std::array< uint8_t, 20 > result()
Return the current raw 160-bits SHA1 for the digested data since the last call to init().
size_type size() const
Determine the number of elements in the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void append(StringRef RHS)
Append from a StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
const ValueTy & getValue() const
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.
LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
std::pair< iterator, bool > insert(const ValueT &V)
void build(llvm::MapVector< CallStackId, llvm::SmallVector< FrameIdTy > > &&MemProfCallStackData, const llvm::DenseMap< FrameIdTy, LinearFrameId > *MemProfFrameIndexes, llvm::DenseMap< FrameIdTy, FrameStat > &FrameHistogram)
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an std::string.
std::string & str()
Returns the string's reference.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
@ CE
Windows NT (Windows on ARM)
@ TYPE_CODE_OPAQUE_POINTER
@ METADATA_TEMPLATE_VALUE
@ METADATA_LEXICAL_BLOCK_FILE
@ METADATA_SUBROUTINE_TYPE
@ METADATA_GLOBAL_DECL_ATTACHMENT
@ METADATA_IMPORTED_ENTITY
@ METADATA_GENERIC_SUBRANGE
@ METADATA_COMPOSITE_TYPE
@ METADATA_FIXED_POINT_TYPE
@ METADATA_GLOBAL_VAR_EXPR
GlobalValueSummarySymtabCodes
@ FS_CONTEXT_RADIX_TREE_ARRAY
@ FS_COMBINED_GLOBALVAR_INIT_REFS
@ FS_TYPE_CHECKED_LOAD_VCALLS
@ FS_COMBINED_ORIGINAL_NAME
@ FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_CONST_VCALL
@ FS_PERMODULE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_VCALLS
@ FS_COMBINED_ALLOC_INFO_NO_CONTEXT
@ FS_COMBINED_CALLSITE_INFO
@ FS_PERMODULE_CALLSITE_INFO
@ FS_PERMODULE_ALLOC_INFO
@ FS_TYPE_CHECKED_LOAD_CONST_VCALL
@ IDENTIFICATION_CODE_EPOCH
@ IDENTIFICATION_CODE_STRING
@ CST_CODE_DSO_LOCAL_EQUIVALENT
@ CST_CODE_CE_GEP_WITH_INRANGE
@ COMDAT_SELECTION_KIND_LARGEST
@ COMDAT_SELECTION_KIND_ANY
@ COMDAT_SELECTION_KIND_SAME_SIZE
@ COMDAT_SELECTION_KIND_EXACT_MATCH
@ COMDAT_SELECTION_KIND_NO_DUPLICATES
@ ATTR_KIND_STACK_PROTECT
@ ATTR_KIND_STACK_PROTECT_STRONG
@ ATTR_KIND_SANITIZE_MEMORY
@ ATTR_KIND_OPTIMIZE_FOR_SIZE
@ ATTR_KIND_FNRETTHUNK_EXTERN
@ ATTR_KIND_NO_DIVERGENCE_SOURCE
@ ATTR_KIND_SANITIZE_ADDRESS
@ ATTR_KIND_NO_IMPLICIT_FLOAT
@ ATTR_KIND_DEAD_ON_UNWIND
@ ATTR_KIND_STACK_ALIGNMENT
@ ATTR_KIND_STACK_PROTECT_REQ
@ ATTR_KIND_NULL_POINTER_IS_VALID
@ ATTR_KIND_SANITIZE_HWADDRESS
@ ATTR_KIND_RETURNS_TWICE
@ ATTR_KIND_SHADOWCALLSTACK
@ ATTR_KIND_OPT_FOR_FUZZING
@ ATTR_KIND_DENORMAL_FPENV
@ ATTR_KIND_SANITIZE_NUMERICAL_STABILITY
@ ATTR_KIND_ALLOCATED_POINTER
@ ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION
@ ATTR_KIND_CORO_ELIDE_SAFE
@ ATTR_KIND_NON_LAZY_BIND
@ ATTR_KIND_DEREFERENCEABLE
@ ATTR_KIND_OPTIMIZE_NONE
@ ATTR_KIND_HYBRID_PATCHABLE
@ ATTR_KIND_DEREFERENCEABLE_OR_NULL
@ ATTR_KIND_SANITIZE_REALTIME
@ ATTR_KIND_SPECULATIVE_LOAD_HARDENING
@ ATTR_KIND_ALWAYS_INLINE
@ ATTR_KIND_SANITIZE_TYPE
@ ATTR_KIND_PRESPLIT_COROUTINE
@ ATTR_KIND_SANITIZE_ALLOC_TOKEN
@ ATTR_KIND_NO_SANITIZE_COVERAGE
@ ATTR_KIND_NO_CREATE_UNDEF_OR_POISON
@ ATTR_KIND_DEAD_ON_RETURN
@ ATTR_KIND_SANITIZE_REALTIME_BLOCKING
@ ATTR_KIND_NO_SANITIZE_BOUNDS
@ ATTR_KIND_SANITIZE_MEMTAG
@ ATTR_KIND_CORO_ONLY_DESTROY_WHEN_COMPLETE
@ ATTR_KIND_SANITIZE_THREAD
@ ATTR_KIND_OPTIMIZE_FOR_DEBUGGING
@ SYNC_SCOPE_NAMES_BLOCK_ID
@ PARAMATTR_GROUP_BLOCK_ID
@ IDENTIFICATION_BLOCK_ID
@ GLOBALVAL_SUMMARY_BLOCK_ID
@ FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID
@ OPERAND_BUNDLE_TAGS_BLOCK_ID
@ MODULE_CODE_SOURCE_FILENAME
@ MODULE_CODE_SECTIONNAME
@ FUNC_CODE_INST_CATCHRET
@ FUNC_CODE_INST_LANDINGPAD
@ FUNC_CODE_INST_EXTRACTVAL
@ FUNC_CODE_INST_CATCHPAD
@ FUNC_CODE_INST_CATCHSWITCH
@ FUNC_CODE_INST_CLEANUPRET
@ FUNC_CODE_DEBUG_RECORD_VALUE
@ FUNC_CODE_INST_LOADATOMIC
@ FUNC_CODE_DEBUG_RECORD_ASSIGN
@ FUNC_CODE_INST_STOREATOMIC
@ FUNC_CODE_INST_ATOMICRMW
@ FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE
@ FUNC_CODE_DEBUG_LOC_AGAIN
@ FUNC_CODE_INST_EXTRACTELT
@ FUNC_CODE_INST_INDIRECTBR
@ FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE
@ FUNC_CODE_INST_INSERTVAL
@ FUNC_CODE_DECLAREBLOCKS
@ FUNC_CODE_DEBUG_RECORD_LABEL
@ FUNC_CODE_INST_INSERTELT
@ FUNC_CODE_BLOCKADDR_USERS
@ FUNC_CODE_INST_CLEANUPPAD
@ FUNC_CODE_INST_SHUFFLEVEC
@ FUNC_CODE_INST_UNREACHABLE
@ FUNC_CODE_DEBUG_RECORD_DECLARE
@ FUNC_CODE_OPERAND_BUNDLE
@ FIRST_APPLICATION_ABBREV
@ PARAMATTR_GRP_CODE_ENTRY
initializer< Ty > init(const Ty &Val)
@ DW_APPLE_ENUM_KIND_invalid
Enum kind for invalid results.
LLVM_ABI Error build(ArrayRef< Module * > Mods, SmallVector< char, 0 > &Symtab, StringTableBuilder &StrtabBuilder, BumpPtrAllocator &Alloc)
Fills in Symtab and StrtabBuilder with a valid symbol and string table for Mods.
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract_or_null(Y &&MD)
Extract a Value from Metadata, allowing null.
LLVM_ABI bool metadataIncludesAllContextSizeInfo()
Whether the alloc memeprof metadata will include context size info for all MIBs.
template LLVM_ABI llvm::DenseMap< LinearFrameId, FrameStat > computeFrameHistogram< LinearFrameId >(llvm::MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &MemProfCallStackData)
LLVM_ABI bool metadataMayIncludeContextSizeInfo()
Whether the alloc memprof metadata may include context size info for some MIBs (but possibly not all)...
NodeAddr< CodeNode * > Code
void write32le(void *P, uint32_t V)
uint32_t read32be(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
FunctionAddr VTableAddr Value
StringMapEntry< Value * > ValueName
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
std::unordered_set< GlobalValueSummary * > GVSummaryPtrSet
A set of global value summary pointers.
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
LLVM_ABI void WriteBitcodeToFile(const Module &M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the specified raw output stream.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
LLVM_ABI void writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the given raw output...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
LLVM_ABI void writeIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out, const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex=nullptr, const GVSummaryPtrSet *DecSummaries=nullptr)
Write the specified module summary index to the given raw output stream, where it will be written in ...
LLVM_ABI void embedBitcodeInModule(Module &M, MemoryBufferRef Buf, bool EmbedBitcode, bool EmbedCmdline, const std::vector< uint8_t > &CmdArgs)
If EmbedBitcode is set, save a copy of the llvm IR as data in the __LLVM,__bitcode section (....
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
FunctionAddr VTableAddr Count
std::map< std::string, GVSummaryMapTy, std::less<> > ModuleToSummariesForIndexTy
Map of a module name to the GUIDs and summaries we will import from that module.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
AtomicOrdering
Atomic ordering for LLVM's memory model.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt copy(R &&Range, OutputIt Out)
constexpr unsigned BitWidth
LLVM_ABI Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue, Dwarf64StrOffsetsPromotion StrOffsetsOptValue)
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.
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