33#include "llvm/Config/llvm-config.h"
95 cl::desc(
"Number of metadatas above which we emit an index "
96 "to enable lazy-loading"));
99 cl::desc(
"The threshold (unit M) for flushing LLVM bitcode."));
119 cl::desc(
"Preserve use-list order when writing LLVM bitcode."));
134 VST_BBENTRY_6_ABBREV,
138 CONSTANTS_INTEGER_ABBREV,
139 CONSTANTS_BYTE_ABBREV,
140 CONSTANTS_CE_CAST_Abbrev,
141 CONSTANTS_NULL_Abbrev,
145 FUNCTION_INST_STORE_ABBREV,
146 FUNCTION_INST_UNOP_ABBREV,
147 FUNCTION_INST_UNOP_FLAGS_ABBREV,
148 FUNCTION_INST_BINOP_ABBREV,
149 FUNCTION_INST_BINOP_FLAGS_ABBREV,
150 FUNCTION_INST_CAST_ABBREV,
151 FUNCTION_INST_CAST_FLAGS_ABBREV,
152 FUNCTION_INST_RET_VOID_ABBREV,
153 FUNCTION_INST_RET_VAL_ABBREV,
154 FUNCTION_INST_BR_UNCOND_ABBREV,
155 FUNCTION_INST_BR_COND_ABBREV,
156 FUNCTION_INST_UNREACHABLE_ABBREV,
157 FUNCTION_INST_GEP_ABBREV,
158 FUNCTION_INST_CMP_ABBREV,
159 FUNCTION_INST_CMP_FLAGS_ABBREV,
160 FUNCTION_DEBUG_RECORD_VALUE_ABBREV,
161 FUNCTION_DEBUG_LOC_ABBREV,
166class BitcodeWriterBase {
169 BitstreamWriter &Stream;
171 StringTableBuilder &StrtabBuilder;
176 BitcodeWriterBase(BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder)
177 : Stream(Stream), StrtabBuilder(StrtabBuilder) {}
180 void writeModuleVersion();
183void BitcodeWriterBase::writeModuleVersion() {
190class ModuleBitcodeWriterBase :
public BitcodeWriterBase {
199 const ModuleSummaryIndex *Index;
204 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
207 unsigned GlobalValueId;
216 ModuleBitcodeWriterBase(
const Module &M, StringTableBuilder &StrtabBuilder,
217 BitstreamWriter &Stream,
218 bool ShouldPreserveUseListOrder,
219 const ModuleSummaryIndex *Index)
220 : BitcodeWriterBase(Stream, StrtabBuilder),
M(
M),
223 : ShouldPreserveUseListOrder),
234 for (
const auto &GUIDSummaryLists :
235 Index->sortedGlobalValueSummariesRange())
237 for (
auto &Summary : GUIDSummaryLists.second.getSummaryList())
243 for (auto &CallEdge : FS->calls())
244 if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
245 assignValueId(CallEdge.first.getGUID());
251 for (auto &RefEdge : FS->refs())
252 if (!RefEdge.haveGVs() || !RefEdge.getValue())
253 assignValueId(RefEdge.getGUID());
258 void writePerModuleGlobalValueSummary();
259 void writeGUIDList();
262 void writePerModuleFunctionSummaryRecord(
263 SmallVector<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
264 unsigned ValueID,
unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
265 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
const Function &
F,
266 DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
268 void writeModuleLevelReferences(
const GlobalVariable &V,
269 SmallVector<uint64_t, 64> &NameVals,
270 unsigned FSModRefsAbbrev,
271 unsigned FSModVTableRefsAbbrev);
274 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
278 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
281 assert(VMI != GUIDToValueIdMap.end() &&
282 "GUID does not have assigned value Id");
287 unsigned getValueId(ValueInfo VI) {
288 if (!
VI.haveGVs() || !
VI.getValue())
289 return getValueId(
VI.getGUID());
293 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
297class ModuleBitcodeWriter :
public ModuleBitcodeWriterBase {
313 ModuleBitcodeWriter(
const Module &M, StringTableBuilder &StrtabBuilder,
314 BitstreamWriter &Stream,
bool ShouldPreserveUseListOrder,
315 const ModuleSummaryIndex *Index,
bool GenerateHash,
317 : ModuleBitcodeWriterBase(
M, StrtabBuilder, Stream,
318 ShouldPreserveUseListOrder,
Index),
319 GenerateHash(GenerateHash), ModHash(ModHash),
320 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
326 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
328 size_t addToStrtab(StringRef Str);
330 void writeAttributeGroupTable();
331 void writeAttributeTable();
332 void writeTypeTable();
334 void writeValueSymbolTableForwardDecl();
335 void writeModuleInfo();
336 void writeValueAsMetadata(
const ValueAsMetadata *MD,
337 SmallVectorImpl<uint64_t> &Record);
338 void writeMDTuple(
const MDTuple *
N, SmallVectorImpl<uint64_t> &Record,
340 unsigned createDILocationAbbrev();
341 void writeDILocation(
const DILocation *
N, SmallVectorImpl<uint64_t> &Record,
343 unsigned createGenericDINodeAbbrev();
345 SmallVectorImpl<uint64_t> &Record,
unsigned &Abbrev);
346 void writeDISubrange(
const DISubrange *
N, SmallVectorImpl<uint64_t> &Record,
349 SmallVectorImpl<uint64_t> &Record,
352 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
356 SmallVectorImpl<uint64_t> &Record,
359 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
361 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
363 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
365 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
367 SmallVectorImpl<uint64_t> &Record,
369 void writeDIFile(
const DIFile *
N, SmallVectorImpl<uint64_t> &Record,
372 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
374 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
376 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
378 SmallVectorImpl<uint64_t> &Record,
381 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
384 void writeDIMacro(
const DIMacro *
N, SmallVectorImpl<uint64_t> &Record,
388 void writeDIArgList(
const DIArgList *
N, SmallVectorImpl<uint64_t> &Record);
389 void writeDIModule(
const DIModule *
N, SmallVectorImpl<uint64_t> &Record,
391 void writeDIAssignID(
const DIAssignID *
N, SmallVectorImpl<uint64_t> &Record,
394 SmallVectorImpl<uint64_t> &Record,
397 SmallVectorImpl<uint64_t> &Record,
400 SmallVectorImpl<uint64_t> &Record,
403 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
405 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
407 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
409 SmallVectorImpl<uint64_t> &Record,
412 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
413 void writeDIProperty(
const DIProperty *
N, SmallVectorImpl<uint64_t> &Record,
416 SmallVectorImpl<uint64_t> &Record,
418 unsigned createNamedMetadataAbbrev();
419 void writeNamedMetadata(SmallVectorImpl<uint64_t> &Record);
420 unsigned createMetadataStringsAbbrev();
422 SmallVectorImpl<uint64_t> &Record);
424 SmallVectorImpl<uint64_t> &Record,
425 std::vector<unsigned> *MDAbbrevs =
nullptr,
426 std::vector<uint64_t> *IndexPos =
nullptr);
427 void writeModuleMetadata();
428 void writeFunctionMetadata(
const Function &
F);
429 void writeFunctionMetadataAttachment(
const Function &
F);
430 void pushGlobalMetadataAttachment(SmallVectorImpl<uint64_t> &Record,
431 const GlobalObject &GO);
432 void writeModuleMetadataKinds();
433 void writeOperandBundleTags();
434 void writeSyncScopeNames();
435 void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
436 void writeModuleConstants();
437 bool pushValueAndType(
const Value *V,
unsigned InstID,
438 SmallVectorImpl<unsigned> &Vals);
439 bool pushValueOrMetadata(
const Value *V,
unsigned InstID,
440 SmallVectorImpl<unsigned> &Vals);
441 void writeOperandBundles(
const CallBase &CB,
unsigned InstID);
442 void pushValue(
const Value *V,
unsigned InstID,
443 SmallVectorImpl<unsigned> &Vals);
444 void pushValueSigned(
const Value *V,
unsigned InstID,
445 SmallVectorImpl<uint64_t> &Vals);
446 void writeInstruction(
const Instruction &
I,
unsigned InstID,
447 SmallVectorImpl<unsigned> &Vals);
448 void writeFunctionLevelValueSymbolTable(
const ValueSymbolTable &VST);
449 void writeGlobalValueSymbolTable(
450 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
451 void writeUseList(UseListOrder &&Order);
452 void writeUseListBlock(
const Function *
F);
455 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
456 void writeBlockInfo();
457 void writeModuleHash(StringRef View);
460 return unsigned(SSID);
463 unsigned getEncodedAlign(MaybeAlign Alignment) {
return encode(Alignment); }
467class IndexBitcodeWriter :
public BitcodeWriterBase {
469 const ModuleSummaryIndex &
Index;
482 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
486 std::vector<uint64_t> StackIds;
491 DenseMap<unsigned, unsigned> StackIdIndicesToIndex;
494 unsigned GlobalValueId = 0;
498 DenseMap<StringRef, uint64_t> ModuleIdMap;
508 BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder,
509 const ModuleSummaryIndex &Index,
512 : BitcodeWriterBase(Stream, StrtabBuilder),
Index(
Index),
513 DecSummaries(DecSummaries),
514 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
518 auto RecordStackIdReference = [&](
unsigned StackIdIndex) {
523 StackIdIndicesToIndex.
insert({StackIdIndex, StackIds.size()});
525 StackIds.push_back(
Index.getStackIdAtIndex(StackIdIndex));
532 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
533 GUIDToValueIdMap[
I.first] = ++GlobalValueId;
545 for (
auto &CI :
FS->callsites()) {
556 if (CI.StackIdIndices.empty()) {
557 GUIDToValueIdMap[CI.Callee.getGUID()] = ++GlobalValueId;
560 for (
auto Idx : CI.StackIdIndices)
561 RecordStackIdReference(Idx);
564 for (
auto &AI :
FS->allocs())
565 for (
auto &MIB : AI.MIBs)
566 for (
auto Idx : MIB.StackIdIndices)
567 RecordStackIdReference(Idx);
573 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
578 template<
typename Functor>
579 void forEachSummary(Functor Callback) {
580 if (ModuleToSummariesForIndex) {
581 for (
auto &M : *ModuleToSummariesForIndex)
582 for (
auto &Summary :
M.second) {
588 Callback({AS->getAliaseeGUID(), &AS->getAliasee()},
true);
592 for (
const auto &Summaries :
Index.sortedGlobalValueSummariesRange())
593 for (
auto &Summary : Summaries.second.getSummaryList())
602 template <
typename Functor>
void forEachModule(Functor Callback) {
603 if (ModuleToSummariesForIndex) {
604 for (
const auto &M : *ModuleToSummariesForIndex) {
605 const auto &MPI =
Index.modulePaths().find(
M.first);
606 if (MPI ==
Index.modulePaths().end()) {
610 assert(ModuleToSummariesForIndex->size() == 1);
620 std::vector<StringRef> ModulePaths;
621 for (
auto &[ModPath,
_] :
Index.modulePaths())
622 ModulePaths.push_back(ModPath);
624 for (
auto &ModPath : ModulePaths)
633 void writeModStrings();
634 void writeCombinedGlobalValueSummary();
637 auto VMI = GUIDToValueIdMap.find(ValGUID);
638 if (VMI == GUIDToValueIdMap.end())
643 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
678 case Instruction::Add:
680 case Instruction::Sub:
682 case Instruction::Mul:
685 case Instruction::FDiv:
688 case Instruction::FRem:
700 unsigned Encoding = 0;
701 switch (
I.getOperation()) {
774 if (
I.isElementwise())
809 case Attribute::Alignment:
811 case Attribute::AllocAlign:
813 case Attribute::AllocSize:
815 case Attribute::AlwaysInline:
817 case Attribute::Builtin:
819 case Attribute::ByVal:
821 case Attribute::Convergent:
823 case Attribute::InAlloca:
825 case Attribute::Cold:
827 case Attribute::DisableSanitizerInstrumentation:
829 case Attribute::FnRetThunkExtern:
831 case Attribute::Flatten:
835 case Attribute::ElementType:
837 case Attribute::HybridPatchable:
839 case Attribute::InlineHint:
841 case Attribute::InReg:
843 case Attribute::JumpTable:
845 case Attribute::MinSize:
847 case Attribute::AllocatedPointer:
849 case Attribute::AllocKind:
851 case Attribute::Memory:
853 case Attribute::NoFPClass:
855 case Attribute::Naked:
857 case Attribute::Nest:
859 case Attribute::NoAlias:
861 case Attribute::NoBuiltin:
863 case Attribute::NoCallback:
865 case Attribute::NoDivergenceSource:
867 case Attribute::NoDuplicate:
869 case Attribute::NoFree:
871 case Attribute::NoFreeObj:
873 case Attribute::NoImplicitFloat:
875 case Attribute::NoInline:
877 case Attribute::NoRecurse:
879 case Attribute::NoMerge:
881 case Attribute::NonLazyBind:
883 case Attribute::NonNull:
885 case Attribute::Dereferenceable:
887 case Attribute::DereferenceableOrNull:
889 case Attribute::NoRedZone:
891 case Attribute::NoReturn:
893 case Attribute::NoSync:
895 case Attribute::NoCfCheck:
897 case Attribute::NoProfile:
899 case Attribute::SkipProfile:
901 case Attribute::NoUnwind:
903 case Attribute::NoSanitizeBounds:
905 case Attribute::NoSanitizeCoverage:
907 case Attribute::NullPointerIsValid:
909 case Attribute::OptimizeForDebugging:
911 case Attribute::OptForFuzzing:
913 case Attribute::OptimizeForSize:
915 case Attribute::OptimizeNone:
917 case Attribute::ReadNone:
919 case Attribute::ReadOnly:
921 case Attribute::Returned:
923 case Attribute::ReturnsTwice:
925 case Attribute::SExt:
927 case Attribute::Speculatable:
929 case Attribute::StackAlignment:
931 case Attribute::StackProtect:
933 case Attribute::StackProtectReq:
935 case Attribute::StackProtectStrong:
937 case Attribute::SafeStack:
939 case Attribute::ShadowCallStack:
941 case Attribute::StrictFP:
943 case Attribute::StructRet:
945 case Attribute::SanitizeAddress:
947 case Attribute::SanitizeAllocToken:
949 case Attribute::SanitizeHWAddress:
951 case Attribute::SanitizeThread:
953 case Attribute::SanitizeType:
955 case Attribute::SanitizeMemory:
957 case Attribute::SanitizeNumericalStability:
959 case Attribute::SanitizeRealtime:
961 case Attribute::SanitizeRealtimeBlocking:
963 case Attribute::SpeculativeLoadHardening:
965 case Attribute::SwiftError:
967 case Attribute::SwiftSelf:
969 case Attribute::SwiftAsync:
971 case Attribute::UWTable:
973 case Attribute::VScaleRange:
975 case Attribute::WillReturn:
977 case Attribute::WriteOnly:
979 case Attribute::ZExt:
981 case Attribute::ImmArg:
983 case Attribute::SanitizeMemTag:
985 case Attribute::Preallocated:
987 case Attribute::NoUndef:
989 case Attribute::ByRef:
991 case Attribute::MustProgress:
993 case Attribute::PresplitCoroutine:
995 case Attribute::Writable:
997 case Attribute::CoroDestroyOnlyWhenComplete:
999 case Attribute::CoroElideSafe:
1001 case Attribute::DeadOnUnwind:
1003 case Attribute::Range:
1005 case Attribute::Initializes:
1007 case Attribute::NoExt:
1009 case Attribute::Captures:
1011 case Attribute::DeadOnReturn:
1013 case Attribute::NoCreateUndefOrPoison:
1015 case Attribute::DenormalFPEnv:
1017 case Attribute::NoOutline:
1019 case Attribute::NoIPA:
1034 if ((int64_t)V >= 0)
1045 unsigned NumWords =
A.getActiveWords();
1046 const uint64_t *RawData =
A.getRawData();
1047 for (
unsigned i = 0; i < NumWords; i++)
1067void ModuleBitcodeWriter::writeAttributeGroupTable() {
1068 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
1070 if (AttrGrps.empty())
return;
1074 SmallVector<uint64_t, 64>
Record;
1076 unsigned AttrListIndex = Pair.first;
1077 AttributeSet AS = Pair.second;
1079 Record.push_back(AttrListIndex);
1082 if (Attr.isEnumAttribute()) {
1085 }
else if (Attr.isIntAttribute()) {
1087 Attribute::AttrKind
Kind = Attr.getKindAsEnum();
1089 if (Kind == Attribute::Memory) {
1094 Record.push_back(Attr.getValueAsInt());
1096 }
else if (Attr.isStringAttribute()) {
1097 StringRef
Kind = Attr.getKindAsString();
1098 StringRef Val = Attr.getValueAsString();
1107 }
else if (Attr.isTypeAttribute()) {
1108 Type *Ty = Attr.getValueAsType();
1109 Record.push_back(Ty ? 6 : 5);
1113 }
else if (Attr.isConstantRangeAttribute()) {
1119 assert(Attr.isConstantRangeListAttribute());
1125 for (
auto &CR : Val)
1137void ModuleBitcodeWriter::writeAttributeTable() {
1139 if (
Attrs.empty())
return;
1143 SmallVector<uint64_t, 64>
Record;
1144 for (
const AttributeList &AL : Attrs) {
1145 for (
unsigned i :
AL.indexes()) {
1146 AttributeSet AS =
AL.getAttributes(i);
1159void ModuleBitcodeWriter::writeTypeTable() {
1163 SmallVector<uint64_t, 64> TypeVals;
1168 auto Abbv = std::make_shared<BitCodeAbbrev>();
1170 Abbv->Add(BitCodeAbbrevOp(0));
1171 unsigned OpaquePtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1174 Abbv = std::make_shared<BitCodeAbbrev>();
1179 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1182 Abbv = std::make_shared<BitCodeAbbrev>();
1187 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1190 Abbv = std::make_shared<BitCodeAbbrev>();
1194 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1197 Abbv = std::make_shared<BitCodeAbbrev>();
1202 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1205 Abbv = std::make_shared<BitCodeAbbrev>();
1209 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1217 for (
Type *
T : TypeList) {
1218 int AbbrevToUse = 0;
1221 switch (
T->getTypeID()) {
1231 case Type::MetadataTyID:
1236 case Type::ByteTyID:
1241 case Type::IntegerTyID:
1246 case Type::PointerTyID: {
1253 AbbrevToUse = OpaquePtrAbbrev;
1256 case Type::FunctionTyID: {
1262 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1264 AbbrevToUse = FunctionAbbrev;
1267 case Type::StructTyID: {
1272 for (
Type *ET :
ST->elements())
1275 if (
ST->isLiteral()) {
1277 AbbrevToUse = StructAnonAbbrev;
1279 if (
ST->isOpaque()) {
1283 AbbrevToUse = StructNamedAbbrev;
1287 if (!
ST->getName().empty())
1293 case Type::ArrayTyID: {
1297 TypeVals.
push_back(AT->getNumElements());
1299 AbbrevToUse = ArrayAbbrev;
1302 case Type::FixedVectorTyID:
1303 case Type::ScalableVectorTyID: {
1308 TypeVals.
push_back(VT->getElementCount().getKnownMinValue());
1314 case Type::TargetExtTyID: {
1320 for (
Type *InnerTy :
TET->type_params())
1325 case Type::TypedPointerTyID:
1330 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
1371 RawFlags |= Flags.ReadNone;
1372 RawFlags |= (Flags.ReadOnly << 1);
1373 RawFlags |= (Flags.NoRecurse << 2);
1374 RawFlags |= (Flags.ReturnDoesNotAlias << 3);
1375 RawFlags |= (Flags.NoInline << 4);
1376 RawFlags |= (Flags.AlwaysInline << 5);
1377 RawFlags |= (Flags.NoUnwind << 6);
1378 RawFlags |= (Flags.MayThrow << 7);
1379 RawFlags |= (Flags.HasUnknownCall << 8);
1380 RawFlags |= (Flags.MustBeUnreachable << 9);
1387 bool ImportAsDecl =
false) {
1390 RawFlags |= Flags.NotEligibleToImport;
1391 RawFlags |= (Flags.Live << 1);
1392 RawFlags |= (Flags.DSOLocal << 2);
1393 RawFlags |= (Flags.CanAutoHide << 3);
1398 RawFlags = (RawFlags << 4) | Flags.Linkage;
1400 RawFlags |= (Flags.Visibility << 8);
1402 unsigned ImportType = Flags.ImportType | ImportAsDecl;
1403 RawFlags |= (ImportType << 10);
1405 RawFlags |= (Flags.NoRenameOnPromotion << 11);
1411 uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1412 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1455 switch (
C.getSelectionKind()) {
1479size_t ModuleBitcodeWriter::addToStrtab(StringRef Str) {
1482 return StrtabBuilder.
add(Str);
1485void ModuleBitcodeWriter::writeComdats() {
1500void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1505 auto Abbv = std::make_shared<BitCodeAbbrev>();
1511 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1527 bool isChar6 =
true;
1528 for (
char C : Str) {
1531 if ((
unsigned char)
C & 128)
1540static_assert(
sizeof(GlobalValue::SanitizerMetadata) <=
sizeof(unsigned),
1541 "Sanitizer Metadata is too large for naive serialization.");
1544 return Meta.NoAddress | (
Meta.NoHWAddress << 1) |
1545 (
Meta.Memtag << 2) | (
Meta.IsDynInit << 3);
1551void ModuleBitcodeWriter::writeModuleInfo() {
1553 if (!
M.getTargetTriple().empty())
1555 M.getTargetTriple().str(), 0 );
1556 const std::string &
DL =
M.getDataLayoutStr();
1560 for (
const Module::GlobalAsmFragment &Frag :
M.getModuleInlineAsm()) {
1562 Frag.Props.getAsStrings();
1575 std::map<std::string, unsigned> SectionMap;
1576 std::map<std::string, unsigned> GCMap;
1577 MaybeAlign MaxGVarAlignment;
1578 unsigned MaxGlobalType = 0;
1579 for (
const GlobalVariable &GV :
M.globals()) {
1580 if (MaybeAlign
A = GV.getAlign())
1581 MaxGVarAlignment = !MaxGVarAlignment ? *
A : std::max(*MaxGVarAlignment, *
A);
1582 MaxGlobalType = std::max(MaxGlobalType, VE.
getTypeID(GV.getValueType()));
1583 if (GV.hasSection()) {
1585 unsigned &
Entry = SectionMap[std::string(GV.getSection())];
1589 Entry = SectionMap.size();
1594 if (
F.hasSection()) {
1596 unsigned &
Entry = SectionMap[std::string(
F.getSection())];
1600 Entry = SectionMap.size();
1605 unsigned &
Entry = GCMap[
F.getGC()];
1609 Entry = GCMap.size();
1615 unsigned SimpleGVarAbbrev = 0;
1616 if (!
M.global_empty()) {
1618 auto Abbv = std::make_shared<BitCodeAbbrev>();
1629 if (!MaxGVarAlignment)
1630 Abbv->Add(BitCodeAbbrevOp(0));
1632 unsigned MaxEncAlignment = getEncodedAlign(MaxGVarAlignment);
1636 if (SectionMap.empty())
1637 Abbv->Add(BitCodeAbbrevOp(0));
1642 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1656 auto Abbv = std::make_shared<BitCodeAbbrev>();
1659 Abbv->Add(AbbrevOpToUse);
1660 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1662 for (
const auto P :
M.getSourceFileName())
1673 for (
const GlobalVariable &GV :
M.globals()) {
1674 unsigned AbbrevToUse = 0;
1680 Vals.
push_back(addToStrtab(GV.getName()));
1683 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1687 Vals.
push_back(getEncodedAlign(GV.getAlign()));
1688 Vals.
push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1690 if (GV.isThreadLocal() ||
1692 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1693 GV.isExternallyInitialized() ||
1695 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1696 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1700 Vals.
push_back(GV.isExternallyInitialized());
1704 auto AL = GV.getAttributesAsList(AttributeList::FunctionIndex);
1708 Vals.
push_back(addToStrtab(GV.getPartition()));
1709 Vals.
push_back(GV.getPartition().size());
1712 GV.getSanitizerMetadata())
1716 AbbrevToUse = SimpleGVarAbbrev;
1737 Vals.
push_back(getEncodedAlign(
F.getAlign()));
1738 Vals.
push_back(
F.hasSection() ? SectionMap[std::string(
F.getSection())]
1750 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1754 Vals.
push_back(addToStrtab(
F.getPartition()));
1756 Vals.
push_back(getEncodedAlign(
F.getPreferredAlignment()));
1758 unsigned AbbrevToUse = 0;
1764 for (
const GlobalAlias &
A :
M.aliases()) {
1771 Vals.
push_back(
A.getType()->getAddressSpace());
1779 Vals.
push_back(addToStrtab(
A.getPartition()));
1782 unsigned AbbrevToUse = 0;
1788 for (
const GlobalIFunc &
I :
M.ifuncs()) {
1794 Vals.
push_back(
I.getType()->getAddressSpace());
1799 Vals.
push_back(addToStrtab(
I.getPartition()));
1805 writeValueSymbolTableForwardDecl();
1812 if (OBO->hasNoSignedWrap())
1814 if (OBO->hasNoUnsignedWrap())
1820 if (PDI->isDisjoint())
1823 if (FPMO->hasAllowReassoc())
1825 if (FPMO->hasNoNaNs())
1827 if (FPMO->hasNoInfs())
1829 if (FPMO->hasNoSignedZeros())
1831 if (FPMO->hasAllowReciprocal())
1833 if (FPMO->hasAllowContract())
1835 if (FPMO->hasApproxFunc())
1841 if (NNI->hasNonNeg())
1845 if (NNI->hasNonNeg())
1848 if (TI->hasNoSignedWrap())
1850 if (TI->hasNoUnsignedWrap())
1853 if (
GEP->isInBounds())
1855 if (
GEP->hasNoUnsignedSignedWrap())
1857 if (
GEP->hasNoUnsignedWrap())
1860 if (ICmp->hasSameSign())
1863 if (ASC->hasNonNull())
1870void ModuleBitcodeWriter::writeValueAsMetadata(
1871 const ValueAsMetadata *MD, SmallVectorImpl<uint64_t> &Record) {
1880void ModuleBitcodeWriter::writeMDTuple(
const MDTuple *
N,
1881 SmallVectorImpl<uint64_t> &Record,
1883 for (
const MDOperand &MDO :
N->operands()) {
1886 "Unexpected function-local metadata");
1895unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1898 auto Abbv = std::make_shared<BitCodeAbbrev>();
1911void ModuleBitcodeWriter::writeDILocation(
const DILocation *
N,
1912 SmallVectorImpl<uint64_t> &Record,
1915 Abbrev = createDILocationAbbrev();
1917 Record.push_back(
N->isDistinct());
1918 Record.push_back(
N->getLine());
1919 Record.push_back(
N->getColumn());
1922 Record.push_back(
N->isImplicitCode());
1923 Record.push_back(
N->getAtomGroup());
1924 Record.push_back(
N->getAtomRank());
1929unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1932 auto Abbv = std::make_shared<BitCodeAbbrev>();
1943void ModuleBitcodeWriter::writeGenericDINode(
const GenericDINode *
N,
1944 SmallVectorImpl<uint64_t> &Record,
1947 Abbrev = createGenericDINodeAbbrev();
1949 Record.push_back(
N->isDistinct());
1950 Record.push_back(
N->getTag());
1953 for (
auto &
I :
N->operands())
1960void ModuleBitcodeWriter::writeDISubrange(
const DISubrange *
N,
1961 SmallVectorImpl<uint64_t> &Record,
1974void ModuleBitcodeWriter::writeDIGenericSubrange(
1975 const DIGenericSubrange *
N, SmallVectorImpl<uint64_t> &Record,
1987void ModuleBitcodeWriter::writeDIEnumerator(
const DIEnumerator *
N,
1988 SmallVectorImpl<uint64_t> &Record,
1991 Record.push_back(IsBigInt | (
N->isUnsigned() << 1) |
N->isDistinct());
1992 Record.push_back(
N->getValue().getBitWidth());
2000void ModuleBitcodeWriter::writeDIBasicType(
const DIBasicType *
N,
2001 SmallVectorImpl<uint64_t> &Record,
2003 const unsigned SizeIsMetadata = 0x2;
2004 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2005 Record.push_back(
N->getTag());
2008 Record.push_back(
N->getAlignInBits());
2009 Record.push_back(
N->getEncoding());
2010 Record.push_back(
N->getFlags());
2011 Record.push_back(
N->getNumExtraInhabitants());
2012 Record.push_back(
N->getDataSizeInBits());
2014 Record.push_back(
N->getLine());
2021void ModuleBitcodeWriter::writeDIFixedPointType(
2022 const DIFixedPointType *
N, SmallVectorImpl<uint64_t> &Record,
2024 const unsigned SizeIsMetadata = 0x2;
2025 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2026 Record.push_back(
N->getTag());
2029 Record.push_back(
N->getAlignInBits());
2030 Record.push_back(
N->getEncoding());
2031 Record.push_back(
N->getFlags());
2032 Record.push_back(
N->getKind());
2033 Record.push_back(
N->getFactorRaw());
2035 auto WriteWideInt = [&](
const APInt &
Value) {
2040 Record.push_back(Encoded);
2044 WriteWideInt(
N->getNumeratorRaw());
2045 WriteWideInt(
N->getDenominatorRaw());
2048 Record.push_back(
N->getLine());
2055void ModuleBitcodeWriter::writeDIStringType(
const DIStringType *
N,
2056 SmallVectorImpl<uint64_t> &Record,
2058 const unsigned SizeIsMetadata = 0x2;
2059 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2060 Record.push_back(
N->getTag());
2066 Record.push_back(
N->getAlignInBits());
2067 Record.push_back(
N->getEncoding());
2073void ModuleBitcodeWriter::writeDIDerivedType(
const DIDerivedType *
N,
2074 SmallVectorImpl<uint64_t> &Record,
2076 const unsigned SizeIsMetadata = 0x2;
2077 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2078 Record.push_back(
N->getTag());
2081 Record.push_back(
N->getLine());
2085 Record.push_back(
N->getAlignInBits());
2087 Record.push_back(
N->getFlags());
2092 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
2093 Record.push_back(*DWARFAddressSpace + 1);
2099 if (
auto PtrAuthData =
N->getPtrAuthData())
2100 Record.push_back(PtrAuthData->RawData);
2108void ModuleBitcodeWriter::writeDISubrangeType(
const DISubrangeType *
N,
2109 SmallVectorImpl<uint64_t> &Record,
2111 const unsigned SizeIsMetadata = 0x2;
2112 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2115 Record.push_back(
N->getLine());
2118 Record.push_back(
N->getAlignInBits());
2119 Record.push_back(
N->getFlags());
2130void ModuleBitcodeWriter::writeDICompositeType(
2131 const DICompositeType *
N, SmallVectorImpl<uint64_t> &Record,
2133 const unsigned IsNotUsedInOldTypeRef = 0x2;
2134 const unsigned SizeIsMetadata = 0x4;
2135 Record.push_back(SizeIsMetadata | IsNotUsedInOldTypeRef |
2136 (
unsigned)
N->isDistinct());
2137 Record.push_back(
N->getTag());
2140 Record.push_back(
N->getLine());
2144 Record.push_back(
N->getAlignInBits());
2146 Record.push_back(
N->getFlags());
2148 Record.push_back(
N->getRuntimeLang());
2158 Record.push_back(
N->getNumExtraInhabitants());
2168void ModuleBitcodeWriter::writeDISubroutineType(
2169 const DISubroutineType *
N, SmallVectorImpl<uint64_t> &Record,
2171 const unsigned HasNoOldTypeRefs = 0x2;
2172 Record.push_back(HasNoOldTypeRefs | (
unsigned)
N->isDistinct());
2173 Record.push_back(
N->getFlags());
2181void ModuleBitcodeWriter::writeDIFile(
const DIFile *
N,
2182 SmallVectorImpl<uint64_t> &Record,
2184 Record.push_back(
N->isDistinct());
2187 if (
N->getRawChecksum()) {
2188 Record.push_back(
N->getRawChecksum()->Kind);
2196 auto Source =
N->getRawSource();
2204void ModuleBitcodeWriter::writeDICompileUnit(
const DICompileUnit *
N,
2205 SmallVectorImpl<uint64_t> &Record,
2207 assert(
N->isDistinct() &&
"Expected distinct compile units");
2210 auto Lang =
N->getSourceLanguage();
2211 Record.push_back(Lang.getName());
2214 if (Lang.hasVersionedName())
2219 Record.push_back(
N->isOptimized());
2221 Record.push_back(
N->getRuntimeVersion());
2223 Record.push_back(
N->getEmissionKind());
2229 Record.push_back(
N->getDWOId());
2231 Record.push_back(
N->getSplitDebugInlining());
2232 Record.push_back(
N->getDebugInfoForProfiling());
2233 Record.push_back((
unsigned)
N->getNameTableKind());
2234 Record.push_back(
N->getRangesBaseAddress());
2237 Record.push_back(Lang.hasVersionedName() ? Lang.getVersion() : 0);
2238 Record.push_back(Lang.getDialect());
2244void ModuleBitcodeWriter::writeDISubprogram(
const DISubprogram *
N,
2245 SmallVectorImpl<uint64_t> &Record,
2247 const uint64_t HasUnitFlag = 1 << 1;
2248 const uint64_t HasSPFlagsFlag = 1 << 2;
2249 Record.push_back(
uint64_t(
N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
2254 Record.push_back(
N->getLine());
2256 Record.push_back(
N->getScopeLine());
2258 Record.push_back(
N->getSPFlags());
2259 Record.push_back(
N->getVirtualIndex());
2260 Record.push_back(
N->getFlags());
2265 Record.push_back(
N->getThisAdjustment());
2269 Record.push_back(
N->getKeyInstructionsEnabled());
2275void ModuleBitcodeWriter::writeDILexicalBlock(
const DILexicalBlock *
N,
2276 SmallVectorImpl<uint64_t> &Record,
2278 Record.push_back(
N->isDistinct());
2281 Record.push_back(
N->getLine());
2282 Record.push_back(
N->getColumn());
2288void ModuleBitcodeWriter::writeDILexicalBlockFile(
2289 const DILexicalBlockFile *
N, SmallVectorImpl<uint64_t> &Record,
2291 Record.push_back(
N->isDistinct());
2294 Record.push_back(
N->getDiscriminator());
2300void ModuleBitcodeWriter::writeDICommonBlock(
const DICommonBlock *
N,
2301 SmallVectorImpl<uint64_t> &Record,
2303 Record.push_back(
N->isDistinct());
2308 Record.push_back(
N->getLineNo());
2314void ModuleBitcodeWriter::writeDINamespace(
const DINamespace *
N,
2315 SmallVectorImpl<uint64_t> &Record,
2317 Record.push_back(
N->isDistinct() |
N->getExportSymbols() << 1);
2325void ModuleBitcodeWriter::writeDIMacro(
const DIMacro *
N,
2326 SmallVectorImpl<uint64_t> &Record,
2328 Record.push_back(
N->isDistinct());
2329 Record.push_back(
N->getMacinfoType());
2330 Record.push_back(
N->getLine());
2338void ModuleBitcodeWriter::writeDIMacroFile(
const DIMacroFile *
N,
2339 SmallVectorImpl<uint64_t> &Record,
2341 Record.push_back(
N->isDistinct());
2342 Record.push_back(
N->getMacinfoType());
2343 Record.push_back(
N->getLine());
2351void ModuleBitcodeWriter::writeDIArgList(
const DIArgList *
N,
2352 SmallVectorImpl<uint64_t> &Record) {
2353 Record.reserve(
N->getArgs().size());
2354 for (ValueAsMetadata *MD :
N->getArgs())
2361void ModuleBitcodeWriter::writeDIModule(
const DIModule *
N,
2362 SmallVectorImpl<uint64_t> &Record,
2364 Record.push_back(
N->isDistinct());
2365 for (
auto &
I :
N->operands())
2367 Record.push_back(
N->getLineNo());
2368 Record.push_back(
N->getIsDecl());
2374void ModuleBitcodeWriter::writeDIAssignID(
const DIAssignID *
N,
2375 SmallVectorImpl<uint64_t> &Record,
2378 Record.push_back(
N->isDistinct());
2383void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2384 const DITemplateTypeParameter *
N, SmallVectorImpl<uint64_t> &Record,
2386 Record.push_back(
N->isDistinct());
2389 Record.push_back(
N->isDefault());
2395void ModuleBitcodeWriter::writeDITemplateValueParameter(
2396 const DITemplateValueParameter *
N, SmallVectorImpl<uint64_t> &Record,
2398 Record.push_back(
N->isDistinct());
2399 Record.push_back(
N->getTag());
2402 Record.push_back(
N->isDefault());
2409void ModuleBitcodeWriter::writeDIGlobalVariable(
2410 const DIGlobalVariable *
N, SmallVectorImpl<uint64_t> &Record,
2418 Record.push_back(
N->getLine());
2420 Record.push_back(
N->isLocalToUnit());
2421 Record.push_back(
N->isDefinition());
2424 Record.push_back(
N->getAlignInBits());
2431void ModuleBitcodeWriter::writeDILocalVariable(
2432 const DILocalVariable *
N, SmallVectorImpl<uint64_t> &Record,
2447 const uint64_t HasAlignmentFlag = 1 << 1;
2452 Record.push_back(
N->getLine());
2454 Record.push_back(
N->getArg());
2455 Record.push_back(
N->getFlags());
2456 Record.push_back(
N->getAlignInBits());
2463void ModuleBitcodeWriter::writeDILabel(
2464 const DILabel *
N, SmallVectorImpl<uint64_t> &Record,
2471 Record.push_back(
N->getLine());
2472 Record.push_back(
N->getColumn());
2473 Record.push_back(
N->getCoroSuspendIdx().has_value()
2474 ? (
uint64_t)
N->getCoroSuspendIdx().value()
2475 : std::numeric_limits<uint64_t>::max());
2481void ModuleBitcodeWriter::writeDIExpression(
const DIExpression *
N,
2482 SmallVectorImpl<uint64_t> &Record,
2484 Record.reserve(
N->getElements().size() + 1);
2487 Record.append(
N->elements_begin(),
N->elements_end());
2493void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2494 const DIGlobalVariableExpression *
N, SmallVectorImpl<uint64_t> &Record,
2496 Record.push_back(
N->isDistinct());
2504void ModuleBitcodeWriter::writeDIObjCProperty(
const DIObjCProperty *
N,
2505 SmallVectorImpl<uint64_t> &Record,
2507 Record.push_back(
N->isDistinct());
2510 Record.push_back(
N->getLine());
2513 Record.push_back(
N->getAttributes());
2520void ModuleBitcodeWriter::writeDIProperty(
const DIProperty *
N,
2521 SmallVectorImpl<uint64_t> &Record,
2523 Record.push_back(
N->isDistinct());
2526 Record.push_back(
N->getLine());
2534void ModuleBitcodeWriter::writeDIImportedEntity(
2535 const DIImportedEntity *
N, SmallVectorImpl<uint64_t> &Record,
2537 Record.push_back(
N->isDistinct());
2538 Record.push_back(
N->getTag());
2541 Record.push_back(
N->getLine());
2550unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2551 auto Abbv = std::make_shared<BitCodeAbbrev>();
2558void ModuleBitcodeWriter::writeNamedMetadata(
2559 SmallVectorImpl<uint64_t> &Record) {
2560 if (
M.named_metadata_empty())
2563 unsigned Abbrev = createNamedMetadataAbbrev();
2564 for (
const NamedMDNode &NMD :
M.named_metadata()) {
2566 StringRef Str = NMD.getName();
2567 Record.append(Str.bytes_begin(), Str.bytes_end());
2572 for (
const MDNode *
N : NMD.operands())
2579unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2580 auto Abbv = std::make_shared<BitCodeAbbrev>();
2592void ModuleBitcodeWriter::writeMetadataStrings(
2594 if (Strings.
empty())
2602 SmallString<256> Blob;
2604 BitstreamWriter
W(Blob);
2624#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
2625#include "llvm/IR/Metadata.def"
2629void ModuleBitcodeWriter::writeMetadataRecords(
2631 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2636#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
2637#include "llvm/IR/Metadata.def"
2643 assert(
N->isResolved() &&
"Expected forward references to be resolved");
2645 switch (
N->getMetadataID()) {
2648#define HANDLE_MDNODE_LEAF(CLASS) \
2649 case Metadata::CLASS##Kind: \
2651 write##CLASS(cast<CLASS>(N), Record, \
2652 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
2654 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
2656#include "llvm/IR/Metadata.def"
2667void ModuleBitcodeWriter::writeModuleMetadata() {
2668 if (!VE.
hasMDs() &&
M.named_metadata_empty())
2672 SmallVector<uint64_t, 64>
Record;
2676 std::vector<unsigned> MDAbbrevs;
2679 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2680 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2681 createGenericDINodeAbbrev();
2683 auto Abbv = std::make_shared<BitCodeAbbrev>();
2687 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2689 Abbv = std::make_shared<BitCodeAbbrev>();
2693 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2715 std::vector<uint64_t> IndexPos;
2719 writeMetadataRecords(VE.
getNonMDStrings(), Record, &MDAbbrevs, &IndexPos);
2730 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2731 for (
auto &Elt : IndexPos) {
2732 auto EltDelta = Elt - PreviousValue;
2733 PreviousValue = Elt;
2742 writeNamedMetadata(Record);
2744 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2745 SmallVector<uint64_t, 4>
Record;
2747 pushGlobalMetadataAttachment(Record, GO);
2751 if (
F.isDeclaration() &&
F.hasMetadata())
2752 AddDeclAttachedMetadata(
F);
2753 for (
const GlobalIFunc &GI :
M.ifuncs())
2754 if (GI.hasMetadata())
2755 AddDeclAttachedMetadata(GI);
2758 for (
const GlobalVariable &GV :
M.globals())
2759 if (GV.hasMetadata())
2760 AddDeclAttachedMetadata(GV);
2765void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2770 SmallVector<uint64_t, 64>
Record;
2776void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2777 SmallVectorImpl<uint64_t> &Record,
const GlobalObject &GO) {
2781 for (
const auto &
I : MDs) {
2787void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &
F) {
2790 SmallVector<uint64_t, 64>
Record;
2792 if (
F.hasMetadata()) {
2793 pushGlobalMetadataAttachment(Record,
F);
2801 for (
const BasicBlock &BB :
F)
2802 for (
const Instruction &
I : BB) {
2804 I.getAllMetadataOtherThanDebugLoc(MDs);
2807 if (MDs.
empty())
continue;
2811 for (
const auto &[ID, MD] : MDs) {
2822void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2823 SmallVector<uint64_t, 64>
Record;
2828 M.getMDKindNames(Names);
2830 if (Names.
empty())
return;
2834 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2835 Record.push_back(MDKindID);
2836 StringRef KName = Names[MDKindID];
2846void ModuleBitcodeWriter::writeOperandBundleTags() {
2854 M.getOperandBundleTags(Tags);
2861 SmallVector<uint64_t, 64>
Record;
2863 for (
auto Tag : Tags) {
2873void ModuleBitcodeWriter::writeSyncScopeNames() {
2875 M.getContext().getSyncScopeNames(SSNs);
2881 SmallVector<uint64_t, 64>
Record;
2882 for (
auto SSN : SSNs) {
2883 Record.append(SSN.begin(), SSN.end());
2891void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2893 if (FirstVal == LastVal)
return;
2897 unsigned AggregateAbbrev = 0;
2898 unsigned String8Abbrev = 0;
2899 unsigned CString7Abbrev = 0;
2900 unsigned CString6Abbrev = 0;
2904 auto Abbv = std::make_shared<BitCodeAbbrev>();
2908 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2911 Abbv = std::make_shared<BitCodeAbbrev>();
2915 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2917 Abbv = std::make_shared<BitCodeAbbrev>();
2921 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2923 Abbv = std::make_shared<BitCodeAbbrev>();
2927 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2930 SmallVector<uint64_t, 64>
Record;
2933 Type *LastTy =
nullptr;
2934 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2935 const Value *
V = Vals[i].first;
2937 if (
V->getType() != LastTy) {
2938 LastTy =
V->getType();
2941 CONSTANTS_SETTYPE_ABBREV);
2948 unsigned(
IA->hasSideEffects()) |
unsigned(
IA->isAlignStack()) << 1 |
2949 unsigned(
IA->getDialect() & 1) << 2 |
unsigned(
IA->canThrow()) << 3);
2952 StringRef AsmStr =
IA->getAsmString();
2957 StringRef ConstraintStr =
IA->getConstraintString();
2965 unsigned Code = -1U;
2966 unsigned AbbrevToUse = 0;
2967 if (
C->isNullValue()) {
2974 if (
IV->getBitWidth() <= 64) {
2978 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2984 if (BV->getBitWidth() <= 64) {
2988 AbbrevToUse = CONSTANTS_BYTE_ABBREV;
2998 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
3002 APInt api = CFP->getValueAPF().bitcastToAPInt();
3004 Record.push_back((p[1] << 48) | (p[0] >> 16));
3005 Record.push_back(p[0] & 0xffffLL);
3007 APInt api = CFP->getValueAPF().bitcastToAPInt();
3012 assert(0 &&
"Unknown FP type!");
3018 uint64_t NumElts = Str->getNumElements();
3020 if (Str->isCString()) {
3025 AbbrevToUse = String8Abbrev;
3029 for (
uint64_t i = 0; i != NumElts; ++i) {
3030 unsigned char V = Str->getElementAsInteger(i);
3032 isCStr7 &= (
V & 128) == 0;
3038 AbbrevToUse = CString6Abbrev;
3040 AbbrevToUse = CString7Abbrev;
3041 }
else if (
const ConstantDataSequential *CDS =
3044 Type *EltTy = CDS->getElementType();
3046 for (
uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
3047 Record.push_back(CDS->getElementAsInteger(i));
3049 for (
uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
3051 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
3055 for (
const Value *
Op :
C->operands())
3057 AbbrevToUse = AggregateAbbrev;
3059 switch (
CE->getOpcode()) {
3066 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
3068 assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
3078 case Instruction::FNeg: {
3079 assert(
CE->getNumOperands() == 1 &&
"Unknown constant expr!");
3088 case Instruction::GetElementPtr: {
3093 if (std::optional<ConstantRange>
Range = GO->getInRange()) {
3097 for (
const Value *
Op :
CE->operands()) {
3103 case Instruction::ExtractElement:
3110 case Instruction::InsertElement:
3117 case Instruction::ShuffleVector:
3122 if (
C->getType() ==
C->getOperand(0)->getType()) {
3159 Stream.
EmitRecord(Code, Record, AbbrevToUse);
3166void ModuleBitcodeWriter::writeModuleConstants() {
3171 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
3173 writeConstants(i, Vals.size(),
true);
3187bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
3188 SmallVectorImpl<unsigned> &Vals) {
3192 if (ValID >= InstID) {
3199bool ModuleBitcodeWriter::pushValueOrMetadata(
const Value *V,
unsigned InstID,
3200 SmallVectorImpl<unsigned> &Vals) {
3201 bool IsMetadata =
V->getType()->isMetadataTy();
3209 return pushValueAndType(V, InstID, Vals);
3212void ModuleBitcodeWriter::writeOperandBundles(
const CallBase &CS,
3219 Record.push_back(
C.getOperandBundleTagID(Bundle.getTagName()));
3221 for (
auto &Input : Bundle.Inputs)
3222 pushValueOrMetadata(Input, InstID, Record);
3231void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
3232 SmallVectorImpl<unsigned> &Vals) {
3237void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
3238 SmallVectorImpl<uint64_t> &Vals) {
3240 int64_t diff = ((int32_t)InstID - (int32_t)ValID);
3245void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
3247 SmallVectorImpl<unsigned> &Vals) {
3249 unsigned AbbrevToUse = 0;
3251 switch (
I.getOpcode()) {
3255 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3256 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
3261 if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
3262 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
3268 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3269 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
3270 pushValue(
I.getOperand(1), InstID, Vals);
3274 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
3275 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
3280 case Instruction::FNeg: {
3282 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3283 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
3287 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
3288 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
3293 case Instruction::GetElementPtr: {
3295 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
3299 for (
const Value *
Op :
I.operands())
3300 pushValueAndType(
Op, InstID, Vals);
3303 case Instruction::ExtractValue: {
3305 pushValueAndType(
I.getOperand(0), InstID, Vals);
3310 case Instruction::InsertValue: {
3312 pushValueAndType(
I.getOperand(0), InstID, Vals);
3313 pushValueAndType(
I.getOperand(1), InstID, Vals);
3318 case Instruction::Select: {
3320 pushValueAndType(
I.getOperand(1), InstID, Vals);
3321 pushValue(
I.getOperand(2), InstID, Vals);
3322 pushValueAndType(
I.getOperand(0), InstID, Vals);
3328 case Instruction::ExtractElement:
3330 pushValueAndType(
I.getOperand(0), InstID, Vals);
3331 pushValueAndType(
I.getOperand(1), InstID, Vals);
3333 case Instruction::InsertElement:
3335 pushValueAndType(
I.getOperand(0), InstID, Vals);
3336 pushValue(
I.getOperand(1), InstID, Vals);
3337 pushValueAndType(
I.getOperand(2), InstID, Vals);
3339 case Instruction::ShuffleVector:
3341 pushValueAndType(
I.getOperand(0), InstID, Vals);
3342 pushValue(
I.getOperand(1), InstID, Vals);
3346 case Instruction::ICmp:
3347 case Instruction::FCmp: {
3350 AbbrevToUse = FUNCTION_INST_CMP_ABBREV;
3351 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3353 pushValue(
I.getOperand(1), InstID, Vals);
3359 AbbrevToUse = FUNCTION_INST_CMP_FLAGS_ABBREV;
3364 case Instruction::Ret:
3367 unsigned NumOperands =
I.getNumOperands();
3368 if (NumOperands == 0)
3369 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
3370 else if (NumOperands == 1) {
3371 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3372 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
3374 for (
const Value *
Op :
I.operands())
3375 pushValueAndType(
Op, InstID, Vals);
3379 case Instruction::UncondBr: {
3381 AbbrevToUse = FUNCTION_INST_BR_UNCOND_ABBREV;
3385 case Instruction::CondBr: {
3387 AbbrevToUse = FUNCTION_INST_BR_COND_ABBREV;
3391 pushValue(
II.getCondition(), InstID, Vals);
3393 case Instruction::Switch:
3398 pushValue(
SI.getCondition(), InstID, Vals);
3400 for (
auto Case :
SI.cases()) {
3406 case Instruction::IndirectBr:
3410 pushValue(
I.getOperand(0), InstID, Vals);
3415 case Instruction::Invoke: {
3418 FunctionType *FTy =
II->getFunctionType();
3420 if (
II->hasOperandBundles())
3421 writeOperandBundles(*
II, InstID);
3430 pushValueAndType(Callee, InstID, Vals);
3433 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3434 pushValue(
I.getOperand(i), InstID, Vals);
3437 if (FTy->isVarArg()) {
3438 for (
unsigned i = FTy->getNumParams(), e =
II->arg_size(); i != e; ++i)
3439 pushValueAndType(
I.getOperand(i), InstID, Vals);
3443 case Instruction::Resume:
3445 pushValueAndType(
I.getOperand(0), InstID, Vals);
3447 case Instruction::CleanupRet: {
3450 pushValue(CRI.getCleanupPad(), InstID, Vals);
3451 if (CRI.hasUnwindDest())
3455 case Instruction::CatchRet: {
3458 pushValue(CRI.getCatchPad(), InstID, Vals);
3462 case Instruction::CleanupPad:
3463 case Instruction::CatchPad: {
3467 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3469 unsigned NumArgOperands = FuncletPad.arg_size();
3471 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
3472 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
3475 case Instruction::CatchSwitch: {
3479 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3481 unsigned NumHandlers = CatchSwitch.getNumHandlers();
3483 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
3486 if (CatchSwitch.hasUnwindDest())
3490 case Instruction::CallBr: {
3496 writeOperandBundles(*CBI, InstID);
3511 pushValueAndType(Callee, InstID, Vals);
3514 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3515 pushValue(
I.getOperand(i), InstID, Vals);
3518 if (FTy->isVarArg()) {
3519 for (
unsigned i = FTy->getNumParams(), e = CBI->
arg_size(); i != e; ++i)
3520 pushValueAndType(
I.getOperand(i), InstID, Vals);
3524 case Instruction::Unreachable:
3526 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3529 case Instruction::PHI: {
3547 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
3552 case Instruction::LandingPad: {
3563 pushValueAndType(LP.
getClause(
I), InstID, Vals);
3568 case Instruction::Alloca: {
3574 using APV = AllocaPackedValues;
3576 unsigned EncodedAlign = getEncodedAlign(AI.
getAlign());
3578 Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3580 EncodedAlign >> APV::AlignLower::Bits);
3587 if (AS !=
M.getDataLayout().getAllocaAddrSpace())
3592 case Instruction::Load: {
3594 if (LI.isAtomic()) {
3596 pushValueAndType(LI.getOperand(0), InstID, Vals);
3599 if (!pushValueAndType(LI.getOperand(0), InstID, Vals))
3600 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3603 Vals.
push_back(getEncodedAlign(LI.getAlign()));
3605 if (LI.isAtomic()) {
3607 Vals.
push_back(getEncodedSyncScopeID(LI.getSyncScopeID()));
3608 if (LI.isElementwise())
3614 case Instruction::Store: {
3616 if (
SI.isAtomic()) {
3620 AbbrevToUse = FUNCTION_INST_STORE_ABBREV;
3622 if (pushValueAndType(
I.getOperand(1), InstID, Vals))
3624 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3628 if (
SI.isAtomic()) {
3630 Vals.
push_back(getEncodedSyncScopeID(
SI.getSyncScopeID()));
3631 if (
SI.isElementwise())
3637 case Instruction::AtomicCmpXchg:
3639 pushValueAndType(
I.getOperand(0), InstID, Vals);
3640 pushValueAndType(
I.getOperand(1), InstID, Vals);
3641 pushValue(
I.getOperand(2), InstID, Vals);
3652 case Instruction::AtomicRMW:
3654 pushValueAndType(
I.getOperand(0), InstID, Vals);
3655 pushValueAndType(
I.getOperand(1), InstID, Vals);
3663 case Instruction::Fence:
3668 case Instruction::Call: {
3673 writeOperandBundles(CI, InstID);
3693 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3697 if (FTy->isVarArg()) {
3698 for (
unsigned i = FTy->getNumParams(), e = CI.
arg_size(); i != e; ++i)
3703 case Instruction::VAArg:
3706 pushValue(
I.getOperand(0), InstID, Vals);
3709 case Instruction::Freeze:
3711 pushValueAndType(
I.getOperand(0), InstID, Vals);
3721void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3722 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3727 VSTOffset -= bitcodeStartBit();
3728 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
3732 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3736 auto Abbv = std::make_shared<BitCodeAbbrev>();
3740 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3745 if (
F.isDeclaration())
3752 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
3753 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
3757 Record[1] = BitcodeIndex / 32 + 1;
3766void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3767 const ValueSymbolTable &VST) {
3775 SmallVector<uint64_t, 64> NameVals;
3781 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3790 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3794 AbbrevToUse = VST_ENTRY_6_ABBREV;
3796 AbbrevToUse = VST_ENTRY_7_ABBREV;
3799 for (
const auto P :
Name.getKey())
3803 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3810void ModuleBitcodeWriter::writeUseList(UseListOrder &&Order) {
3811 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3818 SmallVector<uint64_t, 64>
Record(Order.Shuffle.begin(), Order.Shuffle.end());
3823void ModuleBitcodeWriter::writeUseListBlock(
const Function *
F) {
3825 "Expected to be preserving use-list order");
3827 auto hasMore = [&]() {
3843void ModuleBitcodeWriter::writeFunction(
3845 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3862 unsigned CstStart, CstEnd;
3864 writeConstants(CstStart, CstEnd,
false);
3867 writeFunctionMetadata(
F);
3870 unsigned InstID = CstEnd;
3872 bool NeedsMetadataAttachment =
F.hasMetadata();
3874 DILocation *LastDL =
nullptr;
3875 SmallSetVector<Function *, 4> BlockAddressUsers;
3878 for (
const BasicBlock &BB :
F) {
3879 for (
const Instruction &
I : BB) {
3880 writeInstruction(
I, InstID, Vals);
3882 if (!
I.getType()->isVoidTy())
3886 NeedsMetadataAttachment |=
I.hasMetadataOtherThanDebugLoc();
3889 if (DILocation *
DL =
I.getDebugLoc()) {
3902 FUNCTION_DEBUG_LOC_ABBREV);
3912 if (
I.hasDbgRecords()) {
3916 auto PushValueOrMetadata = [&Vals, InstID,
3919 "RawLocation unexpectedly null in DbgVariableRecord");
3921 SmallVector<unsigned, 2> ValAndType;
3925 if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
3939 for (DbgRecord &DR :
I.DebugMarker->getDbgRecordRange()) {
3965 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3989 SmallPtrSet<Value *, 8> Visited{BA};
3990 while (!Worklist.
empty()) {
3992 for (User *U :
V->users()) {
3998 Visited.
insert(U).second)
4005 if (!BlockAddressUsers.
empty()) {
4014 if (
auto *Symtab =
F.getValueSymbolTable())
4015 writeFunctionLevelValueSymbolTable(*Symtab);
4017 if (NeedsMetadataAttachment)
4018 writeFunctionMetadataAttachment(
F);
4020 writeUseListBlock(&
F);
4026void ModuleBitcodeWriter::writeBlockInfo() {
4039 auto Abbv = std::make_shared<BitCodeAbbrev>();
4050 auto Abbv = std::make_shared<BitCodeAbbrev>();
4060 auto Abbv = std::make_shared<BitCodeAbbrev>();
4070 auto Abbv = std::make_shared<BitCodeAbbrev>();
4076 VST_BBENTRY_6_ABBREV)
4081 auto Abbv = std::make_shared<BitCodeAbbrev>();
4083 Abbv->Add(TypeAbbrevOp);
4085 CONSTANTS_SETTYPE_ABBREV)
4090 auto Abbv = std::make_shared<BitCodeAbbrev>();
4094 CONSTANTS_INTEGER_ABBREV)
4099 auto Abbv = std::make_shared<BitCodeAbbrev>();
4103 CONSTANTS_BYTE_ABBREV)
4108 auto Abbv = std::make_shared<BitCodeAbbrev>();
4116 CONSTANTS_CE_CAST_Abbrev)
4120 auto Abbv = std::make_shared<BitCodeAbbrev>();
4123 CONSTANTS_NULL_Abbrev)
4130 auto Abbv = std::make_shared<BitCodeAbbrev>();
4132 Abbv->Add(ValAbbrevOp);
4133 Abbv->Add(TypeAbbrevOp);
4137 FUNCTION_INST_LOAD_ABBREV)
4141 auto Abbv = std::make_shared<BitCodeAbbrev>();
4143 Abbv->Add(ValAbbrevOp);
4144 Abbv->Add(ValAbbrevOp);
4148 FUNCTION_INST_STORE_ABBREV)
4152 auto Abbv = std::make_shared<BitCodeAbbrev>();
4154 Abbv->Add(ValAbbrevOp);
4157 FUNCTION_INST_UNOP_ABBREV)
4161 auto Abbv = std::make_shared<BitCodeAbbrev>();
4163 Abbv->Add(ValAbbrevOp);
4167 FUNCTION_INST_UNOP_FLAGS_ABBREV)
4171 auto Abbv = std::make_shared<BitCodeAbbrev>();
4173 Abbv->Add(ValAbbrevOp);
4174 Abbv->Add(ValAbbrevOp);
4177 FUNCTION_INST_BINOP_ABBREV)
4181 auto Abbv = std::make_shared<BitCodeAbbrev>();
4183 Abbv->Add(ValAbbrevOp);
4184 Abbv->Add(ValAbbrevOp);
4188 FUNCTION_INST_BINOP_FLAGS_ABBREV)
4192 auto Abbv = std::make_shared<BitCodeAbbrev>();
4194 Abbv->Add(ValAbbrevOp);
4195 Abbv->Add(TypeAbbrevOp);
4198 FUNCTION_INST_CAST_ABBREV)
4202 auto Abbv = std::make_shared<BitCodeAbbrev>();
4204 Abbv->Add(ValAbbrevOp);
4205 Abbv->Add(TypeAbbrevOp);
4209 FUNCTION_INST_CAST_FLAGS_ABBREV)
4214 auto Abbv = std::make_shared<BitCodeAbbrev>();
4217 FUNCTION_INST_RET_VOID_ABBREV)
4221 auto Abbv = std::make_shared<BitCodeAbbrev>();
4223 Abbv->Add(ValAbbrevOp);
4225 FUNCTION_INST_RET_VAL_ABBREV)
4229 auto Abbv = std::make_shared<BitCodeAbbrev>();
4232 Abbv->Add(ValAbbrevOp);
4234 FUNCTION_INST_BR_UNCOND_ABBREV)
4238 auto Abbv = std::make_shared<BitCodeAbbrev>();
4241 Abbv->Add(ValAbbrevOp);
4242 Abbv->Add(ValAbbrevOp);
4243 Abbv->Add(ValAbbrevOp);
4245 FUNCTION_INST_BR_COND_ABBREV)
4249 auto Abbv = std::make_shared<BitCodeAbbrev>();
4252 FUNCTION_INST_UNREACHABLE_ABBREV)
4256 auto Abbv = std::make_shared<BitCodeAbbrev>();
4259 Abbv->Add(TypeAbbrevOp);
4261 Abbv->Add(ValAbbrevOp);
4263 FUNCTION_INST_GEP_ABBREV)
4267 auto Abbv = std::make_shared<BitCodeAbbrev>();
4269 Abbv->Add(ValAbbrevOp);
4270 Abbv->Add(ValAbbrevOp);
4273 FUNCTION_INST_CMP_ABBREV)
4277 auto Abbv = std::make_shared<BitCodeAbbrev>();
4279 Abbv->Add(ValAbbrevOp);
4280 Abbv->Add(ValAbbrevOp);
4284 FUNCTION_INST_CMP_FLAGS_ABBREV)
4288 auto Abbv = std::make_shared<BitCodeAbbrev>();
4293 Abbv->Add(ValAbbrevOp);
4295 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
4299 auto Abbv = std::make_shared<BitCodeAbbrev>();
4310 FUNCTION_DEBUG_LOC_ABBREV)
4318void IndexBitcodeWriter::writeModStrings() {
4324 auto Abbv = std::make_shared<BitCodeAbbrev>();
4329 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
4332 Abbv = std::make_shared<BitCodeAbbrev>();
4337 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
4340 Abbv = std::make_shared<BitCodeAbbrev>();
4345 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
4348 Abbv = std::make_shared<BitCodeAbbrev>();
4355 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
4358 forEachModule([&](
const StringMapEntry<ModuleHash> &MPSE) {
4360 const auto &Hash = MPSE.
getValue();
4362 unsigned AbbrevToUse = Abbrev8Bit;
4364 AbbrevToUse = Abbrev6Bit;
4366 AbbrevToUse = Abbrev7Bit;
4368 auto ModuleId = ModuleIdMap.
size();
4369 ModuleIdMap[
Key] = ModuleId;
4379 Vals.
assign(Hash.begin(), Hash.end());
4391template <
typename Fn>
4395 if (!FS->type_tests().empty())
4400 auto WriteVFuncIdVec = [&](
uint64_t Ty,
4405 for (
auto &VF : VFs) {
4406 Record.push_back(VF.GUID);
4407 Record.push_back(VF.Offset);
4413 FS->type_test_assume_vcalls());
4415 FS->type_checked_load_vcalls());
4417 auto WriteConstVCallVec = [&](
uint64_t Ty,
4419 for (
auto &VC : VCs) {
4421 Record.push_back(VC.VFunc.GUID);
4422 Record.push_back(VC.VFunc.Offset);
4429 FS->type_test_assume_const_vcalls());
4431 FS->type_checked_load_const_vcalls());
4441 if (!FS->paramAccesses().empty()) {
4443 for (
auto &Arg : FS->paramAccesses()) {
4444 size_t UndoSize =
Record.size();
4445 Record.push_back(Arg.ParamNo);
4446 WriteRange(Arg.Use);
4447 Record.push_back(Arg.Calls.size());
4448 for (
auto &
Call : Arg.Calls) {
4450 std::optional<unsigned> ValueID = GetValueID(
Call.Callee);
4457 Record.push_back(*ValueID);
4458 WriteRange(
Call.Offsets);
4469 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
4470 if (!FS->type_tests().empty())
4471 for (
auto &TT : FS->type_tests())
4472 ReferencedTypeIds.insert(TT);
4474 auto GetReferencedTypesFromVFuncIdVec =
4476 for (
auto &VF : VFs)
4477 ReferencedTypeIds.insert(VF.GUID);
4480 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4481 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4483 auto GetReferencedTypesFromConstVCallVec =
4485 for (
auto &VC : VCs)
4486 ReferencedTypeIds.insert(VC.VFunc.GUID);
4489 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4490 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
4526 NameVals.
push_back(Summary.TTRes.TheKind);
4527 NameVals.
push_back(Summary.TTRes.SizeM1BitWidth);
4528 NameVals.
push_back(Summary.TTRes.AlignLog2);
4529 NameVals.
push_back(Summary.TTRes.SizeM1);
4530 NameVals.
push_back(Summary.TTRes.BitMask);
4531 NameVals.
push_back(Summary.TTRes.InlineBits);
4533 for (
auto &W : Summary.WPDRes)
4545 for (
auto &
P : Summary) {
4547 NameVals.
push_back(
VE.getValueID(
P.VTableVI.getValue()));
4561 static_assert(std::is_same_v<LinearFrameId, unsigned>);
4562 for (
auto &AI : FS->allocs()) {
4563 for (
auto &MIB : AI.MIBs) {
4565 StackIdIndices.
reserve(MIB.StackIdIndices.size());
4566 for (
auto Id : MIB.StackIdIndices)
4567 StackIdIndices.
push_back(GetStackIndex(Id));
4569 CallStacks.insert({CallStacks.size(), StackIdIndices});
4582 assert(!CallStacks.empty());
4588 Builder.
build(std::move(CallStacks),
nullptr,
4592 return Builder.takeCallStackPos();
4597 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
bool PerModule,
4598 std::function<
unsigned(
const ValueInfo &VI)> GetValueID,
4599 std::function<
unsigned(
unsigned)> GetStackIndex,
4600 bool WriteContextSizeInfoIndex,
4605 for (
auto &CI : FS->callsites()) {
4609 assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4610 Record.push_back(GetValueID(CI.Callee));
4612 Record.push_back(CI.StackIdIndices.size());
4613 Record.push_back(CI.Clones.size());
4615 for (
auto Id : CI.StackIdIndices)
4616 Record.push_back(GetStackIndex(Id));
4624 for (
auto &AI : FS->allocs()) {
4628 assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4629 Record.push_back(AI.MIBs.size());
4631 Record.push_back(AI.Versions.size());
4632 for (
auto &MIB : AI.MIBs) {
4639 assert(CallStackCount <= CallStackPos.
size());
4640 Record.push_back(CallStackPos[CallStackCount++]);
4645 assert(AI.ContextSizeInfos.empty() ||
4646 AI.ContextSizeInfos.size() == AI.MIBs.size());
4648 if (WriteContextSizeInfoIndex && !AI.ContextSizeInfos.empty()) {
4656 ContextIds.
reserve(AI.ContextSizeInfos.size() * 2);
4657 for (
auto &Infos : AI.ContextSizeInfos) {
4658 Record.push_back(Infos.size());
4659 for (
auto [FullStackId, TotalSize] : Infos) {
4666 Record.push_back(TotalSize);
4684void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4685 SmallVector<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
4686 unsigned ValueID,
unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
4687 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
const Function &
F,
4688 DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
4695 Stream, FS, [&](
const ValueInfo &VI) -> std::optional<unsigned> {
4699 auto SpecialRefCnts =
FS->specialRefCounts();
4704 NameVals.
push_back(SpecialRefCnts.first);
4705 NameVals.
push_back(SpecialRefCnts.second);
4707 for (
auto &RI :
FS->refs())
4710 for (
auto &ECI :
FS->calls()) {
4711 NameVals.
push_back(getValueId(ECI.first));
4720 Stream, FS, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
4722 [&](
const ValueInfo &VI) {
return getValueId(VI); },
4723 [&](
unsigned I) {
return I; },
4724 true, CallStackPos, CallStackCount);
4729void ModuleBitcodeWriterBase::writeModuleLevelReferences(
4730 const GlobalVariable &V, SmallVector<uint64_t, 64> &NameVals,
4731 unsigned FSModRefsAbbrev,
unsigned FSModVTableRefsAbbrev) {
4736 auto VI =
Index->getValueInfo(GUID);
4737 if (!VI ||
VI.getSummaryList().empty()) {
4743 auto *
Summary =
VI.getSummaryList()[0].get();
4749 auto VTableFuncs =
VS->vTableFuncs();
4750 if (!VTableFuncs.empty())
4753 unsigned SizeBeforeRefs = NameVals.
size();
4754 for (
auto &RI :
VS->refs())
4760 if (VTableFuncs.empty())
4765 for (
auto &
P : VTableFuncs) {
4771 FSModVTableRefsAbbrev);
4778void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
4781 bool IsThinLTO =
true;
4784 IsThinLTO = MD->getZExtValue();
4796 if (
Index->enableSplitLTOUnit())
4798 if (
Index->hasUnifiedLTO())
4808 auto Abbv = std::make_shared<BitCodeAbbrev>();
4814 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4816 for (
const auto &GVI : valueIds()) {
4818 ArrayRef<uint32_t>{GVI.second,
4819 static_cast<uint32_t
>(GVI.first >> 32),
4820 static_cast<uint32_t
>(GVI.first)},
4824 if (!
Index->stackIds().empty()) {
4825 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4832 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4833 SmallVector<uint32_t> Vals;
4835 for (
auto Id :
Index->stackIds()) {
4836 Vals.
push_back(
static_cast<uint32_t
>(Id >> 32));
4837 Vals.
push_back(
static_cast<uint32_t
>(Id));
4842 unsigned ContextIdAbbvId = 0;
4845 auto ContextIdAbbv = std::make_shared<BitCodeAbbrev>();
4857 ContextIdAbbvId = Stream.
EmitAbbrev(std::move(ContextIdAbbv));
4861 Abbv = std::make_shared<BitCodeAbbrev>();
4873 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4876 Abbv = std::make_shared<BitCodeAbbrev>();
4882 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4885 Abbv = std::make_shared<BitCodeAbbrev>();
4893 unsigned FSModVTableRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4896 Abbv = std::make_shared<BitCodeAbbrev>();
4901 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4904 Abbv = std::make_shared<BitCodeAbbrev>();
4911 unsigned TypeIdCompatibleVtableAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4913 Abbv = std::make_shared<BitCodeAbbrev>();
4919 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4921 Abbv = std::make_shared<BitCodeAbbrev>();
4928 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4930 Abbv = std::make_shared<BitCodeAbbrev>();
4935 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4942 MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
4953 ValueInfo
VI =
Index->getValueInfo(GUID);
4954 if (!VI ||
VI.getSummaryList().empty()) {
4957 if (!
F.isDeclaration())
4959 " to have an associated value info.");
4962 auto *
Summary =
VI.getSummaryList()[0].get();
4965 FS, [](
unsigned I) {
return I; }, CallStacks);
4969 DenseMap<CallStackId, LinearCallStackId> CallStackPos;
4970 if (!CallStacks.
empty()) {
4978 SmallVector<uint64_t, 64> NameVals;
4989 ValueInfo
VI =
Index->getValueInfo(GUID);
4990 if (!VI ||
VI.getSummaryList().empty()) {
4996 auto *
Summary =
VI.getSummaryList()[0].get();
4997 writePerModuleFunctionSummaryRecord(NameVals, Summary, VE.
getValueID(&
F),
4998 FSCallsProfileAbbrev, CallsiteAbbrev,
4999 AllocAbbrev, ContextIdAbbvId,
F,
5000 CallStackPos, CallStackCount);
5005 for (
const GlobalVariable &
G :
M.globals())
5006 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev,
5007 FSModVTableRefsAbbrev);
5009 for (
const GlobalAlias &
A :
M.aliases()) {
5010 auto *Aliasee =
A.getAliaseeObject();
5026 for (
auto &S :
Index->typeIdCompatibleVtableMap()) {
5030 TypeIdCompatibleVtableAbbrev);
5034 if (
Index->getBlockCount())
5036 ArrayRef<uint64_t>{
Index->getBlockCount()});
5041void ModuleBitcodeWriterBase::writeGUIDList() {
5043 const size_t Max = Vals.size();
5045 std::vector<GlobalValue::GUID> GUIDs(Max, 0);
5046 for (
const GlobalValue &GV :
M.global_values()) {
5047 auto MaybeGUID = GV.getGUIDIfAssigned();
5050 auto GUID = *MaybeGUID;
5053 GUIDs[ValueID] =
GUID;
5056 auto Abbv = std::make_shared<BitCodeAbbrev>();
5060 unsigned GUIDListAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5062 SmallVector<uint32_t> RecordVals;
5064 for (
auto GUID : GUIDs) {
5065 RecordVals.
push_back(
static_cast<uint32_t
>(GUID >> 32));
5066 RecordVals.
push_back(
static_cast<uint32_t
>(GUID));
5073void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
5082 auto Abbv = std::make_shared<BitCodeAbbrev>();
5088 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5090 for (
const auto &GVI : valueIds()) {
5092 ArrayRef<uint32_t>{GVI.second,
5093 static_cast<uint32_t
>(GVI.first >> 32),
5094 static_cast<uint32_t
>(GVI.first)},
5100 if (!StackIds.empty()) {
5101 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
5108 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
5109 SmallVector<uint32_t> Vals;
5110 Vals.
reserve(StackIds.size() * 2);
5111 for (
auto Id : StackIds) {
5112 Vals.
push_back(
static_cast<uint32_t
>(Id >> 32));
5113 Vals.
push_back(
static_cast<uint32_t
>(Id));
5119 Abbv = std::make_shared<BitCodeAbbrev>();
5133 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5136 Abbv = std::make_shared<BitCodeAbbrev>();
5143 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5146 Abbv = std::make_shared<BitCodeAbbrev>();
5152 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5154 Abbv = std::make_shared<BitCodeAbbrev>();
5162 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5164 Abbv = std::make_shared<BitCodeAbbrev>();
5175 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5177 auto shouldImportValueAsDecl = [&](GlobalValueSummary *GVS) ->
bool {
5178 if (DecSummaries ==
nullptr)
5180 return DecSummaries->
count(GVS);
5188 DenseMap<const GlobalValueSummary *, unsigned> SummaryToValueIdMap;
5190 SmallVector<uint64_t, 64> NameVals;
5194 std::set<GlobalValue::GUID> ReferencedTypeIds;
5198 auto MaybeEmitOriginalName = [&](GlobalValueSummary &S) {
5208 NameVals.
push_back(S.getOriginalName());
5213 DenseMap<CallStackId, LinearCallStackId> CallStackPos;
5215 Abbv = std::make_shared<BitCodeAbbrev>();
5220 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5227 MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
5228 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5234 GlobalValueSummary *S =
I.second;
5247 return StackIdIndicesToIndex[
I];
5253 if (!CallStacks.
empty()) {
5263 DenseSet<GlobalValue::GUID> DefOrUseGUIDs;
5264 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5265 GlobalValueSummary *S =
I.second;
5267 DefOrUseGUIDs.
insert(
I.first);
5268 for (
const ValueInfo &VI : S->
refs())
5269 DefOrUseGUIDs.
insert(
VI.getGUID());
5271 auto ValueId = getValueId(
I.first);
5273 SummaryToValueIdMap[S] = *ValueId;
5291 NameVals.
push_back(ModuleIdMap[
VS->modulePath()]);
5295 for (
auto &RI :
VS->refs()) {
5296 auto RefValueId = getValueId(RI.getGUID());
5306 MaybeEmitOriginalName(*S);
5310 auto GetValueId = [&](
const ValueInfo &
VI) -> std::optional<unsigned> {
5312 return std::nullopt;
5313 return getValueId(
VI.getGUID());
5322 NameVals.
push_back(ModuleIdMap[
FS->modulePath()]);
5335 unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
5336 for (
auto &RI :
FS->refs()) {
5337 auto RefValueId = getValueId(RI.getGUID());
5341 if (RI.isReadOnly())
5343 else if (RI.isWriteOnly())
5347 NameVals[6] =
Count;
5348 NameVals[7] = RORefCnt;
5349 NameVals[8] = WORefCnt;
5351 for (
auto &EI :
FS->calls()) {
5354 std::optional<unsigned> CallValueId = GetValueId(EI.first);
5363 FSCallsProfileAbbrev);
5367 Stream, FS, CallsiteAbbrev, AllocAbbrev, 0,
5370 [&](
const ValueInfo &VI) ->
unsigned {
5371 std::optional<unsigned> ValueID = GetValueId(VI);
5386 return StackIdIndicesToIndex[
I];
5388 false, CallStackPos, CallStackCount);
5390 MaybeEmitOriginalName(*S);
5393 for (
auto *AS : Aliases) {
5394 auto AliasValueId = SummaryToValueIdMap[AS];
5403 auto AliaseeValueId =
5410 MaybeEmitOriginalName(*AS);
5418 auto EmitCfiFunctions = [&](
const CfiFunctionIndex &CfiIndex,
5420 if (CfiIndex.
empty())
5424 for (StringRef Name : Names)
5427 if (Functions.
empty())
5430 for (
const auto &Record : Functions) {
5445 for (
auto &
T : ReferencedTypeIds) {
5446 auto TidIter =
Index.typeIds().equal_range(
T);
5447 for (
const auto &[GUID, TypeIdPair] :
make_range(TidIter)) {
5455 if (
Index.getBlockCount())
5457 ArrayRef<uint64_t>{
Index.getBlockCount()});
5468 auto Abbv = std::make_shared<BitCodeAbbrev>();
5472 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5474 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
5477 Abbv = std::make_shared<BitCodeAbbrev>();
5480 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5486void ModuleBitcodeWriter::writeModuleHash(StringRef View) {
5491 Hasher.
update(ArrayRef<uint8_t>(
5492 reinterpret_cast<const uint8_t *
>(
View.data()),
View.size()));
5493 std::array<uint8_t, 20> Hash = Hasher.
result();
5494 for (
int Pos = 0; Pos < 20; Pos += 4) {
5507void ModuleBitcodeWriter::write() {
5515 writeModuleVersion();
5524 writeAttributeGroupTable();
5527 writeAttributeTable();
5536 writeModuleConstants();
5539 writeModuleMetadataKinds();
5542 writeModuleMetadata();
5546 writeUseListBlock(
nullptr);
5548 writeOperandBundleTags();
5549 writeSyncScopeNames();
5552 DenseMap<const Function *, uint64_t> FunctionToBitcodeIndex;
5554 if (!
F.isDeclaration())
5555 writeFunction(
F, FunctionToBitcodeIndex);
5560 writePerModuleGlobalValueSummary();
5562 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
5590 unsigned CPUType = ~0U;
5597 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
5598 DARWIN_CPU_TYPE_X86 = 7,
5599 DARWIN_CPU_TYPE_ARM = 12,
5600 DARWIN_CPU_TYPE_POWERPC = 18
5605 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
5607 CPUType = DARWIN_CPU_TYPE_X86;
5609 CPUType = DARWIN_CPU_TYPE_POWERPC;
5611 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
5613 CPUType = DARWIN_CPU_TYPE_ARM;
5617 "Expected header size to be reserved");
5622 unsigned Position = 0;
5630 while (Buffer.
size() & 15)
5637 Stream.
Emit((
unsigned)
'B', 8);
5638 Stream.
Emit((
unsigned)
'C', 8);
5639 Stream.
Emit(0x0, 4);
5640 Stream.
Emit(0xC, 4);
5641 Stream.
Emit(0xE, 4);
5642 Stream.
Emit(0xD, 4);
5660 auto Abbv = std::make_shared<BitCodeAbbrev>();
5663 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
5671 assert(!WroteStrtab && !WroteSymtab);
5677 if (M->getModuleInlineAsm().empty())
5681 const Triple TT(M->getTargetTriple());
5683 if (!
T || !
T->hasMCAsmParser())
5705 std::vector<char> Strtab;
5706 StrtabBuilder.finalizeInOrder();
5707 Strtab.resize(StrtabBuilder.getSize());
5708 StrtabBuilder.write((
uint8_t *)Strtab.data());
5711 {Strtab.data(), Strtab.size()});
5722 bool ShouldPreserveUseListOrder,
5731 assert(M.isMaterialized());
5732 Mods.push_back(
const_cast<Module *
>(&M));
5734 ModuleBitcodeWriter ModuleWriter(M, StrtabBuilder, *Stream,
5735 ShouldPreserveUseListOrder, Index,
5736 GenerateHash, ModHash);
5737 ModuleWriter.write();
5744 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, DecSummaries,
5745 ModuleToSummariesForIndex);
5746 IndexWriter.write();
5751 bool ShouldPreserveUseListOrder,
5755 Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
5757 Writer.writeSymtab();
5758 Writer.writeStrtab();
5760 Triple TT(M.getTargetTriple());
5761 if (TT.isOSDarwin() || TT.isOSBinFormatMachO()) {
5779void IndexBitcodeWriter::write() {
5782 writeModuleVersion();
5788 writeCombinedGlobalValueSummary();
5805 Writer.
writeIndex(&Index, ModuleToSummariesForIndex, DecSummaries);
5814class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
5824 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5826 ModHash(&ModHash) {}
5831 void writeSimplifiedModuleInfo();
5841void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5853 auto Abbv = std::make_shared<BitCodeAbbrev>();
5856 Abbv->Add(AbbrevOpToUse);
5857 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5859 for (
const auto P :
M.getSourceFileName())
5925void ThinLinkBitcodeWriter::write() {
5928 writeModuleVersion();
5930 writeSimplifiedModuleInfo();
5932 writePerModuleGlobalValueSummary();
5949 assert(M.isMaterialized());
5950 Mods.push_back(
const_cast<Module *
>(&M));
5952 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream, Index,
5954 ThinLinkWriter.write();
5975 switch (
T.getObjectFormat()) {
5977 return "__LLVM,__bitcode";
6002 switch (
T.getObjectFormat()) {
6004 return "__LLVM,__cmdline";
6030 const std::vector<uint8_t> &CmdArgs) {
6035 Type *UsedElementType = Used ? Used->getValueType()->getArrayElementType()
6037 for (
auto *GV : UsedGlobals) {
6038 if (GV->getName() !=
"llvm.embedded.module" &&
6039 GV->getName() !=
"llvm.cmdline")
6044 Used->eraseFromParent();
6049 Triple T(M.getTargetTriple());
6078 M.getGlobalVariable(
"llvm.embedded.module",
true)) {
6079 assert(Old->hasZeroLiveUses() &&
6080 "llvm.embedded.module can only be used once in llvm.compiler.used");
6082 Old->eraseFromParent();
6084 GV->
setName(
"llvm.embedded.module");
6102 assert(Old->hasZeroLiveUses() &&
6103 "llvm.cmdline can only be used once in llvm.compiler.used");
6105 Old->eraseFromParent();
6111 if (UsedArray.
empty())
6119 NewUsed->setSection(
"llvm.metadata");
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
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 writeDIProperty(raw_ostream &Out, const DIProperty *N, AsmWriterContext &WriterCtx)
static void writeDILexicalBlockFile(raw_ostream &Out, const DILexicalBlockFile *N, AsmWriterContext &WriterCtx)
static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, AsmWriterContext &)
static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, AsmWriterContext &WriterCtx)
static void writeDIExpression(raw_ostream &Out, const DIExpression *N, AsmWriterContext &WriterCtx)
static void writeDIAssignID(raw_ostream &Out, const DIAssignID *DL, AsmWriterContext &WriterCtx)
static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, AsmWriterContext &WriterCtx)
static void writeDIArgList(raw_ostream &Out, const DIArgList *N, AsmWriterContext &WriterCtx, bool FromValue=false)
static void writeDITemplateValueParameter(raw_ostream &Out, const DITemplateValueParameter *N, AsmWriterContext &WriterCtx)
static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, AsmWriterContext &WriterCtx)
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static void writeFunctionHeapProfileRecords(BitstreamWriter &Stream, FunctionSummary *FS, unsigned CallsiteAbbrev, unsigned AllocAbbrev, unsigned ContextIdAbbvId, bool PerModule, std::function< unsigned(const ValueInfo &VI)> GetValueID, std::function< unsigned(unsigned)> GetStackIndex, bool WriteContextSizeInfoIndex, DenseMap< CallStackId, LinearCallStackId > &CallStackPos, CallStackId &CallStackCount)
static unsigned serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta)
static void writeTypeIdCompatibleVtableSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdCompatibleVtableInfo &Summary, ValueEnumerator &VE)
static void getReferencedTypeIds(FunctionSummary *FS, std::set< GlobalValue::GUID > &ReferencedTypeIds)
Collect type IDs from type tests used by function.
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
static void collectMemProfCallStacks(FunctionSummary *FS, std::function< LinearFrameId(unsigned)> GetStackIndex, MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &CallStacks)
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
static unsigned getEncodedVisibility(const GlobalValue &GV)
static uint64_t getOptimizationFlags(const Value *V)
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
static cl::opt< bool > PreserveBitcodeUseListOrder("preserve-bc-uselistorder", cl::Hidden, cl::init(true), cl::desc("Preserve use-list order when writing LLVM bitcode."))
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
static DenseMap< CallStackId, LinearCallStackId > writeMemoryProfileRadixTree(MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &&CallStacks, BitstreamWriter &Stream, unsigned RadixAbbrev)
static void writeIdentificationBlock(BitstreamWriter &Stream)
Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version,...
static unsigned getEncodedCastOpcode(unsigned Opcode)
static cl::opt< uint32_t > FlushThreshold("bitcode-flush-threshold", cl::Hidden, cl::init(512), cl::desc("The threshold (unit M) for flushing LLVM bitcode."))
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
static unsigned getEncodedUnnamedAddr(const GlobalValue &GV)
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags, bool ImportAsDecl=false)
static void emitDarwinBCHeaderAndTrailer(SmallVectorImpl< char > &Buffer, const Triple &TT)
If generating a bc file on darwin, we have to emit a header and trailer to make it compatible with th...
static void writeBitcodeHeader(BitstreamWriter &Stream)
Helper to write the header common to all bitcode files.
static void writeWholeProgramDevirtResolutionByArg(SmallVector< uint64_t, 64 > &NameVals, const std::vector< uint64_t > &args, const WholeProgramDevirtResolution::ByArg &ByArg)
static void emitConstantRange(SmallVectorImpl< uint64_t > &Record, const ConstantRange &CR, bool EmitBitWidth)
static StringEncoding getStringEncoding(StringRef Str)
Determine the encoding to use for the given string name and length.
static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags)
static const char * getSectionNameForCommandline(const Triple &T)
static cl::opt< unsigned > IndexThreshold("bitcode-mdindex-threshold", cl::Hidden, cl::init(25), cl::desc("Number of metadatas above which we emit an index " "to enable lazy-loading"))
static void writeTypeIdSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdSummary &Summary)
static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, FunctionSummary *FS, Fn GetValueID)
Write the function type metadata related records that need to appear before a function summary entry ...
static uint64_t getEncodedHotnessCallEdgeInfo(const CalleeInfo &CI)
static void emitWideAPInt(SmallVectorImpl< uint64_t > &Vals, const APInt &A)
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
static unsigned getEncodedRMWOperation(const AtomicRMWInst &I)
static void writeWholeProgramDevirtResolution(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, uint64_t Id, const WholeProgramDevirtResolution &Wpd)
static unsigned getEncodedDLLStorageClass(const GlobalValue &GV)
static void writeInt32ToBuffer(uint32_t Value, SmallVectorImpl< char > &Buffer, uint32_t &Position)
static const char * getSectionNameForBitcode(const Triple &T)
static cl::opt< bool > CombinedIndexMemProfContext("combined-index-memprof-context", cl::Hidden, cl::init(true), cl::desc(""))
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
This file contains constants used for implementing Dwarf debug support.
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
static MaybeAlign getAlign(Value *Ptr)
Module.h This file contains the declarations for the Module class.
static cl::opt< LTOBitcodeEmbedding > EmbedBitcode("lto-embed-bitcode", cl::init(LTOBitcodeEmbedding::DoNotEmbed), cl::values(clEnumValN(LTOBitcodeEmbedding::DoNotEmbed, "none", "Do not embed"), clEnumValN(LTOBitcodeEmbedding::EmbedOptimized, "optimized", "Embed after all optimization passes"), clEnumValN(LTOBitcodeEmbedding::EmbedPostMergePreOptimized, "post-merge-pre-opt", "Embed post merge, but before optimizations")), cl::desc("Embed LLVM bitcode in object files produced by LTO"))
Machine Check Debug Module
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static const uint32_t IV[8]
Class for arbitrary precision integers.
unsigned getActiveWords() const
Compute the number of active words in the value of this APInt.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
int64_t getSExtValue() const
Get sign extended value.
const GlobalValueSummary & getAliasee() const
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
unsigned getAddressSpace() const
Return the address space for the allocation.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
bool empty() const
Check if the array is empty.
Class to represent array types.
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
an instruction that atomically reads a memory location, combines it with another value,...
@ USubCond
Subtract only if no unsigned overflow.
@ FMinimum
*p = minimum(old, v) minimum matches the behavior of llvm.minimum.
@ Min
*p = old <signed v ? old : v
@ USubSat
*p = usub.sat(old, v) usub.sat matches the behavior of llvm.usub.sat.
@ FMaximum
*p = maximum(old, v) maximum matches the behavior of llvm.maximum.
@ UIncWrap
Increment one up to a maximum value.
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ UMax
*p = old >unsigned v ? old : v
@ FMaximumNum
*p = maximumnum(old, v) maximumnum matches the behavior of llvm.maximumnum.
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
@ FMinimumNum
*p = minimumnum(old, v) minimumnum matches the behavior of llvm.minimumnum.
bool hasAttributes() const
Return true if attributes exists in this set.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
@ None
No attributes have been set.
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
@ EndAttrKinds
Sentinel value useful for loops.
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
LLVM_ABI void writeThinLinkBitcode(const Module &M, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the buffer specified...
LLVM_ABI void writeIndex(const ModuleSummaryIndex *Index, const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex, const GVSummaryPtrSet *DecSummaries)
LLVM_ABI void copyStrtab(StringRef Strtab)
Copy the string table for another module into this bitcode file.
LLVM_ABI void writeStrtab()
Write the bitcode file's string table.
LLVM_ABI ~BitcodeWriter()
LLVM_ABI void writeSymtab()
Attempt to write a symbol table to the bitcode file.
LLVM_ABI void writeModule(const Module &M, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the buffer specified at construction time.
LLVM_ABI BitcodeWriter(SmallVectorImpl< char > &Buffer)
Create a BitcodeWriter that writes to Buffer.
unsigned EmitAbbrev(std::shared_ptr< BitCodeAbbrev > Abbv)
Emits the abbreviation Abbv to the stream.
void markAndBlockFlushing()
For scenarios where the user wants to access a section of the stream to (for example) compute some ch...
StringRef getMarkedBufferAndResumeFlushing()
resumes flushing, but does not flush, and returns the section in the internal buffer starting from th...
void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev=0)
EmitRecord - Emit the specified record to the stream, using an abbrev if we have one to compress the ...
void Emit(uint32_t Val, unsigned NumBits)
void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals, StringRef Blob)
EmitRecordWithBlob - Emit the specified record to the stream, using an abbrev that includes a blob at...
unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr< BitCodeAbbrev > Abbv)
EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified BlockID.
void EnterBlockInfoBlock()
EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
void BackpatchWord(uint64_t BitNo, unsigned Val)
void BackpatchWord64(uint64_t BitNo, uint64_t Val)
void EnterSubblock(unsigned BlockID, unsigned CodeLen)
uint64_t GetCurrentBitNo() const
Retrieve the current position in the stream, in bits.
void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals)
EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
static LLVM_ABI BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
CallingConv::ID getCallingConv() const
Value * getCalledOperand() const
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
bool hasOperandBundles() const
Return true if this User has any operand bundles.
BasicBlock * getIndirectDest(unsigned i) const
BasicBlock * getDefaultDest() const
unsigned getNumIndirectDests() const
Return the number of callbr indirect dest labels.
bool isNoTailCall() const
bool isMustTailCall() const
auto getNamesForGUID(GlobalValue::GUID GUID) const
get the name(s) associated with a given ThinLTO GUID.
@ Largest
The linker will choose the largest COMDAT.
@ SameSize
The data referenced by the COMDAT must be the same size.
@ Any
The linker may choose any COMDAT.
@ NoDeduplicate
No deduplication is performed.
@ ExactMatch
The data referenced by the COMDAT must be the same.
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
static LLVM_ABI Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
This class represents a range of values.
const APInt & getLower() const
Return the lower value for this range.
const APInt & getUpper() const
Return the upper value for this range.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
This is an important base class in LLVM.
DebugLoc getDebugLoc() const
LLVM_ABI DIAssignID * getAssignID() const
DIExpression * getExpression() const
DILocalVariable * getVariable() const
bool isDbgDeclareValue() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
bool isDbgDeclare() const
Metadata * getRawAddress() const
DIExpression * getAddressExpression() const
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Lightweight error class with error context and mandatory checking.
Function summary information to aid decisions and implementation of importing.
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
LLVM_ABI void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
LLVM_ABI void setSection(StringRef S)
Change the section for this global.
GVFlags flags() const
Get the flags for this GlobalValue (see struct GVFlags).
StringRef modulePath() const
Get the path to the module containing this function.
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
VisibilityTypes getVisibility() const
static bool isLocalLinkage(LinkageTypes Linkage)
LinkageTypes getLinkage() const
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
ThreadLocalMode getThreadLocalMode() const
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ProtectedVisibility
The GV is protected.
UnnamedAddr getUnnamedAddr() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
DLLStorageClassTypes getDLLStorageClass() const
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalVariable.
idx_iterator idx_end() const
idx_iterator idx_begin() const
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
This class implements a map that also provides access to all stored values in a deterministic order.
size_t getBufferSize() const
const char * getBufferStart() const
const char * getBufferEnd() const
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static constexpr uint64_t BitcodeSummaryVersion
A Module instance is used to store all the information related to an LLVM module.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PointerType * getUnqual(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Digest more data.
LLVM_ABI std::array< uint8_t, 20 > result()
Return the current raw 160-bits SHA1 for the digested data since the last call to init().
size_type size() const
Determine the number of elements in the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void append(StringRef RHS)
Append from a StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
const ValueTy & getValue() const
Represent a constant reference to a string, i.e.
constexpr bool empty() const
Check if the string is empty.
constexpr size_t size() const
Get the string size.
Utility for building string tables with deduplicated suffixes.
LLVM_ABI size_t add(CachedHashStringRef S, uint8_t Priority=0)
Add a string to the builder.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isX86_FP80Ty() const
Return true if this is x86 long double.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
bool isFP128Ty() const
Return true if this is 'fp128'.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
std::vector< std::pair< const Value *, unsigned > > ValueList
unsigned getTypeID(Type *T) const
unsigned getMetadataID(const Metadata *MD) const
UseListOrderStack UseListOrders
ArrayRef< const Metadata * > getNonMDStrings() const
Get the non-MDString metadata for this block.
unsigned getInstructionID(const Instruction *I) const
unsigned getAttributeListID(AttributeList PAL) const
void incorporateFunction(const Function &F)
incorporateFunction/purgeFunction - If you'd like to deal with a function, use these two methods to g...
void getFunctionConstantRange(unsigned &Start, unsigned &End) const
getFunctionConstantRange - Return the range of values that corresponds to function-local constants.
unsigned getAttributeGroupID(IndexAndAttrSet Group) const
bool hasMDs() const
Check whether the current block has any metadata to emit.
unsigned getComdatID(const Comdat *C) const
uint64_t computeBitsRequiredForTypeIndices() const
unsigned getValueID(const Value *V) const
unsigned getMetadataOrNullID(const Metadata *MD) const
const std::vector< IndexAndAttrSet > & getAttributeGroups() const
const ValueList & getValues() const
unsigned getGlobalBasicBlockID(const BasicBlock *BB) const
getGlobalBasicBlockID - This returns the function-specific ID for the specified basic block.
void setInstructionID(const Instruction *I)
const std::vector< const BasicBlock * > & getBasicBlocks() const
const std::vector< AttributeList > & getAttributeLists() const
bool shouldPreserveUseListOrder() const
const ComdatSetType & getComdats() const
std::vector< Type * > TypeList
ArrayRef< const Metadata * > getMDStrings() const
Get the MDString metadata for this block.
std::pair< unsigned, AttributeSet > IndexAndAttrSet
Attribute groups as encoded in bitcode are almost AttributeSets, but they include the AttributeList i...
const TypeList & getTypes() const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
std::pair< iterator, bool > insert(const ValueT &V)
void build(llvm::MapVector< CallStackId, llvm::SmallVector< FrameIdTy > > &&MemProfCallStackData, const llvm::DenseMap< FrameIdTy, LinearFrameId > *MemProfFrameIndexes, llvm::DenseMap< FrameIdTy, FrameStat > &FrameHistogram)
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an std::string.
std::string & str()
Returns the string's reference.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
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
@ MODULE_CODE_ASM_PROPERTY
@ FUNC_CODE_INST_CATCHRET
@ FUNC_CODE_INST_LANDINGPAD
@ FUNC_CODE_INST_EXTRACTVAL
@ FUNC_CODE_INST_CATCHPAD
@ FUNC_CODE_INST_CATCHSWITCH
@ FUNC_CODE_INST_CLEANUPRET
@ FUNC_CODE_DEBUG_RECORD_VALUE
@ FUNC_CODE_INST_LOADATOMIC
@ FUNC_CODE_DEBUG_RECORD_ASSIGN
@ FUNC_CODE_INST_STOREATOMIC
@ FUNC_CODE_INST_ATOMICRMW
@ FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE
@ FUNC_CODE_DEBUG_LOC_AGAIN
@ FUNC_CODE_INST_EXTRACTELT
@ FUNC_CODE_INST_INDIRECTBR
@ FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE
@ FUNC_CODE_INST_INSERTVAL
@ FUNC_CODE_DECLAREBLOCKS
@ FUNC_CODE_DEBUG_RECORD_LABEL
@ FUNC_CODE_INST_INSERTELT
@ FUNC_CODE_BLOCKADDR_USERS
@ FUNC_CODE_INST_CLEANUPPAD
@ FUNC_CODE_INST_SHUFFLEVEC
@ FUNC_CODE_INST_UNREACHABLE
@ FUNC_CODE_DEBUG_RECORD_DECLARE
@ FUNC_CODE_OPERAND_BUNDLE
@ FIRST_APPLICATION_ABBREV
@ PARAMATTR_GRP_CODE_ENTRY
initializer< Ty > init(const Ty &Val)
@ DW_APPLE_ENUM_KIND_invalid
Enum kind for invalid results.
LLVM_ABI Error build(ArrayRef< Module * > Mods, SmallVector< char, 0 > &Symtab, StringTableBuilder &StrtabBuilder, BumpPtrAllocator &Alloc)
Fills in Symtab and StrtabBuilder with a valid symbol and string table for Mods.
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract_or_null(Y &&MD)
Extract a Value from Metadata, allowing null.
LLVM_ABI bool metadataIncludesAllContextSizeInfo()
Whether the alloc memeprof metadata will include context size info for all MIBs.
template LLVM_ABI llvm::DenseMap< LinearFrameId, FrameStat > computeFrameHistogram< LinearFrameId >(llvm::MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &MemProfCallStackData)
LLVM_ABI bool metadataMayIncludeContextSizeInfo()
Whether the alloc memprof metadata may include context size info for some MIBs (but possibly not all)...
NodeAddr< CodeNode * > Code
void write32le(void *P, uint32_t V)
uint32_t read32be(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
StringMapEntry< Value * > ValueName
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
LLVM_ABI void WriteBitcodeToFile(const Module &M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the specified raw output stream.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
LLVM_ABI void writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the given raw output...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
LLVM_ABI void writeIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out, const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex=nullptr, const GVSummaryPtrSet *DecSummaries=nullptr)
Write the specified module summary index to the given raw output stream, where it will be written in ...
LLVM_ABI void embedBitcodeInModule(Module &M, MemoryBufferRef Buf, bool EmbedBitcode, bool EmbedCmdline, const std::vector< uint8_t > &CmdArgs)
If EmbedBitcode is set, save a copy of the llvm IR as data in the __LLVM,__bitcode section (....
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
std::map< std::string, GVSummaryMapTy, std::less<> > ModuleToSummariesForIndexTy
Map of a module name to the GUIDs and summaries we will import from that module.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
AtomicOrdering
Atomic ordering for LLVM's memory model.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt copy(R &&Range, OutputIt Out)
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
bool isBitcode(const unsigned char *BufPtr, const unsigned char *BufEnd)
isBitcode - Return true if the given bytes are the magic bytes for LLVM IR bitcode,...
SmallPtrSet< GlobalValueSummary *, 0 > GVSummaryPtrSet
A set of global value summary pointers.
void consumeError(Error Err)
Consume a Error without doing anything.
LLVM_ABI Error write(DWPWriter &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue, Dwarf64StrOffsetsPromotion StrOffsetsOptValue, raw_pwrite_stream *OS=nullptr)
LLVM_ABI GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallVectorImpl< GlobalValue * > &Vec, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
This struct is a compact representation of a valid (non-zero power of two) alignment.
static void set(StorageType &Packed, typename Bitfield::Type Value)
Sets the typed value in the provided Packed value.
Class to accumulate and hold information about a callee.
Flags specific to function summaries.
static constexpr uint32_t RangeWidth
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
static LLVM_ABI const Target * lookupTarget(const Triple &TheTriple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
Struct that holds a reference to a particular GUID in a global value summary.
uint64_t Info
Additional information for the resolution:
enum llvm::WholeProgramDevirtResolution::ByArg::Kind TheKind
enum llvm::WholeProgramDevirtResolution::Kind TheKind
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument,...
std::string SingleImplName