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;
211 uint64_t VSTOffsetPlaceholder = 0;
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),
233 for (
const auto &GUIDSummaryLists : *Index)
235 for (
auto &Summary : GUIDSummaryLists.second.getSummaryList())
241 for (auto &CallEdge : FS->calls())
242 if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
243 assignValueId(CallEdge.first.getGUID());
249 for (auto &RefEdge : FS->refs())
250 if (!RefEdge.haveGVs() || !RefEdge.getValue())
251 assignValueId(RefEdge.getGUID());
256 void writePerModuleGlobalValueSummary();
259 void writePerModuleFunctionSummaryRecord(
260 SmallVector<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
261 unsigned ValueID,
unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
262 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
const Function &
F,
263 DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
265 void writeModuleLevelReferences(
const GlobalVariable &V,
266 SmallVector<uint64_t, 64> &NameVals,
267 unsigned FSModRefsAbbrev,
268 unsigned FSModVTableRefsAbbrev);
271 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
275 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
278 assert(VMI != GUIDToValueIdMap.end() &&
279 "GUID does not have assigned value Id");
284 unsigned getValueId(ValueInfo VI) {
285 if (!
VI.haveGVs() || !
VI.getValue())
286 return getValueId(
VI.getGUID());
290 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
294class ModuleBitcodeWriter :
public ModuleBitcodeWriterBase {
305 uint64_t BitcodeStartBit;
310 ModuleBitcodeWriter(
const Module &M, StringTableBuilder &StrtabBuilder,
311 BitstreamWriter &Stream,
bool ShouldPreserveUseListOrder,
312 const ModuleSummaryIndex *Index,
bool GenerateHash,
314 : ModuleBitcodeWriterBase(
M, StrtabBuilder, Stream,
315 ShouldPreserveUseListOrder,
Index),
316 GenerateHash(GenerateHash), ModHash(ModHash),
317 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
323 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
325 size_t addToStrtab(StringRef Str);
327 void writeAttributeGroupTable();
328 void writeAttributeTable();
329 void writeTypeTable();
331 void writeValueSymbolTableForwardDecl();
332 void writeModuleInfo();
333 void writeValueAsMetadata(
const ValueAsMetadata *MD,
334 SmallVectorImpl<uint64_t> &Record);
335 void writeMDTuple(
const MDTuple *
N, SmallVectorImpl<uint64_t> &Record,
337 unsigned createDILocationAbbrev();
338 void writeDILocation(
const DILocation *
N, SmallVectorImpl<uint64_t> &Record,
340 unsigned createGenericDINodeAbbrev();
342 SmallVectorImpl<uint64_t> &Record,
unsigned &Abbrev);
343 void writeDISubrange(
const DISubrange *
N, SmallVectorImpl<uint64_t> &Record,
346 SmallVectorImpl<uint64_t> &Record,
349 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
353 SmallVectorImpl<uint64_t> &Record,
356 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
358 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
360 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
362 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
364 SmallVectorImpl<uint64_t> &Record,
366 void writeDIFile(
const DIFile *
N, SmallVectorImpl<uint64_t> &Record,
369 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
371 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
373 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
375 SmallVectorImpl<uint64_t> &Record,
378 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
381 void writeDIMacro(
const DIMacro *
N, SmallVectorImpl<uint64_t> &Record,
385 void writeDIArgList(
const DIArgList *
N, SmallVectorImpl<uint64_t> &Record);
386 void writeDIModule(
const DIModule *
N, SmallVectorImpl<uint64_t> &Record,
388 void writeDIAssignID(
const DIAssignID *
N, SmallVectorImpl<uint64_t> &Record,
391 SmallVectorImpl<uint64_t> &Record,
394 SmallVectorImpl<uint64_t> &Record,
397 SmallVectorImpl<uint64_t> &Record,
400 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
402 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
404 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
406 SmallVectorImpl<uint64_t> &Record,
409 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
411 SmallVectorImpl<uint64_t> &Record,
413 unsigned createNamedMetadataAbbrev();
414 void writeNamedMetadata(SmallVectorImpl<uint64_t> &Record);
415 unsigned createMetadataStringsAbbrev();
417 SmallVectorImpl<uint64_t> &Record);
419 SmallVectorImpl<uint64_t> &Record,
420 std::vector<unsigned> *MDAbbrevs =
nullptr,
421 std::vector<uint64_t> *IndexPos =
nullptr);
422 void writeModuleMetadata();
423 void writeFunctionMetadata(
const Function &
F);
424 void writeFunctionMetadataAttachment(
const Function &
F);
425 void pushGlobalMetadataAttachment(SmallVectorImpl<uint64_t> &Record,
426 const GlobalObject &GO);
427 void writeModuleMetadataKinds();
428 void writeOperandBundleTags();
429 void writeSyncScopeNames();
430 void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
431 void writeModuleConstants();
432 bool pushValueAndType(
const Value *V,
unsigned InstID,
433 SmallVectorImpl<unsigned> &Vals);
434 bool pushValueOrMetadata(
const Value *V,
unsigned InstID,
435 SmallVectorImpl<unsigned> &Vals);
436 void writeOperandBundles(
const CallBase &CB,
unsigned InstID);
437 void pushValue(
const Value *V,
unsigned InstID,
438 SmallVectorImpl<unsigned> &Vals);
439 void pushValueSigned(
const Value *V,
unsigned InstID,
440 SmallVectorImpl<uint64_t> &Vals);
441 void writeInstruction(
const Instruction &
I,
unsigned InstID,
442 SmallVectorImpl<unsigned> &Vals);
443 void writeFunctionLevelValueSymbolTable(
const ValueSymbolTable &VST);
444 void writeGlobalValueSymbolTable(
445 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
446 void writeUseList(UseListOrder &&Order);
447 void writeUseListBlock(
const Function *
F);
449 writeFunction(
const Function &
F,
450 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
451 void writeBlockInfo();
452 void writeModuleHash(StringRef View);
455 return unsigned(SSID);
458 unsigned getEncodedAlign(MaybeAlign Alignment) {
return encode(Alignment); }
462class IndexBitcodeWriter :
public BitcodeWriterBase {
464 const ModuleSummaryIndex &
Index;
477 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
481 std::vector<uint64_t> StackIds;
486 DenseMap<unsigned, unsigned> StackIdIndicesToIndex;
489 unsigned GlobalValueId = 0;
493 DenseMap<StringRef, uint64_t> ModuleIdMap;
503 BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder,
504 const ModuleSummaryIndex &Index,
507 : BitcodeWriterBase(Stream, StrtabBuilder),
Index(
Index),
508 DecSummaries(DecSummaries),
509 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
513 auto RecordStackIdReference = [&](
unsigned StackIdIndex) {
518 StackIdIndicesToIndex.
insert({StackIdIndex, StackIds.size()});
520 StackIds.push_back(
Index.getStackIdAtIndex(StackIdIndex));
527 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
528 GUIDToValueIdMap[
I.first] = ++GlobalValueId;
540 for (
auto &CI :
FS->callsites()) {
551 if (CI.StackIdIndices.empty()) {
552 GUIDToValueIdMap[CI.Callee.getGUID()] = ++GlobalValueId;
555 for (
auto Idx : CI.StackIdIndices)
556 RecordStackIdReference(Idx);
559 for (
auto &AI :
FS->allocs())
560 for (
auto &MIB : AI.MIBs)
561 for (
auto Idx : MIB.StackIdIndices)
562 RecordStackIdReference(Idx);
568 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
573 template<
typename Functor>
574 void forEachSummary(Functor Callback) {
575 if (ModuleToSummariesForIndex) {
576 for (
auto &M : *ModuleToSummariesForIndex)
577 for (
auto &Summary :
M.second) {
583 Callback({AS->getAliaseeGUID(), &AS->getAliasee()},
true);
586 for (
auto &Summaries : Index)
587 for (
auto &Summary : Summaries.second.getSummaryList())
596 template <
typename Functor>
void forEachModule(Functor Callback) {
597 if (ModuleToSummariesForIndex) {
598 for (
const auto &M : *ModuleToSummariesForIndex) {
599 const auto &MPI =
Index.modulePaths().find(
M.first);
600 if (MPI ==
Index.modulePaths().end()) {
604 assert(ModuleToSummariesForIndex->size() == 1);
614 std::vector<StringRef> ModulePaths;
615 for (
auto &[ModPath,
_] :
Index.modulePaths())
616 ModulePaths.push_back(ModPath);
618 for (
auto &ModPath : ModulePaths)
627 void writeModStrings();
628 void writeCombinedGlobalValueSummary();
631 auto VMI = GUIDToValueIdMap.find(ValGUID);
632 if (VMI == GUIDToValueIdMap.end())
637 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
672 case Instruction::Add:
674 case Instruction::Sub:
676 case Instruction::Mul:
679 case Instruction::FDiv:
682 case Instruction::FRem:
760 case Attribute::Alignment:
762 case Attribute::AllocAlign:
764 case Attribute::AllocSize:
766 case Attribute::AlwaysInline:
768 case Attribute::Builtin:
770 case Attribute::ByVal:
772 case Attribute::Convergent:
774 case Attribute::InAlloca:
776 case Attribute::Cold:
778 case Attribute::DisableSanitizerInstrumentation:
780 case Attribute::FnRetThunkExtern:
782 case Attribute::Flatten:
786 case Attribute::ElementType:
788 case Attribute::HybridPatchable:
790 case Attribute::InlineHint:
792 case Attribute::InReg:
794 case Attribute::JumpTable:
796 case Attribute::MinSize:
798 case Attribute::AllocatedPointer:
800 case Attribute::AllocKind:
802 case Attribute::Memory:
804 case Attribute::NoFPClass:
806 case Attribute::Naked:
808 case Attribute::Nest:
810 case Attribute::NoAlias:
812 case Attribute::NoBuiltin:
814 case Attribute::NoCallback:
816 case Attribute::NoDivergenceSource:
818 case Attribute::NoDuplicate:
820 case Attribute::NoFree:
822 case Attribute::NoImplicitFloat:
824 case Attribute::NoInline:
826 case Attribute::NoRecurse:
828 case Attribute::NoMerge:
830 case Attribute::NonLazyBind:
832 case Attribute::NonNull:
834 case Attribute::Dereferenceable:
836 case Attribute::DereferenceableOrNull:
838 case Attribute::NoRedZone:
840 case Attribute::NoReturn:
842 case Attribute::NoSync:
844 case Attribute::NoCfCheck:
846 case Attribute::NoProfile:
848 case Attribute::SkipProfile:
850 case Attribute::NoUnwind:
852 case Attribute::NoSanitizeBounds:
854 case Attribute::NoSanitizeCoverage:
856 case Attribute::NullPointerIsValid:
858 case Attribute::OptimizeForDebugging:
860 case Attribute::OptForFuzzing:
862 case Attribute::OptimizeForSize:
864 case Attribute::OptimizeNone:
866 case Attribute::ReadNone:
868 case Attribute::ReadOnly:
870 case Attribute::Returned:
872 case Attribute::ReturnsTwice:
874 case Attribute::SExt:
876 case Attribute::Speculatable:
878 case Attribute::StackAlignment:
880 case Attribute::StackProtect:
882 case Attribute::StackProtectReq:
884 case Attribute::StackProtectStrong:
886 case Attribute::SafeStack:
888 case Attribute::ShadowCallStack:
890 case Attribute::StrictFP:
892 case Attribute::StructRet:
894 case Attribute::SanitizeAddress:
896 case Attribute::SanitizeAllocToken:
898 case Attribute::SanitizeHWAddress:
900 case Attribute::SanitizeThread:
902 case Attribute::SanitizeType:
904 case Attribute::SanitizeMemory:
906 case Attribute::SanitizeNumericalStability:
908 case Attribute::SanitizeRealtime:
910 case Attribute::SanitizeRealtimeBlocking:
912 case Attribute::SpeculativeLoadHardening:
914 case Attribute::SwiftError:
916 case Attribute::SwiftSelf:
918 case Attribute::SwiftAsync:
920 case Attribute::UWTable:
922 case Attribute::VScaleRange:
924 case Attribute::WillReturn:
926 case Attribute::WriteOnly:
928 case Attribute::ZExt:
930 case Attribute::ImmArg:
932 case Attribute::SanitizeMemTag:
934 case Attribute::Preallocated:
936 case Attribute::NoUndef:
938 case Attribute::ByRef:
940 case Attribute::MustProgress:
942 case Attribute::PresplitCoroutine:
944 case Attribute::Writable:
946 case Attribute::CoroDestroyOnlyWhenComplete:
948 case Attribute::CoroElideSafe:
950 case Attribute::DeadOnUnwind:
952 case Attribute::Range:
954 case Attribute::Initializes:
956 case Attribute::NoExt:
958 case Attribute::Captures:
960 case Attribute::DeadOnReturn:
962 case Attribute::NoCreateUndefOrPoison:
964 case Attribute::DenormalFPEnv:
966 case Attribute::NoOutline:
992 unsigned NumWords =
A.getActiveWords();
993 const uint64_t *RawData =
A.getRawData();
994 for (
unsigned i = 0; i < NumWords; i++)
1014void ModuleBitcodeWriter::writeAttributeGroupTable() {
1015 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
1017 if (AttrGrps.empty())
return;
1021 SmallVector<uint64_t, 64>
Record;
1023 unsigned AttrListIndex = Pair.first;
1024 AttributeSet AS = Pair.second;
1026 Record.push_back(AttrListIndex);
1029 if (Attr.isEnumAttribute()) {
1032 }
else if (Attr.isIntAttribute()) {
1034 Attribute::AttrKind
Kind = Attr.getKindAsEnum();
1036 if (Kind == Attribute::Memory) {
1041 Record.push_back(Attr.getValueAsInt());
1043 }
else if (Attr.isStringAttribute()) {
1044 StringRef
Kind = Attr.getKindAsString();
1045 StringRef Val = Attr.getValueAsString();
1054 }
else if (Attr.isTypeAttribute()) {
1055 Type *Ty = Attr.getValueAsType();
1056 Record.push_back(Ty ? 6 : 5);
1060 }
else if (Attr.isConstantRangeAttribute()) {
1066 assert(Attr.isConstantRangeListAttribute());
1072 for (
auto &CR : Val)
1084void ModuleBitcodeWriter::writeAttributeTable() {
1086 if (
Attrs.empty())
return;
1090 SmallVector<uint64_t, 64>
Record;
1091 for (
const AttributeList &AL : Attrs) {
1092 for (
unsigned i :
AL.indexes()) {
1093 AttributeSet AS =
AL.getAttributes(i);
1106void ModuleBitcodeWriter::writeTypeTable() {
1110 SmallVector<uint64_t, 64> TypeVals;
1115 auto Abbv = std::make_shared<BitCodeAbbrev>();
1117 Abbv->Add(BitCodeAbbrevOp(0));
1118 unsigned OpaquePtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1121 Abbv = std::make_shared<BitCodeAbbrev>();
1126 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1129 Abbv = std::make_shared<BitCodeAbbrev>();
1134 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1137 Abbv = std::make_shared<BitCodeAbbrev>();
1141 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1144 Abbv = std::make_shared<BitCodeAbbrev>();
1149 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1152 Abbv = std::make_shared<BitCodeAbbrev>();
1156 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1164 for (
Type *
T : TypeList) {
1165 int AbbrevToUse = 0;
1168 switch (
T->getTypeID()) {
1178 case Type::MetadataTyID:
1183 case Type::ByteTyID:
1188 case Type::IntegerTyID:
1193 case Type::PointerTyID: {
1200 AbbrevToUse = OpaquePtrAbbrev;
1203 case Type::FunctionTyID: {
1209 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1211 AbbrevToUse = FunctionAbbrev;
1214 case Type::StructTyID: {
1219 for (
Type *ET :
ST->elements())
1222 if (
ST->isLiteral()) {
1224 AbbrevToUse = StructAnonAbbrev;
1226 if (
ST->isOpaque()) {
1230 AbbrevToUse = StructNamedAbbrev;
1234 if (!
ST->getName().empty())
1240 case Type::ArrayTyID: {
1244 TypeVals.
push_back(AT->getNumElements());
1246 AbbrevToUse = ArrayAbbrev;
1249 case Type::FixedVectorTyID:
1250 case Type::ScalableVectorTyID: {
1255 TypeVals.
push_back(VT->getElementCount().getKnownMinValue());
1261 case Type::TargetExtTyID: {
1267 for (
Type *InnerTy :
TET->type_params())
1272 case Type::TypedPointerTyID:
1277 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
1318 RawFlags |= Flags.ReadNone;
1319 RawFlags |= (Flags.ReadOnly << 1);
1320 RawFlags |= (Flags.NoRecurse << 2);
1321 RawFlags |= (Flags.ReturnDoesNotAlias << 3);
1322 RawFlags |= (Flags.NoInline << 4);
1323 RawFlags |= (Flags.AlwaysInline << 5);
1324 RawFlags |= (Flags.NoUnwind << 6);
1325 RawFlags |= (Flags.MayThrow << 7);
1326 RawFlags |= (Flags.HasUnknownCall << 8);
1327 RawFlags |= (Flags.MustBeUnreachable << 9);
1334 bool ImportAsDecl =
false) {
1337 RawFlags |= Flags.NotEligibleToImport;
1338 RawFlags |= (Flags.Live << 1);
1339 RawFlags |= (Flags.DSOLocal << 2);
1340 RawFlags |= (Flags.CanAutoHide << 3);
1345 RawFlags = (RawFlags << 4) | Flags.Linkage;
1347 RawFlags |= (Flags.Visibility << 8);
1349 unsigned ImportType = Flags.ImportType | ImportAsDecl;
1350 RawFlags |= (ImportType << 10);
1352 RawFlags |= (Flags.NoRenameOnPromotion << 11);
1358 uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1359 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1402 switch (
C.getSelectionKind()) {
1426size_t ModuleBitcodeWriter::addToStrtab(StringRef Str) {
1429 return StrtabBuilder.
add(Str);
1432void ModuleBitcodeWriter::writeComdats() {
1447void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1452 auto Abbv = std::make_shared<BitCodeAbbrev>();
1458 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1474 bool isChar6 =
true;
1475 for (
char C : Str) {
1478 if ((
unsigned char)
C & 128)
1487static_assert(
sizeof(GlobalValue::SanitizerMetadata) <=
sizeof(unsigned),
1488 "Sanitizer Metadata is too large for naive serialization.");
1491 return Meta.NoAddress | (
Meta.NoHWAddress << 1) |
1492 (
Meta.Memtag << 2) | (
Meta.IsDynInit << 3);
1498void ModuleBitcodeWriter::writeModuleInfo() {
1500 if (!
M.getTargetTriple().empty())
1502 M.getTargetTriple().str(), 0 );
1503 const std::string &
DL =
M.getDataLayoutStr();
1506 if (!
M.getModuleInlineAsm().empty())
1512 std::map<std::string, unsigned> SectionMap;
1513 std::map<std::string, unsigned> GCMap;
1514 MaybeAlign MaxGVarAlignment;
1515 unsigned MaxGlobalType = 0;
1516 for (
const GlobalVariable &GV :
M.globals()) {
1517 if (MaybeAlign
A = GV.getAlign())
1518 MaxGVarAlignment = !MaxGVarAlignment ? *
A : std::max(*MaxGVarAlignment, *
A);
1519 MaxGlobalType = std::max(MaxGlobalType, VE.
getTypeID(GV.getValueType()));
1520 if (GV.hasSection()) {
1522 unsigned &
Entry = SectionMap[std::string(GV.getSection())];
1526 Entry = SectionMap.size();
1530 for (
const Function &
F : M) {
1531 if (
F.hasSection()) {
1533 unsigned &
Entry = SectionMap[std::string(
F.getSection())];
1537 Entry = SectionMap.size();
1542 unsigned &
Entry = GCMap[
F.getGC()];
1546 Entry = GCMap.size();
1552 unsigned SimpleGVarAbbrev = 0;
1553 if (!
M.global_empty()) {
1555 auto Abbv = std::make_shared<BitCodeAbbrev>();
1566 if (!MaxGVarAlignment)
1567 Abbv->Add(BitCodeAbbrevOp(0));
1569 unsigned MaxEncAlignment = getEncodedAlign(MaxGVarAlignment);
1573 if (SectionMap.empty())
1574 Abbv->Add(BitCodeAbbrevOp(0));
1579 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1593 auto Abbv = std::make_shared<BitCodeAbbrev>();
1596 Abbv->Add(AbbrevOpToUse);
1597 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1599 for (
const auto P :
M.getSourceFileName())
1608 for (
const GlobalVariable &GV :
M.globals()) {
1609 unsigned AbbrevToUse = 0;
1615 Vals.
push_back(addToStrtab(GV.getName()));
1618 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1622 Vals.
push_back(getEncodedAlign(GV.getAlign()));
1623 Vals.
push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1625 if (GV.isThreadLocal() ||
1627 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1628 GV.isExternallyInitialized() ||
1630 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1631 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1635 Vals.
push_back(GV.isExternallyInitialized());
1639 auto AL = GV.getAttributesAsList(AttributeList::FunctionIndex);
1643 Vals.
push_back(addToStrtab(GV.getPartition()));
1644 Vals.
push_back(GV.getPartition().size());
1647 GV.getSanitizerMetadata())
1651 AbbrevToUse = SimpleGVarAbbrev;
1659 for (
const Function &
F : M) {
1672 Vals.
push_back(getEncodedAlign(
F.getAlign()));
1673 Vals.
push_back(
F.hasSection() ? SectionMap[std::string(
F.getSection())]
1685 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1689 Vals.
push_back(addToStrtab(
F.getPartition()));
1691 Vals.
push_back(getEncodedAlign(
F.getPreferredAlignment()));
1693 unsigned AbbrevToUse = 0;
1699 for (
const GlobalAlias &
A :
M.aliases()) {
1706 Vals.
push_back(
A.getType()->getAddressSpace());
1714 Vals.
push_back(addToStrtab(
A.getPartition()));
1717 unsigned AbbrevToUse = 0;
1723 for (
const GlobalIFunc &
I :
M.ifuncs()) {
1729 Vals.
push_back(
I.getType()->getAddressSpace());
1734 Vals.
push_back(addToStrtab(
I.getPartition()));
1740 writeValueSymbolTableForwardDecl();
1747 if (OBO->hasNoSignedWrap())
1749 if (OBO->hasNoUnsignedWrap())
1755 if (PDI->isDisjoint())
1758 if (FPMO->hasAllowReassoc())
1760 if (FPMO->hasNoNaNs())
1762 if (FPMO->hasNoInfs())
1764 if (FPMO->hasNoSignedZeros())
1766 if (FPMO->hasAllowReciprocal())
1768 if (FPMO->hasAllowContract())
1770 if (FPMO->hasApproxFunc())
1773 if (NNI->hasNonNeg())
1776 if (TI->hasNoSignedWrap())
1778 if (TI->hasNoUnsignedWrap())
1781 if (
GEP->isInBounds())
1783 if (
GEP->hasNoUnsignedSignedWrap())
1785 if (
GEP->hasNoUnsignedWrap())
1788 if (ICmp->hasSameSign())
1795void ModuleBitcodeWriter::writeValueAsMetadata(
1796 const ValueAsMetadata *MD, SmallVectorImpl<uint64_t> &Record) {
1805void ModuleBitcodeWriter::writeMDTuple(
const MDTuple *
N,
1806 SmallVectorImpl<uint64_t> &Record,
1808 for (
const MDOperand &MDO :
N->operands()) {
1811 "Unexpected function-local metadata");
1820unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1823 auto Abbv = std::make_shared<BitCodeAbbrev>();
1836void ModuleBitcodeWriter::writeDILocation(
const DILocation *
N,
1837 SmallVectorImpl<uint64_t> &Record,
1840 Abbrev = createDILocationAbbrev();
1842 Record.push_back(
N->isDistinct());
1843 Record.push_back(
N->getLine());
1844 Record.push_back(
N->getColumn());
1847 Record.push_back(
N->isImplicitCode());
1848 Record.push_back(
N->getAtomGroup());
1849 Record.push_back(
N->getAtomRank());
1854unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1857 auto Abbv = std::make_shared<BitCodeAbbrev>();
1868void ModuleBitcodeWriter::writeGenericDINode(
const GenericDINode *
N,
1869 SmallVectorImpl<uint64_t> &Record,
1872 Abbrev = createGenericDINodeAbbrev();
1874 Record.push_back(
N->isDistinct());
1875 Record.push_back(
N->getTag());
1878 for (
auto &
I :
N->operands())
1885void ModuleBitcodeWriter::writeDISubrange(
const DISubrange *
N,
1886 SmallVectorImpl<uint64_t> &Record,
1888 const uint64_t
Version = 2 << 1;
1899void ModuleBitcodeWriter::writeDIGenericSubrange(
1900 const DIGenericSubrange *
N, SmallVectorImpl<uint64_t> &Record,
1902 Record.push_back((uint64_t)
N->isDistinct());
1912void ModuleBitcodeWriter::writeDIEnumerator(
const DIEnumerator *
N,
1913 SmallVectorImpl<uint64_t> &Record,
1915 const uint64_t IsBigInt = 1 << 2;
1916 Record.push_back(IsBigInt | (
N->isUnsigned() << 1) |
N->isDistinct());
1917 Record.push_back(
N->getValue().getBitWidth());
1925void ModuleBitcodeWriter::writeDIBasicType(
const DIBasicType *
N,
1926 SmallVectorImpl<uint64_t> &Record,
1928 const unsigned SizeIsMetadata = 0x2;
1929 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1930 Record.push_back(
N->getTag());
1933 Record.push_back(
N->getAlignInBits());
1934 Record.push_back(
N->getEncoding());
1935 Record.push_back(
N->getFlags());
1936 Record.push_back(
N->getNumExtraInhabitants());
1937 Record.push_back(
N->getDataSizeInBits());
1943void ModuleBitcodeWriter::writeDIFixedPointType(
1944 const DIFixedPointType *
N, SmallVectorImpl<uint64_t> &Record,
1946 const unsigned SizeIsMetadata = 0x2;
1947 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1948 Record.push_back(
N->getTag());
1951 Record.push_back(
N->getAlignInBits());
1952 Record.push_back(
N->getEncoding());
1953 Record.push_back(
N->getFlags());
1954 Record.push_back(
N->getKind());
1955 Record.push_back(
N->getFactorRaw());
1957 auto WriteWideInt = [&](
const APInt &
Value) {
1960 uint64_t NumWords =
Value.getActiveWords();
1961 uint64_t
Encoded = (NumWords << 32) |
Value.getBitWidth();
1962 Record.push_back(Encoded);
1966 WriteWideInt(
N->getNumeratorRaw());
1967 WriteWideInt(
N->getDenominatorRaw());
1973void ModuleBitcodeWriter::writeDIStringType(
const DIStringType *
N,
1974 SmallVectorImpl<uint64_t> &Record,
1976 const unsigned SizeIsMetadata = 0x2;
1977 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1978 Record.push_back(
N->getTag());
1984 Record.push_back(
N->getAlignInBits());
1985 Record.push_back(
N->getEncoding());
1991void ModuleBitcodeWriter::writeDIDerivedType(
const DIDerivedType *
N,
1992 SmallVectorImpl<uint64_t> &Record,
1994 const unsigned SizeIsMetadata = 0x2;
1995 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1996 Record.push_back(
N->getTag());
1999 Record.push_back(
N->getLine());
2003 Record.push_back(
N->getAlignInBits());
2005 Record.push_back(
N->getFlags());
2010 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
2011 Record.push_back(*DWARFAddressSpace + 1);
2017 if (
auto PtrAuthData =
N->getPtrAuthData())
2018 Record.push_back(PtrAuthData->RawData);
2026void ModuleBitcodeWriter::writeDISubrangeType(
const DISubrangeType *
N,
2027 SmallVectorImpl<uint64_t> &Record,
2029 const unsigned SizeIsMetadata = 0x2;
2030 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2033 Record.push_back(
N->getLine());
2036 Record.push_back(
N->getAlignInBits());
2037 Record.push_back(
N->getFlags());
2048void ModuleBitcodeWriter::writeDICompositeType(
2049 const DICompositeType *
N, SmallVectorImpl<uint64_t> &Record,
2051 const unsigned IsNotUsedInOldTypeRef = 0x2;
2052 const unsigned SizeIsMetadata = 0x4;
2053 Record.push_back(SizeIsMetadata | IsNotUsedInOldTypeRef |
2054 (
unsigned)
N->isDistinct());
2055 Record.push_back(
N->getTag());
2058 Record.push_back(
N->getLine());
2062 Record.push_back(
N->getAlignInBits());
2064 Record.push_back(
N->getFlags());
2066 Record.push_back(
N->getRuntimeLang());
2076 Record.push_back(
N->getNumExtraInhabitants());
2086void ModuleBitcodeWriter::writeDISubroutineType(
2087 const DISubroutineType *
N, SmallVectorImpl<uint64_t> &Record,
2089 const unsigned HasNoOldTypeRefs = 0x2;
2090 Record.push_back(HasNoOldTypeRefs | (
unsigned)
N->isDistinct());
2091 Record.push_back(
N->getFlags());
2099void ModuleBitcodeWriter::writeDIFile(
const DIFile *
N,
2100 SmallVectorImpl<uint64_t> &Record,
2102 Record.push_back(
N->isDistinct());
2105 if (
N->getRawChecksum()) {
2106 Record.push_back(
N->getRawChecksum()->Kind);
2114 auto Source =
N->getRawSource();
2122void ModuleBitcodeWriter::writeDICompileUnit(
const DICompileUnit *
N,
2123 SmallVectorImpl<uint64_t> &Record,
2125 assert(
N->isDistinct() &&
"Expected distinct compile units");
2128 auto Lang =
N->getSourceLanguage();
2129 Record.push_back(Lang.getName());
2132 if (Lang.hasVersionedName())
2133 Record.back() ^= (uint64_t(1) << 63);
2137 Record.push_back(
N->isOptimized());
2139 Record.push_back(
N->getRuntimeVersion());
2141 Record.push_back(
N->getEmissionKind());
2147 Record.push_back(
N->getDWOId());
2149 Record.push_back(
N->getSplitDebugInlining());
2150 Record.push_back(
N->getDebugInfoForProfiling());
2151 Record.push_back((
unsigned)
N->getNameTableKind());
2152 Record.push_back(
N->getRangesBaseAddress());
2155 Record.push_back(Lang.hasVersionedName() ? Lang.getVersion() : 0);
2161void ModuleBitcodeWriter::writeDISubprogram(
const DISubprogram *
N,
2162 SmallVectorImpl<uint64_t> &Record,
2164 const uint64_t HasUnitFlag = 1 << 1;
2165 const uint64_t HasSPFlagsFlag = 1 << 2;
2166 Record.push_back(uint64_t(
N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
2171 Record.push_back(
N->getLine());
2173 Record.push_back(
N->getScopeLine());
2175 Record.push_back(
N->getSPFlags());
2176 Record.push_back(
N->getVirtualIndex());
2177 Record.push_back(
N->getFlags());
2182 Record.push_back(
N->getThisAdjustment());
2186 Record.push_back(
N->getKeyInstructionsEnabled());
2192void ModuleBitcodeWriter::writeDILexicalBlock(
const DILexicalBlock *
N,
2193 SmallVectorImpl<uint64_t> &Record,
2195 Record.push_back(
N->isDistinct());
2198 Record.push_back(
N->getLine());
2199 Record.push_back(
N->getColumn());
2205void ModuleBitcodeWriter::writeDILexicalBlockFile(
2206 const DILexicalBlockFile *
N, SmallVectorImpl<uint64_t> &Record,
2208 Record.push_back(
N->isDistinct());
2211 Record.push_back(
N->getDiscriminator());
2217void ModuleBitcodeWriter::writeDICommonBlock(
const DICommonBlock *
N,
2218 SmallVectorImpl<uint64_t> &Record,
2220 Record.push_back(
N->isDistinct());
2225 Record.push_back(
N->getLineNo());
2231void ModuleBitcodeWriter::writeDINamespace(
const DINamespace *
N,
2232 SmallVectorImpl<uint64_t> &Record,
2234 Record.push_back(
N->isDistinct() |
N->getExportSymbols() << 1);
2242void ModuleBitcodeWriter::writeDIMacro(
const DIMacro *
N,
2243 SmallVectorImpl<uint64_t> &Record,
2245 Record.push_back(
N->isDistinct());
2246 Record.push_back(
N->getMacinfoType());
2247 Record.push_back(
N->getLine());
2255void ModuleBitcodeWriter::writeDIMacroFile(
const DIMacroFile *
N,
2256 SmallVectorImpl<uint64_t> &Record,
2258 Record.push_back(
N->isDistinct());
2259 Record.push_back(
N->getMacinfoType());
2260 Record.push_back(
N->getLine());
2268void ModuleBitcodeWriter::writeDIArgList(
const DIArgList *
N,
2269 SmallVectorImpl<uint64_t> &Record) {
2270 Record.reserve(
N->getArgs().size());
2271 for (ValueAsMetadata *MD :
N->getArgs())
2278void ModuleBitcodeWriter::writeDIModule(
const DIModule *
N,
2279 SmallVectorImpl<uint64_t> &Record,
2281 Record.push_back(
N->isDistinct());
2282 for (
auto &
I :
N->operands())
2284 Record.push_back(
N->getLineNo());
2285 Record.push_back(
N->getIsDecl());
2291void ModuleBitcodeWriter::writeDIAssignID(
const DIAssignID *
N,
2292 SmallVectorImpl<uint64_t> &Record,
2295 Record.push_back(
N->isDistinct());
2300void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2301 const DITemplateTypeParameter *
N, SmallVectorImpl<uint64_t> &Record,
2303 Record.push_back(
N->isDistinct());
2306 Record.push_back(
N->isDefault());
2312void ModuleBitcodeWriter::writeDITemplateValueParameter(
2313 const DITemplateValueParameter *
N, SmallVectorImpl<uint64_t> &Record,
2315 Record.push_back(
N->isDistinct());
2316 Record.push_back(
N->getTag());
2319 Record.push_back(
N->isDefault());
2326void ModuleBitcodeWriter::writeDIGlobalVariable(
2327 const DIGlobalVariable *
N, SmallVectorImpl<uint64_t> &Record,
2329 const uint64_t
Version = 2 << 1;
2335 Record.push_back(
N->getLine());
2337 Record.push_back(
N->isLocalToUnit());
2338 Record.push_back(
N->isDefinition());
2341 Record.push_back(
N->getAlignInBits());
2348void ModuleBitcodeWriter::writeDILocalVariable(
2349 const DILocalVariable *
N, SmallVectorImpl<uint64_t> &Record,
2364 const uint64_t HasAlignmentFlag = 1 << 1;
2365 Record.push_back((uint64_t)
N->isDistinct() | HasAlignmentFlag);
2369 Record.push_back(
N->getLine());
2371 Record.push_back(
N->getArg());
2372 Record.push_back(
N->getFlags());
2373 Record.push_back(
N->getAlignInBits());
2380void ModuleBitcodeWriter::writeDILabel(
2381 const DILabel *
N, SmallVectorImpl<uint64_t> &Record,
2383 uint64_t IsArtificialFlag = uint64_t(
N->isArtificial()) << 1;
2384 Record.push_back((uint64_t)
N->isDistinct() | IsArtificialFlag);
2388 Record.push_back(
N->getLine());
2389 Record.push_back(
N->getColumn());
2390 Record.push_back(
N->getCoroSuspendIdx().has_value()
2391 ? (uint64_t)
N->getCoroSuspendIdx().value()
2392 : std::numeric_limits<uint64_t>::max());
2398void ModuleBitcodeWriter::writeDIExpression(
const DIExpression *
N,
2399 SmallVectorImpl<uint64_t> &Record,
2401 Record.reserve(
N->getElements().size() + 1);
2402 const uint64_t
Version = 3 << 1;
2404 Record.append(
N->elements_begin(),
N->elements_end());
2410void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2411 const DIGlobalVariableExpression *
N, SmallVectorImpl<uint64_t> &Record,
2413 Record.push_back(
N->isDistinct());
2421void ModuleBitcodeWriter::writeDIObjCProperty(
const DIObjCProperty *
N,
2422 SmallVectorImpl<uint64_t> &Record,
2424 Record.push_back(
N->isDistinct());
2427 Record.push_back(
N->getLine());
2430 Record.push_back(
N->getAttributes());
2437void ModuleBitcodeWriter::writeDIImportedEntity(
2438 const DIImportedEntity *
N, SmallVectorImpl<uint64_t> &Record,
2440 Record.push_back(
N->isDistinct());
2441 Record.push_back(
N->getTag());
2444 Record.push_back(
N->getLine());
2453unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2454 auto Abbv = std::make_shared<BitCodeAbbrev>();
2461void ModuleBitcodeWriter::writeNamedMetadata(
2462 SmallVectorImpl<uint64_t> &Record) {
2463 if (
M.named_metadata_empty())
2466 unsigned Abbrev = createNamedMetadataAbbrev();
2467 for (
const NamedMDNode &NMD :
M.named_metadata()) {
2469 StringRef Str = NMD.getName();
2470 Record.append(Str.bytes_begin(), Str.bytes_end());
2475 for (
const MDNode *
N : NMD.operands())
2482unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2483 auto Abbv = std::make_shared<BitCodeAbbrev>();
2495void ModuleBitcodeWriter::writeMetadataStrings(
2497 if (Strings.
empty())
2505 SmallString<256> Blob;
2507 BitstreamWriter
W(Blob);
2527#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
2528#include "llvm/IR/Metadata.def"
2532void ModuleBitcodeWriter::writeMetadataRecords(
2534 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2539#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
2540#include "llvm/IR/Metadata.def"
2546 assert(
N->isResolved() &&
"Expected forward references to be resolved");
2548 switch (
N->getMetadataID()) {
2551#define HANDLE_MDNODE_LEAF(CLASS) \
2552 case Metadata::CLASS##Kind: \
2554 write##CLASS(cast<CLASS>(N), Record, \
2555 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
2557 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
2559#include "llvm/IR/Metadata.def"
2570void ModuleBitcodeWriter::writeModuleMetadata() {
2571 if (!VE.
hasMDs() &&
M.named_metadata_empty())
2575 SmallVector<uint64_t, 64>
Record;
2579 std::vector<unsigned> MDAbbrevs;
2582 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2583 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2584 createGenericDINodeAbbrev();
2586 auto Abbv = std::make_shared<BitCodeAbbrev>();
2590 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2592 Abbv = std::make_shared<BitCodeAbbrev>();
2596 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2608 uint64_t Vals[] = {0, 0};
2618 std::vector<uint64_t> IndexPos;
2622 writeMetadataRecords(VE.
getNonMDStrings(), Record, &MDAbbrevs, &IndexPos);
2633 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2634 for (
auto &Elt : IndexPos) {
2635 auto EltDelta = Elt - PreviousValue;
2636 PreviousValue = Elt;
2645 writeNamedMetadata(Record);
2647 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2648 SmallVector<uint64_t, 4>
Record;
2650 pushGlobalMetadataAttachment(Record, GO);
2653 for (
const Function &
F : M)
2654 if (
F.isDeclaration() &&
F.hasMetadata())
2655 AddDeclAttachedMetadata(
F);
2656 for (
const GlobalIFunc &GI :
M.ifuncs())
2657 if (GI.hasMetadata())
2658 AddDeclAttachedMetadata(GI);
2661 for (
const GlobalVariable &GV :
M.globals())
2662 if (GV.hasMetadata())
2663 AddDeclAttachedMetadata(GV);
2668void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2673 SmallVector<uint64_t, 64>
Record;
2679void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2680 SmallVectorImpl<uint64_t> &Record,
const GlobalObject &GO) {
2684 for (
const auto &
I : MDs) {
2690void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &
F) {
2693 SmallVector<uint64_t, 64>
Record;
2695 if (
F.hasMetadata()) {
2696 pushGlobalMetadataAttachment(Record,
F);
2704 for (
const BasicBlock &BB :
F)
2705 for (
const Instruction &
I : BB) {
2707 I.getAllMetadataOtherThanDebugLoc(MDs);
2710 if (MDs.
empty())
continue;
2714 for (
const auto &[
ID, MD] : MDs) {
2725void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2726 SmallVector<uint64_t, 64>
Record;
2731 M.getMDKindNames(Names);
2733 if (Names.
empty())
return;
2737 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2738 Record.push_back(MDKindID);
2739 StringRef KName = Names[MDKindID];
2749void ModuleBitcodeWriter::writeOperandBundleTags() {
2757 M.getOperandBundleTags(Tags);
2764 SmallVector<uint64_t, 64>
Record;
2766 for (
auto Tag : Tags) {
2776void ModuleBitcodeWriter::writeSyncScopeNames() {
2778 M.getContext().getSyncScopeNames(SSNs);
2784 SmallVector<uint64_t, 64>
Record;
2785 for (
auto SSN : SSNs) {
2786 Record.append(SSN.begin(), SSN.end());
2794void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2796 if (FirstVal == LastVal)
return;
2800 unsigned AggregateAbbrev = 0;
2801 unsigned String8Abbrev = 0;
2802 unsigned CString7Abbrev = 0;
2803 unsigned CString6Abbrev = 0;
2807 auto Abbv = std::make_shared<BitCodeAbbrev>();
2811 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2814 Abbv = std::make_shared<BitCodeAbbrev>();
2818 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2820 Abbv = std::make_shared<BitCodeAbbrev>();
2824 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2826 Abbv = std::make_shared<BitCodeAbbrev>();
2830 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2833 SmallVector<uint64_t, 64>
Record;
2836 Type *LastTy =
nullptr;
2837 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2838 const Value *
V = Vals[i].first;
2840 if (
V->getType() != LastTy) {
2841 LastTy =
V->getType();
2844 CONSTANTS_SETTYPE_ABBREV);
2851 unsigned(
IA->hasSideEffects()) |
unsigned(
IA->isAlignStack()) << 1 |
2852 unsigned(
IA->getDialect() & 1) << 2 |
unsigned(
IA->canThrow()) << 3);
2855 StringRef AsmStr =
IA->getAsmString();
2860 StringRef ConstraintStr =
IA->getConstraintString();
2868 unsigned Code = -1U;
2869 unsigned AbbrevToUse = 0;
2870 if (
C->isNullValue()) {
2877 if (
IV->getBitWidth() <= 64) {
2878 uint64_t
V =
IV->getSExtValue();
2881 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2887 if (BV->getBitWidth() <= 64) {
2888 uint64_t
V = BV->getSExtValue();
2891 AbbrevToUse = CONSTANTS_BYTE_ABBREV;
2901 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2905 APInt api = CFP->getValueAPF().bitcastToAPInt();
2907 Record.push_back((p[1] << 48) | (p[0] >> 16));
2908 Record.push_back(p[0] & 0xffffLL);
2910 APInt api = CFP->getValueAPF().bitcastToAPInt();
2915 assert(0 &&
"Unknown FP type!");
2921 uint64_t NumElts = Str->getNumElements();
2923 if (Str->isCString()) {
2928 AbbrevToUse = String8Abbrev;
2932 for (uint64_t i = 0; i != NumElts; ++i) {
2933 unsigned char V = Str->getElementAsInteger(i);
2935 isCStr7 &= (
V & 128) == 0;
2941 AbbrevToUse = CString6Abbrev;
2943 AbbrevToUse = CString7Abbrev;
2944 }
else if (
const ConstantDataSequential *CDS =
2947 Type *EltTy = CDS->getElementType();
2949 for (uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
2950 Record.push_back(CDS->getElementAsInteger(i));
2952 for (uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
2954 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2958 for (
const Value *
Op :
C->operands())
2960 AbbrevToUse = AggregateAbbrev;
2962 switch (
CE->getOpcode()) {
2969 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2971 assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2981 case Instruction::FNeg: {
2982 assert(
CE->getNumOperands() == 1 &&
"Unknown constant expr!");
2991 case Instruction::GetElementPtr: {
2996 if (std::optional<ConstantRange>
Range = GO->getInRange()) {
3000 for (
const Value *
Op :
CE->operands()) {
3006 case Instruction::ExtractElement:
3013 case Instruction::InsertElement:
3020 case Instruction::ShuffleVector:
3025 if (
C->getType() ==
C->getOperand(0)->getType()) {
3062 Stream.
EmitRecord(Code, Record, AbbrevToUse);
3069void ModuleBitcodeWriter::writeModuleConstants() {
3074 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
3076 writeConstants(i, Vals.size(),
true);
3090bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
3091 SmallVectorImpl<unsigned> &Vals) {
3095 if (ValID >= InstID) {
3102bool ModuleBitcodeWriter::pushValueOrMetadata(
const Value *V,
unsigned InstID,
3103 SmallVectorImpl<unsigned> &Vals) {
3104 bool IsMetadata =
V->getType()->isMetadataTy();
3112 return pushValueAndType(V, InstID, Vals);
3115void ModuleBitcodeWriter::writeOperandBundles(
const CallBase &CS,
3122 Record.push_back(
C.getOperandBundleTagID(Bundle.getTagName()));
3124 for (
auto &Input : Bundle.Inputs)
3125 pushValueOrMetadata(Input, InstID, Record);
3134void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
3135 SmallVectorImpl<unsigned> &Vals) {
3140void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
3141 SmallVectorImpl<uint64_t> &Vals) {
3143 int64_t diff = ((int32_t)InstID - (int32_t)ValID);
3148void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
3150 SmallVectorImpl<unsigned> &Vals) {
3152 unsigned AbbrevToUse = 0;
3154 switch (
I.getOpcode()) {
3158 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3159 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
3164 if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
3165 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
3171 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3172 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
3173 pushValue(
I.getOperand(1), InstID, Vals);
3177 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
3178 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
3183 case Instruction::FNeg: {
3185 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3186 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
3190 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
3191 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
3196 case Instruction::GetElementPtr: {
3198 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
3202 for (
const Value *
Op :
I.operands())
3203 pushValueAndType(
Op, InstID, Vals);
3206 case Instruction::ExtractValue: {
3208 pushValueAndType(
I.getOperand(0), InstID, Vals);
3213 case Instruction::InsertValue: {
3215 pushValueAndType(
I.getOperand(0), InstID, Vals);
3216 pushValueAndType(
I.getOperand(1), InstID, Vals);
3221 case Instruction::Select: {
3223 pushValueAndType(
I.getOperand(1), InstID, Vals);
3224 pushValue(
I.getOperand(2), InstID, Vals);
3225 pushValueAndType(
I.getOperand(0), InstID, Vals);
3231 case Instruction::ExtractElement:
3233 pushValueAndType(
I.getOperand(0), InstID, Vals);
3234 pushValueAndType(
I.getOperand(1), InstID, Vals);
3236 case Instruction::InsertElement:
3238 pushValueAndType(
I.getOperand(0), InstID, Vals);
3239 pushValue(
I.getOperand(1), InstID, Vals);
3240 pushValueAndType(
I.getOperand(2), InstID, Vals);
3242 case Instruction::ShuffleVector:
3244 pushValueAndType(
I.getOperand(0), InstID, Vals);
3245 pushValue(
I.getOperand(1), InstID, Vals);
3249 case Instruction::ICmp:
3250 case Instruction::FCmp: {
3253 AbbrevToUse = FUNCTION_INST_CMP_ABBREV;
3254 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3256 pushValue(
I.getOperand(1), InstID, Vals);
3262 AbbrevToUse = FUNCTION_INST_CMP_FLAGS_ABBREV;
3267 case Instruction::Ret:
3270 unsigned NumOperands =
I.getNumOperands();
3271 if (NumOperands == 0)
3272 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
3273 else if (NumOperands == 1) {
3274 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3275 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
3277 for (
const Value *
Op :
I.operands())
3278 pushValueAndType(
Op, InstID, Vals);
3282 case Instruction::UncondBr: {
3284 AbbrevToUse = FUNCTION_INST_BR_UNCOND_ABBREV;
3288 case Instruction::CondBr: {
3290 AbbrevToUse = FUNCTION_INST_BR_COND_ABBREV;
3294 pushValue(
II.getCondition(), InstID, Vals);
3296 case Instruction::Switch:
3301 pushValue(
SI.getCondition(), InstID, Vals);
3303 for (
auto Case :
SI.cases()) {
3309 case Instruction::IndirectBr:
3313 pushValue(
I.getOperand(0), InstID, Vals);
3318 case Instruction::Invoke: {
3321 FunctionType *FTy =
II->getFunctionType();
3323 if (
II->hasOperandBundles())
3324 writeOperandBundles(*
II, InstID);
3333 pushValueAndType(Callee, InstID, Vals);
3336 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3337 pushValue(
I.getOperand(i), InstID, Vals);
3340 if (FTy->isVarArg()) {
3341 for (
unsigned i = FTy->getNumParams(), e =
II->arg_size(); i != e; ++i)
3342 pushValueAndType(
I.getOperand(i), InstID, Vals);
3346 case Instruction::Resume:
3348 pushValueAndType(
I.getOperand(0), InstID, Vals);
3350 case Instruction::CleanupRet: {
3353 pushValue(CRI.getCleanupPad(), InstID, Vals);
3354 if (CRI.hasUnwindDest())
3358 case Instruction::CatchRet: {
3361 pushValue(CRI.getCatchPad(), InstID, Vals);
3365 case Instruction::CleanupPad:
3366 case Instruction::CatchPad: {
3370 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3372 unsigned NumArgOperands = FuncletPad.arg_size();
3374 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
3375 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
3378 case Instruction::CatchSwitch: {
3382 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3384 unsigned NumHandlers = CatchSwitch.getNumHandlers();
3386 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
3389 if (CatchSwitch.hasUnwindDest())
3393 case Instruction::CallBr: {
3399 writeOperandBundles(*CBI, InstID);
3414 pushValueAndType(Callee, InstID, Vals);
3417 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3418 pushValue(
I.getOperand(i), InstID, Vals);
3421 if (FTy->isVarArg()) {
3422 for (
unsigned i = FTy->getNumParams(), e = CBI->
arg_size(); i != e; ++i)
3423 pushValueAndType(
I.getOperand(i), InstID, Vals);
3427 case Instruction::Unreachable:
3429 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3432 case Instruction::PHI: {
3450 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
3455 case Instruction::LandingPad: {
3466 pushValueAndType(LP.
getClause(
I), InstID, Vals);
3471 case Instruction::Alloca: {
3477 using APV = AllocaPackedValues;
3479 unsigned EncodedAlign = getEncodedAlign(AI.
getAlign());
3481 Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3483 EncodedAlign >> APV::AlignLower::Bits);
3490 if (AS !=
M.getDataLayout().getAllocaAddrSpace())
3495 case Instruction::Load:
3498 pushValueAndType(
I.getOperand(0), InstID, Vals);
3501 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3502 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3512 case Instruction::Store:
3517 AbbrevToUse = FUNCTION_INST_STORE_ABBREV;
3519 if (pushValueAndType(
I.getOperand(1), InstID, Vals))
3521 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3531 case Instruction::AtomicCmpXchg:
3533 pushValueAndType(
I.getOperand(0), InstID, Vals);
3534 pushValueAndType(
I.getOperand(1), InstID, Vals);
3535 pushValue(
I.getOperand(2), InstID, Vals);
3546 case Instruction::AtomicRMW:
3548 pushValueAndType(
I.getOperand(0), InstID, Vals);
3549 pushValueAndType(
I.getOperand(1), InstID, Vals);
3558 case Instruction::Fence:
3563 case Instruction::Call: {
3568 writeOperandBundles(CI, InstID);
3588 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3592 if (FTy->isVarArg()) {
3593 for (
unsigned i = FTy->getNumParams(), e = CI.
arg_size(); i != e; ++i)
3598 case Instruction::VAArg:
3601 pushValue(
I.getOperand(0), InstID, Vals);
3604 case Instruction::Freeze:
3606 pushValueAndType(
I.getOperand(0), InstID, Vals);
3616void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3617 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3622 VSTOffset -= bitcodeStartBit();
3623 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
3627 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3631 auto Abbv = std::make_shared<BitCodeAbbrev>();
3635 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3637 for (
const Function &
F : M) {
3640 if (
F.isDeclaration())
3647 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
3648 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
3652 Record[1] = BitcodeIndex / 32 + 1;
3661void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3662 const ValueSymbolTable &VST) {
3670 SmallVector<uint64_t, 64> NameVals;
3676 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3685 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3689 AbbrevToUse = VST_ENTRY_6_ABBREV;
3691 AbbrevToUse = VST_ENTRY_7_ABBREV;
3694 for (
const auto P :
Name.getKey())
3698 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3705void ModuleBitcodeWriter::writeUseList(UseListOrder &&Order) {
3706 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3713 SmallVector<uint64_t, 64>
Record(Order.Shuffle.begin(), Order.Shuffle.end());
3718void ModuleBitcodeWriter::writeUseListBlock(
const Function *
F) {
3720 "Expected to be preserving use-list order");
3722 auto hasMore = [&]() {
3738void ModuleBitcodeWriter::writeFunction(
3740 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3757 unsigned CstStart, CstEnd;
3759 writeConstants(CstStart, CstEnd,
false);
3762 writeFunctionMetadata(
F);
3765 unsigned InstID = CstEnd;
3767 bool NeedsMetadataAttachment =
F.hasMetadata();
3769 DILocation *LastDL =
nullptr;
3770 SmallSetVector<Function *, 4> BlockAddressUsers;
3773 for (
const BasicBlock &BB :
F) {
3774 for (
const Instruction &
I : BB) {
3775 writeInstruction(
I, InstID, Vals);
3777 if (!
I.getType()->isVoidTy())
3781 NeedsMetadataAttachment |=
I.hasMetadataOtherThanDebugLoc();
3784 if (DILocation *
DL =
I.getDebugLoc()) {
3797 FUNCTION_DEBUG_LOC_ABBREV);
3807 if (
I.hasDbgRecords()) {
3811 auto PushValueOrMetadata = [&Vals, InstID,
3814 "RawLocation unexpectedly null in DbgVariableRecord");
3816 SmallVector<unsigned, 2> ValAndType;
3820 if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
3834 for (DbgRecord &DR :
I.DebugMarker->getDbgRecordRange()) {
3860 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3884 SmallPtrSet<Value *, 8> Visited{BA};
3885 while (!Worklist.
empty()) {
3887 for (User *U :
V->users()) {
3893 Visited.
insert(U).second)
3900 if (!BlockAddressUsers.
empty()) {
3909 if (
auto *Symtab =
F.getValueSymbolTable())
3910 writeFunctionLevelValueSymbolTable(*Symtab);
3912 if (NeedsMetadataAttachment)
3913 writeFunctionMetadataAttachment(
F);
3915 writeUseListBlock(&
F);
3921void ModuleBitcodeWriter::writeBlockInfo() {
3934 auto Abbv = std::make_shared<BitCodeAbbrev>();
3945 auto Abbv = std::make_shared<BitCodeAbbrev>();
3955 auto Abbv = std::make_shared<BitCodeAbbrev>();
3965 auto Abbv = std::make_shared<BitCodeAbbrev>();
3971 VST_BBENTRY_6_ABBREV)
3976 auto Abbv = std::make_shared<BitCodeAbbrev>();
3978 Abbv->Add(TypeAbbrevOp);
3980 CONSTANTS_SETTYPE_ABBREV)
3985 auto Abbv = std::make_shared<BitCodeAbbrev>();
3989 CONSTANTS_INTEGER_ABBREV)
3994 auto Abbv = std::make_shared<BitCodeAbbrev>();
3998 CONSTANTS_BYTE_ABBREV)
4003 auto Abbv = std::make_shared<BitCodeAbbrev>();
4011 CONSTANTS_CE_CAST_Abbrev)
4015 auto Abbv = std::make_shared<BitCodeAbbrev>();
4018 CONSTANTS_NULL_Abbrev)
4025 auto Abbv = std::make_shared<BitCodeAbbrev>();
4027 Abbv->Add(ValAbbrevOp);
4028 Abbv->Add(TypeAbbrevOp);
4032 FUNCTION_INST_LOAD_ABBREV)
4036 auto Abbv = std::make_shared<BitCodeAbbrev>();
4038 Abbv->Add(ValAbbrevOp);
4039 Abbv->Add(ValAbbrevOp);
4043 FUNCTION_INST_STORE_ABBREV)
4047 auto Abbv = std::make_shared<BitCodeAbbrev>();
4049 Abbv->Add(ValAbbrevOp);
4052 FUNCTION_INST_UNOP_ABBREV)
4056 auto Abbv = std::make_shared<BitCodeAbbrev>();
4058 Abbv->Add(ValAbbrevOp);
4062 FUNCTION_INST_UNOP_FLAGS_ABBREV)
4066 auto Abbv = std::make_shared<BitCodeAbbrev>();
4068 Abbv->Add(ValAbbrevOp);
4069 Abbv->Add(ValAbbrevOp);
4072 FUNCTION_INST_BINOP_ABBREV)
4076 auto Abbv = std::make_shared<BitCodeAbbrev>();
4078 Abbv->Add(ValAbbrevOp);
4079 Abbv->Add(ValAbbrevOp);
4083 FUNCTION_INST_BINOP_FLAGS_ABBREV)
4087 auto Abbv = std::make_shared<BitCodeAbbrev>();
4089 Abbv->Add(ValAbbrevOp);
4090 Abbv->Add(TypeAbbrevOp);
4093 FUNCTION_INST_CAST_ABBREV)
4097 auto Abbv = std::make_shared<BitCodeAbbrev>();
4099 Abbv->Add(ValAbbrevOp);
4100 Abbv->Add(TypeAbbrevOp);
4104 FUNCTION_INST_CAST_FLAGS_ABBREV)
4109 auto Abbv = std::make_shared<BitCodeAbbrev>();
4112 FUNCTION_INST_RET_VOID_ABBREV)
4116 auto Abbv = std::make_shared<BitCodeAbbrev>();
4118 Abbv->Add(ValAbbrevOp);
4120 FUNCTION_INST_RET_VAL_ABBREV)
4124 auto Abbv = std::make_shared<BitCodeAbbrev>();
4127 Abbv->Add(ValAbbrevOp);
4129 FUNCTION_INST_BR_UNCOND_ABBREV)
4133 auto Abbv = std::make_shared<BitCodeAbbrev>();
4136 Abbv->Add(ValAbbrevOp);
4137 Abbv->Add(ValAbbrevOp);
4138 Abbv->Add(ValAbbrevOp);
4140 FUNCTION_INST_BR_COND_ABBREV)
4144 auto Abbv = std::make_shared<BitCodeAbbrev>();
4147 FUNCTION_INST_UNREACHABLE_ABBREV)
4151 auto Abbv = std::make_shared<BitCodeAbbrev>();
4154 Abbv->Add(TypeAbbrevOp);
4156 Abbv->Add(ValAbbrevOp);
4158 FUNCTION_INST_GEP_ABBREV)
4162 auto Abbv = std::make_shared<BitCodeAbbrev>();
4164 Abbv->Add(ValAbbrevOp);
4165 Abbv->Add(ValAbbrevOp);
4168 FUNCTION_INST_CMP_ABBREV)
4172 auto Abbv = std::make_shared<BitCodeAbbrev>();
4174 Abbv->Add(ValAbbrevOp);
4175 Abbv->Add(ValAbbrevOp);
4179 FUNCTION_INST_CMP_FLAGS_ABBREV)
4183 auto Abbv = std::make_shared<BitCodeAbbrev>();
4188 Abbv->Add(ValAbbrevOp);
4190 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
4194 auto Abbv = std::make_shared<BitCodeAbbrev>();
4205 FUNCTION_DEBUG_LOC_ABBREV)
4213void IndexBitcodeWriter::writeModStrings() {
4219 auto Abbv = std::make_shared<BitCodeAbbrev>();
4224 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
4227 Abbv = std::make_shared<BitCodeAbbrev>();
4232 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
4235 Abbv = std::make_shared<BitCodeAbbrev>();
4240 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
4243 Abbv = std::make_shared<BitCodeAbbrev>();
4250 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
4253 forEachModule([&](
const StringMapEntry<ModuleHash> &MPSE) {
4255 const auto &Hash = MPSE.
getValue();
4257 unsigned AbbrevToUse = Abbrev8Bit;
4259 AbbrevToUse = Abbrev6Bit;
4261 AbbrevToUse = Abbrev7Bit;
4263 auto ModuleId = ModuleIdMap.
size();
4264 ModuleIdMap[
Key] = ModuleId;
4273 Vals.
assign(Hash.begin(), Hash.end());
4285template <
typename Fn>
4289 if (!FS->type_tests().empty())
4294 auto WriteVFuncIdVec = [&](
uint64_t Ty,
4299 for (
auto &VF : VFs) {
4300 Record.push_back(VF.GUID);
4301 Record.push_back(VF.Offset);
4307 FS->type_test_assume_vcalls());
4309 FS->type_checked_load_vcalls());
4311 auto WriteConstVCallVec = [&](
uint64_t Ty,
4313 for (
auto &VC : VCs) {
4315 Record.push_back(VC.VFunc.GUID);
4316 Record.push_back(VC.VFunc.Offset);
4323 FS->type_test_assume_const_vcalls());
4325 FS->type_checked_load_const_vcalls());
4335 if (!FS->paramAccesses().empty()) {
4337 for (
auto &Arg : FS->paramAccesses()) {
4338 size_t UndoSize =
Record.size();
4339 Record.push_back(Arg.ParamNo);
4340 WriteRange(Arg.Use);
4341 Record.push_back(Arg.Calls.size());
4342 for (
auto &
Call : Arg.Calls) {
4344 std::optional<unsigned> ValueID = GetValueID(
Call.Callee);
4351 Record.push_back(*ValueID);
4352 WriteRange(
Call.Offsets);
4363 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
4364 if (!FS->type_tests().empty())
4365 for (
auto &TT : FS->type_tests())
4366 ReferencedTypeIds.insert(TT);
4368 auto GetReferencedTypesFromVFuncIdVec =
4370 for (
auto &VF : VFs)
4371 ReferencedTypeIds.insert(VF.GUID);
4374 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4375 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4377 auto GetReferencedTypesFromConstVCallVec =
4379 for (
auto &VC : VCs)
4380 ReferencedTypeIds.insert(VC.VFunc.GUID);
4383 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4384 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
4420 NameVals.
push_back(Summary.TTRes.TheKind);
4421 NameVals.
push_back(Summary.TTRes.SizeM1BitWidth);
4422 NameVals.
push_back(Summary.TTRes.AlignLog2);
4423 NameVals.
push_back(Summary.TTRes.SizeM1);
4424 NameVals.
push_back(Summary.TTRes.BitMask);
4425 NameVals.
push_back(Summary.TTRes.InlineBits);
4427 for (
auto &W : Summary.WPDRes)
4439 for (
auto &
P : Summary) {
4441 NameVals.
push_back(
VE.getValueID(
P.VTableVI.getValue()));
4455 static_assert(std::is_same_v<LinearFrameId, unsigned>);
4456 for (
auto &AI : FS->allocs()) {
4457 for (
auto &MIB : AI.MIBs) {
4459 StackIdIndices.
reserve(MIB.StackIdIndices.size());
4460 for (
auto Id : MIB.StackIdIndices)
4461 StackIdIndices.
push_back(GetStackIndex(Id));
4463 CallStacks.insert({CallStacks.size(), StackIdIndices});
4476 assert(!CallStacks.empty());
4482 Builder.
build(std::move(CallStacks),
nullptr,
4486 return Builder.takeCallStackPos();
4491 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
bool PerModule,
4492 std::function<
unsigned(
const ValueInfo &VI)> GetValueID,
4493 std::function<
unsigned(
unsigned)> GetStackIndex,
4494 bool WriteContextSizeInfoIndex,
4499 for (
auto &CI : FS->callsites()) {
4503 assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4504 Record.push_back(GetValueID(CI.Callee));
4506 Record.push_back(CI.StackIdIndices.size());
4507 Record.push_back(CI.Clones.size());
4509 for (
auto Id : CI.StackIdIndices)
4510 Record.push_back(GetStackIndex(Id));
4518 for (
auto &AI : FS->allocs()) {
4522 assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4523 Record.push_back(AI.MIBs.size());
4525 Record.push_back(AI.Versions.size());
4526 for (
auto &MIB : AI.MIBs) {
4533 assert(CallStackCount <= CallStackPos.
size());
4534 Record.push_back(CallStackPos[CallStackCount++]);
4539 assert(AI.ContextSizeInfos.empty() ||
4540 AI.ContextSizeInfos.size() == AI.MIBs.size());
4542 if (WriteContextSizeInfoIndex && !AI.ContextSizeInfos.empty()) {
4550 ContextIds.
reserve(AI.ContextSizeInfos.size() * 2);
4551 for (
auto &Infos : AI.ContextSizeInfos) {
4552 Record.push_back(Infos.size());
4553 for (
auto [FullStackId, TotalSize] : Infos) {
4560 Record.push_back(TotalSize);
4578void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4579 SmallVector<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
4580 unsigned ValueID,
unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
4581 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
const Function &
F,
4582 DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
4589 Stream, FS, [&](
const ValueInfo &VI) -> std::optional<unsigned> {
4593 auto SpecialRefCnts =
FS->specialRefCounts();
4598 NameVals.
push_back(SpecialRefCnts.first);
4599 NameVals.
push_back(SpecialRefCnts.second);
4601 for (
auto &RI :
FS->refs())
4604 for (
auto &ECI :
FS->calls()) {
4605 NameVals.
push_back(getValueId(ECI.first));
4614 Stream, FS, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
4616 [&](
const ValueInfo &VI) {
return getValueId(VI); },
4617 [&](
unsigned I) {
return I; },
4618 true, CallStackPos, CallStackCount);
4623void ModuleBitcodeWriterBase::writeModuleLevelReferences(
4624 const GlobalVariable &V, SmallVector<uint64_t, 64> &NameVals,
4625 unsigned FSModRefsAbbrev,
unsigned FSModVTableRefsAbbrev) {
4626 auto VI =
Index->getValueInfo(
V.getGUID());
4627 if (!VI ||
VI.getSummaryList().empty()) {
4633 auto *
Summary =
VI.getSummaryList()[0].get();
4639 auto VTableFuncs =
VS->vTableFuncs();
4640 if (!VTableFuncs.empty())
4643 unsigned SizeBeforeRefs = NameVals.
size();
4644 for (
auto &RI :
VS->refs())
4650 if (VTableFuncs.empty())
4655 for (
auto &
P : VTableFuncs) {
4661 FSModVTableRefsAbbrev);
4668void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
4671 bool IsThinLTO =
true;
4674 IsThinLTO = MD->getZExtValue();
4686 if (
Index->enableSplitLTOUnit())
4688 if (
Index->hasUnifiedLTO())
4698 auto Abbv = std::make_shared<BitCodeAbbrev>();
4704 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4706 for (
const auto &GVI : valueIds()) {
4708 ArrayRef<uint32_t>{GVI.second,
4709 static_cast<uint32_t
>(GVI.first >> 32),
4710 static_cast<uint32_t
>(GVI.first)},
4714 if (!
Index->stackIds().empty()) {
4715 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4722 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4723 SmallVector<uint32_t> Vals;
4725 for (
auto Id :
Index->stackIds()) {
4726 Vals.
push_back(
static_cast<uint32_t
>(Id >> 32));
4727 Vals.
push_back(
static_cast<uint32_t
>(Id));
4732 unsigned ContextIdAbbvId = 0;
4735 auto ContextIdAbbv = std::make_shared<BitCodeAbbrev>();
4747 ContextIdAbbvId = Stream.
EmitAbbrev(std::move(ContextIdAbbv));
4751 Abbv = std::make_shared<BitCodeAbbrev>();
4763 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4766 Abbv = std::make_shared<BitCodeAbbrev>();
4772 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4775 Abbv = std::make_shared<BitCodeAbbrev>();
4783 unsigned FSModVTableRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4786 Abbv = std::make_shared<BitCodeAbbrev>();
4791 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4794 Abbv = std::make_shared<BitCodeAbbrev>();
4801 unsigned TypeIdCompatibleVtableAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4803 Abbv = std::make_shared<BitCodeAbbrev>();
4809 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4811 Abbv = std::make_shared<BitCodeAbbrev>();
4818 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4820 Abbv = std::make_shared<BitCodeAbbrev>();
4825 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4832 MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
4833 for (
const Function &
F : M) {
4839 ValueInfo
VI =
Index->getValueInfo(
F.getGUID());
4840 if (!VI ||
VI.getSummaryList().empty()) {
4846 auto *
Summary =
VI.getSummaryList()[0].get();
4849 FS, [](
unsigned I) {
return I; }, CallStacks);
4853 DenseMap<CallStackId, LinearCallStackId> CallStackPos;
4854 if (!CallStacks.
empty()) {
4862 SmallVector<uint64_t, 64> NameVals;
4865 for (
const Function &
F : M) {
4871 ValueInfo
VI =
Index->getValueInfo(
F.getGUID());
4872 if (!VI ||
VI.getSummaryList().empty()) {
4878 auto *
Summary =
VI.getSummaryList()[0].get();
4879 writePerModuleFunctionSummaryRecord(NameVals, Summary, VE.
getValueID(&
F),
4880 FSCallsProfileAbbrev, CallsiteAbbrev,
4881 AllocAbbrev, ContextIdAbbvId,
F,
4882 CallStackPos, CallStackCount);
4887 for (
const GlobalVariable &
G :
M.globals())
4888 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev,
4889 FSModVTableRefsAbbrev);
4891 for (
const GlobalAlias &
A :
M.aliases()) {
4892 auto *Aliasee =
A.getAliaseeObject();
4908 for (
auto &S :
Index->typeIdCompatibleVtableMap()) {
4912 TypeIdCompatibleVtableAbbrev);
4916 if (
Index->getBlockCount())
4918 ArrayRef<uint64_t>{
Index->getBlockCount()});
4924void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4933 auto Abbv = std::make_shared<BitCodeAbbrev>();
4939 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4941 for (
const auto &GVI : valueIds()) {
4943 ArrayRef<uint32_t>{GVI.second,
4944 static_cast<uint32_t
>(GVI.first >> 32),
4945 static_cast<uint32_t
>(GVI.first)},
4951 if (!StackIds.empty()) {
4952 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4959 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4960 SmallVector<uint32_t> Vals;
4961 Vals.
reserve(StackIds.size() * 2);
4962 for (
auto Id : StackIds) {
4963 Vals.
push_back(
static_cast<uint32_t
>(Id >> 32));
4964 Vals.
push_back(
static_cast<uint32_t
>(Id));
4970 Abbv = std::make_shared<BitCodeAbbrev>();
4984 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4987 Abbv = std::make_shared<BitCodeAbbrev>();
4994 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4997 Abbv = std::make_shared<BitCodeAbbrev>();
5003 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5005 Abbv = std::make_shared<BitCodeAbbrev>();
5013 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5015 Abbv = std::make_shared<BitCodeAbbrev>();
5026 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5028 auto shouldImportValueAsDecl = [&](GlobalValueSummary *GVS) ->
bool {
5029 if (DecSummaries ==
nullptr)
5031 return DecSummaries->count(GVS);
5039 DenseMap<const GlobalValueSummary *, unsigned> SummaryToValueIdMap;
5041 SmallVector<uint64_t, 64> NameVals;
5045 std::set<GlobalValue::GUID> ReferencedTypeIds;
5049 auto MaybeEmitOriginalName = [&](GlobalValueSummary &S) {
5059 NameVals.
push_back(S.getOriginalName());
5064 DenseMap<CallStackId, LinearCallStackId> CallStackPos;
5066 Abbv = std::make_shared<BitCodeAbbrev>();
5071 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5078 MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
5079 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5085 GlobalValueSummary *S =
I.second;
5098 return StackIdIndicesToIndex[
I];
5104 if (!CallStacks.
empty()) {
5114 DenseSet<GlobalValue::GUID> DefOrUseGUIDs;
5115 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5116 GlobalValueSummary *S =
I.second;
5118 DefOrUseGUIDs.
insert(
I.first);
5119 for (
const ValueInfo &VI : S->
refs())
5120 DefOrUseGUIDs.
insert(
VI.getGUID());
5122 auto ValueId = getValueId(
I.first);
5124 SummaryToValueIdMap[S] = *ValueId;
5142 NameVals.
push_back(ModuleIdMap[
VS->modulePath()]);
5146 for (
auto &RI :
VS->refs()) {
5147 auto RefValueId = getValueId(RI.getGUID());
5157 MaybeEmitOriginalName(*S);
5161 auto GetValueId = [&](
const ValueInfo &
VI) -> std::optional<unsigned> {
5163 return std::nullopt;
5164 return getValueId(
VI.getGUID());
5173 NameVals.
push_back(ModuleIdMap[
FS->modulePath()]);
5186 unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
5187 for (
auto &RI :
FS->refs()) {
5188 auto RefValueId = getValueId(RI.getGUID());
5192 if (RI.isReadOnly())
5194 else if (RI.isWriteOnly())
5198 NameVals[6] =
Count;
5199 NameVals[7] = RORefCnt;
5200 NameVals[8] = WORefCnt;
5202 for (
auto &EI :
FS->calls()) {
5205 std::optional<unsigned> CallValueId = GetValueId(EI.first);
5214 FSCallsProfileAbbrev);
5218 Stream, FS, CallsiteAbbrev, AllocAbbrev, 0,
5221 [&](
const ValueInfo &VI) ->
unsigned {
5222 std::optional<unsigned> ValueID = GetValueId(VI);
5237 return StackIdIndicesToIndex[
I];
5239 false, CallStackPos, CallStackCount);
5241 MaybeEmitOriginalName(*S);
5244 for (
auto *AS : Aliases) {
5245 auto AliasValueId = SummaryToValueIdMap[AS];
5254 auto AliaseeValueId =
5261 MaybeEmitOriginalName(*AS);
5269 auto EmitCfiFunctions = [&](
const CfiFunctionIndex &CfiIndex,
5271 if (CfiIndex.
empty())
5274 auto Defs = CfiIndex.
forGuid(GUID);
5277 if (Functions.
empty())
5280 for (
const auto &S : Functions) {
5294 for (
auto &
T : ReferencedTypeIds) {
5295 auto TidIter =
Index.typeIds().equal_range(
T);
5296 for (
const auto &[GUID, TypeIdPair] :
make_range(TidIter)) {
5304 if (
Index.getBlockCount())
5306 ArrayRef<uint64_t>{
Index.getBlockCount()});
5317 auto Abbv = std::make_shared<BitCodeAbbrev>();
5321 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5323 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
5326 Abbv = std::make_shared<BitCodeAbbrev>();
5329 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5335void ModuleBitcodeWriter::writeModuleHash(StringRef View) {
5340 Hasher.
update(ArrayRef<uint8_t>(
5341 reinterpret_cast<const uint8_t *
>(
View.data()),
View.size()));
5342 std::array<uint8_t, 20> Hash = Hasher.
result();
5343 for (
int Pos = 0; Pos < 20; Pos += 4) {
5356void ModuleBitcodeWriter::write() {
5364 writeModuleVersion();
5373 writeAttributeGroupTable();
5376 writeAttributeTable();
5385 writeModuleConstants();
5388 writeModuleMetadataKinds();
5391 writeModuleMetadata();
5395 writeUseListBlock(
nullptr);
5397 writeOperandBundleTags();
5398 writeSyncScopeNames();
5401 DenseMap<const Function *, uint64_t> FunctionToBitcodeIndex;
5402 for (
const Function &
F : M)
5403 if (!
F.isDeclaration())
5404 writeFunction(
F, FunctionToBitcodeIndex);
5409 writePerModuleGlobalValueSummary();
5411 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
5439 unsigned CPUType = ~0U;
5446 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
5447 DARWIN_CPU_TYPE_X86 = 7,
5448 DARWIN_CPU_TYPE_ARM = 12,
5449 DARWIN_CPU_TYPE_POWERPC = 18
5454 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
5456 CPUType = DARWIN_CPU_TYPE_X86;
5458 CPUType = DARWIN_CPU_TYPE_POWERPC;
5460 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
5462 CPUType = DARWIN_CPU_TYPE_ARM;
5466 "Expected header size to be reserved");
5471 unsigned Position = 0;
5479 while (Buffer.
size() & 15)
5486 Stream.
Emit((
unsigned)
'B', 8);
5487 Stream.
Emit((
unsigned)
'C', 8);
5488 Stream.
Emit(0x0, 4);
5489 Stream.
Emit(0xC, 4);
5490 Stream.
Emit(0xE, 4);
5491 Stream.
Emit(0xD, 4);
5509 auto Abbv = std::make_shared<BitCodeAbbrev>();
5512 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
5520 assert(!WroteStrtab && !WroteSymtab);
5526 if (M->getModuleInlineAsm().empty())
5530 const Triple TT(M->getTargetTriple());
5532 if (!
T || !
T->hasMCAsmParser())
5554 std::vector<char> Strtab;
5555 StrtabBuilder.finalizeInOrder();
5556 Strtab.resize(StrtabBuilder.getSize());
5557 StrtabBuilder.write((
uint8_t *)Strtab.data());
5560 {Strtab.data(), Strtab.size()});
5571 bool ShouldPreserveUseListOrder,
5580 assert(M.isMaterialized());
5581 Mods.push_back(
const_cast<Module *
>(&M));
5583 ModuleBitcodeWriter ModuleWriter(M, StrtabBuilder, *Stream,
5584 ShouldPreserveUseListOrder, Index,
5585 GenerateHash, ModHash);
5586 ModuleWriter.write();
5593 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, DecSummaries,
5594 ModuleToSummariesForIndex);
5595 IndexWriter.write();
5600 bool ShouldPreserveUseListOrder,
5604 Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
5606 Writer.writeSymtab();
5607 Writer.writeStrtab();
5609 Triple TT(M.getTargetTriple());
5610 if (TT.isOSDarwin() || TT.isOSBinFormatMachO()) {
5628void IndexBitcodeWriter::write() {
5631 writeModuleVersion();
5637 writeCombinedGlobalValueSummary();
5654 Writer.
writeIndex(&Index, ModuleToSummariesForIndex, DecSummaries);
5663class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
5673 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5675 ModHash(&ModHash) {}
5680 void writeSimplifiedModuleInfo();
5690void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5702 auto Abbv = std::make_shared<BitCodeAbbrev>();
5705 Abbv->Add(AbbrevOpToUse);
5706 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5708 for (
const auto P :
M.getSourceFileName())
5772void ThinLinkBitcodeWriter::write() {
5775 writeModuleVersion();
5777 writeSimplifiedModuleInfo();
5779 writePerModuleGlobalValueSummary();
5796 assert(M.isMaterialized());
5797 Mods.push_back(
const_cast<Module *
>(&M));
5799 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream, Index,
5801 ThinLinkWriter.write();
5822 switch (
T.getObjectFormat()) {
5824 return "__LLVM,__bitcode";
5849 switch (
T.getObjectFormat()) {
5851 return "__LLVM,__cmdline";
5877 const std::vector<uint8_t> &CmdArgs) {
5882 Type *UsedElementType = Used ? Used->getValueType()->getArrayElementType()
5884 for (
auto *GV : UsedGlobals) {
5885 if (GV->getName() !=
"llvm.embedded.module" &&
5886 GV->getName() !=
"llvm.cmdline")
5891 Used->eraseFromParent();
5896 Triple T(M.getTargetTriple());
5925 M.getGlobalVariable(
"llvm.embedded.module",
true)) {
5926 assert(Old->hasZeroLiveUses() &&
5927 "llvm.embedded.module can only be used once in llvm.compiler.used");
5929 Old->eraseFromParent();
5931 GV->
setName(
"llvm.embedded.module");
5949 assert(Old->hasZeroLiveUses() &&
5950 "llvm.cmdline can only be used once in llvm.compiler.used");
5952 Old->eraseFromParent();
5958 if (UsedArray.
empty())
5966 NewUsed->setSection(
"llvm.metadata");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void writeDIMacro(raw_ostream &Out, const DIMacro *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, AsmWriterContext &WriterCtx)
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, AsmWriterContext &WriterCtx)
static void writeDIFixedPointType(raw_ostream &Out, const DIFixedPointType *N, AsmWriterContext &WriterCtx)
static void writeDISubrangeType(raw_ostream &Out, const DISubrangeType *N, AsmWriterContext &WriterCtx)
static void writeDIStringType(raw_ostream &Out, const DIStringType *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, AsmWriterContext &WriterCtx)
static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, AsmWriterContext &WriterCtx)
static void writeDIModule(raw_ostream &Out, const DIModule *N, AsmWriterContext &WriterCtx)
static void writeDIFile(raw_ostream &Out, const DIFile *N, AsmWriterContext &)
static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, AsmWriterContext &WriterCtx)
static void writeDILabel(raw_ostream &Out, const DILabel *N, AsmWriterContext &WriterCtx)
static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, AsmWriterContext &WriterCtx)
static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, AsmWriterContext &WriterCtx)
static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, AsmWriterContext &WriterCtx)
static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, AsmWriterContext &WriterCtx)
static void writeDILocation(raw_ostream &Out, const DILocation *DL, AsmWriterContext &WriterCtx)
static void writeDINamespace(raw_ostream &Out, const DINamespace *N, AsmWriterContext &WriterCtx)
static void writeDICommonBlock(raw_ostream &Out, const DICommonBlock *N, AsmWriterContext &WriterCtx)
static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, AsmWriterContext &WriterCtx)
static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, AsmWriterContext &WriterCtx)
static void writeDITemplateTypeParameter(raw_ostream &Out, const DITemplateTypeParameter *N, AsmWriterContext &WriterCtx)
static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, AsmWriterContext &WriterCtx)
static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N, AsmWriterContext &WriterCtx)
static void writeDISubrange(raw_ostream &Out, const DISubrange *N, AsmWriterContext &WriterCtx)
static void writeDILexicalBlockFile(raw_ostream &Out, const DILexicalBlockFile *N, AsmWriterContext &WriterCtx)
static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, AsmWriterContext &)
static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, AsmWriterContext &WriterCtx)
static void writeDIExpression(raw_ostream &Out, const DIExpression *N, AsmWriterContext &WriterCtx)
static void writeDIAssignID(raw_ostream &Out, const DIAssignID *DL, AsmWriterContext &WriterCtx)
static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, AsmWriterContext &WriterCtx)
static void writeDIArgList(raw_ostream &Out, const DIArgList *N, AsmWriterContext &WriterCtx, bool FromValue=false)
static void writeDITemplateValueParameter(raw_ostream &Out, const DITemplateValueParameter *N, AsmWriterContext &WriterCtx)
static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, AsmWriterContext &WriterCtx)
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static void writeFunctionHeapProfileRecords(BitstreamWriter &Stream, FunctionSummary *FS, unsigned CallsiteAbbrev, unsigned AllocAbbrev, unsigned ContextIdAbbvId, bool PerModule, std::function< unsigned(const ValueInfo &VI)> GetValueID, std::function< unsigned(unsigned)> GetStackIndex, bool WriteContextSizeInfoIndex, DenseMap< CallStackId, LinearCallStackId > &CallStackPos, CallStackId &CallStackCount)
static unsigned serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta)
static void writeTypeIdCompatibleVtableSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdCompatibleVtableInfo &Summary, ValueEnumerator &VE)
static void getReferencedTypeIds(FunctionSummary *FS, std::set< GlobalValue::GUID > &ReferencedTypeIds)
Collect type IDs from type tests used by function.
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
static void collectMemProfCallStacks(FunctionSummary *FS, std::function< LinearFrameId(unsigned)> GetStackIndex, MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &CallStacks)
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
static unsigned getEncodedVisibility(const GlobalValue &GV)
static uint64_t getOptimizationFlags(const Value *V)
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
static cl::opt< bool > PreserveBitcodeUseListOrder("preserve-bc-uselistorder", cl::Hidden, cl::init(true), cl::desc("Preserve use-list order when writing LLVM bitcode."))
static unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
static DenseMap< CallStackId, LinearCallStackId > writeMemoryProfileRadixTree(MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &&CallStacks, BitstreamWriter &Stream, unsigned RadixAbbrev)
static void writeIdentificationBlock(BitstreamWriter &Stream)
Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version,...
static unsigned getEncodedCastOpcode(unsigned Opcode)
static cl::opt< uint32_t > FlushThreshold("bitcode-flush-threshold", cl::Hidden, cl::init(512), cl::desc("The threshold (unit M) for flushing LLVM bitcode."))
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
static unsigned getEncodedUnnamedAddr(const GlobalValue &GV)
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags, bool ImportAsDecl=false)
static void emitDarwinBCHeaderAndTrailer(SmallVectorImpl< char > &Buffer, const Triple &TT)
If generating a bc file on darwin, we have to emit a header and trailer to make it compatible with th...
static void writeBitcodeHeader(BitstreamWriter &Stream)
Helper to write the header common to all bitcode files.
static void writeWholeProgramDevirtResolutionByArg(SmallVector< uint64_t, 64 > &NameVals, const std::vector< uint64_t > &args, const WholeProgramDevirtResolution::ByArg &ByArg)
static void emitConstantRange(SmallVectorImpl< uint64_t > &Record, const ConstantRange &CR, bool EmitBitWidth)
static StringEncoding getStringEncoding(StringRef Str)
Determine the encoding to use for the given string name and length.
static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags)
static const char * getSectionNameForCommandline(const Triple &T)
static cl::opt< unsigned > IndexThreshold("bitcode-mdindex-threshold", cl::Hidden, cl::init(25), cl::desc("Number of metadatas above which we emit an index " "to enable lazy-loading"))
static void writeTypeIdSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdSummary &Summary)
static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, FunctionSummary *FS, Fn GetValueID)
Write the function type metadata related records that need to appear before a function summary entry ...
static uint64_t getEncodedHotnessCallEdgeInfo(const CalleeInfo &CI)
static void emitWideAPInt(SmallVectorImpl< uint64_t > &Vals, const APInt &A)
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
static void writeWholeProgramDevirtResolution(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, uint64_t Id, const WholeProgramDevirtResolution &Wpd)
static unsigned getEncodedDLLStorageClass(const GlobalValue &GV)
static void writeInt32ToBuffer(uint32_t Value, SmallVectorImpl< char > &Buffer, uint32_t &Position)
static const char * getSectionNameForBitcode(const Triple &T)
static cl::opt< bool > CombinedIndexMemProfContext("combined-index-memprof-context", cl::Hidden, cl::init(true), cl::desc(""))
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
This file contains constants used for implementing Dwarf debug support.
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
static MaybeAlign getAlign(Value *Ptr)
Module.h This file contains the declarations for the Module class.
static cl::opt< LTOBitcodeEmbedding > EmbedBitcode("lto-embed-bitcode", cl::init(LTOBitcodeEmbedding::DoNotEmbed), cl::values(clEnumValN(LTOBitcodeEmbedding::DoNotEmbed, "none", "Do not embed"), clEnumValN(LTOBitcodeEmbedding::EmbedOptimized, "optimized", "Embed after all optimization passes"), clEnumValN(LTOBitcodeEmbedding::EmbedPostMergePreOptimized, "post-merge-pre-opt", "Embed post merge, but before optimizations")), cl::desc("Embed LLVM bitcode in object files produced by LTO"))
Machine Check Debug Module
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static const uint32_t IV[8]
Class for arbitrary precision integers.
unsigned getActiveWords() const
Compute the number of active words in the value of this APInt.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
int64_t getSExtValue() const
Get sign extended value.
const GlobalValueSummary & getAliasee() const
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
unsigned getAddressSpace() const
Return the address space for the allocation.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
Class to represent array types.
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ USubCond
Subtract only if no unsigned overflow.
@ FMinimum
*p = minimum(old, v) minimum matches the behavior of llvm.minimum.
@ Min
*p = old <signed v ? old : v
@ USubSat
*p = usub.sat(old, v) usub.sat matches the behavior of llvm.usub.sat.
@ FMaximum
*p = maximum(old, v) maximum matches the behavior of llvm.maximum.
@ UIncWrap
Increment one up to a maximum value.
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ UMax
*p = old >unsigned v ? old : v
@ 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
iterator_range< NestedIterator > forGuid(GlobalValue::GUID GUID) const
@ Largest
The linker will choose the largest COMDAT.
@ SameSize
The data referenced by the COMDAT must be the same size.
@ Any
The linker may choose any COMDAT.
@ NoDeduplicate
No deduplication is performed.
@ ExactMatch
The data referenced by the COMDAT must be the same.
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
static LLVM_ABI Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
This class represents a range of values.
const APInt & getLower() const
Return the lower value for this range.
const APInt & getUpper() const
Return the upper value for this range.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
This is an important base class in LLVM.
DebugLoc getDebugLoc() const
LLVM_ABI DIAssignID * getAssignID() const
DIExpression * getExpression() const
DILocalVariable * getVariable() const
bool isDbgDeclareValue() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
bool isDbgDeclare() const
Metadata * getRawAddress() const
DIExpression * getAddressExpression() const
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Lightweight error class with error context and mandatory checking.
Function summary information to aid decisions and implementation of importing.
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
LLVM_ABI void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
LLVM_ABI void setSection(StringRef S)
Change the section for this global.
GVFlags flags() const
Get the flags for this GlobalValue (see struct GVFlags).
StringRef modulePath() const
Get the path to the module containing this function.
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
VisibilityTypes getVisibility() const
static bool isLocalLinkage(LinkageTypes Linkage)
LinkageTypes getLinkage() const
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
ThreadLocalMode getThreadLocalMode() const
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ProtectedVisibility
The GV is protected.
UnnamedAddr getUnnamedAddr() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
DLLStorageClassTypes getDLLStorageClass() const
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalVariable.
idx_iterator idx_end() const
idx_iterator idx_begin() const
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
This class implements a map that also provides access to all stored values in a deterministic order.
size_t getBufferSize() const
const char * getBufferStart() const
const char * getBufferEnd() const
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static constexpr uint64_t BitcodeSummaryVersion
A Module instance is used to store all the information related to an LLVM module.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Digest more data.
LLVM_ABI std::array< uint8_t, 20 > result()
Return the current raw 160-bits SHA1 for the digested data since the last call to init().
size_type size() const
Determine the number of elements in the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void append(StringRef RHS)
Append from a StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
const ValueTy & getValue() const
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
Utility for building string tables with deduplicated suffixes.
LLVM_ABI size_t add(CachedHashStringRef S, uint8_t Priority=0)
Add a string to the builder.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isX86_FP80Ty() const
Return true if this is x86 long double.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
bool isFP128Ty() const
Return true if this is 'fp128'.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
std::vector< std::pair< const Value *, unsigned > > ValueList
unsigned getTypeID(Type *T) const
unsigned getMetadataID(const Metadata *MD) const
UseListOrderStack UseListOrders
ArrayRef< const Metadata * > getNonMDStrings() const
Get the non-MDString metadata for this block.
unsigned getInstructionID(const Instruction *I) const
unsigned getAttributeListID(AttributeList PAL) const
void incorporateFunction(const Function &F)
incorporateFunction/purgeFunction - If you'd like to deal with a function, use these two methods to g...
void getFunctionConstantRange(unsigned &Start, unsigned &End) const
getFunctionConstantRange - Return the range of values that corresponds to function-local constants.
unsigned getAttributeGroupID(IndexAndAttrSet Group) const
bool hasMDs() const
Check whether the current block has any metadata to emit.
unsigned getComdatID(const Comdat *C) const
uint64_t computeBitsRequiredForTypeIndices() const
unsigned getValueID(const Value *V) const
unsigned getMetadataOrNullID(const Metadata *MD) const
const std::vector< IndexAndAttrSet > & getAttributeGroups() const
const ValueList & getValues() const
unsigned getGlobalBasicBlockID(const BasicBlock *BB) const
getGlobalBasicBlockID - This returns the function-specific ID for the specified basic block.
void setInstructionID(const Instruction *I)
const std::vector< const BasicBlock * > & getBasicBlocks() const
const std::vector< AttributeList > & getAttributeLists() const
bool shouldPreserveUseListOrder() const
const ComdatSetType & getComdats() const
std::vector< Type * > TypeList
ArrayRef< const Metadata * > getMDStrings() const
Get the MDString metadata for this block.
std::pair< unsigned, AttributeSet > IndexAndAttrSet
Attribute groups as encoded in bitcode are almost AttributeSets, but they include the AttributeList i...
const TypeList & getTypes() const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
std::pair< iterator, bool > insert(const ValueT &V)
void build(llvm::MapVector< CallStackId, llvm::SmallVector< FrameIdTy > > &&MemProfCallStackData, const llvm::DenseMap< FrameIdTy, LinearFrameId > *MemProfFrameIndexes, llvm::DenseMap< FrameIdTy, FrameStat > &FrameHistogram)
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an std::string.
std::string & str()
Returns the string's reference.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
@ CE
Windows NT (Windows on ARM)
@ TYPE_CODE_OPAQUE_POINTER
@ METADATA_TEMPLATE_VALUE
@ METADATA_LEXICAL_BLOCK_FILE
@ METADATA_SUBROUTINE_TYPE
@ METADATA_GLOBAL_DECL_ATTACHMENT
@ METADATA_IMPORTED_ENTITY
@ METADATA_GENERIC_SUBRANGE
@ METADATA_COMPOSITE_TYPE
@ METADATA_FIXED_POINT_TYPE
@ METADATA_GLOBAL_VAR_EXPR
GlobalValueSummarySymtabCodes
@ FS_CONTEXT_RADIX_TREE_ARRAY
@ FS_COMBINED_GLOBALVAR_INIT_REFS
@ FS_TYPE_CHECKED_LOAD_VCALLS
@ FS_COMBINED_ORIGINAL_NAME
@ FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_CONST_VCALL
@ FS_PERMODULE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_VCALLS
@ FS_COMBINED_ALLOC_INFO_NO_CONTEXT
@ FS_COMBINED_CALLSITE_INFO
@ FS_PERMODULE_CALLSITE_INFO
@ FS_PERMODULE_ALLOC_INFO
@ FS_TYPE_CHECKED_LOAD_CONST_VCALL
@ IDENTIFICATION_CODE_EPOCH
@ IDENTIFICATION_CODE_STRING
@ CST_CODE_DSO_LOCAL_EQUIVALENT
@ CST_CODE_CE_GEP_WITH_INRANGE
@ COMDAT_SELECTION_KIND_LARGEST
@ COMDAT_SELECTION_KIND_ANY
@ COMDAT_SELECTION_KIND_SAME_SIZE
@ COMDAT_SELECTION_KIND_EXACT_MATCH
@ COMDAT_SELECTION_KIND_NO_DUPLICATES
@ ATTR_KIND_STACK_PROTECT
@ ATTR_KIND_STACK_PROTECT_STRONG
@ ATTR_KIND_SANITIZE_MEMORY
@ ATTR_KIND_OPTIMIZE_FOR_SIZE
@ ATTR_KIND_FNRETTHUNK_EXTERN
@ ATTR_KIND_NO_DIVERGENCE_SOURCE
@ ATTR_KIND_SANITIZE_ADDRESS
@ ATTR_KIND_NO_IMPLICIT_FLOAT
@ ATTR_KIND_DEAD_ON_UNWIND
@ ATTR_KIND_STACK_ALIGNMENT
@ ATTR_KIND_STACK_PROTECT_REQ
@ ATTR_KIND_NULL_POINTER_IS_VALID
@ ATTR_KIND_SANITIZE_HWADDRESS
@ ATTR_KIND_RETURNS_TWICE
@ ATTR_KIND_SHADOWCALLSTACK
@ ATTR_KIND_OPT_FOR_FUZZING
@ ATTR_KIND_DENORMAL_FPENV
@ ATTR_KIND_SANITIZE_NUMERICAL_STABILITY
@ ATTR_KIND_ALLOCATED_POINTER
@ ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION
@ ATTR_KIND_CORO_ELIDE_SAFE
@ ATTR_KIND_NON_LAZY_BIND
@ ATTR_KIND_DEREFERENCEABLE
@ ATTR_KIND_OPTIMIZE_NONE
@ ATTR_KIND_HYBRID_PATCHABLE
@ ATTR_KIND_DEREFERENCEABLE_OR_NULL
@ ATTR_KIND_SANITIZE_REALTIME
@ ATTR_KIND_SPECULATIVE_LOAD_HARDENING
@ ATTR_KIND_ALWAYS_INLINE
@ ATTR_KIND_SANITIZE_TYPE
@ ATTR_KIND_PRESPLIT_COROUTINE
@ ATTR_KIND_SANITIZE_ALLOC_TOKEN
@ ATTR_KIND_NO_SANITIZE_COVERAGE
@ ATTR_KIND_NO_CREATE_UNDEF_OR_POISON
@ ATTR_KIND_DEAD_ON_RETURN
@ ATTR_KIND_SANITIZE_REALTIME_BLOCKING
@ ATTR_KIND_NO_SANITIZE_BOUNDS
@ ATTR_KIND_SANITIZE_MEMTAG
@ ATTR_KIND_CORO_ONLY_DESTROY_WHEN_COMPLETE
@ ATTR_KIND_SANITIZE_THREAD
@ ATTR_KIND_OPTIMIZE_FOR_DEBUGGING
@ SYNC_SCOPE_NAMES_BLOCK_ID
@ PARAMATTR_GROUP_BLOCK_ID
@ IDENTIFICATION_BLOCK_ID
@ GLOBALVAL_SUMMARY_BLOCK_ID
@ FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID
@ OPERAND_BUNDLE_TAGS_BLOCK_ID
@ MODULE_CODE_SOURCE_FILENAME
@ MODULE_CODE_SECTIONNAME
@ FUNC_CODE_INST_CATCHRET
@ FUNC_CODE_INST_LANDINGPAD
@ FUNC_CODE_INST_EXTRACTVAL
@ FUNC_CODE_INST_CATCHPAD
@ FUNC_CODE_INST_CATCHSWITCH
@ FUNC_CODE_INST_CLEANUPRET
@ FUNC_CODE_DEBUG_RECORD_VALUE
@ FUNC_CODE_INST_LOADATOMIC
@ FUNC_CODE_DEBUG_RECORD_ASSIGN
@ FUNC_CODE_INST_STOREATOMIC
@ FUNC_CODE_INST_ATOMICRMW
@ FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE
@ FUNC_CODE_DEBUG_LOC_AGAIN
@ FUNC_CODE_INST_EXTRACTELT
@ FUNC_CODE_INST_INDIRECTBR
@ FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE
@ FUNC_CODE_INST_INSERTVAL
@ FUNC_CODE_DECLAREBLOCKS
@ FUNC_CODE_DEBUG_RECORD_LABEL
@ FUNC_CODE_INST_INSERTELT
@ FUNC_CODE_BLOCKADDR_USERS
@ FUNC_CODE_INST_CLEANUPPAD
@ FUNC_CODE_INST_SHUFFLEVEC
@ FUNC_CODE_INST_UNREACHABLE
@ FUNC_CODE_DEBUG_RECORD_DECLARE
@ FUNC_CODE_OPERAND_BUNDLE
@ FIRST_APPLICATION_ABBREV
@ PARAMATTR_GRP_CODE_ENTRY
initializer< Ty > init(const Ty &Val)
@ DW_APPLE_ENUM_KIND_invalid
Enum kind for invalid results.
LLVM_ABI Error build(ArrayRef< Module * > Mods, SmallVector< char, 0 > &Symtab, StringTableBuilder &StrtabBuilder, BumpPtrAllocator &Alloc)
Fills in Symtab and StrtabBuilder with a valid symbol and string table for Mods.
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract_or_null(Y &&MD)
Extract a Value from Metadata, allowing null.
LLVM_ABI bool metadataIncludesAllContextSizeInfo()
Whether the alloc memeprof metadata will include context size info for all MIBs.
template LLVM_ABI llvm::DenseMap< LinearFrameId, FrameStat > computeFrameHistogram< LinearFrameId >(llvm::MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &MemProfCallStackData)
LLVM_ABI bool metadataMayIncludeContextSizeInfo()
Whether the alloc memprof metadata may include context size info for some MIBs (but possibly not all)...
NodeAddr< CodeNode * > Code
void write32le(void *P, uint32_t V)
uint32_t read32be(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
FunctionAddr VTableAddr Value
StringMapEntry< Value * > ValueName
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
std::unordered_set< GlobalValueSummary * > GVSummaryPtrSet
A set of global value summary pointers.
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
LLVM_ABI void WriteBitcodeToFile(const Module &M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the specified raw output stream.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
LLVM_ABI void writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the given raw output...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
LLVM_ABI void writeIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out, const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex=nullptr, const GVSummaryPtrSet *DecSummaries=nullptr)
Write the specified module summary index to the given raw output stream, where it will be written in ...
LLVM_ABI void embedBitcodeInModule(Module &M, MemoryBufferRef Buf, bool EmbedBitcode, bool EmbedCmdline, const std::vector< uint8_t > &CmdArgs)
If EmbedBitcode is set, save a copy of the llvm IR as data in the __LLVM,__bitcode section (....
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
FunctionAddr VTableAddr Count
std::map< std::string, GVSummaryMapTy, std::less<> > ModuleToSummariesForIndexTy
Map of a module name to the GUIDs and summaries we will import from that module.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
AtomicOrdering
Atomic ordering for LLVM's memory model.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt copy(R &&Range, OutputIt Out)
constexpr unsigned BitWidth
LLVM_ABI Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue, Dwarf64StrOffsetsPromotion StrOffsetsOptValue)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
bool isBitcode(const unsigned char *BufPtr, const unsigned char *BufEnd)
isBitcode - Return true if the given bytes are the magic bytes for LLVM IR bitcode,...
void consumeError(Error Err)
Consume a Error without doing anything.
LLVM_ABI GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallVectorImpl< GlobalValue * > &Vec, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
This struct is a compact representation of a valid (non-zero power of two) alignment.
static void set(StorageType &Packed, typename Bitfield::Type Value)
Sets the typed value in the provided Packed value.
Class to accumulate and hold information about a callee.
Flags specific to function summaries.
static constexpr uint32_t RangeWidth
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
static const Target * lookupTarget(StringRef TripleStr, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
Struct that holds a reference to a particular GUID in a global value summary.
uint64_t Info
Additional information for the resolution:
enum llvm::WholeProgramDevirtResolution::ByArg::Kind TheKind
enum llvm::WholeProgramDevirtResolution::Kind TheKind
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument,...
std::string SingleImplName