33#include "llvm/Config/llvm-config.h"
95 cl::desc(
"Number of metadatas above which we emit an index "
96 "to enable lazy-loading"));
99 cl::desc(
"The threshold (unit M) for flushing LLVM bitcode."));
119 cl::desc(
"Preserve use-list order when writing LLVM bitcode."));
134 VST_BBENTRY_6_ABBREV,
138 CONSTANTS_INTEGER_ABBREV,
139 CONSTANTS_CE_CAST_Abbrev,
140 CONSTANTS_NULL_Abbrev,
144 FUNCTION_INST_STORE_ABBREV,
145 FUNCTION_INST_UNOP_ABBREV,
146 FUNCTION_INST_UNOP_FLAGS_ABBREV,
147 FUNCTION_INST_BINOP_ABBREV,
148 FUNCTION_INST_BINOP_FLAGS_ABBREV,
149 FUNCTION_INST_CAST_ABBREV,
150 FUNCTION_INST_CAST_FLAGS_ABBREV,
151 FUNCTION_INST_RET_VOID_ABBREV,
152 FUNCTION_INST_RET_VAL_ABBREV,
153 FUNCTION_INST_BR_UNCOND_ABBREV,
154 FUNCTION_INST_BR_COND_ABBREV,
155 FUNCTION_INST_UNREACHABLE_ABBREV,
156 FUNCTION_INST_GEP_ABBREV,
157 FUNCTION_INST_CMP_ABBREV,
158 FUNCTION_INST_CMP_FLAGS_ABBREV,
159 FUNCTION_DEBUG_RECORD_VALUE_ABBREV,
160 FUNCTION_DEBUG_LOC_ABBREV,
165class BitcodeWriterBase {
168 BitstreamWriter &Stream;
170 StringTableBuilder &StrtabBuilder;
175 BitcodeWriterBase(BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder)
176 : Stream(Stream), StrtabBuilder(StrtabBuilder) {}
179 void writeModuleVersion();
182void BitcodeWriterBase::writeModuleVersion() {
189class ModuleBitcodeWriterBase :
public BitcodeWriterBase {
198 const ModuleSummaryIndex *Index;
203 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
206 unsigned GlobalValueId;
210 uint64_t VSTOffsetPlaceholder = 0;
215 ModuleBitcodeWriterBase(
const Module &M, StringTableBuilder &StrtabBuilder,
216 BitstreamWriter &Stream,
217 bool ShouldPreserveUseListOrder,
218 const ModuleSummaryIndex *Index)
219 : BitcodeWriterBase(Stream, StrtabBuilder),
M(
M),
222 : ShouldPreserveUseListOrder),
232 for (
const auto &GUIDSummaryLists : *Index)
234 for (
auto &Summary : GUIDSummaryLists.second.getSummaryList())
240 for (auto &CallEdge : FS->calls())
241 if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
242 assignValueId(CallEdge.first.getGUID());
248 for (auto &RefEdge : FS->refs())
249 if (!RefEdge.haveGVs() || !RefEdge.getValue())
250 assignValueId(RefEdge.getGUID());
255 void writePerModuleGlobalValueSummary();
258 void writePerModuleFunctionSummaryRecord(
259 SmallVector<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
260 unsigned ValueID,
unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
261 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
const Function &
F,
262 DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
264 void writeModuleLevelReferences(
const GlobalVariable &V,
265 SmallVector<uint64_t, 64> &NameVals,
266 unsigned FSModRefsAbbrev,
267 unsigned FSModVTableRefsAbbrev);
270 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
274 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
277 assert(VMI != GUIDToValueIdMap.end() &&
278 "GUID does not have assigned value Id");
283 unsigned getValueId(ValueInfo VI) {
284 if (!
VI.haveGVs() || !
VI.getValue())
285 return getValueId(
VI.getGUID());
289 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
293class ModuleBitcodeWriter :
public ModuleBitcodeWriterBase {
304 uint64_t BitcodeStartBit;
309 ModuleBitcodeWriter(
const Module &M, StringTableBuilder &StrtabBuilder,
310 BitstreamWriter &Stream,
bool ShouldPreserveUseListOrder,
311 const ModuleSummaryIndex *Index,
bool GenerateHash,
313 : ModuleBitcodeWriterBase(
M, StrtabBuilder, Stream,
314 ShouldPreserveUseListOrder,
Index),
315 GenerateHash(GenerateHash), ModHash(ModHash),
316 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
322 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
324 size_t addToStrtab(StringRef Str);
326 void writeAttributeGroupTable();
327 void writeAttributeTable();
328 void writeTypeTable();
330 void writeValueSymbolTableForwardDecl();
331 void writeModuleInfo();
332 void writeValueAsMetadata(
const ValueAsMetadata *MD,
333 SmallVectorImpl<uint64_t> &Record);
334 void writeMDTuple(
const MDTuple *
N, SmallVectorImpl<uint64_t> &Record,
336 unsigned createDILocationAbbrev();
337 void writeDILocation(
const DILocation *
N, SmallVectorImpl<uint64_t> &Record,
339 unsigned createGenericDINodeAbbrev();
341 SmallVectorImpl<uint64_t> &Record,
unsigned &Abbrev);
342 void writeDISubrange(
const DISubrange *
N, SmallVectorImpl<uint64_t> &Record,
345 SmallVectorImpl<uint64_t> &Record,
348 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
352 SmallVectorImpl<uint64_t> &Record,
355 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
357 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
359 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
361 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
363 SmallVectorImpl<uint64_t> &Record,
365 void writeDIFile(
const DIFile *
N, SmallVectorImpl<uint64_t> &Record,
368 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
370 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
372 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
374 SmallVectorImpl<uint64_t> &Record,
377 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
380 void writeDIMacro(
const DIMacro *
N, SmallVectorImpl<uint64_t> &Record,
384 void writeDIArgList(
const DIArgList *
N, SmallVectorImpl<uint64_t> &Record);
385 void writeDIModule(
const DIModule *
N, SmallVectorImpl<uint64_t> &Record,
387 void writeDIAssignID(
const DIAssignID *
N, SmallVectorImpl<uint64_t> &Record,
390 SmallVectorImpl<uint64_t> &Record,
393 SmallVectorImpl<uint64_t> &Record,
396 SmallVectorImpl<uint64_t> &Record,
399 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
401 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
403 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
405 SmallVectorImpl<uint64_t> &Record,
408 SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev);
410 SmallVectorImpl<uint64_t> &Record,
412 unsigned createNamedMetadataAbbrev();
413 void writeNamedMetadata(SmallVectorImpl<uint64_t> &Record);
414 unsigned createMetadataStringsAbbrev();
416 SmallVectorImpl<uint64_t> &Record);
418 SmallVectorImpl<uint64_t> &Record,
419 std::vector<unsigned> *MDAbbrevs =
nullptr,
420 std::vector<uint64_t> *IndexPos =
nullptr);
421 void writeModuleMetadata();
422 void writeFunctionMetadata(
const Function &
F);
423 void writeFunctionMetadataAttachment(
const Function &
F);
424 void pushGlobalMetadataAttachment(SmallVectorImpl<uint64_t> &Record,
425 const GlobalObject &GO);
426 void writeModuleMetadataKinds();
427 void writeOperandBundleTags();
428 void writeSyncScopeNames();
429 void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
430 void writeModuleConstants();
431 bool pushValueAndType(
const Value *V,
unsigned InstID,
432 SmallVectorImpl<unsigned> &Vals);
433 bool pushValueOrMetadata(
const Value *V,
unsigned InstID,
434 SmallVectorImpl<unsigned> &Vals);
435 void writeOperandBundles(
const CallBase &CB,
unsigned InstID);
436 void pushValue(
const Value *V,
unsigned InstID,
437 SmallVectorImpl<unsigned> &Vals);
438 void pushValueSigned(
const Value *V,
unsigned InstID,
439 SmallVectorImpl<uint64_t> &Vals);
440 void writeInstruction(
const Instruction &
I,
unsigned InstID,
441 SmallVectorImpl<unsigned> &Vals);
442 void writeFunctionLevelValueSymbolTable(
const ValueSymbolTable &VST);
443 void writeGlobalValueSymbolTable(
444 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
445 void writeUseList(UseListOrder &&Order);
446 void writeUseListBlock(
const Function *
F);
448 writeFunction(
const Function &
F,
449 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
450 void writeBlockInfo();
451 void writeModuleHash(StringRef View);
454 return unsigned(SSID);
457 unsigned getEncodedAlign(MaybeAlign Alignment) {
return encode(Alignment); }
461class IndexBitcodeWriter :
public BitcodeWriterBase {
463 const ModuleSummaryIndex &
Index;
476 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
480 std::vector<uint64_t> StackIds;
485 DenseMap<unsigned, unsigned> StackIdIndicesToIndex;
488 unsigned GlobalValueId = 0;
492 DenseMap<StringRef, uint64_t> ModuleIdMap;
502 BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder,
503 const ModuleSummaryIndex &Index,
506 : BitcodeWriterBase(Stream, StrtabBuilder),
Index(
Index),
507 DecSummaries(DecSummaries),
508 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
512 auto RecordStackIdReference = [&](
unsigned StackIdIndex) {
517 StackIdIndicesToIndex.
insert({StackIdIndex, StackIds.size()});
519 StackIds.push_back(
Index.getStackIdAtIndex(StackIdIndex));
526 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
527 GUIDToValueIdMap[
I.first] = ++GlobalValueId;
539 for (
auto &CI :
FS->callsites()) {
550 if (CI.StackIdIndices.empty()) {
551 GUIDToValueIdMap[CI.Callee.getGUID()] = ++GlobalValueId;
554 for (
auto Idx : CI.StackIdIndices)
555 RecordStackIdReference(Idx);
558 for (
auto &AI :
FS->allocs())
559 for (
auto &MIB : AI.MIBs)
560 for (
auto Idx : MIB.StackIdIndices)
561 RecordStackIdReference(Idx);
567 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
572 template<
typename Functor>
573 void forEachSummary(Functor Callback) {
574 if (ModuleToSummariesForIndex) {
575 for (
auto &M : *ModuleToSummariesForIndex)
576 for (
auto &Summary :
M.second) {
582 Callback({AS->getAliaseeGUID(), &AS->getAliasee()},
true);
585 for (
auto &Summaries : Index)
586 for (
auto &Summary : Summaries.second.getSummaryList())
595 template <
typename Functor>
void forEachModule(Functor Callback) {
596 if (ModuleToSummariesForIndex) {
597 for (
const auto &M : *ModuleToSummariesForIndex) {
598 const auto &MPI =
Index.modulePaths().find(
M.first);
599 if (MPI ==
Index.modulePaths().end()) {
603 assert(ModuleToSummariesForIndex->size() == 1);
613 std::vector<StringRef> ModulePaths;
614 for (
auto &[ModPath,
_] :
Index.modulePaths())
615 ModulePaths.push_back(ModPath);
617 for (
auto &ModPath : ModulePaths)
626 void writeModStrings();
627 void writeCombinedGlobalValueSummary();
630 auto VMI = GUIDToValueIdMap.find(ValGUID);
631 if (VMI == GUIDToValueIdMap.end())
636 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
671 case Instruction::Add:
673 case Instruction::Sub:
675 case Instruction::Mul:
678 case Instruction::FDiv:
681 case Instruction::FRem:
755 case Attribute::Alignment:
757 case Attribute::AllocAlign:
759 case Attribute::AllocSize:
761 case Attribute::AlwaysInline:
763 case Attribute::Builtin:
765 case Attribute::ByVal:
767 case Attribute::Convergent:
769 case Attribute::InAlloca:
771 case Attribute::Cold:
773 case Attribute::DisableSanitizerInstrumentation:
775 case Attribute::FnRetThunkExtern:
779 case Attribute::ElementType:
781 case Attribute::HybridPatchable:
783 case Attribute::InlineHint:
785 case Attribute::InReg:
787 case Attribute::JumpTable:
789 case Attribute::MinSize:
791 case Attribute::AllocatedPointer:
793 case Attribute::AllocKind:
795 case Attribute::Memory:
797 case Attribute::NoFPClass:
799 case Attribute::Naked:
801 case Attribute::Nest:
803 case Attribute::NoAlias:
805 case Attribute::NoBuiltin:
807 case Attribute::NoCallback:
809 case Attribute::NoDivergenceSource:
811 case Attribute::NoDuplicate:
813 case Attribute::NoFree:
815 case Attribute::NoImplicitFloat:
817 case Attribute::NoInline:
819 case Attribute::NoRecurse:
821 case Attribute::NoMerge:
823 case Attribute::NonLazyBind:
825 case Attribute::NonNull:
827 case Attribute::Dereferenceable:
829 case Attribute::DereferenceableOrNull:
831 case Attribute::NoRedZone:
833 case Attribute::NoReturn:
835 case Attribute::NoSync:
837 case Attribute::NoCfCheck:
839 case Attribute::NoProfile:
841 case Attribute::SkipProfile:
843 case Attribute::NoUnwind:
845 case Attribute::NoSanitizeBounds:
847 case Attribute::NoSanitizeCoverage:
849 case Attribute::NullPointerIsValid:
851 case Attribute::OptimizeForDebugging:
853 case Attribute::OptForFuzzing:
855 case Attribute::OptimizeForSize:
857 case Attribute::OptimizeNone:
859 case Attribute::ReadNone:
861 case Attribute::ReadOnly:
863 case Attribute::Returned:
865 case Attribute::ReturnsTwice:
867 case Attribute::SExt:
869 case Attribute::Speculatable:
871 case Attribute::StackAlignment:
873 case Attribute::StackProtect:
875 case Attribute::StackProtectReq:
877 case Attribute::StackProtectStrong:
879 case Attribute::SafeStack:
881 case Attribute::ShadowCallStack:
883 case Attribute::StrictFP:
885 case Attribute::StructRet:
887 case Attribute::SanitizeAddress:
889 case Attribute::SanitizeAllocToken:
891 case Attribute::SanitizeHWAddress:
893 case Attribute::SanitizeThread:
895 case Attribute::SanitizeType:
897 case Attribute::SanitizeMemory:
899 case Attribute::SanitizeNumericalStability:
901 case Attribute::SanitizeRealtime:
903 case Attribute::SanitizeRealtimeBlocking:
905 case Attribute::SpeculativeLoadHardening:
907 case Attribute::SwiftError:
909 case Attribute::SwiftSelf:
911 case Attribute::SwiftAsync:
913 case Attribute::UWTable:
915 case Attribute::VScaleRange:
917 case Attribute::WillReturn:
919 case Attribute::WriteOnly:
921 case Attribute::ZExt:
923 case Attribute::ImmArg:
925 case Attribute::SanitizeMemTag:
927 case Attribute::Preallocated:
929 case Attribute::NoUndef:
931 case Attribute::ByRef:
933 case Attribute::MustProgress:
935 case Attribute::PresplitCoroutine:
937 case Attribute::Writable:
939 case Attribute::CoroDestroyOnlyWhenComplete:
941 case Attribute::CoroElideSafe:
943 case Attribute::DeadOnUnwind:
945 case Attribute::Range:
947 case Attribute::Initializes:
949 case Attribute::NoExt:
951 case Attribute::Captures:
953 case Attribute::DeadOnReturn:
955 case Attribute::NoCreateUndefOrPoison:
981 unsigned NumWords =
A.getActiveWords();
982 const uint64_t *RawData =
A.getRawData();
983 for (
unsigned i = 0; i < NumWords; i++)
1003void ModuleBitcodeWriter::writeAttributeGroupTable() {
1004 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
1006 if (AttrGrps.empty())
return;
1010 SmallVector<uint64_t, 64>
Record;
1012 unsigned AttrListIndex = Pair.first;
1013 AttributeSet AS = Pair.second;
1015 Record.push_back(AttrListIndex);
1018 if (Attr.isEnumAttribute()) {
1021 }
else if (Attr.isIntAttribute()) {
1023 Attribute::AttrKind
Kind = Attr.getKindAsEnum();
1025 if (Kind == Attribute::Memory) {
1030 Record.push_back(Attr.getValueAsInt());
1032 }
else if (Attr.isStringAttribute()) {
1033 StringRef
Kind = Attr.getKindAsString();
1034 StringRef Val = Attr.getValueAsString();
1043 }
else if (Attr.isTypeAttribute()) {
1044 Type *Ty = Attr.getValueAsType();
1045 Record.push_back(Ty ? 6 : 5);
1049 }
else if (Attr.isConstantRangeAttribute()) {
1055 assert(Attr.isConstantRangeListAttribute());
1061 for (
auto &CR : Val)
1073void ModuleBitcodeWriter::writeAttributeTable() {
1075 if (
Attrs.empty())
return;
1079 SmallVector<uint64_t, 64>
Record;
1080 for (
const AttributeList &AL : Attrs) {
1081 for (
unsigned i :
AL.indexes()) {
1082 AttributeSet AS =
AL.getAttributes(i);
1095void ModuleBitcodeWriter::writeTypeTable() {
1099 SmallVector<uint64_t, 64> TypeVals;
1104 auto Abbv = std::make_shared<BitCodeAbbrev>();
1106 Abbv->Add(BitCodeAbbrevOp(0));
1107 unsigned OpaquePtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1110 Abbv = std::make_shared<BitCodeAbbrev>();
1115 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1118 Abbv = std::make_shared<BitCodeAbbrev>();
1123 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1126 Abbv = std::make_shared<BitCodeAbbrev>();
1130 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1133 Abbv = std::make_shared<BitCodeAbbrev>();
1138 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1141 Abbv = std::make_shared<BitCodeAbbrev>();
1145 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1153 for (
Type *
T : TypeList) {
1154 int AbbrevToUse = 0;
1157 switch (
T->getTypeID()) {
1167 case Type::MetadataTyID:
1172 case Type::IntegerTyID:
1177 case Type::PointerTyID: {
1184 AbbrevToUse = OpaquePtrAbbrev;
1187 case Type::FunctionTyID: {
1193 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1195 AbbrevToUse = FunctionAbbrev;
1198 case Type::StructTyID: {
1203 for (
Type *ET :
ST->elements())
1206 if (
ST->isLiteral()) {
1208 AbbrevToUse = StructAnonAbbrev;
1210 if (
ST->isOpaque()) {
1214 AbbrevToUse = StructNamedAbbrev;
1218 if (!
ST->getName().empty())
1224 case Type::ArrayTyID: {
1228 TypeVals.
push_back(AT->getNumElements());
1230 AbbrevToUse = ArrayAbbrev;
1233 case Type::FixedVectorTyID:
1234 case Type::ScalableVectorTyID: {
1239 TypeVals.
push_back(VT->getElementCount().getKnownMinValue());
1245 case Type::TargetExtTyID: {
1251 for (
Type *InnerTy :
TET->type_params())
1256 case Type::TypedPointerTyID:
1261 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
1302 RawFlags |= Flags.ReadNone;
1303 RawFlags |= (Flags.ReadOnly << 1);
1304 RawFlags |= (Flags.NoRecurse << 2);
1305 RawFlags |= (Flags.ReturnDoesNotAlias << 3);
1306 RawFlags |= (Flags.NoInline << 4);
1307 RawFlags |= (Flags.AlwaysInline << 5);
1308 RawFlags |= (Flags.NoUnwind << 6);
1309 RawFlags |= (Flags.MayThrow << 7);
1310 RawFlags |= (Flags.HasUnknownCall << 8);
1311 RawFlags |= (Flags.MustBeUnreachable << 9);
1318 bool ImportAsDecl =
false) {
1321 RawFlags |= Flags.NotEligibleToImport;
1322 RawFlags |= (Flags.Live << 1);
1323 RawFlags |= (Flags.DSOLocal << 2);
1324 RawFlags |= (Flags.CanAutoHide << 3);
1329 RawFlags = (RawFlags << 4) | Flags.Linkage;
1331 RawFlags |= (Flags.Visibility << 8);
1333 unsigned ImportType = Flags.ImportType | ImportAsDecl;
1334 RawFlags |= (ImportType << 10);
1340 uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1341 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1384 switch (
C.getSelectionKind()) {
1408size_t ModuleBitcodeWriter::addToStrtab(StringRef Str) {
1411 return StrtabBuilder.
add(Str);
1414void ModuleBitcodeWriter::writeComdats() {
1429void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1434 auto Abbv = std::make_shared<BitCodeAbbrev>();
1440 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1456 bool isChar6 =
true;
1457 for (
char C : Str) {
1460 if ((
unsigned char)
C & 128)
1469static_assert(
sizeof(GlobalValue::SanitizerMetadata) <=
sizeof(unsigned),
1470 "Sanitizer Metadata is too large for naive serialization.");
1473 return Meta.NoAddress | (
Meta.NoHWAddress << 1) |
1474 (
Meta.Memtag << 2) | (
Meta.IsDynInit << 3);
1480void ModuleBitcodeWriter::writeModuleInfo() {
1482 if (!
M.getTargetTriple().empty())
1484 M.getTargetTriple().str(), 0 );
1485 const std::string &
DL =
M.getDataLayoutStr();
1488 if (!
M.getModuleInlineAsm().empty())
1494 std::map<std::string, unsigned> SectionMap;
1495 std::map<std::string, unsigned> GCMap;
1496 MaybeAlign MaxGVarAlignment;
1497 unsigned MaxGlobalType = 0;
1498 for (
const GlobalVariable &GV :
M.globals()) {
1499 if (MaybeAlign
A = GV.getAlign())
1500 MaxGVarAlignment = !MaxGVarAlignment ? *
A : std::max(*MaxGVarAlignment, *
A);
1501 MaxGlobalType = std::max(MaxGlobalType, VE.
getTypeID(GV.getValueType()));
1502 if (GV.hasSection()) {
1504 unsigned &
Entry = SectionMap[std::string(GV.getSection())];
1508 Entry = SectionMap.size();
1512 for (
const Function &
F : M) {
1513 if (
F.hasSection()) {
1515 unsigned &
Entry = SectionMap[std::string(
F.getSection())];
1519 Entry = SectionMap.size();
1524 unsigned &
Entry = GCMap[
F.getGC()];
1528 Entry = GCMap.size();
1534 unsigned SimpleGVarAbbrev = 0;
1535 if (!
M.global_empty()) {
1537 auto Abbv = std::make_shared<BitCodeAbbrev>();
1548 if (!MaxGVarAlignment)
1549 Abbv->Add(BitCodeAbbrevOp(0));
1551 unsigned MaxEncAlignment = getEncodedAlign(MaxGVarAlignment);
1555 if (SectionMap.empty())
1556 Abbv->Add(BitCodeAbbrevOp(0));
1561 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1575 auto Abbv = std::make_shared<BitCodeAbbrev>();
1578 Abbv->Add(AbbrevOpToUse);
1579 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1581 for (
const auto P :
M.getSourceFileName())
1590 for (
const GlobalVariable &GV :
M.globals()) {
1591 unsigned AbbrevToUse = 0;
1597 Vals.
push_back(addToStrtab(GV.getName()));
1600 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1604 Vals.
push_back(getEncodedAlign(GV.getAlign()));
1605 Vals.
push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1607 if (GV.isThreadLocal() ||
1609 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1610 GV.isExternallyInitialized() ||
1612 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1613 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1617 Vals.
push_back(GV.isExternallyInitialized());
1621 auto AL = GV.getAttributesAsList(AttributeList::FunctionIndex);
1625 Vals.
push_back(addToStrtab(GV.getPartition()));
1626 Vals.
push_back(GV.getPartition().size());
1629 GV.getSanitizerMetadata())
1633 AbbrevToUse = SimpleGVarAbbrev;
1641 for (
const Function &
F : M) {
1653 Vals.
push_back(getEncodedAlign(
F.getAlign()));
1654 Vals.
push_back(
F.hasSection() ? SectionMap[std::string(
F.getSection())]
1666 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1670 Vals.
push_back(addToStrtab(
F.getPartition()));
1673 unsigned AbbrevToUse = 0;
1679 for (
const GlobalAlias &
A :
M.aliases()) {
1686 Vals.
push_back(
A.getType()->getAddressSpace());
1694 Vals.
push_back(addToStrtab(
A.getPartition()));
1697 unsigned AbbrevToUse = 0;
1703 for (
const GlobalIFunc &
I :
M.ifuncs()) {
1709 Vals.
push_back(
I.getType()->getAddressSpace());
1714 Vals.
push_back(addToStrtab(
I.getPartition()));
1720 writeValueSymbolTableForwardDecl();
1727 if (OBO->hasNoSignedWrap())
1729 if (OBO->hasNoUnsignedWrap())
1735 if (PDI->isDisjoint())
1738 if (FPMO->hasAllowReassoc())
1740 if (FPMO->hasNoNaNs())
1742 if (FPMO->hasNoInfs())
1744 if (FPMO->hasNoSignedZeros())
1746 if (FPMO->hasAllowReciprocal())
1748 if (FPMO->hasAllowContract())
1750 if (FPMO->hasApproxFunc())
1753 if (NNI->hasNonNeg())
1756 if (TI->hasNoSignedWrap())
1758 if (TI->hasNoUnsignedWrap())
1761 if (
GEP->isInBounds())
1763 if (
GEP->hasNoUnsignedSignedWrap())
1765 if (
GEP->hasNoUnsignedWrap())
1768 if (ICmp->hasSameSign())
1775void ModuleBitcodeWriter::writeValueAsMetadata(
1776 const ValueAsMetadata *MD, SmallVectorImpl<uint64_t> &Record) {
1785void ModuleBitcodeWriter::writeMDTuple(
const MDTuple *
N,
1786 SmallVectorImpl<uint64_t> &Record,
1788 for (
const MDOperand &MDO :
N->operands()) {
1791 "Unexpected function-local metadata");
1800unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1803 auto Abbv = std::make_shared<BitCodeAbbrev>();
1816void ModuleBitcodeWriter::writeDILocation(
const DILocation *
N,
1817 SmallVectorImpl<uint64_t> &Record,
1820 Abbrev = createDILocationAbbrev();
1822 Record.push_back(
N->isDistinct());
1823 Record.push_back(
N->getLine());
1824 Record.push_back(
N->getColumn());
1827 Record.push_back(
N->isImplicitCode());
1828 Record.push_back(
N->getAtomGroup());
1829 Record.push_back(
N->getAtomRank());
1834unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1837 auto Abbv = std::make_shared<BitCodeAbbrev>();
1848void ModuleBitcodeWriter::writeGenericDINode(
const GenericDINode *
N,
1849 SmallVectorImpl<uint64_t> &Record,
1852 Abbrev = createGenericDINodeAbbrev();
1854 Record.push_back(
N->isDistinct());
1855 Record.push_back(
N->getTag());
1858 for (
auto &
I :
N->operands())
1865void ModuleBitcodeWriter::writeDISubrange(
const DISubrange *
N,
1866 SmallVectorImpl<uint64_t> &Record,
1868 const uint64_t
Version = 2 << 1;
1879void ModuleBitcodeWriter::writeDIGenericSubrange(
1880 const DIGenericSubrange *
N, SmallVectorImpl<uint64_t> &Record,
1882 Record.push_back((uint64_t)
N->isDistinct());
1892void ModuleBitcodeWriter::writeDIEnumerator(
const DIEnumerator *
N,
1893 SmallVectorImpl<uint64_t> &Record,
1895 const uint64_t IsBigInt = 1 << 2;
1896 Record.push_back(IsBigInt | (
N->isUnsigned() << 1) |
N->isDistinct());
1897 Record.push_back(
N->getValue().getBitWidth());
1905void ModuleBitcodeWriter::writeDIBasicType(
const DIBasicType *
N,
1906 SmallVectorImpl<uint64_t> &Record,
1908 const unsigned SizeIsMetadata = 0x2;
1909 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1910 Record.push_back(
N->getTag());
1913 Record.push_back(
N->getAlignInBits());
1914 Record.push_back(
N->getEncoding());
1915 Record.push_back(
N->getFlags());
1916 Record.push_back(
N->getNumExtraInhabitants());
1917 Record.push_back(
N->getDataSizeInBits());
1923void ModuleBitcodeWriter::writeDIFixedPointType(
1924 const DIFixedPointType *
N, SmallVectorImpl<uint64_t> &Record,
1926 const unsigned SizeIsMetadata = 0x2;
1927 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1928 Record.push_back(
N->getTag());
1931 Record.push_back(
N->getAlignInBits());
1932 Record.push_back(
N->getEncoding());
1933 Record.push_back(
N->getFlags());
1934 Record.push_back(
N->getKind());
1935 Record.push_back(
N->getFactorRaw());
1937 auto WriteWideInt = [&](
const APInt &
Value) {
1940 uint64_t NumWords =
Value.getActiveWords();
1941 uint64_t
Encoded = (NumWords << 32) |
Value.getBitWidth();
1942 Record.push_back(Encoded);
1946 WriteWideInt(
N->getNumeratorRaw());
1947 WriteWideInt(
N->getDenominatorRaw());
1953void ModuleBitcodeWriter::writeDIStringType(
const DIStringType *
N,
1954 SmallVectorImpl<uint64_t> &Record,
1956 const unsigned SizeIsMetadata = 0x2;
1957 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1958 Record.push_back(
N->getTag());
1964 Record.push_back(
N->getAlignInBits());
1965 Record.push_back(
N->getEncoding());
1971void ModuleBitcodeWriter::writeDIDerivedType(
const DIDerivedType *
N,
1972 SmallVectorImpl<uint64_t> &Record,
1974 const unsigned SizeIsMetadata = 0x2;
1975 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1976 Record.push_back(
N->getTag());
1979 Record.push_back(
N->getLine());
1983 Record.push_back(
N->getAlignInBits());
1985 Record.push_back(
N->getFlags());
1990 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
1991 Record.push_back(*DWARFAddressSpace + 1);
1997 if (
auto PtrAuthData =
N->getPtrAuthData())
1998 Record.push_back(PtrAuthData->RawData);
2006void ModuleBitcodeWriter::writeDISubrangeType(
const DISubrangeType *
N,
2007 SmallVectorImpl<uint64_t> &Record,
2009 const unsigned SizeIsMetadata = 0x2;
2010 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2013 Record.push_back(
N->getLine());
2016 Record.push_back(
N->getAlignInBits());
2017 Record.push_back(
N->getFlags());
2028void ModuleBitcodeWriter::writeDICompositeType(
2029 const DICompositeType *
N, SmallVectorImpl<uint64_t> &Record,
2031 const unsigned IsNotUsedInOldTypeRef = 0x2;
2032 const unsigned SizeIsMetadata = 0x4;
2033 Record.push_back(SizeIsMetadata | IsNotUsedInOldTypeRef |
2034 (
unsigned)
N->isDistinct());
2035 Record.push_back(
N->getTag());
2038 Record.push_back(
N->getLine());
2042 Record.push_back(
N->getAlignInBits());
2044 Record.push_back(
N->getFlags());
2046 Record.push_back(
N->getRuntimeLang());
2056 Record.push_back(
N->getNumExtraInhabitants());
2066void ModuleBitcodeWriter::writeDISubroutineType(
2067 const DISubroutineType *
N, SmallVectorImpl<uint64_t> &Record,
2069 const unsigned HasNoOldTypeRefs = 0x2;
2070 Record.push_back(HasNoOldTypeRefs | (
unsigned)
N->isDistinct());
2071 Record.push_back(
N->getFlags());
2079void ModuleBitcodeWriter::writeDIFile(
const DIFile *
N,
2080 SmallVectorImpl<uint64_t> &Record,
2082 Record.push_back(
N->isDistinct());
2085 if (
N->getRawChecksum()) {
2086 Record.push_back(
N->getRawChecksum()->Kind);
2094 auto Source =
N->getRawSource();
2102void ModuleBitcodeWriter::writeDICompileUnit(
const DICompileUnit *
N,
2103 SmallVectorImpl<uint64_t> &Record,
2105 assert(
N->isDistinct() &&
"Expected distinct compile units");
2108 auto Lang =
N->getSourceLanguage();
2109 Record.push_back(Lang.getName());
2112 if (Lang.hasVersionedName())
2113 Record.back() ^= (uint64_t(1) << 63);
2117 Record.push_back(
N->isOptimized());
2119 Record.push_back(
N->getRuntimeVersion());
2121 Record.push_back(
N->getEmissionKind());
2127 Record.push_back(
N->getDWOId());
2129 Record.push_back(
N->getSplitDebugInlining());
2130 Record.push_back(
N->getDebugInfoForProfiling());
2131 Record.push_back((
unsigned)
N->getNameTableKind());
2132 Record.push_back(
N->getRangesBaseAddress());
2135 Record.push_back(Lang.hasVersionedName() ? Lang.getVersion() : 0);
2141void ModuleBitcodeWriter::writeDISubprogram(
const DISubprogram *
N,
2142 SmallVectorImpl<uint64_t> &Record,
2144 const uint64_t HasUnitFlag = 1 << 1;
2145 const uint64_t HasSPFlagsFlag = 1 << 2;
2146 Record.push_back(uint64_t(
N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
2151 Record.push_back(
N->getLine());
2153 Record.push_back(
N->getScopeLine());
2155 Record.push_back(
N->getSPFlags());
2156 Record.push_back(
N->getVirtualIndex());
2157 Record.push_back(
N->getFlags());
2162 Record.push_back(
N->getThisAdjustment());
2166 Record.push_back(
N->getKeyInstructionsEnabled());
2172void ModuleBitcodeWriter::writeDILexicalBlock(
const DILexicalBlock *
N,
2173 SmallVectorImpl<uint64_t> &Record,
2175 Record.push_back(
N->isDistinct());
2178 Record.push_back(
N->getLine());
2179 Record.push_back(
N->getColumn());
2185void ModuleBitcodeWriter::writeDILexicalBlockFile(
2186 const DILexicalBlockFile *
N, SmallVectorImpl<uint64_t> &Record,
2188 Record.push_back(
N->isDistinct());
2191 Record.push_back(
N->getDiscriminator());
2197void ModuleBitcodeWriter::writeDICommonBlock(
const DICommonBlock *
N,
2198 SmallVectorImpl<uint64_t> &Record,
2200 Record.push_back(
N->isDistinct());
2205 Record.push_back(
N->getLineNo());
2211void ModuleBitcodeWriter::writeDINamespace(
const DINamespace *
N,
2212 SmallVectorImpl<uint64_t> &Record,
2214 Record.push_back(
N->isDistinct() |
N->getExportSymbols() << 1);
2222void ModuleBitcodeWriter::writeDIMacro(
const DIMacro *
N,
2223 SmallVectorImpl<uint64_t> &Record,
2225 Record.push_back(
N->isDistinct());
2226 Record.push_back(
N->getMacinfoType());
2227 Record.push_back(
N->getLine());
2235void ModuleBitcodeWriter::writeDIMacroFile(
const DIMacroFile *
N,
2236 SmallVectorImpl<uint64_t> &Record,
2238 Record.push_back(
N->isDistinct());
2239 Record.push_back(
N->getMacinfoType());
2240 Record.push_back(
N->getLine());
2248void ModuleBitcodeWriter::writeDIArgList(
const DIArgList *
N,
2249 SmallVectorImpl<uint64_t> &Record) {
2250 Record.reserve(
N->getArgs().size());
2251 for (ValueAsMetadata *MD :
N->getArgs())
2258void ModuleBitcodeWriter::writeDIModule(
const DIModule *
N,
2259 SmallVectorImpl<uint64_t> &Record,
2261 Record.push_back(
N->isDistinct());
2262 for (
auto &
I :
N->operands())
2264 Record.push_back(
N->getLineNo());
2265 Record.push_back(
N->getIsDecl());
2271void ModuleBitcodeWriter::writeDIAssignID(
const DIAssignID *
N,
2272 SmallVectorImpl<uint64_t> &Record,
2275 Record.push_back(
N->isDistinct());
2280void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2281 const DITemplateTypeParameter *
N, SmallVectorImpl<uint64_t> &Record,
2283 Record.push_back(
N->isDistinct());
2286 Record.push_back(
N->isDefault());
2292void ModuleBitcodeWriter::writeDITemplateValueParameter(
2293 const DITemplateValueParameter *
N, SmallVectorImpl<uint64_t> &Record,
2295 Record.push_back(
N->isDistinct());
2296 Record.push_back(
N->getTag());
2299 Record.push_back(
N->isDefault());
2306void ModuleBitcodeWriter::writeDIGlobalVariable(
2307 const DIGlobalVariable *
N, SmallVectorImpl<uint64_t> &Record,
2309 const uint64_t
Version = 2 << 1;
2315 Record.push_back(
N->getLine());
2317 Record.push_back(
N->isLocalToUnit());
2318 Record.push_back(
N->isDefinition());
2321 Record.push_back(
N->getAlignInBits());
2328void ModuleBitcodeWriter::writeDILocalVariable(
2329 const DILocalVariable *
N, SmallVectorImpl<uint64_t> &Record,
2344 const uint64_t HasAlignmentFlag = 1 << 1;
2345 Record.push_back((uint64_t)
N->isDistinct() | HasAlignmentFlag);
2349 Record.push_back(
N->getLine());
2351 Record.push_back(
N->getArg());
2352 Record.push_back(
N->getFlags());
2353 Record.push_back(
N->getAlignInBits());
2360void ModuleBitcodeWriter::writeDILabel(
2361 const DILabel *
N, SmallVectorImpl<uint64_t> &Record,
2363 uint64_t IsArtificialFlag = uint64_t(
N->isArtificial()) << 1;
2364 Record.push_back((uint64_t)
N->isDistinct() | IsArtificialFlag);
2368 Record.push_back(
N->getLine());
2369 Record.push_back(
N->getColumn());
2370 Record.push_back(
N->getCoroSuspendIdx().has_value()
2371 ? (uint64_t)
N->getCoroSuspendIdx().value()
2372 : std::numeric_limits<uint64_t>::max());
2378void ModuleBitcodeWriter::writeDIExpression(
const DIExpression *
N,
2379 SmallVectorImpl<uint64_t> &Record,
2381 Record.reserve(
N->getElements().size() + 1);
2382 const uint64_t
Version = 3 << 1;
2384 Record.append(
N->elements_begin(),
N->elements_end());
2390void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2391 const DIGlobalVariableExpression *
N, SmallVectorImpl<uint64_t> &Record,
2393 Record.push_back(
N->isDistinct());
2401void ModuleBitcodeWriter::writeDIObjCProperty(
const DIObjCProperty *
N,
2402 SmallVectorImpl<uint64_t> &Record,
2404 Record.push_back(
N->isDistinct());
2407 Record.push_back(
N->getLine());
2410 Record.push_back(
N->getAttributes());
2417void ModuleBitcodeWriter::writeDIImportedEntity(
2418 const DIImportedEntity *
N, SmallVectorImpl<uint64_t> &Record,
2420 Record.push_back(
N->isDistinct());
2421 Record.push_back(
N->getTag());
2424 Record.push_back(
N->getLine());
2433unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2434 auto Abbv = std::make_shared<BitCodeAbbrev>();
2441void ModuleBitcodeWriter::writeNamedMetadata(
2442 SmallVectorImpl<uint64_t> &Record) {
2443 if (
M.named_metadata_empty())
2446 unsigned Abbrev = createNamedMetadataAbbrev();
2447 for (
const NamedMDNode &NMD :
M.named_metadata()) {
2449 StringRef Str = NMD.getName();
2450 Record.append(Str.bytes_begin(), Str.bytes_end());
2455 for (
const MDNode *
N : NMD.operands())
2462unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2463 auto Abbv = std::make_shared<BitCodeAbbrev>();
2475void ModuleBitcodeWriter::writeMetadataStrings(
2477 if (Strings.
empty())
2485 SmallString<256> Blob;
2487 BitstreamWriter
W(Blob);
2507#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
2508#include "llvm/IR/Metadata.def"
2512void ModuleBitcodeWriter::writeMetadataRecords(
2514 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2519#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
2520#include "llvm/IR/Metadata.def"
2526 assert(
N->isResolved() &&
"Expected forward references to be resolved");
2528 switch (
N->getMetadataID()) {
2531#define HANDLE_MDNODE_LEAF(CLASS) \
2532 case Metadata::CLASS##Kind: \
2534 write##CLASS(cast<CLASS>(N), Record, \
2535 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
2537 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
2539#include "llvm/IR/Metadata.def"
2550void ModuleBitcodeWriter::writeModuleMetadata() {
2551 if (!VE.
hasMDs() &&
M.named_metadata_empty())
2555 SmallVector<uint64_t, 64>
Record;
2559 std::vector<unsigned> MDAbbrevs;
2562 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2563 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2564 createGenericDINodeAbbrev();
2566 auto Abbv = std::make_shared<BitCodeAbbrev>();
2570 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2572 Abbv = std::make_shared<BitCodeAbbrev>();
2576 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2588 uint64_t Vals[] = {0, 0};
2598 std::vector<uint64_t> IndexPos;
2602 writeMetadataRecords(VE.
getNonMDStrings(), Record, &MDAbbrevs, &IndexPos);
2613 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2614 for (
auto &Elt : IndexPos) {
2615 auto EltDelta = Elt - PreviousValue;
2616 PreviousValue = Elt;
2625 writeNamedMetadata(Record);
2627 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2628 SmallVector<uint64_t, 4>
Record;
2630 pushGlobalMetadataAttachment(Record, GO);
2633 for (
const Function &
F : M)
2634 if (
F.isDeclaration() &&
F.hasMetadata())
2635 AddDeclAttachedMetadata(
F);
2636 for (
const GlobalIFunc &GI :
M.ifuncs())
2637 if (GI.hasMetadata())
2638 AddDeclAttachedMetadata(GI);
2641 for (
const GlobalVariable &GV :
M.globals())
2642 if (GV.hasMetadata())
2643 AddDeclAttachedMetadata(GV);
2648void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2653 SmallVector<uint64_t, 64>
Record;
2659void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2660 SmallVectorImpl<uint64_t> &Record,
const GlobalObject &GO) {
2664 for (
const auto &
I : MDs) {
2670void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &
F) {
2673 SmallVector<uint64_t, 64>
Record;
2675 if (
F.hasMetadata()) {
2676 pushGlobalMetadataAttachment(Record,
F);
2684 for (
const BasicBlock &BB :
F)
2685 for (
const Instruction &
I : BB) {
2687 I.getAllMetadataOtherThanDebugLoc(MDs);
2690 if (MDs.
empty())
continue;
2694 for (
const auto &[
ID, MD] : MDs) {
2705void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2706 SmallVector<uint64_t, 64>
Record;
2711 M.getMDKindNames(Names);
2713 if (Names.
empty())
return;
2717 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2718 Record.push_back(MDKindID);
2719 StringRef KName = Names[MDKindID];
2729void ModuleBitcodeWriter::writeOperandBundleTags() {
2737 M.getOperandBundleTags(Tags);
2744 SmallVector<uint64_t, 64>
Record;
2746 for (
auto Tag : Tags) {
2756void ModuleBitcodeWriter::writeSyncScopeNames() {
2758 M.getContext().getSyncScopeNames(SSNs);
2764 SmallVector<uint64_t, 64>
Record;
2765 for (
auto SSN : SSNs) {
2766 Record.append(SSN.begin(), SSN.end());
2774void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2776 if (FirstVal == LastVal)
return;
2780 unsigned AggregateAbbrev = 0;
2781 unsigned String8Abbrev = 0;
2782 unsigned CString7Abbrev = 0;
2783 unsigned CString6Abbrev = 0;
2787 auto Abbv = std::make_shared<BitCodeAbbrev>();
2791 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2794 Abbv = std::make_shared<BitCodeAbbrev>();
2798 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2800 Abbv = std::make_shared<BitCodeAbbrev>();
2804 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2806 Abbv = std::make_shared<BitCodeAbbrev>();
2810 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2813 SmallVector<uint64_t, 64>
Record;
2816 Type *LastTy =
nullptr;
2817 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2818 const Value *
V = Vals[i].first;
2820 if (
V->getType() != LastTy) {
2821 LastTy =
V->getType();
2824 CONSTANTS_SETTYPE_ABBREV);
2831 unsigned(
IA->hasSideEffects()) |
unsigned(
IA->isAlignStack()) << 1 |
2832 unsigned(
IA->getDialect() & 1) << 2 |
unsigned(
IA->canThrow()) << 3);
2835 StringRef AsmStr =
IA->getAsmString();
2840 StringRef ConstraintStr =
IA->getConstraintString();
2848 unsigned Code = -1U;
2849 unsigned AbbrevToUse = 0;
2850 if (
C->isNullValue()) {
2857 if (
IV->getBitWidth() <= 64) {
2858 uint64_t
V =
IV->getSExtValue();
2861 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2871 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2875 APInt api = CFP->getValueAPF().bitcastToAPInt();
2877 Record.push_back((p[1] << 48) | (p[0] >> 16));
2878 Record.push_back(p[0] & 0xffffLL);
2880 APInt api = CFP->getValueAPF().bitcastToAPInt();
2885 assert(0 &&
"Unknown FP type!");
2891 uint64_t NumElts = Str->getNumElements();
2893 if (Str->isCString()) {
2898 AbbrevToUse = String8Abbrev;
2902 for (uint64_t i = 0; i != NumElts; ++i) {
2903 unsigned char V = Str->getElementAsInteger(i);
2905 isCStr7 &= (
V & 128) == 0;
2911 AbbrevToUse = CString6Abbrev;
2913 AbbrevToUse = CString7Abbrev;
2914 }
else if (
const ConstantDataSequential *CDS =
2917 Type *EltTy = CDS->getElementType();
2919 for (uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
2920 Record.push_back(CDS->getElementAsInteger(i));
2922 for (uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
2924 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2928 for (
const Value *
Op :
C->operands())
2930 AbbrevToUse = AggregateAbbrev;
2932 switch (
CE->getOpcode()) {
2939 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2941 assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2951 case Instruction::FNeg: {
2952 assert(
CE->getNumOperands() == 1 &&
"Unknown constant expr!");
2961 case Instruction::GetElementPtr: {
2966 if (std::optional<ConstantRange>
Range = GO->getInRange()) {
2970 for (
const Value *
Op :
CE->operands()) {
2976 case Instruction::ExtractElement:
2983 case Instruction::InsertElement:
2990 case Instruction::ShuffleVector:
2995 if (
C->getType() ==
C->getOperand(0)->getType()) {
3032 Stream.
EmitRecord(Code, Record, AbbrevToUse);
3039void ModuleBitcodeWriter::writeModuleConstants() {
3044 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
3046 writeConstants(i, Vals.size(),
true);
3060bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
3061 SmallVectorImpl<unsigned> &Vals) {
3065 if (ValID >= InstID) {
3072bool ModuleBitcodeWriter::pushValueOrMetadata(
const Value *V,
unsigned InstID,
3073 SmallVectorImpl<unsigned> &Vals) {
3074 bool IsMetadata =
V->getType()->isMetadataTy();
3082 return pushValueAndType(V, InstID, Vals);
3085void ModuleBitcodeWriter::writeOperandBundles(
const CallBase &CS,
3092 Record.push_back(
C.getOperandBundleTagID(Bundle.getTagName()));
3094 for (
auto &Input : Bundle.Inputs)
3095 pushValueOrMetadata(Input, InstID, Record);
3104void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
3105 SmallVectorImpl<unsigned> &Vals) {
3110void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
3111 SmallVectorImpl<uint64_t> &Vals) {
3113 int64_t diff = ((int32_t)InstID - (int32_t)ValID);
3118void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
3120 SmallVectorImpl<unsigned> &Vals) {
3122 unsigned AbbrevToUse = 0;
3124 switch (
I.getOpcode()) {
3128 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3129 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
3134 if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
3135 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
3141 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3142 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
3143 pushValue(
I.getOperand(1), InstID, Vals);
3147 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
3148 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
3153 case Instruction::FNeg: {
3155 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3156 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
3160 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
3161 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
3166 case Instruction::GetElementPtr: {
3168 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
3172 for (
const Value *
Op :
I.operands())
3173 pushValueAndType(
Op, InstID, Vals);
3176 case Instruction::ExtractValue: {
3178 pushValueAndType(
I.getOperand(0), InstID, Vals);
3183 case Instruction::InsertValue: {
3185 pushValueAndType(
I.getOperand(0), InstID, Vals);
3186 pushValueAndType(
I.getOperand(1), InstID, Vals);
3191 case Instruction::Select: {
3193 pushValueAndType(
I.getOperand(1), InstID, Vals);
3194 pushValue(
I.getOperand(2), InstID, Vals);
3195 pushValueAndType(
I.getOperand(0), InstID, Vals);
3201 case Instruction::ExtractElement:
3203 pushValueAndType(
I.getOperand(0), InstID, Vals);
3204 pushValueAndType(
I.getOperand(1), InstID, Vals);
3206 case Instruction::InsertElement:
3208 pushValueAndType(
I.getOperand(0), InstID, Vals);
3209 pushValue(
I.getOperand(1), InstID, Vals);
3210 pushValueAndType(
I.getOperand(2), InstID, Vals);
3212 case Instruction::ShuffleVector:
3214 pushValueAndType(
I.getOperand(0), InstID, Vals);
3215 pushValue(
I.getOperand(1), InstID, Vals);
3219 case Instruction::ICmp:
3220 case Instruction::FCmp: {
3223 AbbrevToUse = FUNCTION_INST_CMP_ABBREV;
3224 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3226 pushValue(
I.getOperand(1), InstID, Vals);
3232 AbbrevToUse = FUNCTION_INST_CMP_FLAGS_ABBREV;
3237 case Instruction::Ret:
3240 unsigned NumOperands =
I.getNumOperands();
3241 if (NumOperands == 0)
3242 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
3243 else if (NumOperands == 1) {
3244 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3245 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
3247 for (
const Value *
Op :
I.operands())
3248 pushValueAndType(
Op, InstID, Vals);
3252 case Instruction::Br:
3255 AbbrevToUse = FUNCTION_INST_BR_UNCOND_ABBREV;
3258 if (
II.isConditional()) {
3260 pushValue(
II.getCondition(), InstID, Vals);
3261 AbbrevToUse = FUNCTION_INST_BR_COND_ABBREV;
3265 case Instruction::Switch:
3270 pushValue(
SI.getCondition(), InstID, Vals);
3272 for (
auto Case :
SI.cases()) {
3278 case Instruction::IndirectBr:
3282 pushValue(
I.getOperand(0), InstID, Vals);
3287 case Instruction::Invoke: {
3290 FunctionType *FTy =
II->getFunctionType();
3292 if (
II->hasOperandBundles())
3293 writeOperandBundles(*
II, InstID);
3302 pushValueAndType(Callee, InstID, Vals);
3305 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3306 pushValue(
I.getOperand(i), InstID, Vals);
3309 if (FTy->isVarArg()) {
3310 for (
unsigned i = FTy->getNumParams(), e =
II->arg_size(); i != e; ++i)
3311 pushValueAndType(
I.getOperand(i), InstID, Vals);
3315 case Instruction::Resume:
3317 pushValueAndType(
I.getOperand(0), InstID, Vals);
3319 case Instruction::CleanupRet: {
3322 pushValue(CRI.getCleanupPad(), InstID, Vals);
3323 if (CRI.hasUnwindDest())
3327 case Instruction::CatchRet: {
3330 pushValue(CRI.getCatchPad(), InstID, Vals);
3334 case Instruction::CleanupPad:
3335 case Instruction::CatchPad: {
3339 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3341 unsigned NumArgOperands = FuncletPad.arg_size();
3343 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
3344 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
3347 case Instruction::CatchSwitch: {
3351 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3353 unsigned NumHandlers = CatchSwitch.getNumHandlers();
3355 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
3358 if (CatchSwitch.hasUnwindDest())
3362 case Instruction::CallBr: {
3368 writeOperandBundles(*CBI, InstID);
3383 pushValueAndType(Callee, InstID, Vals);
3386 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3387 pushValue(
I.getOperand(i), InstID, Vals);
3390 if (FTy->isVarArg()) {
3391 for (
unsigned i = FTy->getNumParams(), e = CBI->
arg_size(); i != e; ++i)
3392 pushValueAndType(
I.getOperand(i), InstID, Vals);
3396 case Instruction::Unreachable:
3398 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3401 case Instruction::PHI: {
3419 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
3424 case Instruction::LandingPad: {
3435 pushValueAndType(LP.
getClause(
I), InstID, Vals);
3440 case Instruction::Alloca: {
3446 using APV = AllocaPackedValues;
3448 unsigned EncodedAlign = getEncodedAlign(AI.
getAlign());
3450 Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3452 EncodedAlign >> APV::AlignLower::Bits);
3459 if (AS !=
M.getDataLayout().getAllocaAddrSpace())
3464 case Instruction::Load:
3467 pushValueAndType(
I.getOperand(0), InstID, Vals);
3470 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3471 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3481 case Instruction::Store:
3486 AbbrevToUse = FUNCTION_INST_STORE_ABBREV;
3488 if (pushValueAndType(
I.getOperand(1), InstID, Vals))
3490 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3500 case Instruction::AtomicCmpXchg:
3502 pushValueAndType(
I.getOperand(0), InstID, Vals);
3503 pushValueAndType(
I.getOperand(1), InstID, Vals);
3504 pushValue(
I.getOperand(2), InstID, Vals);
3515 case Instruction::AtomicRMW:
3517 pushValueAndType(
I.getOperand(0), InstID, Vals);
3518 pushValueAndType(
I.getOperand(1), InstID, Vals);
3527 case Instruction::Fence:
3532 case Instruction::Call: {
3537 writeOperandBundles(CI, InstID);
3557 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3561 if (FTy->isVarArg()) {
3562 for (
unsigned i = FTy->getNumParams(), e = CI.
arg_size(); i != e; ++i)
3567 case Instruction::VAArg:
3570 pushValue(
I.getOperand(0), InstID, Vals);
3573 case Instruction::Freeze:
3575 pushValueAndType(
I.getOperand(0), InstID, Vals);
3585void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3586 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3591 VSTOffset -= bitcodeStartBit();
3592 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
3596 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3600 auto Abbv = std::make_shared<BitCodeAbbrev>();
3604 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3606 for (
const Function &
F : M) {
3609 if (
F.isDeclaration())
3616 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
3617 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
3621 Record[1] = BitcodeIndex / 32 + 1;
3630void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3631 const ValueSymbolTable &VST) {
3639 SmallVector<uint64_t, 64> NameVals;
3645 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3654 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3658 AbbrevToUse = VST_ENTRY_6_ABBREV;
3660 AbbrevToUse = VST_ENTRY_7_ABBREV;
3663 for (
const auto P :
Name.getKey())
3667 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3674void ModuleBitcodeWriter::writeUseList(UseListOrder &&Order) {
3675 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3682 SmallVector<uint64_t, 64>
Record(Order.Shuffle.begin(), Order.Shuffle.end());
3687void ModuleBitcodeWriter::writeUseListBlock(
const Function *
F) {
3689 "Expected to be preserving use-list order");
3691 auto hasMore = [&]() {
3707void ModuleBitcodeWriter::writeFunction(
3709 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3726 unsigned CstStart, CstEnd;
3728 writeConstants(CstStart, CstEnd,
false);
3731 writeFunctionMetadata(
F);
3734 unsigned InstID = CstEnd;
3736 bool NeedsMetadataAttachment =
F.hasMetadata();
3738 DILocation *LastDL =
nullptr;
3739 SmallSetVector<Function *, 4> BlockAddressUsers;
3742 for (
const BasicBlock &BB :
F) {
3743 for (
const Instruction &
I : BB) {
3744 writeInstruction(
I, InstID, Vals);
3746 if (!
I.getType()->isVoidTy())
3750 NeedsMetadataAttachment |=
I.hasMetadataOtherThanDebugLoc();
3753 if (DILocation *
DL =
I.getDebugLoc()) {
3766 FUNCTION_DEBUG_LOC_ABBREV);
3776 if (
I.hasDbgRecords()) {
3780 auto PushValueOrMetadata = [&Vals, InstID,
3783 "RawLocation unexpectedly null in DbgVariableRecord");
3785 SmallVector<unsigned, 2> ValAndType;
3789 if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
3803 for (DbgRecord &DR :
I.DebugMarker->getDbgRecordRange()) {
3829 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3853 SmallPtrSet<Value *, 8> Visited{BA};
3854 while (!Worklist.
empty()) {
3856 for (User *U :
V->users()) {
3862 Visited.
insert(U).second)
3869 if (!BlockAddressUsers.
empty()) {
3878 if (
auto *Symtab =
F.getValueSymbolTable())
3879 writeFunctionLevelValueSymbolTable(*Symtab);
3881 if (NeedsMetadataAttachment)
3882 writeFunctionMetadataAttachment(
F);
3884 writeUseListBlock(&
F);
3890void ModuleBitcodeWriter::writeBlockInfo() {
3903 auto Abbv = std::make_shared<BitCodeAbbrev>();
3914 auto Abbv = std::make_shared<BitCodeAbbrev>();
3924 auto Abbv = std::make_shared<BitCodeAbbrev>();
3934 auto Abbv = std::make_shared<BitCodeAbbrev>();
3940 VST_BBENTRY_6_ABBREV)
3945 auto Abbv = std::make_shared<BitCodeAbbrev>();
3947 Abbv->Add(TypeAbbrevOp);
3949 CONSTANTS_SETTYPE_ABBREV)
3954 auto Abbv = std::make_shared<BitCodeAbbrev>();
3958 CONSTANTS_INTEGER_ABBREV)
3963 auto Abbv = std::make_shared<BitCodeAbbrev>();
3971 CONSTANTS_CE_CAST_Abbrev)
3975 auto Abbv = std::make_shared<BitCodeAbbrev>();
3978 CONSTANTS_NULL_Abbrev)
3985 auto Abbv = std::make_shared<BitCodeAbbrev>();
3987 Abbv->Add(ValAbbrevOp);
3988 Abbv->Add(TypeAbbrevOp);
3992 FUNCTION_INST_LOAD_ABBREV)
3996 auto Abbv = std::make_shared<BitCodeAbbrev>();
3998 Abbv->Add(ValAbbrevOp);
3999 Abbv->Add(ValAbbrevOp);
4003 FUNCTION_INST_STORE_ABBREV)
4007 auto Abbv = std::make_shared<BitCodeAbbrev>();
4009 Abbv->Add(ValAbbrevOp);
4012 FUNCTION_INST_UNOP_ABBREV)
4016 auto Abbv = std::make_shared<BitCodeAbbrev>();
4018 Abbv->Add(ValAbbrevOp);
4022 FUNCTION_INST_UNOP_FLAGS_ABBREV)
4026 auto Abbv = std::make_shared<BitCodeAbbrev>();
4028 Abbv->Add(ValAbbrevOp);
4029 Abbv->Add(ValAbbrevOp);
4032 FUNCTION_INST_BINOP_ABBREV)
4036 auto Abbv = std::make_shared<BitCodeAbbrev>();
4038 Abbv->Add(ValAbbrevOp);
4039 Abbv->Add(ValAbbrevOp);
4043 FUNCTION_INST_BINOP_FLAGS_ABBREV)
4047 auto Abbv = std::make_shared<BitCodeAbbrev>();
4049 Abbv->Add(ValAbbrevOp);
4050 Abbv->Add(TypeAbbrevOp);
4053 FUNCTION_INST_CAST_ABBREV)
4057 auto Abbv = std::make_shared<BitCodeAbbrev>();
4059 Abbv->Add(ValAbbrevOp);
4060 Abbv->Add(TypeAbbrevOp);
4064 FUNCTION_INST_CAST_FLAGS_ABBREV)
4069 auto Abbv = std::make_shared<BitCodeAbbrev>();
4072 FUNCTION_INST_RET_VOID_ABBREV)
4076 auto Abbv = std::make_shared<BitCodeAbbrev>();
4078 Abbv->Add(ValAbbrevOp);
4080 FUNCTION_INST_RET_VAL_ABBREV)
4084 auto Abbv = std::make_shared<BitCodeAbbrev>();
4087 Abbv->Add(ValAbbrevOp);
4089 FUNCTION_INST_BR_UNCOND_ABBREV)
4093 auto Abbv = std::make_shared<BitCodeAbbrev>();
4096 Abbv->Add(ValAbbrevOp);
4097 Abbv->Add(ValAbbrevOp);
4098 Abbv->Add(ValAbbrevOp);
4100 FUNCTION_INST_BR_COND_ABBREV)
4104 auto Abbv = std::make_shared<BitCodeAbbrev>();
4107 FUNCTION_INST_UNREACHABLE_ABBREV)
4111 auto Abbv = std::make_shared<BitCodeAbbrev>();
4114 Abbv->Add(TypeAbbrevOp);
4116 Abbv->Add(ValAbbrevOp);
4118 FUNCTION_INST_GEP_ABBREV)
4122 auto Abbv = std::make_shared<BitCodeAbbrev>();
4124 Abbv->Add(ValAbbrevOp);
4125 Abbv->Add(ValAbbrevOp);
4128 FUNCTION_INST_CMP_ABBREV)
4132 auto Abbv = std::make_shared<BitCodeAbbrev>();
4134 Abbv->Add(ValAbbrevOp);
4135 Abbv->Add(ValAbbrevOp);
4139 FUNCTION_INST_CMP_FLAGS_ABBREV)
4143 auto Abbv = std::make_shared<BitCodeAbbrev>();
4148 Abbv->Add(ValAbbrevOp);
4150 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
4154 auto Abbv = std::make_shared<BitCodeAbbrev>();
4165 FUNCTION_DEBUG_LOC_ABBREV)
4173void IndexBitcodeWriter::writeModStrings() {
4179 auto Abbv = std::make_shared<BitCodeAbbrev>();
4184 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
4187 Abbv = std::make_shared<BitCodeAbbrev>();
4192 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
4195 Abbv = std::make_shared<BitCodeAbbrev>();
4200 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
4203 Abbv = std::make_shared<BitCodeAbbrev>();
4210 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
4213 forEachModule([&](
const StringMapEntry<ModuleHash> &MPSE) {
4215 const auto &Hash = MPSE.
getValue();
4217 unsigned AbbrevToUse = Abbrev8Bit;
4219 AbbrevToUse = Abbrev6Bit;
4221 AbbrevToUse = Abbrev7Bit;
4223 auto ModuleId = ModuleIdMap.
size();
4224 ModuleIdMap[
Key] = ModuleId;
4233 Vals.
assign(Hash.begin(), Hash.end());
4245template <
typename Fn>
4249 if (!FS->type_tests().empty())
4254 auto WriteVFuncIdVec = [&](
uint64_t Ty,
4259 for (
auto &VF : VFs) {
4260 Record.push_back(VF.GUID);
4261 Record.push_back(VF.Offset);
4267 FS->type_test_assume_vcalls());
4269 FS->type_checked_load_vcalls());
4271 auto WriteConstVCallVec = [&](
uint64_t Ty,
4273 for (
auto &VC : VCs) {
4275 Record.push_back(VC.VFunc.GUID);
4276 Record.push_back(VC.VFunc.Offset);
4283 FS->type_test_assume_const_vcalls());
4285 FS->type_checked_load_const_vcalls());
4295 if (!FS->paramAccesses().empty()) {
4297 for (
auto &Arg : FS->paramAccesses()) {
4298 size_t UndoSize =
Record.size();
4299 Record.push_back(Arg.ParamNo);
4300 WriteRange(Arg.Use);
4301 Record.push_back(Arg.Calls.size());
4302 for (
auto &
Call : Arg.Calls) {
4304 std::optional<unsigned> ValueID = GetValueID(
Call.Callee);
4311 Record.push_back(*ValueID);
4312 WriteRange(
Call.Offsets);
4323 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
4324 if (!FS->type_tests().empty())
4325 for (
auto &TT : FS->type_tests())
4326 ReferencedTypeIds.insert(TT);
4328 auto GetReferencedTypesFromVFuncIdVec =
4330 for (
auto &VF : VFs)
4331 ReferencedTypeIds.insert(VF.GUID);
4334 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4335 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4337 auto GetReferencedTypesFromConstVCallVec =
4339 for (
auto &VC : VCs)
4340 ReferencedTypeIds.insert(VC.VFunc.GUID);
4343 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4344 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
4380 NameVals.
push_back(Summary.TTRes.TheKind);
4381 NameVals.
push_back(Summary.TTRes.SizeM1BitWidth);
4382 NameVals.
push_back(Summary.TTRes.AlignLog2);
4383 NameVals.
push_back(Summary.TTRes.SizeM1);
4384 NameVals.
push_back(Summary.TTRes.BitMask);
4385 NameVals.
push_back(Summary.TTRes.InlineBits);
4387 for (
auto &W : Summary.WPDRes)
4399 for (
auto &
P : Summary) {
4401 NameVals.
push_back(
VE.getValueID(
P.VTableVI.getValue()));
4415 static_assert(std::is_same_v<LinearFrameId, unsigned>);
4416 for (
auto &AI : FS->allocs()) {
4417 for (
auto &MIB : AI.MIBs) {
4419 StackIdIndices.
reserve(MIB.StackIdIndices.size());
4420 for (
auto Id : MIB.StackIdIndices)
4421 StackIdIndices.
push_back(GetStackIndex(Id));
4423 CallStacks.insert({CallStacks.size(), StackIdIndices});
4436 assert(!CallStacks.empty());
4442 Builder.
build(std::move(CallStacks),
nullptr,
4446 return Builder.takeCallStackPos();
4451 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
bool PerModule,
4452 std::function<
unsigned(
const ValueInfo &VI)> GetValueID,
4453 std::function<
unsigned(
unsigned)> GetStackIndex,
4454 bool WriteContextSizeInfoIndex,
4459 for (
auto &CI : FS->callsites()) {
4463 assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4464 Record.push_back(GetValueID(CI.Callee));
4466 Record.push_back(CI.StackIdIndices.size());
4467 Record.push_back(CI.Clones.size());
4469 for (
auto Id : CI.StackIdIndices)
4470 Record.push_back(GetStackIndex(Id));
4478 for (
auto &AI : FS->allocs()) {
4482 assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4483 Record.push_back(AI.MIBs.size());
4485 Record.push_back(AI.Versions.size());
4486 for (
auto &MIB : AI.MIBs) {
4493 assert(CallStackCount <= CallStackPos.
size());
4494 Record.push_back(CallStackPos[CallStackCount++]);
4499 assert(AI.ContextSizeInfos.empty() ||
4500 AI.ContextSizeInfos.size() == AI.MIBs.size());
4502 if (WriteContextSizeInfoIndex && !AI.ContextSizeInfos.empty()) {
4510 ContextIds.
reserve(AI.ContextSizeInfos.size() * 2);
4511 for (
auto &Infos : AI.ContextSizeInfos) {
4512 Record.push_back(Infos.size());
4513 for (
auto [FullStackId, TotalSize] : Infos) {
4520 Record.push_back(TotalSize);
4538void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4539 SmallVector<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
4540 unsigned ValueID,
unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
4541 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
const Function &
F,
4542 DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
4549 Stream, FS, [&](
const ValueInfo &VI) -> std::optional<unsigned> {
4554 Stream, FS, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
4556 [&](
const ValueInfo &VI) {
return getValueId(VI); },
4557 [&](
unsigned I) {
return I; },
4558 true, CallStackPos, CallStackCount);
4560 auto SpecialRefCnts =
FS->specialRefCounts();
4565 NameVals.
push_back(SpecialRefCnts.first);
4566 NameVals.
push_back(SpecialRefCnts.second);
4568 for (
auto &RI :
FS->refs())
4571 for (
auto &ECI :
FS->calls()) {
4572 NameVals.
push_back(getValueId(ECI.first));
4583void ModuleBitcodeWriterBase::writeModuleLevelReferences(
4584 const GlobalVariable &V, SmallVector<uint64_t, 64> &NameVals,
4585 unsigned FSModRefsAbbrev,
unsigned FSModVTableRefsAbbrev) {
4586 auto VI =
Index->getValueInfo(
V.getGUID());
4587 if (!VI ||
VI.getSummaryList().empty()) {
4593 auto *
Summary =
VI.getSummaryList()[0].get();
4599 auto VTableFuncs =
VS->vTableFuncs();
4600 if (!VTableFuncs.empty())
4603 unsigned SizeBeforeRefs = NameVals.
size();
4604 for (
auto &RI :
VS->refs())
4610 if (VTableFuncs.empty())
4615 for (
auto &
P : VTableFuncs) {
4621 FSModVTableRefsAbbrev);
4628void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
4631 bool IsThinLTO =
true;
4634 IsThinLTO = MD->getZExtValue();
4646 if (
Index->enableSplitLTOUnit())
4648 if (
Index->hasUnifiedLTO())
4658 auto Abbv = std::make_shared<BitCodeAbbrev>();
4664 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4666 for (
const auto &GVI : valueIds()) {
4668 ArrayRef<uint32_t>{GVI.second,
4669 static_cast<uint32_t
>(GVI.first >> 32),
4670 static_cast<uint32_t
>(GVI.first)},
4674 if (!
Index->stackIds().empty()) {
4675 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4682 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4683 SmallVector<uint32_t> Vals;
4685 for (
auto Id :
Index->stackIds()) {
4686 Vals.
push_back(
static_cast<uint32_t
>(Id >> 32));
4687 Vals.
push_back(
static_cast<uint32_t
>(Id));
4692 unsigned ContextIdAbbvId = 0;
4695 auto ContextIdAbbv = std::make_shared<BitCodeAbbrev>();
4707 ContextIdAbbvId = Stream.
EmitAbbrev(std::move(ContextIdAbbv));
4711 Abbv = std::make_shared<BitCodeAbbrev>();
4723 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4726 Abbv = std::make_shared<BitCodeAbbrev>();
4732 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4735 Abbv = std::make_shared<BitCodeAbbrev>();
4743 unsigned FSModVTableRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4746 Abbv = std::make_shared<BitCodeAbbrev>();
4751 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4754 Abbv = std::make_shared<BitCodeAbbrev>();
4761 unsigned TypeIdCompatibleVtableAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4763 Abbv = std::make_shared<BitCodeAbbrev>();
4769 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4771 Abbv = std::make_shared<BitCodeAbbrev>();
4778 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4780 Abbv = std::make_shared<BitCodeAbbrev>();
4785 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4792 MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
4793 for (
const Function &
F : M) {
4799 ValueInfo
VI =
Index->getValueInfo(
F.getGUID());
4800 if (!VI ||
VI.getSummaryList().empty()) {
4806 auto *
Summary =
VI.getSummaryList()[0].get();
4809 FS, [](
unsigned I) {
return I; }, CallStacks);
4813 DenseMap<CallStackId, LinearCallStackId> CallStackPos;
4814 if (!CallStacks.
empty()) {
4822 SmallVector<uint64_t, 64> NameVals;
4825 for (
const Function &
F : M) {
4831 ValueInfo
VI =
Index->getValueInfo(
F.getGUID());
4832 if (!VI ||
VI.getSummaryList().empty()) {
4838 auto *
Summary =
VI.getSummaryList()[0].get();
4839 writePerModuleFunctionSummaryRecord(NameVals, Summary, VE.
getValueID(&
F),
4840 FSCallsProfileAbbrev, CallsiteAbbrev,
4841 AllocAbbrev, ContextIdAbbvId,
F,
4842 CallStackPos, CallStackCount);
4847 for (
const GlobalVariable &
G :
M.globals())
4848 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev,
4849 FSModVTableRefsAbbrev);
4851 for (
const GlobalAlias &
A :
M.aliases()) {
4852 auto *Aliasee =
A.getAliaseeObject();
4868 for (
auto &S :
Index->typeIdCompatibleVtableMap()) {
4872 TypeIdCompatibleVtableAbbrev);
4876 if (
Index->getBlockCount())
4878 ArrayRef<uint64_t>{
Index->getBlockCount()});
4884void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4893 auto Abbv = std::make_shared<BitCodeAbbrev>();
4899 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4901 for (
const auto &GVI : valueIds()) {
4903 ArrayRef<uint32_t>{GVI.second,
4904 static_cast<uint32_t
>(GVI.first >> 32),
4905 static_cast<uint32_t
>(GVI.first)},
4911 if (!StackIds.empty()) {
4912 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4919 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4920 SmallVector<uint32_t> Vals;
4921 Vals.
reserve(StackIds.size() * 2);
4922 for (
auto Id : StackIds) {
4923 Vals.
push_back(
static_cast<uint32_t
>(Id >> 32));
4924 Vals.
push_back(
static_cast<uint32_t
>(Id));
4930 Abbv = std::make_shared<BitCodeAbbrev>();
4944 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4947 Abbv = std::make_shared<BitCodeAbbrev>();
4954 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4957 Abbv = std::make_shared<BitCodeAbbrev>();
4963 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4965 Abbv = std::make_shared<BitCodeAbbrev>();
4973 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4975 Abbv = std::make_shared<BitCodeAbbrev>();
4986 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4988 auto shouldImportValueAsDecl = [&](GlobalValueSummary *GVS) ->
bool {
4989 if (DecSummaries ==
nullptr)
4991 return DecSummaries->count(GVS);
4999 DenseMap<const GlobalValueSummary *, unsigned> SummaryToValueIdMap;
5001 SmallVector<uint64_t, 64> NameVals;
5005 std::set<GlobalValue::GUID> ReferencedTypeIds;
5009 auto MaybeEmitOriginalName = [&](GlobalValueSummary &S) {
5019 NameVals.
push_back(S.getOriginalName());
5024 DenseMap<CallStackId, LinearCallStackId> CallStackPos;
5026 Abbv = std::make_shared<BitCodeAbbrev>();
5031 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5038 MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
5039 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5045 GlobalValueSummary *S =
I.second;
5058 return StackIdIndicesToIndex[
I];
5064 if (!CallStacks.
empty()) {
5074 DenseSet<GlobalValue::GUID> DefOrUseGUIDs;
5075 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5076 GlobalValueSummary *S =
I.second;
5078 DefOrUseGUIDs.
insert(
I.first);
5079 for (
const ValueInfo &VI : S->
refs())
5080 DefOrUseGUIDs.
insert(
VI.getGUID());
5082 auto ValueId = getValueId(
I.first);
5084 SummaryToValueIdMap[S] = *ValueId;
5102 NameVals.
push_back(ModuleIdMap[
VS->modulePath()]);
5106 for (
auto &RI :
VS->refs()) {
5107 auto RefValueId = getValueId(RI.getGUID());
5117 MaybeEmitOriginalName(*S);
5121 auto GetValueId = [&](
const ValueInfo &
VI) -> std::optional<unsigned> {
5123 return std::nullopt;
5124 return getValueId(
VI.getGUID());
5132 Stream, FS, CallsiteAbbrev, AllocAbbrev, 0,
5135 [&](
const ValueInfo &VI) ->
unsigned {
5136 std::optional<unsigned> ValueID = GetValueId(VI);
5151 return StackIdIndicesToIndex[
I];
5153 false, CallStackPos, CallStackCount);
5157 NameVals.
push_back(ModuleIdMap[
FS->modulePath()]);
5170 unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
5171 for (
auto &RI :
FS->refs()) {
5172 auto RefValueId = getValueId(RI.getGUID());
5176 if (RI.isReadOnly())
5178 else if (RI.isWriteOnly())
5182 NameVals[6] =
Count;
5183 NameVals[7] = RORefCnt;
5184 NameVals[8] = WORefCnt;
5186 for (
auto &EI :
FS->calls()) {
5189 std::optional<unsigned> CallValueId = GetValueId(EI.first);
5198 FSCallsProfileAbbrev);
5200 MaybeEmitOriginalName(*S);
5203 for (
auto *AS : Aliases) {
5204 auto AliasValueId = SummaryToValueIdMap[AS];
5213 auto AliaseeValueId =
5220 MaybeEmitOriginalName(*AS);
5228 auto EmitCfiFunctions = [&](
const CfiFunctionIndex &CfiIndex,
5230 if (CfiIndex.
empty())
5233 auto Defs = CfiIndex.
forGuid(GUID);
5236 if (Functions.
empty())
5239 for (
const auto &S : Functions) {
5253 for (
auto &
T : ReferencedTypeIds) {
5254 auto TidIter =
Index.typeIds().equal_range(
T);
5255 for (
const auto &[GUID, TypeIdPair] :
make_range(TidIter)) {
5263 if (
Index.getBlockCount())
5265 ArrayRef<uint64_t>{
Index.getBlockCount()});
5276 auto Abbv = std::make_shared<BitCodeAbbrev>();
5280 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5282 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
5285 Abbv = std::make_shared<BitCodeAbbrev>();
5288 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5294void ModuleBitcodeWriter::writeModuleHash(StringRef View) {
5299 Hasher.
update(ArrayRef<uint8_t>(
5300 reinterpret_cast<const uint8_t *
>(
View.data()),
View.size()));
5301 std::array<uint8_t, 20> Hash = Hasher.
result();
5302 for (
int Pos = 0; Pos < 20; Pos += 4) {
5315void ModuleBitcodeWriter::write() {
5323 writeModuleVersion();
5332 writeAttributeGroupTable();
5335 writeAttributeTable();
5344 writeModuleConstants();
5347 writeModuleMetadataKinds();
5350 writeModuleMetadata();
5354 writeUseListBlock(
nullptr);
5356 writeOperandBundleTags();
5357 writeSyncScopeNames();
5360 DenseMap<const Function *, uint64_t> FunctionToBitcodeIndex;
5361 for (
const Function &
F : M)
5362 if (!
F.isDeclaration())
5363 writeFunction(
F, FunctionToBitcodeIndex);
5368 writePerModuleGlobalValueSummary();
5370 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
5398 unsigned CPUType = ~0U;
5405 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
5406 DARWIN_CPU_TYPE_X86 = 7,
5407 DARWIN_CPU_TYPE_ARM = 12,
5408 DARWIN_CPU_TYPE_POWERPC = 18
5413 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
5415 CPUType = DARWIN_CPU_TYPE_X86;
5417 CPUType = DARWIN_CPU_TYPE_POWERPC;
5419 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
5421 CPUType = DARWIN_CPU_TYPE_ARM;
5425 "Expected header size to be reserved");
5430 unsigned Position = 0;
5438 while (Buffer.
size() & 15)
5445 Stream.
Emit((
unsigned)
'B', 8);
5446 Stream.
Emit((
unsigned)
'C', 8);
5447 Stream.
Emit(0x0, 4);
5448 Stream.
Emit(0xC, 4);
5449 Stream.
Emit(0xE, 4);
5450 Stream.
Emit(0xD, 4);
5468 auto Abbv = std::make_shared<BitCodeAbbrev>();
5471 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
5479 assert(!WroteStrtab && !WroteSymtab);
5485 if (M->getModuleInlineAsm().empty())
5489 const Triple TT(M->getTargetTriple());
5491 if (!
T || !
T->hasMCAsmParser())
5513 std::vector<char> Strtab;
5514 StrtabBuilder.finalizeInOrder();
5515 Strtab.resize(StrtabBuilder.getSize());
5516 StrtabBuilder.write((
uint8_t *)Strtab.data());
5519 {Strtab.data(), Strtab.size()});
5530 bool ShouldPreserveUseListOrder,
5539 assert(M.isMaterialized());
5540 Mods.push_back(
const_cast<Module *
>(&M));
5542 ModuleBitcodeWriter ModuleWriter(M, StrtabBuilder, *Stream,
5543 ShouldPreserveUseListOrder, Index,
5544 GenerateHash, ModHash);
5545 ModuleWriter.write();
5552 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, DecSummaries,
5553 ModuleToSummariesForIndex);
5554 IndexWriter.write();
5559 bool ShouldPreserveUseListOrder,
5563 Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
5565 Writer.writeSymtab();
5566 Writer.writeStrtab();
5568 Triple TT(M.getTargetTriple());
5569 if (TT.isOSDarwin() || TT.isOSBinFormatMachO()) {
5587void IndexBitcodeWriter::write() {
5590 writeModuleVersion();
5596 writeCombinedGlobalValueSummary();
5613 Writer.
writeIndex(&Index, ModuleToSummariesForIndex, DecSummaries);
5622class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
5632 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5634 ModHash(&ModHash) {}
5639 void writeSimplifiedModuleInfo();
5649void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5661 auto Abbv = std::make_shared<BitCodeAbbrev>();
5664 Abbv->Add(AbbrevOpToUse);
5665 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5667 for (
const auto P :
M.getSourceFileName())
5731void ThinLinkBitcodeWriter::write() {
5734 writeModuleVersion();
5736 writeSimplifiedModuleInfo();
5738 writePerModuleGlobalValueSummary();
5755 assert(M.isMaterialized());
5756 Mods.push_back(
const_cast<Module *
>(&M));
5758 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream, Index,
5760 ThinLinkWriter.write();
5781 switch (
T.getObjectFormat()) {
5783 return "__LLVM,__bitcode";
5808 switch (
T.getObjectFormat()) {
5810 return "__LLVM,__cmdline";
5836 const std::vector<uint8_t> &CmdArgs) {
5841 Type *UsedElementType = Used ? Used->getValueType()->getArrayElementType()
5843 for (
auto *GV : UsedGlobals) {
5844 if (GV->getName() !=
"llvm.embedded.module" &&
5845 GV->getName() !=
"llvm.cmdline")
5850 Used->eraseFromParent();
5855 Triple T(M.getTargetTriple());
5884 M.getGlobalVariable(
"llvm.embedded.module",
true)) {
5885 assert(Old->hasZeroLiveUses() &&
5886 "llvm.embedded.module can only be used once in llvm.compiler.used");
5888 Old->eraseFromParent();
5890 GV->
setName(
"llvm.embedded.module");
5908 assert(Old->hasZeroLiveUses() &&
5909 "llvm.cmdline can only be used once in llvm.compiler.used");
5911 Old->eraseFromParent();
5917 if (UsedArray.
empty())
5925 NewUsed->setSection(
"llvm.metadata");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void writeDIMacro(raw_ostream &Out, const DIMacro *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, AsmWriterContext &WriterCtx)
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, AsmWriterContext &WriterCtx)
static void writeDIFixedPointType(raw_ostream &Out, const DIFixedPointType *N, AsmWriterContext &WriterCtx)
static void writeDISubrangeType(raw_ostream &Out, const DISubrangeType *N, AsmWriterContext &WriterCtx)
static void writeDIStringType(raw_ostream &Out, const DIStringType *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, AsmWriterContext &WriterCtx)
static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, AsmWriterContext &WriterCtx)
static void writeDIModule(raw_ostream &Out, const DIModule *N, AsmWriterContext &WriterCtx)
static void writeDIFile(raw_ostream &Out, const DIFile *N, AsmWriterContext &)
static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, AsmWriterContext &WriterCtx)
static void writeDILabel(raw_ostream &Out, const DILabel *N, AsmWriterContext &WriterCtx)
static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, AsmWriterContext &WriterCtx)
static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, AsmWriterContext &WriterCtx)
static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, AsmWriterContext &WriterCtx)
static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, AsmWriterContext &WriterCtx)
static void writeDILocation(raw_ostream &Out, const DILocation *DL, AsmWriterContext &WriterCtx)
static void writeDINamespace(raw_ostream &Out, const DINamespace *N, AsmWriterContext &WriterCtx)
static void writeDICommonBlock(raw_ostream &Out, const DICommonBlock *N, AsmWriterContext &WriterCtx)
static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, AsmWriterContext &WriterCtx)
static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, AsmWriterContext &WriterCtx)
static void writeDITemplateTypeParameter(raw_ostream &Out, const DITemplateTypeParameter *N, AsmWriterContext &WriterCtx)
static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, AsmWriterContext &WriterCtx)
static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N, AsmWriterContext &WriterCtx)
static void writeDISubrange(raw_ostream &Out, const DISubrange *N, AsmWriterContext &WriterCtx)
static void writeDILexicalBlockFile(raw_ostream &Out, const DILexicalBlockFile *N, AsmWriterContext &WriterCtx)
static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, AsmWriterContext &)
static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, AsmWriterContext &WriterCtx)
static void writeDIExpression(raw_ostream &Out, const DIExpression *N, AsmWriterContext &WriterCtx)
static void writeDIAssignID(raw_ostream &Out, const DIAssignID *DL, AsmWriterContext &WriterCtx)
static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, AsmWriterContext &WriterCtx)
static void writeDIArgList(raw_ostream &Out, const DIArgList *N, AsmWriterContext &WriterCtx, bool FromValue=false)
static void writeDITemplateValueParameter(raw_ostream &Out, const DITemplateValueParameter *N, AsmWriterContext &WriterCtx)
static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, AsmWriterContext &WriterCtx)
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static void writeFunctionHeapProfileRecords(BitstreamWriter &Stream, FunctionSummary *FS, unsigned CallsiteAbbrev, unsigned AllocAbbrev, unsigned ContextIdAbbvId, bool PerModule, std::function< unsigned(const ValueInfo &VI)> GetValueID, std::function< unsigned(unsigned)> GetStackIndex, bool WriteContextSizeInfoIndex, DenseMap< CallStackId, LinearCallStackId > &CallStackPos, CallStackId &CallStackCount)
static unsigned serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta)
static void writeTypeIdCompatibleVtableSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdCompatibleVtableInfo &Summary, ValueEnumerator &VE)
static void getReferencedTypeIds(FunctionSummary *FS, std::set< GlobalValue::GUID > &ReferencedTypeIds)
Collect type IDs from type tests used by function.
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
static void collectMemProfCallStacks(FunctionSummary *FS, std::function< LinearFrameId(unsigned)> GetStackIndex, MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &CallStacks)
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
static unsigned getEncodedVisibility(const GlobalValue &GV)
static uint64_t getOptimizationFlags(const Value *V)
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
static cl::opt< bool > PreserveBitcodeUseListOrder("preserve-bc-uselistorder", cl::Hidden, cl::init(true), cl::desc("Preserve use-list order when writing LLVM bitcode."))
static unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
static DenseMap< CallStackId, LinearCallStackId > writeMemoryProfileRadixTree(MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &&CallStacks, BitstreamWriter &Stream, unsigned RadixAbbrev)
static void writeIdentificationBlock(BitstreamWriter &Stream)
Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version,...
static unsigned getEncodedCastOpcode(unsigned Opcode)
static cl::opt< uint32_t > FlushThreshold("bitcode-flush-threshold", cl::Hidden, cl::init(512), cl::desc("The threshold (unit M) for flushing LLVM bitcode."))
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
static unsigned getEncodedUnnamedAddr(const GlobalValue &GV)
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags, bool ImportAsDecl=false)
static void emitDarwinBCHeaderAndTrailer(SmallVectorImpl< char > &Buffer, const Triple &TT)
If generating a bc file on darwin, we have to emit a header and trailer to make it compatible with th...
static void writeBitcodeHeader(BitstreamWriter &Stream)
Helper to write the header common to all bitcode files.
static void writeWholeProgramDevirtResolutionByArg(SmallVector< uint64_t, 64 > &NameVals, const std::vector< uint64_t > &args, const WholeProgramDevirtResolution::ByArg &ByArg)
static void emitConstantRange(SmallVectorImpl< uint64_t > &Record, const ConstantRange &CR, bool EmitBitWidth)
static StringEncoding getStringEncoding(StringRef Str)
Determine the encoding to use for the given string name and length.
static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags)
static const char * getSectionNameForCommandline(const Triple &T)
static cl::opt< unsigned > IndexThreshold("bitcode-mdindex-threshold", cl::Hidden, cl::init(25), cl::desc("Number of metadatas above which we emit an index " "to enable lazy-loading"))
static void writeTypeIdSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdSummary &Summary)
static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, FunctionSummary *FS, Fn GetValueID)
Write the function type metadata related records that need to appear before a function summary entry ...
static uint64_t getEncodedHotnessCallEdgeInfo(const CalleeInfo &CI)
static void emitWideAPInt(SmallVectorImpl< uint64_t > &Vals, const APInt &A)
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
static void writeWholeProgramDevirtResolution(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, uint64_t Id, const WholeProgramDevirtResolution &Wpd)
static unsigned getEncodedDLLStorageClass(const GlobalValue &GV)
static void writeInt32ToBuffer(uint32_t Value, SmallVectorImpl< char > &Buffer, uint32_t &Position)
static const char * getSectionNameForBitcode(const Triple &T)
static cl::opt< bool > CombinedIndexMemProfContext("combined-index-memprof-context", cl::Hidden, cl::init(true), cl::desc(""))
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
This file contains constants used for implementing Dwarf debug support.
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
static MaybeAlign getAlign(Value *Ptr)
Module.h This file contains the declarations for the Module class.
static cl::opt< LTOBitcodeEmbedding > EmbedBitcode("lto-embed-bitcode", cl::init(LTOBitcodeEmbedding::DoNotEmbed), cl::values(clEnumValN(LTOBitcodeEmbedding::DoNotEmbed, "none", "Do not embed"), clEnumValN(LTOBitcodeEmbedding::EmbedOptimized, "optimized", "Embed after all optimization passes"), clEnumValN(LTOBitcodeEmbedding::EmbedPostMergePreOptimized, "post-merge-pre-opt", "Embed post merge, but before optimizations")), cl::desc("Embed LLVM bitcode in object files produced by LTO"))
Machine Check Debug Module
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static const uint32_t IV[8]
Class for arbitrary precision integers.
unsigned getActiveWords() const
Compute the number of active words in the value of this APInt.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
int64_t getSExtValue() const
Get sign extended value.
const GlobalValueSummary & getAliasee() const
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
unsigned getAddressSpace() const
Return the address space for the allocation.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
Class to represent array types.
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ USubCond
Subtract only if no unsigned overflow.
@ FMinimum
*p = minimum(old, v) minimum matches the behavior of llvm.minimum.
@ Min
*p = old <signed v ? old : v
@ USubSat
*p = usub.sat(old, v) usub.sat matches the behavior of llvm.usub.sat.
@ FMaximum
*p = maximum(old, v) maximum matches the behavior of llvm.maximum.
@ UIncWrap
Increment one up to a maximum value.
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ UMax
*p = old >unsigned v ? old : v
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
bool hasAttributes() const
Return true if attributes exists in this set.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
@ None
No attributes have been set.
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
@ EndAttrKinds
Sentinel value useful for loops.
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
LLVM_ABI void writeThinLinkBitcode(const Module &M, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the buffer specified...
LLVM_ABI void writeIndex(const ModuleSummaryIndex *Index, const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex, const GVSummaryPtrSet *DecSummaries)
LLVM_ABI void copyStrtab(StringRef Strtab)
Copy the string table for another module into this bitcode file.
LLVM_ABI void writeStrtab()
Write the bitcode file's string table.
LLVM_ABI ~BitcodeWriter()
LLVM_ABI void writeSymtab()
Attempt to write a symbol table to the bitcode file.
LLVM_ABI void writeModule(const Module &M, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the buffer specified at construction time.
LLVM_ABI BitcodeWriter(SmallVectorImpl< char > &Buffer)
Create a BitcodeWriter that writes to Buffer.
unsigned EmitAbbrev(std::shared_ptr< BitCodeAbbrev > Abbv)
Emits the abbreviation Abbv to the stream.
void markAndBlockFlushing()
For scenarios where the user wants to access a section of the stream to (for example) compute some ch...
StringRef getMarkedBufferAndResumeFlushing()
resumes flushing, but does not flush, and returns the section in the internal buffer starting from th...
void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev=0)
EmitRecord - Emit the specified record to the stream, using an abbrev if we have one to compress the ...
void Emit(uint32_t Val, unsigned NumBits)
void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals, StringRef Blob)
EmitRecordWithBlob - Emit the specified record to the stream, using an abbrev that includes a blob at...
unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr< BitCodeAbbrev > Abbv)
EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified BlockID.
void EnterBlockInfoBlock()
EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
void BackpatchWord(uint64_t BitNo, unsigned Val)
void BackpatchWord64(uint64_t BitNo, uint64_t Val)
void EnterSubblock(unsigned BlockID, unsigned CodeLen)
uint64_t GetCurrentBitNo() const
Retrieve the current position in the stream, in bits.
void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals)
EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
static LLVM_ABI BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
CallingConv::ID getCallingConv() const
Value * getCalledOperand() const
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
bool hasOperandBundles() const
Return true if this User has any operand bundles.
BasicBlock * getIndirectDest(unsigned i) const
BasicBlock * getDefaultDest() const
unsigned getNumIndirectDests() const
Return the number of callbr indirect dest labels.
bool isNoTailCall() const
bool isMustTailCall() const
iterator_range< NestedIterator > forGuid(GlobalValue::GUID GUID) const
@ Largest
The linker will choose the largest COMDAT.
@ SameSize
The data referenced by the COMDAT must be the same size.
@ Any
The linker may choose any COMDAT.
@ NoDeduplicate
No deduplication is performed.
@ ExactMatch
The data referenced by the COMDAT must be the same.
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
static LLVM_ABI Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
This class represents a range of values.
const APInt & getLower() const
Return the lower value for this range.
const APInt & getUpper() const
Return the upper value for this range.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
This is an important base class in LLVM.
DebugLoc getDebugLoc() const
LLVM_ABI DIAssignID * getAssignID() const
DIExpression * getExpression() const
DILocalVariable * getVariable() const
bool isDbgDeclareValue() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
bool isDbgDeclare() const
Metadata * getRawAddress() const
DIExpression * getAddressExpression() const
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Lightweight error class with error context and mandatory checking.
Function summary information to aid decisions and implementation of importing.
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
LLVM_ABI void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
LLVM_ABI void setSection(StringRef S)
Change the section for this global.
GVFlags flags() const
Get the flags for this GlobalValue (see struct GVFlags).
StringRef modulePath() const
Get the path to the module containing this function.
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
VisibilityTypes getVisibility() const
static bool isLocalLinkage(LinkageTypes Linkage)
LinkageTypes getLinkage() const
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
ThreadLocalMode getThreadLocalMode() const
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ProtectedVisibility
The GV is protected.
UnnamedAddr getUnnamedAddr() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
DLLStorageClassTypes getDLLStorageClass() const
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalVariable.
idx_iterator idx_end() const
idx_iterator idx_begin() const
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
This class implements a map that also provides access to all stored values in a deterministic order.
size_t getBufferSize() const
const char * getBufferStart() const
const char * getBufferEnd() const
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static constexpr uint64_t BitcodeSummaryVersion
A Module instance is used to store all the information related to an LLVM module.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Digest more data.
LLVM_ABI std::array< uint8_t, 20 > result()
Return the current raw 160-bits SHA1 for the digested data since the last call to init().
size_type size() const
Determine the number of elements in the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void append(StringRef RHS)
Append from a StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
const ValueTy & getValue() const
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
Utility for building string tables with deduplicated suffixes.
LLVM_ABI size_t add(CachedHashStringRef S, uint8_t Priority=0)
Add a string to the builder.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isX86_FP80Ty() const
Return true if this is x86 long double.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
bool isFP128Ty() const
Return true if this is 'fp128'.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
std::vector< std::pair< const Value *, unsigned > > ValueList
unsigned getTypeID(Type *T) const
unsigned getMetadataID(const Metadata *MD) const
UseListOrderStack UseListOrders
ArrayRef< const Metadata * > getNonMDStrings() const
Get the non-MDString metadata for this block.
unsigned getInstructionID(const Instruction *I) const
unsigned getAttributeListID(AttributeList PAL) const
void incorporateFunction(const Function &F)
incorporateFunction/purgeFunction - If you'd like to deal with a function, use these two methods to g...
void getFunctionConstantRange(unsigned &Start, unsigned &End) const
getFunctionConstantRange - Return the range of values that corresponds to function-local constants.
unsigned getAttributeGroupID(IndexAndAttrSet Group) const
bool hasMDs() const
Check whether the current block has any metadata to emit.
unsigned getComdatID(const Comdat *C) const
uint64_t computeBitsRequiredForTypeIndices() const
unsigned getValueID(const Value *V) const
unsigned getMetadataOrNullID(const Metadata *MD) const
const std::vector< IndexAndAttrSet > & getAttributeGroups() const
const ValueList & getValues() const
unsigned getGlobalBasicBlockID(const BasicBlock *BB) const
getGlobalBasicBlockID - This returns the function-specific ID for the specified basic block.
void setInstructionID(const Instruction *I)
const std::vector< const BasicBlock * > & getBasicBlocks() const
const std::vector< AttributeList > & getAttributeLists() const
bool shouldPreserveUseListOrder() const
const ComdatSetType & getComdats() const
std::vector< Type * > TypeList
ArrayRef< const Metadata * > getMDStrings() const
Get the MDString metadata for this block.
std::pair< unsigned, AttributeSet > IndexAndAttrSet
Attribute groups as encoded in bitcode are almost AttributeSets, but they include the AttributeList i...
const TypeList & getTypes() const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
std::pair< iterator, bool > insert(const ValueT &V)
void build(llvm::MapVector< CallStackId, llvm::SmallVector< FrameIdTy > > &&MemProfCallStackData, const llvm::DenseMap< FrameIdTy, LinearFrameId > *MemProfFrameIndexes, llvm::DenseMap< FrameIdTy, FrameStat > &FrameHistogram)
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an std::string.
std::string & str()
Returns the string's reference.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
@ CE
Windows NT (Windows on ARM)
@ TYPE_CODE_OPAQUE_POINTER
@ METADATA_TEMPLATE_VALUE
@ METADATA_LEXICAL_BLOCK_FILE
@ METADATA_SUBROUTINE_TYPE
@ METADATA_GLOBAL_DECL_ATTACHMENT
@ METADATA_IMPORTED_ENTITY
@ METADATA_GENERIC_SUBRANGE
@ METADATA_COMPOSITE_TYPE
@ METADATA_FIXED_POINT_TYPE
@ METADATA_GLOBAL_VAR_EXPR
GlobalValueSummarySymtabCodes
@ FS_CONTEXT_RADIX_TREE_ARRAY
@ FS_COMBINED_GLOBALVAR_INIT_REFS
@ FS_TYPE_CHECKED_LOAD_VCALLS
@ FS_COMBINED_ORIGINAL_NAME
@ FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_CONST_VCALL
@ FS_PERMODULE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_VCALLS
@ FS_COMBINED_ALLOC_INFO_NO_CONTEXT
@ FS_COMBINED_CALLSITE_INFO
@ FS_PERMODULE_CALLSITE_INFO
@ FS_PERMODULE_ALLOC_INFO
@ FS_TYPE_CHECKED_LOAD_CONST_VCALL
@ IDENTIFICATION_CODE_EPOCH
@ IDENTIFICATION_CODE_STRING
@ CST_CODE_DSO_LOCAL_EQUIVALENT
@ CST_CODE_CE_GEP_WITH_INRANGE
@ COMDAT_SELECTION_KIND_LARGEST
@ COMDAT_SELECTION_KIND_ANY
@ COMDAT_SELECTION_KIND_SAME_SIZE
@ COMDAT_SELECTION_KIND_EXACT_MATCH
@ COMDAT_SELECTION_KIND_NO_DUPLICATES
@ ATTR_KIND_STACK_PROTECT
@ ATTR_KIND_STACK_PROTECT_STRONG
@ ATTR_KIND_SANITIZE_MEMORY
@ ATTR_KIND_OPTIMIZE_FOR_SIZE
@ ATTR_KIND_FNRETTHUNK_EXTERN
@ ATTR_KIND_NO_DIVERGENCE_SOURCE
@ ATTR_KIND_SANITIZE_ADDRESS
@ ATTR_KIND_NO_IMPLICIT_FLOAT
@ ATTR_KIND_DEAD_ON_UNWIND
@ ATTR_KIND_STACK_ALIGNMENT
@ ATTR_KIND_STACK_PROTECT_REQ
@ ATTR_KIND_NULL_POINTER_IS_VALID
@ ATTR_KIND_SANITIZE_HWADDRESS
@ ATTR_KIND_RETURNS_TWICE
@ ATTR_KIND_SHADOWCALLSTACK
@ ATTR_KIND_OPT_FOR_FUZZING
@ ATTR_KIND_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